CMS 3D CMS Logo

DD4hep_DDG4Builder.cc
Go to the documentation of this file.
2 
5 
8 #include <DDG4/Geant4Converter.h>
9 #include <DDG4/Geant4GeometryInfo.h>
10 #include <DDG4/Geant4Mapping.h>
11 #include <DD4hep/Detector.h>
12 #include <DD4hep/Filter.h>
13 
14 #include "G4LogicalVolume.hh"
15 #include "G4LogicalVolumeStore.hh"
16 #include "G4ReflectionFactory.hh"
17 
19 
20 #include <algorithm>
21 
22 using namespace cms;
23 using namespace dd4hep;
24 using namespace dd4hep::sim;
25 
26 DDG4Builder::DDG4Builder(const cms::DDCompactView *cpv, dd4hep::sim::Geant4GeometryMaps::VolumeMap &lvmap, bool check)
27  : compactView_(cpv), map_(lvmap), check_(check) {}
28 
30  G4ReflectionFactory *refFact = G4ReflectionFactory::Instance();
31  refFact->SetScalePrecision(100. * refFact->GetScalePrecision());
32 
33  const cms::DDDetector *det = compactView_->detector();
34  DetElement world = det->description()->world();
35  const Detector &detector = *det->description();
36 
37  // GET FULL G4 GEOMETRY
38  Geant4Converter g4Geo(detector);
39  g4Geo.debugMaterials = false;
40  Geant4GeometryInfo *geometry = g4Geo.create(world).detach();
41  map_ = geometry->g4Volumes;
42 
43  // FIND & STORE ALL G4 LOGICAL VOLUMES DEFINED AS SENSITIVE IN CMSSW XMLS
44  std::vector<std::pair<G4LogicalVolume *, const dd4hep::SpecPar *>> dd4hepVec;
45  const dd4hep::SpecParRegistry &specPars = det->specpars();
46  dd4hep::SpecParRefs specs;
47  specPars.filter(specs, "SensitiveDetector");
48  for (auto const &it : map_) {
49  for (auto const &fit : specs) {
50  for (auto const &pit : fit.second->paths) {
51  if (dd4hep::dd::compareEqualName(dd4hep::dd::realTopName(pit), dd4hep::dd::noNamespace(it.first.name()))) {
52  dd4hepVec.emplace_back(&*it.second, &*fit.second);
53  }
54  }
55  }
56  }
57 
58  // ADD ALL SELECTED G4 LOGICAL VOLUMES TO SENSITIVE DETECTORS CATALOGUE
59  for (auto const &it : dd4hepVec) {
60  // Sensitive detector info
61  const G4String &sensitiveDetectorG4Name = it.first->GetName();
62  auto sClassName = it.second->strValue("SensitiveDetector");
63  auto sROUName = it.second->strValue("ReadOutName");
64  // Add to catalogue
65  catalog.insert({sClassName.data(), sClassName.size()}, {sROUName.data(), sROUName.size()}, sensitiveDetectorG4Name);
66 
67  edm::LogVerbatim("SimG4CoreApplication") << " DDG4SensitiveConverter: Sensitive " << sensitiveDetectorG4Name
68  << " Class Name " << sClassName << " ROU Name " << sROUName;
69 
70  // Reflected sensors also need to be added to the senstive detectors catalogue!
71  // Similar treatment here with DD4hep, as what was done for old DD.
72  const G4String &sensitiveDetectorG4ReflectedName = sensitiveDetectorG4Name + "_refl";
73 
74  const G4LogicalVolumeStore *const allG4LogicalVolumes = G4LogicalVolumeStore::GetInstance();
75  const bool hasG4ReflectedVolume =
76  std::find_if(
77  allG4LogicalVolumes->begin(), allG4LogicalVolumes->end(), [&](G4LogicalVolume *const aG4LogicalVolume) {
78  return (aG4LogicalVolume->GetName() == sensitiveDetectorG4ReflectedName);
79  }) != allG4LogicalVolumes->end();
80  if (hasG4ReflectedVolume) {
81  // Add reflected sensitive detector to catalogue
82  catalog.insert(
83  {sClassName.data(), sClassName.size()}, {sROUName.data(), sROUName.size()}, sensitiveDetectorG4ReflectedName);
84 
85  edm::LogVerbatim("SimG4CoreApplication")
86  << " DDG4SensitiveConverter: Sensitive " << sensitiveDetectorG4ReflectedName << " Class Name " << sClassName
87  << " ROU Name " << sROUName;
88  }
89  }
90 
91  return geometry->world();
92 }
cms::DDDetector::specpars
dd4hep::SpecParRegistry const & specpars() const
Definition: DDDetector.h:21
MessageLogger.h
cms::DDG4Builder::compactView_
const cms::DDCompactView * compactView_
Definition: DD4hep_DDG4Builder.h:29
getEcalConditions_orcoffint2r_cff.catalog
catalog
Definition: getEcalConditions_orcoffint2r_cff.py:40
cms::DDG4Builder::DDG4Builder
DDG4Builder(const cms::DDCompactView *, dd4hep::sim::Geant4GeometryMaps::VolumeMap &, bool check)
Definition: DD4hep_DDG4Builder.cc:26
geometry
Definition: geometry.py:1
HistogramManager_cfi.specs
specs
Definition: HistogramManager_cfi.py:80
DDDetector.h
cms::DDDetector::description
dd4hep::Detector const * description() const
Definition: DDDetector.h:35
RPCNoise_example.check
check
Definition: RPCNoise_example.py:71
cms::DDG4Builder::BuildGeometry
G4VPhysicalVolume * BuildGeometry(SensitiveDetectorCatalog &)
Definition: DD4hep_DDG4Builder.cc:29
SensitiveDetectorCatalog
Definition: SensitiveDetectorCatalog.h:10
DDCompactView.h
particleFlowSimParticle_cfi.sim
sim
Definition: particleFlowSimParticle_cfi.py:21
DD4hep_DDG4Builder.h
SensitiveDetectorCatalog.h
align::Detector
Definition: StructureType.h:86
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
dd4hep
Definition: DDPlugins.h:8
cms::DDDetector
Definition: DDDetector.h:12
cms::DDCompactView
Definition: DDCompactView.h:31
Exception.h
hgcalTestNeighbor_cfi.detector
detector
Definition: hgcalTestNeighbor_cfi.py:6
cms::DDG4Builder::map_
dd4hep::sim::Geant4GeometryMaps::VolumeMap & map_
Definition: DD4hep_DDG4Builder.h:30
cms::DDCompactView::detector
const cms::DDDetector * detector() const
Definition: DDCompactView.h:34
fit
Definition: CombinedChiSquaredLikelihood.h:6
cms
Namespace of DDCMS conversion namespace.
Definition: ProducerAnalyzer.cc:21