ATLAS Offline Software
Loading...
Searching...
No Matches
AthenaTrackingAction.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include <iostream>
8
9#include "G4EventManager.hh"
10
11#include "MCTruth/TrackHelper.h"
14
15namespace G4UA
16{
17
18 //---------------------------------------------------------------------------
19 // Constructor
20 //---------------------------------------------------------------------------
22 int secondarySavingLevel, int subDetVolLevel)
23 : AthMessaging("AthenaTrackingAction")
24 , m_secondarySavingLevel(secondarySavingLevel)
25 , m_subDetVolLevel(subDetVolLevel)
26 {
27 setLevel(lvl);
28 }
29
30 //---------------------------------------------------------------------------
31 // Pre-tracking action.
32 //---------------------------------------------------------------------------
34 {
35 ATH_MSG_DEBUG("Starting to track a new particle");
36
37 // Use the TrackHelper code to identify the kind of particle.
38 TrackHelper trackHelper(track);
39
40 // The G4Trajectory is currently attached to the TrackingManager. Therefore, only one Trajectory can
41 // be handled at the time, so it must be disabled for parallel tracking on the GPU
42#ifndef ATHSIMULATION_USE_ADEPT
43
44 // Condition for creating a trajectory object to store truth.
45 if (trackHelper.IsPrimary() ||
46 (trackHelper.IsRegisteredSecondary() && m_secondarySavingLevel>1) ||
47 (trackHelper.IsSecondary() && m_secondarySavingLevel>2))
48 {
49 ATH_MSG_DEBUG("Preparing an AtlasTrajectory for saving truth");
50
51 // Create a new AtlasTrajectory for this particle
52 AtlasTrajectory* trajectory = new AtlasTrajectory(track, m_subDetVolLevel);
53
54 // Assign the trajectory to the tracking manager.
55 // TODO: consider caching the tracking manager once to reduce overhead.
56 auto trkMgr = G4EventManager::GetEventManager()->GetTrackingManager();
57 //trajectory->setTrackingManager(trkMgr);
58 trkMgr->SetStoreTrajectory(true);
59 trkMgr->SetTrajectory(trajectory);
60 }
61#endif
62 }
63
64 //---------------------------------------------------------------------------
65 // Post-tracking action.
66 //---------------------------------------------------------------------------
67 void AthenaTrackingAction::PostUserTrackingAction(const G4Track* /*track*/)
68 {
69 ATH_MSG_DEBUG("Finished tracking a particle");
70
71 // The G4Trajectory is currently attached to the TrackingManager. Therefore, only one Trajectory can
72 // be handled at the time, so it must be disabled for parallel tracking on the GPU
73#ifndef ATHSIMULATION_USE_ADEPT
74 // We are done tracking this particle, so reset the trajectory.
75 // TODO: consider caching the tracking manager once to reduce overhead.
76 G4EventManager::GetEventManager()->GetTrackingManager()->
77 SetStoreTrajectory(false);
78#endif
79 }
80
81} // namespace G4UA
#define ATH_MSG_DEBUG(x)
void setLevel(MSG::Level lvl)
Change the current logging level.
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
Class to store G4 trajectory information.
AthenaTrackingAction(MSG::Level lvl, int secondarySavingLevel, int subDetVolLevel)
Constructor.
int m_subDetVolLevel
The level in the G4 volume hierarchy at which can we find the sub-detector name.
virtual void PreUserTrackingAction(const G4Track *) override final
Called before tracking a new particle.
virtual void PostUserTrackingAction(const G4Track *) override final
Called after tracking a particle.
int m_secondarySavingLevel
The saving level for secondaries.
bool IsPrimary() const
bool IsSecondary() const
bool IsRegisteredSecondary() const