]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4SpecialControls.cxx
Add ResetDecayTable() and SsetDecayTable() methods.
[u/mrichter/AliRoot.git] / TGeant4 / TG4SpecialControls.cxx
1 // $Id$ //
2 // Category: physics
3 //
4 // See the class description in the header file.
5
6 #include "TG4SpecialControls.h"
7 #include "TG4Limits.h"
8
9 #include <G4StepStatus.hh>
10 #include <G4ProcessManager.hh>
11 #include <G4ProcessVector.hh>
12
13 TG4SpecialControls::TG4SpecialControls(const G4String& aName)
14   : G4VProcess(aName),
15     fSwitchControls(kUnswitch)
16 {
17    // verboseLevel = 1;
18    if (verboseLevel>0) {
19      G4cout << GetProcessName() << " is created "<< G4endl;
20    }
21 }
22
23 TG4SpecialControls::TG4SpecialControls(const TG4SpecialControls& right) {
24 // 
25   TG4Globals::Exception(
26     "TG4SpecialControls is protected from copying.");
27 }
28
29 TG4SpecialControls::~TG4SpecialControls() {
30 //
31 }
32
33 // operators
34
35 TG4SpecialControls& TG4SpecialControls::operator=(
36                                           const TG4SpecialControls& right)
37 {
38   // check assignement to self
39   if (this == &right) return *this;
40
41   TG4Globals::Exception(
42     "TG4SpecialControls is protected from assigning.");
43     
44   return *this;  
45
46
47 // public methods   
48           
49 G4double TG4SpecialControls::PostStepGetPhysicalInteractionLength(
50                            const G4Track& track, G4double previousStepSize,
51                            G4ForceCondition* condition)
52 {
53 // Returns the Step-size (actual length) which is allowed 
54 // by this process.
55 // ---
56
57   *condition = NotForced;
58
59   G4double proposedStep = DBL_MAX;
60   G4double minStep = (1.0e-9)*m;
61     // must be greater than DBL_MIN - so that particle can get out of
62     // the boundary 
63     // proposedStep = 0.; causes navigator to fall into panic 
64   
65   G4StepStatus status     
66     = track.GetStep()->GetPreStepPoint()->GetStepStatus();
67   TG4Limits* limits 
68     = (TG4Limits*) track.GetVolume()->GetLogicalVolume()->GetUserLimits();
69
70   if (fSwitchControls != kUnswitch) {
71     if (status == fGeomBoundary) {
72       if  ((limits) && (limits->IsControl())) {
73         // particle is exiting a logical volume with special controls
74         // and entering another logical volume with special controls 
75         proposedStep = minStep;
76         fSwitchControls = kReswitch;
77         if (verboseLevel>0) G4cout << "kReswitch" << G4endl;
78       }
79       else {
80         // particle is exiting a logical volume with special controls
81         // and entering a logical volume without special controls 
82         proposedStep = minStep;
83         fSwitchControls = kUnswitch;
84         if (verboseLevel>0) G4cout << "kUnswitch" << G4endl;
85       }
86     }
87   }
88   else if ((limits) && (limits->IsControl())) {
89        // particle is entering a logical volume with special controls
90        // that have not yet been set
91        proposedStep = minStep;
92        fSwitchControls = kSwitch;
93        if (verboseLevel>0) G4cout << "kSwitch" << G4endl;
94   }  
95   return proposedStep;
96 }
97
98 G4VParticleChange* TG4SpecialControls::PostStepDoIt(
99                       const G4Track& track, const G4Step& step)
100 {
101 // Changes processes activation of the current track
102 // according to the current user limits.
103 // ---
104
105   TG4Limits* limits 
106     = (TG4Limits*) track.GetVolume()->GetLogicalVolume()->GetUserLimits();
107
108   G4ProcessManager* processManager
109     = track.GetDefinition()->GetProcessManager();
110   G4ProcessVector* processVector = processManager->GetProcessList();
111   // processManager->DumpInfo();
112
113   if ((fSwitchControls==kUnswitch) || (fSwitchControls==kReswitch)) {
114     // set processes activation back
115     for (G4int i=0; i<fSwitchedProcesses.entries(); i++) {
116       if (verboseLevel>0) {
117         G4cout << "Reset process activation back in" 
118                << track.GetVolume()->GetName() 
119                << G4endl;
120       }
121       processManager
122         ->SetProcessActivation(fSwitchedProcesses[i],fSwitchedControls[i]);
123     }
124     fSwitchedProcesses.clear();
125     fSwitchedControls.clear();
126   }
127
128   if ((fSwitchControls==kSwitch) ||  (fSwitchControls==kReswitch)) {
129     // set TG4Limits processes controls
130     for (G4int i=0; i<processManager->GetProcessListLength(); i++) {
131       G4int control = limits->GetControl((*processVector)[i]);
132       if (control != kUnset) {
133         // store the current processes controls;
134         fSwitchedProcesses.insert((*processVector)[i]);
135         //fSwitchedControls.insert(processManager->GetProcessActivation(i));
136         fSwitchedControls.push_back(processManager->GetProcessActivation(i));
137         if (control == kInActivate) {
138           if (verboseLevel>0) {
139             G4cout << "Set process inactivation for " 
140                    << (*processVector)[i]->GetProcessName() << " in " 
141                    << track.GetVolume()->GetName() 
142                    << G4endl;
143           }
144           processManager->SetProcessActivation(i,false);
145         }  
146         else {
147           // ((control == kActivate) || (control == kActivate2)) 
148           if (verboseLevel>0) {
149             G4cout << "Set process activation for " 
150                    << (*processVector)[i]->GetProcessName() << " in " 
151                    << track.GetVolume()->GetName() 
152                    << G4endl;
153           }
154           processManager->SetProcessActivation(i,true);
155         }
156       }  
157     }
158   }  
159   // processManager->DumpInfo();        
160   aParticleChange.Initialize(track);
161   aParticleChange.SetStatusChange(fAlive);
162   return &aParticleChange;
163 }
164