CMS 3D CMS Logo

EgammaHLTBcHcalIsolationProducersRegional.cc
Go to the documentation of this file.
1 /* \class EgammaHLTBcHcalIsolationProducersRegional
2  *
3  * \author Matteo Sani (UCSD)
4  *
5  */
6 
7 #include <iostream>
8 #include <vector>
9 #include <memory>
10 
13 
17 
21 
26 
30 
32  doEtSum_( config.getParameter<bool>("doEtSum") ),
33  etMin_( config.getParameter<double>("etMin") ),
34  innerCone_( config.getParameter<double>("innerCone") ),
35  outerCone_( config.getParameter<double>("outerCone") ),
36  depth_( config.getParameter<int>("depth") ),
37  useSingleTower_( config.getParameter<bool>("useSingleTower") ),
38  doRhoCorrection_( config.getParameter<bool>("doRhoCorrection") ),
39  rhoScale_( config.getParameter<double>("rhoScale") ),
40  rhoMax_( config.getParameter<double>("rhoMax") ),
41  effectiveAreas_( config.getParameter<std::vector<double> >("effectiveAreas") ),
42  absEtaLowEdges_( config.getParameter<std::vector<double> >("absEtaLowEdges") ),
43  recoEcalCandidateProducer_( consumes<reco::RecoEcalCandidateCollection>(config.getParameter<edm::InputTag>("recoEcalCandidateProducer")) ),
44  caloTowerProducer_( consumes<CaloTowerCollection>(config.getParameter<edm::InputTag>("caloTowerProducer")) ),
45  rhoProducer_( doRhoCorrection_ ? consumes<double>(config.getParameter<edm::InputTag>("rhoProducer")) : edm::EDGetTokenT<double>() )
46 {
47 
48  if (doRhoCorrection_) {
49  if (absEtaLowEdges_.size() != effectiveAreas_.size())
50  throw cms::Exception("IncompatibleVects") << "absEtaLowEdges and effectiveAreas should be of the same size. \n";
51 
52  if (absEtaLowEdges_.at(0) != 0.0)
53  throw cms::Exception("IncompleteCoverage") << "absEtaLowEdges should start from 0. \n";
54 
55  for (unsigned int aIt = 0; aIt < absEtaLowEdges_.size() - 1; aIt++) {
56  if ( !(absEtaLowEdges_.at( aIt ) < absEtaLowEdges_.at( aIt + 1 )) )
57  throw cms::Exception("ImproperBinning") << "absEtaLowEdges entries should be in increasing order. \n";
58  }
59  }
60 
62  hcalCfg.hOverEConeSize = outerCone_;
63  hcalCfg.useTowers = true;
65  hcalCfg.hOverEPtMin = etMin_;
66  hcalHelper_ = new ElectronHcalHelper(hcalCfg);
67 
68  produces<reco::RecoEcalCandidateIsolationMap>();
69 }
70 
72  delete hcalHelper_;
73 }
74 
76 
78 
79  desc.add<edm::InputTag>(("recoEcalCandidateProducer"), edm::InputTag("hltRecoEcalCandidate"));
80  desc.add<edm::InputTag>(("caloTowerProducer"), edm::InputTag("hltTowerMakerForAll"));
81  desc.add<edm::InputTag>(("rhoProducer"), edm::InputTag("fixedGridRhoFastjetAllCalo"));
82  desc.add<bool>(("doRhoCorrection"), false);
83  desc.add<double>(("rhoMax"), 999999.);
84  desc.add<double>(("rhoScale"), 1.0);
85  desc.add<double>(("etMin"), -1.0);
86  desc.add<double>(("innerCone"), 0);
87  desc.add<double>(("outerCone"), 0.15);
88  desc.add<int>(("depth"), -1);
89  desc.add<bool>(("doEtSum"), false);
90  desc.add<bool>(("useSingleTower"), false);
91  desc.add<std::vector<double> >("effectiveAreas", {0.079, 0.25}); // 2016 post-ichep sinEle default
92  desc.add<std::vector<double> >("absEtaLowEdges", {0.0, 1.479}); // Barrel, Endcap
93  descriptions.add(("hltEgammaHLTBcHcalIsolationProducersRegional"), desc);
94 }
95 
97 
98  // Get the HLT filtered objects
100  iEvent.getByToken(recoEcalCandidateProducer_, recoEcalCandHandle);
101 
102  edm::Handle<CaloTowerCollection> caloTowersHandle;
103  iEvent.getByToken(caloTowerProducer_, caloTowersHandle);
104 
105  edm::Handle<double> rhoHandle;
106  double rho = 0.0;
107 
108  if (doRhoCorrection_) {
109  iEvent.getByToken(rhoProducer_, rhoHandle);
110  rho = *(rhoHandle.product());
111  }
112 
113  if (rho > rhoMax_)
114  rho = rhoMax_;
115 
116  rho = rho*rhoScale_;
117 
118  hcalHelper_->checkSetup(iSetup);
119  hcalHelper_->readEvent(iEvent);
120 
121  reco::RecoEcalCandidateIsolationMap isoMap(recoEcalCandHandle);
122 
123  for(unsigned int iRecoEcalCand=0; iRecoEcalCand <recoEcalCandHandle->size(); iRecoEcalCand++) {
124 
125  reco::RecoEcalCandidateRef recoEcalCandRef(recoEcalCandHandle, iRecoEcalCand);
126 
127  float isol = 0;
128 
129  std::vector<CaloTowerDetId> towersBehindCluster;
130 
131  if (useSingleTower_)
132  towersBehindCluster = hcalHelper_->hcalTowersBehindClusters(*(recoEcalCandRef->superCluster()));
133 
134  if (doEtSum_) { //calculate hcal isolation excluding the towers behind the cluster which will be used for H for H/E
135  EgammaTowerIsolation isolAlgo(outerCone_, innerCone_, etMin_, depth_, caloTowersHandle.product());
136  if (useSingleTower_)
137  isol = isolAlgo.getTowerEtSum(&(*recoEcalCandRef), &(towersBehindCluster)); // towersBehindCluster are excluded from the isolation sum
138  else
139  isol = isolAlgo.getTowerEtSum(&(*recoEcalCandRef));
140 
141  } else { //calcuate H for H/E
142  if (useSingleTower_)
143  isol = hcalHelper_->hcalESumDepth1BehindClusters(towersBehindCluster) + hcalHelper_->hcalESumDepth2BehindClusters(towersBehindCluster);
144  else
145  isol = hcalHelper_->hcalESum(*(recoEcalCandRef->superCluster()));
146 
147  }
148 
149  if (doRhoCorrection_) {
150  int iEA = -1;
151  auto scEta = std::abs(recoEcalCandRef->superCluster()->eta());
152  for (int bIt = absEtaLowEdges_.size() - 1; bIt > -1; bIt--) {
153  if ( scEta > absEtaLowEdges_.at(bIt) ) {
154  iEA = bIt;
155  break;
156  }
157  }
158  isol = isol - rho*effectiveAreas_.at(iEA);
159  }
160 
161  isoMap.insert(recoEcalCandRef, isol);
162  }
163 
164  iEvent.put(std::make_unique<reco::RecoEcalCandidateIsolationMap>(isoMap));
165 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
double hcalESum(const reco::SuperCluster &, const std::vector< CaloTowerDetId > *excludeTowers=0)
void readEvent(const edm::Event &)
const edm::EDGetTokenT< CaloTowerCollection > caloTowerProducer_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
double hcalESumDepth2BehindClusters(const std::vector< CaloTowerDetId > &towers)
std::vector< CaloTowerDetId > hcalTowersBehindClusters(const reco::SuperCluster &sc)
void checkSetup(const edm::EventSetup &)
Definition: config.py:1
double hcalESumDepth1BehindClusters(const std::vector< CaloTowerDetId > &towers)
int iEvent
Definition: GenABIO.cc:230
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterDescriptionBase * add(U const &iLabel, T const &value)
virtual void produce(edm::Event &, const edm::EventSetup &) override final
T const * product() const
Definition: Handle.h:81
void insert(const key_type &k, const data_type &v)
insert an association
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< RecoEcalCandidate > RecoEcalCandidateCollection
collectin of RecoEcalCandidate objects
fixed size matrix
HLT enums.
double getTowerEtSum(const reco::Candidate *cand, const std::vector< CaloTowerDetId > *detIdToExclude=0) const
edm::EDGetTokenT< CaloTowerCollection > hcalTowers
const edm::EDGetTokenT< reco::RecoEcalCandidateCollection > recoEcalCandidateProducer_