CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Attributes
EGRegressionModifierV2 Class Reference
Inheritance diagram for EGRegressionModifierV2:
ModifyObjectValueBase

Classes

struct  CondNames
 

Public Member Functions

 EGRegressionModifierV2 (const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
 
void modifyObject (reco::GsfElectron &) const final
 
void modifyObject (reco::Photon &) const final
 
void modifyObject (pat::Electron &ele) const final
 
void modifyObject (pat::Photon &pho) const final
 
void setEvent (const edm::Event &) final
 
void setEventContent (const edm::EventSetup &) final
 
- Public Member Functions inherited from ModifyObjectValueBase
virtual void modifyObject (reco::Muon &) const
 
virtual void modifyObject (reco::BaseTau &) const
 
virtual void modifyObject (reco::Jet &) const
 
virtual void modifyObject (pat::Muon &) const
 
virtual void modifyObject (pat::Tau &) const
 
virtual void modifyObject (pat::Jet &) const
 
 ModifyObjectValueBase (const edm::ParameterSet &conf)
 
const std::string & name () const
 
virtual ~ModifyObjectValueBase ()
 

Private Attributes

CondNames eleCondNames_
 
std::vector< const GBRForestD * > eleForestsMean_
 
std::vector< const GBRForestD * > eleForestsSigma_
 
const double eOverPEcalTrkThr_
 
const double epDiffSigEcalTrackThr_
 
const double epSigEcalTrackThr_
 
const bool forceHighEnergyEcalTrainingIfSaturated_
 
const double highEnergyEcalTrackThr_
 
const edm::EventSetupiSetup_
 
const double lowEnergyEcalOnlyThr_
 
const double lowEnergyEcalTrackThr_
 
CondNames phoCondNames_
 
std::vector< const GBRForestD * > phoForestsMean_
 
std::vector< const GBRForestD * > phoForestsSigma_
 
edm::EDGetTokenT< double > rhoToken_
 
float rhoValue_
 

Detailed Description

Definition at line 16 of file EGRegressionModifierV2.cc.

Constructor & Destructor Documentation

EGRegressionModifierV2::EGRegressionModifierV2 ( const edm::ParameterSet conf,
edm::ConsumesCollector cc 
)

Definition at line 62 of file EGRegressionModifierV2.cc.

References eleCondNames_, nano_cff::electrons, eleForestsMean_, eleForestsSigma_, edm::ParameterSet::getParameter(), EGRegressionModifierV2::CondNames::mean, phoCondNames_, phoForestsMean_, phoForestsSigma_, and nano_cff::photons.

63  : ModifyObjectValueBase(conf)
64  , rhoToken_(cc.consumes<double>(conf.getParameter<edm::InputTag>("rhoCollection")))
65  , lowEnergyEcalOnlyThr_(conf.getParameter<double>("lowEnergy_ECALonlyThr"))
66  , lowEnergyEcalTrackThr_(conf.getParameter<double>("lowEnergy_ECALTRKThr"))
67  , highEnergyEcalTrackThr_(conf.getParameter<double>("highEnergy_ECALTRKThr"))
68  , eOverPEcalTrkThr_(conf.getParameter<double>("eOverP_ECALTRKThr"))
69  , epDiffSigEcalTrackThr_(conf.getParameter<double>("epDiffSig_ECALTRKThr"))
70  , epSigEcalTrackThr_(conf.getParameter<double>("epSig_ECALTRKThr"))
71  , forceHighEnergyEcalTrainingIfSaturated_(conf.getParameter<bool>("forceHighEnergyEcalTrainingIfSaturated"))
72 {
73  const edm::ParameterSet& electrons = conf.getParameter<edm::ParameterSet>("electron_config");
74  eleCondNames_ = CondNames {
75  .mean = electrons.getParameter<std::vector<std::string> >("regressionKey"),
76  .sigma = electrons.getParameter<std::vector<std::string> >("uncertaintyKey"),
77  };
78 
79  unsigned int encor = eleCondNames_.mean.size();
80  eleForestsMean_.reserve(2*encor);
81  eleForestsSigma_.reserve(2*encor);
82 
83  const edm::ParameterSet& photons = conf.getParameter<edm::ParameterSet>("photon_config");
84  phoCondNames_ = CondNames {
85  .mean = photons.getParameter<std::vector<std::string> >("regressionKey"),
86  .sigma = photons.getParameter<std::vector<std::string> >("uncertaintyKey"),
87  };
88 
89  unsigned int ncor = phoCondNames_.mean.size();
90  phoForestsMean_.reserve(ncor);
91  phoForestsSigma_.reserve(ncor);
92 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
std::vector< const GBRForestD * > phoForestsSigma_
std::vector< const GBRForestD * > phoForestsMean_
ModifyObjectValueBase(const edm::ParameterSet &conf)
const bool forceHighEnergyEcalTrainingIfSaturated_
edm::EDGetTokenT< double > rhoToken_
std::vector< const GBRForestD * > eleForestsMean_
std::vector< const GBRForestD * > eleForestsSigma_

Member Function Documentation

void EGRegressionModifierV2::modifyObject ( reco::GsfElectron ele) const
finalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 112 of file EGRegressionModifierV2.cc.

References funct::abs(), constexpr, reco::GsfElectron::correctMomentum(), reco::deltaPhi(), DetId::det(), reco::GsfElectron::ShowerShape::e5x5, reco::GsfElectron::ecalDrivenSeed(), eleForestsMean_, eleForestsSigma_, eOverPEcalTrkThr_, epDiffSigEcalTrackThr_, epSigEcalTrackThr_, reco::CaloCluster::eta(), reco::GsfElectron::fbrem(), forceHighEnergyEcalTrainingIfSaturated_, reco::GsfElectron::full5x5_showerShape(), edm::EventSetup::get(), reco::GsfElectron::gsfTrack(), reco::GsfElectron::hcalOverEcalBc(), highEnergyEcalTrackThr_, edm::Ref< C, T, F >::isAvailable(), reco::GsfElectron::isEB(), iSetup_, EcalTools::isHGCalDet(), CastorSimpleRecAlgoImpl::isSaturated(), egammaTools::localEcalClusterCoordsEB(), egammaTools::localEcalClusterCoordsEE(), lowEnergyEcalOnlyThr_, lowEnergyEcalTrackThr_, SiStripPI::max, SiStripPI::mean, reco::GsfElectron::nSaturatedXtals(), reco::GsfElectron::p4(), reco::CaloCluster::phi(), jets_cff::rawPt, mathSSE::return(), rhoValue_, reco::CaloCluster::seed(), SurveyInfoScenario_cff::seed, reco::GsfElectron::setCorrectedEcalEnergy(), reco::GsfElectron::setCorrectedEcalEnergyError(), mathSSE::sqrt(), reco::GsfElectron::superCluster(), reco::GsfElectron::ClassificationVariables::trackFbrem, and reco::GsfElectron::trackMomentumError().

112  {
113 
114  // regression calculation needs no additional valuemaps
115 
116  const reco::SuperClusterRef& superClus = ele.superCluster();
117  const edm::Ptr<reco::CaloCluster>& seed = superClus->seed();
118 
119  // skip HGCAL for now
120  if( EcalTools::isHGCalDet(seed->seed().det()) ) return;
121 
122  const int numberOfClusters = superClus->clusters().size();
123  const bool missing_clusters = !superClus->clusters()[numberOfClusters-1].isAvailable();
124  if( missing_clusters ) return ; // do not apply corrections in case of missing info (slimmed MiniAOD electrons)
125 
126  //check if fbrem is filled as its needed for E/p combination so abort if its set to the default value
127  //this will be the case for <5 (or current cuts) for miniAOD electrons
129 
130  const bool isEB = ele.isEB();
131 
132  std::array<float, 32> eval;
133  const double rawEnergy = superClus->rawEnergy();
134  const double raw_es_energy = superClus->preshowerEnergy();
135  const auto& full5x5_ess = ele.full5x5_showerShape();
136 
137  float e5x5Inverse = full5x5_ess.e5x5 != 0. ? vdt::fast_inv(full5x5_ess.e5x5) : 0.;
138 
139  eval[0] = rawEnergy;
140  eval[1] = superClus->etaWidth();
141  eval[2] = superClus->phiWidth();
142  eval[3] = superClus->seed()->energy()/rawEnergy;
143  eval[4] = full5x5_ess.e5x5/rawEnergy;
144  eval[5] = ele.hcalOverEcalBc();
145  eval[6] = rhoValue_;
146  eval[7] = seed->eta() - superClus->position().Eta();
147  eval[8] = reco::deltaPhi( seed->phi(),superClus->position().Phi());
148  eval[9] = full5x5_ess.r9;
149  eval[10] = full5x5_ess.sigmaIetaIeta;
150  eval[11] = full5x5_ess.sigmaIetaIphi;
151  eval[12] = full5x5_ess.sigmaIphiIphi;
152  eval[13] = full5x5_ess.eMax*e5x5Inverse;
153  eval[14] = full5x5_ess.e2nd*e5x5Inverse;
154  eval[15] = full5x5_ess.eTop*e5x5Inverse;
155  eval[16] = full5x5_ess.eBottom*e5x5Inverse;
156  eval[17] = full5x5_ess.eLeft*e5x5Inverse;
157  eval[18] = full5x5_ess.eRight*e5x5Inverse;
158  eval[19] = full5x5_ess.e2x5Max*e5x5Inverse;
159  eval[20] = full5x5_ess.e2x5Left*e5x5Inverse;
160  eval[21] = full5x5_ess.e2x5Right*e5x5Inverse;
161  eval[22] = full5x5_ess.e2x5Top*e5x5Inverse;
162  eval[23] = full5x5_ess.e2x5Bottom*e5x5Inverse;
163  eval[24] = ele.nSaturatedXtals();
164  eval[25] = std::max(0,numberOfClusters);
165 
166  // calculate coordinate variables
167  edm::ESHandle<CaloGeometry> caloGeometry;
168  iSetup_->get<CaloGeometryRecord>().get(caloGeometry);
169  if (isEB) {
170 
171  float dummy;
172  int ieta;
173  int iphi;
174  egammaTools::localEcalClusterCoordsEB(*seed, *caloGeometry, dummy, dummy, ieta, iphi, dummy, dummy);
175  eval[26] = ieta;
176  eval[27] = iphi;
177  int signieta = ieta > 0 ? +1 : -1;
178  eval[28] = (ieta-signieta)%5;
179  eval[29] = (iphi-1)%2;
180  eval[30] = (abs(ieta)<=25)*((ieta-signieta)) + (abs(ieta)>25)*((ieta-26*signieta)%20);
181  eval[31] = (iphi-1)%20;
182 
183  } else {
184 
185  float dummy;
186  int ix;
187  int iy;
188  egammaTools::localEcalClusterCoordsEE(*seed, *caloGeometry, dummy, dummy, ix, iy, dummy, dummy);
189  eval[26] = ix;
190  eval[27] = iy;
191  eval[28] = raw_es_energy/rawEnergy;
192 
193  }
194 
195  //magic numbers for MINUIT-like transformation of BDT output onto limited range
196  //(These should be stored inside the conditions object in the future as well)
197  constexpr double meanlimlow = -1.0;
198  constexpr double meanlimhigh = 3.0;
199  constexpr double meanoffset = meanlimlow + 0.5*(meanlimhigh-meanlimlow);
200  constexpr double meanscale = 0.5*(meanlimhigh-meanlimlow);
201 
202  constexpr double sigmalimlow = 0.0002;
203  constexpr double sigmalimhigh = 0.5;
204  constexpr double sigmaoffset = sigmalimlow + 0.5*(sigmalimhigh-sigmalimlow);
205  constexpr double sigmascale = 0.5*(sigmalimhigh-sigmalimlow);
206 
207 
208  size_t coridx = 0;
209  float rawPt = rawEnergy*superClus->position().rho()/superClus->position().r();
210  bool isSaturated = ele.nSaturatedXtals()!=0;
211 
212  if(rawPt >= lowEnergyEcalOnlyThr_ ||
213  (isSaturated && forceHighEnergyEcalTrainingIfSaturated_)){
214  if(isEB) coridx = 1;
215  else coridx = 3;
216  }else{
217  if(isEB) coridx = 0;
218  else coridx = 2;
219  }
220 
221 
222  //these are the actual BDT responses
223  double rawmean = eleForestsMean_[coridx]->GetResponse(eval.data());
224  double rawsigma = eleForestsSigma_[coridx]->GetResponse(eval.data());
225 
226  //apply transformation to limited output range (matching the training)
227  double mean = meanoffset + meanscale*vdt::fast_sin(rawmean);
228  double sigma = sigmaoffset + sigmascale*vdt::fast_sin(rawsigma);
229 
230  // Correct the energy. A negative energy means that the correction went
231  // outside the boundaries of the training. In this case uses raw.
232  // The resolution estimation, on the other hand should be ok.
233  if (mean < 0.) mean = 1.0;
234 
235  const double ecor = mean*(rawEnergy + raw_es_energy);
236  const double sigmacor = sigma*ecor;
237 
238  ele.setCorrectedEcalEnergy(ecor);
239  ele.setCorrectedEcalEnergyError(sigmacor);
240 
241  double combinedEnergy = ecor;
242  double combinedEnergyError = sigmacor;
243 
244  auto el_track = ele.gsfTrack();
245  const float trkMomentum = el_track->pMode();
246  const float trkEta = el_track->etaMode();
247  const float trkPhi = el_track->phiMode();
248  const float trkMomentumError = std::abs(el_track->qoverpModeError())*trkMomentum*trkMomentum;
249 
250  const float eOverP = (rawEnergy+raw_es_energy)*mean/trkMomentum;
251  const float fbrem = ele.fbrem();
252 
253  // E-p combination
254  if (ecor < highEnergyEcalTrackThr_ &&
255  eOverP > eOverPEcalTrkThr_ &&
256  std::abs(ecor - trkMomentum) < epDiffSigEcalTrackThr_*std::sqrt(trkMomentumError*trkMomentumError+sigmacor*sigmacor) &&
257  trkMomentumError < epSigEcalTrackThr_*trkMomentum) {
258 
259  rawPt = ecor/cosh(trkEta);
260  if (isEB && rawPt < lowEnergyEcalTrackThr_)
261  coridx = 4;
262  else if (isEB && rawPt >= lowEnergyEcalTrackThr_)
263  coridx = 5;
264  else if (!isEB && rawPt < lowEnergyEcalTrackThr_)
265  coridx = 6;
266  else if (!isEB && rawPt >= lowEnergyEcalTrackThr_)
267  coridx = 7;
268 
269  eval[0] = ecor;
270  eval[1] = sigma/mean;
271  eval[2] = trkMomentumError/trkMomentum;
272  eval[3] = eOverP;
273  eval[4] = ele.ecalDrivenSeed();
274  eval[5] = full5x5_ess.r9;
275  eval[6] = fbrem;
276  eval[7] = trkEta;
277  eval[8] = trkPhi;
278 
279  float ecalEnergyVar = (rawEnergy + raw_es_energy)*sigma;
280  float rawcombNormalization = (trkMomentumError*trkMomentumError + ecalEnergyVar*ecalEnergyVar);
281  float rawcomb = ( ecor*trkMomentumError*trkMomentumError + trkMomentum*ecalEnergyVar*ecalEnergyVar ) / rawcombNormalization;
282 
283  //these are the actual BDT responses
284  double rawmean_trk = eleForestsMean_[coridx]->GetResponse(eval.data());
285  double rawsigma_trk = eleForestsSigma_[coridx]->GetResponse(eval.data());
286 
287  //apply transformation to limited output range (matching the training)
288  double mean_trk = meanoffset + meanscale*vdt::fast_sin(rawmean_trk);
289  double sigma_trk = sigmaoffset + sigmascale*vdt::fast_sin(rawsigma_trk);
290 
291  // Final correction
292  // A negative energy means that the correction went
293  // outside the boundaries of the training. In this case uses raw.
294  // The resolution estimation, on the other hand should be ok.
295  if (mean_trk < 0.) mean_trk = 1.0;
296 
297  combinedEnergy = mean_trk*rawcomb;
298  combinedEnergyError = sigma_trk*rawcomb;
299  }
300 
301  math::XYZTLorentzVector oldFourMomentum = ele.p4();
302  math::XYZTLorentzVector newFourMomentum( oldFourMomentum.x()*combinedEnergy/oldFourMomentum.t(),
303  oldFourMomentum.y()*combinedEnergy/oldFourMomentum.t(),
304  oldFourMomentum.z()*combinedEnergy/oldFourMomentum.t(),
305  combinedEnergy );
306 
307  ele.correctMomentum(newFourMomentum, ele.trackMomentumError(), combinedEnergyError);
308 }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
bool isAvailable() const
Definition: Ref.h:575
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
Definition: GsfElectron.h:186
static bool isHGCalDet(DetId::Detector thedet)
identify HGCal cells
Definition: EcalTools.h:54
void localEcalClusterCoordsEB(const reco::CaloCluster &bclus, const CaloGeometry &geom, float &etacry, float &phicry, int &ieta, int &iphi, float &thetatilt, float &phitilt)
float nSaturatedXtals() const
Definition: GsfElectron.h:520
float trackMomentumError() const
Definition: GsfElectron.h:846
const LorentzVector & p4(P4Kind kind) const
Definition: GsfElectron.cc:225
const edm::EventSetup * iSetup_
void correctMomentum(const LorentzVector &p4, float trackMomentumError, float p4Error)
Definition: GsfElectron.h:868
float fbrem() const
Definition: GsfElectron.h:771
bool isEB() const
Definition: GsfElectron.h:356
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:168
return((rh^lh)&mask)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
void setCorrectedEcalEnergyError(float newEnergyError)
Definition: GsfElectron.cc:179
T sqrt(T t)
Definition: SSEVec.h:18
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void localEcalClusterCoordsEE(const reco::CaloCluster &bclus, const CaloGeometry &geom, float &xcry, float &ycry, int &ix, int &iy, float &thetatilt, float &phitilt)
float hcalOverEcalBc() const
Definition: GsfElectron.h:452
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:207
const bool forceHighEnergyEcalTrainingIfSaturated_
void setCorrectedEcalEnergy(float newEnergy)
Definition: GsfElectron.cc:182
bool isSaturated(const Digi &digi, const int &maxADCvalue, int ifirst, int n)
const ShowerShape & full5x5_showerShape() const
Definition: GsfElectron.h:483
T get() const
Definition: EventSetup.h:71
SuperClusterRef superCluster() const override
reference to a SuperCluster
Definition: GsfElectron.h:185
double phi() const
azimuthal angle of cluster centroid
Definition: CaloCluster.h:171
std::vector< const GBRForestD * > eleForestsMean_
std::vector< const GBRForestD * > eleForestsSigma_
#define constexpr
bool ecalDrivenSeed() const
Definition: GsfElectron.h:188
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39
void EGRegressionModifierV2::modifyObject ( reco::Photon pho) const
finalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 310 of file EGRegressionModifierV2.cc.

References funct::abs(), constexpr, reco::deltaPhi(), DetId::det(), reco::Photon::ShowerShape::e5x5, reco::CaloCluster::eta(), forceHighEnergyEcalTrainingIfSaturated_, reco::Photon::full5x5_r9(), reco::Photon::full5x5_showerShapeVariables(), edm::EventSetup::get(), reco::Photon::hadronicOverEm(), edm::Ref< C, T, F >::isAvailable(), reco::Photon::isEB(), iSetup_, EcalTools::isHGCalDet(), CastorSimpleRecAlgoImpl::isSaturated(), egammaTools::localEcalClusterCoordsEB(), egammaTools::localEcalClusterCoordsEE(), lowEnergyEcalOnlyThr_, SiStripPI::max, SiStripPI::mean, reco::Photon::nSaturatedXtals(), reco::CaloCluster::phi(), phoForestsMean_, phoForestsSigma_, jets_cff::rawPt, mathSSE::return(), rhoValue_, reco::CaloCluster::seed(), SurveyInfoScenario_cff::seed, reco::Photon::setCorrectedEnergy(), and reco::Photon::superCluster().

310  {
311  // regression calculation needs no additional valuemaps
312 
313  const reco::SuperClusterRef& superClus = pho.superCluster();
314  const edm::Ptr<reco::CaloCluster>& seed = superClus->seed();
315 
316  // skip HGCAL for now
317  if( EcalTools::isHGCalDet(seed->seed().det()) ) return;
318 
319  const int numberOfClusters = superClus->clusters().size();
320  const bool missing_clusters = !superClus->clusters()[numberOfClusters-1].isAvailable();
321  if( missing_clusters ) return ; // do not apply corrections in case of missing info (slimmed MiniAOD electrons)
322 
323  const bool isEB = pho.isEB();
324 
325  std::array<float, 32> eval;
326  const double rawEnergy = superClus->rawEnergy();
327  const double raw_es_energy = superClus->preshowerEnergy();
328  const auto& full5x5_pss = pho.full5x5_showerShapeVariables();
329 
330  float e5x5Inverse = full5x5_pss.e5x5 != 0. ? vdt::fast_inv(full5x5_pss.e5x5) : 0.;
331 
332  eval[0] = rawEnergy;
333  eval[1] = superClus->etaWidth();
334  eval[2] = superClus->phiWidth();
335  eval[3] = superClus->seed()->energy()/rawEnergy;
336  eval[4] = full5x5_pss.e5x5/rawEnergy;
337  eval[5] = pho.hadronicOverEm();
338  eval[6] = rhoValue_;
339  eval[7] = seed->eta() - superClus->position().Eta();
340  eval[8] = reco::deltaPhi( seed->phi(),superClus->position().Phi());
341  eval[9] = pho.full5x5_r9();
342  eval[10] = full5x5_pss.sigmaIetaIeta;
343  eval[11] = full5x5_pss.sigmaIetaIphi;
344  eval[12] = full5x5_pss.sigmaIphiIphi;
345  eval[13] = full5x5_pss.maxEnergyXtal*e5x5Inverse;
346  eval[14] = full5x5_pss.e2nd*e5x5Inverse;
347  eval[15] = full5x5_pss.eTop*e5x5Inverse;
348  eval[16] = full5x5_pss.eBottom*e5x5Inverse;
349  eval[17] = full5x5_pss.eLeft*e5x5Inverse;
350  eval[18] = full5x5_pss.eRight*e5x5Inverse;
351  eval[19] = full5x5_pss.e2x5Max*e5x5Inverse;
352  eval[20] = full5x5_pss.e2x5Left*e5x5Inverse;
353  eval[21] = full5x5_pss.e2x5Right*e5x5Inverse;
354  eval[22] = full5x5_pss.e2x5Top*e5x5Inverse;
355  eval[23] = full5x5_pss.e2x5Bottom*e5x5Inverse;
356  eval[24] = pho.nSaturatedXtals();
357  eval[25] = std::max(0,numberOfClusters);
358 
359  // calculate coordinate variables
360  edm::ESHandle<CaloGeometry> caloGeometry;
361  iSetup_->get<CaloGeometryRecord>().get(caloGeometry);
362 
363  if (isEB) {
364 
365  float dummy;
366  int ieta;
367  int iphi;
368  egammaTools::localEcalClusterCoordsEB(*seed, *caloGeometry, dummy, dummy, ieta, iphi, dummy, dummy);
369  eval[26] = ieta;
370  eval[27] = iphi;
371  int signieta = ieta > 0 ? +1 : -1;
372  eval[28] = (ieta-signieta)%5;
373  eval[29] = (iphi-1)%2;
374  eval[30] = (abs(ieta)<=25)*((ieta-signieta)) + (abs(ieta)>25)*((ieta-26*signieta)%20);
375  eval[31] = (iphi-1)%20;
376 
377  } else {
378 
379  float dummy;
380  int ix;
381  int iy;
382  egammaTools::localEcalClusterCoordsEE(*seed, *caloGeometry, dummy, dummy, ix, iy, dummy, dummy);
383  eval[26] = ix;
384  eval[27] = iy;
385  eval[28] = raw_es_energy/rawEnergy;
386 
387  }
388 
389  //magic numbers for MINUIT-like transformation of BDT output onto limited range
390  //(These should be stored inside the conditions object in the future as well)
391  constexpr double meanlimlow = -1.0;
392  constexpr double meanlimhigh = 3.0;
393  constexpr double meanoffset = meanlimlow + 0.5*(meanlimhigh-meanlimlow);
394  constexpr double meanscale = 0.5*(meanlimhigh-meanlimlow);
395 
396  constexpr double sigmalimlow = 0.0002;
397  constexpr double sigmalimhigh = 0.5;
398  constexpr double sigmaoffset = sigmalimlow + 0.5*(sigmalimhigh-sigmalimlow);
399  constexpr double sigmascale = 0.5*(sigmalimhigh-sigmalimlow);
400 
401  size_t coridx = 0;
402  float rawPt = rawEnergy*superClus->position().rho()/superClus->position().r();
403  bool isSaturated = pho.nSaturatedXtals();
404 
405  if(rawPt >= lowEnergyEcalOnlyThr_ ||
406  (isSaturated && forceHighEnergyEcalTrainingIfSaturated_)){
407  if(isEB) coridx = 1;
408  else coridx = 3;
409  }else{
410  if(isEB) coridx = 0;
411  else coridx = 2;
412  }
413 
414  //these are the actual BDT responses
415  double rawmean = phoForestsMean_[coridx]->GetResponse(eval.data());
416  double rawsigma = phoForestsSigma_[coridx]->GetResponse(eval.data());
417 
418  //apply transformation to limited output range (matching the training)
419  double mean = meanoffset + meanscale*vdt::fast_sin(rawmean);
420  double sigma = sigmaoffset + sigmascale*vdt::fast_sin(rawsigma);
421 
422  // Correct the energy. A negative energy means that the correction went
423  // outside the boundaries of the training. In this case uses raw.
424  // The resolution estimation, on the other hand should be ok.
425  if (mean < 0.) mean = 1.0;
426 
427  const double ecor = mean*(rawEnergy + raw_es_energy);
428  const double sigmacor = sigma*ecor;
429 
430  pho.setCorrectedEnergy(reco::Photon::P4type::regression2, ecor, sigmacor, true);
431 }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
bool isAvailable() const
Definition: Ref.h:575
static bool isHGCalDet(DetId::Detector thedet)
identify HGCal cells
Definition: EcalTools.h:54
void localEcalClusterCoordsEB(const reco::CaloCluster &bclus, const CaloGeometry &geom, float &etacry, float &phicry, int &ieta, int &iphi, float &thetatilt, float &phitilt)
void setCorrectedEnergy(P4type type, float E, float dE, bool toCand=true)
const edm::EventSetup * iSetup_
reco::SuperClusterRef superCluster() const override
Ref to SuperCluster.
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:168
return((rh^lh)&mask)
std::vector< const GBRForestD * > phoForestsSigma_
float full5x5_r9() const
Definition: Photon.h:252
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< const GBRForestD * > phoForestsMean_
void localEcalClusterCoordsEE(const reco::CaloCluster &bclus, const CaloGeometry &geom, float &xcry, float &ycry, int &ix, int &iy, float &thetatilt, float &phitilt)
float hadronicOverEm() const
the total hadronic over electromagnetic fraction
Definition: Photon.h:212
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:207
const bool forceHighEnergyEcalTrainingIfSaturated_
bool isEB() const
Definition: Photon.h:121
bool isSaturated(const Digi &digi, const int &maxADCvalue, int ifirst, int n)
const ShowerShape & full5x5_showerShapeVariables() const
Definition: Photon.h:206
T get() const
Definition: EventSetup.h:71
double phi() const
azimuthal angle of cluster centroid
Definition: CaloCluster.h:171
float nSaturatedXtals() const
Definition: Photon.h:266
#define constexpr
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39
void EGRegressionModifierV2::modifyObject ( pat::Electron ele) const
inlinefinalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 28 of file EGRegressionModifierV2.cc.

References modifyObject().

Referenced by modifyObject().

28 { modifyObject(static_cast<reco::GsfElectron&>(ele)); }
void modifyObject(reco::GsfElectron &) const final
void EGRegressionModifierV2::modifyObject ( pat::Photon pho) const
inlinefinalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 29 of file EGRegressionModifierV2.cc.

References modifyObject().

Referenced by modifyObject().

29 { modifyObject(static_cast<reco::Photon&>(pho)); }
void modifyObject(reco::GsfElectron &) const final
void EGRegressionModifierV2::setEvent ( const edm::Event evt)
finalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 94 of file EGRegressionModifierV2.cc.

References edm::Event::getByToken(), rhoToken_, and rhoValue_.

95 {
97  evt.getByToken(rhoToken_, rhoH);
98  rhoValue_ = *rhoH;
99 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
edm::EDGetTokenT< double > rhoToken_
void EGRegressionModifierV2::setEventContent ( const edm::EventSetup evs)
finalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 101 of file EGRegressionModifierV2.cc.

References eleCondNames_, eleForestsMean_, eleForestsSigma_, iSetup_, EGRegressionModifierV2::CondNames::mean, phoCondNames_, phoForestsMean_, phoForestsSigma_, retrieveGBRForests(), and EGRegressionModifierV2::CondNames::sigma.

102 {
103  iSetup_ = &evs;
104 
107 
110 }
const edm::EventSetup * iSetup_
std::vector< const GBRForestD * > phoForestsSigma_
std::vector< const GBRForestD * > retrieveGBRForests(edm::EventSetup const &evs, std::vector< std::string > const &names)
std::vector< const GBRForestD * > phoForestsMean_
std::vector< const GBRForestD * > eleForestsMean_
std::vector< const GBRForestD * > eleForestsSigma_

Member Data Documentation

CondNames EGRegressionModifierV2::eleCondNames_
private

Definition at line 37 of file EGRegressionModifierV2.cc.

Referenced by EGRegressionModifierV2(), and setEventContent().

std::vector<const GBRForestD*> EGRegressionModifierV2::eleForestsMean_
private

Definition at line 47 of file EGRegressionModifierV2.cc.

Referenced by EGRegressionModifierV2(), modifyObject(), and setEventContent().

std::vector<const GBRForestD*> EGRegressionModifierV2::eleForestsSigma_
private

Definition at line 48 of file EGRegressionModifierV2.cc.

Referenced by EGRegressionModifierV2(), modifyObject(), and setEventContent().

const double EGRegressionModifierV2::eOverPEcalTrkThr_
private

Definition at line 53 of file EGRegressionModifierV2.cc.

Referenced by modifyObject().

const double EGRegressionModifierV2::epDiffSigEcalTrackThr_
private

Definition at line 54 of file EGRegressionModifierV2.cc.

Referenced by modifyObject().

const double EGRegressionModifierV2::epSigEcalTrackThr_
private

Definition at line 55 of file EGRegressionModifierV2.cc.

Referenced by modifyObject().

const bool EGRegressionModifierV2::forceHighEnergyEcalTrainingIfSaturated_
private

Definition at line 56 of file EGRegressionModifierV2.cc.

Referenced by modifyObject().

const double EGRegressionModifierV2::highEnergyEcalTrackThr_
private

Definition at line 52 of file EGRegressionModifierV2.cc.

Referenced by modifyObject().

const edm::EventSetup* EGRegressionModifierV2::iSetup_
private

Definition at line 43 of file EGRegressionModifierV2.cc.

Referenced by modifyObject(), and setEventContent().

const double EGRegressionModifierV2::lowEnergyEcalOnlyThr_
private

Definition at line 50 of file EGRegressionModifierV2.cc.

Referenced by modifyObject().

const double EGRegressionModifierV2::lowEnergyEcalTrackThr_
private

Definition at line 51 of file EGRegressionModifierV2.cc.

Referenced by modifyObject().

CondNames EGRegressionModifierV2::phoCondNames_
private

Definition at line 38 of file EGRegressionModifierV2.cc.

Referenced by EGRegressionModifierV2(), and setEventContent().

std::vector<const GBRForestD*> EGRegressionModifierV2::phoForestsMean_
private

Definition at line 45 of file EGRegressionModifierV2.cc.

Referenced by EGRegressionModifierV2(), modifyObject(), and setEventContent().

std::vector<const GBRForestD*> EGRegressionModifierV2::phoForestsSigma_
private

Definition at line 46 of file EGRegressionModifierV2.cc.

Referenced by EGRegressionModifierV2(), modifyObject(), and setEventContent().

edm::EDGetTokenT<double> EGRegressionModifierV2::rhoToken_
private

Definition at line 41 of file EGRegressionModifierV2.cc.

Referenced by setEvent().

float EGRegressionModifierV2::rhoValue_
private

Definition at line 40 of file EGRegressionModifierV2.cc.

Referenced by modifyObject(), and setEvent().