ATLAS Offline Software
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 
14 namespace 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 
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 
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:
179  PufitMultiGrid *const m_parent;
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  }
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 
261  typename std::vector<Tower>::const_iterator begin() const;
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>
281  PufitGrid &get()
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>
334  struct Element
335  {
340  }; //> end struct Element<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
HLT::MET::PeriodicGridBase::displacePhi
bool displacePhi() const
Whether or not this is displaced in phi.
Definition: PeriodicGridBase.cxx:144
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
HLT::MET::PufitGrid
Bins energy deposits into a grid.
Definition: PufitGrid.h:50
HLT::MET::intLog2
constexpr uint16_t intLog2(std::size_t i, uint16_t tmp=0)
Compile time calculation of the log base 2 of an integer.
Definition: PufitMultiGrid.h:46
HLT::MET::PufitMultiGrid::Tower::Tower
Tower(PufitMultiGrid *parent, std::size_t index)
Create a tower with its parent grid.
HLT::MET::PufitMultiGrid::operator+=
PufitMultiGrid & operator+=(const PufitMultiGrid &other)
Add a whole grid into this.
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
HLT::MET::PufitMultiGrid::PufitMultiGrid
PufitMultiGrid(const PufitMultiGrid &other)
Copy constructor.
HLT::MET::PufitMultiGrid::operator[]
Tower & operator[](std::size_t index)
Access stored value by global index number (access is bounds checked)
HLT::MET::PufitMultiGridSet::Element::parent
PufitMultiGridSet & parent
Definition: PufitMultiGrid.h:337
HLT::MET::PufitMultiGrid::Tower::eta
double eta(std::size_t type=All) const
This tower's kinematic eta.
HLT::MET::PeriodicGridBase::nPhiTowers
std::size_t nPhiTowers() const
The number of phi bins.
Definition: PeriodicGridBase.cxx:141
HLT::MET::PufitMultiGrid::PufitMultiGrid
PufitMultiGrid(double maxEta, std::size_t nEtaTowers, std::size_t nPhiTowers, bool displaceEta=false, bool displacePhi=false)
Create a new tower grid.
HLT::MET::PufitMultiGrid::NCategories
constexpr static std::size_t NCategories
The number of separate categories in the grid.
Definition: PufitMultiGrid.h:73
HLT::MET::PeriodicGridBase::Tower
Base class for towers belonging to the grids.
Definition: PeriodicGridBase.h:82
PufitGrid.h
HLT::MET::PufitMultiGrid::Tower::operator-=
Tower & operator-=(const Tower &other)
Subtract another tower's energies from this one.
index
Definition: index.py:1
Trk::indices
std::pair< long int, long int > indices
Definition: AlSymMatBase.h:24
HLT::MET::PufitMultiGridSet::Element::operator+=
Element & operator+=(const SignedKinematics &kin)
HLT::MET::PufitGridSet
Helper struct to contain a full set of grids.
Definition: PufitGrid.h:252
athena.value
value
Definition: athena.py:122
HLT::MET::PufitMultiGrid::operator-=
PufitMultiGrid & operator-=(const PufitMultiGrid &other)
Subtract a whole grid from this.
HLT::MET::PufitMultiGrid::end
std::vector< Tower >::iterator end()
Iterator end point.
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
HLT::MET::isPow2
constexpr bool isPow2(std::size_t i)
Compile time check if a number is a power of 2.
Definition: PufitMultiGrid.h:19
HLT::MET::PufitMultiGrid::operator[]
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)
HLT::MET::PufitMultiGrid::begin
std::vector< Tower >::const_iterator begin() const
Access by iterator.
TrigVSI::AlgConsts::nPhi
constexpr int nPhi
Default bin number of phi for vertex map.
Definition: Trigger/TrigTools/TrigVrtSecInclusive/TrigVrtSecInclusive/Constants.h:27
PUfitVar::maxEta
constexpr float maxEta
Definition: GepMETPufitAlg.cxx:13
HLT::MET::PufitMultiGrid::Tower::ez
double ez(std::size_t type=All) const
The z-component of this tower's energy.
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::PufitMultiGrid::Tower::sumE
double sumE(std::size_t type=All) const
The total sumE in this tower.
HLT::MET::GridDisplacement
GridDisplacement
Enum to describe the positioning of the grid.
Definition: PeriodicGridBase.h:23
HLT::MET::PufitMultiGridSet::operator[]
Grid & operator[](GridDisplacement displacement)
Select a grid.
Definition: PufitMultiGrid.h:321
HLT::MET::SignedKinematics
Class to describe the kinematics of an object that can have negative energies.
Definition: SignedKinematics.h:42
HLT::MET::PufitMultiGrid::operator[]
const Tower & operator[](std::size_t index) const
Access stored value by global index number (access is bounds checked)
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
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
lumiFormat.i
int i
Definition: lumiFormat.py:92
HLT::MET::PufitMultiGrid::Tower::PufitMulitGrid
friend class PufitMulitGrid
Definition: PufitMultiGrid.h:84
HLT::MET::PufitMultiGrid::operator=
PufitMultiGrid & operator=(const PufitMultiGrid &other)
Assignment operator.
PufitMultiGrid.icc
HLT::MET::PufitGrid::Tower
Describes a single element of the grid.
Definition: PufitGrid.h:60
HLT::MET::PufitMultiGrid::All
constexpr static std::size_t All
Maximum value representable by N bits.
Definition: PufitMultiGrid.h:71
TCS::MET
@ MET
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/Types.h:16
test_pyathena.parent
parent
Definition: test_pyathena.py:15
HLT::MET::PufitMultiGrid::Tower::phi
double phi(std::size_t type=All) const
This tower's kinematic phi.
HLT::MET::PufitMultiGrid::Tower::ey
double ey(std::size_t type=All) const
The y-component of this tower's energy.
HLT::MET::PufitMultiGrid::Tower::sumEt
double sumEt(std::size_t type=All) const
The total sumEt in this tower.
HLT::MET::PufitMultiGrid::Tower::sumOver
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.
Definition: PufitMultiGrid.h:205
HLT::MET::PufitMultiGridSet::operator[]
const Grid & operator[](GridDisplacement displacement) const
Select a grid (const)
Definition: PufitMultiGrid.h:327
HLT::MET::PufitMultiGridSet::Element::operator-=
Element & operator-=(const SignedKinematics &kin)
HLT::MET::PufitMultiGrid::Tower::Tower
Tower(const Tower &)=default
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
HLT::MET::PufitMultiGridSet::Element::Element
Element(PufitMultiGridSet &parent)
HLT::MET::PufitMultiGrid::Tower::kinematics
SignedKinematics kinematics(std::size_t type=All) const
Build a kinematics object from this tower.
HLT::MET::PufitMultiGrid::Tower::applyToAll
void applyToAll(PufitGrid::Tower &(PufitGrid::Tower::*f)(const PufitGrid::Tower &), const PufitMultiGrid::Tower &other)
Apply a function to all sub towers.
Definition: PufitMultiGrid.h:196
HLT::MET::PufitMultiGrid::begin
std::vector< Tower >::iterator begin()
Access by iterator.
HLT::MET::PeriodicGridBase::maxEta
double maxEta() const
The maximum eta range for the grid.
Definition: PeriodicGridBase.cxx:139
HLT::MET::PufitMultiGrid::Tower::grid
const PufitMultiGrid * grid() const override
The parent grid of this tower.
HLT::MET::PufitMultiGrid::Tower
Tower in the multi-grid.
Definition: PufitMultiGrid.h:83
PeriodicGridBase.h
Provide a base class for the grids used in some pufit algorithms.
HLT::MET::PufitMultiGrid::reset
void reset()
Reset the internal storage.
HLT::MET::PufitMultiGrid::end
std::vector< Tower >::const_iterator end() const
Iterator end point.
HLT::MET::PeriodicGridBase
Base class for grids used in some of the pufit algorithms.
Definition: PeriodicGridBase.h:76
HLT::MET::PufitMultiGrid::operator[]
Tower & operator[](const std::pair< std::size_t, std::size_t > &indices)
Access stored value by eta/phi index (access is bounds checked)
HLT::MET::PufitMultiGrid
Multiple grids combined into one.
Definition: PufitMultiGrid.h:63
HLT::MET::PufitMultiGrid::Tower::operator=
Tower & operator=(const Tower &other)
Copy assignment operator.
HLT::MET::PufitMultiGrid::Tower::ex
double ex(std::size_t type=All) const
The x-component of this tower's energy.
HLT::MET::PufitMultiGridSet::Element
Helper struct to forward the SignedKinematics operators nicely.
Definition: PufitMultiGrid.h:335
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
HLT::MET::PufitMultiGridSet::PufitMultiGridSet
PufitMultiGridSet(double maxEta, std::size_t nEta, std::size_t nPhi)
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
HLT::MET::PufitMultiGrid::Tower::mask
void mask(bool value=true)
Set the mask on this tower.
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
HLT::MET::GridParameters
Parameters describing a grid.
Definition: PeriodicGridBase.h:43
HLT::MET::PufitMultiGridSet::grids
std::array< Grid, 4 > grids
Definition: PufitMultiGrid.h:318
HLT::MET::PufitMultiGrid::Tower::operator+=
Tower & operator+=(const Tower &other)
Add another tower's energies into this one.
I
#define I(x, y, z)
Definition: MD5.cxx:116
HLT::MET::PufitMultiGrid::Tower::masked
bool masked() const
Whether or not this tower was masked.
TrigVSI::AlgConsts::nEta
constexpr int nEta
Default bin number of eta for vertex map.
Definition: Trigger/TrigTools/TrigVrtSecInclusive/TrigVrtSecInclusive/Constants.h:26
xAOD::JetInput::Tower
@ Tower
Definition: JetContainerInfo.h:58
HLT::MET::PufitMultiGridSet
Helper struct to forward the SignedKinematics operators nicely.
Definition: PufitMultiGrid.h:316
HLT::MET::PufitMultiGrid::PufitMultiGrid
PufitMultiGrid(const GridParameters &parameters)
Construct a grid from the provided parameters.
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
HLT::MET::PeriodicGridBase::nEtaTowers
std::size_t nEtaTowers() const
The number of eta bins.
Definition: PeriodicGridBase.cxx:140