From 3ce8e61a3285cbbf52e0f3910dba30b0de07912d Mon Sep 17 00:00:00 2001 From: crovelli Date: Thu, 16 Jul 2020 08:24:59 +0200 Subject: [PATCH 1/7] Extra variables for LowPtElectrons Id added --- .../plugins/LowPtGsfElectronIDProducer.cc | 405 ++++++++++++++---- 1 file changed, 313 insertions(+), 92 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc index 7a87bd26f0a42..b6ba26c61fc5b 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc @@ -11,119 +11,323 @@ #include "DataFormats/EgammaReco/interface/SuperCluster.h" #include "DataFormats/GsfTrackReco/interface/GsfTrack.h" #include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/Math/interface/LorentzVector.h" #include "FWCore/Framework/interface/Event.h" +#include "CommonTools/BaseParticlePropagator/interface/BaseParticlePropagator.h" +#include #include #include namespace { - std::vector getFeatures(reco::GsfElectronRef const& ele, float rho) { - // KF track - float trk_p = -1.; - float trk_nhits = -1.; - float trk_chi2red = -1.; - // GSF track - float gsf_nhits = -1.; - float gsf_chi2red = -1.; - // SC - float sc_E = -1.; - float sc_eta = -1.; - float sc_etaWidth = -1.; - float sc_phiWidth = -1.; - // Track-cluster matching - float match_seed_dEta = -1.; - float match_eclu_EoverP = -1.; - float match_SC_EoverP = -1.; - float match_SC_dEta = -1.; - float match_SC_dPhi = -1.; - // Shower shape vars - float shape_full5x5_sigmaIetaIeta = -1.; - float shape_full5x5_sigmaIphiIphi = -1.; - float shape_full5x5_HoverE = -1.; - float shape_full5x5_r9 = -1.; - float shape_full5x5_circularity = -1.; - // Misc - float brem_frac = -1.; - float ele_pt = -1.; - - // KF tracks - if (ele->core().isNonnull()) { - reco::TrackRef trk = ele->core()->ctfTrack(); //@@ is this what we want?! - if (trk.isNonnull()) { - trk_p = float(trk->p()); - trk_nhits = float(trk->found()); - trk_chi2red = float(trk->normalizedChi2()); + std::vector getFeatures(reco::GsfElectronRef const& ele, float rho, float unbiased) { + + float eid_rho = -999.; + float eid_sc_eta = -999.; + float eid_shape_full5x5_r9 = -999.; + float eid_sc_etaWidth = -999.; + float eid_sc_phiWidth = -999.; + float eid_shape_full5x5_HoverE = -999.; + float eid_trk_nhits = -999.; + float eid_trk_chi2red = -999.; + float eid_gsf_chi2red = -999.; + float eid_brem_frac = -999.; + float eid_gsf_nhits = -999.; + float eid_match_SC_EoverP = -999.; + float eid_match_eclu_EoverP = -999.; + float eid_match_SC_dEta = -999.; + float eid_match_SC_dPhi = -999.; + float eid_match_seed_dEta = -999.; + float eid_sc_E = -999.; + float eid_trk_p = -999.; + float gsf_mode_p = -999.; + float core_shFracHits = -999.; + float gsf_bdtout1 = -999.; + float gsf_dr = -999.; + float trk_dr = -999.; + float sc_Nclus = -999.; + float sc_clus1_nxtal = -999.; + float sc_clus1_dphi = -999.; + float sc_clus2_dphi = -999.; + float sc_clus1_deta = -999.; + float sc_clus2_deta = -999.; + float sc_clus1_E = -999.; + float sc_clus2_E = -999.; + float sc_clus1_E_ov_p = -999.; + float sc_clus2_E_ov_p = -999.; + + // KF tracks + if ( ele->core().isNonnull() ) { + reco::TrackRef trk = ele->closestCtfTrackRef(); + if ( trk.isNonnull() ) { + eid_trk_p = (float)trk->p(); + eid_trk_nhits = (float)trk->found(); + eid_trk_chi2red = (float)trk->normalizedChi2(); + TVector3 trkTV3(0,0,0); + trkTV3.SetPtEtaPhi(trk->pt(), trk->eta(), trk->phi()); + TVector3 eleTV3(0,0,0); + eleTV3.SetPtEtaPhi(ele->pt(), ele->eta(), ele->phi()); + trk_dr = eleTV3.DeltaR(trkTV3); } } - // GSF tracks - if (ele->core().isNonnull()) { + // GSF tracks + if ( ele->core().isNonnull() ) { reco::GsfTrackRef gsf = ele->core()->gsfTrack(); - if (gsf.isNonnull()) { - gsf_nhits = gsf->found(); - gsf_chi2red = gsf->normalizedChi2(); + if ( gsf.isNonnull() ) { + gsf_mode_p = gsf->pMode(); + eid_gsf_nhits = (float)gsf->found(); + eid_gsf_chi2red = gsf->normalizedChi2(); + TVector3 gsfTV3(0,0,0); + gsfTV3.SetPtEtaPhi(gsf->ptMode(), gsf->etaMode(), gsf->phiMode()); + TVector3 eleTV3(0,0,0); + eleTV3.SetPtEtaPhi(ele->pt(), ele->eta(), ele->phi()); + gsf_dr = eleTV3.DeltaR(gsfTV3); } } - // Super clusters - if (ele->core().isNonnull()) { + // Super clusters + if ( ele->core().isNonnull() ) { reco::SuperClusterRef sc = ele->core()->superCluster(); - if (sc.isNonnull()) { - sc_E = sc->energy(); - sc_eta = sc->eta(); - sc_etaWidth = sc->etaWidth(); - sc_phiWidth = sc->phiWidth(); + if ( sc.isNonnull() ) { + eid_sc_E = sc->energy(); + eid_sc_eta = sc->eta(); + eid_sc_etaWidth = sc->etaWidth(); + eid_sc_phiWidth = sc->phiWidth(); + sc_Nclus = sc->clustersSize(); } } - // Track-cluster matching - if (ele.isNonnull()) { - match_seed_dEta = ele->deltaEtaSeedClusterTrackAtCalo(); - match_eclu_EoverP = (1. / ele->ecalEnergy()) - (1. / ele->p()); - match_SC_EoverP = ele->eSuperClusterOverP(); - match_SC_dEta = ele->deltaEtaSuperClusterTrackAtVtx(); - match_SC_dPhi = ele->deltaPhiSuperClusterTrackAtVtx(); - } + // Track-cluster matching + if ( ele.isNonnull() ) { + eid_match_seed_dEta = ele->deltaEtaSeedClusterTrackAtCalo(); + eid_match_eclu_EoverP = (1./ele->ecalEnergy()) - (1./ele->p()); + eid_match_SC_EoverP = ele->eSuperClusterOverP(); + eid_match_SC_dEta = ele->deltaEtaSuperClusterTrackAtVtx(); + eid_match_SC_dPhi = ele->deltaPhiSuperClusterTrackAtVtx(); + } - // Shower shape vars - if (ele.isNonnull()) { - shape_full5x5_sigmaIetaIeta = ele->full5x5_sigmaIetaIeta(); - shape_full5x5_sigmaIphiIphi = ele->full5x5_sigmaIphiIphi(); - shape_full5x5_HoverE = ele->full5x5_hcalOverEcal(); - shape_full5x5_r9 = ele->full5x5_r9(); - shape_full5x5_circularity = 1. - ele->full5x5_e1x5() / ele->full5x5_e5x5(); + // Shower shape vars + if ( ele.isNonnull() ) { + eid_shape_full5x5_HoverE = ele->full5x5_hcalOverEcal(); + eid_shape_full5x5_r9 = ele->full5x5_r9(); } // Misc - if (ele.isNonnull()) { - brem_frac = ele->fbrem(); - ele_pt = ele->pt(); + eid_rho = rho; + + if ( ele.isNonnull() ) { + eid_brem_frac = ele->fbrem(); + core_shFracHits = ele->shFracInnerHits(); } + + // Unbiased BDT from ElectronSeed + gsf_bdtout1 = unbiased; + + // Clusters + if ( ele->core().isNonnull() ) { + reco::GsfTrackRef gsf = ele->core()->gsfTrack(); + if ( gsf.isNonnull() ) { + reco::SuperClusterRef sc = ele->core()->superCluster(); + if ( sc.isNonnull() ) { + + // Propagate electron track to ECAL surface + double mass_ = 0.000511*0.000511; + float p2=pow( gsf->p() ,2 ); + float energy = sqrt(mass_ + p2); + math::XYZTLorentzVector mom = math::XYZTLorentzVector(gsf->px(), gsf->py(), gsf->pz(), energy); + math::XYZTLorentzVector pos = math::XYZTLorentzVector(gsf->vx(), gsf->vy(), gsf->vz(), 0.); + float field_z=3.8; + BaseParticlePropagator mypart(RawParticle(mom, pos, gsf->charge()), 0, 0, field_z); + mypart.propagateToEcalEntrance(true); // true only first half loop , false more than one loop + bool reach_ECAL = mypart.getSuccess(); // 0 does not reach ECAL, 1 yes barrel, 2 yes endcaps + + // ECAL entry point for track + GlobalPoint ecal_pos(mypart.particle().vertex().x(), mypart.particle().vertex().y(), mypart.particle().vertex().z()); + + // Iterate through ECAL clusters and sort in energy + int clusNum=0; + float maxEne1=-1; + float maxEne2=-1; + int i1=-1; + int i2=-1; + try{ + if(sc->clustersSize()>0 && sc->clustersBegin()!=sc->clustersEnd()){ + for(auto& cluster : sc->clusters()) { + if (cluster->energy() > maxEne1){ + maxEne1=cluster->energy(); + i1=clusNum; + } + clusNum++; + } + if(sc->clustersSize()>1){ + clusNum=0; + for(auto& cluster : sc->clusters()) { + if (clusNum!=i1) { + if (cluster->energy() > maxEne2){ + maxEne2=cluster->energy(); + i2=clusNum; + } + } + clusNum++; + } + } + } // loop over clusters + } catch(...) { + std::cout<<"exception caught clusNum="<clustersSize()<<" energy="<< sc->energy()<clustersSize()>0&& sc->clustersBegin()!=sc->clustersEnd()){ + for(auto& cluster : sc->clusters()) { + double pi_=3.1415926535; + float deta = std::fabs(ecal_pos.eta()-cluster->eta()) ; + float dphi = std::fabs(ecal_pos.phi()-cluster->phi()); + if (dphi > pi_) dphi -= 2 * pi_; + if (ecal_pos.phi()-cluster->phi()<0) dphi=-dphi; + if (ecal_pos.eta()-cluster->eta()<0) deta=-deta; + + if (clusNum==i1) { + sc_clus1_E = cluster->energy(); + if(gsf->pMode()>0) sc_clus1_E_ov_p = cluster->energy()/gsf->pMode(); + sc_clus1_nxtal = (int)cluster->size(); + if (reach_ECAL>0){ + sc_clus1_deta = deta; + sc_clus1_dphi = dphi; + } + } else if (clusNum==i2) { + sc_clus2_E = cluster->energy(); + if(gsf->pMode()>0) sc_clus2_E_ov_p = cluster->energy()/gsf->pMode(); + if (reach_ECAL>0){ + sc_clus2_deta = deta; + sc_clus2_dphi = dphi; + } + } + clusNum++; + } + } + } catch(...) { + std::cout<<"caught an exception"<100) eid_rho=100; + if (eid_sc_eta<-5) eid_sc_eta=-5; + if (eid_sc_eta>5) eid_sc_eta=5; + if (eid_shape_full5x5_r9<0) eid_shape_full5x5_r9=0; + if (eid_shape_full5x5_r9>2) eid_shape_full5x5_r9=2; + if (eid_sc_etaWidth<0) eid_sc_etaWidth=0; + if (eid_sc_etaWidth>3.14) eid_sc_etaWidth=3.14; + if (eid_sc_phiWidth<0) eid_sc_phiWidth=0; + if (eid_sc_phiWidth>3.14) eid_sc_phiWidth=3.14; + if (eid_shape_full5x5_HoverE<0) eid_shape_full5x5_HoverE=0; + if (eid_shape_full5x5_HoverE>50) eid_shape_full5x5_HoverE=50; + if (eid_trk_nhits<-1) eid_trk_nhits=-1; + if (eid_trk_nhits>50) eid_trk_nhits=50; + if (eid_trk_chi2red<-1) eid_trk_chi2red=-1; + if (eid_trk_chi2red>50) eid_trk_chi2red=50; + if (eid_gsf_chi2red<-1) eid_gsf_chi2red=-1; + if (eid_gsf_chi2red>100) eid_gsf_chi2red=100; + if (eid_brem_frac<0) eid_brem_frac=-1; + if (eid_brem_frac>1) eid_brem_frac=1; + if (eid_gsf_nhits<-1) eid_gsf_nhits=-1; + if (eid_gsf_nhits>50) eid_gsf_nhits=50; + if (eid_match_SC_EoverP<0) eid_match_SC_EoverP=0; + if (eid_match_SC_EoverP>100) eid_match_SC_EoverP=100; + if (eid_match_eclu_EoverP<-0.001) eid_match_eclu_EoverP=-0.001; + if (eid_match_eclu_EoverP>0.001) eid_match_eclu_EoverP=0.001; + eid_match_eclu_EoverP=eid_match_eclu_EoverP*1.E7; + if (eid_match_SC_dEta<-10) eid_match_SC_dEta=-10; + if (eid_match_SC_dEta>10) eid_match_SC_dEta=10; + if (eid_match_SC_dPhi<-3.14) eid_match_SC_dPhi=-3.14; + if (eid_match_SC_dPhi>3.14) eid_match_SC_dPhi=3.14; + if (eid_match_seed_dEta<-10) eid_match_seed_dEta=-10; + if (eid_match_seed_dEta>10) eid_match_seed_dEta=10; + if (eid_sc_E<0) eid_sc_E=0; + if (eid_sc_E>1000) eid_sc_E=1000; + if (eid_trk_p<-1) eid_trk_p=-1; + if (eid_trk_p>1000) eid_trk_p=1000; + if (gsf_mode_p<0) gsf_mode_p=0; + if (gsf_mode_p>1000) gsf_mode_p=1000; + if (core_shFracHits<0) core_shFracHits=0; + if (core_shFracHits>1) core_shFracHits=1; + if (gsf_bdtout1<-20) gsf_bdtout1=-20; + if (gsf_bdtout1>20) gsf_bdtout1=20; + if (gsf_dr<0) gsf_dr=5; + if (gsf_dr>5) gsf_dr=5; + if (trk_dr<0) trk_dr=5; + if (trk_dr>5) trk_dr=5; + if (sc_Nclus<0) sc_Nclus=0; + if (sc_Nclus>20) sc_Nclus=20; + if (sc_clus1_nxtal<0) sc_clus1_nxtal=0; + if (sc_clus1_nxtal>100) sc_clus1_nxtal=100; + if (sc_clus1_dphi<-3.14) sc_clus1_dphi=-5; + if (sc_clus1_dphi>3.14) sc_clus1_dphi=5; + if (sc_clus2_dphi<-3.14) sc_clus2_dphi=-5; + if (sc_clus2_dphi>3.14) sc_clus2_dphi=5; + if (sc_clus1_deta<-5) sc_clus1_deta=-5; + if (sc_clus1_deta>5) sc_clus1_deta=5; + if (sc_clus2_deta<-5) sc_clus2_deta=-5; + if (sc_clus2_deta>5) sc_clus2_deta=5; + if (sc_clus1_E<0) sc_clus1_E=0; + if (sc_clus1_E>1000) sc_clus1_E=1000; + if (sc_clus2_E<0) sc_clus2_E=0; + if (sc_clus2_E>1000) sc_clus2_E=1000; + if (sc_clus1_E_ov_p<0) sc_clus1_E_ov_p=-1; + if (sc_clus2_E_ov_p<0) sc_clus2_E_ov_p=-1; return { - rho, - ele_pt, - sc_eta, - shape_full5x5_sigmaIetaIeta, - shape_full5x5_sigmaIphiIphi, - shape_full5x5_circularity, - shape_full5x5_r9, - sc_etaWidth, - sc_phiWidth, - shape_full5x5_HoverE, - trk_nhits, - trk_chi2red, - gsf_chi2red, - brem_frac, - gsf_nhits, - match_SC_EoverP, - match_eclu_EoverP, - match_SC_dEta, - match_SC_dPhi, - match_seed_dEta, - sc_E, - trk_p, + eid_rho, + eid_sc_eta, + eid_shape_full5x5_r9, + eid_sc_etaWidth, + eid_sc_phiWidth, + eid_shape_full5x5_HoverE, + eid_trk_nhits, + eid_trk_chi2red, + eid_gsf_chi2red, + eid_brem_frac, + eid_gsf_nhits, + eid_match_SC_EoverP, + eid_match_eclu_EoverP, + eid_match_SC_dEta, + eid_match_SC_dPhi, + eid_match_seed_dEta, + eid_sc_E, + eid_trk_p, + gsf_mode_p, + core_shFracHits, + gsf_bdtout1, + gsf_dr, + trk_dr, + sc_Nclus, + sc_clus1_nxtal, + sc_clus1_dphi, + sc_clus2_dphi, + sc_clus1_deta, + sc_clus2_deta, + sc_clus1_E, + sc_clus2_E, + sc_clus1_E_ov_p, + sc_clus2_E_ov_p }; } @@ -138,10 +342,11 @@ class LowPtGsfElectronIDProducer final : public edm::global::EDProducer<> { static void fillDescriptions(edm::ConfigurationDescriptions&); private: - double eval(const std::string& name, const reco::GsfElectronRef&, double rho) const; + double eval(const std::string& name, const reco::GsfElectronRef&, double rho, float unbiased) const; const edm::EDGetTokenT gsfElectrons_; const edm::EDGetTokenT rho_; + const edm::EDGetTokenT< edm::ValueMap > unbiased_; const std::vector names_; const bool passThrough_; const double minPtThreshold_; @@ -155,6 +360,7 @@ class LowPtGsfElectronIDProducer final : public edm::global::EDProducer<> { LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer(const edm::ParameterSet& conf) : gsfElectrons_(consumes(conf.getParameter("electrons"))), rho_(consumes(conf.getParameter("rho"))), + unbiased_(consumes< edm::ValueMap >(conf.getParameter("unbiased"))), names_(conf.getParameter >("ModelNames")), passThrough_(conf.getParameter("PassThrough")), minPtThreshold_(conf.getParameter("MinPtThreshold")), @@ -179,6 +385,7 @@ LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer(const edm::ParameterSet& //////////////////////////////////////////////////////////////////////////////// // void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const edm::EventSetup& setup) const { + // Pileup edm::Handle rho; event.getByToken(rho_, rho); @@ -193,6 +400,13 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const edm::LogError("Problem with gsfElectrons handle"); } + // ElectronSeed unbiased BDT + edm::Handle< edm::ValueMap > unbiasedH; + event.getByToken(unbiased_,unbiasedH); + if (!unbiasedH.isValid()) { + edm::LogError("Problem with unbiased handle"); + } + // Iterate through Electrons, evaluate BDT, and store result std::vector > output; for (unsigned int iname = 0; iname < names_.size(); ++iname) { @@ -200,9 +414,15 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const } for (unsigned int iele = 0; iele < gsfElectrons->size(); iele++) { reco::GsfElectronRef ele(gsfElectrons, iele); + + if ( ele->core().isNull() ) { continue; } + reco::GsfTrackRef gsf = ele->core()->gsfTrack(); + if ( gsf.isNull() ) { continue; } + float unbiased = (*unbiasedH)[gsf]; + //if ( !passThrough_ && ( ele->pt() < minPtThreshold_ ) ) { continue; } for (unsigned int iname = 0; iname < names_.size(); ++iname) { - output[iname][iele] = eval(names_[iname], ele, *rho); + output[iname][iele] = eval(names_[iname], ele, *rho, unbiased); } } @@ -217,11 +437,11 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const } } -double LowPtGsfElectronIDProducer::eval(const std::string& name, const reco::GsfElectronRef& ele, double rho) const { +double LowPtGsfElectronIDProducer::eval(const std::string& name, const reco::GsfElectronRef& ele, double rho, float unbiased) const { auto iter = std::find(names_.begin(), names_.end(), name); if (iter != names_.end()) { int index = std::distance(names_.begin(), iter); - std::vector inputs = getFeatures(ele, rho); + std::vector inputs = getFeatures(ele, rho, unbiased); return models_.at(index)->GetResponse(inputs.data()); } else { throw cms::Exception("Unknown model name") << "'Name given: '" << name << "'. Check against configuration file.\n"; @@ -234,6 +454,7 @@ double LowPtGsfElectronIDProducer::eval(const std::string& name, const reco::Gsf void LowPtGsfElectronIDProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; desc.add("electrons", edm::InputTag("lowPtGsfElectrons")); + desc.add("unbiased",edm::InputTag("lowPtGsfElectronSeedValueMaps:unbiased")); desc.add("rho", edm::InputTag("fixedGridRhoFastjetAllTmp")); desc.add >("ModelNames", {""}); desc.add >( From c8a9fc89024bff1eb1bb5969e7f9857aaaf51a8c Mon Sep 17 00:00:00 2001 From: bainbrid Date: Fri, 17 Jul 2020 14:17:05 +0200 Subject: [PATCH 2/7] reverse-engineer move of APIs for model features --- .../EgammaElectronProducers/BuildFile.xml | 11 + .../interface/LowPtGsfElectronFeatures.h | 34 ++ .../plugins/BuildFile.xml | 1 + .../plugins/LowPtGsfElectronIDProducer.cc | 323 +----------- .../LowPtGsfElectronSeedHeavyObjectCache.cc | 101 +--- .../LowPtGsfElectronSeedHeavyObjectCache.h | 36 -- .../src/LowPtGsfElectronFeatures.cc | 461 ++++++++++++++++++ 7 files changed, 515 insertions(+), 452 deletions(-) create mode 100644 RecoEgamma/EgammaElectronProducers/BuildFile.xml create mode 100644 RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h create mode 100644 RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc diff --git a/RecoEgamma/EgammaElectronProducers/BuildFile.xml b/RecoEgamma/EgammaElectronProducers/BuildFile.xml new file mode 100644 index 0000000000000..4ac99e1cbc67e --- /dev/null +++ b/RecoEgamma/EgammaElectronProducers/BuildFile.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h b/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h new file mode 100644 index 0000000000000..81536678bffb0 --- /dev/null +++ b/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h @@ -0,0 +1,34 @@ +#ifndef RecoEgamma_EgammaElectronProducers_LowPtGsfElectronFeatures_h +#define RecoEgamma_EgammaElectronProducers_LowPtGsfElectronFeatures_h + +#include "DataFormats/Common/interface/Ptr.h" +#include "DataFormats/Common/interface/Ref.h" +#include "DataFormats/Common/interface/RefToPtr.h" +#include "DataFormats/Common/interface/View.h" +#include "DataFormats/EgammaCandidates/interface/GsfElectron.h" +#include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h" +#include + +namespace reco { + class BeamSpot; + class PreId; +} // namespace reco + +namespace lowptgsfeleseed { + + std::vector features( const reco::PreId& ecal, const reco::PreId& hcal, double rho, + const reco::BeamSpot& spot, noZS::EcalClusterLazyTools& ecalTools ); + +} + +namespace lowptgsfeleid { + + std::vector features( edm::Ptr const& ele, float rho, float unbiased ); + + std::vector features( edm::Ref< std::vector > const& ele, float rho, float unbiased ); + + std::vector features( edm::Ref< edm::View > const& ele, float rho, float unbiased ); + +} // namespace + +#endif // RecoEgamma_EgammaElectronProducers_LowPtGsfElectronFeatures_h diff --git a/RecoEgamma/EgammaElectronProducers/plugins/BuildFile.xml b/RecoEgamma/EgammaElectronProducers/plugins/BuildFile.xml index 86fd2663b26b9..dd6603c1f6a81 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/BuildFile.xml +++ b/RecoEgamma/EgammaElectronProducers/plugins/BuildFile.xml @@ -20,6 +20,7 @@ + diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc index b6ba26c61fc5b..23cc93b18b4a0 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc @@ -1,3 +1,4 @@ +#include "CommonTools/BaseParticlePropagator/interface/BaseParticlePropagator.h" #include "DataFormats/Common/interface/Handle.h" #include "DataFormats/Common/interface/ValueMap.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" @@ -13,326 +14,12 @@ #include "DataFormats/TrackReco/interface/Track.h" #include "DataFormats/Math/interface/LorentzVector.h" #include "FWCore/Framework/interface/Event.h" -#include "CommonTools/BaseParticlePropagator/interface/BaseParticlePropagator.h" -#include - +#include "RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h" #include #include -namespace { - - std::vector getFeatures(reco::GsfElectronRef const& ele, float rho, float unbiased) { - - float eid_rho = -999.; - float eid_sc_eta = -999.; - float eid_shape_full5x5_r9 = -999.; - float eid_sc_etaWidth = -999.; - float eid_sc_phiWidth = -999.; - float eid_shape_full5x5_HoverE = -999.; - float eid_trk_nhits = -999.; - float eid_trk_chi2red = -999.; - float eid_gsf_chi2red = -999.; - float eid_brem_frac = -999.; - float eid_gsf_nhits = -999.; - float eid_match_SC_EoverP = -999.; - float eid_match_eclu_EoverP = -999.; - float eid_match_SC_dEta = -999.; - float eid_match_SC_dPhi = -999.; - float eid_match_seed_dEta = -999.; - float eid_sc_E = -999.; - float eid_trk_p = -999.; - float gsf_mode_p = -999.; - float core_shFracHits = -999.; - float gsf_bdtout1 = -999.; - float gsf_dr = -999.; - float trk_dr = -999.; - float sc_Nclus = -999.; - float sc_clus1_nxtal = -999.; - float sc_clus1_dphi = -999.; - float sc_clus2_dphi = -999.; - float sc_clus1_deta = -999.; - float sc_clus2_deta = -999.; - float sc_clus1_E = -999.; - float sc_clus2_E = -999.; - float sc_clus1_E_ov_p = -999.; - float sc_clus2_E_ov_p = -999.; - - // KF tracks - if ( ele->core().isNonnull() ) { - reco::TrackRef trk = ele->closestCtfTrackRef(); - if ( trk.isNonnull() ) { - eid_trk_p = (float)trk->p(); - eid_trk_nhits = (float)trk->found(); - eid_trk_chi2red = (float)trk->normalizedChi2(); - TVector3 trkTV3(0,0,0); - trkTV3.SetPtEtaPhi(trk->pt(), trk->eta(), trk->phi()); - TVector3 eleTV3(0,0,0); - eleTV3.SetPtEtaPhi(ele->pt(), ele->eta(), ele->phi()); - trk_dr = eleTV3.DeltaR(trkTV3); - } - } - - // GSF tracks - if ( ele->core().isNonnull() ) { - reco::GsfTrackRef gsf = ele->core()->gsfTrack(); - if ( gsf.isNonnull() ) { - gsf_mode_p = gsf->pMode(); - eid_gsf_nhits = (float)gsf->found(); - eid_gsf_chi2red = gsf->normalizedChi2(); - TVector3 gsfTV3(0,0,0); - gsfTV3.SetPtEtaPhi(gsf->ptMode(), gsf->etaMode(), gsf->phiMode()); - TVector3 eleTV3(0,0,0); - eleTV3.SetPtEtaPhi(ele->pt(), ele->eta(), ele->phi()); - gsf_dr = eleTV3.DeltaR(gsfTV3); - } - } - - // Super clusters - if ( ele->core().isNonnull() ) { - reco::SuperClusterRef sc = ele->core()->superCluster(); - if ( sc.isNonnull() ) { - eid_sc_E = sc->energy(); - eid_sc_eta = sc->eta(); - eid_sc_etaWidth = sc->etaWidth(); - eid_sc_phiWidth = sc->phiWidth(); - sc_Nclus = sc->clustersSize(); - } - } - - // Track-cluster matching - if ( ele.isNonnull() ) { - eid_match_seed_dEta = ele->deltaEtaSeedClusterTrackAtCalo(); - eid_match_eclu_EoverP = (1./ele->ecalEnergy()) - (1./ele->p()); - eid_match_SC_EoverP = ele->eSuperClusterOverP(); - eid_match_SC_dEta = ele->deltaEtaSuperClusterTrackAtVtx(); - eid_match_SC_dPhi = ele->deltaPhiSuperClusterTrackAtVtx(); - } - - // Shower shape vars - if ( ele.isNonnull() ) { - eid_shape_full5x5_HoverE = ele->full5x5_hcalOverEcal(); - eid_shape_full5x5_r9 = ele->full5x5_r9(); - } - - // Misc - eid_rho = rho; - - if ( ele.isNonnull() ) { - eid_brem_frac = ele->fbrem(); - core_shFracHits = ele->shFracInnerHits(); - } - - // Unbiased BDT from ElectronSeed - gsf_bdtout1 = unbiased; - - // Clusters - if ( ele->core().isNonnull() ) { - reco::GsfTrackRef gsf = ele->core()->gsfTrack(); - if ( gsf.isNonnull() ) { - reco::SuperClusterRef sc = ele->core()->superCluster(); - if ( sc.isNonnull() ) { - - // Propagate electron track to ECAL surface - double mass_ = 0.000511*0.000511; - float p2=pow( gsf->p() ,2 ); - float energy = sqrt(mass_ + p2); - math::XYZTLorentzVector mom = math::XYZTLorentzVector(gsf->px(), gsf->py(), gsf->pz(), energy); - math::XYZTLorentzVector pos = math::XYZTLorentzVector(gsf->vx(), gsf->vy(), gsf->vz(), 0.); - float field_z=3.8; - BaseParticlePropagator mypart(RawParticle(mom, pos, gsf->charge()), 0, 0, field_z); - mypart.propagateToEcalEntrance(true); // true only first half loop , false more than one loop - bool reach_ECAL = mypart.getSuccess(); // 0 does not reach ECAL, 1 yes barrel, 2 yes endcaps - - // ECAL entry point for track - GlobalPoint ecal_pos(mypart.particle().vertex().x(), mypart.particle().vertex().y(), mypart.particle().vertex().z()); - - // Iterate through ECAL clusters and sort in energy - int clusNum=0; - float maxEne1=-1; - float maxEne2=-1; - int i1=-1; - int i2=-1; - try{ - if(sc->clustersSize()>0 && sc->clustersBegin()!=sc->clustersEnd()){ - for(auto& cluster : sc->clusters()) { - if (cluster->energy() > maxEne1){ - maxEne1=cluster->energy(); - i1=clusNum; - } - clusNum++; - } - if(sc->clustersSize()>1){ - clusNum=0; - for(auto& cluster : sc->clusters()) { - if (clusNum!=i1) { - if (cluster->energy() > maxEne2){ - maxEne2=cluster->energy(); - i2=clusNum; - } - } - clusNum++; - } - } - } // loop over clusters - } catch(...) { - std::cout<<"exception caught clusNum="<clustersSize()<<" energy="<< sc->energy()<clustersSize()>0&& sc->clustersBegin()!=sc->clustersEnd()){ - for(auto& cluster : sc->clusters()) { - double pi_=3.1415926535; - float deta = std::fabs(ecal_pos.eta()-cluster->eta()) ; - float dphi = std::fabs(ecal_pos.phi()-cluster->phi()); - if (dphi > pi_) dphi -= 2 * pi_; - if (ecal_pos.phi()-cluster->phi()<0) dphi=-dphi; - if (ecal_pos.eta()-cluster->eta()<0) deta=-deta; - - if (clusNum==i1) { - sc_clus1_E = cluster->energy(); - if(gsf->pMode()>0) sc_clus1_E_ov_p = cluster->energy()/gsf->pMode(); - sc_clus1_nxtal = (int)cluster->size(); - if (reach_ECAL>0){ - sc_clus1_deta = deta; - sc_clus1_dphi = dphi; - } - } else if (clusNum==i2) { - sc_clus2_E = cluster->energy(); - if(gsf->pMode()>0) sc_clus2_E_ov_p = cluster->energy()/gsf->pMode(); - if (reach_ECAL>0){ - sc_clus2_deta = deta; - sc_clus2_dphi = dphi; - } - } - clusNum++; - } - } - } catch(...) { - std::cout<<"caught an exception"<100) eid_rho=100; - if (eid_sc_eta<-5) eid_sc_eta=-5; - if (eid_sc_eta>5) eid_sc_eta=5; - if (eid_shape_full5x5_r9<0) eid_shape_full5x5_r9=0; - if (eid_shape_full5x5_r9>2) eid_shape_full5x5_r9=2; - if (eid_sc_etaWidth<0) eid_sc_etaWidth=0; - if (eid_sc_etaWidth>3.14) eid_sc_etaWidth=3.14; - if (eid_sc_phiWidth<0) eid_sc_phiWidth=0; - if (eid_sc_phiWidth>3.14) eid_sc_phiWidth=3.14; - if (eid_shape_full5x5_HoverE<0) eid_shape_full5x5_HoverE=0; - if (eid_shape_full5x5_HoverE>50) eid_shape_full5x5_HoverE=50; - if (eid_trk_nhits<-1) eid_trk_nhits=-1; - if (eid_trk_nhits>50) eid_trk_nhits=50; - if (eid_trk_chi2red<-1) eid_trk_chi2red=-1; - if (eid_trk_chi2red>50) eid_trk_chi2red=50; - if (eid_gsf_chi2red<-1) eid_gsf_chi2red=-1; - if (eid_gsf_chi2red>100) eid_gsf_chi2red=100; - if (eid_brem_frac<0) eid_brem_frac=-1; - if (eid_brem_frac>1) eid_brem_frac=1; - if (eid_gsf_nhits<-1) eid_gsf_nhits=-1; - if (eid_gsf_nhits>50) eid_gsf_nhits=50; - if (eid_match_SC_EoverP<0) eid_match_SC_EoverP=0; - if (eid_match_SC_EoverP>100) eid_match_SC_EoverP=100; - if (eid_match_eclu_EoverP<-0.001) eid_match_eclu_EoverP=-0.001; - if (eid_match_eclu_EoverP>0.001) eid_match_eclu_EoverP=0.001; - eid_match_eclu_EoverP=eid_match_eclu_EoverP*1.E7; - if (eid_match_SC_dEta<-10) eid_match_SC_dEta=-10; - if (eid_match_SC_dEta>10) eid_match_SC_dEta=10; - if (eid_match_SC_dPhi<-3.14) eid_match_SC_dPhi=-3.14; - if (eid_match_SC_dPhi>3.14) eid_match_SC_dPhi=3.14; - if (eid_match_seed_dEta<-10) eid_match_seed_dEta=-10; - if (eid_match_seed_dEta>10) eid_match_seed_dEta=10; - if (eid_sc_E<0) eid_sc_E=0; - if (eid_sc_E>1000) eid_sc_E=1000; - if (eid_trk_p<-1) eid_trk_p=-1; - if (eid_trk_p>1000) eid_trk_p=1000; - if (gsf_mode_p<0) gsf_mode_p=0; - if (gsf_mode_p>1000) gsf_mode_p=1000; - if (core_shFracHits<0) core_shFracHits=0; - if (core_shFracHits>1) core_shFracHits=1; - if (gsf_bdtout1<-20) gsf_bdtout1=-20; - if (gsf_bdtout1>20) gsf_bdtout1=20; - if (gsf_dr<0) gsf_dr=5; - if (gsf_dr>5) gsf_dr=5; - if (trk_dr<0) trk_dr=5; - if (trk_dr>5) trk_dr=5; - if (sc_Nclus<0) sc_Nclus=0; - if (sc_Nclus>20) sc_Nclus=20; - if (sc_clus1_nxtal<0) sc_clus1_nxtal=0; - if (sc_clus1_nxtal>100) sc_clus1_nxtal=100; - if (sc_clus1_dphi<-3.14) sc_clus1_dphi=-5; - if (sc_clus1_dphi>3.14) sc_clus1_dphi=5; - if (sc_clus2_dphi<-3.14) sc_clus2_dphi=-5; - if (sc_clus2_dphi>3.14) sc_clus2_dphi=5; - if (sc_clus1_deta<-5) sc_clus1_deta=-5; - if (sc_clus1_deta>5) sc_clus1_deta=5; - if (sc_clus2_deta<-5) sc_clus2_deta=-5; - if (sc_clus2_deta>5) sc_clus2_deta=5; - if (sc_clus1_E<0) sc_clus1_E=0; - if (sc_clus1_E>1000) sc_clus1_E=1000; - if (sc_clus2_E<0) sc_clus2_E=0; - if (sc_clus2_E>1000) sc_clus2_E=1000; - if (sc_clus1_E_ov_p<0) sc_clus1_E_ov_p=-1; - if (sc_clus2_E_ov_p<0) sc_clus2_E_ov_p=-1; - - return { - eid_rho, - eid_sc_eta, - eid_shape_full5x5_r9, - eid_sc_etaWidth, - eid_sc_phiWidth, - eid_shape_full5x5_HoverE, - eid_trk_nhits, - eid_trk_chi2red, - eid_gsf_chi2red, - eid_brem_frac, - eid_gsf_nhits, - eid_match_SC_EoverP, - eid_match_eclu_EoverP, - eid_match_SC_dEta, - eid_match_SC_dPhi, - eid_match_seed_dEta, - eid_sc_E, - eid_trk_p, - gsf_mode_p, - core_shFracHits, - gsf_bdtout1, - gsf_dr, - trk_dr, - sc_Nclus, - sc_clus1_nxtal, - sc_clus1_dphi, - sc_clus2_dphi, - sc_clus1_deta, - sc_clus2_deta, - sc_clus1_E, - sc_clus2_E, - sc_clus1_E_ov_p, - sc_clus2_E_ov_p - }; - } - -} // namespace - +//////////////////////////////////////////////////////////////////////////////// +// class LowPtGsfElectronIDProducer final : public edm::global::EDProducer<> { public: explicit LowPtGsfElectronIDProducer(const edm::ParameterSet&); @@ -441,7 +128,7 @@ double LowPtGsfElectronIDProducer::eval(const std::string& name, const reco::Gsf auto iter = std::find(names_.begin(), names_.end(), name); if (iter != names_.end()) { int index = std::distance(names_.begin(), iter); - std::vector inputs = getFeatures(ele, rho, unbiased); + std::vector inputs = lowptgsfeleid::features(ele, rho, unbiased); return models_.at(index)->GetResponse(inputs.data()); } else { throw cms::Exception("Unknown model name") << "'Name given: '" << name << "'. Check against configuration file.\n"; diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedHeavyObjectCache.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedHeavyObjectCache.cc index a80fd431a1cb4..6ce8a01823be6 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedHeavyObjectCache.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedHeavyObjectCache.cc @@ -1,3 +1,4 @@ +#include "LowPtGsfElectronSeedHeavyObjectCache.h" #include "CommonTools/MVAUtils/interface/GBRForestTools.h" #include "DataFormats/BeamSpot/interface/BeamSpot.h" #include "DataFormats/ParticleFlowReco/interface/PFCluster.h" @@ -6,106 +7,12 @@ #include "DataFormats/TrackReco/interface/Track.h" #include "DataFormats/TrackReco/interface/TrackFwd.h" #include "FWCore/ParameterSet/interface/FileInPath.h" - -#include "LowPtGsfElectronSeedHeavyObjectCache.h" +#include "RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h" #include namespace lowptgsfeleseed { - //////////////////////////////////////////////////////////////////////////////// - // - std::vector Features::get() { - std::vector output = {trk_pt_, - trk_eta_, - trk_phi_, - trk_p_, - trk_nhits_, - trk_high_quality_, - trk_chi2red_, - rho_, - ktf_ecal_cluster_e_, - ktf_ecal_cluster_deta_, - ktf_ecal_cluster_dphi_, - ktf_ecal_cluster_e3x3_, - ktf_ecal_cluster_e5x5_, - ktf_ecal_cluster_covEtaEta_, - ktf_ecal_cluster_covEtaPhi_, - ktf_ecal_cluster_covPhiPhi_, - ktf_ecal_cluster_r9_, - ktf_ecal_cluster_circularity_, - ktf_hcal_cluster_e_, - ktf_hcal_cluster_deta_, - ktf_hcal_cluster_dphi_, - preid_gsf_dpt_, - preid_trk_gsf_chiratio_, - preid_gsf_chi2red_, - trk_dxy_sig_}; - return output; - } - - //////////////////////////////////////////////////////////////////////////////// - // - void Features::set(const reco::PreId& ecal, - const reco::PreId& hcal, - double rho, - const reco::BeamSpot& spot, - noZS::EcalClusterLazyTools& tools) { - // Tracks - reco::TrackRef trk = ecal.trackRef(); - if (trk.isNonnull()) { - trk_pt_ = trk->pt(); - trk_eta_ = trk->eta(); - trk_phi_ = trk->phi(); - trk_p_ = trk->p(); - trk_nhits_ = static_cast(trk->found()); - trk_high_quality_ = static_cast(trk->quality(reco::TrackBase::qualityByName("highPurity"))); - trk_chi2red_ = trk->normalizedChi2(); - if (trk->dxy(spot) > 0.) { - trk_dxy_sig_ = trk->dxyError() / trk->dxy(spot); //@@ to be consistent with the training based on 94X MC - } - ktf_ecal_cluster_dphi_ *= trk->charge(); //@@ to be consistent with the training based on 94X MC - } - - // Rho - rho_ = static_cast(rho); - - // ECAL clusters - reco::PFClusterRef ecal_clu = ecal.clusterRef(); - if (ecal_clu.isNonnull()) { - ktf_ecal_cluster_e_ = ecal_clu->energy(); - ktf_ecal_cluster_deta_ = ecal.geomMatching()[0]; - ktf_ecal_cluster_dphi_ = ecal.geomMatching()[1]; - ktf_ecal_cluster_e3x3_ = tools.e3x3(*ecal_clu); - ktf_ecal_cluster_e5x5_ = tools.e5x5(*ecal_clu); - auto covs = tools.localCovariances(*ecal_clu); - ktf_ecal_cluster_covEtaEta_ = covs[0]; - ktf_ecal_cluster_covEtaPhi_ = covs[1]; - ktf_ecal_cluster_covPhiPhi_ = covs[2]; - if (ktf_ecal_cluster_e_ > 0.) { - ktf_ecal_cluster_r9_ = ktf_ecal_cluster_e3x3_ / ktf_ecal_cluster_e_; - } - if (ktf_ecal_cluster_e5x5_ > 0.) { - ktf_ecal_cluster_circularity_ = 1. - tools.e1x5(*ecal_clu) / ktf_ecal_cluster_e5x5_; - } else { - ktf_ecal_cluster_circularity_ = -0.1; - } - } - - // HCAL clusters - reco::PFClusterRef hcal_clu = hcal.clusterRef(); - if (hcal_clu.isNonnull()) { - ktf_hcal_cluster_e_ = hcal_clu->energy(); - ktf_hcal_cluster_deta_ = hcal.geomMatching()[0]; - ktf_hcal_cluster_dphi_ = hcal.geomMatching()[1]; - } - - // PreId - preid_gsf_dpt_ = ecal.dpt(); - preid_trk_gsf_chiratio_ = ecal.chi2Ratio(); - preid_gsf_chi2red_ = ecal.gsfChi2(); - }; - //////////////////////////////////////////////////////////////////////////////// // HeavyObjectCache::HeavyObjectCache(const edm::ParameterSet& conf) { @@ -140,9 +47,7 @@ namespace lowptgsfeleseed { std::vector::const_iterator iter = std::find(names_.begin(), names_.end(), name); if (iter != names_.end()) { int index = std::distance(names_.begin(), iter); - Features features; - features.set(ecal, hcal, rho, spot, ecalTools); - std::vector inputs = features.get(); + std::vector inputs = features(ecal, hcal, rho, spot, ecalTools); float output = models_.at(index)->GetResponse(inputs.data()); bool pass = output > thresholds_.at(index); ecal.setMVA(pass, output, index); diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedHeavyObjectCache.h b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedHeavyObjectCache.h index fe3807b8415fc..32af215f87c38 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedHeavyObjectCache.h +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedHeavyObjectCache.h @@ -13,42 +13,6 @@ namespace reco { namespace lowptgsfeleseed { - class Features { - public: - float trk_pt_ = -1.; - float trk_eta_ = -1.; - float trk_phi_ = -1.; - float trk_p_ = -1.; - float trk_nhits_ = -1.; - float trk_high_quality_ = -1.; - float trk_chi2red_ = -1.; - float rho_ = -1.; - float ktf_ecal_cluster_e_ = -1.; - float ktf_ecal_cluster_deta_ = -42.; - float ktf_ecal_cluster_dphi_ = -42.; - float ktf_ecal_cluster_e3x3_ = -1.; - float ktf_ecal_cluster_e5x5_ = -1.; - float ktf_ecal_cluster_covEtaEta_ = -42.; - float ktf_ecal_cluster_covEtaPhi_ = -42.; - float ktf_ecal_cluster_covPhiPhi_ = -42.; - float ktf_ecal_cluster_r9_ = -0.1; - float ktf_ecal_cluster_circularity_ = -0.1; - float ktf_hcal_cluster_e_ = -1.; - float ktf_hcal_cluster_deta_ = -42.; - float ktf_hcal_cluster_dphi_ = -42.; - float preid_gsf_dpt_ = -1.; - float preid_trk_gsf_chiratio_ = -1.; - float preid_gsf_chi2red_ = -1.; - float trk_dxy_sig_ = -1.; // must be last (not used by unbiased model) - public: - std::vector get(); - void set(const reco::PreId& ecal, - const reco::PreId& hcal, - double rho, - const reco::BeamSpot& spot, - noZS::EcalClusterLazyTools& ecalTools); - }; - class HeavyObjectCache { public: HeavyObjectCache(const edm::ParameterSet&); diff --git a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc new file mode 100644 index 0000000000000..45db532586f4d --- /dev/null +++ b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc @@ -0,0 +1,461 @@ +#include "RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h" +#include "CommonTools/BaseParticlePropagator/interface/BaseParticlePropagator.h" +#include "DataFormats/BeamSpot/interface/BeamSpot.h" +#include "DataFormats/GsfTrackReco/interface/GsfTrack.h" +#include "DataFormats/ParticleFlowReco/interface/PFCluster.h" +#include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h" +#include "DataFormats/ParticleFlowReco/interface/PreId.h" +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/TrackReco/interface/TrackFwd.h" +#include + +namespace lowptgsfeleseed { + + //////////////////////////////////////////////////////////////////////////////// + // + std::vector features( const reco::PreId& ecal, + const reco::PreId& hcal, + double rho, + const reco::BeamSpot& spot, + noZS::EcalClusterLazyTools& tools ) { + + float trk_pt_ = -1.; + float trk_eta_ = -1.; + float trk_phi_ = -1.; + float trk_p_ = -1.; + float trk_nhits_ = -1.; + float trk_high_quality_ = -1.; + float trk_chi2red_ = -1.; + float rho_ = -1.; + float ktf_ecal_cluster_e_ = -1.; + float ktf_ecal_cluster_deta_ = -42.; + float ktf_ecal_cluster_dphi_ = -42.; + float ktf_ecal_cluster_e3x3_ = -1.; + float ktf_ecal_cluster_e5x5_ = -1.; + float ktf_ecal_cluster_covEtaEta_ = -42.; + float ktf_ecal_cluster_covEtaPhi_ = -42.; + float ktf_ecal_cluster_covPhiPhi_ = -42.; + float ktf_ecal_cluster_r9_ = -0.1; + float ktf_ecal_cluster_circularity_ = -0.1; + float ktf_hcal_cluster_e_ = -1.; + float ktf_hcal_cluster_deta_ = -42.; + float ktf_hcal_cluster_dphi_ = -42.; + float preid_gsf_dpt_ = -1.; + float preid_trk_gsf_chiratio_ = -1.; + float preid_gsf_chi2red_ = -1.; + float trk_dxy_sig_ = -1.; // must be last (not used by unbiased model) + + // Tracks + reco::TrackRef trk = ecal.trackRef(); + if (trk.isNonnull()) { + trk_pt_ = trk->pt(); + trk_eta_ = trk->eta(); + trk_phi_ = trk->phi(); + trk_p_ = trk->p(); + trk_nhits_ = static_cast(trk->found()); + trk_high_quality_ = static_cast(trk->quality(reco::TrackBase::qualityByName("highPurity"))); + trk_chi2red_ = trk->normalizedChi2(); + if (trk->dxy(spot) > 0.) { + trk_dxy_sig_ = trk->dxyError() / trk->dxy(spot); //@@ to be consistent with the training based on 94X MC + } + ktf_ecal_cluster_dphi_ *= trk->charge(); //@@ to be consistent with the training based on 94X MC + } + + // Rho + rho_ = static_cast(rho); + + // ECAL clusters + reco::PFClusterRef ecal_clu = ecal.clusterRef(); + if (ecal_clu.isNonnull()) { + ktf_ecal_cluster_e_ = ecal_clu->energy(); + ktf_ecal_cluster_deta_ = ecal.geomMatching()[0]; + ktf_ecal_cluster_dphi_ = ecal.geomMatching()[1]; + ktf_ecal_cluster_e3x3_ = tools.e3x3(*ecal_clu); + ktf_ecal_cluster_e5x5_ = tools.e5x5(*ecal_clu); + auto covs = tools.localCovariances(*ecal_clu); + ktf_ecal_cluster_covEtaEta_ = covs[0]; + ktf_ecal_cluster_covEtaPhi_ = covs[1]; + ktf_ecal_cluster_covPhiPhi_ = covs[2]; + if (ktf_ecal_cluster_e_ > 0.) { + ktf_ecal_cluster_r9_ = ktf_ecal_cluster_e3x3_ / ktf_ecal_cluster_e_; + } + if (ktf_ecal_cluster_e5x5_ > 0.) { + ktf_ecal_cluster_circularity_ = 1. - tools.e1x5(*ecal_clu) / ktf_ecal_cluster_e5x5_; + } else { + ktf_ecal_cluster_circularity_ = -0.1; + } + } + + // HCAL clusters + reco::PFClusterRef hcal_clu = hcal.clusterRef(); + if (hcal_clu.isNonnull()) { + ktf_hcal_cluster_e_ = hcal_clu->energy(); + ktf_hcal_cluster_deta_ = hcal.geomMatching()[0]; + ktf_hcal_cluster_dphi_ = hcal.geomMatching()[1]; + } + + // PreId + preid_gsf_dpt_ = ecal.dpt(); + preid_trk_gsf_chiratio_ = ecal.chi2Ratio(); + preid_gsf_chi2red_ = ecal.gsfChi2(); + + // Set contents of vector + std::vector output = {trk_pt_, + trk_eta_, + trk_phi_, + trk_p_, + trk_nhits_, + trk_high_quality_, + trk_chi2red_, + rho_, + ktf_ecal_cluster_e_, + ktf_ecal_cluster_deta_, + ktf_ecal_cluster_dphi_, + ktf_ecal_cluster_e3x3_, + ktf_ecal_cluster_e5x5_, + ktf_ecal_cluster_covEtaEta_, + ktf_ecal_cluster_covEtaPhi_, + ktf_ecal_cluster_covPhiPhi_, + ktf_ecal_cluster_r9_, + ktf_ecal_cluster_circularity_, + ktf_hcal_cluster_e_, + ktf_hcal_cluster_deta_, + ktf_hcal_cluster_dphi_, + preid_gsf_dpt_, + preid_trk_gsf_chiratio_, + preid_gsf_chi2red_, + trk_dxy_sig_}; + return output; + + }; + +} // namespace + +namespace lowptgsfeleid { + + std::vector features( edm::Ptr const& ele, float rho, float unbiased ) { + + float eid_rho = -999.; + float eid_sc_eta = -999.; + float eid_shape_full5x5_r9 = -999.; + float eid_sc_etaWidth = -999.; + float eid_sc_phiWidth = -999.; + float eid_shape_full5x5_HoverE = -999.; + float eid_trk_nhits = -999.; + float eid_trk_chi2red = -999.; + float eid_gsf_chi2red = -999.; + float eid_brem_frac = -999.; + float eid_gsf_nhits = -999.; + float eid_match_SC_EoverP = -999.; + float eid_match_eclu_EoverP = -999.; + float eid_match_SC_dEta = -999.; + float eid_match_SC_dPhi = -999.; + float eid_match_seed_dEta = -999.; + float eid_sc_E = -999.; + float eid_trk_p = -999.; + float gsf_mode_p = -999.; + float core_shFracHits = -999.; + float gsf_bdtout1 = -999.; + float gsf_dr = -999.; + float trk_dr = -999.; + float sc_Nclus = -999.; + float sc_clus1_nxtal = -999.; + float sc_clus1_dphi = -999.; + float sc_clus2_dphi = -999.; + float sc_clus1_deta = -999.; + float sc_clus2_deta = -999.; + float sc_clus1_E = -999.; + float sc_clus2_E = -999.; + float sc_clus1_E_ov_p = -999.; + float sc_clus2_E_ov_p = -999.; + + // KF tracks + if ( ele->core().isNonnull() ) { + reco::TrackRef trk = ele->closestCtfTrackRef(); + if ( trk.isNonnull() ) { + eid_trk_p = (float)trk->p(); + eid_trk_nhits = (float)trk->found(); + eid_trk_chi2red = (float)trk->normalizedChi2(); + TVector3 trkTV3(0,0,0); + trkTV3.SetPtEtaPhi(trk->pt(), trk->eta(), trk->phi()); + TVector3 eleTV3(0,0,0); + eleTV3.SetPtEtaPhi(ele->pt(), ele->eta(), ele->phi()); + trk_dr = eleTV3.DeltaR(trkTV3); + } + } + + // GSF tracks + if ( ele->core().isNonnull() ) { + reco::GsfTrackRef gsf = ele->core()->gsfTrack(); + if ( gsf.isNonnull() ) { + gsf_mode_p = gsf->pMode(); + eid_gsf_nhits = (float)gsf->found(); + eid_gsf_chi2red = gsf->normalizedChi2(); + TVector3 gsfTV3(0,0,0); + gsfTV3.SetPtEtaPhi(gsf->ptMode(), gsf->etaMode(), gsf->phiMode()); + TVector3 eleTV3(0,0,0); + eleTV3.SetPtEtaPhi(ele->pt(), ele->eta(), ele->phi()); + gsf_dr = eleTV3.DeltaR(gsfTV3); + } + } + + // Super clusters + if ( ele->core().isNonnull() ) { + reco::SuperClusterRef sc = ele->core()->superCluster(); + if ( sc.isNonnull() ) { + eid_sc_E = sc->energy(); + eid_sc_eta = sc->eta(); + eid_sc_etaWidth = sc->etaWidth(); + eid_sc_phiWidth = sc->phiWidth(); + sc_Nclus = sc->clustersSize(); + } + } + + // Track-cluster matching + if ( ele.isNonnull() ) { + eid_match_seed_dEta = ele->deltaEtaSeedClusterTrackAtCalo(); + eid_match_eclu_EoverP = (1./ele->ecalEnergy()) - (1./ele->p()); + eid_match_SC_EoverP = ele->eSuperClusterOverP(); + eid_match_SC_dEta = ele->deltaEtaSuperClusterTrackAtVtx(); + eid_match_SC_dPhi = ele->deltaPhiSuperClusterTrackAtVtx(); + } + + // Shower shape vars + if ( ele.isNonnull() ) { + eid_shape_full5x5_HoverE = ele->full5x5_hcalOverEcal(); + eid_shape_full5x5_r9 = ele->full5x5_r9(); + } + + // Misc + eid_rho = rho; + + if ( ele.isNonnull() ) { + eid_brem_frac = ele->fbrem(); + core_shFracHits = ele->shFracInnerHits(); + } + + // Unbiased BDT from ElectronSeed + gsf_bdtout1 = unbiased; + + // Clusters + if ( ele->core().isNonnull() ) { + reco::GsfTrackRef gsf = ele->core()->gsfTrack(); + if ( gsf.isNonnull() ) { + reco::SuperClusterRef sc = ele->core()->superCluster(); + if ( sc.isNonnull() ) { + + // Propagate electron track to ECAL surface + double mass_ = 0.000511*0.000511; + float p2=pow( gsf->p() ,2 ); + float energy = sqrt(mass_ + p2); + math::XYZTLorentzVector mom = math::XYZTLorentzVector(gsf->px(), gsf->py(), gsf->pz(), energy); + math::XYZTLorentzVector pos = math::XYZTLorentzVector(gsf->vx(), gsf->vy(), gsf->vz(), 0.); + float field_z=3.8; + BaseParticlePropagator mypart(RawParticle(mom, pos, gsf->charge()), 0, 0, field_z); + mypart.propagateToEcalEntrance(true); // true only first half loop , false more than one loop + bool reach_ECAL = mypart.getSuccess(); // 0 does not reach ECAL, 1 yes barrel, 2 yes endcaps + + // ECAL entry point for track + GlobalPoint ecal_pos(mypart.particle().vertex().x(), mypart.particle().vertex().y(), mypart.particle().vertex().z()); + + // Iterate through ECAL clusters and sort in energy + int clusNum=0; + float maxEne1=-1; + float maxEne2=-1; + int i1=-1; + int i2=-1; + try{ + if(sc->clustersSize()>0 && sc->clustersBegin()!=sc->clustersEnd()){ + for(auto& cluster : sc->clusters()) { + if (cluster->energy() > maxEne1){ + maxEne1=cluster->energy(); + i1=clusNum; + } + clusNum++; + } + if(sc->clustersSize()>1){ + clusNum=0; + for(auto& cluster : sc->clusters()) { + if (clusNum!=i1) { + if (cluster->energy() > maxEne2){ + maxEne2=cluster->energy(); + i2=clusNum; + } + } + clusNum++; + } + } + } // loop over clusters + } catch(...) { + std::cout<<"exception caught clusNum="<clustersSize()<<" energy="<< sc->energy()<clustersSize()>0&& sc->clustersBegin()!=sc->clustersEnd()){ + for(auto& cluster : sc->clusters()) { + double pi_=3.1415926535; + float deta = std::fabs(ecal_pos.eta()-cluster->eta()) ; + float dphi = std::fabs(ecal_pos.phi()-cluster->phi()); + if (dphi > pi_) dphi -= 2 * pi_; + if (ecal_pos.phi()-cluster->phi()<0) dphi=-dphi; + if (ecal_pos.eta()-cluster->eta()<0) deta=-deta; + + if (clusNum==i1) { + sc_clus1_E = cluster->energy(); + if(gsf->pMode()>0) sc_clus1_E_ov_p = cluster->energy()/gsf->pMode(); + sc_clus1_nxtal = (int)cluster->size(); + if (reach_ECAL>0){ + sc_clus1_deta = deta; + sc_clus1_dphi = dphi; + } + } else if (clusNum==i2) { + sc_clus2_E = cluster->energy(); + if(gsf->pMode()>0) sc_clus2_E_ov_p = cluster->energy()/gsf->pMode(); + if (reach_ECAL>0){ + sc_clus2_deta = deta; + sc_clus2_dphi = dphi; + } + } + clusNum++; + } + } + } catch(...) { + std::cout<<"caught an exception"<100) eid_rho=100; + if (eid_sc_eta<-5) eid_sc_eta=-5; + if (eid_sc_eta>5) eid_sc_eta=5; + if (eid_shape_full5x5_r9<0) eid_shape_full5x5_r9=0; + if (eid_shape_full5x5_r9>2) eid_shape_full5x5_r9=2; + if (eid_sc_etaWidth<0) eid_sc_etaWidth=0; + if (eid_sc_etaWidth>3.14) eid_sc_etaWidth=3.14; + if (eid_sc_phiWidth<0) eid_sc_phiWidth=0; + if (eid_sc_phiWidth>3.14) eid_sc_phiWidth=3.14; + if (eid_shape_full5x5_HoverE<0) eid_shape_full5x5_HoverE=0; + if (eid_shape_full5x5_HoverE>50) eid_shape_full5x5_HoverE=50; + if (eid_trk_nhits<-1) eid_trk_nhits=-1; + if (eid_trk_nhits>50) eid_trk_nhits=50; + if (eid_trk_chi2red<-1) eid_trk_chi2red=-1; + if (eid_trk_chi2red>50) eid_trk_chi2red=50; + if (eid_gsf_chi2red<-1) eid_gsf_chi2red=-1; + if (eid_gsf_chi2red>100) eid_gsf_chi2red=100; + if (eid_brem_frac<0) eid_brem_frac=-1; + if (eid_brem_frac>1) eid_brem_frac=1; + if (eid_gsf_nhits<-1) eid_gsf_nhits=-1; + if (eid_gsf_nhits>50) eid_gsf_nhits=50; + if (eid_match_SC_EoverP<0) eid_match_SC_EoverP=0; + if (eid_match_SC_EoverP>100) eid_match_SC_EoverP=100; + if (eid_match_eclu_EoverP<-0.001) eid_match_eclu_EoverP=-0.001; + if (eid_match_eclu_EoverP>0.001) eid_match_eclu_EoverP=0.001; + eid_match_eclu_EoverP=eid_match_eclu_EoverP*1.E7; + if (eid_match_SC_dEta<-10) eid_match_SC_dEta=-10; + if (eid_match_SC_dEta>10) eid_match_SC_dEta=10; + if (eid_match_SC_dPhi<-3.14) eid_match_SC_dPhi=-3.14; + if (eid_match_SC_dPhi>3.14) eid_match_SC_dPhi=3.14; + if (eid_match_seed_dEta<-10) eid_match_seed_dEta=-10; + if (eid_match_seed_dEta>10) eid_match_seed_dEta=10; + if (eid_sc_E<0) eid_sc_E=0; + if (eid_sc_E>1000) eid_sc_E=1000; + if (eid_trk_p<-1) eid_trk_p=-1; + if (eid_trk_p>1000) eid_trk_p=1000; + if (gsf_mode_p<0) gsf_mode_p=0; + if (gsf_mode_p>1000) gsf_mode_p=1000; + if (core_shFracHits<0) core_shFracHits=0; + if (core_shFracHits>1) core_shFracHits=1; + if (gsf_bdtout1<-20) gsf_bdtout1=-20; + if (gsf_bdtout1>20) gsf_bdtout1=20; + if (gsf_dr<0) gsf_dr=5; + if (gsf_dr>5) gsf_dr=5; + if (trk_dr<0) trk_dr=5; + if (trk_dr>5) trk_dr=5; + if (sc_Nclus<0) sc_Nclus=0; + if (sc_Nclus>20) sc_Nclus=20; + if (sc_clus1_nxtal<0) sc_clus1_nxtal=0; + if (sc_clus1_nxtal>100) sc_clus1_nxtal=100; + if (sc_clus1_dphi<-3.14) sc_clus1_dphi=-5; + if (sc_clus1_dphi>3.14) sc_clus1_dphi=5; + if (sc_clus2_dphi<-3.14) sc_clus2_dphi=-5; + if (sc_clus2_dphi>3.14) sc_clus2_dphi=5; + if (sc_clus1_deta<-5) sc_clus1_deta=-5; + if (sc_clus1_deta>5) sc_clus1_deta=5; + if (sc_clus2_deta<-5) sc_clus2_deta=-5; + if (sc_clus2_deta>5) sc_clus2_deta=5; + if (sc_clus1_E<0) sc_clus1_E=0; + if (sc_clus1_E>1000) sc_clus1_E=1000; + if (sc_clus2_E<0) sc_clus2_E=0; + if (sc_clus2_E>1000) sc_clus2_E=1000; + if (sc_clus1_E_ov_p<0) sc_clus1_E_ov_p=-1; + if (sc_clus2_E_ov_p<0) sc_clus2_E_ov_p=-1; + + // Set contents of vector + std::vector output = { + eid_rho, + eid_sc_eta, + eid_shape_full5x5_r9, + eid_sc_etaWidth, + eid_sc_phiWidth, + eid_shape_full5x5_HoverE, + eid_trk_nhits, + eid_trk_chi2red, + eid_gsf_chi2red, + eid_brem_frac, + eid_gsf_nhits, + eid_match_SC_EoverP, + eid_match_eclu_EoverP, + eid_match_SC_dEta, + eid_match_SC_dPhi, + eid_match_seed_dEta, + eid_sc_E, + eid_trk_p, + gsf_mode_p, + core_shFracHits, + gsf_bdtout1, + gsf_dr, + trk_dr, + sc_Nclus, + sc_clus1_nxtal, + sc_clus1_dphi, + sc_clus2_dphi, + sc_clus1_deta, + sc_clus2_deta, + sc_clus1_E, + sc_clus2_E, + sc_clus1_E_ov_p, + sc_clus2_E_ov_p + }; + return output; + + } + + //////////////////////////////////////////////////////////////////////////////// + // + std::vector features( edm::Ref< std::vector > const& ele, float rho, float unbiased ) { + return features(edm::refToPtr(ele),rho,unbiased); + } + + //////////////////////////////////////////////////////////////////////////////// + // + std::vector features( edm::Ref< edm::View > const& ele, float rho, float unbiased ) { + return features(edm::refToPtr(ele),rho,unbiased); + } + +} // namespace From 623d3f6078ffdc114a96a258fa0da46cd8bc876c Mon Sep 17 00:00:00 2001 From: crovelli Date: Thu, 30 Jul 2020 11:22:08 +0200 Subject: [PATCH 3/7] float-int fixes; e_sc range change --- .../src/LowPtGsfElectronFeatures.cc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc index 45db532586f4d..9fba6fbc31a9e 100644 --- a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc +++ b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc @@ -207,7 +207,7 @@ namespace lowptgsfeleid { eid_sc_eta = sc->eta(); eid_sc_etaWidth = sc->etaWidth(); eid_sc_phiWidth = sc->phiWidth(); - sc_Nclus = sc->clustersSize(); + sc_Nclus = (float)sc->clustersSize(); } } @@ -231,7 +231,7 @@ namespace lowptgsfeleid { if ( ele.isNonnull() ) { eid_brem_frac = ele->fbrem(); - core_shFracHits = ele->shFracInnerHits(); + core_shFracHits = (float)ele->shFracInnerHits(); } // Unbiased BDT from ElectronSeed @@ -291,7 +291,7 @@ namespace lowptgsfeleid { } // Initializations - sc_clus1_nxtal = -999; + sc_clus1_nxtal = -999.; sc_clus1_dphi = -999.; sc_clus2_dphi = -999.; sc_clus1_deta = -999.; @@ -316,7 +316,7 @@ namespace lowptgsfeleid { if (clusNum==i1) { sc_clus1_E = cluster->energy(); if(gsf->pMode()>0) sc_clus1_E_ov_p = cluster->energy()/gsf->pMode(); - sc_clus1_nxtal = (int)cluster->size(); + sc_clus1_nxtal = (float)cluster->size(); if (reach_ECAL>0){ sc_clus1_deta = deta; sc_clus1_dphi = dphi; @@ -364,9 +364,8 @@ namespace lowptgsfeleid { if (eid_gsf_nhits>50) eid_gsf_nhits=50; if (eid_match_SC_EoverP<0) eid_match_SC_EoverP=0; if (eid_match_SC_EoverP>100) eid_match_SC_EoverP=100; - if (eid_match_eclu_EoverP<-0.001) eid_match_eclu_EoverP=-0.001; - if (eid_match_eclu_EoverP>0.001) eid_match_eclu_EoverP=0.001; - eid_match_eclu_EoverP=eid_match_eclu_EoverP*1.E7; + if (eid_match_eclu_EoverP<-1.) eid_match_eclu_EoverP=-1.; + if (eid_match_eclu_EoverP>1.) eid_match_eclu_EoverP=1.; if (eid_match_SC_dEta<-10) eid_match_SC_dEta=-10; if (eid_match_SC_dEta>10) eid_match_SC_dEta=10; if (eid_match_SC_dPhi<-3.14) eid_match_SC_dPhi=-3.14; From b7fa8e89d4ee2b055502c9f55b059cb64203435e Mon Sep 17 00:00:00 2001 From: bainbrid Date: Thu, 6 Aug 2020 19:00:50 +0200 Subject: [PATCH 4/7] use edm::View and edm::Ptr to allow evaluation using patElectrons --- .../plugins/LowPtGsfElectronIDProducer.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc index 23cc93b18b4a0..64d1623aba18a 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc @@ -1,6 +1,8 @@ #include "CommonTools/BaseParticlePropagator/interface/BaseParticlePropagator.h" #include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/Common/interface/Ptr.h" #include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/Common/interface/View.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "FWCore/Utilities/interface/InputTag.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" @@ -29,9 +31,9 @@ class LowPtGsfElectronIDProducer final : public edm::global::EDProducer<> { static void fillDescriptions(edm::ConfigurationDescriptions&); private: - double eval(const std::string& name, const reco::GsfElectronRef&, double rho, float unbiased) const; + double eval(const std::string& name, const edm::Ptr, double rho, float unbiased) const; - const edm::EDGetTokenT gsfElectrons_; + const edm::EDGetTokenT< edm::View > gsfElectrons_; const edm::EDGetTokenT rho_; const edm::EDGetTokenT< edm::ValueMap > unbiased_; const std::vector names_; @@ -45,7 +47,7 @@ class LowPtGsfElectronIDProducer final : public edm::global::EDProducer<> { //////////////////////////////////////////////////////////////////////////////// // LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer(const edm::ParameterSet& conf) - : gsfElectrons_(consumes(conf.getParameter("electrons"))), + : gsfElectrons_(consumes< edm::View >(conf.getParameter("electrons"))), rho_(consumes(conf.getParameter("rho"))), unbiased_(consumes< edm::ValueMap >(conf.getParameter("unbiased"))), names_(conf.getParameter >("ModelNames")), @@ -81,7 +83,7 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const } // Retrieve GsfElectrons from Event - edm::Handle gsfElectrons; + edm::Handle< edm::View > gsfElectrons; event.getByToken(gsfElectrons_, gsfElectrons); if (!gsfElectrons.isValid()) { edm::LogError("Problem with gsfElectrons handle"); @@ -100,7 +102,7 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const output.emplace_back(gsfElectrons->size(), -999.); } for (unsigned int iele = 0; iele < gsfElectrons->size(); iele++) { - reco::GsfElectronRef ele(gsfElectrons, iele); + edm::Ptr ele(gsfElectrons, iele); if ( ele->core().isNull() ) { continue; } reco::GsfTrackRef gsf = ele->core()->gsfTrack(); @@ -119,12 +121,12 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const edm::ValueMap::Filler filler(*ptr); filler.insert(gsfElectrons, output[iname].begin(), output[iname].end()); filler.fill(); - reco::GsfElectronRef ele(gsfElectrons, 0); + //reco::GsfElectronRef ele(gsfElectrons, 0); event.put(std::move(ptr), names_[iname]); } } -double LowPtGsfElectronIDProducer::eval(const std::string& name, const reco::GsfElectronRef& ele, double rho, float unbiased) const { +double LowPtGsfElectronIDProducer::eval(const std::string& name, const edm::Ptr ele, double rho, float unbiased) const { auto iter = std::find(names_.begin(), names_.end(), name); if (iter != names_.end()) { int index = std::distance(names_.begin(), iter); From d553c1815c6d7f0d311e2159e80d6e447ea94bc6 Mon Sep 17 00:00:00 2001 From: bainbrid Date: Thu, 6 Aug 2020 20:32:47 +0200 Subject: [PATCH 5/7] scram build code-checks, scram build code-format --- .../interface/LowPtGsfElectronFeatures.h | 17 +- .../plugins/LowPtGsfElectronIDProducer.cc | 38 +- .../src/LowPtGsfElectronFeatures.cc | 638 ++++++++++-------- 3 files changed, 383 insertions(+), 310 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h b/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h index 81536678bffb0..c50fea353ca64 100644 --- a/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h +++ b/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h @@ -16,19 +16,22 @@ namespace reco { namespace lowptgsfeleseed { - std::vector features( const reco::PreId& ecal, const reco::PreId& hcal, double rho, - const reco::BeamSpot& spot, noZS::EcalClusterLazyTools& ecalTools ); + std::vector features(const reco::PreId& ecal, + const reco::PreId& hcal, + double rho, + const reco::BeamSpot& spot, + noZS::EcalClusterLazyTools& ecalTools); } namespace lowptgsfeleid { - std::vector features( edm::Ptr const& ele, float rho, float unbiased ); + std::vector features(edm::Ptr const& ele, float rho, float unbiased); - std::vector features( edm::Ref< std::vector > const& ele, float rho, float unbiased ); + std::vector features(edm::Ref > const& ele, float rho, float unbiased); - std::vector features( edm::Ref< edm::View > const& ele, float rho, float unbiased ); - -} // namespace + std::vector features(edm::Ref > const& ele, float rho, float unbiased); + +} // namespace lowptgsfeleid #endif // RecoEgamma_EgammaElectronProducers_LowPtGsfElectronFeatures_h diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc index 64d1623aba18a..22808b2794d54 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc @@ -33,9 +33,9 @@ class LowPtGsfElectronIDProducer final : public edm::global::EDProducer<> { private: double eval(const std::string& name, const edm::Ptr, double rho, float unbiased) const; - const edm::EDGetTokenT< edm::View > gsfElectrons_; + const edm::EDGetTokenT > gsfElectrons_; const edm::EDGetTokenT rho_; - const edm::EDGetTokenT< edm::ValueMap > unbiased_; + const edm::EDGetTokenT > unbiased_; const std::vector names_; const bool passThrough_; const double minPtThreshold_; @@ -47,9 +47,9 @@ class LowPtGsfElectronIDProducer final : public edm::global::EDProducer<> { //////////////////////////////////////////////////////////////////////////////// // LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer(const edm::ParameterSet& conf) - : gsfElectrons_(consumes< edm::View >(conf.getParameter("electrons"))), + : gsfElectrons_(consumes >(conf.getParameter("electrons"))), rho_(consumes(conf.getParameter("rho"))), - unbiased_(consumes< edm::ValueMap >(conf.getParameter("unbiased"))), + unbiased_(consumes >(conf.getParameter("unbiased"))), names_(conf.getParameter >("ModelNames")), passThrough_(conf.getParameter("PassThrough")), minPtThreshold_(conf.getParameter("MinPtThreshold")), @@ -74,7 +74,6 @@ LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer(const edm::ParameterSet& //////////////////////////////////////////////////////////////////////////////// // void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const edm::EventSetup& setup) const { - // Pileup edm::Handle rho; event.getByToken(rho_, rho); @@ -83,17 +82,17 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const } // Retrieve GsfElectrons from Event - edm::Handle< edm::View > gsfElectrons; + edm::Handle > gsfElectrons; event.getByToken(gsfElectrons_, gsfElectrons); if (!gsfElectrons.isValid()) { edm::LogError("Problem with gsfElectrons handle"); } - // ElectronSeed unbiased BDT - edm::Handle< edm::ValueMap > unbiasedH; - event.getByToken(unbiased_,unbiasedH); - if (!unbiasedH.isValid()) { - edm::LogError("Problem with unbiased handle"); + // ElectronSeed unbiased BDT + edm::Handle > unbiasedH; + event.getByToken(unbiased_, unbiasedH); + if (!unbiasedH.isValid()) { + edm::LogError("Problem with unbiased handle"); } // Iterate through Electrons, evaluate BDT, and store result @@ -104,10 +103,14 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const for (unsigned int iele = 0; iele < gsfElectrons->size(); iele++) { edm::Ptr ele(gsfElectrons, iele); - if ( ele->core().isNull() ) { continue; } + if (ele->core().isNull()) { + continue; + } reco::GsfTrackRef gsf = ele->core()->gsfTrack(); - if ( gsf.isNull() ) { continue; } - float unbiased = (*unbiasedH)[gsf]; + if (gsf.isNull()) { + continue; + } + float unbiased = (*unbiasedH)[gsf]; //if ( !passThrough_ && ( ele->pt() < minPtThreshold_ ) ) { continue; } for (unsigned int iname = 0; iname < names_.size(); ++iname) { @@ -126,7 +129,10 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const } } -double LowPtGsfElectronIDProducer::eval(const std::string& name, const edm::Ptr ele, double rho, float unbiased) const { +double LowPtGsfElectronIDProducer::eval(const std::string& name, + const edm::Ptr ele, + double rho, + float unbiased) const { auto iter = std::find(names_.begin(), names_.end(), name); if (iter != names_.end()) { int index = std::distance(names_.begin(), iter); @@ -143,7 +149,7 @@ double LowPtGsfElectronIDProducer::eval(const std::string& name, const edm::Ptr< void LowPtGsfElectronIDProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; desc.add("electrons", edm::InputTag("lowPtGsfElectrons")); - desc.add("unbiased",edm::InputTag("lowPtGsfElectronSeedValueMaps:unbiased")); + desc.add("unbiased", edm::InputTag("lowPtGsfElectronSeedValueMaps:unbiased")); desc.add("rho", edm::InputTag("fixedGridRhoFastjetAllTmp")); desc.add >("ModelNames", {""}); desc.add >( diff --git a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc index 9fba6fbc31a9e..675beccf23048 100644 --- a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc +++ b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc @@ -13,12 +13,11 @@ namespace lowptgsfeleseed { //////////////////////////////////////////////////////////////////////////////// // - std::vector features( const reco::PreId& ecal, - const reco::PreId& hcal, - double rho, - const reco::BeamSpot& spot, - noZS::EcalClusterLazyTools& tools ) { - + std::vector features(const reco::PreId& ecal, + const reco::PreId& hcal, + double rho, + const reco::BeamSpot& spot, + noZS::EcalClusterLazyTools& tools) { float trk_pt_ = -1.; float trk_eta_ = -1.; float trk_phi_ = -1.; @@ -126,335 +125,400 @@ namespace lowptgsfeleseed { preid_gsf_chi2red_, trk_dxy_sig_}; return output; - }; - -} // namespace + +} // namespace lowptgsfeleseed namespace lowptgsfeleid { - std::vector features( edm::Ptr const& ele, float rho, float unbiased ) { - - float eid_rho = -999.; - float eid_sc_eta = -999.; - float eid_shape_full5x5_r9 = -999.; - float eid_sc_etaWidth = -999.; - float eid_sc_phiWidth = -999.; - float eid_shape_full5x5_HoverE = -999.; - float eid_trk_nhits = -999.; - float eid_trk_chi2red = -999.; - float eid_gsf_chi2red = -999.; - float eid_brem_frac = -999.; - float eid_gsf_nhits = -999.; - float eid_match_SC_EoverP = -999.; - float eid_match_eclu_EoverP = -999.; - float eid_match_SC_dEta = -999.; - float eid_match_SC_dPhi = -999.; - float eid_match_seed_dEta = -999.; - float eid_sc_E = -999.; - float eid_trk_p = -999.; - float gsf_mode_p = -999.; - float core_shFracHits = -999.; - float gsf_bdtout1 = -999.; - float gsf_dr = -999.; - float trk_dr = -999.; + std::vector features(edm::Ptr const& ele, float rho, float unbiased) { + float eid_rho = -999.; + float eid_sc_eta = -999.; + float eid_shape_full5x5_r9 = -999.; + float eid_sc_etaWidth = -999.; + float eid_sc_phiWidth = -999.; + float eid_shape_full5x5_HoverE = -999.; + float eid_trk_nhits = -999.; + float eid_trk_chi2red = -999.; + float eid_gsf_chi2red = -999.; + float eid_brem_frac = -999.; + float eid_gsf_nhits = -999.; + float eid_match_SC_EoverP = -999.; + float eid_match_eclu_EoverP = -999.; + float eid_match_SC_dEta = -999.; + float eid_match_SC_dPhi = -999.; + float eid_match_seed_dEta = -999.; + float eid_sc_E = -999.; + float eid_trk_p = -999.; + float gsf_mode_p = -999.; + float core_shFracHits = -999.; + float gsf_bdtout1 = -999.; + float gsf_dr = -999.; + float trk_dr = -999.; float sc_Nclus = -999.; - float sc_clus1_nxtal = -999.; - float sc_clus1_dphi = -999.; - float sc_clus2_dphi = -999.; - float sc_clus1_deta = -999.; - float sc_clus2_deta = -999.; - float sc_clus1_E = -999.; - float sc_clus2_E = -999.; - float sc_clus1_E_ov_p = -999.; - float sc_clus2_E_ov_p = -999.; + float sc_clus1_nxtal = -999.; + float sc_clus1_dphi = -999.; + float sc_clus2_dphi = -999.; + float sc_clus1_deta = -999.; + float sc_clus2_deta = -999.; + float sc_clus1_E = -999.; + float sc_clus2_E = -999.; + float sc_clus1_E_ov_p = -999.; + float sc_clus2_E_ov_p = -999.; - // KF tracks - if ( ele->core().isNonnull() ) { - reco::TrackRef trk = ele->closestCtfTrackRef(); - if ( trk.isNonnull() ) { - eid_trk_p = (float)trk->p(); - eid_trk_nhits = (float)trk->found(); - eid_trk_chi2red = (float)trk->normalizedChi2(); - TVector3 trkTV3(0,0,0); - trkTV3.SetPtEtaPhi(trk->pt(), trk->eta(), trk->phi()); - TVector3 eleTV3(0,0,0); - eleTV3.SetPtEtaPhi(ele->pt(), ele->eta(), ele->phi()); - trk_dr = eleTV3.DeltaR(trkTV3); + // KF tracks + if (ele->core().isNonnull()) { + reco::TrackRef trk = ele->closestCtfTrackRef(); + if (trk.isNonnull()) { + eid_trk_p = (float)trk->p(); + eid_trk_nhits = (float)trk->found(); + eid_trk_chi2red = (float)trk->normalizedChi2(); + TVector3 trkTV3(0, 0, 0); + trkTV3.SetPtEtaPhi(trk->pt(), trk->eta(), trk->phi()); + TVector3 eleTV3(0, 0, 0); + eleTV3.SetPtEtaPhi(ele->pt(), ele->eta(), ele->phi()); + trk_dr = eleTV3.DeltaR(trkTV3); } } - // GSF tracks - if ( ele->core().isNonnull() ) { + // GSF tracks + if (ele->core().isNonnull()) { reco::GsfTrackRef gsf = ele->core()->gsfTrack(); - if ( gsf.isNonnull() ) { - gsf_mode_p = gsf->pMode(); - eid_gsf_nhits = (float)gsf->found(); - eid_gsf_chi2red = gsf->normalizedChi2(); - TVector3 gsfTV3(0,0,0); - gsfTV3.SetPtEtaPhi(gsf->ptMode(), gsf->etaMode(), gsf->phiMode()); - TVector3 eleTV3(0,0,0); - eleTV3.SetPtEtaPhi(ele->pt(), ele->eta(), ele->phi()); - gsf_dr = eleTV3.DeltaR(gsfTV3); + if (gsf.isNonnull()) { + gsf_mode_p = gsf->pMode(); + eid_gsf_nhits = (float)gsf->found(); + eid_gsf_chi2red = gsf->normalizedChi2(); + TVector3 gsfTV3(0, 0, 0); + gsfTV3.SetPtEtaPhi(gsf->ptMode(), gsf->etaMode(), gsf->phiMode()); + TVector3 eleTV3(0, 0, 0); + eleTV3.SetPtEtaPhi(ele->pt(), ele->eta(), ele->phi()); + gsf_dr = eleTV3.DeltaR(gsfTV3); } } - // Super clusters - if ( ele->core().isNonnull() ) { + // Super clusters + if (ele->core().isNonnull()) { reco::SuperClusterRef sc = ele->core()->superCluster(); - if ( sc.isNonnull() ) { - eid_sc_E = sc->energy(); - eid_sc_eta = sc->eta(); - eid_sc_etaWidth = sc->etaWidth(); - eid_sc_phiWidth = sc->phiWidth(); - sc_Nclus = (float)sc->clustersSize(); + if (sc.isNonnull()) { + eid_sc_E = sc->energy(); + eid_sc_eta = sc->eta(); + eid_sc_etaWidth = sc->etaWidth(); + eid_sc_phiWidth = sc->phiWidth(); + sc_Nclus = (float)sc->clustersSize(); } } - // Track-cluster matching - if ( ele.isNonnull() ) { + // Track-cluster matching + if (ele.isNonnull()) { eid_match_seed_dEta = ele->deltaEtaSeedClusterTrackAtCalo(); - eid_match_eclu_EoverP = (1./ele->ecalEnergy()) - (1./ele->p()); + eid_match_eclu_EoverP = (1. / ele->ecalEnergy()) - (1. / ele->p()); eid_match_SC_EoverP = ele->eSuperClusterOverP(); eid_match_SC_dEta = ele->deltaEtaSuperClusterTrackAtVtx(); eid_match_SC_dPhi = ele->deltaPhiSuperClusterTrackAtVtx(); - } + } - // Shower shape vars - if ( ele.isNonnull() ) { - eid_shape_full5x5_HoverE = ele->full5x5_hcalOverEcal(); - eid_shape_full5x5_r9 = ele->full5x5_r9(); + // Shower shape vars + if (ele.isNonnull()) { + eid_shape_full5x5_HoverE = ele->full5x5_hcalOverEcal(); + eid_shape_full5x5_r9 = ele->full5x5_r9(); } // Misc - eid_rho = rho; + eid_rho = rho; - if ( ele.isNonnull() ) { + if (ele.isNonnull()) { eid_brem_frac = ele->fbrem(); core_shFracHits = (float)ele->shFracInnerHits(); } - - // Unbiased BDT from ElectronSeed + + // Unbiased BDT from ElectronSeed gsf_bdtout1 = unbiased; - // Clusters - if ( ele->core().isNonnull() ) { + // Clusters + if (ele->core().isNonnull()) { reco::GsfTrackRef gsf = ele->core()->gsfTrack(); - if ( gsf.isNonnull() ) { - reco::SuperClusterRef sc = ele->core()->superCluster(); - if ( sc.isNonnull() ) { - - // Propagate electron track to ECAL surface - double mass_ = 0.000511*0.000511; - float p2=pow( gsf->p() ,2 ); - float energy = sqrt(mass_ + p2); - math::XYZTLorentzVector mom = math::XYZTLorentzVector(gsf->px(), gsf->py(), gsf->pz(), energy); - math::XYZTLorentzVector pos = math::XYZTLorentzVector(gsf->vx(), gsf->vy(), gsf->vz(), 0.); - float field_z=3.8; - BaseParticlePropagator mypart(RawParticle(mom, pos, gsf->charge()), 0, 0, field_z); - mypart.propagateToEcalEntrance(true); // true only first half loop , false more than one loop - bool reach_ECAL = mypart.getSuccess(); // 0 does not reach ECAL, 1 yes barrel, 2 yes endcaps + if (gsf.isNonnull()) { + reco::SuperClusterRef sc = ele->core()->superCluster(); + if (sc.isNonnull()) { + // Propagate electron track to ECAL surface + double mass_ = 0.000511 * 0.000511; + float p2 = pow(gsf->p(), 2); + float energy = sqrt(mass_ + p2); + math::XYZTLorentzVector mom = math::XYZTLorentzVector(gsf->px(), gsf->py(), gsf->pz(), energy); + math::XYZTLorentzVector pos = math::XYZTLorentzVector(gsf->vx(), gsf->vy(), gsf->vz(), 0.); + float field_z = 3.8; + BaseParticlePropagator mypart(RawParticle(mom, pos, gsf->charge()), 0, 0, field_z); + mypart.propagateToEcalEntrance(true); // true only first half loop , false more than one loop + bool reach_ECAL = mypart.getSuccess(); // 0 does not reach ECAL, 1 yes barrel, 2 yes endcaps - // ECAL entry point for track - GlobalPoint ecal_pos(mypart.particle().vertex().x(), mypart.particle().vertex().y(), mypart.particle().vertex().z()); + // ECAL entry point for track + GlobalPoint ecal_pos( + mypart.particle().vertex().x(), mypart.particle().vertex().y(), mypart.particle().vertex().z()); - // Iterate through ECAL clusters and sort in energy - int clusNum=0; - float maxEne1=-1; - float maxEne2=-1; - int i1=-1; - int i2=-1; - try{ - if(sc->clustersSize()>0 && sc->clustersBegin()!=sc->clustersEnd()){ - for(auto& cluster : sc->clusters()) { - if (cluster->energy() > maxEne1){ - maxEne1=cluster->energy(); - i1=clusNum; - } - clusNum++; - } - if(sc->clustersSize()>1){ - clusNum=0; - for(auto& cluster : sc->clusters()) { - if (clusNum!=i1) { - if (cluster->energy() > maxEne2){ - maxEne2=cluster->energy(); - i2=clusNum; - } - } - clusNum++; - } - } - } // loop over clusters - } catch(...) { - std::cout<<"exception caught clusNum="<clustersSize()<<" energy="<< sc->energy()<clustersSize() > 0 && sc->clustersBegin() != sc->clustersEnd()) { + for (auto& cluster : sc->clusters()) { + if (cluster->energy() > maxEne1) { + maxEne1 = cluster->energy(); + i1 = clusNum; + } + clusNum++; + } + if (sc->clustersSize() > 1) { + clusNum = 0; + for (auto& cluster : sc->clusters()) { + if (clusNum != i1) { + if (cluster->energy() > maxEne2) { + maxEne2 = cluster->energy(); + i2 = clusNum; + } + } + clusNum++; + } + } + } // loop over clusters + } catch (...) { + std::cout << "exception caught clusNum=" << clusNum << " clus size" << sc->clustersSize() + << " energy=" << sc->energy() << std::endl; + } - // Initializations - sc_clus1_nxtal = -999.; - sc_clus1_dphi = -999.; - sc_clus2_dphi = -999.; - sc_clus1_deta = -999.; - sc_clus2_deta = -999.; - sc_clus1_E = -999.; - sc_clus2_E = -999.; - sc_clus1_E_ov_p = -999.; - sc_clus2_E_ov_p = -999.; + // Initializations + sc_clus1_nxtal = -999.; + sc_clus1_dphi = -999.; + sc_clus2_dphi = -999.; + sc_clus1_deta = -999.; + sc_clus2_deta = -999.; + sc_clus1_E = -999.; + sc_clus2_E = -999.; + sc_clus1_E_ov_p = -999.; + sc_clus2_E_ov_p = -999.; - // track-clusters match - clusNum=0; - try { - if(sc->clustersSize()>0&& sc->clustersBegin()!=sc->clustersEnd()){ - for(auto& cluster : sc->clusters()) { - double pi_=3.1415926535; - float deta = std::fabs(ecal_pos.eta()-cluster->eta()) ; - float dphi = std::fabs(ecal_pos.phi()-cluster->phi()); - if (dphi > pi_) dphi -= 2 * pi_; - if (ecal_pos.phi()-cluster->phi()<0) dphi=-dphi; - if (ecal_pos.eta()-cluster->eta()<0) deta=-deta; + // track-clusters match + clusNum = 0; + try { + if (sc->clustersSize() > 0 && sc->clustersBegin() != sc->clustersEnd()) { + for (auto& cluster : sc->clusters()) { + double pi_ = 3.1415926535; + float deta = std::fabs(ecal_pos.eta() - cluster->eta()); + float dphi = std::fabs(ecal_pos.phi() - cluster->phi()); + if (dphi > pi_) + dphi -= 2 * pi_; + if (ecal_pos.phi() - cluster->phi() < 0) + dphi = -dphi; + if (ecal_pos.eta() - cluster->eta() < 0) + deta = -deta; - if (clusNum==i1) { - sc_clus1_E = cluster->energy(); - if(gsf->pMode()>0) sc_clus1_E_ov_p = cluster->energy()/gsf->pMode(); - sc_clus1_nxtal = (float)cluster->size(); - if (reach_ECAL>0){ - sc_clus1_deta = deta; - sc_clus1_dphi = dphi; - } - } else if (clusNum==i2) { - sc_clus2_E = cluster->energy(); - if(gsf->pMode()>0) sc_clus2_E_ov_p = cluster->energy()/gsf->pMode(); - if (reach_ECAL>0){ - sc_clus2_deta = deta; - sc_clus2_dphi = dphi; - } - } - clusNum++; - } - } - } catch(...) { - std::cout<<"caught an exception"<energy(); + if (gsf->pMode() > 0) + sc_clus1_E_ov_p = cluster->energy() / gsf->pMode(); + sc_clus1_nxtal = (float)cluster->size(); + if (reach_ECAL > 0) { + sc_clus1_deta = deta; + sc_clus1_dphi = dphi; + } + } else if (clusNum == i2) { + sc_clus2_E = cluster->energy(); + if (gsf->pMode() > 0) + sc_clus2_E_ov_p = cluster->energy() / gsf->pMode(); + if (reach_ECAL > 0) { + sc_clus2_deta = deta; + sc_clus2_dphi = dphi; + } + } + clusNum++; + } + } + } catch (...) { + std::cout << "caught an exception" << std::endl; + } + } } } // clusters // Out-of-range - if (eid_rho<0) eid_rho=0; - if (eid_rho>100) eid_rho=100; - if (eid_sc_eta<-5) eid_sc_eta=-5; - if (eid_sc_eta>5) eid_sc_eta=5; - if (eid_shape_full5x5_r9<0) eid_shape_full5x5_r9=0; - if (eid_shape_full5x5_r9>2) eid_shape_full5x5_r9=2; - if (eid_sc_etaWidth<0) eid_sc_etaWidth=0; - if (eid_sc_etaWidth>3.14) eid_sc_etaWidth=3.14; - if (eid_sc_phiWidth<0) eid_sc_phiWidth=0; - if (eid_sc_phiWidth>3.14) eid_sc_phiWidth=3.14; - if (eid_shape_full5x5_HoverE<0) eid_shape_full5x5_HoverE=0; - if (eid_shape_full5x5_HoverE>50) eid_shape_full5x5_HoverE=50; - if (eid_trk_nhits<-1) eid_trk_nhits=-1; - if (eid_trk_nhits>50) eid_trk_nhits=50; - if (eid_trk_chi2red<-1) eid_trk_chi2red=-1; - if (eid_trk_chi2red>50) eid_trk_chi2red=50; - if (eid_gsf_chi2red<-1) eid_gsf_chi2red=-1; - if (eid_gsf_chi2red>100) eid_gsf_chi2red=100; - if (eid_brem_frac<0) eid_brem_frac=-1; - if (eid_brem_frac>1) eid_brem_frac=1; - if (eid_gsf_nhits<-1) eid_gsf_nhits=-1; - if (eid_gsf_nhits>50) eid_gsf_nhits=50; - if (eid_match_SC_EoverP<0) eid_match_SC_EoverP=0; - if (eid_match_SC_EoverP>100) eid_match_SC_EoverP=100; - if (eid_match_eclu_EoverP<-1.) eid_match_eclu_EoverP=-1.; - if (eid_match_eclu_EoverP>1.) eid_match_eclu_EoverP=1.; - if (eid_match_SC_dEta<-10) eid_match_SC_dEta=-10; - if (eid_match_SC_dEta>10) eid_match_SC_dEta=10; - if (eid_match_SC_dPhi<-3.14) eid_match_SC_dPhi=-3.14; - if (eid_match_SC_dPhi>3.14) eid_match_SC_dPhi=3.14; - if (eid_match_seed_dEta<-10) eid_match_seed_dEta=-10; - if (eid_match_seed_dEta>10) eid_match_seed_dEta=10; - if (eid_sc_E<0) eid_sc_E=0; - if (eid_sc_E>1000) eid_sc_E=1000; - if (eid_trk_p<-1) eid_trk_p=-1; - if (eid_trk_p>1000) eid_trk_p=1000; - if (gsf_mode_p<0) gsf_mode_p=0; - if (gsf_mode_p>1000) gsf_mode_p=1000; - if (core_shFracHits<0) core_shFracHits=0; - if (core_shFracHits>1) core_shFracHits=1; - if (gsf_bdtout1<-20) gsf_bdtout1=-20; - if (gsf_bdtout1>20) gsf_bdtout1=20; - if (gsf_dr<0) gsf_dr=5; - if (gsf_dr>5) gsf_dr=5; - if (trk_dr<0) trk_dr=5; - if (trk_dr>5) trk_dr=5; - if (sc_Nclus<0) sc_Nclus=0; - if (sc_Nclus>20) sc_Nclus=20; - if (sc_clus1_nxtal<0) sc_clus1_nxtal=0; - if (sc_clus1_nxtal>100) sc_clus1_nxtal=100; - if (sc_clus1_dphi<-3.14) sc_clus1_dphi=-5; - if (sc_clus1_dphi>3.14) sc_clus1_dphi=5; - if (sc_clus2_dphi<-3.14) sc_clus2_dphi=-5; - if (sc_clus2_dphi>3.14) sc_clus2_dphi=5; - if (sc_clus1_deta<-5) sc_clus1_deta=-5; - if (sc_clus1_deta>5) sc_clus1_deta=5; - if (sc_clus2_deta<-5) sc_clus2_deta=-5; - if (sc_clus2_deta>5) sc_clus2_deta=5; - if (sc_clus1_E<0) sc_clus1_E=0; - if (sc_clus1_E>1000) sc_clus1_E=1000; - if (sc_clus2_E<0) sc_clus2_E=0; - if (sc_clus2_E>1000) sc_clus2_E=1000; - if (sc_clus1_E_ov_p<0) sc_clus1_E_ov_p=-1; - if (sc_clus2_E_ov_p<0) sc_clus2_E_ov_p=-1; + if (eid_rho < 0) + eid_rho = 0; + if (eid_rho > 100) + eid_rho = 100; + if (eid_sc_eta < -5) + eid_sc_eta = -5; + if (eid_sc_eta > 5) + eid_sc_eta = 5; + if (eid_shape_full5x5_r9 < 0) + eid_shape_full5x5_r9 = 0; + if (eid_shape_full5x5_r9 > 2) + eid_shape_full5x5_r9 = 2; + if (eid_sc_etaWidth < 0) + eid_sc_etaWidth = 0; + if (eid_sc_etaWidth > 3.14) + eid_sc_etaWidth = 3.14; + if (eid_sc_phiWidth < 0) + eid_sc_phiWidth = 0; + if (eid_sc_phiWidth > 3.14) + eid_sc_phiWidth = 3.14; + if (eid_shape_full5x5_HoverE < 0) + eid_shape_full5x5_HoverE = 0; + if (eid_shape_full5x5_HoverE > 50) + eid_shape_full5x5_HoverE = 50; + if (eid_trk_nhits < -1) + eid_trk_nhits = -1; + if (eid_trk_nhits > 50) + eid_trk_nhits = 50; + if (eid_trk_chi2red < -1) + eid_trk_chi2red = -1; + if (eid_trk_chi2red > 50) + eid_trk_chi2red = 50; + if (eid_gsf_chi2red < -1) + eid_gsf_chi2red = -1; + if (eid_gsf_chi2red > 100) + eid_gsf_chi2red = 100; + if (eid_brem_frac < 0) + eid_brem_frac = -1; + if (eid_brem_frac > 1) + eid_brem_frac = 1; + if (eid_gsf_nhits < -1) + eid_gsf_nhits = -1; + if (eid_gsf_nhits > 50) + eid_gsf_nhits = 50; + if (eid_match_SC_EoverP < 0) + eid_match_SC_EoverP = 0; + if (eid_match_SC_EoverP > 100) + eid_match_SC_EoverP = 100; + if (eid_match_eclu_EoverP < -1.) + eid_match_eclu_EoverP = -1.; + if (eid_match_eclu_EoverP > 1.) + eid_match_eclu_EoverP = 1.; + if (eid_match_SC_dEta < -10) + eid_match_SC_dEta = -10; + if (eid_match_SC_dEta > 10) + eid_match_SC_dEta = 10; + if (eid_match_SC_dPhi < -3.14) + eid_match_SC_dPhi = -3.14; + if (eid_match_SC_dPhi > 3.14) + eid_match_SC_dPhi = 3.14; + if (eid_match_seed_dEta < -10) + eid_match_seed_dEta = -10; + if (eid_match_seed_dEta > 10) + eid_match_seed_dEta = 10; + if (eid_sc_E < 0) + eid_sc_E = 0; + if (eid_sc_E > 1000) + eid_sc_E = 1000; + if (eid_trk_p < -1) + eid_trk_p = -1; + if (eid_trk_p > 1000) + eid_trk_p = 1000; + if (gsf_mode_p < 0) + gsf_mode_p = 0; + if (gsf_mode_p > 1000) + gsf_mode_p = 1000; + if (core_shFracHits < 0) + core_shFracHits = 0; + if (core_shFracHits > 1) + core_shFracHits = 1; + if (gsf_bdtout1 < -20) + gsf_bdtout1 = -20; + if (gsf_bdtout1 > 20) + gsf_bdtout1 = 20; + if (gsf_dr < 0) + gsf_dr = 5; + if (gsf_dr > 5) + gsf_dr = 5; + if (trk_dr < 0) + trk_dr = 5; + if (trk_dr > 5) + trk_dr = 5; + if (sc_Nclus < 0) + sc_Nclus = 0; + if (sc_Nclus > 20) + sc_Nclus = 20; + if (sc_clus1_nxtal < 0) + sc_clus1_nxtal = 0; + if (sc_clus1_nxtal > 100) + sc_clus1_nxtal = 100; + if (sc_clus1_dphi < -3.14) + sc_clus1_dphi = -5; + if (sc_clus1_dphi > 3.14) + sc_clus1_dphi = 5; + if (sc_clus2_dphi < -3.14) + sc_clus2_dphi = -5; + if (sc_clus2_dphi > 3.14) + sc_clus2_dphi = 5; + if (sc_clus1_deta < -5) + sc_clus1_deta = -5; + if (sc_clus1_deta > 5) + sc_clus1_deta = 5; + if (sc_clus2_deta < -5) + sc_clus2_deta = -5; + if (sc_clus2_deta > 5) + sc_clus2_deta = 5; + if (sc_clus1_E < 0) + sc_clus1_E = 0; + if (sc_clus1_E > 1000) + sc_clus1_E = 1000; + if (sc_clus2_E < 0) + sc_clus2_E = 0; + if (sc_clus2_E > 1000) + sc_clus2_E = 1000; + if (sc_clus1_E_ov_p < 0) + sc_clus1_E_ov_p = -1; + if (sc_clus2_E_ov_p < 0) + sc_clus2_E_ov_p = -1; // Set contents of vector - std::vector output = { - eid_rho, - eid_sc_eta, - eid_shape_full5x5_r9, - eid_sc_etaWidth, - eid_sc_phiWidth, - eid_shape_full5x5_HoverE, - eid_trk_nhits, - eid_trk_chi2red, - eid_gsf_chi2red, - eid_brem_frac, - eid_gsf_nhits, - eid_match_SC_EoverP, - eid_match_eclu_EoverP, - eid_match_SC_dEta, - eid_match_SC_dPhi, - eid_match_seed_dEta, - eid_sc_E, - eid_trk_p, - gsf_mode_p, - core_shFracHits, - gsf_bdtout1, - gsf_dr, - trk_dr, - sc_Nclus, - sc_clus1_nxtal, - sc_clus1_dphi, - sc_clus2_dphi, - sc_clus1_deta, - sc_clus2_deta, - sc_clus1_E, - sc_clus2_E, - sc_clus1_E_ov_p, - sc_clus2_E_ov_p - }; + std::vector output = {eid_rho, + eid_sc_eta, + eid_shape_full5x5_r9, + eid_sc_etaWidth, + eid_sc_phiWidth, + eid_shape_full5x5_HoverE, + eid_trk_nhits, + eid_trk_chi2red, + eid_gsf_chi2red, + eid_brem_frac, + eid_gsf_nhits, + eid_match_SC_EoverP, + eid_match_eclu_EoverP, + eid_match_SC_dEta, + eid_match_SC_dPhi, + eid_match_seed_dEta, + eid_sc_E, + eid_trk_p, + gsf_mode_p, + core_shFracHits, + gsf_bdtout1, + gsf_dr, + trk_dr, + sc_Nclus, + sc_clus1_nxtal, + sc_clus1_dphi, + sc_clus2_dphi, + sc_clus1_deta, + sc_clus2_deta, + sc_clus1_E, + sc_clus2_E, + sc_clus1_E_ov_p, + sc_clus2_E_ov_p}; return output; - } - + //////////////////////////////////////////////////////////////////////////////// // - std::vector features( edm::Ref< std::vector > const& ele, float rho, float unbiased ) { - return features(edm::refToPtr(ele),rho,unbiased); + std::vector features(edm::Ref > const& ele, float rho, float unbiased) { + return features(edm::refToPtr(ele), rho, unbiased); } - + //////////////////////////////////////////////////////////////////////////////// // - std::vector features( edm::Ref< edm::View > const& ele, float rho, float unbiased ) { - return features(edm::refToPtr(ele),rho,unbiased); + std::vector features(edm::Ref > const& ele, float rho, float unbiased) { + return features(edm::refToPtr(ele), rho, unbiased); } - -} // namespace + +} // namespace lowptgsfeleid From 14635b12da1f2a528d2dee02ee75986911849c28 Mon Sep 17 00:00:00 2001 From: bainbrid Date: Thu, 13 Aug 2020 10:56:50 +0200 Subject: [PATCH 6/7] Joosep Pata comments --- .../interface/LowPtGsfElectronFeatures.h | 7 +--- .../plugins/LowPtGsfElectronIDProducer.cc | 24 +++++++---- .../src/LowPtGsfElectronFeatures.cc | 42 +++++++++---------- 3 files changed, 40 insertions(+), 33 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h b/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h index c50fea353ca64..f2d64aff698ba 100644 --- a/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h +++ b/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h @@ -1,19 +1,16 @@ #ifndef RecoEgamma_EgammaElectronProducers_LowPtGsfElectronFeatures_h #define RecoEgamma_EgammaElectronProducers_LowPtGsfElectronFeatures_h +#include "DataFormats/BeamSpot/interface/BeamSpot.h" #include "DataFormats/Common/interface/Ptr.h" #include "DataFormats/Common/interface/Ref.h" #include "DataFormats/Common/interface/RefToPtr.h" #include "DataFormats/Common/interface/View.h" #include "DataFormats/EgammaCandidates/interface/GsfElectron.h" +#include "DataFormats/ParticleFlowReco/interface/PreId.h" #include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h" #include -namespace reco { - class BeamSpot; - class PreId; -} // namespace reco - namespace lowptgsfeleseed { std::vector features(const reco::PreId& ecal, diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc index 22808b2794d54..13455c56fe220 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc @@ -31,7 +31,7 @@ class LowPtGsfElectronIDProducer final : public edm::global::EDProducer<> { static void fillDescriptions(edm::ConfigurationDescriptions&); private: - double eval(const std::string& name, const edm::Ptr, double rho, float unbiased) const; + double eval(const std::string& name, const edm::Ptr&, double rho, float unbiased) const; const edm::EDGetTokenT > gsfElectrons_; const edm::EDGetTokenT rho_; @@ -78,21 +78,30 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const edm::Handle rho; event.getByToken(rho_, rho); if (!rho.isValid()) { - edm::LogError("Problem with rho handle"); + std::ostringstream os; + os << "Problem accessing rho collection for low-pT electrons" << std::endl; + edm::LogError("InvalidHandle") << os.str(); + throw cms::Exception("InvalidHandle", os.str()); } // Retrieve GsfElectrons from Event edm::Handle > gsfElectrons; event.getByToken(gsfElectrons_, gsfElectrons); if (!gsfElectrons.isValid()) { - edm::LogError("Problem with gsfElectrons handle"); + std::ostringstream os; + os << "Problem accessing low-pT gsfElectrons collection" << std::endl; + edm::LogError("InvalidHandle") << os.str(); + throw cms::Exception("InvalidHandle", os.str()); } // ElectronSeed unbiased BDT edm::Handle > unbiasedH; event.getByToken(unbiased_, unbiasedH); if (!unbiasedH.isValid()) { - edm::LogError("Problem with unbiased handle"); + std::ostringstream os; + os << "Problem accessing low-pT 'unbiased' ElectronSeed collection" << std::endl; + edm::LogError("InvalidHandle") << os.str(); + throw cms::Exception("InvalidHandle", os.str()); } // Iterate through Electrons, evaluate BDT, and store result @@ -106,7 +115,7 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const if (ele->core().isNull()) { continue; } - reco::GsfTrackRef gsf = ele->core()->gsfTrack(); + const auto& gsf = ele->core()->gsfTrack(); // reco::GsfTrackRef if (gsf.isNull()) { continue; } @@ -124,13 +133,14 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const edm::ValueMap::Filler filler(*ptr); filler.insert(gsfElectrons, output[iname].begin(), output[iname].end()); filler.fill(); - //reco::GsfElectronRef ele(gsfElectrons, 0); event.put(std::move(ptr), names_[iname]); } } +////////////////////////////////////////////////////////////////////////////////////////// +// double LowPtGsfElectronIDProducer::eval(const std::string& name, - const edm::Ptr ele, + const edm::Ptr& ele, double rho, float unbiased) const { auto iter = std::find(names_.begin(), names_.end(), name); diff --git a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc index 675beccf23048..93a347a3d8f38 100644 --- a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc +++ b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc @@ -1,13 +1,11 @@ #include "RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronFeatures.h" #include "CommonTools/BaseParticlePropagator/interface/BaseParticlePropagator.h" -#include "DataFormats/BeamSpot/interface/BeamSpot.h" #include "DataFormats/GsfTrackReco/interface/GsfTrack.h" #include "DataFormats/ParticleFlowReco/interface/PFCluster.h" #include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h" -#include "DataFormats/ParticleFlowReco/interface/PreId.h" #include "DataFormats/TrackReco/interface/Track.h" #include "DataFormats/TrackReco/interface/TrackFwd.h" -#include +#include "TVector3.h" namespace lowptgsfeleseed { @@ -45,7 +43,7 @@ namespace lowptgsfeleseed { float trk_dxy_sig_ = -1.; // must be last (not used by unbiased model) // Tracks - reco::TrackRef trk = ecal.trackRef(); + const auto& trk = ecal.trackRef(); // reco::TrackRef if (trk.isNonnull()) { trk_pt_ = trk->pt(); trk_eta_ = trk->eta(); @@ -64,14 +62,14 @@ namespace lowptgsfeleseed { rho_ = static_cast(rho); // ECAL clusters - reco::PFClusterRef ecal_clu = ecal.clusterRef(); + const auto& ecal_clu = ecal.clusterRef(); // reco::PFClusterRef if (ecal_clu.isNonnull()) { ktf_ecal_cluster_e_ = ecal_clu->energy(); ktf_ecal_cluster_deta_ = ecal.geomMatching()[0]; ktf_ecal_cluster_dphi_ = ecal.geomMatching()[1]; ktf_ecal_cluster_e3x3_ = tools.e3x3(*ecal_clu); ktf_ecal_cluster_e5x5_ = tools.e5x5(*ecal_clu); - auto covs = tools.localCovariances(*ecal_clu); + const auto& covs = tools.localCovariances(*ecal_clu); ktf_ecal_cluster_covEtaEta_ = covs[0]; ktf_ecal_cluster_covEtaPhi_ = covs[1]; ktf_ecal_cluster_covPhiPhi_ = covs[2]; @@ -86,7 +84,7 @@ namespace lowptgsfeleseed { } // HCAL clusters - reco::PFClusterRef hcal_clu = hcal.clusterRef(); + const auto& hcal_clu = hcal.clusterRef(); // reco::PFClusterRef if (hcal_clu.isNonnull()) { ktf_hcal_cluster_e_ = hcal_clu->energy(); ktf_hcal_cluster_deta_ = hcal.geomMatching()[0]; @@ -168,7 +166,7 @@ namespace lowptgsfeleid { // KF tracks if (ele->core().isNonnull()) { - reco::TrackRef trk = ele->closestCtfTrackRef(); + const auto& trk = ele->closestCtfTrackRef(); // reco::TrackRef if (trk.isNonnull()) { eid_trk_p = (float)trk->p(); eid_trk_nhits = (float)trk->found(); @@ -183,7 +181,7 @@ namespace lowptgsfeleid { // GSF tracks if (ele->core().isNonnull()) { - reco::GsfTrackRef gsf = ele->core()->gsfTrack(); + const auto& gsf = ele->core()->gsfTrack(); // reco::GsfTrackRef if (gsf.isNonnull()) { gsf_mode_p = gsf->pMode(); eid_gsf_nhits = (float)gsf->found(); @@ -198,7 +196,7 @@ namespace lowptgsfeleid { // Super clusters if (ele->core().isNonnull()) { - reco::SuperClusterRef sc = ele->core()->superCluster(); + const auto& sc = ele->core()->superCluster(); // reco::SuperClusterRef if (sc.isNonnull()) { eid_sc_E = sc->energy(); eid_sc_eta = sc->eta(); @@ -236,9 +234,9 @@ namespace lowptgsfeleid { // Clusters if (ele->core().isNonnull()) { - reco::GsfTrackRef gsf = ele->core()->gsfTrack(); + const auto& gsf = ele->core()->gsfTrack(); // reco::GsfTrackRef if (gsf.isNonnull()) { - reco::SuperClusterRef sc = ele->core()->superCluster(); + const auto& sc = ele->core()->superCluster(); // reco::SuperClusterRef if (sc.isNonnull()) { // Propagate electron track to ECAL surface double mass_ = 0.000511 * 0.000511; @@ -263,7 +261,7 @@ namespace lowptgsfeleid { int i2 = -1; try { if (sc->clustersSize() > 0 && sc->clustersBegin() != sc->clustersEnd()) { - for (auto& cluster : sc->clusters()) { + for (const auto& cluster : sc->clusters()) { if (cluster->energy() > maxEne1) { maxEne1 = cluster->energy(); i1 = clusNum; @@ -272,7 +270,7 @@ namespace lowptgsfeleid { } if (sc->clustersSize() > 1) { clusNum = 0; - for (auto& cluster : sc->clusters()) { + for (const auto& cluster : sc->clusters()) { if (clusNum != i1) { if (cluster->energy() > maxEne2) { maxEne2 = cluster->energy(); @@ -284,8 +282,11 @@ namespace lowptgsfeleid { } } // loop over clusters } catch (...) { - std::cout << "exception caught clusNum=" << clusNum << " clus size" << sc->clustersSize() - << " energy=" << sc->energy() << std::endl; + edm::LogError("SuperClusters") << "Problem accessing SC constituent clusters:" + << " clusNum=" << clusNum + << " clustersSize=" << sc->clustersSize() + << " energy=" << sc->energy() + << std::endl; } // Initializations @@ -303,12 +304,11 @@ namespace lowptgsfeleid { clusNum = 0; try { if (sc->clustersSize() > 0 && sc->clustersBegin() != sc->clustersEnd()) { - for (auto& cluster : sc->clusters()) { - double pi_ = 3.1415926535; + for (const auto& cluster : sc->clusters()) { float deta = std::fabs(ecal_pos.eta() - cluster->eta()); float dphi = std::fabs(ecal_pos.phi() - cluster->phi()); - if (dphi > pi_) - dphi -= 2 * pi_; + if (dphi > M_PI) + dphi -= 2 * M_PI; if (ecal_pos.phi() - cluster->phi() < 0) dphi = -dphi; if (ecal_pos.eta() - cluster->eta() < 0) @@ -336,7 +336,7 @@ namespace lowptgsfeleid { } } } catch (...) { - std::cout << "caught an exception" << std::endl; + edm::LogError("SuperClusters") << "Problem with track-cluster matching" << std::endl; } } } From c9e11d9ca5f4f0377276949e604606518fff64da Mon Sep 17 00:00:00 2001 From: bainbrid Date: Thu, 13 Aug 2020 12:01:43 +0200 Subject: [PATCH 7/7] scram build code-format --- .../plugins/LowPtGsfElectronIDProducer.cc | 2 +- .../src/LowPtGsfElectronFeatures.cc | 22 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc index 13455c56fe220..ca46d4f4100d5 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronIDProducer.cc @@ -115,7 +115,7 @@ void LowPtGsfElectronIDProducer::produce(edm::StreamID, edm::Event& event, const if (ele->core().isNull()) { continue; } - const auto& gsf = ele->core()->gsfTrack(); // reco::GsfTrackRef + const auto& gsf = ele->core()->gsfTrack(); // reco::GsfTrackRef if (gsf.isNull()) { continue; } diff --git a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc index 93a347a3d8f38..a346367b7900f 100644 --- a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc +++ b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronFeatures.cc @@ -43,7 +43,7 @@ namespace lowptgsfeleseed { float trk_dxy_sig_ = -1.; // must be last (not used by unbiased model) // Tracks - const auto& trk = ecal.trackRef(); // reco::TrackRef + const auto& trk = ecal.trackRef(); // reco::TrackRef if (trk.isNonnull()) { trk_pt_ = trk->pt(); trk_eta_ = trk->eta(); @@ -62,7 +62,7 @@ namespace lowptgsfeleseed { rho_ = static_cast(rho); // ECAL clusters - const auto& ecal_clu = ecal.clusterRef(); // reco::PFClusterRef + const auto& ecal_clu = ecal.clusterRef(); // reco::PFClusterRef if (ecal_clu.isNonnull()) { ktf_ecal_cluster_e_ = ecal_clu->energy(); ktf_ecal_cluster_deta_ = ecal.geomMatching()[0]; @@ -84,7 +84,7 @@ namespace lowptgsfeleseed { } // HCAL clusters - const auto& hcal_clu = hcal.clusterRef(); // reco::PFClusterRef + const auto& hcal_clu = hcal.clusterRef(); // reco::PFClusterRef if (hcal_clu.isNonnull()) { ktf_hcal_cluster_e_ = hcal_clu->energy(); ktf_hcal_cluster_deta_ = hcal.geomMatching()[0]; @@ -166,7 +166,7 @@ namespace lowptgsfeleid { // KF tracks if (ele->core().isNonnull()) { - const auto& trk = ele->closestCtfTrackRef(); // reco::TrackRef + const auto& trk = ele->closestCtfTrackRef(); // reco::TrackRef if (trk.isNonnull()) { eid_trk_p = (float)trk->p(); eid_trk_nhits = (float)trk->found(); @@ -181,7 +181,7 @@ namespace lowptgsfeleid { // GSF tracks if (ele->core().isNonnull()) { - const auto& gsf = ele->core()->gsfTrack(); // reco::GsfTrackRef + const auto& gsf = ele->core()->gsfTrack(); // reco::GsfTrackRef if (gsf.isNonnull()) { gsf_mode_p = gsf->pMode(); eid_gsf_nhits = (float)gsf->found(); @@ -196,7 +196,7 @@ namespace lowptgsfeleid { // Super clusters if (ele->core().isNonnull()) { - const auto& sc = ele->core()->superCluster(); // reco::SuperClusterRef + const auto& sc = ele->core()->superCluster(); // reco::SuperClusterRef if (sc.isNonnull()) { eid_sc_E = sc->energy(); eid_sc_eta = sc->eta(); @@ -234,9 +234,9 @@ namespace lowptgsfeleid { // Clusters if (ele->core().isNonnull()) { - const auto& gsf = ele->core()->gsfTrack(); // reco::GsfTrackRef + const auto& gsf = ele->core()->gsfTrack(); // reco::GsfTrackRef if (gsf.isNonnull()) { - const auto& sc = ele->core()->superCluster(); // reco::SuperClusterRef + const auto& sc = ele->core()->superCluster(); // reco::SuperClusterRef if (sc.isNonnull()) { // Propagate electron track to ECAL surface double mass_ = 0.000511 * 0.000511; @@ -283,10 +283,8 @@ namespace lowptgsfeleid { } // loop over clusters } catch (...) { edm::LogError("SuperClusters") << "Problem accessing SC constituent clusters:" - << " clusNum=" << clusNum - << " clustersSize=" << sc->clustersSize() - << " energy=" << sc->energy() - << std::endl; + << " clusNum=" << clusNum << " clustersSize=" << sc->clustersSize() + << " energy=" << sc->energy() << std::endl; } // Initializations