CMS 3D CMS Logo

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< PFEnergyCalibrationcalibrator_
 
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< EBSrFlagCollectionebSrFlagToken_
 
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_
 
const EcalReadoutTools::ESGetTokens ecalReadoutToolsESGetTokens_
 
edm::EDGetTokenT< EESrFlagCollectioneeSrFlagToken_
 
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< EcalRecHitCollectionrecHitsEB_
 
edm::EDGetTokenT< EcalRecHitCollectionrecHitsEE_
 
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() [1/2]

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

Definition at line 14 of file PFClusterEMEnergyCorrector.cc.

References gpuPixelDoublets::cc, and 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 
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 
107  ebSrFlagToken_ = cc.consumes<EBSrFlagCollection>(conf.getParameter<edm::InputTag>("ebSrFlagLabel"));
108  eeSrFlagToken_ = cc.consumes<EESrFlagCollection>(conf.getParameter<edm::InputTag>("eeSrFlagLabel"));
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++) {
131  forestMeanTokens_25ns_.emplace_back(cc.esConsumes(edm::ESInputTag("", condnames_mean_[i])));
132  forestSigmaTokens_25ns_.emplace_back(cc.esConsumes(edm::ESInputTag("", condnames_sigma_[i])));
133  }
134  } else {
135  for (short i = 0; i < (short)condnames_mean_25ns_.size(); i++) {
136  forestMeanTokens_25ns_.emplace_back(cc.esConsumes(edm::ESInputTag("", condnames_mean_25ns_[i])));
137  forestSigmaTokens_25ns_.emplace_back(cc.esConsumes(edm::ESInputTag("", condnames_sigma_25ns_[i])));
138  }
139  for (short i = 0; i < (short)condnames_mean_50ns_.size(); i++) {
140  forestMeanTokens_50ns_.emplace_back(cc.esConsumes(edm::ESInputTag("", condnames_mean_50ns_[i])));
141  forestSigmaTokens_50ns_.emplace_back(cc.esConsumes(edm::ESInputTag("", condnames_sigma_50ns_[i])));
142  }
143  }
144  }
145 }
std::vector< edm::ESGetToken< GBRForestD, GBRDWrapperRcd > > forestMeanTokens_50ns_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
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_
std::vector< std::string > condnames_sigma_
const EcalReadoutTools::ESGetTokens ecalReadoutToolsESGetTokens_
edm::EDGetTokenT< EcalRecHitCollection > recHitsEB_
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_
def move(src, dest)
Definition: eostools.py:511

◆ PFClusterEMEnergyCorrector() [2/2]

PFClusterEMEnergyCorrector::PFClusterEMEnergyCorrector ( const PFClusterEMEnergyCorrector )
delete

Member Function Documentation

◆ correctEnergies()

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_, applyMVACorrections_, trackingPlots::assoc, autoDetectBunchSpacing_, bunchSpacing_, bunchSpacingManual_, calibrator_, condnames_mean_25ns_, condnames_mean_50ns_, callgraph::cs, MillePedeFileConverter_cfg::e, ebSrFlagToken_, PFLayer::ECAL_BARREL, ecalClusterToolsESGetTokens_, ecalReadoutToolsESGetTokens_, eeSrFlagToken_, edm::SortedCollection< T, SORT >::end(), reco::PFCluster::energy(), JetChargeProducer_cfi::exp, edm::SortedCollection< T, SORT >::find(), forestMeanTokens_25ns_, forestMeanTokens_50ns_, forestSigmaTokens_25ns_, forestSigmaTokens_50ns_, EcalClusterLazyToolsBase::ESGetTokens::get(), getAssociatedPSEnergy(), edm::Event::getByToken(), edm::EventSetup::getHandle(), GBRForestD::GetResponse(), heavyIonCSV_trainingSettings::idx, EBDetId::ieta(), edm::HandleBase::isValid(), EEDetId::ix(), reco::PFCluster::layer(), LogDebug, maxPtForMVAEvaluation_, SiStripPI::mean, meanoffsetEB_, meanoffsetEE_, meanscaleEB_, meanscaleEE_, SiStripPI::min, or, DiDispStaMuonMonitor_cfi::pt, reco::PFCluster::pt(), recHitsEB_, recHitsEE_, reco::CaloCluster::seed(), reco::CaloCluster::setCorrectedEnergy(), reco::CaloCluster::setCorrectedEnergyUncertainty(), setEnergyUncertainty_, sigmaoffsetEB_, sigmaoffsetEE_, sigmascaleEB_, sigmascaleEE_, findQualityFiles::size, and srfAwareCorrection_.

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 (not ebSrFlags.isValid() or not eeSrFlags.isValid())
282  edm::LogInfo("PFClusterEMEnergyCorrector") << "SrFlagCollection information is not available. The ECAL PFCluster "
283  "corrections will assume \"full readout\" for all hits.";
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  // Assume that hits for which no information is avaiable have a Full Readout (binary 0011)
334  int clusFlag = 3;
335  if (iseb) {
336  if (ebSrFlags.isValid()) {
337  auto ecalUnit = readoutTool.readOutUnitOf(static_cast<EBDetId>(cluster.seed()));
338  EBSrFlagCollection::const_iterator srf = ebSrFlags->find(ecalUnit);
339  if (srf != ebSrFlags->end())
340  clusFlag = srf->value();
341  }
342  } else {
343  if (eeSrFlags.isValid()) {
344  auto ecalUnit = readoutTool.readOutUnitOf(static_cast<EEDetId>(cluster.seed()));
345  EESrFlagCollection::const_iterator srf = eeSrFlags->find(ecalUnit);
346  if (srf != eeSrFlags->end())
347  clusFlag = srf->value();
348  }
349  }
350 
351  // Find index of corrections (0-3 for EB, 4-7 for EE, depending on cluster size and raw pt)
352  int coridx = 0;
353  int regind = 0;
354  if (!iseb)
355  regind = 4;
356 
366  int ZS_bit = clusFlag >> 0 & 1;
367  int FR_bit = clusFlag >> 1 & 1;
368 
369  if (ZS_bit != 0 && FR_bit == 0)
370  coridx = 0 + regind;
371  else {
372  if (pt < 2.5)
373  coridx = 1 + regind;
374  else if (pt >= 2.5 && pt < 6.)
375  coridx = 2 + regind;
376  else if (pt >= 6.)
377  coridx = 3 + regind;
378  }
379  if (ZS_bit == 0 || clusFlag > 7) {
380  edm::LogWarning("PFClusterEMEnergyCorrector")
381  << "We can only correct regions readout in ZS (flag 1,5) or FULL readout (flag 3,7). Flag " << clusFlag
382  << " is not recognized."
383  << "\n"
384  << "Assuming FULL readout and continuing";
385  }
386 
387  const GBRForestD &meanforest = *forestH_mean[coridx].product();
388  const GBRForestD &sigmaforest = *forestH_sigma[coridx].product();
389 
390  //fill array for forest evaluation
391  if (iseb) {
392  evalEB[0] = evale;
393  evalEB[1] = ietaix;
394  evalEB[2] = iphiiy;
395  evalEB[3] = ietamod20;
396  evalEB[4] = iphimod20;
397  evalEB[5] = reducedHits;
398  } else {
399  evalEE[0] = evale;
400  evalEE[1] = ietaix;
401  evalEE[2] = iphiiy;
402  evalEE[3] = (ePS1 + ePS2) * invE;
403  evalEE[4] = reducedHits;
404  }
405 
406  //these are the actual BDT responses
407  double rawmean = 1;
408  double rawsigma = 0;
409 
410  if (iseb) {
411  rawmean = meanforest.GetResponse(evalEB.data());
412  rawsigma = sigmaforest.GetResponse(evalEB.data());
413  } else {
414  rawmean = meanforest.GetResponse(evalEE.data());
415  rawsigma = sigmaforest.GetResponse(evalEE.data());
416  }
417 
418  //apply transformation to limited output range (matching the training)
419  //the training was done with different transformations for EB and EE (width only)
420  //makes a the code a bit more cumbersome, but it is not a problem per se
421  double mean = iseb ? meanoffsetEB_ + meanscaleEB_ * vdt::fast_sin(rawmean)
422  : meanoffsetEE_ + meanscaleEE_ * vdt::fast_sin(rawmean);
423  double sigma = iseb ? sigmaoffsetEB_ + sigmascaleEB_ * vdt::fast_sin(rawsigma)
424  : sigmaoffsetEE_ + sigmascaleEE_ * vdt::fast_sin(rawsigma);
425 
426  //regression target is ln(Etrue/Eraw)
427  //so corrected energy is ecor=exp(mean)*e, uncertainty is exp(mean)*eraw*sigma=ecor*sigma
428  double ecor = iseb ? vdt::fast_exp(mean) * e : vdt::fast_exp(mean) * (e + ePS1 + ePS2);
429  double sigmacor = sigma * ecor;
430 
431  LogDebug("PFClusterEMEnergyCorrector")
432  << "ieta : iphi : ietamod20 : iphimod20 : size : reducedHits = " << ietaix << " " << iphiiy << " " << ietamod20
433  << " " << iphimod20 << " " << size << " " << reducedHits << "\n"
434  << "isEB : eraw : ePS1 : ePS2 : (eps1+eps2)/raw : Flag = " << iseb << " " << evale << " " << ePS1 << " " << ePS2
435  << " " << (ePS1 + ePS2) / evale << " " << clusFlag << "\n"
436  << "response : correction = " << exp(mean) << " " << ecor;
437 
438  cluster.setCorrectedEnergy(ecor);
440  cluster.setCorrectedEnergyUncertainty(sigmacor);
441  else
442  cluster.setCorrectedEnergyUncertainty(0.);
443  }
444 }
size
Write out results.
std::vector< edm::ESGetToken< GBRForestD, GBRDWrapperRcd > > forestMeanTokens_50ns_
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:42
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:219
int ix() const
Definition: EEDetId.h:77
std::vector< T >::const_iterator const_iterator
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:526
PFLayer::Layer layer() const
cluster layer, see PFLayer.h in this directory
Definition: PFCluster.cc:56
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_
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_
ESData get(edm::EventSetup const &eventSetup) const
std::vector< std::string > condnames_mean_25ns_
void setCorrectedEnergy(double cenergy)
Definition: CaloCluster.h:137
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
double energy() const
cluster energy
Definition: PFCluster.h:74
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const EcalReadoutTools::ESGetTokens ecalReadoutToolsESGetTokens_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
double pt() const
transverse momentum, massless approximation
Definition: PFCluster.h:108
double GetResponse(const float *vector) const
Definition: GBRForestD.h:49
const_iterator end() const
edm::EDGetTokenT< EcalRecHitCollection > recHitsEB_
bool isValid() const
Definition: HandleBase.h:70
iterator find(key_type k)
std::vector< edm::ESGetToken< GBRForestD, GBRDWrapperRcd > > forestSigmaTokens_50ns_
edm::EDGetTokenT< EBSrFlagCollection > ebSrFlagToken_
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_
#define LogDebug(id)

◆ getAssociatedPSEnergy()

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

Definition at line 446 of file PFClusterEMEnergyCorrector.cc.

References trackingPlots::assoc, StorageManager_cfg::e1, reco::PFCluster::energy(), reco::PFCluster::layer(), PFLayer::PS1, PFLayer::PS2, and sortByKey().

Referenced by correctEnergies().

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

◆ operator=()

PFClusterEMEnergyCorrector& PFClusterEMEnergyCorrector::operator= ( const PFClusterEMEnergyCorrector )
delete

Member Data Documentation

◆ applyCrackCorrections_

bool PFClusterEMEnergyCorrector::applyCrackCorrections_
private

Definition at line 62 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ applyMVACorrections_

bool PFClusterEMEnergyCorrector::applyMVACorrections_
private

Definition at line 63 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ autoDetectBunchSpacing_

bool PFClusterEMEnergyCorrector::autoDetectBunchSpacing_
private

Definition at line 66 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ bunchSpacing_

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

Definition at line 48 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ bunchSpacingManual_

int PFClusterEMEnergyCorrector::bunchSpacingManual_
private

Definition at line 67 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ calibrator_

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

Definition at line 69 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ condnames_mean_

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

Definition at line 53 of file PFClusterEMEnergyCorrector.h.

◆ condnames_mean_25ns_

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

Definition at line 56 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ condnames_mean_50ns_

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

Definition at line 58 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ condnames_sigma_

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

Definition at line 54 of file PFClusterEMEnergyCorrector.h.

◆ condnames_sigma_25ns_

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

Definition at line 57 of file PFClusterEMEnergyCorrector.h.

◆ condnames_sigma_50ns_

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

Definition at line 59 of file PFClusterEMEnergyCorrector.h.

◆ ebSrFlagToken_

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

Definition at line 42 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ ecalClusterToolsESGetTokens_

const EcalClusterLazyTools::ESGetTokens PFClusterEMEnergyCorrector::ecalClusterToolsESGetTokens_
private

Definition at line 50 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ ecalReadoutToolsESGetTokens_

const EcalReadoutTools::ESGetTokens PFClusterEMEnergyCorrector::ecalReadoutToolsESGetTokens_
private

Definition at line 51 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ eeSrFlagToken_

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

Definition at line 43 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ forestMeanTokens_25ns_

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

Definition at line 96 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ forestMeanTokens_50ns_

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

Definition at line 98 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ forestSigmaTokens_25ns_

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

Definition at line 97 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ forestSigmaTokens_50ns_

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

Definition at line 99 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ maxPtForMVAEvaluation_

double PFClusterEMEnergyCorrector::maxPtForMVAEvaluation_
private

Definition at line 40 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ meanlimhighEB_

double PFClusterEMEnergyCorrector::meanlimhighEB_
private

Definition at line 76 of file PFClusterEMEnergyCorrector.h.

◆ meanlimhighEE_

double PFClusterEMEnergyCorrector::meanlimhighEE_
private

Definition at line 81 of file PFClusterEMEnergyCorrector.h.

◆ meanlimlowEB_

double PFClusterEMEnergyCorrector::meanlimlowEB_
private

Definition at line 75 of file PFClusterEMEnergyCorrector.h.

◆ meanlimlowEE_

double PFClusterEMEnergyCorrector::meanlimlowEE_
private

Definition at line 80 of file PFClusterEMEnergyCorrector.h.

◆ meanoffsetEB_

double PFClusterEMEnergyCorrector::meanoffsetEB_
private

Definition at line 77 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ meanoffsetEE_

double PFClusterEMEnergyCorrector::meanoffsetEE_
private

Definition at line 82 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ meanscaleEB_

double PFClusterEMEnergyCorrector::meanscaleEB_
private

Definition at line 78 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ meanscaleEE_

double PFClusterEMEnergyCorrector::meanscaleEE_
private

Definition at line 83 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ recHitsEB_

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

Definition at line 46 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ recHitsEE_

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

Definition at line 47 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ setEnergyUncertainty_

bool PFClusterEMEnergyCorrector::setEnergyUncertainty_
private

Definition at line 64 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ sigmalimhighEB_

double PFClusterEMEnergyCorrector::sigmalimhighEB_
private

Definition at line 86 of file PFClusterEMEnergyCorrector.h.

◆ sigmalimhighEE_

double PFClusterEMEnergyCorrector::sigmalimhighEE_
private

Definition at line 91 of file PFClusterEMEnergyCorrector.h.

◆ sigmalimlowEB_

double PFClusterEMEnergyCorrector::sigmalimlowEB_
private

Definition at line 85 of file PFClusterEMEnergyCorrector.h.

◆ sigmalimlowEE_

double PFClusterEMEnergyCorrector::sigmalimlowEE_
private

Definition at line 90 of file PFClusterEMEnergyCorrector.h.

◆ sigmaoffsetEB_

double PFClusterEMEnergyCorrector::sigmaoffsetEB_
private

Definition at line 87 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ sigmaoffsetEE_

double PFClusterEMEnergyCorrector::sigmaoffsetEE_
private

Definition at line 92 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ sigmascaleEB_

double PFClusterEMEnergyCorrector::sigmascaleEB_
private

Definition at line 88 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ sigmascaleEE_

double PFClusterEMEnergyCorrector::sigmascaleEE_
private

Definition at line 93 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().

◆ srfAwareCorrection_

bool PFClusterEMEnergyCorrector::srfAwareCorrection_
private

Definition at line 61 of file PFClusterEMEnergyCorrector.h.

Referenced by correctEnergies().