LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
G4BadIdeaAction.cxx
Go to the documentation of this file.
1 
9 
11 
12 #include "Geant4/G4Track.hh"
13 #include "Geant4/G4ThreeVector.hh"
14 #include "Geant4/G4Step.hh"
15 #include "Geant4/G4StepPoint.hh"
16 
17 #include <algorithm>
18 
19 namespace larg4 {
20 
21  //----------------------------------------------------------------------------
22  // Constructor.
24  fNoIncomingMuons(trkOption)
25  {
26  // trkOption comes from LArG4's fSmartStacking
27  // Negative values effect action in this routine. Positive values
28  // effect action in LArStackingAction.
29  mf::LogWarning("G4BadIdeaAction") << "instantiating the G4BadIdeaAction \n"
30  << "This UserAction is only to be used with "
31  << "Geant4 v4.9.4.p02 to solve a stepping bug.\n"
32  << "If you are using a different version of G4, "
33  << "remove this UserAction from your list in LArG4.cxx";
34  }
35 
36  //----------------------------------------------------------------------------
37  // Destructor.
39  {
40  }
41 
42  //----------------------------------------------------------------------------
43  // With every step, add to the particle's trajectory.
44  void G4BadIdeaAction::SteppingAction(const G4Step* step)
45  {
50 
51  // If the step size is such that the particle appears to be "stuck"
52  // in its trajectory, give it a kick.
53  const double epsilon = 5000. * std::numeric_limits<double>::epsilon();
54  const double stepSize = step->GetStepLength();
55  G4Track* nonConstTrack = const_cast<G4Track*>( step->GetTrack() );
56 
57  if (step->GetTrack()->GetCurrentStepNumber() > 5e4
58  && stepSize < epsilon
59  && (step->GetTrack()->GetCurrentStepNumber()%1000) == 1 ){
60 
61  // Cast away the const-ness of the pointer to G4Step.
62  // This is dangerous. Don't do this at home. We're
63  // only doing this because we're desperate.
64  // The need to do this is the result of a bug in Geant4 v4.9.4.p02
65  // We should no longer call this code when we move beyond that version
66  const double kick = 0.001;
67 
68  G4ThreeVector aValue = nonConstTrack->GetPosition();
69 
70  mf::LogWarning("G4BadIdeaAction") << "##### In endless loop. Kicking particle by "
71  << " (+0.001,+0.001,+0.001) --- "
72  << " PDG and encoding "
73  << step->GetTrack()->GetDynamicParticle()->GetPDGcode()
74  << " "
75  << step->GetTrack()->GetDynamicParticle()->GetParticleDefinition()->GetParticleName()
76  << " current step number: "
77  << step->GetTrack()->GetCurrentStepNumber()
78  << " stepsize: " << stepSize
79  << " x,y,z "
80  << aValue.x() << " " << aValue.y() << " " << aValue.z();
81 
82  G4ThreeVector translate(kick,kick,kick);
83  aValue+=translate;
84 
85  nonConstTrack->SetPosition(aValue);
86  }
87 
88 
89  if (fNoIncomingMuons<0)
90  {
91  // This is for overlays of, say, rock muons, which we have
92  G4StepPoint * thePrePoint = step->GetPreStepPoint();
93  G4VPhysicalVolume * thePrePV = thePrePoint->GetPhysicalVolume();
94  G4String thePrePVname = thePrePV->GetName();
95  G4StepPoint * thePostPoint = step->GetPostStepPoint();
96  G4VPhysicalVolume * thePostPV = thePostPoint->GetPhysicalVolume();
97  G4String thePostPVname("null");
98  if (thePostPV) thePostPVname = thePostPV->GetName();
99 
100  if (abs(step->GetTrack()->GetDynamicParticle()->GetPDGcode()) == 13
101  && thePostPVname.contains("volTPCActive")
102  && !thePrePVname.contains("volTPCActive")
103  )
104  ((G4Track*)nonConstTrack)->SetTrackStatus(fStopAndKill);
105  }
106 
107  return;
108  }
109 
110 } // namespace LArG4
Geant4 interface.
this UserAction derived class is to implement catches to known bugs in Geant4 that require grabbing c...
std::string translate(errors::ErrorCodes)
Definition: Exception.cc:18
virtual void SteppingAction(const G4Step *)
G4UserSteppingAction interface.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning