CMS 3D CMS Logo

HGCalHistoSeedingImpl.h
Go to the documentation of this file.
1 #ifndef __L1Trigger_L1THGCal_HGCalHistoSeedingImpl_h__
2 #define __L1Trigger_L1THGCal_HGCalHistoSeedingImpl_h__
3 
8 
13 
15 private:
16  struct Bin {
17  enum Content { Sum, Ecal, Hcal };
18  std::array<float, 3> values = {{0., 0., 0.}};
19  float weighted_x = 0.;
20  float weighted_y = 0.;
21  };
22  template <typename T>
23  class HistogramT {
24  public:
25  using Data = std::vector<T>;
26  using iterator = typename Data::iterator;
27  using const_iterator = typename Data::const_iterator;
28 
29  public:
30  HistogramT() : bins1_(0), bins2_(0), bins_(0) {}
31  HistogramT(unsigned bins1, unsigned bins2)
32  : bins1_(bins1), bins2_(bins2), bins_(bins1 * bins2), histogram_(bins_ * kSides_) {}
33 
34  T& at(int zside, unsigned x1, unsigned x2) { return histogram_[index(zside, x1, x2)]; }
35 
36  const T& at(int zside, unsigned x1, unsigned x2) const { return histogram_[index(zside, x1, x2)]; }
37 
38  iterator begin() { return histogram_.begin(); }
39  const_iterator begin() const { return histogram_.begin(); }
40  iterator end() { return histogram_.end(); }
41  const_iterator end() const { return histogram_.end(); }
42 
43  private:
44  static constexpr unsigned kSides_ = 2;
45  unsigned bins1_ = 0;
46  unsigned bins2_ = 0;
47  unsigned bins_ = 0;
49 
50  unsigned index(int zside, unsigned x1, unsigned x2) const {
51  if (x1 >= bins1_ || x2 >= bins2_) {
52  throw cms::Exception("OutOfBound") << "Trying to access bin (" << x1 << "," << x2
53  << ") in seeding histogram of size (" << bins1_ << "," << bins2_ << ")";
54  }
55  return x2 + bins2_ * x1 + bins_ * (zside > 0 ? 1 : 0);
56  }
57  };
59 
60  class Navigator {
61  public:
62  enum class AxisType { Bounded, Circular };
63 
65 
66  Navigator(int bins1, AxisType type_axis1, int bins2, AxisType type_axis2)
67  : axis_types_({{type_axis1, type_axis2}}), bins_({{bins1, bins2}}), home_({{0, 0}}) {}
68 
69  void setHome(int x1, int x2) {
70  if (x1 < 0 || x2 < 0 || x1 >= std::get<0>(bins_) || x2 >= std::get<1>(bins_)) {
71  throw cms::Exception("OutOfBound") << "Setting invalid navigator home position (" << x1 << "," << x2 << "\n)";
72  }
73  home_[0] = x1;
74  home_[1] = x2;
75  }
76 
77  std::array<int, 2> move(int offset1, int offset2) { return {{offset<0>(offset1), offset<1>(offset2)}}; }
78 
79  template <unsigned N>
80  int offset(int shift) {
81  int shifted = std::get<N>(home_);
82  int max = std::get<N>(bins_);
83  switch (std::get<N>(axis_types_)) {
84  case AxisType::Bounded:
85  shifted += shift;
86  if (shifted < 0 || shifted >= max)
87  shifted = -1;
88  break;
89  case AxisType::Circular:
90  shifted += shift;
91  while (shifted < 0)
92  shifted += max;
93  while (shifted >= max)
94  shifted -= max;
95  break;
96  default:
97  break;
98  }
99  return shifted;
100  }
101 
102  private:
103  std::array<AxisType, 2> axis_types_;
104  std::array<int, 2> bins_;
105  std::array<int, 2> home_;
106  };
107 
108 public:
110 
112 
113  float dR(const l1t::HGCalCluster& clu, const GlobalPoint& seed) const;
114 
115  void findHistoSeeds(const std::vector<edm::Ptr<l1t::HGCalCluster>>& clustersPtr,
116  std::vector<std::pair<GlobalPoint, double>>& seedPositionsEnergy);
117 
118 private:
120  enum SeedingSpace { RPhi, XY };
122 
124 
125  Histogram fillSmoothHistoClusters(const Histogram&, const vector<double>&, Bin::Content);
126  Histogram fillSmoothPhiHistoClusters(const Histogram& histoClusters, const vector<unsigned>& binSums);
127  Histogram fillSmoothRPhiHistoClusters(const Histogram& histoClusters);
128 
129  void setSeedEnergyAndPosition(std::vector<std::pair<GlobalPoint, double>>& seedPositionsEnergy,
130  int z_side,
131  unsigned bin_R,
132  unsigned bin_phi,
133  const Bin& histBin);
134 
135  std::vector<std::pair<GlobalPoint, double>> computeMaxSeeds(const Histogram& histoClusters);
136 
137  std::vector<std::pair<GlobalPoint, double>> computeSecondaryMaxSeeds(const Histogram& histoClusters);
138 
139  std::vector<std::pair<GlobalPoint, double>> computeInterpolatedMaxSeeds(const Histogram& histoClusters);
140 
141  std::vector<std::pair<GlobalPoint, double>> computeThresholdSeeds(const Histogram& histoClusters);
142 
143  std::array<double, 4> boundaries();
144 
149 
150  unsigned nBins1_ = 42;
151  unsigned nBins2_ = 216;
152  std::vector<unsigned> binsSumsHisto_;
153  double histoThreshold_ = 20.;
154  static constexpr double area_per_triggercell_ =
155  4.91E-05; // Hex_Wafer_Area (x/z units)/N_TC (per wafer) = (0.866*((hexWafer_minimal_diameter)*(1./319.))^2 / 48)
156  std::vector<double> neighbour_weights_;
157  std::vector<double> smoothing_ecal_;
158  std::vector<double> smoothing_hcal_;
160 
161  float area_10pct_;
162 
165 
166  static constexpr unsigned neighbour_weights_size_ = 9;
167  const double kROverZMin_ = 0.076;
168  const double kROverZMax_ = 0.58;
169 
170  static constexpr double kXYMax_ = 0.6;
171 };
172 
173 #endif
std::vector< std::pair< GlobalPoint, double > > computeInterpolatedMaxSeeds(const Histogram &histoClusters)
static constexpr unsigned neighbour_weights_size_
std::vector< unsigned > binsSumsHisto_
Histogram fillSmoothPhiHistoClusters(const Histogram &histoClusters, const vector< unsigned > &binSums)
const T & at(int zside, unsigned x1, unsigned x2) const
Histogram fillSmoothRPhiHistoClusters(const Histogram &histoClusters)
SeedingPosition seedingPosition_
int zside(DetId const &)
typename Data::const_iterator const_iterator
std::vector< std::pair< GlobalPoint, double > > computeMaxSeeds(const Histogram &histoClusters)
HGCalTriggerTools triggerTools_
void setGeometry(const HGCalTriggerGeometryBase *const)
std::vector< std::pair< GlobalPoint, double > > computeSecondaryMaxSeeds(const Histogram &histoClusters)
void findHistoSeeds(const std::vector< edm::Ptr< l1t::HGCalCluster >> &clustersPtr, std::vector< std::pair< GlobalPoint, double >> &seedPositionsEnergy)
void setSeedEnergyAndPosition(std::vector< std::pair< GlobalPoint, double >> &seedPositionsEnergy, int z_side, unsigned bin_R, unsigned bin_phi, const Bin &histBin)
Histogram fillSmoothHistoClusters(const Histogram &, const vector< double > &, Bin::Content)
std::array< int, 2 > move(int offset1, int offset2)
std::array< double, 4 > boundaries()
HistogramT< Bin > Histogram
float dR(const l1t::HGCalCluster &clu, const GlobalPoint &seed) const
std::vector< double > smoothing_ecal_
void setGeometry(const HGCalTriggerGeometryBase *const geom)
std::vector< std::pair< GlobalPoint, double > > computeThresholdSeeds(const Histogram &histoClusters)
std::array< float, 3 > values
std::array< AxisType, 2 > axis_types_
unsigned index(int zside, unsigned x1, unsigned x2) const
std::vector< double > neighbour_weights_
Histogram fillHistoClusters(const std::vector< edm::Ptr< l1t::HGCalCluster >> &clustersPtrs)
static constexpr double kXYMax_
static unsigned int const shift
Navigator(int bins1, AxisType type_axis1, int bins2, AxisType type_axis2)
T & at(int zside, unsigned x1, unsigned x2)
std::vector< double > smoothing_hcal_
long double T
HistogramT(unsigned bins1, unsigned bins2)
static constexpr double area_per_triggercell_
HGCalHistoSeedingImpl(const edm::ParameterSet &conf)