From 0535062c0fb84efdb3b7fe774608ddd7d363aeeb Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Sat, 27 Feb 2021 15:49:00 +0100 Subject: [PATCH 1/4] Add calo-boundary information to simtracks --- SimG4CMS/Calo/src/CaloTrkProcessing.cc | 2 +- SimG4Core/Application/src/TrackingAction.cc | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/SimG4CMS/Calo/src/CaloTrkProcessing.cc b/SimG4CMS/Calo/src/CaloTrkProcessing.cc index 16900a1e99f06..fb7474e0cca02 100644 --- a/SimG4CMS/Calo/src/CaloTrkProcessing.cc +++ b/SimG4CMS/Calo/src/CaloTrkProcessing.cc @@ -162,7 +162,7 @@ CaloTrkProcessing::CaloTrkProcessing(const std::string& name, << detectors_[i].fromDetL[k] << " at level " << detectors_[i].fromLevels[k]; } - doFineCalo_ = !(fineDetectors_.empty()); + doFineCalo_ = doFineCalo_ && !(fineDetectors_.empty()); edm::LogVerbatim("CaloSim") << "CaloTrkProcessing: with " << fineDetectors_.size() << " special calorimetric volumes"; for (unsigned int i = 0; i < detectors_.size(); i++) edm::LogVerbatim("CaloSim") << "CaloTrkProcessing: Calorimeter volume " << i << " " << detectors_[i].name << " LV " diff --git a/SimG4Core/Application/src/TrackingAction.cc b/SimG4Core/Application/src/TrackingAction.cc index 249585d2d27bd..f863bc340039b 100644 --- a/SimG4Core/Application/src/TrackingAction.cc +++ b/SimG4Core/Application/src/TrackingAction.cc @@ -103,7 +103,11 @@ void TrackingAction::PostUserTrackingAction(const G4Track* aTrack) { } } - if (extractor_(aTrack).storeTrack() || currentTrack_->saved()) { + TrackInformation* trkInfo = (TrackInformation*)aTrack->GetUserInformation(); + if (extractor_(aTrack).storeTrack() || currentTrack_->saved() || trkInfo->crossedBoundary()) { + if (trkInfo->crossedBoundary()) { + currentTrack_->setCrossedBoundaryPosMom(id, trkInfo->getPositionAtBoundary(), trkInfo->getMomentumAtBoundary()); + } currentTrack_->save(); eventAction_->addTkCaloStateInfo(id, p); From f6b9b62da0746ec5a4debb8199d4bfb68074a694 Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Sat, 27 Feb 2021 16:03:23 +0100 Subject: [PATCH 2/4] Set calo-boundary information --- SimG4CMS/Calo/src/CaloTrkProcessing.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/SimG4CMS/Calo/src/CaloTrkProcessing.cc b/SimG4CMS/Calo/src/CaloTrkProcessing.cc index fb7474e0cca02..cee9d7fd718cf 100644 --- a/SimG4CMS/Calo/src/CaloTrkProcessing.cc +++ b/SimG4CMS/Calo/src/CaloTrkProcessing.cc @@ -279,6 +279,7 @@ void CaloTrkProcessing::update(const G4Step* aStep) { trkInfo->setIDonCaloSurface( id, ical, inside, theTrack->GetDefinition()->GetPDGEncoding(), theTrack->GetMomentum().mag()); trkInfo->setCaloIDChecked(true); + trkInfo->setCrossedBoundary(theTrack); lastTrackID_ = id; if (theTrack->GetKineticEnergy() / CLHEP::MeV > eMin_) trkInfo->putInHistory(); From b8e1f85198dc16423b369b29e60f56117d6dabae Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Tue, 2 Mar 2021 17:37:19 +0100 Subject: [PATCH 3/4] Code format --- SimG4Core/Application/src/TrackingAction.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SimG4Core/Application/src/TrackingAction.cc b/SimG4Core/Application/src/TrackingAction.cc index f863bc340039b..8ecf71c2abb94 100644 --- a/SimG4Core/Application/src/TrackingAction.cc +++ b/SimG4Core/Application/src/TrackingAction.cc @@ -106,7 +106,7 @@ void TrackingAction::PostUserTrackingAction(const G4Track* aTrack) { TrackInformation* trkInfo = (TrackInformation*)aTrack->GetUserInformation(); if (extractor_(aTrack).storeTrack() || currentTrack_->saved() || trkInfo->crossedBoundary()) { if (trkInfo->crossedBoundary()) { - currentTrack_->setCrossedBoundaryPosMom(id, trkInfo->getPositionAtBoundary(), trkInfo->getMomentumAtBoundary()); + currentTrack_->setCrossedBoundaryPosMom(id, trkInfo->getPositionAtBoundary(), trkInfo->getMomentumAtBoundary()); } currentTrack_->save(); From 50db9836909eb22e9cb18a9bff8d89381ed60842 Mon Sep 17 00:00:00 2001 From: Marco Rovere Date: Thu, 4 Mar 2021 08:45:33 +0100 Subject: [PATCH 4/4] Activate CaloBoundary information only for Phase2 workflows --- SimG4Core/Application/interface/TrackingAction.h | 1 + SimG4Core/Application/python/g4SimHits_cfi.py | 9 ++++++++- SimG4Core/Application/src/TrackingAction.cc | 4 +++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/SimG4Core/Application/interface/TrackingAction.h b/SimG4Core/Application/interface/TrackingAction.h index fdbbe613c7c34..e65176435570d 100644 --- a/SimG4Core/Application/interface/TrackingAction.h +++ b/SimG4Core/Application/interface/TrackingAction.h @@ -36,6 +36,7 @@ class TrackingAction : public G4UserTrackingAction { const G4Track* g4Track_; bool checkTrack_; bool doFineCalo_; + bool saveCaloBoundaryInformation_; double eMinFine_; }; diff --git a/SimG4Core/Application/python/g4SimHits_cfi.py b/SimG4Core/Application/python/g4SimHits_cfi.py index b54b28eaae131..75bdbb6ff65c9 100644 --- a/SimG4Core/Application/python/g4SimHits_cfi.py +++ b/SimG4Core/Application/python/g4SimHits_cfi.py @@ -37,12 +37,13 @@ ) common_UseLuminosity = cms.PSet( - InstLuminosity = cms.double(0.), + InstLuminosity = cms.double(0.), DelivLuminosity = cms.double(5000.) ) common_MCtruth = cms.PSet( DoFineCalo = cms.bool(False), + SaveCaloBoundaryInformation = cms.bool(False), # currently unused; left in place for future studies EminFineTrack = cms.double(10000.0), FineCaloNames = cms.vstring('ECAL', 'HCAL', 'HGCal', 'HFNoseVol', 'VCAL'), @@ -56,6 +57,12 @@ DoFineCalo = True ) +## enable CaloBoundary information for all Phase2 workflows +from Configuration.Eras.Modifier_phase2_hgcal_cff import phase2_hgcal +phase2_hgcal.toModify(common_MCtruth, + SaveCaloBoundaryInformation =True +) + g4SimHits = cms.EDProducer("OscarMTProducer", g4GeometryDD4hepSource = cms.bool(False), NonBeamEvent = cms.bool(False), diff --git a/SimG4Core/Application/src/TrackingAction.cc b/SimG4Core/Application/src/TrackingAction.cc index 8ecf71c2abb94..174a256d2b15a 100644 --- a/SimG4Core/Application/src/TrackingAction.cc +++ b/SimG4Core/Application/src/TrackingAction.cc @@ -23,6 +23,7 @@ TrackingAction::TrackingAction(EventAction* e, const edm::ParameterSet& p, CMSSt g4Track_(nullptr), checkTrack_(p.getUntrackedParameter("CheckTrack", false)), doFineCalo_(p.getParameter("DoFineCalo")), + saveCaloBoundaryInformation_(p.getParameter("SaveCaloBoundaryInformation")), eMinFine_(p.getParameter("EminFineTrack") * CLHEP::MeV) {} TrackingAction::~TrackingAction() {} @@ -104,7 +105,8 @@ void TrackingAction::PostUserTrackingAction(const G4Track* aTrack) { } TrackInformation* trkInfo = (TrackInformation*)aTrack->GetUserInformation(); - if (extractor_(aTrack).storeTrack() || currentTrack_->saved() || trkInfo->crossedBoundary()) { + if (extractor_(aTrack).storeTrack() || currentTrack_->saved() || + (saveCaloBoundaryInformation_ && trkInfo->crossedBoundary())) { if (trkInfo->crossedBoundary()) { currentTrack_->setCrossedBoundaryPosMom(id, trkInfo->getPositionAtBoundary(), trkInfo->getMomentumAtBoundary()); }