DetectorPropertiesStandard_test.cc
Go to the documentation of this file.
1 /**
2  * @file DetectorPropertiesStandard_test.cc
3  * @brief Simple instantiation-only test for DetectorPropertiesStandard
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date May 6th, 2016
6  */
7 
8 // LArSoft libraries
16 #include "test/Geometry/geometry_unit_test_base.h"
17 
18 // C/C++ standard libraries
19 #include <array>
20 #include <iomanip>
21 
22 //------------------------------------------------------------------------------
23 //--- The test environment
24 //---
25 
26 /*
27  * GeometryTesterEnvironment, configured with a geometry-aware configuration
28  * object, is used in a non-Boost-unit-test context.
29  * It provides:
30  * - all the other services configured as dependencies
31  */
32 using TesterConfiguration =
35 
36 //------------------------------------------------------------------------------
37 //--- The tests
38 //---
39 
40 /** ****************************************************************************
41  * @brief Runs the test
42  * @param argc number of arguments in argv
43  * @param argv arguments to the function
44  * @return number of detected errors (0 on success)
45  * @throw cet::exception most of error situations throw
46  *
47  * The arguments in argv are:
48  * 0. name of the executable ("DetectorPropertiesStandard_test")
49  * 1. (mandatory) path to the FHiCL configuration file
50  * 2. FHiCL path to the configuration of the test
51  * (default: physics.analyzers.larptest)
52  * 3. FHiCL path to the configuration of DetectorProperties service
53  * (default: services.DetectorPropertiesService)
54  *
55  */
56 //------------------------------------------------------------------------------
57 int
58 main(int argc, char const** argv)
59 {
60 
61  TesterConfiguration config("detp_test");
62 
63  //
64  // parameter parsing
65  //
66  int iParam = 0;
67 
68  // first argument: configuration file (mandatory)
69  if (++iParam < argc)
70  config.SetConfigurationPath(argv[iParam]);
71  else {
72  std::cerr << "FHiCL configuration file path required as first argument!" << std::endl;
73  return 1;
74  }
75 
76  // second argument: path of the parameter set for geometry test configuration
77  // (optional; default does not have any tester)
78  if (++iParam < argc) config.SetMainTesterParameterSetPath(argv[iParam]);
79 
80  // third argument: path of the parameter set for DetectorProperties confi
81  // (optional; default: "services.DetectorProperties" from inherited object)
82  if (++iParam < argc) {
83  config.SetServiceParameterSetPath("DetectorPropertiesService", argv[iParam]);
84  }
85 
86  unsigned int nErrors = 0 /* Tester.Run() */;
87 
88  //
89  // testing environment setup
90  //
91  TestEnvironment TestEnv(config);
92 
93  // DetectorPropertiesStandard and all its dependencies support the simple set
94  // up (see testing::TesterEnvironment::SimpleProviderSetup()), except for
95  // Geometry, that has been configured already in the geometry-aware
96  // environment. So we invoke a simple set up for each of the dependencies:
97  TestEnv.SimpleProviderSetup<detinfo::LArPropertiesStandard>();
98  TestEnv.SimpleProviderSetup<detinfo::DetectorClocksStandard>();
99  TestEnv.SimpleProviderSetup<detinfo::DetectorPropertiesStandard>();
100 
101  //
102  // run the test algorithm
103  // (I leave it here for reference -- there is no test algorithm here)
104  //
105 
106  // 1. we initialize it from the configuration in the environment,
107  // MyTestAlgo Tester(TestEnv.TesterParameters());
108 
109  // 2. we set it up with the geometry from the environment
110  // Tester.Setup(*(TestEnv.Provider<detinfo::DetectorProperties>()));
111 
112  // 3. then we run it!
113  auto const& geom = *TestEnv.Provider<geo::GeometryCore>();
114  auto const clock_data = TestEnv.Provider<detinfo::DetectorClocks>()->DataForJob();
115  auto const& detp = *TestEnv.Provider<detinfo::DetectorProperties>();
116 
117  auto const driftVelocity = detp.DriftVelocity();
118  auto const TDCtick = sampling_rate(clock_data);
119  unsigned int const nWaveformTicks = detp.NumberTimeSamples();
120  unsigned int const nReadoutWindowTicks = detp.ReadOutWindowSize();
121 
122  mf::LogVerbatim("detp_test") << "Electric field in the active volume: " << detp.Efield()
123  << " kV/cm"
124  << "\nSampling rate: " << TDCtick << " ns"
125  << "\nArgon temperature: " << detp.Temperature() << " K"
126  << "\nArgon density: " << detp.Density() << " kg/dm^3 (at " << detp.Temperature() << " K)"
127  << "\nArgon density: " << detp.Density(87.0) << " kg/dm^3 (at 87 K)"
128  << "\nDrift velocity: " << driftVelocity << " cm/us"
129  << "\nReadout window: " << nReadoutWindowTicks << " ticks ("
130  << (nReadoutWindowTicks * TDCtick / 1000) << " us)"
131  << "\nTPC waveform length: " << nWaveformTicks << " ticks ("
132  << (nWaveformTicks * TDCtick / 1000) << " us)";
133 
134  // accumulate the plane IDs; needed just for table formatting
135  unsigned int headerColWidth = 0U;
136  for (auto planeID : geom.IteratePlaneIDs()) {
137  auto const l = std::string(planeID).length();
138  if (headerColWidth < l) headerColWidth = l;
139  }
140 
141  // print drift distances
142  // collect all drift distances, and check whether they are all equal
143  bool allSameDrift = true;
144  lar::util::RealComparisons<double> check(1.0); // 1 cm tolerance
145  auto driftDistances = geom.makeTPCData<double>();
146  for (auto const& TPC : geom.IterateTPCs()) {
147  auto const driftDistance = TPC.DriftDistance();
148  driftDistances[TPC.ID()] = driftDistance;
149  allSameDrift = allSameDrift & check.equal(driftDistance, driftDistances.first());
150  } // for
151 
152  if (allSameDrift) {
153  // print drift distance
154  auto const driftDistance = driftDistances.first();
155  auto const driftTime = driftDistance / driftVelocity;
156  mf::LogVerbatim("detp_test") << "Drift distance: " << driftDistance << " cm"
157  << "\nDrift time: " << driftTime << " us, "
158  << (driftTime / (TDCtick / 1000.)) << " ticks";
159  }
160  else {
161  // print drift distance table header
162  mf::LogVerbatim log("detp_test");
163  std::array<unsigned int, 4U> const columnSizes = {{headerColWidth, 9U, 13U, 7U}};
164  log << std::setw(columnSizes[0]) << "Drift:"
165  << " | " << std::setw(columnSizes[1]) << "time [us]"
166  << " | " << std::setw(columnSizes[2]) << "distance [cm]"
167  << " | " << std::setw(columnSizes[3]) << "ticks";
168 
169  // print drift distances by TPC
170  for (auto const& TPCID : geom.IterateTPCIDs()) {
171  auto const driftDistance = driftDistances[TPCID];
172  auto const driftTime = driftDistance / driftVelocity;
173  log << "\n"
174  << std::setw(columnSizes[0]) << TPCID << " | " << std::setw(columnSizes[1]) << driftTime
175  << " | " << std::setw(columnSizes[2]) << driftDistance << " | "
176  << std::setw(columnSizes[3]) << (driftTime / (TDCtick / 1000.));
177  } // for TPC
178  }
179 
180  // 4. And finally we cross fingers.
181  if (nErrors > 0) { mf::LogError("detp_test") << nErrors << " errors detected!"; }
182 
183  return nErrors;
184 } // main()
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::string string
Definition: nybbler.cc:12
Provides simple real number checks.
Helper functions for support of LArPropertiesService in LArSoft tests.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
int main(int argc, char const **argv)
Runs the test.
static QStrList * l
Definition: config.cpp:1044
Class for approximate comparisons.
bool check(const std::vector< std::vector< float > > &outputs)
Helper functions for support of DetectorClocksService in LArSoft tests.
testing::BasicGeometryEnvironmentConfiguration< geo::ChannelMapStandardAlg > TesterConfiguration
static Config * config
Definition: config.cpp:1054
Environment for a geometry test.
Description of geometry of one entire detector.
Class used for the conversion of times between different formats and references.
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
Class holding a configuration for a test environment.
testing::TesterEnvironment< testing::BasicEnvironmentConfiguration > TestEnvironment
virtual double DriftVelocity(double efield=0., double temperature=0.) const =0
Properties related to liquid argon environment in the detector.
Implementation of detinfo::DetectorClocks interface with fixed settings from configuration.
Access the description of detector geometry.
IDparameter< geo::TPCID > TPCID
Member type of validated geo::TPCID parameter.
constexpr bool equal(Value_t a, Value_t b) const
Returns whether a and b are no farther than the threshold.
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
QTextStream & endl(QTextStream &s)