Skip to content

Commit 8445e80

Browse files
authored
Merge pull request cms-sw#31996 from bsunanda/Run3-gex31
Run3-gex31 Identify fine detector in CaloSD and refine EcalDumpGeometry
2 parents 51de474 + 1ba2111 commit 8445e80

File tree

7 files changed

+96
-14
lines changed

7 files changed

+96
-14
lines changed

SimG4CMS/Calo/interface/CaloSD.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class CaloSD : public SensitiveCaloDetector,
6767
void fillHits(edm::PCaloHitContainer&, const std::string&) override;
6868
void reset() override;
6969

70+
bool isItFineCalo(const G4VTouchable* touch);
71+
7072
protected:
7173
virtual double getEnergyDeposit(const G4Step* step);
7274
virtual double EnergyCorrected(const G4Step& step, const G4Track*);
@@ -142,6 +144,13 @@ class CaloSD : public SensitiveCaloDetector,
142144
bool forceSave;
143145

144146
private:
147+
struct Detector {
148+
Detector() {}
149+
std::string name;
150+
G4LogicalVolume* lv;
151+
int level;
152+
};
153+
145154
const SimTrackManager* m_trackManager;
146155

147156
std::unique_ptr<CaloSlaveSD> slave;
@@ -170,6 +179,7 @@ class CaloSD : public SensitiveCaloDetector,
170179
std::map<CaloHitID, CaloG4Hit*> hitMap;
171180
std::map<int, TrackWithHistory*> tkMap;
172181
std::vector<std::unique_ptr<CaloG4Hit>> reusehit;
182+
std::vector<Detector> fineDetectors_;
173183
};
174184

175185
#endif // SimG4CMS_CaloSD_h

SimG4CMS/Calo/interface/EcalDumpGeometry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class EcalDumpGeometry {
2828

2929
private:
3030
void dumpTouch(G4VPhysicalVolume *pv, unsigned int leafDepth);
31+
std::string noRefl(const std::string &name);
3132

3233
EcalBarrelNumberingScheme ebNumbering_;
3334
EcalEndcapNumberingScheme eeNumbering_;

SimG4CMS/Calo/src/CaloSD.cc

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88
#include "SimG4Core/Notification/interface/TrackInformation.h"
99
#include "SimG4Core/Notification/interface/G4TrackToParticleID.h"
1010
#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"
1114

1215
#include "G4EventManager.hh"
16+
#include "G4LogicalVolumeStore.hh"
17+
#include "G4LogicalVolume.hh"
1318
#include "G4SDManager.hh"
1419
#include "G4Step.hh"
1520
#include "G4Track.hh"
@@ -101,6 +106,47 @@ CaloSD::CaloSD(const std::string& name,
101106
<< eminHitD / CLHEP::MeV << " MeV (for nonzero depths);\n Time Slice Unit "
102107
<< timeSlice << "\nIgnore TrackID Flag " << ignoreTrackID << " UseFineCaloID flag "
103108
<< 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+
}
104150
}
105151

106152
CaloSD::~CaloSD() {}
@@ -254,6 +300,26 @@ double CaloSD::EnergyCorrected(const G4Step& aStep, const G4Track*) { return aSt
254300

255301
bool CaloSD::getFromLibrary(const G4Step*) { return false; }
256302

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+
257323
void CaloSD::Initialize(G4HCofThisEvent* HCE) {
258324
totalHits = 0;
259325

SimG4CMS/Calo/src/CaloTrkProcessing.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ CaloTrkProcessing::CaloTrkProcessing(const std::string& name,
4141
<< ":" << eMinFine_ << ":" << eMinFinePhoton_ << " MeV and Flags " << putHistory_
4242
<< " (History), " << doFineCalo_ << " (Special Calorimeter)";
4343

44-
// Get pointers to HcalDDDConstant and HcalSimulationParameters
44+
// Get pointer to CaloSimulationParameters
4545
edm::ESHandle<CaloSimulationParameters> csps;
4646
es.get<HcalParametersRcd>().get(csps);
4747
if (csps.isValid()) {
@@ -148,8 +148,8 @@ CaloTrkProcessing::CaloTrkProcessing(const std::string& name,
148148
}
149149
}
150150
} else {
151-
edm::LogError("HcalSim") << "CaloTrkProcessing: Cannot find CaloSimulationParameters";
152-
throw cms::Exception("Unknown", "CaloSD") << "Cannot find CaloSimulationParameters\n";
151+
edm::LogError("CaloSim") << "CaloTrkProcessing: Cannot find CaloSimulationParameters";
152+
throw cms::Exception("Unknown", "CaloTrkProcessing") << "Cannot find CaloSimulationParameters\n";
153153
}
154154

155155
edm::LogVerbatim("CaloSim") << "CaloTrkProcessing: with " << detectors_.size() << " calorimetric volumes";

SimG4CMS/Calo/src/EcalDumpGeometry.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void EcalDumpGeometry::dumpTouch(G4VPhysicalVolume* pv, unsigned int leafDepth)
9999
double a2 = (std::abs(solid->GetTanAlpha2()) > 1.e-5) ? solid->GetTanAlpha2() : 0.0;
100100
pars.emplace_back(a2);
101101
}
102-
infoVec_.emplace_back(CaloDetInfo(id, lvname, globalpoint, pars));
102+
infoVec_.emplace_back(CaloDetInfo(id, noRefl(lvname), globalpoint, pars));
103103
}
104104
break;
105105
}
@@ -115,3 +115,12 @@ void EcalDumpGeometry::dumpTouch(G4VPhysicalVolume* pv, unsigned int leafDepth)
115115
if (leafDepth > 0)
116116
fHistory_.BackLevel();
117117
}
118+
119+
std::string EcalDumpGeometry::noRefl(const std::string& name) {
120+
if (name.find("_refl") == std::string::npos) {
121+
return name;
122+
} else {
123+
size_t n = name.size();
124+
return name.substr(0, n - 5);
125+
}
126+
}

SimG4CMS/Calo/test/python/runHGC2_cfg.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import FWCore.ParameterSet.Config as cms
2+
from Configuration.Eras.Era_Phase2C9_cff import Phase2C9
3+
4+
process = cms.Process("PROD",Phase2C9)
25

3-
process = cms.Process("PROD")
46
process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi")
57
process.load("IOMC.EventVertexGenerators.VtxSmearedGauss_cfi")
6-
process.load("Geometry.CMSCommonData.cmsExtendedGeometry2023D3XML_cfi")
8+
process.load("Configuration.Geometry.GeometryExtended2026D49_cff")
79
process.load("Geometry.TrackerNumberingBuilder.trackerNumberingGeometry_cfi")
810
process.load("Configuration.StandardSequences.MagneticField_cff")
911
process.load("Configuration.EventContent.EventContent_cff")
10-
process.load("Geometry.HcalCommonData.hcalDDConstants_cff")
11-
process.load("Geometry.HGCalCommonData.hgcalV6ParametersInitialization_cfi")
12-
process.load("Geometry.HGCalCommonData.hgcalV6NumberingInitialization_cfi")
1312
process.load('Configuration.StandardSequences.Generator_cff')
1413
process.load('Configuration.StandardSequences.SimIdeal_cff')
1514
process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
1615
from Configuration.AlCa.autoCond import autoCond
17-
process.GlobalTag.globaltag = autoCond['run2_mc']
16+
process.GlobalTag.globaltag = autoCond['phase2_realistic']
1817

1918
process.MessageLogger = cms.Service("MessageLogger",
2019
destinations = cms.untracked.vstring('cout'),

SimG4CMS/Calo/test/python/runHGC4_cfg.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
process = cms.Process("PROD",Phase2C11)
55
process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi")
66
process.load("IOMC.EventVertexGenerators.VtxSmearedGauss_cfi")
7-
process.load("Configuration.Geometry.GeometryExtended2026D62_cff")
8-
#process.load("Geometry.HGCalCommonData.testHGCalV14XML_cfi")
9-
#process.load("Geometry.HGCalCommonData.hgcalParametersInitialization_cfi")
10-
#process.load("Geometry.HGCalCommonData.hgcalNumberingInitialization_cfi")
7+
process.load("Configuration.Geometry.GeometryExtended2026D71_cff")
118
process.load("Configuration.StandardSequences.MagneticField_cff")
129
process.load("Configuration.EventContent.EventContent_cff")
1310
process.load('Configuration.StandardSequences.Generator_cff')

0 commit comments

Comments
 (0)