From 543af0e026ab456771a2841fdc1051a3268d9c62 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Fri, 18 Nov 2022 19:34:53 +0100 Subject: [PATCH 1/5] Check Geant4 voxelisation --- .../Application/interface/RunManagerMT.h | 4 ++ SimG4Core/Application/python/g4SimHits_cfi.py | 4 ++ SimG4Core/Application/src/RunManagerMT.cc | 60 +++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/SimG4Core/Application/interface/RunManagerMT.h b/SimG4Core/Application/interface/RunManagerMT.h index c07d6121e994b..3c77481355473 100644 --- a/SimG4Core/Application/interface/RunManagerMT.h +++ b/SimG4Core/Application/interface/RunManagerMT.h @@ -80,6 +80,10 @@ class RunManagerMT { private: void terminateRun(); + void checkVoxels(); + + void setupVoxels(); + G4MTRunManagerKernel* m_kernel; CustomUIsession* m_UIsession; diff --git a/SimG4Core/Application/python/g4SimHits_cfi.py b/SimG4Core/Application/python/g4SimHits_cfi.py index ded467d761428..17bbfdf2d8e5e 100644 --- a/SimG4Core/Application/python/g4SimHits_cfi.py +++ b/SimG4Core/Application/python/g4SimHits_cfi.py @@ -90,6 +90,10 @@ UseParametrisedEMPhysics = cms.untracked.bool(True), ThresholdForGeometryExceptions = cms.double(0.1), ## in GeV TraceExceptions = cms.bool(False), + DefaultVoxelDensity = cms.double(2.0), + NumberOfVoxelRegions = cms.int32(0), + VoxelRegions = cms.vstring(), + VoxelDensityPerRegion = cms.vdouble(), CheckGeometry = cms.untracked.bool(False), OnlySDs = cms.vstring('ZdcSensitiveDetector', 'TotemT2ScintSensitiveDetector', 'TotemSensitiveDetector', 'RomanPotSensitiveDetector', 'PLTSensitiveDetector', 'MuonSensitiveDetector', 'MtdSensitiveDetector', 'BCM1FSensitiveDetector', 'EcalSensitiveDetector', 'CTPPSSensitiveDetector', 'BSCSensitiveDetector', 'CTPPSDiamondSensitiveDetector', 'FP420SensitiveDetector', 'BHMSensitiveDetector', 'CastorSensitiveDetector', 'CaloTrkProcessing', 'HcalSensitiveDetector', 'TkAccumulatingSensitiveDetector'), G4CheckOverlap = cms.untracked.PSet( diff --git a/SimG4Core/Application/src/RunManagerMT.cc b/SimG4Core/Application/src/RunManagerMT.cc index 222a88b2988a7..3380e2b1a7951 100644 --- a/SimG4Core/Application/src/RunManagerMT.cc +++ b/SimG4Core/Application/src/RunManagerMT.cc @@ -202,6 +202,8 @@ void RunManagerMT::initG4(const DDCompactView* pDD, } } + setupVoxels(); + m_stateManager->SetNewState(G4State_Init); edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMT: G4State is Init"; m_kernel->InitializePhysics(); @@ -216,6 +218,8 @@ void RunManagerMT::initG4(const DDCompactView* pDD, throw cms::Exception("LogicError") << "G4RunManagerKernel initialization failed!"; } + if (m_check) { checkVoxels(); } + if (m_StorePhysicsTables) { std::ostringstream dir; dir << m_PhysicsTablesDir << '\0'; @@ -301,3 +305,59 @@ void RunManagerMT::terminateRun() { m_runTerminated = true; edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMT::terminateRun done"; } + +void RunManagerMT::checkVoxels() { + const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance(); + int numLV = lvs->size(); + edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMT: nLV=" << numLV; + int nvox = 0; + int nslice = 0; + for(int i=0; iGetNoDaughters(); + auto vox = lv->GetVoxelHeader(); + auto sma = lv->GetSmartless(); + auto reg = lv->GetRegion(); + size_t nsl = (nullptr == vox) ? 0 : vox->GetNoSlices(); + if(0 < nsl) { + nslice += nsl; + std::string rname = (nullptr != reg) ? reg->GetName() : ""; + edm::LogVerbatim("Voxels") + << " " << i << ". Nd=" << nd << " Nsl=" << nsl + << " Smartless=" << sma << " " << lv->GetName() + << " Region: " << rname; + ++nvox; + } + } + edm::LogVerbatim("SimG4CoreApplication") + << "RunManagerMT: nLV=" << numLV << " NlvVox=" << nvox + << " Nslices=" << nslice; +} + +void RunManagerMT::setupVoxels() { + double density = m_p.getParameter("DefaultVoxelDensity"); + std::vector rnames = + m_p.getParameter >("VoxelRegions"); + std::vector rdensities = + m_p.getParameter >("VoxelDensityPerRegions"); + int nr = 0; + std::size_t n = rnames.size(); + if(n == rdensities.size()) { nr = (int)n; } + const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance(); + for(auto & lv : *lvs) { + double den = density; + if(0 < nr) { + std::string nam = lv->GetRegion()->GetName(); + for(int i=0; iSetSmartless(den); + } + edm::LogVerbatim("SimG4CoreApplication") + << "RunManagerMT: density=" << density << "; number of special regions " << nr; +} + From 553ee01b1cafaceb84cfa342bd54fdac1416cb14 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Fri, 18 Nov 2022 19:37:11 +0100 Subject: [PATCH 2/5] code format --- SimG4Core/Application/src/RunManagerMT.cc | 46 +++++++++++------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/SimG4Core/Application/src/RunManagerMT.cc b/SimG4Core/Application/src/RunManagerMT.cc index 3380e2b1a7951..0be6d17164c59 100644 --- a/SimG4Core/Application/src/RunManagerMT.cc +++ b/SimG4Core/Application/src/RunManagerMT.cc @@ -218,7 +218,9 @@ void RunManagerMT::initG4(const DDCompactView* pDD, throw cms::Exception("LogicError") << "G4RunManagerKernel initialization failed!"; } - if (m_check) { checkVoxels(); } + if (m_check) { + checkVoxels(); + } if (m_StorePhysicsTables) { std::ostringstream dir; @@ -312,52 +314,48 @@ void RunManagerMT::checkVoxels() { edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMT: nLV=" << numLV; int nvox = 0; int nslice = 0; - for(int i=0; iGetNoDaughters(); auto vox = lv->GetVoxelHeader(); auto sma = lv->GetSmartless(); auto reg = lv->GetRegion(); size_t nsl = (nullptr == vox) ? 0 : vox->GetNoSlices(); - if(0 < nsl) { + if (0 < nsl) { nslice += nsl; std::string rname = (nullptr != reg) ? reg->GetName() : ""; - edm::LogVerbatim("Voxels") - << " " << i << ". Nd=" << nd << " Nsl=" << nsl - << " Smartless=" << sma << " " << lv->GetName() - << " Region: " << rname; + edm::LogVerbatim("Voxels") << " " << i << ". Nd=" << nd << " Nsl=" << nsl << " Smartless=" << sma << " " + << lv->GetName() << " Region: " << rname; ++nvox; } } - edm::LogVerbatim("SimG4CoreApplication") - << "RunManagerMT: nLV=" << numLV << " NlvVox=" << nvox - << " Nslices=" << nslice; + edm::LogVerbatim("SimG4CoreApplication") + << "RunManagerMT: nLV=" << numLV << " NlvVox=" << nvox << " Nslices=" << nslice; } void RunManagerMT::setupVoxels() { double density = m_p.getParameter("DefaultVoxelDensity"); - std::vector rnames = - m_p.getParameter >("VoxelRegions"); - std::vector rdensities = - m_p.getParameter >("VoxelDensityPerRegions"); + std::vector rnames = m_p.getParameter >("VoxelRegions"); + std::vector rdensities = m_p.getParameter >("VoxelDensityPerRegions"); int nr = 0; std::size_t n = rnames.size(); - if(n == rdensities.size()) { nr = (int)n; } + if (n == rdensities.size()) { + nr = (int)n; + } const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance(); - for(auto & lv : *lvs) { + for (auto& lv : *lvs) { double den = density; - if(0 < nr) { + if (0 < nr) { std::string nam = lv->GetRegion()->GetName(); - for(int i=0; iSetSmartless(den); } edm::LogVerbatim("SimG4CoreApplication") - << "RunManagerMT: density=" << density << "; number of special regions " << nr; + << "RunManagerMT: density=" << density << "; number of special regions " << nr; } - From 605c04f1d8a85975bf0ae9a7d531f2c26bcbeacf Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sat, 19 Nov 2022 05:07:39 +0100 Subject: [PATCH 3/5] improved printout --- SimG4Core/Application/src/RunManagerMT.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SimG4Core/Application/src/RunManagerMT.cc b/SimG4Core/Application/src/RunManagerMT.cc index 0be6d17164c59..bee56ed245d86 100644 --- a/SimG4Core/Application/src/RunManagerMT.cc +++ b/SimG4Core/Application/src/RunManagerMT.cc @@ -357,5 +357,5 @@ void RunManagerMT::setupVoxels() { lv->SetSmartless(den); } edm::LogVerbatim("SimG4CoreApplication") - << "RunManagerMT: density=" << density << "; number of special regions " << nr; + << "RunManagerMT: default voxel density=" << density << "; number of regions with special density " << nr; } From 07e50c728e6a060e2af9ed2833bc408653295fc2 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sat, 19 Nov 2022 20:21:48 +0100 Subject: [PATCH 4/5] fixed typo --- SimG4Core/Application/src/RunManagerMT.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SimG4Core/Application/src/RunManagerMT.cc b/SimG4Core/Application/src/RunManagerMT.cc index bee56ed245d86..e50745c900dce 100644 --- a/SimG4Core/Application/src/RunManagerMT.cc +++ b/SimG4Core/Application/src/RunManagerMT.cc @@ -334,7 +334,7 @@ void RunManagerMT::checkVoxels() { } void RunManagerMT::setupVoxels() { - double density = m_p.getParameter("DefaultVoxelDensity"); + double density = m_p.getParameter("DefaultVoxelDensity"); std::vector rnames = m_p.getParameter >("VoxelRegions"); std::vector rdensities = m_p.getParameter >("VoxelDensityPerRegions"); int nr = 0; From 841fbf245be4ae149969e2482ab25fd8497a7b94 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sun, 20 Nov 2022 14:47:29 +0100 Subject: [PATCH 5/5] fixed typo --- SimG4Core/Application/python/g4SimHits_cfi.py | 1 - SimG4Core/Application/src/RunManagerMT.cc | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/SimG4Core/Application/python/g4SimHits_cfi.py b/SimG4Core/Application/python/g4SimHits_cfi.py index 17bbfdf2d8e5e..3a8ede10cf298 100644 --- a/SimG4Core/Application/python/g4SimHits_cfi.py +++ b/SimG4Core/Application/python/g4SimHits_cfi.py @@ -91,7 +91,6 @@ ThresholdForGeometryExceptions = cms.double(0.1), ## in GeV TraceExceptions = cms.bool(False), DefaultVoxelDensity = cms.double(2.0), - NumberOfVoxelRegions = cms.int32(0), VoxelRegions = cms.vstring(), VoxelDensityPerRegion = cms.vdouble(), CheckGeometry = cms.untracked.bool(False), diff --git a/SimG4Core/Application/src/RunManagerMT.cc b/SimG4Core/Application/src/RunManagerMT.cc index e50745c900dce..d1b779c4f56e9 100644 --- a/SimG4Core/Application/src/RunManagerMT.cc +++ b/SimG4Core/Application/src/RunManagerMT.cc @@ -336,7 +336,7 @@ void RunManagerMT::checkVoxels() { void RunManagerMT::setupVoxels() { double density = m_p.getParameter("DefaultVoxelDensity"); std::vector rnames = m_p.getParameter >("VoxelRegions"); - std::vector rdensities = m_p.getParameter >("VoxelDensityPerRegions"); + std::vector rdensities = m_p.getParameter >("VoxelDensityPerRegion"); int nr = 0; std::size_t n = rnames.size(); if (n == rdensities.size()) {