Geant4 VMC
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
source
run
src
TG4RunAction.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 <G4Timer.hh>
16
// in order to avoid the odd dependency for the
17
// times system function this include must be the first
18
19
#include "
TG4Globals.h
"
20
#include "
TG4VRegionsManager.h
"
21
#include "
TG4RunAction.h
"
22
#include "
TGeant4.h
"
23
24
#include <G4AutoLock.hh>
25
#include <G4Electron.hh>
26
#include <G4Positron.hh>
27
#include <G4Run.hh>
28
#include <G4SystemOfUnits.hh>
29
#include <G4Threading.hh>
30
#include <G4Transportation.hh>
31
#include <G4Types.hh>
32
#include <G4UImanager.hh>
33
#include <Randomize.hh>
34
35
#include <TObjArray.h>
36
37
// mutex in a file scope
38
39
namespace
40
{
41
42
#ifdef G4MULTITHREADED
43
// Mutex to lock master application when merging data
44
G4Mutex mergeMutex = G4MUTEX_INITIALIZER;
45
#endif
46
47
G4Transportation* FindTransportation(
48
const
G4ParticleDefinition
* particleDefinition)
49
{
50
const
auto
* processManager = particleDefinition->GetProcessManager();
51
return
dynamic_cast<
G4Transportation*
>
(
52
processManager->GetProcess(
"Transportation"
));
53
}
54
55
}
// namespace
56
57
const
G4String
TG4RunAction::fgkDefaultRandomStatusFile
=
"currentRun.rndm"
;
58
59
//_____________________________________________________________________________
60
TG4RunAction::TG4RunAction
()
61
:
G4UserRunAction
(),
62
TG4Verbose
(
"runAction"
),
63
fMessenger
(this),
64
fCrossSectionManager
(),
65
fTimer
(0),
66
fRunID
(-1),
67
fSaveRandomStatus
(false),
68
fReadRandomStatus
(false),
69
fRandomStatusFile
(
fgkDefaultRandomStatusFile
),
70
fThresholdWarningEnergy
(-1.0),
71
fThresholdImportantEnergy
(-1.0),
72
fNumberOfThresholdTrials
(0)
73
{
75
76
if
(
VerboseLevel
() > 2)
77
G4cout <<
"TG4RunAction::TG4RunAction "
<<
this
<< G4endl;
78
79
fTimer
=
new
G4Timer;
80
}
81
82
//_____________________________________________________________________________
83
TG4RunAction::~TG4RunAction
()
84
{
86
87
if
(
VerboseLevel
() > 2)
88
G4cout <<
"TG4RunAction::~TG4RunAction "
<<
this
<< G4endl;
89
90
delete
fTimer
;
91
}
92
93
//
94
// private methods
95
//
96
97
//_____________________________________________________________________________
98
void
TG4RunAction::ChangeLooperParameters
(
99
const
G4ParticleDefinition
* particleDefinition)
100
{
101
// Nothing to be done if no parameters change
102
if
(
fThresholdWarningEnergy
< 0. &&
fThresholdImportantEnergy
< 0. &&
103
fNumberOfThresholdTrials
== 0) {
104
return
;
105
}
106
107
auto
* transportation = FindTransportation(particleDefinition);
108
if
(!transportation) {
109
TG4Globals::Warning
(
"TG4RunAction"
,
"ChangeLooperParameters"
,
110
"Cannot set parameters. Transportation process not found."
);
111
return
;
112
}
113
114
if
(
fThresholdWarningEnergy
>= 0.) {
115
if
(
VerboseLevel
() > 2) {
116
G4cout <<
"ChangeLooperParameters: ThresholdWarningEnergy [keV] = "
117
<<
fThresholdWarningEnergy
/ keV << G4endl;
118
}
119
transportation->SetThresholdWarningEnergy(
fThresholdWarningEnergy
);
120
}
121
122
if
(
fThresholdImportantEnergy
>= 0.) {
123
if
(
VerboseLevel
() > 2) {
124
G4cout <<
"ChangeLooperParameters: ThresholdImportantEnergy [keV] = "
125
<<
fThresholdImportantEnergy
/ keV << G4endl;
126
}
127
transportation->SetThresholdImportantEnergy(
fThresholdImportantEnergy
);
128
}
129
130
if
(
fNumberOfThresholdTrials
> 0) {
131
if
(
VerboseLevel
() > 2) {
132
G4cout <<
"ChangeLooperParameters: NumberOfThresholdTrials = "
133
<<
fNumberOfThresholdTrials
<< G4endl;
134
}
135
transportation->SetThresholdTrials(
fNumberOfThresholdTrials
);
136
}
137
}
138
139
//_____________________________________________________________________________
140
void
TG4RunAction::PrintLooperParameters
()
const
141
{
143
144
auto
transportation = FindTransportation(G4Electron::Definition());
145
if
(transportation) {
146
G4cout <<
"ThresholdWarningEnergy [MeV] = "
147
<< transportation->GetThresholdWarningEnergy() / MeV << G4endl;
148
G4cout <<
"ThresholdImportantEnergy [MeV] = "
149
<< transportation->GetThresholdImportantEnergy() / MeV << G4endl;
150
G4cout <<
"NumberOfThresholdTrials = "
151
<< transportation->GetThresholdTrials() << G4endl;
152
}
153
}
154
155
//
156
// public methods
157
//
158
159
//_____________________________________________________________________________
160
void
TG4RunAction::BeginOfRunAction
(
const
G4Run* run)
161
{
163
164
fRunID
++;
165
166
if
(
VerboseLevel
() > 0) {
167
G4cout <<
"### Run "
<< run->GetRunID() <<
" start."
<< G4endl;
168
}
169
170
auto
regionsManager =
TG4VRegionsManager::Instance
();
171
if
(regionsManager !=
nullptr
) {
172
if
(regionsManager->IsCheck()) {
173
regionsManager->CheckRegions();
174
}
175
if
(regionsManager->IsPrint()) {
176
regionsManager->PrintRegions(G4cout);
177
}
178
if
(regionsManager->IsSave()) {
179
regionsManager->SaveRegions();
180
}
181
}
182
183
// activate random number status
184
if
(
fSaveRandomStatus
) {
185
G4UImanager::GetUIpointer()->ApplyCommand(
"/random/setSavingFlag true"
);
186
if
(
VerboseLevel
() > 0)
187
G4cout <<
"Activated saving random status "
<< G4endl;
188
CLHEP::HepRandom::showEngineStatus();
189
G4cout << G4endl;
190
}
191
192
if
(
fReadRandomStatus
) {
193
// restore event random number status from a file
194
CLHEP::HepRandom::showEngineStatus();
195
G4String command(
"/random/resetEngineFrom "
);
196
command +=
fRandomStatusFile
;
197
G4UImanager::GetUIpointer()->ApplyCommand(command.data());
198
if
(
VerboseLevel
() > 0) {
199
G4cout <<
"Resetting random engine from "
<<
fRandomStatusFile
<< G4endl;
200
CLHEP::HepRandom::showEngineStatus();
201
G4cout << G4endl;
202
}
203
}
204
205
// set looper thresholds parameters
206
// (only if defaults are overriden by user)
207
ChangeLooperParameters
(G4Electron::Electron());
208
ChangeLooperParameters
(G4Positron::Positron());
209
210
// Print looping threshold parameters
211
if
(
VerboseLevel
() > 1) {
212
PrintLooperParameters
();
213
}
214
215
fTimer
->Start();
216
}
217
218
//_____________________________________________________________________________
219
void
TG4RunAction::EndOfRunAction
(
const
G4Run* run)
220
{
222
223
#ifdef G4MULTITHREADED
224
if
(! IsMaster()) {
225
// Merge user application data collected on workers to master
226
G4AutoLock lm(&mergeMutex);
227
TGeant4::MasterApplicationInstance
()->Merge(
228
TVirtualMCApplication::Instance());
229
lm.unlock();
230
}
231
#endif
232
233
if
(
fCrossSectionManager
.IsMakeHistograms()) {
234
fCrossSectionManager
.MakeHistograms();
235
}
236
237
fTimer
->Stop();
238
239
if
(
VerboseLevel
() > 0) {
240
G4cout <<
"Time of this run: "
<< *
fTimer
<< G4endl;
241
G4cout <<
"Number of events processed: "
<< run->GetNumberOfEvent()
242
<< G4endl;
243
}
244
}
TG4Globals.h
Definition of the TG4Globals class and basic container types.
TG4RunAction.h
Definition of the TG4RunAction class.
TG4VRegionsManager.h
Definition of the TG4VRegionsManager class.
TGeant4.h
Definition of the TGeant4 class.
G4ParticleDefinition
G4UserRunAction
TG4Globals::Warning
static void Warning(const TString &className, const TString &methodName, const TString &text)
Definition
TG4Globals.cxx:48
TG4RunAction::BeginOfRunAction
virtual void BeginOfRunAction(const G4Run *run)
Definition
TG4RunAction.cxx:160
TG4RunAction::fRandomStatusFile
G4String fRandomStatusFile
random engine status file name
Definition
TG4RunAction.h:74
TG4RunAction::fReadRandomStatus
G4bool fReadRandomStatus
control for reading random engine status
Definition
TG4RunAction.h:73
TG4RunAction::fNumberOfThresholdTrials
G4int fNumberOfThresholdTrials
Number of trials to propagate a looping track.
Definition
TG4RunAction.h:85
TG4RunAction::~TG4RunAction
virtual ~TG4RunAction()
Definition
TG4RunAction.cxx:83
TG4RunAction::fMessenger
TG4RunActionMessenger fMessenger
messenger
Definition
TG4RunAction.h:68
TG4RunAction::fRunID
G4int fRunID
run ID
Definition
TG4RunAction.h:71
TG4RunAction::fThresholdWarningEnergy
G4double fThresholdWarningEnergy
Energy threshold for warnings about killing looping tracks.
Definition
TG4RunAction.h:77
TG4RunAction::TG4RunAction
TG4RunAction()
Definition
TG4RunAction.cxx:60
TG4RunAction::fCrossSectionManager
TG4CrossSectionManager fCrossSectionManager
cross section manager
Definition
TG4RunAction.h:69
TG4RunAction::fThresholdImportantEnergy
G4double fThresholdImportantEnergy
Definition
TG4RunAction.h:82
TG4RunAction::EndOfRunAction
virtual void EndOfRunAction(const G4Run *run)
Definition
TG4RunAction.cxx:219
TG4RunAction::fSaveRandomStatus
G4bool fSaveRandomStatus
control for saving random engine status
Definition
TG4RunAction.h:72
TG4RunAction::PrintLooperParameters
void PrintLooperParameters() const
Definition
TG4RunAction.cxx:140
TG4RunAction::ChangeLooperParameters
void ChangeLooperParameters(const G4ParticleDefinition *particleDefinition)
Definition
TG4RunAction.cxx:98
TG4RunAction::fTimer
G4Timer * fTimer
G4Timer.
Definition
TG4RunAction.h:70
TG4RunAction::fgkDefaultRandomStatusFile
static const G4String fgkDefaultRandomStatusFile
default name of the random engine status file to be read in
Definition
TG4RunAction.h:65
TG4VRegionsManager::Instance
static TG4VRegionsManager * Instance()
Return the singleton instance.
Definition
TG4VRegionsManager.h:137
TG4Verbose::VerboseLevel
virtual G4int VerboseLevel() const
Definition
TG4Verbose.h:78
TG4Verbose::TG4Verbose
TG4Verbose(const G4String &cmdName)
Definition
TG4Verbose.cxx:24
TGeant4::MasterApplicationInstance
static TVirtualMCApplication * MasterApplicationInstance()
Generated on
for Geant4 VMC by
1.17.0