ATLAS Offline Software
Loading...
Searching...
No Matches
AddTrackSummaryAlg.cxx
Go to the documentation of this file.
1// Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
4
5namespace Trk {
6
7AddTrackSummaryAlg::AddTrackSummaryAlg(const std::string& name, ISvcLocator* pSvcLocator)
8 : AthReentrantAlgorithm(name, pSvcLocator)
9{}
10
12 ATH_MSG_DEBUG("Initializing " << name());
13
14 // Check configuration
17 ATH_CHECK(m_trackSummaryTool.retrieve());
18
19 ATH_MSG_INFO("Will add TrackSummary to: " << m_inputTrackCollection.key());
20 ATH_MSG_INFO("Output collection: " << m_outputTrackCollection.key());
21
22 return StatusCode::SUCCESS;
23}
24
25StatusCode AddTrackSummaryAlg::execute(const EventContext& ctx) const {
26 ATH_MSG_DEBUG("Executing " << name());
27
28 // Retrieve the input track collection
30 if (!inputTracks.isValid()) {
31 ATH_MSG_ERROR("Failed to retrieve track collection: " << m_inputTrackCollection.key());
32 return StatusCode::FAILURE;
33 }
34
35 ATH_MSG_DEBUG("Retrieved " << inputTracks->size() << " tracks from " << m_inputTrackCollection.key());
36
37 // Create output collection - use VIEW to avoid copying track objects
38 auto outputTracks = std::make_unique<ConstDataVector<TrackCollection>>(SG::VIEW_ELEMENTS);
39 outputTracks->reserve(inputTracks->size());
40
41 // Loop through tracks and add summary to those missing it
42 int tracksProcessed = 0;
43 int tracksAlreadyHaveSummary = 0;
44
45 for (const Trk::Track* track : *inputTracks) {
46 if (!track) {
47 ATH_MSG_WARNING("Null track pointer in collection");
48 continue;
49 }
50
51 // Check if track already has a summary
52 if (!track->trackSummary()) {
53 bool doSummary = true;
54
55 const Trk::Perigee* per = track->perigeeParameters();
56 if (per) {
57 const float pt = per->momentum().perp();
58 const float eta = per->momentum().eta();
59
60 if (m_minPt > 0.0 && pt < m_minPt) doSummary = false;
61 if (m_maxAbsEta < 90.0 && std::abs(eta) > m_maxAbsEta) doSummary = false;
62 }
63
64 // Create and attach the summary (updateTrackSummary modifies track in-place)
65 // This is thread-safe because each event gets its own copy of tracks
66 if (doSummary){
67 m_trackSummaryTool->updateTrackSummary(ctx, *const_cast<Trk::Track*>(track));
68 ++tracksProcessed;
69
70 // Verify the summary was actually created
71 if (!track->trackSummary()) {
72 ATH_MSG_ERROR("Failed to create TrackSummary for track!");
73 return StatusCode::FAILURE;
74 }
75 }
76 } else {
77 ++tracksAlreadyHaveSummary;
78 }
79
80 // Add track pointer to output collection
81 outputTracks->push_back(track);
82 }
83
84 ATH_MSG_DEBUG("Processed " << tracksProcessed << " tracks. " << tracksAlreadyHaveSummary << " tracks already had summary");
85
86 // Record output collection
88 ATH_CHECK(outputHandle.record(std::move(outputTracks)));
89
90 return StatusCode::SUCCESS;
91}
92
93} // namespace Trk
94
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
An algorithm that can be simultaneously executed in multiple threads.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
AddTrackSummaryAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
SG::WriteHandleKey< ConstDataVector< TrackCollection > > m_outputTrackCollection
Output track collection with summaries added.
Gaudi::Property< float > m_minPt
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadHandleKey< TrackCollection > m_inputTrackCollection
Input track collection (read-only)
Gaudi::Property< float > m_maxAbsEta
ToolHandle< Trk::ITrackSummaryTool > m_trackSummaryTool
Track summary tool.
const Amg::Vector3D & momentum() const
Access method for the momentum.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Ensure that the ATLAS eigen extensions are properly loaded.
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee