File indexing completed on 2024-06-13 03:23:32
0001
0002
0003
0004 #ifndef DataFormats_HGCalReco_TICLLayerTile_h
0005 #define DataFormats_HGCalReco_TICLLayerTile_h
0006
0007 #include "DataFormats/HGCalReco/interface/Common.h"
0008 #include "DataFormats/Math/interface/normalizedPhi.h"
0009
0010 template <typename T>
0011 class TICLLayerTileT {
0012 public:
0013 typedef T type;
0014
0015 void fill(float eta, float phi, unsigned int layerClusterId) { tile_[globalBin(eta, phi)].push_back(layerClusterId); }
0016
0017 int etaBin(float eta) const {
0018 constexpr float etaRange = T::maxEta - T::minEta;
0019 static_assert(etaRange >= 0.f);
0020 float r = T::nEtaBins / etaRange;
0021 int etaBin = (std::abs(eta) - T::minEta) * r;
0022 etaBin = std::clamp(etaBin, 0, T::nEtaBins - 1);
0023 return etaBin;
0024 }
0025
0026 int phiBin(float phi) const {
0027 auto normPhi = normalizedPhi(phi);
0028 float r = T::nPhiBins * M_1_PI * 0.5f;
0029 int phiBin = (normPhi + M_PI) * r;
0030
0031 return phiBin;
0032 }
0033
0034 std::array<int, 4> searchBoxEtaPhi(float etaMin, float etaMax, float phiMin, float phiMax) const {
0035
0036
0037 if (etaMin * etaMax < 0) {
0038 return std::array<int, 4>({{0, 0, 0, 0}});
0039 }
0040 if (etaMax - etaMin < 0) {
0041 return std::array<int, 4>({{0, 0, 0, 0}});
0042 }
0043 int etaBinMin = etaBin(etaMin);
0044 int etaBinMax = etaBin(etaMax);
0045 int phiBinMin = phiBin(phiMin);
0046 int phiBinMax = phiBin(phiMax);
0047 if (etaMin < 0) {
0048 std::swap(etaBinMin, etaBinMax);
0049 }
0050
0051
0052
0053
0054
0055 if (phiBinMax < phiBinMin) {
0056 phiBinMax += T::nPhiBins;
0057 }
0058 return std::array<int, 4>({{etaBinMin, etaBinMax, phiBinMin, phiBinMax}});
0059 }
0060
0061 int globalBin(int etaBin, int phiBin) const { return phiBin + etaBin * T::nPhiBins; }
0062
0063 int globalBin(float eta, float phi) const { return phiBin(phi) + etaBin(eta) * T::nPhiBins; }
0064
0065 void clear() {
0066 auto nBins = T::nEtaBins * T::nPhiBins;
0067 for (int j = 0; j < nBins; ++j)
0068 tile_[j].clear();
0069 }
0070
0071 const std::vector<unsigned int>& operator[](int globalBinId) const { return tile_[globalBinId]; }
0072
0073 private:
0074 std::array<std::vector<unsigned int>, T::nBins> tile_;
0075 };
0076
0077 namespace ticl {
0078 using TICLLayerTile = TICLLayerTileT<TileConstants>;
0079 using Tiles = std::array<TICLLayerTile, TileConstants::nLayers>;
0080 using TracksterTiles = std::array<TICLLayerTile, TileConstants::iterations>;
0081
0082 using TICLLayerTileHFNose = TICLLayerTileT<TileConstantsHFNose>;
0083 using TilesHFNose = std::array<TICLLayerTileHFNose, TileConstantsHFNose::nLayers>;
0084 using TracksterTilesHFNose = std::array<TICLLayerTileHFNose, TileConstantsHFNose::iterations>;
0085
0086 }
0087
0088 template <typename T>
0089 class TICLGenericTile {
0090 public:
0091
0092 using constants_type_t = typename T::value_type::type;
0093
0094
0095
0096 const auto& operator[](int index) const { return tiles_[index]; }
0097 void fill(int index, float eta, float phi, unsigned int objectId) { tiles_[index].fill(eta, phi, objectId); }
0098
0099 private:
0100 T tiles_;
0101 };
0102
0103 using TICLLayerTiles = TICLGenericTile<ticl::Tiles>;
0104 using TICLTracksterTiles = TICLGenericTile<ticl::TracksterTiles>;
0105 using TICLLayerTilesHFNose = TICLGenericTile<ticl::TilesHFNose>;
0106 using TICLTracksterTilesHFNose = TICLGenericTile<ticl::TracksterTilesHFNose>;
0107
0108 #endif