From f79b6e2e5ac2870431e38c5c8350e549162a4807 Mon Sep 17 00:00:00 2001 From: Sunanda Date: Sat, 8 Jan 2022 23:11:08 +0100 Subject: [PATCH 1/5] Make runtime variables to allow/disallow creation of SimHits for demonstration chambers --- .../Muon/interface/MuonSensitiveDetector.h | 18 ++-- .../plugins/MuonSensitiveDetectorBuilder.cc | 11 +-- SimG4CMS/Muon/src/MuonSensitiveDetector.cc | 85 +++++++++++++++---- SimG4Core/Application/python/g4SimHits_cfi.py | 8 +- 4 files changed, 87 insertions(+), 35 deletions(-) diff --git a/SimG4CMS/Muon/interface/MuonSensitiveDetector.h b/SimG4CMS/Muon/interface/MuonSensitiveDetector.h index 48e721ba32923..746f2fdd65f08 100644 --- a/SimG4CMS/Muon/interface/MuonSensitiveDetector.h +++ b/SimG4CMS/Muon/interface/MuonSensitiveDetector.h @@ -20,6 +20,7 @@ #include "SimG4Core/SensitiveDetector/interface/SensitiveTkDetector.h" #include "DataFormats/GeometryVector/interface/LocalPoint.h" #include "CondFormats/GeometryObjects/interface/MuonOffsetMap.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" #include "Geometry/MuonNumbering/interface/MuonGeometryConstants.h" #include @@ -41,10 +42,7 @@ class MuonSensitiveDetector : public SensitiveTkDetector, public Observer()}, - geomConstantsToken_{cc.esConsumes()} { - edm::ParameterSet muonSD = p.getParameter("MuonSD"); - ePersistentCutGeV_ = muonSD.getParameter("EnergyThresholdForPersistency") / CLHEP::GeV; //Default 1. GeV - allMuonsPersistent_ = muonSD.getParameter("AllMuonsPersistent"); - printHits_ = muonSD.getParameter("PrintHits"); - dd4hep_ = p.getParameter("g4GeometryDD4hepSource"); - } + geomConstantsToken_{cc.esConsumes()} {} void beginRun(const edm::EventSetup& es) final { edm::ESHandle mom = es.getHandle(offsetToken_); @@ -55,8 +49,7 @@ class MuonSensitiveDetectorBuilder : public SensitiveDetectorMakerBase { const edm::ParameterSet& p, const SimTrackManager* man, SimActivityRegistry& reg) const final { - auto sd = std::make_unique( - iname, offmap_, *mdc_, clg, ePersistentCutGeV_, allMuonsPersistent_, printHits_, dd4hep_, man); + auto sd = std::make_unique(iname, offmap_, *mdc_, clg, p, man); SimActivityRegistryEnroller::enroll(reg, sd.get()); return sd; } diff --git a/SimG4CMS/Muon/src/MuonSensitiveDetector.cc b/SimG4CMS/Muon/src/MuonSensitiveDetector.cc index cf22fe9e8436e..cb3161d7b2faf 100644 --- a/SimG4CMS/Muon/src/MuonSensitiveDetector.cc +++ b/SimG4CMS/Muon/src/MuonSensitiveDetector.cc @@ -9,6 +9,10 @@ #include "SimG4CMS/Muon/interface/SimHitPrinter.h" #include "SimDataFormats/TrackingHit/interface/UpdatablePSimHit.h" #include "DataFormats/GeometryVector/interface/GlobalPoint.h" +#include "DataFormats/MuonDetId/interface/MuonSubdetId.h" +#include "DataFormats/MuonDetId/interface/GEMDetId.h" +#include "DataFormats/MuonDetId/interface/ME0DetId.h" +#include "DataFormats/MuonDetId/interface/RPCDetId.h" #include "SimG4CMS/Muon/interface/MuonG4Numbering.h" #include "Geometry/MuonNumbering/interface/MuonGeometryConstants.h" @@ -36,10 +40,7 @@ MuonSensitiveDetector::MuonSensitiveDetector(const std::string& name, const MuonOffsetMap* offmap, const MuonGeometryConstants& constants, const SensitiveDetectorCatalog& clg, - double aEPersistentCutGeV, - bool aAllMuonsPersistent, - bool aPrintHits, - bool dd4hep, + edm::ParameterSet const& p, const SimTrackManager* manager) : SensitiveTkDetector(name, clg), thePV(nullptr), @@ -47,15 +48,23 @@ MuonSensitiveDetector::MuonSensitiveDetector(const std::string& name, theDetUnitId(0), newDetUnitId(0), theTrackID(0), - printHits(aPrintHits), thePrinter(nullptr), - ePersistentCutGeV(aEPersistentCutGeV), - allMuonsPersistent(aAllMuonsPersistent), theManager(manager) { // Here simply create 1 MuonSlaveSD for the moment // + bool dd4hep = p.getParameter("g4GeometryDD4hepSource"); + edm::ParameterSet muonSD = p.getParameter("MuonSD"); + printHits_ = muonSD.getParameter("PrintHits"); + ePersistentCutGeV_ = muonSD.getParameter("EnergyThresholdForPersistency") / CLHEP::GeV; //Default 1. GeV + allMuonsPersistent_ = muonSD.getParameter("AllMuonsPersistent"); + haveDemo_ = muonSD.getParameter("HaveDemoChambers"); + demoGEM_ = muonSD.getParameter("UseDemoHitGEM"); + demoRPC_ = muonSD.getParameter("UseDemoHitRPC"); + #ifdef EDM_ML_DEBUG - edm::LogVerbatim("MuonSim") << "create MuonSubDetector " << name << " with dd4hep flag " << dd4hep; + edm::LogVerbatim("MuonSim") << "create MuonSubDetector " << name << " with dd4hep flag " << dd4hep + << " Flags for Demonstration chambers " << haveDemo_ << " for GEM " << demoGEM_ + << " for RPC " << demoRPC_; #endif detector = new MuonSubDetector(name); @@ -81,12 +90,12 @@ MuonSensitiveDetector::MuonSensitiveDetector(const std::string& name, numbering = new MuonSimHitNumberingScheme(detector, constants); g4numbering = new MuonG4Numbering(constants, offmap, dd4hep); - if (printHits) { + if (printHits_) { thePrinter = new SimHitPrinter("HitPositionOSCAR.dat"); } edm::LogVerbatim("MuonSim") << " of type " << sdet << " <" << GetName() << "> EnergyThresholdForPersistency(GeV) " - << ePersistentCutGeV / CLHEP::GeV << " allMuonsPersistent: " << allMuonsPersistent; + << ePersistentCutGeV_ / CLHEP::GeV << " allMuonsPersistent: " << allMuonsPersistent_; theG4ProcessTypeEnumerator = new G4ProcessTypeEnumerator; } @@ -122,7 +131,13 @@ bool MuonSensitiveDetector::ProcessHits(G4Step* aStep, G4TouchableHistory* ROhis if (aStep->GetTotalEnergyDeposit() > 0.) { newDetUnitId = setDetUnitId(aStep); - +#ifdef EDM_ML_DEBUG + G4VPhysicalVolume* vol = aStep->GetPreStepPoint()->GetTouchable()->GetVolume(0); + std::string namx = static_cast(vol->GetName()); + std::string name = namx.substr(0, 2); + if (name == "RE") + edm::LogVerbatim("MuonSim") << "DETID " << namx << " " << RPCDetId(newDetUnitId); +#endif if (newHit(aStep)) { saveHit(); createHit(aStep); @@ -223,7 +238,7 @@ void MuonSensitiveDetector::createHit(const G4Step* aStep) { // Make track persistent int thePID = std::abs(theTrack->GetDefinition()->GetPDGEncoding()); //---VI - in parameters cut in energy is declared but applied to momentum - if (thePabs > ePersistentCutGeV || (thePID == 13 && allMuonsPersistent)) { + if (thePabs > ePersistentCutGeV_ || (thePID == 13 && allMuonsPersistent_)) { TrackInformation* info = cmsTrackInformation(theTrack); info->storeTrack(true); } @@ -290,13 +305,15 @@ void MuonSensitiveDetector::updateHit(const G4Step* aStep) { void MuonSensitiveDetector::saveHit() { if (theHit) { - if (printHits) { - thePrinter->startNewSimHit(detector->name()); - thePrinter->printId(theHit->detUnitId()); - thePrinter->printLocal(theHit->entryPoint(), theHit->exitPoint()); + if (acceptHit(theHit->detUnitId())) { + if (printHits_) { + thePrinter->startNewSimHit(detector->name()); + thePrinter->printId(theHit->detUnitId()); + thePrinter->printLocal(theHit->entryPoint(), theHit->exitPoint()); + } + // hit is included into hit collection + slaveMuon->processHits(*theHit); } - // hit is included into hit collection - slaveMuon->processHits(*theHit); delete theHit; theHit = nullptr; } @@ -336,3 +353,35 @@ Local3DPoint MuonSensitiveDetector::FinalStepPositionVsParent(const G4Step* curr return ConvertToLocal3DPoint(localCoordinates); } + +bool MuonSensitiveDetector::acceptHit(uint32_t id) { + bool flag(true); + if (haveDemo_) { + int subdet = DetId(id).subdetId(); + if (subdet == MuonSubdetId::GEM) { + if (GEMDetId(id).station() == 2) + flag = demoGEM_; + } else if (subdet == MuonSubdetId::RPC) { + if ((RPCDetId(id).region() != 0) && (RPCDetId(id).ring() == 1) && (RPCDetId(id).station() > 2)) + flag = demoRPC_; + } + } + if (id == 0) + flag = false; +#ifdef EDM_ML_DEBUG + int subdet = DetId(id).subdetId(); + if (subdet == MuonSubdetId::RPC) + edm::LogVerbatim("MuonSim") << "DetId " << std::hex << id << std::dec << " " << RPCDetId(id) << " Flag " << flag; + else if (subdet == MuonSubdetId::GEM) + edm::LogVerbatim("MuonSim") << "DetId " << std::hex << id << std::dec << " " << GEMDetId(id) << " Flag " << flag; + else if (subdet == MuonSubdetId::ME0) + edm::LogVerbatim("MuonSim") << "DetId " << std::hex << id << std::dec << " " << ME0DetId(id) << " Flag " << flag; + else if (subdet == MuonSubdetId::CSC) + edm::LogVerbatim("MuonSim") << "DetId " << std::hex << id << std::dec << " CSC Flag " << flag; + else if (subdet == MuonSubdetId::DT) + edm::LogVerbatim("MuonSim") << "DetId " << std::hex << id << std::dec << " DT Flag " << flag; + else + edm::LogVerbatim("MuonSim") << "DetId " << std::hex << id << std::dec << " Unknown Flag " << flag; +#endif + return flag; +} diff --git a/SimG4Core/Application/python/g4SimHits_cfi.py b/SimG4Core/Application/python/g4SimHits_cfi.py index b5f6c6e3c51bd..debc11c0a25d7 100644 --- a/SimG4Core/Application/python/g4SimHits_cfi.py +++ b/SimG4Core/Application/python/g4SimHits_cfi.py @@ -327,7 +327,10 @@ MuonSD = cms.PSet( EnergyThresholdForPersistency = cms.double(1.0), PrintHits = cms.bool(False), - AllMuonsPersistent = cms.bool(True) + AllMuonsPersistent = cms.bool(True), + UseDemoHitRPC = cms.bool(False), + UseDemoHitGEM = cms.bool(False), + HaveDemoChambers = cms.bool(False) ), CaloSD = cms.PSet( common_heavy_suppression, @@ -630,6 +633,9 @@ from Configuration.Eras.Modifier_run3_common_cff import run3_common run3_common.toModify( g4SimHits, CastorSD = dict( useShowerLibrary = False ) ) run3_common.toModify( g4SimHits, LHCTransport = False ) +run3_common.toModify( g4SimHits, MuonSD = dict( + HaveDemoChambers = True ) +) ## ## Disable PPS from Run 3 PbPb runs From 1eb520e9264812f1aba178a05ac3241a76d7cc44 Mon Sep 17 00:00:00 2001 From: Sunanda Date: Mon, 10 Jan 2022 13:54:38 +0100 Subject: [PATCH 2/5] Correct for phase2 SIM step --- SimG4Core/Application/python/g4SimHits_cfi.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SimG4Core/Application/python/g4SimHits_cfi.py b/SimG4Core/Application/python/g4SimHits_cfi.py index debc11c0a25d7..b543611d85b13 100644 --- a/SimG4Core/Application/python/g4SimHits_cfi.py +++ b/SimG4Core/Application/python/g4SimHits_cfi.py @@ -330,7 +330,7 @@ AllMuonsPersistent = cms.bool(True), UseDemoHitRPC = cms.bool(False), UseDemoHitGEM = cms.bool(False), - HaveDemoChambers = cms.bool(False) + HaveDemoChambers = cms.bool(True) ), CaloSD = cms.PSet( common_heavy_suppression, @@ -633,9 +633,6 @@ from Configuration.Eras.Modifier_run3_common_cff import run3_common run3_common.toModify( g4SimHits, CastorSD = dict( useShowerLibrary = False ) ) run3_common.toModify( g4SimHits, LHCTransport = False ) -run3_common.toModify( g4SimHits, MuonSD = dict( - HaveDemoChambers = True ) -) ## ## Disable PPS from Run 3 PbPb runs @@ -675,3 +672,6 @@ phase2_common.toModify(g4SimHits, OnlySDs = ['ZdcSensitiveDetector', 'TotemT2ScintSensitiveDetector', 'TotemSensitiveDetector', 'RomanPotSensitiveDetector', 'PLTSensitiveDetector', 'MuonSensitiveDetector', 'MtdSensitiveDetector', 'BCM1FSensitiveDetector', 'EcalSensitiveDetector', 'CTPPSSensitiveDetector', 'HGCalSensitiveDetector', 'BSCSensitiveDetector', 'CTPPSDiamondSensitiveDetector', 'FP420SensitiveDetector', 'BHMSensitiveDetector', 'HFNoseSensitiveDetector', 'HGCScintillatorSensitiveDetector', 'CastorSensitiveDetector', 'CaloTrkProcessing', 'HcalSensitiveDetector', 'TkAccumulatingSensitiveDetector'], LHCTransport = False ) +phase2_common.toModify( g4SimHits, MuonSD = dict( + HaveDemoChambers = False ) +) From 189fbae24621f232593712921c6639461d18c65d Mon Sep 17 00:00:00 2001 From: Sunanda Date: Tue, 11 Jan 2022 14:55:57 +0100 Subject: [PATCH 3/5] Take care of Andrea's comments --- SimG4CMS/Muon/src/MuonSensitiveDetector.cc | 8 ++++++-- SimG4Core/Application/python/g4SimHits_cfi.py | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/SimG4CMS/Muon/src/MuonSensitiveDetector.cc b/SimG4CMS/Muon/src/MuonSensitiveDetector.cc index cb3161d7b2faf..a8d04595e3162 100644 --- a/SimG4CMS/Muon/src/MuonSensitiveDetector.cc +++ b/SimG4CMS/Muon/src/MuonSensitiveDetector.cc @@ -355,6 +355,12 @@ Local3DPoint MuonSensitiveDetector::FinalStepPositionVsParent(const G4Step* curr } bool MuonSensitiveDetector::acceptHit(uint32_t id) { + if (id == 0) { +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("MuonSim") << "DetId " << id << " Flag " << false; +#endif + return false; + } bool flag(true); if (haveDemo_) { int subdet = DetId(id).subdetId(); @@ -366,8 +372,6 @@ bool MuonSensitiveDetector::acceptHit(uint32_t id) { flag = demoRPC_; } } - if (id == 0) - flag = false; #ifdef EDM_ML_DEBUG int subdet = DetId(id).subdetId(); if (subdet == MuonSubdetId::RPC) diff --git a/SimG4Core/Application/python/g4SimHits_cfi.py b/SimG4Core/Application/python/g4SimHits_cfi.py index b543611d85b13..127fa6f7c1a3e 100644 --- a/SimG4Core/Application/python/g4SimHits_cfi.py +++ b/SimG4Core/Application/python/g4SimHits_cfi.py @@ -671,7 +671,7 @@ from Configuration.Eras.Modifier_phase2_common_cff import phase2_common phase2_common.toModify(g4SimHits, OnlySDs = ['ZdcSensitiveDetector', 'TotemT2ScintSensitiveDetector', 'TotemSensitiveDetector', 'RomanPotSensitiveDetector', 'PLTSensitiveDetector', 'MuonSensitiveDetector', 'MtdSensitiveDetector', 'BCM1FSensitiveDetector', 'EcalSensitiveDetector', 'CTPPSSensitiveDetector', 'HGCalSensitiveDetector', 'BSCSensitiveDetector', 'CTPPSDiamondSensitiveDetector', 'FP420SensitiveDetector', 'BHMSensitiveDetector', 'HFNoseSensitiveDetector', 'HGCScintillatorSensitiveDetector', 'CastorSensitiveDetector', 'CaloTrkProcessing', 'HcalSensitiveDetector', 'TkAccumulatingSensitiveDetector'], - LHCTransport = False ) -phase2_common.toModify( g4SimHits, MuonSD = dict( - HaveDemoChambers = False ) + LHCTransport = False, + MuonSD = dict( + HaveDemoChambers = False ) ) From e7a75dd22f97f4c56d4f16b425c910ba398065c1 Mon Sep 17 00:00:00 2001 From: Sunanda Date: Tue, 11 Jan 2022 16:26:16 +0100 Subject: [PATCH 4/5] Small change --- SimG4CMS/Muon/src/MuonSensitiveDetector.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SimG4CMS/Muon/src/MuonSensitiveDetector.cc b/SimG4CMS/Muon/src/MuonSensitiveDetector.cc index a8d04595e3162..597b5c7269ca6 100644 --- a/SimG4CMS/Muon/src/MuonSensitiveDetector.cc +++ b/SimG4CMS/Muon/src/MuonSensitiveDetector.cc @@ -375,9 +375,9 @@ bool MuonSensitiveDetector::acceptHit(uint32_t id) { #ifdef EDM_ML_DEBUG int subdet = DetId(id).subdetId(); if (subdet == MuonSubdetId::RPC) - edm::LogVerbatim("MuonSim") << "DetId " << std::hex << id << std::dec << " " << RPCDetId(id) << " Flag " << flag; + edm::LogVerbatim("MuonSim") << "DetId " << std::hex << id << std::dec << " RPC " << RPCDetId(id) << " Flag " << flag; else if (subdet == MuonSubdetId::GEM) - edm::LogVerbatim("MuonSim") << "DetId " << std::hex << id << std::dec << " " << GEMDetId(id) << " Flag " << flag; + edm::LogVerbatim("MuonSim") << "DetId " << std::hex << id << std::dec << " GEM " << GEMDetId(id) << " Flag " << flag; else if (subdet == MuonSubdetId::ME0) edm::LogVerbatim("MuonSim") << "DetId " << std::hex << id << std::dec << " " << ME0DetId(id) << " Flag " << flag; else if (subdet == MuonSubdetId::CSC) From fc190fdaf8fdd3665a932a43c541aa5e2b6e7b66 Mon Sep 17 00:00:00 2001 From: Sunanda Date: Tue, 11 Jan 2022 17:05:50 +0100 Subject: [PATCH 5/5] Code check --- SimG4CMS/Muon/src/MuonSensitiveDetector.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SimG4CMS/Muon/src/MuonSensitiveDetector.cc b/SimG4CMS/Muon/src/MuonSensitiveDetector.cc index 597b5c7269ca6..b00b0aca9e327 100644 --- a/SimG4CMS/Muon/src/MuonSensitiveDetector.cc +++ b/SimG4CMS/Muon/src/MuonSensitiveDetector.cc @@ -375,9 +375,11 @@ bool MuonSensitiveDetector::acceptHit(uint32_t id) { #ifdef EDM_ML_DEBUG int subdet = DetId(id).subdetId(); if (subdet == MuonSubdetId::RPC) - edm::LogVerbatim("MuonSim") << "DetId " << std::hex << id << std::dec << " RPC " << RPCDetId(id) << " Flag " << flag; + edm::LogVerbatim("MuonSim") << "DetId " << std::hex << id << std::dec << " RPC " << RPCDetId(id) << " Flag " + << flag; else if (subdet == MuonSubdetId::GEM) - edm::LogVerbatim("MuonSim") << "DetId " << std::hex << id << std::dec << " GEM " << GEMDetId(id) << " Flag " << flag; + edm::LogVerbatim("MuonSim") << "DetId " << std::hex << id << std::dec << " GEM " << GEMDetId(id) << " Flag " + << flag; else if (subdet == MuonSubdetId::ME0) edm::LogVerbatim("MuonSim") << "DetId " << std::hex << id << std::dec << " " << ME0DetId(id) << " Flag " << flag; else if (subdet == MuonSubdetId::CSC)