Skip to content

Commit 6ef9d3f

Browse files
committed
split run2,3 and Run4
1 parent 69e3d47 commit 6ef9d3f

12 files changed

+373
-46
lines changed

SimG4Core/Application/interface/CMSSimEventManager.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ namespace edm {
1818
}
1919

2020
class G4Event;
21-
class EventAction;
22-
class StackingAction;
23-
class TrackingAction;
21+
class G4UserEventAction;
22+
class G4UserStackingAction;
23+
class G4UserTrackingAction;
2424
class G4UserSteppingAction;
2525
class G4SDManager;
2626
class G4StateManager;
@@ -41,9 +41,9 @@ class CMSSimEventManager {
4141
// This method aborts the processing of the current event.
4242
void AbortCurrentEvent();
4343

44-
void SetUserAction(EventAction* ptr);
45-
void SetUserAction(StackingAction* ptr);
46-
void SetUserAction(TrackingAction* ptr);
44+
void SetUserAction(G4UserEventAction* ptr);
45+
void SetUserAction(G4UserStackingAction* ptr);
46+
void SetUserAction(G4UserTrackingAction* ptr);
4747
void SetUserAction(G4UserSteppingAction* ptr);
4848

4949
CMSSimEventManager(const CMSSimEventManager& right) = delete;
@@ -58,9 +58,9 @@ class CMSSimEventManager {
5858
G4PrimaryTransformer* m_primaryTransformer;
5959
G4Navigator* m_navigator;
6060

61-
EventAction* m_eventAction;
62-
StackingAction* m_stackingAction;
63-
TrackingAction* m_trackingAction;
61+
G4UserEventAction* m_eventAction;
62+
G4UserTrackingAction* m_trackingAction;
63+
G4UserStackingAction* m_stackingAction;
6464

6565
G4int trackID_{0};
6666
G4int verbose_;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#ifndef SimG4Core_Phase2EventAction_H
2+
#define SimG4Core_Phase2EventAction_H
3+
//
4+
// Package: Application
5+
// Class : Phase2EventAction
6+
//
7+
// Description: Manage MC truth
8+
// Created: 08.04.2025 V.Ivantchenko
9+
//
10+
11+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
12+
13+
#include "SimG4Core/Notification/interface/SimTrackManager.h"
14+
#include "SimG4Core/Notification/interface/TrackWithHistory.h"
15+
#include "SimG4Core/Notification/interface/TrackContainer.h"
16+
#include "SimG4Core/Notification/interface/SimActivityRegistry.h"
17+
18+
#include "G4UserEventAction.hh"
19+
20+
#include <vector>
21+
#include <string>
22+
23+
class SimRunInterface;
24+
class BeginOfEvent;
25+
class EndOfEvent;
26+
class CMSSteppingVerbose;
27+
28+
class Phase2EventAction : public G4UserEventAction {
29+
public:
30+
explicit Phase2EventAction(const edm::ParameterSet& ps, SimRunInterface*, SimTrackManager*, CMSSteppingVerbose*);
31+
~Phase2EventAction() override = default;
32+
33+
void BeginOfEventAction(const G4Event* evt) override;
34+
void EndOfEventAction(const G4Event* evt) override;
35+
36+
void abortEvent();
37+
38+
const TrackContainer* trackContainer() const { return m_trackManager->trackContainer(); }
39+
40+
TrackWithHistory* getTrackByID(int id) const { return m_trackManager->getTrackByID(id); }
41+
42+
SimActivityRegistry::BeginOfEventSignal m_beginOfEventSignal;
43+
SimActivityRegistry::EndOfEventSignal m_endOfEventSignal;
44+
45+
Phase2EventAction(const Phase2EventAction&) = delete;
46+
const Phase2EventAction& operator=(const Phase2EventAction&) = delete;
47+
48+
private:
49+
SimRunInterface* m_runInterface;
50+
SimTrackManager* m_trackManager;
51+
CMSSteppingVerbose* m_SteppingVerbose;
52+
std::string m_stopFile;
53+
bool m_printRandom;
54+
bool m_debug;
55+
};
56+
57+
#endif
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#ifndef SimG4Core_Phase2TrackingAction_H
2+
#define SimG4Core_Phase2TrackingAction_H
3+
//
4+
// Package: Application
5+
// Class : Phase2TrackingAction
6+
//
7+
// Description: Manage tracks
8+
// Created: 08.04.2025 V.Ivantchenko
9+
//
10+
11+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
12+
#include "SimG4Core/Notification/interface/SimActivityRegistry.h"
13+
14+
#include "G4UserTrackingAction.hh"
15+
#include "G4Region.hh"
16+
17+
#include <vector>
18+
19+
class SimTrackManager;
20+
class CMSG4TrackInterface;
21+
class TrackWithHistory;
22+
class BeginOfTrack;
23+
class EndOfTrack;
24+
class CMSSteppingVerbose;
25+
class TrackInformation;
26+
27+
class Phase2TrackingAction : public G4UserTrackingAction {
28+
public:
29+
explicit Phase2TrackingAction(SimTrackManager*, CMSSteppingVerbose*, const edm::ParameterSet& ps);
30+
~Phase2TrackingAction() override = default;
31+
32+
void PreUserTrackingAction(const G4Track* aTrack) override;
33+
void PostUserTrackingAction(const G4Track* aTrack) override;
34+
35+
inline TrackWithHistory* currentTrackWithHistory() { return currentTrack_; }
36+
inline const G4Track* geant4Track() const { return g4Track_; }
37+
inline G4TrackingManager* getTrackManager() { return fpTrackingManager; }
38+
39+
SimActivityRegistry::BeginOfTrackSignal m_beginOfTrackSignal;
40+
SimActivityRegistry::EndOfTrackSignal m_endOfTrackSignal;
41+
42+
Phase2TrackingAction(Phase2TrackingAction&) = delete;
43+
Phase2TrackingAction& operator=(const Phase2TrackingAction& right) = delete;
44+
45+
private:
46+
SimTrackManager* trackManager_;
47+
CMSG4TrackInterface* trackInterface_;
48+
CMSSteppingVerbose* steppingVerbose_;
49+
const G4Track* g4Track_ = nullptr;
50+
TrackInformation* trkInfo_ = nullptr;
51+
TrackWithHistory* currentTrack_ = nullptr;
52+
int endPrintTrackID_;
53+
bool checkTrack_;
54+
bool doFineCalo_;
55+
bool saveCaloBoundaryInformation_;
56+
double ekinMin_;
57+
std::vector<double> ekinMinRegion_;
58+
std::vector<G4Region*> ptrRegion_;
59+
};
60+
61+
#endif

SimG4Core/Application/interface/RunManagerMTWorker.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class CustomUIsession;
3636

3737
class RunAction;
3838
class EventAction;
39+
class Phase2EventAction;
3940
class TrackingAction;
41+
class Phase2TrackingAction;
4042
class SteppingAction;
4143
class Phase2SteppingAction;
4244
class CMSSteppingVerbose;
@@ -65,7 +67,9 @@ class RunManagerMTWorker {
6567

6668
void Connect(RunAction*);
6769
void Connect(EventAction*);
70+
void Connect(Phase2EventAction*);
6871
void Connect(TrackingAction*);
72+
void Connect(Phase2TrackingAction*);
6973
void Connect(SteppingAction*);
7074
void Connect(Phase2SteppingAction*);
7175

SimG4Core/Application/interface/StackingAction.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
class TrackingAction;
1515
class CMSSteppingVerbose;
1616
class G4VProcess;
17+
class CMSG4TrackInterface;
1718

1819
class StackingAction : public G4UserStackingAction {
1920
public:
20-
explicit StackingAction(const TrackingAction*, const edm::ParameterSet& ps, const CMSSteppingVerbose*);
21+
explicit StackingAction(const edm::ParameterSet& ps, const CMSSteppingVerbose*);
2122

2223
~StackingAction() override = default;
2324

@@ -69,7 +70,7 @@ class StackingAction : public G4UserStackingAction {
6970
std::vector<const G4Region*> deadRegions;
7071

7172
G4VSolid* worldSolid;
72-
const TrackingAction* trackAction;
73+
CMSG4TrackInterface* m_trackInterface;
7374
const CMSSteppingVerbose* steppingVerbose;
7475
const G4VProcess* m_Compton{nullptr};
7576

SimG4Core/Application/src/CMSSimEventManager.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#include "SimG4Core/Application/interface/CMSSimEventManager.h"
22
#include "SimG4Core/Application/interface/RunAction.h"
3-
#include "SimG4Core/Application/interface/EventAction.h"
4-
#include "SimG4Core/Application/interface/StackingAction.h"
5-
#include "SimG4Core/Application/interface/TrackingAction.h"
63

74
#include "FWCore/ParameterSet/interface/ParameterSet.h"
85
#include "FWCore/MessageLogger/interface/MessageLogger.h"
@@ -13,7 +10,10 @@
1310
#include "G4PrimaryTransformer.hh"
1411
#include "G4TrackingManager.hh"
1512
#include "G4TrackStatus.hh"
13+
#include "G4UserEventAction.hh"
14+
#include "G4UserTrackingAction.hh"
1615
#include "G4UserSteppingAction.hh"
16+
#include "G4UserStackingAction.hh"
1717

1818
#include "G4SDManager.hh"
1919
#include "G4StateManager.hh"
@@ -98,13 +98,13 @@ void CMSSimEventManager::StackTracks(G4TrackVector* trackVector, bool IDisSet) {
9898
trackVector->clear();
9999
}
100100

101-
void CMSSimEventManager::SetUserAction(EventAction* ptr) { m_eventAction = ptr; }
101+
void CMSSimEventManager::SetUserAction(G4UserEventAction* ptr) { m_eventAction = ptr; }
102102

103-
void CMSSimEventManager::SetUserAction(StackingAction* ptr) { m_stackingAction = ptr; }
103+
void CMSSimEventManager::SetUserAction(G4UserStackingAction* ptr) { m_stackingAction = ptr; }
104104

105-
void CMSSimEventManager::SetUserAction(TrackingAction* ptr) {
105+
void CMSSimEventManager::SetUserAction(G4UserTrackingAction* ptr) {
106106
m_trackingAction = ptr;
107-
m_defTrackManager->SetUserAction((G4UserTrackingAction*)ptr);
107+
m_defTrackManager->SetUserAction(ptr);
108108
}
109109

110110
void CMSSimEventManager::SetUserAction(G4UserSteppingAction* ptr) { m_defTrackManager->SetUserAction(ptr); }
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include "SimG4Core/Application/interface/Phase2EventAction.h"
2+
#include "SimG4Core/Application/interface/SimRunInterface.h"
3+
#include "SimG4Core/Notification/interface/TmpSimEvent.h"
4+
#include "SimG4Core/Notification/interface/TmpSimVertex.h"
5+
#include "SimG4Core/Notification/interface/BeginOfEvent.h"
6+
#include "SimG4Core/Notification/interface/EndOfEvent.h"
7+
#include "SimG4Core/Notification/interface/CMSSteppingVerbose.h"
8+
9+
#include "FWCore/MessageLogger/interface/MessageLogger.h"
10+
11+
#include "Randomize.hh"
12+
13+
Phase2EventAction::Phase2EventAction(const edm::ParameterSet& p,
14+
SimRunInterface* rm,
15+
SimTrackManager* iManager,
16+
CMSSteppingVerbose* sv)
17+
: m_runInterface(rm),
18+
m_trackManager(iManager),
19+
m_SteppingVerbose(sv),
20+
m_stopFile(p.getParameter<std::string>("StopFile")),
21+
m_printRandom(p.getParameter<bool>("PrintRandomSeed")),
22+
m_debug(p.getUntrackedParameter<bool>("debug", false)) {}
23+
24+
void Phase2EventAction::BeginOfEventAction(const G4Event* anEvent) {
25+
BeginOfEvent e(anEvent);
26+
m_beginOfEventSignal(&e);
27+
28+
if (m_printRandom) {
29+
edm::LogVerbatim("SimG4CoreApplication")
30+
<< "BeginOfEvent " << anEvent->GetEventID() << " Random number: " << G4UniformRand();
31+
}
32+
33+
if (nullptr != m_SteppingVerbose) {
34+
m_SteppingVerbose->beginOfEvent(anEvent);
35+
}
36+
}
37+
38+
void Phase2EventAction::EndOfEventAction(const G4Event* anEvent) {
39+
if (m_printRandom) {
40+
edm::LogVerbatim("SimG4CoreApplication")
41+
<< "Phase2EventAction::EndOfEventAction: " << anEvent->GetEventID() << " Random number: " << G4UniformRand();
42+
}
43+
if (!m_stopFile.empty() && std::ifstream(m_stopFile.c_str())) {
44+
edm::LogWarning("SimG4CoreApplication")
45+
<< "Phase2EventAction::EndOfEventAction: termination signal received at event " << anEvent->GetEventID();
46+
// soft abort run
47+
m_runInterface->abortRun(true);
48+
}
49+
if (anEvent->GetNumberOfPrimaryVertex() == 0) {
50+
edm::LogWarning("SimG4CoreApplication") << "Phase2EventACtion::EndOfEventAction: event " << anEvent->GetEventID()
51+
<< " must have failed (no G4PrimaryVertices found) and will be skipped";
52+
return;
53+
}
54+
55+
m_trackManager->storeTracks();
56+
57+
// dispatch now end of event
58+
EndOfEvent e(anEvent);
59+
m_endOfEventSignal(&e);
60+
61+
// delete transient objects
62+
m_trackManager->reset();
63+
}
64+
65+
void Phase2EventAction::abortEvent() { m_runInterface->abortEvent(); }

0 commit comments

Comments
 (0)