ECCE @ EIC Software
Reference for
ECCE @ EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
RunAction.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file RunAction.cc
1
//
2
// ********************************************************************
3
// * License and Disclaimer *
4
// * *
5
// * The Geant4 software is copyright of the Copyright Holders of *
6
// * the Geant4 Collaboration. It is provided under the terms and *
7
// * conditions of the Geant4 Software License, included in the file *
8
// * LICENSE and available at http://cern.ch/geant4/license . These *
9
// * include a list of copyright holders. *
10
// * *
11
// * Neither the authors of this software system, nor their employing *
12
// * institutes,nor the agencies providing financial support for this *
13
// * work make any representation or warranty, express or implied, *
14
// * regarding this software system or assume any liability for its *
15
// * use. Please see the license in the file LICENSE and URL above *
16
// * for the full disclaimer and the limitation of liability. *
17
// * *
18
// * This code implementation is the result of the scientific and *
19
// * technical work of the GEANT4 collaboration. *
20
// * By using, copying, modifying or distributing the software (or *
21
// * any work based on the software) you agree to acknowledge its *
22
// * use in resulting scientific publications, and indicate your *
23
// * acceptance of all terms of the Geant4 Software license. *
24
// ********************************************************************
25
//
26
// This example is provided by the Geant4-DNA collaboration
27
// Any report or published results obtained using the Geant4-DNA software
28
// shall cite the following Geant4-DNA collaboration publication:
29
// Med. Phys. 37 (2010) 4692-4708
30
// The Geant4-DNA web site is available at http://geant4-dna.org
31
//
34
35
#include "RunAction.hh"
36
#include "
G4Run.hh
"
37
#include "
G4RunManager.hh
"
38
#include "Analysis.hh"
39
#include "
G4Threading.hh
"
40
#include "CommandLineParser.hh"
41
42
using namespace
G4DNAPARSER;
43
44
void
PrintNParticles
(std::map<const G4ParticleDefinition*, int>& container);
45
46
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47
48
RunAction::RunAction
() :
G4UserRunAction
(),
49
fInitialized(0), fDebug(
false
)
50
{}
51
52
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53
54
RunAction::~RunAction
()
55
{}
56
57
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58
59
void
RunAction::BeginOfRunAction
(
const
G4Run
* run)
60
{
61
// In this example, we considered that the same class was
62
// used for both master and worker threads.
63
// However, in case the run action is long,
64
// for better code review, this practice is not recommanded.
65
//
66
// Please note, in the example provided with the Geant4 X beta version,
67
// this RunAction class were not used by the master thread.
68
69
70
bool
sequential = (
G4RunManager::GetRunManager
()->
GetRunManagerType
() ==
71
G4RunManager::sequentialRM
);
72
73
if
(
isMaster
&& sequential ==
false
)
74
// WARNING : in sequential mode, isMaster == true
75
{
76
BeginMaster
(run);
77
}
78
else
BeginWorker
(run);
79
}
80
81
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
82
83
void
RunAction::EndOfRunAction
(
const
G4Run
* run)
84
{
85
86
bool
sequential = (
G4RunManager::GetRunManager
()->
GetRunManagerType
() ==
87
G4RunManager::sequentialRM
);
88
89
if
(
isMaster
&& sequential ==
false
)
90
{
91
EndMaster
(run);
92
}
93
else
94
{
95
EndWorker
(run);
96
}
97
}
98
99
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
100
101
void
RunAction::BeginMaster
(
const
G4Run
* run)
102
{
103
if
(
fDebug
)
104
{
105
bool
sequential = (
G4RunManager::GetRunManager
()->
GetRunManagerType
() ==
106
G4RunManager::sequentialRM
);
107
G4cout
<<
"==================================="
<<
G4endl
;
108
if
(!sequential)
109
G4cout
<<
"================ RunAction::BeginMaster"
<<
G4endl
;
110
PrintRunInfo
(run);
111
G4cout
<<
"==================================="
<<
G4endl
;
112
}
113
}
114
115
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
116
117
void
RunAction::BeginWorker
(
const
G4Run
* run)
118
{
119
if
(
fDebug
)
120
{
121
G4cout
<<
"==================================="
<<
G4endl
;
122
G4cout
<<
"================ RunAction::BeginWorker"
<<
G4endl
;
123
PrintRunInfo
(run);
124
G4cout
<<
"==================================="
<<
G4endl
;
125
}
126
if
(
fInitialized
==
false
)
InitializeWorker
(run);
127
128
CreateNtuple
();
129
}
130
131
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
132
133
void
RunAction::EndMaster
(
const
G4Run
*)
134
{
135
}
136
137
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
138
139
void
RunAction::EndWorker
(
const
G4Run
* run)
140
{
141
if
(
fDebug
)
142
{
143
PrintRunInfo
(run);
144
}
145
146
G4int
nofEvents = run->
GetNumberOfEvent
();
147
if
( nofEvents == 0 )
148
{
149
if
(
fDebug
)
150
{
151
G4cout
<<
"================ NO EVENTS TREATED IN THIS RUN ==> Exit"
152
<<
G4endl
;
153
}
154
return
;
155
}
156
158
// Write Ntuple
159
//
160
WriteNtuple
();
161
163
// Complete cleanup
164
//
165
delete
G4AnalysisManager::Instance
();
166
}
167
168
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
169
170
void
RunAction::InitializeWorker
(
const
G4Run
*)
171
{
172
// Initialize worker here
173
// example: you want to retrieve pointers to other user actions
174
fInitialized
=
true
;
175
}
176
177
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
178
179
void
RunAction::CreateNtuple
()
180
{
181
// Book histograms, ntuple
182
183
// Create analysis manager
184
// The choice of analysis technology is done via selection of a namespace
185
// in Analysis.hh
186
187
CommandLineParser
*
parser
= CommandLineParser::GetParser();
188
Command
* command(0);
189
if
((command = parser->
GetCommandIfActive
(
"-out"
))==0)
return
;
190
191
G4cout
<<
"##### Create analysis manager "
<<
" "
<<
this
<<
G4endl
;
192
G4AnalysisManager
* analysisManager =
G4AnalysisManager::Instance
();
193
// if(!analysisManager->IsActive()) {return; }
194
195
G4cout
<<
"Using "
<< analysisManager->
GetType
() <<
196
" analysis manager"
<<
G4endl
;
197
198
// Create directories
199
200
//analysisManager->SetHistoDirectoryName("histograms");
201
//analysisManager->SetNtupleDirectoryName("ntuple");
202
analysisManager->
SetVerboseLevel
(1);
203
204
// Open an output file
205
G4String
fileName;
206
if
(command->
GetOption
().empty() ==
false
)
207
{
208
fileName = command->
GetOption
();
209
}
210
else
211
{
212
fileName =
"wholeNuclearDNA"
;
213
// fileName = command->GetDefaultOption(); // should work as well
214
}
215
analysisManager->
OpenFile
(fileName);
216
217
// Creating ntuple
218
analysisManager->
CreateNtuple
(
"ntuple"
,
"geom_dna"
);
219
analysisManager->
CreateNtupleDColumn
(
"flagParticle"
);
220
analysisManager->
CreateNtupleDColumn
(
"flagProcess"
);
221
analysisManager->
CreateNtupleDColumn
(
"flagVolume"
);
222
analysisManager->
CreateNtupleDColumn
(
"x"
);
223
analysisManager->
CreateNtupleDColumn
(
"y"
);
224
analysisManager->
CreateNtupleDColumn
(
"z"
);
225
analysisManager->
CreateNtupleDColumn
(
"edep"
);
226
analysisManager->
CreateNtupleDColumn
(
"stepLength"
);
227
228
analysisManager->
FinishNtuple
();
229
230
}
231
232
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
233
234
void
RunAction::WriteNtuple
()
235
{
236
CommandLineParser
*
parser
= CommandLineParser::GetParser();
237
Command
* commandLine(0);
238
if
((commandLine = parser->
GetCommandIfActive
(
"-out"
))==0)
return
;
239
240
// print histogram statistics
241
//
242
G4AnalysisManager
* analysisManager =
G4AnalysisManager::Instance
();
243
// if(!analysisManager->IsActive()) {return; }
244
245
// save histograms
246
//
247
analysisManager->
Write
();
248
analysisManager->
CloseFile
();
249
}
250
251
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
252
253
void
RunAction::PrintRunInfo
(
const
G4Run
* run)
254
{
255
G4cout
<<
"================ Run is = "
256
<< run->
GetRunID
() <<
G4endl
;
257
G4cout
<<
"================ Run type is = "
258
<<
G4RunManager::GetRunManager
()->
GetRunManagerType
() <<
G4endl
;
259
G4cout
<<
"================ Event processed = "
260
<< run->
GetNumberOfEventToBeProcessed
() <<
G4endl
;
261
G4cout
<<
"================ Nevent = "
262
<< run->
GetNumberOfEvent
() <<
G4endl
;
263
}
264
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
geant4
tree
geant4-10.6-release
examples
extended
medical
dna
wholeNuclearDNA
src
RunAction.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:24:52
using
1.8.2 with
ECCE GitHub integration