42#include "CLHEP/Units/SystemOfUnits.h"
44#include <CLHEP/Vector/LorentzVector.h>
47using CLHEP::HepLorentzVector;
61std::vector<std::pair<unsigned int, double> > makeSortedTruthPairs(
62 const std::unordered_map<int, double>& truthMap,
63 unsigned int maxTruthParticles)
65 std::vector<std::pair<unsigned int, double> > truthPairs;
66 truthPairs.reserve(truthMap.size());
67 for (
const auto& [pid, energy] : truthMap) {
71 truthPairs.emplace_back(
static_cast<unsigned int>(pid), energy);
76 [](
const auto&
a,
const auto& b) { return a.second > b.second; });
77 if (truthPairs.size() > maxTruthParticles) {
78 truthPairs.resize(maxTruthParticles);
88 const std::string& name,
89 const IInterface* parent)
93 declareInterface<CaloClusterCollectionProcessor>(
this);
104 for (
int im = 0; im < 3; ++im) {
129 return StatusCode::SUCCESS;
139 std::vector<std::pair<unsigned int, double> > >
140 caloClusterWriteDecorHandleNLeadingTruthParticlesL(
143 std::vector<std::pair<unsigned int, double> > >
144 caloClusterWriteDecorHandleNLeadingTruthParticlesT(
147 ATH_MSG_DEBUG(
"Starting CaloCalibClusterTruthAttributerToolOOC::execute");
151 bool foundAllContainers(
true);
152 std::vector<const CaloCalibrationHitContainer*> v_cchc;
163 ATH_MSG_ERROR(
"SG does not contain calibration hit container " << key.key());
165 foundAllContainers =
false;
168 v_cchc.push_back(cchc.
cptr());
176 if (!foundAllContainers) {
177 return StatusCode::SUCCESS;
187 unsigned int nHitsTotal = 0;
188 unsigned int nHitsWithoutParticleUID = 0;
195 nHitsWithoutParticleUID,
198 ATH_MSG_ERROR(
"Invalid uniqueID detected - this sample cannot be properly analysed.");
201 std::array<std::vector<std::unordered_map<int, double> >, 3> engCalibOut;
202 std::array<ClusList, 3> clusLists;
203 for (
auto& clusList : clusLists) {
206 for (
auto& engByTruth : engCalibOut) {
207 engByTruth.resize(theClusColl->
size());
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]}};
240 [&engCalibOut](
unsigned int ii,
int iClus,
int uniqueID,
double energy) {
241 engCalibOut[ii][iClus][uniqueID] += energy;
248 const std::unordered_map<int, double>& truthMapL = engCalibOut[0][clusIdx];
249 if (!truthMapL.empty()) {
250 caloClusterWriteDecorHandleNLeadingTruthParticlesL(*thisCaloCluster) =
254 const std::unordered_map<int, double>& truthMapT = engCalibOut[2][clusIdx];
255 if (!truthMapT.empty()) {
256 caloClusterWriteDecorHandleNLeadingTruthParticlesT(*thisCaloCluster) =
261 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition of CaloDetDescrManager.
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
const ServiceHandle< StoreGateSvc > & detStore() 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.
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.