4 // Author: I. Hrivnacova
6 // Class TG4G3ControlVector
7 // ------------------------
8 // See the class description in the header file.
10 #include "TG4G3ControlVector.h"
11 #include "TG4G3CutVector.h"
12 #include "TG4ProcessControlMap.h"
13 #include "TG4G3Defaults.h"
14 #include "TG4Globals.h"
16 #include <G4VProcess.hh>
17 #include <g4std/strstream>
21 TG4StringVector TG4G3ControlVector::fgControlNameVector;
23 //_____________________________________________________________________________
24 TG4G3ControlVector::TG4G3ControlVector()
26 // initialize fControlVector
27 for (G4int i=0; i<=kNoG3Controls; i++) fControlVector.push_back(kUnset);
30 if (fgControlNameVector.size() == 0) FillControlNameVector();
33 //_____________________________________________________________________________
34 TG4G3ControlVector::TG4G3ControlVector(const TG4G3ControlVector& right)
35 : fControlVector(right.fControlVector.size())
41 //_____________________________________________________________________________
42 TG4G3ControlVector::~TG4G3ControlVector() {
48 //_____________________________________________________________________________
49 TG4G3ControlVector& TG4G3ControlVector::operator=(
50 const TG4G3ControlVector& right)
52 // check assignement to self
53 if (this == &right) return *this;
55 // initialize fControlVector
56 for (G4int i=0; i<=kNoG3Controls; i++)
57 fControlVector[i] = right.fControlVector[i];
62 //_____________________________________________________________________________
63 TG4G3ControlValue TG4G3ControlVector::operator[](G4int index) const
66 if (index <= kNoG3Controls)
67 return fControlVector[index];
69 TG4Globals::Exception(
70 "TG4G3ControlVector::operator[]: index out of the vector scope");
77 //_____________________________________________________________________________
78 void TG4G3ControlVector::FillControlNameVector()
80 // Defines fControlNameVector.
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");
104 //_____________________________________________________________________________
105 TG4G3Control TG4G3ControlVector::GetControl(const G4String& controlName)
107 // Retrieves corresponding TG4G3Control constant from the controlName.
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;
125 //_____________________________________________________________________________
126 const G4String& TG4G3ControlVector::GetControlName(TG4G3Control control)
128 // Returns name of a specified cut.
132 if (fgControlNameVector.size() == 0)
133 TG4G3ControlVector::FillControlNameVector();
135 return fgControlNameVector[control];
138 //_____________________________________________________________________________
139 TG4G3ControlValue TG4G3ControlVector::GetControlValue(G4int value,
140 TG4G3Control control)
142 // Conversion G4int -> G3ControlValue,
143 // special treatment for LOSS values 3,4,5.
156 case 3: case 4: case 5:
157 if (control == kLOSS)
166 //_____________________________________________________________________________
167 TG4G3ControlValue TG4G3ControlVector::GetControlValue(G4double value,
168 TG4G3Control control)
170 // Conversion G4double -> G3ControlValue
173 return TG4G3ControlVector::GetControlValue((G4int)value, control);
177 //_____________________________________________________________________________
178 G4bool TG4G3ControlVector::SetControl(TG4G3Control control,
179 TG4G3ControlValue controlValue,
180 TG4G3CutVector& cuts)
182 // Sets the controlValue for the specified process control.
183 // Modifies cuts if necessary.
184 // Returns true if the control value was set.
187 if (control == kDRAY)
188 if (controlValue == kActivate &&
189 GetControlValue(kLOSS) == kActivate2) {
191 "TG4Limits::SetG3Control: Cannot set DRAY=1 when LOSS=2.");
195 cuts.SetDeltaRaysOn(true);
197 if (control == kLOSS && controlValue == kActivate2) {
198 SetControl(kDRAY, kInActivate, cuts);
199 cuts.SetDeltaRaysOn(false);
202 fControlVector[control] = controlValue;
206 //_____________________________________________________________________________
207 void TG4G3ControlVector::SetG3Defaults()
209 // Sets G3 default values for all controls.
212 for (G4int i=0; i<=kNoG3Controls; i++)
213 fControlVector[i] = TG4G3Defaults::Instance()->ControlValue(i);
216 //_____________________________________________________________________________
217 G4bool TG4G3ControlVector::Update(const TG4G3ControlVector& vector)
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.
225 G4bool result = false;
227 if (fControlVector[kDRAY] != kUnset ) {
228 fControlVector[kDRAY] = kUnset;
232 // if both kLOSS values will have the same effect
233 // unset this control
235 TG4G3ControlValue passed = vector[kLOSS];
236 TG4G3ControlValue current = fControlVector[kLOSS];
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
243 if (current == passed) current = kUnset;
244 // if both kLOSS values will have the same effect
245 // unset this control
247 if (current != fControlVector[kLOSS]) {
248 fControlVector[kLOSS] = current;
254 //_____________________________________________________________________________
255 G4String TG4G3ControlVector::Format() const
257 // Formats the output into a string.
262 tmpStream << " G3 control vector:" << G4endl;
263 for (G4int i=0; i<kNoG3Controls; i++)
265 tmpStream << " " << fgControlNameVector[i]
266 << " control value: " << fControlVector[i] << G4endl;
269 return tmpStream.str();
272 //_____________________________________________________________________________
273 void TG4G3ControlVector::Print() const
275 // Prints the controls.
281 //_____________________________________________________________________________
283 TG4G3ControlVector::GetControlValue(G4VProcess* process) const
285 // Returns the control value for the particle associated with
286 // the specified process.
290 = TG4ProcessControlMap::Instance()->GetControl(process);
292 return fControlVector[control];
295 //_____________________________________________________________________________
297 TG4G3ControlVector::GetControlValue(TG4G3Control control) const
299 // Returns the control value for the particle associated with
300 // the specified process.
303 return fControlVector[control];
306 //_____________________________________________________________________________
307 G4bool TG4G3ControlVector::IsControl() const
309 // Returns true if any of controls is set.
312 for (G4int i=0; i<kNoG3Controls; i++)
313 if (fControlVector[i] != kUnset) return true;