ATLAS Offline Software
Loading...
Searching...
No Matches
CaloTopoTowerFromClusterCalibrator.cxx
Go to the documentation of this file.
1/* Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration */
2
5
7
8#include "CaloGeoHelpers/CaloSampling.h"
9
10#include <numeric>
11
12namespace {
13 double accumulateWeight(const CaloCellClusterWeights::weight_t& wght) // A cell can be split across clusters (usually only two). //
14 { return wght.empty() // It thus receives two different calibration weights, //
15 ? 0. // including geometrical weight introduced by splitting. //
16 : wght.size() == 1 // The overall weight is the sum of the two. //
17 ? wght.front()
18 : std::accumulate(wght.begin(),wght.end(),0.);
19 }
20}
21
22CaloTopoTowerFromClusterCalibrator::CaloTopoTowerFromClusterCalibrator(const std::string& type,const std::string& name,const IInterface* pParent)
23 : AthAlgTool(type,name,pParent)
24{
25 declareInterface<CaloTowerCollectionProcessor>(this);
26}
27
28StatusCode CaloTopoTowerFromClusterCalibrator::execute(const EventContext& /*ctx*/,
30 CaloCellClusterWeights* cellWeights) const
31{
32
33 // protection needed?
34 if ( cellWeights == nullptr ) {
35 ATH_MSG_ERROR("Tower calibrator needs valid pointer to LCW weight lookup");
36 return StatusCode::FAILURE;
37 }
38
40 // Calibrated clusters //
42
43 // loop towers
44 for ( auto pClus : *pClusCont ) {
45 // loop cells in towers
46 for ( auto fCell(pClus->cell_begin()); fCell != pClus->cell_end(); ++fCell ) {
47 // pick up the LCW weights (one if cell is only in one topo-cluster, two if cell is split between two) -> w_cell
48 const CaloCellClusterWeights::weight_t& wght(cellWeights->at(*fCell));
49 // pick up geometrical weight of cells in tower
50 double weight(fCell.weight());
51 // combine the weights -> w_geo * w_cell
52 weight *= accumulateWeight(wght);
53 if ( weight == 0. ) {
54 // weight = 0 should actualy never happen!!!!
55 ATH_MSG_DEBUG( CaloRec::Helpers::fmtMsg("[NO_LCW_REWEIGHT] Tower (%6.3f,%6.3f) cell [%6zu] weight = %6.3f [# LCW weights %zu geo %6.3f LCW %6.3f] SamplingID %2u Name \042%s\042",
56 pClus->eta(),pClus->phi(),(size_t)fCell->caloDDE()->calo_hash(),weight,wght.size(),fCell.weight(),weight/std::max(fCell.weight(),1e-08),
57 (unsigned int)fCell->caloDDE()->getSampling(),CaloSampling::getSamplingName(fCell->caloDDE()->getSampling()).c_str()) );
58 } else {
59 // valid weight, apply to cell in tower
60 ATH_MSG_DEBUG( CaloRec::Helpers::fmtMsg("[DO_LCW_REWEIGHT] Tower (%6.3f,%6.3f) cell [%6zu] weight = %6.3f [# LCW weights %zu geo %6.3f LCW %6.3f]",
61 pClus->eta(),pClus->phi(),(size_t)fCell->caloDDE()->calo_hash(),weight,wght.size(),fCell.weight(),weight/fCell.weight()) );
62 pClus->reweightCell(fCell,weight); // Set new weight. //
63 }
64 }
65 // preserve raw (EM) kinematics
66 double rawE(pClus->e());
67 double rawEta(pClus->eta()); // Clusters are instantiated with signal state CALIBRATED. The kinematics prior to the //
68 double rawPhi(pClus->phi()); // application of LCW is EM. This code saves the EM scale kinematics. //
69 double rawM(pClus->m());
70 // update cluster kinematics
72 pClus->setRawE(rawE); // The calculateKine function recombines cell signals with the updated weights (combined //
73 pClus->setRawEta(rawEta); // LCW and tower geometry weights). After this function, the CALIBRATED state reflects //
74 pClus->setRawPhi(rawPhi); // these combined weights. The EM scale kinematics is restored as raw (UNCALIBRATED). //
75 pClus->setRawM(rawM);
76 } // cluster loop
77
78 // order clusters by Pt if requested
79 if ( m_orderByPt ) {
80 std::sort(pClusCont->begin(),pClusCont->end(),[](xAOD::CaloCluster* pc1,xAOD::CaloCluster* pc2) {
81 volatile double pt1(pc1->pt());
82 volatile double pt2(pc2->pt());
83 return ( pt1 > pt2 );
84 }
85 );
86 }
87
88 return StatusCode::SUCCESS;
89}
90
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Hash lookup of calibration weights for calorimeter cells.
std::vector< double > weight_t
Type of weight.
const weight_t & at(size_t hash) const
Accessing value using function and hash.
static std::string getSamplingName(CaloSample theSample)
Returns a string (name) for each CaloSampling.
CaloTopoTowerFromClusterCalibrator(const std::string &type, const std::string &name, const IInterface *pParent)
Tool constructor.
Gaudi::Property< bool > m_orderByPt
Turn on pT ordering if true.
virtual StatusCode execute(const EventContext &ctx, xAOD::CaloClusterContainer *pClusCont, CaloCellClusterWeights *cellWeights) const override
Tool execution.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
bool calculateKine(xAOD::CaloCluster *pClus, bool onlyKine=false)
Kinematic updates.
std::string fmtMsg(const char *fmt,...)
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.