ATLAS Offline Software
Loading...
Searching...
No Matches
PufitGrid.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4
7#include <algorithm>
8#include <cmath>
9
10namespace HLT
11{
12 namespace MET
13 {
14
16 m_parent(parent)
17 {
18 }
19
21 {
22 m_kin = other.kinematics();
23 m_sumEt = other.sumEt();
24 m_sumE = other.sumE();
25 m_mask = other.masked();
26 return *this;
27 }
28
29 double PufitGrid::Tower::ex() const { return m_kin.px(); }
30 double PufitGrid::Tower::ey() const { return m_kin.py(); }
31 double PufitGrid::Tower::ez() const { return m_kin.pz(); }
32 double PufitGrid::Tower::sumEt() const { return m_sumEt; }
33 double PufitGrid::Tower::sumE() const { return m_sumE; }
34 double PufitGrid::Tower::phi() const { return kinematics().phi(); }
35 double PufitGrid::Tower::eta() const { return kinematics().eta(); }
36 bool PufitGrid::Tower::masked() const { return m_mask; }
37 void PufitGrid::Tower::mask(bool value) { m_mask = value; }
38
39 const PufitGrid *PufitGrid::Tower::grid() const { return m_parent; }
40
45 PufitGrid::Tower::operator SignedKinematics() const { return kinematics(); }
46
48 {
49 m_kin += kin;
50 m_sumEt += kin.pt();
51 m_sumE += kin.energy();
52 return *this;
53 }
55 {
56 m_kin -= kin;
57 m_sumEt -= kin.pt();
58 m_sumE -= kin.energy();
59 return *this;
60 }
62 {
63 m_kin += other.kinematics();
64 m_sumEt += other.sumEt();
65 m_sumE += other.sumE();
66 return *this;
67 }
69 {
70 m_kin -= other.kinematics();
71 m_sumEt -= other.sumEt();
72 m_sumE -= other.sumE();
73 return *this;
74 }
75
77 double maxEta,
78 std::size_t nEtaTowers,
79 std::size_t nPhiTowers,
80 bool displaceEta,
81 bool displacePhi)
83 {
84 }
85
88 {
89 m_towers.reserve(nTowers());
90 for (std::size_t index = 0; index < nTowers(); ++index)
91 m_towers.emplace_back(this, index);
92 }
93
95 {
96 *this = other;
97 }
98
100 {
101 if (parameters() != other.parameters())
102 throw std::invalid_argument("Grid parameters do not match!");
103 std::copy(other.begin(), other.end(), m_towers.begin());
104 return *this;
105 }
106
108 {
109 // Here we construct a standalone tower to copy in 0 values to the tower
110 // kinematics. This kind of object is safe here but in general it's not a
111 // good idea to have one.
112 std::fill(begin(), end(), Tower(nullptr, -1));
113 }
114
116 {
117 // Find the right tower to add to
118 bool outOfRange = false;
119 std::size_t index = getIndex(kin.eta(), kin.phi(), outOfRange);
120 if (!outOfRange)
121 operator[](index) += kin;
122 return *this;
123 }
125 {
126 // Find the right tower to subtract from
127 bool outOfRange = false;
128 std::size_t index = getIndex(kin.eta(), kin.phi(), outOfRange);
129 if (!outOfRange)
130 operator[](index) -= kin;
131 return *this;
132 }
133
135 const std::pair<std::size_t, std::size_t> &indices)
136 {
137 return operator[](globalIndex(indices.first, indices.second));
138 }
140 const std::pair<std::size_t, std::size_t> &indices) const
141 {
142 return operator[](globalIndex(indices.first, indices.second));
143 }
144
146 {
147 return m_towers.at(index);
148 }
150 {
151 return m_towers.at(index);
152 }
153
154 std::vector<PufitGrid::Tower>::iterator PufitGrid::begin()
155 {
156 return m_towers.begin();
157 }
158 std::vector<PufitGrid::Tower>::const_iterator PufitGrid::begin() const
159 {
160 return m_towers.begin();
161 }
162 std::vector<PufitGrid::Tower>::iterator PufitGrid::end()
163 {
164 return m_towers.end();
165 }
166 std::vector<PufitGrid::Tower>::const_iterator PufitGrid::end() const
167 {
168 return m_towers.end();
169 }
170
172 {
173 METComponent total;
174 switch (strategy)
175 {
176 case SumStrategy::All:
177 for (const Tower &tower : *this)
178 total += tower;
179 break;
181 for (const Tower &tower : *this)
182 if (tower.masked())
183 total += tower;
184 break;
186 for (const Tower &tower : *this)
187 if (!tower.masked())
188 total += tower;
189 break;
190 }
191 return total;
192 }
193
195 {
196 if (parameters() != other.parameters())
197 throw std::invalid_argument("Grid parameters do not match");
198 auto itr = begin();
199 auto otherItr = other.begin();
200 for (; itr != end(); ++itr, ++otherItr)
201 *itr += *otherItr;
202 return *this;
203 }
205 {
206 if (parameters() != other.parameters())
207 throw std::invalid_argument("Grid parameters do not match");
208 auto itr = begin();
209 auto otherItr = other.begin();
210 for (; itr != end(); ++itr, ++otherItr)
211 *itr -= *otherItr;
212 return *this;
213 }
214
215 PufitGridSet::PufitGridSet(double maxEta, std::size_t nEta, std::size_t nPhi)
216 : grids({PufitGrid(maxEta, nEta, nPhi, false, false),
217 PufitGrid(maxEta, nEta, nPhi, true, false),
218 PufitGrid(maxEta, nEta, nPhi, false, true),
219 PufitGrid(maxEta, nEta, nPhi, true, true)})
220 {
221 }
222
224 {
225 for (PufitGrid &grid : grids)
226 grid += kin;
227 return *this;
228 }
230 {
231 for (PufitGrid &grid : grids)
232 grid -= kin;
233 return *this;
234 }
236 {
237 return grids[displacement];
238 }
240 {
241 return grids[displacement];
242 }
243
244 PufitGrid operator+(const PufitGrid &lhs, const PufitGrid &rhs)
245 {
246 PufitGrid ret(lhs);
247 ret += rhs;
248 return ret;
249 }
250 PufitGrid operator-(const PufitGrid &lhs, const PufitGrid &rhs)
251 {
252 PufitGrid ret(lhs);
253 ret -= rhs;
254 return ret;
255 }
256
257 } // namespace MET
258} // namespace HLT
Helper struct to build up MET values before moving them into the EDM.
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.
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.
const GridParameters & parameters() const
The grid parameters.
Describes a single element of the grid.
Definition PufitGrid.h:48
void mask(bool value=true)
Set the mask on this tower.
Definition PufitGrid.cxx:37
Tower & operator=(const Tower &other)
Copy assignment operator.
Definition PufitGrid.cxx:20
double eta() const
This tower's kinematic eta.
Definition PufitGrid.cxx:35
double ey() const
The y-component of this tower's energy.
Definition PufitGrid.cxx:30
double m_sumE
The summed energy.
Definition PufitGrid.h:139
double phi() const
This tower's kinematic phi.
Definition PufitGrid.cxx:34
Tower & operator+=(const SignedKinematics &kin)
Add a signed object to this tower.
Definition PufitGrid.cxx:47
bool masked() const
Whether or not this tower was masked.
Definition PufitGrid.cxx:36
Tower & operator-=(const SignedKinematics &kin)
Remove the energy of a signed object from this tower.
Definition PufitGrid.cxx:54
SignedKinematics m_kin
Definition PufitGrid.h:135
bool m_mask
The mask value.
Definition PufitGrid.h:141
double ez() const
The z-component of this tower's energy.
Definition PufitGrid.cxx:31
virtual const PufitGrid * grid() const override
The parent grid of this tower.
Definition PufitGrid.cxx:39
SignedKinematics kinematics() const
Build a kinematics object from this tower.
Definition PufitGrid.cxx:41
const PufitGrid *const m_parent
The parent grid.
Definition PufitGrid.h:133
double ex() const
The x-component of this tower's energy.
Definition PufitGrid.cxx:29
Tower(const PufitGrid *parent, std::size_t index)
Create a tower with its parent.
Definition PufitGrid.cxx:15
double sumEt() const
The total sumEt in this tower.
Definition PufitGrid.cxx:32
double m_sumEt
The summed et.
Definition PufitGrid.h:137
double sumE() const
The total sumE in this tower.
Definition PufitGrid.cxx:33
Bins energy deposits into a grid.
Definition PufitGrid.h:38
std::vector< Tower >::iterator begin()
Access by iterator.
std::vector< Tower >::iterator end()
Iterator end point.
SumStrategy
Helper enum to describe how to sum over towers.
Definition PufitGrid.h:221
PufitGrid & operator=(const PufitGrid &other)
Assignment operator.
Definition PufitGrid.cxx:99
PufitGrid & operator+=(const SignedKinematics &kin)
Add a signed object to this grid.
METComponent sum(SumStrategy strategy=SumStrategy::All) const
Tower & operator[](const std::pair< std::size_t, std::size_t > &indices)
Access stored value by eta/phi index (access is bounds-checked)
void reset()
Reset the internal storage.
PufitGrid & operator-=(const SignedKinematics &kin)
Remove the energy of a signed object from this grid.
PufitGrid(double maxEta, std::size_t nEtaTowers, std::size_t nPhiTowers, bool displaceEta=false, bool displacePhi=false)
Create a new tower grid.
Definition PufitGrid.cxx:76
std::vector< Tower > m_towers
Definition PufitGrid.h:235
Class to describe the kinematics of an object that can have negative energies.
double eta() const
Direction.
double energy() const
Energy values (signed) energy.
double pt() const
(signed) pt
METComponent operator+(const METComponent &lhs, const METComponent &rhs)
GridDisplacement
Enum to describe the positioning of the grid.
PufitGrid operator-(const PufitGrid &lhs, const PufitGrid &rhs)
Elementwise subtraction.
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.
PufitGridSet & operator-=(const SignedKinematics &kin)
Subtract kinematics.
PufitGridSet & operator+=(const SignedKinematics &kin)
Add kinematics.
PufitGrid & operator[](GridDisplacement displacement)
Select a grid.
PufitGridSet(double maxEta, std::size_t nEta, std::size_t nPhi)
std::array< PufitGrid, 4 > grids
Definition PufitGrid.h:242