ATLAS Offline Software
Loading...
Searching...
No Matches
CaloCalibClusterDecoratorToolOOC.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5//-----------------------------------------------------------------------
6// File and Version Information:
7// $Id: CaloCalibClusterTruthAttributerToolOOC.cxx,v 1.16 2009-05-18 16:16:49 pospelov Exp $
8//
9// Description: see CaloCalibClusterTruthAttributerToolOOC.h
10//
11// Environment:
12// Software developed for the ATLAS Detector at CERN LHC
13//
14// Author List:
15// Sven Menke
16//
17//-----------------------------------------------------------------------
18
19//-----------------------
20// This Class's Header --
21//-----------------------
23
24//---------------
25// C++ Headers --
26//---------------
27#include <iterator>
28#include <sstream>
29#include <set>
30
31#include "CaloEvent/CaloCell.h"
36
41
42#include "CLHEP/Units/SystemOfUnits.h"
43
44#include <CLHEP/Vector/LorentzVector.h>
45#include <cmath>
46
47using CLHEP::HepLorentzVector;
48using CLHEP::MeV;
49using CLHEP::cm;
50
51namespace {
52
61std::vector<std::pair<unsigned int, double> > makeSortedTruthPairs(
62 const std::unordered_map<int, double>& truthMap,
63 unsigned int maxTruthParticles)
64{
65 std::vector<std::pair<unsigned int, double> > truthPairs;
66 truthPairs.reserve(truthMap.size());
67 for (const auto& [pid, energy] : truthMap) {
68 // The internal bookkeeping uses the signed uniqueID/barcode type propagated
69 // by the calibration-hit helpers, while the final decoration stores the
70 // identifier as unsigned.
71 truthPairs.emplace_back(static_cast<unsigned int>(pid), energy);
72 }
73
74 std::sort(truthPairs.begin(),
75 truthPairs.end(),
76 [](const auto& a, const auto& b) { return a.second > b.second; });
77 if (truthPairs.size() > maxTruthParticles) {
78 truthPairs.resize(maxTruthParticles);
79 }
80 return truthPairs;
81}
82
83} // namespace
84
85//###############################################################################
86
88 const std::string& name,
89 const IInterface* parent)
90 : AthAlgTool(type, name, parent),
91 m_calo_id(nullptr)
92{
93 declareInterface<CaloClusterCollectionProcessor>(this);
94
95 m_n_phi_out = 127; // not more than 127 since we store indices (-127,...,-1,0,...,126) with 8 bits
96 m_n_eta_out = 127;
98 m_out_eta_max = 6.;
99
100 m_rmaxOut[0] = 1.0;
101 m_rmaxOut[1] = 0.5;
102 m_rmaxOut[2] = 0.3;
103
104 for (int im = 0; im < 3; ++im) {
105 m_i_phi_eta[im].resize(m_n_eta_out);
106 }
107}
108
109//###############################################################################
110
131
132//###############################################################################
133
134StatusCode
136 xAOD::CaloClusterContainer* theClusColl) const
137{
139 std::vector<std::pair<unsigned int, double> > >
140 caloClusterWriteDecorHandleNLeadingTruthParticlesL(
143 std::vector<std::pair<unsigned int, double> > >
144 caloClusterWriteDecorHandleNLeadingTruthParticlesT(
146
147 ATH_MSG_DEBUG("Starting CaloCalibClusterTruthAttributerToolOOC::execute");
149 const CaloDetDescrManager* calo_dd_man = *caloMgrHandle;
150
151 bool foundAllContainers(true);
152 std::vector<const CaloCalibrationHitContainer*> v_cchc;
153
154 // Only emit an error once the job has previously seen a complete set of
155 // calibration-hit containers. This avoids logging one ERROR per event in
156 // jobs where the containers are absent throughout, while still flagging a
157 // transition from "containers present" to "containers missing".
161 if (!cchc.isValid()) {
163 ATH_MSG_ERROR("SG does not contain calibration hit container " << key.key());
164 }
165 foundAllContainers = false;
166 }
167 else {
168 v_cchc.push_back(cchc.cptr());
169 }
170 }
171
172 if (!m_foundAllContainers && foundAllContainers) {
174 }
175
176 if (!foundAllContainers) {
177 return StatusCode::SUCCESS;
178 }
179 ATH_MSG_DEBUG("SG has all containers");
180
181 // Helper to store cluster calibration energies
182 ClusInfo_t clusInfoVec(theClusColl->size());
183
186
187 unsigned int nHitsTotal = 0;
188 unsigned int nHitsWithoutParticleUID = 0;
190 v_cchc,
191 cellInfo,
192 *m_calo_id,
193 clusInfoVec,
194 nHitsTotal,
195 nHitsWithoutParticleUID,
196 true,
197 [this]() {
198 ATH_MSG_ERROR("Invalid uniqueID detected - this sample cannot be properly analysed.");
199 });
200
201 std::array<std::vector<std::unordered_map<int, double> >, 3> engCalibOut;
202 std::array<ClusList, 3> clusLists;
203 for (auto& clusList : clusLists) {
204 clusList.resize((2 * m_n_phi_out + 1) * (2 * m_n_eta_out + 1));
205 }
206 for (auto& engByTruth : engCalibOut) {
207 engByTruth.resize(theClusColl->size());
208 }
209
210 // This decorator always evaluates the loose, medium and tight OOC matching
211 // definitions when building the helper lookup structures.
212 const std::array<bool, 3> doOutOfCluster{{true, true, true}};
213 const std::array<ClusList*, 3> clusListPtrs{{
214 &clusLists[0], &clusLists[1], &clusLists[2]}};
215 const std::array<const ClusList*, 3> constClusListPtrs{{
216 &clusLists[0], &clusLists[1], &clusLists[2]}};
217
219 *theClusColl,
220 clusInfoVec,
226 doOutOfCluster,
227 clusListPtrs);
228
230 v_cchc,
231 cellInfo,
232 *calo_dd_man,
233 clusInfoVec,
238 doOutOfCluster,
239 constClusListPtrs,
240 [&engCalibOut](unsigned int ii, int iClus, int uniqueID, double energy) {
241 engCalibOut[ii][iClus][uniqueID] += energy;
242 });
243
244 int clusIdx = -1;
245 for (const xAOD::CaloCluster* thisCaloCluster : *theClusColl) {
246 ++clusIdx;
247
248 const std::unordered_map<int, double>& truthMapL = engCalibOut[0][clusIdx];
249 if (!truthMapL.empty()) {
250 caloClusterWriteDecorHandleNLeadingTruthParticlesL(*thisCaloCluster) =
251 makeSortedTruthPairs(truthMapL, m_numTruthParticles);
252 }
253
254 const std::unordered_map<int, double>& truthMapT = engCalibOut[2][clusIdx];
255 if (!truthMapT.empty()) {
256 caloClusterWriteDecorHandleNLeadingTruthParticlesT(*thisCaloCluster) =
257 makeSortedTruthPairs(truthMapT, m_numTruthParticles);
258 }
259 }
260
261 return StatusCode::SUCCESS;
262}
#define M_PI
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Definition of CaloDetDescrManager.
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
double m_rmaxOut[3]
Maximum matching radii for the loose/medium/tight OOC definitions.
std::atomic< bool > m_foundAllContainers
Tracks whether a previous event had the full set of calibration-hit containers.
double m_out_phi_max
Maximum |Δphi| covered by the out-of-cluster lookup tables.
SG::WriteDecorHandleKey< xAOD::CaloClusterContainer > m_caloClusterWriteDecorHandleKeyNLeadingTruthParticlesT
Writehandle for the decoration holding the leading truth-particle barcode/energy pairs for the tight ...
std::array< std::vector< std::vector< CalibHitIPhiIEtaRange > >, 3 > m_i_phi_eta
Precomputed eta/phi search windows used by the OOC helper methods.
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloDetDescrMgrKey
Conditions Handle Key to access the CaloDetDescrManager.
const CaloCell_ID * m_calo_id
Cached pointer to the calorimeter cell identifier helper.
int m_n_eta_out
Number of bins in the lookup table for out-of-cluster eta offsets.
Gaudi::Property< unsigned int > m_numTruthParticles
Number of leading truth particles to store per cluster.
SG::WriteDecorHandleKey< xAOD::CaloClusterContainer > m_caloClusterWriteDecorHandleKeyNLeadingTruthParticlesL
Writehandle for the decoration holding the leading truth-particle barcode/energy pairs for the loose ...
double m_out_eta_max
Maximum |Δeta| covered by the out-of-cluster lookup tables.
int m_n_phi_out
Number of bins in the lookup table for out-of-cluster phi offsets.
virtual StatusCode execute(const EventContext &ctx, xAOD::CaloClusterContainer *theClusColl) const override
Execute on an entire collection of clusters.
CaloCalibClusterDecoratorToolOOC(const std::string &type, const std::string &name, const IInterface *parent)
SG::ReadHandleKeyArray< CaloCalibrationHitContainer > m_CalibrationHitContainerNames
vector of calibration hit container names to use.
CaloCalibClusterMomentsMaker2::ClusInfo_t ClusInfo_t
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticleContainerKey
Readhandle for Truth-particle container used to validate barcode / uniqueID usage.
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.
std::map< Identifier, MyCellInfo > CellInfoSet_t
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 void accumulateOutOfClusterEnergy(const std::vector< const CaloCalibrationHitContainer * > &v_cchc, const CellInfoSet_t &cellInfo, const CaloDetDescrManager &calo_dd_man, const ClusInfo_t &clusInfoVec, int n_phi_out, int n_eta_out, double out_phi_max, double out_eta_max, const std::array< bool, 3 > &doOutOfCluster, const std::array< const ClusList *, 3 > &clusLists, AddOutOfClusterEnergy &&addOutOfClusterEnergy)
This class provides the client interface for accessing the detector description information common to...
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.