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