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