CMS 3D CMS Logo

HGCalHistoSeedingImpl.cc
Go to the documentation of this file.
5 #include <numeric>
6 
8  : seedingAlgoType_(conf.getParameter<std::string>("type_histoalgo")),
9  nBins1_(conf.getParameter<unsigned>("nBins_X1_histo_multicluster")),
10  nBins2_(conf.getParameter<unsigned>("nBins_X2_histo_multicluster")),
11  binsSumsHisto_(conf.getParameter<std::vector<unsigned>>("binSumsHisto")),
12  histoThreshold_(conf.getParameter<double>("threshold_histo_multicluster")),
13  neighbour_weights_(conf.getParameter<std::vector<double>>("neighbour_weights")),
14  smoothing_ecal_(conf.getParameter<std::vector<double>>("seed_smoothing_ecal")),
15  smoothing_hcal_(conf.getParameter<std::vector<double>>("seed_smoothing_hcal")) {
16  if (seedingAlgoType_ == "HistoMaxC3d") {
18  } else if (seedingAlgoType_ == "HistoSecondaryMaxC3d") {
20  } else if (seedingAlgoType_ == "HistoThresholdC3d") {
22  } else if (seedingAlgoType_ == "HistoInterpolatedMaxC3d") {
24  } else {
25  throw cms::Exception("HGCTriggerParameterError") << "Unknown Multiclustering type '" << seedingAlgoType_;
26  }
27 
28  if (conf.getParameter<std::string>("seed_position") == "BinCentre") {
30  } else if (conf.getParameter<std::string>("seed_position") == "TCWeighted") {
32  } else {
33  throw cms::Exception("HGCTriggerParameterError")
34  << "Unknown Seed Position option '" << conf.getParameter<std::string>("seed_position");
35  }
36  if (conf.getParameter<std::string>("seeding_space") == "RPhi") {
39  } else if (conf.getParameter<std::string>("seeding_space") == "XY") {
40  seedingSpace_ = XY;
42  } else {
43  throw cms::Exception("HGCTriggerParameterError")
44  << "Unknown seeding space '" << conf.getParameter<std::string>("seeding_space");
45  }
46 
47  edm::LogInfo("HGCalMulticlusterParameters")
48  << "\nMulticluster number of X1-bins for the histo algorithm: " << nBins1_
49  << "\nMulticluster number of X2-bins for the histo algorithm: " << nBins2_
50  << "\nMulticluster MIPT threshold for histo threshold algorithm: " << histoThreshold_
51  << "\nMulticluster type of multiclustering algortihm: " << seedingAlgoType_;
52 
53  if (seedingAlgoType_.find("Histo") != std::string::npos && seedingSpace_ == RPhi &&
54  nBins1_ != binsSumsHisto_.size()) {
55  throw cms::Exception("Inconsistent bin size")
56  << "Inconsistent nBins_X1_histo_multicluster ( " << nBins1_ << " ) and binSumsHisto ( " << binsSumsHisto_.size()
57  << " ) size in HGCalMulticlustering\n";
58  }
59 
61  throw cms::Exception("Inconsistent vector size")
62  << "Inconsistent size of neighbour weights vector in HGCalMulticlustering ( " << neighbour_weights_.size()
63  << " ). Should be " << neighbour_weights_size_ << "\n";
64  }
65 }
66 
68  const std::vector<edm::Ptr<l1t::HGCalCluster>>& clustersPtrs) {
69  Histogram histoClusters(nBins1_, nBins2_);
70  std::array<double, 4> bounds = boundaries();
71  double minx1 = std::get<0>(bounds);
72  double maxx1 = std::get<1>(bounds);
73  double minx2 = std::get<2>(bounds);
74  double maxx2 = std::get<3>(bounds);
75 
76  for (auto& clu : clustersPtrs) {
77  float x1 = 0., x2 = 0;
78  switch (seedingSpace_) {
79  case RPhi:
80  x1 = sqrt(pow(clu->centreProj().x(), 2) + pow(clu->centreProj().y(), 2));
81  x2 = reco::reduceRange(clu->phi());
82  break;
83  case XY:
84  x1 = clu->centreProj().x();
85  x2 = clu->centreProj().y();
86  break;
87  };
88  if (x1 < minx1 || x1 >= maxx1) {
89  throw cms::Exception("OutOfBound") << "TC X1 = " << x1 << " out of the seeding histogram bounds " << minx1
90  << " - " << maxx1;
91  }
92  if (x2 < minx2 || x2 >= maxx2) {
93  throw cms::Exception("OutOfBound") << "TC X2 = " << x2 << " out of the seeding histogram bounds " << minx2
94  << " - " << maxx2;
95  }
96  unsigned bin1 = unsigned((x1 - minx1) * nBins1_ / (maxx1 - minx1));
97  unsigned bin2 = unsigned((x2 - minx2) * nBins2_ / (maxx2 - minx2));
98 
99  auto& bin = histoClusters.at(triggerTools_.zside(clu->detId()), bin1, bin2);
100  bin.values[Bin::Content::Sum] += clu->mipPt();
101  if (triggerTools_.isEm(clu->detId())) {
102  bin.values[Bin::Content::Ecal] += clu->mipPt();
103  } else {
104  bin.values[Bin::Content::Hcal] += clu->mipPt();
105  }
106  bin.weighted_x += (clu->centreProj().x()) * clu->mipPt();
107  bin.weighted_y += (clu->centreProj().y()) * clu->mipPt();
108  }
109 
110  for (auto& bin : histoClusters) {
111  bin.weighted_x /= bin.values[Bin::Content::Sum];
112  bin.weighted_y /= bin.values[Bin::Content::Sum];
113  }
114 
115  return histoClusters;
116 }
117 
119  const vector<double>& kernel,
120  Bin::Content binContent) {
121  Histogram histoSmooth(histoClusters);
122 
123  unsigned kernel_size = std::sqrt(kernel.size());
124  if (kernel_size * kernel_size != kernel.size()) {
125  throw cms::Exception("HGCTriggerParameterError") << "Only square kernels can be used.";
126  }
127  if (kernel_size % 2 != 1) {
128  throw cms::Exception("HGCTriggerParameterError") << "The kernel size must be an odd value.";
129  }
130  int shift_max = (kernel_size - 1) / 2;
131  double normalization = std::accumulate(kernel.begin(), kernel.end(), 0.);
132  for (int z_side : {-1, 1}) {
133  for (unsigned x1 = 0; x1 < nBins1_; x1++) {
134  for (unsigned x2 = 0; x2 < nBins2_; x2++) {
135  const auto& bin_orig = histoClusters.at(z_side, x1, x2);
136  double smooth = 0.;
138  for (int x1_shift = -shift_max; x1_shift <= shift_max; x1_shift++) {
139  int index1 = x1_shift + shift_max;
140  for (int x2_shift = -shift_max; x2_shift <= shift_max; x2_shift++) {
141  auto shifted = navigator_.move(x1_shift, x2_shift);
142  int index2 = x2_shift + shift_max;
143  double kernel_value = kernel.at(index1 * kernel_size + index2);
144  bool out = shifted[0] == -1 || shifted[1] == -1;
145  double content = (out ? 0. : histoClusters.at(z_side, shifted[0], shifted[1]).values[binContent]);
146  smooth += content * kernel_value;
147  }
148  }
149  auto& bin = histoSmooth.at(z_side, x1, x2);
150  bin.values[binContent] = smooth / normalization;
151  bin.weighted_x = bin_orig.weighted_x;
152  bin.weighted_y = bin_orig.weighted_y;
153  }
154  }
155  }
156 
157  return histoSmooth;
158 }
159 
161  const vector<unsigned>& binSums) {
162  Histogram histoSumPhiClusters(nBins1_, nBins2_);
163 
164  for (int z_side : {-1, 1}) {
165  for (unsigned bin1 = 0; bin1 < nBins1_; bin1++) {
166  int nBinsSide = (binSums[bin1] - 1) / 2;
167  float R1 = kROverZMin_ + bin1 * (kROverZMax_ - kROverZMin_);
168  float R2 = R1 + (kROverZMax_ - kROverZMin_);
169  double area =
170  0.5 * (pow(R2, 2) - pow(R1, 2)) *
171  (1 +
172  0.5 *
173  (1 -
174  pow(0.5,
175  nBinsSide))); // Takes into account different area of bins in different R-rings + sum of quadratic weights used
176 
177  for (unsigned bin2 = 0; bin2 < nBins2_; bin2++) {
178  const auto& bin_orig = histoClusters.at(z_side, bin1, bin2);
179  float content = bin_orig.values[Bin::Content::Sum];
180 
181  for (int bin22 = 1; bin22 <= nBinsSide; bin22++) {
182  int binToSumLeft = bin2 - bin22;
183  if (binToSumLeft < 0)
184  binToSumLeft += nBins2_;
185  unsigned binToSumRight = bin2 + bin22;
186  if (binToSumRight >= nBins2_)
187  binToSumRight -= nBins2_;
188 
189  content += histoClusters.at(z_side, bin1, binToSumLeft).values[Bin::Content::Sum] /
190  pow(2, bin22); // quadratic kernel
191 
192  content += histoClusters.at(z_side, bin1, binToSumRight).values[Bin::Content::Sum] /
193  pow(2, bin22); // quadratic kernel
194  }
195 
196  auto& bin = histoSumPhiClusters.at(z_side, bin1, bin2);
197  bin.values[Bin::Content::Sum] = content / area;
198  bin.weighted_x = bin_orig.weighted_x;
199  bin.weighted_y = bin_orig.weighted_y;
200  }
201  }
202  }
203 
204  return histoSumPhiClusters;
205 }
206 
208  Histogram histoSumRPhiClusters(nBins1_, nBins2_);
209 
210  for (int z_side : {-1, 1}) {
211  for (unsigned bin1 = 0; bin1 < nBins1_; bin1++) {
212  float weight =
213  (bin1 == 0 || bin1 == nBins1_ - 1) ? 1.5 : 2.; //Take into account edges with only one side up or down
214 
215  for (unsigned bin2 = 0; bin2 < nBins2_; bin2++) {
216  const auto& bin_orig = histoClusters.at(z_side, bin1, bin2);
217  float content = bin_orig.values[Bin::Content::Sum];
218  float contentDown = bin1 > 0 ? histoClusters.at(z_side, bin1 - 1, bin2).values[Bin::Content::Sum] : 0;
219  float contentUp = bin1 < (nBins1_ - 1) ? histoClusters.at(z_side, bin1 + 1, bin2).values[Bin::Content::Sum] : 0;
220 
221  auto& bin = histoSumRPhiClusters.at(z_side, bin1, bin2);
222  bin.values[Bin::Content::Sum] = (content + 0.5 * contentDown + 0.5 * contentUp) / weight;
223  bin.weighted_x = bin_orig.weighted_x;
224  bin.weighted_y = bin_orig.weighted_y;
225  }
226  }
227  }
228 
229  return histoSumRPhiClusters;
230 }
231 
232 void HGCalHistoSeedingImpl::setSeedEnergyAndPosition(std::vector<std::pair<GlobalPoint, double>>& seedPositionsEnergy,
233  int z_side,
234  unsigned bin1,
235  unsigned bin2,
236  const Bin& histBin) {
237  float x_seed = 0;
238  float y_seed = 0;
239  std::array<double, 4> bounds = boundaries();
240  double minx1 = std::get<0>(bounds);
241  double maxx1 = std::get<1>(bounds);
242  double minx2 = std::get<2>(bounds);
243  double maxx2 = std::get<3>(bounds);
244 
245  if (seedingPosition_ == BinCentre) {
246  float x1_seed = minx1 + (bin1 + 0.5) * (maxx1 - minx1) / nBins1_;
247  float x2_seed = minx2 + (bin2 + 0.5) * (maxx2 - minx2) / nBins2_;
248  switch (seedingSpace_) {
249  case RPhi:
250  x_seed = x1_seed * cos(x2_seed);
251  y_seed = x1_seed * sin(x2_seed);
252  break;
253  case XY:
254  x_seed = x1_seed;
255  y_seed = x2_seed;
256  };
257  } else if (seedingPosition_ == TCWeighted) {
258  x_seed = histBin.weighted_x;
259  y_seed = histBin.weighted_y;
260  }
261 
262  seedPositionsEnergy.emplace_back(GlobalPoint(x_seed, y_seed, z_side), histBin.values[Bin::Content::Sum]);
263 }
264 
265 std::vector<std::pair<GlobalPoint, double>> HGCalHistoSeedingImpl::computeMaxSeeds(const Histogram& histoClusters) {
266  std::vector<std::pair<GlobalPoint, double>> seedPositionsEnergy;
267 
268  for (int z_side : {-1, 1}) {
269  for (unsigned bin1 = 0; bin1 < nBins1_; bin1++) {
270  for (unsigned bin2 = 0; bin2 < nBins2_; bin2++) {
271  float MIPT_seed = histoClusters.at(z_side, bin1, bin2).values[Bin::Content::Sum];
272  bool isMax = MIPT_seed > histoThreshold_;
273  if (!isMax)
274  continue;
275 
276  navigator_.setHome(bin1, bin2);
277  auto pos_N = navigator_.move(1, 0);
278  auto pos_S = navigator_.move(-1, 0);
279  auto pos_W = navigator_.move(0, -1);
280  auto pos_E = navigator_.move(0, 1);
281  auto pos_NW = navigator_.move(1, -1);
282  auto pos_NE = navigator_.move(1, 1);
283  auto pos_SW = navigator_.move(-1, -1);
284  auto pos_SE = navigator_.move(-1, 1);
285 
286  float MIPT_N = (pos_N[0] != -1 && pos_N[1] != -1)
287  ? histoClusters.at(z_side, pos_N[0], pos_N[1]).values[Bin::Content::Sum]
288  : 0;
289  float MIPT_S = (pos_S[0] != -1 && pos_S[1] != -1)
290  ? histoClusters.at(z_side, pos_S[0], pos_S[1]).values[Bin::Content::Sum]
291  : 0;
292  float MIPT_W = (pos_W[0] != -1 && pos_W[1] != -1)
293  ? histoClusters.at(z_side, pos_W[0], pos_W[1]).values[Bin::Content::Sum]
294  : 0;
295  float MIPT_E = (pos_E[0] != -1 && pos_E[1] != -1)
296  ? histoClusters.at(z_side, pos_E[0], pos_E[1]).values[Bin::Content::Sum]
297  : 0;
298  float MIPT_NW = (pos_NW[0] != -1 && pos_NW[1] != -1)
299  ? histoClusters.at(z_side, pos_NW[0], pos_NW[1]).values[Bin::Content::Sum]
300  : 0;
301  float MIPT_NE = (pos_NE[0] != -1 && pos_NE[1] != -1)
302  ? histoClusters.at(z_side, pos_NE[0], pos_NE[1]).values[Bin::Content::Sum]
303  : 0;
304  float MIPT_SW = (pos_SW[0] != -1 && pos_SW[1] != -1)
305  ? histoClusters.at(z_side, pos_SW[0], pos_SW[1]).values[Bin::Content::Sum]
306  : 0;
307  float MIPT_SE = (pos_SE[0] != -1 && pos_SE[1] != -1)
308  ? histoClusters.at(z_side, pos_SE[0], pos_SE[1]).values[Bin::Content::Sum]
309  : 0;
310 
311  isMax &= MIPT_seed >= MIPT_S && MIPT_seed > MIPT_N && MIPT_seed >= MIPT_E && MIPT_seed >= MIPT_SE &&
312  MIPT_seed >= MIPT_NE && MIPT_seed > MIPT_W && MIPT_seed > MIPT_SW && MIPT_seed > MIPT_NW;
313 
314  if (isMax) {
315  setSeedEnergyAndPosition(seedPositionsEnergy, z_side, bin1, bin2, histoClusters.at(z_side, bin1, bin2));
316  }
317  }
318  }
319  }
320 
321  return seedPositionsEnergy;
322 }
323 
324 std::vector<std::pair<GlobalPoint, double>> HGCalHistoSeedingImpl::computeInterpolatedMaxSeeds(
325  const Histogram& histoClusters) {
326  std::vector<std::pair<GlobalPoint, double>> seedPositionsEnergy;
327 
328  for (int z_side : {-1, 1}) {
329  for (unsigned bin1 = 0; bin1 < nBins1_; bin1++) {
330  for (unsigned bin2 = 0; bin2 < nBins2_; bin2++) {
331  float MIPT_seed = histoClusters.at(z_side, bin1, bin2).values[Bin::Content::Sum];
332 
333  navigator_.setHome(bin1, bin2);
334  auto pos_N = navigator_.move(1, 0);
335  auto pos_S = navigator_.move(-1, 0);
336  auto pos_W = navigator_.move(0, -1);
337  auto pos_E = navigator_.move(0, 1);
338  auto pos_NW = navigator_.move(1, -1);
339  auto pos_NE = navigator_.move(1, 1);
340  auto pos_SW = navigator_.move(-1, -1);
341  auto pos_SE = navigator_.move(-1, 1);
342 
343  float MIPT_N = (pos_N[0] != -1 && pos_N[1] != -1)
344  ? histoClusters.at(z_side, pos_N[0], pos_N[1]).values[Bin::Content::Sum]
345  : 0;
346  float MIPT_S = (pos_S[0] != -1 && pos_S[1] != -1)
347  ? histoClusters.at(z_side, pos_S[0], pos_S[1]).values[Bin::Content::Sum]
348  : 0;
349  float MIPT_W = (pos_W[0] != -1 && pos_W[1] != -1)
350  ? histoClusters.at(z_side, pos_W[0], pos_W[1]).values[Bin::Content::Sum]
351  : 0;
352  float MIPT_E = (pos_E[0] != -1 && pos_E[1] != -1)
353  ? histoClusters.at(z_side, pos_E[0], pos_E[1]).values[Bin::Content::Sum]
354  : 0;
355  float MIPT_NW = (pos_NW[0] != -1 && pos_NW[1] != -1)
356  ? histoClusters.at(z_side, pos_NW[0], pos_NW[1]).values[Bin::Content::Sum]
357  : 0;
358  float MIPT_NE = (pos_NE[0] != -1 && pos_NE[1] != -1)
359  ? histoClusters.at(z_side, pos_NE[0], pos_NE[1]).values[Bin::Content::Sum]
360  : 0;
361  float MIPT_SW = (pos_SW[0] != -1 && pos_SW[1] != -1)
362  ? histoClusters.at(z_side, pos_SW[0], pos_SW[1]).values[Bin::Content::Sum]
363  : 0;
364  float MIPT_SE = (pos_SE[0] != -1 && pos_SE[1] != -1)
365  ? histoClusters.at(z_side, pos_SE[0], pos_SE[1]).values[Bin::Content::Sum]
366  : 0;
367 
368  float MIPT_pred = neighbour_weights_.at(0) * MIPT_NW + neighbour_weights_.at(1) * MIPT_N +
369  neighbour_weights_.at(2) * MIPT_NE + neighbour_weights_.at(3) * MIPT_W +
370  neighbour_weights_.at(5) * MIPT_E + neighbour_weights_.at(6) * MIPT_SW +
371  neighbour_weights_.at(7) * MIPT_S + neighbour_weights_.at(8) * MIPT_SE;
372 
373  bool isMax = MIPT_seed >= (MIPT_pred + histoThreshold_);
374 
375  if (isMax) {
376  setSeedEnergyAndPosition(seedPositionsEnergy, z_side, bin1, bin2, histoClusters.at(z_side, bin1, bin2));
377  }
378  }
379  }
380  }
381 
382  return seedPositionsEnergy;
383 }
384 
385 std::vector<std::pair<GlobalPoint, double>> HGCalHistoSeedingImpl::computeThresholdSeeds(
386  const Histogram& histoClusters) {
387  std::vector<std::pair<GlobalPoint, double>> seedPositionsEnergy;
388 
389  for (int z_side : {-1, 1}) {
390  for (unsigned bin1 = 0; bin1 < nBins1_; bin1++) {
391  for (unsigned bin2 = 0; bin2 < nBins2_; bin2++) {
392  float MIPT_seed = histoClusters.at(z_side, bin1, bin2).values[Bin::Content::Sum];
393  bool isSeed = MIPT_seed > histoThreshold_;
394 
395  if (isSeed) {
396  setSeedEnergyAndPosition(seedPositionsEnergy, z_side, bin1, bin2, histoClusters.at(z_side, bin1, bin2));
397  }
398  }
399  }
400  }
401 
402  return seedPositionsEnergy;
403 }
404 
405 std::vector<std::pair<GlobalPoint, double>> HGCalHistoSeedingImpl::computeSecondaryMaxSeeds(
406  const Histogram& histoClusters) {
407  std::vector<std::pair<GlobalPoint, double>> seedPositionsEnergy;
408 
409  HistogramT<uint8_t> primarySeedPositions(nBins1_, nBins2_);
410  HistogramT<uint8_t> vetoPositions(nBins1_, nBins2_);
411 
412  //Search for primary seeds
413  for (int z_side : {-1, 1}) {
414  for (unsigned bin1 = 0; bin1 < nBins1_; bin1++) {
415  for (unsigned bin2 = 0; bin2 < nBins2_; bin2++) {
416  float MIPT_seed = histoClusters.at(z_side, bin1, bin2).values[Bin::Content::Sum];
417  bool isMax = MIPT_seed > histoThreshold_;
418 
419  if (!isMax)
420  continue;
421 
422  float MIPT_S = bin1 < (nBins1_ - 1) ? histoClusters.at(z_side, bin1 + 1, bin2).values[Bin::Content::Sum] : 0;
423  float MIPT_N = bin1 > 0 ? histoClusters.at(z_side, bin1 - 1, bin2).values[Bin::Content::Sum] : 0;
424 
425  int binLeft = bin2 - 1;
426  if (binLeft < 0)
427  binLeft += nBins2_;
428  unsigned binRight = bin2 + 1;
429  if (binRight >= nBins2_)
430  binRight -= nBins2_;
431 
432  float MIPT_W = histoClusters.at(z_side, bin1, binLeft).values[Bin::Content::Sum];
433  float MIPT_E = histoClusters.at(z_side, bin1, binRight).values[Bin::Content::Sum];
434  float MIPT_NW = bin1 > 0 ? histoClusters.at(z_side, bin1 - 1, binLeft).values[Bin::Content::Sum] : 0;
435  float MIPT_NE = bin1 > 0 ? histoClusters.at(z_side, bin1 - 1, binRight).values[Bin::Content::Sum] : 0;
436  float MIPT_SW =
437  bin1 < (nBins1_ - 1) ? histoClusters.at(z_side, bin1 + 1, binLeft).values[Bin::Content::Sum] : 0;
438  float MIPT_SE =
439  bin1 < (nBins1_ - 1) ? histoClusters.at(z_side, bin1 + 1, binRight).values[Bin::Content::Sum] : 0;
440 
441  isMax &= MIPT_seed >= MIPT_S && MIPT_seed > MIPT_N && MIPT_seed >= MIPT_E && MIPT_seed >= MIPT_SE &&
442  MIPT_seed >= MIPT_NE && MIPT_seed > MIPT_W && MIPT_seed > MIPT_SW && MIPT_seed > MIPT_NW;
443 
444  if (isMax) {
445  setSeedEnergyAndPosition(seedPositionsEnergy, z_side, bin1, bin2, histoClusters.at(z_side, bin1, bin2));
446 
447  primarySeedPositions.at(z_side, bin1, bin2) = true;
448 
449  vetoPositions.at(z_side, bin1, binLeft) = true;
450  vetoPositions.at(z_side, bin1, binRight) = true;
451  if (bin1 > 0) {
452  vetoPositions.at(z_side, bin1 - 1, bin2) = true;
453  vetoPositions.at(z_side, bin1 - 1, binRight) = true;
454  vetoPositions.at(z_side, bin1 - 1, binLeft) = true;
455  }
456  if (bin1 < (nBins1_ - 1)) {
457  vetoPositions.at(z_side, bin1 + 1, bin2) = true;
458  vetoPositions.at(z_side, bin1 + 1, binRight) = true;
459  vetoPositions.at(z_side, bin1 + 1, binLeft) = true;
460  }
461  }
462  }
463  }
464  }
465 
466  //Search for secondary seeds
467 
468  for (int z_side : {-1, 1}) {
469  for (unsigned bin1 = 0; bin1 < nBins1_; bin1++) {
470  for (unsigned bin2 = 0; bin2 < nBins2_; bin2++) {
471  //Cannot be a secondary seed if already a primary seed, or adjacent to primary seed
472  if (primarySeedPositions.at(z_side, bin1, bin2) || vetoPositions.at(z_side, bin1, bin2))
473  continue;
474 
475  float MIPT_seed = histoClusters.at(z_side, bin1, bin2).values[Bin::Content::Sum];
476  bool isMax = MIPT_seed > histoThreshold_;
477 
478  float MIPT_S = bin1 < (nBins1_ - 1) ? histoClusters.at(z_side, bin1 + 1, bin2).values[Bin::Content::Sum] : 0;
479  float MIPT_N = bin1 > 0 ? histoClusters.at(z_side, bin1 - 1, bin2).values[Bin::Content::Sum] : 0;
480 
481  int binLeft = bin2 - 1;
482  if (binLeft < 0)
483  binLeft += nBins2_;
484  unsigned binRight = bin2 + 1;
485  if (binRight >= nBins2_)
486  binRight -= nBins2_;
487 
488  float MIPT_W = histoClusters.at(z_side, bin1, binLeft).values[Bin::Content::Sum];
489  float MIPT_E = histoClusters.at(z_side, bin1, binRight).values[Bin::Content::Sum];
490  float MIPT_NW = bin1 > 0 ? histoClusters.at(z_side, bin1 - 1, binLeft).values[Bin::Content::Sum] : 0;
491  float MIPT_NE = bin1 > 0 ? histoClusters.at(z_side, bin1 - 1, binRight).values[Bin::Content::Sum] : 0;
492  float MIPT_SW =
493  bin1 < (nBins1_ - 1) ? histoClusters.at(z_side, bin1 + 1, binLeft).values[Bin::Content::Sum] : 0;
494  float MIPT_SE =
495  bin1 < (nBins1_ - 1) ? histoClusters.at(z_side, bin1 + 1, binRight).values[Bin::Content::Sum] : 0;
496 
497  isMax &= (((bin1 < nBins1_ - 1) && vetoPositions.at(z_side, bin1 + 1, bin2)) or MIPT_seed >= MIPT_S) &&
498  (((bin1 > 0) && vetoPositions.at(z_side, bin1 - 1, bin2)) or MIPT_seed > MIPT_N) &&
499  ((vetoPositions.at(z_side, bin1, binRight)) or MIPT_seed >= MIPT_E) &&
500  (((bin1 < nBins1_ - 1) && vetoPositions.at(z_side, bin1 + 1, binRight)) or MIPT_seed >= MIPT_SE) &&
501  (((bin1 > 0) && vetoPositions.at(z_side, bin1 - 1, binRight)) or MIPT_seed >= MIPT_NE) &&
502  ((vetoPositions.at(z_side, bin1, binLeft)) or MIPT_seed > MIPT_W) &&
503  (((bin1 < nBins1_ - 1) && vetoPositions.at(z_side, bin1 + 1, binLeft)) or MIPT_seed > MIPT_SW) &&
504  (((bin1 > 0) && vetoPositions.at(z_side, bin1 - 1, binLeft)) or MIPT_seed > MIPT_NW);
505 
506  if (isMax) {
507  setSeedEnergyAndPosition(seedPositionsEnergy, z_side, bin1, bin2, histoClusters.at(z_side, bin1, bin2));
508  }
509  }
510  }
511  }
512 
513  return seedPositionsEnergy;
514 }
515 
517  std::vector<std::pair<GlobalPoint, double>>& seedPositionsEnergy) {
518  /* put clusters into an r/z x phi histogram */
519  Histogram histoCluster = fillHistoClusters(clustersPtrs);
520 
521  Histogram smoothHistoCluster;
522  if (seedingSpace_ == RPhi) {
523  /* smoothen along the phi direction + normalize each bin to same area */
524  Histogram smoothPhiHistoCluster = fillSmoothPhiHistoClusters(histoCluster, binsSumsHisto_);
525 
526  /* smoothen along the r/z direction */
527  smoothHistoCluster = fillSmoothRPhiHistoClusters(smoothPhiHistoCluster);
528  } else if (seedingSpace_ == XY) {
529  smoothHistoCluster = fillSmoothHistoClusters(histoCluster, smoothing_ecal_, Bin::Content::Ecal);
530  smoothHistoCluster = fillSmoothHistoClusters(smoothHistoCluster, smoothing_hcal_, Bin::Content::Hcal);
531  // Update sum with smoothen ECAL + HCAL
532  for (int z_side : {-1, 1}) {
533  for (unsigned x1 = 0; x1 < nBins1_; x1++) {
534  for (unsigned x2 = 0; x2 < nBins2_; x2++) {
535  auto& bin = smoothHistoCluster.at(z_side, x1, x2);
536  bin.values[Bin::Content::Sum] = bin.values[Bin::Content::Ecal] + bin.values[Bin::Content::Hcal];
537  }
538  }
539  }
540  }
541 
542  /* seeds determined with local maximum criteria */
543  if (seedingType_ == HistoMaxC3d)
544  seedPositionsEnergy = computeMaxSeeds(smoothHistoCluster);
545  else if (seedingType_ == HistoThresholdC3d)
546  seedPositionsEnergy = computeThresholdSeeds(smoothHistoCluster);
548  seedPositionsEnergy = computeInterpolatedMaxSeeds(smoothHistoCluster);
550  seedPositionsEnergy = computeSecondaryMaxSeeds(smoothHistoCluster);
551 }
552 
553 std::array<double, 4> HGCalHistoSeedingImpl::boundaries() {
554  switch (seedingSpace_) {
555  case RPhi:
556  return {{kROverZMin_, kROverZMax_, -M_PI, M_PI}};
557  case XY:
558  return {{-kXYMax_, kXYMax_, -kXYMax_, kXYMax_}};
559  }
560  return {{0., 0., 0., 0.}};
561 }
std::vector< std::pair< GlobalPoint, double > > computeInterpolatedMaxSeeds(const Histogram &histoClusters)
T getParameter(std::string const &) const
std::vector< unsigned > binsSumsHisto_
constexpr T reduceRange(T x)
Definition: deltaPhi.h:18
Histogram fillSmoothPhiHistoClusters(const Histogram &histoClusters, const vector< unsigned > &binSums)
static unsigned neighbour_weights_size_
Histogram fillSmoothRPhiHistoClusters(const Histogram &histoClusters)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Definition: weight.py:1
SeedingPosition seedingPosition_
std::vector< std::pair< GlobalPoint, double > > computeMaxSeeds(const Histogram &histoClusters)
HGCalTriggerTools triggerTools_
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)
int zside(const DetId &) const
T sqrt(T t)
Definition: SSEVec.h:19
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
void setSeedEnergyAndPosition(std::vector< std::pair< GlobalPoint, double >> &seedPositionsEnergy, int z_side, unsigned bin_R, unsigned bin_phi, const Bin &histBin)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Histogram fillSmoothHistoClusters(const Histogram &, const vector< double > &, Bin::Content)
std::array< int, 2 > move(int offset1, int offset2)
std::array< double, 4 > boundaries()
std::vector< double > smoothing_ecal_
#define M_PI
std::vector< std::pair< GlobalPoint, double > > computeThresholdSeeds(const Histogram &histoClusters)
std::array< float, 3 > values
std::vector< double > neighbour_weights_
Histogram fillHistoClusters(const std::vector< edm::Ptr< l1t::HGCalCluster >> &clustersPtrs)
bool isEm(const DetId &) const
T & at(int zside, unsigned x1, unsigned x2)
std::vector< double > smoothing_hcal_
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
HGCalHistoSeedingImpl(const edm::ParameterSet &conf)