CMS 3D CMS Logo

EgammaHLTBcHcalIsolationProducersRegional.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EgammaHLTProducers
4 // Class: EgammaHLTBcHcalIsolationProducersRegional
5 //
6 // Original Author: Matteo Sani (UCSD)
7 // Created: Thu Nov 24 11:38:00 CEST 2011
8 //
9 
19 
20 //this class produces either Hcal isolation or H for H/E depending if doEtSum=true or false
21 //H for H/E = towers behind SC, hcal isolation has these towers excluded
22 //a rho correction can be applied
23 
25 public:
27 
28 public:
29  void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const final;
30  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
31 
32 private:
33  const bool doEtSum_;
34  const double etMin_;
35  const double innerCone_;
36  const double outerCone_;
37  const int depth_;
38  const bool useSingleTower_;
39 
40  const bool doRhoCorrection_;
41  const double rhoScale_;
42  const double rhoMax_;
43  const std::vector<double> effectiveAreas_;
44  const std::vector<double> absEtaLowEdges_;
45 
49 
51 
53 };
54 
56  : doEtSum_(config.getParameter<bool>("doEtSum")),
57  etMin_(config.getParameter<double>("etMin")),
58  innerCone_(config.getParameter<double>("innerCone")),
59  outerCone_(config.getParameter<double>("outerCone")),
60  depth_(config.getParameter<int>("depth")),
61  useSingleTower_(config.getParameter<bool>("useSingleTower")),
62  doRhoCorrection_(config.getParameter<bool>("doRhoCorrection")),
63  rhoScale_(config.getParameter<double>("rhoScale")),
64  rhoMax_(config.getParameter<double>("rhoMax")),
65  effectiveAreas_(config.getParameter<std::vector<double> >("effectiveAreas")),
66  absEtaLowEdges_(config.getParameter<std::vector<double> >("absEtaLowEdges")),
67  recoEcalCandidateProducer_(consumes(config.getParameter<edm::InputTag>("recoEcalCandidateProducer"))),
68  caloTowerProducer_(consumes(config.getParameter<edm::InputTag>("caloTowerProducer"))),
69  rhoProducer_(doRhoCorrection_ ? consumes<double>(config.getParameter<edm::InputTag>("rhoProducer"))
70  : edm::EDGetTokenT<double>()),
71  caloTowerConstituentsMapToken_{esConsumes()},
72  putToken_{produces<reco::RecoEcalCandidateIsolationMap>()} {
73  if (doRhoCorrection_) {
74  if (absEtaLowEdges_.size() != effectiveAreas_.size()) {
75  throw cms::Exception("IncompatibleVects") << "absEtaLowEdges and effectiveAreas should be of the same size. \n";
76  }
77 
78  if (absEtaLowEdges_.at(0) != 0.0) {
79  throw cms::Exception("IncompleteCoverage") << "absEtaLowEdges should start from 0. \n";
80  }
81 
82  for (unsigned int aIt = 0; aIt < absEtaLowEdges_.size() - 1; aIt++) {
83  if (!(absEtaLowEdges_.at(aIt) < absEtaLowEdges_.at(aIt + 1))) {
84  throw cms::Exception("ImproperBinning") << "absEtaLowEdges entries should be in increasing order. \n";
85  }
86  }
87  }
88 }
89 
92 
93  desc.add<edm::InputTag>(("recoEcalCandidateProducer"), edm::InputTag("hltRecoEcalCandidate"));
94  desc.add<edm::InputTag>(("caloTowerProducer"), edm::InputTag("hltTowerMakerForAll"));
95  desc.add<edm::InputTag>(("rhoProducer"), edm::InputTag("fixedGridRhoFastjetAllCalo"));
96  desc.add<bool>(("doRhoCorrection"), false);
97  desc.add<double>(("rhoMax"), 999999.);
98  desc.add<double>(("rhoScale"), 1.0);
99  desc.add<double>(("etMin"), -1.0);
100  desc.add<double>(("innerCone"), 0);
101  desc.add<double>(("outerCone"), 0.15);
102  desc.add<int>(("depth"), -1);
103  desc.add<bool>(("doEtSum"), false);
104  desc.add<bool>(("useSingleTower"), false);
105  desc.add<std::vector<double> >("effectiveAreas", {0.079, 0.25}); // 2016 post-ichep sinEle default
106  desc.add<std::vector<double> >("absEtaLowEdges", {0.0, 1.479}); // Barrel, Endcap
107  descriptions.add(("hltEgammaHLTBcHcalIsolationProducersRegional"), desc);
108 }
109 
112  const edm::EventSetup &iSetup) const {
113  // Get the HLT filtered objects
114  auto recoEcalCandHandle = iEvent.getHandle(recoEcalCandidateProducer_);
115 
116  double rho = 0.0;
117 
118  if (doRhoCorrection_) {
119  rho = iEvent.get(rhoProducer_);
120  if (rho > rhoMax_) {
121  rho = rhoMax_;
122  }
123  rho = rho * rhoScale_;
124  }
125 
126  auto const &caloTowers = iEvent.get(caloTowerProducer_);
127  auto const &ctmaph = iSetup.getData(caloTowerConstituentsMapToken_);
128 
129  const EgammaTowerIsolation towerIso1(outerCone_, 0., etMin_, 1, &caloTowers);
130  const EgammaTowerIsolation towerIso2(outerCone_, 0., etMin_, 2, &caloTowers);
131 
132  reco::RecoEcalCandidateIsolationMap isoMap(recoEcalCandHandle);
133 
134  for (unsigned int iRecoEcalCand = 0; iRecoEcalCand < recoEcalCandHandle->size(); iRecoEcalCand++) {
135  reco::RecoEcalCandidateRef recoEcalCandRef(recoEcalCandHandle, iRecoEcalCand);
136 
137  float isol = 0;
138 
139  auto towersBehindCluster =
140  useSingleTower_ ? egamma::towersOf(*(recoEcalCandRef->superCluster()), ctmaph) : std::vector<CaloTowerDetId>{};
141 
142  if (doEtSum_) { //calculate hcal isolation excluding the towers behind the cluster which will be used for H for H/E
144  if (useSingleTower_) {
145  // towersBehindCluster are excluded from the isolation sum
146  isol = isolAlgo.getTowerEtSum(recoEcalCandRef.get(), &towersBehindCluster);
147  } else {
148  isol = isolAlgo.getTowerEtSum(recoEcalCandRef.get());
149  }
150 
151  } else { //calcuate H for H/E
152  if (useSingleTower_)
153  isol = egamma::depth1HcalESum(towersBehindCluster, caloTowers) +
154  egamma::depth2HcalESum(towersBehindCluster, caloTowers);
155  else {
156  auto const &sc = recoEcalCandRef->superCluster().get();
157  isol = towerIso1.getTowerESum(sc) + towerIso2.getTowerESum(sc);
158  }
159  }
160 
161  if (doRhoCorrection_) {
162  int iEA = -1;
163  auto scEta = std::abs(recoEcalCandRef->superCluster()->eta());
164  for (int bIt = absEtaLowEdges_.size() - 1; bIt > -1; bIt--) {
165  if (scEta > absEtaLowEdges_.at(bIt)) {
166  iEA = bIt;
167  break;
168  }
169  }
170  isol = isol - rho * effectiveAreas_.at(iEA);
171  }
172 
173  isoMap.insert(recoEcalCandRef, isol);
174  }
175 
176  iEvent.emplace(putToken_, isoMap);
177 }
178 
const edm::EDGetTokenT< CaloTowerCollection > caloTowerProducer_
double getTowerESum(const reco::Candidate *cand, const std::vector< CaloTowerDetId > *detIdToExclude=nullptr) const
Definition: config.py:1
int iEvent
Definition: GenABIO.cc:224
const edm::EDPutTokenT< reco::RecoEcalCandidateIsolationMap > putToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool getData(T &iHolder) const
Definition: EventSetup.h:122
double depth2HcalESum(std::vector< CaloTowerDetId > const &towers, CaloTowerCollection const &)
const edm::ESGetToken< CaloTowerConstituentsMap, CaloGeometryRecord > caloTowerConstituentsMapToken_
double depth1HcalESum(std::vector< CaloTowerDetId > const &towers, CaloTowerCollection const &)
void insert(const key_type &k, const data_type &v)
insert an association
double getTowerEtSum(const reco::Candidate *cand, const std::vector< CaloTowerDetId > *detIdToExclude=nullptr) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
const edm::EDGetTokenT< reco::RecoEcalCandidateCollection > recoEcalCandidateProducer_
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const final
std::vector< CaloTowerDetId > towersOf(reco::SuperCluster const &sc, CaloTowerConstituentsMap const &towerMap, HoeMode mode=HoeMode::SingleTower)