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

edm::ESHandle< CaloGeometrycaloGeometry_
 
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 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 61 of file EGRegressionModifierV2.cc.

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

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

References funct::abs(), caloGeometry_, 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(), reco::GsfElectron::gsfTrack(), reco::GsfElectron::hcalOverEcalBc(), highEnergyEcalTrackThr_, edm::Ref< C, T, F >::isAvailable(), reco::GsfElectron::isEB(), 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().

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

References funct::abs(), caloGeometry_, constexpr, reco::deltaPhi(), DetId::det(), reco::Photon::ShowerShape::e5x5, reco::CaloCluster::eta(), forceHighEnergyEcalTrainingIfSaturated_, reco::Photon::full5x5_r9(), reco::Photon::full5x5_showerShapeVariables(), reco::Photon::hadronicOverEm(), edm::Ref< C, T, F >::isAvailable(), reco::Photon::isEB(), 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().

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

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

94 {
96  evt.getByToken(rhoToken_, rhoH);
97  rhoValue_ = *rhoH;
98 }
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 100 of file EGRegressionModifierV2.cc.

References caloGeometry_, eleCondNames_, eleForestsMean_, eleForestsSigma_, edm::EventSetup::get(), EGRegressionModifierV2::CondNames::mean, phoCondNames_, phoForestsMean_, phoForestsSigma_, retrieveGBRForests(), and EGRegressionModifierV2::CondNames::sigma.

101 {
104 
107 
109 }
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_
edm::ESHandle< CaloGeometry > caloGeometry_
T get() const
Definition: EventSetup.h:71
std::vector< const GBRForestD * > eleForestsMean_
std::vector< const GBRForestD * > eleForestsSigma_

Member Data Documentation

edm::ESHandle<CaloGeometry> EGRegressionModifierV2::caloGeometry_
private

Definition at line 42 of file EGRegressionModifierV2.cc.

Referenced by modifyObject(), and setEventContent().

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 46 of file EGRegressionModifierV2.cc.

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

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

Definition at line 47 of file EGRegressionModifierV2.cc.

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

const double EGRegressionModifierV2::eOverPEcalTrkThr_
private

Definition at line 52 of file EGRegressionModifierV2.cc.

Referenced by modifyObject().

const double EGRegressionModifierV2::epDiffSigEcalTrackThr_
private

Definition at line 53 of file EGRegressionModifierV2.cc.

Referenced by modifyObject().

const double EGRegressionModifierV2::epSigEcalTrackThr_
private

Definition at line 54 of file EGRegressionModifierV2.cc.

Referenced by modifyObject().

const bool EGRegressionModifierV2::forceHighEnergyEcalTrainingIfSaturated_
private

Definition at line 55 of file EGRegressionModifierV2.cc.

Referenced by modifyObject().

const double EGRegressionModifierV2::highEnergyEcalTrackThr_
private

Definition at line 51 of file EGRegressionModifierV2.cc.

Referenced by modifyObject().

const double EGRegressionModifierV2::lowEnergyEcalOnlyThr_
private

Definition at line 49 of file EGRegressionModifierV2.cc.

Referenced by modifyObject().

const double EGRegressionModifierV2::lowEnergyEcalTrackThr_
private

Definition at line 50 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 44 of file EGRegressionModifierV2.cc.

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

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

Definition at line 45 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().