DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
DetectorCheck.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DD4hep/Detector.h>
16 #include <DD4hep/Printout.h>
17 #include <DD4hep/Factories.h>
18 #include <DD4hep/IDDescriptor.h>
19 #include <DD4hep/VolumeManager.h>
20 #include <DD4hep/DetectorTools.h>
21 #include <DD4hep/MatrixHelpers.h>
24 
25 // C/C++ include files
26 #include <stdexcept>
27 #include <algorithm>
28 #include <cstdlib>
29 
30 using namespace dd4hep;
31 
33 namespace dd4hep { namespace detail { namespace tools {
35  std::string elementPath(const PlacementPath& nodes, bool reverse= false);
36  } } }
37 
38 namespace {
39 
41 
59  struct DetectorCheck {
60  using StructureElements = std::map<DetElement, size_t>;
61  using Chain = detail::tools::PlacementPath;
63 
65  struct FND {
66  const std::string& test;
67  FND(const std::string& c) : test(c) {}
68  bool operator()(const VolIDs::value_type& c) const { return c.first == test; }
69  };
70  struct counters {
71  size_t elements { 0 };
72  size_t errors { 0 };
73  void reset() { elements = errors = 0; }
74  counters& operator+=(const counters& c) {
75  elements += c.elements;
76  errors += c.errors;
77  return *this;
78  }
79  };
80 
81  Detector& description;
82  AlignmentsNominalMap m_mapping;
83  DetElement m_current_detector;
84  SensitiveDetector m_current_sensitive;
85  IDDescriptor m_current_iddesc;
86  VolumeManager m_volMgr;
87  DetElement m_det;
88  std::string m_name { "GeometryCheck" };
89 
90  counters m_place_counters, m_sens_counters, m_geo_counters, m_struct_counters;
91  StructureElements m_structure_elements;
92 
93  bool check_structure { false };
94  bool check_geometry { false };
95  bool check_placements { false };
96  bool check_volmgr { false };
97  bool check_sensitive { false };
98  bool ignore_detector { false };
99 
100  SensitiveDetector get_current_sensitive_detector();
101 
103  DetectorCheck(Detector& description);
105  virtual ~DetectorCheck() = default;
106 
108  void checkManagerSingleVolume(DetElement e, PlacedVolume pv, const VolIDs& child_ids, const Chain& chain);
110  void checkManagerVolumeTree(DetElement e, PlacedVolume pv, VolIDs ids, const Chain& chain, size_t depth, size_t mx_depth);
111 
113  void checkSingleVolume(DetElement e, PlacedVolume pv);
115  void checkVolumeTree(DetElement e, PlacedVolume pv);
116 
118  bool checkDetElement(const std::string& path, DetElement detector, PlacedVolume pv);
120  bool checkDetElementTree(const std::string& path, DetElement detector, PlacedVolume pv);
121 
122  void execute(DetElement sdet, size_t depth);
123 
125  static long run(Detector& description,int argc,char** argv);
126  static void help(int argc,char** argv);
127  };
128  const char* tag_fail(size_t errs) {
129  return errs==0 ? "PASSED" : "FAILED";
130  }
131 }
132 
133 
135 DetectorCheck::DetectorCheck(Detector& desc)
136  : description(desc), m_mapping(desc.world())
137 {
138 }
139 
140 SensitiveDetector DetectorCheck::get_current_sensitive_detector() {
141  DetElement de = m_current_detector;
142  m_current_sensitive = description.sensitiveDetector(de.name());
143  m_current_iddesc = IDDescriptor();
144  if ( m_current_sensitive.isValid() ) {
145  m_current_iddesc = m_current_sensitive.readout().idSpec();
146  }
147  return m_current_sensitive;
148 }
149 
150 void DetectorCheck::execute(DetElement sdet, size_t depth) {
151  const char* line = "============================";
152  struct counters count_volmgr_sens, count_volmgr_place;
153  struct counters total, count_struct;
154  struct counters count_geo, count_geo_sens;
155 
156  if ( !sdet.isValid() ) {
157  ++m_place_counters.errors;
158  except("VolumeMgrTest", "The detector element is not known to the geometry.");
159  return;
160  }
161 
162  m_det = sdet;
163  m_current_detector = m_det;
164 
166  if ( check_sensitive || check_volmgr ) {
167  if ( m_det == m_det.world() ) {
168  m_current_sensitive = SensitiveDetector();
169  m_current_iddesc = IDDescriptor();
170  }
171  else {
172  m_current_sensitive = description.sensitiveDetector(m_det.name());
173  if ( !m_current_sensitive.isValid() ) {
174  printout(ERROR, m_name,
175  "The sensitive detector of subdetector %s "
176  "is not known to the geometry.", m_det.name());
177  return;
178  }
179  m_current_iddesc = m_current_sensitive.readout().idSpec();
180  }
181  }
183  if ( check_structure ) {
184  printout(ALWAYS, m_name, "%s%s Executing STRUCTURE test %s%s", line, line, line, line);
185  PlacedVolume pv = m_det.placement();
186  checkDetElementTree(m_det.path(), m_det, pv);
187  count_struct.elements = m_structure_elements.size();
188  count_struct.errors = m_struct_counters.errors;
189  total += count_struct;
190  m_structure_elements.clear();
191  m_struct_counters.reset();
192  }
193  if ( check_geometry ) {
194  printout(ALWAYS, m_name, "%s%s Executing GEOMETRY test %s%s", line, line, line, line);
195  PlacedVolume pv = m_det.placement();
196  checkVolumeTree(m_det, pv);
197  count_geo = m_geo_counters;
198  count_geo_sens = m_sens_counters;
199  total += count_geo_sens;
200  total += count_geo;
201  m_sens_counters.reset();
202  m_geo_counters.reset();
203  }
204 
205  if ( check_volmgr ) {
206  Chain chain;
207  PlacedVolume pv = m_det.placement();
208  VolIDs ids;
209 
210  printout(ALWAYS, m_name, "%s%s Executing VOLUME MANAGER test %s%s", line, line, line, line);
211  chain.emplace_back(pv);
212  m_volMgr = description.volumeManager();
213  if ( !m_volMgr.isValid() ) {
214  printout(ERROR, m_name, "Volume manager is not instantiated. Required for test!");
215  return;
216  }
217  if ( pv.volume() != description.worldVolume() ) {
218  ids = pv.volIDs();
219  }
220  m_sens_counters.reset();
221  m_current_detector = m_det;
222  checkManagerVolumeTree(m_det, pv, std::move(ids), chain, 1, depth);
223  count_volmgr_place = m_place_counters;
224  count_volmgr_sens = m_sens_counters;
225  total += count_volmgr_place;
226  total += count_volmgr_sens;
227  m_place_counters.reset();
228  m_sens_counters.reset();
229  }
230 
231  if ( check_structure ) {
232  printout(count_struct.errors > 0 ? ERROR : ALWAYS,
233  m_name, "+++ %s: Checked %10ld structure elements. Num.Errors:%6ld (structure test)",
234  tag_fail(count_struct.errors), count_struct.elements, count_struct.errors);
235  }
236  if ( check_geometry ) {
237  if ( check_sensitive ) {
238  printout(count_geo_sens.errors > 0 ? ERROR : ALWAYS,
239  m_name, "+++ %s: Checked %10ld sensitive elements. Num.Errors:%6ld (geometry test)",
240  tag_fail(count_geo_sens.errors), count_geo_sens.elements, count_geo_sens.errors);
241  }
242  printout(count_geo.errors > 0 ? ERROR : ALWAYS,
243  m_name, "+++ %s: Checked %10ld placements. Num.Errors:%6ld (geometry test)",
244  tag_fail(count_geo.errors), count_geo.elements, count_geo.errors);
245  }
246  if ( check_volmgr ) {
247  if ( check_sensitive ) {
248  printout(count_volmgr_sens.errors > 0 ? ERROR : ALWAYS,
249  m_name, "+++ %s: Checked %10ld sensitive elements. Num.Errors:%6ld (phys.VolID test)",
250  tag_fail(count_volmgr_sens.errors), count_volmgr_sens.elements, count_volmgr_sens.errors);
251  }
252  printout(count_volmgr_place.errors > 0 ? ERROR : ALWAYS,
253  m_name, "+++ %s: Checked %10ld sensitive placements. Num.Errors:%6ld (phys.VolID test)",
254  tag_fail(count_volmgr_place.errors), count_volmgr_sens.elements, count_volmgr_place.errors);
255  }
256  printout(ALWAYS, m_name, "+++ %s: Checked a total of %11ld elements. Num.Errors:%6ld (Some elements checked twice)",
257  tag_fail(total.errors), total.elements, total.errors);
258 }
259 
261 bool DetectorCheck::checkDetElement(const std::string& path, DetElement detector, PlacedVolume pv) {
262  bool det_valid = true;
263  bool parent_valid = true;
264  bool place_valid = true;
265  bool det_place_valid = true;
266  bool vol_valid = true;
267  auto nerrs = m_struct_counters.errors;
268  const char* de_path = detector.path().c_str();
269 
270  if ( !pv.isValid() ) {
271  printout(ERROR, m_name, "Invalid DetElement placement: %s", de_path);
272  ++m_struct_counters.errors;
273  place_valid = false;
274  }
275  if ( detector.path() != path ) {
276  printout(ERROR, m_name, "Invalid DetElement [path mismatch]: %s <> %s",
277  de_path, path.c_str());
278  ++m_struct_counters.errors;
279  }
280  if ( !detector.parent().isValid() && detector.world() != detector ) {
281  printout(ERROR, m_name, "Invalid DetElement [No parent]: %s", de_path);
282  ++m_struct_counters.errors;
283  parent_valid = false;
284  }
285  if ( !detector.placement().isValid() ) {
286  printout(ERROR, m_name, "Invalid DetElement [No placement]: %s", de_path);
287  ++m_struct_counters.errors;
288  det_place_valid = false;
289  }
290  else if ( !detector.volume().isValid() ) {
291  printout(ERROR, m_name, "Invalid DetElement [No volume]: %s", de_path);
292  ++m_struct_counters.errors;
293  vol_valid = false;
294  }
295  if ( detector.placement().isValid() && detector.placement() != pv ) {
296  printout(ERROR, m_name, "Invalid DetElement [Mismatched placement]: %s", de_path);
297  ++m_struct_counters.errors;
298  det_place_valid = false;
299  }
300  auto count = ++m_structure_elements[detector];
301  if ( count > 1 ) {
302  DetElement par = detector.parent();
303  printout(ERROR, m_name, "DetElement %s parent: %s is placed %ld times! Only single placement allowed.",
304  de_path, par.isValid() ? par.path().c_str() : "", m_structure_elements[detector]);
305  ++m_struct_counters.errors;
306  }
307  Alignment ideal = detector.nominal();
308  if ( !ideal.isValid() ) {
309  printout(ERROR, m_name, "Invalid DetElement [No ideal alignment]: %s", de_path);
310  ++m_struct_counters.errors;
311  }
312  Alignment survey = detector.survey();
313  if ( !survey.isValid() ) {
314  printout(ERROR, m_name, "Invalid DetElement [No survey alignment]: %s", de_path);
315  ++m_struct_counters.errors;
316  }
317  if ( ideal.isValid() ) {
318  const TGeoHMatrix& matrix = ideal.worldTransformation();
319  if ( matrix.IsIdentity() ) {
320  }
321  }
322  printout(nerrs != m_struct_counters.errors ? ERROR : INFO, m_name,
323  "DetElement %s [%s] parent: %s placement: %s [%s] volume: %s",
324  path.c_str(), yes_no(det_valid), yes_no(parent_valid), yes_no(det_place_valid),
325  yes_no(place_valid), yes_no(vol_valid));
326  return nerrs == m_struct_counters.errors;
327 }
328 
330 bool DetectorCheck::checkDetElementTree(const std::string& path, DetElement detector, PlacedVolume pv) {
331  auto nerrs = m_struct_counters.errors;
332  if ( !detector.isValid() ) {
333  printout(ERROR, m_name, "Invalid DetElement seen: %s", path.c_str());
334  ++m_struct_counters.errors;
335  return false;
336  }
337  bool is_world = detector == detector.world();
339  checkDetElement(path, detector, pv);
341  for ( const auto& c : detector.children() ) {
342  DetElement de = c.second;
343  if ( is_world ) {
344  m_current_sensitive = SensitiveDetector();
345  m_current_iddesc = IDDescriptor();
346  m_current_detector = de;
347  }
348  if ( de.parent().isValid() && de.parent() != detector ) {
349  printout(ERROR, m_name, "Invalid DetElement [Parent mismatch]: %s", de.path().c_str());
350  printout(ERROR, m_name, " apparent parent: %s structural parent: %s",
351  de.parent().path().c_str(), detector.path().c_str());
352  ++m_struct_counters.errors;
353  }
355  checkDetElementTree(path + "/" + c.first, de, de.placement());
356  }
357  return nerrs == m_struct_counters.errors;
358 }
359 
361 void DetectorCheck::checkSingleVolume(DetElement e, PlacedVolume pv) {
362 
363  ++m_geo_counters.elements;
365  if ( !e.isValid() ) {
366  printout(ERROR, m_name, "Invalid DetElement [Invalid handle]");
367  ++m_geo_counters.errors;
368  }
370  if ( !pv.isValid() ) {
371  printout(ERROR, m_name, "Invalid PlacedVolume [Invalid handle] DetElement: %s", e.path().c_str());
372  ++m_geo_counters.errors;
373  }
374  Volume vol = pv.volume();
376  if ( !vol.isValid() ) {
377  printout(ERROR, m_name, "Invalid Volume [Invalid handle] DetElement: %s", e.path().c_str());
378  ++m_geo_counters.errors;
379  return;
380  }
382  if ( check_sensitive && vol.isSensitive() ) {
384  ++m_sens_counters.elements;
385  if ( !sdv.isValid() ) {
386  printout(ERROR, m_name, "Invalid SensitiveDetector DetElement: %s", e.path().c_str());
387  ++m_sens_counters.errors;
388  }
389  SensitiveDetector sdd = get_current_sensitive_detector();
390  if ( sdd != sdv ) {
391  printout(ERROR, m_name, "Inconsistent sensitive detectors for DetElement: %s", e.path().c_str());
392  ++m_sens_counters.errors;
393  }
394  }
395 }
396 
398 void DetectorCheck::checkVolumeTree(DetElement detector, PlacedVolume pv) {
399  const TGeoNode* current = pv.ptr();
400  TObjArray* nodes = current->GetNodes();
401  int num_children = nodes ? nodes->GetEntriesFast() : 0;
402  bool is_world = detector == description.world();
403 
405  checkSingleVolume(detector, pv);
407  for(int i=0; i < num_children; ++i) {
408  TGeoNode* node = (TGeoNode*)nodes->At(i);
409  PlacedVolume place(node);
410  DetElement de = detector;
411 
412  if ( is_world ) {
413  m_current_detector = de;
414  get_current_sensitive_detector();
415  }
416 
418  for ( const auto& c : detector.children() ) {
419  if ( c.second.placement() == place ) {
420  de = c.second;
421  break;
422  }
423  }
424  checkVolumeTree(de, place);
425  if ( is_world ) {
426  m_current_sensitive = SensitiveDetector();
427  m_current_iddesc = IDDescriptor();
428  }
429  }
430 }
431 
433 void DetectorCheck::checkManagerSingleVolume(DetElement detector, PlacedVolume pv, const VolIDs& child_ids, const Chain& chain) {
434  std::stringstream err, log;
435  VolumeID det_vol_id = detector.volumeID();
436  VolumeID vid = det_vol_id;
437  DetElement top_sdet, det_elem;
438  VolumeManagerContext* mgr_ctxt = 0;
439 
440  ++m_place_counters.elements;
441 
442  try {
443  vid = m_current_iddesc.encode(child_ids);
444  top_sdet = m_volMgr.lookupDetector(vid);
445  det_elem = m_volMgr.lookupDetElement(vid);
446  mgr_ctxt = m_volMgr.lookupContext(vid);
447 
448  if ( pv.volume().isSensitive() ) {
449  PlacedVolume det_place = m_volMgr.lookupDetElementPlacement(vid);
450  ++m_sens_counters.elements;
451  if ( !ignore_detector && pv.ptr() != det_place.ptr() ) {
452  err << "VolumeMgrTest: Wrong placement "
453  << " got " << det_place.name() << " (" << (void*)det_place.ptr() << ")"
454  << " instead of " << pv.name() << " (" << (void*)pv.ptr() << ") "
455  << " vid:" << volumeID(vid);
456  ++m_place_counters.errors;
457  }
458  else if ( top_sdet.ptr() != detector.ptr() ) {
459  top_sdet = m_volMgr.lookupDetector(vid);
460  err << "VolumeMgrTest: Wrong associated sub-detector element vid=" << volumeID(vid)
461  << " got " << top_sdet.path() << " (" << (void*)top_sdet.ptr() << ") "
462  << " instead of " << detector.path() << " (" << (void*)detector.ptr() << ")"
463  << " vid:" << volumeID(vid);
464  ++m_place_counters.errors;
465  }
466  else if ( !detail::tools::isParentElement(detector,det_elem) ) {
467  // This is sort of a bit wischi-waschi....
468  err << "VolumeMgrTest: Wrong associated detector element vid=" << volumeID(vid)
469  << " got " << det_elem.path() << " (" << (void*)det_elem.ptr() << ") "
470  << " instead of " << detector.path() << " (" << (void*)detector.ptr() << ")"
471  << " vid:" << volumeID(vid);
472  ++m_place_counters.errors;
473  }
474  else if ( top_sdet.ptr() != m_det.ptr() ) {
475  err << "VolumeMgrTest: Wrong associated detector "
476  << " vid:" << volumeID(vid);
477  ++m_place_counters.errors;
478  }
479  }
480  }
481  catch(const std::exception& ex) {
482  err << "Lookup " << pv.name() << " id:" << volumeID(vid)
483  << " path:" << detector.path() << " error:" << ex.what();
484  ++m_place_counters.errors;
485  }
486 
487  if ( pv.volume().isSensitive() || (0 != det_vol_id) ) {
488  std::string id_desc;
489  log << "Volume:" << std::setw(50) << std::left << pv.name();
490  if ( pv.volume().isSensitive() ) {
492  log << " IDDesc:" << (char*)(dsc.ptr() == m_current_iddesc.ptr() ? "OK " : "BAD");
493  if ( dsc.ptr() != m_current_iddesc.ptr() ) ++m_place_counters.errors;
494  }
495  else {
496  log << std::setw(11) << " ";
497  }
498  id_desc = m_current_iddesc.str(vid);
499  log << " [" << char(pv.volume().isSensitive() ? 'S' : 'N') << "] " << std::right
500  << " vid:" << volumeID(vid)
501  << " " << id_desc;
502  if ( !err.str().empty() ) {
503  printout(ERROR, m_det.name(),err.str()+" "+log.str());
504  //throw std::runtime_error(err.str());
505  return;
506  }
507  id_desc = m_current_iddesc.str(det_elem.volumeID());
508  printout(INFO, m_det.name(),log.str());
509  printout(INFO, m_det.name(), " Elt:%-64s vid:%s %s Parent-OK:%3s",
510  det_elem.path().c_str(),volumeID(det_elem.volumeID()).c_str(),
511  id_desc.c_str(),
512  yes_no(detail::tools::isParentElement(detector,det_elem)));
513 
514  try {
515  if ( pv.volume().isSensitive() ) {
516  TGeoHMatrix trafo;
517  for (size_t i = chain.size()-1; i > 0; --i) {
518  //for (size_t i = 0; i<chain.size(); ++i ) {
519  const TGeoMatrix* mat = chain[i]->GetMatrix();
520  trafo.MultiplyLeft(mat);
521  }
522  for (size_t i = chain.size(); i > 0; --i) {
523  const TGeoMatrix* mat = chain[i-1]->GetMatrix();
524  if ( printLevel() <= INFO ) {
525  ::printf("Placement [%d] VolID:%s\t\t",int(i),chain[i-1].volIDs().str().c_str());
526  mat->Print();
527  }
528  }
529  det_elem = m_volMgr.lookupDetElement(vid);
530  if ( printLevel() <= INFO ) {
531  ::printf("Computed Trafo (from placements):\t\t");
532  trafo.Print();
533  ::printf("DetElement Trafo: %s [%s]\t\t",
534  det_elem.path().c_str(),volumeID(det_elem.volumeID()).c_str());
535  det_elem.nominal().worldTransformation().Print();
536  ::printf("VolumeMgr Trafo: %s [%s]\t\t",det_elem.path().c_str(),volumeID(vid).c_str());
537  m_volMgr.worldTransformation(m_mapping,vid).Print();
538  }
539 
541  if ( 0 == mgr_ctxt ) {
542  printout(ERROR, m_det.name(), "VOLUME_MANAGER FAILED: Could not find entry for vid:%s.",
543  volumeID(vid).c_str());
544  ++m_place_counters.errors;
545  }
546 
548  if ( &det_elem.nominal().worldTransformation() != &m_volMgr.worldTransformation(m_mapping,det_elem.volumeID()) )
549  {
550  printout(ERROR, m_det.name(), "DETELEMENT_PERSISTENCY FAILED: World transformation have DIFFERET pointer!");
551  ++m_place_counters.errors;
552  }
553 
554  if ( !ignore_detector ) {
555  if ( pv.ptr() == det_elem.placement().ptr() ) {
556  // The computed transformation 'trafo' MUST be equal to:
557  // m_volMgr.worldTransformation(vid) AND det_elem.nominal().worldTransformation()
558  int res1 = detail::matrix::_matrixEqual(trafo, det_elem.nominal().worldTransformation());
559  int res2 = detail::matrix::_matrixEqual(trafo, m_volMgr.worldTransformation(m_mapping,vid));
561  printout(ERROR, m_det.name(), "DETELEMENT_PLACEMENT FAILED: World transformation DIFFER.");
562  ++m_place_counters.errors;
563  }
564  else {
565  printout(INFO, m_det.name(), "DETELEMENT_PLACEMENT: PASSED. All matrices equal: %s",
566  volumeID(vid).c_str());
567  }
568  }
569  else {
570  // The computed transformation 'trafo' MUST be equal to:
571  // m_volMgr.worldTransformation(vid)
572  // The det_elem.nominal().worldTransformation() however is DIFFERENT!
573  int res2 = detail::matrix::_matrixEqual(trafo, m_volMgr.worldTransformation(m_mapping,vid));
574  if ( res2 != detail::matrix::MATRICES_EQUAL ) {
575  printout(ERROR, m_det.name(), "VOLUME_PLACEMENT FAILED: World transformation DIFFER.");
576  ++m_place_counters.errors;
577  }
578  else {
579  printout(INFO, m_det.name(), "VOLUME_PLACEMENT: PASSED. All matrices equal: %s",
580  volumeID(vid).c_str());
581  }
582  }
583  }
584  }
585  }
586  catch(const std::exception& ex) {
587  err << "Matrix " << pv.name() << " id:" << volumeID(vid)
588  << " path:" << detector.path() << " error:" << ex.what();
589  ++m_place_counters.errors;
590  }
591 
592  }
593 }
594 
596 void DetectorCheck::checkManagerVolumeTree(DetElement detector, PlacedVolume pv, VolIDs ids, const Chain& chain,
597  size_t depth, size_t mx_depth)
598 {
599  if ( depth <= mx_depth ) {
600  const TGeoNode* current = pv.ptr();
601  TObjArray* nodes = current->GetNodes();
602  int num_children = nodes ? nodes->GetEntriesFast() : 0;
603  bool is_world = detector == description.world();
604 
605  for(int i=0; i<num_children; ++i) {
606  TGeoNode* node = (TGeoNode*)nodes->At(i);
607  PlacedVolume place(node);
608  VolIDs child_ids(ids);
609  Chain child_chain(chain);
610  DetElement de = detector;
611  if ( is_world ) {
613  for ( const auto& c : detector.children() ) {
614  if ( c.second.placement() == place ) {
615  de = c.second;
616  break;
617  }
618  }
619  m_current_detector = de;
620  get_current_sensitive_detector();
621  }
622  place.access(); // Test validity
623  child_chain.emplace_back(place);
624  child_ids.insert(child_ids.end(), place.volIDs().begin(), place.volIDs().end());
625  checkManagerSingleVolume(de, place, child_ids, child_chain);
626  checkManagerVolumeTree(de, place, std::move(child_ids), child_chain, depth+1, mx_depth);
627  }
628  }
629 }
630 
631 void DetectorCheck::help(int argc,char** argv) {
632  std::cout
633  <<
634  "DD4hep_DetectorCheck -option [-option] \n"
635  " -help Print this help message \n"
636  " -name <subdetector name> Name of the subdetector to be checked \n"
637  " \"ALL\" or \"all\": loop over known subdetectors\n"
638  " \"world\" start from the mother of all... \n"
639  " -structure Check structural tree consistency \n"
640  " -geometry Check geometry tree consistency \n"
641  " -sensitve Check consistency between detector and volume \n"
642  " settings of sensitive detectors. \n"
643  " -volmgr Check volume manager entries against volIDs of \n"
644  " sensitive volume placements. \n\n"
645  " NOTE: Option requires proper PhysVolID setup \n"
646  " of the sensitive volume placements ! \n"
647  " -ignore_detector Ignore DetElement placement check for -volmgr \n"
648  << std::endl;
649  std::cout << "Arguments: " << std::endl;
650  for(int iarg=0; iarg<argc;++iarg) {
651  std::cout << "Argument[" << iarg << "] = " << argv[iarg] << std::endl;
652  }
653  ::exit(EINVAL);
654 }
655 
657 long DetectorCheck::run(Detector& description,int argc,char** argv) {
658  std::string name;
659  bool volmgr = false;
660  bool geometry = false;
661  bool structure = false;
662  bool sensitive = false;
663  bool placements = false;
664  bool ignore_de = false;
665  printout(ALWAYS, "DetectorCheck", "++ Processing plugin...");
666  for(int iarg=0; iarg<argc;++iarg) {
667  if ( argv[iarg] == 0 ) break;
668  if ( ::strncasecmp(argv[iarg], "-name",4) == 0 && (iarg+1) < argc )
669  name = argv[++iarg];
670  else if ( ::strncasecmp(argv[iarg], "-structure",4) == 0 )
671  structure = true;
672  else if ( ::strncasecmp(argv[iarg], "-placements",4) == 0 )
673  placements = true;
674  else if ( ::strncasecmp(argv[iarg], "-volmgr",4) == 0 )
675  volmgr = true;
676  else if ( ::strncasecmp(argv[iarg], "-geometry",4) == 0 )
677  geometry = true;
678  else if ( ::strncasecmp(argv[iarg], "-sensitive",4) == 0 )
679  sensitive = true;
680  else if ( ::strncasecmp(argv[iarg], "-ignore_detelement",4) == 0 )
681  ignore_de = true;
682  else if ( ::strncasecmp(argv[iarg], "-help",4) == 0 )
683  help(argc, argv);
684  else
685  help(argc, argv);
686  }
687  if ( argc == 0 ) help(argc, argv);
688  if ( !name.empty() ) {
689  DetectorCheck test(description);
690  if ( name == "all" || name == "All" || name == "ALL" ) {
691  for (const auto& det : description.detectors() ) {
692  printout(INFO, "DetectorCheck", "++ Processing subdetector: %s", det.second.name());
693  test.check_structure = structure;
694  test.check_placements = placements;
695  test.check_volmgr = volmgr;
696  test.check_geometry = geometry;
697  test.check_sensitive = sensitive;
698  test.ignore_detector = ignore_de;
699  test.execute(det.second, 9999);
700  }
701  return 1;
702  }
703  DetElement det = (::strcasecmp(name.c_str(), "world") == 0)
704  ? description.world() : description.detector(name);
705  printout(INFO, "DetectorCheck", "++ Processing subdetector: %s",name.c_str());
706  test.check_structure = structure;
707  test.check_placements = placements;
708  test.check_volmgr = volmgr;
709  test.check_geometry = geometry;
710  test.check_sensitive = sensitive;
711  test.ignore_detector = ignore_de;
712  test.execute(det, 9999);
713  }
714  return 1;
715 }
716 
717 DECLARE_APPLY(DD4hep_DetectorCheck,DetectorCheck::run)
718 
719 long run_VolumeMgrTest(Detector& description,int argc, const char*const* argv) {
721  const char* args[] = {"-name", argc > 0 ? argv[0] : "world", "-structure", "-geometry", "-volmgr", 0 };
722  return DetectorCheck::run(description, 6, (char**)args);
723 }
724 DECLARE_APPLY(DD4hep_VolumeMgrTest,run_VolumeMgrTest)
dd4hep::DetElement::children
const Children & children() const
Access to the list of children.
Definition: DetElement.cpp:207
dd4hep::DetElement::path
const std::string & path() const
Path of the detector element (not necessarily identical to placement path!)
Definition: DetElement.cpp:158
dd4hep::Detector::world
virtual DetElement world() const =0
Return reference to the top-most (world) detector element.
dd4hep::Detector::detector
virtual DetElement detector(const std::string &name) const =0
Retrieve a subdetector element by its name from the detector description.
dd4hep::SensitiveDetector
Handle class to hold the information of a sensitive detector.
Definition: DetElement.h:44
dd4hep::DetElement::parent
DetElement parent() const
Access to the detector elements's parent.
Definition: DetElement.cpp:239
MatrixHelpers.h
Detector.h
dd4hep::AlignmentsNominalMap
An implementation of the ConditionsMap interface to fall back to nominal alignment.
Definition: AlignmentsNominalMap.h:44
dd4hep::exception
void exception(const std::string &src, const std::string &msg)
Definition: RootDictionary.h:69
dd4hep::PlacedVolume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:163
dd4hep::Detector::detectors
virtual const HandleMap & detectors() const =0
Accessor to the map of sub-detectors.
dd4hep::DetElement::placement
PlacedVolume placement() const
Access to the physical volume of this detector element.
Definition: DetElement.cpp:321
VolumeManagerInterna.h
dd4hep::IDDescriptor
Class implementing the ID encoding of the detector response.
Definition: IDDescriptor.h:37
DECLARE_APPLY
#define DECLARE_APPLY(name, func)
Definition: Factories.h:281
AlignmentsNominalMap.h
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::Volume::isSensitive
bool isSensitive() const
Accessor if volume is sensitive (ie. is attached to a sensitive detector)
Definition: Volumes.cpp:1322
dd4hep::DetElement::volumeID
VolumeID volumeID() const
The cached VolumeID of this subdetector element.
Definition: DetElement.cpp:344
Factories.h
dd4hep::Handle::name
const char * name() const
Access the object name (or "" if not supported by the object)
help
void help(std::string argv0)
Definition: listcomponents.cpp:29
VolumeManager.h
run_VolumeMgrTest
long run_VolumeMgrTest(Detector &description, int argc, const char *const *argv)
Action routine to execute the test for backwards compatibility.
Definition: DetectorCheck.cpp:720
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::PlacedVolumeExtension::VolIDs
Volume ID container.
Definition: Volumes.h:88
dd4hep::Volume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:370
dd4hep::detail::matrix::MATRICES_EQUAL
@ MATRICES_EQUAL
Definition: MatrixHelpers.h:121
dd4hep::VolumeManager
Class to support the retrieval of detector elements and volumes given a valid identifier.
Definition: VolumeManager.h:135
dd4hep::DetElement::volume
Volume volume() const
Access to the logical volume of the detector element's placement.
Definition: DetElement.cpp:352
dd4hep::Alignment::worldTransformation
const TGeoHMatrix & worldTransformation() const
Create cached matrix to transform to world coordinates.
Definition: Alignments.cpp:68
DetectorTools.h
dd4hep::IDDescriptor::str
std::string str(VolumeID vid) const
Decode volume IDs and return string reprensentation for debugging purposes.
Definition: IDDescriptor.cpp:174
dd4hep::Alignment
Main handle class to hold an alignment object.
Definition: Alignments.h:115
dd4hep::DetElement::nominal
Alignment nominal() const
Access to the constant ideal (nominal) alignment information.
Definition: DetElement.cpp:185
dd4hep::PlacedVolume::VolIDs
PlacedVolumeExtension::VolIDs VolIDs
Definition: Volumes.h:166
dd4hep::sim::IDDescriptor
IDDescriptor IDDescriptor
Definition: LCIOConversions.cpp:69
dd4hep::detail::tools::isParentElement
bool isParentElement(DetElement parent, DetElement child)
Find path between the child element and the parent element.
Definition: DetectorTools.cpp:57
VolumeID
dd4hep::DDSegmentation::VolumeID VolumeID
Definition: SegmentationDictionary.h:50
dd4hep::detail::tools::elementPath
std::string elementPath(DetElement element)
Assemble the path of a particular detector element.
Definition: DetectorTools.cpp:207
IDDescriptor.h
dd4hep::Handle::ptr
T * ptr() const
Access to the held object.
Definition: Handle.h:153
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
det
DetElement::Object * det
Definition: AlignmentsCalculator.cpp:66
dd4hep::SensitiveDetector::readout
Readout readout() const
Access readout structure of the sensitive detector.
Definition: DetElement.cpp:420
dd4hep::detail::tools::PlacementPath
std::vector< PlacedVolume > PlacementPath
Definition: DetectorTools.h:39
dd4hep::PlacedVolume::volume
Volume volume() const
Logical volume of this placement.
Definition: Volumes.cpp:468
dd4hep::PlacedVolumeExtension::VolIDs::insert
std::pair< std::vector< VolID >::iterator, bool > insert(const std::string &name, int value)
Insert new entry.
Definition: Volumes.cpp:422
dd4hep::VolumeManagerContext
This structure describes the cached data for one placement held by the volume manager.
Definition: VolumeManager.h:50
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::detail::matrix::_matrixEqual
int _matrixEqual(const TGeoMatrix &left, const TGeoMatrix &right)
Check matrices for equality.
Definition: MatrixHelpers.cpp:277
dd4hep::Readout::idSpec
IDDescriptor idSpec() const
Access IDDescription structure.
Definition: Readout.cpp:112
dd4hep::PlacedVolume::volIDs
const PlacedVolumeExtension::VolIDs & volIDs() const
Access to the volume IDs.
Definition: Volumes.cpp:496
PlacementPath
detail::tools::PlacementPath PlacementPath
Definition: DetectorInterna.cpp:29
dd4hep::DetElement::world
DetElement world() const
Access to the world object. Only possible once the geometry is closed.
Definition: DetElement.cpp:245
dd4hep::DetElement::survey
Alignment survey() const
Access to the constant survey alignment information.
Definition: DetElement.cpp:198
Printout.h
dd4hep::Volume::sensitiveDetector
Handle< NamedObject > sensitiveDetector() const
Access to the handle to the sensitive detector.
Definition: Volumes.cpp:1316