From 629245f46cd5644eb4ec7a749e04d2e519360b08 Mon Sep 17 00:00:00 2001 From: Ruben Lopez Ruiz <24.lopezr@gmail.com> Date: Tue, 28 Jan 2025 10:49:15 +0100 Subject: [PATCH] Add process modifier + naming change + changes in Generator3 --- .../python/fixLongLivedSleptonSim_cff.py | 4 ++++ SimG4Core/Application/python/g4SimHits_cfi.py | 10 +++++++++- SimG4Core/Generators/interface/Generator.h | 2 +- SimG4Core/Generators/interface/Generator3.h | 1 + SimG4Core/Generators/src/Generator.cc | 6 +++--- SimG4Core/Generators/src/Generator3.cc | 12 ++++++++++-- 6 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 Configuration/ProcessModifiers/python/fixLongLivedSleptonSim_cff.py diff --git a/Configuration/ProcessModifiers/python/fixLongLivedSleptonSim_cff.py b/Configuration/ProcessModifiers/python/fixLongLivedSleptonSim_cff.py new file mode 100644 index 0000000000000..8b9358c09713b --- /dev/null +++ b/Configuration/ProcessModifiers/python/fixLongLivedSleptonSim_cff.py @@ -0,0 +1,4 @@ +import FWCore.ParameterSet.Config as cms + +# Designed to disable a bug affecting long lived slepton decays in HepMC-G4 interface +fixLongLivedSleptonSim = cms.Modifier() diff --git a/SimG4Core/Application/python/g4SimHits_cfi.py b/SimG4Core/Application/python/g4SimHits_cfi.py index 20cbb095e3c02..1d3696a9e6a16 100644 --- a/SimG4Core/Application/python/g4SimHits_cfi.py +++ b/SimG4Core/Application/python/g4SimHits_cfi.py @@ -285,7 +285,7 @@ MinPhiCut = cms.double(-3.14159265359), ## (radians) MaxPhiCut = cms.double(3.14159265359), ## according to CMS conventions ApplyLumiMonitorCuts = cms.bool(False), ## primary for lumi monitors - IsSmuon = cms.bool(False), + IsSlepton = cms.bool(False), Verbosity = cms.untracked.int32(0), PDGselection = cms.PSet( PDGfilterSel = cms.bool(False), ## filter out unwanted particles @@ -790,3 +790,11 @@ HGCSD = dict( HitCollection = 2) ) + +## +## Fix for long-lived slepton simulation +## +from Configuration.ProcessModifiers.fixLongLivedSleptonSim_cff import fixLongLivedSleptonSim +dd4hep.toModify( g4SimHits, + Generator = dict(IsSlepton = True) +) diff --git a/SimG4Core/Generators/interface/Generator.h b/SimG4Core/Generators/interface/Generator.h index e14d65e89c4d5..59c34360664c5 100644 --- a/SimG4Core/Generators/interface/Generator.h +++ b/SimG4Core/Generators/interface/Generator.h @@ -45,7 +45,7 @@ class Generator { bool fEtaCuts; bool fPhiCuts; bool fFiductialCuts; - bool fSmuon; + bool fSlepton; double theMinPhiCut; double theMaxPhiCut; double theMinEtaCut; diff --git a/SimG4Core/Generators/interface/Generator3.h b/SimG4Core/Generators/interface/Generator3.h index c2bae7b9600eb..92f3f24115e0d 100644 --- a/SimG4Core/Generators/interface/Generator3.h +++ b/SimG4Core/Generators/interface/Generator3.h @@ -45,6 +45,7 @@ class Generator3 { bool fEtaCuts; bool fPhiCuts; bool fFiductialCuts; + bool fSlepton; double theMinPhiCut; double theMaxPhiCut; double theMinEtaCut; diff --git a/SimG4Core/Generators/src/Generator.cc b/SimG4Core/Generators/src/Generator.cc index c68031da7a782..41478f50c3771 100644 --- a/SimG4Core/Generators/src/Generator.cc +++ b/SimG4Core/Generators/src/Generator.cc @@ -25,7 +25,7 @@ Generator::Generator(const ParameterSet &p) fPtransCut(p.getParameter("ApplyPtransCut")), fEtaCuts(p.getParameter("ApplyEtaCuts")), fPhiCuts(p.getParameter("ApplyPhiCuts")), - fSmuon(p.getParameter("IsSmuon")), + fSlepton(p.getParameter("IsSlepton")), theMinPhiCut(p.getParameter("MinPhiCut")), // in radians (CMS standard) theMaxPhiCut(p.getParameter("MaxPhiCut")), theMinEtaCut(p.getParameter("MinEtaCut")), @@ -366,7 +366,7 @@ void Generator::HepMC2G4(const HepMC::GenEvent *evt_orig, G4Event *g4evt) { // Decay chain outside the fiducial cylinder defined by theRDecLenCut // are used for Geant4 tracking with predefined decay channel // In the case of decay in vacuum particle is not tracked by Geant4 - } else if (2 == status && x2 * x2 + y2 * y2 >= theDecRCut2 && (fSmuon || std::abs(z2) < Z_hector)) { + } else if (2 == status && x2 * x2 + y2 * y2 >= theDecRCut2 && (fSlepton || std::abs(z2) < Z_hector)) { toBeAdded = true; if (verbose > 1) edm::LogVerbatim("SimG4CoreGenerator") << "GenParticle barcode = " << (*pitr)->barcode() << " passed case 2" @@ -478,7 +478,7 @@ void Generator::particleAssignDaughters(G4PrimaryParticle *g4p, HepMC::GenPartic << "Assigning a " << (*vpdec)->pdg_id() << " as daughter of a " << vp->pdg_id() << " status=" << status; bool isInList; - if (fSmuon) { + if (fSlepton) { std::vector fParticleList = {1000011, 1000013, 1000015, 2000011, 2000013, 2000015}; isInList = (std::find(fParticleList.begin(), fParticleList.end(), std::abs(vp->pdg_id())) != fParticleList.end()); } else { diff --git a/SimG4Core/Generators/src/Generator3.cc b/SimG4Core/Generators/src/Generator3.cc index c9b188ec83d97..cbafff8ba25ee 100644 --- a/SimG4Core/Generators/src/Generator3.cc +++ b/SimG4Core/Generators/src/Generator3.cc @@ -27,6 +27,7 @@ Generator3::Generator3(const ParameterSet &p) fPtransCut(p.getParameter("ApplyPtransCut")), fEtaCuts(p.getParameter("ApplyEtaCuts")), fPhiCuts(p.getParameter("ApplyPhiCuts")), + fSlepton(p.getParameter("IsSlepton")), theMinPhiCut(p.getParameter("MinPhiCut")), // in radians (CMS standard) theMaxPhiCut(p.getParameter("MaxPhiCut")), theMinEtaCut(p.getParameter("MinEtaCut")), @@ -367,7 +368,7 @@ void Generator3::HepMC2G4(const HepMC3::GenEvent *evt_orig, G4Event *g4evt) { // Decay chain outside the fiducial cylinder defined by theRDecLenCut // are used for Geant4 tracking with predefined decay channel // In the case of decay in vacuum particle is not tracked by Geant4 - } else if (2 == status && x2 * x2 + y2 * y2 >= theDecRCut2 && std::abs(z2) < Z_hector) { + } else if (2 == status && x2 * x2 + y2 * y2 >= theDecRCut2 && (fSlepton || std::abs(z2) < Z_hector)) { toBeAdded = true; if (verbose > 1) edm::LogVerbatim("SimG4CoreGenerator3") << "GenParticle barcode = " << pitr->id() << " passed case 2" @@ -477,7 +478,14 @@ void Generator3::particleAssignDaughters(G4PrimaryParticle *g4p, HepMC3::GenPart LogDebug("SimG4CoreGenerator3::::particleAssignDaughters") << "Assigning a " << vpdec->pid() << " as daughter of a " << vp->pid() << " status=" << status; - if ((status == 2 || (status == 23 && std::abs(vp->pid()) == 1000015) || (status > 50 && status < 100)) && + bool isInList; + if (fSlepton) { + std::vector fParticleList = {1000011, 1000013, 1000015, 2000011, 2000013, 2000015}; + isInList = (std::find(fParticleList.begin(), fParticleList.end(), std::abs(vp->pdg_id())) != fParticleList.end()); + } else { + isInList = std::abs(vp->pdg_id()) == 1000015; + } + if ((status == 2 || (status == 23 && isInList) || (status > 50 && status < 100)) && vpdec->end_vertex() != nullptr) { double x2 = vpdec->end_vertex()->position().x(); double y2 = vpdec->end_vertex()->position().y();