ATLAS Offline Software
Loading...
Searching...
No Matches
PrdAssociationAlg.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#include "Acts/EventData/TrackStateType.hpp"
8
10#include <utility>
12
13namespace ActsTrk {
14
16 {
17 ATH_MSG_DEBUG("Initializing " << name() << " ...");
18
20 ATH_CHECK(m_inputPrdMap.initialize(not m_inputPrdMap.empty()));
21 ATH_CHECK(m_outputPrdMap.initialize());
22
23 return StatusCode::SUCCESS;
24 }
25
27 {
28 ATH_MSG_INFO("Prd Map statistics" << std::endl << makeTable(m_stat,
29 std::array<std::string, kNStat>{
30 "N. Tracks",
31 "N. Pixel Measurements",
32 "N. Strip Measurements",
33 "N. Hgtd Measurements"
34 }).columnWidth(10));
35 return StatusCode::SUCCESS;
36 }
37
38 StatusCode PrdAssociationAlg::execute(const EventContext& ctx) const
39 {
40 ATH_MSG_DEBUG("Executing " << name() << " ...");
41
42 const ActsTrk::TrackContainer *tracks{nullptr};
44 ATH_MSG_DEBUG(" \\__ Number of retrieved tracks: " << tracks->size());
45 m_stat[kNTracks] += tracks->size();
46
47 const ActsTrk::PrepRawDataAssociation *inputPrdMap = nullptr;
48 ATH_CHECK(SG::get(inputPrdMap, m_inputPrdMap, ctx));
49
50 if (inputPrdMap) {
51 ATH_MSG_DEBUG(" \\__ Number of already used measurement from previous passes: " << inputPrdMap->size());
52 }
53
54 ATH_MSG_DEBUG("Creating new Prd Map for ACTS measurements with key: " << m_outputPrdMap.key());
55 SG::WriteHandle outputPrdMapHandle{ m_outputPrdMap, ctx};
56 if (inputPrdMap == nullptr) {
57 ATH_CHECK( outputPrdMapHandle.record( std::make_unique< ActsTrk::PrepRawDataAssociation >() ) );
58 } else {
59 ATH_CHECK( outputPrdMapHandle.record( std::make_unique< ActsTrk::PrepRawDataAssociation >( *inputPrdMap ) ) );
60 }
61 ActsTrk::PrepRawDataAssociation *prdMap = outputPrdMapHandle.ptr();
62
63 ATH_MSG_DEBUG("Filling map");
64 enum class RecordStatus : int {UNKNOWN=0, SUCCESS, NOSOURCELINK, NULLSOURCELINK, ALREADYSTORED};
65 std::size_t nMeasurements = 0ul;
66 RecordStatus status = RecordStatus::UNKNOWN;
67
68 for (std::size_t i(0ul); i<tracks->size(); ++i) {
69 tracks->trackStateContainer().visitBackwards(tracks->getTrack(i).tipIndex(),
70 [&prdMap, &nMeasurements, &status, this]
71 (const auto state) -> bool
72 {
73 // only consider measurements
74 if (not state.typeFlags().isMeasurement()) {
75 return true;
76 }
77 ++nMeasurements;
78 // Check it has link to uncalibrated cluster
79 if ( not state.hasUncalibratedSourceLink() ) {
80 status = RecordStatus::NOSOURCELINK;
81 return false;
82 }
83 // Get the uncalibrated measurement
84 if (detail::xAODUncalibMeasCalibrator::getType(state.getUncalibratedSourceLink()) !=
86 return false;
87 }
88
89 const auto* uncalibMeas = detail::xAODUncalibMeasCalibrator::unpack(state.getUncalibratedSourceLink());
90
91 if (uncalibMeas == nullptr) {
92 status = RecordStatus::NULLSOURCELINK;
93 return false;
94 }
95
96 switch(uncalibMeas->type()) {
97 case xAOD::UncalibMeasType::PixelClusterType:
98 ++m_stat[kNPixelMeasurements];
99 break;
100 case xAOD::UncalibMeasType::StripClusterType:
101 ++m_stat[kNStripMeasurements];
102 break;
103 case xAOD::UncalibMeasType::HGTDClusterType:
104 ++m_stat[kNHgtdMeasurements];
105 break;
106 default:
107 break;
108 };
109
110 // Store the identifier
111 const auto& [itr, inserted] = prdMap->markAsUsed(uncalibMeas->identifier());
112 if (not inserted) {
113 status = RecordStatus::ALREADYSTORED;
114 return true;
115 }
116 status = RecordStatus::SUCCESS;
117 return true;
118 });
119 if (status == RecordStatus::SUCCESS) continue;
120
121 switch(status) {
122 case RecordStatus::NOSOURCELINK:
123 { ATH_MSG_ERROR("There was a problem when storing the Prd collections");
124 ATH_MSG_ERROR("Source link was not available."); }
125 return StatusCode::FAILURE;
126 case RecordStatus::NULLSOURCELINK:
127 { ATH_MSG_ERROR("There was a problem when storing the Prd collections");
128 ATH_MSG_ERROR("Source link was nullptr."); }
129 return StatusCode::FAILURE;
130 case RecordStatus::ALREADYSTORED:
131 // do not stop execution, right now it is still possible at this stage two
132 // tracks use the same measurement
133 { ATH_MSG_DEBUG("There was a problem when storing the Prd collections");
134 ATH_MSG_DEBUG("Measurement was already stored."); }
135 break;
136 default:
137 { ATH_MSG_WARNING("There was a problem when storing the Prd collections");
138 ATH_MSG_WARNING("No iteration on track states has been performed."); }
139 break;
140 }
141 } // loop on tracks
142
143 ATH_MSG_DEBUG("Number of used measurements: " << prdMap->size() << " from " << tracks->size() << " tracks");
144 ATH_MSG_DEBUG(" \\__ Found a total of " << nMeasurements << " measurements");
145
146 return StatusCode::SUCCESS;
147 }
148
149}
150
151
#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)
if(pathvar)
TableUtils::StatTable< T > makeTable(const std::array< T, N > &counter, const std::array< std::string, N > &label)
Definition TableUtils.h:543
SG::ReadHandleKey< ActsTrk::TrackContainer > m_inputTrackCollections
SG::ReadHandleKey< ActsTrk::PrepRawDataAssociation > m_inputPrdMap
virtual StatusCode finalize() override
SG::WriteHandleKey< ActsTrk::PrepRawDataAssociation > m_outputPrdMap
virtual StatusCode initialize() override
virtual StatusCode execute(const EventContext &ctx) const override
std::pair< typename std::unordered_set< xAOD::DetectorIdentType >::iterator, bool > markAsUsed(xAOD::DetectorIdentType id)
static SourceLinkType getType(const Acts::SourceLink &sl)
Returns the enumeration corresponding to the object type cached within the Acts::SourceLink.
static const xAOD::UncalibratedMeasurement * unpack(const Acts::SourceLink &sl)
Helper method to unpack an Acts source link to an uncalibrated measurement.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
@ xAODUnCalibMeas
UnCalibrated Trk::PrepRawData objects.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.