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
12
16
17#include <map>
18#include <cmath>
19
20namespace InDet {
21
22
24 ATH_MSG_INFO( "Initializing " << name() << " ... " );
25
26 // Pixel Clusters
28 if (m_processPixel) {
29 ATH_CHECK( detStore()->retrieve(m_pixelID,"PixelID") );
30 }
36
37 // Strip Clusters
39 if (m_processStrip) {
40 ATH_CHECK( detStore()->retrieve(m_stripID, "SCT_ID") );
41 }
47
48 ATH_CHECK( m_lorentzAngleTool.retrieve(EnableTool{not m_lorentzAngleTool.empty()}) );
49
50 // Hgtd Clusters
52 if (m_processHgtd) {
53 ATH_CHECK( detStore()->retrieve(m_hgtdID, "HGTD_ID") );
54 }
58
59 return StatusCode::SUCCESS;
60 }
61
62 StatusCode XAODToInDetClusterConversion::execute(const EventContext& ctx) const
63 {
64 ATH_MSG_DEBUG( "Executing " << name() << " ... ");
65 if (m_processPixel) {
66 ATH_MSG_DEBUG("Converting Pixel Clusters: xAOD -> InDet");
68 }
69
70 if (m_processStrip) {
71 ATH_MSG_DEBUG("Converting Strip Clusters: xAOD -> InDet");
73 }
74
75 if (m_processHgtd) {
76 ATH_MSG_DEBUG("Converting HGTD Clusters: xAOD -> InDet");
78 }
79
80 return StatusCode::SUCCESS;
81 }
82
83 StatusCode XAODToInDetClusterConversion::convertPixelClusters(const EventContext& ctx) const {
84 const InDetDD::SiDetectorElementCollection* pixElements{};
85 ATH_CHECK(SG::get(pixElements, m_pixelDetEleCollKey, ctx));
86
87 const xAOD::PixelClusterContainer *inputPixelClusters{};
88 ATH_CHECK(SG::get(inputPixelClusters, m_inputPixelClusterContainerKey, ctx));
89
92 SG::WriteHandle outputPixelClusterContainer{m_outputPixelClusterContainerKey, ctx};
93 ATH_CHECK( outputPixelClusterContainer.record (std::make_unique<InDet::PixelClusterContainer>(m_pixelID->wafer_hash_max(), EventContainers::Mode::OfflineFast)) );
94 ATH_MSG_DEBUG( "Container '" << m_outputPixelClusterContainerKey.key() << "' initialised" );
95
96 ATH_CHECK( outputPixelClusterContainer.symLink( m_pixelClusterContainerLinkKey ) );
97
98
99 // Conversion
100 // Access to the cluster from a given detector element is possible
101 // via the ContainerAccessor.
103 pixelAccessor ( *inputPixelClusters,
104 [] (const xAOD::PixelCluster& cl) -> IdentifierHash { return cl.identifierHash(); },
105 pixElements->size());
106
107 const auto& allIdHashes = pixelAccessor.allIdentifiers();
108 for (const auto& hashId : allIdHashes) {
109 const InDetDD::SiDetectorElement *element = pixElements->getDetectorElement(hashId);
110 if ( element == nullptr ) {
111 ATH_MSG_FATAL( "Invalid pixel detector element for hash " << hashId);
112 return StatusCode::FAILURE;
113 }
114
115 // The readout design is a property of the detector element, so resolve it once
116 // here rather than for every cluster on the element.
118 if ( design == nullptr ) {
119 ATH_MSG_FATAL( "Invalid pixel module design for hash " << hashId);
120 return StatusCode::FAILURE;
121 }
122
123 std::unique_ptr<InDet::PixelClusterCollection> collection = std::make_unique<InDet::PixelClusterCollection>(hashId);
124
125 // Get the detector element and range for the idHash
126 for (const auto& this_range : pixelAccessor.rangesForIdentifierDirect(hashId)) {
127 for (auto start = this_range.first; start != this_range.second; ++start) {
128 const xAOD::PixelCluster* in_cluster = *start;
129 auto cluster = TrackingUtilities::convertXaodToInDetCluster(*in_cluster, *element, *design, *m_pixelID);
130 if (!cluster) continue;
131 cluster->setHashAndIndex(hashId, collection->size());
132
133 // Add to Collection
134 collection->push_back(cluster.get());
135 dec_link(*in_cluster) = Link_t{cluster.release(), *collection};
136 }
137 }
138
139 InDet::PixelClusterContainer::IDC_WriteHandle lock = outputPixelClusterContainer->getWriteHandle(hashId);
140 ATH_CHECK(lock.addOrDelete( std::move(collection) ));
141
142 } // loop on hashIds
143
144 auto offsets = std::make_unique<std::vector<unsigned int>>(m_pixelID->wafer_hash_max(), 0);
145 unsigned int counter(0);
146 for (const auto coll : *outputPixelClusterContainer) {
147 (*offsets)[coll->identifyHash()] = counter;
148 counter += coll->size();
149 }
150 SG::WriteHandle offSetHandle{m_pixelClusterOffSetKey ,ctx};
151 ATH_CHECK(offSetHandle.record(std::move(offsets)));
152
153 return StatusCode::SUCCESS;
154 }
155
156 StatusCode XAODToInDetClusterConversion::convertStripClusters(const EventContext& ctx) const {
157 const InDetDD::SiDetectorElementCollection* stripElements{};
158 ATH_CHECK(SG::get(stripElements, m_stripDetEleCollKey, ctx));
159 const xAOD::StripClusterContainer *inputStripClusters{};
160 ATH_CHECK(SG::get(inputStripClusters, m_inputStripClusterContainerKey, ctx));
161
164
165 SG::WriteHandle outputStripClusterContainer{m_outputStripClusterContainerKey, ctx};
166 ATH_CHECK( outputStripClusterContainer.record (std::make_unique<InDet::SCT_ClusterContainer>(m_stripID->wafer_hash_max(), EventContainers::Mode::OfflineFast)) );
167 ATH_MSG_DEBUG( "Container '" << m_outputStripClusterContainerKey.key() << "' initialised" );
168
169 ATH_CHECK( outputStripClusterContainer.symLink( m_stripClusterContainerLinkKey ) );
170
171 // Conversion
172 // Access to the cluster from a given detector element is possible
173 // via the ContainerAccessor.
175 stripAccessor ( *inputStripClusters,
176 [] (const xAOD::StripCluster& cl) -> IdentifierHash { return cl.identifierHash(); },
177 stripElements->size());
178
179
180
181 const auto& allIdHashes = stripAccessor.allIdentifiers();
182 for (const auto& hashId : allIdHashes) {
183 const InDetDD::SiDetectorElement *element = stripElements->getDetectorElement(hashId);
184 if ( element == nullptr ) {
185 ATH_MSG_FATAL( "Invalid strip detector element for hash " << hashId);
186 return StatusCode::FAILURE;
187 }
188
189 bool isBarrel = element->isBarrel();
190 double shift = not isBarrel ? m_lorentzAngleTool->getLorentzShift(hashId, ctx) : 0.;
191
192 // The readout design is a property of the detector element, so resolve it once
193 // here rather than for every cluster on the element.
195 if ( design == nullptr ) {
196 ATH_MSG_FATAL( "Invalid strip module design for hash " << hashId);
197 return StatusCode::FAILURE;
198 }
199
200 std::unique_ptr<InDet::SCT_ClusterCollection> collection = std::make_unique<InDet::SCT_ClusterCollection>(hashId);
201
202
203 // Get the detector element and range for the idHash
204 for (const auto& this_range : stripAccessor.rangesForIdentifierDirect(hashId)) {
205 for (auto start = this_range.first; start != this_range.second; ++start) {
206 const xAOD::StripCluster* in_cluster = *start;
207
208 auto cluster = TrackingUtilities::convertXaodToInDetCluster(*in_cluster, *element, *design, *m_stripID, shift);
209 if (!cluster) continue;
210 cluster->setHashAndIndex(hashId, collection->size());
211
212
213 // Add to Collection
214 collection->push_back( cluster.get() );
215 dec_link(*in_cluster) = Link_t{cluster.release(), *collection};
216 }
217 }
218
219 InDet::SCT_ClusterContainer::IDC_WriteHandle lock = outputStripClusterContainer->getWriteHandle(hashId);
220 ATH_CHECK(lock.addOrDelete( std::move(collection) ));
221
222 }
223
224 auto offsets = std::make_unique<std::vector<unsigned int>>(m_stripID->wafer_hash_max(), 0);
225 unsigned int counter(0);
226 for (const auto coll : *outputStripClusterContainer) {
227 (*offsets)[coll->identifyHash()] = counter;
228 counter += coll->size();
229 }
230 SG::WriteHandle offSetHandle{m_stripClusterOffSetKey ,ctx};
231 ATH_CHECK(offSetHandle.record(std::move(offsets)));
232
233 return StatusCode::SUCCESS;
234 }
235
236 StatusCode XAODToInDetClusterConversion::convertHgtdClusters(const EventContext& ctx) const {
237 const InDetDD::HGTD_DetectorElementCollection *hgtdElements{};
238 ATH_CHECK(SG::get(hgtdElements,m_HGTDDetEleCollKey, ctx));
239
240 const xAOD::HGTDClusterContainer *inputHgtdClusters{};
241 ATH_CHECK(SG::get(inputHgtdClusters, m_inputHgtdClusterContainerKey, ctx));
242
245
246 SG::WriteHandle outputHgtdClusterContainer{m_outputHgtdClusterContainerKey, ctx};
247 ATH_CHECK( outputHgtdClusterContainer.record (std::make_unique<::HGTD_ClusterContainer>(m_hgtdID->wafer_hash_max(), EventContainers::Mode::OfflineFast)) );
248 ATH_MSG_DEBUG( "Container '" << m_outputHgtdClusterContainerKey.key() << "' initialised" );
249
251 hgtdAccessor ( *inputHgtdClusters,
252 [] (const xAOD::HGTDCluster& cl) -> IdentifierHash { return cl.identifierHash(); },
253 hgtdElements->size());
254
255 const auto& allIdHashes = hgtdAccessor.allIdentifiers();
256 for (const auto& hashId : allIdHashes) {
257 const auto *element = InDetDD::HGTDDetEl::getDetectorElement(hashId,*hgtdElements);
258 if ( element == nullptr ) {
259 ATH_MSG_FATAL( "Invalid hgtd detector element for hash " << hashId);
260 return StatusCode::FAILURE;
261 }
262
263 std::unique_ptr<::HGTD_ClusterCollection> collection = std::make_unique<::HGTD_ClusterCollection>(hashId);
264
265 // Get the detector element and range for the idHash
266 for (const auto& this_range : hgtdAccessor.rangesForIdentifierDirect(hashId)) {
267 for (auto start = this_range.first; start != this_range.second; ++start) {
268 const xAOD::HGTDCluster* in_cluster = *start;
269
270 auto cluster = TrackingUtilities::convertXaodToInDetCluster(*in_cluster, *element);
271 cluster->setHashAndIndex(hashId, collection->size());
272
273 // Add to Collection
274 collection->push_back(cluster.get());
275 dec_link(*in_cluster) = Link_t{cluster.release(), *collection};
276 }
277 }
278
279 ::HGTD_ClusterContainer::IDC_WriteHandle lock = outputHgtdClusterContainer->getWriteHandle(hashId);
280 ATH_CHECK(lock.addOrDelete( std::move(collection) ));
281
282 } // loop on hashIds
283
284 ATH_CHECK( outputHgtdClusterContainer.setConst() );
285
286 return StatusCode::SUCCESS;
287 }
288
289
290}
291
292
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(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 used to describe the design of a module (diode segmentation and readout scheme).
Base class for the SCT module side design, extended by the Forward and Barrel module design.
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.
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.
const InDetDD::PixelModuleDesign * pixelModuleDesign(const InDetDD::SiDetectorElement &element)
Resolve the readout design of a pixel/strip detector element.
const InDetDD::SCT_ModuleSideDesign * stripModuleSideDesign(const InDetDD::SiDetectorElement &element)
std::unique_ptr< InDet::PixelCluster > convertXaodToInDetCluster(const xAOD::PixelCluster &xaodCluster, const InDetDD::SiDetectorElement &element, const InDetDD::PixelModuleDesign &design, const PixelID &pixelID)
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