4 // See the class description in the header file.
6 #include "TG4G3PhysicsManager.h"
7 #include "TG4G3CutVector.h"
8 #include "TG4G3ControlVector.h"
9 #include "TG4G3Defaults.h"
11 #include <G4ParticleDefinition.hh>
12 #include <G4VProcess.hh>
13 #include <G4UImessenger.hh>
14 #include <G4ProcessTable.hh>
16 TG4G3PhysicsManager* TG4G3PhysicsManager::fgInstance = 0;
18 TG4G3PhysicsManager::TG4G3PhysicsManager()
25 TG4Globals::Exception(
26 "TG4G3PhysicsManager: attempt to create two instances of singleton.");
31 // initialize fIsCutVector
32 fIsCutVector = new TG4boolVector;
34 //for (i=0; i<kNofParticlesWSP; i++) fIsCutVector->insert(false);
35 for (i=0; i<kNofParticlesWSP; i++) fIsCutVector->push_back(false);
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);
42 // define fCutNameVector, fControlNameVector
43 FillG3CutNameVector();
44 FillG3ControlNameVector();
47 TG4G3PhysicsManager::TG4G3PhysicsManager(const TG4G3PhysicsManager& right) {
49 TG4Globals::Exception(
50 "Attempt to copy TG4G3PhysicsManager singleton.");
53 TG4G3PhysicsManager::~TG4G3PhysicsManager() {
56 delete fIsControlVector;
62 TG4G3PhysicsManager::operator=(const TG4G3PhysicsManager& right)
64 // check assignement to self
65 if (this == &right) return *this;
67 TG4Globals::Exception(
68 "Attempt to assign TG4G3PhysicsManager singleton.");
75 void TG4G3PhysicsManager::FillG3CutNameVector()
77 // Defines fCutNameVector.
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");
92 void TG4G3PhysicsManager::FillG3ControlNameVector()
94 // Defines fControlNameVector.
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");
111 void TG4G3PhysicsManager::SetCut(TG4G3Cut cut, G4double cutValue)
113 // Sets kinetic energy cut (in a G3-like way).
117 // create vector of kinetic energy cut values
118 fCutVector = new TG4G3CutVector();
120 fCutVector->SetG3Cut(cut, cutValue);
121 SwitchIsCutVector(cut);
124 void TG4G3PhysicsManager::SetProcess(TG4G3Control control, G4int controlValue)
126 // Sets control process control (in a G3-like way).
129 if (!fControlVector) {
130 // create vector of control process control values
131 fControlVector = new TG4G3ControlVector;
133 fControlVector->SetG3Control(control, controlValue);
137 void TG4G3PhysicsManager::SwitchIsCutVector(TG4G3Cut cut)
139 // Updates the vector of booleans (fIsCutVector) for the specified cut.
144 (*fIsCutVector)[kGamma] = true;
147 (*fIsCutVector)[kGamma] = true;
150 (*fIsCutVector)[kGamma] = true;
153 (*fIsCutVector)[kElectron] = true;
156 (*fIsCutVector)[kElectron] = true;
159 (*fIsCutVector)[kElectron] = true;
162 (*fIsCutVector)[kNeutralHadron] = true;
165 (*fIsCutVector)[kChargedHadron] = true;
168 (*fIsCutVector)[kMuon] = true;
175 void TG4G3PhysicsManager::SwitchIsControlVector(TG4G3Control control)
177 // Updates the vector of booleans (fIsControlVector) for the specified control.
183 (*fIsControlVector)[kGamma] = true;
187 (*fIsControlVector)[kGamma] = true;
191 (*fIsControlVector)[kGamma] = true;
195 (*fIsControlVector)[kGamma] = true;
198 // all charged particles
199 (*fIsControlVector)[kElectron] = true;
200 (*fIsControlVector)[kEplus] = true;
201 (*fIsControlVector)[kChargedHadron] = true;
202 (*fIsControlVector)[kMuon] = true;
206 (*fIsControlVector)[kEplus] = true;
210 (*fIsControlVector)[kElectron] = true;
211 (*fIsControlVector)[kEplus] = true;
212 (*fIsControlVector)[kMuon] = true;
216 (*fIsControlVector)[kNeutralHadron] = true;
217 (*fIsControlVector)[kChargedHadron] = true;
221 (*fIsControlVector)[kMuon] = true;
225 (*fIsControlVector)[kAny] = true;
228 // all charged particles
229 (*fIsControlVector)[kElectron] = true;
230 (*fIsControlVector)[kEplus] = true;
231 (*fIsControlVector)[kChargedHadron] = true;
232 (*fIsControlVector)[kMuon] = true;
235 // all charged particles
236 (*fIsControlVector)[kElectron] = true;
237 (*fIsControlVector)[kEplus] = true;
238 (*fIsControlVector)[kChargedHadron] = true;
239 (*fIsControlVector)[kMuon] = true;
246 TG4G3Cut TG4G3PhysicsManager::GetG3Cut(G4String cutName)
248 // Retrieves corresponding TG4G3Cut constant from the cutName.
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;
263 TG4G3Control TG4G3PhysicsManager::GetG3Control(G4String controlName)
265 // Retrieves corresponding TG4G3Control constant from the controlName.
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;
286 void TG4G3PhysicsManager::CheckLock()
288 // Gives exception in case the physics manager is locked.
289 // Prevents from modifying physics setup after the physics manager is locked.
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);
301 G4VProcess* TG4G3PhysicsManager::FindProcess(G4String processName) const
303 // Finds G4VProcess with specified name.
306 G4ProcessTable* processTable = G4ProcessTable::GetProcessTable();
308 G4ProcessVector* processVector
309 = processTable->FindProcesses(processName);
310 G4VProcess* firstFoundProcess = 0;
311 if (processVector->entries()>0) firstFoundProcess= (*processVector)[0];
313 processVector->clear();
314 delete processVector;
316 return firstFoundProcess;
320 G4bool TG4G3PhysicsManager::CheckCutWithTheVector(G4String name,
321 G4double value, TG4G3Cut& cut)
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.
330 // convert cut name -> TG4G3Cut
331 cut = GetG3Cut(name);
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);
347 G4bool TG4G3PhysicsManager::CheckControlWithTheVector(G4String name,
348 G4double value, TG4G3Control& control)
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.
357 // convert control name -> TG4G3Control
358 control = GetG3Control(name);
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);
372 G4bool TG4G3PhysicsManager::CheckCutWithG3Defaults(G4String name,
373 G4double value, TG4G3Cut& cut)
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.
382 // convert cut name -> TG4G3Cut
383 cut = GetG3Cut(name);
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);
397 G4bool TG4G3PhysicsManager::CheckControlWithG3Defaults(G4String name,
398 G4double value, TG4G3Control& control)
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.
407 // convert control name -> TG4G3Control
408 control = GetG3Control(name);
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);
422 void TG4G3PhysicsManager::SetG3DefaultCuts()
424 // Sets G3 default values of kinetic energy cuts.
429 // create vector of kinetic energy cut values
430 fCutVector = new TG4G3CutVector();
432 fCutVector->SetG3Defaults();
435 void TG4G3PhysicsManager::SetG3DefaultControls()
437 // Sets G3 default values of control process controls.
441 if (!fControlVector) {
442 // create vector of control process control values
443 fControlVector = new TG4G3ControlVector;
445 fControlVector->SetG3Defaults();
448 G4bool TG4G3PhysicsManager::IsSpecialCuts() const
450 // Returns true if any special cut value is set.
453 for (G4int i=0; i<kNofParticlesWSP; i++)
454 { if ((*fIsCutVector)[i]) return true; }
459 G4bool TG4G3PhysicsManager::IsSpecialControls() const
461 // Returns true if any special control value is set.
464 for (G4int i=0; i<kNofParticlesWSP; i++)
465 { if ((*fIsControlVector)[i]) return true; }
470 TG4G3ParticleWSP TG4G3PhysicsManager::GetG3ParticleWSP(
471 G4ParticleDefinition* particle) const
473 // Returns TG4G3ParticleWSP constant for the specified particle.
474 // (See TG4G3ParticleWSP.h, too.)
477 G4String name = particle->GetParticleName();
478 G4String pType = particle->GetParticleType();
480 if (name == "gamma") {
483 else if (name == "e-") {
486 else if (name == "e+") {
489 else if (( pType == "baryon" || pType == "meson" || pType == "nucleus" )) {
490 if (particle->GetPDGCharge() == 0) {
491 return kNeutralHadron;
494 return kChargedHadron;
496 else if ( name == "mu-" || name == "mu+" ) {
500 return kNofParticlesWSP;
504 void TG4G3PhysicsManager::GetG3ParticleWSPName(G4int particleWSP,
505 G4String& name) const
507 // Fills the passed name with the name/type of particle specified
508 // by TG4G3ParticleWSP constant.
509 // (See TG4G3ParticleWSP.h, too.)
512 switch (particleWSP) {
523 name = "NeutralHadron";
526 name = "ChargedHadron";
534 case kNofParticlesWSP:
538 G4String text = "TG4G3PhysicsManager::GetG3ParticleWSPName:\n";
539 text = text + " Wrong particleWSP.";
540 TG4Globals::Exception(text);