CMS 3D CMS Logo

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_HGCalRecAlgos_HGCalLayerTiles
5 #define RecoLocalCalo_HGCalRecAlgos_HGCalLayerTiles
6 
8 
9 #include <vector>
10 #include <array>
11 #include <cmath>
12 #include <algorithm>
13 #include <cassert>
14 
16 public:
17  void fill(const std::vector<float>& x,
18  const std::vector<float>& y,
19  const std::vector<float>& eta,
20  const std::vector<float>& phi,
21  const std::vector<bool>& isSi) {
22  auto cellsSize = x.size();
23  for (unsigned int i = 0; i < cellsSize; ++i) {
24  tiles_[getGlobalBin(x[i], y[i])].push_back(i);
25  if (!isSi[i]) {
26  tiles_[getGlobalBinEtaPhi(eta[i], phi[i])].push_back(i);
27  // Copy cells in phi=[-3.15,-3.] to the last bin
28  if (getPhiBin(phi[i]) == mPiPhiBin) {
29  tiles_[getGlobalBinEtaPhi(eta[i], phi[i] + 2 * M_PI)].push_back(i);
30  }
31  // Copy cells in phi=[3.,3.15] to the first bin
32  if (getPhiBin(phi[i]) == pPiPhiBin) {
33  tiles_[getGlobalBinEtaPhi(eta[i], phi[i] - 2 * M_PI)].push_back(i);
34  }
35  }
36  }
37  }
38 
39  int getXBin(float x) const {
41  static_assert(xRange >= 0.);
43  int xBin = (x - hgcaltilesconstants::minX) * r;
44  xBin = std::clamp(xBin, 0, hgcaltilesconstants::nColumns - 1);
45  return xBin;
46  }
47 
48  int getYBin(float y) const {
50  static_assert(yRange >= 0.);
52  int yBin = (y - hgcaltilesconstants::minY) * r;
53  yBin = std::clamp(yBin, 0, hgcaltilesconstants::nRows - 1);
54  return yBin;
55  }
56 
57  int getEtaBin(float eta) const {
59  static_assert(etaRange >= 0.);
61  int etaBin = (eta - hgcaltilesconstants::minEta) * r;
62  etaBin = std::clamp(etaBin, 0, hgcaltilesconstants::nColumnsEta - 1);
63  return etaBin;
64  }
65 
66  int getPhiBin(float phi) const {
68  static_assert(phiRange >= 0.);
69  constexpr float r = hgcaltilesconstants::nRowsPhi / phiRange;
70  int phiBin = (phi - hgcaltilesconstants::minPhi) * r;
71  phiBin = std::clamp(phiBin, 0, hgcaltilesconstants::nRowsPhi - 1);
72  return phiBin;
73  }
74 
77 
78  int getGlobalBin(float x, float y) const { return getXBin(x) + getYBin(y) * hgcaltilesconstants::nColumns; }
79 
80  int getGlobalBinByBin(int xBin, int yBin) const { return xBin + yBin * hgcaltilesconstants::nColumns; }
81 
82  int getGlobalBinEtaPhi(float eta, float phi) const {
85  }
86 
87  int getGlobalBinByBinEtaPhi(int etaBin, int phiBin) const {
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>, hgcaltilesconstants::nTiles> tiles_;
117 };
118 
119 #endif
int getEtaBin(float eta) const
int getYBin(float y) const
int getGlobalBinByBinEtaPhi(int etaBin, int phiBin) const
constexpr float minEta
std::array< int, 4 > searchBox(float xMin, float xMax, float yMin, float yMax) const
std::array< std::vector< int >, hgcaltilesconstants::nTiles > tiles_
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)
int getGlobalBinByBin(int xBin, int yBin) const
int getPhiBin(float phi) const
int getGlobalBin(float x, float y) const
int getGlobalBinEtaPhi(float eta, float phi) const
std::array< int, 4 > searchBoxEtaPhi(float etaMin, float etaMax, float phiMin, float phiMax) const
#define M_PI
const std::vector< int > & operator[](int globalBinId) const
constexpr float maxPhi
constexpr float minPhi
constexpr float maxEta
#define constexpr
int getXBin(float x) const