ATLAS Offline Software
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"
10 #include "InDetIdentifier/SCT_ID.h"
14 
15 #include "StoreGate/WriteHandle.h"
16 #include "StoreGate/ReadHandle.h"
17 
20 
23 
25 #include "AthAllocators/DataPool.h"
26 #include <iterator>
27 
28 
29 
30 using namespace InDet;
31 
32 // Constructor with parameters:
33 InDetToXAODClusterConversion::InDetToXAODClusterConversion(const std::string &name, ISvcLocator *pSvcLocator) :
34 AthReentrantAlgorithm(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 //
66 StatusCode 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 
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 
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 
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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
TrackingUtilities::convertInDetToXaodCluster
StatusCode convertInDetToXaodCluster(const InDet::PixelCluster &indetCluster, const InDetDD::SiDetectorElement &element, xAOD::PixelCluster &xaodCluster)
Definition: ClusterConversionUtilities.cxx:74
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
InDet::InDetToXAODClusterConversion::m_hgtdID
const HGTD_ID * m_hgtdID
Definition: InDetToXAODClusterConversion.h:70
InDet::InDetToXAODClusterConversion::m_inputPixelClusterContainerKey
SG::ReadHandleKey< InDet::PixelClusterContainer > m_inputPixelClusterContainerKey
Definition: InDetToXAODClusterConversion.h:76
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:27
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
HGTD_ID::wafer_hash
IdentifierHash wafer_hash(Identifier wafer_id) const
wafer hash from id
Definition: HGTD_ID.h:404
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
InDet::InDetToXAODClusterConversion::convertHgtdClusters
StatusCode convertHgtdClusters(const EventContext &ctx) const
Definition: InDetToXAODClusterConversion.cxx:196
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
InDet
Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
xAOD::HGTDCluster
HGTDCluster_v1 HGTDCluster
Define the version of the pixel cluster class.
Definition: HGTDCluster.h:13
pool
pool namespace
Definition: libname.h:15
InDet::InDetToXAODClusterConversion::m_outputHgtdClusterContainerKey
SG::WriteHandleKey< xAOD::HGTDClusterContainer > m_outputHgtdClusterContainerKey
Definition: InDetToXAODClusterConversion.h:83
SG::ALWAYS_TRACK_INDICES
@ ALWAYS_TRACK_INDICES
Always track indices, regardless of the setting of the ownership policy.
Definition: IndexTrackingPolicy.h:43
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:210
xAOD::HGTDCluster_v1
Definition: HGTDCluster_v1.h:23
InDet::InDetToXAODClusterConversion::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: InDetToXAODClusterConversion.cxx:66
InDet::InDetToXAODClusterConversion::m_outputPixelClusterContainerKey
SG::WriteHandleKey< xAOD::PixelClusterContainer > m_outputPixelClusterContainerKey
Definition: InDetToXAODClusterConversion.h:79
InDet::InDetToXAODClusterConversion::convertStripClusters
StatusCode convertStripClusters(const EventContext &ctx) const
Definition: InDetToXAODClusterConversion.cxx:141
InDet::InDetToXAODClusterConversion::convertPixelClusters
StatusCode convertPixelClusters(const EventContext &ctx) const
Definition: InDetToXAODClusterConversion.cxx:87
PixelID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
For a single crystal.
Definition: PixelID.h:360
DataVector::push_new
size_type push_new(size_type n, F alloc)
Create and add a number of new elements to the end of the container.
HGTD_ID::wafer_id
Identifier wafer_id(int endcap, int layer, int phi_module, int eta_module) const
For a single crystal.
Definition: HGTD_ID.h:287
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
InDet::InDetToXAODClusterConversion::m_pixelDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
Definition: InDetToXAODClusterConversion.h:72
WriteHandle.h
Handle class for recording to StoreGate.
SCT_ClusterCollection.h
PixelID::wafer_hash
IdentifierHash wafer_hash(Identifier wafer_id) const
wafer hash from id
Definition: PixelID.h:383
InDet::InDetToXAODClusterConversion::m_processStrip
Gaudi::Property< bool > m_processStrip
Definition: InDetToXAODClusterConversion.h:86
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
PixelClusterAuxContainer.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
InDet::InDetToXAODClusterConversion::InDetToXAODClusterConversion
InDetToXAODClusterConversion()=delete
xAOD::StripCluster_v1
Definition: StripCluster_v1.h:17
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SCT_ID::wafer_hash
IdentifierHash wafer_hash(const Identifier &wafer_id) const
wafer hash from id - optimized
Definition: SCT_ID.h:492
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
InDet::InDetToXAODClusterConversion::m_stripID
const SCT_ID * m_stripID
Definition: InDetToXAODClusterConversion.h:69
PixelClusterCollection.h
DataVector< HGTD_DetectorElement >
ClusterConversionUtilities.h
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
DataPool.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
InDet::InDetToXAODClusterConversion::m_inputHgtdClusterContainerKey
SG::ReadHandleKey<::HGTD_ClusterContainer > m_inputHgtdClusterContainerKey
Definition: InDetToXAODClusterConversion.h:82
HGTD_ID.h
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
InDet::InDetToXAODClusterConversion::m_pixelID
const PixelID * m_pixelID
Definition: InDetToXAODClusterConversion.h:68
SiDetectorElement.h
InDet::InDetToXAODClusterConversion::m_stripDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_stripDetEleCollKey
Definition: InDetToXAODClusterConversion.h:73
StripClusterAuxContainer.h
StripStereoAnnulusDesign.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
xAOD::PixelCluster_v1
Definition: PixelCluster_v1.h:17
InDet::InDetToXAODClusterConversion::m_HGTDDetEleCollKey
SG::ReadCondHandleKey< InDetDD::HGTD_DetectorElementCollection > m_HGTDDetEleCollKey
Definition: InDetToXAODClusterConversion.h:74
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
DataPool
a typed memory pool that saves time spent allocation small object. This is typically used by containe...
Definition: DataPool.h:63
InDet::InDetToXAODClusterConversion::m_processHgtd
Gaudi::Property< bool > m_processHgtd
Definition: InDetToXAODClusterConversion.h:87
InDet::InDetToXAODClusterConversion::m_inputStripClusterContainerKey
SG::ReadHandleKey< InDet::SCT_ClusterContainer > m_inputStripClusterContainerKey
Definition: InDetToXAODClusterConversion.h:77
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
InDetToXAODClusterConversion.h
ReadHandle.h
Handle class for reading from StoreGate.
SCT_ID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module, int side) const
For a single side of module.
Definition: SCT_ID.h:464
InDet::InDetToXAODClusterConversion::initialize
virtual StatusCode initialize() override
Definition: InDetToXAODClusterConversion.cxx:40
InDetDD::HGTDDetEl::getDetectorElement
const HGTD_DetectorElement * getDetectorElement(const IdentifierHash &hash, const HGTD_DetectorElementCollection &coll)
Definition: HGTD_DetectorElementCollection.h:25
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
InDetDD::SiDetectorElementCollection::getDetectorElement
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
Definition: SiDetectorElementCollection.cxx:9
InDet::InDetToXAODClusterConversion::m_isITk
Gaudi::Property< bool > m_isITk
Definition: InDetToXAODClusterConversion.h:88
InDet::InDetToXAODClusterConversion::m_outputStripClusterContainerKey
SG::WriteHandleKey< xAOD::StripClusterContainer > m_outputStripClusterContainerKey
Definition: InDetToXAODClusterConversion.h:80
InDet::InDetToXAODClusterConversion::m_processPixel
Gaudi::Property< bool > m_processPixel
Definition: InDetToXAODClusterConversion.h:85
Identifier
Definition: IdentifierFieldParser.cxx:14