1 | // |
---|
2 | // ******************************************************************** |
---|
3 | // * License and Disclaimer * |
---|
4 | // * * |
---|
5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
7 | // * conditions of the Geant4 Software License, included in the file * |
---|
8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
9 | // * include a list of copyright holders. * |
---|
10 | // * * |
---|
11 | // * Neither the authors of this software system, nor their employing * |
---|
12 | // * institutes,nor the agencies providing financial support for this * |
---|
13 | // * work make any representation or warranty, express or implied, * |
---|
14 | // * regarding this software system or assume any liability for its * |
---|
15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
16 | // * for the full disclaimer and the limitation of liability. * |
---|
17 | // * * |
---|
18 | // * This code implementation is the result of the scientific and * |
---|
19 | // * technical work of the GEANT4 collaboration. * |
---|
20 | // * By using, copying, modifying or distributing the software (or * |
---|
21 | // * any work based on the software) you agree to acknowledge its * |
---|
22 | // * use in resulting scientific publications, and indicate your * |
---|
23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
24 | // ******************************************************************** |
---|
25 | // |
---|
26 | // |
---|
27 | // $Id: G4SteppingManager.cc,v 1.50 2009/02/27 08:09:50 tsasaki Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-03-cand-01 $ |
---|
29 | // |
---|
30 | //--------------------------------------------------------------- |
---|
31 | // |
---|
32 | // G4SteppingManager.cc |
---|
33 | // |
---|
34 | // Description: |
---|
35 | // This class represents the manager who steers to move the give |
---|
36 | // particle from the TrackingManger by one Step. |
---|
37 | // |
---|
38 | // Contact: |
---|
39 | // Questions and comments to this code should be sent to |
---|
40 | // Katsuya Amako (e-mail: Katsuya.Amako@kek.jp) |
---|
41 | // Takashi Sasaki (e-mail: Takashi.Sasaki@kek.jp) |
---|
42 | // |
---|
43 | //--------------------------------------------------------------- |
---|
44 | |
---|
45 | #include "G4SteppingManager.hh" |
---|
46 | #include "G4SteppingVerbose.hh" |
---|
47 | #include "G4UImanager.hh" |
---|
48 | #include "G4ForceCondition.hh" |
---|
49 | #include "G4GPILSelection.hh" |
---|
50 | #include "G4SteppingControl.hh" |
---|
51 | #include "G4TransportationManager.hh" |
---|
52 | #include "G4UserLimits.hh" |
---|
53 | #include "G4VSensitiveDetector.hh" // Include from 'hits/digi' |
---|
54 | #include "G4GeometryTolerance.hh" |
---|
55 | |
---|
56 | ////////////////////////////////////// |
---|
57 | G4SteppingManager::G4SteppingManager() |
---|
58 | ////////////////////////////////////// |
---|
59 | : fUserSteppingAction(NULL), verboseLevel(0) |
---|
60 | { |
---|
61 | |
---|
62 | // Construct simple 'has-a' related objects |
---|
63 | fStep = new G4Step(); |
---|
64 | fSecondary = fStep->NewSecondaryVector(); |
---|
65 | fPreStepPoint = fStep->GetPreStepPoint(); |
---|
66 | fPostStepPoint = fStep->GetPostStepPoint(); |
---|
67 | #ifdef G4VERBOSE |
---|
68 | if(G4VSteppingVerbose::GetInstance()==0) { |
---|
69 | fVerbose = new G4SteppingVerbose(); |
---|
70 | G4VSteppingVerbose::SetInstance(fVerbose); |
---|
71 | fVerbose -> SetManager(this); |
---|
72 | KillVerbose = true; |
---|
73 | } |
---|
74 | else { |
---|
75 | fVerbose = G4VSteppingVerbose::GetInstance(); |
---|
76 | fVerbose -> SetManager(this); |
---|
77 | KillVerbose = false; |
---|
78 | } |
---|
79 | #endif |
---|
80 | SetNavigator(G4TransportationManager::GetTransportationManager() |
---|
81 | ->GetNavigatorForTracking()); |
---|
82 | |
---|
83 | fSelectedAtRestDoItVector |
---|
84 | = new G4SelectedAtRestDoItVector(SizeOfSelectedDoItVector,0); |
---|
85 | fSelectedAlongStepDoItVector |
---|
86 | = new G4SelectedAlongStepDoItVector(SizeOfSelectedDoItVector,0); |
---|
87 | fSelectedPostStepDoItVector |
---|
88 | = new G4SelectedPostStepDoItVector(SizeOfSelectedDoItVector,0); |
---|
89 | |
---|
90 | SetNavigator(G4TransportationManager::GetTransportationManager() |
---|
91 | ->GetNavigatorForTracking()); |
---|
92 | |
---|
93 | physIntLength = DBL_MAX; |
---|
94 | kCarTolerance = 0.5*G4GeometryTolerance::GetInstance()->GetSurfaceTolerance(); |
---|
95 | } |
---|
96 | |
---|
97 | /////////////////////////////////////// |
---|
98 | G4SteppingManager::~G4SteppingManager() |
---|
99 | /////////////////////////////////////// |
---|
100 | { |
---|
101 | |
---|
102 | // Destruct simple 'has-a' objects |
---|
103 | fStep->DeleteSecondaryVector(); |
---|
104 | /////////////////////////// delete fSecondary; |
---|
105 | delete fStep; |
---|
106 | delete fSelectedAtRestDoItVector; |
---|
107 | delete fSelectedAlongStepDoItVector; |
---|
108 | delete fSelectedPostStepDoItVector; |
---|
109 | if (fUserSteppingAction) delete fUserSteppingAction; |
---|
110 | #ifdef G4VERBOSE |
---|
111 | if(KillVerbose) delete fVerbose; |
---|
112 | #endif |
---|
113 | } |
---|
114 | |
---|
115 | |
---|
116 | ////////////////////////////////////////// |
---|
117 | G4StepStatus G4SteppingManager::Stepping() |
---|
118 | ////////////////////////////////////////// |
---|
119 | { |
---|
120 | |
---|
121 | //-------- |
---|
122 | // Prelude |
---|
123 | //-------- |
---|
124 | #ifdef G4VERBOSE |
---|
125 | // !!!!! Verbose |
---|
126 | if(verboseLevel>0) fVerbose->NewStep(); |
---|
127 | else |
---|
128 | if(verboseLevel==-1) { |
---|
129 | G4VSteppingVerbose::SetSilent(1); |
---|
130 | } |
---|
131 | else |
---|
132 | G4VSteppingVerbose::SetSilent(0); |
---|
133 | #endif |
---|
134 | |
---|
135 | // Store last PostStepPoint to PreStepPoint, and swap current and nex |
---|
136 | // volume information of G4Track. Reset total energy deposit in one Step. |
---|
137 | fStep->CopyPostToPreStepPoint(); |
---|
138 | fStep->ResetTotalEnergyDeposit(); |
---|
139 | |
---|
140 | // Switch next touchable in track to current one |
---|
141 | fTrack->SetTouchableHandle(fTrack->GetNextTouchableHandle()); |
---|
142 | |
---|
143 | // Reset the secondary particles |
---|
144 | fN2ndariesAtRestDoIt = 0; |
---|
145 | fN2ndariesAlongStepDoIt = 0; |
---|
146 | fN2ndariesPostStepDoIt = 0; |
---|
147 | |
---|
148 | //JA Set the volume before it is used (in DefineStepLength() for User Limit) |
---|
149 | fCurrentVolume = fStep->GetPreStepPoint()->GetPhysicalVolume(); |
---|
150 | |
---|
151 | // Reset the step's auxiliary points vector pointer |
---|
152 | fStep->SetPointerToVectorOfAuxiliaryPoints(0); |
---|
153 | |
---|
154 | //----------------- |
---|
155 | // AtRest Processes |
---|
156 | //----------------- |
---|
157 | |
---|
158 | if( fTrack->GetTrackStatus() == fStopButAlive ){ |
---|
159 | if( MAXofAtRestLoops>0 ){ |
---|
160 | InvokeAtRestDoItProcs(); |
---|
161 | fStepStatus = fAtRestDoItProc; |
---|
162 | fStep->GetPostStepPoint()->SetStepStatus( fStepStatus ); |
---|
163 | |
---|
164 | #ifdef G4VERBOSE |
---|
165 | // !!!!! Verbose |
---|
166 | if(verboseLevel>0) fVerbose->AtRestDoItInvoked(); |
---|
167 | #endif |
---|
168 | |
---|
169 | } |
---|
170 | // Make sure the track is killed |
---|
171 | fTrack->SetTrackStatus( fStopAndKill ); |
---|
172 | } |
---|
173 | |
---|
174 | //--------------------------------- |
---|
175 | // AlongStep and PostStep Processes |
---|
176 | //--------------------------------- |
---|
177 | |
---|
178 | |
---|
179 | else{ |
---|
180 | // Find minimum Step length demanded by active disc./cont. processes |
---|
181 | DefinePhysicalStepLength(); |
---|
182 | |
---|
183 | // Store the Step length (geometrical length) to G4Step and G4Track |
---|
184 | fStep->SetStepLength( PhysicalStep ); |
---|
185 | fTrack->SetStepLength( PhysicalStep ); |
---|
186 | G4double GeomStepLength = PhysicalStep; |
---|
187 | |
---|
188 | // Store StepStatus to PostStepPoint |
---|
189 | fStep->GetPostStepPoint()->SetStepStatus( fStepStatus ); |
---|
190 | |
---|
191 | // Invoke AlongStepDoIt |
---|
192 | InvokeAlongStepDoItProcs(); |
---|
193 | |
---|
194 | // Update track by taking into account all changes by AlongStepDoIt |
---|
195 | fStep->UpdateTrack(); |
---|
196 | |
---|
197 | // Update safety after invocation of all AlongStepDoIts |
---|
198 | endpointSafOrigin= fPostStepPoint->GetPosition(); |
---|
199 | // endpointSafety= std::max( proposedSafety - GeomStepLength, 0.); |
---|
200 | endpointSafety= std::max( proposedSafety - GeomStepLength, kCarTolerance); |
---|
201 | |
---|
202 | fStep->GetPostStepPoint()->SetSafety( endpointSafety ); |
---|
203 | |
---|
204 | #ifdef G4VERBOSE |
---|
205 | // !!!!! Verbose |
---|
206 | if(verboseLevel>0) fVerbose->AlongStepDoItAllDone(); |
---|
207 | #endif |
---|
208 | |
---|
209 | // Invoke PostStepDoIt |
---|
210 | InvokePostStepDoItProcs(); |
---|
211 | |
---|
212 | #ifdef G4VERBOSE |
---|
213 | // !!!!! Verbose |
---|
214 | if(verboseLevel>0) fVerbose->PostStepDoItAllDone(); |
---|
215 | #endif |
---|
216 | } |
---|
217 | |
---|
218 | //------- |
---|
219 | // Finale |
---|
220 | //------- |
---|
221 | |
---|
222 | // Update 'TrackLength' and remeber the Step length of the current Step |
---|
223 | fTrack->AddTrackLength(fStep->GetStepLength()); |
---|
224 | fPreviousStepSize = fStep->GetStepLength(); |
---|
225 | fStep->SetTrack(fTrack); |
---|
226 | #ifdef G4VERBOSE |
---|
227 | // !!!!! Verbose |
---|
228 | |
---|
229 | if(verboseLevel>0) fVerbose->StepInfo(); |
---|
230 | #endif |
---|
231 | // Send G4Step information to Hit/Dig if the volume is sensitive |
---|
232 | fCurrentVolume = fStep->GetPreStepPoint()->GetPhysicalVolume(); |
---|
233 | StepControlFlag = fStep->GetControlFlag(); |
---|
234 | if( fCurrentVolume != 0 && StepControlFlag != AvoidHitInvocation) { |
---|
235 | fSensitive = fStep->GetPreStepPoint()-> |
---|
236 | GetSensitiveDetector(); |
---|
237 | if( fSensitive != 0 ) { |
---|
238 | fSensitive->Hit(fStep); |
---|
239 | } |
---|
240 | } |
---|
241 | |
---|
242 | // User intervention process. |
---|
243 | if( fUserSteppingAction != NULL ) { |
---|
244 | fUserSteppingAction->UserSteppingAction(fStep); |
---|
245 | } |
---|
246 | G4UserSteppingAction* regionalAction |
---|
247 | = fStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume()->GetRegion() |
---|
248 | ->GetRegionalSteppingAction(); |
---|
249 | if( regionalAction ) regionalAction->UserSteppingAction(fStep); |
---|
250 | |
---|
251 | // Stepping process finish. Return the value of the StepStatus. |
---|
252 | return fStepStatus; |
---|
253 | |
---|
254 | } |
---|
255 | |
---|
256 | /////////////////////////////////////////////////////////// |
---|
257 | void G4SteppingManager::SetInitialStep(G4Track* valueTrack) |
---|
258 | /////////////////////////////////////////////////////////// |
---|
259 | { |
---|
260 | |
---|
261 | // Set up several local variables. |
---|
262 | PreStepPointIsGeom = false; |
---|
263 | FirstStep = true; |
---|
264 | fParticleChange = NULL; |
---|
265 | fPreviousStepSize = 0.; |
---|
266 | fStepStatus = fUndefined; |
---|
267 | |
---|
268 | fTrack = valueTrack; |
---|
269 | Mass = fTrack->GetDynamicParticle()->GetMass(); |
---|
270 | |
---|
271 | PhysicalStep = 0.; |
---|
272 | GeometricalStep = 0.; |
---|
273 | CorrectedStep = 0.; |
---|
274 | PreStepPointIsGeom = false; |
---|
275 | FirstStep = false; |
---|
276 | fStepStatus = fUndefined; |
---|
277 | |
---|
278 | TempInitVelocity = 0.; |
---|
279 | TempVelocity = 0.; |
---|
280 | sumEnergyChange = 0.; |
---|
281 | |
---|
282 | |
---|
283 | // If the primary track has 'Suspend' or 'PostponeToNextEvent' state, |
---|
284 | // set the track state to 'Alive'. |
---|
285 | if( (fTrack->GetTrackStatus()==fSuspend) || |
---|
286 | (fTrack->GetTrackStatus()==fPostponeToNextEvent) ){ |
---|
287 | fTrack->SetTrackStatus(fAlive); |
---|
288 | } |
---|
289 | |
---|
290 | // If the primary track has 'zero' kinetic energy, set the track |
---|
291 | // state to 'StopButAlive'. |
---|
292 | if(fTrack->GetKineticEnergy() <= 0.0){ |
---|
293 | fTrack->SetTrackStatus( fStopButAlive ); |
---|
294 | } |
---|
295 | |
---|
296 | |
---|
297 | // Set Touchable to track and a private attribute of G4SteppingManager |
---|
298 | |
---|
299 | |
---|
300 | if ( ! fTrack->GetTouchableHandle() ) { |
---|
301 | G4ThreeVector direction= fTrack->GetMomentumDirection(); |
---|
302 | fNavigator->LocateGlobalPointAndSetup( fTrack->GetPosition(), |
---|
303 | &direction, false, false ); |
---|
304 | fTouchableHandle = fNavigator->CreateTouchableHistory(); |
---|
305 | |
---|
306 | fTrack->SetTouchableHandle( fTouchableHandle ); |
---|
307 | fTrack->SetNextTouchableHandle( fTouchableHandle ); |
---|
308 | }else{ |
---|
309 | fTrack->SetNextTouchableHandle( fTouchableHandle = fTrack->GetTouchableHandle() ); |
---|
310 | G4VPhysicalVolume* oldTopVolume= fTrack->GetTouchableHandle()->GetVolume(); |
---|
311 | G4VPhysicalVolume* newTopVolume= |
---|
312 | fNavigator->ResetHierarchyAndLocate( fTrack->GetPosition(), |
---|
313 | fTrack->GetMomentumDirection(), |
---|
314 | *((G4TouchableHistory*)fTrack->GetTouchableHandle()()) ); |
---|
315 | // if(newTopVolume != oldTopVolume ){ |
---|
316 | if(newTopVolume != oldTopVolume || oldTopVolume->GetRegularStructureId() == 1 ) { |
---|
317 | fTouchableHandle = fNavigator->CreateTouchableHistory(); |
---|
318 | fTrack->SetTouchableHandle( fTouchableHandle ); |
---|
319 | fTrack->SetNextTouchableHandle( fTouchableHandle ); |
---|
320 | } |
---|
321 | } |
---|
322 | // Set vertex information of G4Track at here |
---|
323 | if ( fTrack->GetCurrentStepNumber() == 0 ) { |
---|
324 | fTrack->SetVertexPosition( fTrack->GetPosition() ); |
---|
325 | fTrack->SetVertexMomentumDirection( fTrack->GetMomentumDirection() ); |
---|
326 | fTrack->SetVertexKineticEnergy( fTrack->GetKineticEnergy() ); |
---|
327 | fTrack->SetLogicalVolumeAtVertex( fTrack->GetVolume()->GetLogicalVolume() ); |
---|
328 | } |
---|
329 | // Initial set up for attributes of 'G4SteppingManager' |
---|
330 | fCurrentVolume = fTouchableHandle->GetVolume(); |
---|
331 | |
---|
332 | // If track is already outside the world boundary, kill it |
---|
333 | if( fCurrentVolume==0 ){ |
---|
334 | // If the track is a primary, stop processing |
---|
335 | if(fTrack->GetParentID()==0) |
---|
336 | { |
---|
337 | G4cerr << "Primary particle starting at " |
---|
338 | << fTrack->GetPosition() |
---|
339 | << " is outside of the world volume." << G4endl; |
---|
340 | G4Exception("G4SteppingManager::Primary vertex outside of the world"); |
---|
341 | } |
---|
342 | |
---|
343 | fTrack->SetTrackStatus( fStopAndKill ); |
---|
344 | G4cerr << "G4SteppingManager::SetInitialStep(): warning: " |
---|
345 | << "initial track position is outside world! " |
---|
346 | << fTrack->GetPosition() << G4endl; |
---|
347 | } |
---|
348 | else { |
---|
349 | // Initial set up for attribues of 'Step' |
---|
350 | fStep->InitializeStep( fTrack ); |
---|
351 | } |
---|
352 | #ifdef G4VERBOSE |
---|
353 | // !!!!! Verbose |
---|
354 | if(verboseLevel>0) fVerbose->TrackingStarted(); |
---|
355 | #endif |
---|
356 | } |
---|
357 | |
---|