Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
G4SteppingManager.cc
Go to the documentation of this file.
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$
28//
29//---------------------------------------------------------------
30//
31// G4SteppingManager.cc
32//
33// Description:
34// This class represents the manager who steers to move the give
35// particle from the TrackingManger by one Step.
36//
37// Contact:
38// Questions and comments to this code should be sent to
39// Katsuya Amako (e-mail: Katsuya.Amako@kek.jp)
40// Takashi Sasaki (e-mail: Takashi.Sasaki@kek.jp)
41//
42//---------------------------------------------------------------
43
44#include "G4SteppingManager.hh"
45#include "G4SteppingVerbose.hh"
46#include "G4UImanager.hh"
47#include "G4ForceCondition.hh"
48#include "G4GPILSelection.hh"
49#include "G4SteppingControl.hh"
51#include "G4UserLimits.hh"
52#include "G4VSensitiveDetector.hh" // Include from 'hits/digi'
54
55//////////////////////////////////////
57//////////////////////////////////////
58 : fUserSteppingAction(0), verboseLevel(0)
59{
60
61// Construct simple 'has-a' related objects
62 fStep = new G4Step();
63 fSecondary = fStep->NewSecondaryVector();
64 fPreStepPoint = fStep->GetPreStepPoint();
65 fPostStepPoint = fStep->GetPostStepPoint();
66#ifdef G4VERBOSE
68 fVerbose = new G4SteppingVerbose();
70 fVerbose -> SetManager(this);
71 KillVerbose = true;
72 }
73 else {
75 fVerbose -> SetManager(this);
76 KillVerbose = false;
77 }
78#endif
80 ->GetNavigatorForTracking());
81
82 fSelectedAtRestDoItVector
83 = new G4SelectedAtRestDoItVector(SizeOfSelectedDoItVector,0);
84 fSelectedAlongStepDoItVector
85 = new G4SelectedAlongStepDoItVector(SizeOfSelectedDoItVector,0);
86 fSelectedPostStepDoItVector
87 = new G4SelectedPostStepDoItVector(SizeOfSelectedDoItVector,0);
88
90 ->GetNavigatorForTracking());
91
92 physIntLength = DBL_MAX;
94}
95
96///////////////////////////////////////
98///////////////////////////////////////
99{
100
101// Destruct simple 'has-a' objects
102 fStep->DeleteSecondaryVector();
103/////////////////////////// delete fSecondary;
104 delete fStep;
105 delete fSelectedAtRestDoItVector;
106 delete fSelectedAlongStepDoItVector;
107 delete fSelectedPostStepDoItVector;
108 if (fUserSteppingAction) delete fUserSteppingAction;
109#ifdef G4VERBOSE
110 if(KillVerbose) delete fVerbose;
111#endif
112}
113
114
115//////////////////////////////////////////
117//////////////////////////////////////////
118{
119
120//--------
121// Prelude
122//--------
123#ifdef G4VERBOSE
124 // !!!!! Verbose
125 if(verboseLevel>0) fVerbose->NewStep();
126 else
127 if(verboseLevel==-1) {
129 }
130 else
132#endif
133
134// Store last PostStepPoint to PreStepPoint, and swap current and nex
135// volume information of G4Track. Reset total energy deposit in one Step.
136 fStep->CopyPostToPreStepPoint();
138
139// Switch next touchable in track to current one
141
142// Reset the secondary particles
143 fN2ndariesAtRestDoIt = 0;
144 fN2ndariesAlongStepDoIt = 0;
145 fN2ndariesPostStepDoIt = 0;
146
147//JA Set the volume before it is used (in DefineStepLength() for User Limit)
148 fCurrentVolume = fStep->GetPreStepPoint()->GetPhysicalVolume();
149
150// Reset the step's auxiliary points vector pointer
152
153//-----------------
154// AtRest Processes
155//-----------------
156
157 if( fTrack->GetTrackStatus() == fStopButAlive ){
158 if( MAXofAtRestLoops>0 ){
159 InvokeAtRestDoItProcs();
160 fStepStatus = fAtRestDoItProc;
161 fStep->GetPostStepPoint()->SetStepStatus( fStepStatus );
162
163#ifdef G4VERBOSE
164 // !!!!! Verbose
165 if(verboseLevel>0) fVerbose->AtRestDoItInvoked();
166#endif
167
168 }
169 // Make sure the track is killed
170 fTrack->SetTrackStatus( fStopAndKill );
171 }
172
173//---------------------------------
174// AlongStep and PostStep Processes
175//---------------------------------
176
177
178 else{
179 // Find minimum Step length demanded by active disc./cont. processes
180 DefinePhysicalStepLength();
181
182 // Store the Step length (geometrical length) to G4Step and G4Track
183 fStep->SetStepLength( PhysicalStep );
184 fTrack->SetStepLength( PhysicalStep );
185 G4double GeomStepLength = PhysicalStep;
186
187 // Store StepStatus to PostStepPoint
188 fStep->GetPostStepPoint()->SetStepStatus( fStepStatus );
189
190 // Invoke AlongStepDoIt
191 InvokeAlongStepDoItProcs();
192
193 // Update track by taking into account all changes by AlongStepDoIt
194 fStep->UpdateTrack();
195
196 // Update safety after invocation of all AlongStepDoIts
197 endpointSafOrigin= fPostStepPoint->GetPosition();
198// endpointSafety= std::max( proposedSafety - GeomStepLength, 0.);
199 endpointSafety= std::max( proposedSafety - GeomStepLength, kCarTolerance);
200
201 fStep->GetPostStepPoint()->SetSafety( endpointSafety );
202
203#ifdef G4VERBOSE
204 // !!!!! Verbose
205 if(verboseLevel>0) fVerbose->AlongStepDoItAllDone();
206#endif
207
208 // Invoke PostStepDoIt
209 InvokePostStepDoItProcs();
210
211#ifdef G4VERBOSE
212 // !!!!! Verbose
213 if(verboseLevel>0) fVerbose->PostStepDoItAllDone();
214#endif
215 }
216
217//-------
218// Finale
219//-------
220
221// Update 'TrackLength' and remeber the Step length of the current Step
222 fTrack->AddTrackLength(fStep->GetStepLength());
223 fPreviousStepSize = fStep->GetStepLength();
224 fStep->SetTrack(fTrack);
225#ifdef G4VERBOSE
226 // !!!!! Verbose
227
228 if(verboseLevel>0) fVerbose->StepInfo();
229#endif
230// Send G4Step information to Hit/Dig if the volume is sensitive
231 fCurrentVolume = fStep->GetPreStepPoint()->GetPhysicalVolume();
232 StepControlFlag = fStep->GetControlFlag();
233 if( fCurrentVolume != 0 && StepControlFlag != AvoidHitInvocation) {
234 fSensitive = fStep->GetPreStepPoint()->
235 GetSensitiveDetector();
236 if( fSensitive != 0 ) {
237 fSensitive->Hit(fStep);
238 }
239 }
240
241// User intervention process.
242 if( fUserSteppingAction != 0 ) {
243 fUserSteppingAction->UserSteppingAction(fStep);
244 }
245 G4UserSteppingAction* regionalAction
248 if( regionalAction ) regionalAction->UserSteppingAction(fStep);
249
250// Stepping process finish. Return the value of the StepStatus.
251 return fStepStatus;
252
253}
254
255///////////////////////////////////////////////////////////
257///////////////////////////////////////////////////////////
258{
259
260// Set up several local variables.
261 PreStepPointIsGeom = false;
262 FirstStep = true;
263 fParticleChange = 0;
264 fPreviousStepSize = 0.;
265 fStepStatus = fUndefined;
266
267 fTrack = valueTrack;
268 Mass = fTrack->GetDynamicParticle()->GetMass();
269
270 PhysicalStep = 0.;
271 GeometricalStep = 0.;
272 CorrectedStep = 0.;
273 PreStepPointIsGeom = false;
274 FirstStep = false;
275 fStepStatus = fUndefined;
276
277 TempInitVelocity = 0.;
278 TempVelocity = 0.;
279 sumEnergyChange = 0.;
280
281
282// If the primary track has 'Suspend' or 'PostponeToNextEvent' state,
283// set the track state to 'Alive'.
284 if( (fTrack->GetTrackStatus()==fSuspend) ||
285 (fTrack->GetTrackStatus()==fPostponeToNextEvent) ){
286 fTrack->SetTrackStatus(fAlive);
287 }
288
289// If the primary track has 'zero' kinetic energy, set the track
290// state to 'StopButAlive'.
291 if(fTrack->GetKineticEnergy() <= 0.0){
292 fTrack->SetTrackStatus( fStopButAlive );
293 }
294
295
296// Set Touchable to track and a private attribute of G4SteppingManager
297
298
299 if ( ! fTrack->GetTouchableHandle() ) {
300 G4ThreeVector direction= fTrack->GetMomentumDirection();
301 fNavigator->LocateGlobalPointAndSetup( fTrack->GetPosition(),
302 &direction, false, false );
303 fTouchableHandle = fNavigator->CreateTouchableHistory();
304
305 fTrack->SetTouchableHandle( fTouchableHandle );
306 fTrack->SetNextTouchableHandle( fTouchableHandle );
307 }else{
308 fTrack->SetNextTouchableHandle( fTouchableHandle = fTrack->GetTouchableHandle() );
309 G4VPhysicalVolume* oldTopVolume= fTrack->GetTouchableHandle()->GetVolume();
310 G4VPhysicalVolume* newTopVolume=
311 fNavigator->ResetHierarchyAndLocate( fTrack->GetPosition(),
312 fTrack->GetMomentumDirection(),
313 *((G4TouchableHistory*)fTrack->GetTouchableHandle()()) );
314// if(newTopVolume != oldTopVolume ){
315 if(newTopVolume != oldTopVolume || oldTopVolume->GetRegularStructureId() == 1 ) {
316 fTouchableHandle = fNavigator->CreateTouchableHistory();
317 fTrack->SetTouchableHandle( fTouchableHandle );
318 fTrack->SetNextTouchableHandle( fTouchableHandle );
319 }
320 }
321// Set vertex information of G4Track at here
322 if ( fTrack->GetCurrentStepNumber() == 0 ) {
323 fTrack->SetVertexPosition( fTrack->GetPosition() );
325 fTrack->SetVertexKineticEnergy( fTrack->GetKineticEnergy() );
327 }
328// Initial set up for attributes of 'G4SteppingManager'
329 fCurrentVolume = fTouchableHandle->GetVolume();
330
331// If track is already outside the world boundary, kill it
332 if( fCurrentVolume==0 ){
333 // If the track is a primary, stop processing
334 if(fTrack->GetParentID()==0)
335 {
336 G4cerr << "ERROR - G4SteppingManager::SetInitialStep()" << G4endl
337 << " Primary particle starting at - "
338 << fTrack->GetPosition()
339 << " - is outside of the world volume." << G4endl;
340 G4Exception("G4SteppingManager::SetInitialStep()", "Tracking0010",
341 FatalException, "Primary vertex outside of the world!");
342 }
343
344 fTrack->SetTrackStatus( fStopAndKill );
345 G4cout << "WARNING - G4SteppingManager::SetInitialStep()" << G4endl
346 << " Initial track position is outside world! - "
347 << fTrack->GetPosition() << G4endl;
348 }
349 else {
350// Initial set up for attribues of 'Step'
351 fStep->InitializeStep( fTrack );
352 }
353#ifdef G4VERBOSE
354 // !!!!! Verbose
355 if(verboseLevel>0) fVerbose->TrackingStarted();
356#endif
357}
358
@ FatalException
G4StepStatus
Definition: G4StepStatus.hh:51
@ fUndefined
Definition: G4StepStatus.hh:66
@ fAtRestDoItProc
Definition: G4StepStatus.hh:56
@ AvoidHitInvocation
std::vector< G4int > G4SelectedAlongStepDoItVector
std::vector< G4int > G4SelectedAtRestDoItVector
std::vector< G4int > G4SelectedPostStepDoItVector
@ fSuspend
@ fAlive
@ fStopAndKill
@ fStopButAlive
@ fPostponeToNextEvent
double G4double
Definition: G4Types.hh:64
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cerr
G4DLLIMPORT std::ostream G4cout
G4double GetMass() const
G4double GetSurfaceTolerance() const
static G4GeometryTolerance * GetInstance()
G4Region * GetRegion() const
G4TouchableHistory * CreateTouchableHistory() const
virtual G4VPhysicalVolume * ResetHierarchyAndLocate(const G4ThreeVector &point, const G4ThreeVector &direction, const G4TouchableHistory &h)
Definition: G4Navigator.cc:88
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=0, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
Definition: G4Navigator.cc:116
G4UserSteppingAction * GetRegionalSteppingAction() const
void SetSafety(const G4double aValue)
void SetStepStatus(const G4StepStatus aValue)
const G4ThreeVector & GetPosition() const
G4VPhysicalVolume * GetPhysicalVolume() const
Definition: G4Step.hh:78
void DeleteSecondaryVector()
void InitializeStep(G4Track *aValue)
G4SteppingControl GetControlFlag() const
void UpdateTrack()
void ResetTotalEnergyDeposit()
void SetStepLength(G4double value)
void CopyPostToPreStepPoint()
G4StepPoint * GetPreStepPoint() const
void SetPointerToVectorOfAuxiliaryPoints(std::vector< G4ThreeVector > *theNewVectorPointer)
Definition: G4Step.hh:237
G4double GetStepLength() const
G4TrackVector * NewSecondaryVector()
G4StepPoint * GetPostStepPoint() const
void SetTrack(G4Track *value)
G4StepStatus Stepping()
void SetNavigator(G4Navigator *value)
void SetInitialStep(G4Track *valueTrack)
G4TrackStatus GetTrackStatus() const
void SetTrackStatus(const G4TrackStatus aTrackStatus)
void SetStepLength(G4double value)
G4VPhysicalVolume * GetVolume() const
void SetVertexPosition(const G4ThreeVector &aValue)
const G4TouchableHandle & GetNextTouchableHandle() const
void SetVertexMomentumDirection(const G4ThreeVector &aValue)
void SetNextTouchableHandle(const G4TouchableHandle &apValue)
const G4ThreeVector & GetPosition() const
void SetTouchableHandle(const G4TouchableHandle &apValue)
G4int GetCurrentStepNumber() const
void AddTrackLength(const G4double aValue)
const G4DynamicParticle * GetDynamicParticle() const
const G4TouchableHandle & GetTouchableHandle() const
const G4ThreeVector & GetMomentumDirection() const
G4double GetKineticEnergy() const
void SetVertexKineticEnergy(const G4double aValue)
G4int GetParentID() const
void SetLogicalVolumeAtVertex(const G4LogicalVolume *)
static G4TransportationManager * GetTransportationManager()
virtual void UserSteppingAction(const G4Step *)
G4LogicalVolume * GetLogicalVolume() const
virtual G4int GetRegularStructureId() const =0
G4bool Hit(G4Step *aStep)
static G4VSteppingVerbose * GetInstance()
virtual void AlongStepDoItAllDone()=0
static void SetInstance(G4VSteppingVerbose *Instance)
virtual void PostStepDoItAllDone()=0
virtual void AtRestDoItInvoked()=0
virtual void StepInfo()=0
static void SetSilent(G4int fSilent)
virtual void TrackingStarted()=0
virtual void NewStep()=0
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
Definition: G4VTouchable.cc:44
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define DBL_MAX
Definition: templates.hh:83