CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HGCalLayerTiles.h
Go to the documentation of this file.
1 // Authors: Felice Pantaleo - felice.pantaleo@cern.ch
2 // Date: 03/2019
3 
4 #ifndef RecoLocalCalo_HGCalRecProducers_HGCalLayerTiles_h
5 #define RecoLocalCalo_HGCalRecProducers_HGCalLayerTiles_h
6 
9 
10 #include <vector>
11 #include <array>
12 #include <cmath>
13 #include <algorithm>
14 #include <cassert>
15 
16 template <typename T>
18 public:
19  void fill(const std::vector<float>& x,
20  const std::vector<float>& y,
21  const std::vector<float>& eta,
22  const std::vector<float>& phi,
23  const std::vector<bool>& isSi) {
24  auto cellsSize = x.size();
25  for (unsigned int i = 0; i < cellsSize; ++i) {
26  tiles_[getGlobalBin(x[i], y[i])].push_back(i);
27  if (!isSi[i]) {
28  tiles_[getGlobalBinEtaPhi(eta[i], phi[i])].push_back(i);
29  // Copy cells in phi=[-3.15,-3.] to the last bin
30  if (getPhiBin(phi[i]) == mPiPhiBin) {
31  tiles_[getGlobalBinEtaPhi(eta[i], phi[i] + 2 * M_PI)].push_back(i);
32  }
33  // Copy cells in phi=[3.,3.15] to the first bin
34  if (getPhiBin(phi[i]) == pPiPhiBin) {
35  tiles_[getGlobalBinEtaPhi(eta[i], phi[i] - 2 * M_PI)].push_back(i);
36  }
37  }
38  }
39  }
40 
41  int getXBin(float x) const {
42  constexpr float xRange = T::maxX - T::minX;
43  static_assert(xRange >= 0.);
44  constexpr float r = T::nColumns / xRange;
45  int xBin = (x - T::minX) * r;
46  xBin = std::clamp(xBin, 0, T::nColumns - 1);
47  return xBin;
48  }
49 
50  int getYBin(float y) const {
51  constexpr float yRange = T::maxY - T::minY;
52  static_assert(yRange >= 0.);
53  constexpr float r = T::nRows / yRange;
54  int yBin = (y - T::minY) * r;
55  yBin = std::clamp(yBin, 0, T::nRows - 1);
56  return yBin;
57  }
58 
59  int getEtaBin(float eta) const {
60  constexpr float etaRange = T::maxEta - T::minEta;
61  static_assert(etaRange >= 0.);
62  constexpr float r = T::nColumnsEta / etaRange;
63  int etaBin = (eta - T::minEta) * r;
64  etaBin = std::clamp(etaBin, 0, T::nColumnsEta - 1);
65  return etaBin;
66  }
67 
68  int getPhiBin(float phi) const {
69  constexpr float phiRange = T::maxPhi - T::minPhi;
70  static_assert(phiRange >= 0.);
71  constexpr float r = T::nRowsPhi / phiRange;
72  int phiBin = (phi - T::minPhi) * r;
73  phiBin = std::clamp(phiBin, 0, T::nRowsPhi - 1);
74  return phiBin;
75  }
76 
79 
80  int getGlobalBin(float x, float y) const { return getXBin(x) + getYBin(y) * T::nColumns; }
81 
82  int getGlobalBinByBin(int xBin, int yBin) const { return xBin + yBin * T::nColumns; }
83 
84  int getGlobalBinEtaPhi(float eta, float phi) const {
85  return T::nColumns * T::nRows + getEtaBin(eta) + getPhiBin(phi) * T::nColumnsEta;
86  }
87 
88  int getGlobalBinByBinEtaPhi(int etaBin, int phiBin) const {
89  return T::nColumns * T::nRows + etaBin + phiBin * T::nColumnsEta;
90  }
91 
92  std::array<int, 4> searchBox(float xMin, float xMax, float yMin, float yMax) const {
93  int xBinMin = getXBin(xMin);
94  int xBinMax = getXBin(xMax);
95  int yBinMin = getYBin(yMin);
96  int yBinMax = getYBin(yMax);
97  return std::array<int, 4>({{xBinMin, xBinMax, yBinMin, yBinMax}});
98  }
99 
100  std::array<int, 4> searchBoxEtaPhi(float etaMin, float etaMax, float phiMin, float phiMax) const {
101  int etaBinMin = getEtaBin(etaMin);
102  int etaBinMax = getEtaBin(etaMax);
103  int phiBinMin = getPhiBin(phiMin);
104  int phiBinMax = getPhiBin(phiMax);
105  return std::array<int, 4>({{etaBinMin, etaBinMax, phiBinMin, phiBinMax}});
106  }
107 
108  void clear() {
109  for (auto& t : tiles_)
110  t.clear();
111  }
112 
113  const std::vector<int>& operator[](int globalBinId) const { return tiles_[globalBinId]; }
114 
115 private:
116  std::array<std::vector<int>, T::nTiles> tiles_;
117 };
118 
121 #endif
std::array< int, 4 > searchBoxEtaPhi(float etaMin, float etaMax, float phiMin, float phiMax) const
tuple yBin
Definition: cuy.py:892
int getXBin(float x) const
int getEtaBin(float eta) const
tuple etaMin
Definition: Puppi_cff.py:45
double maxEta
int getPhiBin(float phi) const
int getGlobalBinEtaPhi(float eta, float phi) const
int getGlobalBin(float x, float y) const
std::array< std::vector< int >, T::nTiles > tiles_
#define M_PI
int getYBin(float y) const
void fill(const std::vector< float > &x, const std::vector< float > &y, const std::vector< float > &eta, const std::vector< float > &phi, const std::vector< bool > &isSi)
const std::vector< int > & operator[](int globalBinId) const
int getGlobalBinByBinEtaPhi(int etaBin, int phiBin) const
int getGlobalBinByBin(int xBin, int yBin) const
tuple etaMax
Definition: Puppi_cff.py:46
std::array< int, 4 > searchBox(float xMin, float xMax, float yMin, float yMax) const
int etaBin(const l1t::HGCalMulticluster *cl)