ATLAS Offline Software
Loading...
Searching...
No Matches
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
15#include "CaloEvent/CaloCluster.h"
16
18
19#include <cstdlib>
20
21std::string const CaloClusterCellWeightCalib::m_posName = "Signal";
22std::string const CaloClusterCellWeightCalib::m_absName = "AbsSignal";
23std::string const CaloClusterCellWeightCalib::m_rawName = "RawSignal";
24
25std::string const CaloClusterCellWeightCalib::m_defName = m_absName;
26
28// Constructor & Destructor //
30
32CaloClusterCellWeightCalib(const std::string& type,
33 const std::string& name,
34 const IInterface* pParent)
35 : CaloClusterProcessor(type,name,pParent)
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
65 StatusCode checkOut = m_calibNoiseLikeAll
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
94StatusCode
95CaloClusterCellWeightCalib::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
157StatusCode CaloClusterCellWeightCalib::setupAll(MsgStream& report)
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
165StatusCode CaloClusterCellWeightCalib::setupSpc(MsgStream& report)
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) &&
172 this->setup(m_noiseDirectionCalculation,belowTag,m_calc_noise,conf,report)
173 ? StatusCode::SUCCESS : StatusCode::FAILURE;
174}
175
176bool 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;
190 calc = m_ignoreGeoWghts
193 return true;
194 }
196 {
197 report << MSG::INFO
198 << "cluster direction ("
199 << tag
200 << ") from absolute cell signals"
201 << endmsg;
202 conf = name;
203 calc = m_ignoreGeoWghts
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;
216 calc = m_ignoreGeoWghts
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
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}
#define endmsg
CaloPhiRange class declaration.
static Double_t a
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
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.
bool m_ignoreGeoWghts
Flag to ignore geometrical cell weights in clusters.
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.
static const std::string m_defName
Negative signal handling: default tag.
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 const std::string m_posName
Negative signal handling: positive signal tag.
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.
ToolHandle< ICellWeightTool > m_cellWeight
Handle for cell weight tool.
double m_eThreshold
Energy threshold for direction calculation.
bool m_calibNoiseLikeAll
Property controlling calibration of noise clusters.
StatusCode setupSpc(MsgStream &report)
Setup for different calculation for noise clusters.
CALCULATOR m_calc_noise
Pointer to direction calculation for noise clusters.
static const std::string m_rawName
Negative signal handling: raw signal tag.
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 const std::string m_absName
Negative signal handling: absolute signal tag.
virtual ~CaloClusterCellWeightCalib() override
Base tool destructor.
std::string m_noiseDirectionCalculation
Property controlling calibration method for noise clusters.
std::string m_directionCalculation
Property controlling negative signal handling.
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