ATLAS Offline Software
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 
10 namespace 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 
42  {
43  return m_kin;
44  }
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  }
149  const PufitGrid::Tower &PufitGrid::operator[](std::size_t index) const
150  {
151  return m_towers.at(index);
152  }
153 
155  {
156  return m_towers.begin();
157  }
158  std::vector<PufitGrid::Tower>::const_iterator PufitGrid::begin() const
159  {
160  return m_towers.begin();
161  }
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;
180  case SumStrategy::Masked:
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
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
xAOD::strategy
strategy
Definition: L2CombinedMuon_v1.cxx:107
METComponent.h
HLT::MET::PufitGrid
Bins energy deposits into a grid.
Definition: PufitGrid.h:50
HLT::MET::PufitGrid::Tower::operator-=
Tower & operator-=(const SignedKinematics &kin)
Remove the energy of a signed object from this tower.
Definition: PufitGrid.cxx:54
HLT::MET::PufitGrid::Tower::operator=
Tower & operator=(const Tower &other)
Copy assignment operator.
Definition: PufitGrid.cxx:20
HLT::MET::PeriodicGridBase::nPhiTowers
std::size_t nPhiTowers() const
The number of phi bins.
Definition: PeriodicGridBase.cxx:141
HLT::MET::PufitGrid::Tower::masked
bool masked() const
Whether or not this tower was masked.
Definition: PufitGrid.cxx:36
HLT::MET::PufitGrid::reset
void reset()
Reset the internal storage.
Definition: PufitGrid.cxx:107
HLT::MET::PufitGrid::sum
METComponent sum(SumStrategy strategy=SumStrategy::All) const
Definition: PufitGrid.cxx:171
PufitGrid.h
index
Definition: index.py:1
Trk::indices
std::pair< long int, long int > indices
Definition: AlSymMatBase.h:24
HLT::MET::PufitGridSet
Helper struct to contain a full set of grids.
Definition: PufitGrid.h:252
HLT::MET::PufitGrid::SumStrategy::All
@ All
HLT::MET::PufitGrid::operator-=
PufitGrid & operator-=(const SignedKinematics &kin)
Remove the energy of a signed object from this grid.
Definition: PufitGrid.cxx:124
athena.value
value
Definition: athena.py: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::SignedKinematics::pt
double pt() const
(signed) pt
Definition: SignedKinematics.cxx:112
TrigVSI::AlgConsts::nPhi
constexpr int nPhi
Default bin number of phi for vertex map.
Definition: Trigger/TrigTools/TrigVrtSecInclusive/TrigVrtSecInclusive/Constants.h:27
HLT::MET::PufitGrid::operator+=
PufitGrid & operator+=(const SignedKinematics &kin)
Add a signed object to this grid.
Definition: PufitGrid.cxx:115
PUfitVar::maxEta
constexpr float maxEta
Definition: GepMETPufitAlg.cxx:13
HLT::MET::PufitGridSet::PufitGridSet
PufitGridSet(double maxEta, std::size_t nEta, std::size_t nPhi)
Definition: PufitGrid.cxx:215
HLT::MET::PeriodicGridBase::displaceEta
bool displaceEta() const
Whether or not this is displaced in eta.
Definition: PeriodicGridBase.cxx:143
HLT::MET::GridDisplacement
GridDisplacement
Enum to describe the positioning of the grid.
Definition: PeriodicGridBase.h:23
HLT::MET::PufitGrid::operator=
PufitGrid & operator=(const PufitGrid &other)
Assignment operator.
Definition: PufitGrid.cxx:99
HLT::MET::PufitGrid::SumStrategy::Unmasked
@ Unmasked
HLT::MET::SignedKinematics
Class to describe the kinematics of an object that can have negative energies.
Definition: SignedKinematics.h:42
HLT::MET::PufitGrid::Tower::operator+=
Tower & operator+=(const SignedKinematics &kin)
Add a signed object to this tower.
Definition: PufitGrid.cxx:47
HLT::MET::PeriodicGridBase::parameters
const GridParameters & parameters() const
The grid parameters.
Definition: PeriodicGridBase.cxx:138
HLT::MET::PufitGrid::Tower::ey
double ey() const
The y-component of this tower's energy.
Definition: PufitGrid.cxx:30
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::PufitGrid::end
std::vector< Tower >::iterator end()
Iterator end point.
Definition: PufitGrid.cxx:162
HLT::MET::PufitGrid::SumStrategy::Masked
@ Masked
HLT::MET::PufitGridSet::grids
std::array< PufitGrid, 4 > grids
Definition: PufitGrid.h:254
HLT::MET::PufitGridSet::operator-=
PufitGridSet & operator-=(const SignedKinematics &kin)
Subtract kinematics.
Definition: PufitGrid.cxx:229
HLT::MET::PufitGrid::Tower::sumEt
double sumEt() const
The total sumEt in this tower.
Definition: PufitGrid.cxx:32
HLT::MET::PufitGrid::Tower
Describes a single element of the grid.
Definition: PufitGrid.h:60
test_pyathena.parent
parent
Definition: test_pyathena.py:15
HLT::MET::PufitGrid::m_towers
std::vector< Tower > m_towers
Definition: PufitGrid.h:247
HLT::MET::PufitGrid::Tower::eta
double eta() const
This tower's kinematic eta.
Definition: PufitGrid.cxx:35
HLT::MET::PufitGrid::begin
std::vector< Tower >::iterator begin()
Access by iterator.
Definition: PufitGrid.cxx:154
fill
void fill(H5::Group &out_file, size_t iterations)
Definition: test-hdf5-writer.cxx:95
HLT::MET::PufitGridSet::operator[]
PufitGrid & operator[](GridDisplacement displacement)
Select a grid.
Definition: PufitGrid.cxx:235
HLT::MET::PeriodicGridBase::maxEta
double maxEta() const
The maximum eta range for the grid.
Definition: PeriodicGridBase.cxx:139
HLT::MET::METComponent
Helper struct to build up MET values before moving them into the EDM.
Definition: METComponent.h:40
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::PufitGrid::PufitGrid
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
HLT::MET::PeriodicGridBase
Base class for grids used in some of the pufit algorithms.
Definition: PeriodicGridBase.h:76
HLT::MET::PufitGrid::Tower::grid
virtual const PufitGrid * grid() const override
The parent grid of this tower.
Definition: PufitGrid.cxx:39
HLT::MET::PufitGrid::Tower::sumE
double sumE() const
The total sumE in this tower.
Definition: PufitGrid.cxx:33
DeMoScan.index
string index
Definition: DeMoScan.py:364
HLT::MET::PufitGrid::operator[]
Tower & operator[](const std::pair< std::size_t, std::size_t > &indices)
Access stored value by eta/phi index (access is bounds-checked)
Definition: PufitGrid.cxx:134
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
HLT::MET::PufitGrid::Tower::ez
double ez() const
The z-component of this tower's energy.
Definition: PufitGrid.cxx:31
HLT::MET::PufitGrid::Tower::kinematics
SignedKinematics kinematics() const
Build a kinematics object from this tower.
Definition: PufitGrid.cxx:41
HLT::MET::PufitGrid::Tower::ex
double ex() const
The x-component of this tower's energy.
Definition: PufitGrid.cxx:29
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
physics_parameters.parameters
parameters
Definition: physics_parameters.py:144
HLT::MET::PufitGrid::Tower::Tower
Tower(const PufitGrid *parent, std::size_t index)
Create a tower with its parent.
Definition: PufitGrid.cxx:15
HLT::MET::operator-
PufitGrid operator-(const PufitGrid &lhs, const PufitGrid &rhs)
Elementwise subtraction.
Definition: PufitGrid.cxx:250
HLT::MET::PufitGridSet::operator+=
PufitGridSet & operator+=(const SignedKinematics &kin)
Add kinematics.
Definition: PufitGrid.cxx:223
HLT::MET::SignedKinematics::phi
double phi() const
Definition: SignedKinematics.cxx:66
HLT::MET::SignedKinematics::energy
double energy() const
Energy values (signed) energy.
Definition: SignedKinematics.cxx:131
calibdata.copy
bool copy
Definition: calibdata.py:27
TrigVSI::AlgConsts::nEta
constexpr int nEta
Default bin number of eta for vertex map.
Definition: Trigger/TrigTools/TrigVrtSecInclusive/TrigVrtSecInclusive/Constants.h:26
HLT::MET::PufitGrid::Tower::mask
void mask(bool value=true)
Set the mask on this tower.
Definition: PufitGrid.cxx:37
xAOD::JetInput::Tower
@ Tower
Definition: JetContainerInfo.h:58
HLT::MET::PufitGrid::SumStrategy
SumStrategy
Helper enum to describe how to sum over towers.
Definition: PufitGrid.h:233
HLT::MET::PufitGrid::Tower::phi
double phi() const
This tower's kinematic phi.
Definition: PufitGrid.cxx:34
HLT::MET::operator+
METComponent operator+(const METComponent &lhs, const METComponent &rhs)
Definition: METComponent.cxx:48
HLT::MET::SignedKinematics::eta
double eta() const
Direction.
Definition: SignedKinematics.cxx:62
HLT::MET::PeriodicGridBase::nEtaTowers
std::size_t nEtaTowers() const
The number of eta bins.
Definition: PeriodicGridBase.cxx:140