Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:20

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     // The tile only handles one endcap at a time and does not hold mixed eta
0038     // values.
0039     if (etaMin * etaMax < 0) {
0040       return std::array<int, 4>({{0, 0, 0, 0}});
0041     }
0042     if (etaMax - etaMin < 0) {
0043       return std::array<int, 4>({{0, 0, 0, 0}});
0044     }
0045     int etaBinMin = etaBin(etaMin);
0046     int etaBinMax = etaBin(etaMax);
0047     int phiBinMin = phiBin(phiMin);
0048     int phiBinMax = phiBin(phiMax);
0049     if (etaMin < 0) {
0050       std::swap(etaBinMin, etaBinMax);
0051     }
0052     // If the search window cross the phi-bin boundary, add T::nPhiBins to the
0053     // MAx value. This guarantees that the caller can perform a valid doule
0054     // loop on eta and phi. It is the caller responsibility to perform a module
0055     // operation on the phiBin values returned by this function, to explore the
0056     // correct bins.
0057     if (phiBinMax < phiBinMin) {
0058       phiBinMax += T::nPhiBins;
0059     }
0060     return std::array<int, 4>({{etaBinMin, etaBinMax, phiBinMin, phiBinMax}});
0061   }
0062 
0063   int globalBin(int etaBin, int phiBin) const { return phiBin + etaBin * T::nPhiBins; }
0064 
0065   int globalBin(double eta, double phi) const { return phiBin(phi) + etaBin(eta) * T::nPhiBins; }
0066 
0067   void clear() {
0068     auto nBins = T::nEtaBins * T::nPhiBins;
0069     for (int j = 0; j < nBins; ++j)
0070       tile_[j].clear();
0071   }
0072 
0073   const std::vector<unsigned int>& operator[](int globalBinId) const { return tile_[globalBinId]; }
0074 
0075 private:
0076   std::array<std::vector<unsigned int>, T::nBins> tile_;
0077 };
0078 
0079 namespace ticl {
0080   using TICLLayerTile = TICLLayerTileT<TileConstants>;
0081   using Tiles = std::array<TICLLayerTile, TileConstants::nLayers>;
0082   using TracksterTiles = std::array<TICLLayerTile, TileConstants::iterations>;
0083 
0084   using TICLLayerTileHFNose = TICLLayerTileT<TileConstantsHFNose>;
0085   using TilesHFNose = std::array<TICLLayerTileHFNose, TileConstantsHFNose::nLayers>;
0086   using TracksterTilesHFNose = std::array<TICLLayerTileHFNose, TileConstantsHFNose::iterations>;
0087 
0088 }  // namespace ticl
0089 
0090 template <typename T>
0091 class TICLGenericTile {
0092 public:
0093   // value_type_t is the type of the type of the array used by the incoming <T> type.
0094   using constants_type_t = typename T::value_type::type;
0095   // This class represents a generic collection of Tiles. The additional index
0096   // numbering is not handled internally. It is the user's responsibility to
0097   // properly use and consistently access it here.
0098   const auto& operator[](int index) const { return tiles_[index]; }
0099   void fill(int index, double eta, double phi, unsigned int objectId) { tiles_[index].fill(eta, phi, objectId); }
0100 
0101 private:
0102   T tiles_;
0103 };
0104 
0105 using TICLLayerTiles = TICLGenericTile<ticl::Tiles>;
0106 using TICLTracksterTiles = TICLGenericTile<ticl::TracksterTiles>;
0107 using TICLLayerTilesHFNose = TICLGenericTile<ticl::TilesHFNose>;
0108 using TICLTracksterTilesHFNose = TICLGenericTile<ticl::TracksterTilesHFNose>;
0109 
0110 #endif