Skip to content

Commit

Permalink
Merge pull request #41404 from civanch/stepping_action_for_phase2
Browse files Browse the repository at this point in the history
Different Geant4 SteppingActions for Run3 and Phase2
  • Loading branch information
cmsbuild authored Apr 26, 2023
2 parents 0c3a8c6 + 1b6d40f commit 0d81be4
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 68 deletions.
4 changes: 2 additions & 2 deletions SimG4Core/Application/interface/CMSSimEventManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class G4Event;
class EventAction;
class StackingAction;
class TrackingAction;
class SteppingAction;
class G4UserSteppingAction;
class G4SDManager;
class G4StateManager;
class G4PrimaryTransformer;
Expand All @@ -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;
Expand Down
13 changes: 1 addition & 12 deletions SimG4Core/Application/interface/Phase2SteppingAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions SimG4Core/Application/interface/RunManagerMT.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ 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();

void checkVoxels();

void setupVoxels();

void runForPhase2();

G4MTRunManagerKernel* m_kernel;

CustomUIsession* m_UIsession;
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions SimG4Core/Application/interface/RunManagerMTWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class RunAction;
class EventAction;
class TrackingAction;
class SteppingAction;
class Phase2SteppingAction;
class CMSSteppingVerbose;
class CMSSimEventManager;
class G4Field;
Expand Down Expand Up @@ -63,6 +64,7 @@ class RunManagerMTWorker {
void Connect(EventAction*);
void Connect(TrackingAction*);
void Connect(SteppingAction*);
void Connect(Phase2SteppingAction*);

SimTrackManager* GetSimTrackManager();
std::vector<SensitiveTkDetector*>& sensTkDetectors();
Expand Down Expand Up @@ -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};

Expand Down
14 changes: 1 addition & 13 deletions SimG4Core/Application/interface/SteppingAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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);
Expand All @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions SimG4Core/Application/interface/SteppingTrackStatus.h
Original file line number Diff line number Diff line change
@@ -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
6 changes: 2 additions & 4 deletions SimG4Core/Application/src/CMSSimEventManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -14,6 +13,7 @@
#include "G4PrimaryTransformer.hh"
#include "G4TrackingManager.hh"
#include "G4TrackStatus.hh"
#include "G4UserSteppingAction.hh"

#include "G4SDManager.hh"
#include "G4StateManager.hh"
Expand Down Expand Up @@ -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); }
12 changes: 12 additions & 0 deletions SimG4Core/Application/src/RunManagerMT.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ void RunManagerMT::initG4(const DDCompactView* pDD,

// G4Region dump file name
auto regionFile = m_p.getUntrackedParameter<std::string>("FileNameRegions", "");
runForPhase2();

// Geometry checks
if (m_check || !regionFile.empty()) {
Expand Down Expand Up @@ -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;
}
}
}
20 changes: 18 additions & 2 deletions SimG4Core/Application/src/RunManagerMTWorker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -56,6 +57,7 @@
#include "G4Field.hh"
#include "G4FieldManager.hh"
#include "G4ScoringManager.hh"
#include "G4UserSteppingAction.hh"

#include <atomic>
#include <memory>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
39 changes: 4 additions & 35 deletions SimG4Core/Application/src/SteppingAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<TrackInformation*>(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<TrackInformation*>(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<TrackInformation*>(theTrack->GetUserInformation());
if (!trkinfo->crossedBoundary()) {
trkinfo->setCrossedBoundary(theTrack);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0d81be4

Please sign in to comment.