ATLAS Offline Software
CaloClusterCellWeightCalib.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 
7 #include "CLHEP/Units/SystemOfUnits.h"
8 
10 
12 
13 #include "CaloGeoHelpers/proxim.h"
15 #include "CaloEvent/CaloCluster.h"
16 
18 
19 #include <cstdlib>
20 
21 std::string const CaloClusterCellWeightCalib::m_posName = "Signal";
22 std::string const CaloClusterCellWeightCalib::m_absName = "AbsSignal";
23 std::string const CaloClusterCellWeightCalib::m_rawName = "RawSignal";
24 
25 std::string const CaloClusterCellWeightCalib::m_defName = m_absName;
26 
28 // Constructor & Destructor //
30 
32 CaloClusterCellWeightCalib(const std::string& type,
33  const std::string& name,
34  const IInterface* pParent)
35  : CaloClusterProcessor(type,name,pParent)
36  , m_directionCalculation(m_defName)
37  , m_calibNoiseLikeAll(true)
38  , m_noiseDirectionCalculation(m_defName)
39  , m_eThreshold(0.)
40  , m_ignoreGeoWghts(false)
41  , m_cellWeight(this)
42  , m_calc(nullptr)
43  , m_calc_noise(nullptr)
44 {
46  declareProperty("BelowThresholdLikeAll", m_calibNoiseLikeAll);
47  declareProperty("BelowThresholdDirection", m_noiseDirectionCalculation);
48  declareProperty("EnergyThreshold", m_eThreshold);
49  declareProperty("IgnoreGeoWeights", m_ignoreGeoWghts);
50  declareProperty("CellSignalWeightTool", m_cellWeight);
51 }
52 
54 = default;
55 
57 // Initialization //
59 
61 {
62  MsgStream report(msgSvc(),name());
63 
64  // configure direction calculations
66  ? this->setupAll(report) // all clusters the same
67  : this->setupSpc(report); // dedicated noise cluster treatment
68  if ( checkOut.isFailure() )
69  {
70  report << MSG::ERROR
71  << "failed to configure direction calculations."
72  << endmsg;
73  return StatusCode::FAILURE;
74  }
75 
76  // retrieve tool
77  if ( m_cellWeight.empty() || (m_cellWeight.retrieve()).isFailure() )
78  {
79  report << MSG::ERROR
80  << "*** configuration insufficient *** "
81  << "no hadronic cell calibration tool configured"
82  << endmsg;
83  return StatusCode::FAILURE;
84  }
85 
86  //
87  return StatusCode::SUCCESS;
88 }
89 
91 // Execution //
93 
95 CaloClusterCellWeightCalib::execute(const EventContext& /*ctx*/,
96  xAOD::CaloCluster* pClus) const
97 {
98 
99  // retrieve raw cluster signals
100  double clusterE(pClus->rawE());
101  double clusterEta(pClus->rawEta());
102  double clusterPhi(pClus->rawPhi());
103 
104  // report << MSG::INFO << "<UNCALIBRATED> cluster kinematics ("
105  // << pClus->e() << ","
106  // << pClus->eta() << ","
107  // << pClus->phi() << ")" << endmsg;
108 
110 
111  pClus->setE(clusterE);
112  pClus->setEta(clusterEta);
113  pClus->setPhi(clusterPhi);
114 
115  // report << MSG::INFO << "<ALTCALIBRATED> cluster kinematics, initial ("
116  // << pClus->e() << "/" << clusterE << ","
117  // << pClus->eta() << "/" << clusterEta << ","
118  // << pClus->phi() << "/" << clusterPhi << ")" << endmsg;
119 
120  // calculate new 4-vector
121  StatusCode checkOut(StatusCode::SUCCESS);
122  if ( m_calibNoiseLikeAll )
123  {
124  checkOut = (this->*m_calc)(pClus);
125  }
126  else
127  {
128  checkOut = pClus->e() > 0.
129  ? (this->*m_calc)(pClus) : (this->*m_calc_noise)(pClus);
130  }
131 
132  // report << MSG::INFO << "<ALTCALIBRATED> cluster kinematics, final ("
133  // << pClus->e() << ","
134  // << pClus->eta() << ","
135  // << pClus->phi() << ")" << endmsg;
136 
137  // check result
138  if ( checkOut.isFailure() )
139  {
140  msg(MSG::WARNING)
141  << "problem in calculation of cell weighted signal state"
142  << endmsg;
143  return StatusCode::SUCCESS;
144  }
145  else
146  {
147  // change reco status
149  return checkOut;
150  }
151 }
152 
154 // Internal Use: Setup //
156 
158 {
159  std::string conf;
160  std::string tag("all");
161  return this->setup(m_directionCalculation,tag,m_calc,conf,report)
162  ? StatusCode::SUCCESS : StatusCode::FAILURE;
163 }
164 
166 {
167  std::string conf;
168  std::string aboveTag("above threshold");
169  std::string belowTag("below threshold");
170  return
171  this->setup(m_directionCalculation,aboveTag,m_calc,conf,report) &&
173  ? StatusCode::SUCCESS : StatusCode::FAILURE;
174 }
175 
176 bool CaloClusterCellWeightCalib::setup(const std::string& name,
177  const std::string& tag,
178  CALCULATOR& calc,
179  std::string& conf,
180  MsgStream& report)
181 {
183  {
184  report << MSG::INFO
185  << "cluster direction ("
186  << tag
187  << ") from positive cells only"
188  << endmsg;
189  conf = name;
193  return true;
194  }
196  {
197  report << MSG::INFO
198  << "cluster direction ("
199  << tag
200  << ") from absolute cell signals"
201  << endmsg;
202  conf = name;
206  return true;
207  }
209  {
210  report << MSG::INFO
211  << "cluster direction ("
212  << tag
213  << ") from raw signals (unchanged by this tool)"
214  << endmsg;
215  conf = name;
219  return true;
220  }
221  else
222  {
223  report << MSG::WARNING
224  << "invalid configuration, use default!"
225  << endmsg;
226  return this->setup(m_defName,tag,calc,conf,report);
227  }
228 }
229 
230 bool CaloClusterCellWeightCalib::cmpNoCase(const std::string& a,
231  const std::string& b)
232 {
233  // same length required
234  if ( a.length() != b.length() ) return false;
235  // adapted from Stroustrup, The C++ Programming Language, Special
236  // Edition, (2001 printing), p 591.
237  std::string::const_iterator p1(a.begin());
238  std::string::const_iterator p2(b.begin());
239  while ( p1 != a.end() && p2 != b.end() )
240  {
241  if ( std::toupper(*p1) != std::toupper(*p2) ) return false;
242  ++p1;
243  ++p2;
244  }
245  return true;
246 }
247 
249 // Internal Use: Direction Calculators //
251 
252 // -- keep em scale direction, use geometrical cell signal weights
254 {
255  // loop cells in clusters
256  double eCal(0.);
259  for ( ; fCell != lCell; fCell++ )
260  {
261  const CaloCell* cell = *fCell;
262  //
263  eCal +=
264  fCell.weight() *
265  cell->e() *
266  m_cellWeight->wtCell(cell);
267  }
268  // set cluster kinematics (cluster is in ALTCALIBRATED state
269  pClus->setE(eCal);
270  //
271  return StatusCode::SUCCESS;
272 }
273 // -- keep em scale direction, ignore geometrical cell signal weights
275 {
276  // loop cells in clusters
277  double eCal(0.);
278  for (const CaloCell* cell : *pClus)
279  {
280  //
281  eCal +=
282  cell->e() *
283  m_cellWeight->wtCell(cell);
284  }
285  // set cluster kinematics (cluster is in ALTCALIBRATED state
286  pClus->setE(eCal);
287  //
288  return StatusCode::SUCCESS;
289 }
290 
291 // -- direction from signals above threshold, use geo weights
293 {
294  // loop cells in clusters
295  double eCal(0.);
296  double eRef(0.);
297  double etaRef(0.);
298  double phiRef(0.);
301  for ( ; fCell != lCell; fCell++ )
302  {
303  const CaloCell* cell = *fCell;
304  //
305  double eWght(fCell.weight() *
306  cell->e() *
307  m_cellWeight->wtCell(cell));
308  eCal += eWght;
309  //
310  if ( eWght > m_eThreshold )
311  {
312  double phiCell(proxim(cell->phi(),phiRef));
313  etaRef += cell->eta() * eWght;
314  phiRef = CaloPhiRange::fix((phiCell * eWght + eRef * phiRef)/(eRef+eWght));
315  eRef += eWght;
316  }
317  }
318  // set cluster kinematics
319  pClus->setE(eCal);
320  if ( eRef > 0. )
321  {
322  pClus->setEta(etaRef/eRef);
323  pClus->setPhi(phiRef);
324  }
325  //
326  return StatusCode::SUCCESS;
327 }
328 // -- direction from signals above threshold, ignore geo weights
330 {
331  // loop cells in clusters
332  double eCal(0.);
333  double eRef(0.);
334  double etaRef(0.);
335  double phiRef(0.);
336  for (const CaloCell* cell : *pClus)
337  {
338  //
339  double eWght(cell->e() *
340  m_cellWeight->wtCell(cell));
341  eCal += eWght;
342  //
343  if ( eWght > m_eThreshold )
344  {
345  double phiCell(proxim(cell->phi(),phiRef));
346  etaRef += cell->eta() * eWght;
347  phiRef = CaloPhiRange::fix((phiCell * eWght + eRef * phiRef)/(eRef+eWght));
348  eRef += eWght;
349  }
350  }
351  // set cluster kinematics
352  pClus->setE(eCal);
353  if ( eRef > 0. )
354  {
355  pClus->setEta(etaRef/eRef);
356  pClus->setPhi(phiRef);
357  }
358  //
359  return StatusCode::SUCCESS;
360 }
361 
363 {
364  // loop cells in clusters
365  double eCal(0.);
366  double eRef(0.);
367  double etaRef(0.);
368  double phiRef(0.);
371  for ( ; fCell != lCell; fCell++ )
372  {
373  const CaloCell* cell = *fCell;
374  //
375  double eWght(fCell.weight() *
376  cell->e() *
377  m_cellWeight->wtCell(cell));
378  double phiCell(proxim(cell->phi(),phiRef));
379  //
380  eCal += eWght;
381  eWght = fabs(eWght);
382  etaRef += cell->eta() * eWght;
383  phiRef = CaloPhiRange::fix((phiCell * eWght + eRef * phiRef)/(eRef+eWght));
384  eRef += eWght;
385  }
386  // set cluster kinematics
387  pClus->setE(eCal);
388  if ( eRef > 0. )
389  {
390  pClus->setEta(etaRef/eRef);
391  pClus->setPhi(phiRef);
392  }
393  //
394  return StatusCode::SUCCESS;
395 }
396 
398 {
399  // loop cells in clusters
400  double eCal(0.);
401  double eRef(0.);
402  double etaRef(0.);
403  double phiRef(0.);
404  for (const CaloCell* cell : *pClus)
405  {
406  //
407  double eWght(cell->e() * m_cellWeight->wtCell(cell));
408  double phiCell(proxim(cell->phi(),phiRef));
409  //
410  eCal += eWght;
411  eWght = fabs(eWght);
412  etaRef += cell->eta() * eWght;
413  phiRef = CaloPhiRange::fix((phiCell * eWght + eRef * phiRef)/(eRef+eWght));
414  eRef += eWght;
415  }
416  // set cluster kinematics
417  pClus->setE(eCal);
418  if ( eRef > 0. )
419  {
420  pClus->setEta(etaRef/eRef);
421  pClus->setPhi(phiRef);
422  }
423  //
424  return StatusCode::SUCCESS;
425 }
CaloClusterCellWeightCalib::f_dirPosNW
StatusCode f_dirPosNW(xAOD::CaloCluster *pClus) const
Calculator implementation for direction from positive signal.
Definition: CaloClusterCellWeightCalib.cxx:329
xAOD::CaloCluster_v1::rawE
flt_t rawE() const
CaloClusterChangeSignalState
Helper to temporarily change the signal state of a cluster.
Definition: CaloClusterChangeSignalState.h:19
xAOD::CaloCluster_v1::cell_begin
const_cell_iterator cell_begin() const
Iterator of the underlying CaloClusterCellLink (const version)
Definition: CaloCluster_v1.h:812
xAOD::CaloCluster_v1::rawEta
flt_t rawEta() const
Get in signal state UNCALIBRATED.
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
CaloClusterCellWeightCalib::f_dirRaw
StatusCode f_dirRaw(xAOD::CaloCluster *pClus) const
Calculator implementation for energy only update.
Definition: CaloClusterCellWeightCalib.cxx:253
CaloRecoStatus::setStatus
virtual void setStatus(const StatusIndicator &statusIndicator)
Set status.
Definition: CaloRecoStatus.h:107
CaloClusterCellWeightCalib::m_directionCalculation
std::string m_directionCalculation
Property controlling negative signal handling.
Definition: CaloClusterCellWeightCalib.h:49
CaloRecoStatus::CALIBRATEDALT
@ CALIBRATEDALT
Definition: CaloRecoStatus.h:44
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloClusterCellWeightCalib::f_dirAbs
StatusCode f_dirAbs(xAOD::CaloCluster *pClus) const
Calculator implementation for direction from absolute signal.
Definition: CaloClusterCellWeightCalib.cxx:362
proxim
double proxim(double b, double a)
Definition: proxim.h:17
CaloClusterCellWeightCalib::setupSpc
StatusCode setupSpc(MsgStream &report)
Setup for different calculation for noise clusters.
Definition: CaloClusterCellWeightCalib.cxx:165
checkTP.report
report
Definition: checkTP.py:127
CaloClusterProcessor
Definition: CaloClusterProcessor.h:33
CaloClusterCellWeightCalib::m_defName
static const std::string m_defName
Negative signal handling: default tag.
Definition: CaloClusterCellWeightCalib.h:92
CaloClusterCellWeightCalib::m_posName
static const std::string m_posName
Negative signal handling: positive signal tag.
Definition: CaloClusterCellWeightCalib.h:94
CaloClusterCellWeightCalib.h
CaloClusterCellWeightCalib::m_cellWeight
ToolHandle< ICellWeightTool > m_cellWeight
Handle for cell weight tool.
Definition: CaloClusterCellWeightCalib.h:87
CaloClusterCellWeightCalib::f_dirAbsNW
StatusCode f_dirAbsNW(xAOD::CaloCluster *pClus) const
Calculator implementation for direction from absolute signal.
Definition: CaloClusterCellWeightCalib.cxx:397
CaloClusterCellWeightCalib::m_eThreshold
double m_eThreshold
Energy threshold for direction calculation.
Definition: CaloClusterCellWeightCalib.h:72
proxim.h
xAOD::CaloCluster_v1::setE
void setE(flt_t)
Definition: CaloCluster_v1.cxx:375
CaloClusterCellWeightCalib::m_ignoreGeoWghts
bool m_ignoreGeoWghts
Flag to ignore geometrical cell weights in clusters.
Definition: CaloClusterCellWeightCalib.h:84
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
python.ConfigurableDb.conf
def conf
Definition: ConfigurableDb.py:282
CaloClusterCellWeightCalib::m_rawName
static const std::string m_rawName
Negative signal handling: raw signal tag.
Definition: CaloClusterCellWeightCalib.h:98
CaloClusterCellWeightCalib::m_calibNoiseLikeAll
bool m_calibNoiseLikeAll
Property controlling calibration of noise clusters.
Definition: CaloClusterCellWeightCalib.h:58
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
CaloClusterCellWeightCalib::f_dirPos
StatusCode f_dirPos(xAOD::CaloCluster *pClus) const
Calculator implementation for direction from positive signal.
Definition: CaloClusterCellWeightCalib.cxx:292
CaloClusterCellWeightCalib::initialize
virtual StatusCode initialize() override
Tool initialization.
Definition: CaloClusterCellWeightCalib.cxx:60
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CaloClusterCellWeightCalib::~CaloClusterCellWeightCalib
virtual ~CaloClusterCellWeightCalib() override
Base tool destructor.
CaloClusterCellWeightCalib::setup
bool setup(const std::string &name, const std::string &tag, CALCULATOR &calc, std::string &conf, MsgStream &report)
Common setup function.
Definition: CaloClusterCellWeightCalib.cxx:176
CaloClusterCellWeightCalib::m_noiseDirectionCalculation
std::string m_noiseDirectionCalculation
Property controlling calibration method for noise clusters.
Definition: CaloClusterCellWeightCalib.h:69
CaloPhiRange.h
CaloPhiRange class declaration.
CaloClusterCellWeightCalib::f_dirRawNW
StatusCode f_dirRawNW(xAOD::CaloCluster *pClus) const
Calculator implementation for energy only update.
Definition: CaloClusterCellWeightCalib.cxx:274
CaloPhiRange::fix
static double fix(double phi)
Definition: CaloPhiRange.cxx:14
CaloRecoStatus.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAOD::CaloCluster_v1::recoStatus
CaloRecoStatus & recoStatus()
Accesssor to CaloRecoStatus (non-const)
Definition: CaloCluster_v1.h:840
CaloClusterCellWeightCalib::execute
virtual StatusCode execute(const EventContext &ctx, xAOD::CaloCluster *theCluster) const override
Execute on a single cluster.
Definition: CaloClusterCellWeightCalib.cxx:95
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
CaloClusterCellWeightCalib::m_absName
static const std::string m_absName
Negative signal handling: absolute signal tag.
Definition: CaloClusterCellWeightCalib.h:96
CaloClusterChangeSignalState.h
a
TList * a
Definition: liststreamerinfos.cxx:10
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
xAOD::CaloCluster_v1::rawPhi
flt_t rawPhi() const
Get in signal state UNCALIBRATED.
xAOD::CaloCluster_v1::ALTCALIBRATED
@ ALTCALIBRATED
Definition: CaloCluster_v1.h:308
CaloClusterCellWeightCalib::m_calc
CALCULATOR m_calc
Pointer to direction calculation implementation.
Definition: CaloClusterCellWeightCalib.h:161
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::CaloCluster_v1::cell_end
const_cell_iterator cell_end() const
Definition: CaloCluster_v1.h:813
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
xAOD::CaloCluster_v1::setPhi
bool setPhi(const CaloSample sampling, const float phi)
Set in a given sampling. Returns false if the sample isn't part of the cluster.
Definition: CaloCluster_v1.cxx:556
CaloClusterCellWeightCalib::cmpNoCase
static bool cmpNoCase(const std::string &a, const std::string &b)
Helper for non-case sensitive string comparison.
Definition: CaloClusterCellWeightCalib.cxx:230
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
xAOD::CaloCluster_v1::setEta
bool setEta(const CaloSample sampling, const float eta)
Set in a given sampling. Returns false if the sample isn't part of the cluster.
Definition: CaloCluster_v1.cxx:541
CaloClusterCellWeightCalib::CaloClusterCellWeightCalib
CaloClusterCellWeightCalib(const std::string &type, const std::string &name, const IInterface *pParent)
Algorithm tool constructor.
Definition: CaloClusterCellWeightCalib.cxx:32
beamspotnt.calc
calc
Definition: bin/beamspotnt.py:1252
CaloClusterCellWeightCalib::m_calc_noise
CALCULATOR m_calc_noise
Pointer to direction calculation for noise clusters.
Definition: CaloClusterCellWeightCalib.h:164
CaloClusterCellWeightCalib::setupAll
StatusCode setupAll(MsgStream &report)
Setup for calculation for all or non-noise clusters.
Definition: CaloClusterCellWeightCalib.cxx:157
xAOD::CaloCluster_v1::e
virtual double e() const
The total energy of the particle.
Definition: CaloCluster_v1.cxx:265