|
8 | 8 | #include "SimG4Core/Notification/interface/TrackInformation.h" |
9 | 9 | #include "SimG4Core/Notification/interface/G4TrackToParticleID.h" |
10 | 10 | #include "SimG4Core/Notification/interface/SimTrackManager.h" |
| 11 | +#include "Geometry/Records/interface/HcalParametersRcd.h" |
| 12 | +#include "CondFormats/GeometryObjects/interface/CaloSimulationParameters.h" |
| 13 | +#include "FWCore/Framework/interface/ESHandle.h" |
11 | 14 |
|
12 | 15 | #include "G4EventManager.hh" |
| 16 | +#include "G4LogicalVolumeStore.hh" |
| 17 | +#include "G4LogicalVolume.hh" |
13 | 18 | #include "G4SDManager.hh" |
14 | 19 | #include "G4Step.hh" |
15 | 20 | #include "G4Track.hh" |
@@ -101,6 +106,47 @@ CaloSD::CaloSD(const std::string& name, |
101 | 106 | << eminHitD / CLHEP::MeV << " MeV (for nonzero depths);\n Time Slice Unit " |
102 | 107 | << timeSlice << "\nIgnore TrackID Flag " << ignoreTrackID << " UseFineCaloID flag " |
103 | 108 | << useFineCaloID_; |
| 109 | + |
| 110 | + // Get pointer to CaloSimulationParameters |
| 111 | + edm::ESHandle<CaloSimulationParameters> csps; |
| 112 | + es.get<HcalParametersRcd>().get(csps); |
| 113 | + if (csps.isValid()) { |
| 114 | + const CaloSimulationParameters* csp = csps.product(); |
| 115 | + edm::LogVerbatim("CaloSim") << "CaloSD: " << csp->fCaloNames_.size() << " entries for fineCalorimeters:"; |
| 116 | + for (unsigned int i = 0; i < csp->fCaloNames_.size(); i++) |
| 117 | + edm::LogVerbatim("CaloSim") << " [" << i << "] " << csp->fCaloNames_[i] << ":" << csp->fLevels_[i]; |
| 118 | + |
| 119 | + const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance(); |
| 120 | + std::vector<G4LogicalVolume*>::const_iterator lvcite; |
| 121 | + for (unsigned int i = 0; i < csp->fCaloNames_.size(); i++) { |
| 122 | + G4LogicalVolume* lv = nullptr; |
| 123 | + G4String name = static_cast<G4String>(csp->fCaloNames_[i]); |
| 124 | + for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) { |
| 125 | + if ((*lvcite)->GetName() == name) { |
| 126 | + lv = (*lvcite); |
| 127 | + break; |
| 128 | + } |
| 129 | + } |
| 130 | + if (lv != nullptr) { |
| 131 | + CaloSD::Detector detector; |
| 132 | + detector.name = name; |
| 133 | + detector.lv = lv; |
| 134 | + detector.level = csp->fLevels_[i]; |
| 135 | + fineDetectors_.emplace_back(detector); |
| 136 | + } |
| 137 | + } |
| 138 | +#ifdef EDM_ML_DEBUG |
| 139 | + edm::LogVerbatim("CaloSim") << "CaloSD::Loads information for " << fineDetectors_.size() << " fine detectors"; |
| 140 | + unsigned int k(0); |
| 141 | + for (const auto& detector : fineDetectors_) { |
| 142 | + edm::LogVerbatim("CaloSim") << "Detector[" << k << "] " << detector.name << " at level " << detector.level |
| 143 | + << " pointer to LV: " << detector.lv; |
| 144 | + } |
| 145 | +#endif |
| 146 | + } else { |
| 147 | + edm::LogError("CaloSim") << "CaloSD: Cannot find CaloSimulationParameters"; |
| 148 | + throw cms::Exception("Unknown", "CaloSD") << "Cannot find CaloSimulationParameters\n"; |
| 149 | + } |
104 | 150 | } |
105 | 151 |
|
106 | 152 | CaloSD::~CaloSD() {} |
@@ -254,6 +300,26 @@ double CaloSD::EnergyCorrected(const G4Step& aStep, const G4Track*) { return aSt |
254 | 300 |
|
255 | 301 | bool CaloSD::getFromLibrary(const G4Step*) { return false; } |
256 | 302 |
|
| 303 | +bool CaloSD::isItFineCalo(const G4VTouchable* touch) { |
| 304 | + bool ok(false); |
| 305 | + int level = ((touch->GetHistoryDepth()) + 1); |
| 306 | + for (const auto& detector : fineDetectors_) { |
| 307 | + if (level > 0 && level >= detector.level) { |
| 308 | + int ii = level - detector.level; |
| 309 | + G4LogicalVolume* lv = touch->GetVolume(ii)->GetLogicalVolume(); |
| 310 | + ok = (lv == detector.lv); |
| 311 | +#ifdef EDM_ML_DEBUG |
| 312 | + std::string name = (lv == 0) ? "Unknown" : lv->GetName(); |
| 313 | + edm::LogVerbatim("CaloSim") << "CaloSD: volume " << name1 << ":" << detector.name << " at Level " |
| 314 | + << detector.level << " Flag " << ok; |
| 315 | +#endif |
| 316 | + if (ok) |
| 317 | + break; |
| 318 | + } |
| 319 | + } |
| 320 | + return ok; |
| 321 | +} |
| 322 | + |
257 | 323 | void CaloSD::Initialize(G4HCofThisEvent* HCE) { |
258 | 324 | totalHits = 0; |
259 | 325 |
|
|
0 commit comments