From d86f808759e8ec7cd3d1aca625c54c51b3a84baa Mon Sep 17 00:00:00 2001 From: Sunanda Date: Fri, 30 Oct 2020 17:40:05 +0100 Subject: [PATCH 1/3] Identify fine detector in CaloSD and refine EcalDumpGeometry --- SimG4CMS/Calo/interface/CaloSD.h | 9 ++++ SimG4CMS/Calo/interface/EcalDumpGeometry.h | 1 + SimG4CMS/Calo/src/CaloSD.cc | 63 ++++++++++++++++++++++ SimG4CMS/Calo/src/CaloTrkProcessing.cc | 6 +-- SimG4CMS/Calo/src/EcalDumpGeometry.cc | 11 +++- SimG4CMS/Calo/test/python/runHGC2_cfg.py | 11 ++-- SimG4CMS/Calo/test/python/runHGC4_cfg.py | 5 +- 7 files changed, 92 insertions(+), 14 deletions(-) diff --git a/SimG4CMS/Calo/interface/CaloSD.h b/SimG4CMS/Calo/interface/CaloSD.h index d1f6d2c5acd1d..da8c0d56f8dc5 100644 --- a/SimG4CMS/Calo/interface/CaloSD.h +++ b/SimG4CMS/Calo/interface/CaloSD.h @@ -113,6 +113,7 @@ class CaloSD : public SensitiveCaloDetector, inline void setNumberCheckedHits(int val) { nCheckedHits = val; } + bool isItFineCalo(const G4VTouchable* touch); private: void storeHit(CaloG4Hit*); bool saveHit(CaloG4Hit*); @@ -142,6 +143,13 @@ class CaloSD : public SensitiveCaloDetector, bool forceSave; private: + struct Detector { + Detector() {} + std::string name; + G4LogicalVolume* lv; + int level; + }; + const SimTrackManager* m_trackManager; std::unique_ptr slave; @@ -170,6 +178,7 @@ class CaloSD : public SensitiveCaloDetector, std::map hitMap; std::map tkMap; std::vector> reusehit; + std::vector fineDetectors_; }; #endif // SimG4CMS_CaloSD_h diff --git a/SimG4CMS/Calo/interface/EcalDumpGeometry.h b/SimG4CMS/Calo/interface/EcalDumpGeometry.h index 658dc9721037a..d0e778ee12248 100644 --- a/SimG4CMS/Calo/interface/EcalDumpGeometry.h +++ b/SimG4CMS/Calo/interface/EcalDumpGeometry.h @@ -28,6 +28,7 @@ class EcalDumpGeometry { private: void dumpTouch(G4VPhysicalVolume *pv, unsigned int leafDepth); + std::string noRefl(const std::string& name); EcalBarrelNumberingScheme ebNumbering_; EcalEndcapNumberingScheme eeNumbering_; diff --git a/SimG4CMS/Calo/src/CaloSD.cc b/SimG4CMS/Calo/src/CaloSD.cc index c361fc56c7d75..fb655dd7f95db 100644 --- a/SimG4CMS/Calo/src/CaloSD.cc +++ b/SimG4CMS/Calo/src/CaloSD.cc @@ -8,8 +8,13 @@ #include "SimG4Core/Notification/interface/TrackInformation.h" #include "SimG4Core/Notification/interface/G4TrackToParticleID.h" #include "SimG4Core/Notification/interface/SimTrackManager.h" +#include "Geometry/Records/interface/HcalParametersRcd.h" +#include "CondFormats/GeometryObjects/interface/CaloSimulationParameters.h" +#include "FWCore/Framework/interface/ESHandle.h" #include "G4EventManager.hh" +#include "G4LogicalVolumeStore.hh" +#include "G4LogicalVolume.hh" #include "G4SDManager.hh" #include "G4Step.hh" #include "G4Track.hh" @@ -101,6 +106,46 @@ CaloSD::CaloSD(const std::string& name, << eminHitD / CLHEP::MeV << " MeV (for nonzero depths);\n Time Slice Unit " << timeSlice << "\nIgnore TrackID Flag " << ignoreTrackID << " UseFineCaloID flag " << useFineCaloID_; + + // Get pointer to CaloSimulationParameters + edm::ESHandle csps; + es.get().get(csps); + if (csps.isValid()) { + const CaloSimulationParameters* csp = csps.product(); + edm::LogVerbatim("CaloSim") << "CaloSD: " << csp->fCaloNames_.size() << " entries for fineCalorimeters:"; + for (unsigned int i = 0; i < csp->fCaloNames_.size(); i++) + edm::LogVerbatim("CaloSim") << " [" << i << "] " << csp->fCaloNames_[i] << ":" << csp->fLevels_[i]; + + const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance(); + std::vector::const_iterator lvcite; + for (unsigned int i = 0; i < csp->fCaloNames_.size(); i++) { + G4LogicalVolume* lv = nullptr; + G4String name = static_cast(csp->fCaloNames_[i]); + for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) { + if ((*lvcite)->GetName() == name) { + lv = (*lvcite); + break; + } + } + if (lv != nullptr) { + CaloSD::Detector detector; + detector.name = name; + detector.lv = lv; + detector.level = csp->fLevels_[i]; + fineDetectors_.emplace_back(detector); + } + } +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("CaloSim") << "CaloSD::Loads information for " << fineDetectors_.size() << " fine detectors"; + unsigned int k(0); + for (const auto& detector : fineDetectors_) { + edm::LogVerbatim("CaloSim") << "Detector[" << k << "] " << detector.name << " at level " << detector.level << " pointer to LV: " << detector.lv; + } +#endif + } else { + edm::LogError("CaloSim") << "CaloSD: Cannot find CaloSimulationParameters"; + throw cms::Exception("Unknown", "CaloSD") << "Cannot find CaloSimulationParameters\n"; + } } CaloSD::~CaloSD() {} @@ -254,6 +299,24 @@ double CaloSD::EnergyCorrected(const G4Step& aStep, const G4Track*) { return aSt bool CaloSD::getFromLibrary(const G4Step*) { return false; } +bool CaloSD::isItFineCalo(const G4VTouchable* touch) { + bool ok(false); + int level = ((touch->GetHistoryDepth()) + 1); + for (const auto& detector : fineDetectors_) { + if (level > 0 && level >= detector.level) { + int ii = level - detector.level; + G4LogicalVolume* lv = touch->GetVolume(ii)->GetLogicalVolume(); + ok = (lv == detector.lv); +#ifdef EDM_ML_DEBUG + std::string name = (lv == 0) ? "Unknown" : lv->GetName(); + edm::LogVerbatim("CaloSim") << "CaloSD: volume " << name1 << ":" << detector.name << " at Level " << detector.level << " Flag " << ok; +#endif + if (ok) break; + } + } + return ok; +} + void CaloSD::Initialize(G4HCofThisEvent* HCE) { totalHits = 0; diff --git a/SimG4CMS/Calo/src/CaloTrkProcessing.cc b/SimG4CMS/Calo/src/CaloTrkProcessing.cc index 75ac6603474d8..8a22f6a553883 100644 --- a/SimG4CMS/Calo/src/CaloTrkProcessing.cc +++ b/SimG4CMS/Calo/src/CaloTrkProcessing.cc @@ -41,7 +41,7 @@ CaloTrkProcessing::CaloTrkProcessing(const std::string& name, << ":" << eMinFine_ << ":" << eMinFinePhoton_ << " MeV and Flags " << putHistory_ << " (History), " << doFineCalo_ << " (Special Calorimeter)"; - // Get pointers to HcalDDDConstant and HcalSimulationParameters + // Get pointer to CaloSimulationParameters edm::ESHandle csps; es.get().get(csps); if (csps.isValid()) { @@ -148,8 +148,8 @@ CaloTrkProcessing::CaloTrkProcessing(const std::string& name, } } } else { - edm::LogError("HcalSim") << "CaloTrkProcessing: Cannot find CaloSimulationParameters"; - throw cms::Exception("Unknown", "CaloSD") << "Cannot find CaloSimulationParameters\n"; + edm::LogError("CaloSim") << "CaloTrkProcessing: Cannot find CaloSimulationParameters"; + throw cms::Exception("Unknown", "CaloTrkProcessing") << "Cannot find CaloSimulationParameters\n"; } edm::LogVerbatim("CaloSim") << "CaloTrkProcessing: with " << detectors_.size() << " calorimetric volumes"; diff --git a/SimG4CMS/Calo/src/EcalDumpGeometry.cc b/SimG4CMS/Calo/src/EcalDumpGeometry.cc index c9dc117d7e6d5..d583f4061b00f 100644 --- a/SimG4CMS/Calo/src/EcalDumpGeometry.cc +++ b/SimG4CMS/Calo/src/EcalDumpGeometry.cc @@ -99,7 +99,7 @@ void EcalDumpGeometry::dumpTouch(G4VPhysicalVolume* pv, unsigned int leafDepth) double a2 = (std::abs(solid->GetTanAlpha2()) > 1.e-5) ? solid->GetTanAlpha2() : 0.0; pars.emplace_back(a2); } - infoVec_.emplace_back(CaloDetInfo(id, lvname, globalpoint, pars)); + infoVec_.emplace_back(CaloDetInfo(id, noRefl(lvname), globalpoint, pars)); } break; } @@ -115,3 +115,12 @@ void EcalDumpGeometry::dumpTouch(G4VPhysicalVolume* pv, unsigned int leafDepth) if (leafDepth > 0) fHistory_.BackLevel(); } + +std::string EcalDumpGeometry::noRefl(const std::string & name) { + if (name.find("_refl") == std::string::npos) { + return name; + } else { + size_t n = name.size(); + return name.substr(0, n-5); + } +} diff --git a/SimG4CMS/Calo/test/python/runHGC2_cfg.py b/SimG4CMS/Calo/test/python/runHGC2_cfg.py index 7d8fa855a6f72..f77e550ffed20 100644 --- a/SimG4CMS/Calo/test/python/runHGC2_cfg.py +++ b/SimG4CMS/Calo/test/python/runHGC2_cfg.py @@ -1,20 +1,19 @@ import FWCore.ParameterSet.Config as cms +from Configuration.Eras.Era_Phase2C9_cff import Phase2C9 + +process = cms.Process("PROD",Phase2C9) -process = cms.Process("PROD") process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi") process.load("IOMC.EventVertexGenerators.VtxSmearedGauss_cfi") -process.load("Geometry.CMSCommonData.cmsExtendedGeometry2023D3XML_cfi") +process.load("Configuration.Geometry.GeometryExtended2026D49_cff") process.load("Geometry.TrackerNumberingBuilder.trackerNumberingGeometry_cfi") process.load("Configuration.StandardSequences.MagneticField_cff") process.load("Configuration.EventContent.EventContent_cff") -process.load("Geometry.HcalCommonData.hcalDDConstants_cff") -process.load("Geometry.HGCalCommonData.hgcalV6ParametersInitialization_cfi") -process.load("Geometry.HGCalCommonData.hgcalV6NumberingInitialization_cfi") process.load('Configuration.StandardSequences.Generator_cff') process.load('Configuration.StandardSequences.SimIdeal_cff') process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") from Configuration.AlCa.autoCond import autoCond -process.GlobalTag.globaltag = autoCond['run2_mc'] +process.GlobalTag.globaltag = autoCond['phase2_realistic'] process.MessageLogger = cms.Service("MessageLogger", destinations = cms.untracked.vstring('cout'), diff --git a/SimG4CMS/Calo/test/python/runHGC4_cfg.py b/SimG4CMS/Calo/test/python/runHGC4_cfg.py index 44fd0d2fa789a..dd2d88a4bfb97 100644 --- a/SimG4CMS/Calo/test/python/runHGC4_cfg.py +++ b/SimG4CMS/Calo/test/python/runHGC4_cfg.py @@ -4,10 +4,7 @@ process = cms.Process("PROD",Phase2C11) process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi") process.load("IOMC.EventVertexGenerators.VtxSmearedGauss_cfi") -process.load("Configuration.Geometry.GeometryExtended2026D62_cff") -#process.load("Geometry.HGCalCommonData.testHGCalV14XML_cfi") -#process.load("Geometry.HGCalCommonData.hgcalParametersInitialization_cfi") -#process.load("Geometry.HGCalCommonData.hgcalNumberingInitialization_cfi") +process.load("Configuration.Geometry.GeometryExtended2026D71_cff") process.load("Configuration.StandardSequences.MagneticField_cff") process.load("Configuration.EventContent.EventContent_cff") process.load('Configuration.StandardSequences.Generator_cff') From 1c107ed77d6d45dd2496ac6e3210c8dfbb1f2aee Mon Sep 17 00:00:00 2001 From: Sunanda Date: Fri, 30 Oct 2020 18:26:48 +0100 Subject: [PATCH 2/3] Code check --- SimG4CMS/Calo/interface/CaloSD.h | 1 + SimG4CMS/Calo/interface/EcalDumpGeometry.h | 2 +- SimG4CMS/Calo/src/CaloSD.cc | 9 ++++++--- SimG4CMS/Calo/src/EcalDumpGeometry.cc | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/SimG4CMS/Calo/interface/CaloSD.h b/SimG4CMS/Calo/interface/CaloSD.h index da8c0d56f8dc5..a1c0df4ea6c3d 100644 --- a/SimG4CMS/Calo/interface/CaloSD.h +++ b/SimG4CMS/Calo/interface/CaloSD.h @@ -114,6 +114,7 @@ class CaloSD : public SensitiveCaloDetector, inline void setNumberCheckedHits(int val) { nCheckedHits = val; } bool isItFineCalo(const G4VTouchable* touch); + private: void storeHit(CaloG4Hit*); bool saveHit(CaloG4Hit*); diff --git a/SimG4CMS/Calo/interface/EcalDumpGeometry.h b/SimG4CMS/Calo/interface/EcalDumpGeometry.h index d0e778ee12248..483ef7a6b8b2b 100644 --- a/SimG4CMS/Calo/interface/EcalDumpGeometry.h +++ b/SimG4CMS/Calo/interface/EcalDumpGeometry.h @@ -28,7 +28,7 @@ class EcalDumpGeometry { private: void dumpTouch(G4VPhysicalVolume *pv, unsigned int leafDepth); - std::string noRefl(const std::string& name); + std::string noRefl(const std::string &name); EcalBarrelNumberingScheme ebNumbering_; EcalEndcapNumberingScheme eeNumbering_; diff --git a/SimG4CMS/Calo/src/CaloSD.cc b/SimG4CMS/Calo/src/CaloSD.cc index fb655dd7f95db..d366f900a058f 100644 --- a/SimG4CMS/Calo/src/CaloSD.cc +++ b/SimG4CMS/Calo/src/CaloSD.cc @@ -139,7 +139,8 @@ CaloSD::CaloSD(const std::string& name, edm::LogVerbatim("CaloSim") << "CaloSD::Loads information for " << fineDetectors_.size() << " fine detectors"; unsigned int k(0); for (const auto& detector : fineDetectors_) { - edm::LogVerbatim("CaloSim") << "Detector[" << k << "] " << detector.name << " at level " << detector.level << " pointer to LV: " << detector.lv; + edm::LogVerbatim("CaloSim") << "Detector[" << k << "] " << detector.name << " at level " << detector.level + << " pointer to LV: " << detector.lv; } #endif } else { @@ -309,9 +310,11 @@ bool CaloSD::isItFineCalo(const G4VTouchable* touch) { ok = (lv == detector.lv); #ifdef EDM_ML_DEBUG std::string name = (lv == 0) ? "Unknown" : lv->GetName(); - edm::LogVerbatim("CaloSim") << "CaloSD: volume " << name1 << ":" << detector.name << " at Level " << detector.level << " Flag " << ok; + edm::LogVerbatim("CaloSim") << "CaloSD: volume " << name1 << ":" << detector.name << " at Level " + << detector.level << " Flag " << ok; #endif - if (ok) break; + if (ok) + break; } } return ok; diff --git a/SimG4CMS/Calo/src/EcalDumpGeometry.cc b/SimG4CMS/Calo/src/EcalDumpGeometry.cc index d583f4061b00f..fc934d8904920 100644 --- a/SimG4CMS/Calo/src/EcalDumpGeometry.cc +++ b/SimG4CMS/Calo/src/EcalDumpGeometry.cc @@ -116,11 +116,11 @@ void EcalDumpGeometry::dumpTouch(G4VPhysicalVolume* pv, unsigned int leafDepth) fHistory_.BackLevel(); } -std::string EcalDumpGeometry::noRefl(const std::string & name) { +std::string EcalDumpGeometry::noRefl(const std::string& name) { if (name.find("_refl") == std::string::npos) { return name; } else { size_t n = name.size(); - return name.substr(0, n-5); + return name.substr(0, n - 5); } } From 1ba21112fd1b3f7ac476bfb662d869d13ebcba7a Mon Sep 17 00:00:00 2001 From: Sunanda Date: Fri, 30 Oct 2020 19:58:58 +0100 Subject: [PATCH 3/3] Small fix --- SimG4CMS/Calo/interface/CaloSD.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SimG4CMS/Calo/interface/CaloSD.h b/SimG4CMS/Calo/interface/CaloSD.h index a1c0df4ea6c3d..b35ccb72ffd5a 100644 --- a/SimG4CMS/Calo/interface/CaloSD.h +++ b/SimG4CMS/Calo/interface/CaloSD.h @@ -67,6 +67,8 @@ class CaloSD : public SensitiveCaloDetector, void fillHits(edm::PCaloHitContainer&, const std::string&) override; void reset() override; + bool isItFineCalo(const G4VTouchable* touch); + protected: virtual double getEnergyDeposit(const G4Step* step); virtual double EnergyCorrected(const G4Step& step, const G4Track*); @@ -113,8 +115,6 @@ class CaloSD : public SensitiveCaloDetector, inline void setNumberCheckedHits(int val) { nCheckedHits = val; } - bool isItFineCalo(const G4VTouchable* touch); - private: void storeHit(CaloG4Hit*); bool saveHit(CaloG4Hit*);