ATLAS Offline Software
Loading...
Searching...
No Matches
MCTruthUserAction.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// MCTruthUserAction.cxx, (c) ATLAS Detector software
8
9// class header
10#include "MCTruthUserAction.h"
11
12// package includes
13#include "ISFTrajectory.h"
14
15// ISF includes
17
20
21// ISF Geant4 includes
23
24// Athena includes
27#include "MCTruth/TrackHelper.h"
28
29#include "G4EventManager.hh"
30
31// Atlas G4 Helpers
32
33
34namespace G4UA{
35
36 namespace iGeant4{
37
39 : m_config(config)
40 , m_truthRecordSvcQuick(nullptr)
41 {
42
43 if(4<m_config.verboseLevel)
44 {
45 G4cout << "create MCTruthUserAction" << G4endl;
46 }
47
48 if (m_config.truthRecordSvc.retrieve().isFailure()){
49 G4ExceptionDescription description;
50 description << G4String("MCTruthUserAction: ") + "Could not retrieve " << m_config.truthRecordSvc;
51 G4Exception("G4UA::iGeant4::MCTruthUserAction", "NoTruthSvc", FatalException, description);
52 return; //The G4Exception call above should abort the job, but Coverity does not seem to pick this up.
53 }
54
55 // store a pointer directly to the truth service class
56 // by doing so, the Gaudi overhead can be minimized
57 m_truthRecordSvcQuick = &(*(m_config.truthRecordSvc));
58 }
59
60 void MCTruthUserAction::PreUserTrackingAction(const G4Track* inTrack){
61 // The G4Trajectory is currently attached to the TrackingManager. Therefore, only one Trajectory can
62 // be handled at the time, so it must be disabled for parallel tracking on the GPU
63#ifndef ATHSIMULATION_USE_ADEPT
64
65 TrackHelper trackHelper(inTrack);
66
67 if (trackHelper.IsPrimary() ||
68 (trackHelper.IsRegisteredSecondary()&&m_config.ilevel>1) ||
69 (trackHelper.IsSecondary()&&m_config.ilevel>2)) {
70
71 auto trkMgr = G4EventManager::GetEventManager()->GetTrackingManager();
72 G4Trajectory *temp=new ::iGeant4::ISFTrajectory(inTrack, m_truthRecordSvcQuick);
73 trkMgr->SetStoreTrajectory(true);
74 trkMgr->SetTrajectory(temp);
75
76 // TODO: check that the 'temp' object is actually deleted by the G4TrackingManager
77 // after FADS::FadsTrackingAction::GetTrackingAction()->ResetTraj() is executed
78 }
79#else
80 // Prevent unused parameter warning.
81 (void)inTrack;
82#endif
83
84 }
85
87 // The G4Trajectory is currently attached to the TrackingManager. Therefore, only one Trajectory can
88 // be handled at the time, so it must be disabled for parallel tracking on the GPU
89#ifndef ATHSIMULATION_USE_ADEPT
90 G4EventManager::GetEventManager()->GetTrackingManager()->SetStoreTrajectory(false);
91#endif
92 }
93 } // namespace iGeant4
94
95} // namespace G4UA
if(pathvar)
virtual void PreUserTrackingAction(const G4Track *) override
virtual void PostUserTrackingAction(const G4Track *) override
ISF::ITruthSvc * m_truthRecordSvcQuick
used for faster access
MCTruthUserAction(const Config &config)
bool IsPrimary() const
bool IsSecondary() const
bool IsRegisteredSecondary() const