10 #include "test/Geometry/GeometryTestAlg.h" 13 #include "Geometry/GeometryCore.h" 14 #include "Geometry/AuxDetGeo.h" 21 #include "TGeoManager.h" 22 #include "TStopwatch.h" 24 #include "TGeoVolume.h" 39 #include <initializer_list> 44 inline T sqr(
T v) {
return v*v; }
48 std::ostringstream sstr;
63 Point2D(
double new_y,
double new_z): y(new_y), z(new_z) {}
67 {
return { a.
y + b.
y, a.
z + b.
z }; }
69 {
return { p.
y *
f, p.
z * f }; }
71 {
return { p.
y /
f, p.
z / f }; }
72 template <
typename Stream>
74 { out <<
"( " << p.
y <<
" ; " << p.
z <<
" )";
return out; }
89 double DeltaY()
const {
return Max().y - Min().y; }
90 double DeltaZ()
const {
return Max().z - Min().z; }
91 bool isEmpty()
const {
return (DeltaY() == 0) || (DeltaZ() == 0); }
95 set_min_max(
min.y,
max.y, point.
y);
96 set_min_max(
min.z,
max.z, point.
z);
100 { IncludePoint(area.
min); IncludePoint(area.
max); }
116 { set_min(min_var, val); set_max(max_var, val); }
119 if (a > b) { min_var =
b; max_var =
a; }
120 else { min_var =
a; max_var =
b; }
135 std::vector<std::string> NonFatalErrors(pset.
get<std::vector<std::string>>
136 (
"ForgiveExceptions", std::vector<std::string>()));
137 std::copy(NonFatalErrors.begin(), NonFatalErrors.end(),
153 std::ostringstream sstr;
156 MF_LOG_INFO(
"GeometryTestAlg") <<
"Test selection:" << sstr.str();
166 <<
"GeometryTestAlg not configured: no valid geometry provided.\n";
173 <<
"GeometryTest version 1.0";
176 <<
"\tRunning on detector: '" 179 <<
"\n\tGeometry file: " 184 MF_LOG_INFO(
"GeometryTest") <<
"test for overlaps ...";
185 gGeoManager->CheckOverlaps(1
e-5);
186 gGeoManager->PrintOverlaps();
187 if (!gGeoManager->GetListOfOverlaps()->IsEmpty()) {
189 << gGeoManager->GetListOfOverlaps()->GetSize()
190 <<
" overlaps found in geometry during overlap test!";
197 MF_LOG_INFO(
"GeometryTest") <<
"thorough geometry test ...";
198 gGeoManager->CheckGeometryFull();
199 if (!gGeoManager->GetListOfOverlaps()->IsEmpty()) {
201 << gGeoManager->GetListOfOverlaps()->GetSize()
202 <<
" overlaps found in geometry during thorough test!";
209 MF_LOG_INFO(
"GeometryTest") <<
"test FindAllVolumes method ...";
215 MF_LOG_INFO(
"GeometryTest") <<
"testNearestChannel...";
232 std::ostringstream out;
235 <<
"(postumous) configuration error detected!\n" 240 log <<
"Tests completed:";
242 if (tests_run.empty()) {
243 log <<
"\n no test run";
246 log <<
"\n " << tests_run.size() <<
" tests run:\t ";
247 for (
std::string const& test_name: tests_run) log <<
" " << test_name;
250 if (!tests_skipped.empty()) {
251 log <<
"\n " << tests_skipped.size() <<
" tests skipped:\t ";
252 for (
std::string const& test_name: tests_skipped) log <<
" " << test_name;
282 TVector3
origin(0., 0., 0.);
283 TVector3 outside(1.e6, 1.e6, 1.e6);
286 <<
"test check of point in world: \n(0, 0, 0) is in volume " 288 <<
"\n (1e6, 1e6, 1e6) is in volume " 306 std::set<std::string> volume_names;
307 std::vector<TGeoNode const*>
nodes;
317 <<
" world volumes '" 319 for (TGeoNode
const* node: nodes) {
320 TGeoVolume
const* pVolume = node->GetVolume();
321 log <<
"\n - '" << pVolume->GetName() <<
"' (a " 322 << pVolume->GetShape()->GetName() <<
")";
325 if (nodes.size() != 1) {
328 <<
"Found " << nodes.size() <<
" world volumes '" 341 std::set<std::string> volume_names({
"volTPC"});
349 for (
auto const& path: node_paths) {
350 TGeoNode
const* node = path.back();
351 TGeoVolume
const* pVolume = node->GetVolume();
352 log <<
"\n - '" << pVolume->GetName() <<
"' (a " 353 << pVolume->GetShape()->GetName() <<
") with " << (path.size()-1)
355 for (TGeoNode
const* pNode: path) {
356 TGeoVolume
const* pVolume_loc = pNode->GetVolume();
357 log <<
"\n * '" << pVolume_loc->GetName() <<
"' (a " 358 << pVolume_loc->GetShape()->GetName() <<
") with a " 359 << pNode->GetMatrix()->IsA()->GetName() <<
" that " 360 << (pNode->GetMatrix()->IsTranslation()?
"is":
"is not")
361 <<
" a simple translation";
384 <<
"Collected " << nErrors <<
" errors during FindAllVolumes() test!\n";
400 float posWorld[3] = {0.0,0.0,0.0};
407 <<
" find nearest channel to point (" 419 <<
"\t ...nearest channel to point: " 423 std::array<float, 3> posWorldV;
424 for (
int i = 0; i < 3; ++i) posWorldV[i] = posWorld[i];
429 <<
"\t ...nearest channel to point: " 439 MF_LOG_DEBUG(
"GeometryTest") <<
"\tdone testing nearest channel";
444 <<
"\tattempt to cause an exception to be caught " 445 <<
"when looking for a nearest channel";
449 nullptr, posWorld + 1,
450 nullptr, posWorld + 2);
451 for (
int i = 0; i < 3; ++i) posWorld[i] *= 2.;
453 bool hasThrown =
false;
454 unsigned int nearest_to_what = 0;
460 <<
"caught execpetion: " 467 <<
"GeometryCore::NearestChannel() did not raise an exception on out-of-world position (" 473 <<
"), and returned " 475 <<
" instead.\n This is normally considered a failure.";
487 double xyz[3] = {0.};
488 double dxyz[3] = {0., 0., 1.};
493 <<
"\n\tposition:" << xyz[0] <<
"\t" << xyz[1] <<
"\t" << xyz[2]
494 <<
"\n\tdirection:" << dxyz[0] <<
"\t" << dxyz[1] <<
"\t" << dxyz[2];
496 gGeoManager->InitTrack(xyz, dxyz);
497 for (
int i=0; i<10; ++i) {
498 const double*
pos = gGeoManager->GetCurrentPoint();
499 const double*
dir = gGeoManager->GetCurrentDirection();
501 << gGeoManager->GetCurrentNode()->GetName()
502 <<
"\n\t\tpos=" <<
"\t" 506 <<
"\n\t\tdir=" <<
"\t" 511 << gGeoManager->GetCurrentNode()->GetVolume()->GetMaterial()->GetName();
513 gGeoManager->FindNextBoundary();
514 gGeoManager->FindNormal();
515 gGeoManager->Step(kTRUE,kTRUE);
518 xyz[0] = 306.108; xyz[1] = -7.23775; xyz[2] = 856.757;
519 gGeoManager->InitTrack(xyz, dxyz);
521 << gGeoManager->GetCurrentNode()->GetName()
523 << gGeoManager->GetCurrentNode()->GetVolume()->GetMaterial()->GetName();
525 gGeoManager->GetCurrentNode()->GetVolume()->GetMaterial()->Print();
testing::NameSelector fRunTests
test filter
std::vector< TGeoNode const * > FindAllVolumes(std::set< std::string > const &vol_names) const
Returns all the nodes with volumes with any of the specified names.
void set_sorted(double &min_var, double &max_var, double a, double b)
void Include(Area const &area)
void printChannelSummary()
void AddToDefinition(std::string set_name, NAMES...names)
Parses a list of names and add them to the specified definition.
void Intersect(Area const &area)
Names_t RejectedNames() const
Returns a list of names that were rejected.
void ParseNames(NAMES...names)
Parses a list of names and adds them to the selector.
void PrintConfiguration(std::ostream &) const
Prints the configuration into a stream.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Area(Point2D const &a, Point2D const &b)
Point2D(double new_y, double new_z)
Point2D operator*(Point2D const &p, double f)
void testNearestChannel()
void WorldBox(float *xlo, float *xhi, float *ylo, float *yhi, float *zlo, float *zhi) const
Fills the arguments with the boundaries of the world.
unsigned int testFindWorldVolumes()
unsigned int testFindTPCvolumePaths()
Names_t AcceptedNames() const
Returns a list of names that were accepted.
unsigned int NearestChannel(float const worldLoc[3]) const
Returns the ID of the channel nearest to the specified position.
std::set< std::string > fNonFatalExceptions
float TPCRadius() const
Returns the radius of the TPC (y or z direction)
void Parse(LIST const &items)
Parses the names in the list and adds them to the selector.
Point2D const & Min() const
T get(std::string const &key) const
bool CheckQueryRegistry() const
Checks that no known element with valid response was left unqueried.
void IncludePoint(Point2D const &point)
static int max(int a, int b)
Point2D operator/(Point2D const &p, double f)
#define MF_LOG_INFO(category)
virtual unsigned int Run()
Runs the test, returns a number of errors (very unlikely!)
Point2D const & Max() const
gar::geo::GeometryCore const * geom
pointer to geometry service provider
bool shouldRunTests(std::string test_name) const
General GArSoft Utilities.
Stream & operator<<(Stream &out, Point2D const &p)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
void set_min(double &var, double val)
void set_max(double &var, double val)
#define MF_LOG_VERBATIM(category)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::vector< std::vector< TGeoNode const * > > FindAllVolumePaths(std::set< std::string > const &vol_names) const
Returns paths of all nodes with volumes with the specified names.
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
float TPCLength() const
Returns the length of the TPC (x direction)
const std::string VolumeName(TVector3 const &point) const
Returns the name of the deepest volume containing specified point.
#define MF_LOG_WARNING(category)
unsigned int NChannels() const
Point2D operator+(Point2D const &a, Point2D const &b)
LArSoft geometry interface.
std::string GetWorldVolumeName() const
std::string ROOTFile() const
Returns the full directory path to the geometry file source.
std::string to_string(ModuleType const mt)
void set_min_max(double &min_var, double &max_var, double val)
constexpr Point origin()
Returns a origin position with a point of the specified type.
cet::coded_exception< error, detail::translate > exception
void printAllGeometry() const