ATLAS Offline Software
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 
21 class eflowAzimuth {
22 public:
23 eflowAzimuth(double phi): m_value(phi) { if (phi != -999. && !std::isnan(phi)) adjustRange(); }
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;
31  adjustRange();
32  return m_value;
33  }
34 
36  m_value += deltaPhi;
37  adjustRange();
38  return *this;
39  }
41  m_value -= deltaPhi;
42  adjustRange();
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 
63 private:
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 
86 public:
87  eflowEtaPhiPosition() = default;
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 
101 private:
102  double m_eta{NAN};
104 };
105 
109 template <class T>
111 public:
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 = "[";
129  result += ", ";
131  result += ']';
132  return result;
133  }
134 
135 private:
136  T m_min{NAN};
137  T m_max{NAN};
138 };
140 
141 #endif /* EFLOWUTIL_H_ */
eflowAzimuth::~eflowAzimuth
~eflowAzimuth()
Definition: eflowUtil.h:26
eflowEtaPhiPosition::dRSq
double dRSq(const eflowEtaPhiPosition &other) const
Definition: eflowUtil.h:94
eflowRangeBase::getCenter
T getCenter() const
Definition: eflowUtil.h:121
eflowAzimuth::eflowAzimuth
eflowAzimuth(const eflowAzimuth &other)
Definition: eflowUtil.h:24
eflowEtaPhiPosition::m_phi
eflowAzimuth m_phi
Definition: eflowUtil.h:103
eflowEtaPhiPosition::eflowEtaPhiPosition
eflowEtaPhiPosition(double eta, double phi)
Definition: eflowUtil.h:88
eflowRangeBase::m_max
T m_max
Definition: eflowUtil.h:137
get_generator_info.result
result
Definition: get_generator_info.py:21
max
#define max(a, b)
Definition: cfImp.cxx:41
eflowRangeBase::eflowRangeBase
eflowRangeBase()=default
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
eflowRangeBase::setCenterAndWidth
void setCenterAndWidth(T center, double width)
Definition: eflowUtil.h:115
eflowAzimuth::cycle
double cycle(double phi)
Definition: eflowUtil.h:52
eflowAzimuth::operator+=
eflowAzimuth operator+=(double deltaPhi)
Definition: eflowUtil.h:35
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
eflowAzimuth::m_value
double m_value
Definition: eflowUtil.h:64
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:160
eflowEtaPhiPosition::getEta
double getEta() const
Definition: eflowUtil.h:90
eflowEtaPhiPosition::getPhiD
double getPhiD() const
Definition: eflowUtil.h:92
M_PI
#define M_PI
Definition: ActiveFraction.h:11
eflowEtaPhiPosition
Definition: eflowUtil.h:85
eflowAzimuth::operator=
eflowAzimuth & operator=(const eflowAzimuth &other)
Definition: eflowUtil.h:25
eflowRangeBase::eflowRangeBase
eflowRangeBase(const T &min, const T &max)
Definition: eflowUtil.h:113
x
#define x
eflowAzimuth::cycle
double cycle(const eflowAzimuth &other)
Definition: eflowUtil.h:51
eflowRangeBase::getWidth
T getWidth() const
Definition: eflowUtil.h:122
eflowAzimuth::getAbsDifference
double getAbsDifference(const eflowAzimuth &other) const
Definition: eflowUtil.h:46
eflowAzimuth::operator()
double operator()() const
Definition: eflowUtil.h:28
eflowEtaPhiPosition::m_eta
double m_eta
Definition: eflowUtil.h:102
eflowEtaPhiPosition::eflowEtaPhiPosition
eflowEtaPhiPosition()=default
eflowEtaPhiPosition::getPhi
eflowAzimuth getPhi() const
Definition: eflowUtil.h:91
eflowAzimuth::adjustRange
void adjustRange()
Definition: eflowUtil.h:75
eflowRange
eflowRangeBase< double > eflowRange
Definition: eflowUtil.h:139
TauGNNUtils::Variables::Track::dPhi
bool dPhi(const xAOD::TauJet &tau, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:538
eflowAzimuth::operator-=
eflowAzimuth operator-=(double deltaPhi)
Definition: eflowUtil.h:40
eflowRangeBase::print
std::string print() const
Definition: eflowUtil.h:126
eflowAzimuth::adjustRange
double adjustRange(double a)
Definition: eflowUtil.h:66
eflowAzimuth
eflowAzimuth represents phi and has kinematic functions which correctly deal with phi wraparound etc.
Definition: eflowUtil.h:21
eflowRangeBase::contains
bool contains(const T &x)
Definition: eflowUtil.h:124
eflowRangeBase::getMax
T getMax() const
Definition: eflowUtil.h:118
min
#define min(a, b)
Definition: cfImp.cxx:40
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
eflowAzimuth::eflowAzimuth
eflowAzimuth(double phi)
Definition: eflowUtil.h:23
a
TList * a
Definition: liststreamerinfos.cxx:10
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
eflowEtaPhiPosition::dR
double dR(const eflowEtaPhiPosition &other) const
Definition: eflowUtil.h:99
eflowRangeBase::m_min
T m_min
Definition: eflowUtil.h:136
eflowRangeBase::getMin
T getMin() const
Definition: eflowUtil.h:119
TauGNNUtils::Variables::Track::dEta
bool dEta(const xAOD::TauJet &tau, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:527
eflowRangeBase::shift
void shift(double shift)
Definition: eflowUtil.h:116
eflowRangeBase
eflowRangeBase is an object to represent a length in eta or phi, and this is used in eflowCellIntegra...
Definition: eflowUtil.h:110
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35