Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-18 02:03:30

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(double eta, double phi, unsigned int layerClusterId) {
0016     tile_[globalBin(eta, phi)].push_back(layerClusterId);
0017   }
0018 
0019   int etaBin(float eta) const {
0020     constexpr float etaRange = T::maxEta - T::minEta;
0021     static_assert(etaRange >= 0.f);
0022     float r = T::nEtaBins / etaRange;
0023     int etaBin = (std::abs(eta) - T::minEta) * r;
0024     etaBin = std::clamp(etaBin, 0, T::nEtaBins - 1);
0025     return etaBin;
0026   }
0027 
0028   int phiBin(float phi) const {
0029     auto normPhi = normalizedPhi(phi);
0030     float r = T::nPhiBins * M_1_PI * 0.5f;
0031     int phiBin = (normPhi + M_PI) * r;
0032 
0033     return phiBin;
0034   }
0035 
0036   std::array<int, 4> searchBoxEtaPhi(float etaMin, float etaMax, float phiMin, float phiMax) const {
0037     int etaBinMin = etaBin(etaMin);
0038     int etaBinMax = etaBin(etaMax);
0039     int phiBinMin = phiBin(phiMin);
0040     int phiBinMax = phiBin(phiMax);
0041     // If the search window cross the phi-bin boundary, add T::nPhiBins to the
0042     // MAx value. This guarantees that the caller can perform a valid doule
0043     // loop on eta and phi. It is the caller responsibility to perform a module
0044     // operation on the phiBin values returned by this function, to explore the
0045     // correct bins.
0046     if (phiBinMax < phiBinMin) {
0047       phiBinMax += T::nPhiBins;
0048     }
0049     return std::array<int, 4>({{etaBinMin, etaBinMax, phiBinMin, phiBinMax}});
0050   }
0051 
0052   int globalBin(int etaBin, int phiBin) const { return phiBin + etaBin * T::nPhiBins; }
0053 
0054   int globalBin(double eta, double phi) const { return phiBin(phi) + etaBin(eta) * T::nPhiBins; }
0055 
0056   void clear() {
0057     auto nBins = T::nEtaBins * T::nPhiBins;
0058     for (int j = 0; j < nBins; ++j)
0059       tile_[j].clear();
0060   }
0061 
0062   const std::vector<unsigned int>& operator[](int globalBinId) const { return tile_[globalBinId]; }
0063 
0064 private:
0065   std::array<std::vector<unsigned int>, T::nBins> tile_;
0066 };
0067 
0068 namespace ticl {
0069   using TICLLayerTile = TICLLayerTileT<TileConstants>;
0070   using Tiles = std::array<TICLLayerTile, TileConstants::nLayers>;
0071   using TracksterTiles = std::array<TICLLayerTile, TileConstants::iterations>;
0072 
0073   using TICLLayerTileHFNose = TICLLayerTileT<TileConstantsHFNose>;
0074   using TilesHFNose = std::array<TICLLayerTileHFNose, TileConstantsHFNose::nLayers>;
0075   using TracksterTilesHFNose = std::array<TICLLayerTileHFNose, TileConstantsHFNose::iterations>;
0076 
0077 }  // namespace ticl
0078 
0079 template <typename T>
0080 class TICLGenericTile {
0081 public:
0082   // value_type_t is the type of the type of the array used by the incoming <T> type.
0083   using constants_type_t = typename T::value_type::type;
0084   // This class represents a generic collection of Tiles. The additional index
0085   // numbering is not handled internally. It is the user's responsibility to
0086   // properly use and consistently access it here.
0087   const auto& operator[](int index) const { return tiles_[index]; }
0088   void fill(int index, double eta, double phi, unsigned int objectId) { tiles_[index].fill(eta, phi, objectId); }
0089 
0090 private:
0091   T tiles_;
0092 };
0093 
0094 using TICLLayerTiles = TICLGenericTile<ticl::Tiles>;
0095 using TICLTracksterTiles = TICLGenericTile<ticl::TracksterTiles>;
0096 using TICLLayerTilesHFNose = TICLGenericTile<ticl::TilesHFNose>;
0097 using TICLTracksterTilesHFNose = TICLGenericTile<ticl::TracksterTilesHFNose>;
0098 
0099 #endif