Geant4  10.00.p02
G4ITStepProcessor2.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 // $Id: G4ITStepProcessor2.cc 82326 2014-06-16 09:19:18Z gcosmo $
27 //
28 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
29 //
30 // History:
31 // -----------
32 // 10 Oct 2011 M.Karamitros created
33 //
34 // -------------------------------------------------------------------
35 
36 #include "G4ITStepProcessor.hh"
37 #include "G4LossTableManager.hh"
38 #include "G4ProductionCuts.hh"
39 #include "G4ProductionCutsTable.hh"
40 #include "G4VITProcess.hh"
41 #include "G4TrackingInformation.hh"
42 #include "G4IT.hh"
43 #include "G4ITTrackingManager.hh"
44 #include "G4ITTransportation.hh"
45 
46 #include "G4ITNavigator.hh" // Include from 'geometry'
47 //#include "G4Navigator.hh" // Include from 'geometry'
48 
50 {
51  // Now Store the secondaries from ParticleChange to SecondaryList
52  G4Track* tempSecondaryTrack;
53 
54  for(G4int DSecLoop=0 ;
56  DSecLoop++)
57  {
58  tempSecondaryTrack = fpParticleChange->GetSecondary(DSecLoop);
59 
60  if(tempSecondaryTrack->GetDefinition()->GetApplyCutsFlag())
61  {
62  ApplyProductionCut(tempSecondaryTrack);
63  }
64 
65  // Set parentID
66  tempSecondaryTrack->SetParentID( fpTrack->GetTrackID() );
67 
68  // Set the process pointer which created this track
69  tempSecondaryTrack->SetCreatorProcess( fpCurrentProcess );
70 
71  // If this 2ndry particle has 'zero' kinetic energy, make sure
72  // it invokes a rest process at the beginning of the tracking
73  if(tempSecondaryTrack->GetKineticEnergy() <= DBL_MIN)
74  {
75  G4ProcessManager* pm = tempSecondaryTrack->GetDefinition()->GetProcessManager();
76  if (pm->GetAtRestProcessVector()->entries()>0){
77  tempSecondaryTrack->SetTrackStatus( fStopButAlive );
78  fpSecondary->push_back( tempSecondaryTrack );
80  } else {
81  delete tempSecondaryTrack;
82  }
83  }
84  else
85  {
86  fpSecondary->push_back( tempSecondaryTrack );
87  counter++;
88  }
89  } //end of loop on secondary
90 }
91 
92 //______________________________________________________________________________
93 
94 void G4ITStepProcessor::Stepping(G4Track* track, const double & timeStep)
95 {
97  if(track == 0) return ; // maybe put an exception here
98  fTimeStep = timeStep ;
99  SetTrack(track);
100  DoStepping();
101 }
102 //______________________________________________________________________________
103 
104 // ************************************************************************
105 // Stepping
106 // ************************************************************************
108 {
109  SetupMembers() ;
110 
111  if(!fpProcessInfo)
112  {
113  G4ExceptionDescription exceptionDescription ;
114  exceptionDescription << "No process info found for particle :"
116  G4Exception("G4ITStepProcessor::DoStepping","ITStepProcessor0012",
117  FatalErrorInArgument,exceptionDescription);
118  return ;
119  }
120  else if(fpTrack->GetTrackStatus() == fStopAndKill )
121  {
123  return ;
124  }
125 
129  {
130  fpTrack -> SetTrackStatus(fStopAndKill) ;
132  return ;
133  }
134  //---------------------------------
135  // AtRestStep, AlongStep and PostStep Processes
136  //---------------------------------
137  else
138  {
144  // We reset the navigator state before checking for AtRest
145  // in case a AtRest processe would use a navigator info
146 
148  {
150  fpProcessInfo->fpAtRestDoItVector != 0) // second condition to make coverity happy
151  {
152  //-----------------
153  // AtRestStepDoIt
154  //-----------------
158 
159  }
160  // Make sure the track is killed
162  }
163  else // if(fTimeStep > 0.) // Bye, because PostStepIL can return 0 => time =0
164  {
165  if(fpITrack == 0)
166  {
167  G4ExceptionDescription exceptionDescription ;
168  exceptionDescription
169  << " !!! TrackID : "<< fpTrack->GetTrackID() << G4endl
170  << " !!! Track status : "<< fpTrack->GetTrackStatus() << G4endl
171  << " !!! Particle Name : "<< fpTrack -> GetDefinition() -> GetParticleName() << G4endl
172  << "No G4ITStepProcessor::fpITrack found" << G4endl;
173 
174  G4Exception("G4ITStepProcessor::DoStepping","ITStepProcessor0013",
175  FatalErrorInArgument,exceptionDescription);
176  return ; // to make coverity happy
177  }
178 
179  if(fpITrack->GetTrackingInfo()->IsLeadingStep() == false)
180  {
181  // In case the track has NOT the minimum step length
182  // Given the final step time, the transportation
183  // will compute the final position of the particle
184 
189  }
190 
191 
192  // Store the Step length (geometrical length) to G4Step and G4Track
195 
196  G4double GeomStepLength = fpState->fPhysicalStep;
197 
198  // Store StepStatus to PostStepPoint
200 
201  // Invoke AlongStepDoIt
203 
204  // Update track by taking into account all changes by AlongStepDoIt
205  // fpStep->UpdateTrack(); // done in InvokeAlongStepDoItProcs
206 
207  // Update safety after invocation of all AlongStepDoIts
209 
211 
213 
214  if(GetIT(fpTrack)->GetTrackingInfo()->IsLeadingStep())
215  {
216  // Invoke PostStepDoIt including G4ITTransportation::PSDI
218  }
219  else
220  {
221  // Only invoke transportation
223  }
224  }
225 
228  }
229  //-------
230  // Finale
231  //-------
232 
233  // Update 'TrackLength' and remeber the Step length of the current Step
236 
237  // Send G4Step information to Hit/Dig if the volume is sensitive
238 /***
239  fpCurrentVolume = fpStep->GetPreStepPoint()->GetPhysicalVolume();
240  StepControlFlag = fpStep->GetControlFlag();
241 
242  if( fpCurrentVolume != 0 && StepControlFlag != AvoidHitInvocation)
243  {
244  fpSensitive = fpStep->GetPreStepPoint()->
245  GetSensitiveDetector();
246  if( fpSensitive != 0 )
247  {
248  fpSensitive->Hit(fpStep);
249  }
250  }
251 
252  User intervention process.
253  if( fpUserSteppingAction != 0 )
254  {
255  fpUserSteppingAction->UserSteppingAction(fpStep);
256  }
257  G4UserSteppingAction* regionalAction
258  = fpStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume()->GetRegion()
259  ->GetRegionalSteppingAction();
260  if( regionalAction ) regionalAction->UserSteppingAction(fpStep);
261 ***/
263  // Stepping process finish. Return the value of the StepStatus.
264 
265  // return fpState->fStepStatus;
266 }
267 
268 //______________________________________________________________________________
269 
270 // ************************************************************************
271 // AtRestDoIt
272 // ************************************************************************
273 
275 {
276  fpStep->SetStepLength( 0. ); //the particle has stopped
277  fpTrack->SetStepLength( 0. );
278 
279  G4SelectedAtRestDoItVector& selectedAtRestDoItVector = fpState->fSelectedAtRestDoItVector;
280 
281  // invoke selected process
282  for(size_t np=0; np < fpProcessInfo->MAXofAtRestLoops; np++)
283  {
284  //
285  // Note: DoItVector has inverse order against GetPhysIntVector
286  // and SelectedAtRestDoItVector.
287  //
288  if( selectedAtRestDoItVector[fpProcessInfo->MAXofAtRestLoops-np-1] != InActivated)
289  {
291 
296  //fpCurrentProcess->SetProcessState(0);
298 
299 
300  // Set the current process as a process which defined this Step length
303 
304  // Update Step
306 
307  // Now Store the secondaries from ParticleChange to SecondaryList
309 
310  // clear ParticleChange
312 
313  } //if(fSelectedAtRestDoItVector[np] != InActivated){
314  } //for(size_t np=0; np < MAXofAtRestLoops; np++){
315  fpStep->UpdateTrack();
316 
318 }
319 
320 //______________________________________________________________________________
321 
322 // ************************************************************************
323 // AlongStepDoIt
324 // ************************************************************************
325 
327 {
328 
329  // If the current Step is defined by a 'ExclusivelyForced'
330  // PostStepDoIt, then don't invoke any AlongStepDoIt
332  {
333  return; // Take note 'return' at here !!!
334  }
335 
336  // Invoke the all active continuous processes
337  for( size_t ci=0 ; ci<fpProcessInfo->MAXofAlongStepLoops ; ci++ )
338  {
340  if (fpCurrentProcess== 0) continue;
341  // NULL means the process is inactivated by a user on fly.
342 
346  //fpCurrentProcess->SetProcessState(0);
348  // Update the PostStepPoint of Step according to ParticleChange
349 
351 
352  // Now Store the secondaries from ParticleChange to SecondaryList
354 
355  // Set the track status according to what the process defined
356  // if kinetic energy >0, otherwise set fStopButAlive
358 
359  // clear ParticleChange
361  }
362 
363  fpStep->UpdateTrack();
364 
365  G4TrackStatus fNewStatus = fpTrack->GetTrackStatus();
366 
367  if ( fNewStatus == fAlive && fpTrack->GetKineticEnergy() <= DBL_MIN )
368  {
369  // G4cout << "G4ITStepProcessor::InvokeAlongStepDoItProcs : Track will be killed" << G4endl;
370  if(fpProcessInfo->MAXofAtRestLoops>0) fNewStatus = fStopButAlive;
371  else fNewStatus = fStopAndKill;
372  fpTrack->SetTrackStatus( fNewStatus );
373  }
374 
375 }
376 
377 //______________________________________________________________________________
378 
379 
380 // ************************************************************************
381 // PostStepDoIt
382 // ************************************************************************
383 
384 
386 {
387 
389  G4StepStatus& stepStatus = fpState->fStepStatus;
390 
391  // Invoke the specified discrete processes
392  for(size_t np=0; np < fpProcessInfo->MAXofPostStepLoops; np++)
393  {
394  //
395  // Note: DoItVector has inverse order against GetPhysIntVector
396  // and SelectedPostStepDoItVector.
397  //
398  G4int Cond = selectedPostStepDoItVector[fpProcessInfo->MAXofPostStepLoops-np-1];
399  if(Cond != InActivated)
400  {
401  if( ((Cond == NotForced) && (stepStatus == fPostStepDoItProc)) ||
402  ((Cond == Forced) && (stepStatus != fExclusivelyForcedProc)) ||
403  // ((Cond == Conditionally) && (stepStatus == fAlongStepDoItProc)) ||
404  ((Cond == ExclusivelyForced) && (stepStatus == fExclusivelyForcedProc)) ||
405  ((Cond == StronglyForced) )
406  )
407  {
408 
409  InvokePSDIP(np);
410  }
411  } //if(*fSelectedPostStepDoItVector(np)........
412 
413  // Exit from PostStepLoop if the track has been killed,
414  // but extra treatment for processes with Strongly Forced flag
416  {
417  for(size_t np1=np+1; np1 < fpProcessInfo->MAXofPostStepLoops; np1++)
418  {
419  G4int Cond2 = selectedPostStepDoItVector[fpProcessInfo->MAXofPostStepLoops-np1-1];
420  if (Cond2 == StronglyForced)
421  {
422  InvokePSDIP(np1);
423  }
424  }
425  break;
426  }
427  } //for(size_t np=0; np < MAXofPostStepLoops; np++){
428 }
429 
430 //______________________________________________________________________________
431 
433 {
435 
439  //fpCurrentProcess->SetProcessState(0);
441 
442  // Update PostStepPoint of Step according to ParticleChange
444 
445  // Update G4Track according to ParticleChange after each PostStepDoIt
446  fpStep->UpdateTrack();
447 
448  // Update safety after each invocation of PostStepDoIts
450 
451  // Now Store the secondaries from ParticleChange to SecondaryList
453 
454  // Set the track status according to what the process defined
456 
457  // clear ParticleChange
459 }
460 
461 //______________________________________________________________________________
462 
463 // ************************************************************************
464 // Transport on a given time
465 // ************************************************************************
466 
468 {
469  double physicalStep(0.) ;
470 
472  // dynamic_cast<G4ITTransportation*>((fpProcessInfo->fpAlongStepGetPhysIntVector)[MAXofAlongStepLoops-1]);
473 
474  if(!fpTrack)
475  {
476  G4ExceptionDescription exceptionDescription ;
477  exceptionDescription
478  << "No G4ITStepProcessor::fpTrack found";
479  G4Exception("G4ITStepProcessor::FindTransportationStep","ITStepProcessor0013",
480  FatalErrorInArgument,exceptionDescription);
481  return;
482 
483  }
484  if(!fpITrack)
485  {
486  G4ExceptionDescription exceptionDescription ;
487  exceptionDescription
488  << "No G4ITStepProcessor::fITrack" ;
489  G4Exception("G4ITStepProcessor::FindTransportationStep","ITStepProcessor0014",
490  FatalErrorInArgument,exceptionDescription);
491  return;
492  }
493  if(!(fpITrack->GetTrack()))
494  {
495  G4ExceptionDescription exceptionDescription ;
496  exceptionDescription
497  << "No G4ITStepProcessor::fITrack->GetTrack()" ;
498  G4Exception("G4ITStepProcessor::FindTransportationStep","ITStepProcessor0015",
499  FatalErrorInArgument,exceptionDescription);
500  return;
501  }
502 
503  if(fpTransportation)
504  {
506  fpTransportation->ComputeStep(*fpTrack, *fpStep, fTimeStep, physicalStep) ;
507  //fpCurrentProcess->SetProcessState(0);
509  }
510 
511  if(physicalStep >= DBL_MAX)
512  {
513  fpTrack -> SetTrackStatus(fStopAndKill) ;
514  return ;
515  }
516 
517  fpState->fPhysicalStep = physicalStep ;
518 }
519 
520 //______________________________________________________________________________
521 
523 {
524  size_t _MAXofPostStepLoops = fpProcessInfo->MAXofPostStepLoops;
526  G4StepStatus& stepStatus = fpState->fStepStatus;
527 
528  // Invoke the specified discrete processes
529  for(size_t np=0; np < _MAXofPostStepLoops; np++)
530  {
531  //
532  // Note: DoItVector has inverse order against GetPhysIntVector
533  // and SelectedPostStepDoItVector.
534  //
535  G4int Cond = selectedPostStepDoItVector[_MAXofPostStepLoops-np-1];
536  if(Cond != InActivated)
537  {
538  if(
539  ((Cond == Forced) && (stepStatus != fExclusivelyForcedProc)) ||
540  // ((Cond == Conditionally) && (stepStatus == fAlongStepDoItProc)) ||
541  ((Cond == ExclusivelyForced) && (stepStatus == fExclusivelyForcedProc)) ||
542  ((Cond == StronglyForced) )
543  )
544  {
545 
546  InvokePSDIP(np);
547  }
548  } //if(*fSelectedPostStepDoItVector(np)........
549 
550  // Exit from PostStepLoop if the track has been killed,
551  // but extra treatment for processes with Strongly Forced flag
553  {
554  for(size_t np1=np+1; np1 < _MAXofPostStepLoops; np1++)
555  {
556  G4int Cond2 = selectedPostStepDoItVector[_MAXofPostStepLoops-np1-1];
557  if (Cond2 == StronglyForced)
558  {
559  InvokePSDIP(np1);
560  }
561  }
562  break;
563  }
564  }
565 }
566 
567 //______________________________________________________________________________
568 
569 // ************************************************************************
570 // Apply cuts
571 // ************************************************************************
572 
573 
575 {
576  G4bool tBelowCutEnergyAndSafety = false;
577  G4int tPtclIdx
578  = G4ProductionCuts::GetIndex(aSecondary->GetDefinition());
579  if (tPtclIdx<0)
580  {
581  return;
582  }
583  G4ProductionCutsTable* tCutsTbl
585  G4int tCoupleIdx
587  G4double tProdThreshold
588  = (*(tCutsTbl->GetEnergyCutsVector(tPtclIdx)))[tCoupleIdx];
589  if( aSecondary->GetKineticEnergy()<tProdThreshold )
590  {
591  tBelowCutEnergyAndSafety = true;
592  if(std::abs(aSecondary->GetDynamicParticle()->GetCharge()) > DBL_MIN)
593  {
594  G4double currentRange
596  aSecondary->GetKineticEnergy(),
598  tBelowCutEnergyAndSafety = (currentRange < CalculateSafety() );
599  }
600  }
601 
602  if( tBelowCutEnergyAndSafety )
603  {
604  if( !(aSecondary->IsGoodForTracking()) )
605  {
606  // Add kinetic energy to the total energy deposit
608  aSecondary->GetKineticEnergy() );
609  aSecondary->SetKineticEnergy(0.0);
610  }
611  }
612 }
G4TrackVector * fpSecondary
void SetTrackStatus(const G4TrackStatus aTrackStatus)
G4ParticleDefinition * GetDefinition() const
void SetStepLength(G4double value)
bool IsLeadingStep()
If the track is the one having the minimum step time, then it "leads" the step.
virtual G4VPhysicalVolume * ResetHierarchyAndLocate(const G4ThreeVector &point, const G4ThreeVector &direction, const G4TouchableHistory &h)
G4int GetNumberOfSecondaries() const
virtual G4Step * UpdateStepForAlongStep(G4Step *Step)
const std::vector< G4double > * GetEnergyCutsVector(size_t pcIdx) const
static G4LossTableManager * Instance()
G4Track * GetSecondary(G4int anIndex) const
static G4int GetIndex(const G4String &name)
G4ITTrackingManager * fpTrackingManager
G4::shared_ptr< G4ProcessState_Lock > GetProcessState(size_t index)
Every process should store the information computed at the InteractionLegth stage in the track...
void SetProcessDefinedStep(const G4VProcess *aValue)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4double GetStepLength() const
const G4DynamicParticle * GetDynamicParticle() const
class std::vector< int, std::allocator< int > > G4SelectedAtRestDoItVector
G4SelectedAtRestDoItVector fSelectedAtRestDoItVector
const G4ThreeVector & GetPosition() const
G4TrackStatus GetTrackStatus() const
G4VITProcess * fpCurrentProcess
G4ProcessManager * GetProcessManager() const
int G4int
Definition: G4Types.hh:78
const G4MaterialCutsCouple * GetMaterialCutsCouple() const
void SetStepStatus(const G4StepStatus aValue)
const G4String & GetParticleName() const
G4StepStatus
Definition: G4StepStatus.hh:49
void SetCreatorProcess(const G4VProcess *aValue)
void SetTrack(G4Track *)
void UpdateTrack()
G4ITNavigatorState_Lock * GetNavigatorState()
G4IT * GetIT(const G4Track *track)
Definition: G4IT.cc:48
G4ProcessVector * GetAtRestProcessVector(G4ProcessVectorTypeIndex typ=typeGPIL) const
G4double GetKineticEnergy() const
G4int entries() const
G4TrackingInformation * fpTrackingInfo
class std::vector< int, std::allocator< int > > G4SelectedPostStepDoItVector
G4StepPoint * fpPreStepPoint
const G4ThreeVector & GetPosition() const
virtual void ComputeStep(const G4Track &, const G4Step &, const double timeStep, double &spaceStep)
void ApplyProductionCut(G4Track *)
bool G4bool
Definition: G4Types.hh:79
void SetStepLength(G4double value)
G4int GetCoupleIndex(const G4MaterialCutsCouple *aCouple) const
G4double GetCharge() const
void DealWithSecondaries(G4int &)
G4ITNavigatorState_Lock * GetNavigatorState() const
G4int GetTrackID() const
G4ITNavigator * fpNavigator
G4ITStepProcessorState * fpState
G4StepPoint * fpPostStepPoint
const G4TouchableHandle & GetTouchableHandle() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4TrackingInformation * GetTrackingInfo()
Definition: G4IT.hh:134
static G4ProductionCutsTable * GetProductionCutsTable()
G4VParticleChange * fpParticleChange
const G4ThreeVector & GetMomentumDirection() const
void IncrementCurrentStepNumber()
T max(const T t1, const T t2)
brief Return the largest of the two arguments
virtual G4VParticleChange * AlongStepDoIt(const G4Track &track, const G4Step &stepData)=0
G4ITTransportation * fpTransportation
void Stepping(G4Track *, const double &)
void SetParentID(const G4int aValue)
G4StepPoint * GetPostStepPoint() const
void AddTotalEnergyDeposit(G4double value)
#define DBL_MIN
Definition: templates.hh:75
void SetNavigatorState(G4ITNavigatorState_Lock *)
G4Track * GetTrack()
Definition: G4IT.hh:208
void SetProcessState(G4::shared_ptr< G4ProcessState_Lock > aProcInfo)
void SetNavigatorState(G4ITNavigatorState_Lock *)
G4bool IsGoodForTracking() const
ProcessGeneralInfo * fpProcessInfo
#define G4endl
Definition: G4ios.hh:61
G4bool GetApplyCutsFlag() const
G4TrackStatus GetTrackStatus() const
void AddTrackLength(const G4double aValue)
void SetKineticEnergy(const G4double aValue)
double G4double
Definition: G4Types.hh:76
virtual G4Step * UpdateStepForPostStep(G4Step *Step)
void SetSafety(const G4double aValue)
virtual G4VParticleChange * PostStepDoIt(const G4Track &track, const G4Step &stepData)=0
G4VITProcess inherits from G4VProcess.
Definition: G4VITProcess.hh:74
#define DBL_MAX
Definition: templates.hh:83
void ResetProcessState()
G4SelectedPostStepDoItVector fSelectedPostStepDoItVector
size_t GetProcessID() const
Definition: G4VITProcess.hh:91
G4double GetRange(const G4ParticleDefinition *aParticle, G4double kineticEnergy, const G4MaterialCutsCouple *couple)
G4TrackStatus
virtual void AppendStep(G4Track *track, G4Step *step)
virtual G4Step * UpdateStepForAtRest(G4Step *Step)
virtual G4VParticleChange * AtRestDoIt(const G4Track &track, const G4Step &stepData)=0