ATLAS Offline Software
Loading...
Searching...
No Matches
TrackOverlayRoISiRDOMergerAlg.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3 * */
4
6
17
18#include <algorithm>
19#include <stdexcept>
20#include <vector>
21
22namespace {
23
24// Copies of RDO collections. The collections are views; the RDO objects are owned by
25// per-event DataPools (as in PixelOverlay/SCTOverlay), avoiding one heap allocation per hit.
26struct RDOPools {
27 DataPool<Pixel1RawData>& pixel;
28 DataPool<SCT3_RawData>& sct3;
29 DataPool<SCT1_RawData>& sct1;
30};
31
32std::unique_ptr<PixelRDO_Collection> copyCollection(const PixelRDO_Collection& in, RDOPools& pools) {
33 auto out = std::make_unique<PixelRDO_Collection>(in.identifyHash());
34 out->setIdentifier(in.identify());
35 out->clear(SG::VIEW_ELEMENTS);
36 out->reserve(in.size());
37 for (const PixelRDORawData* rdo : in) {
38 Pixel1RawData* copy = pools.pixel.nextElementPtr();
39 *copy = Pixel1RawData(rdo->identify(), rdo->getWord());
40 out->push_back(copy);
41 }
42 return out;
43}
44
45std::unique_ptr<SCT_RDO_Collection> copyCollection(const SCT_RDO_Collection& in, RDOPools& pools) {
46 auto out = std::make_unique<SCT_RDO_Collection>(in.identifyHash());
47 out->setIdentifier(in.identify());
48 out->clear(SG::VIEW_ELEMENTS);
49 out->reserve(in.size());
50 for (const SCT_RDORawData* rdo : in) {
51 if (const auto* rdo3 = dynamic_cast<const SCT3_RawData*>(rdo)) {
52 SCT3_RawData* copy = pools.sct3.nextElementPtr();
53 *copy = *rdo3;
54 out->push_back(copy);
55 } else if (const auto* rdo1 = dynamic_cast<const SCT1_RawData*>(rdo)) {
56 SCT1_RawData* copy = pools.sct1.nextElementPtr();
57 *copy = *rdo1;
58 out->push_back(copy);
59 } else {
60 throw std::runtime_error("TrackOverlayRoISiRDOMergerAlg: unknown SCT RDO type");
61 }
62 }
63 return out;
64}
65
66// Fill output with the merged collection for hashes in the RoI mask, signal-only otherwise
67template <class CONT>
68StatusCode fillContainer(const CONT& sig, const CONT& merged, const std::vector<bool>& inRoI, CONT& out, RDOPools& pools) {
69 for (const auto& [hash, coll] : sig.GetAllHashPtrPair()) {
70 if (hash < inRoI.size() && inRoI[hash]) continue;
71 if (out.addOrDelete(copyCollection(*coll, pools), hash).isFailure()) return StatusCode::FAILURE;
72 }
73 for (size_t i = 0; i < inRoI.size(); ++i) {
74 if (!inRoI[i]) continue;
75 const IdentifierHash hash(i);
76 if (const auto* coll = merged.indexFindPtr(hash)) {
77 if (out.addOrDelete(copyCollection(*coll, pools), hash).isFailure()) return StatusCode::FAILURE;
78 }
79 }
80 return StatusCode::SUCCESS;
81}
82
83} // namespace
84
85namespace TrackOverlay {
86
88{
89 ATH_CHECK(m_clusterKey.initialize());
90 ATH_CHECK(m_sigPixelKey.initialize());
91 ATH_CHECK(m_fullPixelKey.initialize());
92 ATH_CHECK(m_outPixelKey.initialize());
93 ATH_CHECK(m_sigSCTKey.initialize());
94 ATH_CHECK(m_fullSCTKey.initialize());
95 ATH_CHECK(m_outSCTKey.initialize());
96 ATH_CHECK(m_regSelPixel.retrieve());
97 ATH_CHECK(m_regSelSCT.retrieve());
98 ATH_CHECK(detStore()->retrieve(m_pixelID, "PixelID"));
99 ATH_CHECK(detStore()->retrieve(m_sctID, "SCT_ID"));
100 ATH_MSG_INFO("RoI-limited Si overlay: clusters " << m_clusterKey.key() << " with ET > " << m_minClusterEt
101 << " MeV, RoI half widths deta=" << m_etaHalfWidth << " dphi=" << m_phiHalfWidth
102 << " dz=" << m_zHalfWidth << " mm");
103 return StatusCode::SUCCESS;
104}
105
106StatusCode TrackOverlayRoISiRDOMergerAlg::execute(const EventContext& ctx) const
107{
109 if (!clusters.isValid()) {
110 ATH_MSG_ERROR("Could not retrieve " << m_clusterKey.key());
111 return StatusCode::FAILURE;
112 }
113
114 std::vector<bool> pixelInRoI(m_pixelID->wafer_hash_max(), false);
115 std::vector<bool> sctInRoI(m_sctID->wafer_hash_max(), false);
116 std::vector<IdentifierHash> hashes;
117 unsigned int nRoIs = 0;
118
119 for (const xAOD::CaloCluster* cl : *clusters) {
120 if (cl->et() < m_minClusterEt.value()) continue;
121 const double eta = cl->eta();
122 const double phi = cl->phi();
123 const double dEta = m_etaHalfWidth.value();
124 const double dPhi = m_phiHalfWidth.value();
125 const double dZ = m_zHalfWidth.value();
126 const TrigRoiDescriptor roi(eta, eta - dEta, eta + dEta,
127 phi, P4Helpers::deltaPhi(phi - dPhi, 0.), P4Helpers::deltaPhi(phi + dPhi, 0.),
128 0., -dZ, dZ);
129 ++nRoIs;
130 hashes.clear();
131 m_regSelPixel->lookup(ctx)->HashIDList(roi, hashes);
132 for (IdentifierHash h : hashes) if (h < pixelInRoI.size()) pixelInRoI[h] = true;
133 hashes.clear();
134 m_regSelSCT->lookup(ctx)->HashIDList(roi, hashes);
135 for (IdentifierHash h : hashes) if (h < sctInRoI.size()) sctInRoI[h] = true;
136 }
137
142 if (!sigPixel.isValid() || !fullPixel.isValid() || !sigSCT.isValid() || !fullSCT.isValid()) {
143 ATH_MSG_ERROR("Missing input Pixel/SCT RDO containers");
144 return StatusCode::FAILURE;
145 }
146
147 // The DataPools own the copied RDOs for the lifetime of the event; the containers are views
148 DataPool<Pixel1RawData> pixelPool(ctx);
149 DataPool<SCT3_RawData> sct3Pool(ctx);
150 DataPool<SCT1_RawData> sct1Pool(ctx);
151 pixelPool.prepareToAdd(50000);
152 sct3Pool.prepareToAdd(50000);
153 RDOPools pools{pixelPool, sct3Pool, sct1Pool};
154
156 ATH_CHECK(outPixel.record(std::make_unique<PixelRDO_Container>(m_pixelID->wafer_hash_max())));
157 ATH_CHECK(fillContainer(*sigPixel, *fullPixel, pixelInRoI, *outPixel, pools));
158
160 ATH_CHECK(outSCT.record(std::make_unique<SCT_RDO_Container>(m_sctID->wafer_hash_max())));
161 ATH_CHECK(fillContainer(*sigSCT, *fullSCT, sctInRoI, *outSCT, pools));
162
163 const unsigned long nPix = std::count(pixelInRoI.begin(), pixelInRoI.end(), true);
164 const unsigned long nSCT = std::count(sctInRoI.begin(), sctInRoI.end(), true);
165 ATH_MSG_DEBUG(nRoIs << " RoIs, " << nPix << " Pixel and " << nSCT << " SCT modules with merged RDOs");
166 ++m_nEvents;
167 m_nRoIs += nRoIs;
168 m_nPixelRoIModules += nPix;
169 m_nSCTRoIModules += nSCT;
170 return StatusCode::SUCCESS;
171}
172
174{
175 const double n = std::max<unsigned long>(m_nEvents.load(), 1);
176 ATH_MSG_INFO("Events: " << m_nEvents << ", RoIs/event: " << m_nRoIs.load() / n
177 << ", merged Pixel modules/event: " << m_nPixelRoIModules.load() / n << " of " << m_pixelID->wafer_hash_max()
178 << ", merged SCT modules/event: " << m_nSCTRoIModules.load() / n << " of " << m_sctID->wafer_hash_max());
179 return StatusCode::SUCCESS;
180}
181
182} // namespace TrackOverlay
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
This is an Identifier helper class for the Pixel subdetector.
InDetRawDataCollection< PixelRDORawData > PixelRDO_Collection
This is an Identifier helper class for the SCT subdetector.
InDetRawDataCollection< SCT_RDORawData > SCT_RDO_Collection
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
const ServiceHandle< StoreGateSvc > & detStore() const
Header file for AthHistogramAlgorithm.
a typed memory pool that saves time spent allocation small object.
Definition DataPool.h:63
void prepareToAdd(unsigned int size)
Prepare to add cached elements.
size_type size() const noexcept
This is a "hash" representation of an Identifier.
virtual Identifier identify() const override final
virtual IdentifierHash identifyHash() const override final
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.
SG::ReadHandleKey< SCT_RDO_Container > m_sigSCTKey
SG::ReadHandleKey< PixelRDO_Container > m_sigPixelKey
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteHandleKey< SCT_RDO_Container > m_outSCTKey
SG::WriteHandleKey< PixelRDO_Container > m_outPixelKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clusterKey
SG::ReadHandleKey< SCT_RDO_Container > m_fullSCTKey
SG::ReadHandleKey< PixelRDO_Container > m_fullPixelKey
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
::StatusCode StatusCode
StatusCode definition for legacy code.
std::unique_ptr< HGTD_RDO_Collection > copyCollection(const IdentifierHash &hashId, const HGTD_RDO_Collection *collection)
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Definition P4Helpers.h:34
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
bool copy
Definition calibdata.py:26
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.