ATLAS Offline Software
Loading...
Searching...
No Matches
eflowUtil.h
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 * eflowUtil.h
7 *
8 * Created on: 09.08.2013
9 * Author: tlodd
10 */
11
12#ifndef EFLOWREC_EFLOWUTIL_H
13#define EFLOWREC_EFLOWUTIL_H
14
15#include <cmath>
16#include <string>
17
22public:
23eflowAzimuth(double phi): m_value(phi) { if (phi != -999. && !std::isnan(phi)) adjustRange(); }
24
25 inline double operator ()() const { return m_value; }
26 inline double operator =(double phi) {
27 m_value = phi;
29 return m_value;
30 }
31
35 return *this;
36 }
40 return *this;
41 }
42
43 inline double getAbsDifference(const eflowAzimuth& other) const {
44 double plainAbsDifference = std::abs(m_value - other.m_value);
45 return plainAbsDifference <= M_PI ? plainAbsDifference : 2*M_PI - plainAbsDifference;
46 }
47
48 inline double cycle(const eflowAzimuth& other) { return cycle(other.m_value); }
49 inline double cycle(double phi) {
50 double plainDifference = phi-m_value;
51 if (plainDifference > M_PI) {
52 return m_value+2.0*M_PI;
53 } else if (plainDifference < -M_PI) {
54 return m_value-2.0*M_PI;
55 } else {
56 return m_value;
57 }
58 }
59
60private:
61 double m_value{};
62
63 inline double adjustRange(double a) {
64 if (a <= -M_PI) {
65 return a+(2*M_PI*std::floor(-(a-M_PI)/(2*M_PI)));
66 } else if (a > M_PI) {
67 return a-(2*M_PI*std::floor((a+M_PI)/(2*M_PI)));
68 } else {
69 return a;
70 }
71 }
72 inline void adjustRange() {
73 if (m_value <= -M_PI) {
74 m_value+=(2*M_PI*std::floor(-(m_value-M_PI)/(2*M_PI)));
75 } else if (m_value > M_PI) {
76 m_value-=(2*M_PI*std::floor((m_value+M_PI)/(2*M_PI)));
77 }
78 }
79
80};
81
83public:
85 eflowEtaPhiPosition(double eta, double phi): m_eta(eta), m_phi(phi) {}
86
87 inline double getEta() const { return m_eta; }
88 inline eflowAzimuth getPhi() const { return m_phi; }
89 inline double getPhiD() const { return m_phi(); }
90
91 inline double dRSq(const eflowEtaPhiPosition& other) const {
92 double dEta(m_eta-other.m_eta);
93 double dPhi(m_phi.getAbsDifference(other.m_phi));
94 return dEta*dEta + dPhi*dPhi;
95 }
96 inline double dR(const eflowEtaPhiPosition& other) const { return std::sqrt(this->dRSq(other)); }
97
98private:
99 double m_eta{NAN};
101};
102
106template <class T>
108public:
109 eflowRangeBase() = default;
110 eflowRangeBase(const T& min, const T& max): m_min(min), m_max(max) { }
111
112 inline void setCenterAndWidth(T center, double width) { m_min = center - width/2; m_max = m_min + width; }
113 inline void shift(double shift) { m_min += shift; m_max += shift; }
114
115 inline T getMax() const { return m_max; }
116 inline T getMin() const { return m_min; }
117
118 inline T getCenter() const { return (m_max + m_min)/2; }
119 inline T getWidth() const { return (m_max - m_min); }
120
121 bool contains(const T& x) { return ( (m_min < x) && (m_max > x) ); }
122
123 std::string print() const {
124 std::string result = "[";
125 result += std::to_string(m_min);
126 result += ", ";
127 result += std::to_string(m_max);
128 result += ']';
129 return result;
130 }
131
132private:
133 T m_min{NAN};
134 T m_max{NAN};
135};
137
138#endif /* EFLOWREC_EFLOWUTIL_H */
#define M_PI
Scalar eta() const
pseudorapidity method
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
Scalar phi() const
phi method
static Double_t a
const double width
#define x
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
eflowAzimuth represents phi and has kinematic functions which correctly deal with phi wraparound etc.
Definition eflowUtil.h:21
eflowAzimuth operator-=(double deltaPhi)
Definition eflowUtil.h:37
double cycle(const eflowAzimuth &other)
Definition eflowUtil.h:48
void adjustRange()
Definition eflowUtil.h:72
eflowAzimuth operator+=(double deltaPhi)
Definition eflowUtil.h:32
double m_value
Definition eflowUtil.h:61
double getAbsDifference(const eflowAzimuth &other) const
Definition eflowUtil.h:43
double operator=(double phi)
Definition eflowUtil.h:26
double operator()() const
Definition eflowUtil.h:25
double adjustRange(double a)
Definition eflowUtil.h:63
eflowAzimuth(double phi)
Definition eflowUtil.h:23
double cycle(double phi)
Definition eflowUtil.h:49
eflowAzimuth getPhi() const
Definition eflowUtil.h:88
eflowEtaPhiPosition(double eta, double phi)
Definition eflowUtil.h:85
double dR(const eflowEtaPhiPosition &other) const
Definition eflowUtil.h:96
double dRSq(const eflowEtaPhiPosition &other) const
Definition eflowUtil.h:91
double getPhiD() const
Definition eflowUtil.h:89
eflowEtaPhiPosition()=default
eflowAzimuth m_phi
Definition eflowUtil.h:100
double getEta() const
Definition eflowUtil.h:87
eflowRangeBase is an object to represent a length in eta or phi, and this is used in eflowCellIntegra...
Definition eflowUtil.h:107
T getMin() const
Definition eflowUtil.h:116
T getMax() const
Definition eflowUtil.h:115
eflowRangeBase()=default
void shift(double shift)
Definition eflowUtil.h:113
T getWidth() const
Definition eflowUtil.h:119
bool contains(const T &x)
Definition eflowUtil.h:121
void setCenterAndWidth(T center, double width)
Definition eflowUtil.h:112
std::string print() const
Definition eflowUtil.h:123
T getCenter() const
Definition eflowUtil.h:118
eflowRangeBase(const T &min, const T &max)
Definition eflowUtil.h:110
eflowRangeBase< double > eflowRange
Definition eflowUtil.h:136