29 namespace DDSegmentation {
34 using std::runtime_error;
35 using std::stringstream;
40 _name(
"Segmentation"), _type(
"Segmentation"), _decoder(new
BitFieldCoder(cellEncoding)), _ownsDecoder(true) {
46 _name(
"Segmentation"), _type(
"Segmentation"), _decoder(newDecoder), _ownsDecoder(false) {
55 if ( p.second )
delete p.second;
62 throw std::runtime_error(
"This segmentation type:"+
_type+
" does not support sub-segmentations.");
67 map<std::string, StringParameter>::const_iterator it;
70 std::string identifier = it->second->typedValue();
78 map<std::string, StringParameter>::const_iterator it;
80 const std::string& identifier = it->second->typedValue();
86 cellNeighbours.insert(nID);
87 }
catch (runtime_error& e) {
92 cellNeighbours.insert(nID);
93 }
catch (runtime_error& e) {
111 map<std::string, Parameter>::const_iterator it =
_parameters.find(parameterName);
116 s <<
"Unknown parameter " << parameterName <<
" for segmentation type " <<
_type;
117 throw std::runtime_error(s.str());
124 pars.emplace_back(it.second);
130 for (
const auto* p : pars )
136 const std::string& defaultValue) {
146 return bin * cellSize + offset;
151 if (cellSize <= 1e-10) {
152 throw runtime_error(
"Invalid cell size: 0.0");
154 return int(floor((
position + 0.5 * cellSize - offset) / cellSize));
159 return (cellBoundaries[bin+1] + cellBoundaries[bin])*0.5 + offset;
165 if(fabs(
position/cellBoundaries.front()-1.0) < 3e-12)
return 0;
168 if(fabs(
position/cellBoundaries.back()-1.0) < 3e-12)
return int(cellBoundaries.size()-2);
171 if(
position < cellBoundaries.front()) {
172 std::stringstream err;
173 err << std::setprecision(20) << std::scientific;
174 err <<
"Hit Position (" <<
position <<
") is below the acceptance"
175 <<
" (" << cellBoundaries.front() <<
") "
176 <<
"of the segmentation";
177 throw std::runtime_error(err.str());
179 if(
position > cellBoundaries.back() ) {
180 std::stringstream err;
181 err << std::setprecision(20) << std::scientific;
182 err <<
"Hit Position (" <<
position <<
") is above the acceptance"
183 <<
" (" << cellBoundaries.back() <<
") "
184 <<
"of the segmentation";
185 throw std::runtime_error(err.str());
187 std::vector<double>::const_iterator bin = std::upper_bound(cellBoundaries.begin(),
188 cellBoundaries.end(),
191 return bin - cellBoundaries.begin() - 1 ;
196 std::stringstream errorMessage;
197 errorMessage << __func__ <<
" is not implemented for " <<
_type;
198 throw std::logic_error(errorMessage.str());