]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TGeant4/TG4G3ControlVector.cxx
Minor improvements on the code
[u/mrichter/AliRoot.git] / TGeant4 / TG4G3ControlVector.cxx
CommitLineData
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>
17
18#include <math.h>
19
e5967ab3 20TG4StringVector TG4G3ControlVector::fgControlNameVector;
21
72095f7c 22//_____________________________________________________________________________
ae542d51 23TG4G3ControlVector::TG4G3ControlVector()
24{
25 // initialize fControlVector
e5967ab3 26 for (G4int i=0; i<=kNoG3Controls; i++) fControlVector.push_back(kUnset);
27
28 // fill name vector
29 if (fgControlNameVector.size() == 0) FillControlNameVector();
ae542d51 30}
31
72095f7c 32//_____________________________________________________________________________
ae542d51 33TG4G3ControlVector::TG4G3ControlVector(const TG4G3ControlVector& right)
e5967ab3 34 : fControlVector(right.fControlVector.size())
ae542d51 35{
58c0119e 36 // copy stuff
37 *this = right;
ae542d51 38}
39
72095f7c 40//_____________________________________________________________________________
ae542d51 41TG4G3ControlVector::~TG4G3ControlVector() {
42//
ae542d51 43}
44
45// operators
46
72095f7c 47//_____________________________________________________________________________
ae542d51 48TG4G3ControlVector& TG4G3ControlVector::operator=(
49 const TG4G3ControlVector& right)
50{
51 // check assignement to self
52 if (this == &right) return *this;
53
54 // initialize fControlVector
e5967ab3 55 for (G4int i=0; i<=kNoG3Controls; i++)
56 fControlVector[i] = right.fControlVector[i];
ae542d51 57
58 return *this;
59}
60
72095f7c 61//_____________________________________________________________________________
e5967ab3 62TG4G3ControlValue TG4G3ControlVector::operator[](G4int index) const
ae542d51 63{
64//
e5967ab3 65 if (index <= kNoG3Controls)
66 return fControlVector[index];
ae542d51 67 else {
68 TG4Globals::Exception(
69 "TG4G3ControlVector::operator[]: index out of the vector scope");
e5967ab3 70 return kUnset;
ae542d51 71 }
72}
73
e5967ab3 74// private methods
75
76//_____________________________________________________________________________
77void 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
ae542d51 101// public methods
102
72095f7c 103//_____________________________________________________________________________
e5967ab3 104TG4G3Control 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//_____________________________________________________________________________
125const 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//_____________________________________________________________________________
138TG4G3ControlValue 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//_____________________________________________________________________________
166TG4G3ControlValue 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//_____________________________________________________________________________
177G4bool TG4G3ControlVector::SetControl(TG4G3Control control,
178 TG4G3ControlValue controlValue,
179 TG4G3CutVector& cuts)
ae542d51 180{
181// Sets the controlValue for the specified process control.
e5967ab3 182// Modifies cuts if necessary.
183// Returns true if the control value was set.
ae542d51 184// ---
185
e5967ab3 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;
ae542d51 203}
204
72095f7c 205//_____________________________________________________________________________
ae542d51 206void TG4G3ControlVector::SetG3Defaults()
207{
208// Sets G3 default values for all controls.
209// ---
210
e5967ab3 211 for (G4int i=0; i<=kNoG3Controls; i++)
212 fControlVector[i] = TG4G3Defaults::Instance()->ControlValue(i);
213}
214
215//_____________________________________________________________________________
216G4bool 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//_____________________________________________________________________________
254void 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//_____________________________________________________________________________
268TG4G3ControlValue
269TG4G3ControlVector::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];
ae542d51 279}
280
72095f7c 281//_____________________________________________________________________________
e5967ab3 282TG4G3ControlValue
283TG4G3ControlVector::GetControlValue(TG4G3Control control) const
ae542d51 284{
285// Returns the control value for the particle associated with
286// the specified process.
287// ---
288
e5967ab3 289 return fControlVector[control];
ae542d51 290}
e5967ab3 291
292//_____________________________________________________________________________
293G4bool 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}