CMS 3D CMS Logo

HGCalIsoCalculator.cc
Go to the documentation of this file.
1 /*
2  * HGCalIsoCalculator.cc
3  *
4  * Created on: 13 Oct 2017
5  * Author: jkiesele, ncsmith
6  */
7 
10 
12  : dr2_(0.15 * 0.15), mindr2_(0), rechittools_(nullptr), debug_(false), nlayers_(30) {
13  setNRings(5);
14 }
15 
17 
21  recHitsEE_ = hitsEE;
22  recHitsFH_ = hitsFH;
23  recHitsBH_ = hitsBH;
24 
25  if (!rechittools_)
26  throw cms::Exception("HGCalIsoCalculator::produceHGCalIso: rechittools not set");
27 
28  hitEtaPhiCache_.clear();
29  hitEtaPhiCache_.reserve(recHitsEE_->size() + recHitsFH_->size() + recHitsBH_->size());
30 
31  // Since HGCal is not projective and the rechits don't cache any
32  // eta,phi, we make our own here
33  auto makeEtaPhiPair = [this](const auto& hit) {
35  float eta = rechittools_->getEta(position, 0); //assume vertex at z=0
36  float phi = rechittools_->getPhi(position);
37  return std::make_pair(eta, phi);
38  };
39 
40  for (const auto& hit : *recHitsEE_)
41  hitEtaPhiCache_.push_back(makeEtaPhiPair(hit));
42  for (const auto& hit : *recHitsFH_)
43  hitEtaPhiCache_.push_back(makeEtaPhiPair(hit));
44  for (const auto& hit : *recHitsBH_)
45  hitEtaPhiCache_.push_back(makeEtaPhiPair(hit));
46 }
47 
49  if (!rechittools_)
50  throw cms::Exception("HGCalIsoCalculator::produceHGCalIso: rechittools not set");
51 
52  for (auto& r : isoringdeposits_)
53  r = 0;
54 
55  // make local temporaries to pass to the lambda
56  // avoids recomputing every iteration
57  const float seedEta = seed->eta();
58  const float seedPhi = seed->phi();
59  const std::vector<std::pair<DetId, float>>& seedHitsAndFractions = seed->hitsAndFractions();
60 
61  auto checkAndFill = [this, &seedEta, &seedPhi, &seedHitsAndFractions](const HGCRecHit& hit,
62  std::pair<float, float> etaphiVal) {
63  float deltar2 = reco::deltaR2(etaphiVal.first, etaphiVal.second, seedEta, seedPhi);
64  if (deltar2 > dr2_ || deltar2 < mindr2_)
65  return;
66 
67  unsigned int layer = rechittools_->getLayerWithOffset(hit.id());
68  if (layer >= nlayers_)
69  return;
70 
71  //do not consider hits associated to the photon cluster
72  if (std::none_of(seedHitsAndFractions.begin(), seedHitsAndFractions.end(), [&hit](const auto& seedhit) {
73  return hit.id() == seedhit.first;
74  })) {
75  const unsigned int ring = ringasso_.at(layer);
76  isoringdeposits_.at(ring) += hit.energy();
77  }
78  };
79 
80  // The cache order is EE,FH,BH, so we should loop over them the same here
81  auto itEtaPhiCache = hitEtaPhiCache_.cbegin();
82  for (const auto& hit : *recHitsEE_) {
83  checkAndFill(hit, *itEtaPhiCache);
84  itEtaPhiCache++;
85  }
86  for (const auto& hit : *recHitsFH_) {
87  checkAndFill(hit, *itEtaPhiCache);
88  itEtaPhiCache++;
89  }
90  for (const auto& hit : *recHitsBH_) {
91  checkAndFill(hit, *itEtaPhiCache);
92  itEtaPhiCache++;
93  }
94 }
95 
96 void HGCalIsoCalculator::setNRings(const size_t nrings) {
97  if (nrings > nlayers_)
98  throw std::logic_error("PhotonHGCalIsoCalculator::setNRings: max number of rings reached");
99 
100  ringasso_.clear();
101  isoringdeposits_.clear();
102  unsigned int separator = nlayers_ / nrings;
103  size_t counter = 0;
104  for (size_t i = 0; i < nlayers_ + 1; i++) {
105  ringasso_.push_back(counter);
106  //the last ring might be larger.
107  if (i && !(i % separator) && (int)counter < (int)nrings - 1) {
108  counter++;
109  }
110  }
111  isoringdeposits_.resize(nrings, 0);
112 }
113 
114 const float HGCalIsoCalculator::getIso(const unsigned int ring) const {
115  if (ring >= isoringdeposits_.size())
116  throw cms::Exception("HGCalIsoCalculator::getIso: ring index out of range");
117  return isoringdeposits_[ring];
118 }
string separator
Definition: mps_merge.py:79
edm::Handle< HGCRecHitCollection > recHitsEE_
edm::Handle< HGCRecHitCollection > recHitsBH_
float getPhi(const GlobalPoint &position) const
Definition: RecHitTools.cc:452
void setNRings(const size_t nrings)
void setRecHits(edm::Handle< HGCRecHitCollection > hitsEE, edm::Handle< HGCRecHitCollection > hitsFH, edm::Handle< HGCRecHitCollection > hitsBH)
fill - once per event
std::vector< unsigned int > ringasso_
const hgcal::RecHitTools * rechittools_
const float getIso(const unsigned int ring) const
std::vector< std::pair< float, float > > hitEtaPhiCache_
GlobalPoint getPosition(const DetId &id) const
Definition: RecHitTools.cc:129
void produceHGCalIso(const reco::CaloClusterPtr &seedCluster)
edm::Handle< HGCRecHitCollection > recHitsFH_
std::vector< float > isoringdeposits_
unsigned int id
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
float getEta(const GlobalPoint &position, const float &vertex_z=0.) const
Definition: RecHitTools.cc:441
static int position[264][3]
Definition: ReadPGInfo.cc:289
unsigned int getLayerWithOffset(const DetId &) const
Definition: RecHitTools.cc:365