ATLAS Offline Software
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 
12 namespace {
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 
22 CaloTopoTowerFromClusterCalibrator::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 
30  xAOD::CaloClusterContainer* pClusCont,
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 
CaloTopoTowerFromClusterCalibrator::CaloTopoTowerFromClusterCalibrator
CaloTopoTowerFromClusterCalibrator(const std::string &type, const std::string &name, const IInterface *pParent)
Tool constructor.
Definition: CaloTopoTowerFromClusterCalibrator.cxx:22
max
#define max(a, b)
Definition: cfImp.cxx:41
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloCellClusterWeights::weight_t
std::vector< double > weight_t
Type of weight.
Definition: CaloCellClusterWeights.h:28
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
xAOD::rawPhi
setRawEt rawPhi
Definition: TrigCaloCluster_v1.cxx:29
CaloRec::Helpers::fmtMsg
std::string fmtMsg(const char *fmt,...)
Definition: CaloTopoClusterFromTowerHelpers.cxx:13
CaloCellClusterWeights::at
const weight_t & at(size_t hash) const
Accessing value using function and hash.
Definition: CaloCellClusterWeights.cxx:31
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
CaloTopoTowerFromClusterCalibrator::m_orderByPt
bool m_orderByPt
Turn on pT ordering if true.
Definition: CaloTopoTowerFromClusterCalibrator.h:33
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
CaloRec::Helpers::calculateKine
bool calculateKine(xAOD::CaloCluster *pClus, bool onlyKine=false)
Kinematic updates.
Definition: CaloTopoClusterFromTowerHelpers.cxx:118
CaloTopoTowerFromClusterCalibrator::execute
virtual StatusCode execute(const EventContext &ctx, xAOD::CaloClusterContainer *pClusCont, CaloCellClusterWeights *cellWeights) const override
Tool execution.
Definition: CaloTopoTowerFromClusterCalibrator.cxx:29
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
CaloTopoTowerFromClusterCalibrator.h
CaloCellClusterWeights
Hash lookup of calibration weights for calorimeter cells.
Definition: CaloCellClusterWeights.h:23
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
CaloTopoClusterFromTowerHelpers.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
CaloSampling::getSamplingName
static std::string getSamplingName(CaloSample theSample)
Returns a string (name) for each CaloSampling.
Definition: Calorimeter/CaloGeoHelpers/Root/CaloSampling.cxx:18
AthAlgTool
Definition: AthAlgTool.h:26
CaloCellClusterWeights.h