]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4G3PhysicsManager.cxx
Changed for new Aliroot version.
[u/mrichter/AliRoot.git] / TGeant4 / TG4G3PhysicsManager.cxx
1 // $Id$
2 // Category: physics
3 //
4 // Author: I. Hrivnacova
5 //
6 // Class TG4G3PhysicsManager
7 // -------------------------
8 // See the class description in the header file.
9
10 #include "TG4G3PhysicsManager.h"
11 #include "TG4G3CutVector.h"
12 #include "TG4G3ControlVector.h"
13 #include "TG4G3Defaults.h"
14 #include "TG4G3Units.h"
15
16 #include <G4ParticleDefinition.hh>
17 #include <G4VProcess.hh>
18 #include <G4UImessenger.hh>
19 #include <G4ProcessTable.hh>
20
21 TG4G3PhysicsManager* TG4G3PhysicsManager::fgInstance = 0;
22
23 //_____________________________________________________________________________
24 TG4G3PhysicsManager::TG4G3PhysicsManager()
25   : fLock(false),
26     fCutVector(0),
27     fControlVector(0),
28     fIsCutVector(0),
29     fIsControlVector(0) 
30 {
31 // 
32   if (fgInstance) {
33     TG4Globals::Exception(
34       "TG4G3PhysicsManager: attempt to create two instances of singleton.");
35   }
36       
37   fgInstance = this;  
38
39   // create vector of kinetic energy cut values  
40   fCutVector = new TG4G3CutVector();
41
42   // create vector of control process control values
43   fControlVector = new TG4G3ControlVector();
44
45   // initialize fIsCutVector 
46   fIsCutVector = new TG4boolVector();
47   G4int i;
48   for (i=0; i<kNofParticlesWSP; i++) fIsCutVector->push_back(false);
49
50   // initialize fIsControlVector 
51   fIsControlVector = new TG4boolVector;
52   for (i=0; i<kNofParticlesWSP; i++) fIsControlVector->push_back(false);
53 }
54
55 //_____________________________________________________________________________
56 TG4G3PhysicsManager::TG4G3PhysicsManager(const TG4G3PhysicsManager& right) {
57 // 
58   TG4Globals::Exception(
59     "Attempt to copy TG4G3PhysicsManager singleton.");
60 }
61
62 //_____________________________________________________________________________
63 TG4G3PhysicsManager::~TG4G3PhysicsManager() {
64 //
65 //  delete fIsCutVector;
66   delete fIsControlVector;
67 }
68
69 // operators
70
71 //_____________________________________________________________________________
72 TG4G3PhysicsManager& 
73 TG4G3PhysicsManager::operator=(const TG4G3PhysicsManager& right)
74 {
75   // check assignement to self
76   if (this == &right) return *this;
77
78   TG4Globals::Exception(
79     "Attempt to assign TG4G3PhysicsManager singleton.");
80     
81   return *this;  
82 }    
83           
84 // private methods
85
86 //_____________________________________________________________________________
87 void TG4G3PhysicsManager::SetCut(TG4G3Cut cut, G4double cutValue)
88 {  
89 // Sets kinetic energy cut (in a G3-like way).
90 // ---
91
92   fCutVector->SetCut(cut, cutValue);
93   SwitchIsCutVector(cut);
94 }  
95
96 //_____________________________________________________________________________
97 void TG4G3PhysicsManager::SetProcess(TG4G3Control control, 
98                                      TG4G3ControlValue controlValue)
99 {
100 // Sets control process control (in a G3-like way).
101 // ---
102   
103   if (control == kDRAY || control == kLOSS) {
104       SwitchIsCutVector(kDCUTE);
105       SwitchIsCutVector(kDCUTM);
106   }  
107
108   fControlVector->SetControl(control, controlValue, *fCutVector);
109
110
111
112 //_____________________________________________________________________________
113 void TG4G3PhysicsManager::SwitchIsCutVector(TG4G3Cut cut)
114 {
115 // Updates the vector of booleans (fIsCutVector) for the specified cut.
116 // ---
117
118   switch (cut) {
119     case kCUTGAM: 
120            (*fIsCutVector)[kGamma] = true; 
121            break;
122     case kBCUTE:
123            (*fIsCutVector)[kGamma] = true; 
124            break;
125     case kBCUTM:
126            (*fIsCutVector)[kGamma] = true; 
127            break;
128     case kCUTELE:
129            (*fIsCutVector)[kElectron] = true; 
130            (*fIsCutVector)[kEplus] = true; 
131            break;
132     case kDCUTE:
133            (*fIsCutVector)[kElectron] = true; 
134            break;
135     case kDCUTM:
136            (*fIsCutVector)[kElectron] = true; 
137            break;
138     case kCUTNEU:
139            (*fIsCutVector)[kNeutralHadron] = true; 
140            break;
141     case kCUTHAD:
142            (*fIsCutVector)[kChargedHadron] = true; 
143            break;
144     case kCUTMUO:
145            (*fIsCutVector)[kMuon] = true; 
146            break;
147     default:
148            break;
149   }
150 }
151
152 //_____________________________________________________________________________
153 void TG4G3PhysicsManager::SwitchIsControlVector(TG4G3Control control)
154 {
155 // Updates the vector of booleans (fIsControlVector) for the specified control.
156 // ---
157
158   switch (control) {
159     case kPAIR: 
160            // gamma
161            (*fIsControlVector)[kGamma] = true; 
162            break;
163     case kCOMP:
164            // gamma
165            (*fIsControlVector)[kGamma] = true; 
166            break;
167     case kPHOT:
168            // gamma
169            (*fIsControlVector)[kGamma] = true; 
170            break;
171     case kPFIS:
172            // gamma
173            (*fIsControlVector)[kGamma] = true; 
174            break;
175     case kDRAY: 
176            // all charged particles
177            (*fIsControlVector)[kElectron] = true; 
178            (*fIsControlVector)[kEplus] = true; 
179            (*fIsControlVector)[kChargedHadron] = true; 
180            (*fIsControlVector)[kMuon] = true; 
181            break;
182     case kANNI:
183            // e+ only
184            (*fIsControlVector)[kEplus] = true; 
185            break;
186     case kBREM:
187            // e-/e+, muons
188            (*fIsControlVector)[kElectron] = true; 
189            (*fIsControlVector)[kEplus] = true; 
190            (*fIsControlVector)[kMuon] = true; 
191            break;
192     case kHADR:
193            // hadrons
194            (*fIsControlVector)[kNeutralHadron] = true; 
195            (*fIsControlVector)[kChargedHadron] = true; 
196            break;
197     case kMUNU:
198            // muons
199            (*fIsControlVector)[kMuon] = true; 
200            break;
201     case kDCAY:
202            // any
203            (*fIsControlVector)[kAny] = true; 
204            break;
205     case kLOSS:
206            // all charged particles
207            (*fIsControlVector)[kElectron] = true; 
208            (*fIsControlVector)[kEplus] = true; 
209            (*fIsControlVector)[kChargedHadron] = true; 
210            (*fIsControlVector)[kMuon] = true; 
211            break;
212     case kMULS:
213            // all charged particles
214            (*fIsControlVector)[kElectron] = true; 
215            (*fIsControlVector)[kEplus] = true; 
216            (*fIsControlVector)[kChargedHadron] = true; 
217            (*fIsControlVector)[kMuon] = true; 
218            break;
219     default:
220           break;
221   }
222 }
223
224 // public methods
225
226 //_____________________________________________________________________________
227 void TG4G3PhysicsManager::CheckLock()
228 {
229 // Gives exception in case the physics manager is locked.
230 // Prevents from modifying physics setup after the physics manager is locked.
231 // ---
232
233   if (fLock) {
234     G4String text = "TG4PhysicsManager: \n";
235     text = text + "    It is too late to change physics setup. \n";
236     text = text + "    PhysicsManager has been already locked.";
237     TG4Globals::Exception(text);
238   }  
239 }
240
241 //_____________________________________________________________________________
242 G4VProcess* TG4G3PhysicsManager::FindProcess(G4String processName) const
243 {
244 // Finds G4VProcess with specified name.
245 // ---
246
247   G4ProcessTable* processTable = G4ProcessTable::GetProcessTable();
248
249   G4ProcessVector* processVector 
250     = processTable->FindProcesses(processName);
251   G4VProcess* firstFoundProcess = 0;
252   if (processVector->entries()>0) firstFoundProcess= (*processVector)[0];
253
254   processVector->clear();
255   delete processVector;
256   
257   return firstFoundProcess;
258 }
259
260 //_____________________________________________________________________________
261 G4bool TG4G3PhysicsManager::CheckCutWithTheVector(G4String name, 
262                                  G4double value, TG4G3Cut& cut)
263 {
264 // Retrieves corresponding TG4G3Cut from the name and 
265 // in case the value is different from the value in cutVector
266 // sets true the value of the fIsCutVector element 
267 // corresponding to this cut and returns true; 
268 // returns false otherwise.
269 // ---
270
271   // convert cut name -> TG4G3Cut
272   cut = TG4G3CutVector::GetCut(name);
273
274   // set switch vector element only if the value
275   // is different from the value in cutVector
276   if (cut !=kNoG3Cuts) {
277     // get tolerance from TG4G3CutVector in G3 units
278     G4double tolerance = TG4G3CutVector::Tolerance()/ TG4G3Units::Energy();
279     if (abs(value - (*fCutVector)[cut]) > tolerance) {
280       SwitchIsCutVector(cut);      
281       return true;
282     }  
283     else return false;  
284   }                      
285   return false;
286 }
287
288 //_____________________________________________________________________________
289 G4bool TG4G3PhysicsManager::CheckControlWithTheVector(G4String name, 
290                                  G4double value, TG4G3Control& control,
291                                  TG4G3ControlValue& controlValue)
292 {
293 // Retrieves corresponding TG4G3Control from the name and 
294 // in case the value is different from the value in controlVector
295 // sets true the value of the fIsControlVector element 
296 // corresponding to this control and returns true; 
297 // returns false otherwise.
298 // ---
299
300   // convert control name -> TG4G3Control
301   control = TG4G3ControlVector::GetControl(name);
302
303   // convert double value -> TG4G3ControlValue
304   controlValue = TG4G3ControlVector::GetControlValue(value, control);
305
306   // set switch vector element only if the value
307   // is different from the value in controlVector
308   if (control !=kNoG3Controls) {
309     if (controlValue != (*fControlVector)[control]) {
310       SwitchIsControlVector(control);      
311       return true;
312     }  
313     else return false;  
314   }                      
315   return false;
316 }
317
318 //_____________________________________________________________________________
319 G4bool TG4G3PhysicsManager::CheckCutWithG3Defaults(G4String name, 
320                                  G4double value, TG4G3Cut& cut)
321 {
322 // Retrieves corresponding TG4G3Cut from the name and 
323 // in case the value is different from the G3 default value
324 // sets true the value of the SwitchCutVector element 
325 // corresponding to this cut and returns true; 
326 // returns false otherwise.
327 // ---
328
329   // convert cut name -> TG4G3Cut
330   cut = TG4G3CutVector::GetCut(name);
331
332   // set switch vector element only if the value
333   // is different from G3 default
334   if (cut !=kNoG3Cuts) {
335     if (!fG3Defaults.IsDefaultCut(cut, value)) {
336       SwitchIsCutVector(cut);      
337       return true;
338     }  
339     else return false;  
340   }                      
341   return false;
342 }
343
344 //_____________________________________________________________________________
345 G4bool TG4G3PhysicsManager::CheckControlWithG3Defaults(G4String name, 
346                                  G4double value, TG4G3Control& control,
347                                  TG4G3ControlValue& controlValue)
348 {
349 // Retrieves corresponding TG4G3Control from the name and 
350 // in case the value is different from the G3 default value
351 // sets true the value of the SwitchControlVector element 
352 // corresponding to this control and returns true; 
353 // returns false otherwise.
354 // ---
355
356   // convert control name -> TG4G3Control
357   control = TG4G3ControlVector::GetControl(name);
358
359   // convert double value -> TG4G3ControlValue
360   controlValue = TG4G3ControlVector::GetControlValue(value, control);
361
362   // set switch vector element only if the value
363   // is different from G3 default
364   if (control !=kNoG3Controls) {
365     if (!fG3Defaults.IsDefaultControl(control, controlValue)) {
366       SwitchIsControlVector(control);      
367       return true;
368     }  
369     else return false;  
370   }                      
371   return false;
372 }
373
374 //_____________________________________________________________________________
375 void TG4G3PhysicsManager::SetG3DefaultCuts() 
376 {
377 // Sets G3 default values of kinetic energy cuts.
378 // ---
379
380   CheckLock();
381   fCutVector->SetG3Defaults();
382 }
383
384 //_____________________________________________________________________________
385 void TG4G3PhysicsManager::SetG3DefaultControls()
386 {
387 // Sets G3 default values of control process controls.
388 // ---
389
390   CheckLock();
391   fControlVector->SetG3Defaults();
392 }  
393
394 //_____________________________________________________________________________
395 G4bool TG4G3PhysicsManager::IsSpecialCuts() const
396 {
397 // Returns true if any special cut value is set.
398 // ---
399
400
401   for (G4int i=0; i<kNofParticlesWSP; i++)
402   {  if ((*fIsCutVector)[i]) return true; }
403
404   return false;
405 }
406
407 //_____________________________________________________________________________
408 G4bool TG4G3PhysicsManager::IsSpecialControls() const
409 {
410 // Returns true if any special control value is set.
411 // ---
412
413   for (G4int i=0; i<kNofParticlesWSP; i++)
414   {  if ((*fIsControlVector)[i]) return true; }
415
416   return false;
417 }
418
419 //_____________________________________________________________________________
420 TG4G3ParticleWSP TG4G3PhysicsManager::GetG3ParticleWSP(
421                                       G4ParticleDefinition* particle) const 
422 {
423 // Returns TG4G3ParticleWSP constant for the specified particle.
424 // (See TG4G3ParticleWSP.h, too.)
425 // ---
426
427   G4String name = particle->GetParticleName();     
428   G4String pType = particle->GetParticleType();
429     
430   if (name == "gamma") {
431     return kGamma;
432   }  
433   else if (name == "e-") {    
434     return kElectron;
435   }  
436   else if (name == "e+") {   
437     return kEplus;
438   }  
439   else if (( pType == "baryon" || pType == "meson" || pType == "nucleus" )) {
440     if (particle->GetPDGCharge() == 0) { 
441       return kNeutralHadron;
442     }
443     else  
444       return kChargedHadron;
445   }    
446   else if ( name == "mu-" || name == "mu+" ) {
447     return kMuon;
448   }  
449   else {
450     return kNofParticlesWSP;
451   }    
452 }  
453
454 //_____________________________________________________________________________
455 G4String TG4G3PhysicsManager::GetG3ParticleWSPName(G4int particleWSP) const 
456 {
457 // Returns the name of the particle specified by TG4G3ParticleWSP constant.
458 // (See TG4G3ParticleWSP.h, too.)
459 // ---
460
461   switch (particleWSP) {
462     case kGamma:
463       return "Gamma";
464       break;
465     case kElectron:
466       return "Electron";
467       break;
468     case kEplus:
469       return "Eplus";
470       break;
471     case kNeutralHadron:
472       return "NeutralHadron";
473       break;
474     case kChargedHadron:
475       return "ChargedHadron";
476       break;
477     case kMuon:
478       return "Muon";
479       break;
480     case kAny:
481       return "Any";
482       break;
483     case kNofParticlesWSP:
484       return "NoSP";
485       break;
486     default:
487       G4String text = "TG4G3PhysicsManager::GetG3ParticleWSPName:\n";
488       text = text + "   Wrong particleWSP."; 
489       TG4Globals::Exception(text);
490       return "";
491   }
492 }  
493