ATLAS Offline Software
Loading...
Searching...
No Matches
PixelClusterTruthDecoratorAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
14
15
16namespace ActsTrk {
17
19 ISvcLocator *pSvcLocator) :
20 AthReentrantAlgorithm(name, pSvcLocator)
21 {}
22
24 ATH_MSG_DEBUG("Initialize " << name() << " ...");
25
26 // Read keys
29 ATH_CHECK(m_pixelDetEleCollKey.initialize());
30
31 // Tracks only needed if we want on track clusters only
33
34 // Write keys
35 ATH_CHECK(m_write_xaod_key.initialize());
36
37 // Decorators
39
42
44 ATH_CHECK(m_measurement_waferID.initialize());
45 ATH_CHECK(m_measurement_bec.initialize());
46 ATH_CHECK(m_measurement_layer.initialize());
47 ATH_CHECK(m_measurement_sizePhi.initialize());
48 ATH_CHECK(m_measurement_sizeZ.initialize());
49 ATH_CHECK(m_measurement_SiWidth.initialize());
52 ATH_CHECK(m_measurement_omegax.initialize());
53 ATH_CHECK(m_measurement_omegay.initialize());
57 ATH_CHECK(m_measurement_side.initialize());
58
59 ATH_CHECK(m_measurement_tots.initialize());
60
61 ATH_CHECK( m_lorentzAngleTool.retrieve() );
63
64 return StatusCode::SUCCESS;
65 }
66
67 StatusCode PixelClusterTruthDecoratorAlg::execute(const EventContext& ctx) const {
68
69 //Mandatory. Require if the algorithm is scheduled.
71 ATH_CHECK(PixelClusterContainer.isValid());
72 const xAOD::PixelClusterContainer* clusters = PixelClusterContainer.cptr();
73
75 ATH_CHECK(pixelDetEleHandle.isValid());
76 const InDetDD::SiDetectorElementCollection* pixelDetEle = pixelDetEleHandle.cptr();
77
78 // Get the truth association map
79 const MeasurementToTruthParticleAssociation* measToTruth(nullptr);
80 if (m_useTruthInfo) {
82 ATH_CHECK(measToTruthHandle.isValid());
83 measToTruth = measToTruthHandle.cptr();
84 }
85
86 // Setup outputs
87 // Create the xAOD container and its auxiliary store:
89 ATH_CHECK(xaod.record(std::make_unique<xAOD::TrackMeasurementValidationContainer>(),
90 std::make_unique<xAOD::TrackMeasurementValidationAuxContainer>()));
91
92 // Decorations
95
111
113
114 // Create output collection
115 std::vector<bool> keepClusterCollection {};
116 ATH_CHECK( labelMeasurementToKeep(ctx, *clusters, keepClusterCollection) );
117 xAOD::TrackMeasurementValidationContainer *measurements = xaod.ptr();
118
119 // loop over collection and convert to xAOD::TrackMeasurementValidation
120 for (std::size_t i(0); i<clusters->size(); ++i) {
121 if (not keepClusterCollection[i]) continue;
122 const xAOD::PixelCluster* cluster = clusters->at(i);
123
124 measurements->push_back( new xAOD::TrackMeasurementValidation() );
125 xAOD::TrackMeasurementValidation* measurement = measurements->back();
127 measurements->back()->index() );
128
129 ATH_CHECK( mlink.isValid() );
130 decorator_measurement_link(*cluster) = std::move(mlink);
131
132 xAOD::DetectorIdentType clusterId = cluster->identifier();
133 xAOD::DetectorIDHashType hashId = cluster->identifierHash();
134
135 const InDetDD::SiDetectorElement *element = pixelDetEle->getDetectorElement(hashId);
136 if ( not element ) {
137 ATH_MSG_FATAL( "Invalid pixel detector element for hash " << hashId );
138 return StatusCode::FAILURE;
139 }
140
142 rdoList = cluster->rdoList();
143 std::vector< std::uint64_t > rdoIdentifierList;
144 rdoIdentifierList.reserve(rdoList.size());
145 int rowmin = std::numeric_limits<int>::max();
146 int rowmax = std::numeric_limits<int>::min();
147 int colmin = std::numeric_limits<int>::max();
148 int colmax = std::numeric_limits<int>::min();
149 for( const Identifier::value_type& hitIdentifierValue : rdoList ){
150 Identifier hitIdentifier(hitIdentifierValue);
151 rdoIdentifierList.push_back( hitIdentifier.get_compact() );
152 //May want to addinformation about the individual hits here
153 int row = m_PixelHelper->phi_index(hitIdentifier);
154 int col = m_PixelHelper->eta_index(hitIdentifier);
155 rowmin = std::min(rowmin, row);
156 rowmax = std::max(rowmax, row);
157 colmin = std::min(colmin, col);
158 colmax = std::max(colmax, col);
159 }
160
161 // compute centroid
162 const InDetDD::PixelModuleDesign* design = dynamic_cast<const InDetDD::PixelModuleDesign*>(&element->design());
163 if (not design) {
164 ATH_MSG_ERROR("Cannot retrieve detector design");
165 return StatusCode::FAILURE;
166 }
167 InDetDD::SiLocalPosition pos1 = design->positionFromColumnRow(colmin,rowmin);
168 InDetDD::SiLocalPosition pos2 = design->positionFromColumnRow(colmax,rowmin);
169 InDetDD::SiLocalPosition pos3 = design->positionFromColumnRow(colmin,rowmax);
170 InDetDD::SiLocalPosition pos4 = design->positionFromColumnRow(colmax,rowmax);
171 InDetDD::SiLocalPosition centroid = 0.25 * (pos1 + pos2 + pos3 + pos4);
172
173 //Set Identifier
174 measurement->setIdentifier( clusterId );
175 measurement->setRdoIdentifierList(std::move(rdoIdentifierList));
176
177 //Set Global Position
178 auto gpos = cluster->globalPosition();
179 measurement->setGlobalPosition(gpos.x(), gpos.y(), gpos.z());
180
181 // Set local position and error matrix
182 auto locpos = cluster->localPosition<2>();
183 measurement->setLocalPosition(locpos[0], locpos[1]);
184
185 auto localCov = cluster->localCovariance<2>();
186 measurement->setLocalPositionError( localCov(0,0), localCov(1,1), localCov(0,1) );
187
188 const auto& [omegax, omegay] = TrackingUtilities::computeOmegas(*cluster,
190
191 const Identifier waferId = m_PixelHelper->wafer_id(hashId);
192 decor_detectorElementID(*measurement) = hashId;
193 decor_waferID(*measurement) = waferId.get_compact();
194 decor_bec(*measurement) = m_PixelHelper->barrel_ec(waferId);
195 decor_layer(*measurement) = m_PixelHelper->layer_disk(waferId);
196 decor_sizePhi(*measurement) = cluster->channelsInPhi();
197 decor_sizeZ(*measurement) = cluster->channelsInEta();
198 decor_SiWidth(*measurement) = cluster->channelsInPhi();
199 decor_eta_module(*measurement) = m_PixelHelper->eta_module(waferId);
200 decor_phi_module(*measurement) = m_PixelHelper->phi_module(waferId);
201 decor_omegax(*measurement) = omegax;
202 decor_omegay(*measurement) = omegay;
203 decor_LorentzShift(*measurement) = static_cast<float>( m_lorentzAngleTool->getLorentzShift(cluster->identifierHash(), ctx) );
204 decor_centroid_xphi(*measurement) = centroid.xPhi();
205 decor_centroid_xeta(*measurement) = centroid.xEta();
206 decor_side(*measurement) = 0;
207 decor_tots(*measurement) = cluster->totList();
208 }
209
210
211 // handle the truth
212 if (m_useTruthInfo) {
215
216 // reset measurement counter
217 std::size_t measurementIndex = 0;
218 for (std::size_t i(0); i<clusters->size(); ++i) {
219 if (not keepClusterCollection[i]) continue;
220 const xAOD::PixelCluster* cluster = clusters->at(i);
221 xAOD::TrackMeasurementValidation* measurement = measurements->at(measurementIndex);
222
223 // check the two match
224 if (cluster->identifier() != measurement->identifier()) {
225 ATH_MSG_ERROR("Cluster and Measurement are not matching!");
226 return StatusCode::FAILURE;
227 }
228
229 // Use the MultiTruth Collection
230 // to get a list of all true particle contributing to the cluster
231 if (cluster->index() >= measToTruth->size()) {
232 ATH_MSG_ERROR( "PRD index "<< cluster->index() << " not present in the measurement to truth vector with size " << measToTruth->size() );
233 return StatusCode::FAILURE;
234 }
235
236 auto tps = measToTruth->at(cluster->index());
237
238 std::vector<unsigned int> tp_indices;
239 std::vector<unsigned int> tp_barcodes;
240 for (const auto& tp : tps) {
241 tp_indices.push_back(tp->index());
242 tp_barcodes.push_back(HepMC::uniqueID(tp));
243 }
244
245 // decorate
246 decor_truth_indices(*measurement) = std::move(tp_indices);
247 decor_truth_barcode(*measurement) = std::move(tp_barcodes);
248 ++measurementIndex;
249 } // loop on clusters/measurements
250 } // if do truth
251
252 ATH_MSG_DEBUG( " recorded PixelPrepData objects: size " << measurements->size() );
253 return StatusCode::SUCCESS;
254}
255
257 const xAOD::PixelClusterContainer& clusters,
258 std::vector<bool>& labels) const
259{
260 labels.clear();
262 labels.resize(clusters.size(), true);
263 return StatusCode::SUCCESS;
264 }
265 labels.resize(clusters.size(), false);
266
267
268 // get the tracks
270 SG::ReadHandle<xAOD::TrackParticleContainer> trackParticleHandle = SG::makeHandle( trackParticleKey, ctx );
271 ATH_CHECK(trackParticleHandle.isValid());
272 const xAOD::TrackParticleContainer* trackParticles = trackParticleHandle.cptr();
273
274 for (const xAOD::TrackParticle* trackParticle : *trackParticles) {
275
276 std::optional<ActsTrk::TrackContainer::ConstTrackProxy> optional_track = getActsTrack(*trackParticle);
277 if ( not optional_track.has_value() ) {
278 ATH_MSG_ERROR("Invalid track link for particle " << trackParticle->index());
279 return StatusCode::FAILURE;
280 }
281 ActsTrk::TrackContainer::ConstTrackProxy track = optional_track.value();
282
283 // loop on track states
284 track.container().trackStateContainer()
285 .visitBackwards(track.tipIndex(),
286 [&labels]
287 (const typename ActsTrk::TrackContainer::ConstTrackStateProxy& state)
288 {
289 auto flags = state.typeFlags();
290 if (not flags.hasMeasurement()) return;
291
292 auto sl = state.getUncalibratedSourceLink().template get<ATLASUncalibSourceLink>();
293 if (sl == nullptr) return;
294
295 const xAOD::UncalibratedMeasurement &cluster = getUncalibratedMeasurement(sl);
296 if (cluster.type() != xAOD::UncalibMeasType::PixelClusterType) return;
297 labels.at(cluster.index()) = true;
298 });
299 } // loop on tracks
300 } // loop on read handle keys
301
302 return StatusCode::SUCCESS;
303}
304
305}
306
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_DEBUG(x)
ATLAS-specific HepMC functions.
Handle class for reading a decoration on an object.
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_centroid_xphi
SG::ReadHandleKey< xAOD::PixelClusterContainer > m_clustercontainer_key
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_LorentzShift
SG::ReadHandleKey< ActsTrk::MeasurementToTruthParticleAssociation > m_associationMap_key
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_sizeZ
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_centroid_xeta
SG::WriteHandleKey< xAOD::TrackMeasurementValidationContainer > m_write_xaod_key
PixelClusterTruthDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_omegay
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_truth_barcodes
StatusCode labelMeasurementToKeep(const EventContext &ctx, const xAOD::PixelClusterContainer &clusters, std::vector< bool > &labels) const
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_omegax
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_side
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_detectorElementID
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_truth_indices
SG::ReadHandleKeyArray< xAOD::TrackParticleContainer > m_trackParticlesKey
ToolHandle< ISiLorentzAngleTool > m_lorentzAngleTool
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_phi_module
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_sizePhi
SG::WriteDecorHandleKey< xAOD::PixelClusterContainer > m_trackMeasurement_link
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_eta_module
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_layer
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_waferID
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_tots
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_bec
SG::WriteDecorHandleKey< xAOD::TrackMeasurementValidationContainer > m_measurement_SiWidth
const ServiceHandle< StoreGateSvc > & detStore() 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.
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 used to describe the design of a module (diode segmentation and readout scheme).
SiLocalPosition positionFromColumnRow(const int column, const int row) const
Given row and column index of a diode, return position of diode center ALTERNATIVE/PREFERED way is to...
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.
virtual const SiDetectorDesign & design() const override final
access to the local description (inline):
Class to represent a position in the natural frame of a silicon sensor, for Pixel and SCT For Pixel: ...
double xPhi() const
position along phi direction:
double xEta() const
position along eta direction:
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.
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.
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) and eta (y) directions,...
ConstVectorMap< 3 > globalPosition() const
Returns the global position of the pixel cluster.
SG::ConstAccessor< SG::JaggedVecElt< int > >::element_type totList() const
Returns the list of ToT of the channels building the cluster.
int channelsInEta() const
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())
std::pair< float, float > computeOmegas(const xAOD::PixelCluster &cluster, const PixelID &pixelID)
PixelClusterContainer_v1 PixelClusterContainer
Define the version of the pixel cluster container.
TrackMeasurementValidation_v1 TrackMeasurementValidation
Reference the current persistent version:
TrackParticle_v1 TrackParticle
Reference the current persistent version:
long unsigned int DetectorIdentType
PixelCluster_v1 PixelCluster
Define the version of the pixel cluster class.
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