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