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