File indexing completed on 2025-01-30 09:17:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/Shapes.h>
0016 #include <DD4hep/Printout.h>
0017 #include <DD4hep/SurfaceInstaller.h>
0018
0019
0020 #include <TClass.h>
0021
0022 using namespace dd4hep;
0023
0024 typedef DetElement::Children _C;
0025
0026
0027 SurfaceInstaller::SurfaceInstaller(Detector& description, int argc, char** argv)
0028 : m_detDesc(description), m_det(), m_stopScanning(false)
0029 {
0030 if ( argc > 0 ) {
0031 std::string det_name = argv[0];
0032 std::string n = det_name[0] == '-' ? det_name.substr(1) : det_name;
0033 m_det = description.detector(n);
0034 if ( !m_det.isValid() ) {
0035 std::stringstream err;
0036 err << "The subdetector " << det_name << " is not known to the geometry.";
0037 printout(INFO,"SurfaceInstaller",err.str().c_str());
0038 except(det_name, err.str());
0039 }
0040 printout(INFO,m_det.name(), "+++ Processing SurfaceInstaller for subdetector: '%s'",m_det.name());
0041 return;
0042 }
0043 except("SurfaceInstaller", "The plugin takes at least one argument. No argument supplied");
0044 }
0045
0046
0047 void SurfaceInstaller::invalidInstaller(const std::string& msg) const {
0048 const char* det = m_det.isValid() ? m_det.name() : "<UNKNOWN>";
0049 std::string typ = m_det.isValid() ? m_det.type() : std::string("<UNKNOWN>");
0050 printout(FATAL,"SurfaceInstaller","+++ Surfaces for: %s",det);
0051 printout(FATAL,"SurfaceInstaller","+++ %s.",msg.c_str());
0052 printout(FATAL,"SurfaceInstaller","+++ You sure you apply the correct plugin to generate");
0053 printout(FATAL,"SurfaceInstaller","+++ surfaces for a detector of type %s",typ.c_str());
0054 except("SurfaceInstaller", "+++ Failed to install Surfaces to detector "+std::string(det));
0055 }
0056
0057
0058 Volume SurfaceInstaller::parentVolume(DetElement component) const {
0059 DetElement module = component.parent();
0060 if ( module.isValid() ) {
0061 return module.placement().volume();
0062 }
0063 return Volume();
0064 }
0065
0066
0067 const double* SurfaceInstaller::placementTranslation(DetElement component) const {
0068 TGeoMatrix* mat = component.placement()->GetMatrix();
0069 const double* trans = mat->GetTranslation();
0070 return trans;
0071 }
0072
0073
0074 void SurfaceInstaller::install(DetElement component, PlacedVolume pv) {
0075 if ( pv.volume().isSensitive() ) {
0076 std::stringstream log;
0077 PlacementPath all_nodes;
0078 ElementPath det_elts;
0079 detail::tools::elementPath(component,det_elts);
0080 detail::tools::placementPath(component,all_nodes);
0081 std::string elt_path = detail::tools::elementPath(det_elts);
0082 std::string node_path = detail::tools::placementPath(all_nodes);
0083
0084 log << "Lookup " << " Detector[" << det_elts.size() << "]: " << elt_path;
0085 printout(INFO,m_det.name(), log.str());
0086 log.str("");
0087 log << " " << " Places[" << all_nodes.size() << "]: " << node_path;
0088 printout(INFO,m_det.name(), log.str());
0089 log.str("");
0090 log << " " << " detail::matrix[" << all_nodes.size() << "]: ";
0091 for(PlacementPath::const_reverse_iterator i=all_nodes.rbegin(); i!=all_nodes.rend(); ++i) {
0092 PlacedVolume placed = *i;
0093 log << (void*)(placed->GetMatrix()) << " ";
0094 if ( placed->GetUserExtension() ) {
0095 const PlacedVolume::VolIDs& vid = placed.volIDs();
0096 for(PlacedVolume::VolIDs::const_iterator j=vid.begin(); j!=vid.end(); ++j) {
0097 log << (*j).first << ":" << (*j).second << " ";
0098 }
0099 }
0100 log << " ";
0101 if ( i+1 == all_nodes.rend() ) log << "( -> " << placed->GetName() << ")";
0102 }
0103
0104 printout(INFO,m_det.name(),log.str());
0105 log.str("");
0106 Volume vol = pv.volume();
0107 log << " "
0108 << " Sensitive: " << (vol.isSensitive() ? "YES" : "NO ")
0109 << " Volume: " << (void*)vol.ptr() << " "
0110 << " Shape: " << vol.solid().toString();
0111 printout(INFO,m_det.name(),log.str());
0112 return;
0113 }
0114 std::cout << component.name() << ": " << pv.name() << std::endl;
0115 }
0116
0117
0118 void SurfaceInstaller::scan(DetElement e) {
0119 const _C& children = e.children();
0120 install(e,e.placement());
0121 for (_C::const_iterator i=children.begin(); !m_stopScanning && i!=children.end(); ++i)
0122 scan((*i).second);
0123 }
0124
0125
0126 void SurfaceInstaller::scan() {
0127 scan(m_det);
0128 }
0129