CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
PFClusterEMEnergyCorrector Class Reference

#include <PFClusterEMEnergyCorrector.h>

Public Member Functions

void correctEnergies (const edm::Event &evt, const edm::EventSetup &es, const reco::PFCluster::EEtoPSAssociation &assoc, reco::PFClusterCollection &cs)
 
PFClusterEMEnergyCorrectoroperator= (const PFClusterEMEnergyCorrector &)=delete
 
 PFClusterEMEnergyCorrector (const edm::ParameterSet &conf, edm::ConsumesCollector &&cc)
 
 PFClusterEMEnergyCorrector (const PFClusterEMEnergyCorrector &)=delete
 

Private Member Functions

void getAssociatedPSEnergy (const size_t clusIdx, const reco::PFCluster::EEtoPSAssociation &assoc, float &e1, float &e2)
 

Private Attributes

bool applyCrackCorrections_
 
bool applyMVACorrections_
 
bool autoDetectBunchSpacing_
 
edm::EDGetTokenT< unsigned int > bunchSpacing_
 
int bunchSpacingManual_
 
std::unique_ptr
< PFEnergyCalibration
calibrator_
 
std::vector< std::string > condnames_mean_
 
std::vector< std::string > condnames_mean_25ns_
 
std::vector< std::string > condnames_mean_50ns_
 
std::vector< std::string > condnames_sigma_
 
std::vector< std::string > condnames_sigma_25ns_
 
std::vector< std::string > condnames_sigma_50ns_
 
edm::EDGetTokenT
< EBSrFlagCollection
ebSrFlagToken_
 
const
EcalClusterLazyTools::ESGetTokens 
ecalClusterToolsESGetTokens_
 
const EcalReadoutTools::ESGetTokens ecalReadoutToolsESGetTokens_
 
edm::EDGetTokenT
< EESrFlagCollection
eeSrFlagToken_
 
std::vector< edm::ESGetToken
< GBRForestD, GBRDWrapperRcd > > 
forestMeanTokens_25ns_
 
std::vector< edm::ESGetToken
< GBRForestD, GBRDWrapperRcd > > 
forestMeanTokens_50ns_
 
std::vector< edm::ESGetToken
< GBRForestD, GBRDWrapperRcd > > 
forestSigmaTokens_25ns_
 
std::vector< edm::ESGetToken
< GBRForestD, GBRDWrapperRcd > > 
forestSigmaTokens_50ns_
 
double maxPtForMVAEvaluation_
 
double meanlimhighEB_
 
double meanlimhighEE_
 
double meanlimlowEB_
 
double meanlimlowEE_
 
double meanoffsetEB_
 
double meanoffsetEE_
 
double meanscaleEB_
 
double meanscaleEE_
 
edm::EDGetTokenT
< EcalRecHitCollection
recHitsEB_
 
edm::EDGetTokenT
< EcalRecHitCollection
recHitsEE_
 
bool setEnergyUncertainty_
 
double sigmalimhighEB_
 
double sigmalimhighEE_
 
double sigmalimlowEB_
 
double sigmalimlowEE_
 
double sigmaoffsetEB_
 
double sigmaoffsetEE_
 
double sigmascaleEB_
 
double sigmascaleEE_
 
bool srfAwareCorrection_
 

Detailed Description

Definition at line 28 of file PFClusterEMEnergyCorrector.h.

Constructor & Destructor Documentation

PFClusterEMEnergyCorrector::PFClusterEMEnergyCorrector ( const edm::ParameterSet conf,
edm::ConsumesCollector &&  cc 
)

Definition at line 14 of file PFClusterEMEnergyCorrector.cc.

References eostools::move().

18  applyCrackCorrections_ = conf.getParameter<bool>("applyCrackCorrections");
19  applyMVACorrections_ = conf.getParameter<bool>("applyMVACorrections");
20  srfAwareCorrection_ = conf.getParameter<bool>("srfAwareCorrection");
21  setEnergyUncertainty_ = conf.getParameter<bool>("setEnergyUncertainty");
22  maxPtForMVAEvaluation_ = conf.getParameter<double>("maxPtForMVAEvaluation");
23 
24  if (applyMVACorrections_) {
25  meanlimlowEB_ = -0.336;
26  meanlimhighEB_ = 0.916;
29 
30  meanlimlowEE_ = -0.336;
31  meanlimhighEE_ = 0.916;
34 
35  sigmalimlowEB_ = 0.001;
36  sigmalimhighEB_ = 0.4;
39 
40  sigmalimlowEE_ = 0.001;
41  sigmalimhighEE_ = 0.4;
44 
45  recHitsEB_ = cc.consumes<EcalRecHitCollection>(conf.getParameter<edm::InputTag>("recHitsEBLabel"));
46  recHitsEE_ = cc.consumes<EcalRecHitCollection>(conf.getParameter<edm::InputTag>("recHitsEELabel"));
47  autoDetectBunchSpacing_ = conf.getParameter<bool>("autoDetectBunchSpacing");
48 
50  bunchSpacing_ = cc.consumes<unsigned int>(edm::InputTag("bunchSpacingProducer"));
52  } else {
53  bunchSpacingManual_ = conf.getParameter<int>("bunchSpacing");
54  }
55 
57  {"ecalPFClusterCorV2_EB_pfSize1_mean_25ns",
58  "ecalPFClusterCorV2_EB_pfSize2_mean_25ns",
59  "ecalPFClusterCorV2_EB_pfSize3_ptbin1_mean_25ns",
60  "ecalPFClusterCorV2_EB_pfSize3_ptbin2_mean_25ns",
61  "ecalPFClusterCorV2_EB_pfSize3_ptbin3_mean_25ns",
62  "ecalPFClusterCorV2_EE_pfSize1_mean_25ns",
63  "ecalPFClusterCorV2_EE_pfSize2_mean_25ns",
64  "ecalPFClusterCorV2_EE_pfSize3_ptbin1_mean_25ns",
65  "ecalPFClusterCorV2_EE_pfSize3_ptbin2_mean_25ns",
66  "ecalPFClusterCorV2_EE_pfSize3_ptbin3_mean_25ns"});
68  {"ecalPFClusterCorV2_EB_pfSize1_sigma_25ns",
69  "ecalPFClusterCorV2_EB_pfSize2_sigma_25ns",
70  "ecalPFClusterCorV2_EB_pfSize3_ptbin1_sigma_25ns",
71  "ecalPFClusterCorV2_EB_pfSize3_ptbin2_sigma_25ns",
72  "ecalPFClusterCorV2_EB_pfSize3_ptbin3_sigma_25ns",
73  "ecalPFClusterCorV2_EE_pfSize1_sigma_25ns",
74  "ecalPFClusterCorV2_EE_pfSize2_sigma_25ns",
75  "ecalPFClusterCorV2_EE_pfSize3_ptbin1_sigma_25ns",
76  "ecalPFClusterCorV2_EE_pfSize3_ptbin2_sigma_25ns",
77  "ecalPFClusterCorV2_EE_pfSize3_ptbin3_sigma_25ns"});
79  {"ecalPFClusterCorV2_EB_pfSize1_mean_50ns",
80  "ecalPFClusterCorV2_EB_pfSize2_mean_50ns",
81  "ecalPFClusterCorV2_EB_pfSize3_ptbin1_mean_50ns",
82  "ecalPFClusterCorV2_EB_pfSize3_ptbin2_mean_50ns",
83  "ecalPFClusterCorV2_EB_pfSize3_ptbin3_mean_50ns",
84  "ecalPFClusterCorV2_EE_pfSize1_mean_50ns",
85  "ecalPFClusterCorV2_EE_pfSize2_mean_50ns",
86  "ecalPFClusterCorV2_EE_pfSize3_ptbin1_mean_50ns",
87  "ecalPFClusterCorV2_EE_pfSize3_ptbin2_mean_50ns",
88  "ecalPFClusterCorV2_EE_pfSize3_ptbin3_mean_50ns"});
90  {"ecalPFClusterCorV2_EB_pfSize1_sigma_50ns",
91  "ecalPFClusterCorV2_EB_pfSize2_sigma_50ns",
92  "ecalPFClusterCorV2_EB_pfSize3_ptbin1_sigma_50ns",
93  "ecalPFClusterCorV2_EB_pfSize3_ptbin2_sigma_50ns",
94  "ecalPFClusterCorV2_EB_pfSize3_ptbin3_sigma_50ns",
95  "ecalPFClusterCorV2_EE_pfSize1_sigma_50ns",
96  "ecalPFClusterCorV2_EE_pfSize2_sigma_50ns",
97  "ecalPFClusterCorV2_EE_pfSize3_ptbin1_sigma_50ns",
98  "ecalPFClusterCorV2_EE_pfSize3_ptbin2_sigma_50ns",
99  "ecalPFClusterCorV2_EE_pfSize3_ptbin3_sigma_50ns"});
100 
101  if (srfAwareCorrection_) {
102  sigmalimlowEE_ = 0.001;
103  sigmalimhighEE_ = 0.1;
106 
109 
110  condnames_mean_.insert(condnames_mean_.end(),
111  {"ecalPFClusterCor2017V2_EB_ZS_mean_25ns",
112  "ecalPFClusterCor2017V2_EB_Full_ptbin1_mean_25ns",
113  "ecalPFClusterCor2017V2_EB_Full_ptbin2_mean_25ns",
114  "ecalPFClusterCor2017V2_EB_Full_ptbin3_mean_25ns",
115  "ecalPFClusterCor2017V2_EE_ZS_mean_25ns",
116  "ecalPFClusterCor2017V2_EE_Full_ptbin1_mean_25ns",
117  "ecalPFClusterCor2017V2_EE_Full_ptbin2_mean_25ns",
118  "ecalPFClusterCor2017V2_EE_Full_ptbin3_mean_25ns"});
119 
120  condnames_sigma_.insert(condnames_sigma_.end(),
121  {"ecalPFClusterCor2017V2_EB_ZS_sigma_25ns",
122  "ecalPFClusterCor2017V2_EB_Full_ptbin1_sigma_25ns",
123  "ecalPFClusterCor2017V2_EB_Full_ptbin2_sigma_25ns",
124  "ecalPFClusterCor2017V2_EB_Full_ptbin3_sigma_25ns",
125  "ecalPFClusterCor2017V2_EE_ZS_sigma_25ns",
126  "ecalPFClusterCor2017V2_EE_Full_ptbin1_sigma_25ns",
127  "ecalPFClusterCor2017V2_EE_Full_ptbin2_sigma_25ns",
128  "ecalPFClusterCor2017V2_EE_Full_ptbin3_sigma_25ns"});
129 
130  for (short i = 0; i < (short)condnames_mean_.size(); i++) {
133  }
134  } else {
135  for (short i = 0; i < (short)condnames_mean_25ns_.size(); i++) {
138  }
139  for (short i = 0; i < (short)condnames_mean_50ns_.size(); i++) {
142  }
143  }
144  }
145 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< edm::ESGetToken< GBRForestD, GBRDWrapperRcd > > forestMeanTokens_50ns_
std::vector< edm::ESGetToken< GBRForestD, GBRDWrapperRcd > > forestMeanTokens_25ns_
edm::EDGetTokenT< EESrFlagCollection > eeSrFlagToken_
std::unique_ptr< PFEnergyCalibration > calibrator_
edm::EDGetTokenT< unsigned int > bunchSpacing_
edm::EDGetTokenT< EcalRecHitCollection > recHitsEE_
std::vector< std::string > condnames_mean_50ns_
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_
std::vector< std::string > condnames_sigma_25ns_
std::vector< std::string > condnames_mean_25ns_
def move
Definition: eostools.py:511
std::vector< std::string > condnames_sigma_
const EcalReadoutTools::ESGetTokens ecalReadoutToolsESGetTokens_
edm::EDGetTokenT< EcalRecHitCollection > recHitsEB_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< edm::ESGetToken< GBRForestD, GBRDWrapperRcd > > forestSigmaTokens_50ns_
edm::EDGetTokenT< EBSrFlagCollection > ebSrFlagToken_
std::vector< std::string > condnames_sigma_50ns_
std::vector< edm::ESGetToken< GBRForestD, GBRDWrapperRcd > > forestSigmaTokens_25ns_
std::vector< std::string > condnames_mean_
PFClusterEMEnergyCorrector::PFClusterEMEnergyCorrector ( const PFClusterEMEnergyCorrector )
delete

Member Function Documentation

void PFClusterEMEnergyCorrector::correctEnergies ( const edm::Event evt,
const edm::EventSetup es,
const reco::PFCluster::EEtoPSAssociation assoc,
reco::PFClusterCollection cs 
)

a hit can be ZS or forced ZS. A hit can be in Full readout or Forced to be FULL readout if it is ZS, then clusFlag (in binary) = 0001 if it is forced ZS, then clusFlag (in binary) = 0101 if it is FR, then clusFlag (in binary) = 0011 if it is forced FR, then clusFlag (in binary) = 0111 i.e 3rd bit is set. Even if it is forced, we should mark it is as ZS or FR. To take care of it, just check the LSB and second LSB(SLSB)

it is clusFlag==1, 5

Definition at line 147 of file PFClusterEMEnergyCorrector.cc.

References funct::abs(), applyCrackCorrections_, autoDetectBunchSpacing_, bunchSpacing_, bunchSpacingManual_, calibrator_, condnames_mean_25ns_, condnames_mean_50ns_, alignCSCRings::e, ebSrFlagToken_, PFLayer::ECAL_BARREL, ecalClusterToolsESGetTokens_, ecalReadoutToolsESGetTokens_, eeSrFlagToken_, reco::PFCluster::energy(), funct::exp(), forestMeanTokens_25ns_, forestMeanTokens_50ns_, forestSigmaTokens_25ns_, forestSigmaTokens_50ns_, EcalClusterLazyToolsBase::ESGetTokens::get(), getAssociatedPSEnergy(), edm::Event::getByToken(), edm::EventSetup::getHandle(), GBRForestD::GetResponse(), EBDetId::ieta(), edm::HandleBase::isValid(), EEDetId::ix(), reco::PFCluster::layer(), LogDebug, SiStripPI::mean, meanoffsetEB_, meanoffsetEE_, meanscaleEB_, meanscaleEE_, SiStripPI::min, DiDispStaMuonMonitor_cfi::pt, reco::PFCluster::pt(), recHitsEB_, recHitsEE_, reco::CaloCluster::seed(), reco::CaloCluster::setCorrectedEnergy(), reco::CaloCluster::setCorrectedEnergyUncertainty(), sigmaoffsetEB_, sigmaoffsetEE_, sigmascaleEB_, sigmascaleEE_, and findQualityFiles::size.

150  {
151  // First deal with pre-MVA corrections
152  // Kept for backward compatibility (and for HLT)
153  if (!applyMVACorrections_) {
154  for (unsigned int idx = 0; idx < cs.size(); ++idx) {
155  reco::PFCluster &cluster = cs[idx];
156  bool iseb = cluster.layer() == PFLayer::ECAL_BARREL;
157  float ePS1 = 0., ePS2 = 0.;
158  if (!iseb)
159  getAssociatedPSEnergy(idx, assoc, ePS1, ePS2);
160  double correctedEnergy = calibrator_->energyEm(cluster, ePS1, ePS2, applyCrackCorrections_);
161  cluster.setCorrectedEnergy(correctedEnergy);
162  }
163  return;
164  }
165 
166  // Common objects for SRF-aware and old style corrections
168  EcalReadoutTools readoutTool(evt, es, ecalReadoutToolsESGetTokens_);
169 
170  if (!srfAwareCorrection_) {
171  int bunchspacing = 450;
173  edm::Handle<unsigned int> bunchSpacingH;
174  evt.getByToken(bunchSpacing_, bunchSpacingH);
175  bunchspacing = *bunchSpacingH;
176  } else {
177  bunchspacing = bunchSpacingManual_;
178  }
179 
180  const unsigned int ncor = (bunchspacing == 25) ? condnames_mean_25ns_.size() : condnames_mean_50ns_.size();
181 
182  std::vector<edm::ESHandle<GBRForestD> > forestH_mean(ncor);
183  std::vector<edm::ESHandle<GBRForestD> > forestH_sigma(ncor);
184 
185  if (bunchspacing == 25) {
186  for (unsigned int icor = 0; icor < ncor; ++icor) {
187  forestH_mean[icor] = es.getHandle(forestMeanTokens_25ns_[icor]);
188  forestH_sigma[icor] = es.getHandle(forestSigmaTokens_25ns_[icor]);
189  }
190  } else {
191  for (unsigned int icor = 0; icor < ncor; ++icor) {
192  forestH_mean[icor] = es.getHandle(forestMeanTokens_50ns_[icor]);
193  forestH_sigma[icor] = es.getHandle(forestSigmaTokens_50ns_[icor]);
194  }
195  }
196 
197  std::array<float, 5> eval;
198  for (unsigned int idx = 0; idx < cs.size(); ++idx) {
199  reco::PFCluster &cluster = cs[idx];
200  bool iseb = cluster.layer() == PFLayer::ECAL_BARREL;
201  float ePS1 = 0., ePS2 = 0.;
202  if (!iseb)
203  getAssociatedPSEnergy(idx, assoc, ePS1, ePS2);
204 
205  double e = cluster.energy();
206  double pt = cluster.pt();
207  double evale = e;
209  evale *= maxPtForMVAEvaluation_ / pt;
210  }
211  double invE = (e == 0.) ? 0. : 1. / e; //guard against dividing by 0.
212  int size = lazyTool.n5x5(cluster);
213 
214  int ietaix = 0;
215  int iphiiy = 0;
216  if (iseb) {
217  EBDetId ebseed(cluster.seed());
218  ietaix = ebseed.ieta();
219  iphiiy = ebseed.iphi();
220  } else {
221  EEDetId eeseed(cluster.seed());
222  ietaix = eeseed.ix();
223  iphiiy = eeseed.iy();
224  }
225 
226  //find index of corrections (0-4 for EB, 5-9 for EE, depending on cluster size and raw pt)
227  int coridx = std::min(size, 3) - 1;
228  if (coridx == 2) {
229  if (pt > 4.5) {
230  coridx += 1;
231  }
232  if (pt > 18.) {
233  coridx += 1;
234  }
235  }
236  if (!iseb) {
237  coridx += 5;
238  }
239 
240  const GBRForestD &meanforest = *forestH_mean[coridx].product();
241  const GBRForestD &sigmaforest = *forestH_sigma[coridx].product();
242 
243  //fill array for forest evaluation
244  eval[0] = evale;
245  eval[1] = ietaix;
246  eval[2] = iphiiy;
247  if (!iseb) {
248  eval[3] = ePS1 * invE;
249  eval[4] = ePS2 * invE;
250  }
251 
252  //these are the actual BDT responses
253  double rawmean = meanforest.GetResponse(eval.data());
254  double rawsigma = sigmaforest.GetResponse(eval.data());
255 
256  //apply transformation to limited output range (matching the training)
257  double mean = iseb ? meanoffsetEB_ + meanscaleEB_ * vdt::fast_sin(rawmean)
258  : meanoffsetEE_ + meanscaleEE_ * vdt::fast_sin(rawmean);
259  double sigma = iseb ? sigmaoffsetEB_ + sigmascaleEB_ * vdt::fast_sin(rawsigma)
260  : sigmaoffsetEE_ + sigmascaleEE_ * vdt::fast_sin(rawsigma);
261 
262  //regression target is ln(Etrue/Eraw)
263  //so corrected energy is ecor=exp(mean)*e, uncertainty is exp(mean)*eraw*sigma=ecor*sigma
264  double ecor = vdt::fast_exp(mean) * e;
265  double sigmacor = sigma * ecor;
266 
267  cluster.setCorrectedEnergy(ecor);
269  cluster.setCorrectedEnergyUncertainty(sigmacor);
270  else
271  cluster.setCorrectedEnergyUncertainty(0.);
272  }
273  return;
274  }
275 
276  // Selective Readout Flags
279  evt.getByToken(ebSrFlagToken_, ebSrFlags);
280  evt.getByToken(eeSrFlagToken_, eeSrFlags);
281  if (!ebSrFlags.isValid() || !eeSrFlags.isValid())
282  throw cms::Exception("PFClusterEMEnergyCorrector")
283  << "This version of PFCluster corrections requires the SrFlagCollection information to proceed!\n";
284 
285  const unsigned int ncor = forestMeanTokens_25ns_.size();
286  std::vector<edm::ESHandle<GBRForestD> > forestH_mean(ncor);
287  std::vector<edm::ESHandle<GBRForestD> > forestH_sigma(ncor);
288 
289  for (unsigned int icor = 0; icor < ncor; ++icor) {
290  forestH_mean[icor] = es.getHandle(forestMeanTokens_25ns_[icor]);
291  forestH_sigma[icor] = es.getHandle(forestSigmaTokens_25ns_[icor]);
292  }
293 
294  std::array<float, 6> evalEB;
295  std::array<float, 5> evalEE;
296 
297  for (unsigned int idx = 0; idx < cs.size(); ++idx) {
298  reco::PFCluster &cluster = cs[idx];
299  bool iseb = cluster.layer() == PFLayer::ECAL_BARREL;
300  float ePS1 = 0., ePS2 = 0.;
301  if (!iseb)
302  getAssociatedPSEnergy(idx, assoc, ePS1, ePS2);
303 
304  double e = cluster.energy();
305  double pt = cluster.pt();
306  double evale = e;
308  evale *= maxPtForMVAEvaluation_ / pt;
309  }
310  double invE = (e == 0.) ? 0. : 1. / e; //guard against dividing by 0.
311  int size = lazyTool.n5x5(cluster);
312  int reducedHits = size;
313  if (size >= 3)
314  reducedHits = 3;
315 
316  int ietaix = 0;
317  int iphiiy = 0;
318  if (iseb) {
319  EBDetId ebseed(cluster.seed());
320  ietaix = ebseed.ieta();
321  iphiiy = ebseed.iphi();
322  } else {
323  EEDetId eeseed(cluster.seed());
324  ietaix = eeseed.ix();
325  iphiiy = eeseed.iy();
326  }
327 
328  // Hardcoded number are positions of modules boundaries of ECAL
329  int signeta = (ietaix > 0) ? 1 : -1;
330  int ietamod20 = (std::abs(ietaix) < 26) ? ietaix - signeta : (ietaix - 26 * signeta) % 20;
331  int iphimod20 = (iphiiy - 1) % 20;
332 
333  int clusFlag = 0;
334  if (iseb) {
335  auto ecalUnit = readoutTool.readOutUnitOf(static_cast<EBDetId>(cluster.seed()));
336  EBSrFlagCollection::const_iterator srf = ebSrFlags->find(ecalUnit);
337  if (srf != ebSrFlags->end())
338  clusFlag = srf->value();
339  else
340  clusFlag = 3;
341  } else {
342  auto ecalUnit = readoutTool.readOutUnitOf(static_cast<EEDetId>(cluster.seed()));
343  EESrFlagCollection::const_iterator srf = eeSrFlags->find(ecalUnit);
344  if (srf != eeSrFlags->end())
345  clusFlag = srf->value();
346  else
347  clusFlag = 3;
348  }
349 
350  //find index of corrections (0-3 for EB, 4-7 for EE, depending on cluster size and raw pt)
351  int coridx = 0;
352  int regind = 0;
353  if (!iseb)
354  regind = 4;
355 
365  int ZS_bit = clusFlag >> 0 & 1;
366  int FR_bit = clusFlag >> 1 & 1;
367 
368  if (ZS_bit != 0 && FR_bit == 0)
369  coridx = 0 + regind;
370  else {
371  if (pt < 2.5)
372  coridx = 1 + regind;
373  else if (pt >= 2.5 && pt < 6.)
374  coridx = 2 + regind;
375  else if (pt >= 6.)
376  coridx = 3 + regind;
377  }
378  if (ZS_bit == 0 || clusFlag > 7) {
379  edm::LogWarning("PFClusterEMEnergyCorrector")
380  << "We can only correct regions readout in ZS (flag 1,5) or FULL readout (flag 3,7). Flag " << clusFlag
381  << " is not recognized."
382  << "\n"
383  << "Assuming FULL readout and continuing";
384  }
385 
386  const GBRForestD &meanforest = *forestH_mean[coridx].product();
387  const GBRForestD &sigmaforest = *forestH_sigma[coridx].product();
388 
389  //fill array for forest evaluation
390  if (iseb) {
391  evalEB[0] = evale;
392  evalEB[1] = ietaix;
393  evalEB[2] = iphiiy;
394  evalEB[3] = ietamod20;
395  evalEB[4] = iphimod20;
396  evalEB[5] = reducedHits;
397  } else {
398  evalEE[0] = evale;
399  evalEE[1] = ietaix;
400  evalEE[2] = iphiiy;
401  evalEE[3] = (ePS1 + ePS2) * invE;
402  evalEE[4] = reducedHits;
403  }
404 
405  //these are the actual BDT responses
406  double rawmean = 1;
407  double rawsigma = 0;
408 
409  if (iseb) {
410  rawmean = meanforest.GetResponse(evalEB.data());
411  rawsigma = sigmaforest.GetResponse(evalEB.data());
412  } else {
413  rawmean = meanforest.GetResponse(evalEE.data());
414  rawsigma = sigmaforest.GetResponse(evalEE.data());
415  }
416 
417  //apply transformation to limited output range (matching the training)
418  //the training was done with different transformations for EB and EE (width only)
419  //makes a the code a bit more cumbersome, but it is not a problem per se
420  double mean = iseb ? meanoffsetEB_ + meanscaleEB_ * vdt::fast_sin(rawmean)
421  : meanoffsetEE_ + meanscaleEE_ * vdt::fast_sin(rawmean);
422  double sigma = iseb ? sigmaoffsetEB_ + sigmascaleEB_ * vdt::fast_sin(rawsigma)
423  : sigmaoffsetEE_ + sigmascaleEE_ * vdt::fast_sin(rawsigma);
424 
425  //regression target is ln(Etrue/Eraw)
426  //so corrected energy is ecor=exp(mean)*e, uncertainty is exp(mean)*eraw*sigma=ecor*sigma
427  double ecor = iseb ? vdt::fast_exp(mean) * e : vdt::fast_exp(mean) * (e + ePS1 + ePS2);
428  double sigmacor = sigma * ecor;
429 
430  LogDebug("PFClusterEMEnergyCorrector")
431  << "ieta : iphi : ietamod20 : iphimod20 : size : reducedHits = " << ietaix << " " << iphiiy << " " << ietamod20
432  << " " << iphimod20 << " " << size << " " << reducedHits << "\n"
433  << "isEB : eraw : ePS1 : ePS2 : (eps1+eps2)/raw : Flag = " << iseb << " " << evale << " " << ePS1 << " " << ePS2
434  << " " << (ePS1 + ePS2) / evale << " " << clusFlag << "\n"
435  << "response : correction = " << exp(mean) << " " << ecor;
436 
437  cluster.setCorrectedEnergy(ecor);
439  cluster.setCorrectedEnergyUncertainty(sigmacor);
440  else
441  cluster.setCorrectedEnergyUncertainty(0.);
442  }
443 }
PFLayer::Layer layer() const
cluster layer, see PFLayer.h in this directory
Definition: PFCluster.cc:56
double GetResponse(const float *vector) const
Definition: GBRForestD.h:49
std::vector< edm::ESGetToken< GBRForestD, GBRDWrapperRcd > > forestMeanTokens_50ns_
int ix() const
Definition: EEDetId.h:77
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:42
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
unique_ptr< ClusterSequence > cs
std::vector< T >::const_iterator const_iterator
double pt() const
transverse momentum, massless approximation
Definition: PFCluster.h:110
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
std::vector< edm::ESGetToken< GBRForestD, GBRDWrapperRcd > > forestMeanTokens_25ns_
edm::EDGetTokenT< EESrFlagCollection > eeSrFlagToken_
std::unique_ptr< PFEnergyCalibration > calibrator_
edm::EDGetTokenT< unsigned int > bunchSpacing_
edm::EDGetTokenT< EcalRecHitCollection > recHitsEE_
std::vector< std::string > condnames_mean_50ns_
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_
std::vector< std::string > condnames_mean_25ns_
void setCorrectedEnergy(double cenergy)
Definition: CaloCluster.h:137
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
bool isValid() const
Definition: HandleBase.h:70
const EcalReadoutTools::ESGetTokens ecalReadoutToolsESGetTokens_
double energy() const
cluster energy
Definition: PFCluster.h:74
ESData get(edm::EventSetup const &eventSetup) const
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:219
edm::EDGetTokenT< EcalRecHitCollection > recHitsEB_
std::vector< edm::ESGetToken< GBRForestD, GBRDWrapperRcd > > forestSigmaTokens_50ns_
edm::EDGetTokenT< EBSrFlagCollection > ebSrFlagToken_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
Log< level::Warning, false > LogWarning
void setCorrectedEnergyUncertainty(float energyerr)
Definition: CaloCluster.h:138
void getAssociatedPSEnergy(const size_t clusIdx, const reco::PFCluster::EEtoPSAssociation &assoc, float &e1, float &e2)
std::vector< edm::ESGetToken< GBRForestD, GBRDWrapperRcd > > forestSigmaTokens_25ns_
tuple size
Write out results.
#define LogDebug(id)
void PFClusterEMEnergyCorrector::getAssociatedPSEnergy ( const size_t  clusIdx,
const reco::PFCluster::EEtoPSAssociation assoc,
float &  e1,
float &  e2 
)
private

Definition at line 445 of file PFClusterEMEnergyCorrector.cc.

References PFLayer::PS1, PFLayer::PS2, and sortByKey().

Referenced by correctEnergies().

448  {
449  e1 = 0;
450  e2 = 0;
451  auto ee_key_val = std::make_pair(clusIdx, edm::Ptr<reco::PFCluster>());
452  const auto clustops = std::equal_range(assoc.begin(), assoc.end(), ee_key_val, sortByKey);
453  for (auto i_ps = clustops.first; i_ps != clustops.second; ++i_ps) {
454  edm::Ptr<reco::PFCluster> psclus(i_ps->second);
455  switch (psclus->layer()) {
456  case PFLayer::PS1:
457  e1 += psclus->energy();
458  break;
459  case PFLayer::PS2:
460  e2 += psclus->energy();
461  break;
462  default:
463  break;
464  }
465  }
466 }
bool sortByKey(const EEPSPair &a, const EEPSPair &b)
PFClusterEMEnergyCorrector& PFClusterEMEnergyCorrector::operator= ( const PFClusterEMEnergyCorrector )
delete

Member Data Documentation

bool PFClusterEMEnergyCorrector::applyCrackCorrections_
private

Definition at line 62 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

bool PFClusterEMEnergyCorrector::applyMVACorrections_
private

Definition at line 63 of file PFClusterEMEnergyCorrector.h.

bool PFClusterEMEnergyCorrector::autoDetectBunchSpacing_
private

Definition at line 66 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

edm::EDGetTokenT<unsigned int> PFClusterEMEnergyCorrector::bunchSpacing_
private

Definition at line 48 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

int PFClusterEMEnergyCorrector::bunchSpacingManual_
private

Definition at line 67 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

std::unique_ptr<PFEnergyCalibration> PFClusterEMEnergyCorrector::calibrator_
private

Definition at line 69 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

std::vector<std::string> PFClusterEMEnergyCorrector::condnames_mean_
private

Definition at line 53 of file PFClusterEMEnergyCorrector.h.

std::vector<std::string> PFClusterEMEnergyCorrector::condnames_mean_25ns_
private

Definition at line 56 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

std::vector<std::string> PFClusterEMEnergyCorrector::condnames_mean_50ns_
private

Definition at line 58 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

std::vector<std::string> PFClusterEMEnergyCorrector::condnames_sigma_
private

Definition at line 54 of file PFClusterEMEnergyCorrector.h.

std::vector<std::string> PFClusterEMEnergyCorrector::condnames_sigma_25ns_
private

Definition at line 57 of file PFClusterEMEnergyCorrector.h.

std::vector<std::string> PFClusterEMEnergyCorrector::condnames_sigma_50ns_
private

Definition at line 59 of file PFClusterEMEnergyCorrector.h.

edm::EDGetTokenT<EBSrFlagCollection> PFClusterEMEnergyCorrector::ebSrFlagToken_
private

Definition at line 42 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

const EcalClusterLazyTools::ESGetTokens PFClusterEMEnergyCorrector::ecalClusterToolsESGetTokens_
private

Definition at line 50 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

const EcalReadoutTools::ESGetTokens PFClusterEMEnergyCorrector::ecalReadoutToolsESGetTokens_
private

Definition at line 51 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

edm::EDGetTokenT<EESrFlagCollection> PFClusterEMEnergyCorrector::eeSrFlagToken_
private

Definition at line 43 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

std::vector<edm::ESGetToken<GBRForestD, GBRDWrapperRcd> > PFClusterEMEnergyCorrector::forestMeanTokens_25ns_
private

Definition at line 96 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

std::vector<edm::ESGetToken<GBRForestD, GBRDWrapperRcd> > PFClusterEMEnergyCorrector::forestMeanTokens_50ns_
private

Definition at line 98 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

std::vector<edm::ESGetToken<GBRForestD, GBRDWrapperRcd> > PFClusterEMEnergyCorrector::forestSigmaTokens_25ns_
private

Definition at line 97 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

std::vector<edm::ESGetToken<GBRForestD, GBRDWrapperRcd> > PFClusterEMEnergyCorrector::forestSigmaTokens_50ns_
private

Definition at line 99 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

double PFClusterEMEnergyCorrector::maxPtForMVAEvaluation_
private

Definition at line 40 of file PFClusterEMEnergyCorrector.h.

double PFClusterEMEnergyCorrector::meanlimhighEB_
private

Definition at line 76 of file PFClusterEMEnergyCorrector.h.

double PFClusterEMEnergyCorrector::meanlimhighEE_
private

Definition at line 81 of file PFClusterEMEnergyCorrector.h.

double PFClusterEMEnergyCorrector::meanlimlowEB_
private

Definition at line 75 of file PFClusterEMEnergyCorrector.h.

double PFClusterEMEnergyCorrector::meanlimlowEE_
private

Definition at line 80 of file PFClusterEMEnergyCorrector.h.

double PFClusterEMEnergyCorrector::meanoffsetEB_
private

Definition at line 77 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

double PFClusterEMEnergyCorrector::meanoffsetEE_
private

Definition at line 82 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

double PFClusterEMEnergyCorrector::meanscaleEB_
private

Definition at line 78 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

double PFClusterEMEnergyCorrector::meanscaleEE_
private

Definition at line 83 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

edm::EDGetTokenT<EcalRecHitCollection> PFClusterEMEnergyCorrector::recHitsEB_
private

Definition at line 46 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

edm::EDGetTokenT<EcalRecHitCollection> PFClusterEMEnergyCorrector::recHitsEE_
private

Definition at line 47 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

bool PFClusterEMEnergyCorrector::setEnergyUncertainty_
private

Definition at line 64 of file PFClusterEMEnergyCorrector.h.

double PFClusterEMEnergyCorrector::sigmalimhighEB_
private

Definition at line 86 of file PFClusterEMEnergyCorrector.h.

double PFClusterEMEnergyCorrector::sigmalimhighEE_
private

Definition at line 91 of file PFClusterEMEnergyCorrector.h.

double PFClusterEMEnergyCorrector::sigmalimlowEB_
private

Definition at line 85 of file PFClusterEMEnergyCorrector.h.

double PFClusterEMEnergyCorrector::sigmalimlowEE_
private

Definition at line 90 of file PFClusterEMEnergyCorrector.h.

double PFClusterEMEnergyCorrector::sigmaoffsetEB_
private

Definition at line 87 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

double PFClusterEMEnergyCorrector::sigmaoffsetEE_
private

Definition at line 92 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

double PFClusterEMEnergyCorrector::sigmascaleEB_
private

Definition at line 88 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

double PFClusterEMEnergyCorrector::sigmascaleEE_
private

Definition at line 93 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

bool PFClusterEMEnergyCorrector::srfAwareCorrection_
private

Definition at line 61 of file PFClusterEMEnergyCorrector.h.