DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
SurfaceInstaller.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/Shapes.h>
16 #include <DD4hep/Printout.h>
18 
19 // ROOT includes
20 #include <TClass.h>
21 
22 using namespace dd4hep;
23 
25 
27 SurfaceInstaller::SurfaceInstaller(Detector& description, int argc, char** argv)
28  : m_detDesc(description), m_det(), m_stopScanning(false)
29 {
30  if ( argc > 0 ) {
31  std::string det_name = argv[0];
32  std::string n = det_name[0] == '-' ? det_name.substr(1) : det_name;
33  m_det = description.detector(n);
34  if ( !m_det.isValid() ) {
35  std::stringstream err;
36  err << "The subdetector " << det_name << " is not known to the geometry.";
37  printout(INFO,"SurfaceInstaller",err.str().c_str());
38  except(det_name, err.str());
39  }
40  printout(INFO,m_det.name(), "+++ Processing SurfaceInstaller for subdetector: '%s'",m_det.name());
41  return;
42  }
43  except("SurfaceInstaller", "The plugin takes at least one argument. No argument supplied");
44 }
45 
47 void SurfaceInstaller::invalidInstaller(const std::string& msg) const {
48  const char* det = m_det.isValid() ? m_det.name() : "<UNKNOWN>";
49  std::string typ = m_det.isValid() ? m_det.type() : std::string("<UNKNOWN>");
50  printout(FATAL,"SurfaceInstaller","+++ Surfaces for: %s",det);
51  printout(FATAL,"SurfaceInstaller","+++ %s.",msg.c_str());
52  printout(FATAL,"SurfaceInstaller","+++ You sure you apply the correct plugin to generate");
53  printout(FATAL,"SurfaceInstaller","+++ surfaces for a detector of type %s",typ.c_str());
54  except("SurfaceInstaller", "+++ Failed to install Surfaces to detector "+std::string(det));
55 }
56 
59  DetElement module = component.parent();
60  if ( module.isValid() ) {
61  return module.placement().volume();
62  }
63  return Volume();
64 }
65 
67 const double* SurfaceInstaller::placementTranslation(DetElement component) const {
68  TGeoMatrix* mat = component.placement()->GetMatrix();
69  const double* trans = mat->GetTranslation();
70  return trans;
71 }
72 
75  if ( pv.volume().isSensitive() ) {
76  std::stringstream log;
77  PlacementPath all_nodes;
78  ElementPath det_elts;
79  detail::tools::elementPath(component,det_elts);
80  detail::tools::placementPath(component,all_nodes);
81  std::string elt_path = detail::tools::elementPath(det_elts);
82  std::string node_path = detail::tools::placementPath(all_nodes);
83 
84  log << "Lookup " << " Detector[" << det_elts.size() << "]: " << elt_path;
85  printout(INFO,m_det.name(), log.str());
86  log.str("");
87  log << " " << " Places[" << all_nodes.size() << "]: " << node_path;
88  printout(INFO,m_det.name(), log.str());
89  log.str("");
90  log << " " << " detail::matrix[" << all_nodes.size() << "]: ";
91  for(PlacementPath::const_reverse_iterator i=all_nodes.rbegin(); i!=all_nodes.rend(); ++i) {
92  PlacedVolume placed = *i;
93  log << (void*)(placed->GetMatrix()) << " ";
94  if ( placed->GetUserExtension() ) {
95  const PlacedVolume::VolIDs& vid = placed.volIDs();
96  for(PlacedVolume::VolIDs::const_iterator j=vid.begin(); j!=vid.end(); ++j) {
97  log << (*j).first << ":" << (*j).second << " ";
98  }
99  }
100  log << " ";
101  if ( i+1 == all_nodes.rend() ) log << "( -> " << placed->GetName() << ")";
102  }
103  // Get the module element:
104  printout(INFO,m_det.name(),log.str());
105  log.str("");
106  Volume vol = pv.volume();
107  log << " "
108  << " Sensitive: " << (vol.isSensitive() ? "YES" : "NO ")
109  << " Volume: " << (void*)vol.ptr() << " "
110  << " Shape: " << vol.solid().toString();
111  printout(INFO,m_det.name(),log.str());
112  return;
113  }
114  std::cout << component.name() << ": " << pv.name() << std::endl;
115 }
116 
119  const _C& children = e.children();
120  install(e,e.placement());
121  for (_C::const_iterator i=children.begin(); !m_stopScanning && i!=children.end(); ++i)
122  scan((*i).second);
123 }
124 
127  scan(m_det);
128 }
129 
dd4hep::DetElement::children
const Children & children() const
Access to the list of children.
Definition: DetElement.cpp:207
SurfaceInstaller.h
dd4hep::Detector::detector
virtual DetElement detector(const std::string &name) const =0
Retrieve a subdetector element by its name from the detector description.
dd4hep::DetElement::parent
DetElement parent() const
Access to the detector elements's parent.
Definition: DetElement.cpp:239
_C
DetElement::Children _C
Definition: GeometryWalk.cpp:64
dd4hep::DetElement::type
std::string type() const
Access detector type (structure, tracker, calorimeter, etc.).
Definition: DetElement.cpp:97
dd4hep::PlacedVolume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:173
dd4hep::DetElement::placement
PlacedVolume placement() const
Access to the physical volume of this detector element.
Definition: DetElement.cpp:321
dd4hep::detail::tools::placementPath
std::string placementPath(DetElement element)
Assemble the placement path from a given detector element to the world volume.
Definition: DetectorTools.cpp:276
dd4hep::Volume::solid
Solid solid() const
Access to Solid (Shape)
Definition: Volumes.cpp:1223
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:1293
dd4hep::Handle::name
const char * name() const
Access the object name (or "" if not supported by the object)
dd4hep::SurfaceInstaller::m_det
DetElement m_det
Reference to the detector element of the subdetector.
Definition: SurfaceInstaller.h:66
dd4hep::SurfaceInstaller::install
virtual void install(DetElement e, PlacedVolume pv)
Install volume information. Default implementation only prints!
Definition: SurfaceInstaller.cpp:74
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:378
dd4hep::SurfaceInstaller::scan
void scan()
Scan through tree of detector elements.
Definition: SurfaceInstaller.cpp:126
dd4hep::SurfaceInstaller::SurfaceInstaller
SurfaceInstaller()=delete
No default constructor.
dd4hep::SurfaceInstaller::parentVolume
Volume parentVolume(DetElement component) const
Shortcut to access the parent detectorelement's volume.
Definition: SurfaceInstaller.cpp:58
dd4hep::SurfaceInstaller::invalidInstaller
void invalidInstaller(const std::string &msg) const
Indicate error message and throw exception.
Definition: SurfaceInstaller.cpp:47
Shapes.h
dd4hep::SurfaceInstaller::PlacementPath
detail::tools::PlacementPath PlacementPath
Definition: SurfaceInstaller.h:58
dd4hep::detail::tools::elementPath
std::string elementPath(DetElement element)
Assemble the path of a particular detector element.
Definition: DetectorTools.cpp:207
dd4hep::DetElement::Children
std::map< std::string, DetElement > Children
Definition: DetElement.h:206
dd4hep::SurfaceInstaller::placementTranslation
const double * placementTranslation(DetElement component) const
Shortcut to access the translation vector of a given component.
Definition: SurfaceInstaller.cpp:67
dd4hep::SurfaceInstaller::ElementPath
detail::tools::ElementPath ElementPath
Definition: SurfaceInstaller.h:57
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
dd4hep::Solid_type::toString
std::string toString(int precision=2) const
Conversion to string for pretty print.
Definition: Shapes.h:190
det
DetElement::Object * det
Definition: AlignmentsCalculator.cpp:66
_C
DetElement::Children _C
Definition: SurfaceInstaller.cpp:24
dd4hep::PlacedVolume::volume
Volume volume() const
Logical volume of this placement.
Definition: Volumes.cpp:452
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::PlacedVolume::volIDs
const PlacedVolumeExtension::VolIDs & volIDs() const
Access to the volume IDs.
Definition: Volumes.cpp:480
dd4hep::SurfaceInstaller::m_stopScanning
bool m_stopScanning
Flag to inhibit useless further scans.
Definition: SurfaceInstaller.h:70
Printout.h