ATLAS Offline Software
Loading...
Searching...
No Matches
eflowUtil.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 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 EFLOWUTIL_H_
13#define 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 eflowAzimuth(const eflowAzimuth& other): m_value(other.m_value) { }
25 eflowAzimuth& operator=(const eflowAzimuth& other) { if (this == &other) return *this; else { m_value = other.m_value; return *this; } }
27
28 inline double operator ()() const { return m_value; }
29 inline double operator =(double phi) {
30 m_value = phi;
32 return m_value;
33 }
34
38 return *this;
39 }
43 return *this;
44 }
45
46 inline double getAbsDifference(const eflowAzimuth& other) const {
47 double plainAbsDifference = std::abs(m_value - other.m_value);
48 return plainAbsDifference <= M_PI ? plainAbsDifference : 2*M_PI - plainAbsDifference;
49 }
50
51 inline double cycle(const eflowAzimuth& other) { return cycle(other.m_value); }
52 inline double cycle(double phi) {
53 double plainDifference = phi-m_value;
54 if (plainDifference > M_PI) {
55 return m_value+2.0*M_PI;
56 } else if (plainDifference < -M_PI) {
57 return m_value-2.0*M_PI;
58 } else {
59 return m_value;
60 }
61 }
62
63private:
64 double m_value;
65
66 inline double adjustRange(double a) {
67 if (a <= -M_PI) {
68 return a+(2*M_PI*std::floor(-(a-M_PI)/(2*M_PI)));
69 } else if (a > M_PI) {
70 return a-(2*M_PI*std::floor((a+M_PI)/(2*M_PI)));
71 } else {
72 return a;
73 }
74 }
75 inline void adjustRange() {
76 if (m_value <= -M_PI) {
77 m_value+=(2*M_PI*std::floor(-(m_value-M_PI)/(2*M_PI)));
78 } else if (m_value > M_PI) {
79 m_value-=(2*M_PI*std::floor((m_value+M_PI)/(2*M_PI)));
80 }
81 }
82
83};
84
86public:
88 eflowEtaPhiPosition(double eta, double phi): m_eta(eta), m_phi(phi) {}
89
90 inline double getEta() const { return m_eta; }
91 inline eflowAzimuth getPhi() const { return m_phi; }
92 inline double getPhiD() const { return m_phi(); }
93
94 inline double dRSq(const eflowEtaPhiPosition& other) const {
95 double dEta(m_eta-other.m_eta);
96 double dPhi(m_phi.getAbsDifference(other.m_phi));
97 return dEta*dEta + dPhi*dPhi;
98 }
99 inline double dR(const eflowEtaPhiPosition& other) const { return std::sqrt(this->dRSq(other)); }
100
101private:
102 double m_eta{NAN};
104};
105
109template <class T>
111public:
112 eflowRangeBase() = default;
113 eflowRangeBase(const T& min, const T& max): m_min(min), m_max(max) { }
114
115 inline void setCenterAndWidth(T center, double width) { m_min = center - width/2; m_max = m_min + width; }
116 inline void shift(double shift) { m_min += shift; m_max += shift; }
117
118 inline T getMax() const { return m_max; }
119 inline T getMin() const { return m_min; }
120
121 inline T getCenter() const { return (m_max + m_min)/2; }
122 inline T getWidth() const { return (m_max - m_min); }
123
124 bool contains(const T& x) { return ( (m_min < x) && (m_max > x) ); }
125
126 std::string print() const {
127 std::string result = "[";
128 result += std::to_string(m_min);
129 result += ", ";
130 result += std::to_string(m_max);
131 result += ']';
132 return result;
133 }
134
135private:
136 T m_min{NAN};
137 T m_max{NAN};
138};
140
141#endif /* 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:40
eflowAzimuth & operator=(const eflowAzimuth &other)
Definition eflowUtil.h:25
double cycle(const eflowAzimuth &other)
Definition eflowUtil.h:51
void adjustRange()
Definition eflowUtil.h:75
eflowAzimuth operator+=(double deltaPhi)
Definition eflowUtil.h:35
double m_value
Definition eflowUtil.h:64
double getAbsDifference(const eflowAzimuth &other) const
Definition eflowUtil.h:46
double operator()() const
Definition eflowUtil.h:28
double adjustRange(double a)
Definition eflowUtil.h:66
eflowAzimuth(const eflowAzimuth &other)
Definition eflowUtil.h:24
eflowAzimuth(double phi)
Definition eflowUtil.h:23
double cycle(double phi)
Definition eflowUtil.h:52
eflowAzimuth getPhi() const
Definition eflowUtil.h:91
eflowEtaPhiPosition(double eta, double phi)
Definition eflowUtil.h:88
double dR(const eflowEtaPhiPosition &other) const
Definition eflowUtil.h:99
double dRSq(const eflowEtaPhiPosition &other) const
Definition eflowUtil.h:94
double getPhiD() const
Definition eflowUtil.h:92
eflowEtaPhiPosition()=default
eflowAzimuth m_phi
Definition eflowUtil.h:103
double getEta() const
Definition eflowUtil.h:90
eflowRangeBase is an object to represent a length in eta or phi, and this is used in eflowCellIntegra...
Definition eflowUtil.h:110
T getMin() const
Definition eflowUtil.h:119
T getMax() const
Definition eflowUtil.h:118
eflowRangeBase()=default
void shift(double shift)
Definition eflowUtil.h:116
T getWidth() const
Definition eflowUtil.h:122
bool contains(const T &x)
Definition eflowUtil.h:124
void setCenterAndWidth(T center, double width)
Definition eflowUtil.h:115
std::string print() const
Definition eflowUtil.h:126
T getCenter() const
Definition eflowUtil.h:121
eflowRangeBase(const T &min, const T &max)
Definition eflowUtil.h:113
eflowRangeBase< double > eflowRange
Definition eflowUtil.h:139