ATLAS Offline Software
Loading...
Searching...
No Matches
CaloTopoTowerFromClusterCalibrator.cxx
Go to the documentation of this file.
1/* Copyright (C) 2002-2017 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 declareProperty("OrderClusterByPt", m_orderByPt, "Order clusters by calibrated Pt (input)");
27}
28
29StatusCode CaloTopoTowerFromClusterCalibrator::execute(const EventContext& /*ctx*/,
31 CaloCellClusterWeights* cellWeights) const
32{
33
34 // protection needed?
35 if ( cellWeights == nullptr ) {
36 ATH_MSG_ERROR("Tower calibrator needs valid pointer to LCW weight lookup");
37 return StatusCode::FAILURE;
38 }
39
41 // Calibrated clusters //
43
44 // loop towers
45 for ( auto pClus : *pClusCont ) {
46 // loop cells in towers
47 for ( auto fCell(pClus->cell_begin()); fCell != pClus->cell_end(); ++fCell ) {
48 // pick up the LCW weights (one if cell is only in one topo-cluster, two if cell is split between two) -> w_cell
49 const CaloCellClusterWeights::weight_t& wght(cellWeights->at(*fCell));
50 // pick up geometrical weight of cells in tower
51 double weight(fCell.weight());
52 // combine the weights -> w_geo * w_cell
53 weight *= accumulateWeight(wght);
54 if ( weight == 0. ) {
55 // weight = 0 should actualy never happen!!!!
56 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",
57 pClus->eta(),pClus->phi(),(size_t)fCell->caloDDE()->calo_hash(),weight,wght.size(),fCell.weight(),weight/std::max(fCell.weight(),1e-08),
58 (unsigned int)fCell->caloDDE()->getSampling(),CaloSampling::getSamplingName(fCell->caloDDE()->getSampling()).c_str()) );
59 } else {
60 // valid weight, apply to cell in tower
61 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]",
62 pClus->eta(),pClus->phi(),(size_t)fCell->caloDDE()->calo_hash(),weight,wght.size(),fCell.weight(),weight/fCell.weight()) );
63 pClus->reweightCell(fCell,weight); // Set new weight. //
64 }
65 }
66 // preserve raw (EM) kinematics
67 double rawE(pClus->e());
68 double rawEta(pClus->eta()); // Clusters are instantiated with signal state CALIBRATED. The kinematics prior to the //
69 double rawPhi(pClus->phi()); // application of LCW is EM. This code saves the EM scale kinematics. //
70 double rawM(pClus->m());
71 // update cluster kinematics
73 pClus->setRawE(rawE); // The calculateKine function recombines cell signals with the updated weights (combined //
74 pClus->setRawEta(rawEta); // LCW and tower geometry weights). After this function, the CALIBRATED state reflects //
75 pClus->setRawPhi(rawPhi); // these combined weights. The EM scale kinematics is restored as raw (UNCALIBRATED). //
76 pClus->setRawM(rawM);
77 } // cluster loop
78
79 // order clusters by Pt if requested
80 if ( m_orderByPt ) {
81 std::sort(pClusCont->begin(),pClusCont->end(),[](xAOD::CaloCluster* pc1,xAOD::CaloCluster* pc2) {
82 volatile double pt1(pc1->pt());
83 volatile double pt2(pc2->pt());
84 return ( pt1 > pt2 );
85 }
86 );
87 }
88
89 return StatusCode::SUCCESS;
90}
91
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
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.
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.