]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4G3ControlVector.cxx
Enable clusterizing from any Digits branch
[u/mrichter/AliRoot.git] / TGeant4 / TG4G3ControlVector.cxx
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 #include <g4std/strstream>
18
19 #include <math.h>
20
21 TG4StringVector TG4G3ControlVector::fgControlNameVector;
22
23 //_____________________________________________________________________________
24 TG4G3ControlVector::TG4G3ControlVector()
25 {
26   // initialize fControlVector 
27   for (G4int i=0; i<=kNoG3Controls; i++) fControlVector.push_back(kUnset); 
28   
29   // fill name vector
30   if (fgControlNameVector.size() == 0) FillControlNameVector(); 
31 }
32
33 //_____________________________________________________________________________
34 TG4G3ControlVector::TG4G3ControlVector(const TG4G3ControlVector& right)
35   :  fControlVector(right.fControlVector.size())
36 {
37   // copy stuff
38   *this = right;  
39 }
40
41 //_____________________________________________________________________________
42 TG4G3ControlVector::~TG4G3ControlVector() {
43 //
44 }
45
46 // operators
47
48 //_____________________________________________________________________________
49 TG4G3ControlVector& TG4G3ControlVector::operator=(
50                                           const TG4G3ControlVector& right)
51 {
52   // check assignement to self
53   if (this == &right) return *this;
54
55   // initialize fControlVector 
56   for (G4int i=0; i<=kNoG3Controls; i++) 
57     fControlVector[i] = right.fControlVector[i];
58   
59   return *this;   
60 }  
61
62 //_____________________________________________________________________________
63 TG4G3ControlValue TG4G3ControlVector::operator[](G4int index) const
64 {
65 //
66   if (index <= kNoG3Controls)
67     return fControlVector[index];
68   else {
69     TG4Globals::Exception(
70       "TG4G3ControlVector::operator[]: index out of the vector scope");
71     return kUnset;  
72   }    
73 }  
74
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
102 // public methods
103
104 //_____________________________________________________________________________
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)
181 {
182 // Sets the controlValue for the specified process control.
183 // Modifies cuts if necessary.
184 // Returns true if the control value was set.
185 // ---
186
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;
204 }
205
206 //_____________________________________________________________________________
207 void TG4G3ControlVector::SetG3Defaults()
208 {
209 // Sets G3 default values for all controls.
210 // ---
211
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 //_____________________________________________________________________________
255 G4String TG4G3ControlVector::Format() const
256 {
257 // Formats the output into a string.
258 // ---
259
260   strstream tmpStream;
261
262   tmpStream << "  G3 control vector:" << G4endl; 
263   for (G4int i=0; i<kNoG3Controls; i++) 
264     //if (i != kDRAY) {
265       tmpStream << "    " << fgControlNameVector[i] 
266                 << " control value: " << fControlVector[i] << G4endl; 
267     //}      
268     
269   return tmpStream.str();  
270 }          
271
272 //_____________________________________________________________________________
273 void TG4G3ControlVector::Print() const
274 {
275 // Prints the controls.
276 // ---
277
278   G4cout << Format();        
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];
293 }
294
295 //_____________________________________________________________________________
296 TG4G3ControlValue 
297 TG4G3ControlVector::GetControlValue(TG4G3Control control) const 
298 {
299 // Returns the control value for the particle associated with
300 // the specified process.
301 // ---
302
303   return fControlVector[control];
304 }
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 }