ATLAS Offline Software
Loading...
Searching...
No Matches
CaloClusterCellWeightCalib.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6
7#include "CLHEP/Units/SystemOfUnits.h"
8
10
12
15#include "CaloEvent/CaloCluster.h"
16
18
19#include <cstdlib>
20
22// Constructor & Destructor //
24
26CaloClusterCellWeightCalib(const std::string& type,
27 const std::string& name,
28 const IInterface* pParent)
29 : CaloClusterProcessor(type,name,pParent)
30{
31}
32
34= default;
35
37// Initialization //
39
41{
42 MsgStream report(msgSvc(),name());
43
44 // configure direction calculations
45 StatusCode checkOut = m_calibNoiseLikeAll
46 ? this->setupAll(report) // all clusters the same
47 : this->setupSpc(report); // dedicated noise cluster treatment
48 if ( checkOut.isFailure() )
49 {
50 report << MSG::ERROR
51 << "failed to configure direction calculations."
52 << endmsg;
53 return StatusCode::FAILURE;
54 }
55
56 // retrieve tool
57 if ( m_cellWeight.empty() || (m_cellWeight.retrieve()).isFailure() )
58 {
59 report << MSG::ERROR
60 << "*** configuration insufficient *** "
61 << "no hadronic cell calibration tool configured"
62 << endmsg;
63 return StatusCode::FAILURE;
64 }
65
66 //
67 return StatusCode::SUCCESS;
68}
69
71// Execution //
73
74StatusCode
75CaloClusterCellWeightCalib::execute(const EventContext& /*ctx*/,
76 xAOD::CaloCluster* pClus) const
77{
78
79 // retrieve raw cluster signals
80 double clusterE(pClus->rawE());
81 double clusterEta(pClus->rawEta());
82 double clusterPhi(pClus->rawPhi());
83
84 // report << MSG::INFO << "<UNCALIBRATED> cluster kinematics ("
85 // << pClus->e() << ","
86 // << pClus->eta() << ","
87 // << pClus->phi() << ")" << endmsg;
88
90
91 pClus->setE(clusterE);
92 pClus->setEta(clusterEta);
93 pClus->setPhi(clusterPhi);
94
95 // report << MSG::INFO << "<ALTCALIBRATED> cluster kinematics, initial ("
96 // << pClus->e() << "/" << clusterE << ","
97 // << pClus->eta() << "/" << clusterEta << ","
98 // << pClus->phi() << "/" << clusterPhi << ")" << endmsg;
99
100 // calculate new 4-vector
101 StatusCode checkOut(StatusCode::SUCCESS);
102 if ( m_calibNoiseLikeAll )
103 {
104 checkOut = (this->*m_calc)(pClus);
105 }
106 else
107 {
108 checkOut = pClus->e() > 0.
109 ? (this->*m_calc)(pClus) : (this->*m_calc_noise)(pClus);
110 }
111
112 // report << MSG::INFO << "<ALTCALIBRATED> cluster kinematics, final ("
113 // << pClus->e() << ","
114 // << pClus->eta() << ","
115 // << pClus->phi() << ")" << endmsg;
116
117 // check result
118 if ( checkOut.isFailure() )
119 {
120 msg(MSG::WARNING)
121 << "problem in calculation of cell weighted signal state"
122 << endmsg;
123 return StatusCode::SUCCESS;
124 }
125 else
126 {
127 // change reco status
129 return checkOut;
130 }
131}
132
134// Internal Use: Setup //
136
137StatusCode CaloClusterCellWeightCalib::setupAll(MsgStream& report)
138{
139 std::string conf;
140 std::string tag("all");
141 return this->setup(m_directionCalculation,tag,m_calc,conf,report)
142 ? StatusCode::SUCCESS : StatusCode::FAILURE;
143}
144
145StatusCode CaloClusterCellWeightCalib::setupSpc(MsgStream& report)
146{
147 std::string conf;
148 std::string aboveTag("above threshold");
149 std::string belowTag("below threshold");
150 return
151 this->setup(m_directionCalculation,aboveTag,m_calc,conf,report) &&
152 this->setup(m_noiseDirectionCalculation,belowTag,m_calc_noise,conf,report)
153 ? StatusCode::SUCCESS : StatusCode::FAILURE;
154}
155
156bool CaloClusterCellWeightCalib::setup(const std::string& name,
157 const std::string& tag,
158 CALCULATOR& calc,
159 std::string& conf,
160 MsgStream& report)
161{
163 {
164 report << MSG::INFO
165 << "cluster direction ("
166 << tag
167 << ") from positive cells only"
168 << endmsg;
169 conf = name;
170 calc = m_ignoreGeoWghts
173 return true;
174 }
176 {
177 report << MSG::INFO
178 << "cluster direction ("
179 << tag
180 << ") from absolute cell signals"
181 << endmsg;
182 conf = name;
183 calc = m_ignoreGeoWghts
186 return true;
187 }
189 {
190 report << MSG::INFO
191 << "cluster direction ("
192 << tag
193 << ") from raw signals (unchanged by this tool)"
194 << endmsg;
195 conf = name;
196 calc = m_ignoreGeoWghts
199 return true;
200 }
201 else
202 {
203 report << MSG::WARNING
204 << "invalid configuration, use default!"
205 << endmsg;
206 return this->setup(s_defName,tag,calc,conf,report);
207 }
208}
209
211 const std::string& b)
212{
213 // same length required
214 if ( a.length() != b.length() ) return false;
215 // adapted from Stroustrup, The C++ Programming Language, Special
216 // Edition, (2001 printing), p 591.
217 std::string::const_iterator p1(a.begin());
218 std::string::const_iterator p2(b.begin());
219 while ( p1 != a.end() && p2 != b.end() )
220 {
221 if ( std::toupper(*p1) != std::toupper(*p2) ) return false;
222 ++p1;
223 ++p2;
224 }
225 return true;
226}
227
229// Internal Use: Direction Calculators //
231
232// -- keep em scale direction, use geometrical cell signal weights
234{
235 // loop cells in clusters
236 double eCal(0.);
239 for ( ; fCell != lCell; fCell++ )
240 {
241 const CaloCell* cell = *fCell;
242 //
243 eCal +=
244 fCell.weight() *
245 cell->e() *
246 m_cellWeight->wtCell(cell);
247 }
248 // set cluster kinematics (cluster is in ALTCALIBRATED state
249 pClus->setE(eCal);
250 //
251 return StatusCode::SUCCESS;
252}
253// -- keep em scale direction, ignore geometrical cell signal weights
255{
256 // loop cells in clusters
257 double eCal(0.);
258 for (const CaloCell* cell : *pClus)
259 {
260 //
261 eCal +=
262 cell->e() *
263 m_cellWeight->wtCell(cell);
264 }
265 // set cluster kinematics (cluster is in ALTCALIBRATED state
266 pClus->setE(eCal);
267 //
268 return StatusCode::SUCCESS;
269}
270
271// -- direction from signals above threshold, use geo weights
273{
274 // loop cells in clusters
275 double eCal(0.);
276 double eRef(0.);
277 double etaRef(0.);
278 double phiRef(0.);
281 for ( ; fCell != lCell; fCell++ )
282 {
283 const CaloCell* cell = *fCell;
284 //
285 double eWght(fCell.weight() *
286 cell->e() *
287 m_cellWeight->wtCell(cell));
288 eCal += eWght;
289 //
290 if ( eWght > m_eThreshold )
291 {
292 double phiCell(proxim(cell->phi(),phiRef));
293 etaRef += cell->eta() * eWght;
294 phiRef = CaloPhiRange::fix((phiCell * eWght + eRef * phiRef)/(eRef+eWght));
295 eRef += eWght;
296 }
297 }
298 // set cluster kinematics
299 pClus->setE(eCal);
300 if ( eRef > 0. )
301 {
302 pClus->setEta(etaRef/eRef);
303 pClus->setPhi(phiRef);
304 }
305 //
306 return StatusCode::SUCCESS;
307}
308// -- direction from signals above threshold, ignore geo weights
310{
311 // loop cells in clusters
312 double eCal(0.);
313 double eRef(0.);
314 double etaRef(0.);
315 double phiRef(0.);
316 for (const CaloCell* cell : *pClus)
317 {
318 //
319 double eWght(cell->e() *
320 m_cellWeight->wtCell(cell));
321 eCal += eWght;
322 //
323 if ( eWght > m_eThreshold )
324 {
325 double phiCell(proxim(cell->phi(),phiRef));
326 etaRef += cell->eta() * eWght;
327 phiRef = CaloPhiRange::fix((phiCell * eWght + eRef * phiRef)/(eRef+eWght));
328 eRef += eWght;
329 }
330 }
331 // set cluster kinematics
332 pClus->setE(eCal);
333 if ( eRef > 0. )
334 {
335 pClus->setEta(etaRef/eRef);
336 pClus->setPhi(phiRef);
337 }
338 //
339 return StatusCode::SUCCESS;
340}
341
343{
344 // loop cells in clusters
345 double eCal(0.);
346 double eRef(0.);
347 double etaRef(0.);
348 double phiRef(0.);
351 for ( ; fCell != lCell; fCell++ )
352 {
353 const CaloCell* cell = *fCell;
354 //
355 double eWght(fCell.weight() *
356 cell->e() *
357 m_cellWeight->wtCell(cell));
358 double phiCell(proxim(cell->phi(),phiRef));
359 //
360 eCal += eWght;
361 eWght = fabs(eWght);
362 etaRef += cell->eta() * eWght;
363 phiRef = CaloPhiRange::fix((phiCell * eWght + eRef * phiRef)/(eRef+eWght));
364 eRef += eWght;
365 }
366 // set cluster kinematics
367 pClus->setE(eCal);
368 if ( eRef > 0. )
369 {
370 pClus->setEta(etaRef/eRef);
371 pClus->setPhi(phiRef);
372 }
373 //
374 return StatusCode::SUCCESS;
375}
376
378{
379 // loop cells in clusters
380 double eCal(0.);
381 double eRef(0.);
382 double etaRef(0.);
383 double phiRef(0.);
384 for (const CaloCell* cell : *pClus)
385 {
386 //
387 double eWght(cell->e() * m_cellWeight->wtCell(cell));
388 double phiCell(proxim(cell->phi(),phiRef));
389 //
390 eCal += eWght;
391 eWght = fabs(eWght);
392 etaRef += cell->eta() * eWght;
393 phiRef = CaloPhiRange::fix((phiCell * eWght + eRef * phiRef)/(eRef+eWght));
394 eRef += eWght;
395 }
396 // set cluster kinematics
397 pClus->setE(eCal);
398 if ( eRef > 0. )
399 {
400 pClus->setEta(etaRef/eRef);
401 pClus->setPhi(phiRef);
402 }
403 //
404 return StatusCode::SUCCESS;
405}
#define endmsg
CaloPhiRange class declaration.
static Double_t a
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
StatusCode f_dirAbs(xAOD::CaloCluster *pClus) const
Calculator implementation for direction from absolute signal.
StatusCode f_dirRaw(xAOD::CaloCluster *pClus) const
Calculator implementation for energy only update.
StatusCode f_dirPos(xAOD::CaloCluster *pClus) const
Calculator implementation for direction from positive signal.
StatusCode(CaloClusterCellWeightCalib::* CALCULATOR)(xAOD::CaloCluster *pClus) const
Processor type for cluster calibration.
StatusCode f_dirPosNW(xAOD::CaloCluster *pClus) const
Calculator implementation for direction from positive signal.
StatusCode setupAll(MsgStream &report)
Setup for calculation for all or non-noise clusters.
Gaudi::Property< double > m_eThreshold
Energy threshold for direction calculation.
Gaudi::Property< std::string > m_directionCalculation
Property controlling negative signal handling.
StatusCode f_dirRawNW(xAOD::CaloCluster *pClus) const
Calculator implementation for energy only update.
virtual StatusCode initialize() override
Tool initialization.
StatusCode f_dirAbsNW(xAOD::CaloCluster *pClus) const
Calculator implementation for direction from absolute signal.
static constexpr std::string s_posName
Negative signal handling: positive signal tag.
Gaudi::Property< bool > m_ignoreGeoWghts
Flag to ignore geometrical cell weights in clusters.
CaloClusterCellWeightCalib(const std::string &type, const std::string &name, const IInterface *pParent)
Algorithm tool constructor.
bool setup(const std::string &name, const std::string &tag, CALCULATOR &calc, std::string &conf, MsgStream &report)
Common setup function.
static constexpr std::string s_defName
Negative signal handling: default tag.
static constexpr std::string s_absName
Negative signal handling: absolute signal tag.
Gaudi::Property< bool > m_calibNoiseLikeAll
Property controlling calibration of noise clusters.
ToolHandle< ICellWeightTool > m_cellWeight
Handle for cell weight tool.
StatusCode setupSpc(MsgStream &report)
Setup for different calculation for noise clusters.
Gaudi::Property< std::string > m_noiseDirectionCalculation
Property controlling calibration method for noise clusters.
CALCULATOR m_calc_noise
Pointer to direction calculation for noise clusters.
static bool cmpNoCase(const std::string &a, const std::string &b)
Helper for non-case sensitive string comparison.
CALCULATOR m_calc
Pointer to direction calculation implementation.
virtual StatusCode execute(const EventContext &ctx, xAOD::CaloCluster *theCluster) const override
Execute on a single cluster.
static constexpr std::string s_rawName
Negative signal handling: raw signal tag.
virtual ~CaloClusterCellWeightCalib() override
Base tool destructor.
Helper to temporarily change the signal state of a cluster.
CaloClusterProcessor(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
static double fix(double phi)
virtual void setStatus(const StatusIndicator &statusIndicator)
Set status.
flt_t rawE() const
bool setPhi(const CaloSample sampling, const float phi)
Set in a given sampling. Returns false if the sample isn't part of the cluster.
flt_t rawPhi() const
Get in signal state UNCALIBRATED.
CaloClusterCellLink::iterator cell_iterator
Iterator of the underlying CaloClusterCellLink (non-const version)
flt_t rawEta() const
Get in signal state UNCALIBRATED.
virtual double e() const
The total energy of the particle.
const_cell_iterator cell_end() const
bool setEta(const CaloSample sampling, const float eta)
Set in a given sampling. Returns false if the sample isn't part of the cluster.
const_cell_iterator cell_begin() const
Iterator of the underlying CaloClusterCellLink (const version)
CaloRecoStatus & recoStatus()
Accesssor to CaloRecoStatus (non-const)
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
double proxim(double b, double a)
Definition proxim.h:17
MsgStream & msg
Definition testRead.cxx:32