ATLAS Offline Software
PeriodicGridBase.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3  */
5 #include <cmath>
6 
7 namespace HLT
8 {
9  namespace MET
10  {
12  {
13  return maxEta != other.maxEta ||
14  nEtaTowers != other.nEtaTowers ||
15  nPhiTowers != other.nPhiTowers ||
16  displaceEta != other.displaceEta ||
17  displacePhi != other.displacePhi;
18  }
19 
21  {
22  return !(*this != other);
23  }
24 
26  {
27  return static_cast<GridDisplacement>(
30  }
31 
32  PeriodicGridBase::Tower::Tower(std::size_t index) : m_index(index) {}
33 
35  {
36  return grid()->centralPhi(m_index);
37  }
38 
40  {
41  return grid()->centralEta(m_index);
42  }
43 
44  std::size_t PeriodicGridBase::Tower::index() const
45  {
46  return m_index;
47  }
48 
50  {
51  return etaPhiIndex().first;
52  }
53 
55  {
56  return etaPhiIndex().second;
57  }
58 
59  std::pair<std::size_t, std::size_t> PeriodicGridBase::Tower::etaPhiIndex() const
60  {
61  return grid()->etaPhiIndex(m_index);
62  }
63 
66  {
67  }
68 
70  double maxEta,
71  std::size_t nEtaTowers,
72  std::size_t nPhiTowers,
73  bool displaceEta,
74  bool displacePhi)
76  {
77  }
78 
79  std::size_t PeriodicGridBase::getIndex(double eta, double phi, bool &outOfRange) const
80  {
81  std::size_t etaIndex = getEtaIndex(eta, outOfRange);
82  if (outOfRange)
83  return nTowers();
84  return globalIndex(etaIndex, getPhiIndex(phi));
85  }
86 
87  std::size_t PeriodicGridBase::getEtaIndex(double eta, bool &outOfRange) const
88  {
89  if (std::abs(eta) >= maxEta())
90  {
91  outOfRange = true;
92  return nEtaTowers();
93  }
94  outOfRange = false;
95  if (displaceEta())
96  {
97  // Apply the displacement by adding the displacement to the input
98  // coordinate. This shifts the grid in the negative direction
99  eta += etaWidth() / 2;
100  // If necessary apply eta periodicity here
101  if (eta >= maxEta())
102  eta -= 2 * maxEta();
103  }
104  return (eta + maxEta()) / etaWidth();
105  }
106 
107  std::size_t PeriodicGridBase::getPhiIndex(double phi) const
108  {
109  if (displacePhi())
110  // Apply the displacement by adding the displacement to the input
111  // coordinate. This shifts the grid in the negative direction
112  phi += phiWidth() / 2;
113  // Apply periodicity
114  phi = std::fmod(phi, 2 * M_PI);
115  if (phi < 0)
116  phi += 2 * M_PI;
117  return phi / phiWidth();
118  }
119 
120  std::size_t PeriodicGridBase::globalIndex(std::size_t iEta, std::size_t iPhi) const
121  {
122  return iEta * nPhiTowers() + iPhi;
123  }
124  std::pair<std::size_t, std::size_t> PeriodicGridBase::etaPhiIndex(std::size_t index) const
125  {
126  return std::make_pair(index / nPhiTowers(), index % nPhiTowers());
127  }
128 
129  double PeriodicGridBase::centralEta(std::size_t iEta) const
130  {
131  return -maxEta() + etaWidth() * (iEta + 0.5) + (displaceEta() ? etaWidth() / 2 : 0);
132  }
133  double PeriodicGridBase::centralPhi(std::size_t iPhi) const
134  {
135  return phiWidth() * (iPhi + 0.5) + (displacePhi() ? phiWidth() / 2 : 0);
136  }
137 
139  double PeriodicGridBase::maxEta() const { return parameters().maxEta; }
140  std::size_t PeriodicGridBase::nEtaTowers() const { return parameters().nEtaTowers; }
141  std::size_t PeriodicGridBase::nPhiTowers() const { return parameters().nPhiTowers; }
142  std::size_t PeriodicGridBase::nTowers() const { return nEtaTowers() * nPhiTowers(); }
146  {
147  return parameters().displacement();
148  }
149  double PeriodicGridBase::etaWidth() const { return 2 * maxEta() / nEtaTowers(); }
150  double PeriodicGridBase::phiWidth() const { return 2 * M_PI / nPhiTowers(); }
151  } // namespace MET
152 } // namespace HLT
HLT::MET::PeriodicGridBase::displacePhi
bool displacePhi() const
Whether or not this is displaced in phi.
Definition: PeriodicGridBase.cxx:144
HLT::MET::PeriodicGridBase::Tower::etaPhiIndex
std::pair< std::size_t, std::size_t > etaPhiIndex() const
The eta/phi indices of the tower together.
Definition: PeriodicGridBase.cxx:59
HLT::MET::PeriodicGridBase::Tower::towerPhi
double towerPhi() const
The central phi coordinate of this tower.
Definition: PeriodicGridBase.cxx:34
HLT::MET::PeriodicGridBase::Tower::etaIndex
std::size_t etaIndex() const
The eta index of this tower.
Definition: PeriodicGridBase.cxx:49
HLT::MET::PeriodicGridBase::nPhiTowers
std::size_t nPhiTowers() const
The number of phi bins.
Definition: PeriodicGridBase.cxx:141
HLT::MET::EtaDisplaced
@ EtaDisplaced
The grid is shifted by half a tower width in eta.
Definition: PeriodicGridBase.h:27
index
Definition: index.py:1
HLT::MET::GridParameters::nEtaTowers
std::size_t nEtaTowers
The number of divisions along the eta axis.
Definition: PeriodicGridBase.h:47
HLT::MET::GridParameters::operator==
bool operator==(const GridParameters &other) const
Definition: PeriodicGridBase.cxx:20
HLT::MET::GridParameters::displacePhi
bool displacePhi
Whether the grid is displaced in phi.
Definition: PeriodicGridBase.h:53
M_PI
#define M_PI
Definition: ActiveFraction.h:11
HLT::MET::PhiDisplaced
@ PhiDisplaced
The grid is shifted by half a tower width in phi.
Definition: PeriodicGridBase.h:29
HLT::MET::PeriodicGridBase::m_params
const GridParameters m_params
The grid's parameters.
Definition: PeriodicGridBase.h:191
HLT::MET::PeriodicGridBase::Tower::Tower
Tower(std::size_t index)
Definition: PeriodicGridBase.cxx:32
HLT::MET::PeriodicGridBase::etaPhiIndex
std::pair< std::size_t, std::size_t > etaPhiIndex(std::size_t index) const
Convert a global index to an eta/phi index pair.
Definition: PeriodicGridBase.cxx:124
HLT::MET::PeriodicGridBase::getIndex
std::size_t getIndex(double eta, double phi, bool &outOfRange) const
Get the index for the given eta, phi values.
Definition: PeriodicGridBase.cxx:79
HLT::MET::PeriodicGridBase::displacement
GridDisplacement displacement() const
The grid displacement.
Definition: PeriodicGridBase.cxx:145
HLT::MET::PeriodicGridBase::Tower::phiIndex
std::size_t phiIndex() const
The phi index of this tower.
Definition: PeriodicGridBase.cxx:54
PUfitVar::maxEta
constexpr float maxEta
Definition: GepMETPufitAlg.cxx:13
HLT::MET::PeriodicGridBase::Tower::index
std::size_t index() const
The global index of this tower.
Definition: PeriodicGridBase.cxx:44
HLT::MET::PeriodicGridBase::displaceEta
bool displaceEta() const
Whether or not this is displaced in eta.
Definition: PeriodicGridBase.cxx:143
HLT::MET::NoDisplacement
@ NoDisplacement
The grid is not shifted.
Definition: PeriodicGridBase.h:25
HLT::MET::GridDisplacement
GridDisplacement
Enum to describe the positioning of the grid.
Definition: PeriodicGridBase.h:23
HLT::MET::PeriodicGridBase::phiWidth
double phiWidth() const
The bin width in phi.
Definition: PeriodicGridBase.cxx:150
HLT::MET::PeriodicGridBase::parameters
const GridParameters & parameters() const
The grid parameters.
Definition: PeriodicGridBase.cxx:138
HLT
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Definition: HLTResultReader.h:26
HLT::MET::GridParameters::displacement
GridDisplacement displacement() const
The.
Definition: PeriodicGridBase.cxx:25
HLT::MET::PeriodicGridBase::getEtaIndex
std::size_t getEtaIndex(double eta, bool &outOfRange) const
Get the eta index for the given value.
Definition: PeriodicGridBase.cxx:87
HLT::MET::GridParameters::nPhiTowers
std::size_t nPhiTowers
The number of divisions along the phi axis.
Definition: PeriodicGridBase.h:49
HLT::MET::PeriodicGridBase::PeriodicGridBase
PeriodicGridBase(const GridParameters &parameters)
Construct the grid from its parameters.
Definition: PeriodicGridBase.cxx:64
HLT::MET::GridParameters::displaceEta
bool displaceEta
Whether the grid is displaced in eta.
Definition: PeriodicGridBase.h:51
HLT::MET::PeriodicGridBase::maxEta
double maxEta() const
The maximum eta range for the grid.
Definition: PeriodicGridBase.cxx:139
HLT::MET::PeriodicGridBase::getPhiIndex
std::size_t getPhiIndex(double phi) const
Get the phi index for the given value.
Definition: PeriodicGridBase.cxx:107
HLT::MET::PeriodicGridBase::Tower::towerEta
double towerEta() const
The central eta coordinate of this tower.
Definition: PeriodicGridBase.cxx:39
PeriodicGridBase.h
Provide a base class for the grids used in some pufit algorithms.
HLT::MET::PeriodicGridBase::globalIndex
std::size_t globalIndex(std::size_t iEta, std::size_t iPhi) const
Convert eta and phi to a global index.
Definition: PeriodicGridBase.cxx:120
MET
Definition: MET.py:1
HLT::MET::PeriodicGridBase
Base class for grids used in some of the pufit algorithms.
Definition: PeriodicGridBase.h:76
HLT::MET::PeriodicGridBase::centralPhi
double centralPhi(std::size_t iPhi) const
Central phi coordinate of the given phi.
Definition: PeriodicGridBase.cxx:133
HLT::MET::PeriodicGridBase::centralEta
double centralEta(std::size_t iEta) const
Central eta coordinate of the given eta index.
Definition: PeriodicGridBase.cxx:129
Trk::iPhi
@ iPhi
Definition: ParamDefs.h:47
HLT::MET::GridParameters::operator!=
bool operator!=(const GridParameters &other) const
Check inequality with other parameter sets.
Definition: PeriodicGridBase.cxx:11
HLT::MET::GridParameters::maxEta
double maxEta
The maximum |eta| value.
Definition: PeriodicGridBase.h:45
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
HLT::MET::GridParameters
Parameters describing a grid.
Definition: PeriodicGridBase.h:43
HLT::MET::PeriodicGridBase::nTowers
std::size_t nTowers() const
The number of bins.
Definition: PeriodicGridBase.cxx:142
xAOD::iEta
setScale setgFexType iEta
Definition: gFexJetRoI_v1.cxx:77
HLT::MET::PeriodicGridBase::etaWidth
double etaWidth() const
The bin width in eta.
Definition: PeriodicGridBase.cxx:149
HLT::MET::PeriodicGridBase::nEtaTowers
std::size_t nEtaTowers() const
The number of eta bins.
Definition: PeriodicGridBase.cxx:140