Geant4 VMC Version 6.6
Loading...
Searching...
No Matches
TG4SpecialControlsV2.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
16#include "TG4G3ParticleWSP.h"
17#include "TG4G3PhysicsManager.h"
18#include "TG4GeometryServices.h"
19#include "TG4Limits.h"
20
21#include <G4ProcessManager.hh>
22#include <G4ProcessVector.hh>
23#include <G4StepStatus.hh>
24
25//_____________________________________________________________________________
27 : TG4Verbose("specialControlsV2"),
28 fIsApplicable(false),
29 fkTrack(0),
30 fSwitch(kUnswitch),
31 fSwitchedProcesses(),
32 fSwitchedControls(),
33 fProcessActivations()
34{
36}
37
38//_____________________________________________________________________________
43
44//
45// private methods
46//
47
48//_____________________________________________________________________________
50{
52
53 // get limits
54#ifdef MCDEBUG
56 fkTrack->GetNextVolume()->GetLogicalVolume()->GetUserLimits());
57#else
58 TG4Limits* limits =
59 (TG4Limits*)fkTrack->GetNextVolume()->GetLogicalVolume()->GetUserLimits();
60#endif
61
62 if (!limits) {
63 TG4Globals::Warning("TG4SpecialControlsV2", "SetSwitch",
64 "No limits defined in " +
65 TString(fkTrack->GetNextVolume()->GetLogicalVolume()->GetName()));
66 return;
67 }
68
69 if (fSwitch != kUnswitch) {
70 if (limits->IsControl()) {
71 // particle is exiting a logical volume with special controls
72 // and entering another logical volume with special controls
74 if (VerboseLevel() > 1) G4cout << "kReswitch" << G4endl;
75 }
76 else {
77 // particle is exiting a logical volume with special controls
78 // and entering a logical volume without special controls
80 if (VerboseLevel() > 1) G4cout << "kUnswitch" << G4endl;
81 }
82 }
83 else if (limits->IsControl()) {
84 // particle is entering a logical volume with special controls
85 // that have not yet been set
87 if (VerboseLevel() > 1) G4cout << "kSwitch" << G4endl;
88 }
89}
90
91//_____________________________________________________________________________
93{
95
97
98 // clear buffers
99 fSwitchedProcesses.clear();
100 fSwitchedControls.clear();
101 fProcessActivations.clear();
102}
103
104//
105// public methods
106//
107
108//_____________________________________________________________________________
109void TG4SpecialControlsV2::StartTrack(const G4Track* track)
110{
112
113 // check applicability
114 G4ParticleDefinition* particle = track->GetDefinition();
115 TG4G3ParticleWSP particleWSP =
117
118 if (particleWSP == kNofParticlesWSP) {
119 fIsApplicable = false;
120 fkTrack = 0;
121 return;
122 }
123
124 // set applicability, current track
125 fIsApplicable = true;
126 fkTrack = track;
127
128 // save origin process activation
129 G4ProcessManager* processManager =
130 track->GetDefinition()->GetProcessManager();
131 G4ProcessVector* processVector = processManager->GetProcessList();
132
133 for (size_t i = 0; i < processVector->length(); i++) {
134 fProcessActivations.push_back(processManager->GetProcessActivation(i));
135 }
136
137 // apply controls
139}
140
141//_____________________________________________________________________________
143{
146
147#ifdef MCDEBUG
148 if (!fkTrack) {
150 "TG4SpecialControlsV2", "ApplyControls", "No track is set.");
151 }
152#endif
153
154 SetSwitch();
155
156 G4ProcessManager* processManager =
157 fkTrack->GetDefinition()->GetProcessManager();
158 G4ProcessVector* processVector = processManager->GetProcessList();
159
160 if (fSwitch == kUnswitch || fSwitch == kReswitch) {
161
162 // set processes activation back
163 for (size_t i = 0; i < fSwitchedProcesses.length(); i++) {
164 if (VerboseLevel() > 1) {
165 G4cout << "Reset process activation back in "
166 << fkTrack->GetNextVolume()->GetName() << G4endl;
167 }
168 processManager->SetProcessActivation(
170 }
171 fSwitchedProcesses.clear();
172 fSwitchedControls.clear();
173 }
174
175 if (fSwitch == kSwitch || fSwitch == kReswitch) {
176
177 // set TG4Limits processes controls
178 TG4Limits* limits =
179 (TG4Limits*)fkTrack->GetNextVolume()->GetLogicalVolume()->GetUserLimits();
180
181 for (size_t i = 0; i < processVector->length(); i++) {
182
183 TG4G3ControlValue control = limits->GetControl((*processVector)[i]);
184 G4bool activation = processManager->GetProcessActivation(i);
185
186 if (control != kUnsetControlValue &&
187 !TG4Globals::Compare(activation, control)) {
188
189 // store the current processes controls
190 if (VerboseLevel() > 1) {
191 G4cout << "Something goes to fSwitchedProcesses" << G4endl;
192 }
193 fSwitchedProcesses.insert((*processVector)[i]);
194 fSwitchedControls.push_back(activation);
195
196 // set new process activation
197 if (control == kInActivate) {
198 if (VerboseLevel() > 1) {
199 G4cout << "Set process inactivation for "
200 << (*processVector)[i]->GetProcessName() << " in "
201 << fkTrack->GetNextVolume()->GetName() << G4endl;
202 }
203 processManager->SetProcessActivation(i, false);
204 }
205 else {
206 // ((control == kActivate) || (control == kActivate2))
207 if (VerboseLevel() > 1) {
208 G4cout << "Set process activation for "
209 << (*processVector)[i]->GetProcessName() << " in "
210 << fkTrack->GetNextVolume()->GetName() << G4endl;
211 }
212 processManager->SetProcessActivation(i, true);
213 }
214 }
215 }
216 }
217}
218
219//_____________________________________________________________________________
221{
224
225 G4ProcessManager* processManager =
226 fkTrack->GetDefinition()->GetProcessManager();
227 G4ProcessVector* processVector = processManager->GetProcessList();
228
229 for (size_t i = 0; i < processVector->length(); i++) {
230 if (processManager->GetProcessActivation(i) != fProcessActivations[i]) {
231 processManager->SetProcessActivation(i, fProcessActivations[i]);
232 }
233 }
234
235 Reset();
236}
Definition of the enumeration TG4G3ParticleWSP.
Definition of the TG4G3PhysicsManager class.
Definition of the TG4GeometryServices class.
Definition of the TG4Limits class.
Definition of the TG4SpecialControlsV2 class.
static TG4G3PhysicsManager * Instance()
TG4G3ParticleWSP GetG3ParticleWSP(G4ParticleDefinition *particle) const
static TG4GeometryServices * Instance()
TG4Limits * GetLimits(G4UserLimits *limits) const
static void Warning(const TString &className, const TString &methodName, const TString &text)
static void Exception(const TString &className, const TString &methodName, const TString &text)
static G4bool Compare(G4bool activation, TG4G3ControlValue controlValue)
Extended G4UserLimits class.
Definition TG4Limits.h:38
TG4G3ControlValue GetControl(G4VProcess *process) const
G4bool IsControl() const
Definition TG4Limits.h:117
@ kUnswitch
do not switch the process activation
@ kReswitch
switch the process activation back
@ kSwitch
switch the process activation
G4bool fIsApplicable
Applicability for the current track.
Switch fSwitch
The action to be performed in the current step.
TG4boolVector fSwitchedControls
Vector for storing the current values of the processes activation.
G4ProcessVector fSwitchedProcesses
Vector of the processes the activation of which is changed by this process.
TG4boolVector fProcessActivations
vector of the origin process activations
const G4Track * fkTrack
The current track.
void StartTrack(const G4Track *track)
Base class for defining the verbose level and a common messenger.
Definition TG4Verbose.h:36
virtual G4int VerboseLevel() const
Definition TG4Verbose.h:78
TG4G3ControlValue
Enumeration for G3 processes control values.
@ kInActivate
process is not activated
@ kUnsetControlValue
value not set
TG4G3ParticleWSP
The particles types which a special process (cuts, controls) is applicable for.
@ kNofParticlesWSP
not a particle with a special control