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