CMS 3D CMS Logo

CaloClusterer.cc
Go to the documentation of this file.
2 
3 #include <cassert>
4 
9 
11  0, 0.087, 0.174, 0.261, 0.348, 0.435, 0.522, 0.609, 0.696, 0.783, 0.870, 0.957, 1.044, 1.131,
12  1.218, 1.305, 1.392, 1.479, 1.566, 1.653, 1.740, 1.830, 1.930, 2.043, 2.172, 2.322, 2.5, 2.650,
13  2.853, 3.139, 3.314, 3.489, 3.664, 3.839, 4.013, 4.191, 4.363, 4.538, 4.716, 4.889, 5.191};
15  0, 0.087, 0.174, 0.261, 0.348, 0.435, 0.522, 0.609, 0.696, 0.783, 0.870, 0.957, 1.044, 1.131, 1.218, 1.305,
16  1.392, 1.479, 1.564, 1.648, 1.732, 1.817, 1.901, 1.986, 2.071, 2.155, 2.240, 2.324, 2.409, 2.493, 2.577, 2.662,
17  2.747, 2.831, 2.915, 3.0, 3.139, 3.314, 3.489, 3.664, 3.839, 4.013, 4.191, 4.363, 4.538, 4.716, 4.889, 5.191};
18 
20  int nEta, int nPhi, int ietaCoarse, int ietaVeryCoarse, const float *towerEtas)
21  : Grid(2 * ((ietaCoarse - 1) * nPhi + (ietaVeryCoarse - ietaCoarse) * (nPhi / 2) +
22  (nEta - ietaVeryCoarse + 1) * (nPhi / 4))),
23  nEta_(nEta),
24  nPhi_(nPhi),
25  ietaCoarse_(ietaCoarse),
26  ietaVeryCoarse_(ietaVeryCoarse),
27  towerEtas_(towerEtas),
28  cell_map_(2 * nEta * nPhi, -1) {
29  int icell = 0;
30  for (int ie = -nEta_; ie <= nEta_; ++ie) {
31  int absie = std::abs(ie);
32  for (int iph = 1; iph <= nPhi_; ++iph) {
33  if (!valid_ieta_iphi(ie, iph))
34  continue;
35  ieta_[icell] = ie;
36  iphi_[icell] = iph;
37  eta_[icell] = (ie > 0 ? 0.5 : -0.5) * (towerEtas_[absie - 1] + towerEtas_[absie]);
38  etaWidth_[icell] = (towerEtas_[absie] - towerEtas_[absie - 1]);
39  phiWidth_[icell] = 2 * M_PI / nPhi_;
40  if (absie >= ietaVeryCoarse_)
41  phiWidth_[icell] *= 4;
42  else if (absie >= ietaCoarse_)
43  phiWidth_[icell] *= 2;
44  phi_[icell] = (iph - 1) * 2 * M_PI / nPhi_ + 0.5 * phiWidth_[icell];
45  if (phi_[icell] > M_PI)
46  phi_[icell] -= 2 * M_PI;
47  std::fill(neighbours_[icell].begin(), neighbours_[icell].end(), -1);
48  cell_map_[(ie + nEta_) + 2 * nEta_ * (iph - 1)] = icell;
49  icell++;
50  }
51  }
52  assert(unsigned(icell) == ncells_);
53  // now link the cells
54  for (icell = 0; icell < int(ncells_); ++icell) {
55  int ie = ieta_[icell], iph = iphi_[icell];
56  int ineigh = 0;
57  for (int deta = -1; deta <= +1; ++deta) {
58  for (int dphi = -1; dphi <= +1; ++dphi) {
59  if (deta == 0 && dphi == 0)
60  continue;
61  neighbours_[icell][ineigh++] = imove(ie, iph, deta, dphi);
62  }
63  }
64  }
67  //for (float teta = 0; teta <= 5.0; teta += 0.02) {
68  // for (float tphi = -M_PI; tphi <= M_PI; tphi += 0.02) {
69  // find_cell(+teta, tphi);
70  // find_cell(-teta, tphi);
71  // }
72  //}
73 }
74 
75 int l1tpf_calo::Phase1GridBase::find_cell(float eta, float phi) const {
76  int ieta =
77  (eta != 0) ? std::distance(towerEtas_, std::lower_bound(towerEtas_, towerEtas_ + nEta_, std::abs(eta))) : 1;
78  if (ieta == nEta_)
79  return -1; // outside bounds
80  assert(ieta > 0 && ieta < nEta_);
81  if (ieta > nEta_)
82  ieta = nEta_;
83  if (eta < 0)
84  ieta = -ieta;
85  phi = reco::reduceRange(phi); // [-PI, PI]
86  if (phi < 0) // then bring to [0, 2*PI]
87  phi += 2 * M_PI;
88  int iphi = std::floor(phi * nPhi_ / (2 * M_PI));
89  if (phi >= 2 * M_PI)
90  iphi = nPhi_ - 1; // fix corner case due to roundings etc
91  assert(iphi < nPhi_);
92  if (std::abs(ieta) >= ietaVeryCoarse_)
93  iphi -= (iphi % 4);
94  else if (std::abs(ieta) >= ietaCoarse_)
95  iphi -= (iphi % 2);
96  iphi += 1;
98  //if (!valid_ieta_iphi(ieta,iphi)) {
99  // printf("Error in finding cell for eta %+7.4f phi %+7.4f, got ieta = %+3d iphi %2d which is not valid\n",
100  // eta, phi, ieta, iphi);
101  //}
102  assert(valid_ieta_iphi(ieta, iphi));
103  int icell = ifind_cell(ieta, iphi);
104  assert(icell != -1);
105 
107  //if (std::abs(eta - eta_[icell]) > 0.501*etaWidth_[icell] || std::abs(deltaPhi(phi, phi_[icell])) > 0.501*phiWidth_[icell]) {
108  // printf("Mismatch in finding cell for eta %+7.4f phi %+7.4f, got ieta = %+3d iphi %2d which has eta %+7.4f +- %.4f phi %+7.4f +- %.4f ; deta = %+7.4f dphi = %+7.4f\n",
109  // eta, phi, ieta, iphi, eta_[icell], etaWidth_[icell], phi_[icell], phiWidth_[icell], eta - eta_[icell], deltaPhi(phi, phi_[icell]));
110  //}
111  //assert(std::abs(eta - eta_[icell]) <= 0.5*etaWidth_[icell]);
112  //assert(std::abs(deltaPhi(phi, phi_[icell])) <= 0.5*phiWidth_[icell]);
113  return icell;
114 }
115 
116 int l1tpf_calo::Phase1GridBase::imove(int ieta, int iphi, int deta, int dphi) {
117  int ie = ieta, iph = iphi;
118  switch (deta) {
119  case -1:
120  ie = (ie == -nEta_ ? 0 : (ie == +1 ? -1 : ie - 1));
121  break;
122  case +1:
123  ie = (ie == +nEta_ ? 0 : (ie == -1 ? +1 : ie + 1));
124  break;
125  case 0:
126  break;
127  default:
128  assert(false);
129  };
130  if (ie == 0)
131  return -1;
132  switch (dphi) {
133  case -1:
134  iph = (iph == 1 ? nPhi_ : iph - 1);
135  break;
136  case +1:
137  iph = (iph == nPhi_ ? 1 : iph + 1);
138  break;
139  case 0:
140  break;
141  default:
142  assert(false);
143  };
144  if (!valid_ieta_iphi(ie, iph))
145  return -1;
146  int icell = ifind_cell(ie, iph);
147  assert(!(ie == ieta && iph == iphi));
148  assert(icell != -1);
149  assert(icell != ifind_cell(ieta, iphi));
150  return icell;
151 }
152 
154  static const Phase1Grid _phase1Grid;
155  static const Phase2Grid _phase2Grid;
156  if (type == "phase1")
157  return &_phase1Grid;
158  else if (type == "phase2")
159  return &_phase2Grid;
160  else
161  throw cms::Exception("Configuration") << "Unsupported grid type '" << type << "'\n";
162 }
163 
165  : grid_(getGrid(pset.getParameter<std::string>("grid"))),
166  rawet_(*grid_),
167  unclustered_(*grid_),
168  precluster_(*grid_),
169  clusterIndex_(*grid_),
170  cellKey_(*grid_),
171  clusters_(),
172  nullCluster_(),
173  zsEt_(pset.getParameter<double>("zsEt")),
174  seedEt_(pset.getParameter<double>("seedEt")),
175  minClusterEt_(pset.getParameter<double>("minClusterEt")),
176  minEtToGrow_(pset.existsAs<double>("minEtToGrow") ? pset.getParameter<double>("minEtToGrow") : -1),
177  energyWeightedPosition_(pset.getParameter<bool>("energyWeightedPosition")) {
178  std::string energyShareAlgo = pset.getParameter<std::string>("energyShareAlgo");
179  if (energyShareAlgo == "fractions")
181  else if (energyShareAlgo == "none")
183  else if (energyShareAlgo == "greedy")
185  else if (energyShareAlgo == "crude")
187  else
188  throw cms::Exception("Configuration") << "Unsupported energyShareAlgo '" << energyShareAlgo << "'\n";
189 }
190 
192 
194  rawet_.zero();
195  clusters_.clear();
196  clusterIndex_.fill(-1);
197 }
198 
200  unsigned int i, ncells = grid_->size();
201 
202  // kill zeros. count non-zeros, for linking later
203  cellKey_.fill(-1);
204  int key = 0;
205  for (i = 0; i < ncells; ++i) {
206  if (rawet_[i] < zsEt_) {
207  rawet_[i] = 0;
208  } else {
209  cellKey_[i] = key++;
210  }
211  }
212 
213  precluster_.clear();
214  // pre-cluster step 1: at each cell, set the value equal to itself if it's a local maxima, zero otherwise
215  // can be done in parallel on all cells
216  for (i = 0; i < ncells; ++i) {
217  if (rawet_[i] > seedEt_) {
218  precluster_[i].ptLocalMax = rawet_[i];
220  //printf(" candidate precluster pt %7.2f at %4d (ieta %+3d iphi %2d)\n", rawet_[i], i, grid_->ieta(i), grid_->iphi(i));
221  for (int ineigh = 0; ineigh <= 3; ++ineigh) {
222  if (rawet_.neigh(i, ineigh) > rawet_[i])
223  precluster_[i].ptLocalMax = 0;
225  //int ncell = grid_->neighbour(i,ineigh);
226  //if (ncell == -1) printf(" \t neigh %d is null\n", ineigh);
227  //else printf(" \t neigh %d at %4d (ieta %+3d iphi %2d) has pt %7.2f: comparison %1d \n", ineigh, ncell, grid_->ieta(ncell), grid_->iphi(ncell), rawet_[ncell], precluster_[i].ptLocalMax > 0);
228  }
229  for (int ineigh = 4; ineigh < 8; ++ineigh) {
230  if (rawet_.neigh(i, ineigh) >= rawet_[i])
231  precluster_[i].ptLocalMax = 0;
233  //int ncell = grid_->neighbour(i,ineigh);
234  //if (ncell == -1) printf(" \t neigh %d is null\n", ineigh);
235  //else printf(" \t neigh %d at %4d (ieta %+3d iphi %2d) has pt %7.2f: comparison %1d \n", ineigh, ncell, grid_->ieta(ncell), grid_->iphi(ncell), rawet_[ncell], precluster_[i].ptLocalMax > 0);
236  }
237  }
238  }
239  // pre-cluster step 2: compute information from neighbouring local max, for energy sharing purposes
240  for (i = 0; i < ncells; ++i) {
241  if (precluster_[i].ptLocalMax == 0) {
242  switch (energyShareAlgo_) {
243  case EnergyShareAlgo::Fractions: {
244  float tot = 0;
245  for (int ineigh = 0; ineigh < 8; ++ineigh) {
246  tot += precluster_.neigh(i, ineigh).ptLocalMax;
247  }
248  precluster_[i].ptOverNeighLocalMaxSum = tot ? rawet_[i] / tot : 0;
249  } break;
251  precluster_[i].ptOverNeighLocalMaxSum = rawet_[i];
252  break;
253  case EnergyShareAlgo::Greedy: {
254  float maxet = 0;
255  for (int ineigh = 0; ineigh < 8; ++ineigh) {
256  maxet = std::max(maxet, precluster_.neigh(i, ineigh).ptLocalMax);
257  }
258  precluster_[i].ptOverNeighLocalMaxSum = maxet;
259  } break;
260  case EnergyShareAlgo::Crude: {
261  int number = 0;
262  for (int ineigh = 0; ineigh < 8; ++ineigh) {
263  number += (precluster_.neigh(i, ineigh).ptLocalMax > 0);
264  }
265  precluster_[i].ptOverNeighLocalMaxSum = (number > 1 ? 0.5 : 1.0) * rawet_[i];
266  } break;
267  }
268  }
269  }
270 
271  clusterIndex_.fill(-1);
272  clusters_.clear();
273  unclustered_ = rawet_;
274  // cluster: at each localMax cell, take itself plus the weighted contributions of the neighbours
275  Cluster cluster;
276  for (i = 0; i < ncells; ++i) {
277  if (precluster_[i].ptLocalMax > 0) {
278  float myet = rawet_[i];
279  float tot = myet;
280  float avg_eta = 0;
281  float avg_phi = 0;
282  cluster.clear();
283  cluster.constituents.emplace_back(i, 1.0);
284  for (int ineigh = 0; ineigh < 8; ++ineigh) {
285  int ineighcell = grid_->neighbour(i, ineigh);
286  if (ineighcell == -1)
287  continue; // skip dummy cells
288  float fracet = 0;
289  switch (energyShareAlgo_) {
290  case EnergyShareAlgo::Fractions:
291  fracet = myet * precluster_.neigh(i, ineigh).ptOverNeighLocalMaxSum;
292  break;
294  fracet = precluster_.neigh(i, ineigh).ptOverNeighLocalMaxSum;
295  break;
296  case EnergyShareAlgo::Greedy:
297  fracet = (myet == precluster_.neigh(i, ineigh).ptOverNeighLocalMaxSum ? rawet_.neigh(i, ineigh) : 0);
298  break;
299  case EnergyShareAlgo::Crude:
300  fracet = precluster_.neigh(i, ineigh).ptOverNeighLocalMaxSum;
301  break;
302  }
303  if (fracet == 0)
304  continue;
305  tot += fracet;
306  cluster.constituents.emplace_back(ineighcell, fracet / rawet_.neigh(i, ineigh));
307  if (energyWeightedPosition_) {
308  avg_eta += fracet * (grid_->eta(ineighcell) - grid_->eta(i));
309  avg_phi += fracet * deltaPhi(grid_->phi(ineighcell), grid_->phi(i));
310  }
311  }
312  if (tot > minClusterEt_) {
313  cluster.et = tot;
314  unclustered_[i] = 0;
315  for (int ineigh = 0; ineigh < 8; ++ineigh) {
316  int ineighcell = grid_->neighbour(i, ineigh);
317  if (ineighcell == -1)
318  continue; // skip dummy cells
319  unclustered_[ineighcell] = 0;
320  }
321  if (energyWeightedPosition_) {
322  cluster.eta = grid_->eta(i) + avg_eta / tot;
323  cluster.phi = grid_->phi(i) + avg_phi / tot;
324  // wrap around phi
325  cluster.phi = reco::reduceRange(cluster.phi);
326  } else {
327  cluster.eta = grid_->eta(i);
328  cluster.phi = grid_->phi(i);
329  }
330  clusterIndex_[i] = clusters_.size();
331  clusters_.push_back(cluster);
332  }
333  }
334  }
335  if (minEtToGrow_ > 0)
336  grow();
337 }
338 
340  int selneighs[4] = {1, 3, 4, 6}; // -eta, -phi, +phi, +eta
341  std::vector<int> toreset;
342  for (Cluster &cluster : clusters_) {
343  if (cluster.et > minEtToGrow_) {
344  int i = cluster.constituents.front().first;
345  for (int side = 0; side < 4; ++side) {
346  int neigh = grid_->neighbour(i, selneighs[side]);
347  if (neigh == -1)
348  continue;
349  for (int in = 0; in < 8; ++in) {
350  int n2 = grid_->neighbour(neigh, in);
351  if (n2 == -1)
352  continue;
353  cluster.et += unclustered_[n2];
354  if (unclustered_[n2]) {
355  cluster.constituents.emplace_back(n2, 1.0);
356  toreset.push_back(n2);
357  }
358  }
359  }
360  }
361  }
362  for (int i : toreset)
363  unclustered_[i] = 0;
364 }
365 
366 std::unique_ptr<l1t::PFClusterCollection> l1tpf_calo::SingleCaloClusterer::fetchCells(bool unclusteredOnly,
367  float ptMin) const {
368  auto ret = std::make_unique<l1t::PFClusterCollection>();
369  const EtGrid &src = (unclusteredOnly ? unclustered_ : rawet_);
370  for (unsigned int i = 0, ncells = grid_->size(); i < ncells; ++i) {
371  if (src[i] <= ptMin)
372  continue;
373  if ((unclusteredOnly == false) && (ptMin == 0)) {
374  assert(cellKey_[i] == int(ret->size()));
375  }
376  ret->emplace_back(src[i], grid_->eta(i), grid_->phi(i));
377  ret->back().setHwEta(grid_->ieta(i));
378  ret->back().setHwPhi(grid_->iphi(i));
379  }
380  return ret;
381 }
382 
383 std::unique_ptr<l1t::PFClusterCollection> l1tpf_calo::SingleCaloClusterer::fetch(float ptMin) const {
384  auto ret = std::make_unique<l1t::PFClusterCollection>();
385  for (const Cluster &cluster : clusters_) {
386  if (cluster.et > ptMin) {
387  ret->emplace_back(cluster.et, cluster.eta, cluster.phi);
388  }
389  }
390  return ret;
391 }
392 
393 std::unique_ptr<l1t::PFClusterCollection> l1tpf_calo::SingleCaloClusterer::fetch(
395  auto ret = std::make_unique<l1t::PFClusterCollection>();
396  for (const Cluster &cluster : clusters_) {
397  if (cluster.et > ptMin) {
398  ret->emplace_back(cluster.et, cluster.eta, cluster.phi);
399  for (const auto &pair : cluster.constituents) {
400  edm::Ptr<l1t::PFCluster> ref(cells, cellKey_[pair.first]);
401  ret->back().addConstituent(ref, pair.second);
402  }
403  }
404  }
405  return ret;
406 }
407 
409  const SingleCaloClusterer &ecal,
410  const SingleCaloClusterer &hcal)
411  : grid_(getGrid(pset.getParameter<std::string>("grid"))),
412  ecal_(ecal),
413  hcal_(hcal),
414  clusterIndex_(*grid_),
415  clusters_(),
416  hoeCut_(pset.getParameter<double>("hoeCut")),
417  minPhotonEt_(pset.getParameter<double>("minPhotonEt")),
418  minHadronRawEt_(pset.getParameter<double>("minHadronRawEt")),
419  minHadronEt_(pset.getParameter<double>("minHadronEt")),
420  noEmInHGC_(pset.getParameter<bool>("noEmInHGC")) {
421  if (grid_ != &ecal.raw().grid())
422  throw cms::Exception("LogicError", "Inconsistent grid between ecal and linker\n");
423  if (grid_ != &hcal.raw().grid())
424  throw cms::Exception("LogicError", "Inconsistent grid between hcal and linker\n");
425 }
426 
428 
429 std::unique_ptr<l1t::PFClusterCollection> l1tpf_calo::SimpleCaloLinkerBase::fetch() const {
431  return fetch(ecal, hcal);
432 }
433 
434 std::unique_ptr<l1t::PFClusterCollection> l1tpf_calo::SimpleCaloLinkerBase::fetch(
437  bool setRefs = (ecal.isValid() && hcal.isValid());
438  auto ret = std::make_unique<l1t::PFClusterCollection>();
439  for (const CombinedCluster &cluster : clusters_) {
440  if (cluster.et > 0) {
441  bool photon = (cluster.hcal_et < hoeCut_ * cluster.ecal_et);
442  if (photon && noEmInHGC_) {
443  if (std::abs(cluster.eta) > 1.5 && std::abs(cluster.eta) < 3.0) { // 1.5-3 = eta range of HGCal
444  continue;
445  }
446  }
447  if (cluster.et > (photon ? minPhotonEt_ : minHadronEt_)) {
448  ret->emplace_back(cluster.et,
449  cluster.eta,
450  cluster.phi,
451  cluster.ecal_et > 0 ? std::max(cluster.et - cluster.ecal_et, 0.f) / cluster.ecal_et : -1,
452  photon);
453  if (setRefs) {
454  for (const auto &pair : cluster.constituents) {
455  assert(pair.first != 0);
456  if (pair.first > 0) { // 1+hcal index
457  ret->back().addConstituent(edm::Ptr<l1t::PFCluster>(hcal, +pair.first - 1), pair.second);
458  } else { // -1-ecal index
459  ret->back().addConstituent(edm::Ptr<l1t::PFCluster>(ecal, -pair.first + 1), pair.second);
460  }
461  }
462  }
463  }
464  }
465  }
466  return ret;
467 }
468 
470  const SingleCaloClusterer &ecal,
471  const SingleCaloClusterer &hcal)
472  : SimpleCaloLinkerBase(pset, ecal, hcal), ecalToHCal_(*grid_) {}
473 
475 
477  clearBase();
478  ecalToHCal_.clear();
479 }
480 
482  unsigned int i, ncells = grid_->size();
483 
484  const EtGrid &hraw = hcal_.raw();
485  const IndexGrid &ecals = ecal_.indexGrid();
486  const IndexGrid &hcals = hcal_.indexGrid();
487 
488  // for each ECal cluster, get the corresponding HCal cluster and the sum of the neighbour HCal clusters
489  ecalToHCal_.clear();
490  for (i = 0; i < ncells; ++i) {
491  if (ecals[i] >= 0) {
492  if (hcals[i] >= 0) {
493  ecalToHCal_[i].ptLocalMax = hcal_.cluster(i).et;
494  } else {
495  float tot = 0;
496  for (int ineigh = 0; ineigh < 8; ++ineigh) {
497  tot += hcal_.cluster(grid_->neighbour(i, ineigh)).et;
498  }
499  ecalToHCal_[i].ptOverNeighLocalMaxSum = tot ? ecal_.cluster(i).et / tot : 0;
500  }
501  }
502  }
503 
504  clusterIndex_.fill(-1);
505  clusters_.clear();
506  CombinedCluster cluster;
507  // promote HCal clusters to final clusters
508  for (i = 0; i < ncells; ++i) {
509  if (hcals[i] >= 0) {
510  const Cluster &hcal = hcal_.cluster(i);
511  cluster.clear();
512  cluster.constituents.emplace_back(+i + 1, 1);
513  if (ecalToHCal_[i].ptLocalMax > 0) {
514  // direct linking is easy
515  const Cluster &ecal = ecal_.cluster(i);
516  if (ecal.et + hcal.et > minHadronRawEt_) {
517  cluster.ecal_et = ecal.et;
518  cluster.hcal_et = hcal.et;
519  cluster.et = cluster.ecal_et + cluster.hcal_et;
520  float wecal = cluster.ecal_et / cluster.et, whcal = 1.0 - wecal;
521  cluster.eta = ecal.eta * wecal + hcal.eta * whcal;
522  cluster.phi = ecal.phi * wecal + hcal.phi * whcal;
523  // wrap around phi
524  cluster.phi = reco::reduceRange(cluster.phi);
525  cluster.constituents.emplace_back(-i - 1, 1);
526  }
527  } else {
528  // sidewas linking is more annonying
529  float myet = hcal.et;
530  float etot = 0;
531  float avg_eta = 0;
532  float avg_phi = 0;
533  for (int ineigh = 0; ineigh < 8; ++ineigh) {
534  int ineighcell = grid_->neighbour(i, ineigh);
535  if (ineighcell == -1)
536  continue; // skip dummy cells
537  float fracet = myet * ecalToHCal_.neigh(i, ineigh).ptOverNeighLocalMaxSum;
538  if (fracet == 0)
539  continue;
540  etot += fracet;
541  avg_eta += fracet * (grid_->eta(ineighcell) - grid_->eta(i));
542  avg_phi += fracet * deltaPhi(grid_->phi(ineighcell), grid_->phi(i));
543  cluster.constituents.emplace_back(-i - 1, fracet / ecal_.cluster(ineighcell).et);
544  }
545  if (myet + etot > minHadronRawEt_) {
546  cluster.hcal_et = hcal.et;
547  cluster.ecal_et = etot;
548  cluster.et = myet + etot;
549  cluster.eta = hcal.eta + avg_eta / cluster.et;
550  cluster.phi = hcal.phi + avg_phi / cluster.et;
551  // wrap around phi
552  cluster.phi = reco::reduceRange(cluster.phi);
553  }
554  }
555  if (cluster.et > 0) {
556  clusterIndex_[i] = clusters_.size();
557  clusters_.push_back(cluster);
558  }
559  }
560  }
561 
562  // promote Unlinked ECal clusters to final clusters
563  for (i = 0; i < ncells; ++i) {
564  if (ecals[i] >= 0 && ecalToHCal_[i].ptLocalMax == 0 && ecalToHCal_[i].ptOverNeighLocalMaxSum == 0) {
565  cluster.clear();
566  const Cluster &ecal = ecal_.cluster(i);
567  cluster.ecal_et = ecal.et;
568  cluster.hcal_et = hraw[i];
569  cluster.et = cluster.ecal_et + cluster.hcal_et;
570  cluster.eta = ecal.eta;
571  cluster.phi = ecal.phi;
572  cluster.constituents.emplace_back(-i - 1, 1);
573  clusterIndex_[i] = clusters_.size();
574  clusters_.push_back(cluster);
575  }
576  }
577 }
578 
580  const SingleCaloClusterer &ecal,
581  const SingleCaloClusterer &hcal)
582  : SimpleCaloLinkerBase(pset, ecal, hcal), combClusterer_(pset) {}
583 
585 
587  clearBase();
588  combClusterer_.clear();
589 }
590 
592  combClusterer_.clear();
593 
594  const EtGrid &hraw = hcal_.raw();
595  const EtGrid &eraw = ecal_.raw();
596  combClusterer_.raw() = eraw;
597  combClusterer_.raw() += hraw;
598 
599  combClusterer_.run();
600  clusterIndex_ = combClusterer_.indexGrid();
601  const std::vector<Cluster> &clustersSrc = combClusterer_.clusters();
602  unsigned int nclust = clustersSrc.size();
603  clusters_.resize(nclust);
604  for (unsigned int ic = 0; ic < nclust; ++ic) {
605  const Cluster &src = clustersSrc[ic];
606  CombinedCluster &dst = clusters_[ic];
607  dst.et = src.et;
608  dst.eta = src.eta;
609  dst.phi = src.phi;
610  dst.ecal_et = 0;
611  dst.hcal_et = 0;
612  for (const auto &pair : src.constituents) {
613  if (eraw[pair.first]) {
614  dst.ecal_et += pair.second * eraw[pair.first];
615  dst.constituents.emplace_back(-pair.first - 1, pair.second);
616  }
617  if (hraw[pair.first]) {
618  dst.hcal_et += pair.second * hraw[pair.first];
619  dst.constituents.emplace_back(+pair.first + 1, pair.second);
620  }
621  }
622  }
623 }
624 
625 std::unique_ptr<l1tpf_calo::SimpleCaloLinkerBase> l1tpf_calo::makeCaloLinker(const edm::ParameterSet &pset,
626  const SingleCaloClusterer &ecal,
627  const SingleCaloClusterer &hcal) {
628  const std::string &algo = pset.getParameter<std::string>("algo");
629  if (algo == "simple") {
630  return std::make_unique<l1tpf_calo::SimpleCaloLinker>(pset, ecal, hcal);
631  } else if (algo == "flat") {
632  return std::make_unique<l1tpf_calo::FlatCaloLinker>(pset, ecal, hcal);
633  } else {
634  throw cms::Exception("Configuration") << "Unsupported linker algo '" << algo << "'\n";
635  }
636 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
l1tpf_calo::CombinedCluster::clear
void clear()
Definition: CaloClusterer.h:172
muons2muons_cfi.photon
photon
Definition: muons2muons_cfi.py:28
l1tpf_calo::Grid::neighbours_
std::vector< std::array< int, 8 > > neighbours_
Definition: CaloClusterer.h:48
l1tpf_calo::SimpleCaloLinkerBase::~SimpleCaloLinkerBase
virtual ~SimpleCaloLinkerBase()
Definition: CaloClusterer.cc:427
electrons_cff.bool
bool
Definition: electrons_cff.py:372
l1tpf_calo::GridData::clear
void clear()
Definition: CaloClusterer.h:139
mps_fire.i
i
Definition: mps_fire.py:355
l1tpf_calo::Phase1GridBase::nEta_
const int nEta_
Definition: CaloClusterer.h:59
l1tpf_calo::Phase1GridBase::towerEtas_
const float * towerEtas_
Definition: CaloClusterer.h:60
l1tpf_calo::Phase1GridBase::nPhi_
const int nPhi_
Definition: CaloClusterer.h:59
l1tpf_calo::Phase1GridBase::imove
int imove(int ieta, int iphi, int deta, int dphi)
Definition: CaloClusterer.cc:116
l1tpf_calo::getGrid
const Grid * getGrid(const std::string &type)
Definition: CaloClusterer.cc:153
hcal
Definition: ConfigurationDatabase.cc:13
l1tpf_calo::CombinedCluster::ecal_et
float ecal_et
Definition: CaloClusterer.h:171
l1tpf_calo::Grid
Definition: CaloClusterer.h:22
l1tpf_calo::Grid::ncells_
unsigned int ncells_
Definition: CaloClusterer.h:45
l1tpf_calo::FlatCaloLinker::clear
void clear() override
Definition: CaloClusterer.cc:586
ptMin
constexpr float ptMin
Definition: PhotonIDValueMapProducer.cc:153
cms::cuda::assert
assert(be >=bs)
HLT_2018_cff.distance
distance
Definition: HLT_2018_cff.py:6417
l1tpf_calo::Grid::phi_
std::vector< float > phi_
Definition: CaloClusterer.h:46
l1tpf_calo::Phase2Grid::phase2_nEta_
static const int phase2_nEta_
Definition: CaloClusterer.h:91
l1tpf_calo::Phase1Grid::phase1_towerEtas_
static const float phase1_towerEtas_[phase1_nEta_]
Definition: CaloClusterer.h:83
l1tpf_calo::FlatCaloLinker::run
void run() override
Definition: CaloClusterer.cc:591
pfClustersFromCombinedCalo_cfi.energyShareAlgo
energyShareAlgo
Definition: pfClustersFromCombinedCalo_cfi.py:22
l1tpf_calo::SimpleCaloLinker::SimpleCaloLinker
SimpleCaloLinker(const edm::ParameterSet &pset, const SingleCaloClusterer &ecal, const SingleCaloClusterer &hcal)
Definition: CaloClusterer.cc:469
l1tpf_calo::makeCaloLinker
std::unique_ptr< SimpleCaloLinkerBase > makeCaloLinker(const edm::ParameterSet &pset, const SingleCaloClusterer &ecal, const SingleCaloClusterer &hcal)
Definition: CaloClusterer.cc:625
end
#define end
Definition: vmac.h:39
l1tpf_calo::Cluster::constituents
std::vector< std::pair< int, float > > constituents
Definition: CaloClusterer.h:163
cond::persistency::fetch
std::pair< std::string, std::shared_ptr< void > > fetch(const cond::Hash &payloadId, Session &session)
Definition: CondDBFetch.cc:336
l1tpf_calo::SimpleCaloLinkerBase::SimpleCaloLinkerBase
SimpleCaloLinkerBase(const edm::ParameterSet &pset, const SingleCaloClusterer &ecal, const SingleCaloClusterer &hcal)
Definition: CaloClusterer.cc:408
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
patCandidatesForDimuonsSequences_cff.hcal
hcal
Definition: patCandidatesForDimuonsSequences_cff.py:37
cmsdt::algo
algo
Definition: constants.h:164
l1tpf_calo::Cluster
Definition: CaloClusterer.h:160
None
Definition: APVGainStruct.h:52
l1tpf_calo::Cluster::clear
void clear()
Definition: CaloClusterer.h:164
contentValuesFiles.number
number
Definition: contentValuesFiles.py:53
l1tpf_calo::Grid::etaWidth_
std::vector< float > etaWidth_
Definition: CaloClusterer.h:46
l1tpf_calo::SingleCaloClusterer::grow
void grow()
possibly grow clusters by adding unclustered energy on the sides
Definition: CaloClusterer.cc:339
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
PVValHelper::eta
Definition: PVValidationHelpers.h:69
l1tpf_calo::FlatCaloLinker::FlatCaloLinker
FlatCaloLinker(const edm::ParameterSet &pset, const SingleCaloClusterer &ecal, const SingleCaloClusterer &hcal)
Definition: CaloClusterer.cc:579
l1tpf_calo::Phase1GridBase::cell_map_
std::vector< int > cell_map_
Definition: CaloClusterer.h:61
l1tpf_calo::SimpleCaloLinkerBase::fetch
std::unique_ptr< l1t::PFClusterCollection > fetch() const
Definition: CaloClusterer.cc:429
l1tpf_calo::Phase1GridBase::valid_ieta_iphi
bool valid_ieta_iphi(int ieta, int iphi) const
Definition: CaloClusterer.h:63
l1tpf_calo::SingleCaloClusterer::fetchCells
std::unique_ptr< l1t::PFClusterCollection > fetchCells(bool unclusteredOnly=false, float ptMin=0.) const
Definition: CaloClusterer.cc:366
l1tpf_calo::Grid::ieta_
std::vector< int > ieta_
Definition: CaloClusterer.h:47
cuda_std::lower_bound
__host__ constexpr __device__ RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Definition: cudastdAlgorithm.h:27
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
l1tpf_calo::Phase1GridBase::find_cell
int find_cell(float eta, float phi) const override
Definition: CaloClusterer.cc:75
l1tpf_calo::SingleCaloClusterer::~SingleCaloClusterer
~SingleCaloClusterer()
Definition: CaloClusterer.cc:191
ntuplemaker.fill
fill
Definition: ntuplemaker.py:304
l1tpf_calo::Phase1GridBase::ietaVeryCoarse_
const int ietaVeryCoarse_
Definition: CaloClusterer.h:59
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
edm::ParameterSet
Definition: ParameterSet.h:36
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
l1tpf_calo::SingleCaloClusterer::clear
void clear()
Definition: CaloClusterer.cc:193
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
l1tpf_calo::CombinedCluster
Definition: CaloClusterer.h:170
recoMuon::in
Definition: RecoMuonEnumerators.h:6
createfilelist.int
int
Definition: createfilelist.py:10
RefToPtr.h
l1tpf_calo::Grid::phiWidth_
std::vector< float > phiWidth_
Definition: CaloClusterer.h:46
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:50
HLT_2018_cff.nEta
nEta
Definition: HLT_2018_cff.py:5271
l1tpf_calo::Cluster::eta
float eta
Definition: CaloClusterer.h:162
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
l1tpf_calo::Phase2Grid::phase2_towerEtas_
static const float phase2_towerEtas_[phase2_nEta_]
Definition: CaloClusterer.h:92
l1tpf_calo::SingleCaloClusterer::EnergyShareAlgo::Fractions
l1tpf_calo::Phase1GridBase::ietaCoarse_
const int ietaCoarse_
Definition: CaloClusterer.h:59
l1tpf_calo::SingleCaloClusterer::run
void run()
Definition: CaloClusterer.cc:199
edm::Ptr
Definition: AssociationVector.h:31
l1tpf_calo::Cluster::et
float et
Definition: CaloClusterer.h:162
l1tpf_calo::SimpleCaloLinkerBase::grid_
const Grid * grid_
Definition: CaloClusterer.h:261
l1tpf_calo::GridData< float >
l1tpf_calo::Phase2Grid
Definition: CaloClusterer.h:85
l1tpf_calo::SimpleCaloLinker::run
void run() override
Definition: CaloClusterer.cc:481
l1tpf_calo::Grid::eta_
std::vector< float > eta_
Definition: CaloClusterer.h:46
type
type
Definition: HCALResponse.h:21
l1tpf_calo::SingleCaloClusterer::EnergyShareAlgo::Greedy
std
Definition: JetResolutionObject.h:76
edm::OrphanHandle
Definition: EDProductfwd.h:39
l1tpf_calo::Cluster::phi
float phi
Definition: CaloClusterer.h:162
l1tpf_calo::SingleCaloClusterer::EnergyShareAlgo::Crude
Exception
Definition: hltDiff.cc:246
postprocess-scan-build.cells
cells
Definition: postprocess-scan-build.py:13
l1tpf_calo::SingleCaloClusterer::EnergyShareAlgo::None
l1tpf_calo::SimpleCaloLinkerBase
Definition: CaloClusterer.h:235
l1tpf_calo::FlatCaloLinker::~FlatCaloLinker
~FlatCaloLinker() override
Definition: CaloClusterer.cc:584
DeadROCCounter.nclust
nclust
Definition: DeadROCCounter.py:66
Exception.h
l1tpf_calo::SingleCaloClusterer
Definition: CaloClusterer.h:180
bsc_activity_cfg.ecal
ecal
Definition: bsc_activity_cfg.py:25
l1tpf_calo::Grid::iphi_
std::vector< int > iphi_
Definition: CaloClusterer.h:47
HLT_2018_cff.nPhi
nPhi
Definition: HLT_2018_cff.py:5272
cms::Exception
Definition: Exception.h:70
math::cholesky::dst
M2 & dst
Definition: choleskyInversion.h:158
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
crabWrapper.key
key
Definition: crabWrapper.py:19
l1tpf_calo::CombinedCluster::hcal_et
float hcal_et
Definition: CaloClusterer.h:171
l1tpf_calo::SimpleCaloLinker::~SimpleCaloLinker
~SimpleCaloLinker() override
Definition: CaloClusterer.cc:474
l1tpf_calo::SingleCaloClusterer::energyShareAlgo_
EnergyShareAlgo energyShareAlgo_
Definition: CaloClusterer.h:231
l1tpf_calo::SingleCaloClusterer::fetch
std::unique_ptr< l1t::PFClusterCollection > fetch(float ptMin=0.) const
Definition: CaloClusterer.cc:383
l1tpf_calo::SingleCaloClusterer::SingleCaloClusterer
SingleCaloClusterer(const edm::ParameterSet &pset)
Definition: CaloClusterer.cc:164
begin
#define begin
Definition: vmac.h:32
l1tpf_calo::Phase1GridBase::Phase1GridBase
Phase1GridBase(int nEta, int nPhi, int ietaCoarse, int ietaVeryCoarse, const float *towerEtas)
Definition: CaloClusterer.cc:19
l1tpf_calo::SimpleCaloLinker::clear
void clear() override
Definition: CaloClusterer.cc:476
l1tpf_calo::Phase1Grid
Definition: CaloClusterer.h:76
HiEvtPlane_cfi.maxet
maxet
Definition: HiEvtPlane_cfi.py:18
deltaPhi.h
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
CaloClusterer.h
reco::reduceRange
constexpr T reduceRange(T x)
Definition: deltaPhi.h:18
l1tpf_calo::Phase1Grid::phase1_nEta_
static const int phase1_nEta_
Definition: CaloClusterer.h:82