ATLAS Offline Software
Loading...
Searching...
No Matches
InDetToXAODClusterConversion.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8#include "Identifier/Identifier.h"
14
17
20
23
26#include <iterator>
27
28
29
30using namespace InDet;
31
32// Constructor with parameters:
33InDetToXAODClusterConversion::InDetToXAODClusterConversion(const std::string &name, ISvcLocator *pSvcLocator) :
34AthReentrantAlgorithm(name, pSvcLocator)
35{}
36
37
38//-----------------------------------------------------------------------------
39// Initialize method:
41 ATH_MSG_INFO("Initializing " << name() << " ...");
42
43 ATH_CHECK(detStore()->retrieve(m_pixelID,"PixelID"));
44 ATH_CHECK(detStore()->retrieve(m_stripID,"SCT_ID"));
45 if (m_processHgtd)
46 {ATH_CHECK(detStore()->retrieve(m_hgtdID,"HGTD_ID"));}
47
51
56
59
60 ATH_MSG_DEBUG( "Initialize done !" );
61 return StatusCode::SUCCESS;
62}
63
64//----------------------------------------------------------------------------
65//
66StatusCode InDetToXAODClusterConversion::execute(const EventContext& ctx) const {
67 ATH_MSG_DEBUG("Executing " << name() << " ...");
68
69 if (m_processPixel.value()) {
70 ATH_MSG_DEBUG("Converting Pixel Clusters: InDet -> xAOD");
72 }
73
74 if (m_processStrip.value()) {
75 ATH_MSG_DEBUG("Converting Strip Clusters: InDet -> xAOD");
77 }
78
79 if (m_processHgtd.value()) {
80 ATH_MSG_DEBUG("Converting HGTD Clusters: InDet -> xAOD");
82 }
83
84 return StatusCode::SUCCESS;
85}
86
87StatusCode InDetToXAODClusterConversion::convertPixelClusters(const EventContext& ctx) const {
89 const InDetDD::SiDetectorElementCollection* pixElements(*pixelDetEleHandle);
90 if (not pixelDetEleHandle.isValid() or pixElements==nullptr) {
91 ATH_MSG_FATAL(m_pixelDetEleCollKey.fullKey() << " is not available.");
92 return StatusCode::FAILURE;
93 }
94
96 ATH_CHECK( outputPixelClusterContainer.record (std::make_unique<xAOD::PixelClusterContainer>(SG::VIEW_ELEMENTS, SG::ALWAYS_TRACK_INDICES),
97 std::make_unique<xAOD::PixelClusterAuxContainer>()) );
98 ATH_MSG_DEBUG( "Recorded xAOD::PixelClusterContainer with key: " << m_outputPixelClusterContainerKey.key() );
99
101
102 static const SG::AuxElement::Accessor< ElementLink< InDet::PixelClusterCollection > > pixelLinkAcc("pixelClusterLink");
103
104 size_t nclusters = 0;
105 for (const auto *const clusterCollection : *inputPixelClusterContainer) {
106 if (!clusterCollection) continue;
107 nclusters += clusterCollection->size();
108 }
110 outputPixelClusterContainer->push_new (nclusters, [&pool](){return pool.nextElementPtr();});
111 size_t icluster = 0;
112
113 for (const auto *const clusterCollection : *inputPixelClusterContainer) {
114 if (!clusterCollection) continue;
115 for(const auto *const theCluster : *clusterCollection) {
116 Identifier clusterId = theCluster->identify();
117
118 const InDetDD::SiDetectorElement *element=pixElements->getDetectorElement(m_pixelID->wafer_hash(m_pixelID->wafer_id(clusterId)));
119 if ( element==nullptr ) {
120 ATH_MSG_FATAL( "Invalid pixel detector element for cluster identifier " << clusterId );
121 return StatusCode::FAILURE;
122 }
123
124 xAOD::PixelCluster * pixelCl = outputPixelClusterContainer->at(icluster++);
125 ATH_CHECK( TrackingUtilities::convertInDetToXaodCluster(*theCluster, *element, *pixelCl) );
126
127 // Create auxiliary branches accessors
128 ElementLink<InDet::PixelClusterCollection> pixelLink(theCluster, *clusterCollection);
129 pixelLinkAcc( *pixelCl ) = pixelLink;
130 }
131 }
132 if (icluster != outputPixelClusterContainer->size()) {
133 ATH_MSG_ERROR("xAOD::PixelClusterContainer miscount; " << icluster << " versus " << outputPixelClusterContainer->size());
134 return StatusCode::FAILURE;
135 }
136
137 ATH_MSG_DEBUG("xAOD::PixelClusterContainer with size: " << outputPixelClusterContainer->size());
138 return StatusCode::SUCCESS;
139}
140
141StatusCode InDetToXAODClusterConversion::convertStripClusters(const EventContext& ctx) const {
143 const InDetDD::SiDetectorElementCollection* stripElements(*stripDetEleHandle);
144 if (not stripDetEleHandle.isValid() or stripElements==nullptr) {
145 ATH_MSG_FATAL(m_stripDetEleCollKey.fullKey() << " is not available.");
146 return StatusCode::FAILURE;
147 }
148
150 ATH_CHECK( outputStripClusterContainer.record (std::make_unique<xAOD::StripClusterContainer>(SG::VIEW_ELEMENTS, SG::ALWAYS_TRACK_INDICES),
151 std::make_unique<xAOD::StripClusterAuxContainer>()) );
152 ATH_MSG_DEBUG( "Recorded xAOD::StripClusterContainer with key: " << m_outputStripClusterContainerKey.key() );
153
155
156 size_t nclusters = 0;
157 for (const auto *const clusterCollection : *inputStripClusterContainer) {
158 if (!clusterCollection) continue;
159 nclusters += clusterCollection->size();
160 }
162 outputStripClusterContainer->push_new (nclusters, [&pool](){return pool.nextElementPtr();});
163 size_t icluster = 0;
164
165 static const SG::AuxElement::Accessor< ElementLink< InDet::SCT_ClusterCollection > > stripLinkAcc("sctClusterLink");
166 for (const auto *const clusterCollection : *inputStripClusterContainer) {
167 if (!clusterCollection) continue;
168 for(const auto *const theCluster : *clusterCollection) {
169 Identifier clusterId = theCluster->identify();
170
171 const InDetDD::SiDetectorElement *element=stripElements->getDetectorElement(m_stripID->wafer_hash(m_stripID->wafer_id(clusterId)));
172 if ( element==nullptr ) {
173 ATH_MSG_FATAL( "Invalid strip detector element for cluster with identifier " << clusterId );
174 return StatusCode::FAILURE;
175 }
176
177
178 xAOD::StripCluster * stripCl = outputStripClusterContainer->at(icluster++);
179 ATH_CHECK( TrackingUtilities::convertInDetToXaodCluster(*theCluster, *element, *stripCl, m_isITk) );
180
181 // Create auxiliary branches accessors
182 ElementLink<InDet::SCT_ClusterCollection> stripLink(theCluster, *clusterCollection);
183 stripLinkAcc( *stripCl ) = stripLink;
184 }
185 }
186 if (icluster != outputStripClusterContainer->size()) {
187 ATH_MSG_ERROR("xAOD::StripClusterContainer miscount; " << icluster << " versus " << outputStripClusterContainer->size());
188 return StatusCode::FAILURE;
189 }
190
191 ATH_MSG_DEBUG("xAOD::StripClusterContainer with size: " << outputStripClusterContainer->size());
192
193 return StatusCode::SUCCESS;
194}
195
196StatusCode InDetToXAODClusterConversion::convertHgtdClusters(const EventContext& ctx) const {
198 const InDetDD::HGTD_DetectorElementCollection* hgtdElements(*hgtdDetEleHandle);
199 if (not hgtdDetEleHandle.isValid() or hgtdElements==nullptr) {
200 ATH_MSG_FATAL(m_HGTDDetEleCollKey.fullKey() << " is not available.");
201 return StatusCode::FAILURE;
202 }
203
205 ATH_CHECK( outputHgtdClusterContainer.record (std::make_unique<xAOD::HGTDClusterContainer>(),
206 std::make_unique<xAOD::HGTDClusterAuxContainer>()) );
207 ATH_MSG_DEBUG( "Recorded xAOD::HGTDClusterContainer with key: " << m_outputHgtdClusterContainerKey.key() );
208
210 ATH_CHECK(inputHgtdClusterContainer.isValid());
211
212 static const SG::AuxElement::Accessor< ElementLink< ::HGTD_ClusterCollection > > hgtdLinkAcc("hgtdClusterLink");
213 for (const auto *const clusterCollection : *inputHgtdClusterContainer) {
214 if (!clusterCollection) continue;
215 for(const auto *const theCluster : *clusterCollection) {
216 Identifier clusterId = theCluster->identify();
217
218 const auto *element = InDetDD::HGTDDetEl::getDetectorElement(m_hgtdID->wafer_hash(m_hgtdID->wafer_id(clusterId)),*hgtdElements);
219 if ( element==nullptr ) {
220 ATH_MSG_FATAL( "Invalid strip detector element for cluster with identifier " << clusterId );
221 return StatusCode::FAILURE;
222 }
223
224 xAOD::HGTDCluster * hgtdCl = new xAOD::HGTDCluster();
225 outputHgtdClusterContainer->push_back(hgtdCl);
226 ATH_CHECK( TrackingUtilities::convertInDetToXaodCluster(*theCluster, *element, *hgtdCl) );
227
228 // Create auxiliary branches accessors
229 ElementLink<::HGTD_ClusterCollection> hgtdLink(theCluster, *clusterCollection);
230 hgtdLinkAcc( *hgtdCl ) = hgtdLink;
231 }
232 }
233
234 ATH_MSG_DEBUG("xAOD::HGTDClusterContainer with size: " << outputHgtdClusterContainer->size());
235 return StatusCode::SUCCESS;
236}
237
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
An STL vector of pointers that by default owns its pointed-to elements.
Algorithm to convert InDet::PixelClusters and InDet::SCT_Clusters to xAOD::PixelClusters and xAOD::St...
This is an Identifier helper class for the Pixel subdetector.
This is an Identifier helper class for the SCT subdetector.
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
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
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.
SG::ReadCondHandleKey< InDetDD::HGTD_DetectorElementCollection > m_HGTDDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_stripDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
SG::WriteHandleKey< xAOD::PixelClusterContainer > m_outputPixelClusterContainerKey
StatusCode convertStripClusters(const EventContext &ctx) const
SG::ReadHandleKey< InDet::SCT_ClusterContainer > m_inputStripClusterContainerKey
SG::WriteHandleKey< xAOD::HGTDClusterContainer > m_outputHgtdClusterContainerKey
virtual StatusCode execute(const EventContext &ctx) const override
StatusCode convertHgtdClusters(const EventContext &ctx) const
StatusCode convertPixelClusters(const EventContext &ctx) const
SG::WriteHandleKey< xAOD::StripClusterContainer > m_outputStripClusterContainerKey
SG::ReadHandleKey<::HGTD_ClusterContainer > m_inputHgtdClusterContainerKey
SG::ReadHandleKey< InDet::PixelClusterContainer > m_inputPixelClusterContainerKey
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
const HGTD_DetectorElement * getDetectorElement(const IdentifierHash &hash, const HGTD_DetectorElementCollection &coll)
DataVector< HGTD_DetectorElement > HGTD_DetectorElementCollection
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
StatusCode convertInDetToXaodCluster(const InDet::PixelCluster &indetCluster, const InDetDD::SiDetectorElement &element, xAOD::PixelCluster &xaodCluster)
pool namespace
Definition libname.h:15
StripCluster_v1 StripCluster
Define the version of the strip cluster class.
PixelCluster_v1 PixelCluster
Define the version of the pixel cluster class.
HGTDCluster_v1 HGTDCluster
Define the version of the pixel cluster class.
Definition HGTDCluster.h:13