diff --git a/SimG4Core/Application/interface/CMSSimEventManager.h b/SimG4Core/Application/interface/CMSSimEventManager.h index 334e995779702..aeb1e62095ba3 100644 --- a/SimG4Core/Application/interface/CMSSimEventManager.h +++ b/SimG4Core/Application/interface/CMSSimEventManager.h @@ -21,7 +21,7 @@ class G4Event; class EventAction; class StackingAction; class TrackingAction; -class SteppingAction; +class G4UserSteppingAction; class G4SDManager; class G4StateManager; class G4PrimaryTransformer; @@ -44,7 +44,7 @@ class CMSSimEventManager { void SetUserAction(EventAction* ptr); void SetUserAction(StackingAction* ptr); void SetUserAction(TrackingAction* ptr); - void SetUserAction(SteppingAction* ptr); + void SetUserAction(G4UserSteppingAction* ptr); CMSSimEventManager(const CMSSimEventManager& right) = delete; CMSSimEventManager& operator=(const CMSSimEventManager& right) = delete; diff --git a/SimG4Core/Application/interface/Phase2SteppingAction.h b/SimG4Core/Application/interface/Phase2SteppingAction.h index 446474f826c2a..9599014fc3c89 100644 --- a/SimG4Core/Application/interface/Phase2SteppingAction.h +++ b/SimG4Core/Application/interface/Phase2SteppingAction.h @@ -3,6 +3,7 @@ #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "SimG4Core/Notification/interface/SimActivityRegistry.h" +#include "SimG4Core/Application/interface/SteppingTrackStatus.h" #include "G4LogicalVolume.hh" #include "G4Region.hh" @@ -16,18 +17,6 @@ class CMSSteppingVerbose; -enum TrackStatus { - sAlive = 0, - sKilledByProcess = 1, - sDeadRegion = 2, - sOutOfTime = 3, - sLowEnergy = 4, - sLowEnergyInVacuum = 5, - sEnergyDepNaN = 6, - sVeryForward = 7, - sNumberOfSteps = 8 -}; - class Phase2SteppingAction : public G4UserSteppingAction { public: explicit Phase2SteppingAction(const CMSSteppingVerbose*, const edm::ParameterSet&, bool hasW); diff --git a/SimG4Core/Application/interface/RunManagerMT.h b/SimG4Core/Application/interface/RunManagerMT.h index 3c77481355473..f2481c3fafa18 100644 --- a/SimG4Core/Application/interface/RunManagerMT.h +++ b/SimG4Core/Application/interface/RunManagerMT.h @@ -77,6 +77,8 @@ class RunManagerMT { // need a non-const pointer. Thread-safety is handled inside Geant4. inline PhysicsList* physicsListForWorker() const { return m_physicsList.get(); } + inline bool isPhase2() const { return m_isPhase2; } + private: void terminateRun(); @@ -84,6 +86,8 @@ class RunManagerMT { void setupVoxels(); + void runForPhase2(); + G4MTRunManagerKernel* m_kernel; CustomUIsession* m_UIsession; @@ -100,6 +104,7 @@ class RunManagerMT { bool m_StorePhysicsTables; bool m_RestorePhysicsTables; bool m_check; + bool m_isPhase2{false}; edm::ParameterSet m_pPhysics; edm::ParameterSet m_pRunAction; edm::ParameterSet m_g4overlap; diff --git a/SimG4Core/Application/interface/RunManagerMTWorker.h b/SimG4Core/Application/interface/RunManagerMTWorker.h index a181483948ef3..bf424a76fb05a 100644 --- a/SimG4Core/Application/interface/RunManagerMTWorker.h +++ b/SimG4Core/Application/interface/RunManagerMTWorker.h @@ -35,6 +35,7 @@ class RunAction; class EventAction; class TrackingAction; class SteppingAction; +class Phase2SteppingAction; class CMSSteppingVerbose; class CMSSimEventManager; class G4Field; @@ -63,6 +64,7 @@ class RunManagerMTWorker { void Connect(EventAction*); void Connect(TrackingAction*); void Connect(SteppingAction*); + void Connect(Phase2SteppingAction*); SimTrackManager* GetSimTrackManager(); std::vector& sensTkDetectors(); @@ -99,6 +101,7 @@ class RunManagerMTWorker { bool m_LHCTransport{false}; bool m_dumpMF{false}; bool m_endOfRun{false}; + bool m_isPhase2{false}; const int m_thread_index{-1}; diff --git a/SimG4Core/Application/interface/SteppingAction.h b/SimG4Core/Application/interface/SteppingAction.h index 89915845e997b..f6eb04ab3a9fd 100644 --- a/SimG4Core/Application/interface/SteppingAction.h +++ b/SimG4Core/Application/interface/SteppingAction.h @@ -3,6 +3,7 @@ #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "SimG4Core/Notification/interface/SimActivityRegistry.h" +#include "SimG4Core/Application/interface/SteppingTrackStatus.h" #include "G4LogicalVolume.hh" #include "G4Region.hh" @@ -16,18 +17,6 @@ class CMSSteppingVerbose; -enum TrackStatus { - sAlive = 0, - sKilledByProcess = 1, - sDeadRegion = 2, - sOutOfTime = 3, - sLowEnergy = 4, - sLowEnergyInVacuum = 5, - sEnergyDepNaN = 6, - sVeryForward = 7, - sNumberOfSteps = 8 -}; - class SteppingAction : public G4UserSteppingAction { public: explicit SteppingAction(const CMSSteppingVerbose*, const edm::ParameterSet&, bool hasW); @@ -48,7 +37,6 @@ class SteppingAction : public G4UserSteppingAction { const G4VPhysicalVolume* tracker{nullptr}; const G4VPhysicalVolume* calo{nullptr}; - const G4VPhysicalVolume* btl{nullptr}; const CMSSteppingVerbose* steppingVerbose; double theCriticalEnergyForVacuum; double theCriticalDensity; diff --git a/SimG4Core/Application/interface/SteppingTrackStatus.h b/SimG4Core/Application/interface/SteppingTrackStatus.h new file mode 100644 index 0000000000000..fadef2f8cb1b2 --- /dev/null +++ b/SimG4Core/Application/interface/SteppingTrackStatus.h @@ -0,0 +1,16 @@ +#ifndef SimG4Core_SteppingTrackStatus_H +#define SimG4Core_SteppingTrackStatus_H + +enum TrackStatus { + sAlive = 0, + sKilledByProcess = 1, + sDeadRegion = 2, + sOutOfTime = 3, + sLowEnergy = 4, + sLowEnergyInVacuum = 5, + sEnergyDepNaN = 6, + sVeryForward = 7, + sNumberOfSteps = 8 +}; + +#endif diff --git a/SimG4Core/Application/src/CMSSimEventManager.cc b/SimG4Core/Application/src/CMSSimEventManager.cc index bd5962fb3b91d..21166b0fcfef4 100644 --- a/SimG4Core/Application/src/CMSSimEventManager.cc +++ b/SimG4Core/Application/src/CMSSimEventManager.cc @@ -3,7 +3,6 @@ #include "SimG4Core/Application/interface/EventAction.h" #include "SimG4Core/Application/interface/StackingAction.h" #include "SimG4Core/Application/interface/TrackingAction.h" -#include "SimG4Core/Application/interface/SteppingAction.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" @@ -14,6 +13,7 @@ #include "G4PrimaryTransformer.hh" #include "G4TrackingManager.hh" #include "G4TrackStatus.hh" +#include "G4UserSteppingAction.hh" #include "G4SDManager.hh" #include "G4StateManager.hh" @@ -107,6 +107,4 @@ void CMSSimEventManager::SetUserAction(TrackingAction* ptr) { m_defTrackManager->SetUserAction((G4UserTrackingAction*)ptr); } -void CMSSimEventManager::SetUserAction(SteppingAction* ptr) { - m_defTrackManager->SetUserAction((G4UserSteppingAction*)ptr); -} +void CMSSimEventManager::SetUserAction(G4UserSteppingAction* ptr) { m_defTrackManager->SetUserAction(ptr); } diff --git a/SimG4Core/Application/src/RunManagerMT.cc b/SimG4Core/Application/src/RunManagerMT.cc index edc44244badaf..1322351d0cdfd 100644 --- a/SimG4Core/Application/src/RunManagerMT.cc +++ b/SimG4Core/Application/src/RunManagerMT.cc @@ -250,6 +250,7 @@ void RunManagerMT::initG4(const DDCompactView* pDD, // G4Region dump file name auto regionFile = m_p.getUntrackedParameter("FileNameRegions", ""); + runForPhase2(); // Geometry checks if (m_check || !regionFile.empty()) { @@ -357,3 +358,14 @@ void RunManagerMT::setupVoxels() { edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMT: default voxel density=" << density << "; number of regions with special density " << nr; } + +void RunManagerMT::runForPhase2() { + const G4RegionStore* regStore = G4RegionStore::GetInstance(); + for (auto& r : *regStore) { + const G4String& name = r->GetName(); + if (name == "HGCalRegion" || name == "FastTimerRegionETL" || name == "FastTimerRegionBTL") { + m_isPhase2 = true; + break; + } + } +} diff --git a/SimG4Core/Application/src/RunManagerMTWorker.cc b/SimG4Core/Application/src/RunManagerMTWorker.cc index c4bb6c944c2e1..3528a03d09918 100644 --- a/SimG4Core/Application/src/RunManagerMTWorker.cc +++ b/SimG4Core/Application/src/RunManagerMTWorker.cc @@ -6,6 +6,7 @@ #include "SimG4Core/Application/interface/StackingAction.h" #include "SimG4Core/Application/interface/TrackingAction.h" #include "SimG4Core/Application/interface/SteppingAction.h" +#include "SimG4Core/Application/interface/Phase2SteppingAction.h" #include "SimG4Core/Application/interface/CMSSimEventManager.h" #include "SimG4Core/Application/interface/CustomUIsessionThreadPrefix.h" #include "SimG4Core/Application/interface/CustomUIsessionToFile.h" @@ -56,6 +57,7 @@ #include "G4Field.hh" #include "G4FieldManager.hh" #include "G4ScoringManager.hh" +#include "G4UserSteppingAction.hh" #include #include @@ -340,6 +342,7 @@ void RunManagerMTWorker::initializeG4(RunManagerMT* runManagerMaster, const edm: // Set the physics list for the worker, share from master PhysicsList* physicsList = runManagerMaster->physicsListForWorker(); + m_isPhase2 = runManagerMaster->isPhase2(); edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMTWorker::InitializeG4: start initialisation of PhysicsList for the thread " << thisID; @@ -415,8 +418,17 @@ void RunManagerMTWorker::initializeUserActions() { m_evtManager->SetUserAction(userTrackingAction); } - auto userSteppingAction = new SteppingAction(m_sVerbose.get(), m_pSteppingAction, m_hasWatchers); - Connect(userSteppingAction); + // different stepping actions for Run2,3 and Phase2 + G4UserSteppingAction* userSteppingAction; + if (m_isPhase2) { + auto ptr = new Phase2SteppingAction(m_sVerbose.get(), m_pSteppingAction, m_hasWatchers); + Connect(ptr); + userSteppingAction = (G4UserSteppingAction*)ptr; + } else { + auto ptr = new SteppingAction(m_sVerbose.get(), m_pSteppingAction, m_hasWatchers); + Connect(ptr); + userSteppingAction = (G4UserSteppingAction*)ptr; + } if (m_UseG4EventManager) { eventManager->SetUserAction(userSteppingAction); } else { @@ -450,6 +462,10 @@ void RunManagerMTWorker::Connect(SteppingAction* steppingAction) { steppingAction->m_g4StepSignal.connect(m_tls->registry->g4StepSignal_); } +void RunManagerMTWorker::Connect(Phase2SteppingAction* steppingAction) { + steppingAction->m_g4StepSignal.connect(m_tls->registry->g4StepSignal_); +} + SimTrackManager* RunManagerMTWorker::GetSimTrackManager() { initializeTLS(); return m_tls->trackManager.get(); diff --git a/SimG4Core/Application/src/SteppingAction.cc b/SimG4Core/Application/src/SteppingAction.cc index c9ea781702bce..10b39543770e2 100644 --- a/SimG4Core/Application/src/SteppingAction.cc +++ b/SimG4Core/Application/src/SteppingAction.cc @@ -158,39 +158,10 @@ void SteppingAction::UserSteppingAction(const G4Step* aStep) { } } } - // check transition tracker/btl and tracker/calo + // check transition tracker/calo bool isKilled = false; if (sAlive == tstat || sVeryForward == tstat) { - // store TrackInformation about transition from one envelope to another - if (preStep->GetPhysicalVolume() == tracker && postStep->GetPhysicalVolume() == btl) { - // store transition tracker -> BTL only for tracks entering BTL for the first time - TrackInformation* trkinfo = static_cast(theTrack->GetUserInformation()); - if (!trkinfo->isFromTtoBTL() && !trkinfo->isFromBTLtoT()) { - trkinfo->setFromTtoBTL(); - trkinfo->setIdAtBTLentrance(theTrack->GetTrackID()); -#ifdef DebugLog - LogDebug("SimG4CoreApplication") << "Setting flag for Tracker -> BTL " << trkinfo->isFromTtoBTL() - << " IdAtBTLentrance = " << trkinfo->idAtBTLentrance(); -#endif - } else { - trkinfo->setBTLlooper(); - trkinfo->setIdAtBTLentrance(theTrack->GetTrackID()); -#ifdef DebugLog - LogDebug("SimG4CoreApplication") << "Setting flag for BTL looper " << trkinfo->isBTLlooper(); - trkinfo->Print(); -#endif - } - } else if (preStep->GetPhysicalVolume() == btl && postStep->GetPhysicalVolume() == tracker) { - // store transition BTL -> tracker - TrackInformation* trkinfo = static_cast(theTrack->GetUserInformation()); - if (!trkinfo->isFromBTLtoT()) { - trkinfo->setFromBTLtoT(); -#ifdef DebugLog - LogDebug("SimG4CoreApplication") << "Setting flag for BTL -> Tracker " << trkinfo->isFromBTLtoT(); -#endif - } - } else if (preStep->GetPhysicalVolume() == tracker && postStep->GetPhysicalVolume() == calo) { - // store transition tracker -> calo + if (preStep->GetPhysicalVolume() == tracker && postStep->GetPhysicalVolume() == calo) { TrackInformation* trkinfo = static_cast(theTrack->GetUserInformation()); if (!trkinfo->crossedBoundary()) { trkinfo->setCrossedBoundary(theTrack); @@ -233,14 +204,12 @@ bool SteppingAction::initPointer() { tracker = pvcite; } else if (pvname == "CALO" || pvname == "caloBase:CALO_1") { calo = pvcite; - } else if (pvname == "BarrelTimingLayer" || pvname == "btl:BarrelTimingLayer_1") { - btl = pvcite; } - if (tracker && calo && btl) + if (tracker && calo) break; } edm::LogVerbatim("SimG4CoreApplication") - << "SteppingAction: pointer for Tracker " << tracker << " and for Calo " << calo << " and for BTL " << btl; + << "SteppingAction: pointer for Tracker " << tracker << " and for Calo " << calo; const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance(); if (numberEkins > 0) {