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