Skip to content

Commit

Permalink
Merge pull request #36652 from bsunanda/Run3-sim102
Browse files Browse the repository at this point in the history
Run3-sim102 Make runtime variables to allow/disallow creation of SimHits for demonstration chambers
  • Loading branch information
cmsbuild authored Jan 12, 2022
2 parents cc03c87 + fc190fd commit 77e4d1f
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 36 deletions.
18 changes: 11 additions & 7 deletions SimG4CMS/Muon/interface/MuonSensitiveDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string>
Expand All @@ -41,10 +42,7 @@ class MuonSensitiveDetector : public SensitiveTkDetector, public Observer<const
const MuonOffsetMap*,
const MuonGeometryConstants&,
const SensitiveDetectorCatalog&,
double ePersistentCutGeV,
bool allMuonsPersistent,
bool aPrintHits,
bool dd4hep,
edm::ParameterSet const& p,
const SimTrackManager*);
~MuonSensitiveDetector() override;
G4bool ProcessHits(G4Step*, G4TouchableHistory*) override;
Expand All @@ -61,6 +59,7 @@ class MuonSensitiveDetector : public SensitiveTkDetector, public Observer<const

private:
inline Local3DPoint cmsUnits(const Local3DPoint& v) { return Local3DPoint(v.x() * 0.1, v.y() * 0.1, v.z() * 0.1); }
bool acceptHit(uint32_t id);

MuonSlaveSD* slaveMuon;
MuonSimHitNumberingScheme* numbering;
Expand All @@ -87,12 +86,17 @@ class MuonSensitiveDetector : public SensitiveTkDetector, public Observer<const
uint32_t newDetUnitId;
int theTrackID;

bool printHits;
bool printHits_;
SimHitPrinter* thePrinter;

//--- SimTracks cuts
float ePersistentCutGeV;
bool allMuonsPersistent;
float ePersistentCutGeV_;
bool allMuonsPersistent_;

// For choice of demo chambers
bool haveDemo_;
bool demoGEM_;
bool demoRPC_;

G4ProcessTypeEnumerator* theG4ProcessTypeEnumerator;

Expand Down
11 changes: 2 additions & 9 deletions SimG4CMS/Muon/plugins/MuonSensitiveDetectorBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@ class MuonSensitiveDetectorBuilder : public SensitiveDetectorMakerBase {
: offmap_{nullptr},
mdc_{nullptr},
offsetToken_{cc.esConsumes<edm::Transition::BeginRun>()},
geomConstantsToken_{cc.esConsumes<edm::Transition::BeginRun>()} {
edm::ParameterSet muonSD = p.getParameter<edm::ParameterSet>("MuonSD");
ePersistentCutGeV_ = muonSD.getParameter<double>("EnergyThresholdForPersistency") / CLHEP::GeV; //Default 1. GeV
allMuonsPersistent_ = muonSD.getParameter<bool>("AllMuonsPersistent");
printHits_ = muonSD.getParameter<bool>("PrintHits");
dd4hep_ = p.getParameter<bool>("g4GeometryDD4hepSource");
}
geomConstantsToken_{cc.esConsumes<edm::Transition::BeginRun>()} {}

void beginRun(const edm::EventSetup& es) final {
edm::ESHandle<MuonOffsetMap> mom = es.getHandle(offsetToken_);
Expand All @@ -55,8 +49,7 @@ class MuonSensitiveDetectorBuilder : public SensitiveDetectorMakerBase {
const edm::ParameterSet& p,
const SimTrackManager* man,
SimActivityRegistry& reg) const final {
auto sd = std::make_unique<MuonSensitiveDetector>(
iname, offmap_, *mdc_, clg, ePersistentCutGeV_, allMuonsPersistent_, printHits_, dd4hep_, man);
auto sd = std::make_unique<MuonSensitiveDetector>(iname, offmap_, *mdc_, clg, p, man);
SimActivityRegistryEnroller::enroll(reg, sd.get());
return sd;
}
Expand Down
91 changes: 73 additions & 18 deletions SimG4CMS/Muon/src/MuonSensitiveDetector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -36,26 +40,31 @@ 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),
theHit(nullptr),
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<bool>("g4GeometryDD4hepSource");
edm::ParameterSet muonSD = p.getParameter<edm::ParameterSet>("MuonSD");
printHits_ = muonSD.getParameter<bool>("PrintHits");
ePersistentCutGeV_ = muonSD.getParameter<double>("EnergyThresholdForPersistency") / CLHEP::GeV; //Default 1. GeV
allMuonsPersistent_ = muonSD.getParameter<bool>("AllMuonsPersistent");
haveDemo_ = muonSD.getParameter<bool>("HaveDemoChambers");
demoGEM_ = muonSD.getParameter<bool>("UseDemoHitGEM");
demoRPC_ = muonSD.getParameter<bool>("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);

Expand All @@ -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;
}
Expand Down Expand Up @@ -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<std::string>(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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
10 changes: 8 additions & 2 deletions SimG4Core/Application/python/g4SimHits_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 )
)

0 comments on commit 77e4d1f

Please sign in to comment.