Geant4 VMC Version 6.6
Loading...
Searching...
No Matches
TG4ActionInitialization.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Geant4 Virtual Monte Carlo package
3// Copyright (C) 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
16#include "TG4EventAction.h"
17#include "TG4Globals.h"
18#include "TG4RunAction.h"
19#include "TG4RunConfiguration.h"
22#include "TG4SteppingAction.h"
23#include "TG4TrackManager.h"
24#include "TG4TrackingAction.h"
25#include "TGeant4.h"
26
27#include <RVersion.h>
28#include <TInterpreter.h>
29#include <TROOT.h>
30#include <TVirtualMCApplication.h>
31
32#include <G4Threading.hh>
33#include <G4Types.hh>
34
35//_____________________________________________________________________________
37 TG4RunConfiguration* runConfiguration)
39 fRunConfiguration(runConfiguration),
40 fEventAction(0),
41 fTrackingAction(0),
42 fSteppingAction(0),
43 fStackingAction(0)
44{
46
51}
52
53//_____________________________________________________________________________
55{
57
58#ifdef G4MULTITHREADED
59 if (G4Threading::G4GetThreadId() != -2 &&
61 // Delete actions not registered to G4RunManager
62 // (created on master in MT)
63 delete fEventAction;
64 delete fTrackingAction;
65 delete fSteppingAction;
66 delete fStackingAction;
67 }
68#endif
69}
70
71//
72// public methods
73//
74
75//_____________________________________________________________________________
77{
79
80 // G4cout << "TG4ActionInitialization::BuildForMaster " << this << G4endl;
81
83 if (runAction) SetUserAction(runAction);
84
85 // G4cout << "TG4ActionInitialization::BuildForMaster end " << G4endl;
86}
87
88//_____________________________________________________________________________
90{
92
93 // G4cout << "TG4ActionInitialization::Build " << this << G4endl;
94
95 G4UserEventAction* eventAction = 0;
96 TG4TrackingAction* trackingAction = 0;
97 TG4SteppingAction* steppingAction = 0;
98 G4UserStackingAction* stackingAction = 0;
99
100 // create MC and MCApplication worker instances
101#ifdef G4MULTITHREADED
102 if (G4Threading::IsWorkerThread()) {
103 if (!TGeant4::MasterApplicationInstance()->CloneForWorker()) {
104 // Give an exception if user application does not implement
105 // CloneForWorker as is run in MT
106 TG4Globals::Exception("TG4ActionInitialization", "Build",
107 "Failed to clone user application." + TG4Globals::Endl() +
108 "TVirtualMCApplication::CloneForWorker() must be overriden in user "
109 "code" +
110 TG4Globals::Endl() + "in order to run in multi-threading mode.");
111 }
113 TVirtualMCApplication::Instance()->InitOnWorker(); // new
114
115 // Create actions on workers
116 eventAction = fRunConfiguration->CreateEventAction();
117 trackingAction = fRunConfiguration->CreateTrackingAction();
118 steppingAction = fRunConfiguration->CreateSteppingAction();
119 stackingAction = fRunConfiguration->CreateStackingAction();
120
121 // Pass properties from objects created on master
122 if (eventAction) {
123 TG4EventAction* tg4EventAction =
124 dynamic_cast<TG4EventAction*>(eventAction);
125 if (tg4EventAction) {
126 TG4EventAction* masterEventAction =
127 static_cast<TG4EventAction*>(fEventAction);
128 tg4EventAction->SetPrintMemory(masterEventAction->GetPrintMemory());
129 tg4EventAction->SetSaveRandomStatus(
130 masterEventAction->GetSaveRandomStatus());
131 tg4EventAction->VerboseLevel(masterEventAction->VerboseLevel());
132 }
133 }
134
135 if (trackingAction) {
137 trackingAction->SetNewVerboseTrackID(
139 trackingAction->GetTrackManager()->SetTrackSaveControl(
141 trackingAction->GetTrackManager()->SetSaveDynamicCharge(
143 trackingAction->VerboseLevel(fTrackingAction->VerboseLevel());
144 trackingAction->GetTrackManager()->VerboseLevel(
146 }
147
148 if (steppingAction) {
149 steppingAction->SetLoopVerboseLevel(
152 }
153
154 if (stackingAction) {
155 TG4SpecialStackingAction* tg4StackingAction =
156 dynamic_cast<TG4SpecialStackingAction*>(stackingAction);
157 if (tg4StackingAction) {
158 TG4SpecialStackingAction* masterStackingAction =
160 tg4StackingAction->SetSkipNeutrino(
161 masterStackingAction->GetSkipNeutrino());
162 tg4StackingAction->VerboseLevel(masterStackingAction->VerboseLevel());
163 }
164 }
165 }
166#endif
167
168 // In sequential build just get the actions created in constructor
169 if (!eventAction) eventAction = fEventAction;
170 if (!trackingAction) trackingAction = fTrackingAction;
171 if (!steppingAction) steppingAction = fSteppingAction;
172 if (!stackingAction) stackingAction = fStackingAction;
173
174 // Create actions (without messengers) which were not yet created
175 // and set them to G4RunManager
176
178
180 if (runAction) SetUserAction(runAction);
181
182 // Set already created actions (with messengers) to G4RunManager
183 if (eventAction) SetUserAction(eventAction);
184 if (trackingAction) SetUserAction(trackingAction);
185 if (steppingAction) SetUserAction(steppingAction);
186 if (stackingAction) SetUserAction(stackingAction);
187 if (runAction) SetUserAction(runAction);
188
189 // Special controls action
190 //
192 G4cout << "### TG4SpecialControlsV2 constructed" << G4endl;
193 TG4SpecialControlsV2* specialControls = new TG4SpecialControlsV2();
194 // special controls are deleted in TG4SteppingAction
195
196 trackingAction->SetSpecialControls(specialControls);
197 steppingAction->SetSpecialControls(specialControls);
198 }
199 // G4cout << "TG4ActionInitialization::Build done " << this << G4endl;
200}
Definition of the TG4ActionInitialization class.
Definition of the TG4EventAction class.
Definition of the TG4Globals class and basic container types.
Definition of the TG4RunAction class.
Definition of the TG4RunConfiguration class.
Definition of the TG4SpecialControlsV2 class.
Definition of the TG4SpecialStackingAction class.
Definition of the TG4SteppingAction class.
Definition of the TG4TrackManager class.
Definition of the TG4TrackingAction class.
Definition of the TGeant4 class.
virtual void BuildForMaster() const
TG4SteppingAction * fSteppingAction
steping action
TG4RunConfiguration * fRunConfiguration
run configuration
G4UserStackingAction * fStackingAction
stacking action
G4UserEventAction * fEventAction
event action
TG4TrackingAction * fTrackingAction
tracking action
TG4ActionInitialization()
Not implemented.
Actions at the beginning and the end of event.
G4bool GetSaveRandomStatus() const
G4bool GetPrintMemory() const
void SetPrintMemory(G4bool printMemory)
void SetSaveRandomStatus(G4bool saveRandomStatus)
static void Exception(const TString &className, const TString &methodName, const TString &text)
static TString Endl()
Definition TG4Globals.h:100
Takes care of creating Geant4 user action classes using VMC.
virtual TG4SteppingAction * CreateSteppingAction()
virtual G4UserStackingAction * CreateStackingAction()
virtual G4UserEventAction * CreateEventAction()
virtual TG4TrackingAction * CreateTrackingAction()
virtual G4VUserPrimaryGeneratorAction * CreatePrimaryGenerator()
virtual G4UserRunAction * CreateRunAction()
The manager class for G3 process controls.
Defines a special stacking mechanism.
G4bool GetSkipNeutrino() const
Return the option for skipping neutrino.
void SetSkipNeutrino(G4bool value)
Set the option for skipping neutrino.
Actions at each step.
void SetMaxNofSteps(G4int number)
G4int GetLoopVerboseLevel() const
void SetLoopVerboseLevel(G4int level)
G4int GetMaxNofSteps() const
void SetSpecialControls(TG4SpecialControlsV2 *specialControls)
TG4TrackSaveControl GetTrackSaveControl() const
void SetTrackSaveControl(TG4TrackSaveControl control)
G4bool GetSaveDynamicCharge() const
void SetSaveDynamicCharge(G4bool saveDynamicCharge)
Actions at the beginnig and at the end of track.
void SetNewVerboseLevel(G4int level)
TG4TrackManager * GetTrackManager() const
G4int GetNewVerboseLevel() const
G4int GetNewVerboseTrackID() const
void SetSpecialControls(TG4SpecialControlsV2 *specialControls)
void SetNewVerboseTrackID(G4int trackID)
virtual void VerboseLevel(G4int level)
Definition TG4Verbose.h:72
static TVirtualMCApplication * MasterApplicationInstance()
static TGeant4 * MasterInstance()
TGeant4 * CloneForWorker() const
Definition TGeant4.cxx:1261