]>
Commit | Line | Data |
---|---|---|
1 | // $Id$ | |
2 | // Category: global | |
3 | // | |
4 | // Author: I. Hrivnacova | |
5 | // | |
6 | // Class TG4G3ControlVector | |
7 | // ------------------------ | |
8 | // See the class description in the header file. | |
9 | ||
10 | #include "TG4G3ControlVector.h" | |
11 | #include "TG4G3CutVector.h" | |
12 | #include "TG4ProcessControlMap.h" | |
13 | #include "TG4G3Defaults.h" | |
14 | #include "TG4Globals.h" | |
15 | ||
16 | #include <G4VProcess.hh> | |
17 | ||
18 | #include <math.h> | |
19 | ||
20 | TG4StringVector TG4G3ControlVector::fgControlNameVector; | |
21 | ||
22 | //_____________________________________________________________________________ | |
23 | TG4G3ControlVector::TG4G3ControlVector() | |
24 | { | |
25 | // initialize fControlVector | |
26 | for (G4int i=0; i<=kNoG3Controls; i++) fControlVector.push_back(kUnset); | |
27 | ||
28 | // fill name vector | |
29 | if (fgControlNameVector.size() == 0) FillControlNameVector(); | |
30 | } | |
31 | ||
32 | //_____________________________________________________________________________ | |
33 | TG4G3ControlVector::TG4G3ControlVector(const TG4G3ControlVector& right) | |
34 | : fControlVector(right.fControlVector.size()) | |
35 | { | |
36 | // copy stuff | |
37 | *this = right; | |
38 | } | |
39 | ||
40 | //_____________________________________________________________________________ | |
41 | TG4G3ControlVector::~TG4G3ControlVector() { | |
42 | // | |
43 | } | |
44 | ||
45 | // operators | |
46 | ||
47 | //_____________________________________________________________________________ | |
48 | TG4G3ControlVector& TG4G3ControlVector::operator=( | |
49 | const TG4G3ControlVector& right) | |
50 | { | |
51 | // check assignement to self | |
52 | if (this == &right) return *this; | |
53 | ||
54 | // initialize fControlVector | |
55 | for (G4int i=0; i<=kNoG3Controls; i++) | |
56 | fControlVector[i] = right.fControlVector[i]; | |
57 | ||
58 | return *this; | |
59 | } | |
60 | ||
61 | //_____________________________________________________________________________ | |
62 | TG4G3ControlValue TG4G3ControlVector::operator[](G4int index) const | |
63 | { | |
64 | // | |
65 | if (index <= kNoG3Controls) | |
66 | return fControlVector[index]; | |
67 | else { | |
68 | TG4Globals::Exception( | |
69 | "TG4G3ControlVector::operator[]: index out of the vector scope"); | |
70 | return kUnset; | |
71 | } | |
72 | } | |
73 | ||
74 | // private methods | |
75 | ||
76 | //_____________________________________________________________________________ | |
77 | void TG4G3ControlVector::FillControlNameVector() | |
78 | { | |
79 | // Defines fControlNameVector. | |
80 | // --- | |
81 | ||
82 | fgControlNameVector.push_back("PAIR"); | |
83 | fgControlNameVector.push_back("COMP"); | |
84 | fgControlNameVector.push_back("PHOT"); | |
85 | fgControlNameVector.push_back("PFIS"); | |
86 | fgControlNameVector.push_back("DRAY"); | |
87 | fgControlNameVector.push_back("ANNI"); | |
88 | fgControlNameVector.push_back("BREM"); | |
89 | fgControlNameVector.push_back("HADR"); | |
90 | fgControlNameVector.push_back("MUNU"); | |
91 | fgControlNameVector.push_back("DCAY"); | |
92 | fgControlNameVector.push_back("LOSS"); | |
93 | fgControlNameVector.push_back("MULS"); | |
94 | fgControlNameVector.push_back("CKOV"); | |
95 | fgControlNameVector.push_back("RAYL"); | |
96 | fgControlNameVector.push_back("LABS"); | |
97 | fgControlNameVector.push_back("SYNC"); | |
98 | fgControlNameVector.push_back("NONE"); | |
99 | } | |
100 | ||
101 | // public methods | |
102 | ||
103 | //_____________________________________________________________________________ | |
104 | TG4G3Control TG4G3ControlVector::GetControl(const G4String& controlName) | |
105 | { | |
106 | // Retrieves corresponding TG4G3Control constant from the controlName. | |
107 | // --- | |
108 | ||
109 | if (controlName == fgControlNameVector[kPAIR]) return kPAIR; | |
110 | else if (controlName == fgControlNameVector[kCOMP]) return kCOMP; | |
111 | else if (controlName == fgControlNameVector[kPHOT]) return kPHOT; | |
112 | else if (controlName == fgControlNameVector[kPFIS]) return kPFIS; | |
113 | else if (controlName == fgControlNameVector[kDRAY]) return kDRAY; | |
114 | else if (controlName == fgControlNameVector[kANNI]) return kANNI; | |
115 | else if (controlName == fgControlNameVector[kBREM]) return kBREM; | |
116 | else if (controlName == fgControlNameVector[kHADR]) return kHADR; | |
117 | else if (controlName == fgControlNameVector[kMUNU]) return kMUNU; | |
118 | else if (controlName == fgControlNameVector[kDCAY]) return kDCAY; | |
119 | else if (controlName == fgControlNameVector[kLOSS]) return kLOSS; | |
120 | else if (controlName == fgControlNameVector[kMULS]) return kMULS; | |
121 | else return kNoG3Controls; | |
122 | } | |
123 | ||
124 | //_____________________________________________________________________________ | |
125 | const G4String& TG4G3ControlVector::GetControlName(TG4G3Control control) | |
126 | { | |
127 | // Returns name of a specified cut. | |
128 | // --- | |
129 | ||
130 | // fill name vector | |
131 | if (fgControlNameVector.size() == 0) | |
132 | TG4G3ControlVector::FillControlNameVector(); | |
133 | ||
134 | return fgControlNameVector[control]; | |
135 | } | |
136 | ||
137 | //_____________________________________________________________________________ | |
138 | TG4G3ControlValue TG4G3ControlVector::GetControlValue(G4int value, | |
139 | TG4G3Control control) | |
140 | { | |
141 | // Conversion G4int -> G3ControlValue, | |
142 | // special treatment for LOSS values 3,4,5. | |
143 | // --- | |
144 | ||
145 | switch (value) { | |
146 | case kInActivate: | |
147 | return kInActivate; | |
148 | ;; | |
149 | case kActivate: | |
150 | return kActivate; | |
151 | ;; | |
152 | case kActivate2: | |
153 | return kActivate2; | |
154 | ;; | |
155 | case 3: case 4: case 5: | |
156 | if (control == kLOSS) | |
157 | return kActivate; | |
158 | else | |
159 | return kUnset; | |
160 | ;; | |
161 | } | |
162 | return kUnset; | |
163 | } | |
164 | ||
165 | //_____________________________________________________________________________ | |
166 | TG4G3ControlValue TG4G3ControlVector::GetControlValue(G4double value, | |
167 | TG4G3Control control) | |
168 | { | |
169 | // Conversion G4double -> G3ControlValue | |
170 | // --- | |
171 | ||
172 | return TG4G3ControlVector::GetControlValue((G4int)value, control); | |
173 | } | |
174 | ||
175 | ||
176 | //_____________________________________________________________________________ | |
177 | G4bool TG4G3ControlVector::SetControl(TG4G3Control control, | |
178 | TG4G3ControlValue controlValue, | |
179 | TG4G3CutVector& cuts) | |
180 | { | |
181 | // Sets the controlValue for the specified process control. | |
182 | // Modifies cuts if necessary. | |
183 | // Returns true if the control value was set. | |
184 | // --- | |
185 | ||
186 | if (control == kDRAY) | |
187 | if (controlValue == kActivate && | |
188 | GetControlValue(kLOSS) == kActivate2) { | |
189 | TG4Globals::Warning( | |
190 | "TG4Limits::SetG3Control: Cannot set DRAY=1 when LOSS=2."); | |
191 | return false; | |
192 | } | |
193 | else | |
194 | cuts.SetDeltaRaysOn(true); | |
195 | ||
196 | if (control == kLOSS && controlValue == kActivate2) { | |
197 | SetControl(kDRAY, kInActivate, cuts); | |
198 | cuts.SetDeltaRaysOn(false); | |
199 | } | |
200 | ||
201 | fControlVector[control] = controlValue; | |
202 | return true; | |
203 | } | |
204 | ||
205 | //_____________________________________________________________________________ | |
206 | void TG4G3ControlVector::SetG3Defaults() | |
207 | { | |
208 | // Sets G3 default values for all controls. | |
209 | // --- | |
210 | ||
211 | for (G4int i=0; i<=kNoG3Controls; i++) | |
212 | fControlVector[i] = TG4G3Defaults::Instance()->ControlValue(i); | |
213 | } | |
214 | ||
215 | //_____________________________________________________________________________ | |
216 | G4bool TG4G3ControlVector::Update(const TG4G3ControlVector& vector) | |
217 | { | |
218 | // Unset value of DRAY (this information was passed to cut vector.) | |
219 | // Resets value of LOSS (the special controls process operates only with | |
220 | // activate/inactivate options.) | |
221 | // Returns true if some value was modified. | |
222 | // --- | |
223 | ||
224 | G4bool result = false; | |
225 | ||
226 | if (fControlVector[kDRAY] != kUnset ) { | |
227 | fControlVector[kDRAY] = kUnset; | |
228 | result = true; | |
229 | } | |
230 | ||
231 | // if both kLOSS values will have the same effect | |
232 | // unset this control | |
233 | ||
234 | TG4G3ControlValue passed = vector[kLOSS]; | |
235 | TG4G3ControlValue current = fControlVector[kLOSS]; | |
236 | ||
237 | if (passed == kActivate2) passed = kActivate; | |
238 | if (current == kActivate2) current = kActivate; | |
239 | // there is no need to distinguish | |
240 | // kActivate, kActivate2 after Init phase | |
241 | ||
242 | if (current == passed) current = kUnset; | |
243 | // if both kLOSS values will have the same effect | |
244 | // unset this control | |
245 | ||
246 | if (current != fControlVector[kLOSS]) { | |
247 | fControlVector[kLOSS] = current; | |
248 | result = true; | |
249 | } | |
250 | return result; | |
251 | } | |
252 | ||
253 | //_____________________________________________________________________________ | |
254 | void TG4G3ControlVector::Print() const | |
255 | { | |
256 | // Prints the controls. | |
257 | // --- | |
258 | ||
259 | G4cout << " G3 control vector:" << G4endl; | |
260 | for (G4int i=0; i<kNoG3Controls; i++) | |
261 | //if (i != kDRAY) { | |
262 | G4cout << " " << fgControlNameVector[i] | |
263 | << " control value: " << fControlVector[i] << G4endl; | |
264 | //} | |
265 | } | |
266 | ||
267 | //_____________________________________________________________________________ | |
268 | TG4G3ControlValue | |
269 | TG4G3ControlVector::GetControlValue(G4VProcess* process) const | |
270 | { | |
271 | // Returns the control value for the particle associated with | |
272 | // the specified process. | |
273 | // --- | |
274 | ||
275 | TG4G3Control control | |
276 | = TG4ProcessControlMap::Instance()->GetControl(process); | |
277 | ||
278 | return fControlVector[control]; | |
279 | } | |
280 | ||
281 | //_____________________________________________________________________________ | |
282 | TG4G3ControlValue | |
283 | TG4G3ControlVector::GetControlValue(TG4G3Control control) const | |
284 | { | |
285 | // Returns the control value for the particle associated with | |
286 | // the specified process. | |
287 | // --- | |
288 | ||
289 | return fControlVector[control]; | |
290 | } | |
291 | ||
292 | //_____________________________________________________________________________ | |
293 | G4bool TG4G3ControlVector::IsControl() const | |
294 | { | |
295 | // Returns true if any of controls is set. | |
296 | // --- | |
297 | ||
298 | for (G4int i=0; i<kNoG3Controls; i++) | |
299 | if (fControlVector[i] != kUnset) return true; | |
300 | ||
301 | return false; | |
302 | } |