ATLAS Offline Software
XAODToInDetClusterConversion.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
11 
14 
15 #include <map>
16 #include <cmath>
17 
18 namespace InDet {
19 
21  ISvcLocator *pSvcLocator)
22  : AthReentrantAlgorithm(name, pSvcLocator)
23  {}
24 
26  {
27  ATH_MSG_INFO( "Initializing " << name() << " ... " );
28 
29  // Pixel Clusters
31  ATH_CHECK( detStore()->retrieve(m_pixelID,"PixelID") );
32 
36 
37  // Strip Clusters
39  ATH_CHECK( detStore()->retrieve(m_stripID, "SCT_ID") );
40 
44 
45  ATH_CHECK( m_lorentzAngleTool.retrieve() );
46 
47  // Hgtd Clusters
49  ATH_CHECK( detStore()->retrieve(m_hgtdID, "HGTD_ID") );
50 
53 
54  return StatusCode::SUCCESS;
55  }
56 
57  StatusCode XAODToInDetClusterConversion::execute(const EventContext& ctx) const
58  {
59  ATH_MSG_DEBUG( "Executing " << name() << " ... " );
60 
61  if (m_processPixel.value()) {
62  ATH_MSG_DEBUG("Converting Pixel Clusters: xAOD -> InDet");
64  }
65 
66  if (m_processStrip.value()) {
67  ATH_MSG_DEBUG("Converting Strip Clusters: xAOD -> InDet");
69  }
70 
71  if (m_processHgtd.value()) {
72  ATH_MSG_DEBUG("Converting HGTD Clusters: xAOD -> InDet");
74  }
75 
76  return StatusCode::SUCCESS;
77  }
78 
80  {
82  const InDetDD::SiDetectorElementCollection* pixElements( *pixelDetEleHandle );
83  if (not pixelDetEleHandle.isValid() or pixElements==nullptr) {
84  ATH_MSG_FATAL(m_pixelDetEleCollKey.fullKey() << " is not available.");
85  return StatusCode::FAILURE;
86  }
87 
89  ATH_CHECK( inputPixelClusterContainer.isValid() );
90  const xAOD::PixelClusterContainer *inputPixelClusters = inputPixelClusterContainer.cptr();
91 
93  ATH_CHECK( outputPixelClusterContainer.record (std::make_unique<InDet::PixelClusterContainer>(m_pixelID->wafer_hash_max(), EventContainers::Mode::OfflineFast)) );
94  ATH_CHECK( outputPixelClusterContainer.isValid() );
95  ATH_MSG_DEBUG( "Container '" << m_outputPixelClusterContainerKey.key() << "' initialised" );
96 
97  ATH_CHECK( outputPixelClusterContainer.symLink( m_pixelClusterContainerLinkKey ) );
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  std::unique_ptr<InDet::PixelClusterCollection> collection = std::make_unique<InDet::PixelClusterCollection>(hashId);
116 
117  // Get the detector element and range for the idHash
118  for (const auto& this_range : pixelAccessor.rangesForIdentifierDirect(hashId)) {
119  for (auto start = this_range.first; start != this_range.second; ++start) {
120  const xAOD::PixelCluster* in_cluster = *start;
121 
122  InDet::PixelCluster* cluster = nullptr;
123  ATH_CHECK( TrackingUtilities::convertXaodToInDetCluster(*in_cluster, *element, *m_pixelID, cluster) );
124  cluster->setHashAndIndex(hashId, collection->size());
125 
126  // Add to Collection
127  collection->push_back(cluster);
128  }
129  }
130 
131  InDet::PixelClusterContainer::IDC_WriteHandle lock = outputPixelClusterContainer->getWriteHandle(hashId);
132  ATH_CHECK(lock.addOrDelete( std::move(collection) ));
133 
134  } // loop on hashIds
135 
136  ATH_CHECK( outputPixelClusterContainer.setConst() );
137 
138  return StatusCode::SUCCESS;
139  }
140 
142  {
144  const InDetDD::SiDetectorElementCollection* stripElements( *stripDetEleHandle );
145  if (not stripDetEleHandle.isValid() or stripElements==nullptr) {
146  ATH_MSG_FATAL(m_stripDetEleCollKey.fullKey() << " is not available.");
147  return StatusCode::FAILURE;
148  }
149 
151  ATH_CHECK( inputStripClusterContainer.isValid() );
152  const xAOD::StripClusterContainer *inputStripClusters = inputStripClusterContainer.cptr();
153 
155  ATH_CHECK( outputStripClusterContainer.record (std::make_unique<InDet::SCT_ClusterContainer>(m_stripID->wafer_hash_max(), EventContainers::Mode::OfflineFast)) );
156  ATH_CHECK( outputStripClusterContainer.isValid() );
157  ATH_MSG_DEBUG( "Container '" << m_outputStripClusterContainerKey.key() << "' initialised" );
158 
159  ATH_CHECK( outputStripClusterContainer.symLink( m_stripClusterContainerLinkKey ) );
160 
161  // Conversion
162  // Access to the cluster from a given detector element is possible
163  // via the ContainerAccessor.
165  stripAccessor ( *inputStripClusters,
166  [] (const xAOD::StripCluster& cl) -> IdentifierHash { return cl.identifierHash(); },
167  stripElements->size());
168 
169 
170 
171  const auto& allIdHashes = stripAccessor.allIdentifiers();
172  for (const auto& hashId : allIdHashes) {
173  const InDetDD::SiDetectorElement *element = stripElements->getDetectorElement(hashId);
174  if ( element == nullptr ) {
175  ATH_MSG_FATAL( "Invalid strip detector element for hash " << hashId);
176  return StatusCode::FAILURE;
177  }
178 
179  bool isBarrel = element->isBarrel();
180 
181  double shift = not isBarrel
182  ? m_lorentzAngleTool->getLorentzShift(hashId, ctx)
183  : 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  cluster->setHashAndIndex(hashId, collection->size());
196 
197  // Add to Collection
198  collection->push_back( cluster );
199  }
200  }
201 
202  InDet::SCT_ClusterContainer::IDC_WriteHandle lock = outputStripClusterContainer->getWriteHandle(hashId);
203  ATH_CHECK(lock.addOrDelete( std::move(collection) ));
204 
205  }
206 
207  ATH_CHECK( outputStripClusterContainer.setConst() );
208 
209  return StatusCode::SUCCESS;
210  }
211 
213  {
215  const InDetDD::HGTD_DetectorElementCollection *hgtdElements( *hgtdDetEleHandle );
216  if (not hgtdDetEleHandle.isValid() or hgtdElements==nullptr) {
217  ATH_MSG_FATAL(m_HGTDDetEleCollKey.fullKey() << " is not available.");
218  return StatusCode::FAILURE;
219  }
220 
222  ATH_CHECK( inputHgtdClusterContainer.isValid() );
223  const xAOD::HGTDClusterContainer *inputHgtdClusters = inputHgtdClusterContainer.cptr();
224 
226  ATH_CHECK( outputHgtdClusterContainer.record (std::make_unique<::HGTD_ClusterContainer>(m_hgtdID->wafer_hash_max(), EventContainers::Mode::OfflineFast)) );
227  ATH_MSG_DEBUG( "Container '" << m_outputHgtdClusterContainerKey.key() << "' initialised" );
228 
230  hgtdAccessor ( *inputHgtdClusters,
231  [] (const xAOD::HGTDCluster& cl) -> IdentifierHash { return cl.identifierHash(); },
232  hgtdElements->size());
233 
234  const auto& allIdHashes = hgtdAccessor.allIdentifiers();
235  for (const auto& hashId : allIdHashes) {
236  const auto *element = hgtdElements->getDetectorElement(hashId);
237  if ( element == nullptr ) {
238  ATH_MSG_FATAL( "Invalid hgtd detector element for hash " << hashId);
239  return StatusCode::FAILURE;
240  }
241 
242  std::unique_ptr<::HGTD_ClusterCollection> collection = std::make_unique<::HGTD_ClusterCollection>(hashId);
243 
244  // Get the detector element and range for the idHash
245  for (const auto& this_range : hgtdAccessor.rangesForIdentifierDirect(hashId)) {
246  for (auto start = this_range.first; start != this_range.second; ++start) {
247  const xAOD::HGTDCluster* in_cluster = *start;
248 
249  ::HGTD_Cluster* cluster = nullptr;
250  ATH_CHECK( TrackingUtilities::convertXaodToInDetCluster(*in_cluster, *element, cluster) );
251  cluster->setHashAndIndex(hashId, collection->size());
252 
253  // Add to Collection
254  collection->push_back(cluster);
255  }
256  }
257 
258  ::HGTD_ClusterContainer::IDC_WriteHandle lock = outputHgtdClusterContainer->getWriteHandle(hashId);
259  ATH_CHECK(lock.addOrDelete( std::move(collection) ));
260 
261  } // loop on hashIds
262 
263  ATH_CHECK( outputHgtdClusterContainer.setConst() );
264 
265  return StatusCode::SUCCESS;
266  }
267 
268 
269 }
270 
271 
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...
InDet::XAODToInDetClusterConversion::m_pixelID
const PixelID * m_pixelID
Definition: XAODToInDetClusterConversion.h:67
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::XAODToInDetClusterConversion::convertStripClusters
StatusCode convertStripClusters(const EventContext &ctx) const
Definition: XAODToInDetClusterConversion.cxx:141
ContainerAccessor
Definition: ContainerAccessor.h:25
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ContainerAccessor::allIdentifiers
std::vector< identifier_t > allIdentifiers() const
Function to return all available identifier (i.e. keys in the map)
Definition: ContainerAccessor.h:84
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
IdentifiableContainerMT::getWriteHandle
IDC_WriteHandle getWriteHandle(IdentifierHash hash)
Definition: IdentifiableContainerMT.h:248
InDet::XAODToInDetClusterConversion::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: XAODToInDetClusterConversion.cxx:57
InDet::XAODToInDetClusterConversion::m_inputStripClusterContainerKey
SG::ReadHandleKey< xAOD::StripClusterContainer > m_inputStripClusterContainerKey
Definition: XAODToInDetClusterConversion.h:80
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
InDet::XAODToInDetClusterConversion::m_HGTDDetEleCollKey
SG::ReadCondHandleKey< InDetDD::HGTD_DetectorElementCollection > m_HGTDDetEleCollKey
Definition: XAODToInDetClusterConversion.h:85
InDet
Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
SG::WriteHandle::symLink
StatusCode symLink(const WriteHandleKey< U > &key)
Make an explicit link.
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
TrackingUtilities::convertXaodToInDetCluster
StatusCode convertXaodToInDetCluster(const xAOD::PixelCluster &xaodCluster, const InDetDD::SiDetectorElement &element, const PixelID &pixelID, InDet::PixelCluster *&indetCluster)
Definition: ClusterConversionUtilities.cxx:142
xAOD::HGTDCluster_v1
Definition: HGTDCluster_v1.h:23
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::VarHandleBase::setConst
StatusCode setConst()
Set the 'const' bit for the bound proxy in the store.
Definition: StoreGate/src/VarHandleBase.cxx:606
InDet::XAODToInDetClusterConversion::convertHgtdClusters
StatusCode convertHgtdClusters(const EventContext &ctx) const
Definition: XAODToInDetClusterConversion.cxx:212
InDet::XAODToInDetClusterConversion::m_stripID
const SCT_ID * m_stripID
Definition: XAODToInDetClusterConversion.h:68
InDet::XAODToInDetClusterConversion::m_pixelClusterContainerLinkKey
SG::WriteHandleKey< InDet::SiClusterContainer > m_pixelClusterContainerLinkKey
Definition: XAODToInDetClusterConversion.h:77
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:83
HGTD_Cluster
Definition: HGTD_Cluster.h:35
InDet::XAODToInDetClusterConversion::XAODToInDetClusterConversion
XAODToInDetClusterConversion()=delete
InDet::XAODToInDetClusterConversion::m_stripDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_stripDetEleCollKey
Definition: XAODToInDetClusterConversion.h:79
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
InDet::XAODToInDetClusterConversion::m_processStrip
Gaudi::Property< bool > m_processStrip
Definition: XAODToInDetClusterConversion.h:91
ContainerAccessor::rangesForIdentifierDirect
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.
Definition: ContainerAccessor.h:69
InDet::XAODToInDetClusterConversion::m_inputPixelClusterContainerKey
SG::ReadHandleKey< xAOD::PixelClusterContainer > m_inputPixelClusterContainerKey
Definition: XAODToInDetClusterConversion.h:74
Trk::PrepRawData::setHashAndIndex
void setHashAndIndex(unsigned short collHash, unsigned short objIndex)
TEMP for testing: might make some classes friends later ...
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::XAODToInDetClusterConversion::m_lorentzAngleTool
ToolHandle< ISiLorentzAngleTool > m_lorentzAngleTool
Definition: XAODToInDetClusterConversion.h:71
IdentifiableContainerMT::IDC_WriteHandle
Definition: IdentifiableContainerMT.h:34
InDet::XAODToInDetClusterConversion::convertPixelClusters
StatusCode convertPixelClusters(const EventContext &ctx) const
Definition: XAODToInDetClusterConversion.cxx:79
xAOD::StripCluster_v1
Definition: StripCluster_v1.h:17
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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::SCT_Cluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/SCT_Cluster.h:34
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
ClusterConversionUtilities.h
InDet::XAODToInDetClusterConversion::m_pixelDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
Definition: XAODToInDetClusterConversion.h:73
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
HGTD_ID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: HGTD_ID.cxx:832
XAODToInDetClusterConversion.h
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SCT_ID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: SCT_ID.cxx:645
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)
PixelID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: PixelID.cxx:831
EventContainers::Mode::OfflineFast
@ OfflineFast
InDetDD::SiDetectorElement::isBarrel
bool isBarrel() const
InDet::XAODToInDetClusterConversion::initialize
virtual StatusCode initialize() override
Definition: XAODToInDetClusterConversion.cxx:25
InDet::XAODToInDetClusterConversion::m_processHgtd
Gaudi::Property< bool > m_processHgtd
Definition: XAODToInDetClusterConversion.h:92
InDet::XAODToInDetClusterConversion::m_outputStripClusterContainerKey
SG::WriteHandleKey< InDet::SCT_ClusterContainer > m_outputStripClusterContainerKey
Definition: XAODToInDetClusterConversion.h:82
IdentifiableContainerMT::IDC_WriteHandle::addOrDelete
StatusCode addOrDelete(std::unique_ptr< T > ptr)
Definition: IdentifiableContainerMT.h:53
InDet::XAODToInDetClusterConversion::m_processPixel
Gaudi::Property< bool > m_processPixel
Definition: XAODToInDetClusterConversion.h:90
InDet::PixelCluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/PixelCluster.h:49
StripStereoAnnulusDesign.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
InDet::XAODToInDetClusterConversion::m_hgtdID
const HGTD_ID * m_hgtdID
Definition: XAODToInDetClusterConversion.h:69
ContainerAccessor.h
xAOD::PixelCluster_v1
Definition: PixelCluster_v1.h:17
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
InDet::XAODToInDetClusterConversion::m_inputHgtdClusterContainerKey
SG::ReadHandleKey< xAOD::HGTDClusterContainer > m_inputHgtdClusterContainerKey
Definition: XAODToInDetClusterConversion.h:87
PixelModuleDesign.h
python.LArCondContChannels.isBarrel
isBarrel
Definition: LArCondContChannels.py:659
InDet::XAODToInDetClusterConversion::m_stripClusterContainerLinkKey
SG::WriteHandleKey< InDet::SiClusterContainer > m_stripClusterContainerLinkKey
Definition: XAODToInDetClusterConversion.h:83
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
InDetDD::HGTD_DetectorElementCollection
Definition: HGTD_DetectorElementCollection.h:29
InDetDD::HGTD_DetectorElementCollection::getDetectorElement
const HGTD_DetectorElement * getDetectorElement(const IdentifierHash &hash) const
Definition: HGTD_DetectorElementCollection.cxx:11
InDet::XAODToInDetClusterConversion::m_outputPixelClusterContainerKey
SG::WriteHandleKey< InDet::PixelClusterContainer > m_outputPixelClusterContainerKey
Definition: XAODToInDetClusterConversion.h:76
InDet::XAODToInDetClusterConversion::m_outputHgtdClusterContainerKey
SG::WriteHandleKey<::HGTD_ClusterContainer > m_outputHgtdClusterContainerKey
Definition: XAODToInDetClusterConversion.h:88
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
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:15