]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TGeant4/TG4SpecialControls.cxx
added inheritance from TG4Verbose;
[u/mrichter/AliRoot.git] / TGeant4 / TG4SpecialControls.cxx
CommitLineData
2817d3e2 1// $Id$ //
2// Category: physics
3//
e5967ab3 4// Author: I. Hrivnacova
5//
6// Class TG4VSpecialControls
7// -------------------------
2817d3e2 8// See the class description in the header file.
9
6a474bd6 10#include "TG4SpecialControls.h"
e5967ab3 11#include "TG4GeometryServices.h"
2817d3e2 12#include "TG4Limits.h"
13
14#include <G4StepStatus.hh>
15#include <G4ProcessManager.hh>
16#include <G4ProcessVector.hh>
17
72095f7c 18//_____________________________________________________________________________
e5967ab3 19TG4SpecialControls::TG4SpecialControls(const G4String& processName)
20 : G4VProcess(processName),
21 fSwitchControls(kUnswitch),
f28a0f65 22 fLastTrackID(0) {
23//
e5967ab3 24 verboseLevel = 1;
2817d3e2 25 if (verboseLevel>0) {
3c7cd15a 26 G4cout << GetProcessName() << " is created "<< G4endl;
2817d3e2 27 }
28}
29
72095f7c 30//_____________________________________________________________________________
6a474bd6 31TG4SpecialControls::TG4SpecialControls(const TG4SpecialControls& right) {
2817d3e2 32//
33 TG4Globals::Exception(
6a474bd6 34 "TG4SpecialControls is protected from copying.");
2817d3e2 35}
36
72095f7c 37//_____________________________________________________________________________
6a474bd6 38TG4SpecialControls::~TG4SpecialControls() {
2817d3e2 39//
40}
41
42// operators
43
72095f7c 44//_____________________________________________________________________________
6a474bd6 45TG4SpecialControls& TG4SpecialControls::operator=(
46 const TG4SpecialControls& right)
2817d3e2 47{
48 // check assignement to self
49 if (this == &right) return *this;
50
51 TG4Globals::Exception(
6a474bd6 52 "TG4SpecialControls is protected from assigning.");
2817d3e2 53
54 return *this;
55}
56
e5967ab3 57// private methods
58
59//_____________________________________________________________________________
60void TG4SpecialControls::Reset()
61{
62// Resets the buffers to the initial state.
63// ---
64
65 fSwitchControls = kUnswitch;
66
67 // clear buffers
68 fSwitchedProcesses.clear();
69 fSwitchedControls.clear();
70}
71
2817d3e2 72// public methods
73
72095f7c 74//_____________________________________________________________________________
6a474bd6 75G4double TG4SpecialControls::PostStepGetPhysicalInteractionLength(
2817d3e2 76 const G4Track& track, G4double previousStepSize,
77 G4ForceCondition* condition)
78{
79// Returns the Step-size (actual length) which is allowed
80// by this process.
81// ---
82
83 *condition = NotForced;
84
e5967ab3 85 if (track.GetTrackID() != fLastTrackID) {
86 // new track
87 Reset();
88 fLastTrackID = track.GetTrackID();
89 }
90
2817d3e2 91 G4double proposedStep = DBL_MAX;
e5967ab3 92 //G4double minStep = (1.0e-9)*m;
93 G4double minStep = 0.;
2817d3e2 94 // must be greater than DBL_MIN - so that particle can get out of
95 // the boundary
96 // proposedStep = 0.; causes navigator to fall into panic
97
98 G4StepStatus status
99 = track.GetStep()->GetPreStepPoint()->GetStepStatus();
e5967ab3 100
101 // get limits
102#ifdef TGEANT4_DEBUG
103 TG4Limits* limits
104 = TG4GeometryServices::Instance()
105 ->GetLimits(track.GetVolume()->GetLogicalVolume()->GetUserLimits());
106
107 if (!limits) {
108 G4String text = "TG4VSpecialControls::PostStepGetPhysicalInteractionLength:\n";
109 text = text + " " + track.GetVolume()->GetLogicalVolume()->GetName();
110 text = text + " has not limits.";
111 TG4Globals::Exception(text);
112 }
113#else
2817d3e2 114 TG4Limits* limits
115 = (TG4Limits*) track.GetVolume()->GetLogicalVolume()->GetUserLimits();
e5967ab3 116#endif
2817d3e2 117
6a474bd6 118 if (fSwitchControls != kUnswitch) {
2817d3e2 119 if (status == fGeomBoundary) {
e5967ab3 120 if (limits->IsControl()) {
6a474bd6 121 // particle is exiting a logical volume with special controls
122 // and entering another logical volume with special controls
2817d3e2 123 proposedStep = minStep;
6a474bd6 124 fSwitchControls = kReswitch;
3c7cd15a 125 if (verboseLevel>0) G4cout << "kReswitch" << G4endl;
2817d3e2 126 }
127 else {
6a474bd6 128 // particle is exiting a logical volume with special controls
129 // and entering a logical volume without special controls
2817d3e2 130 proposedStep = minStep;
6a474bd6 131 fSwitchControls = kUnswitch;
3c7cd15a 132 if (verboseLevel>0) G4cout << "kUnswitch" << G4endl;
2817d3e2 133 }
134 }
135 }
e5967ab3 136 else if (limits->IsControl()) {
6a474bd6 137 // particle is entering a logical volume with special controls
2817d3e2 138 // that have not yet been set
139 proposedStep = minStep;
6a474bd6 140 fSwitchControls = kSwitch;
3c7cd15a 141 if (verboseLevel>0) G4cout << "kSwitch" << G4endl;
2817d3e2 142 }
143 return proposedStep;
144}
145
72095f7c 146//_____________________________________________________________________________
6a474bd6 147G4VParticleChange* TG4SpecialControls::PostStepDoIt(
2817d3e2 148 const G4Track& track, const G4Step& step)
149{
150// Changes processes activation of the current track
151// according to the current user limits.
152// ---
153
2817d3e2 154 G4ProcessManager* processManager
155 = track.GetDefinition()->GetProcessManager();
156 G4ProcessVector* processVector = processManager->GetProcessList();
2817d3e2 157
6a474bd6 158 if ((fSwitchControls==kUnswitch) || (fSwitchControls==kReswitch)) {
e5967ab3 159
2817d3e2 160 // set processes activation back
e5967ab3 161 for (G4int i=0; i<fSwitchedProcesses.length(); i++) {
2817d3e2 162 if (verboseLevel>0) {
e5967ab3 163 G4cout << "Reset process activation back in "
2817d3e2 164 << track.GetVolume()->GetName()
3c7cd15a 165 << G4endl;
2817d3e2 166 }
167 processManager
6a474bd6 168 ->SetProcessActivation(fSwitchedProcesses[i],fSwitchedControls[i]);
2817d3e2 169 }
170 fSwitchedProcesses.clear();
6a474bd6 171 fSwitchedControls.clear();
2817d3e2 172 }
173
6a474bd6 174 if ((fSwitchControls==kSwitch) || (fSwitchControls==kReswitch)) {
e5967ab3 175
6a474bd6 176 // set TG4Limits processes controls
e5967ab3 177 TG4Limits* limits
178 = (TG4Limits*) track.GetVolume()->GetLogicalVolume()->GetUserLimits();
179
180 for (G4int i=0; i<processVector->length(); i++) {
181
182 TG4G3ControlValue control = limits->GetControl((*processVector)[i]);
183 G4bool activation = processManager->GetProcessActivation(i);
184
185 if (control != kUnset && ! TG4Globals::Compare(activation, control)) {
186
187 // store the current processes controls
188 G4cout << "Something goes to fSwitchedProcesses" << G4endl;
2817d3e2 189 fSwitchedProcesses.insert((*processVector)[i]);
e5967ab3 190 fSwitchedControls.push_back(activation);
191
192 // set new process activation
6a474bd6 193 if (control == kInActivate) {
2817d3e2 194 if (verboseLevel>0) {
195 G4cout << "Set process inactivation for "
196 << (*processVector)[i]->GetProcessName() << " in "
197 << track.GetVolume()->GetName()
3c7cd15a 198 << G4endl;
2817d3e2 199 }
200 processManager->SetProcessActivation(i,false);
201 }
202 else {
6a474bd6 203 // ((control == kActivate) || (control == kActivate2))
2817d3e2 204 if (verboseLevel>0) {
205 G4cout << "Set process activation for "
206 << (*processVector)[i]->GetProcessName() << " in "
207 << track.GetVolume()->GetName()
3c7cd15a 208 << G4endl;
2817d3e2 209 }
210 processManager->SetProcessActivation(i,true);
211 }
212 }
213 }
e5967ab3 214 }
215
2817d3e2 216 // processManager->DumpInfo();
217 aParticleChange.Initialize(track);
218 aParticleChange.SetStatusChange(fAlive);
219 return &aParticleChange;
220}
221