ATLAS Offline Software
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>
10 #include "ActsInterop/TableUtils.h"
11 
12 namespace ActsTrk {
13 
15  ISvcLocator* pSvcLocator)
16  : AthReentrantAlgorithm(name, pSvcLocator)
17  {}
18 
20  {
21  ATH_MSG_DEBUG("Initializing " << name() << " ...");
22 
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 typename ActsTrk::TrackStateBackend::ConstTrackStateProxy 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_WARNING("There was a problem when storing the Prd collections");
135  ATH_MSG_WARNING("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 
xAOD::UncalibratedMeasurement_v1::identifier
DetectorIdentType identifier() const
Returns the full Identifier of the measurement.
python.StoreID.UNKNOWN
int UNKNOWN
Definition: StoreID.py:16
xAOD::UncalibMeasType::HGTDClusterType
@ HGTDClusterType
ActsTrk::TrackContainer
Definition: TrackContainer.h:31
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::UncalibMeasType::StripClusterType
@ StripClusterType
ActsTrk::PrepRawDataAssociation::markAsUsed
std::pair< typename std::unordered_set< xAOD::DetectorIdentType >::iterator, bool > markAsUsed(xAOD::DetectorIdentType id)
Definition: PrepRawDataAssociation.h:25
ActsTrk::PrepRawDataAssociation
Definition: PrepRawDataAssociation.h:16
ActsTrk::PrdAssociationAlg::m_inputPrdMap
SG::ReadHandleKey< ActsTrk::PrepRawDataAssociation > m_inputPrdMap
Definition: PrdAssociationAlg.h:31
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
ActsTrk::PrdAssociationAlg::m_inputTrackCollections
SG::ReadHandleKey< ActsTrk::TrackContainer > m_inputTrackCollections
Definition: PrdAssociationAlg.h:28
ActsTrk::PrdAssociationAlg::kNHgtdMeasurements
@ kNHgtdMeasurements
Definition: PrdAssociationAlg.h:42
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
ActsTrk::PrdAssociationAlg::kNPixelMeasurements
@ kNPixelMeasurements
Definition: PrdAssociationAlg.h:40
ActsTrk::PrdAssociationAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: PrdAssociationAlg.cxx:42
xAOD::UncalibratedMeasurement_v1
Definition: UncalibratedMeasurement_v1.h:13
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
makeTable
TableUtils::StatTable< T > makeTable(const std::array< T, N > &counter, const std::array< std::string, N > &label)
Definition: TableUtils.h:521
xAOD::UncalibratedMeasurement_v1::type
virtual xAOD::UncalibMeasType type() const =0
Returns the type of the measurement type as a simple enumeration.
ActsTrk::PrdAssociationAlg::finalize
virtual StatusCode finalize() override
Definition: PrdAssociationAlg.cxx:30
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ActsTrk::PrdAssociationAlg::m_outputPrdMap
SG::WriteHandleKey< ActsTrk::PrepRawDataAssociation > m_outputPrdMap
Definition: PrdAssociationAlg.h:34
ActsTrk::PrdAssociationAlg::PrdAssociationAlg
PrdAssociationAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: PrdAssociationAlg.cxx:14
detail::ul
unsigned long ul
Definition: PrimitiveHelpers.h:46
ActsTrk::PrdAssociationAlg::kNTracks
@ kNTracks
Definition: PrdAssociationAlg.h:39
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
MeasurementDefs.h
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::PrepRawDataAssociation::size
std::size_t size() const
Definition: PrepRawDataAssociation.h:27
ActsTrk::getUncalibratedMeasurement
const xAOD::UncalibratedMeasurement & getUncalibratedMeasurement(const ATLASUncalibSourceLink &source_link)
Definition: ATLASSourceLink.h:26
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
ActsTrk::PrdAssociationAlg::kNStripMeasurements
@ kNStripMeasurements
Definition: PrdAssociationAlg.h:41
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:54
merge.status
status
Definition: merge.py:17
TableUtils.h
ActsTrk::PrdAssociationAlg::initialize
virtual StatusCode initialize() override
Definition: PrdAssociationAlg.cxx:19
xAOD::UncalibMeasType::PixelClusterType
@ PixelClusterType
PrdAssociationAlg.h