52 template <
typename T> T
cube(T side) {
return side * side * side; }
54 template <
typename Po
int>
57 std::vector<Point> points;
58 points.reserve(
cube(pointsPerSide));
61 for (
unsigned int i = 0; i < pointsPerSide; ++i) {
63 for (
unsigned int j = 0; j < pointsPerSide; ++j) {
65 for (
unsigned int k = 0;
k < pointsPerSide; ++
k) {
82 out <<
"PointIsolationAlg algorithm configuration:"
83 <<
"\n radius: " << std::sqrt(config.
radius2)
95 unsigned int pointsPerSide,
102 using Point_t = std::array<Coord_t, 3U>;
110 std::vector<Point_t> points = createPointsInCube<Point_t>(pointsPerSide);
113 auto elapsed_init = std::chrono::duration_cast<std::chrono::duration<float>>
114 (stop_init_time - start_init_time);
116 unsigned int const expected = (config.
radius2 >= 1.)? points.size(): 0;
117 std::cout <<
"Processing " << points.size() <<
" points." << std::endl;
122 PointIsolationAlg_t::validateConfiguration(config);
123 PointIsolationAlg_t algo(config);
125 std::vector<size_t> result = algo.removeIsolatedPoints(points);
128 auto elapsed_run = std::chrono::duration_cast<std::chrono::duration<float>>
129 (stop_run_time - start_run_time);
134 PrintConfiguration<Coord_t>(config);
135 std::cout <<
"Found " << result.size() <<
"/" << points.size()
136 <<
" non-isolated points in " << (elapsed_run.count()*1000.) <<
" ms"
137 <<
" (" << (elapsed_init.count()*1000.) <<
" ms for initialization)"
140 if (result.size() != expected) {
141 throw std::logic_error(
142 "Expected " +
std::to_string(expected) +
" non-isolated points, found "
153 int main(
int argc,
char** argv) {
161 <<
" NumberOfPoints[+|-] IsolationRadius"
166 std::istringstream sstr;
168 enum RoundMode_t { rmNearest, rmCeil, rmFloor, rmDefault = rmNearest };
170 unsigned int requestedPoints = 0;
171 RoundMode_t roundMode = rmDefault;
173 sstr >> requestedPoints;
175 std::cerr <<
"Error: expected number of points as first argument, got '"
176 << argv[1] <<
"' instead." << std::endl;
181 if (sstr.eof()) roundMode = rmDefault;
184 case '+': roundMode = rmCeil;
break;
185 case '-': roundMode = rmFloor;
break;
187 std::cerr <<
"Invalid round mode specification '" << c
188 <<
"' (must be '+', '-' or omitted)" << std::endl;
198 std::cerr <<
"Error: expected isolation radius as second argument, got '"
199 << argv[2] <<
"' instead." << std::endl;
209 double sideLength = std::pow(
double(requestedPoints), 1./3.);
210 unsigned int pointsPerSide = (
unsigned int) std::floor(sideLength);
213 case rmCeil: pointsPerSide = (
unsigned int) std::ceil(sideLength);
break;
215 unsigned int const nFloorPoints =
cube(pointsPerSide),
216 nCeilPoints =
cube(pointsPerSide + 1);
217 if ((requestedPoints - nFloorPoints) >= (nCeilPoints - requestedPoints))
222 if (pointsPerSide < 1) pointsPerSide = 1;
225 constexpr
Coord_t margin = 0.5;
227 config.
radius2 = cet::square(radius);
228 config.
rangeX = { -margin, pointsPerSide - 1.0 + margin };
233 StressTest<Coord_t>(pointsPerSide, config);
235 catch (std::logic_error
const&
e) {
236 std::cerr <<
"Test failure!\n" << e.what() << std::endl;
Algorithm to detect isolated space points.
BEGIN_PROLOG could also be cerr
Coord_t radius2
square of isolation radius [cm^2]
Range_t rangeY
range in Y of the covered volume
enum geo::coordinates Coord_t
Range_t rangeX
range in X of the covered volume
recob::tracking::Point_t Point_t
Coord_t upper
upper boundary
Coord_t lower
lower boundary
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
std::vector< Point > createPointsInCube(unsigned int pointsPerSide)
Type containing all configuration parameters of the algorithm.
void StressTest(unsigned int pointsPerSide, typename lar::example::PointIsolationAlg< T >::Configuration_t const &config)
Algorithm(s) dealing with point isolation in space.
std::string to_string(WindowPattern const &pattern)
Range_t rangeZ
range in Z of the covered volume
int main(int argc, char **argv)
void PrintConfiguration(typename lar::example::PointIsolationAlg< T >::Configuration_t const &config, std::ostream &out=std::cout)
BEGIN_PROLOG could also be cout