ATLAS Offline Software
ActsTrackStateOnSurfaceDecoratorAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 
11 namespace ActsTrk {
12 
14  ISvcLocator *pSvcLocator)
15  : AthReentrantAlgorithm(name, pSvcLocator)
16  {}
17 
19  {
20  ATH_MSG_DEBUG("Initializing " << name() << " ...");
21 
23  ATH_CHECK(m_decorator_actsTracks.initialize());
25 
26  ATH_CHECK(m_pixelMsosKey.initialize());
27  ATH_CHECK(m_stripMsosKey.initialize());
28 
29  return StatusCode::SUCCESS;
30  }
31 
33  {
34  ATH_MSG_DEBUG("Executing " << name() << " ...");
35 
37  ATH_CHECK(trackParticleHandle.isValid());
38  const xAOD::TrackParticleContainer* trackParticles = trackParticleHandle.cptr();
39 
41  ATH_CHECK( pixelMsosHandle.record(std::make_unique<xAOD::TrackStateValidationContainer>(),
42  std::make_unique<xAOD::TrackStateValidationAuxContainer>()) );
43  xAOD::TrackStateValidationContainer* pixelMsos = pixelMsosHandle.ptr();
44 
46  ATH_CHECK( stripMsosHandle.record(std::make_unique<xAOD::TrackStateValidationContainer>(),
47  std::make_unique<xAOD::TrackStateValidationAuxContainer>()) );
48  xAOD::TrackStateValidationContainer* stripMsos = stripMsosHandle.ptr();
49 
50  // Decorators
52  ATH_CHECK(decorator_trackLink.isValid());
53 
55  std::vector< ElementLink< xAOD::TrackStateValidationContainer > > > decorator_msos_link( m_trackMsosLink, ctx );
56  ATH_CHECK(decorator_msos_link.isValid());
57 
58 
59 
60  for (const xAOD::TrackParticle* trackParticle : *trackParticles) {
61  ElementLink<ActsTrk::TrackContainer> trackLink = decorator_trackLink(*trackParticle);
62  ATH_CHECK(trackLink.isValid());
63 
64  std::optional<ActsTrk::TrackContainer::ConstTrackProxy> optional_track = *trackLink;
65  if ( not optional_track.has_value() ) {
66  ATH_MSG_ERROR("Invalid track link for particle " << trackParticle->index());
67  return StatusCode::FAILURE;
68  }
69  ActsTrk::TrackContainer::ConstTrackProxy track = optional_track.value();
70 
71  std::vector< typename ActsTrk::TrackContainer::ConstTrackStateProxy > tsos {};
72  tsos.reserve( track.nTrackStates() );
73 
74 
75  // loop on track states
76  track.container().trackStateContainer()
77  .visitBackwards(track.tipIndex(),
78  [&tsos]
79  (const typename ActsTrk::TrackContainer::ConstTrackStateProxy& state)
80  {
81  auto flags = state.typeFlags();
82  if (not flags.test(Acts::TrackStateFlag::MeasurementFlag) and
83  not flags.test(Acts::TrackStateFlag::OutlierFlag) and
84  not flags.test(Acts::TrackStateFlag::HoleFlag)) return;
85  tsos.push_back( state );
86  });
87 
88  std::vector< ElementLink< xAOD::TrackStateValidationContainer > > msos {};
89  msos.reserve( tsos.size() );
90 
91  for (const typename ActsTrk::TrackContainer::ConstTrackStateProxy& state : tsos) {
92  const Acts::Surface& surface = state.referenceSurface();
93  xAOD::UncalibMeasType detectorTypeFromId = getDetectorType( surface.geometryId().volume() );
94 
95  if ( detectorTypeFromId == xAOD::UncalibMeasType::PixelClusterType ) {
97  msos,
98  *pixelMsos) );
99  pixelMsos->back()->setDetType( Trk::TrackState::Pixel );
100  }
101  else if ( detectorTypeFromId == xAOD::UncalibMeasType::StripClusterType ) {
102  ATH_CHECK( storeTrackState(state,
103  msos,
104  *stripMsos) );
105  stripMsos->back()->setDetType( Trk::TrackState::SCT );
106  }
107  else {
108  ATH_MSG_ERROR("Not recognized detector type");
109  return StatusCode::FAILURE;
110  }
111 
112  } // loop on states
113 
114  decorator_msos_link(*trackParticle) = std::move(msos);
115  } // loop on track particles
116 
117  return StatusCode::SUCCESS;
118  }
119 
120  StatusCode ActsTrackStateOnSurfaceDecoratorAlg::storeTrackState(const typename ActsTrk::TrackContainer::ConstTrackStateProxy& state,
121  std::vector< ElementLink< xAOD::TrackStateValidationContainer > >& msosLinks,
122  xAOD::TrackStateValidationContainer& msosContainer) const
123  {
124  msosContainer.push_back( new xAOD::TrackStateValidation() );
125 
126  ElementLink< xAOD::TrackStateValidationContainer > elink( &msosContainer, msosContainer.back()->index() );
127  ATH_CHECK( elink.isValid() );
128  msosLinks.push_back( std::move(elink) );
129 
130  static const SG::ConstAccessor< ElementLink< xAOD::TrackMeasurementValidationContainer > > decorator_measurement_link("validationMeasurementLink");
131 
132  auto flags = state.typeFlags();
133  if (not flags.test(Acts::TrackStateFlag::HoleFlag) ) {
134  auto sl = state.getUncalibratedSourceLink().template get<ATLASUncalibSourceLink>();
135  ATH_CHECK( sl != nullptr );
137 
138  if (not decorator_measurement_link.isAvailable(cluster)) {
139  ATH_MSG_ERROR("xAOD Cluster does not have a link to TrackMeasurementValidation element");
140  return StatusCode::FAILURE;
141  }
142  const auto& el = decorator_measurement_link(cluster);
143  ATH_CHECK( el.isValid() );
144  const xAOD::TrackMeasurementValidation *measurement = *el;
145 
147  measurement->index() );
148  msosContainer.back()->setTrackMeasurementValidationLink( std::move(tmvc_el) );
149  }
150 
151  if (flags.test(Acts::TrackStateFlag::HoleFlag)) {
152  msosContainer.back()->setType( Trk::TrackStateOnSurface::Hole );
153  } else if (flags.test(Acts::TrackStateFlag::OutlierFlag)) {
154  msosContainer.back()->setType( Trk::TrackStateOnSurface::Outlier );
155  } else {
156  msosContainer.back()->setType( Trk::TrackStateOnSurface::Measurement );
157  }
158 
159  return StatusCode::SUCCESS;
160  }
161 
163  {
164  switch (volumeId) {
165  case 2:
166  case 25:
168  case 22:
169  case 23:
170  case 24:
172  case 8:
173  case 9:
174  case 10:
175  case 13:
176  case 14:
177  case 15:
178  case 16:
179  case 18:
180  case 19:
181  case 20:
183  default:
184  throw std::runtime_error("Cannot recognize volume id");
185  };
186  }
187 
188 }
189 
xAOD::UncalibMeasType::HGTDClusterType
@ HGTDClusterType
Trk::TrackState::Pixel
@ Pixel
Definition: TrackStateDefs.h:28
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
ActsTrk::ActsTrackStateOnSurfaceDecoratorAlg::m_trackParticlesKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackParticlesKey
Definition: ActsTrackStateOnSurfaceDecoratorAlg.h:34
TrackStateDefs.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
xAOD::UncalibMeasType::StripClusterType
@ StripClusterType
AthenaPoolTestRead.flags
flags
Definition: AthenaPoolTestRead.py:8
ActsTrk::ActsTrackStateOnSurfaceDecoratorAlg::storeTrackState
StatusCode storeTrackState(const typename ActsTrk::TrackContainer::ConstTrackStateProxy &state, std::vector< ElementLink< xAOD::TrackStateValidationContainer > > &msosLinks, xAOD::TrackStateValidationContainer &msosContainer) const
Definition: ActsTrackStateOnSurfaceDecoratorAlg.cxx:120
xAOD::TrackParticleContainer
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
Definition: Event/xAOD/xAODTracking/xAODTracking/TrackParticleContainer.h:14
xAOD::TrackStateValidation_v1
Class describing a TrackStateValidation.
Definition: TrackStateValidation_v1.h:28
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
Trk::TrackStateOnSurface::Outlier
@ Outlier
This TSoS contains an outlier, that is, it contains a MeasurementBase/RIO_OnTrack which was not used ...
Definition: TrackStateOnSurface.h:122
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
xAOD::TrackMeasurementValidation_v1
Class describing a TrackMeasurementValidation.
Definition: TrackMeasurementValidation_v1.h:27
xAOD::UncalibratedMeasurement_v1
Definition: UncalibratedMeasurement_v1.h:13
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
Trk::TrackStateOnSurface::Hole
@ Hole
A hole on the track - this is defined in the following way.
Definition: TrackStateOnSurface.h:128
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
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
WriteDecorHandle.h
Handle class for adding a decoration to an object.
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
ActsTrk::ActsTrackStateOnSurfaceDecoratorAlg::m_pixelMsosKey
SG::WriteHandleKey< xAOD::TrackStateValidationContainer > m_pixelMsosKey
Definition: ActsTrackStateOnSurfaceDecoratorAlg.h:37
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
DataVector::back
const T * back() const
Access the last element in the collection as an rvalue.
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
ActsTrk::ActsTrackStateOnSurfaceDecoratorAlg::m_decorator_actsTracks
SG::ReadDecorHandleKey< xAOD::TrackParticleContainer > m_decorator_actsTracks
Definition: ActsTrackStateOnSurfaceDecoratorAlg.h:35
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ActsTrk::ActsTrackStateOnSurfaceDecoratorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: ActsTrackStateOnSurfaceDecoratorAlg.cxx:32
ActsTrk::getUncalibratedMeasurement
const xAOD::UncalibratedMeasurement & getUncalibratedMeasurement(const ATLASUncalibSourceLink &source_link)
Definition: ATLASSourceLink.h:26
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
ActsTrackStateOnSurfaceDecoratorAlg.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
ActsTrk::ActsTrackStateOnSurfaceDecoratorAlg::getDetectorType
xAOD::UncalibMeasType getDetectorType(std::uint64_t volumeId) const
Definition: ActsTrackStateOnSurfaceDecoratorAlg.cxx:162
ActsTrk::ActsTrackStateOnSurfaceDecoratorAlg::m_trackMsosLink
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_trackMsosLink
Definition: ActsTrackStateOnSurfaceDecoratorAlg.h:39
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
xAOD::UncalibMeasType
UncalibMeasType
Define the type of the uncalibrated measurement.
Definition: MeasurementDefs.h:25
ReadDecorHandle.h
Handle class for reading a decoration on an object.
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MSTrackingVolumeBuilder.cxx:24
xAOD::track
@ track
Definition: TrackingPrimitives.h:513
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
Trk::TrackState::SCT
@ SCT
Definition: TrackStateDefs.h:29
SG::AuxElement::container
const SG::AuxVectorData * container() const
Return the container holding this element.
ActsTrk::ActsTrackStateOnSurfaceDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition: ActsTrackStateOnSurfaceDecoratorAlg.cxx:18
Trk::TrackStateOnSurface::Measurement
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
Definition: TrackStateOnSurface.h:101
xAOD::UncalibMeasType::PixelClusterType
@ PixelClusterType
ActsTrk::ActsTrackStateOnSurfaceDecoratorAlg::ActsTrackStateOnSurfaceDecoratorAlg
ActsTrackStateOnSurfaceDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ActsTrackStateOnSurfaceDecoratorAlg.cxx:13
ActsTrk::ActsTrackStateOnSurfaceDecoratorAlg::m_stripMsosKey
SG::WriteHandleKey< xAOD::TrackStateValidationContainer > m_stripMsosKey
Definition: ActsTrackStateOnSurfaceDecoratorAlg.h:38