ATLAS Offline Software
Loading...
Searching...
No Matches
GeantFollower.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6// GeantFollower.cxx, (c) ATLAS Detector software
8
11
12#include "G4Event.hh"
13#include "G4Step.hh"
14#include "G4Material.hh"
15#include "G4StepPoint.hh"
16#include "G4TouchableHistory.hh"
17#include "G4LogicalVolume.hh"
18#include "G4DynamicParticle.hh"
19#include "G4Track.hh"
20
21namespace G4UA{
22
23
25 : m_config(config)
26 , m_helperPointer(nullptr)
27 {}
28
30 {
31 m_helperPointer->beginEvent();
32 }
33
35 {
36 m_helperPointer->endEvent();
37 }
38
40 {
41 if(m_config.helper.retrieve()!=StatusCode::SUCCESS)
42 {
43 G4ExceptionDescription description;
44 description << "Cannot retrieve GeantFollower helper";
45 G4Exception("GeantFollower", "GeantFollower1", FatalException, description);
46 return;
47 }
48
49 m_helperPointer = (&(*m_config.helper));
50 }
51
52 void GeantFollower::UserSteppingAction(const G4Step* aStep)
53 {
54 // kill secondaries
55 if (aStep->GetTrack()->GetParentID())
56 {
57 aStep->GetTrack()->SetTrackStatus(fStopAndKill);
58 return;
59 }
60
61 // get the prestep point and follow this guy
62 G4StepPoint * g4PreStep = aStep->GetPreStepPoint();
63 G4ThreeVector g4Momentum = g4PreStep->GetMomentum();
64 const G4ThreeVector& g4Position = g4PreStep->GetPosition();
65
66 G4Track* g4Track = aStep->GetTrack();
67 const G4DynamicParticle* g4DynParticle = g4Track->GetDynamicParticle();
68
69 // the material information
70 const G4TouchableHistory* touchHist = static_cast<const G4TouchableHistory*>(aStep->GetPreStepPoint()->GetTouchable());
71 if(touchHist) [[likely]]
72 {
73 // G4LogicalVolume
74 const G4LogicalVolume *lv= touchHist->GetVolume()->GetLogicalVolume();
75 if(lv) [[likely]]
76 {
77 const G4Material *mat = lv->GetMaterial();
78 // the step information
79 double steplength = aStep->GetStepLength();
80 // the position information
81 double X0 = mat->GetRadlen();
82 // update the track follower
83 m_helperPointer->trackParticle(g4Position,g4Momentum,g4DynParticle->GetPDGcode(),g4DynParticle->GetCharge(),steplength,X0);
84 }
85 else
86 {
87 G4ExceptionDescription description;
88 description << "GeantFollower::SteppingAction NULL G4LogicalVolume pointer.";
89 G4Exception("GeantFollower", "GeantFollower2", FatalException, description);
90 }
91 }
92 else
93 {
94 G4ExceptionDescription description;
95 description << "GeantFollower::SteppingAction NULL G4TouchableHistory pointer.";
96 G4Exception("GeantFollower", "GeantFollower3", FatalException, description);
97 }
98 }
99
100} // namespace G4UA
Trk::IGeantFollowerHelper * m_helperPointer
virtual void EndOfEventAction(const G4Event *) override
GeantFollower(const Config &config)
virtual void BeginOfEventAction(const G4Event *) override
virtual void UserSteppingAction(const G4Step *) override
virtual void BeginOfRunAction(const G4Run *) override
std::string description
glabal timer - how long have I taken so far?
Definition hcg.cxx:93
#define likely(x)