2 * Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 #ifndef TRIGEFMISSINGET_PUFITMULTIGRID_ICC
6 #define TRIGEFMISSINGET_PUFITMULTIGRID_ICC
14 /// Initialise an array (thank you stack overflow https://stackoverflow.com/a/41259045/8434292)
15 template <typename T, std::size_t... Is>
16 constexpr std::array<T, sizeof...(Is)>
17 make_array(const T &value, std::index_sequence<Is...>)
19 return {{(static_cast<void>(Is), value)...}};
23 template <std::size_t N>
24 PufitMultiGrid<N>::Tower::Tower(PufitMultiGrid *parent, std::size_t index)
25 : PeriodicGridBase::Tower(index),
30 template <std::size_t N>
31 typename PufitMultiGrid<N>::Tower &PufitMultiGrid<N>::Tower::operator=(const Tower &other)
33 applyToAll(&PufitGrid::Tower::operator=, other); // cppcheck-suppress [syntaxError] (bug: https://trac.cppcheck.net/ticket/10080)
37 template <std::size_t N>
38 double PufitMultiGrid<N>::Tower::ex(std::size_t type) const
40 return sumOver(type, &PufitGrid::Tower::ex);
43 template <std::size_t N>
44 double PufitMultiGrid<N>::Tower::ey(std::size_t type) const
46 return sumOver(type, &PufitGrid::Tower::ey);
49 template <std::size_t N>
50 double PufitMultiGrid<N>::Tower::ez(std::size_t type) const
52 return sumOver(type, &PufitGrid::Tower::ez);
55 template <std::size_t N>
56 double PufitMultiGrid<N>::Tower::sumEt(std::size_t type) const
58 return sumOver(type, &PufitGrid::Tower::sumEt);
61 template <std::size_t N>
62 double PufitMultiGrid<N>::Tower::sumE(std::size_t type) const
64 return sumOver(type, &PufitGrid::Tower::sumE);
67 template <std::size_t N>
68 double PufitMultiGrid<N>::Tower::phi(std::size_t type) const
70 return kinematics(type).phi();
73 template <std::size_t N>
74 double PufitMultiGrid<N>::Tower::eta(std::size_t type) const
76 return kinematics(type).eta();
79 template <std::size_t N>
80 bool PufitMultiGrid<N>::Tower::masked() const { return m_mask; }
82 template <std::size_t N>
83 void PufitMultiGrid<N>::Tower::mask(bool value)
86 for (std::size_t ii = 0; ii < N; ++ii)
87 subTower(ii).mask(value);
90 template <std::size_t N>
91 const PufitMultiGrid<N> *PufitMultiGrid<N>::Tower::grid() const { return m_parent; }
93 template <std::size_t N>
94 SignedKinematics PufitMultiGrid<N>::Tower::kinematics(std::size_t type) const
96 return sumOver(type, &PufitGrid::Tower::kinematics);
99 template <std::size_t N>
100 PufitMultiGrid<N>::Tower::operator SignedKinematics() const { return kinematics(); }
102 template <std::size_t N>
103 typename PufitMultiGrid<N>::Tower &PufitMultiGrid<N>::Tower::operator+=(const Tower &other)
105 applyToAll(&PufitGrid::Tower::operator+=, other);
109 template <std::size_t N>
110 typename PufitMultiGrid<N>::Tower &PufitMultiGrid<N>::Tower::operator-=(const Tower &other)
112 applyToAll(&PufitGrid::Tower::operator-=, other);
116 template <std::size_t N>
117 PufitMultiGrid<N>::PufitMultiGrid(
119 std::size_t nEtaTowers,
120 std::size_t nPhiTowers,
124 GridParameters{maxEta, nEtaTowers, nPhiTowers, displaceEta, displacePhi})
128 template <std::size_t N>
129 PufitMultiGrid<N>::PufitMultiGrid(const GridParameters ¶meters)
130 : PeriodicGridBase(parameters),
131 m_grids(detail::make_array(PufitGrid(parameters), std::make_index_sequence<N>()))
133 m_towers.reserve(nTowers());
134 for (std::size_t index = 0; index < nTowers(); ++index)
135 m_towers.emplace_back(this, index);
138 template <std::size_t N>
139 PufitMultiGrid<N>::PufitMultiGrid(const PufitMultiGrid &other)
140 : PufitMultiGrid(other.parameters())
145 template <std::size_t N>
146 PufitMultiGrid<N> &PufitMultiGrid<N>::operator=(const PufitMultiGrid &other)
148 if (parameters() != other.parameters())
149 throw std::invalid_argument("Grid parameters do not match");
150 std::copy(other.begin(), other.end(), m_towers.begin());
151 std::copy(other.m_grids.begin(), other.m_grids.end(), m_grids.begin());
155 template <std::size_t N>
156 void PufitMultiGrid<N>::reset()
158 std::fill(begin(), end(), Tower(nullptr, -1));
159 for (PufitGrid &grid : m_grids)
162 template <std::size_t N>
163 typename PufitMultiGrid<N>::Tower &PufitMultiGrid<N>::operator[](
164 const std::pair<std::size_t, std::size_t> &indices)
166 return operator[](globalIndex(indices.first, indices.second));
168 template <std::size_t N>
169 const typename PufitMultiGrid<N>::Tower &PufitMultiGrid<N>::operator[](
170 const std::pair<std::size_t, std::size_t> &indices) const
172 return operator[](globalIndex(indices.first, indices.second));
175 template <std::size_t N>
176 typename PufitMultiGrid<N>::Tower &PufitMultiGrid<N>::operator[](std::size_t index)
178 return m_towers.at(index);
180 template <std::size_t N>
181 const typename PufitMultiGrid<N>::Tower &PufitMultiGrid<N>::operator[](std::size_t index) const
183 return m_towers.at(index);
186 template <std::size_t N>
187 typename std::vector<typename PufitMultiGrid<N>::Tower>::iterator PufitMultiGrid<N>::begin()
189 return m_towers.begin();
191 template <std::size_t N>
192 typename std::vector<typename PufitMultiGrid<N>::Tower>::const_iterator PufitMultiGrid<N>::begin() const
194 return m_towers.begin();
196 template <std::size_t N>
197 typename std::vector<typename PufitMultiGrid<N>::Tower>::iterator PufitMultiGrid<N>::end()
199 return m_towers.end();
201 template <std::size_t N>
202 typename std::vector<typename PufitMultiGrid<N>::Tower>::const_iterator PufitMultiGrid<N>::end() const
204 return m_towers.end();
207 template <std::size_t N>
208 PufitGrid PufitMultiGrid<N>::get(std::size_t type) const
211 return m_grids[intLog2(type)];
212 PufitGrid val(parameters());
213 for (std::size_t ii = 0; ii < N; ++ii)
219 template <typename Grid>
220 PufitMultiGridSet<Grid>::PufitMultiGridSet(
221 double maxEta, std::size_t nEta, std::size_t nPhi)
222 : grids({Grid(maxEta, nEta, nPhi, false, false),
223 Grid(maxEta, nEta, nPhi, true, false),
224 Grid(maxEta, nEta, nPhi, false, true),
225 Grid(maxEta, nEta, nPhi, true, true)})
229 template <typename Grid>
230 template <std::size_t I>
231 PufitMultiGridSet<Grid>::Element<I>::Element(PufitMultiGridSet &parent)
234 template <typename Grid>
235 template <std::size_t I>
236 typename PufitMultiGridSet<Grid>::template Element<I>&
237 PufitMultiGridSet<Grid>::Element<I>::operator+=(
238 const SignedKinematics &kin)
240 for (Grid &grid : parent.grids)
241 grid.template get<I>() += kin;
245 template <typename Grid>
246 template <std::size_t I>
247 typename PufitMultiGridSet<Grid>::template Element<I>&
248 PufitMultiGridSet<Grid>::Element<I>::operator-=(
249 const SignedKinematics &kin)
251 for (Grid &grid : parent.grids)
252 grid.template get<I>() -= kin;
256 template <typename Grid>
257 template <std::size_t I, typename, typename>
258 typename PufitMultiGridSet<Grid>::template Element<I>
259 PufitMultiGridSet<Grid>::get()
261 return Element<I>(*this);
264 template <typename Grid>
265 PufitGridSet PufitMultiGridSet<Grid>::get(std::size_t type) const
267 PufitGridSet gridSet(grids[0].maxEta, grids[0].nEta, grids[0].nPhi);
268 for (std::size_t ii = 0; ii < 4; ++ii)
269 gridSet.grids[ii] = grids[ii].get(type);
273 template <std::size_t N>
274 PufitMultiGrid<N> &PufitMultiGrid<N>::operator+=(const PufitMultiGrid &other)
276 if (parameters() != other.parameters())
277 throw std::invalid_argument("Grid parameters do not match");
278 auto itr = m_grids.begin();
279 auto otherItr = other.m_grids.begin();
280 for (; itr != end(); ++itr, ++otherItr)
285 template <std::size_t N>
286 PufitMultiGrid<N> &PufitMultiGrid<N>::operator-=(const PufitMultiGrid &other)
288 if (parameters() != other.parameters())
289 throw std::invalid_argument("Grid parameters do not match");
290 auto itr = m_grids.begin();
291 auto otherItr = other.m_grids.begin();
292 for (; itr != end(); ++itr, ++otherItr)
297 template <std::size_t N>
298 PufitMultiGrid<N> operator+(const PufitMultiGrid<N> &lhs, const PufitMultiGrid<N> &rhs)
300 PufitMultiGrid<N> ret(lhs);
305 template <std::size_t N>
306 PufitMultiGrid<N> operator-(const PufitMultiGrid<N> &lhs, const PufitMultiGrid<N> &rhs)
308 PufitMultiGrid<N> ret(lhs);
316 #endif //> !TRIGEFMISSINGET_PUFITMULTIGRID_ICC