DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SurfaceInstaller.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation for LCD
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 // C/C++ include files
20 #include <stdexcept>
21 
22 // ROOT includes
23 #include "TClass.h"
24 
25 using namespace std;
26 using namespace DD4hep;
27 using namespace DD4hep::Geometry;
28 
30 
32 SurfaceInstaller::SurfaceInstaller(LCDD& lcdd, int argc, char** argv)
33  : m_lcdd(lcdd), m_det(), m_stopScanning(false)
34 {
35  if ( argc > 0 ) {
36  string det_name = argv[0];
37  string n = det_name[0] == '-' ? det_name.substr(1) : det_name;
38  m_det = lcdd.detector(n);
39  if ( !m_det.isValid() ) {
40  stringstream err;
41  err << "The subdetector " << det_name << " is not known to the geometry.";
42  printout(INFO,"SurfaceInstaller",err.str().c_str());
43  throw runtime_error(err.str());
44  }
45  printout(INFO,m_det.name(),"+++ Processing SurfaceInstaller for subdetector: '%s'",m_det.name());
46  return;
47  }
48  throw runtime_error("The plugin takes at least one argument. No argument supplied");
49 }
50 
52 void SurfaceInstaller::invalidInstaller(const std::string& msg) const {
53  const char* det = m_det.isValid() ? m_det.name() : "<UNKNOWN>";
54  const char* typ = m_det.isValid() ? m_det.type().c_str() : "<UNKNOWN>";
55  printout(FATAL,"SurfaceInstaller","+++ Surfaces for: %s",det);
56  printout(FATAL,"SurfaceInstaller","+++ %s.",msg.c_str());
57  printout(FATAL,"SurfaceInstaller","+++ You sure you apply the correct plugin to generate");
58  printout(FATAL,"SurfaceInstaller","+++ surfaces for a detector of type %s",typ);
59  throw std::runtime_error("+++ Failed to install Surfaces to detector "+string(det));
60 }
61 
64  DetElement module = component.parent();
65  if ( module.isValid() ) {
66  return module.placement().volume();
67  }
68  return Volume();
69 }
70 
73  TGeoMatrix* mat = component.placement()->GetMatrix();
74  const double* trans = mat->GetTranslation();
75  return trans;
76 }
77 
80  if ( pv.volume().isSensitive() ) {
81  stringstream log;
82  PlacementPath all_nodes;
83  ElementPath det_elts;
84  DetectorTools::elementPath(component,det_elts);
85  DetectorTools::placementPath(component,all_nodes);
86  string elt_path = DetectorTools::elementPath(det_elts);
87  string node_path = DetectorTools::placementPath(all_nodes);
88 
89  log << "Lookup " << " Detector[" << det_elts.size() << "]: " << elt_path;
90  printout(INFO,m_det.name(),log.str());
91  log.str("");
92  log << " " << " Places[" << all_nodes.size() << "]: " << node_path;
93  printout(INFO,m_det.name(),log.str());
94  log.str("");
95  log << " " << " Matrices[" << all_nodes.size() << "]: ";
96  for(PlacementPath::const_reverse_iterator i=all_nodes.rbegin(); i!=all_nodes.rend(); ++i) {
97  PlacedVolume placed = *i;
98  log << (void*)(placed->GetMatrix()) << " ";
99  if ( placed->GetUserExtension() ) {
100  const PlacedVolume::VolIDs& vid = placed.volIDs();
101  for(PlacedVolume::VolIDs::const_iterator j=vid.begin(); j!=vid.end(); ++j) {
102  log << (*j).first << ":" << (*j).second << " ";
103  }
104  }
105  log << " ";
106  if ( i+1 == all_nodes.rend() ) log << "( -> " << placed->GetName() << ")";
107  }
108  // Get the module element:
109  printout(INFO,m_det.name(),log.str());
110  log.str("");
111  Volume vol = pv.volume();
112  log << " "
113  << " Sensitive: " << (vol.isSensitive() ? "YES" : "NO ")
114  << " Volume: " << (void*)vol.ptr() << " "
115  << " Shape: " << vol.solid().toString();
116  printout(INFO,m_det.name(),log.str());
117  return;
118  }
119  cout << component.name() << ": " << pv.name() << endl;
120 }
121 
124  const _C& children = e.children();
125  install(e,e.placement());
126  for (_C::const_iterator i=children.begin(); !m_stopScanning && i!=children.end(); ++i)
127  scan((*i).second);
128 }
129 
132  scan(m_det);
133 }
134 
const double * placementTranslation(DetElement component) const
Shortcut to access the translation vector of a given component.
DetElement m_det
Reference to the detector element of the subdetector.
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:135
Solid solid() const
Access to Solid (Shape)
Definition: Volumes.cpp:693
Volume volume() const
Logical volume of this placement.
Definition: Volumes.cpp:389
const VolIDs & volIDs() const
Access to the volume IDs.
Definition: Volumes.cpp:399
const char * name() const
Access the object name (or "" if not supported by the object)
Definition: Handle.inl:36
Volume parentVolume(DetElement component) const
Shortcut to access the parent detectorelement's volume.
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:124
void invalidInstaller(const std::string &msg) const
Indicate error message and throw exception.
DetElement::Children _C
Geometry::DetectorTools::PlacementPath PlacementPath
const Children & children() const
Access to the list of children.
Definition: Detector.cpp:207
std::string type() const
Access detector type (structure, tracker, calorimeter, etc.).
Definition: Detector.cpp:98
return e
Definition: Volumes.cpp:297
T * ptr() const
Access to the held object.
Definition: Handle.h:149
bool m_stopScanning
Flag to inhibit useless further scans.
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:237
void scan()
Scan through tree of detector elements.
virtual DetElement detector(const std::string &name) const =0
Retrieve a field component by it's name from the detector description.
std::string toString(int precision=2) const
Conversion to string for pretty print.
Definition: Shapes.h:104
std::string placementPath(DetElement element)
Assemble the placement path from a given detector element to the world volume.
static ComponentCast * component(void *p)
PlacedVolume placement() const
Access to the physical volume of this detector element.
Definition: Detector.cpp:279
virtual void install(DetElement e, PlacedVolume pv)
Install volume information. Default implementation only prints!
DetElement parent() const
Access to the detector elements's parent.
Definition: Detector.cpp:222
Handle class describing a detector element.
Definition: Detector.h:172
std::string elementPath(const PlacementPath &nodes, bool reverse)
Assemble the path of the PlacedVolume selection.
Geometry::DetectorTools::ElementPath ElementPath
The main interface to the DD4hep detector description package.
Definition: LCDD.h:82
std::map< std::string, DetElement > Children
Definition: Detector.h:202
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.
Definition: Printout.cpp:111
bool isSensitive() const
Accessor if volume is sensitive (ie. is attached to a sensitive detector)
Definition: Volumes.cpp:749