Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run3-sim102 Make runtime variables to allow/disallow creation of SimHits for demonstration chambers #36652

Merged
merged 5 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
85 changes: 67 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,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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be checked at the very beginning of the method, and simply return false if id == 0 ?
(Possibly with a debug line attached, if you want so)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken care of

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;
}
8 changes: 7 additions & 1 deletion 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 @@ -669,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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please unify with the previous phase2_common.toModify

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

HaveDemoChambers = False )
)