CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
cms::DDG4Builder Class Reference

#include <DD4hep_DDG4Builder.h>

Public Member Functions

G4VPhysicalVolume * BuildGeometry (SensitiveDetectorCatalog &)
 
 DDG4Builder (const cms::DDCompactView *, dd4hep::sim::Geant4GeometryMaps::VolumeMap &, bool check)
 

Private Attributes

bool check_
 
const cms::DDCompactViewcompactView_
 
dd4hep::sim::Geant4GeometryMaps::VolumeMap & map_
 

Detailed Description

Definition at line 23 of file DD4hep_DDG4Builder.h.

Constructor & Destructor Documentation

◆ DDG4Builder()

DDG4Builder::DDG4Builder ( const cms::DDCompactView cpv,
dd4hep::sim::Geant4GeometryMaps::VolumeMap &  lvmap,
bool  check 
)

Definition at line 26 of file DD4hep_DDG4Builder.cc.

27  : compactView_(cpv), map_(lvmap), check_(check) {}
dd4hep::sim::Geant4GeometryMaps::VolumeMap & map_
const cms::DDCompactView * compactView_

Member Function Documentation

◆ BuildGeometry()

G4VPhysicalVolume * DDG4Builder::BuildGeometry ( SensitiveDetectorCatalog catalog)

Definition at line 29 of file DD4hep_DDG4Builder.cc.

References getEcalConditions_orcoffint2r_cff::catalog, compactView_, cms::DDDetector::description(), hgcalTestNeighbor_cfi::detector, cms::DDCompactView::detector(), align::Detector, map_, cms::DDDetector::specpars(), and HistogramManager_cfi::specs.

Referenced by DDDWorld::DDDWorld().

29  {
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  bool foundMatch = false; // Stop search at first occurrence
50  for (auto const &fit : specs) {
51  for (auto const &pit : fit.second->paths) {
52  if (dd4hep::dd::compareEqualName(dd4hep::dd::noNamespace(dd4hep::dd::realTopName(pit)),
53  dd4hep::dd::noNamespace(it.first.name()))) {
54  dd4hepVec.emplace_back(&*it.second, &*fit.second);
55 
56  foundMatch = true;
57  break;
58  }
59  }
60  if (foundMatch)
61  break;
62  }
63  }
64 
65  // ADD ALL SELECTED G4 LOGICAL VOLUMES TO SENSITIVE DETECTORS CATALOGUE
66  for (auto const &it : dd4hepVec) {
67  // Sensitive detector info
68  const G4String &sensitiveDetectorG4Name = it.first->GetName();
69  auto sClassName = it.second->strValue("SensitiveDetector");
70  auto sROUName = it.second->strValue("ReadOutName");
71  // Add to catalogue
72  catalog.insert({sClassName.data(), sClassName.size()}, {sROUName.data(), sROUName.size()}, sensitiveDetectorG4Name);
73 
74  edm::LogVerbatim("SimG4CoreApplication") << " DDG4SensitiveConverter: Sensitive " << sensitiveDetectorG4Name
75  << " Class Name " << sClassName << " ROU Name " << sROUName;
76 
77  // Reflected sensors also need to be added to the senstive detectors catalogue!
78  // Similar treatment here with DD4hep, as what was done for old DD.
79  const G4String &sensitiveDetectorG4ReflectedName = sensitiveDetectorG4Name + "_refl";
80 
81  const G4LogicalVolumeStore *const allG4LogicalVolumes = G4LogicalVolumeStore::GetInstance();
82  const bool hasG4ReflectedVolume =
83  std::find_if(
84  allG4LogicalVolumes->begin(), allG4LogicalVolumes->end(), [&](G4LogicalVolume *const aG4LogicalVolume) {
85  return (aG4LogicalVolume->GetName() == sensitiveDetectorG4ReflectedName);
86  }) != allG4LogicalVolumes->end();
87  if (hasG4ReflectedVolume) {
88  // Add reflected sensitive detector to catalogue
89  catalog.insert(
90  {sClassName.data(), sClassName.size()}, {sROUName.data(), sROUName.size()}, sensitiveDetectorG4ReflectedName);
91 
92  edm::LogVerbatim("SimG4CoreApplication")
93  << " DDG4SensitiveConverter: Sensitive " << sensitiveDetectorG4ReflectedName << " Class Name " << sClassName
94  << " ROU Name " << sROUName;
95  }
96  }
97 
98  return geometry->world();
99 }
Log< level::Info, true > LogVerbatim
dd4hep::Detector const * description() const
Definition: DDDetector.h:35
const cms::DDDetector * detector() const
Definition: DDCompactView.h:34
dd4hep::sim::Geant4GeometryMaps::VolumeMap & map_
const cms::DDCompactView * compactView_
dd4hep::SpecParRegistry const & specpars() const
Definition: DDDetector.h:21

Member Data Documentation

◆ check_

bool cms::DDG4Builder::check_
private

Definition at line 31 of file DD4hep_DDG4Builder.h.

◆ compactView_

const cms::DDCompactView* cms::DDG4Builder::compactView_
private

Definition at line 29 of file DD4hep_DDG4Builder.h.

Referenced by BuildGeometry().

◆ map_

dd4hep::sim::Geant4GeometryMaps::VolumeMap& cms::DDG4Builder::map_
private

Definition at line 30 of file DD4hep_DDG4Builder.h.

Referenced by BuildGeometry().