ATLAS Offline Software
Loading...
Searching...
No Matches
PrdAssociationAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "Acts/EventData/TrackStateType.hpp"
9#include <utility>
11
12namespace ActsTrk {
13
14 PrdAssociationAlg::PrdAssociationAlg(const std::string& name,
15 ISvcLocator* pSvcLocator)
16 : AthReentrantAlgorithm(name, pSvcLocator)
17 {}
18
20 {
21 ATH_MSG_DEBUG("Initializing " << name() << " ...");
22
24 ATH_CHECK(m_inputPrdMap.initialize(not m_inputPrdMap.empty()));
25 ATH_CHECK(m_outputPrdMap.initialize());
26
27 return StatusCode::SUCCESS;
28 }
29
31 {
32 ATH_MSG_INFO("Prd Map statistics" << std::endl << makeTable(m_stat,
33 std::array<std::string, kNStat>{
34 "N. Tracks",
35 "N. Pixel Measurements",
36 "N. Strip Measurements",
37 "N. Hgtd Measurements"
38 }).columnWidth(10));
39 return StatusCode::SUCCESS;
40 }
41
42 StatusCode PrdAssociationAlg::execute(const EventContext& ctx) const
43 {
44 ATH_MSG_DEBUG("Executing " << name() << " ...");
45
46 ATH_MSG_DEBUG("Retrieving track collection with key: " << m_inputTrackCollections.key());
48 ATH_CHECK( trackHandle.isValid() );
49 const ActsTrk::TrackContainer *tracks = trackHandle.cptr();
50 ATH_MSG_DEBUG(" \\__ Number of retrieved tracks: " << tracks->size());
51 m_stat[kNTracks] += tracks->size();
52
53 const ActsTrk::PrepRawDataAssociation *inputPrdMap = nullptr;
54 if (not m_inputPrdMap.empty()) {
55 ATH_MSG_DEBUG("Retrieving Prd map from previous Acts Tracking Pass with key: " << m_inputPrdMap.key());
57 ATH_CHECK( inputPrdMapHandle.isValid() );
58 inputPrdMap = inputPrdMapHandle.cptr();
59 ATH_MSG_DEBUG(" \\__ Number of already used measurement from previous passes: " << inputPrdMap->size());
60 }
61
62 ATH_MSG_DEBUG("Creating new Prd Map for ACTS measurements with key: " << m_outputPrdMap.key());
64 if (inputPrdMap == nullptr) {
65 ATH_CHECK( outputPrdMapHandle.record( std::make_unique< ActsTrk::PrepRawDataAssociation >() ) );
66 } else {
67 ATH_CHECK( outputPrdMapHandle.record( std::make_unique< ActsTrk::PrepRawDataAssociation >( *inputPrdMap ) ) );
68 }
69 ActsTrk::PrepRawDataAssociation *prdMap = outputPrdMapHandle.ptr();
70
71 ATH_MSG_DEBUG("Filling map");
72 enum class RecordStatus : int {UNKNOWN=0, SUCCESS, NOSOURCELINK, NULLSOURCELINK, ALREADYSTORED};
73 std::size_t nMeasurements = 0ul;
74 RecordStatus status = RecordStatus::UNKNOWN;
75
76 for (std::size_t i(0ul); i<tracks->size(); ++i) {
77 tracks->trackStateContainer().visitBackwards(tracks->getTrack(i).tipIndex(),
78 [&prdMap, &nMeasurements, &status, this]
79 (const auto state) -> bool
80 {
81 // only consider measurements
82 if (not state.typeFlags().test(Acts::TrackStateFlag::MeasurementFlag)) return true;
83 ++nMeasurements;
84 // Check it has link to uncalibrated cluster
85 if ( not state.hasUncalibratedSourceLink() ) {
86 status = RecordStatus::NOSOURCELINK;
87 return false;
88 }
89 // Get the uncalibrated measurement
90 const ActsTrk::ATLASUncalibSourceLink sl = state.getUncalibratedSourceLink().template get<ActsTrk::ATLASUncalibSourceLink>();
91 if (sl == nullptr) {
92 status = RecordStatus::NULLSOURCELINK;
93 return false;
94 }
96
97 switch(uncalibMeas.type()) {
99 ++m_stat[kNPixelMeasurements];
100 break;
102 ++m_stat[kNStripMeasurements];
103 break;
105 ++m_stat[kNHgtdMeasurements];
106 break;
107 default:
108 break;
109 };
110
111 // Store the identifier
112 const auto& [itr, inserted] = prdMap->markAsUsed(uncalibMeas.identifier());
113 if (not inserted) {
114 status = RecordStatus::ALREADYSTORED;
115 return true;
116 }
117 status = RecordStatus::SUCCESS;
118 return true;
119 });
120 if (status == RecordStatus::SUCCESS) continue;
121
122 switch(status) {
123 case RecordStatus::NOSOURCELINK:
124 { ATH_MSG_ERROR("There was a problem when storing the Prd collections");
125 ATH_MSG_ERROR("Source link was not available."); }
126 return StatusCode::FAILURE;
127 case RecordStatus::NULLSOURCELINK:
128 { ATH_MSG_ERROR("There was a problem when storing the Prd collections");
129 ATH_MSG_ERROR("Source link was nullptr."); }
130 return StatusCode::FAILURE;
131 case RecordStatus::ALREADYSTORED:
132 // do not stop execution, right now it is still possible at this stage two
133 // tracks use the same measurement
134 { ATH_MSG_DEBUG("There was a problem when storing the Prd collections");
135 ATH_MSG_DEBUG("Measurement was already stored."); }
136 break;
137 default:
138 { ATH_MSG_WARNING("There was a problem when storing the Prd collections");
139 ATH_MSG_WARNING("No iteration on track states has been performed."); }
140 break;
141 }
142 } // loop on tracks
143
144 ATH_MSG_DEBUG("Number of used measurements: " << prdMap->size() << " from " << tracks->size() << " tracks");
145 ATH_MSG_DEBUG(" \\__ Found a total of " << nMeasurements << " measurements");
146
147 return StatusCode::SUCCESS;
148 }
149
150}
151
152
#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(febId1==febId2)
TableUtils::StatTable< T > makeTable(const std::array< T, N > &counter, const std::array< std::string, N > &label)
Definition TableUtils.h:523
SG::ReadHandleKey< ActsTrk::TrackContainer > m_inputTrackCollections
SG::ReadHandleKey< ActsTrk::PrepRawDataAssociation > m_inputPrdMap
virtual StatusCode finalize() override
PrdAssociationAlg(const std::string &name, ISvcLocator *pSvcLocator)
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)
An algorithm that can be simultaneously executed in multiple threads.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
DetectorIdentType identifier() const
Returns the full Identifier of the measurement.
virtual xAOD::UncalibMeasType type() const =0
Returns the type of the measurement type as a simple enumeration.
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
const xAOD::UncalibratedMeasurement & getUncalibratedMeasurement(const ATLASUncalibSourceLink &source_link)
const xAOD::UncalibratedMeasurement * ATLASUncalibSourceLink
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.