ATLAS Offline Software
Loading...
Searching...
No Matches
XAODToInDetClusterConversion.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7
11
15
16#include <map>
17#include <cmath>
18
19namespace InDet {
20
21
23 ATH_MSG_INFO( "Initializing " << name() << " ... " );
24
25 // Pixel Clusters
27 if (m_processPixel) {
28 ATH_CHECK( detStore()->retrieve(m_pixelID,"PixelID") );
29 }
35
36 // Strip Clusters
38 if (m_processStrip) {
39 ATH_CHECK( detStore()->retrieve(m_stripID, "SCT_ID") );
40 }
46
47 ATH_CHECK( m_lorentzAngleTool.retrieve(EnableTool{not m_lorentzAngleTool.empty()}) );
48
49 // Hgtd Clusters
51 if (m_processHgtd) {
52 ATH_CHECK( detStore()->retrieve(m_hgtdID, "HGTD_ID") );
53 }
57
58 return StatusCode::SUCCESS;
59 }
60
61 StatusCode XAODToInDetClusterConversion::execute(const EventContext& ctx) const
62 {
63 ATH_MSG_DEBUG( "Executing " << name() << " ... ");
64 if (m_processPixel) {
65 ATH_MSG_DEBUG("Converting Pixel Clusters: xAOD -> InDet");
67 }
68
69 if (m_processStrip) {
70 ATH_MSG_DEBUG("Converting Strip Clusters: xAOD -> InDet");
72 }
73
74 if (m_processHgtd) {
75 ATH_MSG_DEBUG("Converting HGTD Clusters: xAOD -> InDet");
77 }
78
79 return StatusCode::SUCCESS;
80 }
81
82 StatusCode XAODToInDetClusterConversion::convertPixelClusters(const EventContext& ctx) const {
83 const InDetDD::SiDetectorElementCollection* pixElements{};
84 ATH_CHECK(SG::get(pixElements, m_pixelDetEleCollKey, ctx));
85
86 const xAOD::PixelClusterContainer *inputPixelClusters{};
87 ATH_CHECK(SG::get(inputPixelClusters, m_inputPixelClusterContainerKey, ctx));
88
91 SG::WriteHandle outputPixelClusterContainer{m_outputPixelClusterContainerKey, ctx};
92 ATH_CHECK( outputPixelClusterContainer.record (std::make_unique<InDet::PixelClusterContainer>(m_pixelID->wafer_hash_max(), EventContainers::Mode::OfflineFast)) );
93 ATH_MSG_DEBUG( "Container '" << m_outputPixelClusterContainerKey.key() << "' initialised" );
94
95 ATH_CHECK( outputPixelClusterContainer.symLink( m_pixelClusterContainerLinkKey ) );
96
97
98 // Conversion
99 // Access to the cluster from a given detector element is possible
100 // via the ContainerAccessor.
102 pixelAccessor ( *inputPixelClusters,
103 [] (const xAOD::PixelCluster& cl) -> IdentifierHash { return cl.identifierHash(); },
104 pixElements->size());
105
106 const auto& allIdHashes = pixelAccessor.allIdentifiers();
107 for (const auto& hashId : allIdHashes) {
108 const InDetDD::SiDetectorElement *element = pixElements->getDetectorElement(hashId);
109 if ( element == nullptr ) {
110 ATH_MSG_FATAL( "Invalid pixel detector element for hash " << hashId);
111 return StatusCode::FAILURE;
112 }
113
114 std::unique_ptr<InDet::PixelClusterCollection> collection = std::make_unique<InDet::PixelClusterCollection>(hashId);
115
116 // Get the detector element and range for the idHash
117 for (const auto& this_range : pixelAccessor.rangesForIdentifierDirect(hashId)) {
118 for (auto start = this_range.first; start != this_range.second; ++start) {
119 const xAOD::PixelCluster* in_cluster = *start;
120
121 InDet::PixelCluster* cluster = nullptr;
122 ATH_CHECK( TrackingUtilities::convertXaodToInDetCluster(*in_cluster, *element, *m_pixelID, cluster) );
123 //coverity[FORWARD_NULL:FALSE]
124 cluster->setHashAndIndex(hashId, collection->size());
125
126 // Add to Collection
127 collection->push_back(cluster);
128 dec_link(*in_cluster) = Link_t{cluster, *collection};
129 }
130 }
131
132 InDet::PixelClusterContainer::IDC_WriteHandle lock = outputPixelClusterContainer->getWriteHandle(hashId);
133 ATH_CHECK(lock.addOrDelete( std::move(collection) ));
134
135 } // loop on hashIds
136
137 auto offsets = std::make_unique<std::vector<unsigned int>>(m_pixelID->wafer_hash_max(), 0);
138 unsigned int counter(0);
139 for (const auto coll : *outputPixelClusterContainer) {
140 (*offsets)[coll->identifyHash()] = counter;
141 counter += coll->size();
142 }
143 SG::WriteHandle offSetHandle{m_pixelClusterOffSetKey ,ctx};
144 ATH_CHECK(offSetHandle.record(std::move(offsets)));
145
146 return StatusCode::SUCCESS;
147 }
148
149 StatusCode XAODToInDetClusterConversion::convertStripClusters(const EventContext& ctx) const {
150 const InDetDD::SiDetectorElementCollection* stripElements{};
151 ATH_CHECK(SG::get(stripElements, m_stripDetEleCollKey, ctx));
152 const xAOD::StripClusterContainer *inputStripClusters{};
153 ATH_CHECK(SG::get(inputStripClusters, m_inputStripClusterContainerKey, ctx));
154
157
158 SG::WriteHandle outputStripClusterContainer{m_outputStripClusterContainerKey, ctx};
159 ATH_CHECK( outputStripClusterContainer.record (std::make_unique<InDet::SCT_ClusterContainer>(m_stripID->wafer_hash_max(), EventContainers::Mode::OfflineFast)) );
160 ATH_MSG_DEBUG( "Container '" << m_outputStripClusterContainerKey.key() << "' initialised" );
161
162 ATH_CHECK( outputStripClusterContainer.symLink( m_stripClusterContainerLinkKey ) );
163
164 // Conversion
165 // Access to the cluster from a given detector element is possible
166 // via the ContainerAccessor.
168 stripAccessor ( *inputStripClusters,
169 [] (const xAOD::StripCluster& cl) -> IdentifierHash { return cl.identifierHash(); },
170 stripElements->size());
171
172
173
174 const auto& allIdHashes = stripAccessor.allIdentifiers();
175 for (const auto& hashId : allIdHashes) {
176 const InDetDD::SiDetectorElement *element = stripElements->getDetectorElement(hashId);
177 if ( element == nullptr ) {
178 ATH_MSG_FATAL( "Invalid strip detector element for hash " << hashId);
179 return StatusCode::FAILURE;
180 }
181
182 bool isBarrel = element->isBarrel();
183 double shift = not isBarrel ? m_lorentzAngleTool->getLorentzShift(hashId, ctx) : 0.;
184
185 std::unique_ptr<InDet::SCT_ClusterCollection> collection = std::make_unique<InDet::SCT_ClusterCollection>(hashId);
186
187
188 // Get the detector element and range for the idHash
189 for (const auto& this_range : stripAccessor.rangesForIdentifierDirect(hashId)) {
190 for (auto start = this_range.first; start != this_range.second; ++start) {
191 const xAOD::StripCluster* in_cluster = *start;
192
193 InDet::SCT_Cluster* cluster = nullptr;
194 ATH_CHECK( TrackingUtilities::convertXaodToInDetCluster(*in_cluster, *element, *m_stripID, cluster, shift) );
195 //coverity[FORWARD_NULL:FALSE]
196 cluster->setHashAndIndex(hashId, collection->size());
197
198
199 // Add to Collection
200 collection->push_back( cluster );
201 dec_link(*in_cluster) = Link_t{cluster, *collection};
202 }
203 }
204
205 InDet::SCT_ClusterContainer::IDC_WriteHandle lock = outputStripClusterContainer->getWriteHandle(hashId);
206 ATH_CHECK(lock.addOrDelete( std::move(collection) ));
207
208 }
209
210 auto offsets = std::make_unique<std::vector<unsigned int>>(m_stripID->wafer_hash_max(), 0);
211 unsigned int counter(0);
212 for (const auto coll : *outputStripClusterContainer) {
213 (*offsets)[coll->identifyHash()] = counter;
214 counter += coll->size();
215 }
216 SG::WriteHandle offSetHandle{m_stripClusterOffSetKey ,ctx};
217 ATH_CHECK(offSetHandle.record(std::move(offsets)));
218
219 return StatusCode::SUCCESS;
220 }
221
222 StatusCode XAODToInDetClusterConversion::convertHgtdClusters(const EventContext& ctx) const {
223 const InDetDD::HGTD_DetectorElementCollection *hgtdElements{};
224 ATH_CHECK(SG::get(hgtdElements,m_HGTDDetEleCollKey, ctx));
225
226 const xAOD::HGTDClusterContainer *inputHgtdClusters{};
227 ATH_CHECK(SG::get(inputHgtdClusters, m_inputHgtdClusterContainerKey, ctx));
228
231
232 SG::WriteHandle outputHgtdClusterContainer{m_outputHgtdClusterContainerKey, ctx};
233 ATH_CHECK( outputHgtdClusterContainer.record (std::make_unique<::HGTD_ClusterContainer>(m_hgtdID->wafer_hash_max(), EventContainers::Mode::OfflineFast)) );
234 ATH_MSG_DEBUG( "Container '" << m_outputHgtdClusterContainerKey.key() << "' initialised" );
235
237 hgtdAccessor ( *inputHgtdClusters,
238 [] (const xAOD::HGTDCluster& cl) -> IdentifierHash { return cl.identifierHash(); },
239 hgtdElements->size());
240
241 const auto& allIdHashes = hgtdAccessor.allIdentifiers();
242 for (const auto& hashId : allIdHashes) {
243 const auto *element = InDetDD::HGTDDetEl::getDetectorElement(hashId,*hgtdElements);
244 if ( element == nullptr ) {
245 ATH_MSG_FATAL( "Invalid hgtd detector element for hash " << hashId);
246 return StatusCode::FAILURE;
247 }
248
249 std::unique_ptr<::HGTD_ClusterCollection> collection = std::make_unique<::HGTD_ClusterCollection>(hashId);
250
251 // Get the detector element and range for the idHash
252 for (const auto& this_range : hgtdAccessor.rangesForIdentifierDirect(hashId)) {
253 for (auto start = this_range.first; start != this_range.second; ++start) {
254 const xAOD::HGTDCluster* in_cluster = *start;
255
256 ::HGTD_Cluster* cluster = nullptr;
257 //cluster is overwritten, but it is saved in 'collection' and later moved
258 //coverity[RESOURCE_LEAK]
259 ATH_CHECK( TrackingUtilities::convertXaodToInDetCluster(*in_cluster, *element, cluster) );
260 cluster->setHashAndIndex(hashId, collection->size());
261
262 // Add to Collection
263 collection->push_back(cluster);
264 dec_link(*in_cluster) = Link_t{cluster, *collection};
265 }
266 }
267
268 ::HGTD_ClusterContainer::IDC_WriteHandle lock = outputHgtdClusterContainer->getWriteHandle(hashId);
269 ATH_CHECK(lock.addOrDelete( std::move(collection) ));
270
271 } // loop on hashIds
272
273 ATH_CHECK( outputHgtdClusterContainer.setConst() );
274
275 return StatusCode::SUCCESS;
276 }
277
278
279}
280
281
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
ElementLink< xAOD::TruthParticleContainer > Link_t
This is an Identifier helper class for the Pixel subdetector.
This is an Identifier helper class for the SCT subdetector.
Handle class for adding a decoration to an object.
const ServiceHandle< StoreGateSvc > & detStore() const
Class implementing how to access a container.
const boost::container::small_vector< Range, inline_size > rangesForIdentifierDirect(const identifier_t &identifier) const
Function to return the list of ranges corresponding to a given identifier.
std::vector< identifier_t > allIdentifiers() const
Function to return all available identifier (i.e. keys in the map).
size_type size() const noexcept
Returns the number of elements in the collection.
This is a "hash" representation of an Identifier.
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.
ToolHandle< ISiLorentzAngleTool > m_lorentzAngleTool
SG::ReadHandleKey< xAOD::HGTDClusterContainer > m_inputHgtdClusterContainerKey
SG::WriteHandleKey< std::vector< unsigned int > > m_stripClusterOffSetKey
SG::WriteHandleKey< InDet::SCT_ClusterContainer > m_outputStripClusterContainerKey
StatusCode convertHgtdClusters(const EventContext &ctx) const
SG::WriteHandleKey< std::vector< unsigned int > > m_pixelClusterOffSetKey
SG::ReadHandleKey< xAOD::PixelClusterContainer > m_inputPixelClusterContainerKey
SG::WriteHandleKey< InDet::SiClusterContainer > m_stripClusterContainerLinkKey
SG::WriteDecorHandleKey< xAOD::StripClusterContainer > m_stripClusterLinkKey
StatusCode convertPixelClusters(const EventContext &ctx) const
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
SG::WriteDecorHandleKey< xAOD::HGTDClusterContainer > m_hgdtClusterLinkKey
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadCondHandleKey< InDetDD::HGTD_DetectorElementCollection > m_HGTDDetEleCollKey
SG::WriteHandleKey< InDet::SiClusterContainer > m_pixelClusterContainerLinkKey
SG::WriteHandleKey<::HGTD_ClusterContainer > m_outputHgtdClusterContainerKey
StatusCode convertStripClusters(const EventContext &ctx) const
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_stripDetEleCollKey
SG::ReadHandleKey< xAOD::StripClusterContainer > m_inputStripClusterContainerKey
SG::WriteDecorHandleKey< xAOD::PixelClusterContainer > m_pixelClusterLinkKey
SG::WriteHandleKey< InDet::PixelClusterContainer > m_outputPixelClusterContainerKey
StatusCode setConst()
Set the 'const' bit for the bound proxy in the store.
Handle class for adding a decoration to an object.
StatusCode symLink(const WriteHandleKey< U > &key)
Make an explicit link.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
void setHashAndIndex(unsigned short collHash, unsigned short objIndex)
TEMP for testing: might make some classes friends later ...
const HGTD_DetectorElement * getDetectorElement(const IdentifierHash &hash, const HGTD_DetectorElementCollection &coll)
DataVector< HGTD_DetectorElement > HGTD_DetectorElementCollection
Primary Vertex Finder.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
StatusCode convertXaodToInDetCluster(const xAOD::PixelCluster &xaodCluster, const InDetDD::SiDetectorElement &element, const PixelID &pixelID, InDet::PixelCluster *&indetCluster)
PixelClusterContainer_v1 PixelClusterContainer
Define the version of the pixel cluster container.
HGTDClusterContainer_v1 HGTDClusterContainer
Define the version of the HGTD 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.
HGTDCluster_v1 HGTDCluster
Define the version of the pixel cluster class.
Definition HGTDCluster.h:13