CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
HGCalIsoCalculator Class Reference

#include <HGCalIsoCalculator.h>

Public Member Functions

const float getIso (const unsigned int ring) const
 
 HGCalIsoCalculator ()
 
void produceHGCalIso (const reco::CaloClusterPtr &seedCluster)
 
void setDeltaR (const float dr)
 
void setMinDeltaR (const float dr)
 
void setNLayers (unsigned int nLayers)
 
void setNRings (const size_t nrings)
 
void setRecHits (edm::Handle< HGCRecHitCollection > hitsEE, edm::Handle< HGCRecHitCollection > hitsFH, edm::Handle< HGCRecHitCollection > hitsBH)
 fill - once per event More...
 
void setRecHitTools (const hgcal::RecHitTools *recHitTools)
 
 ~HGCalIsoCalculator ()
 

Private Attributes

bool debug_
 
float dr2_
 
std::vector< std::pair< float, float > > hitEtaPhiCache_
 
std::vector< float > isoringdeposits_
 
float mindr2_
 
unsigned int nlayers_
 
edm::Handle< HGCRecHitCollectionrecHitsBH_
 
edm::Handle< HGCRecHitCollectionrecHitsEE_
 
edm::Handle< HGCRecHitCollectionrecHitsFH_
 
const hgcal::RecHitToolsrechittools_
 
std::vector< unsigned int > ringasso_
 

Detailed Description

Definition at line 46 of file HGCalIsoCalculator.h.

Constructor & Destructor Documentation

HGCalIsoCalculator::HGCalIsoCalculator ( )

Definition at line 11 of file HGCalIsoCalculator.cc.

References setNRings().

11  :dr2_(0.15*0.15),mindr2_(0),rechittools_(nullptr),debug_(false),nlayers_(30){
12  setNRings(5);
13 }
void setNRings(const size_t nrings)
const hgcal::RecHitTools * rechittools_
HGCalIsoCalculator::~HGCalIsoCalculator ( )

Definition at line 15 of file HGCalIsoCalculator.cc.

15  {
16 }

Member Function Documentation

const float HGCalIsoCalculator::getIso ( const unsigned int  ring) const

Definition at line 109 of file HGCalIsoCalculator.cc.

References isoringdeposits_, and relativeConstraints::ring.

Referenced by HGCalEgammaIDHelper::getIsolationRing(), and setNLayers().

109  {
110  if(ring>=isoringdeposits_.size())
111  throw cms::Exception("HGCalIsoCalculator::getIso: ring index out of range");
112  return isoringdeposits_[ring];
113 }
std::vector< float > isoringdeposits_
void HGCalIsoCalculator::produceHGCalIso ( const reco::CaloClusterPtr seedCluster)

Definition at line 47 of file HGCalIsoCalculator.cc.

References reco::deltaR2(), dr2_, Exception, hgcal::RecHitTools::getLayerWithOffset(), hitEtaPhiCache_, isoringdeposits_, mindr2_, nlayers_, alignCSCRings::r, recHitsBH_, recHitsEE_, recHitsFH_, rechittools_, relativeConstraints::ring, and ringasso_.

Referenced by HGCalEgammaIDHelper::computeHGCAL(), and setNLayers().

47  {
48 
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, std::pair<float,float> etaphiVal) {
62  float deltar2=reco::deltaR2(etaphiVal.first,etaphiVal.second,seedEta,seedPhi);
63  if(deltar2>dr2_ || deltar2<mindr2_) return;
64 
65  unsigned int layer=rechittools_->getLayerWithOffset(hit.id());
66  if(layer>=nlayers_) return;
67 
68  //do not consider hits associated to the photon cluster
69  if( std::none_of(seedHitsAndFractions.begin(), seedHitsAndFractions.end(), [&hit](const auto& seedhit){return hit.id()==seedhit.first;}) ){
70  const unsigned int ring=ringasso_.at(layer);
71  isoringdeposits_.at(ring)+=hit.energy();
72  }
73  };
74 
75  // The cache order is EE,FH,BH, so we should loop over them the same here
76  auto itEtaPhiCache = hitEtaPhiCache_.cbegin();
77  for(const auto& hit : *recHitsEE_){
78  checkAndFill(hit, *itEtaPhiCache);
79  itEtaPhiCache++;
80  }
81  for(const auto& hit : *recHitsFH_){
82  checkAndFill(hit, *itEtaPhiCache);
83  itEtaPhiCache++;
84  }
85  for(const auto& hit : *recHitsBH_){
86  checkAndFill(hit, *itEtaPhiCache);
87  itEtaPhiCache++;
88  }
89 }
edm::Handle< HGCRecHitCollection > recHitsEE_
edm::Handle< HGCRecHitCollection > recHitsBH_
std::vector< unsigned int > ringasso_
const hgcal::RecHitTools * rechittools_
std::vector< std::pair< float, float > > hitEtaPhiCache_
edm::Handle< HGCRecHitCollection > recHitsFH_
std::vector< float > isoringdeposits_
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
unsigned int getLayerWithOffset(const DetId &) const
Definition: RecHitTools.cc:283
void HGCalIsoCalculator::setDeltaR ( const float  dr)
inline
void HGCalIsoCalculator::setMinDeltaR ( const float  dr)
inline
void HGCalIsoCalculator::setNLayers ( unsigned int  nLayers)
inline
void HGCalIsoCalculator::setNRings ( const size_t  nrings)

Definition at line 91 of file HGCalIsoCalculator.cc.

References mps_fire::i, isoringdeposits_, nlayers_, ringasso_, and mps_merge::separator.

Referenced by HGCalEgammaIDHelper::HGCalEgammaIDHelper(), HGCalIsoCalculator(), and setRecHitTools().

91  {
92  if(nrings>nlayers_)
93  throw std::logic_error("PhotonHGCalIsoCalculator::setNRings: max number of rings reached");
94 
95  ringasso_.clear();
96  isoringdeposits_.clear();
97  unsigned int separator=nlayers_/nrings;
98  size_t counter=0;
99  for(size_t i=0;i<nlayers_+1;i++){
100  ringasso_.push_back(counter);
101  //the last ring might be larger.
102  if(i && !(i%separator) && (int)counter<(int)nrings-1){
103  counter++;
104  }
105  }
106  isoringdeposits_.resize(nrings,0);
107 }
string separator
Definition: mps_merge.py:78
std::vector< unsigned int > ringasso_
std::vector< float > isoringdeposits_
void HGCalIsoCalculator::setRecHits ( edm::Handle< HGCRecHitCollection hitsEE,
edm::Handle< HGCRecHitCollection hitsFH,
edm::Handle< HGCRecHitCollection hitsBH 
)

fill - once per event

Definition at line 18 of file HGCalIsoCalculator.cc.

References PVValHelper::eta, Exception, hgcal::RecHitTools::getEta(), hgcal::RecHitTools::getPhi(), hgcal::RecHitTools::getPosition(), hitEtaPhiCache_, hit::id, phi, position, recHitsBH_, recHitsEE_, recHitsFH_, and rechittools_.

Referenced by HGCalEgammaIDHelper::eventInit(), and setNLayers().

22  {
23  recHitsEE_=hitsEE;
24  recHitsFH_=hitsFH;
25  recHitsBH_=hitsBH;
26 
27  if(!rechittools_)
28  throw cms::Exception("HGCalIsoCalculator::produceHGCalIso: rechittools not set");
29 
30  hitEtaPhiCache_.clear();
31  hitEtaPhiCache_.reserve(recHitsEE_->size()+recHitsFH_->size()+recHitsBH_->size());
32 
33  // Since HGCal is not projective and the rechits don't cache any
34  // eta,phi, we make our own here
35  auto makeEtaPhiPair = [this](const auto& hit) {
37  float eta=rechittools_->getEta(position, 0); //assume vertex at z=0
38  float phi=rechittools_->getPhi(position);
39  return std::make_pair(eta, phi);
40  };
41 
42  for(const auto& hit : *recHitsEE_) hitEtaPhiCache_.push_back(makeEtaPhiPair(hit));
43  for(const auto& hit : *recHitsFH_) hitEtaPhiCache_.push_back(makeEtaPhiPair(hit));
44  for(const auto& hit : *recHitsBH_) hitEtaPhiCache_.push_back(makeEtaPhiPair(hit));
45 }
edm::Handle< HGCRecHitCollection > recHitsEE_
edm::Handle< HGCRecHitCollection > recHitsBH_
const hgcal::RecHitTools * rechittools_
float getEta(const GlobalPoint &position, const float &vertex_z=0.) const
Definition: RecHitTools.cc:340
float getPhi(const GlobalPoint &position) const
Definition: RecHitTools.cc:351
std::vector< std::pair< float, float > > hitEtaPhiCache_
edm::Handle< HGCRecHitCollection > recHitsFH_
unsigned int id
GlobalPoint getPosition(const DetId &id) const
Definition: RecHitTools.cc:112
static int position[264][3]
Definition: ReadPGInfo.cc:509
void HGCalIsoCalculator::setRecHitTools ( const hgcal::RecHitTools recHitTools)
inline

Definition at line 56 of file HGCalIsoCalculator.h.

References rechittools_, and setNRings().

Referenced by HGCalEgammaIDHelper::eventInit().

56 {rechittools_ = recHitTools;}
const hgcal::RecHitTools * rechittools_

Member Data Documentation

bool HGCalIsoCalculator::debug_
private

Definition at line 84 of file HGCalIsoCalculator.h.

float HGCalIsoCalculator::dr2_
private

Definition at line 77 of file HGCalIsoCalculator.h.

Referenced by produceHGCalIso(), and setDeltaR().

std::vector<std::pair<float,float> > HGCalIsoCalculator::hitEtaPhiCache_
private

Definition at line 83 of file HGCalIsoCalculator.h.

Referenced by produceHGCalIso(), and setRecHits().

std::vector<float> HGCalIsoCalculator::isoringdeposits_
private

Definition at line 74 of file HGCalIsoCalculator.h.

Referenced by getIso(), produceHGCalIso(), and setNRings().

float HGCalIsoCalculator::mindr2_
private

Definition at line 77 of file HGCalIsoCalculator.h.

Referenced by produceHGCalIso(), and setMinDeltaR().

unsigned int HGCalIsoCalculator::nlayers_
private

Definition at line 85 of file HGCalIsoCalculator.h.

Referenced by produceHGCalIso(), setNLayers(), and setNRings().

edm::Handle<HGCRecHitCollection> HGCalIsoCalculator::recHitsBH_
private

Definition at line 82 of file HGCalIsoCalculator.h.

Referenced by produceHGCalIso(), and setRecHits().

edm::Handle<HGCRecHitCollection> HGCalIsoCalculator::recHitsEE_
private

Definition at line 80 of file HGCalIsoCalculator.h.

Referenced by produceHGCalIso(), and setRecHits().

edm::Handle<HGCRecHitCollection> HGCalIsoCalculator::recHitsFH_
private

Definition at line 81 of file HGCalIsoCalculator.h.

Referenced by produceHGCalIso(), and setRecHits().

const hgcal::RecHitTools* HGCalIsoCalculator::rechittools_
private

Definition at line 79 of file HGCalIsoCalculator.h.

Referenced by produceHGCalIso(), setRecHits(), and setRecHitTools().

std::vector<unsigned int> HGCalIsoCalculator::ringasso_
private

Definition at line 75 of file HGCalIsoCalculator.h.

Referenced by produceHGCalIso(), and setNRings().