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