GeometryTestAlg.h
Go to the documentation of this file.
1 /**
2  * @file GeometryTestAlg.h
3  * @brief Unit test for geometry functionalities
4  * @date 2011/02/17
5  * @author brebel@fnal.gov
6  * @see GeometryTestAlg.cxx
7  *
8  * Refactored by Gianluca Petrillo on May 5th, 2015.
9  */
10 
11 #ifndef GEO_GEOMETRYTESTALG_H
12 #define GEO_GEOMETRYTESTALG_H
13 
14 // LArSoft includes
17 
18 // ROOT
19 #include "TVector3.h"
20 
21 // C/C++ standard libraries
22 #include <string>
23 #include <set>
24 #include <vector>
25 #include <array>
26 
27 // forward declarations
28 namespace fhicl {
29  class ParameterSet;
30 }
31 
32 
33 namespace geo {
34 
35  // forward declarations
36  class GeometryCore;
37  class CryostatGeo;
38  class TPCGeo;
39  class PlaneGeo;
40  class AuxDetGeo;
41  class AuxDetSensitiveGeo;
42  struct CryostatID;
43  struct PlaneID;
44 
45  /** **************************************************************************
46  * @brief Performs tests on the geometry as seen by Geometry service
47  *
48  * Configuration parameters
49  * =========================
50  *
51  * - **DisableWireBoundaryCheck** (boolean, default: false): the exceptions
52  * thrown when checking wire boundaries are not fatal
53  * - **ExpectedWirePitches** (list of reals, default: empty):
54  * if specified, marks the expected uniform wire pitch, one entry for each
55  * plane; if there are more planes than elements, the missing pitches are
56  * assumed the same as the one in the last plane; if the parameter is
57  * not specified or empty, no expectation is taken, but the spacing is still
58  * checked to be uniform; exception: for legacy behaviour, default pitches
59  * are provided for some experiments
60  * - **ExpectedPlanePitches** (list of reals, default: empty):
61  * if specified, marks the expected uniform plane pitch, one entry for each
62  * plane vs. the following. It works as /ExpectedWirePitches/
63  * - **ForgiveExceptions** (list of strings, default: empty): the categories
64  * of exceptions in this list are "forgiven" (non-fatal)
65  * - **RunTests** (string list): marks which tests to run; each entry can be
66  * specified with a "+" or "-" prepended, to indicate to add or to remove
67  * the test from the set to be run, respectively. The directives act against
68  * a pre-existing default set that executes all tests, except the ones
69  * explicitly marked as excluded by default in the list below:
70  * + `CheckOverlaps` (not in default) perform overlap checks
71  * + `ThoroughCheck` (not in default) makes ROOT perform full geometry check
72  * + `DetectorIntro`: prints some information about the detector
73  * + `FindVolumes`: checks it can find the volumes corresponding to world
74  * and all cryostats
75  * + `Cryostat`:
76  * + `WireOrientations`: checks that the definition of wire coordinates is
77  * matching the prescription
78  * + `WireCoordFromPlane`: checks `PlaneGeo::WireCoordinateFrom()`
79  * + `ChannelToWire`:
80  * + `FindPlaneCenters`:
81  * + `Projection`:
82  * + `WirePos`: currently disabled
83  * + `PlanePointDecomposition`: methods for projections and decompositions
84  * on the wire coordinate reference system
85  * + `PlaneProjections`: methods for projections on the wire planes in the
86  * reference system of the frame of the plane
87  * + `WireCoordAngle`: tests geo::PlaneGeo::PhiZ()
88  * + `NearestWire`: tests `WireCoordinate()` and `NearestWire()`
89  * + `WireIntersection`: tests `WireIDsIntersect()`
90  * + `ThirdPlane`: tests `ThirdPlane()`
91  * + `ThirdPlaneSlope`: tests `ThirdPlaneSlope()`
92  * + `WirePitch`:
93  * + `PlanePitch`:
94  * + `InterWireProjectedDistance`: tests `geo::PlaneGeo::InterWireProjectedDistance()`
95  * + `Stepping`:
96  * + `FindAuxDet`: test on location of nearest auxiliary detector
97  * + `PrintWires`: (not in default) prints *all* the wires in the geometry
98  * + `default`: represents the default set (optionally prepended by '@')
99  * + `!` (special): means to forget the tests configured so far; used as the
100  * first test name, removes the default list but leaves unchanged the
101  * default behaviour (the one specified with "+*" or "-*")
102  * - **CheckForOverlaps** (boolean, default: false): equivalent to enabling
103  * `+CheckOverlaps` in `RunTests`
104  * - **PrintWires**: (boolean, default: false): equivalent to enabling
105  * `+PrintWires` in `RunTests`
106  * - **ComputeMass**: (boolean, default: `true`): prints the mass of the
107  * detector and cryostats, which may take a lot of time.
108  */
110  public:
111  explicit GeometryTestAlg(fhicl::ParameterSet const& pset);
112 
113  /// Virtual destructor
114  virtual ~GeometryTestAlg() = default;
115 
116  /// Runs the test
117  virtual void Setup(geo::GeometryCore const& new_geo) { geom = &new_geo; }
118 
119  /// Runs the test, returns a number of errors (very unlikely!)
120  virtual unsigned int Run();
121 
122  /// Returns the direction on plane orthogonal to wires where wire number increases
123  static std::array<double, 3> GetIncreasingWireDirection
124  (const geo::PlaneGeo& plane);
125 
126  private:
127  geo::GeometryCore const* geom; ///< pointer to geometry service provider
128 
129  bool fDisableValidWireIDcheck; ///< disable test on out-of-world NearestWire()
130  std::set<std::string> fNonFatalExceptions;
131  std::vector<double> fExpectedWirePitches; ///< wire pitch on each plane
132  std::vector<double> fExpectedPlanePitches; ///< plane pitch on each plane
133 
134  bool fComputeMass = true; ///< Whether to print the detector mass.
135 
136  // using as pointer just not to have to write the declaration in the header
138 
139  void printDetectorIntro() const;
140  void printChannelSummary();
141  void printVolBounds();
142  void printDetDim();
143  void printWirePos();
144  void printWiresInTPC(const TPCGeo& tpc, std::string indent = "") const;
145  void printAllGeometry() const;
146  void testFindVolumes();
147  void testCryostat();
148  void testTPC(geo::CryostatID const& cid);
149  void testPlaneDirections() const;
150  void testWireOrientations() const;
151  void testChannelToROP() const;
152  void testChannelToWire() const;
153  void testFindPlaneCenters();
154  void testProject();
155  void testPlaneProjectionReference() const;
156  void testPlanePointDecompositionFrame() const;
157  void testPlaneProjectionOnFrame() const;
158  void testPlaneProjection() const;
159  void testWireCoordFromPlane() const;
160  void testParallelWires() const;
161  void testPlanePointDecomposition() const;
162  void testWireCoordAngle() const;
163  void testWirePitch();
164  void testInterWireProjectedDistance() const;
165  void testPlanePitch();
166  void testStandardWirePos();
167  void testAPAWirePos();
168  void testNearestWire();
169  void testWireIntersection() const;
170  void testThirdPlane() const;
171  void testThirdPlane_dTdW() const;
172  void testStepping();
173  void testFindAuxDet() const;
174 
175  bool shouldRunTests(std::string test_name) const;
176 
177  // single tests for testFindVolumes
178  unsigned int testFindWorldVolumes();
179  unsigned int testFindCryostatVolumes();
180  unsigned int testFindTPCvolumePaths();
181 
182  /// Method to print the auxiliary detectors on screen.
183  void printAuxiliaryDetectors() const;
184 
185  /// Prints information of an auxiliary detector into the specified stream.
186  template <typename Stream>
187  void printAuxDetGeo(
188  Stream&& out, geo::AuxDetGeo const& auxDet,
189  std::string indent, std::string firstIndent
190  ) const;
191 
192  /// Prints information of an auxiliary detector into the specified stream.
193  template <typename Stream>
194  void printAuxDetGeo
195  (Stream&& out, geo::AuxDetGeo const& auxDet, std::string indent = "")
196  const
197  { printAuxDetGeo(std::forward<Stream>(out), auxDet, indent, indent); }
198 
199  /// Prints information of the sensitive auxiliary detector into a stream.
200  template <typename Stream>
201  void printAuxDetSensitiveGeo(
202  Stream&& out, geo::AuxDetSensitiveGeo const& auxDetSens,
203  std::string indent, std::string firstIndent
204  ) const;
205 
206  /// Prints information of the sensitive auxiliary detector into a stream.
207  template <typename Stream>
209  Stream&& out, geo::AuxDetSensitiveGeo const& auxDetSens,
210  std::string indent = ""
211  ) const
212  {
213  printAuxDetSensitiveGeo
214  (std::forward<Stream>(out), auxDetSens, indent, indent);
215  }
216 
217  /// Returns whether the auxiliary detector at `pos` is the `expected` one.
218  bool CheckAuxDetAtPosition
219  (double const pos[3], unsigned int expected) const;
220 
221  /// Returns whether the auxiliary sensitive detector at `pos` is expected.
222  bool CheckAuxDetSensitiveAtPosition
223  (double const pos[3], unsigned int expectedDet, unsigned int expectedSens)
224  const;
225 
226  /// Helper function for `testWireIntersection()`.
227  bool isWireAlignedToPlaneDirections
228  (geo::PlaneGeo const& plane, geo::Vector_t const& wireDir) const;
229 
230  /// Performs the wire intersection test at a single point
231  unsigned int testWireIntersectionAt
232  (geo::TPCGeo const& TPC, TVector3 const& point) const;
233 
234  /// Returns dT/dW expected from the specified segment A-to-B
235  std::vector<std::pair<geo::PlaneID, double>> ExpectedPlane_dTdW(
236  std::array<double, 3> const& A, std::array<double, 3> const& B,
237  const double driftVelocity = -0.1
238  ) const;
239 
240  /// Performs the third plane slope test with a single configuration
241  unsigned int testThirdPlane_dTdW_at
242  (std::vector<std::pair<geo::PlaneID, double>> const& plane_dTdW) const;
243 
244  };
245 
246 
247  namespace details {
248  /// Class telling whether a test needs to be run
250  public:
251  using TestList_t = std::set<std::string>;
252 
253  virtual ~TestTrackerClassBase() = default;
254 
255  /// Returns whether the specified test should run
256  virtual bool ShouldRun(std::string test_name) const = 0;
257 
258  /// Checks the test and records the request
259  bool operator() (std::string test_name);
260 
261  /// Allow the specified test to run
262  virtual void PleaseRunAlso(std::string test_name) = 0;
263 
264  /// Returns the tests that have been run
265  TestList_t const& RunTests() const { return run; }
266 
267  /// Returns the tests that have been skipped
268  TestList_t const& SkippedTests() const { return skipped; }
269 
270  /// Returns the tests that have been queried
271  TestList_t QueriedTests() const;
272 
273  /// Checks that the validity of the configuration (after the fact)
274  virtual bool CheckQueriesRegistry() const;
275 
276  /// Prints information about the configuration of the filter
277  virtual void PrintConfiguration(std::ostream&) const;
278 
279  protected:
280  TestList_t run; ///< requested tests that should be run
281  TestList_t skipped; ///< requested tests that should be skipped
282 
283  virtual void RecordRequest(std::string test_name, bool bRun);
284 
285  /// Checks the test and records the request
286  virtual bool Query(std::string test_name);
287 
288  /// Adds a vector of tests into a test set
289  static void CopyList
290  (TestList_t& dest, std::vector<std::string> const& from);
291  }; // class TestTrackerClassBase
292 
293  } // namespace details
294 
295 
296 } // namespace geo
297 
298 #endif // GEO_GEOMETRYTESTALG_H
IDparameter< geo::CryostatID > CryostatID
Member type of validated geo::CryostatID parameter.
std::set< std::string > fNonFatalExceptions
std::set< std::string > TestList_t
std::vector< double > fExpectedWirePitches
wire pitch on each plane
def testProject(defname="project", appFamily="demo", appName="demo", appVersion="demo")
Definition: get_files.py:16
const char expected[]
Definition: Exception_t.cc:22
std::string string
Definition: nybbler.cc:12
Geometry information for a single TPC.
Definition: TPCGeo.h:38
struct vector vector
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
Manages a set of names.
Definition: NameSelector.h:36
std::vector< double > fExpectedPlanePitches
plane pitch on each plane
testing::NameSelector fRunTests
test filter
TestList_t const & RunTests() const
Returns the tests that have been run.
Performs tests on the geometry as seen by Geometry service.
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
Definition: PlaneGeo.h:82
bool fDisableValidWireIDcheck
disable test on out-of-world NearestWire()
TestList_t run
requested tests that should be run
virtual void Setup(geo::GeometryCore const &new_geo)
Runs the test.
Description of geometry of one entire detector.
Class telling whether a test needs to be run.
void printAuxDetSensitiveGeo(Stream &&out, geo::AuxDetSensitiveGeo const &auxDetSens, std::string indent="") const
Prints information of the sensitive auxiliary detector into a stream.
TestList_t const & SkippedTests() const
Returns the tests that have been skipped.
TestList_t skipped
requested tests that should be skipped
Definitions of geometry vector data types.
detail::Node< FrameID, bool > PlaneID
Definition: CRTID.h:125
LArSoft geometry interface.
Definition: ChannelGeo.h:16
void PrintConfiguration(typename lar::example::PointIsolationAlg< T >::Configuration_t const &config, std::ostream &out=std::cout)
geo::GeometryCore const * geom
pointer to geometry service provider
The data type to uniquely identify a cryostat.
Definition: geo_types.h:190