ATLAS Offline Software
Loading...
Searching...
No Matches
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
11namespace ActsTrk {
12
14 ISvcLocator *pSvcLocator)
15 : AthReentrantAlgorithm(name, pSvcLocator)
16 {}
17
19 {
20 ATH_MSG_DEBUG("Initializing " << name() << " ...");
21
22 ATH_CHECK(m_trackParticlesKey.initialize());
24 ATH_CHECK(m_trackMsosLink.initialize());
25
26 ATH_CHECK(m_pixelMsosKey.initialize());
27 ATH_CHECK(m_stripMsosKey.initialize());
28
29 return StatusCode::SUCCESS;
30 }
31
32 StatusCode ActsTrackStateOnSurfaceDecoratorAlg::execute(const EventContext& ctx) const
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 ) {
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,
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)) {
155 } else {
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading a decoration on an object.
Handle class for adding a decoration to an object.
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackParticlesKey
ActsTrackStateOnSurfaceDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadDecorHandleKey< xAOD::TrackParticleContainer > m_decorator_actsTracks
xAOD::UncalibMeasType getDetectorType(std::uint64_t volumeId) const
SG::WriteHandleKey< xAOD::TrackStateValidationContainer > m_pixelMsosKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_trackMsosLink
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteHandleKey< xAOD::TrackStateValidationContainer > m_stripMsosKey
StatusCode storeTrackState(const typename ActsTrk::TrackContainer::ConstTrackStateProxy &state, std::vector< ElementLink< xAOD::TrackStateValidationContainer > > &msosLinks, xAOD::TrackStateValidationContainer &msosContainer) const
An algorithm that can be simultaneously executed in multiple threads.
const T * back() const
Access the last element in the collection as an rvalue.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const SG::AuxVectorData * container() const
Return the container holding this element.
size_t index() const
Return the index of this element within its container.
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
Handle class for reading a decoration on an object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
Handle class for adding a decoration to an object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
@ Outlier
This TSoS contains an outlier, that is, it contains a MeasurementBase/RIO_OnTrack which was not used ...
@ Hole
A hole on the track - this is defined in the following way.
void setDetType(char detType)
Sets the detector type.
void setType(int type)
Sets the type (measurement, outlier, hole)
void setTrackMeasurementValidationLink(ElementLink< xAOD::TrackMeasurementValidationContainer > trackMeasurementValidationLink)
sets the link to the TrackMeasurementValidationContainer
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)
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
TrackMeasurementValidation_v1 TrackMeasurementValidation
Reference the current persistent version:
TrackStateValidationContainer_v1 TrackStateValidationContainer
Definition of the current "TrackStateValidation container version".
TrackStateValidation_v1 TrackStateValidation
Reference the current persistent version:
TrackParticle_v1 TrackParticle
Reference the current persistent version:
UncalibMeasType
Define the type of the uncalibrated measurement.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
TrackMeasurementValidationContainer_v1 TrackMeasurementValidationContainer
Definition of the current "TrackMeasurementValidation container version".
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.