ATLAS Offline Software
Loading...
Searching...
No Matches
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
7namespace 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
31
33
35 {
36 return grid()->centralPhi(m_index);
37 }
38
40 {
41 return grid()->centralEta(m_index);
42 }
43
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
68
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(); }
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
#define M_PI
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
Provide a base class for the grids used in some pufit algorithms.
std::pair< std::size_t, std::size_t > etaPhiIndex() const
The eta/phi indices of the tower together.
std::size_t etaIndex() const
The eta index of this tower.
virtual const PeriodicGridBase * grid() const =0
The grid which owns this tower.
double towerEta() const
The central eta coordinate of this tower.
std::size_t index() const
The global index of this tower.
double towerPhi() const
The central phi coordinate of this tower.
std::size_t phiIndex() const
The phi index of this tower.
std::size_t nPhiTowers() const
The number of phi bins.
double maxEta() const
The maximum eta range for the grid.
std::size_t nTowers() const
The number of bins.
double centralEta(std::size_t iEta) const
Central eta coordinate of the given eta index.
std::size_t getPhiIndex(double phi) const
Get the phi index for the given value.
std::size_t nEtaTowers() const
The number of eta bins.
std::size_t getIndex(double eta, double phi, bool &outOfRange) const
Get the index for the given eta, phi values.
bool displacePhi() const
Whether or not this is displaced in phi.
PeriodicGridBase(const GridParameters &parameters)
Construct the grid from its parameters.
bool displaceEta() const
Whether or not this is displaced in eta.
std::size_t globalIndex(std::size_t iEta, std::size_t iPhi) const
Convert eta and phi to a global index.
std::pair< std::size_t, std::size_t > etaPhiIndex(std::size_t index) const
Convert a global index to an eta/phi index pair.
double phiWidth() const
The bin width in phi.
double centralPhi(std::size_t iPhi) const
Central phi coordinate of the given phi.
GridDisplacement displacement() const
The grid displacement.
std::size_t getEtaIndex(double eta, bool &outOfRange) const
Get the eta index for the given value.
double etaWidth() const
The bin width in eta.
const GridParameters & parameters() const
The grid parameters.
const GridParameters m_params
The grid's parameters.
GridDisplacement
Enum to describe the positioning of the grid.
@ PhiDisplaced
The grid is shifted by half a tower width in phi.
@ NoDisplacement
The grid is not shifted.
@ EtaDisplaced
The grid is shifted by half a tower width in eta.
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Definition index.py:1
Parameters describing a grid.
bool operator!=(const GridParameters &other) const
Check inequality with other parameter sets.
GridDisplacement displacement() const
The.
bool displaceEta
Whether the grid is displaced in eta.
bool displacePhi
Whether the grid is displaced in phi.
std::size_t nPhiTowers
The number of divisions along the phi axis.
bool operator==(const GridParameters &other) const
std::size_t nEtaTowers
The number of divisions along the eta axis.
double maxEta
The maximum |eta| value.