ATLAS Offline Software
Loading...
Searching...
No Matches
StripClusterTruthDecoratorAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
11
13
14namespace ActsTrk {
15
16
18 ATH_MSG_DEBUG("Initialize " << name() << " ...");
19
20 // Read keys
23 ATH_CHECK(m_stripDetEleCollKey.initialize());
24
25 // Tracks only needed if we want on track clusters only
27
28 // Write keys
29 ATH_CHECK(m_write_xaod_key.initialize());
30
31 // Decorator
33
36
38 ATH_CHECK(m_measurement_waferID.initialize());
39 ATH_CHECK(m_measurement_bec.initialize());
40 ATH_CHECK(m_measurement_layer.initialize());
41 ATH_CHECK(m_measurement_sizePhi.initialize());
42 ATH_CHECK(m_measurement_sizeZ.initialize());
43 ATH_CHECK(m_measurement_SiWidth.initialize());
46 ATH_CHECK(m_measurement_omegax.initialize());
47 ATH_CHECK(m_measurement_omegay.initialize());
51 ATH_CHECK(m_measurement_side.initialize());
52
53 ATH_CHECK(detStore()->retrieve(m_stripHelper, "SCT_ID"));
54
55 return StatusCode::SUCCESS;
56 }
57
58 StatusCode StripClusterTruthDecoratorAlg::execute(const EventContext& ctx) const {
59
61 ATH_CHECK(StripClusterContainer.isValid());
62 const xAOD::StripClusterContainer *stripClusters = StripClusterContainer.cptr();
63
65 ATH_CHECK(stripDetEleHandle.isValid());
66 const InDetDD::SiDetectorElementCollection* stripElements = stripDetEleHandle.cptr();
67
68 const ActsTrk::MeasurementToTruthParticleAssociation* measToTruth(nullptr);
69 if (m_useTruthInfo) {
71 ATH_CHECK( measToTruthHandle.isValid());
72 measToTruth = measToTruthHandle.ptr();
73 }
74
75 // Setup outputs
76 // Create the xAOD container and its auxiliary store:
78 ATH_CHECK(xaod.record(std::make_unique<xAOD::TrackMeasurementValidationContainer>(),
79 std::make_unique<xAOD::TrackMeasurementValidationAuxContainer>()));
80
83
99
100 // collection
101 std::vector<bool> keepClusterCollection {};
102 ATH_CHECK( labelMeasurementToKeep(ctx, *stripClusters, keepClusterCollection) );
103 xAOD::TrackMeasurementValidationContainer *measurements = xaod.ptr();
104
105 // loop over collection and convert to xAOD::TrackMeasurementValidation
106 for (std::size_t i(0); i<stripClusters->size(); ++i) {
107 if (not keepClusterCollection[i]) continue;
108 const xAOD::StripCluster* cluster = stripClusters->at(i);
109
110 measurements->push_back( new xAOD::TrackMeasurementValidation() );
111 xAOD::TrackMeasurementValidation* measurement = measurements->back();
113 measurements->back()->index(),
114 ctx );
115 ATH_CHECK( mlink.isValid() );
116 decorator_measurement_link(*cluster) = std::move(mlink);
117
118 xAOD::DetectorIdentType clusterId = cluster->identifier();
119 xAOD::DetectorIDHashType hashId = cluster->identifierHash();
120
121 const InDetDD::SiDetectorElement *element = stripElements->getDetectorElement(hashId);
122 if ( not element ) {
123 ATH_MSG_FATAL( "Invalid strip detector element for hash " << hashId );
124 return StatusCode::FAILURE;
125 }
126
128 rdoList = cluster->rdoList();
129 std::vector< std::uint64_t > rdoIdentifierList;
130 rdoIdentifierList.reserve(rdoList.size());
131 for( Identifier::value_type hitIdentifierValue : rdoList ){
132 rdoIdentifierList.push_back( hitIdentifierValue );
133 }
134
135 //Set Identifier
136 measurement->setIdentifier( clusterId );
137 measurement->setRdoIdentifierList(std::move(rdoIdentifierList));
138
139 //Set Global Position
140 auto gpos = cluster->globalPosition();
141 measurement->setGlobalPosition(gpos.x(), gpos.y(), gpos.z());
142
143 // Set local position and error matrix
144 auto locpos = cluster->localPosition<1>();
145 measurement->setLocalPosition(locpos(0), 0.);
146
147 auto localCov = cluster->localCovariance<1>();
148 measurement->setLocalPositionError( localCov(0,0), 0., 0. );
149
150 const Identifier waferId = m_stripHelper->wafer_id(hashId);
151 decor_detectorElementID(*measurement) = hashId;
152 decor_waferID(*measurement) = waferId.get_compact();
153 decor_bec(*measurement) = m_stripHelper->barrel_ec(waferId);
154 decor_layer(*measurement) = m_stripHelper->layer_disk(waferId);
155 decor_sizePhi(*measurement) = cluster->channelsInPhi();
156 decor_sizeZ(*measurement) = 0;
157 decor_SiWidth(*measurement) = cluster->channelsInPhi();
158 decor_eta_module(*measurement) = m_stripHelper->eta_module(waferId);
159 decor_phi_module(*measurement) = m_stripHelper->phi_module(waferId);
160 decor_omegax(*measurement) = 0;
161 decor_omegay(*measurement) = 0;
162 decor_LorentzShift(*measurement) = 0;
163 decor_centroid_xphi(*measurement) = 0;
164 decor_centroid_xeta(*measurement) = 0;
165 decor_side(*measurement) = m_stripHelper->side(waferId);
166 }
167
168
169 // Get a list of all true particle contributing to the cluster
170 if (m_useTruthInfo) {
173
174 std::size_t measurementIndex = 0;
175 for (std::size_t i(0); i<stripClusters->size(); ++i) {
176 if (not keepClusterCollection[i]) continue;
177 const xAOD::StripCluster* cluster = stripClusters->at(i);
178 xAOD::TrackMeasurementValidation* measurement = measurements->at(measurementIndex);
179
180 // Check the two match
181 if (cluster->identifier() != measurement->identifier()) {
182 ATH_MSG_ERROR("Cluster and Measurement are not matching!");
183 return StatusCode::FAILURE;
184 }
185
186 if (cluster->index() >= measToTruth->size()) {
187 ATH_MSG_ERROR("PRD index "<< cluster->index() << " not present in the measurement to truth vector with size " << measToTruth->size());
188 return StatusCode::FAILURE;
189 }
190
191 auto tps = measToTruth->at(cluster->index());
192
193 std::vector<unsigned int> tp_indices;
194 std::vector<unsigned int> tp_barcodes;
195 for (auto tp : tps) {
196 tp_indices.push_back(tp->index());
197 tp_barcodes.push_back(HepMC::uniqueID(tp));
198 }
199
200 decor_truth_indices(*measurement) = std::move(tp_indices);
201 decor_truth_barcode(*measurement) = std::move(tp_barcodes);
202 ++measurementIndex;
203 } // loop on clusters
204 }
205
206 ATH_MSG_DEBUG( " recorded StripPrepData objects: size " << measurements->size() );
207 return StatusCode::SUCCESS;
208 }
209
211 const xAOD::StripClusterContainer& clusters,
212 std::vector<bool>& labels) const
213{
214 labels.clear();
216 labels.resize(clusters.size(), true);
217 return StatusCode::SUCCESS;
218 }
219 labels.resize(clusters.size(), false);
220
221
222 // get the tracks
224 SG::ReadHandle<xAOD::TrackParticleContainer> trackParticleHandle = SG::makeHandle( trackParticlesKey, ctx );
225 ATH_CHECK(trackParticleHandle.isValid());
226 const xAOD::TrackParticleContainer* trackParticles = trackParticleHandle.cptr();
227
228 for (const xAOD::TrackParticle* trackParticle : *trackParticles) {
229
230 std::optional<ActsTrk::TrackContainer::ConstTrackProxy> optional_track = getActsTrack(*trackParticle);
231 if ( not optional_track.has_value() ) {
232 ATH_MSG_ERROR("Invalid track link for particle " << trackParticle->index());
233 return StatusCode::FAILURE;
234 }
235 ActsTrk::TrackContainer::ConstTrackProxy track = optional_track.value();
236
237 // loop on track states
238 track.container().trackStateContainer()
239 .visitBackwards(track.tipIndex(),
240 [&labels]
241 (const typename ActsTrk::TrackContainer::ConstTrackStateProxy& state)
242 {
243 auto flags = state.typeFlags();
244 if (not flags.hasMeasurement()) return;
245 const xAOD::UncalibratedMeasurement* cluster = detail::xAODUncalibMeasCalibrator::unpack(state.getUncalibratedSourceLink());
246 if (!cluster || cluster->type() != xAOD::UncalibMeasType::StripClusterType) return;
247 labels.at(cluster->index()) = true;
248 });
249 } // loop on tracks
250 } // loop on read handle keys
251
252 return StatusCode::SUCCESS;
253}
254
255} // ActsTrk
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_FATAL(x,...)
ATLAS-specific HepMC functions.
Handle class for reading a decoration on an object.
Property holding a SG store/key/clid from which a ReadHandle is made.
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_stripDetEleCollKey
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_phi_module
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_SiWidth
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_layer
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_eta_module
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_centroid_xeta
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_detectorElementID
SG::ReadHandleKey< xAOD::StripClusterContainer > m_clustercontainer_key
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_side
SG::ReadHandleKeyArray< xAOD::TrackParticleContainer > m_trackParticlesKey
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_waferID
SG::WriteHandleKey< xAOD::TrackMeasurementValidationContainer > m_write_xaod_key
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_sizePhi
SG::WriteDecorHandleKey< xAOD::StripClusterContainer > m_trackMeasurement_link
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_LorentzShift
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_sizeZ
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_omegay
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_centroid_xphi
StatusCode labelMeasurementToKeep(const EventContext &ctx, const xAOD::StripClusterContainer &clusters, std::vector< bool > &labels) const
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_omegax
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_bec
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_truth_barcodes
SG::ReadHandleKey< MeasurementToTruthParticleAssociation > m_associationMap_key
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_truth_indices
const ServiceHandle< StoreGateSvc > & detStore() const
const T * back() const
Access the last element in the collection as an rvalue.
const T * at(size_type n) const
Access an element, as an rvalue.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
value_type get_compact() const
Get the compact id.
Class to hold the SiDetectorElement objects to be put in the detector store.
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
Class to hold geometrical description of a silicon detector element.
Helper class to provide constant type-safe access to aux data.
const_pointer_type cptr()
Property holding a SG store/key/clid from which a ReadHandle is made.
const_pointer_type ptr()
Dereference the pointer.
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.
ConstVectorMap< 3 > globalPosition() const
Returns the global position of the strip cluster.
SG::ConstAccessor< SG::JaggedVecElt< Identifier::value_type > >::element_type rdoList() const
Returns the list of identifiers of the channels building the cluster.
int channelsInPhi() const
Returns the dimensions of the cluster in numbers of channels in phi (x), respectively.
void setRdoIdentifierList(const std::vector< uint64_t > &rdoIdentifierList)
Sets the list of RDO identifiers.
void setLocalPositionError(float localXError, float localYError, float localXYCorrelation)
Sets the local position error.
void setLocalPosition(float localX, float localY)
Sets the local position.
void setIdentifier(uint64_t identifier)
Sets the identifier.
void setGlobalPosition(float globalX, float globalY, float globalZ)
Sets the global position.
ConstMatrixMap< N > localCovariance() const
Returns the local covariance of the measurement.
DetectorIDHashType identifierHash() const
Returns the IdentifierHash of the measurement (corresponds to the detector element IdentifierHash).
DetectorIdentType identifier() const
Returns the full Identifier of the measurement.
ConstVectorMap< N > localPosition() const
Returns the local position of the measurement.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
std::optional< ActsTrk::TrackContainer::ConstTrackProxy > getActsTrack(const xAOD::TrackParticle &trkPart)
Return the proxy to the Acts track from which the track particle was made frome.
Definition Decoration.cxx:9
int uniqueID(const T &p)
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
TrackMeasurementValidation_v1 TrackMeasurementValidation
Reference the current persistent version:
StripCluster_v1 StripCluster
Define the version of the strip cluster class.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
long unsigned int DetectorIdentType
StripClusterContainer_v1 StripClusterContainer
Define the version of the strip cluster container.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
TrackMeasurementValidationContainer_v1 TrackMeasurementValidationContainer
Definition of the current "TrackMeasurementValidation container version".
unsigned int DetectorIDHashType
@ detector ID element hash