CMS 3D CMS Logo

DD4hep_DDG4Builder.cc
Go to the documentation of this file.
2 
5 
9 #include "DDG4/Geant4Converter.h"
10 #include "DDG4/Geant4GeometryInfo.h"
11 #include "DDG4/Geant4Mapping.h"
12 #include "DD4hep/Detector.h"
13 
14 #include "G4LogicalVolume.hh"
15 #include "G4ReflectionFactory.hh"
16 
18 
19 using namespace cms;
20 using namespace dd4hep;
21 using namespace dd4hep::sim;
22 
23 DDG4Builder::DDG4Builder(const cms::DDCompactView *cpv, dd4hep::sim::Geant4GeometryMaps::VolumeMap &lvmap, bool check)
24  : compactView_(cpv), map_(lvmap), check_(check) {}
25 
27  G4ReflectionFactory *refFact = G4ReflectionFactory::Instance();
28  refFact->SetScalePrecision(100. * refFact->GetScalePrecision());
29 
30  const cms::DDDetector *det = compactView_->detector();
31 
32  DetElement world = det->description()->world();
33  const Detector &detector = *det->description();
34  Geant4Converter g4Geo(detector);
35  Geant4GeometryInfo *geometry = g4Geo.create(world).detach();
36  map_ = geometry->g4Volumes;
37 
38  std::vector<std::pair<G4LogicalVolume *, const cms::DDSpecPar *>> dd4hepVec;
39  const cms::DDSpecParRegistry &specPars = det->specpars();
41  specPars.filter(specs, "SensitiveDetector");
42  for (auto const &it : map_) {
43  for (auto const &fit : specs) {
44  for (auto const &pit : fit->paths) {
46  dd4hepVec.emplace_back(&*it.second, &*fit);
47  }
48  }
49  }
50  }
51 
52  for (auto const &it : dd4hepVec) {
53  auto sClassName = it.second->strValue("SensitiveDetector");
54  auto sROUName = it.second->strValue("ReadOutName");
55  auto fff = it.first->GetName();
56  catalog.insert({sClassName.data(), sClassName.size()}, {sROUName.data(), sROUName.size()}, fff);
57 
58  edm::LogVerbatim("SimG4CoreApplication")
59  << " DDG4SensitiveConverter: Sensitive " << fff << " Class Name " << sClassName << " ROU Name " << sROUName;
60  }
61 
62  return geometry->world();
63 }
std::string_view realTopName(std::string_view)
DDSpecParRegistry const & specpars() const
Definition: DDDetector.h:26
void filter(DDSpecParRefs &, std::string_view, std::string_view) const
std::string_view noNamespace(std::string_view)
Definition: Filter.cc:61
void insert(const std::string &, const std::string &, const std::string &)
dd4hep::sim::Geant4GeometryMaps::VolumeMap & map_
DDG4Builder(const cms::DDCompactView *, dd4hep::sim::Geant4GeometryMaps::VolumeMap &, bool check)
G4VPhysicalVolume * BuildGeometry(SensitiveDetectorCatalog &)
Namespace of DDCMS conversion namespace.
bool compareEqual(std::string_view, std::string_view)
std::vector< const DDSpecPar * > DDSpecParRefs
const cms::DDCompactView * compactView_
Detector const * description() const
Definition: DDDetector.h:46
const cms::DDDetector * detector() const
Definition: DDCompactView.h:32