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..b00b0aca9e327 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,41 @@ Local3DPoint MuonSensitiveDetector::FinalStepPositionVsParent(const G4Step* curr return ConvertToLocal3DPoint(localCoordinates); } + +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(); + 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_; + } + } +#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; + else if (subdet == MuonSubdetId::GEM) + 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) + 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..127fa6f7c1a3e 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(True) ), CaloSD = cms.PSet( common_heavy_suppression, @@ -668,4 +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 ) + LHCTransport = False, + MuonSD = dict( + HaveDemoChambers = False ) +)