ATLAS Offline Software
Loading...
Searching...
No Matches
CaloCalibClusterDecoratorToolDM.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
10
14
15#include <algorithm>
16#include <unordered_map>
17
18namespace {
19
20std::vector<std::pair<int, double> > makeSortedTruthPairs(
21 const std::unordered_map<int, double>& truthMap,
22 unsigned int maxTruthParticles)
23{
24 std::vector<std::pair<int, double> > truthPairs;
25 truthPairs.reserve(truthMap.size());
26 for (const auto& [pid, energy] : truthMap) {
27 truthPairs.emplace_back(pid, energy);
28 }
29
30 std::sort(truthPairs.begin(),
31 truthPairs.end(),
32 [](const auto& a, const auto& b) { return a.second > b.second; });
33 if (truthPairs.size() > maxTruthParticles) {
34 truthPairs.resize(maxTruthParticles);
35 }
36 return truthPairs;
37}
38
39} // namespace
40
42 const std::string& type,
43 const std::string& name,
44 const IInterface* parent)
45 : AthAlgTool(type, name, parent)
46{
47 declareInterface<CaloClusterCollectionProcessor>(this);
48
49 for (int im = 0; im < 3; ++im) {
50 m_i_phi_eta[im].resize(m_n_eta_out);
51 }
52}
53
73
75 const EventContext& ctx,
76 xAOD::CaloClusterContainer* theClusColl) const
77{
79 std::vector<std::pair<int, double> > >
80 caloClusterWriteDecorHandleNLeadingTruthParticlesDM(
82
83 bool foundAllContainers(true);
84 std::vector<const CaloCalibrationHitContainer*> v_cchc;
85 std::vector<const CaloCalibrationHitContainer*> v_dmcchc;
86
90 if (!cchc.isValid()) {
92 ATH_MSG_ERROR("SG does not contain calibration hit container " << key.key());
93 }
94 foundAllContainers = false;
95 }
96 else {
97 v_cchc.push_back(cchc.cptr());
98 }
99 }
100
104 if (!dmcchc.isValid()) {
106 ATH_MSG_ERROR("SG does not contain DM calibration hit container " << key.key());
107 }
108 foundAllContainers = false;
109 }
110 else {
111 v_dmcchc.push_back(dmcchc.cptr());
112 }
113 }
114
115 if (!m_foundAllContainers && foundAllContainers) {
117 }
118
119 if (!foundAllContainers) {
120 return StatusCode::SUCCESS;
121 }
122
123 ClusInfo_t clusInfoVec(theClusColl->size());
124
125 CellInfoSet_t cellInfo;
127
128 unsigned int nHitsTotal = 0;
129 unsigned int nHitsWithoutParticleUID = 0;
131 v_cchc,
132 cellInfo,
133 *m_calo_id,
134 clusInfoVec,
135 nHitsTotal,
136 nHitsWithoutParticleUID,
138 [this]() {
139 ATH_MSG_ERROR("Invalid uniqueID detected - this sample cannot be properly analysed.");
140 });
141
142 bool useParticleID = m_useParticleID;
143 if (m_useParticleID && (nHitsTotal == nHitsWithoutParticleUID)) {
144 ATH_MSG_INFO("Calibration hits do not have ParticleUID, ids of particle-caused hits are always 0. Continuing without ParticleID machinery.");
145 useParticleID = false;
146 }
147
148 std::array<ClusList, 3> clusLists;
149 const std::array<bool, 3> doClusterLists{{
153
154 for (unsigned int ii = 0; ii < 3; ++ii) {
155 if (doClusterLists[ii]) {
156 clusLists[ii].resize((2 * m_n_phi_out + 1) * (2 * m_n_eta_out + 1));
157 }
158 }
159
160 std::array<ClusList*, 3> clusListPtrs{{&clusLists[0], &clusLists[1], &clusLists[2]}};
162 *theClusColl,
163 clusInfoVec,
169 doClusterLists,
170 clusListPtrs);
171
172 const ClusList* pClusList = nullptr;
174 pClusList = &clusLists[0];
175 }
176 else if (m_MatchDmType == kMatchDmMedium) {
177 pClusList = &clusLists[1];
178 }
179 else if (m_MatchDmType == kMatchDmTight) {
180 pClusList = &clusLists[2];
181 }
182
183 std::vector<std::unordered_map<int, double> > engCalibDeadByTruth(theClusColl->size());
184
185 if (pClusList != nullptr) {
187 v_dmcchc,
188 *theClusColl,
189 clusInfoVec,
190 *pClusList,
191 useParticleID,
192 [&engCalibDeadByTruth](int iClus, int uniqueID, int /*nDmArea*/, double energy) {
193 engCalibDeadByTruth[iClus][uniqueID] += energy;
194 });
195 }
196
197 // Match ENG_CALIB_DEAD_TOT semantics: add the in-cluster dead-like samplings
198 // that MomentsMaker2 adds on top of the assigned DMA_ALL dead-material energy.
199 for (std::size_t iClus = 0; iClus < clusInfoVec.size(); ++iClus) {
200 const auto& particleMap = clusInfoVec[iClus].engCalibParticle;
201 for (const auto& [uniqueID, calibEnergy] : particleMap) {
202 const double inClusterDeadEnergy =
203 calibEnergy.engSmp[CaloSampling::PreSamplerB]
204 + calibEnergy.engSmp[CaloSampling::PreSamplerE]
205 + calibEnergy.engSmp[CaloSampling::TileGap3];
206 if (inClusterDeadEnergy != 0.0) {
207 engCalibDeadByTruth[iClus][uniqueID] += inClusterDeadEnergy;
208 }
209 }
210 }
211
212 int clusIdx = -1;
213 for (const xAOD::CaloCluster* thisCaloCluster : *theClusColl) {
214 ++clusIdx;
215 const std::unordered_map<int, double>& truthMap = engCalibDeadByTruth[clusIdx];
216 if (!truthMap.empty()) {
217 caloClusterWriteDecorHandleNLeadingTruthParticlesDM(*thisCaloCluster) =
218 makeSortedTruthPairs(truthMap, m_numTruthParticles);
219 }
220 }
221
222 return StatusCode::SUCCESS;
223}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
static Double_t a
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
SG::ReadHandleKeyArray< CaloCalibrationHitContainer > m_DMCalibrationHitContainerNames
SG::WriteDecorHandleKey< xAOD::CaloClusterContainer > m_caloClusterWriteDecorHandleKeyNLeadingTruthParticlesDM
CaloCalibClusterMomentsMaker2::ClusList ClusList
SG::ReadHandleKeyArray< CaloCalibrationHitContainer > m_CalibrationHitContainerNames
Gaudi::Property< unsigned int > m_numTruthParticles
std::array< std::vector< std::vector< CalibHitIPhiIEtaRange > >, 3 > m_i_phi_eta
CaloCalibClusterMomentsMaker2::CellInfoSet_t CellInfoSet_t
CaloCalibClusterDecoratorToolDM(const std::string &type, const std::string &name, const IInterface *parent)
CaloCalibClusterMomentsMaker2::ClusInfo_t ClusInfo_t
virtual StatusCode execute(const EventContext &ctx, xAOD::CaloClusterContainer *theClusColl) const override
Execute on an entire collection of clusters.
void accumulateDeadMaterialEnergy(const std::vector< const CaloCalibrationHitContainer * > &v_dmcchc, const xAOD::CaloClusterContainer &theClusColl, const ClusInfo_t &clusInfoVec, const ClusList &clusList, bool useParticleID, AddDeadMaterialEnergy &&addDeadMaterialEnergy) const
static void initializeOutOfClusterDistanceTables(int n_phi_out, int n_eta_out, double out_phi_max, double out_eta_max, const double(&rmaxOut)[3], std::array< std::vector< std::vector< CalibHitIPhiIEtaRange > >, 3 > &i_phi_eta)
Precompute eta/phi lookup tables for quick out-of-cluster hit association to clusters.
static void accumulateClusterCalibHits(const std::vector< const CaloCalibrationHitContainer * > &v_cchc, const CellInfoSet_t &cellInfo, const CaloCell_ID &calo_id, ClusInfo_t &clusInfoVec, unsigned int &nHitsTotal, unsigned int &nHitsWithoutParticleUID, bool useParticleID, InvalidUniqueIdHandler &&invalidUniqueIdHandler)
Accumulate calibration-hit energy inside clusters.
static void buildOutOfClusterClusterLists(const xAOD::CaloClusterContainer &theClusColl, const ClusInfo_t &clusInfoVec, int n_phi_out, int n_eta_out, double out_phi_max, double out_eta_max, const std::array< std::vector< std::vector< CalibHitIPhiIEtaRange > >, 3 > &i_phi_eta, const std::array< bool, 3 > &doOutOfCluster, const std::array< ClusList *, 3 > &clusLists)
Build lookup lists of clusters for out-of-cluster energy sharing.
static void buildCellInfoMap(const xAOD::CaloClusterContainer &theClusColl, CellInfoSet_t &cellInfo)
Build a map of calorimeter cells contributing to clusters.
static const CaloDmDescrManager * instance()
size_type size() const noexcept
Returns the number of elements in the collection.
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
Handle class for adding a decoration to an object.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.