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());
328 Gaudi::Property<std::vector<std::string>>
m_momentsNames{
this,
"MomentsNames", {}};
341 ,
"ENG_CALIB_DEAD_TOT"
342 ,
"ENG_CALIB_DEAD_EMB0"
343 ,
"ENG_CALIB_DEAD_TILE0"
344 ,
"ENG_CALIB_DEAD_TILEG3"
345 ,
"ENG_CALIB_DEAD_EME0"
346 ,
"ENG_CALIB_DEAD_HEC0"
347 ,
"ENG_CALIB_DEAD_FCAL"
348 ,
"ENG_CALIB_DEAD_LEAKAGE"
349 ,
"ENG_CALIB_DEAD_UNCLASS"
350 ,
"ENG_CALIB_FRAC_EM"
351 ,
"ENG_CALIB_FRAC_HAD"
352 ,
"ENG_CALIB_FRAC_REST"
390 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
std::vector< MyClusInfo > ClusInfo_t
SG::ReadHandleKeyArray< CaloCalibrationHitContainer > m_DMCalibrationHitContainerNames
moment_name_vector m_validNames
std::set< xAOD::CaloCluster::MomentType > m_momentsAOD
Gaudi::Property< bool > m_useParticleID
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.
Gaudi::Property< std::vector< std::string > > m_momentsNames
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
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
Gaudi::Property< int > m_MatchDmType
static double angle_mollier_factor(double x)
const CaloDmDescrManager * m_caloDmDescrManager
std::vector< std::vector< int > > ClusList
Gaudi::Property< std::vector< std::string > > m_momentsNamesAOD
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...
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.
@ ENG_CALIB_OUT_M
Attached Calibration Hit energy outside clusters but inside the calorimeter with medium matching (Ang...
@ ENG_CALIB_OUT_L
Attached Calibration Hit energy outside clusters but inside the calorimeter with loose matching (Angl...
@ ENG_CALIB_DEAD_UNCLASS
Attached Calibration Hit energy in dead material in unclassified areas of the detector.
@ ENG_CALIB_DEAD_HEC0
Attached Calibration Hit energy in dead material between EME3 and HEC0.
@ ENG_CALIB_DEAD_TILEG3
Attached Calibration Hit energy in dead material before scintillator.
@ ENG_CALIB_FRAC_REST
Calibration Hit energy inside the cluster caused by other particles.
@ ENG_CALIB_DEAD_EME0
Attached Calibration Hit energy in dead material before EME0, between EME0 and EME1.
@ ENG_CALIB_DEAD_TILE0
Attached Calibration Hit energy in dead material between EMB3 and TILE0.
@ ENG_CALIB_FRAC_EM
Calibration Hit energy inside the cluster caused by e/gamma/pi0.
@ ENG_CALIB_DEAD_FCAL
Attached Calibration Hit energy in dead material before FCAL, between FCAL and HEC.
@ ENG_CALIB_TOT
Calibration Hit energy inside the cluster.
@ ENG_CALIB_OUT_T
Attached Calibration Hit energy outside clusters but inside the calorimeter with tight matching (Angl...
@ ENG_CALIB_DEAD_LEAKAGE
Attached Calibration Hit energy in dead material behind calorimeters.
@ ENG_CALIB_FRAC_HAD
Calibration Hit energy inside the cluster caused by charged pi+ and pi-.
@ ENG_CALIB_EMB0
Calibration Hit energy inside the cluster barrel presampler.
@ ENG_CALIB_EME0
Calibration Hit energy inside the cluster endcap presampler.
@ ENG_CALIB_DEAD_EMB0
Attached Calibration Hit energy in dead material before EMB0, between EMB0 and EMB1.
@ ENG_CALIB_DEAD_TOT
Attached Calibration Hit energy in dead material.
@ ENG_CALIB_TILEG3
Calibration Hit energy inside the cluster scintillator.
constexpr int INVALID_PARTICLE_ID
constexpr int UNDEFINED_ID
HandleKeyArray< ReadHandle< T >, ReadHandleKey< T >, Gaudi::DataHandle::Reader > ReadHandleKeyArray
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.