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 
11 namespace ActsTrk {
12 
14  ISvcLocator* pSvcLocator)
15  : AthReentrantAlgorithm(name, pSvcLocator)
16  {}
17 
19  {
20  ATH_MSG_DEBUG("Initializing " << name() << " ...");
21 
25 
26  return StatusCode::SUCCESS;
27  }
28 
29  StatusCode PrdAssociationAlg::execute(const EventContext& ctx) const
30  {
31  ATH_MSG_DEBUG("Executing " << name() << " ...");
32 
33  ATH_MSG_DEBUG("Retrieving track collection with key: " << m_inputTrackCollections.key());
35  ATH_CHECK( trackHandle.isValid() );
36  const ActsTrk::TrackContainer *tracks = trackHandle.cptr();
37  ATH_MSG_DEBUG(" \\__ Number of retrieved tracks: " << tracks->size());
38 
39  const ActsTrk::PrepRawDataAssociation *inputPrdMap = nullptr;
40  if (not m_inputPrdMap.empty()) {
41  ATH_MSG_DEBUG("Retrieving Prd map from previous Acts Tracking Pass with key: " << m_inputPrdMap.key());
43  ATH_CHECK( inputPrdMapHandle.isValid() );
44  inputPrdMap = inputPrdMapHandle.cptr();
45  ATH_MSG_DEBUG(" \\__ Number of already used measurement from previous passes: " << inputPrdMap->size());
46  }
47 
48  ATH_MSG_DEBUG("Creating new Prd Map for ACTS measurements with key: " << m_outputPrdMap.key());
50  if (inputPrdMap == nullptr) {
51  ATH_CHECK( outputPrdMapHandle.record( std::make_unique< ActsTrk::PrepRawDataAssociation >() ) );
52  } else {
53  ATH_CHECK( outputPrdMapHandle.record( std::make_unique< ActsTrk::PrepRawDataAssociation >( *inputPrdMap ) ) );
54  }
55  ActsTrk::PrepRawDataAssociation *prdMap = outputPrdMapHandle.ptr();
56 
57  ATH_MSG_DEBUG("Filling map");
58  enum class RecordStatus : int {UNKNOWN=0, SUCCESS, NOSOURCELINK, NULLSOURCELINK, ALREADYSTORED};
59  std::size_t nMeasurements = 0ul;
60  RecordStatus status = RecordStatus::UNKNOWN;
61 
62  for (std::size_t i(0ul); i<tracks->size(); ++i) {
63  tracks->trackStateContainer().visitBackwards(tracks->getTrack(i).tipIndex(),
64  [&prdMap, &nMeasurements, &status]
65  (const typename ActsTrk::TrackStateBackend::ConstTrackStateProxy state) -> bool
66  {
67  // only consider measurements
68  if (not state.typeFlags().test(Acts::TrackStateFlag::MeasurementFlag)) return true;
69  ++nMeasurements;
70  // Check it has link to uncalibrated cluster
71  if ( not state.hasUncalibratedSourceLink() ) {
72  status = RecordStatus::NOSOURCELINK;
73  return false;
74  }
75  // Get the uncalibrated measurement
76  const ActsTrk::ATLASUncalibSourceLink sl = state.getUncalibratedSourceLink().template get<ActsTrk::ATLASUncalibSourceLink>();
77  if (sl == nullptr) {
78  status = RecordStatus::NULLSOURCELINK;
79  return false;
80  }
82  // Store the identifier
83  const auto& [itr, inserted] = prdMap->markAsUsed(uncalibMeas.identifier());
84  if (not inserted) {
85  status = RecordStatus::ALREADYSTORED;
86  return true;
87  }
88  status = RecordStatus::SUCCESS;
89  return true;
90  });
91  if (status == RecordStatus::SUCCESS) continue;
92 
93  switch(status) {
94  case RecordStatus::NOSOURCELINK:
95  { ATH_MSG_ERROR("There was a problem when storing the Prd collections");
96  ATH_MSG_ERROR("Source link was not available."); }
97  return StatusCode::FAILURE;
98  case RecordStatus::NULLSOURCELINK:
99  { ATH_MSG_ERROR("There was a problem when storing the Prd collections");
100  ATH_MSG_ERROR("Source link was nullptr."); }
101  return StatusCode::FAILURE;
102  case RecordStatus::ALREADYSTORED:
103  // do not stop execution, right now it is still possible at this stage two
104  // tracks use the same measurement
105  { ATH_MSG_WARNING("There was a problem when storing the Prd collections");
106  ATH_MSG_WARNING("Measurement was already stored."); }
107  break;
108  default:
109  { ATH_MSG_WARNING("There was a problem when storing the Prd collections");
110  ATH_MSG_WARNING("No iteration on track states has been performed."); }
111  break;
112  }
113  } // loop on tracks
114 
115  ATH_MSG_DEBUG("Number of used measurements: " << prdMap->size() << " from " << tracks->size() << " tracks");
116  ATH_MSG_DEBUG(" \\__ Found a total of " << nMeasurements << " measurements");
117 
118  return StatusCode::SUCCESS;
119  }
120 
121 }
122 
123 
xAOD::UncalibratedMeasurement_v1::identifier
DetectorIdentType identifier() const
Returns the full Identifier of the measurement.
python.StoreID.UNKNOWN
int UNKNOWN
Definition: StoreID.py:16
ActsTrk::TrackContainer
Definition: TrackContainer.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
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:30
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:27
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::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: PrdAssociationAlg.cxx:29
xAOD::UncalibratedMeasurement_v1
Definition: UncalibratedMeasurement_v1.h:13
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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:33
ActsTrk::PrdAssociationAlg::PrdAssociationAlg
PrdAssociationAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: PrdAssociationAlg.cxx:13
detail::ul
unsigned long ul
Definition: PrimitiveHelpers.h:45
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:221
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
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:49
merge.status
status
Definition: merge.py:17
ActsTrk::PrdAssociationAlg::initialize
virtual StatusCode initialize() override
Definition: PrdAssociationAlg.cxx:18
PrdAssociationAlg.h