Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: G4SteppingManager.cc 95198 2016-01-29 08:28:27Z gcosmo $
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'
53 #include "G4GeometryTolerance.hh"
54 
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
84  fSelectedAlongStepDoItVector
86  fSelectedPostStepDoItVector
88 
90  ->GetNavigatorForTracking());
91 
92  physIntLength = DBL_MAX;
94 }
95 
99 {
100  fTouchableHandle = 0;
101 // Destruct simple 'has-a' objects
102  fStep->DeleteSecondaryVector();
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 
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();
137  fStep->ResetTotalEnergyDeposit();
138 
139 // Switch next touchable in track to current one
140  fTrack->SetTouchableHandle(fTrack->GetNextTouchableHandle());
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 
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 OriginTouchableHandle for primary track
322  if(fTrack->GetParentID()==0){
323  fTrack->SetOriginTouchableHandle(fTrack->GetTouchableHandle());
324  }
325 
326 // Set vertex information of G4Track at here
327  if ( fTrack->GetCurrentStepNumber() == 0 ) {
328  fTrack->SetVertexPosition( fTrack->GetPosition() );
330  fTrack->SetVertexKineticEnergy( fTrack->GetKineticEnergy() );
331  fTrack->SetLogicalVolumeAtVertex( fTrack->GetVolume()->GetLogicalVolume() );
332  }
333 // Initial set up for attributes of 'G4SteppingManager'
334  fCurrentVolume = fTouchableHandle->GetVolume();
335 
336 // If track is already outside the world boundary, kill it
337  if( fCurrentVolume==0 ){
338  // If the track is a primary, stop processing
339  if(fTrack->GetParentID()==0)
340  {
341  G4cerr << "ERROR - G4SteppingManager::SetInitialStep()" << G4endl
342  << " Primary particle starting at - "
343  << fTrack->GetPosition()
344  << " - is outside of the world volume." << G4endl;
345  G4Exception("G4SteppingManager::SetInitialStep()", "Tracking0010",
346  FatalException, "Primary vertex outside of the world!");
347  }
348 
349  fTrack->SetTrackStatus( fStopAndKill );
350  G4cout << "WARNING - G4SteppingManager::SetInitialStep()" << G4endl
351  << " Initial track position is outside world! - "
352  << fTrack->GetPosition() << G4endl;
353  }
354  else {
355 // Initial set up for attribues of 'Step'
356  fStep->InitializeStep( fTrack );
357  }
358 #ifdef G4VERBOSE
359  // !!!!! Verbose
360  if(verboseLevel>0) fVerbose->TrackingStarted();
361 #endif
362 }
363 
void SetTrackStatus(const G4TrackStatus aTrackStatus)
void SetStepLength(G4double value)
G4int GetParentID() const
void SetTrack(G4Track *value)
void SetVertexMomentumDirection(const G4ThreeVector &aValue)
static G4VSteppingVerbose * GetInstance()
void SetNavigator(G4Navigator *value)
void SetOriginTouchableHandle(const G4TouchableHandle &apValue)
G4UserSteppingAction * GetRegionalSteppingAction() const
Definition: G4Region.cc:155
G4double GetStepLength() const
static void SetSilent(G4int fSilent)
void DeleteSecondaryVector()
const G4DynamicParticle * GetDynamicParticle() const
virtual void StepInfo()=0
class std::vector< int, std::allocator< int > > G4SelectedAtRestDoItVector
class std::vector< int, std::allocator< int > > G4SelectedAlongStepDoItVector
virtual void PostStepDoItAllDone()=0
const G4ThreeVector & GetPosition() const
G4double GetSurfaceTolerance() const
G4TrackStatus GetTrackStatus() const
void SetNextTouchableHandle(const G4TouchableHandle &apValue)
void SetTouchableHandle(const G4TouchableHandle &apValue)
G4SteppingControl GetControlFlag() const
void SetPointerToVectorOfAuxiliaryPoints(std::vector< G4ThreeVector > *theNewVectorPointer)
Definition: G4Step.hh:239
G4Region * GetRegion() const
virtual void UserSteppingAction(const G4Step *)
void SetStepStatus(const G4StepStatus aValue)
virtual G4VPhysicalVolume * ResetHierarchyAndLocate(const G4ThreeVector &point, const G4ThreeVector &direction, const G4TouchableHistory &h)
Definition: G4Navigator.cc:95
G4StepStatus
Definition: G4StepStatus.hh:49
G4StepPoint * GetPreStepPoint() const
void UpdateTrack()
G4double GetKineticEnergy() const
class std::vector< int, std::allocator< int > > G4SelectedPostStepDoItVector
G4GLOB_DLL std::ostream G4cout
G4int GetCurrentStepNumber() const
G4TrackVector * NewSecondaryVector()
G4VPhysicalVolume * GetPhysicalVolume() const
const G4ThreeVector & GetPosition() const
G4double GetMass() const
void SetStepLength(G4double value)
virtual G4int GetRegularStructureId() const =0
void ResetTotalEnergyDeposit()
void SetVertexKineticEnergy(const G4double aValue)
const G4TouchableHandle & GetNextTouchableHandle() const
G4bool Hit(G4Step *aStep)
Definition: G4Step.hh:76
G4StepStatus Stepping()
const G4TouchableHandle & GetTouchableHandle() const
void SetInitialStep(G4Track *valueTrack)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4TransportationManager * GetTransportationManager()
G4TouchableHistory * CreateTouchableHistory() const
const G4ThreeVector & GetMomentumDirection() const
static void SetInstance(G4VSteppingVerbose *Instance)
G4LogicalVolume * GetLogicalVolume() const
T max(const T t1, const T t2)
brief Return the largest of the two arguments
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
Definition: G4VTouchable.cc:44
void SetVertexPosition(const G4ThreeVector &aValue)
G4StepPoint * GetPostStepPoint() const
virtual void AtRestDoItInvoked()=0
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=0, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
Definition: G4Navigator.cc:125
G4VPhysicalVolume * GetVolume() const
#define G4endl
Definition: G4ios.hh:61
void AddTrackLength(const G4double aValue)
void InitializeStep(G4Track *aValue)
virtual void NewStep()=0
virtual void AlongStepDoItAllDone()=0
double G4double
Definition: G4Types.hh:76
void SetSafety(const G4double aValue)
#define DBL_MAX
Definition: templates.hh:83
static G4GeometryTolerance * GetInstance()
static const size_t SizeOfSelectedDoItVector
G4GLOB_DLL std::ostream G4cerr
void SetLogicalVolumeAtVertex(const G4LogicalVolume *)
void CopyPostToPreStepPoint()
virtual void TrackingStarted()=0