Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-07-09 05:00:04

0001 // Authors: Marco Rovere, Felice Pantaleo - marco.rovere@cern.ch, felice.pantaleo@cern.ch
0002 // Date: 05/2019
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;
0022     if constexpr (std::is_same_v<T, ticl::TileConstantsBarrel>)
0023       etaBin = (eta - T::minEta) * r;
0024     else
0025       etaBin = (std::abs(eta) - T::minEta) * r;
0026     etaBin = std::clamp(etaBin, 0, T::nEtaBins - 1);
0027     return etaBin;
0028   }
0029 
0030   int phiBin(float phi) const {
0031     auto normPhi = normalizedPhi(phi);
0032     float r = T::nPhiBins * M_1_PI * 0.5f;
0033     int phiBin = (normPhi + M_PI) * r;
0034 
0035     return phiBin;
0036   }
0037 
0038   std::array<int, 4> searchBoxEtaPhi(float etaMin, float etaMax, float phiMin, float phiMax) const {
0039     // The tile only handles one endcap at a time and does not hold mixed eta
0040     // values.
0041     if (!std::is_same_v<T, ticl::TileConstantsBarrel>) {
0042       if (etaMin * etaMax < 0) {
0043         return std::array<int, 4>({{0, 0, 0, 0}});
0044       }
0045     }
0046     if (etaMax - etaMin < 0) {
0047       return std::array<int, 4>({{0, 0, 0, 0}});
0048     }
0049     int etaBinMin = etaBin(etaMin);
0050     int etaBinMax = etaBin(etaMax);
0051     int phiBinMin = phiBin(phiMin);
0052     int phiBinMax = phiBin(phiMax);
0053     if (etaMin < 0) {
0054       std::swap(etaBinMin, etaBinMax);
0055     }
0056     // If the search window cross the phi-bin boundary, add T::nPhiBins to the
0057     // MAx value. This guarantees that the caller can perform a valid doule
0058     // loop on eta and phi. It is the caller responsibility to perform a module
0059     // operation on the phiBin values returned by this function, to explore the
0060     // correct bins.
0061     if (phiBinMax < phiBinMin) {
0062       phiBinMax += T::nPhiBins;
0063     }
0064     return std::array<int, 4>({{etaBinMin, etaBinMax, phiBinMin, phiBinMax}});
0065   }
0066 
0067   int globalBin(int etaBin, int phiBin) const { return phiBin + etaBin * T::nPhiBins; }
0068 
0069   int globalBin(float eta, float phi) const { return phiBin(phi) + etaBin(eta) * T::nPhiBins; }
0070 
0071   void clear() {
0072     auto nBins = T::nEtaBins * T::nPhiBins;
0073     for (int j = 0; j < nBins; ++j)
0074       tile_[j].clear();
0075   }
0076 
0077   const std::vector<unsigned int>& operator[](int globalBinId) const { return tile_[globalBinId]; }
0078 
0079 private:
0080   std::array<std::vector<unsigned int>, T::nBins> tile_;
0081 };
0082 
0083 namespace ticl {
0084   using TICLLayerTile = TICLLayerTileT<TileConstants>;
0085   using Tiles = std::array<TICLLayerTile, TileConstants::nLayers>;
0086   using TracksterTiles = std::array<TICLLayerTile, TileConstants::iterations>;
0087 
0088   using TICLLayerTileHFNose = TICLLayerTileT<TileConstantsHFNose>;
0089   using TilesHFNose = std::array<TICLLayerTileHFNose, TileConstantsHFNose::nLayers>;
0090   using TracksterTilesHFNose = std::array<TICLLayerTileHFNose, TileConstantsHFNose::iterations>;
0091 
0092   using TICLLayerTileBarrel = TICLLayerTileT<TileConstantsBarrel>;
0093   using TilesBarrel = std::array<TICLLayerTileBarrel, TileConstantsBarrel::nLayers>;
0094   using TracksterTilesBarrel = std::array<TICLLayerTileBarrel, TileConstantsBarrel::iterations>;
0095 }  // namespace ticl
0096 
0097 template <typename T>
0098 class TICLGenericTile {
0099 public:
0100   // value_type_t is the type of the type of the array used by the incoming <T> type.
0101   using constants_type_t = typename T::value_type::type;
0102   // This class represents a generic collection of Tiles. The additional index
0103   // numbering is not handled internally. It is the user's responsibility to
0104   // properly use and consistently access it here.
0105   const auto& operator[](int index) const { return tiles_[index]; }
0106   void fill(int index, float eta, float phi, unsigned int objectId) { tiles_[index].fill(eta, phi, objectId); }
0107 
0108 private:
0109   T tiles_;
0110 };
0111 
0112 using TICLLayerTiles = TICLGenericTile<ticl::Tiles>;
0113 using TICLTracksterTiles = TICLGenericTile<ticl::TracksterTiles>;
0114 using TICLLayerTilesHFNose = TICLGenericTile<ticl::TilesHFNose>;
0115 using TICLTracksterTilesHFNose = TICLGenericTile<ticl::TracksterTilesHFNose>;
0116 using TICLLayerTilesBarrel = TICLGenericTile<ticl::TilesBarrel>;
0117 using TICLTracksterTilesBarrel = TICLGenericTile<ticl::TracksterTilesBarrel>;
0118 
0119 #endif