SpacePointTestUtils.cxx
Go to the documentation of this file.
1 /**
2  * @file SpacePointTestUtils.cxx
3  * @brief Utilities for tests based on space points (implementation file)
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date June 3, 2016
6  * @see SpacePointTestUtils.h
7  * @ingroup RemoveIsolatedSpacePoints
8  *
9  */
10 
11 #include "SpacePointTestUtils.h"
12 
13 // C/C++ standard libraries
14 #include <utility> // std::pair<>
15 #include <cmath> // std::sqrt()
16 #include <array>
17 
18 
19 // function prototype declarations (implementation below)
20 std::pair<int, int> ComputeRangeIndices
21  (double min, double max, double stepSize);
22 
23 
24 //------------------------------------------------------------------------------
26  (int ID, double const* pos, double error /* = 0. */)
27 {
28  // assume it's upper triangular; the documentation does not say
29  double const err[6] = { error, 0., 0., error, 0., error };
30  return {
31  pos,
32  err,
33  0.0, // chisq
34  ID
35  };
36 } // lar::example::tests::MakeSpacePoint()
37 
38 
39 //------------------------------------------------------------------------------
41  std::vector<recob::SpacePoint>& spacePoints,
42  geo::BoxBoundedGeo const& box,
43  double stepSize
44 ) {
45 
46  // determine the starting point
47  auto const indicesX = ComputeRangeIndices(box.MinX(), box.MaxX(), stepSize);
48  auto const indicesY = ComputeRangeIndices(box.MinY(), box.MaxY(), stepSize);
49  auto const indicesZ = ComputeRangeIndices(box.MinZ(), box.MaxZ(), stepSize);
50 
51  int ID = spacePoints.empty()? 1: spacePoints.back().ID() + 1;
52  size_t const origNPoints = spacePoints.size();
53  double const error = stepSize / std::sqrt(12.);
54 
55  // fill the grid;
56  // we don't use an increment (point[0] += stepping) to avoid rounding errors
57  std::array<double, 3> const center
58  {{ box.CenterX(), box.CenterY(), box.CenterZ() }};
59  std::array<double, 3> point;
60  for (int ix = indicesX.first; ix <= indicesX.second; ++ix) {
61  point[0] = center[0] + ix * stepSize;
62 
63  for (int iy = indicesY.first; iy <= indicesY.second; ++iy) {
64  point[1] = center[1] + iy * stepSize;
65 
66  for (int iz = indicesZ.first; iz <= indicesZ.second; ++iz) {
67  point[2] = center[2] + iz * stepSize;
68 
69  spacePoints.push_back(MakeSpacePoint(ID++, point.data(), error));
70 
71  } // for z
72  } // for y
73  } // for x
74 
75  return spacePoints.size() - origNPoints;
76 } // lar::example::tests::FillSpacePointGrid()
77 
78 
79 //------------------------------------------------------------------------------
80 std::pair<int, int> ComputeRangeIndices
81  (double min, double max, double stepSize)
82 {
83  if (min >= max) return { 0, 0 };
84 
85  double const center = (min + max) / 2.;
86  return { -int((center - min) / stepSize), int((max - center) / stepSize) };
87 
88 } // ::ComputeRangeIndices()
89 
90 
91 //------------------------------------------------------------------------------
Utilities for tests based on space points.
unsigned int ID
double MinX() const
Returns the world x coordinate of the start of the box.
Definition: BoxBoundedGeo.h:88
double CenterX() const
Returns the world x coordinate of the center of the box.
Definition: BoxBoundedGeo.h:94
double CenterZ() const
Returns the world z coordinate of the center of the box.
error
Definition: include.cc:26
double MaxX() const
Returns the world x coordinate of the end of the box.
Definition: BoxBoundedGeo.h:91
recob::SpacePoint MakeSpacePoint(int ID, double const *pos, double error=0.)
Creates and returns a new space point.
double MinZ() const
Returns the world z coordinate of the start of the box.
unsigned int FillSpacePointGrid(std::vector< recob::SpacePoint > &spacePoints, geo::BoxBoundedGeo const &box, double stepSize)
Creates space points distributed in a grid.
static int max(int a, int b)
void err(const char *fmt,...)
Definition: message.cpp:226
double MaxY() const
Returns the world y coordinate of the end of the box.
A base class aware of world box coordinatesAn object describing a simple shape can inherit from this ...
Definition: BoxBoundedGeo.h:33
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
double CenterY() const
Returns the world y coordinate of the center of the box.
double MaxZ() const
Returns the world z coordinate of the end of the box.
std::pair< int, int > ComputeRangeIndices(double min, double max, double stepSize)
def center(depos, point)
Definition: depos.py:117
double MinY() const
Returns the world y coordinate of the start of the box.