4 // Author: I. Hrivnacova
6 // Class TG4VSpecialControls
7 // -------------------------
8 // See the class description in the header file.
10 #include "TG4SpecialControls.h"
11 #include "TG4GeometryServices.h"
12 #include "TG4Limits.h"
14 #include <G4StepStatus.hh>
15 #include <G4ProcessManager.hh>
16 #include <G4ProcessVector.hh>
18 //_____________________________________________________________________________
19 TG4SpecialControls::TG4SpecialControls(const G4String& processName)
20 : G4VProcess(processName),
21 fSwitchControls(kUnswitch),
26 G4cout << GetProcessName() << " is created "<< G4endl;
30 //_____________________________________________________________________________
31 TG4SpecialControls::TG4SpecialControls(const TG4SpecialControls& right) {
33 TG4Globals::Exception(
34 "TG4SpecialControls is protected from copying.");
37 //_____________________________________________________________________________
38 TG4SpecialControls::~TG4SpecialControls() {
44 //_____________________________________________________________________________
45 TG4SpecialControls& TG4SpecialControls::operator=(
46 const TG4SpecialControls& right)
48 // check assignement to self
49 if (this == &right) return *this;
51 TG4Globals::Exception(
52 "TG4SpecialControls is protected from assigning.");
59 //_____________________________________________________________________________
60 void TG4SpecialControls::Reset()
62 // Resets the buffers to the initial state.
65 fSwitchControls = kUnswitch;
68 fSwitchedProcesses.clear();
69 fSwitchedControls.clear();
74 //_____________________________________________________________________________
75 G4double TG4SpecialControls::PostStepGetPhysicalInteractionLength(
76 const G4Track& track, G4double previousStepSize,
77 G4ForceCondition* condition)
79 // Returns the Step-size (actual length) which is allowed
83 *condition = NotForced;
85 if (track.GetTrackID() != fLastTrackID) {
88 fLastTrackID = track.GetTrackID();
91 G4double proposedStep = DBL_MAX;
92 //G4double minStep = (1.0e-9)*m;
93 G4double minStep = 0.;
94 // must be greater than DBL_MIN - so that particle can get out of
96 // proposedStep = 0.; causes navigator to fall into panic
99 = track.GetStep()->GetPreStepPoint()->GetStepStatus();
104 = TG4GeometryServices::Instance()
105 ->GetLimits(track.GetVolume()->GetLogicalVolume()->GetUserLimits());
108 G4String text = "TG4VSpecialControls::PostStepGetPhysicalInteractionLength:\n";
109 text = text + " " + track.GetVolume()->GetLogicalVolume()->GetName();
110 text = text + " has not limits.";
111 TG4Globals::Exception(text);
115 = (TG4Limits*) track.GetVolume()->GetLogicalVolume()->GetUserLimits();
118 if (fSwitchControls != kUnswitch) {
119 if (status == fGeomBoundary) {
120 if (limits->IsControl()) {
121 // particle is exiting a logical volume with special controls
122 // and entering another logical volume with special controls
123 proposedStep = minStep;
124 fSwitchControls = kReswitch;
125 if (verboseLevel>0) G4cout << "kReswitch" << G4endl;
128 // particle is exiting a logical volume with special controls
129 // and entering a logical volume without special controls
130 proposedStep = minStep;
131 fSwitchControls = kUnswitch;
132 if (verboseLevel>0) G4cout << "kUnswitch" << G4endl;
136 else if (limits->IsControl()) {
137 // particle is entering a logical volume with special controls
138 // that have not yet been set
139 proposedStep = minStep;
140 fSwitchControls = kSwitch;
141 if (verboseLevel>0) G4cout << "kSwitch" << G4endl;
146 //_____________________________________________________________________________
147 G4VParticleChange* TG4SpecialControls::PostStepDoIt(
148 const G4Track& track, const G4Step& step)
150 // Changes processes activation of the current track
151 // according to the current user limits.
154 G4ProcessManager* processManager
155 = track.GetDefinition()->GetProcessManager();
156 G4ProcessVector* processVector = processManager->GetProcessList();
158 if ((fSwitchControls==kUnswitch) || (fSwitchControls==kReswitch)) {
160 // set processes activation back
161 for (G4int i=0; i<fSwitchedProcesses.length(); i++) {
162 if (verboseLevel>0) {
163 G4cout << "Reset process activation back in "
164 << track.GetVolume()->GetName()
168 ->SetProcessActivation(fSwitchedProcesses[i],fSwitchedControls[i]);
170 fSwitchedProcesses.clear();
171 fSwitchedControls.clear();
174 if ((fSwitchControls==kSwitch) || (fSwitchControls==kReswitch)) {
176 // set TG4Limits processes controls
178 = (TG4Limits*) track.GetVolume()->GetLogicalVolume()->GetUserLimits();
180 for (G4int i=0; i<processVector->length(); i++) {
182 TG4G3ControlValue control = limits->GetControl((*processVector)[i]);
183 G4bool activation = processManager->GetProcessActivation(i);
185 if (control != kUnset && ! TG4Globals::Compare(activation, control)) {
187 // store the current processes controls
188 G4cout << "Something goes to fSwitchedProcesses" << G4endl;
189 fSwitchedProcesses.insert((*processVector)[i]);
190 fSwitchedControls.push_back(activation);
192 // set new process activation
193 if (control == kInActivate) {
194 if (verboseLevel>0) {
195 G4cout << "Set process inactivation for "
196 << (*processVector)[i]->GetProcessName() << " in "
197 << track.GetVolume()->GetName()
200 processManager->SetProcessActivation(i,false);
203 // ((control == kActivate) || (control == kActivate2))
204 if (verboseLevel>0) {
205 G4cout << "Set process activation for "
206 << (*processVector)[i]->GetProcessName() << " in "
207 << track.GetVolume()->GetName()
210 processManager->SetProcessActivation(i,true);
216 // processManager->DumpInfo();
217 aParticleChange.Initialize(track);
218 aParticleChange.SetStatusChange(fAlive);
219 return &aParticleChange;