Initial version
[u/mrichter/AliRoot.git] / TGeant4 / TG4PhysicsConstructorSpecialControls.cxx
1 // $Id$
2 // Category: physics
3 //
4 // See the class description in the header file.
5
6 #include "TG4PhysicsConstructorSpecialControls.h"
7 #include "TG4SpecialControls.h"
8 #include "TG4G3PhysicsManager.h"
9 #include "TG4G3ControlVector.h"
10
11 #include <G4ParticleDefinition.hh>
12 #include <G4ProcessManager.hh>
13 #include <G4VProcess.hh>
14
15 TG4PhysicsConstructorSpecialControls::TG4PhysicsConstructorSpecialControls(
16                                      const G4String& name)
17   : G4VPhysicsConstructor(name)
18 {
19 //
20   SetVerboseLevel(1);
21 }
22
23 TG4PhysicsConstructorSpecialControls::~TG4PhysicsConstructorSpecialControls() {
24 //
25 }
26
27 // protected methods
28
29 void TG4PhysicsConstructorSpecialControls::ConstructParticle()
30 {
31 // The particles are constructed in the 
32 // TG4ModularPhysicsList.
33 // ---
34 }
35
36 void TG4PhysicsConstructorSpecialControls::ConstructProcess()
37 {
38 // Adds TG4SpecialControls "process" that activates
39 // the control process controls defined in TG4Limits.
40 // ---
41
42   TG4G3PhysicsManager* g3PhysicsManager 
43     = TG4G3PhysicsManager::Instance();
44
45   if (g3PhysicsManager->IsSpecialControls())
46   {
47     G4cout << "IsSpecialControls started" << G4endl;
48     TG4boolVector* isControlVector 
49       = g3PhysicsManager->GetIsControlVector(); 
50
51     theParticleIterator->reset();
52     while ((*theParticleIterator)())
53     {
54       G4ParticleDefinition* particle = theParticleIterator->value();
55       TG4G3ParticleWSP particleWSP 
56         = g3PhysicsManager->GetG3ParticleWSP(particle);
57       //G4String name;
58       //GetG3ParticleWSPName(particleWSP, name);
59
60       // special process is set in case
61       // the special control is set by TG4Limits    
62       if ((particleWSP !=kNofParticlesWSP) && 
63           ((*isControlVector)[particleWSP])) {
64         // check if process already exists
65         G4String processName = "specialControl";
66         G4VProcess* process = g3PhysicsManager->FindProcess(processName);
67         if (!process) {
68           process = new TG4SpecialControls(processName);
69         }  
70         //particle->GetProcessManager()->AddProcess(process, 0, -1, 1);
71         particle->GetProcessManager()->AddDiscreteProcess(process);
72       }
73     }
74
75     if (verboseLevel>0) {
76       G4cout << "TG4PhysicsConstructorSpecialControls::ConstructProcess: " << G4endl;
77       G4cout << "   Special controls process is defined for: " << G4endl
78              << "   ";
79       for (G4int i=0; i<kNofParticlesWSP; i++) {
80         G4String name;
81         g3PhysicsManager->GetG3ParticleWSPName(i, name);
82         if ((*isControlVector)[i]) G4cout << name << " ";
83       }  
84       G4cout << G4endl;
85     }  
86   }
87 }
88