12 #include "Geant4/G4Step.hh" 13 #include "Geant4/G4StepPoint.hh" 14 #include "Geant4/G4ThreeVector.hh" 15 #include "Geant4/G4Track.hh" 26 mf::LogWarning(
"G4BadIdeaAction") <<
"instantiating the G4BadIdeaAction \n" 27 <<
"This UserAction is only to be used with " 28 <<
"Geant4 v4.9.4.p02 to solve a stepping bug.\n" 29 <<
"If you are using a different version of G4, " 30 <<
"remove this UserAction from your list in LArG4.cxx";
48 const double epsilon = 5000. * std::numeric_limits<double>::epsilon();
49 const double stepSize = step->GetStepLength();
50 G4Track* nonConstTrack =
const_cast<G4Track*
>(step->GetTrack());
52 if (step->GetTrack()->GetCurrentStepNumber() > 5e4 && stepSize < epsilon &&
53 (step->GetTrack()->GetCurrentStepNumber() % 1000) == 1) {
60 const double kick = 0.001;
62 G4ThreeVector aValue = nonConstTrack->GetPosition();
65 <<
"##### In endless loop. Kicking particle by " 66 <<
" (+0.001,+0.001,+0.001) --- " 67 <<
" PDG and encoding " << step->GetTrack()->GetDynamicParticle()->GetPDGcode() <<
" " 68 << step->GetTrack()->GetDynamicParticle()->GetParticleDefinition()->GetParticleName()
69 <<
" current step number: " << step->GetTrack()->GetCurrentStepNumber()
70 <<
" stepsize: " << stepSize <<
" x,y,z " << aValue.x() <<
" " << aValue.y() <<
" " 73 G4ThreeVector
translate(kick, kick, kick);
76 nonConstTrack->SetPosition(aValue);
81 G4StepPoint* thePrePoint = step->GetPreStepPoint();
82 G4VPhysicalVolume* thePrePV = thePrePoint->GetPhysicalVolume();
83 G4String thePrePVname = thePrePV->GetName();
84 G4StepPoint* thePostPoint = step->GetPostStepPoint();
85 G4VPhysicalVolume* thePostPV = thePostPoint->GetPhysicalVolume();
87 if (thePostPV) thePostPVname = thePostPV->GetName();
89 if (
abs(step->GetTrack()->GetDynamicParticle()->GetPDGcode()) == 13 &&
90 thePostPVname.contains(
"volTPCActive") && !thePrePVname.contains(
"volTPCActive"))
91 ((G4Track*)nonConstTrack)->SetTrackStatus(fStopAndKill);
constexpr auto abs(T v)
Returns the absolute value of the argument.
this UserAction derived class is to implement catches to known bugs in Geant4 that require grabbing c...
std::string translate(errors::ErrorCodes)
virtual void SteppingAction(const G4Step *)
G4UserSteppingAction interface.
virtual ~G4BadIdeaAction()
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning