ATLAS Offline Software
Loading...
Searching...
No Matches
InDetToXAODSpacePointConversion.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
14
15namespace InDet {
16
18 ISvcLocator *pSvcLocator)
19 : AthReentrantAlgorithm(name, pSvcLocator)
20 {}
21
23 {
24 ATH_MSG_DEBUG("Initializing " << name() << " ...");
25
26 ATH_CHECK( m_beamSpotKey.initialize() );
27
31
35
38
41
43 ATH_CHECK(detStore()->retrieve(m_pixelID,"PixelID"));
44 ATH_CHECK(detStore()->retrieve(m_stripID,"SCT_ID"));
45 }
46
47 return StatusCode::SUCCESS;
48 }
49
50 StatusCode InDetToXAODSpacePointConversion::execute(const EventContext& ctx) const
51 {
52 ATH_MSG_DEBUG("Executing " << name() << " ...");
53
54 // Conds
56 const InDet::BeamSpotData* beamSpot = *beamSpotHandle;
57 auto vertex = beamSpot->beamVtx().position();
58
59 // Cluster Containers if requested
60 std::unique_ptr< xAOD::PixelClusterContainer > pixel_cluster_xaod_container = std::make_unique< xAOD::PixelClusterContainer >();
61 std::unique_ptr< xAOD::PixelClusterAuxContainer > pixel_cluster_xaod_aux_container = std::make_unique< xAOD::PixelClusterAuxContainer >();
62 pixel_cluster_xaod_container->setStore( pixel_cluster_xaod_aux_container.get() );
63
64 std::unique_ptr< xAOD::StripClusterContainer > strip_cluster_xaod_container = std::make_unique< xAOD::StripClusterContainer >();
65 std::unique_ptr< xAOD::StripClusterAuxContainer > strip_cluster_xaod_aux_container = std::make_unique< xAOD::StripClusterAuxContainer >();
66 strip_cluster_xaod_container->setStore( strip_cluster_xaod_aux_container.get() );
67
68 // Convert
69 if (m_processPixel.value()) {
70 ATH_CHECK( convertPixel(ctx, pixel_cluster_xaod_container.get()) );
71 }
72
73 if (m_processStrip.value()) {
74 std::unordered_map<Identifier, std::size_t> mapClusters{};
75 ATH_CHECK( convertStrip(ctx, vertex,
76 strip_cluster_xaod_container.get(),
77 mapClusters) );
78 ATH_CHECK( convertStripOverlap(ctx, vertex,
79 strip_cluster_xaod_container.get(),
80 mapClusters) );
81 }
82
83 // Save optional clusters
85 if (m_processPixel.value()) {
87 ATH_CHECK( pixel_cluster_xaod_handle.record( std::move(pixel_cluster_xaod_container),
88 std::move(pixel_cluster_xaod_aux_container) ) );
89 }
90
91 if (m_processStrip.value()) {
93 ATH_CHECK( strip_cluster_xaod_handle.record( std::move(strip_cluster_xaod_container),
94 std::move(strip_cluster_xaod_aux_container) ) );
95 }
96 }
97
98 return StatusCode::SUCCESS;
99 }
100
101 StatusCode InDetToXAODSpacePointConversion::convertPixel(const EventContext& ctx,
102 xAOD::PixelClusterContainer* cluster_xaod_container) const
103 {
104 static const SG::AuxElement::Accessor< ElementLink< ::SpacePointCollection > > linkAcc("pixelSpacePointLink");
105
106 const InDetDD::SiDetectorElementCollection* pixElements = nullptr;
107 if (m_convertClusters) {
109 if (not pixelDetEleHandle.isValid()) {
110 ATH_MSG_FATAL(m_pixelDetEleCollKey.fullKey() << " is not available.");
111 return StatusCode::FAILURE;
112 }
113 pixElements = pixelDetEleHandle.cptr();
114 }
115
116 // Input
118 ATH_CHECK( pixel_handle.isValid() );
119 const ::SpacePointContainer* pixel_container = pixel_handle.cptr();
120
121 // Output
122 std::unique_ptr< xAOD::SpacePointContainer > pixel_xaod_container = std::make_unique< xAOD::SpacePointContainer >(SG::VIEW_ELEMENTS, SG::ALWAYS_TRACK_INDICES);
123 std::unique_ptr< xAOD::SpacePointAuxContainer > pixel_xaod_aux_container = std::make_unique< xAOD::SpacePointAuxContainer >();
124 pixel_xaod_container->setStore( pixel_xaod_aux_container.get() );
125
126 size_t nsp = 0;
127 for (const ::SpacePointCollection *spc : *pixel_container) {
128 nsp += spc->size();
129 }
131 pixel_xaod_container->push_new (nsp, [&pool](){return pool.nextElementPtr();});
132 size_t isp = 0;
133
134 // Conversion
135 for (const ::SpacePointCollection *spc : *pixel_container) {
136 for (const Trk::SpacePoint *sp : *spc) {
137 const InDet::PixelSpacePoint *indetSP = dynamic_cast<const InDet::PixelSpacePoint *>(sp);
138
139 xAOD::SpacePoint* pixel_sp = pixel_xaod_container->at (isp++);
141
142 // Also make cluster object, if requested
143 if (m_convertClusters) {
144 const std::pair<const Trk::PrepRawData*, const Trk::PrepRawData*>& clusterList = sp->clusterList();
145 const InDet::PixelCluster* theCluster = dynamic_cast<const InDet::PixelCluster*>(clusterList.first);
146 if (theCluster == nullptr) {
147 ATH_MSG_FATAL("Cannot cast InDet::PixelCluster");
148 }
149
150 auto clusterId = clusterList.first->identify();
151 const InDetDD::SiDetectorElement *element = pixElements->getDetectorElement(m_pixelID->wafer_hash(m_pixelID->wafer_id(clusterId)));
152 if ( element == nullptr ) {
153 ATH_MSG_FATAL( "Invalid pixel detector element for cluster identifier " << clusterId );
154 return StatusCode::FAILURE;
155 }
156
157 xAOD::PixelCluster * pixelCl = new xAOD::PixelCluster();
158 cluster_xaod_container->push_back(pixelCl);
159 ATH_CHECK( TrackingUtilities::convertInDetToXaodCluster(*theCluster, *element, *pixelCl) );
160 pixel_sp->setMeasurements( {cluster_xaod_container->back()} );
161 }
162
163 // Add link to this space point
164 ElementLink< ::SpacePointCollection > link(indetSP, *spc);
165 linkAcc(*pixel_sp) = link;
166 }
167 }
168
169 // Store
171 ATH_CHECK( pixel_xaod_handle.record( std::move(pixel_xaod_container), std::move(pixel_xaod_aux_container) ) );
172
173 return StatusCode::SUCCESS;
174 }
175
176 StatusCode InDetToXAODSpacePointConversion::convertStrip(const EventContext& ctx,
177 const Amg::Vector3D& vertex,
178 xAOD::StripClusterContainer* cluster_xaod_container,
179 std::unordered_map<Identifier, std::size_t>& mapClusters) const
180 {
181 const InDetDD::SiDetectorElementCollection* stripElements = nullptr;
182 if (m_convertClusters) {
184 if (not stripDetEleHandle.isValid()) {
185 ATH_MSG_FATAL(m_stripDetEleCollKey.fullKey() << " is not available.");
186 return StatusCode::FAILURE;
187 }
188 stripElements = stripDetEleHandle.cptr();
189 }
190
191 static const SG::AuxElement::Accessor< ElementLink< ::SpacePointCollection > > linkAcc("sctSpacePointLink");
192
193 // Input
195 ATH_CHECK( strip_handle.isValid() );
196 const ::SpacePointContainer* strip_container = strip_handle.cptr();
197
198 // Output
199 std::unique_ptr< xAOD::SpacePointContainer > strip_xaod_container = std::make_unique< xAOD::SpacePointContainer >();
200 std::unique_ptr< xAOD::SpacePointAuxContainer > strip_xaod_aux_container = std::make_unique< xAOD::SpacePointAuxContainer >();
201 strip_xaod_container->setStore( strip_xaod_aux_container.get() );
202
203 strip_xaod_container->reserve(strip_container->size());
204 strip_xaod_aux_container->reserve(strip_container->size());
205
206 // Conversion
207 for (const ::SpacePointCollection *spc : *strip_container) {
208 for (const Trk::SpacePoint *sp : *spc) {
209 const InDet::SCT_SpacePoint *indetSP = dynamic_cast<const InDet::SCT_SpacePoint *>(sp);
210
211 strip_xaod_container->push_back( new xAOD::SpacePoint() );
212 ATH_CHECK( TrackingUtilities::convertTrkToXaodStripSpacePoint(*indetSP, vertex, *strip_xaod_container->back()) );
213
214 // Also make cluster object, if requested
215 if (m_convertClusters) {
216 const std::pair<const Trk::PrepRawData*, const Trk::PrepRawData*>& clusterList = sp->clusterList();
217 const InDet::SCT_Cluster* theCluster1 = dynamic_cast<const InDet::SCT_Cluster*>(clusterList.first);
218 const InDet::SCT_Cluster* theCluster2 = dynamic_cast<const InDet::SCT_Cluster*>(clusterList.second);
219 if (theCluster1 == nullptr or
220 theCluster2 == nullptr) {
221 ATH_MSG_FATAL("Cannot cast InDet::SCT_Cluster");
222 }
223
224 auto clusterId1 = clusterList.first->identify();
225 auto clusterId2 = clusterList.second->identify();
226 const InDetDD::SiDetectorElement *element1 = stripElements->getDetectorElement(m_stripID->wafer_hash(m_stripID->wafer_id(clusterId1)));
227 const InDetDD::SiDetectorElement *element2 = stripElements->getDetectorElement(m_stripID->wafer_hash(m_stripID->wafer_id(clusterId2)));
228 if ( element1 == nullptr ) {
229 ATH_MSG_FATAL( "Invalid strip detector element for cluster (1) identifiers " << clusterId1 );
230 return StatusCode::FAILURE;
231 }
232 if ( element2 == nullptr ) {
233 ATH_MSG_FATAL( "Invalid strip detector element for cluster (2) identifiers " << clusterId2 );
234 return StatusCode::FAILURE;
235 }
236 //tries to insert an entry with key clusterId. Returns false and does nothing if the key already exists.
237 auto insertEntry = [&mapClusters, cluster_xaod_container](const auto & clusterId)-> bool{
238 const auto & [p,inserted] = mapClusters.try_emplace(clusterId, cluster_xaod_container->size());
239 return inserted;
240 };
241 // if cluster is not there, add entry and add cluster to container
242 if (insertEntry(clusterId1)){
243 xAOD::StripCluster * stripCl1 = new xAOD::StripCluster();
244 cluster_xaod_container->push_back(stripCl1);
245 ATH_CHECK( TrackingUtilities::convertInDetToXaodCluster(*theCluster1, *element1, *stripCl1) );
246 }
247 if (insertEntry(clusterId2)) {
248 xAOD::StripCluster * stripCl2 = new xAOD::StripCluster();
249 cluster_xaod_container->push_back(stripCl2);
250 ATH_CHECK( TrackingUtilities::convertInDetToXaodCluster(*theCluster2, *element2, *stripCl2) );
251 }
252 // Get the clusters so that we can add a link to them
253 xAOD::StripCluster * stripCl1 = cluster_xaod_container->at(mapClusters[clusterId1]);
254 xAOD::StripCluster * stripCl2 = cluster_xaod_container->at(mapClusters[clusterId2]);
255 strip_xaod_container->back()->setMeasurements( {stripCl1, stripCl2} );
256 }
257
258 // Add link to this space point
259 ElementLink< ::SpacePointCollection > link(indetSP, *spc);
260 linkAcc(*strip_xaod_container->back()) = link;
261 }
262 }
263
264 // Store
266 ATH_CHECK( strip_xaod_handle.record( std::move(strip_xaod_container), std::move(strip_xaod_aux_container) ) );
267
268 return StatusCode::SUCCESS;
269 }
270
271
273 const Amg::Vector3D& vertex,
274 xAOD::StripClusterContainer* cluster_xaod_container,
275 std::unordered_map<Identifier, std::size_t>& mapClusters) const
276 {
277 const InDetDD::SiDetectorElementCollection* stripElements = nullptr;
278 if (m_convertClusters) {
280 if (not stripDetEleHandle.isValid()) {
281 ATH_MSG_FATAL(m_stripDetEleCollKey.fullKey() << " is not available.");
282 return StatusCode::FAILURE;
283 }
284 stripElements = stripDetEleHandle.cptr();
285 }
286
287 // Inputs
289 ATH_CHECK( strip_overlap_handle.isValid() );
290 const ::SpacePointOverlapCollection* strip_overlap_container = strip_overlap_handle.cptr();
291
292 // Outputs
293 std::unique_ptr< xAOD::SpacePointContainer > strip_overlap_xaod_container = std::make_unique< xAOD::SpacePointContainer >();
294 std::unique_ptr< xAOD::SpacePointAuxContainer > strip_overlap_xaod_aux_container = std::make_unique< xAOD::SpacePointAuxContainer >();
295 strip_overlap_xaod_container->setStore( strip_overlap_xaod_aux_container.get() );
296
297 strip_overlap_xaod_container->reserve(strip_overlap_container->size());
298 strip_overlap_xaod_aux_container->reserve(strip_overlap_container->size());
299
300 // Conversion
301 static const SG::AuxElement::Accessor< ElementLink< ::SpacePointOverlapCollection > > stripSpacePointLinkAcc("stripOverlapSpacePointLink");
302
303 for (const Trk::SpacePoint *sp : *strip_overlap_container) {
304 const InDet::SCT_SpacePoint *indetSP = dynamic_cast<const InDet::SCT_SpacePoint *>(sp);
305
306 strip_overlap_xaod_container->push_back( new xAOD::SpacePoint() );
307 ATH_CHECK( TrackingUtilities::convertTrkToXaodStripSpacePoint(*indetSP, vertex, *strip_overlap_xaod_container->back()) );
308
309 // Also make cluster object, if requested
310 if (m_convertClusters) {
311 const std::pair<const Trk::PrepRawData*, const Trk::PrepRawData*>& clusterList = sp->clusterList();
312 const InDet::SCT_Cluster* theCluster1 = dynamic_cast<const InDet::SCT_Cluster*>(clusterList.first);
313 const InDet::SCT_Cluster* theCluster2 = dynamic_cast<const InDet::SCT_Cluster*>(clusterList.second);
314 if (theCluster1 == nullptr or
315 theCluster2 == nullptr) {
316 ATH_MSG_FATAL("Cannot cast InDet::SCT_Cluster");
317 }
318
319 auto clusterId1 = clusterList.first->identify();
320 auto clusterId2 = clusterList.second->identify();
321 const InDetDD::SiDetectorElement *element1 = stripElements->getDetectorElement(m_stripID->wafer_hash(m_stripID->wafer_id(clusterId1)));
322 const InDetDD::SiDetectorElement *element2 = stripElements->getDetectorElement(m_stripID->wafer_hash(m_stripID->wafer_id(clusterId2)));
323
324 if ( element1 == nullptr ) {
325 ATH_MSG_FATAL( "Invalid strip detector element for cluster (1) identifiers " << clusterId1 );
326 return StatusCode::FAILURE;
327 }
328 if ( element2 == nullptr ) {
329 ATH_MSG_FATAL( "Invalid strip detector element for cluster (2) identifiers " << clusterId2 );
330 return StatusCode::FAILURE;
331 }
332 //tries to insert an entry with key clusterId. Returns false and does nothing if the key already exists.
333 auto insertEntry = [&mapClusters, cluster_xaod_container](const auto & clusterId)-> bool{
334 const auto & [p,inserted] = mapClusters.try_emplace(clusterId, cluster_xaod_container->size());
335 return inserted;
336 };
337 if (insertEntry(clusterId1)) {
338 xAOD::StripCluster * stripCl1 = new xAOD::StripCluster();
339 cluster_xaod_container->push_back(stripCl1);
340 ATH_CHECK( TrackingUtilities::convertInDetToXaodCluster(*theCluster1, *element1, *stripCl1) );
341 }
342 if (insertEntry(clusterId2)) {
343 xAOD::StripCluster * stripCl2 = new xAOD::StripCluster();
344 cluster_xaod_container->push_back(stripCl2);
345 ATH_CHECK( TrackingUtilities::convertInDetToXaodCluster(*theCluster2, *element2, *stripCl2) );
346 }
347
348 xAOD::StripCluster * stripCl1 = cluster_xaod_container->at(mapClusters[clusterId1]);
349 xAOD::StripCluster * stripCl2 = cluster_xaod_container->at(mapClusters[clusterId2]);
350 strip_overlap_xaod_container->back()->setMeasurements( {stripCl1, stripCl2} );
351 }
352
353 ElementLink< ::SpacePointOverlapCollection > TrkLink(sp, *strip_overlap_container);
354 stripSpacePointLinkAcc( *strip_overlap_xaod_container->back() ) = TrkLink;
355 }
356
357 // Store
359 ATH_CHECK( strip_overlap_xaod_handle.record( std::move(strip_overlap_xaod_container), std::move(strip_overlap_xaod_aux_container) ) );
360
361 return StatusCode::SUCCESS;
362 }
363
364}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_DEBUG(x)
static Double_t sp
const ServiceHandle< StoreGateSvc > & detStore() const
An algorithm that can be simultaneously executed in multiple threads.
a typed memory pool that saves time spent allocation small object.
Definition DataPool.h:63
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.
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.
StatusCode convertPixel(const EventContext &ctx, xAOD::PixelClusterContainer *cluster_xaod_container) const
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteHandleKey< xAOD::SpacePointContainer > m_outSpacepointsPixel
SG::ReadHandleKey< ::SpacePointContainer > m_inSpacepointsPixel
InDetToXAODSpacePointConversion(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
StatusCode convertStripOverlap(const EventContext &ctx, const Amg::Vector3D &vertex, xAOD::StripClusterContainer *cluster_xaod_container, std::unordered_map< Identifier, std::size_t > &mapClusters) const
SG::WriteHandleKey< xAOD::PixelClusterContainer > m_outClustersPixel
SG::WriteHandleKey< xAOD::SpacePointContainer > m_outSpacepointsOverlap
SG::ReadHandleKey< ::SpacePointContainer > m_inSpacepointsStrip
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
SG::ReadHandleKey< ::SpacePointOverlapCollection > m_inSpacepointsOverlap
SG::WriteHandleKey< xAOD::StripClusterContainer > m_outClustersStrip
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
SG::WriteHandleKey< xAOD::SpacePointContainer > m_outSpacepointsStrip
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_stripDetEleCollKey
StatusCode convertStrip(const EventContext &ctx, const Amg::Vector3D &vertex, xAOD::StripClusterContainer *cluster_xaod_container, std::unordered_map< Identifier, std::size_t > &mapClusters) const
A PixelSpacePoint is created from a PixelCluster.
An SCT_SpacePoint is created from two SCT_Cluster's from two different wafers.
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
const_pointer_type cptr()
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
void setMeasurements(std::vector< const xAOD::UncalibratedMeasurement * > &&value)
Sets the index of the measurements.
Eigen::Matrix< double, 3, 1 > Vector3D
Primary Vertex Finder.
@ ALWAYS_TRACK_INDICES
Always track indices, regardless of the setting of the ownership policy.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
StatusCode convertTrkToXaodStripSpacePoint(const InDet::SCT_SpacePoint &trkSpacePoint, const Amg::Vector3D &vertex, xAOD::SpacePoint &xaodSpacePoint)
StatusCode convertTrkToXaodPixelSpacePoint(const InDet::PixelSpacePoint &trkSpacePoint, xAOD::SpacePoint &xaodSpacePoint)
StatusCode convertInDetToXaodCluster(const InDet::PixelCluster &indetCluster, const InDetDD::SiDetectorElement &element, xAOD::PixelCluster &xaodCluster)
pool namespace
Definition libname.h:15
PixelClusterContainer_v1 PixelClusterContainer
Define the version of the pixel cluster container.
StripCluster_v1 StripCluster
Define the version of the strip cluster class.
StripClusterContainer_v1 StripClusterContainer
Define the version of the strip cluster container.
PixelCluster_v1 PixelCluster
Define the version of the pixel cluster class.