ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
9 
10 namespace ActsTrk {
11 
13  ISvcLocator *pSvcLocator)
14  : AthReentrantAlgorithm(name, pSvcLocator)
15  {}
16 
18  {
19  ATH_MSG_DEBUG("Initializing " << name() << " ...");
20 
23  ATH_CHECK(m_decorator_actsTracks.initialize());
26 
27  ATH_CHECK(m_pixelMeasurementsKey.initialize());
28  ATH_CHECK(m_stripMeasurementsKey.initialize());
29  ATH_CHECK(m_pixelMsosKey.initialize());
30  ATH_CHECK(m_stripMsosKey.initialize());
31 
32  return StatusCode::SUCCESS;
33  }
34 
36  {
37  ATH_MSG_DEBUG("Executing " << name() << " ...");
38 
40  ATH_CHECK(trackParticleHandle.isValid());
41  const xAOD::TrackParticleContainer* trackParticles = trackParticleHandle.cptr();
42 
44  ATH_CHECK(pixelMeasurementHandle.isValid());
45  const xAOD::TrackMeasurementValidationContainer* pixelMeasurements = pixelMeasurementHandle.cptr();
46 
48  ATH_CHECK(stripMeasurementHandle.isValid());
49  const xAOD::TrackMeasurementValidationContainer* stripMeasurements = stripMeasurementHandle.cptr();
50 
52  ATH_CHECK( pixelMsosHandle.record(std::make_unique<xAOD::TrackStateValidationContainer>(),
53  std::make_unique<xAOD::TrackStateValidationAuxContainer>()) );
54  xAOD::TrackStateValidationContainer* pixelMsos = pixelMsosHandle.ptr();
55 
57  ATH_CHECK( stripMsosHandle.record(std::make_unique<xAOD::TrackStateValidationContainer>(),
58  std::make_unique<xAOD::TrackStateValidationAuxContainer>()) );
59  xAOD::TrackStateValidationContainer* stripMsos = stripMsosHandle.ptr();
60 
61  // Decorators
63  ATH_CHECK(decorator_trackLink.isValid());
64 
66  std::vector< ElementLink< xAOD::TrackStateValidationContainer > > > decorator_msos_link( m_trackMsosLink, ctx );
67  ATH_CHECK(decorator_msos_link.isValid());
68 
69 
70 
71  for (const xAOD::TrackParticle* trackParticle : *trackParticles) {
72  ElementLink<ActsTrk::TrackContainer> trackLink = decorator_trackLink(*trackParticle);
73  ATH_CHECK(trackLink.isValid());
74 
75  std::optional<ActsTrk::TrackContainer::ConstTrackProxy> optional_track = *trackLink;
76  if ( not optional_track.has_value() ) {
77  ATH_MSG_ERROR("Invalid track link for particle " << trackParticle->index());
78  return StatusCode::FAILURE;
79  }
80  ActsTrk::TrackContainer::ConstTrackProxy track = optional_track.value();
81 
82  std::vector< typename ActsTrk::TrackContainer::ConstTrackStateProxy > tsos {};
83  tsos.reserve( track.nTrackStates() );
84 
85 
86  // loop on track states
87  track.container().trackStateContainer()
88  .visitBackwards(track.tipIndex(),
89  [&tsos]
90  (const typename ActsTrk::TrackContainer::ConstTrackStateProxy& state)
91  {
92  auto flags = state.typeFlags();
93  if (not flags.test(Acts::TrackStateFlag::MeasurementFlag) and
94  not flags.test(Acts::TrackStateFlag::OutlierFlag) and
95  not flags.test(Acts::TrackStateFlag::HoleFlag)) return;
96  tsos.push_back( state );
97  });
98 
99  std::vector< ElementLink< xAOD::TrackStateValidationContainer > > msos {};
100  msos.reserve( tsos.size() );
101 
102  for (const typename ActsTrk::TrackContainer::ConstTrackStateProxy& state : tsos) {
103  const Acts::Surface& surface = state.referenceSurface();
104  xAOD::UncalibMeasType detectorTypeFromId = getDetectorType( surface.geometryId().volume() );
105 
106  if ( detectorTypeFromId == xAOD::UncalibMeasType::PixelClusterType ) {
107  ATH_CHECK( storeTrackState(state,
108  *pixelMeasurements,
109  msos,
110  *pixelMsos) );
111  pixelMsos->back()->setDetType( Trk::TrackState::Pixel );
112  }
113  else if ( detectorTypeFromId == xAOD::UncalibMeasType::StripClusterType ) {
114  ATH_CHECK( storeTrackState(state,
116  msos,
117  *stripMsos) );
118  stripMsos->back()->setDetType( Trk::TrackState::SCT );
119  }
120  else {
121  ATH_MSG_ERROR("Not recognized detector type");
122  return StatusCode::FAILURE;
123  }
124 
125  } // loop on states
126 
127  decorator_msos_link(*trackParticle) = std::move(msos);
128  } // loop on track particles
129 
130  return StatusCode::SUCCESS;
131  }
132 
133  StatusCode ActsTrackStateOnSurfaceDecoratorAlg::storeTrackState(const typename ActsTrk::TrackContainer::ConstTrackStateProxy& state,
134  const xAOD::TrackMeasurementValidationContainer& measurements,
135  std::vector< ElementLink< xAOD::TrackStateValidationContainer > >& msosLinks,
136  xAOD::TrackStateValidationContainer& msosContainer) const
137  {
138  msosContainer.push_back( new xAOD::TrackStateValidation() );
139 
140  ElementLink< xAOD::TrackStateValidationContainer > elink( &msosContainer, msosContainer.back()->index() );
141  ATH_CHECK( elink.isValid() );
142  msosLinks.push_back( std::move(elink) );
143 
144  auto flags = state.typeFlags();
145  if (not flags.test(Acts::TrackStateFlag::HoleFlag) ) {
146  auto sl = state.getUncalibratedSourceLink().template get<ATLASUncalibSourceLink>();
147  ATH_CHECK( sl != nullptr );
149  msosContainer.back()->setTrackMeasurementValidationLink( ElementLink<xAOD::TrackMeasurementValidationContainer>(&measurements, cluster.index()) );
150  }
151 
152  if (flags.test(Acts::TrackStateFlag::HoleFlag)) {
153  msosContainer.back()->setType( Trk::TrackStateOnSurface::Hole );
154  } else if (flags.test(Acts::TrackStateFlag::OutlierFlag)) {
155  msosContainer.back()->setType( Trk::TrackStateOnSurface::Outlier );
156  } else {
157  msosContainer.back()->setType( Trk::TrackStateOnSurface::Measurement );
158  }
159 
160  return StatusCode::SUCCESS;
161  }
162 
164  {
165  switch (volumeId) {
166  case 2:
167  case 25:
169  case 22:
170  case 23:
171  case 24:
173  case 8:
174  case 9:
175  case 10:
176  case 13:
177  case 14:
178  case 15:
179  case 16:
180  case 18:
181  case 19:
182  case 20:
184  default:
185  throw std::runtime_error("Cannot recognize volume id");
186  };
187  }
188 
189 }
190 
ActsTrk::ActsTrackStateOnSurfaceDecoratorAlg::m_stripMeasurementsKey
SG::ReadHandleKey< xAOD::TrackMeasurementValidationContainer > m_stripMeasurementsKey
Definition: ActsTrackStateOnSurfaceDecoratorAlg.h:37
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:35
TrackStateDefs.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
xAOD::UncalibMeasType::StripClusterType
@ StripClusterType
AthenaPoolTestRead.flags
flags
Definition: AthenaPoolTestRead.py:8
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::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
ActsTrk::ActsTrackStateOnSurfaceDecoratorAlg::m_pixelMeasurementsKey
SG::ReadHandleKey< xAOD::TrackMeasurementValidationContainer > m_pixelMeasurementsKey
Definition: ActsTrackStateOnSurfaceDecoratorAlg.h:36
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::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.
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:40
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:38
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::ActsTrackStateOnSurfaceDecoratorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: ActsTrackStateOnSurfaceDecoratorAlg.cxx:35
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:163
ActsTrk::ActsTrackStateOnSurfaceDecoratorAlg::m_trackMsosLink
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_trackMsosLink
Definition: ActsTrackStateOnSurfaceDecoratorAlg.h:42
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.
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:55
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
Trk::TrackState::SCT
@ SCT
Definition: TrackStateDefs.h:29
ActsTrk::ActsTrackStateOnSurfaceDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition: ActsTrackStateOnSurfaceDecoratorAlg.cxx:17
Trk::TrackFitInputPreparator::stripMeasurements
MeasurementSet stripMeasurements(const Track &, const MeasurementSet &)
get the MeasurementSet out of a track+measurements combination.
Definition: TrackFitInputPreparator.cxx:19
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::storeTrackState
StatusCode storeTrackState(const typename ActsTrk::TrackContainer::ConstTrackStateProxy &state, const xAOD::TrackMeasurementValidationContainer &measurements, std::vector< ElementLink< xAOD::TrackStateValidationContainer > > &msosLinks, xAOD::TrackStateValidationContainer &msosContainer) const
Definition: ActsTrackStateOnSurfaceDecoratorAlg.cxx:133
ActsTrk::ActsTrackStateOnSurfaceDecoratorAlg::ActsTrackStateOnSurfaceDecoratorAlg
ActsTrackStateOnSurfaceDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ActsTrackStateOnSurfaceDecoratorAlg.cxx:12
ActsTrk::ActsTrackStateOnSurfaceDecoratorAlg::m_stripMsosKey
SG::WriteHandleKey< xAOD::TrackStateValidationContainer > m_stripMsosKey
Definition: ActsTrackStateOnSurfaceDecoratorAlg.h:41