5#ifndef CALOCALIBHITREC_CALOCALIBCLUSTERMOMENTSMAKER2_H
6#define CALOCALIBHITREC_CALOCALIBCLUSTERMOMENTSMAKER2_H
21#include "GaudiKernel/ToolHandle.h"
24#include "CaloGeoHelpers/CaloSampling.h"
31#include "CLHEP/Units/SystemOfUnits.h"
51 class MyCellInfo :
public std::vector<std::pair<int, double> > {
53 MyCellInfo(
int iClus,
double w) { this->emplace_back(iClus, w); }
54 void Add(
const MyCellInfo& other) { this->insert(this->end(), other.begin(), other.end()); }
64 std::array<double, CaloSampling::Unknown + 1>
engSmp{};
65 void Add(
double eng,
int nsmp)
72 void Add(
double eng,
int nsmp,
int pid = 0)
85 using ClusList = std::vector<std::vector<int> >;
92 const IInterface* parent);
95 virtual StatusCode
execute(
const EventContext& ctx,
122 const double (&rmaxOut)[3],
123 std::array<std::vector<std::vector<CalibHitIPhiIEtaRange> >, 3>& i_phi_eta);
169 const std::array<std::vector<std::vector<CalibHitIPhiIEtaRange> >, 3>& i_phi_eta,
170 const std::array<bool, 3>& doOutOfCluster,
171 const std::array<ClusList*, 3>& clusLists);
198 template <
class Inval
idUniqueIdHandler>
200 const std::vector<const CaloCalibrationHitContainer*>& v_cchc,
204 unsigned int& nHitsTotal,
205 unsigned int& nHitsWithoutParticleUID,
207 InvalidUniqueIdHandler&& invalidUniqueIdHandler)
212 typename CellInfoSet_t::const_iterator pos = cellInfo.find(myId);
214 if (pos != cellInfo.end()) {
218 for (
const std::pair<int, double>& p : pos->second) {
219 const int iClus = p.first;
220 const double weight = p.second;
225 invalidUniqueIdHandler();
228 clusInfoVec[iClus].Add(weight * hit->energyTotal(),
230 static_cast<unsigned int>(uniqueID));
233 clusInfoVec[iClus].Add(weight * hit->energyTotal(), nsmp);
239 ++nHitsWithoutParticleUID;
246 template <
class AddOutOfClusterEnergy>
248 const std::vector<const CaloCalibrationHitContainer*>& v_cchc,
256 const std::array<bool, 3>& doOutOfCluster,
257 const std::array<const ClusList*, 3>& clusLists,
258 AddOutOfClusterEnergy&& addOutOfClusterEnergy)
263 typename CellInfoSet_t::const_iterator pos = cellInfo.find(myId);
264 if (pos != cellInfo.end()) {
274 const int jeO =
static_cast<int>(std::floor(n_eta_out * (myCDDE->
eta() / out_eta_max)));
275 if (jeO < -n_eta_out || jeO >= n_eta_out) {
279 int jpO =
static_cast<int>(std::floor(n_phi_out * (myCDDE->
phi() / out_phi_max)));
280 if (jpO < -n_phi_out) jpO += 2 * n_phi_out;
281 if (jpO >= n_phi_out) jpO -= 2 * n_phi_out;
283 for (
unsigned int ii = 0; ii < 3; ++ii) {
284 const ClusList* pClusList = clusLists[ii];
285 if (!doOutOfCluster[ii] || pClusList ==
nullptr) {
289 double hitClusNorm = 0.0;
290 std::vector<int> hitClusIndex;
291 std::vector<double> hitClusEffEnergy;
292 const std::vector<int>& matchingClusters =
293 (*pClusList)[(jpO + n_phi_out) * (2 * n_eta_out + 1) + jeO + n_eta_out];
295 for (
int iClus : matchingClusters) {
296 const MyClusInfo& clusInfo = clusInfoVec[iClus];
301 hitClusNorm += partPos->second.engTot;
302 hitClusEffEnergy.push_back(partPos->second.engTot);
303 hitClusIndex.push_back(iClus);
306 if (hitClusNorm <= 0.0) {
310 const double inv_hitClusNorm = 1.0 / hitClusNorm;
311 for (std::size_t i = 0; i < hitClusIndex.size(); ++i) {
312 const int iClus = hitClusIndex[i];
313 const double w = hitClusEffEnergy[i] * inv_hitClusNorm;
314 addOutOfClusterEnergy(ii, iClus, uniqueID, w * hit->energyTotal());
336 template <
class AddDeadMaterialEnergy>
338 const std::vector<const CaloCalibrationHitContainer*>& v_dmcchc,
343 AddDeadMaterialEnergy&& addDeadMaterialEnergy)
const
381 std::vector<int> hitClusIndex;
382 std::vector<double> hitClusEffEnergy;
383 hitClusIndex.reserve(theClusColl.
size());
384 hitClusEffEnergy.reserve(theClusColl.
size());
385 double hitClusNorm = 0.0;
387 const std::vector<int>& matchingClusters =
390 for (
int iClus : matchingClusters) {
392 const MyClusInfo& clusInfo = clusInfoVec[iClus];
398 const double engClusTruthUniqueIDCalib = pos->second.engTot;
399 if (engClusTruthUniqueIDCalib <= m_energyMinCalib || theCluster->e() <=
m_energyMin) {
403 double sum_smp_energy = 0.0;
409 sum_smp_energy += pos->second.engSmp[nsmp];
412 if (sum_smp_energy <= 0.0) {
416 double phi_diff = myCDDE->
phi() - theCluster->
phi();
417 if (phi_diff <= -
M_PI) {
418 phi_diff += 2. *
M_PI;
420 else if (phi_diff >
M_PI) {
421 phi_diff -= 2. *
M_PI;
423 const double eta_diff = myCDDE->
eta() - theCluster->
eta();
424 const float distance = std::sqrt(eta_diff * eta_diff + phi_diff * phi_diff);
427 hitClusIndex.push_back(iClus);
428 hitClusEffEnergy.push_back(effEner);
429 hitClusNorm += effEner;
432 if (hitClusNorm <= 0.0) {
436 const double inv_hitClusNorm = 1.0 / hitClusNorm;
437 for (std::size_t i = 0; i < hitClusIndex.size(); ++i) {
438 const int iClus = hitClusIndex[i];
439 const double dm_weight = hitClusEffEnergy[i] * inv_hitClusNorm;
440 addDeadMaterialEnergy(iClus, uniqueID, nDmArea, hit->energyTotal() * dm_weight);
463 std::array<std::vector<std::vector<CalibHitIPhiIEtaRange> >, 3>
m_i_phi_eta;
Base class for cluster processing tools called from CaloClusterMaker.
Definition of CaloDetDescrManager.
MyCellInfo(int iClus, double w)
void Add(const MyCellInfo &other)
std::array< double, CaloSampling::Unknown+1 > engSmp
void Add(double eng, int nsmp)
ClusCalibEnergy engCalibIn
std::map< int, ClusCalibEnergy > engCalibParticle
void Add(double eng, int nsmp, int pid=0)
std::array< double, CaloDmDescrArea::DMA_MAX > engCalibDeadInArea
std::set< moment_name_pair > moment_name_set
const CaloDM_ID * m_caloDM_ID
std::vector< moment_name_pair > moment_name_vector
virtual StatusCode initialize() override
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
Accumulate dead-material calibration-hit energy assigned to clusters.
std::vector< MyClusInfo > ClusInfo_t
SG::ReadHandleKeyArray< CaloCalibrationHitContainer > m_DMCalibrationHitContainerNames
moment_name_vector m_validNames
std::set< xAOD::CaloCluster::MomentType > m_momentsAOD
virtual StatusCode execute(const EventContext &ctx, xAOD::CaloClusterContainer *theClusColl) const override
Execute on an entire collection of clusters.
moment_name_set m_validMoments
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.
SG::ReadHandleKeyArray< CaloCalibrationHitContainer > m_CalibrationHitContainerNames
const CaloCell_ID * m_calo_id
bool m_doDeadEnergySharing
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.
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticleContainerKey
std::atomic< bool > m_foundAllContainers
std::vector< std::string > m_momentsNames
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.
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloDetDescrMgrKey
CaloCalibClusterMomentsMaker2(const std::string &type, const std::string &name, const IInterface *parent)
std::array< std::vector< std::vector< CalibHitIPhiIEtaRange > >, 3 > m_i_phi_eta
static double angle_mollier_factor(double x)
const CaloDmDescrManager * m_caloDmDescrManager
std::vector< std::string > m_momentsNamesAOD
std::vector< std::vector< int > > ClusList
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)
std::pair< std::string, xAOD::CaloCluster::MomentType > moment_name_pair
Class to store calorimeter calibration hit.
int calo_sample(const Identifier id) const
returns an int taken from Sampling enum and describing the subCalo to which the Id belongs.
Helper class for offline cell identifiers.
virtual StatusCode execute(const EventContext &ctx, xAOD::CaloClusterContainer *collection) const =0
Execute on an entire collection of clusters.
Helper class for Calo Dead Material offline identifiers.
This class groups all DetDescr information related to a CaloCell.
float eta() const
cell eta
float phi() const
cell phi
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
This class provides the client interface for accessing the detector description information common to...
std::vector< short > m_CaloSampleNeighbours
std::vector< float > m_CaloSampleEtaMin
std::vector< float > m_CaloSampleEtaMax
const T * at(size_type n) const
Access an element, as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double phi() const
The azimuthal angle ( ) of the particle.
constexpr int INVALID_PARTICLE_ID
constexpr int UNDEFINED_ID
HandleKeyArray< ReadHandle< T >, ReadHandleKey< T >, Gaudi::DataHandle::Reader > ReadHandleKeyArray
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.