driftvolumes_test.cxx
Go to the documentation of this file.
1 /**
2  * @file driftvolumes_test.cxx
3  * @brief Test for neighbourhood discovery in simple geometries.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date July 13, 2017
6  *
7  * Usage:
8  *
9  * driftvolumes_test configuration.fcl
10  *
11  * The configuration file must contain a geometry service provider configuration
12  * under `services.Geometry`, That geometry configuration must use the standard
13  * channel mapping.
14  */
15 
16 // LArSoft libraries
17 #include "test/Geometry/geometry_unit_test_base.h"
20 #include "larcorealg/Geometry/DriftPartitions.h" // BuildDriftVolumes()
21 #include "larcorealg/CoreUtils/DumpUtils.h" // lar::dump::vector3D()
22 
23 // utility libraries
25 
26 
27 //------------------------------------------------------------------------------
28 //--- The test environment
29 //---
30 
31 // we define here all the configuration that is needed;
32 // we use an existing class provided for this purpose, since our test
33 // environment allows us to tailor it at run time.
36 
37 /*
38  * GeometryTesterFixture, configured with the object above, is used in a
39  * non-Boost-unit-test context.
40  * It provides:
41  * - `geo::GeometryCore const* Geometry()`
42  * - `geo::GeometryCore const* GlobalGeometry()` (static member)
43  */
46 
47 
48 //------------------------------------------------------------------------------
49 //--- The tests
50 //---
51 
52 /** ****************************************************************************
53  * @brief Runs the test
54  * @param argc number of arguments in argv
55  * @param argv arguments to the function
56  * @return number of detected errors (0 on success)
57  * @throw cet::exception most of error situations throw
58  *
59  * The arguments in argv are:
60  * 0. name of the executable ("Geometry_test")
61  * 1. path to the FHiCL configuration file
62  * 2. FHiCL path to the configuration of the geometry
63  * (default: services.Geometry)
64  *
65  */
66 //------------------------------------------------------------------------------
67 int main(int argc, char const** argv) {
68 
69  StandardGeometryConfiguration config("driftvolumes_test");
70 
71  //
72  // parameter parsing
73  //
74  int iParam = 0;
75 
76  // first argument: configuration file (mandatory)
77  if (++iParam < argc) config.SetConfigurationPath(argv[iParam]);
78 
79  // second argument: path of the parameter set for geometry configuration
80  // (optional; default: "services.Geometry" from the inherited object)
81  if (++iParam < argc) config.SetGeometryParameterSetPath(argv[iParam]);
82 
83  //
84  // testing environment setup
85  //
87  auto const& geom = *(TestEnvironment.Provider<geo::GeometryCore>());
88 
89  //
90  // run the test algorithm
91  //
92 
93  unsigned int nErrors = 0;
94  for (auto const& cryo: geom.IterateCryostats()) {
95  auto partition = geo::buildDriftVolumes(cryo);
96  mf::LogVerbatim("driftvolumes_test")
97  << "Partition for cryostat " << cryo.ID() << ":";
98  partition.print(mf::LogVerbatim("driftvolumes_test"));
99 
100  //
101  // test that the partition topology is correct
102  //
103  for (geo::TPCGeo const& TPC: geom.IterateTPCs(cryo.ID())) {
104 
105  auto const& center = TPC.GetCenter<geo::Point_t>();
106 
107  auto where = partition.TPCat(center);
108  if (!where) {
109  mf::LogProblem("driftvolumes_test")
110  << "Center of TPC " << TPC.ID() << " " << lar::dump::vector3D(center)
111  << " not assigned to any TPC!";
112  ++nErrors;
113  }
114  else if (where->ID() != TPC.ID()) {
115  mf::LogProblem log("driftvolumes_test");
116  log
117  << "Center of TPC " << TPC.ID() << " " << lar::dump::vector3D(center)
118  << " assigned to TPC " << where->ID() << ":\n";
119  where->PrintTPCInfo(log, " ", /* verbosity */ 5);
120  ++nErrors;
121  }
122 
123  //
124  // test ownership of a uniform distribution of points inside the TPC
125  //
126  constexpr int nXsteps = 5, nYsteps = 5, nZsteps = 5;
127  const double xstep = TPC.HalfSizeX() / (nXsteps + 1);
128  const double ystep = TPC.HalfSizeY() / (nYsteps + 1);
129  const double zstep = TPC.HalfSizeZ() / (nZsteps + 1);
130  for (int xs = -nXsteps; xs <= nXsteps; ++xs) {
131  double const x = center.X() + xs * xstep;
132  for (int ys = -nYsteps; ys <= nYsteps; ++ys) {
133  double const y = center.Y() + ys * ystep;
134  for (int zs = -nZsteps; zs <= nZsteps; ++zs) {
135  double const z = center.Z() + zs * zstep;
136 
137  auto where = partition.TPCat({ x, y, z});
138  if (!where) {
139  mf::LogProblem("driftvolumes_test")
140  << "Point " << lar::dump::vector3D(center) << " within TPC "
141  << TPC.ID() << " (" << xs << "," << ys << "," << zs
142  << ") not assigned to any TPC!";
143  ++nErrors;
144  }
145  else if (where->ID() != TPC.ID()) {
146  mf::LogProblem log("driftvolumes_test");
147  log
148  << "Point " << lar::dump::vector3D(center) << " within TPC "
149  << TPC.ID() << " (" << xs << "," << ys << "," << zs
150  << ") assigned to TPC " << where->ID() << ":\n";
151  where->PrintTPCInfo(log, " ", /* verbosity */ 5);
152  ++nErrors;
153  }
154 
155  } // for zs
156  } // for ys
157  } // for xs
158 
159  } // for TPCs
160 
161  } // for
162 
163  // 4. And finally we cross fingers.
164  if (nErrors > 0) {
165  mf::LogError("geometry_test") << nErrors << " errors detected!";
166  }
167 
168  return nErrors;
169 } // main()
170 
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
Data structures and algorithms to partition a cryostat volume.
auto vector3D(Vector3D const &v)
Returns a manipulator which will print the specified vector.
Definition: DumpUtils.h:301
Geometry information for a single TPC.
Definition: TPCGeo.h:38
DriftPartitions buildDriftVolumes(geo::CryostatGeo const &cryo)
Creates a DriftPartitions object from the TPCs in a cryostat.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
MaybeLogger_< ELseverityLevel::ELsev_error, true > LogProblem
static Config * config
Definition: config.cpp:1054
Environment for a geometry test.
Description of geometry of one entire detector.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
Class holding a configuration for a test environment.
testing::TesterEnvironment< testing::BasicEnvironmentConfiguration > TestEnvironment
int main(int argc, char const **argv)
Runs the test.
def center(depos, point)
Definition: depos.py:117
testing::GeometryTesterEnvironment< StandardGeometryConfiguration > StandardGeometryTestEnvironment
static constexpr double zs
Definition: Units.h:102
Access the description of detector geometry.
list x
Definition: train.py:276
static constexpr double ys
Definition: Units.h:103