]>
Commit | Line | Data |
---|---|---|
2817d3e2 | 1 | // $Id$ // |
2 | // Category: physics | |
3 | // | |
4 | // See the class description in the header file. | |
5 | ||
6a474bd6 | 6 | #include "TG4SpecialControls.h" |
2817d3e2 | 7 | #include "TG4Limits.h" |
8 | ||
9 | #include <G4StepStatus.hh> | |
10 | #include <G4ProcessManager.hh> | |
11 | #include <G4ProcessVector.hh> | |
12 | ||
6a474bd6 | 13 | TG4SpecialControls::TG4SpecialControls(const G4String& aName) |
2817d3e2 | 14 | : G4VProcess(aName), |
6a474bd6 | 15 | fSwitchControls(kUnswitch) |
2817d3e2 | 16 | { |
17 | // verboseLevel = 1; | |
18 | if (verboseLevel>0) { | |
3c7cd15a | 19 | G4cout << GetProcessName() << " is created "<< G4endl; |
2817d3e2 | 20 | } |
21 | } | |
22 | ||
6a474bd6 | 23 | TG4SpecialControls::TG4SpecialControls(const TG4SpecialControls& right) { |
2817d3e2 | 24 | // |
25 | TG4Globals::Exception( | |
6a474bd6 | 26 | "TG4SpecialControls is protected from copying."); |
2817d3e2 | 27 | } |
28 | ||
6a474bd6 | 29 | TG4SpecialControls::~TG4SpecialControls() { |
2817d3e2 | 30 | // |
31 | } | |
32 | ||
33 | // operators | |
34 | ||
6a474bd6 | 35 | TG4SpecialControls& TG4SpecialControls::operator=( |
36 | const TG4SpecialControls& right) | |
2817d3e2 | 37 | { |
38 | // check assignement to self | |
39 | if (this == &right) return *this; | |
40 | ||
41 | TG4Globals::Exception( | |
6a474bd6 | 42 | "TG4SpecialControls is protected from assigning."); |
2817d3e2 | 43 | |
44 | return *this; | |
45 | } | |
46 | ||
47 | // public methods | |
48 | ||
6a474bd6 | 49 | G4double TG4SpecialControls::PostStepGetPhysicalInteractionLength( |
2817d3e2 | 50 | const G4Track& track, G4double previousStepSize, |
51 | G4ForceCondition* condition) | |
52 | { | |
53 | // Returns the Step-size (actual length) which is allowed | |
54 | // by this process. | |
55 | // --- | |
56 | ||
57 | *condition = NotForced; | |
58 | ||
59 | G4double proposedStep = DBL_MAX; | |
60 | G4double minStep = (1.0e-9)*m; | |
61 | // must be greater than DBL_MIN - so that particle can get out of | |
62 | // the boundary | |
63 | // proposedStep = 0.; causes navigator to fall into panic | |
64 | ||
65 | G4StepStatus status | |
66 | = track.GetStep()->GetPreStepPoint()->GetStepStatus(); | |
67 | TG4Limits* limits | |
68 | = (TG4Limits*) track.GetVolume()->GetLogicalVolume()->GetUserLimits(); | |
69 | ||
6a474bd6 | 70 | if (fSwitchControls != kUnswitch) { |
2817d3e2 | 71 | if (status == fGeomBoundary) { |
6a474bd6 | 72 | if ((limits) && (limits->IsControl())) { |
73 | // particle is exiting a logical volume with special controls | |
74 | // and entering another logical volume with special controls | |
2817d3e2 | 75 | proposedStep = minStep; |
6a474bd6 | 76 | fSwitchControls = kReswitch; |
3c7cd15a | 77 | if (verboseLevel>0) G4cout << "kReswitch" << G4endl; |
2817d3e2 | 78 | } |
79 | else { | |
6a474bd6 | 80 | // particle is exiting a logical volume with special controls |
81 | // and entering a logical volume without special controls | |
2817d3e2 | 82 | proposedStep = minStep; |
6a474bd6 | 83 | fSwitchControls = kUnswitch; |
3c7cd15a | 84 | if (verboseLevel>0) G4cout << "kUnswitch" << G4endl; |
2817d3e2 | 85 | } |
86 | } | |
87 | } | |
6a474bd6 | 88 | else if ((limits) && (limits->IsControl())) { |
89 | // particle is entering a logical volume with special controls | |
2817d3e2 | 90 | // that have not yet been set |
91 | proposedStep = minStep; | |
6a474bd6 | 92 | fSwitchControls = kSwitch; |
3c7cd15a | 93 | if (verboseLevel>0) G4cout << "kSwitch" << G4endl; |
2817d3e2 | 94 | } |
95 | return proposedStep; | |
96 | } | |
97 | ||
6a474bd6 | 98 | G4VParticleChange* TG4SpecialControls::PostStepDoIt( |
2817d3e2 | 99 | const G4Track& track, const G4Step& step) |
100 | { | |
101 | // Changes processes activation of the current track | |
102 | // according to the current user limits. | |
103 | // --- | |
104 | ||
105 | TG4Limits* limits | |
106 | = (TG4Limits*) track.GetVolume()->GetLogicalVolume()->GetUserLimits(); | |
107 | ||
108 | G4ProcessManager* processManager | |
109 | = track.GetDefinition()->GetProcessManager(); | |
110 | G4ProcessVector* processVector = processManager->GetProcessList(); | |
111 | // processManager->DumpInfo(); | |
112 | ||
6a474bd6 | 113 | if ((fSwitchControls==kUnswitch) || (fSwitchControls==kReswitch)) { |
2817d3e2 | 114 | // set processes activation back |
115 | for (G4int i=0; i<fSwitchedProcesses.entries(); i++) { | |
116 | if (verboseLevel>0) { | |
117 | G4cout << "Reset process activation back in" | |
118 | << track.GetVolume()->GetName() | |
3c7cd15a | 119 | << G4endl; |
2817d3e2 | 120 | } |
121 | processManager | |
6a474bd6 | 122 | ->SetProcessActivation(fSwitchedProcesses[i],fSwitchedControls[i]); |
2817d3e2 | 123 | } |
124 | fSwitchedProcesses.clear(); | |
6a474bd6 | 125 | fSwitchedControls.clear(); |
2817d3e2 | 126 | } |
127 | ||
6a474bd6 | 128 | if ((fSwitchControls==kSwitch) || (fSwitchControls==kReswitch)) { |
129 | // set TG4Limits processes controls | |
2817d3e2 | 130 | for (G4int i=0; i<processManager->GetProcessListLength(); i++) { |
6a474bd6 | 131 | G4int control = limits->GetControl((*processVector)[i]); |
132 | if (control != kUnset) { | |
133 | // store the current processes controls; | |
2817d3e2 | 134 | fSwitchedProcesses.insert((*processVector)[i]); |
6a474bd6 | 135 | //fSwitchedControls.insert(processManager->GetProcessActivation(i)); |
136 | fSwitchedControls.push_back(processManager->GetProcessActivation(i)); | |
137 | if (control == kInActivate) { | |
2817d3e2 | 138 | if (verboseLevel>0) { |
139 | G4cout << "Set process inactivation for " | |
140 | << (*processVector)[i]->GetProcessName() << " in " | |
141 | << track.GetVolume()->GetName() | |
3c7cd15a | 142 | << G4endl; |
2817d3e2 | 143 | } |
144 | processManager->SetProcessActivation(i,false); | |
145 | } | |
146 | else { | |
6a474bd6 | 147 | // ((control == kActivate) || (control == kActivate2)) |
2817d3e2 | 148 | if (verboseLevel>0) { |
149 | G4cout << "Set process activation for " | |
150 | << (*processVector)[i]->GetProcessName() << " in " | |
151 | << track.GetVolume()->GetName() | |
3c7cd15a | 152 | << G4endl; |
2817d3e2 | 153 | } |
154 | processManager->SetProcessActivation(i,true); | |
155 | } | |
156 | } | |
157 | } | |
158 | } | |
159 | // processManager->DumpInfo(); | |
160 | aParticleChange.Initialize(track); | |
161 | aParticleChange.SetStatusChange(fAlive); | |
162 | return &aParticleChange; | |
163 | } | |
164 |