ATLAS Offline Software
Loading...
Searching...
No Matches
PufitMultiGrid.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4
5#ifndef TRIGEFMISSINGET_PUFITMULTIGRID_H
6#define TRIGEFMISSINGET_PUFITMULTIGRID_H
7
10#include <cstdint>
11#include <limits>
12#include <type_traits>
13
14namespace HLT
15{
16 namespace MET
17 {
19 constexpr bool isPow2(std::size_t i)
20 {
21 // An int is a power of 2 if it only contains one 'on' bit
22 // We check for this by shifting an int until its first bit is 1. Then it
23 // is a power of two if that is the only bit set.
24 // We also need a check if this is 0 otherwise the recursion will never
25 // end
26 if (i == 0)
27 // 0 is *not* a power of 2
28 return false;
29 else if (i == 1)
30 // 1 is a power of 2
31 return true;
32 else if (i & 1)
33 // If we're not 1, but the '1' bit is set then this can't be a power of 2
34 return false;
35 else
36 // shifting to the right esse
37 return isPow2(i >> 1);
38 }
39
46 constexpr uint16_t intLog2(std::size_t i, uint16_t tmp = 0)
47 {
48 if (i == 0)
49 return UINT16_MAX;
50 else if (i == 1)
51 return tmp;
52 else
53 return intLog2(i >> 1, tmp + 1);
54 }
55
61 template <std::size_t N>
63 {
64 static_assert(N > 0, "N must be greater than 0");
65 // The C++ standard only guarantees that std::size_t has a bit width of
66 // at least 16
67 static_assert(N < 17, "N must be no greater than 16");
68
69 public:
71 constexpr static std::size_t All = (1 << N) - 1;
73 constexpr static std::size_t NCategories = N;
74
83 {
84 friend class PufitMulitGrid;
85
86 public:
92 Tower(PufitMultiGrid *parent, std::size_t index);
93
94 Tower(const Tower&) = default;
95
103 Tower &operator=(const Tower &other);
104
106 double ex(std::size_t type = All) const;
107
109 double ey(std::size_t type = All) const;
110
112 double ez(std::size_t type = All) const;
113
115 double sumEt(std::size_t type = All) const;
116
118 double sumE(std::size_t type = All) const;
119
121 double phi(std::size_t type = All) const;
122
124 double eta(std::size_t type = All) const;
125
127 bool masked() const;
128
130 void mask(bool value = true);
131
133 const PufitMultiGrid *grid() const override;
134
136 SignedKinematics kinematics(std::size_t type = All) const;
137
140 operator SignedKinematics() const;
141
145 Tower &operator+=(const Tower &other);
149 Tower &operator-=(const Tower &other);
150
156 template <std::size_t I,
157 typename = typename std::enable_if<isPow2(I)>::type,
158 typename = typename std::enable_if<I <= All>::type>
160 {
161 return subTower(intLog2(I));
162 }
163
169 template <std::size_t I,
170 typename = typename std::enable_if<isPow2(I)>::type,
171 typename = typename std::enable_if<I <= All>::type>
172 const PufitGrid::Tower &get() const
173 {
174 return subTower(intLog2(I));
175 }
176
177 private:
180
182 bool m_mask{false};
183
185 PufitGrid::Tower &subTower(std::size_t ii)
186 {
187 return m_parent->m_grids[ii][index()];
188 }
189
190 const PufitGrid::Tower &subTower(std::size_t ii) const
191 {
192 return m_parent->m_grids[ii][index()];
193 }
194
197 {
198 for (std::size_t ii = 0; ii < N; ++ii)
199 (subTower(ii).*f)(other.subTower(ii));
200 }
201
204 template <typename T>
205 typename std::decay<T>::type sumOver(int type, T (PufitGrid::Tower::*f)() const) const
206 {
207 typename std::decay<T>::type val{};
208 for (std::size_t ii = 0; ii < N; ++ii)
209 if (1 << ii & type)
210 val += (subTower(ii).*f)();
211 return val;
212 }
213
214 }; //> end class Tower
215
225 double maxEta,
226 std::size_t nEtaTowers,
227 std::size_t nPhiTowers,
228 bool displaceEta = false,
229 bool displacePhi = false);
230
233
236
244
246 void reset();
247
249 Tower &operator[](const std::pair<std::size_t, std::size_t> &indices);
251 const Tower &operator[](const std::pair<std::size_t, std::size_t> &indices) const;
252
254 Tower &operator[](std::size_t index);
256 const Tower &operator[](std::size_t index) const;
257
259 typename std::vector<Tower>::iterator begin();
261 typename std::vector<Tower>::const_iterator begin() const;
263 typename std::vector<Tower>::iterator end();
265 typename std::vector<Tower>::const_iterator end() const;
266
267 // All of these fail if the grid parameters do not match!
272
278 template <std::size_t I,
279 typename = typename std::enable_if<isPow2(I)>::type,
280 typename = typename std::enable_if<I <= All>::type>
282 {
283 return m_grids[intLog2(I)];
284 }
285
291 template <std::size_t I,
292 typename = typename std::enable_if<isPow2(I)>::type,
293 typename = typename std::enable_if<I <= All>::type>
294 const PufitGrid &get() const
295 {
296 return m_grids[intLog2(I)];
297 }
298
306 PufitGrid get(std::size_t type) const;
307
308 private:
309 std::array<PufitGrid, N> m_grids;
310 std::vector<Tower> m_towers;
311 }; //> end class PufitMultiGrid
312
314 template <typename Grid>
316 {
317 PufitMultiGridSet(double maxEta, std::size_t nEta, std::size_t nPhi);
318 std::array<Grid, 4> grids;
319
321 Grid &operator[](GridDisplacement displacement)
322 {
323 return grids[displacement];
324 }
325
327 const Grid &operator[](GridDisplacement displacement) const
328 {
329 return grids[displacement];
330 }
331
333 template <std::size_t I>
341
342 template <std::size_t I,
343 typename = typename std::enable_if<isPow2(I)>::type,
344 typename = typename std::enable_if<I <= Grid::All>::type>
345 Element<I> get();
346
347 PufitGridSet get(std::size_t type) const;
348 }; //> end struct PufitMultiGridSet<Grid>
349 } // namespace MET
350} // namespace HLT
351
353
354#endif //> !TRIGEFMISSINGET_PUFITMULTIGRID_H
#define I(x, y, z)
Definition MD5.cxx:116
Provide a base class for the grids used in some pufit algorithms.
Base class for towers belonging to the grids.
std::size_t index() const
The global 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 nEtaTowers() const
The number of eta bins.
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.
const GridParameters & parameters() const
The grid parameters.
Describes a single element of the grid.
Definition PufitGrid.h:48
Bins energy deposits into a grid.
Definition PufitGrid.h:38
Tower in the multi-grid.
double ex(std::size_t type=All) const
The x-component of this tower's energy.
std::decay< T >::type sumOver(int type, T(PufitGrid::Tower::*f)() const) const
Sum over the results of all sub towers whose indices match the 'type' mask.
const PufitGrid::Tower & subTower(std::size_t ii) const
Get a subtower by index.
PufitMultiGrid *const m_parent
The parent grid.
double ez(std::size_t type=All) const
The z-component of this tower's energy.
double ey(std::size_t type=All) const
The y-component of this tower's energy.
bool masked() const
Whether or not this tower was masked.
PufitGrid::Tower & subTower(std::size_t ii)
Get a subtower by index.
double eta(std::size_t type=All) const
This tower's kinematic eta.
SignedKinematics kinematics(std::size_t type=All) const
Build a kinematics object from this tower.
void mask(bool value=true)
Set the mask on this tower.
const PufitMultiGrid * grid() const override
The parent grid of this tower.
Tower & operator-=(const Tower &other)
Subtract another tower's energies from this one.
Tower & operator+=(const Tower &other)
Add another tower's energies into this one.
const PufitGrid::Tower & get() const
Get one of the underlying towers.
Tower & operator=(const Tower &other)
Copy assignment operator.
Tower(const Tower &)=default
PufitGrid::Tower & get()
Get one of the underlying towers.
double sumE(std::size_t type=All) const
The total sumE in this tower.
Tower(PufitMultiGrid *parent, std::size_t index)
Create a tower with its parent grid.
double sumEt(std::size_t type=All) const
The total sumEt in this tower.
void applyToAll(PufitGrid::Tower &(PufitGrid::Tower::*f)(const PufitGrid::Tower &), const PufitMultiGrid::Tower &other)
Apply a function to all sub towers.
double phi(std::size_t type=All) const
This tower's kinematic phi.
const PufitGrid & get() const
Get one of the underlying grids.
std::vector< Tower > m_towers
std::vector< Tower >::const_iterator begin() const
Access by iterator.
std::vector< Tower >::iterator begin()
Access by iterator.
PufitGrid & get()
Get one of the underlying grids.
PufitMultiGrid(const PufitMultiGrid &other)
Copy constructor.
PufitMultiGrid(double maxEta, std::size_t nEtaTowers, std::size_t nPhiTowers, bool displaceEta=false, bool displacePhi=false)
Create a new tower grid.
Tower & operator[](const std::pair< std::size_t, std::size_t > &indices)
Access stored value by eta/phi index (access is bounds checked)
PufitGrid get(std::size_t type) const
Get one of the underlying grids.
Tower & operator[](std::size_t index)
Access stored value by global index number (access is bounds checked)
static constexpr std::size_t NCategories
The number of separate categories in the grid.
PufitMultiGrid & operator-=(const PufitMultiGrid &other)
Subtract a whole grid from this.
static constexpr std::size_t All
Maximum value representable by N bits.
void reset()
Reset the internal storage.
PufitMultiGrid & operator=(const PufitMultiGrid &other)
Assignment operator.
PufitMultiGrid(const GridParameters &parameters)
Construct a grid from the provided parameters.
const Tower & operator[](const std::pair< std::size_t, std::size_t > &indices) const
Access stored value by eta/phi index (access is bounds checked)
const Tower & operator[](std::size_t index) const
Access stored value by global index number (access is bounds checked)
std::vector< Tower >::iterator end()
Iterator end point.
PufitMultiGrid & operator+=(const PufitMultiGrid &other)
Add a whole grid into this.
std::vector< Tower >::const_iterator end() const
Iterator end point.
std::array< PufitGrid, N > m_grids
Class to describe the kinematics of an object that can have negative energies.
constexpr uint16_t intLog2(std::size_t i, uint16_t tmp=0)
Compile time calculation of the log base 2 of an integer.
GridDisplacement
Enum to describe the positioning of the grid.
constexpr bool isPow2(std::size_t i)
Compile time check if a number is a power of 2.
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.
Helper struct to contain a full set of grids.
Definition PufitGrid.h:240
Element & operator-=(const SignedKinematics &kin)
Element & operator+=(const SignedKinematics &kin)
Element(PufitMultiGridSet &parent)
PufitMultiGridSet(double maxEta, std::size_t nEta, std::size_t nPhi)
const Grid & operator[](GridDisplacement displacement) const
Select a grid (const)
PufitGridSet get(std::size_t type) const
Grid & operator[](GridDisplacement displacement)
Select a grid.