]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TGeant4/TG4G3PhysicsManager.cxx
Format() method added; changed Print() - usage of Format()
[u/mrichter/AliRoot.git] / TGeant4 / TG4G3PhysicsManager.cxx
CommitLineData
17929791 1// $Id$
2// Category: physics
3//
e5967ab3 4// Author: I. Hrivnacova
5//
6// Class TG4G3PhysicsManager
7// -------------------------
17929791 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"
e5967ab3 14#include "TG4G3Units.h"
17929791 15
16#include <G4ParticleDefinition.hh>
17#include <G4VProcess.hh>
18#include <G4UImessenger.hh>
19#include <G4ProcessTable.hh>
20
21TG4G3PhysicsManager* TG4G3PhysicsManager::fgInstance = 0;
22
72095f7c 23//_____________________________________________________________________________
17929791 24TG4G3PhysicsManager::TG4G3PhysicsManager()
25 : fLock(false),
26 fCutVector(0),
e5967ab3 27 fControlVector(0),
28 fIsCutVector(0),
29 fIsControlVector(0)
e2a28c8e 30{
31//
17929791 32 if (fgInstance) {
33 TG4Globals::Exception(
34 "TG4G3PhysicsManager: attempt to create two instances of singleton.");
35 }
36
37 fgInstance = this;
38
e5967ab3 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
17929791 45 // initialize fIsCutVector
e5967ab3 46 fIsCutVector = new TG4boolVector();
17929791 47 G4int i;
17929791 48 for (i=0; i<kNofParticlesWSP; i++) fIsCutVector->push_back(false);
49
50 // initialize fIsControlVector
51 fIsControlVector = new TG4boolVector;
17929791 52 for (i=0; i<kNofParticlesWSP; i++) fIsControlVector->push_back(false);
17929791 53}
54
72095f7c 55//_____________________________________________________________________________
17929791 56TG4G3PhysicsManager::TG4G3PhysicsManager(const TG4G3PhysicsManager& right) {
57//
58 TG4Globals::Exception(
59 "Attempt to copy TG4G3PhysicsManager singleton.");
60}
61
72095f7c 62//_____________________________________________________________________________
17929791 63TG4G3PhysicsManager::~TG4G3PhysicsManager() {
64//
e5967ab3 65// delete fIsCutVector;
17929791 66 delete fIsControlVector;
67}
68
69// operators
70
72095f7c 71//_____________________________________________________________________________
17929791 72TG4G3PhysicsManager&
73TG4G3PhysicsManager::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
72095f7c 86//_____________________________________________________________________________
17929791 87void TG4G3PhysicsManager::SetCut(TG4G3Cut cut, G4double cutValue)
88{
89// Sets kinetic energy cut (in a G3-like way).
90// ---
91
e5967ab3 92 fCutVector->SetCut(cut, cutValue);
17929791 93 SwitchIsCutVector(cut);
94}
95
72095f7c 96//_____________________________________________________________________________
e5967ab3 97void TG4G3PhysicsManager::SetProcess(TG4G3Control control,
98 TG4G3ControlValue controlValue)
17929791 99{
100// Sets control process control (in a G3-like way).
101// ---
e5967ab3 102
103 if (control == kDRAY || control == kLOSS) {
104 SwitchIsCutVector(kDCUTE);
105 SwitchIsCutVector(kDCUTM);
17929791 106 }
e5967ab3 107
108 fControlVector->SetControl(control, controlValue, *fCutVector);
17929791 109}
110
e5967ab3 111
72095f7c 112//_____________________________________________________________________________
17929791 113void 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;
e5967ab3 130 (*fIsCutVector)[kEplus] = true;
17929791 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
72095f7c 152//_____________________________________________________________________________
17929791 153void 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
17929791 224// public methods
225
72095f7c 226//_____________________________________________________________________________
17929791 227void 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
72095f7c 241//_____________________________________________________________________________
17929791 242G4VProcess* 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
72095f7c 260//_____________________________________________________________________________
17929791 261G4bool 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
e5967ab3 272 cut = TG4G3CutVector::GetCut(name);
17929791 273
274 // set switch vector element only if the value
275 // is different from the value in cutVector
276 if (cut !=kNoG3Cuts) {
e5967ab3 277 // get tolerance from TG4G3CutVector in G3 units
278 G4double tolerance = TG4G3CutVector::Tolerance()/ TG4G3Units::Energy();
279 if (abs(value - (*fCutVector)[cut]) > tolerance) {
17929791 280 SwitchIsCutVector(cut);
281 return true;
282 }
283 else return false;
284 }
285 return false;
286}
287
72095f7c 288//_____________________________________________________________________________
17929791 289G4bool TG4G3PhysicsManager::CheckControlWithTheVector(G4String name,
e5967ab3 290 G4double value, TG4G3Control& control,
291 TG4G3ControlValue& controlValue)
17929791 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
e5967ab3 301 control = TG4G3ControlVector::GetControl(name);
302
303 // convert double value -> TG4G3ControlValue
304 controlValue = TG4G3ControlVector::GetControlValue(value, control);
17929791 305
306 // set switch vector element only if the value
307 // is different from the value in controlVector
308 if (control !=kNoG3Controls) {
e5967ab3 309 if (controlValue != (*fControlVector)[control]) {
17929791 310 SwitchIsControlVector(control);
311 return true;
312 }
313 else return false;
314 }
315 return false;
316}
317
72095f7c 318//_____________________________________________________________________________
17929791 319G4bool 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
e5967ab3 330 cut = TG4G3CutVector::GetCut(name);
17929791 331
332 // set switch vector element only if the value
333 // is different from G3 default
334 if (cut !=kNoG3Cuts) {
e5967ab3 335 if (!fG3Defaults.IsDefaultCut(cut, value)) {
17929791 336 SwitchIsCutVector(cut);
337 return true;
338 }
339 else return false;
340 }
341 return false;
342}
343
72095f7c 344//_____________________________________________________________________________
17929791 345G4bool TG4G3PhysicsManager::CheckControlWithG3Defaults(G4String name,
e5967ab3 346 G4double value, TG4G3Control& control,
347 TG4G3ControlValue& controlValue)
17929791 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
e5967ab3 357 control = TG4G3ControlVector::GetControl(name);
358
359 // convert double value -> TG4G3ControlValue
360 controlValue = TG4G3ControlVector::GetControlValue(value, control);
17929791 361
362 // set switch vector element only if the value
363 // is different from G3 default
364 if (control !=kNoG3Controls) {
e5967ab3 365 if (!fG3Defaults.IsDefaultControl(control, controlValue)) {
17929791 366 SwitchIsControlVector(control);
367 return true;
368 }
369 else return false;
370 }
371 return false;
372}
373
72095f7c 374//_____________________________________________________________________________
17929791 375void TG4G3PhysicsManager::SetG3DefaultCuts()
376{
377// Sets G3 default values of kinetic energy cuts.
378// ---
379
380 CheckLock();
17929791 381 fCutVector->SetG3Defaults();
382}
383
72095f7c 384//_____________________________________________________________________________
17929791 385void TG4G3PhysicsManager::SetG3DefaultControls()
386{
387// Sets G3 default values of control process controls.
388// ---
389
390 CheckLock();
17929791 391 fControlVector->SetG3Defaults();
392}
393
72095f7c 394//_____________________________________________________________________________
17929791 395G4bool TG4G3PhysicsManager::IsSpecialCuts() const
396{
397// Returns true if any special cut value is set.
398// ---
399
e5967ab3 400
17929791 401 for (G4int i=0; i<kNofParticlesWSP; i++)
402 { if ((*fIsCutVector)[i]) return true; }
403
404 return false;
405}
406
72095f7c 407//_____________________________________________________________________________
17929791 408G4bool 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
72095f7c 419//_____________________________________________________________________________
17929791 420TG4G3ParticleWSP 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
72095f7c 454//_____________________________________________________________________________
e5967ab3 455G4String TG4G3PhysicsManager::GetG3ParticleWSPName(G4int particleWSP) const
17929791 456{
e5967ab3 457// Returns the name of the particle specified by TG4G3ParticleWSP constant.
17929791 458// (See TG4G3ParticleWSP.h, too.)
459// ---
460
461 switch (particleWSP) {
462 case kGamma:
e5967ab3 463 return "Gamma";
17929791 464 break;
465 case kElectron:
e5967ab3 466 return "Electron";
17929791 467 break;
468 case kEplus:
e5967ab3 469 return "Eplus";
17929791 470 break;
471 case kNeutralHadron:
e5967ab3 472 return "NeutralHadron";
17929791 473 break;
474 case kChargedHadron:
e5967ab3 475 return "ChargedHadron";
17929791 476 break;
477 case kMuon:
e5967ab3 478 return "Muon";
17929791 479 break;
480 case kAny:
e5967ab3 481 return "Any";
17929791 482 break;
483 case kNofParticlesWSP:
e5967ab3 484 return "NoSP";
17929791 485 break;
486 default:
487 G4String text = "TG4G3PhysicsManager::GetG3ParticleWSPName:\n";
488 text = text + " Wrong particleWSP.";
489 TG4Globals::Exception(text);
e5967ab3 490 return "";
17929791 491 }
492}
493