Geant4 VMC
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
source
event
src
TG4EventAction.cxx
Go to the documentation of this file.
1
//------------------------------------------------
2
// The Geant4 Virtual Monte Carlo package
3
// Copyright (C) 2007 - 2014 Ivana Hrivnacova
4
// All rights reserved.
5
//
6
// For the licensing terms see geant4_vmc/LICENSE.
7
// Contact: root-vmc@cern.ch
8
//-------------------------------------------------
9
14
15
#include "
TG4EventAction.h
"
16
#include "
TG4Globals.h
"
17
#include "
TG4ParticlesManager.h
"
18
#include "
TG4SDServices.h
"
19
#include "
TG4StateManager.h
"
20
#include "
TG4TrackManager.h
"
21
#include "
TG4TrackingAction.h
"
22
23
#include <G4Version.hh>
24
#if G4VERSION_NUMBER == 1100
25
// Temporary work-around for bug in Cerenkov
26
#include "
TG4PhysicsManager.h
"
27
#endif
28
29
#include <G4Event.hh>
30
#include <G4Trajectory.hh>
31
#include <G4TrajectoryContainer.hh>
32
#include <G4UImanager.hh>
33
#include <G4VVisManager.hh>
34
#include <Randomize.hh>
35
36
#include <RVersion.h>
37
#include <TSystem.h>
38
#include <TVirtualMC.h>
39
#include <TVirtualMCApplication.h>
40
#include <TVirtualMCSensitiveDetector.h>
41
#include <TVirtualMCStack.h>
42
43
#include <math.h>
44
45
//_____________________________________________________________________________
46
TG4EventAction::TG4EventAction
()
47
:
TG4Verbose
(
"eventAction"
),
48
fMessenger
(this),
49
fTimer
(),
50
fMCApplication
(0),
51
fMCStack
(0),
52
fTrackingAction
(0),
53
fTrackManager
(0),
54
fStateManager
(0),
55
fPrintMemory
(false),
56
fSaveRandomStatus
(false),
57
fIsInterruptibleEvent
(false)
58
{
60
}
61
62
//_____________________________________________________________________________
63
TG4EventAction::~TG4EventAction
()
64
{
66
}
67
68
//
69
// public methods
70
//
71
72
//_____________________________________________________________________________
73
void
TG4EventAction::LateInitialize
()
74
{
76
77
fMCApplication
= TVirtualMCApplication::Instance();
78
fTrackingAction
=
TG4TrackingAction::Instance
();
79
fTrackManager
=
TG4TrackManager::Instance
();
80
fStateManager
=
TG4StateManager::Instance
();
81
}
82
83
//_____________________________________________________________________________
84
void
TG4EventAction::BeginOfEventAction
(
const
G4Event* event)
85
{
87
88
#if G4VERSION_NUMBER == 1100
89
// Temporary work-around for bug in Cerenkov
90
static
G4ThreadLocal
auto
applyCerenkovFix =
true
;
91
if
(applyCerenkovFix) {
92
TG4PhysicsManager::Instance
()->ApplyCerenkovMaxBetaChangeValue();
93
applyCerenkovFix =
false
;
94
}
95
#endif
96
97
// reset the tracks counters
98
fTrackingAction
->PrepareNewEvent();
99
100
// fill primary particles in VMC stack if stack is empty
101
if
(
fMCStack
->GetNtrack() == 0) {
102
if
(
VerboseLevel
() > 0)
103
G4cout <<
"Filling VMC stack with primaries"
<< G4endl;
104
105
for
(G4int iv = 0; iv <
event
->GetNumberOfPrimaryVertex(); iv++) {
106
G4PrimaryVertex* vertex =
event
->GetPrimaryVertex(iv);
107
108
for
(G4int ip = 0; ip < vertex->GetNumberOfParticle(); ip++) {
109
G4PrimaryParticle* particle = vertex->GetPrimary(ip);
110
fTrackManager
->PrimaryToStack(vertex, particle);
111
}
112
}
113
}
114
115
// save the event random number status per event
116
if
(
fSaveRandomStatus
) {
117
G4UImanager::GetUIpointer()->ApplyCommand(
"/random/saveThisEvent"
);
118
if
(
VerboseLevel
() > 0) G4cout <<
"Saving random status: "
<< G4endl;
119
CLHEP::HepRandom::showEngineStatus();
120
G4cout << G4endl;
121
}
122
123
if
(
VerboseLevel
() > 0) {
124
G4cout <<
">>> Event "
<<
event
->GetEventID() << G4endl;
125
fTimer
.Start();
126
}
127
}
128
129
//_____________________________________________________________________________
130
void
TG4EventAction::EndOfEventAction
(
const
G4Event* event)
131
{
133
134
// finish the last primary track of the current event
135
// G4cout << "Finish primary from event action" << G4endl;
136
fTrackingAction
->FinishPrimaryTrack();
137
138
if
(
VerboseLevel
() > 1) {
139
G4cout << G4endl;
140
G4cout <<
">>> End of Event "
<<
event
->GetEventID() << G4endl;
141
}
142
143
if
(
VerboseLevel
() > 2) {
144
G4int nofPrimaryTracks =
fMCStack
->GetNprimary();
145
G4int nofSavedTracks =
fMCStack
->GetNtrack();
146
147
G4cout <<
" "
<< nofPrimaryTracks <<
" primary tracks processed."
148
<< G4endl;
149
G4cout <<
" "
<< nofSavedTracks <<
" tracks saved."
<< G4endl;
150
151
G4int nofAllTracks =
fTrackManager
->GetNofTracks();
152
G4cout <<
" "
<< nofAllTracks <<
" all tracks processed."
<< G4endl;
153
}
154
155
#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 18, 0)
156
// VMC application end of event
157
fMCApplication
->EndOfEvent();
158
#endif
159
160
// User SDs finish event
161
if
(
TG4SDServices::Instance
()->GetUserSDs()) {
162
for
(
auto
& userSD : (*
TG4SDServices::Instance
()->GetUserSDs())) {
163
userSD->EndOfEvent();
164
}
165
}
166
167
// VMC application finish event
168
if
(!
fIsInterruptibleEvent
) {
169
fMCApplication
->FinishEvent();
170
}
171
fStateManager
->SetNewState(
kNotInApplication
);
172
173
if
(
VerboseLevel
() > 1) {
174
// print time
175
fTimer
.Stop();
176
fTimer
.Print();
177
}
178
179
if
(
fPrintMemory
) {
180
ProcInfo_t procInfo;
181
gSystem->GetProcInfo(&procInfo);
182
G4cout <<
"Current memory usage: resident "
<< procInfo.fMemResident
183
<<
", virtual "
<< procInfo.fMemVirtual << G4endl;
184
}
185
}
TG4EventAction.h
Definition of the TG4EventAction class.
TG4Globals.h
Definition of the TG4Globals class and basic container types.
TG4ParticlesManager.h
Definition of the TG4ParticlesManager class.
TG4PhysicsManager.h
Definition of the TG4PhysicsManager class.
TG4SDServices.h
Definition of the TG4SDServices class.
TG4StateManager.h
Definition of the TG4StateManager class.
TG4TrackManager.h
Definition of the TG4TrackManager class.
TG4TrackingAction.h
Definition of the TG4TrackingAction class.
TG4EventAction::fIsInterruptibleEvent
G4bool fIsInterruptibleEvent
Definition
TG4EventAction.h:96
TG4EventAction::BeginOfEventAction
virtual void BeginOfEventAction(const G4Event *event)
Definition
TG4EventAction.cxx:84
TG4EventAction::fSaveRandomStatus
G4bool fSaveRandomStatus
Control for saving random engine status for each event.
Definition
TG4EventAction.h:91
TG4EventAction::TG4EventAction
TG4EventAction()
Definition
TG4EventAction.cxx:46
TG4EventAction::fTrackingAction
TG4TrackingAction * fTrackingAction
Cached pointer to thread-local tracking action.
Definition
TG4EventAction.h:79
TG4EventAction::fMCApplication
TVirtualMCApplication * fMCApplication
Cached pointer to thread-local VMC application.
Definition
TG4EventAction.h:73
TG4EventAction::fPrintMemory
G4bool fPrintMemory
Control for printing memory usage.
Definition
TG4EventAction.h:88
TG4EventAction::fTimer
TStopwatch fTimer
timer
Definition
TG4EventAction.h:70
TG4EventAction::fMessenger
TG4EventActionMessenger fMessenger
messenger
Definition
TG4EventAction.h:69
TG4EventAction::fMCStack
TVirtualMCStack * fMCStack
Cached pointer to thread-local VMC stack.
Definition
TG4EventAction.h:76
TG4EventAction::LateInitialize
void LateInitialize()
Definition
TG4EventAction.cxx:73
TG4EventAction::fStateManager
TG4StateManager * fStateManager
Cached pointer to thread-local state manager.
Definition
TG4EventAction.h:85
TG4EventAction::EndOfEventAction
virtual void EndOfEventAction(const G4Event *event)
Definition
TG4EventAction.cxx:130
TG4EventAction::fTrackManager
TG4TrackManager * fTrackManager
Cached pointer to thread-local track manager.
Definition
TG4EventAction.h:82
TG4EventAction::~TG4EventAction
virtual ~TG4EventAction()
Definition
TG4EventAction.cxx:63
TG4PhysicsManager::Instance
static TG4PhysicsManager * Instance()
Definition
TG4PhysicsManager.h:180
TG4SDServices::Instance
static TG4SDServices * Instance()
Definition
TG4SDServices.h:120
TG4StateManager::Instance
static TG4StateManager * Instance()
Definition
TG4StateManager.h:61
TG4TrackManager::Instance
static TG4TrackManager * Instance()
Definition
TG4TrackManager.h:135
TG4TrackingAction::Instance
static TG4TrackingAction * Instance()
Definition
TG4TrackingAction.h:138
TG4Verbose::VerboseLevel
virtual G4int VerboseLevel() const
Definition
TG4Verbose.h:78
TG4Verbose::TG4Verbose
TG4Verbose(const G4String &cmdName)
Definition
TG4Verbose.cxx:24
kNotInApplication
@ kNotInApplication
not in VMC application
Definition
TG4ApplicationState.h:32
Generated on
for Geant4 VMC by
1.17.0