CMS 3D CMS Logo

EgammaHLTHcalVarProducerFromRecHit.cc
Go to the documentation of this file.
1 // Class: EgammaHLTHcalVarProducerFromRecHit
2 
3 /*
4 
5 Author: Swagata Mukherjee
6 
7 Date: August 2021
8 
9 This class is similar to the existing class EgammaHLTBcHcalIsolationProducersRegional,
10 but the new feature in this code is that the HCAL recHits are used instead of the
11 calotowers which is expected to be phased out sometime in Run3.
12 The old class can also be used until calotowers stay. After that, one need to switch to this new one.
13 
14 As the old producer code, this one also produces either Hcal isolation or H for H/E depending if doEtSum=true or false.
15 H for H/E = either a single HCAL tower behind SC, or towers in a cone, and hcal isolation has these tower(s) excluded.
16 A rho correction can be applied
17 
18 */
19 
38 
40 public:
42 
43 public:
44  void beginRun(edm::Run const &, edm::EventSetup const &);
45  void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const final;
46  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
47 
48 private:
49  const bool doEtSum_;
54  const double innerCone_;
55  const double outerCone_;
56  const int depth_;
57  const int maxSeverityHB_;
58  const int maxSeverityHE_;
59  const bool useSingleTower_;
60  const bool doRhoCorrection_;
61  const double rhoScale_;
62  const double rhoMax_;
63  const std::vector<double> effectiveAreas_;
64  const std::vector<double> absEtaLowEdges_;
74 
75  //Get HCAL thresholds from GT
77  bool cutsFromDB;
78  HcalPFCuts const *hcalCuts = nullptr;
79 };
80 
82  : doEtSum_(config.getParameter<bool>("doEtSum")),
83  eThresHB_(config.getParameter<EgammaHcalIsolation::arrayHB>("eThresHB")),
84  etThresHB_(config.getParameter<EgammaHcalIsolation::arrayHB>("etThresHB")),
85  eThresHE_(config.getParameter<EgammaHcalIsolation::arrayHE>("eThresHE")),
86  etThresHE_(config.getParameter<EgammaHcalIsolation::arrayHE>("etThresHE")),
87  innerCone_(config.getParameter<double>("innerCone")),
88  outerCone_(config.getParameter<double>("outerCone")),
89  depth_(config.getParameter<int>("depth")),
90  maxSeverityHB_(config.getParameter<int>("maxSeverityHB")),
91  maxSeverityHE_(config.getParameter<int>("maxSeverityHE")),
92  useSingleTower_(config.getParameter<bool>("useSingleTower")),
93  doRhoCorrection_(config.getParameter<bool>("doRhoCorrection")),
94  rhoScale_(config.getParameter<double>("rhoScale")),
95  rhoMax_(config.getParameter<double>("rhoMax")),
96  effectiveAreas_(config.getParameter<std::vector<double> >("effectiveAreas")),
97  absEtaLowEdges_(config.getParameter<std::vector<double> >("absEtaLowEdges")),
98  recoEcalCandidateProducer_(consumes(config.getParameter<edm::InputTag>("recoEcalCandidateProducer"))),
99  hbheRecHitsTag_(consumes(config.getParameter<edm::InputTag>("hbheRecHitsTag"))),
100  rhoProducer_(doRhoCorrection_ ? consumes<double>(config.getParameter<edm::InputTag>("rhoProducer"))
101  : edm::EDGetTokenT<double>()),
102  caloGeometryToken_{esConsumes()},
103  hcalTopologyToken_{esConsumes()},
104  hcalChannelQualityToken_{esConsumes(edm::ESInputTag("", "withTopo"))},
105  hcalSevLvlComputerToken_{esConsumes()},
106  caloTowerConstituentsMapToken_{esConsumes()},
107  putToken_{produces<reco::RecoEcalCandidateIsolationMap>()},
108  cutsFromDB(
109  config.getParameter<bool>("usePFThresholdsFromDB")) { //Retrieve HCAL PF thresholds - from config or from DB
110  if (doRhoCorrection_) {
111  if (absEtaLowEdges_.size() != effectiveAreas_.size()) {
112  throw cms::Exception("IncompatibleVects") << "absEtaLowEdges and effectiveAreas should be of the same size. \n";
113  }
114 
115  if (absEtaLowEdges_.at(0) != 0.0) {
116  throw cms::Exception("IncompleteCoverage") << "absEtaLowEdges should start from 0. \n";
117  }
118 
119  for (unsigned int aIt = 0; aIt < absEtaLowEdges_.size() - 1; aIt++) {
120  if (!(absEtaLowEdges_.at(aIt) < absEtaLowEdges_.at(aIt + 1))) {
121  throw cms::Exception("ImproperBinning") << "absEtaLowEdges entries should be in increasing order. \n";
122  }
123  }
124  }
125 
126  if (cutsFromDB) {
127  hcalCutsToken_ = esConsumes<HcalPFCuts, HcalPFCutsRcd, edm::Transition::BeginRun>(edm::ESInputTag("", "withTopo"));
128  }
129 }
130 
133 
134  desc.add<edm::InputTag>("recoEcalCandidateProducer", edm::InputTag("hltRecoEcalCandidate"));
135  desc.add<edm::InputTag>("rhoProducer", edm::InputTag("fixedGridRhoFastjetAllCalo"));
136  desc.add<edm::InputTag>("hbheRecHitsTag", edm::InputTag("hltHbhereco"));
137  desc.add<bool>("doRhoCorrection", false);
138  desc.add<double>("rhoMax", 999999.);
139  desc.add<double>(("rhoScale"), 1.0);
140  //eThresHB/HE are from RecoParticleFlow/PFClusterProducer/python/particleFlowRecHitHBHE_cfi.py
141  desc.add<std::vector<double> >("eThresHB", {0.1, 0.2, 0.3, 0.3});
142  desc.add<std::vector<double> >("etThresHB", {0, 0, 0, 0});
143  desc.add<std::vector<double> >("eThresHE", {0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2});
144  desc.add<std::vector<double> >("etThresHE", {0, 0, 0, 0, 0, 0, 0});
145  desc.add<bool>("usePFThresholdsFromDB", true);
146  desc.add<double>("innerCone", 0);
147  desc.add<double>("outerCone", 0.14);
148  desc.add<int>("depth", 0);
149  desc.add<int>("maxSeverityHB", 9);
150  desc.add<int>("maxSeverityHE", 9);
151  desc.add<bool>("doEtSum", false);
152  desc.add<bool>("useSingleTower", false);
153  desc.add<std::vector<double> >("effectiveAreas", {0.079, 0.25}); // 2016 post-ichep sinEle default
154  desc.add<std::vector<double> >("absEtaLowEdges", {0.0, 1.479}); // Barrel, Endcap
155  descriptions.add("hltEgammaHLTHcalVarProducerFromRecHit", desc);
156 }
157 
159  if (cutsFromDB) {
160  hcalCuts = &iSetup.getData(hcalCutsToken_);
161  }
162 }
163 
166  const edm::EventSetup &iSetup) const {
167  auto recoEcalCandHandle = iEvent.getHandle(recoEcalCandidateProducer_);
168 
169  double rho = 0.0;
170 
171  if (doRhoCorrection_) {
172  rho = iEvent.get(rhoProducer_);
173  if (rho > rhoMax_) {
174  rho = rhoMax_;
175  }
176  rho = rho * rhoScale_;
177  }
178 
179  reco::RecoEcalCandidateIsolationMap isoMap(recoEcalCandHandle);
180 
181  for (unsigned int iRecoEcalCand = 0; iRecoEcalCand < recoEcalCandHandle->size(); iRecoEcalCand++) {
182  reco::RecoEcalCandidateRef recoEcalCandRef(recoEcalCandHandle, iRecoEcalCand);
183 
184  float isol = 0;
187 
188  if (useSingleTower_) {
189  if (!doEtSum_) { //this is single tower based H/E
192  } else { //this is cone-based HCAL isolation with single tower based footprint removal
195  }
196  } else { //useSingleTower_=False means H/E is cone-based
199  }
200 
202  outerCone_,
203  internal,
204  innerCone_,
205  eThresHB_,
206  etThresHB_,
208  eThresHE_,
209  etThresHE_,
211  iEvent.get(hbheRecHitsTag_),
212  iSetup.getData(caloGeometryToken_),
213  iSetup.getData(hcalTopologyToken_),
217 
218  if (useSingleTower_) {
219  if (doEtSum_) { //this is cone-based HCAL isolation with single tower based footprint removal
220  isol = thisHcalVar_.getHcalEtSumBc(recoEcalCandRef.get(), depth_, hcalCuts); //depth=0 means all depths
221  } else { //this is single tower based H/E
222  isol = thisHcalVar_.getHcalESumBc(recoEcalCandRef.get(), depth_, hcalCuts); //depth=0 means all depths
223  }
224  } else { //useSingleTower_=False means H/E is cone-based.
225  if (doEtSum_) { //hcal iso
226  isol = thisHcalVar_.getHcalEtSum(recoEcalCandRef.get(), depth_, hcalCuts); //depth=0 means all depths
227  } else { // doEtSum_=False means sum up energy, this is for H/E
228  isol = thisHcalVar_.getHcalESum(recoEcalCandRef.get(), depth_, hcalCuts); //depth=0 means all depths
229  }
230  }
231 
232  if (doRhoCorrection_) {
233  int iEA = -1;
234  auto scEta = std::abs(recoEcalCandRef->superCluster()->eta());
235  for (int bIt = absEtaLowEdges_.size() - 1; bIt > -1; bIt--) {
236  if (scEta > absEtaLowEdges_.at(bIt)) {
237  iEA = bIt;
238  break;
239  }
240  }
241  isol = isol - rho * effectiveAreas_.at(iEA);
242  }
243 
244  isoMap.insert(recoEcalCandRef, isol);
245  }
246 
247  iEvent.emplace(putToken_, isoMap);
248 }
249 
const edm::ESGetToken< HcalSeverityLevelComputer, HcalSeverityLevelComputerRcd > hcalSevLvlComputerToken_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void beginRun(edm::Run const &, edm::EventSetup const &)
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
double getHcalESumBc(const reco::Candidate *c, int depth, const HcalPFCuts *hcalCuts) const
Definition: config.py:1
double getHcalEtSumBc(const reco::Candidate *c, int depth, const HcalPFCuts *hcalCuts) const
int iEvent
Definition: GenABIO.cc:224
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const final
const edm::ESGetToken< CaloTowerConstituentsMap, CaloGeometryRecord > caloTowerConstituentsMapToken_
const edm::ESGetToken< HcalChannelQuality, HcalChannelQualityRcd > hcalChannelQualityToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double getHcalESum(const reco::Candidate *c, int depth, const HcalPFCuts *hcalCuts) const
const edm::EDGetTokenT< HBHERecHitCollection > hbheRecHitsTag_
const edm::EDGetTokenT< reco::RecoEcalCandidateCollection > recoEcalCandidateProducer_
void insert(const key_type &k, const data_type &v)
insert an association
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::ESGetToken< HcalPFCuts, HcalPFCutsRcd > hcalCutsToken_
HLT enums.
double getHcalEtSum(const reco::Candidate *c, int depth, const HcalPFCuts *hcalCuts) const
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
std::array< double, 4 > arrayHB
const edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > hcalTopologyToken_
Definition: Run.h:45
const edm::EDPutTokenT< reco::RecoEcalCandidateIsolationMap > putToken_
std::array< double, 7 > arrayHE