From 3f6ee4ce47afe15ce1a7112fe52cf502800c763f Mon Sep 17 00:00:00 2001 From: Michal Bluj Date: Tue, 23 Jun 2020 10:50:04 +0200 Subject: [PATCH 1/6] templated version of anti-e MVA6 tauID --- .../RecoTau/interface/AntiElectronIDMVA6.h | 167 +- .../TauDiscriminationAgainstElectronMVA6.cc | 312 ++++ RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc | 1482 ++++++----------- 3 files changed, 871 insertions(+), 1090 deletions(-) create mode 100644 RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronMVA6.cc diff --git a/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h b/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h index 0a6473d62d6ad..bb169a71db71d 100644 --- a/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h +++ b/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h @@ -4,6 +4,7 @@ // Helper Class for applying MVA anti-electron discrimination // // Authors: F.Colombo, C.Veelken +// M. Bluj (template version) //-------------------------------------------------------------------------------------------------- #ifndef RECOTAUTAG_RECOTAU_AntiElectronIDMVA6_H @@ -32,6 +33,59 @@ #include +struct TauVars { + float tauPt; + float tauEtaAtEcalEntrance; + float tauPhi; + float tauLeadChargedPFCandPt; + float tauLeadChargedPFCandEtaAtEcalEntrance; + float tauEmFraction; + float tauLeadPFChargedHadrHoP; + float tauLeadPFChargedHadrEoP; + float tauVisMassIn; + float taudCrackEta; + float taudCrackPhi; + float tauHasGsf; +}; +struct TauGammaVecs { + std::vector gammasdEtaInSigCone; + std::vector gammasdPhiInSigCone; + std::vector gammasPtInSigCone; + std::vector gammasdEtaOutSigCone; + std::vector gammasdPhiOutSigCone; + std::vector gammasPtOutSigCone; +}; +struct TauGammaMoms { + int tauSignalPFGammaCandsIn; + int tauSignalPFGammaCandsOut; + float tauGammaEtaMomIn; + float tauGammaEtaMomOut; + float tauGammaPhiMomIn; + float tauGammaPhiMomOut; + float tauGammaEnFracIn; + float tauGammaEnFracOut; +}; +struct EleVars { + float elecEta; + float elecPhi; + float elecEtotOverPin; + float elecChi2NormGSF; + float elecChi2NormKF; + float elecGSFNumHits; + float elecKFNumHits; + float elecGSFTrackResol; + float elecGSFTracklnPt; + float elecPin; + float elecPout; + float elecEecal; + float elecDeltaEta; + float elecDeltaPhi; + float elecMvaInSigmaEtaEta; + float elecMvaInHadEnergy; + float elecMvaInDeltaEta; +}; + +template class AntiElectronIDMVA6 { public: AntiElectronIDMVA6(const edm::ParameterSet&); @@ -39,91 +93,26 @@ class AntiElectronIDMVA6 { void beginEvent(const edm::Event&, const edm::EventSetup&); - double MVAValue(Float_t TauPt, - Float_t TauEtaAtEcalEntrance, - Float_t TauPhi, - Float_t TauLeadChargedPFCandPt, - Float_t TauLeadChargedPFCandEtaAtEcalEntrance, - Float_t TauEmFraction, - Float_t TauLeadPFChargedHadrHoP, - Float_t TauLeadPFChargedHadrEoP, - Float_t TauVisMassIn, - Float_t TaudCrackEta, - Float_t TaudCrackPhi, - Float_t TauHasGsf, - Int_t TauSignalPFGammaCandsIn, - Int_t TauSignalPFGammaCandsOut, - const std::vector& GammasdEtaInSigCone, - const std::vector& GammasdPhiInSigCone, - const std::vector& GammasPtInSigCone, - const std::vector& GammasdEtaOutSigCone, - const std::vector& GammasdPhiOutSigCone, - const std::vector& GammasPtOutSigCone, - Float_t ElecEta, - Float_t ElecPhi, - Float_t ElecEtotOverPin, - Float_t ElecChi2NormGSF, - Float_t ElecChi2NormKF, - Float_t ElecGSFNumHits, - Float_t ElecKFNumHits, - Float_t ElecGSFTrackResol, - Float_t ElecGSFTracklnPt, - Float_t ElecPin, - Float_t ElecPout, - Float_t ElecEecal, - Float_t ElecDeltaEta, - Float_t ElecDeltaPhi, - Float_t ElecMvaInSigmaEtaEta, - Float_t ElecMvaInHadEnergy, - Float_t ElecMvaInDeltaEta); - - double MVAValue(Float_t TauPt, - Float_t TauEtaAtEcalEntrance, - Float_t TauPhi, - Float_t TauLeadChargedPFCandPt, - Float_t TauLeadChargedPFCandEtaAtEcalEntrance, - Float_t TauEmFraction, - Float_t TauLeadPFChargedHadrHoP, - Float_t TauLeadPFChargedHadrEoP, - Float_t TauVisMassIn, - Float_t TaudCrackEta, - Float_t TaudCrackPhi, - Float_t TauHasGsf, - Int_t TauSignalPFGammaCandsIn, - Int_t TauSignalPFGammaCandsOut, - Float_t TauGammaEtaMomIn, - Float_t TauGammaEtaMomOut, - Float_t TauGammaPhiMomIn, - Float_t TauGammaPhiMomOut, - Float_t TauGammaEnFracIn, - Float_t TauGammaEnFracOut, - Float_t ElecEta, - Float_t ElecPhi, - Float_t ElecEtotOverPin, - Float_t ElecChi2NormGSF, - Float_t ElecChi2NormKF, - Float_t ElecGSFNumHits, - Float_t ElecKFNumHits, - Float_t ElecGSFTrackResol, - Float_t ElecGSFTracklnPt, - Float_t ElecPin, - Float_t ElecPout, - Float_t ElecEecal, - Float_t ElecDeltaEta, - Float_t ElecDeltaPhi, - Float_t ElecMvaInSigmaEtaEta, - Float_t ElecMvaInHadEnergy, - Float_t ElecMvaInDeltaEta); + double MVAValue(const TauVars& tauVars, + const TauGammaVecs& tauGammaVecs, + const EleVars& eleVars); - // this function can be called for all categories - double MVAValue(const reco::PFTau& thePFTau, const reco::GsfElectron& theGsfEle); - // this function can be called for category 1 only !! - double MVAValue(const reco::PFTau& thePFTau); + double MVAValue(const TauVars& tauVars, + const TauGammaMoms& tauGammaMoms, + const EleVars& eleVars); // this function can be called for all categories - double MVAValue(const pat::Tau& theTau, const pat::Electron& theEle); + double MVAValue(const TauType& theTau, const ElectronType& theEle); // this function can be called for category 1 only !! - double MVAValue(const pat::Tau& theTau); + double MVAValue(const TauType& theTau); + + // overloaded method with explicit tau type to avoid partial imlementation of full class + TauVars getTauVarsTypeSpecific(const reco::PFTau& theTau); + TauVars getTauVarsTypeSpecific(const pat::Tau& theTau); + TauVars getTauVars(const TauType& theTau); + TauGammaVecs getTauGammaVecs(const TauType& theTau); + EleVars getEleVars(const ElectronType& theEle); + // track extrapolation to ECAL entrance (used to re-calculate variables that might not be available on miniAOD) bool atECalEntrance(const reco::Candidate* part, math::XYZPoint& pos); @@ -147,14 +136,14 @@ class AntiElectronIDMVA6 { bool usePhiAtEcalEntranceExtrapolation_; - Float_t* Var_NoEleMatch_woGwoGSF_Barrel_; - Float_t* Var_NoEleMatch_wGwoGSF_Barrel_; - Float_t* Var_woGwGSF_Barrel_; - Float_t* Var_wGwGSF_Barrel_; - Float_t* Var_NoEleMatch_woGwoGSF_Endcap_; - Float_t* Var_NoEleMatch_wGwoGSF_Endcap_; - Float_t* Var_woGwGSF_Endcap_; - Float_t* Var_wGwGSF_Endcap_; + float* Var_NoEleMatch_woGwoGSF_Barrel_; + float* Var_NoEleMatch_wGwoGSF_Barrel_; + float* Var_woGwGSF_Barrel_; + float* Var_wGwGSF_Barrel_; + float* Var_NoEleMatch_woGwoGSF_Endcap_; + float* Var_NoEleMatch_wGwoGSF_Endcap_; + float* Var_woGwGSF_Endcap_; + float* Var_wGwGSF_Endcap_; const GBRForest* mva_NoEleMatch_woGwoGSF_BL_; const GBRForest* mva_NoEleMatch_wGwoGSF_BL_; diff --git a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronMVA6.cc b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronMVA6.cc new file mode 100644 index 0000000000000..db4726df8eda1 --- /dev/null +++ b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronMVA6.cc @@ -0,0 +1,312 @@ +/* class TauDiscriminationAgainstElectronMVA6 + * created : Nov 2 2015, + * revised : May 29 2020, + * Authors : Fabio Colombo (KIT) + * Anne-Catherine Le Bihan (IPHC), + * Michal Bluj (NCBJ) + */ + +#include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h" +#include "RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h" +#include "RecoTauTag/RecoTau/interface/PositionAtECalEntranceComputer.h" +#include "DataFormats/Math/interface/deltaR.h" + +template +class TauDiscriminationAgainstElectronMVA6 : public TauDiscriminationProducerBase { +public: + typedef std::vector TauCollection; + typedef edm::Ref TauRef; + typedef std::vector ElectronCollection; + + explicit TauDiscriminationAgainstElectronMVA6(const edm::ParameterSet& cfg) + : TauDiscriminationProducerBase::TauDiscriminationProducerBase(cfg), + moduleLabel_(cfg.getParameter("@module_label")), + mva_(std::make_unique >(cfg)), + Electron_token(edm::EDConsumerBase::consumes(cfg.getParameter("srcElectrons"))), //MB: full specification with prefix mandatory + vetoEcalCracks_(cfg.getParameter("vetoEcalCracks")), + verbosity_(cfg.getParameter("verbosity")) {} + + void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override { + mva_->beginEvent(evt, es); + positionAtECalEntrance_.beginEvent(es); + evt.getByToken(this->Tau_token, taus_); + evt.getByToken(Electron_token, electrons_); + } + + reco::SingleTauDiscriminatorContainer discriminate(const TauRef&) const override; + + ~TauDiscriminationAgainstElectronMVA6() override {} + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + bool isInEcalCrack(double) const; + + // Overloaded method with explicit type specification to avoid partial + //implementation of full class + std::pair getTauEtaAtECalEntrance(const reco::PFTauRef& theTauRef) const; + std::pair getTauEtaAtECalEntrance(const pat::TauRef& theTauRef) const; + + std::string moduleLabel_; + std::unique_ptr > mva_; + + edm::EDGetTokenT Electron_token; + edm::Handle electrons_; + edm::Handle taus_; + + PositionAtECalEntranceComputer positionAtECalEntrance_; + + bool vetoEcalCracks_; + + int verbosity_; +}; + +template +reco::SingleTauDiscriminatorContainer +TauDiscriminationAgainstElectronMVA6::discriminate(const TauRef& theTauRef) const { + + reco::SingleTauDiscriminatorContainer result; + result.rawValues = {1., -1.}; + double category = -1.; + bool isGsfElectronMatched = false; + + float deltaRDummy = 9.9; + + const float ECalBarrelEndcapEtaBorder = 1.479; + + std::pair tauEtaAtECalEntrance; + if (std::is_same::value || + std::is_same::value) + tauEtaAtECalEntrance = getTauEtaAtECalEntrance(theTauRef); + else + throw cms::Exception("TauDiscriminationAgainstElectronMVA6") + << "Unsupported TauType used. You must use either reco::PFTau or pat::Tau."; + + if ((*theTauRef).leadChargedHadrCand().isNonnull()) { + int numSignalGammaCandsInSigCone = 0; + for (const auto& gamma : theTauRef->signalGammaCands()) { + double dR = deltaR(gamma->p4(), theTauRef->leadChargedHadrCand()->p4()); + double signalrad = std::max(0.05, std::min(0.10, 3.0 / std::max(1.0, theTauRef->pt()))); + // pfGammas inside the tau signal cone + if (dR < signalrad) { + numSignalGammaCandsInSigCone += 1; + } + } + + bool hasGsfTrack = false; + const reco::CandidatePtr& leadChCand = theTauRef->leadChargedHadrCand(); + if (leadChCand.isNonnull()) { + const reco::PFCandidate* pfLeadChCand = + dynamic_cast(leadChCand.get()); + if (pfLeadChCand != nullptr) { + hasGsfTrack = pfLeadChCand->gsfTrackRef().isNonnull(); + } else { + pat::PackedCandidate const* packedLeadChCand = + dynamic_cast(leadChCand.get()); + hasGsfTrack = (packedLeadChCand != nullptr && std::abs(packedLeadChCand->pdgId())==11); + } + } + + // loop over the electrons + for (const auto& theElectron : *electrons_) { + if (theElectron.pt() > 10.) { // CV: only take electrons above some minimal energy/Pt into account... + double deltaREleTau = deltaR(theElectron.p4(), theTauRef->p4()); + deltaRDummy = deltaREleTau; + if (deltaREleTau < 0.3) { + double mva_match = mva_->MVAValue(*theTauRef, theElectron); + if (!hasGsfTrack) + hasGsfTrack = theElectron.gsfTrack().isNonnull(); + + // veto taus that go to ECal crack + if (vetoEcalCracks_ && + (isInEcalCrack(tauEtaAtECalEntrance.first) || isInEcalCrack(tauEtaAtECalEntrance.second))) { + // add category index + result.rawValues.at(1) = category; + // return MVA output value + result.rawValues.at(0) = -99.; + return result; + } + // veto taus that go to ECal crack + + if (std::abs(tauEtaAtECalEntrance.first) < ECalBarrelEndcapEtaBorder) { // Barrel + if (numSignalGammaCandsInSigCone == 0 && hasGsfTrack) { + category = 5.; + } else if (numSignalGammaCandsInSigCone >= 1 && hasGsfTrack) { + category = 7.; + } + } else { // Endcap + if (numSignalGammaCandsInSigCone == 0 && hasGsfTrack) { + category = 13.; + } else if (numSignalGammaCandsInSigCone >= 1 && hasGsfTrack) { + category = 15.; + } + } + + result.rawValues.at(0) = std::min(result.rawValues.at(0), float(mva_match)); + isGsfElectronMatched = true; + } // deltaR < 0.3 + } // electron pt > 10 + } // end of loop over electrons + + if (!isGsfElectronMatched) { + result.rawValues.at(0) = mva_->MVAValue(*theTauRef); + + // veto taus that go to ECal crack + if (vetoEcalCracks_ && + (isInEcalCrack(tauEtaAtECalEntrance.first) || isInEcalCrack(tauEtaAtECalEntrance.second))) { + // add category index + result.rawValues.at(1) = category; + // return MVA output value + result.rawValues.at(0) = -99.; + return result; + } + // veto taus that go to ECal crack + + if (std::abs(tauEtaAtECalEntrance.first) < ECalBarrelEndcapEtaBorder) { // Barrel + if (numSignalGammaCandsInSigCone == 0 && !hasGsfTrack) { + category = 0.; + } else if (numSignalGammaCandsInSigCone >= 1 && !hasGsfTrack) { + category = 2.; + } + } else { // Endcap + if (numSignalGammaCandsInSigCone == 0 && !hasGsfTrack) { + category = 8.; + } else if (numSignalGammaCandsInSigCone >= 1 && !hasGsfTrack) { + category = 10.; + } + } + } + } + + if (verbosity_) { + edm::LogPrint(this->getTauTypeString() + "AgainstEleMVA6") + << "<" + this->getTauTypeString() + "AgainstElectronMVA6::discriminate>:"; + edm::LogPrint(this->getTauTypeString() + "AgainstEleMVA6") + << " tau: Pt = " << theTauRef->pt() << ", eta = " << theTauRef->eta() + << ", phi = " << theTauRef->phi(); + edm::LogPrint(this->getTauTypeString() + "AgainstEleMVA6") + << " deltaREleTau = " << deltaRDummy + << ", isGsfElectronMatched = " << isGsfElectronMatched; + edm::LogPrint(this->getTauTypeString() + "AgainstEleMVA6") + << " #Prongs = " << theTauRef->signalChargedHadrCands().size(); + edm::LogPrint(this->getTauTypeString() + "AgainstEleMVA6") + << " MVA = " << result.rawValues.at(0) << ", category = " << category; + } + + // add category index + result.rawValues.at(1) = category; + // return MVA output value + return result; +} + +template +bool TauDiscriminationAgainstElectronMVA6::isInEcalCrack( +double eta) const { + double absEta = std::abs(eta); + return (absEta > 1.460 && absEta < 1.558); +} + +template +std::pair TauDiscriminationAgainstElectronMVA6::getTauEtaAtECalEntrance(const reco::PFTauRef& theTauRef) const { + + float tauEtaAtECalEntrance = -99; + float leadChargedCandEtaAtECalEntrance = -99; + float sumEtaTimesEnergy = 0; + float sumEnergy = 0; + float leadChargedCandPt = -99; + + for (const auto& candidate : theTauRef->signalCands()) { + float etaAtECalEntrance = candidate->eta(); + const reco::Track* track = nullptr; + const reco::PFCandidate* pfCandidate = + dynamic_cast(candidate.get()); + if (pfCandidate != nullptr) { + etaAtECalEntrance = pfCandidate->positionAtECALEntrance().eta(); + if (pfCandidate->trackRef().isNonnull()) + track = pfCandidate->trackRef().get(); + else if (pfCandidate->muonRef().isNonnull() && + pfCandidate->muonRef()->innerTrack().isNonnull()) + track = pfCandidate->muonRef()->innerTrack().get(); + else if (pfCandidate->muonRef().isNonnull() && + pfCandidate->muonRef()->globalTrack().isNonnull()) + track = pfCandidate->muonRef()->globalTrack().get(); + else if (pfCandidate->muonRef().isNonnull() && + pfCandidate->muonRef()->outerTrack().isNonnull()) + track = pfCandidate->muonRef()->outerTrack().get(); + else if (pfCandidate->gsfTrackRef().isNonnull()) + track = pfCandidate->gsfTrackRef().get(); + } else { + bool success = false; + reco::Candidate::Point posAtECal = + positionAtECalEntrance_(candidate.get(), success); + if (success) { + etaAtECalEntrance = posAtECal.eta(); + } + track = candidate->bestTrack(); + } + if (track != nullptr) { + if (track->pt() > leadChargedCandPt) { + leadChargedCandEtaAtECalEntrance = etaAtECalEntrance; + leadChargedCandPt = track->pt(); + } + } + sumEtaTimesEnergy += etaAtECalEntrance * candidate->energy(); + sumEnergy += candidate->energy(); + } + if (sumEnergy > 0.) { + tauEtaAtECalEntrance = sumEtaTimesEnergy / sumEnergy; + } + return std::pair(tauEtaAtECalEntrance, + leadChargedCandEtaAtECalEntrance); +} + +template +std::pair TauDiscriminationAgainstElectronMVA6::getTauEtaAtECalEntrance(const pat::TauRef& theTauRef) const { + return std::pair(theTauRef->etaAtEcalEntrance(), + theTauRef->etaAtEcalEntranceLeadChargedCand()); +} + +template +void TauDiscriminationAgainstElectronMVA6::fillDescriptions( +edm::ConfigurationDescriptions& descriptions) { + // {pfReco,pat}TauDiscriminationAgainstElectronMVA6 + edm::ParameterSetDescription desc; + + desc.add("method", "BDTG"); + desc.add("loadMVAfromDB", true); + desc.add("returnMVA", true); + + desc.add("mvaName_NoEleMatch_woGwoGSF_BL", "gbr_NoEleMatch_woGwoGSF_BL"); + desc.add("mvaName_NoEleMatch_wGwoGSF_BL", "gbr_NoEleMatch_wGwoGSF_BL"); + desc.add("mvaName_woGwGSF_BL", "gbr_woGwGSF_BL"); + desc.add("mvaName_wGwGSF_BL", "gbr_wGwGSF_BL"); + desc.add("mvaName_NoEleMatch_woGwoGSF_EC", "gbr_NoEleMatch_woGwoGSF_EC"); + desc.add("mvaName_NoEleMatch_wGwoGSF_EC", "gbr_NoEleMatch_wGwoGSF_EC"); + desc.add("mvaName_woGwGSF_EC", "gbr_woGwGSF_EC"); + desc.add("mvaName_wGwGSF_EC", "gbr_wGwGSF_EC"); + + desc.add("minMVANoEleMatchWOgWOgsfBL", 0.0); + desc.add("minMVANoEleMatchWgWOgsfBL", 0.0); + desc.add("minMVAWOgWgsfBL", 0.0); + desc.add("minMVAWgWgsfBL", 0.0); + desc.add("minMVANoEleMatchWOgWOgsfEC", 0.0); + desc.add("minMVANoEleMatchWgWOgsfEC", 0.0); + desc.add("minMVAWOgWgsfEC", 0.0); + desc.add("minMVAWgWgsfEC", 0.0); + desc.add("srcElectrons", edm::InputTag("fixme")); + desc.add("vetoEcalCracks", true); + desc.add("usePhiAtEcalEntranceExtrapolation", false); + desc.add("verbosity", 0); + + TauDiscriminationProducerBase::fillProducerDescriptions(desc); // inherited from the base-class + + descriptions.addWithDefaultLabel(desc); +} + +typedef TauDiscriminationAgainstElectronMVA6 + PFRecoTauDiscriminationAgainstElectronMVA6; +typedef TauDiscriminationAgainstElectronMVA6 + PATTauDiscriminationAgainstElectronMVA6; + +DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstElectronMVA6); +DEFINE_FWK_MODULE(PATTauDiscriminationAgainstElectronMVA6); diff --git a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc index 547dc14e07090..96e781a6468df 100644 --- a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc +++ b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc @@ -11,11 +11,11 @@ #include "CondFormats/DataRecord/interface/GBRWrapperRcd.h" #include "FWCore/Framework/interface/ESHandle.h" -#include #include #include -AntiElectronIDMVA6::AntiElectronIDMVA6(const edm::ParameterSet& cfg) +template +AntiElectronIDMVA6::AntiElectronIDMVA6(const edm::ParameterSet& cfg) : isInitialized_(false), mva_NoEleMatch_woGwoGSF_BL_(nullptr), mva_NoEleMatch_wGwoGSF_BL_(nullptr), @@ -45,19 +45,20 @@ AntiElectronIDMVA6::AntiElectronIDMVA6(const edm::ParameterSet& cfg) usePhiAtEcalEntranceExtrapolation_ = cfg.getParameter("usePhiAtEcalEntranceExtrapolation"); - Var_NoEleMatch_woGwoGSF_Barrel_ = new Float_t[10]; - Var_NoEleMatch_wGwoGSF_Barrel_ = new Float_t[18]; - Var_woGwGSF_Barrel_ = new Float_t[24]; - Var_wGwGSF_Barrel_ = new Float_t[32]; - Var_NoEleMatch_woGwoGSF_Endcap_ = new Float_t[9]; - Var_NoEleMatch_wGwoGSF_Endcap_ = new Float_t[17]; - Var_woGwGSF_Endcap_ = new Float_t[23]; - Var_wGwGSF_Endcap_ = new Float_t[31]; + Var_NoEleMatch_woGwoGSF_Barrel_ = new float[10]; + Var_NoEleMatch_wGwoGSF_Barrel_ = new float[18]; + Var_woGwGSF_Barrel_ = new float[24]; + Var_wGwGSF_Barrel_ = new float[32]; + Var_NoEleMatch_woGwoGSF_Endcap_ = new float[9]; + Var_NoEleMatch_wGwoGSF_Endcap_ = new float[17]; + Var_woGwGSF_Endcap_ = new float[23]; + Var_wGwGSF_Endcap_ = new float[31]; verbosity_ = 0; } -AntiElectronIDMVA6::~AntiElectronIDMVA6() { +template +AntiElectronIDMVA6::~AntiElectronIDMVA6() { delete[] Var_NoEleMatch_woGwoGSF_Barrel_; delete[] Var_NoEleMatch_wGwoGSF_Barrel_; delete[] Var_woGwGSF_Barrel_; @@ -101,7 +102,8 @@ namespace { } } // namespace -void AntiElectronIDMVA6::beginEvent(const edm::Event& evt, const edm::EventSetup& es) { +template +void AntiElectronIDMVA6::beginEvent(const edm::Event& evt, const edm::EventSetup& es) { if (!isInitialized_) { if (loadMVAfromDB_) { mva_NoEleMatch_woGwoGSF_BL_ = loadMVAfromDB(es, mvaName_NoEleMatch_woGwoGSF_BL_); @@ -133,882 +135,397 @@ void AntiElectronIDMVA6::beginEvent(const edm::Event& evt, const edm::EventSetup positionAtECalEntrance_.beginEvent(es); } -double AntiElectronIDMVA6::MVAValue(Float_t TauPt, - Float_t TauEtaAtEcalEntrance, - Float_t TauPhi, - Float_t TauLeadChargedPFCandPt, - Float_t TauLeadChargedPFCandEtaAtEcalEntrance, - Float_t TauEmFraction, - Float_t TauLeadPFChargedHadrHoP, - Float_t TauLeadPFChargedHadrEoP, - Float_t TauVisMassIn, - Float_t TaudCrackEta, - Float_t TaudCrackPhi, - Float_t TauHasGsf, - Int_t TauSignalPFGammaCandsIn, - Int_t TauSignalPFGammaCandsOut, - const std::vector& GammasdEtaInSigCone, - const std::vector& GammasdPhiInSigCone, - const std::vector& GammasPtInSigCone, - const std::vector& GammasdEtaOutSigCone, - const std::vector& GammasdPhiOutSigCone, - const std::vector& GammasPtOutSigCone, - Float_t ElecEta, - Float_t ElecPhi, - Float_t ElecEtotOverPin, - Float_t ElecChi2NormGSF, - Float_t ElecChi2NormKF, - Float_t ElecGSFNumHits, - Float_t ElecKFNumHits, - Float_t ElecGSFTrackResol, - Float_t ElecGSFTracklnPt, - Float_t ElecPin, - Float_t ElecPout, - Float_t ElecEecal, - Float_t ElecDeltaEta, - Float_t ElecDeltaPhi, - Float_t ElecMvaInSigmaEtaEta, - Float_t ElecMvaInHadEnergy, - Float_t ElecMvaInDeltaEta) { +template +double AntiElectronIDMVA6::MVAValue(const TauVars& tauVars, + const TauGammaVecs& tauGammaVecs, + const EleVars& eleVars) { + TauGammaMoms tauGammaMoms; double sumPt = 0.; double dEta2 = 0.; double dPhi2 = 0.; double sumPt2 = 0.; - for (unsigned int i = 0; i < GammasPtInSigCone.size(); ++i) { - double pt_i = GammasPtInSigCone[i]; - double phi_i = GammasdPhiInSigCone[i]; - if (GammasdPhiInSigCone[i] > M_PI) - phi_i = GammasdPhiInSigCone[i] - 2 * M_PI; - else if (GammasdPhiInSigCone[i] < -M_PI) - phi_i = GammasdPhiInSigCone[i] + 2 * M_PI; - double eta_i = GammasdEtaInSigCone[i]; + tauGammaMoms.tauSignalPFGammaCandsIn = tauGammaVecs.gammasPtInSigCone.size(); + for (size_t i = 0; i < tauGammaVecs.gammasPtInSigCone.size(); ++i) { + double pt_i = tauGammaVecs.gammasPtInSigCone[i]; + double phi_i = tauGammaVecs.gammasdPhiInSigCone[i]; + if (tauGammaVecs.gammasdPhiInSigCone[i] > M_PI) + phi_i = tauGammaVecs.gammasdPhiInSigCone[i] - 2 * M_PI; + else if (tauGammaVecs.gammasdPhiInSigCone[i] < -M_PI) + phi_i = tauGammaVecs.gammasdPhiInSigCone[i] + 2 * M_PI; + double eta_i = tauGammaVecs.gammasdEtaInSigCone[i]; sumPt += pt_i; sumPt2 += (pt_i * pt_i); dEta2 += (pt_i * eta_i * eta_i); dPhi2 += (pt_i * phi_i * phi_i); } - Float_t TauGammaEnFracIn = -99.; - if (TauPt > 0.) { - TauGammaEnFracIn = sumPt / TauPt; + + tauGammaMoms.tauGammaEnFracIn = -99.; + if (tauVars.tauPt > 0.) { + tauGammaMoms.tauGammaEnFracIn = sumPt / tauVars.tauPt; } if (sumPt > 0.) { dEta2 /= sumPt; dPhi2 /= sumPt; } - Float_t TauGammaEtaMomIn = std::sqrt(dEta2) * std::sqrt(TauGammaEnFracIn) * TauPt; - Float_t TauGammaPhiMomIn = std::sqrt(dPhi2) * std::sqrt(TauGammaEnFracIn) * TauPt; + tauGammaMoms.tauGammaEtaMomIn = std::sqrt(dEta2) * std::sqrt(tauGammaMoms.tauGammaEnFracIn) * tauVars.tauPt; + tauGammaMoms.tauGammaPhiMomIn = std::sqrt(dPhi2) * std::sqrt(tauGammaMoms.tauGammaEnFracIn) * tauVars.tauPt; sumPt = 0.; dEta2 = 0.; dPhi2 = 0.; sumPt2 = 0.; - for (unsigned int i = 0; i < GammasPtOutSigCone.size(); ++i) { - double pt_i = GammasPtOutSigCone[i]; - double phi_i = GammasdPhiOutSigCone[i]; - if (GammasdPhiOutSigCone[i] > M_PI) - phi_i = GammasdPhiOutSigCone[i] - 2 * M_PI; - else if (GammasdPhiOutSigCone[i] < -M_PI) - phi_i = GammasdPhiOutSigCone[i] + 2 * M_PI; - double eta_i = GammasdEtaOutSigCone[i]; + tauGammaMoms.tauSignalPFGammaCandsOut = tauGammaVecs.gammasPtOutSigCone.size(); + for (size_t i = 0; i < tauGammaVecs.gammasPtOutSigCone.size(); ++i) { + double pt_i = tauGammaVecs.gammasPtOutSigCone[i]; + double phi_i = tauGammaVecs.gammasdPhiOutSigCone[i]; + if (tauGammaVecs.gammasdPhiOutSigCone[i] > M_PI) + phi_i = tauGammaVecs.gammasdPhiOutSigCone[i] - 2 * M_PI; + else if (tauGammaVecs.gammasdPhiOutSigCone[i] < -M_PI) + phi_i = tauGammaVecs.gammasdPhiOutSigCone[i] + 2 * M_PI; + double eta_i = tauGammaVecs.gammasdEtaOutSigCone[i]; sumPt += pt_i; sumPt2 += (pt_i * pt_i); dEta2 += (pt_i * eta_i * eta_i); dPhi2 += (pt_i * phi_i * phi_i); } - Float_t TauGammaEnFracOut = sumPt / TauPt; + + tauGammaMoms.tauGammaEnFracOut = -99.; + if (tauVars.tauPt > 0.) { + tauGammaMoms.tauGammaEnFracOut = sumPt / tauVars.tauPt; + } if (sumPt > 0.) { dEta2 /= sumPt; dPhi2 /= sumPt; } - Float_t TauGammaEtaMomOut = std::sqrt(dEta2) * std::sqrt(TauGammaEnFracOut) * TauPt; - Float_t TauGammaPhiMomOut = std::sqrt(dPhi2) * std::sqrt(TauGammaEnFracOut) * TauPt; - - return MVAValue(TauPt, - TauEtaAtEcalEntrance, - TauPhi, - TauLeadChargedPFCandPt, - TauLeadChargedPFCandEtaAtEcalEntrance, - TauEmFraction, - TauLeadPFChargedHadrHoP, - TauLeadPFChargedHadrEoP, - TauVisMassIn, - TaudCrackEta, - TaudCrackPhi, - TauHasGsf, - TauSignalPFGammaCandsIn, - TauSignalPFGammaCandsOut, - TauGammaEtaMomIn, - TauGammaEtaMomOut, - TauGammaPhiMomIn, - TauGammaPhiMomOut, - TauGammaEnFracIn, - TauGammaEnFracOut, - ElecEta, - ElecPhi, - ElecEtotOverPin, - ElecChi2NormGSF, - ElecChi2NormKF, - ElecGSFNumHits, - ElecKFNumHits, - ElecGSFTrackResol, - ElecGSFTracklnPt, - ElecPin, - ElecPout, - ElecEecal, - ElecDeltaEta, - ElecDeltaPhi, - ElecMvaInSigmaEtaEta, - ElecMvaInHadEnergy, - ElecMvaInDeltaEta); + tauGammaMoms.tauGammaEtaMomOut = std::sqrt(dEta2) * std::sqrt(tauGammaMoms.tauGammaEnFracOut) * tauVars.tauPt; + tauGammaMoms.tauGammaPhiMomOut = std::sqrt(dPhi2) * std::sqrt(tauGammaMoms.tauGammaEnFracOut) * tauVars.tauPt; + + return MVAValue(tauVars, tauGammaMoms, eleVars); } -double AntiElectronIDMVA6::MVAValue(Float_t TauPt, - Float_t TauEtaAtEcalEntrance, - Float_t TauPhi, - Float_t TauLeadChargedPFCandPt, - Float_t TauLeadChargedPFCandEtaAtEcalEntrance, - Float_t TauEmFraction, - Float_t TauLeadPFChargedHadrHoP, - Float_t TauLeadPFChargedHadrEoP, - Float_t TauVisMassIn, - Float_t TaudCrackEta, - Float_t TaudCrackPhi, - Float_t TauHasGsf, - Int_t TauSignalPFGammaCandsIn, - Int_t TauSignalPFGammaCandsOut, - Float_t TauGammaEtaMomIn, - Float_t TauGammaEtaMomOut, - Float_t TauGammaPhiMomIn, - Float_t TauGammaPhiMomOut, - Float_t TauGammaEnFracIn, - Float_t TauGammaEnFracOut, - Float_t ElecEta, - Float_t ElecPhi, - Float_t ElecEtotOverPin, - Float_t ElecChi2NormGSF, - Float_t ElecChi2NormKF, - Float_t ElecGSFNumHits, - Float_t ElecKFNumHits, - Float_t ElecGSFTrackResol, - Float_t ElecGSFTracklnPt, - Float_t ElecPin, - Float_t ElecPout, - Float_t ElecEecal, - Float_t ElecDeltaEta, - Float_t ElecDeltaPhi, - Float_t ElecMvaInSigmaEtaEta, - Float_t ElecMvaInHadEnergy, - Float_t ElecMvaInDeltaEta) { +template +double AntiElectronIDMVA6::MVAValue(const TauVars& tauVars, + const TauGammaMoms& tauGammaMoms, + const EleVars& eleVars) { if (!isInitialized_) { - throw cms::Exception("ClassNotInitialized") << " AntiElectronMVA not properly initialized !!\n"; + throw cms::Exception("ClassNotInitialized") << " AntiElectronMVA6 not properly initialized !!\n"; } double mvaValue = -99.; const float ECALBarrelEndcapEtaBorder = 1.479; - float ElecDeltaPinPoutOverPin = (ElecPin > 0.0) ? (std::abs(ElecPin - ElecPout) / ElecPin) : 1.0; - float ElecEecalOverPout = (ElecPout > 0.0) ? (ElecEecal / ElecPout) : 20.0; - float ElecNumHitsDiffOverSum = ((ElecGSFNumHits + ElecKFNumHits) > 0.0) - ? ((ElecGSFNumHits - ElecKFNumHits) / (ElecGSFNumHits + ElecKFNumHits)) + float elecDeltaPinPoutOverPin = (eleVars.elecPin > 0.0) ? (std::abs(eleVars.elecPin - eleVars.elecPout) / eleVars.elecPin) : 1.0; + float elecEecalOverPout = (eleVars.elecPout > 0.0) ? (eleVars.elecEecal / eleVars.elecPout) : 20.0; + float elecNumHitsDiffOverSum = ((eleVars.elecGSFNumHits + eleVars.elecKFNumHits) > 0.0) + ? ((eleVars.elecGSFNumHits - eleVars.elecKFNumHits) / (eleVars.elecGSFNumHits + eleVars.elecKFNumHits)) : 1.0; - if (deltaR(TauEtaAtEcalEntrance, TauPhi, ElecEta, ElecPhi) > 0.3 && TauSignalPFGammaCandsIn == 0 && TauHasGsf < 0.5) { - if (std::abs(TauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { - Var_NoEleMatch_woGwoGSF_Barrel_[0] = TauEtaAtEcalEntrance; - Var_NoEleMatch_woGwoGSF_Barrel_[1] = TauLeadChargedPFCandEtaAtEcalEntrance; - Var_NoEleMatch_woGwoGSF_Barrel_[2] = std::min(float(2.), TauLeadChargedPFCandPt / std::max(float(1.), TauPt)); - Var_NoEleMatch_woGwoGSF_Barrel_[3] = std::log(std::max(float(1.), TauPt)); - Var_NoEleMatch_woGwoGSF_Barrel_[4] = TauEmFraction; - Var_NoEleMatch_woGwoGSF_Barrel_[5] = TauLeadPFChargedHadrHoP; - Var_NoEleMatch_woGwoGSF_Barrel_[6] = TauLeadPFChargedHadrEoP; - Var_NoEleMatch_woGwoGSF_Barrel_[7] = TauVisMassIn; - Var_NoEleMatch_woGwoGSF_Barrel_[8] = TaudCrackEta; - Var_NoEleMatch_woGwoGSF_Barrel_[9] = TaudCrackPhi; + if (deltaR(tauVars.tauEtaAtEcalEntrance, tauVars.tauPhi, eleVars.elecEta, eleVars.elecPhi) > 0.3 && tauGammaMoms.tauSignalPFGammaCandsIn == 0 && tauVars.tauHasGsf < 0.5) { + if (std::abs(tauVars.tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { + Var_NoEleMatch_woGwoGSF_Barrel_[0] = tauVars.tauEtaAtEcalEntrance; + Var_NoEleMatch_woGwoGSF_Barrel_[1] = tauVars.tauLeadChargedPFCandEtaAtEcalEntrance; + Var_NoEleMatch_woGwoGSF_Barrel_[2] = std::min(float(2.), tauVars.tauLeadChargedPFCandPt / std::max(float(1.), tauVars.tauPt)); + Var_NoEleMatch_woGwoGSF_Barrel_[3] = std::log(std::max(float(1.), tauVars.tauPt)); + Var_NoEleMatch_woGwoGSF_Barrel_[4] = tauVars.tauEmFraction; + Var_NoEleMatch_woGwoGSF_Barrel_[5] = tauVars.tauLeadPFChargedHadrHoP; + Var_NoEleMatch_woGwoGSF_Barrel_[6] = tauVars.tauLeadPFChargedHadrEoP; + Var_NoEleMatch_woGwoGSF_Barrel_[7] = tauVars.tauVisMassIn; + Var_NoEleMatch_woGwoGSF_Barrel_[8] = tauVars.taudCrackEta; + Var_NoEleMatch_woGwoGSF_Barrel_[9] = tauVars.taudCrackPhi; mvaValue = mva_NoEleMatch_woGwoGSF_BL_->GetClassifier(Var_NoEleMatch_woGwoGSF_Barrel_); } else { - Var_NoEleMatch_woGwoGSF_Endcap_[0] = TauEtaAtEcalEntrance; - Var_NoEleMatch_woGwoGSF_Endcap_[1] = TauLeadChargedPFCandEtaAtEcalEntrance; - Var_NoEleMatch_woGwoGSF_Endcap_[2] = std::min(float(2.), TauLeadChargedPFCandPt / std::max(float(1.), TauPt)); - Var_NoEleMatch_woGwoGSF_Endcap_[3] = std::log(std::max(float(1.), TauPt)); - Var_NoEleMatch_woGwoGSF_Endcap_[4] = TauEmFraction; - Var_NoEleMatch_woGwoGSF_Endcap_[5] = TauLeadPFChargedHadrHoP; - Var_NoEleMatch_woGwoGSF_Endcap_[6] = TauLeadPFChargedHadrEoP; - Var_NoEleMatch_woGwoGSF_Endcap_[7] = TauVisMassIn; - Var_NoEleMatch_woGwoGSF_Endcap_[8] = TaudCrackEta; + Var_NoEleMatch_woGwoGSF_Endcap_[0] = tauVars.tauEtaAtEcalEntrance; + Var_NoEleMatch_woGwoGSF_Endcap_[1] = tauVars.tauLeadChargedPFCandEtaAtEcalEntrance; + Var_NoEleMatch_woGwoGSF_Endcap_[2] = std::min(float(2.), tauVars.tauLeadChargedPFCandPt / std::max(float(1.), tauVars.tauPt)); + Var_NoEleMatch_woGwoGSF_Endcap_[3] = std::log(std::max(float(1.), tauVars.tauPt)); + Var_NoEleMatch_woGwoGSF_Endcap_[4] = tauVars.tauEmFraction; + Var_NoEleMatch_woGwoGSF_Endcap_[5] = tauVars.tauLeadPFChargedHadrHoP; + Var_NoEleMatch_woGwoGSF_Endcap_[6] = tauVars.tauLeadPFChargedHadrEoP; + Var_NoEleMatch_woGwoGSF_Endcap_[7] = tauVars.tauVisMassIn; + Var_NoEleMatch_woGwoGSF_Endcap_[8] = tauVars.taudCrackEta; mvaValue = mva_NoEleMatch_woGwoGSF_EC_->GetClassifier(Var_NoEleMatch_woGwoGSF_Endcap_); } - } else if (deltaR(TauEtaAtEcalEntrance, TauPhi, ElecEta, ElecPhi) > 0.3 && TauSignalPFGammaCandsIn > 0 && - TauHasGsf < 0.5) { - if (std::abs(TauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { - Var_NoEleMatch_wGwoGSF_Barrel_[0] = TauEtaAtEcalEntrance; - Var_NoEleMatch_wGwoGSF_Barrel_[1] = TauLeadChargedPFCandEtaAtEcalEntrance; - Var_NoEleMatch_wGwoGSF_Barrel_[2] = std::min(float(2.), TauLeadChargedPFCandPt / std::max(float(1.), TauPt)); - Var_NoEleMatch_wGwoGSF_Barrel_[3] = std::log(std::max(float(1.), TauPt)); - Var_NoEleMatch_wGwoGSF_Barrel_[4] = TauEmFraction; - Var_NoEleMatch_wGwoGSF_Barrel_[5] = TauSignalPFGammaCandsIn; - Var_NoEleMatch_wGwoGSF_Barrel_[6] = TauSignalPFGammaCandsOut; - Var_NoEleMatch_wGwoGSF_Barrel_[7] = TauLeadPFChargedHadrHoP; - Var_NoEleMatch_wGwoGSF_Barrel_[8] = TauLeadPFChargedHadrEoP; - Var_NoEleMatch_wGwoGSF_Barrel_[9] = TauVisMassIn; - Var_NoEleMatch_wGwoGSF_Barrel_[10] = TauGammaEtaMomIn; - Var_NoEleMatch_wGwoGSF_Barrel_[11] = TauGammaEtaMomOut; - Var_NoEleMatch_wGwoGSF_Barrel_[12] = TauGammaPhiMomIn; - Var_NoEleMatch_wGwoGSF_Barrel_[13] = TauGammaPhiMomOut; - Var_NoEleMatch_wGwoGSF_Barrel_[14] = TauGammaEnFracIn; - Var_NoEleMatch_wGwoGSF_Barrel_[15] = TauGammaEnFracOut; - Var_NoEleMatch_wGwoGSF_Barrel_[16] = TaudCrackEta; - Var_NoEleMatch_wGwoGSF_Barrel_[17] = TaudCrackPhi; + } else if (deltaR(tauVars.tauEtaAtEcalEntrance, tauVars.tauPhi, eleVars.elecEta, eleVars.elecPhi) > 0.3 && + tauGammaMoms.tauSignalPFGammaCandsIn > 0 && + tauVars.tauHasGsf < 0.5) { + if (std::abs(tauVars.tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { + Var_NoEleMatch_wGwoGSF_Barrel_[0] = tauVars.tauEtaAtEcalEntrance; + Var_NoEleMatch_wGwoGSF_Barrel_[1] = tauVars.tauLeadChargedPFCandEtaAtEcalEntrance; + Var_NoEleMatch_wGwoGSF_Barrel_[2] = std::min(float(2.), tauVars.tauLeadChargedPFCandPt / std::max(float(1.), tauVars.tauPt)); + Var_NoEleMatch_wGwoGSF_Barrel_[3] = std::log(std::max(float(1.), tauVars.tauPt)); + Var_NoEleMatch_wGwoGSF_Barrel_[4] = tauVars.tauEmFraction; + Var_NoEleMatch_wGwoGSF_Barrel_[5] = tauGammaMoms.tauSignalPFGammaCandsIn; + Var_NoEleMatch_wGwoGSF_Barrel_[6] = tauGammaMoms.tauSignalPFGammaCandsOut; + Var_NoEleMatch_wGwoGSF_Barrel_[7] = tauVars.tauLeadPFChargedHadrHoP; + Var_NoEleMatch_wGwoGSF_Barrel_[8] = tauVars.tauLeadPFChargedHadrEoP; + Var_NoEleMatch_wGwoGSF_Barrel_[9] = tauVars.tauVisMassIn; + Var_NoEleMatch_wGwoGSF_Barrel_[10] = tauGammaMoms.tauGammaEtaMomIn; + Var_NoEleMatch_wGwoGSF_Barrel_[11] = tauGammaMoms.tauGammaEtaMomOut; + Var_NoEleMatch_wGwoGSF_Barrel_[12] = tauGammaMoms.tauGammaPhiMomIn; + Var_NoEleMatch_wGwoGSF_Barrel_[13] = tauGammaMoms.tauGammaPhiMomOut; + Var_NoEleMatch_wGwoGSF_Barrel_[14] = tauGammaMoms.tauGammaEnFracIn; + Var_NoEleMatch_wGwoGSF_Barrel_[15] = tauGammaMoms.tauGammaEnFracOut; + Var_NoEleMatch_wGwoGSF_Barrel_[16] = tauVars.taudCrackEta; + Var_NoEleMatch_wGwoGSF_Barrel_[17] = tauVars.taudCrackPhi; mvaValue = mva_NoEleMatch_wGwoGSF_BL_->GetClassifier(Var_NoEleMatch_wGwoGSF_Barrel_); } else { - Var_NoEleMatch_wGwoGSF_Endcap_[0] = TauEtaAtEcalEntrance; - Var_NoEleMatch_wGwoGSF_Endcap_[1] = TauLeadChargedPFCandEtaAtEcalEntrance; - Var_NoEleMatch_wGwoGSF_Endcap_[2] = std::min(float(2.), TauLeadChargedPFCandPt / std::max(float(1.), TauPt)); - Var_NoEleMatch_wGwoGSF_Endcap_[3] = std::log(std::max(float(1.), TauPt)); - Var_NoEleMatch_wGwoGSF_Endcap_[4] = TauEmFraction; - Var_NoEleMatch_wGwoGSF_Endcap_[5] = TauSignalPFGammaCandsIn; - Var_NoEleMatch_wGwoGSF_Endcap_[6] = TauSignalPFGammaCandsOut; - Var_NoEleMatch_wGwoGSF_Endcap_[7] = TauLeadPFChargedHadrHoP; - Var_NoEleMatch_wGwoGSF_Endcap_[8] = TauLeadPFChargedHadrEoP; - Var_NoEleMatch_wGwoGSF_Endcap_[9] = TauVisMassIn; - Var_NoEleMatch_wGwoGSF_Endcap_[10] = TauGammaEtaMomIn; - Var_NoEleMatch_wGwoGSF_Endcap_[11] = TauGammaEtaMomOut; - Var_NoEleMatch_wGwoGSF_Endcap_[12] = TauGammaPhiMomIn; - Var_NoEleMatch_wGwoGSF_Endcap_[13] = TauGammaPhiMomOut; - Var_NoEleMatch_wGwoGSF_Endcap_[14] = TauGammaEnFracIn; - Var_NoEleMatch_wGwoGSF_Endcap_[15] = TauGammaEnFracOut; - Var_NoEleMatch_wGwoGSF_Endcap_[16] = TaudCrackEta; + Var_NoEleMatch_wGwoGSF_Endcap_[0] = tauVars.tauEtaAtEcalEntrance; + Var_NoEleMatch_wGwoGSF_Endcap_[1] = tauVars.tauLeadChargedPFCandEtaAtEcalEntrance; + Var_NoEleMatch_wGwoGSF_Endcap_[2] = std::min(float(2.), tauVars.tauLeadChargedPFCandPt / std::max(float(1.), tauVars.tauPt)); + Var_NoEleMatch_wGwoGSF_Endcap_[3] = std::log(std::max(float(1.), tauVars.tauPt)); + Var_NoEleMatch_wGwoGSF_Endcap_[4] = tauVars.tauEmFraction; + Var_NoEleMatch_wGwoGSF_Endcap_[5] = tauGammaMoms.tauSignalPFGammaCandsIn; + Var_NoEleMatch_wGwoGSF_Endcap_[6] = tauGammaMoms.tauSignalPFGammaCandsOut; + Var_NoEleMatch_wGwoGSF_Endcap_[7] = tauVars.tauLeadPFChargedHadrHoP; + Var_NoEleMatch_wGwoGSF_Endcap_[8] = tauVars.tauLeadPFChargedHadrEoP; + Var_NoEleMatch_wGwoGSF_Endcap_[9] = tauVars.tauVisMassIn; + Var_NoEleMatch_wGwoGSF_Endcap_[10] = tauGammaMoms.tauGammaEtaMomIn; + Var_NoEleMatch_wGwoGSF_Endcap_[11] = tauGammaMoms.tauGammaEtaMomOut; + Var_NoEleMatch_wGwoGSF_Endcap_[12] = tauGammaMoms.tauGammaPhiMomIn; + Var_NoEleMatch_wGwoGSF_Endcap_[13] = tauGammaMoms.tauGammaPhiMomOut; + Var_NoEleMatch_wGwoGSF_Endcap_[14] = tauGammaMoms.tauGammaEnFracIn; + Var_NoEleMatch_wGwoGSF_Endcap_[15] = tauGammaMoms.tauGammaEnFracOut; + Var_NoEleMatch_wGwoGSF_Endcap_[16] = tauVars.taudCrackEta; mvaValue = mva_NoEleMatch_wGwoGSF_EC_->GetClassifier(Var_NoEleMatch_wGwoGSF_Endcap_); } - } else if (TauSignalPFGammaCandsIn == 0 && TauHasGsf > 0.5) { - if (std::abs(TauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { - Var_woGwGSF_Barrel_[0] = std::max(float(-0.1), ElecEtotOverPin); - Var_woGwGSF_Barrel_[1] = std::log(std::max(float(0.01), ElecChi2NormGSF)); - Var_woGwGSF_Barrel_[2] = ElecGSFNumHits; - Var_woGwGSF_Barrel_[3] = std::log(std::max(float(0.01), ElecGSFTrackResol)); - Var_woGwGSF_Barrel_[4] = ElecGSFTracklnPt; - Var_woGwGSF_Barrel_[5] = ElecNumHitsDiffOverSum; - Var_woGwGSF_Barrel_[6] = std::log(std::max(float(0.01), ElecChi2NormKF)); - Var_woGwGSF_Barrel_[7] = std::min(ElecDeltaPinPoutOverPin, float(1.)); - Var_woGwGSF_Barrel_[8] = std::min(ElecEecalOverPout, float(20.)); - Var_woGwGSF_Barrel_[9] = ElecDeltaEta; - Var_woGwGSF_Barrel_[10] = ElecDeltaPhi; - Var_woGwGSF_Barrel_[11] = std::min(ElecMvaInSigmaEtaEta, float(0.01)); - Var_woGwGSF_Barrel_[12] = std::min(ElecMvaInHadEnergy, float(20.)); - Var_woGwGSF_Barrel_[13] = std::min(ElecMvaInDeltaEta, float(0.1)); - Var_woGwGSF_Barrel_[14] = TauEtaAtEcalEntrance; - Var_woGwGSF_Barrel_[15] = TauLeadChargedPFCandEtaAtEcalEntrance; - Var_woGwGSF_Barrel_[16] = std::min(float(2.), TauLeadChargedPFCandPt / std::max(float(1.), TauPt)); - Var_woGwGSF_Barrel_[17] = std::log(std::max(float(1.), TauPt)); - Var_woGwGSF_Barrel_[18] = TauEmFraction; - Var_woGwGSF_Barrel_[19] = TauLeadPFChargedHadrHoP; - Var_woGwGSF_Barrel_[20] = TauLeadPFChargedHadrEoP; - Var_woGwGSF_Barrel_[21] = TauVisMassIn; - Var_woGwGSF_Barrel_[22] = TaudCrackEta; - Var_woGwGSF_Barrel_[23] = TaudCrackPhi; + } else if (tauGammaMoms.tauSignalPFGammaCandsIn == 0 && tauVars.tauHasGsf > 0.5) { + if (std::abs(tauVars.tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { + Var_woGwGSF_Barrel_[0] = std::max(float(-0.1), eleVars.elecEtotOverPin); + Var_woGwGSF_Barrel_[1] = std::log(std::max(float(0.01), eleVars.elecChi2NormGSF)); + Var_woGwGSF_Barrel_[2] = eleVars.elecGSFNumHits; + Var_woGwGSF_Barrel_[3] = std::log(std::max(float(0.01), eleVars.elecGSFTrackResol)); + Var_woGwGSF_Barrel_[4] = eleVars.elecGSFTracklnPt; + Var_woGwGSF_Barrel_[5] = elecNumHitsDiffOverSum; + Var_woGwGSF_Barrel_[6] = std::log(std::max(float(0.01), eleVars.elecChi2NormKF)); + Var_woGwGSF_Barrel_[7] = std::min(elecDeltaPinPoutOverPin, float(1.)); + Var_woGwGSF_Barrel_[8] = std::min(elecEecalOverPout, float(20.)); + Var_woGwGSF_Barrel_[9] = eleVars.elecDeltaEta; + Var_woGwGSF_Barrel_[10] = eleVars.elecDeltaPhi; + Var_woGwGSF_Barrel_[11] = std::min(eleVars.elecMvaInSigmaEtaEta, float(0.01)); + Var_woGwGSF_Barrel_[12] = std::min(eleVars.elecMvaInHadEnergy, float(20.)); + Var_woGwGSF_Barrel_[13] = std::min(eleVars.elecMvaInDeltaEta, float(0.1)); + Var_woGwGSF_Barrel_[14] = tauVars.tauEtaAtEcalEntrance; + Var_woGwGSF_Barrel_[15] = tauVars.tauLeadChargedPFCandEtaAtEcalEntrance; + Var_woGwGSF_Barrel_[16] = std::min(float(2.), tauVars.tauLeadChargedPFCandPt / std::max(float(1.), tauVars.tauPt)); + Var_woGwGSF_Barrel_[17] = std::log(std::max(float(1.), tauVars.tauPt)); + Var_woGwGSF_Barrel_[18] = tauVars.tauEmFraction; + Var_woGwGSF_Barrel_[19] = tauVars.tauLeadPFChargedHadrHoP; + Var_woGwGSF_Barrel_[20] = tauVars.tauLeadPFChargedHadrEoP; + Var_woGwGSF_Barrel_[21] = tauVars.tauVisMassIn; + Var_woGwGSF_Barrel_[22] = tauVars.taudCrackEta; + Var_woGwGSF_Barrel_[23] = tauVars.taudCrackPhi; mvaValue = mva_woGwGSF_BL_->GetClassifier(Var_woGwGSF_Barrel_); } else { - Var_woGwGSF_Endcap_[0] = std::max(float(-0.1), ElecEtotOverPin); - Var_woGwGSF_Endcap_[1] = std::log(std::max(float(0.01), ElecChi2NormGSF)); - Var_woGwGSF_Endcap_[2] = ElecGSFNumHits; - Var_woGwGSF_Endcap_[3] = std::log(std::max(float(0.01), ElecGSFTrackResol)); - Var_woGwGSF_Endcap_[4] = ElecGSFTracklnPt; - Var_woGwGSF_Endcap_[5] = ElecNumHitsDiffOverSum; - Var_woGwGSF_Endcap_[6] = std::log(std::max(float(0.01), ElecChi2NormKF)); - Var_woGwGSF_Endcap_[7] = std::min(ElecDeltaPinPoutOverPin, float(1.)); - Var_woGwGSF_Endcap_[8] = std::min(ElecEecalOverPout, float(20.)); - Var_woGwGSF_Endcap_[9] = ElecDeltaEta; - Var_woGwGSF_Endcap_[10] = ElecDeltaPhi; - Var_woGwGSF_Endcap_[11] = std::min(ElecMvaInSigmaEtaEta, float(0.01)); - Var_woGwGSF_Endcap_[12] = std::min(ElecMvaInHadEnergy, float(20.)); - Var_woGwGSF_Endcap_[13] = std::min(ElecMvaInDeltaEta, float(0.1)); - Var_woGwGSF_Endcap_[14] = TauEtaAtEcalEntrance; - Var_woGwGSF_Endcap_[15] = TauLeadChargedPFCandEtaAtEcalEntrance; - Var_woGwGSF_Endcap_[16] = std::min(float(2.), TauLeadChargedPFCandPt / std::max(float(1.), TauPt)); - Var_woGwGSF_Endcap_[17] = std::log(std::max(float(1.), TauPt)); - Var_woGwGSF_Endcap_[18] = TauEmFraction; - Var_woGwGSF_Endcap_[19] = TauLeadPFChargedHadrHoP; - Var_woGwGSF_Endcap_[20] = TauLeadPFChargedHadrEoP; - Var_woGwGSF_Endcap_[21] = TauVisMassIn; - Var_woGwGSF_Endcap_[22] = TaudCrackEta; + Var_woGwGSF_Endcap_[0] = std::max(float(-0.1), eleVars.elecEtotOverPin); + Var_woGwGSF_Endcap_[1] = std::log(std::max(float(0.01), eleVars.elecChi2NormGSF)); + Var_woGwGSF_Endcap_[2] = eleVars.elecGSFNumHits; + Var_woGwGSF_Endcap_[3] = std::log(std::max(float(0.01), eleVars.elecGSFTrackResol)); + Var_woGwGSF_Endcap_[4] = eleVars.elecGSFTracklnPt; + Var_woGwGSF_Endcap_[5] = elecNumHitsDiffOverSum; + Var_woGwGSF_Endcap_[6] = std::log(std::max(float(0.01), eleVars.elecChi2NormKF)); + Var_woGwGSF_Endcap_[7] = std::min(elecDeltaPinPoutOverPin, float(1.)); + Var_woGwGSF_Endcap_[8] = std::min(elecEecalOverPout, float(20.)); + Var_woGwGSF_Endcap_[9] = eleVars.elecDeltaEta; + Var_woGwGSF_Endcap_[10] = eleVars.elecDeltaPhi; + Var_woGwGSF_Endcap_[11] = std::min(eleVars.elecMvaInSigmaEtaEta, float(0.01)); + Var_woGwGSF_Endcap_[12] = std::min(eleVars.elecMvaInHadEnergy, float(20.)); + Var_woGwGSF_Endcap_[13] = std::min(eleVars.elecMvaInDeltaEta, float(0.1)); + Var_woGwGSF_Endcap_[14] = tauVars.tauEtaAtEcalEntrance; + Var_woGwGSF_Endcap_[15] = tauVars.tauLeadChargedPFCandEtaAtEcalEntrance; + Var_woGwGSF_Endcap_[16] = std::min(float(2.), tauVars.tauLeadChargedPFCandPt / std::max(float(1.), tauVars.tauPt)); + Var_woGwGSF_Endcap_[17] = std::log(std::max(float(1.), tauVars.tauPt)); + Var_woGwGSF_Endcap_[18] = tauVars.tauEmFraction; + Var_woGwGSF_Endcap_[19] = tauVars.tauLeadPFChargedHadrHoP; + Var_woGwGSF_Endcap_[20] = tauVars.tauLeadPFChargedHadrEoP; + Var_woGwGSF_Endcap_[21] = tauVars.tauVisMassIn; + Var_woGwGSF_Endcap_[22] = tauVars.taudCrackEta; mvaValue = mva_woGwGSF_EC_->GetClassifier(Var_woGwGSF_Endcap_); } - } else if (TauSignalPFGammaCandsIn > 0 && TauHasGsf > 0.5) { - if (std::abs(TauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { - Var_wGwGSF_Barrel_[0] = std::max(float(-0.1), ElecEtotOverPin); - Var_wGwGSF_Barrel_[1] = std::log(std::max(float(0.01), ElecChi2NormGSF)); - Var_wGwGSF_Barrel_[2] = ElecGSFNumHits; - Var_wGwGSF_Barrel_[3] = std::log(std::max(float(0.01), ElecGSFTrackResol)); - Var_wGwGSF_Barrel_[4] = ElecGSFTracklnPt; - Var_wGwGSF_Barrel_[5] = ElecNumHitsDiffOverSum; - Var_wGwGSF_Barrel_[6] = std::log(std::max(float(0.01), ElecChi2NormKF)); - Var_wGwGSF_Barrel_[7] = std::min(ElecDeltaPinPoutOverPin, float(1.)); - Var_wGwGSF_Barrel_[8] = std::min(ElecEecalOverPout, float(20.)); - Var_wGwGSF_Barrel_[9] = ElecDeltaEta; - Var_wGwGSF_Barrel_[10] = ElecDeltaPhi; - Var_wGwGSF_Barrel_[11] = std::min(ElecMvaInSigmaEtaEta, float(0.01)); - Var_wGwGSF_Barrel_[12] = std::min(ElecMvaInHadEnergy, float(20.)); - Var_wGwGSF_Barrel_[13] = std::min(ElecMvaInDeltaEta, float(0.1)); - Var_wGwGSF_Barrel_[14] = TauEtaAtEcalEntrance; - Var_wGwGSF_Barrel_[15] = TauLeadChargedPFCandEtaAtEcalEntrance; - Var_wGwGSF_Barrel_[16] = std::min(float(2.), TauLeadChargedPFCandPt / std::max(float(1.), TauPt)); - Var_wGwGSF_Barrel_[17] = std::log(std::max(float(1.), TauPt)); - Var_wGwGSF_Barrel_[18] = TauEmFraction; - Var_wGwGSF_Barrel_[19] = TauSignalPFGammaCandsIn; - Var_wGwGSF_Barrel_[20] = TauSignalPFGammaCandsOut; - Var_wGwGSF_Barrel_[21] = TauLeadPFChargedHadrHoP; - Var_wGwGSF_Barrel_[22] = TauLeadPFChargedHadrEoP; - Var_wGwGSF_Barrel_[23] = TauVisMassIn; - Var_wGwGSF_Barrel_[24] = TauGammaEtaMomIn; - Var_wGwGSF_Barrel_[25] = TauGammaEtaMomOut; - Var_wGwGSF_Barrel_[26] = TauGammaPhiMomIn; - Var_wGwGSF_Barrel_[27] = TauGammaPhiMomOut; - Var_wGwGSF_Barrel_[28] = TauGammaEnFracIn; - Var_wGwGSF_Barrel_[29] = TauGammaEnFracOut; - Var_wGwGSF_Barrel_[30] = TaudCrackEta; - Var_wGwGSF_Barrel_[31] = TaudCrackPhi; + } else if (tauGammaMoms.tauSignalPFGammaCandsIn > 0 && tauVars.tauHasGsf > 0.5) { + if (std::abs(tauVars.tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { + Var_wGwGSF_Barrel_[0] = std::max(float(-0.1), eleVars.elecEtotOverPin); + Var_wGwGSF_Barrel_[1] = std::log(std::max(float(0.01), eleVars.elecChi2NormGSF)); + Var_wGwGSF_Barrel_[2] = eleVars.elecGSFNumHits; + Var_wGwGSF_Barrel_[3] = std::log(std::max(float(0.01), eleVars.elecGSFTrackResol)); + Var_wGwGSF_Barrel_[4] = eleVars.elecGSFTracklnPt; + Var_wGwGSF_Barrel_[5] = elecNumHitsDiffOverSum; + Var_wGwGSF_Barrel_[6] = std::log(std::max(float(0.01), eleVars.elecChi2NormKF)); + Var_wGwGSF_Barrel_[7] = std::min(elecDeltaPinPoutOverPin, float(1.)); + Var_wGwGSF_Barrel_[8] = std::min(elecEecalOverPout, float(20.)); + Var_wGwGSF_Barrel_[9] = eleVars.elecDeltaEta; + Var_wGwGSF_Barrel_[10] = eleVars.elecDeltaPhi; + Var_wGwGSF_Barrel_[11] = std::min(eleVars.elecMvaInSigmaEtaEta, float(0.01)); + Var_wGwGSF_Barrel_[12] = std::min(eleVars.elecMvaInHadEnergy, float(20.)); + Var_wGwGSF_Barrel_[13] = std::min(eleVars.elecMvaInDeltaEta, float(0.1)); + Var_wGwGSF_Barrel_[14] = tauVars.tauEtaAtEcalEntrance; + Var_wGwGSF_Barrel_[15] = tauVars.tauLeadChargedPFCandEtaAtEcalEntrance; + Var_wGwGSF_Barrel_[16] = std::min(float(2.), tauVars.tauLeadChargedPFCandPt / std::max(float(1.), tauVars.tauPt)); + Var_wGwGSF_Barrel_[17] = std::log(std::max(float(1.), tauVars.tauPt)); + Var_wGwGSF_Barrel_[18] = tauVars.tauEmFraction; + Var_wGwGSF_Barrel_[19] = tauGammaMoms.tauSignalPFGammaCandsIn; + Var_wGwGSF_Barrel_[20] = tauGammaMoms.tauSignalPFGammaCandsOut; + Var_wGwGSF_Barrel_[21] = tauVars.tauLeadPFChargedHadrHoP; + Var_wGwGSF_Barrel_[22] = tauVars.tauLeadPFChargedHadrEoP; + Var_wGwGSF_Barrel_[23] = tauVars.tauVisMassIn; + Var_wGwGSF_Barrel_[24] = tauGammaMoms.tauGammaEtaMomIn; + Var_wGwGSF_Barrel_[25] = tauGammaMoms.tauGammaEtaMomOut; + Var_wGwGSF_Barrel_[26] = tauGammaMoms.tauGammaPhiMomIn; + Var_wGwGSF_Barrel_[27] = tauGammaMoms.tauGammaPhiMomOut; + Var_wGwGSF_Barrel_[28] = tauGammaMoms.tauGammaEnFracIn; + Var_wGwGSF_Barrel_[29] = tauGammaMoms.tauGammaEnFracOut; + Var_wGwGSF_Barrel_[30] = tauVars.taudCrackEta; + Var_wGwGSF_Barrel_[31] = tauVars.taudCrackPhi; mvaValue = mva_wGwGSF_BL_->GetClassifier(Var_wGwGSF_Barrel_); } else { - Var_wGwGSF_Endcap_[0] = std::max(float(-0.1), ElecEtotOverPin); - Var_wGwGSF_Endcap_[1] = std::log(std::max(float(0.01), ElecChi2NormGSF)); - Var_wGwGSF_Endcap_[2] = ElecGSFNumHits; - Var_wGwGSF_Endcap_[3] = std::log(std::max(float(0.01), ElecGSFTrackResol)); - Var_wGwGSF_Endcap_[4] = ElecGSFTracklnPt; - Var_wGwGSF_Endcap_[5] = ElecNumHitsDiffOverSum; - Var_wGwGSF_Endcap_[6] = std::log(std::max(float(0.01), ElecChi2NormKF)); - Var_wGwGSF_Endcap_[7] = std::min(ElecDeltaPinPoutOverPin, float(1.)); - Var_wGwGSF_Endcap_[8] = std::min(ElecEecalOverPout, float(20.)); - Var_wGwGSF_Endcap_[9] = ElecDeltaEta; - Var_wGwGSF_Endcap_[10] = ElecDeltaPhi; - Var_wGwGSF_Endcap_[11] = std::min(ElecMvaInSigmaEtaEta, float(0.01)); - Var_wGwGSF_Endcap_[12] = std::min(ElecMvaInHadEnergy, float(20.)); - Var_wGwGSF_Endcap_[13] = std::min(ElecMvaInDeltaEta, float(0.1)); - Var_wGwGSF_Endcap_[14] = TauEtaAtEcalEntrance; - Var_wGwGSF_Endcap_[15] = TauLeadChargedPFCandEtaAtEcalEntrance; - Var_wGwGSF_Endcap_[16] = std::min(float(2.), TauLeadChargedPFCandPt / std::max(float(1.), TauPt)); - Var_wGwGSF_Endcap_[17] = std::log(std::max(float(1.), TauPt)); - Var_wGwGSF_Endcap_[18] = TauEmFraction; - Var_wGwGSF_Endcap_[19] = TauSignalPFGammaCandsIn; - Var_wGwGSF_Endcap_[20] = TauSignalPFGammaCandsOut; - Var_wGwGSF_Endcap_[21] = TauLeadPFChargedHadrHoP; - Var_wGwGSF_Endcap_[22] = TauLeadPFChargedHadrEoP; - Var_wGwGSF_Endcap_[23] = TauVisMassIn; - Var_wGwGSF_Endcap_[24] = TauGammaEtaMomIn; - Var_wGwGSF_Endcap_[25] = TauGammaEtaMomOut; - Var_wGwGSF_Endcap_[26] = TauGammaPhiMomIn; - Var_wGwGSF_Endcap_[27] = TauGammaPhiMomOut; - Var_wGwGSF_Endcap_[28] = TauGammaEnFracIn; - Var_wGwGSF_Endcap_[29] = TauGammaEnFracOut; - Var_wGwGSF_Endcap_[30] = TaudCrackEta; + Var_wGwGSF_Endcap_[0] = std::max(float(-0.1), eleVars.elecEtotOverPin); + Var_wGwGSF_Endcap_[1] = std::log(std::max(float(0.01), eleVars.elecChi2NormGSF)); + Var_wGwGSF_Endcap_[2] = eleVars.elecGSFNumHits; + Var_wGwGSF_Endcap_[3] = std::log(std::max(float(0.01), eleVars.elecGSFTrackResol)); + Var_wGwGSF_Endcap_[4] = eleVars.elecGSFTracklnPt; + Var_wGwGSF_Endcap_[5] = elecNumHitsDiffOverSum; + Var_wGwGSF_Endcap_[6] = std::log(std::max(float(0.01), eleVars.elecChi2NormKF)); + Var_wGwGSF_Endcap_[7] = std::min(elecDeltaPinPoutOverPin, float(1.)); + Var_wGwGSF_Endcap_[8] = std::min(elecEecalOverPout, float(20.)); + Var_wGwGSF_Endcap_[9] = eleVars.elecDeltaEta; + Var_wGwGSF_Endcap_[10] = eleVars.elecDeltaPhi; + Var_wGwGSF_Endcap_[11] = std::min(eleVars.elecMvaInSigmaEtaEta, float(0.01)); + Var_wGwGSF_Endcap_[12] = std::min(eleVars.elecMvaInHadEnergy, float(20.)); + Var_wGwGSF_Endcap_[13] = std::min(eleVars.elecMvaInDeltaEta, float(0.1)); + Var_wGwGSF_Endcap_[14] = tauVars.tauEtaAtEcalEntrance; + Var_wGwGSF_Endcap_[15] = tauVars.tauLeadChargedPFCandEtaAtEcalEntrance; + Var_wGwGSF_Endcap_[16] = std::min(float(2.), tauVars.tauLeadChargedPFCandPt / std::max(float(1.), tauVars.tauPt)); + Var_wGwGSF_Endcap_[17] = std::log(std::max(float(1.), tauVars.tauPt)); + Var_wGwGSF_Endcap_[18] = tauVars.tauEmFraction; + Var_wGwGSF_Endcap_[19] = tauGammaMoms.tauSignalPFGammaCandsIn; + Var_wGwGSF_Endcap_[20] = tauGammaMoms.tauSignalPFGammaCandsOut; + Var_wGwGSF_Endcap_[21] = tauVars.tauLeadPFChargedHadrHoP; + Var_wGwGSF_Endcap_[22] = tauVars.tauLeadPFChargedHadrEoP; + Var_wGwGSF_Endcap_[23] = tauVars.tauVisMassIn; + Var_wGwGSF_Endcap_[24] = tauGammaMoms.tauGammaEtaMomIn; + Var_wGwGSF_Endcap_[25] = tauGammaMoms.tauGammaEtaMomOut; + Var_wGwGSF_Endcap_[26] = tauGammaMoms.tauGammaPhiMomIn; + Var_wGwGSF_Endcap_[27] = tauGammaMoms.tauGammaPhiMomOut; + Var_wGwGSF_Endcap_[28] = tauGammaMoms.tauGammaEnFracIn; + Var_wGwGSF_Endcap_[29] = tauGammaMoms.tauGammaEnFracOut; + Var_wGwGSF_Endcap_[30] = tauVars.taudCrackEta; mvaValue = mva_wGwGSF_EC_->GetClassifier(Var_wGwGSF_Endcap_); } } return mvaValue; } -double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau, const reco::GsfElectron& theGsfEle) +template +double AntiElectronIDMVA6::MVAValue(const TauType& theTau, const ElectronType& theEle) { // === tau variables === - float TauEtaAtEcalEntrance = -99.; - float sumEtaTimesEnergy = 0.; - float sumEnergy = 0.; - const std::vector& signalPFCands = thePFTau.signalPFCands(); - for (const auto& pfCandidate : signalPFCands) { - sumEtaTimesEnergy += pfCandidate->positionAtECALEntrance().eta() * pfCandidate->energy(); - sumEnergy += pfCandidate->energy(); - } - if (sumEnergy > 0.) { - TauEtaAtEcalEntrance = sumEtaTimesEnergy / sumEnergy; - } - - float TauLeadChargedPFCandEtaAtEcalEntrance = -99.; - float TauLeadChargedPFCandPt = -99.; - for (const auto& pfCandidate : signalPFCands) { - const reco::Track* track = nullptr; - if (pfCandidate->trackRef().isNonnull()) - track = pfCandidate->trackRef().get(); - else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->innerTrack().isNonnull()) - track = pfCandidate->muonRef()->innerTrack().get(); - else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->globalTrack().isNonnull()) - track = pfCandidate->muonRef()->globalTrack().get(); - else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->outerTrack().isNonnull()) - track = pfCandidate->muonRef()->outerTrack().get(); - else if (pfCandidate->gsfTrackRef().isNonnull()) - track = pfCandidate->gsfTrackRef().get(); - if (track) { - if (track->pt() > TauLeadChargedPFCandPt) { - TauLeadChargedPFCandEtaAtEcalEntrance = pfCandidate->positionAtECALEntrance().eta(); - TauLeadChargedPFCandPt = track->pt(); - } - } - } - - Float_t TauPt = thePFTau.pt(); - Float_t TauEmFraction = std::max(thePFTau.emFraction(), (Float_t)0.); - Float_t TauLeadPFChargedHadrHoP = 0.; - Float_t TauLeadPFChargedHadrEoP = 0.; - if (thePFTau.leadPFChargedHadrCand()->p() > 0.) { - TauLeadPFChargedHadrHoP = thePFTau.leadPFChargedHadrCand()->hcalEnergy() / thePFTau.leadPFChargedHadrCand()->p(); - TauLeadPFChargedHadrEoP = thePFTau.leadPFChargedHadrCand()->ecalEnergy() / thePFTau.leadPFChargedHadrCand()->p(); - } - - std::vector GammasdEtaInSigCone; - std::vector GammasdPhiInSigCone; - std::vector GammasPtInSigCone; - std::vector GammasdEtaOutSigCone; - std::vector GammasdPhiOutSigCone; - std::vector GammasPtOutSigCone; - reco::Candidate::LorentzVector pfGammaSum(0, 0, 0, 0); - reco::Candidate::LorentzVector pfChargedSum(0, 0, 0, 0); - - for (const auto& gamma : thePFTau.signalGammaCands()) { - float dR = deltaR(gamma->p4(), thePFTau.leadChargedHadrCand()->p4()); - float signalrad = std::max(0.05, std::min(0.10, 3.0 / std::max(1.0, thePFTau.pt()))); - - // pfGammas inside the tau signal cone - if (dR < signalrad) { - if (thePFTau.leadChargedHadrCand().isNonnull()) { - GammasdEtaInSigCone.push_back(gamma->eta() - thePFTau.leadChargedHadrCand()->eta()); - GammasdPhiInSigCone.push_back(gamma->phi() - thePFTau.leadChargedHadrCand()->phi()); - } else { - GammasdEtaInSigCone.push_back(gamma->eta() - thePFTau.eta()); - GammasdPhiInSigCone.push_back(gamma->phi() - thePFTau.phi()); - } - GammasPtInSigCone.push_back(gamma->pt()); - pfGammaSum += gamma->p4(); - } - // pfGammas outside the tau signal cone - else { - if (thePFTau.leadChargedHadrCand().isNonnull()) { - GammasdEtaOutSigCone.push_back(gamma->eta() - thePFTau.leadChargedHadrCand()->eta()); - GammasdPhiOutSigCone.push_back(gamma->phi() - thePFTau.leadChargedHadrCand()->phi()); - } else { - GammasdEtaOutSigCone.push_back(gamma->eta() - thePFTau.eta()); - GammasdPhiOutSigCone.push_back(gamma->phi() - thePFTau.phi()); - } - GammasPtOutSigCone.push_back(gamma->pt()); - } - } - - for (const auto& charged : thePFTau.signalChargedHadrCands()) { - float dR = deltaR(charged->p4(), thePFTau.leadChargedHadrCand()->p4()); - float signalrad = std::max(0.05, std::min(0.10, 3.0 / std::max(1.0, thePFTau.pt()))); - - // charged particles inside the tau signal cone - if (dR < signalrad) { - pfChargedSum += charged->p4(); - } - } - - Int_t TauSignalPFGammaCandsIn = GammasPtInSigCone.size(); - Int_t TauSignalPFGammaCandsOut = GammasPtOutSigCone.size(); - Float_t TauVisMassIn = (pfGammaSum + pfChargedSum).mass(); - - Float_t TauPhi = thePFTau.phi(); - float sumPhiTimesEnergy = 0.; - float sumEnergyPhi = 0.; - if (!usePhiAtEcalEntranceExtrapolation_) { - for (const auto& pfc : signalPFCands) { - sumPhiTimesEnergy += pfc->positionAtECALEntrance().phi() * pfc->energy(); - sumEnergyPhi += pfc->energy(); - } - } else { - TauPhi = -99.; - for (const auto& signalPFCand : signalPFCands) { - reco::Candidate const* signalCand = signalPFCand.get(); - float phi = thePFTau.phi(); - bool success = false; - reco::Candidate::Point aPos = positionAtECalEntrance_(signalCand, success); - if (success) { - phi = aPos.Phi(); - } - sumPhiTimesEnergy += phi * signalCand->energy(); - sumEnergy += signalCand->energy(); - } - } - if (sumEnergyPhi > 0.) { - TauPhi = sumPhiTimesEnergy / sumEnergyPhi; - } - Float_t TaudCrackPhi = dCrackPhi(TauPhi, TauEtaAtEcalEntrance); - Float_t TaudCrackEta = dCrackEta(TauEtaAtEcalEntrance); - Float_t TauHasGsf = thePFTau.leadPFChargedHadrCand()->gsfTrackRef().isNonnull(); + TauVars tauVars = AntiElectronIDMVA6::getTauVars(theTau); + TauGammaVecs tauGammaVecs = AntiElectronIDMVA6::getTauGammaVecs(theTau); // === electron variables === - Float_t ElecEta = theGsfEle.eta(); - Float_t ElecPhi = theGsfEle.phi(); - - //Variables related to the electron Cluster - Float_t ElecEe = 0.; - Float_t ElecEgamma = 0.; - reco::SuperClusterRef pfSuperCluster = theGsfEle.superCluster(); - if (pfSuperCluster.isNonnull() && pfSuperCluster.isAvailable()) { - for (reco::CaloCluster_iterator pfCluster = pfSuperCluster->clustersBegin(); - pfCluster != pfSuperCluster->clustersEnd(); - ++pfCluster) { - double pfClusterEn = (*pfCluster)->energy(); - if (pfCluster == pfSuperCluster->clustersBegin()) - ElecEe += pfClusterEn; - else - ElecEgamma += pfClusterEn; - } - } - - Float_t ElecPin = std::sqrt(theGsfEle.trackMomentumAtVtx().Mag2()); - Float_t ElecPout = std::sqrt(theGsfEle.trackMomentumOut().Mag2()); - Float_t ElecEtotOverPin = (ElecPin > 0.0) ? ((ElecEe + ElecEgamma) / ElecPin) : -0.1; - Float_t ElecEecal = theGsfEle.ecalEnergy(); - Float_t ElecDeltaEta = theGsfEle.deltaEtaSeedClusterTrackAtCalo(); - Float_t ElecDeltaPhi = theGsfEle.deltaPhiSeedClusterTrackAtCalo(); - Float_t ElecMvaInSigmaEtaEta = (theGsfEle).mvaInput().sigmaEtaEta; - Float_t ElecMvaInHadEnergy = (theGsfEle).mvaInput().hadEnergy; - Float_t ElecMvaInDeltaEta = (theGsfEle).mvaInput().deltaEta; - - //Variables related to the GsfTrack - Float_t ElecChi2NormGSF = -99.; - Float_t ElecGSFNumHits = -99.; - Float_t ElecGSFTrackResol = -99.; - Float_t ElecGSFTracklnPt = -99.; - if (theGsfEle.gsfTrack().isNonnull()) { - ElecChi2NormGSF = (theGsfEle).gsfTrack()->normalizedChi2(); - ElecGSFNumHits = (theGsfEle).gsfTrack()->numberOfValidHits(); - if (theGsfEle.gsfTrack()->pt() > 0.) { - ElecGSFTrackResol = theGsfEle.gsfTrack()->ptError() / theGsfEle.gsfTrack()->pt(); - ElecGSFTracklnPt = log(theGsfEle.gsfTrack()->pt()) * M_LN10; - } - } + EleVars eleVars = AntiElectronIDMVA6::getEleVars(theEle); - //Variables related to the CtfTrack - Float_t ElecChi2NormKF = -99.; - Float_t ElecKFNumHits = -99.; - if (theGsfEle.closestCtfTrackRef().isNonnull()) { - ElecChi2NormKF = (theGsfEle).closestCtfTrackRef()->normalizedChi2(); - ElecKFNumHits = (theGsfEle).closestCtfTrackRef()->numberOfValidHits(); - } - - return MVAValue(TauPt, - TauEtaAtEcalEntrance, - TauPhi, - TauLeadChargedPFCandPt, - TauLeadChargedPFCandEtaAtEcalEntrance, - TauEmFraction, - TauLeadPFChargedHadrHoP, - TauLeadPFChargedHadrEoP, - TauVisMassIn, - TaudCrackEta, - TaudCrackPhi, - TauHasGsf, - TauSignalPFGammaCandsIn, - TauSignalPFGammaCandsOut, - GammasdEtaInSigCone, - GammasdPhiInSigCone, - GammasPtInSigCone, - GammasdEtaOutSigCone, - GammasdPhiOutSigCone, - GammasPtOutSigCone, - ElecEta, - ElecPhi, - ElecEtotOverPin, - ElecChi2NormGSF, - ElecChi2NormKF, - ElecGSFNumHits, - ElecKFNumHits, - ElecGSFTrackResol, - ElecGSFTracklnPt, - ElecPin, - ElecPout, - ElecEecal, - ElecDeltaEta, - ElecDeltaPhi, - ElecMvaInSigmaEtaEta, - ElecMvaInHadEnergy, - ElecMvaInDeltaEta); + return MVAValue(tauVars, tauGammaVecs, eleVars); } -double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau) { +template +double AntiElectronIDMVA6::MVAValue(const TauType& theTau) { // === tau variables === - float TauEtaAtEcalEntrance = -99.; - float sumEtaTimesEnergy = 0.; - float sumEnergy = 0.; - const std::vector& signalPFCands = thePFTau.signalPFCands(); - for (const auto& pfCandidate : signalPFCands) { - sumEtaTimesEnergy += pfCandidate->positionAtECALEntrance().eta() * pfCandidate->energy(); - sumEnergy += pfCandidate->energy(); - } - if (sumEnergy > 0.) { - TauEtaAtEcalEntrance = sumEtaTimesEnergy / sumEnergy; - } + TauVars tauVars = AntiElectronIDMVA6::getTauVars(theTau); + TauGammaVecs tauGammaVecs = AntiElectronIDMVA6::getTauGammaVecs(theTau); - float TauLeadChargedPFCandEtaAtEcalEntrance = -99.; - float TauLeadChargedPFCandPt = -99.; - for (const auto& pfCandidate : signalPFCands) { - const reco::Track* track = nullptr; - if (pfCandidate->trackRef().isNonnull()) - track = pfCandidate->trackRef().get(); - else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->innerTrack().isNonnull()) - track = pfCandidate->muonRef()->innerTrack().get(); - else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->globalTrack().isNonnull()) - track = pfCandidate->muonRef()->globalTrack().get(); - else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->outerTrack().isNonnull()) - track = pfCandidate->muonRef()->outerTrack().get(); - else if (pfCandidate->gsfTrackRef().isNonnull()) - track = pfCandidate->gsfTrackRef().get(); - if (track) { - if (track->pt() > TauLeadChargedPFCandPt) { - TauLeadChargedPFCandEtaAtEcalEntrance = pfCandidate->positionAtECALEntrance().eta(); - TauLeadChargedPFCandPt = track->pt(); - } - } - } + // === electron variables === + EleVars eleVars; + eleVars.elecEta = 9.9; //Dummy value used in MVA training - Float_t TauPt = thePFTau.pt(); - Float_t TauEmFraction = std::max(thePFTau.emFraction(), (Float_t)0.); - Float_t TauLeadPFChargedHadrHoP = 0.; - Float_t TauLeadPFChargedHadrEoP = 0.; - if (thePFTau.leadPFChargedHadrCand()->p() > 0.) { - TauLeadPFChargedHadrHoP = thePFTau.leadPFChargedHadrCand()->hcalEnergy() / thePFTau.leadPFChargedHadrCand()->p(); - TauLeadPFChargedHadrEoP = thePFTau.leadPFChargedHadrCand()->ecalEnergy() / thePFTau.leadPFChargedHadrCand()->p(); - } + return MVAValue(tauVars, tauGammaVecs, eleVars); +} - std::vector GammasdEtaInSigCone; - std::vector GammasdPhiInSigCone; - std::vector GammasPtInSigCone; - std::vector GammasdEtaOutSigCone; - std::vector GammasdPhiOutSigCone; - std::vector GammasPtOutSigCone; +template +TauVars AntiElectronIDMVA6::getTauVars(const TauType& theTau){ + TauVars tauVars; + if (std::is_same::value || + std::is_same::value) + tauVars = getTauVarsTypeSpecific(theTau); + else + throw cms::Exception("AntiElectronIDMVA6") + << "Unsupported TauType used. You must use either reco::PFTau or pat::Tau."; + tauVars.tauPt = theTau.pt(); + reco::Candidate::LorentzVector pfGammaSum(0, 0, 0, 0); reco::Candidate::LorentzVector pfChargedSum(0, 0, 0, 0); - - for (const auto& gamma : thePFTau.signalGammaCands()) { - float dR = deltaR(gamma->p4(), thePFTau.leadChargedHadrCand()->p4()); - float signalrad = std::max(0.05, std::min(0.10, 3.0 / std::max(1.0, thePFTau.pt()))); - - // pfGammas inside the tau signal cone + float signalrad = std::max(0.05, std::min(0.10, 3.0 / std::max(1.0, theTau.pt()))); + for (const auto& charged : theTau.signalChargedHadrCands()) { + float dR = deltaR(charged->p4(), theTau.leadChargedHadrCand()->p4()); + // charged particles inside the tau signal cone if (dR < signalrad) { - if (thePFTau.leadChargedHadrCand().isNonnull()) { - GammasdEtaInSigCone.push_back(gamma->eta() - thePFTau.leadChargedHadrCand()->eta()); - GammasdPhiInSigCone.push_back(gamma->phi() - thePFTau.leadChargedHadrCand()->phi()); - } else { - GammasdEtaInSigCone.push_back(gamma->eta() - thePFTau.eta()); - GammasdPhiInSigCone.push_back(gamma->phi() - thePFTau.phi()); - } - GammasPtInSigCone.push_back(gamma->pt()); - pfGammaSum += gamma->p4(); - } - // pfGammas outside the tau signal cone - else { - if (thePFTau.leadChargedHadrCand().isNonnull()) { - GammasdEtaOutSigCone.push_back(gamma->eta() - thePFTau.leadChargedHadrCand()->eta()); - GammasdPhiOutSigCone.push_back(gamma->phi() - thePFTau.leadChargedHadrCand()->phi()); - } else { - GammasdEtaOutSigCone.push_back(gamma->eta() - thePFTau.eta()); - GammasdPhiOutSigCone.push_back(gamma->phi() - thePFTau.phi()); - } - GammasPtOutSigCone.push_back(gamma->pt()); + pfChargedSum += charged->p4(); } } - - for (const auto& charged : thePFTau.signalChargedHadrCands()) { - float dR = deltaR(charged->p4(), thePFTau.leadChargedHadrCand()->p4()); - float signalrad = std::max(0.05, std::min(0.10, 3.0 / std::max(1.0, thePFTau.pt()))); - - // charged particles inside the tau signal cone + for (const auto& gamma : theTau.signalGammaCands()) { + float dR = deltaR(gamma->p4(), theTau.leadChargedHadrCand()->p4()); + // pfGammas inside the tau signal cone if (dR < signalrad) { - pfChargedSum += charged->p4(); + pfGammaSum += gamma->p4(); } } + tauVars.tauVisMassIn = (pfGammaSum + pfChargedSum).mass(); - Int_t TauSignalPFGammaCandsIn = GammasPtInSigCone.size(); - Int_t TauSignalPFGammaCandsOut = GammasPtOutSigCone.size(); - Float_t TauVisMassIn = (pfGammaSum + pfChargedSum).mass(); - - Float_t TauPhi = thePFTau.phi(); - float sumPhiTimesEnergy = 0.; - float sumEnergyPhi = 0.; - if (!usePhiAtEcalEntranceExtrapolation_) { - for (const auto& pfCandidate : signalPFCands) { - sumPhiTimesEnergy += pfCandidate->positionAtECALEntrance().phi() * pfCandidate->energy(); - sumEnergyPhi += pfCandidate->energy(); - } - } else { - TauPhi = -99.; - for (const auto& signalPFCand : signalPFCands) { - reco::Candidate const* signalCand = signalPFCand.get(); - float phi = thePFTau.phi(); - bool success = false; - reco::Candidate::Point aPos = positionAtECalEntrance_(signalCand, success); - if (success) { - phi = aPos.Phi(); + tauVars.tauHasGsf = 0; + if (theTau.leadChargedHadrCand().isNonnull()) { + pat::PackedCandidate const* packedLeadTauCand = + dynamic_cast(theTau.leadChargedHadrCand().get()); + if (packedLeadTauCand != nullptr) { + if (std::abs(packedLeadTauCand->pdgId()) == 11) + tauVars.tauHasGsf = 1; + } else { + reco::PFCandidate const* pfLeadTauCand = + dynamic_cast(theTau.leadChargedHadrCand().get()); + if (pfLeadTauCand != nullptr && pfLeadTauCand->gsfTrackRef().isNonnull()) { + tauVars.tauHasGsf = 1; } - sumPhiTimesEnergy += phi * signalCand->energy(); - sumEnergy += signalCand->energy(); } } - if (sumEnergyPhi > 0.) { - TauPhi = sumPhiTimesEnergy / sumEnergyPhi; - } - Float_t TaudCrackPhi = dCrackPhi(TauPhi, TauEtaAtEcalEntrance); - Float_t TaudCrackEta = dCrackEta(TauEtaAtEcalEntrance); - Float_t TauHasGsf = thePFTau.leadPFChargedHadrCand()->gsfTrackRef().isNonnull(); + tauVars.taudCrackPhi = dCrackPhi(tauVars.tauPhi, tauVars.tauEtaAtEcalEntrance); + tauVars.taudCrackEta = dCrackEta(tauVars.tauEtaAtEcalEntrance); - // === electron variables === - Float_t dummyElecEta = 9.9; - - return MVAValue(TauPt, - TauEtaAtEcalEntrance, - TauPhi, - TauLeadChargedPFCandPt, - TauLeadChargedPFCandEtaAtEcalEntrance, - TauEmFraction, - TauLeadPFChargedHadrHoP, - TauLeadPFChargedHadrEoP, - TauVisMassIn, - TaudCrackEta, - TaudCrackPhi, - TauHasGsf, - TauSignalPFGammaCandsIn, - TauSignalPFGammaCandsOut, - GammasdEtaInSigCone, - GammasdPhiInSigCone, - GammasPtInSigCone, - GammasdEtaOutSigCone, - GammasdPhiOutSigCone, - GammasPtOutSigCone, - dummyElecEta, - 0., - 0., - 0., - 0., - 0., - 0., - 0., - 0., - 0., - 0., - 0., - 0., - 0., - 0., - 0., - 0.); + return tauVars; } -double AntiElectronIDMVA6::MVAValue(const pat::Tau& theTau, const pat::Electron& theEle) { - // === tau variables === - float TauEtaAtEcalEntrance = theTau.etaAtEcalEntrance(); - - float TauLeadChargedPFCandEtaAtEcalEntrance = theTau.etaAtEcalEntranceLeadChargedCand(); - float TauLeadChargedPFCandPt = theTau.ptLeadChargedCand(); +template +TauGammaVecs AntiElectronIDMVA6::getTauGammaVecs(const TauType& theTau){ + TauGammaVecs tauGammaVecs; - Float_t TauPt = theTau.pt(); - //Float_t TauEmFraction = std::max(theTau.ecalEnergy()/(theTau.ecalEnergy()+theTau.hcalEnergy()), (Float_t)0.); - Float_t TauEmFraction = std::max(theTau.emFraction_MVA(), (Float_t)0.); - Float_t TauLeadPFChargedHadrHoP = 0.; - Float_t TauLeadPFChargedHadrEoP = 0.; - if (theTau.leadChargedHadrCand()->p() > 0.) { - TauLeadPFChargedHadrHoP = theTau.hcalEnergyLeadChargedHadrCand() / theTau.leadChargedHadrCand()->p(); - TauLeadPFChargedHadrEoP = theTau.ecalEnergyLeadChargedHadrCand() / theTau.leadChargedHadrCand()->p(); - } - - std::vector GammasdEtaInSigCone; - std::vector GammasdPhiInSigCone; - std::vector GammasPtInSigCone; - std::vector GammasdEtaOutSigCone; - std::vector GammasdPhiOutSigCone; - std::vector GammasPtOutSigCone; - reco::Candidate::LorentzVector pfGammaSum(0, 0, 0, 0); - reco::Candidate::LorentzVector pfChargedSum(0, 0, 0, 0); - - const reco::CandidatePtrVector signalGammaCands = theTau.signalGammaCands(); - for (const auto& gamma : signalGammaCands) { + float signalrad = std::max(0.05, std::min(0.10, 3.0 / std::max(1.0, theTau.pt()))); + for (const auto& gamma : theTau.signalGammaCands()) { float dR = deltaR(gamma->p4(), theTau.leadChargedHadrCand()->p4()); - float signalrad = std::max(0.05, std::min(0.10, 3.0 / std::max(1.0, theTau.pt()))); - // pfGammas inside the tau signal cone if (dR < signalrad) { - if (theTau.leadChargedHadrCand().isNonnull()) { - GammasdEtaInSigCone.push_back(gamma->eta() - theTau.leadChargedHadrCand()->eta()); - GammasdPhiInSigCone.push_back(gamma->phi() - theTau.leadChargedHadrCand()->phi()); - //A.-C. please check whether this change is safe against future trainings - //GammasdPhiInSigCone.push_back(deltaPhi((*gamma)->phi(), theTau.leadChargedHadrCand()->phi())); - } else { - GammasdEtaInSigCone.push_back(gamma->eta() - theTau.eta()); - GammasdPhiInSigCone.push_back(gamma->phi() - theTau.phi()); - //A.-C. please check whether this change is safe against future trainings - //GammasdPhiInSigCone.push_back(deltaPhi(gamma->phi(), theTau.phi())); - } - GammasPtInSigCone.push_back(gamma->pt()); - pfGammaSum += gamma->p4(); + tauGammaVecs.gammasdEtaInSigCone.push_back(gamma->eta() - theTau.leadChargedHadrCand()->eta()); + tauGammaVecs.gammasdPhiInSigCone.push_back(gamma->phi() - theTau.leadChargedHadrCand()->phi()); + tauGammaVecs.gammasPtInSigCone.push_back(gamma->pt()); } // pfGammas outside the tau signal cone else { - if (theTau.leadChargedHadrCand().isNonnull()) { - GammasdEtaOutSigCone.push_back(gamma->eta() - theTau.leadChargedHadrCand()->eta()); - GammasdPhiOutSigCone.push_back(gamma->phi() - theTau.leadChargedHadrCand()->phi()); - //A.-C. please check whether this change is safe against future trainings - //GammasdPhiOutSigCone.push_back(deltaPhi(gamma->phi(), theTau.leadChargedHadrCand()->phi())); - } else { - GammasdEtaOutSigCone.push_back(gamma->eta() - theTau.eta()); - GammasdPhiOutSigCone.push_back(gamma->phi() - theTau.phi()); - //A.-C. please chaekc whether this change is safe against future trainings - //GammasdPhiOutSigCone.push_back(deltaPhi(gamma->phi(), theTau.phi())); - } - GammasPtOutSigCone.push_back(gamma->pt()); - } - } - - const reco::CandidatePtrVector signalChargedCands = theTau.signalChargedHadrCands(); - for (const auto& charged : signalChargedCands) { - float dR = deltaR(charged->p4(), theTau.leadChargedHadrCand()->p4()); - float signalrad = std::max(0.05, std::min(0.10, 3.0 / std::max(1.0, theTau.pt()))); - - // charged particles inside the tau signal cone - if (dR < signalrad) { - pfChargedSum += charged->p4(); - } - } - - Int_t TauSignalPFGammaCandsIn = GammasPtInSigCone.size(); - Int_t TauSignalPFGammaCandsOut = GammasPtOutSigCone.size(); - Float_t TauVisMassIn = (pfGammaSum + pfChargedSum).mass(); - Float_t TauPhi = -99.; - if (usePhiAtEcalEntranceExtrapolation_) { - float sumPhiTimesEnergy = 0.; - float sumEnergy = 0.; - const reco::CandidatePtrVector signalCands = theTau.signalCands(); - for (const auto& signalCandPtr : signalCands) { - reco::Candidate const* signalCand = signalCandPtr.get(); - float phi = theTau.phi(); - bool success = false; - reco::Candidate::Point aPos = positionAtECalEntrance_(signalCand, success); - if (success) { - phi = aPos.Phi(); - } - sumPhiTimesEnergy += phi * signalCand->energy(); - sumEnergy += signalCand->energy(); - } - if (sumEnergy > 0.) { - TauPhi = sumPhiTimesEnergy / sumEnergy; + tauGammaVecs.gammasdEtaOutSigCone.push_back(gamma->eta() - theTau.leadChargedHadrCand()->eta()); + tauGammaVecs.gammasdPhiOutSigCone.push_back(gamma->phi() - theTau.leadChargedHadrCand()->phi()); + tauGammaVecs.gammasPtOutSigCone.push_back(gamma->pt()); } - } else { - TauPhi = theTau.phiAtEcalEntrance(); } + return tauGammaVecs; +} - Float_t TaudCrackPhi = dCrackPhi(TauPhi, TauEtaAtEcalEntrance); - Float_t TaudCrackEta = dCrackEta(TauEtaAtEcalEntrance); +template +EleVars AntiElectronIDMVA6::getEleVars(const ElectronType& theEle){ - Float_t TauHasGsf = 0; - pat::PackedCandidate const* packedLeadTauCand = - dynamic_cast(theTau.leadChargedHadrCand().get()); - if (abs(packedLeadTauCand->pdgId()) == 11) - TauHasGsf = 1; + EleVars eleVars; - // === electron variables === - Float_t ElecEta = theEle.eta(); - Float_t ElecPhi = theEle.phi(); + eleVars.elecEta = theEle.eta(); + eleVars.elecPhi = theEle.phi(); - //Variables related to the electron Cluster - Float_t ElecEe = 0.; - Float_t ElecEgamma = 0.; + // Variables related to the electron Cluster + float elecEe = 0.; + float elecEgamma = 0.; reco::SuperClusterRef pfSuperCluster = theEle.superCluster(); if (pfSuperCluster.isNonnull() && pfSuperCluster.isAvailable()) { for (reco::CaloCluster_iterator pfCluster = pfSuperCluster->clustersBegin(); @@ -1016,229 +533,49 @@ double AntiElectronIDMVA6::MVAValue(const pat::Tau& theTau, const pat::Electron& ++pfCluster) { double pfClusterEn = (*pfCluster)->energy(); if (pfCluster == pfSuperCluster->clustersBegin()) - ElecEe += pfClusterEn; + elecEe += pfClusterEn; else - ElecEgamma += pfClusterEn; + elecEgamma += pfClusterEn; } } - Float_t ElecPin = std::sqrt(theEle.trackMomentumAtVtx().Mag2()); - Float_t ElecPout = std::sqrt(theEle.trackMomentumOut().Mag2()); - Float_t ElecEtotOverPin = (ElecPin > 0.0) ? ((ElecEe + ElecEgamma) / ElecPin) : -0.1; - Float_t ElecEecal = theEle.ecalEnergy(); - Float_t ElecDeltaEta = theEle.deltaEtaSeedClusterTrackAtCalo(); - Float_t ElecDeltaPhi = theEle.deltaPhiSeedClusterTrackAtCalo(); - Float_t ElecMvaInSigmaEtaEta = (theEle).mvaInput().sigmaEtaEta; - Float_t ElecMvaInHadEnergy = (theEle).mvaInput().hadEnergy; - Float_t ElecMvaInDeltaEta = (theEle).mvaInput().deltaEta; - - //Variables related to the GsfTrack - Float_t ElecChi2NormGSF = -99.; - Float_t ElecGSFNumHits = -99.; - Float_t ElecGSFTrackResol = -99.; - Float_t ElecGSFTracklnPt = -99.; + eleVars.elecPin = std::sqrt(theEle.trackMomentumAtVtx().Mag2()); + eleVars.elecPout = std::sqrt(theEle.trackMomentumOut().Mag2()); + eleVars.elecEtotOverPin = (eleVars.elecPin > 0.0) ? ((elecEe + elecEgamma) / eleVars.elecPin) : -0.1; + eleVars.elecEecal = theEle.ecalEnergy(); + eleVars.elecDeltaEta = theEle.deltaEtaSeedClusterTrackAtCalo(); + eleVars.elecDeltaPhi = theEle.deltaPhiSeedClusterTrackAtCalo(); + eleVars.elecMvaInSigmaEtaEta = theEle.mvaInput().sigmaEtaEta; + eleVars.elecMvaInHadEnergy = theEle.mvaInput().hadEnergy; + eleVars.elecMvaInDeltaEta = theEle.mvaInput().deltaEta; + + // Variables related to the GsfTrack + eleVars.elecChi2NormGSF = -99.; + eleVars.elecGSFNumHits = -99.; + eleVars.elecGSFTrackResol = -99.; + eleVars.elecGSFTracklnPt = -99.; if (theEle.gsfTrack().isNonnull()) { - ElecChi2NormGSF = (theEle).gsfTrack()->normalizedChi2(); - ElecGSFNumHits = (theEle).gsfTrack()->numberOfValidHits(); + eleVars.elecChi2NormGSF = theEle.gsfTrack()->normalizedChi2(); + eleVars.elecGSFNumHits = theEle.gsfTrack()->numberOfValidHits(); if (theEle.gsfTrack()->pt() > 0.) { - ElecGSFTrackResol = theEle.gsfTrack()->ptError() / theEle.gsfTrack()->pt(); - ElecGSFTracklnPt = log(theEle.gsfTrack()->pt()) * M_LN10; + eleVars.elecGSFTrackResol = theEle.gsfTrack()->ptError() / theEle.gsfTrack()->pt(); + eleVars.elecGSFTracklnPt = log(theEle.gsfTrack()->pt()) * M_LN10; } } - //Variables related to the CtfTrack - Float_t ElecChi2NormKF = -99.; - Float_t ElecKFNumHits = -99.; + // Variables related to the CtfTrack + eleVars.elecChi2NormKF = -99.; + eleVars.elecKFNumHits = -99.; if (theEle.closestCtfTrackRef().isNonnull()) { - ElecChi2NormKF = (theEle).closestCtfTrackRef()->normalizedChi2(); - ElecKFNumHits = (theEle).closestCtfTrackRef()->numberOfValidHits(); - } - - return MVAValue(TauPt, - TauEtaAtEcalEntrance, - TauPhi, - TauLeadChargedPFCandPt, - TauLeadChargedPFCandEtaAtEcalEntrance, - TauEmFraction, - TauLeadPFChargedHadrHoP, - TauLeadPFChargedHadrEoP, - TauVisMassIn, - TaudCrackEta, - TaudCrackPhi, - TauHasGsf, - TauSignalPFGammaCandsIn, - TauSignalPFGammaCandsOut, - GammasdEtaInSigCone, - GammasdPhiInSigCone, - GammasPtInSigCone, - GammasdEtaOutSigCone, - GammasdPhiOutSigCone, - GammasPtOutSigCone, - ElecEta, - ElecPhi, - ElecEtotOverPin, - ElecChi2NormGSF, - ElecChi2NormKF, - ElecGSFNumHits, - ElecKFNumHits, - ElecGSFTrackResol, - ElecGSFTracklnPt, - ElecPin, - ElecPout, - ElecEecal, - ElecDeltaEta, - ElecDeltaPhi, - ElecMvaInSigmaEtaEta, - ElecMvaInHadEnergy, - ElecMvaInDeltaEta); -} - -double AntiElectronIDMVA6::MVAValue(const pat::Tau& theTau) { - // === tau variables === - float TauEtaAtEcalEntrance = theTau.etaAtEcalEntrance(); - - float TauLeadChargedPFCandEtaAtEcalEntrance = theTau.etaAtEcalEntranceLeadChargedCand(); - float TauLeadChargedPFCandPt = theTau.ptLeadChargedCand(); - - Float_t TauPt = theTau.pt(); - //Float_t TauEmFraction = std::max(theTau.ecalEnergy()/(theTau.ecalEnergy()+theTau.hcalEnergy()), (Float_t)0.); - Float_t TauEmFraction = std::max(theTau.emFraction_MVA(), (Float_t)0.); - Float_t TauLeadPFChargedHadrHoP = 0.; - Float_t TauLeadPFChargedHadrEoP = 0.; - if (theTau.leadChargedHadrCand()->p() > 0.) { - TauLeadPFChargedHadrHoP = theTau.hcalEnergyLeadChargedHadrCand() / theTau.leadChargedHadrCand()->p(); - TauLeadPFChargedHadrEoP = theTau.ecalEnergyLeadChargedHadrCand() / theTau.leadChargedHadrCand()->p(); - } - - std::vector GammasdEtaInSigCone; - std::vector GammasdPhiInSigCone; - std::vector GammasPtInSigCone; - std::vector GammasdEtaOutSigCone; - std::vector GammasdPhiOutSigCone; - std::vector GammasPtOutSigCone; - reco::Candidate::LorentzVector pfGammaSum(0, 0, 0, 0); - reco::Candidate::LorentzVector pfChargedSum(0, 0, 0, 0); - - const reco::CandidatePtrVector signalGammaCands = theTau.signalGammaCands(); - for (const auto& gamma : signalGammaCands) { - float dR = deltaR(gamma->p4(), theTau.leadChargedHadrCand()->p4()); - float signalrad = std::max(0.05, std::min(0.10, 3.0 / std::max(1.0, theTau.pt()))); - - // pfGammas inside the tau signal cone - if (dR < signalrad) { - if (theTau.leadChargedHadrCand().isNonnull()) { - GammasdEtaInSigCone.push_back(gamma->eta() - theTau.leadChargedHadrCand()->eta()); - GammasdPhiInSigCone.push_back(gamma->phi() - theTau.leadChargedHadrCand()->phi()); - } else { - GammasdEtaInSigCone.push_back(gamma->eta() - theTau.eta()); - GammasdPhiInSigCone.push_back(gamma->phi() - theTau.phi()); - } - GammasPtInSigCone.push_back(gamma->pt()); - pfGammaSum += gamma->p4(); - } - // pfGammas outside the tau signal cone - else { - if (theTau.leadChargedHadrCand().isNonnull()) { - GammasdEtaOutSigCone.push_back(gamma->eta() - theTau.leadChargedHadrCand()->eta()); - GammasdPhiOutSigCone.push_back(gamma->phi() - theTau.leadChargedHadrCand()->phi()); - } else { - GammasdEtaOutSigCone.push_back(gamma->eta() - theTau.eta()); - GammasdPhiOutSigCone.push_back(gamma->phi() - theTau.phi()); - } - GammasPtOutSigCone.push_back(gamma->pt()); - } - } - - const reco::CandidatePtrVector signalChargedCands = theTau.signalChargedHadrCands(); - for (const auto& charged : signalChargedCands) { - float dR = deltaR(charged->p4(), theTau.leadChargedHadrCand()->p4()); - float signalrad = std::max(0.05, std::min(0.10, 3.0 / std::max(1.0, theTau.pt()))); - - // charged particles inside the tau signal cone - if (dR < signalrad) { - pfChargedSum += charged->p4(); - } + eleVars.elecChi2NormKF = theEle.closestCtfTrackRef()->normalizedChi2(); + eleVars.elecKFNumHits = theEle.closestCtfTrackRef()->numberOfValidHits(); } - Int_t TauSignalPFGammaCandsIn = GammasPtInSigCone.size(); - Int_t TauSignalPFGammaCandsOut = GammasPtOutSigCone.size(); - Float_t TauVisMassIn = (pfGammaSum + pfChargedSum).mass(); - Float_t TauPhi = -99.; - if (usePhiAtEcalEntranceExtrapolation_) { - float sumPhiTimesEnergy = 0.; - float sumEnergy = 0.; - const reco::CandidatePtrVector signalCands = theTau.signalCands(); - for (const auto& signalCandPtr : signalCands) { - reco::Candidate const* signalCand = signalCandPtr.get(); - float phi = theTau.phi(); - bool success = false; - reco::Candidate::Point aPos = positionAtECalEntrance_(signalCand, success); - if (success) { - phi = aPos.Phi(); - } - sumPhiTimesEnergy += phi * signalCand->energy(); - sumEnergy += signalCand->energy(); - } - if (sumEnergy > 0.) { - TauPhi = sumPhiTimesEnergy / sumEnergy; - } - } else { - TauPhi = theTau.phiAtEcalEntrance(); - } - - Float_t TaudCrackPhi = dCrackPhi(TauPhi, TauEtaAtEcalEntrance); - Float_t TaudCrackEta = dCrackEta(TauEtaAtEcalEntrance); - - Float_t TauHasGsf = 0; - pat::PackedCandidate const* packedLeadTauCand = - dynamic_cast(theTau.leadChargedHadrCand().get()); - //const reco::Track & pseudoTrack = packedLeadTauCand->pseudoTrack(); - if (abs(packedLeadTauCand->pdgId()) == 11) - TauHasGsf = 1; - - // === electron variables === - Float_t dummyElecEta = 9.9; - - return MVAValue(TauPt, - TauEtaAtEcalEntrance, - TauPhi, - TauLeadChargedPFCandPt, - TauLeadChargedPFCandEtaAtEcalEntrance, - TauEmFraction, - TauLeadPFChargedHadrHoP, - TauLeadPFChargedHadrEoP, - TauVisMassIn, - TaudCrackEta, - TaudCrackPhi, - TauHasGsf, - TauSignalPFGammaCandsIn, - TauSignalPFGammaCandsOut, - GammasdEtaInSigCone, - GammasdPhiInSigCone, - GammasPtInSigCone, - GammasdEtaOutSigCone, - GammasdPhiOutSigCone, - GammasPtOutSigCone, - dummyElecEta, - 0., - 0., - 0., - 0., - 0., - 0., - 0., - 0., - 0., - 0., - 0., - 0., - 0., - 0., - 0., - 0.); + return eleVars; } -double AntiElectronIDMVA6::minimum(double a, double b) { +template +double AntiElectronIDMVA6::minimum(double a, double b) { if (std::abs(b) < std::abs(a)) return b; else @@ -1263,7 +600,8 @@ namespace { } // namespace -double AntiElectronIDMVA6::dCrackPhi(double phi, double eta) { +template +double AntiElectronIDMVA6::dCrackPhi(double phi, double eta) { //--- compute the (unsigned) distance to the closest phi-crack in the ECAL barrel constexpr double pi = M_PI; // 3.14159265358979323846; @@ -1313,7 +651,8 @@ double AntiElectronIDMVA6::dCrackPhi(double phi, double eta) { return std::abs(retVal); } -double AntiElectronIDMVA6::dCrackEta(double eta) { +template +double AntiElectronIDMVA6::dCrackEta(double eta) { //--- compute the (unsigned) distance to the closest eta-crack in the ECAL barrel // IN: define locations of the eta-cracks @@ -1330,3 +669,144 @@ double AntiElectronIDMVA6::dCrackEta(double eta) { return std::abs(retVal); } + +// pat::Tau +template +TauVars AntiElectronIDMVA6::getTauVarsTypeSpecific(const pat::Tau& theTau) { + TauVars tauVars; + tauVars.tauEtaAtEcalEntrance = theTau.etaAtEcalEntrance(); + tauVars.tauLeadChargedPFCandEtaAtEcalEntrance = theTau.etaAtEcalEntranceLeadChargedCand(); + tauVars.tauLeadChargedPFCandPt = theTau.ptLeadChargedCand(); + tauVars.tauPhi = theTau.phi(); + if (!usePhiAtEcalEntranceExtrapolation_) { + tauVars.tauPhi = theTau.phiAtEcalEntrance(); + } else { + float sumPhiTimesEnergy = 0.; + float sumEnergy = 0.; + for (const auto& candidate : theTau.signalCands()) { + float phiAtECalEntrance = candidate->phi(); + bool success = false; + reco::Candidate::Point posAtECal = + positionAtECalEntrance_(candidate.get(), success); + if (success) { + phiAtECalEntrance = posAtECal.phi(); + } + sumPhiTimesEnergy += phiAtECalEntrance * candidate->energy(); + sumEnergy += candidate->energy(); + } + if (sumEnergy > 0.) { + tauVars.tauPhi = sumPhiTimesEnergy / sumEnergy; + } + } + tauVars.tauEmFraction = std::max(theTau.emFraction_MVA(), (float)0.); + tauVars.tauLeadPFChargedHadrHoP = 0.; + tauVars.tauLeadPFChargedHadrEoP = 0.; + if (theTau.leadChargedHadrCand()->p() > 0.) { + tauVars.tauLeadPFChargedHadrHoP = theTau.hcalEnergyLeadChargedHadrCand() / theTau.leadChargedHadrCand()->p(); + tauVars.tauLeadPFChargedHadrEoP = theTau.ecalEnergyLeadChargedHadrCand() / theTau.leadChargedHadrCand()->p(); + } + + return tauVars; +} + +// reco::PFTau +template +TauVars AntiElectronIDMVA6::getTauVarsTypeSpecific(const reco::PFTau& theTau) { + TauVars tauVars; + tauVars.tauEtaAtEcalEntrance = -99.; + tauVars.tauLeadChargedPFCandEtaAtEcalEntrance = -99.; + tauVars.tauLeadChargedPFCandPt = -99.; + float sumEtaTimesEnergy = 0.; + float sumPhiTimesEnergy = 0.; + float sumEnergy = 0.; + tauVars.tauPhi = theTau.phi(); + // Check type of candidates building tau to avoid dynamic casts further + bool isFromPFCands = (theTau.leadCand().isNonnull() && + dynamic_cast(theTau.leadCand().get()) != nullptr); + for (const auto& candidate : theTau.signalCands()) { + float etaAtECalEntrance = candidate->eta(); + float phiAtECalEntrance = candidate->phi(); + const reco::Track* track = nullptr; + if (isFromPFCands) { + const reco::PFCandidate* pfCandidate = static_cast(candidate.get()); + etaAtECalEntrance = pfCandidate->positionAtECALEntrance().eta(); + if (!usePhiAtEcalEntranceExtrapolation_) { + phiAtECalEntrance = pfCandidate->positionAtECALEntrance().phi(); + } else { + bool success = false; + reco::Candidate::Point posAtECal = + positionAtECalEntrance_(candidate.get(), success); + if (success) { + phiAtECalEntrance = posAtECal.phi(); + } + } + if (pfCandidate->trackRef().isNonnull()) + track = pfCandidate->trackRef().get(); + else if (pfCandidate->muonRef().isNonnull() && + pfCandidate->muonRef()->innerTrack().isNonnull()) + track = pfCandidate->muonRef()->innerTrack().get(); + else if (pfCandidate->muonRef().isNonnull() && + pfCandidate->muonRef()->globalTrack().isNonnull()) + track = pfCandidate->muonRef()->globalTrack().get(); + else if (pfCandidate->muonRef().isNonnull() && + pfCandidate->muonRef()->outerTrack().isNonnull()) + track = pfCandidate->muonRef()->outerTrack().get(); + else if (pfCandidate->gsfTrackRef().isNonnull()) + track = pfCandidate->gsfTrackRef().get(); + } else { + bool success = false; + reco::Candidate::Point posAtECal = + positionAtECalEntrance_(candidate.get(), success); + if (success) { + etaAtECalEntrance = posAtECal.eta(); + phiAtECalEntrance = posAtECal.phi(); + } + track = candidate->bestTrack(); + } + if (track != nullptr) { + if (track->pt() > tauVars.tauLeadChargedPFCandPt) { + tauVars.tauLeadChargedPFCandEtaAtEcalEntrance = etaAtECalEntrance; + tauVars.tauLeadChargedPFCandPt = track->pt(); + } + } + sumEtaTimesEnergy += etaAtECalEntrance * candidate->energy(); + sumPhiTimesEnergy += phiAtECalEntrance * candidate->energy(); + sumEnergy += candidate->energy(); + } + if (sumEnergy > 0.) { + tauVars.tauEtaAtEcalEntrance = sumEtaTimesEnergy / sumEnergy; + tauVars.tauPhi = sumPhiTimesEnergy / sumEnergy; + } + + tauVars.tauEmFraction = std::max(theTau.emFraction(), (float)0.); + tauVars.tauLeadPFChargedHadrHoP = 0.; + tauVars.tauLeadPFChargedHadrEoP = 0.; + if (theTau.leadChargedHadrCand()->p() > 0.) { + if (isFromPFCands) { + const reco::PFCandidate* pfLeadCandiate = + static_cast(theTau.leadChargedHadrCand().get()); + tauVars.tauLeadPFChargedHadrHoP = pfLeadCandiate->hcalEnergy() / + pfLeadCandiate->p(); + tauVars.tauLeadPFChargedHadrEoP = pfLeadCandiate->ecalEnergy() / + pfLeadCandiate->p(); + } else { + const pat::PackedCandidate* patLeadCandiate = + dynamic_cast(theTau.leadChargedHadrCand().get()); + if (patLeadCandiate != nullptr) { + tauVars.tauLeadPFChargedHadrHoP = patLeadCandiate->caloFraction() * + patLeadCandiate->energy() * patLeadCandiate->hcalFraction() / + patLeadCandiate->p(); + tauVars.tauLeadPFChargedHadrHoP = patLeadCandiate->caloFraction() * + patLeadCandiate->energy() * (1. - patLeadCandiate->hcalFraction()) / + patLeadCandiate->p(); + } + } + } + + return tauVars; +} + +// compile desired types and make available to linker +template class AntiElectronIDMVA6; +template class AntiElectronIDMVA6; + From 96840b8a593707f7e154239557a9a405d6400828 Mon Sep 17 00:00:00 2001 From: Michal Bluj Date: Tue, 23 Jun 2020 10:52:10 +0200 Subject: [PATCH 2/6] Remove old type-specific anti-e MVA6 tauID and use auto-generated configuration for this tauID --- .../NanoAOD/python/taus_updatedMVAIds_cff.py | 6 +- .../Configuration/python/HPSPFTaus_cff.py | 3 +- ...PATTauDiscriminationAgainstElectronMVA6.cc | 229 -------------- ...ecoTauDiscriminationAgainstElectronMVA6.cc | 280 ------------------ ...auDiscriminationAgainstElectronMVA6_cfi.py | 40 --- ...auDiscriminationAgainstElectronMVA6_cfi.py | 41 --- .../RecoTau/python/tools/runTauIdMVA.py | 4 +- .../test/rerunMVAIsolationOnMiniAOD.py | 4 +- 8 files changed, 12 insertions(+), 595 deletions(-) delete mode 100644 RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronMVA6.cc delete mode 100644 RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA6.cc delete mode 100644 RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronMVA6_cfi.py delete mode 100644 RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronMVA6_cfi.py diff --git a/PhysicsTools/NanoAOD/python/taus_updatedMVAIds_cff.py b/PhysicsTools/NanoAOD/python/taus_updatedMVAIds_cff.py index 972dc8bdefa88..5dbc2b104a6de 100644 --- a/PhysicsTools/NanoAOD/python/taus_updatedMVAIds_cff.py +++ b/PhysicsTools/NanoAOD/python/taus_updatedMVAIds_cff.py @@ -168,10 +168,12 @@ ### Define new anit-e discriminants (2018) antiElectronDiscrMVA6_version = "MVA" ## Raw -from RecoTauTag.RecoTau.PATTauDiscriminationAgainstElectronMVA6_cfi import patTauDiscriminationAgainstElectronMVA6 +from RecoTauTag.RecoTau.patTauDiscriminationAgainstElectronMVA6_cfi import patTauDiscriminationAgainstElectronMVA6 from RecoTauTag.RecoTau.TauDiscriminatorTools import noPrediscriminants patTauDiscriminationByElectronRejectionMVA62018Raw = patTauDiscriminationAgainstElectronMVA6.clone( + PATTauProducer = 'slimmedTaus', Prediscriminants = noPrediscriminants, #already selected for MiniAOD + srcElectrons = 'slimmedElectrons', vetoEcalCracks = False, #keep tau candidates in EB-EE cracks mvaName_NoEleMatch_wGwoGSF_BL = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_NoEleMatch_wGwoGSF_BL', mvaName_NoEleMatch_wGwoGSF_EC = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_NoEleMatch_wGwoGSF_EC', @@ -247,7 +249,9 @@ antiElectronDiscrMVA6v1_version = "MVA6v1" ## Raw patTauDiscriminationByElectronRejectionMVA62015Raw = patTauDiscriminationAgainstElectronMVA6.clone( + PATTauProducer = 'slimmedTaus', Prediscriminants = noPrediscriminants, #already selected for MiniAOD + srcElectrons = 'slimmedElectrons', vetoEcalCracks = True, #don't keep tau candidates in EB-EE cracks for v1 mvaName_NoEleMatch_wGwoGSF_BL = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6v1_version+'_gbr_NoEleMatch_wGwoGSF_BL', mvaName_NoEleMatch_wGwoGSF_EC = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6v1_version+'_gbr_NoEleMatch_wGwoGSF_EC', diff --git a/RecoTauTag/Configuration/python/HPSPFTaus_cff.py b/RecoTauTag/Configuration/python/HPSPFTaus_cff.py index e4e48b362898d..cf60d05231113 100644 --- a/RecoTauTag/Configuration/python/HPSPFTaus_cff.py +++ b/RecoTauTag/Configuration/python/HPSPFTaus_cff.py @@ -12,7 +12,7 @@ from RecoTauTag.RecoTau.PFRecoTauDiscriminationByIsolation_cfi import * from RecoTauTag.RecoTau.PFRecoTauDiscriminationByLeadingTrackFinding_cfi import * from RecoTauTag.RecoTau.PFRecoTauDiscriminationAgainstElectron_cfi import * -from RecoTauTag.RecoTau.PFRecoTauDiscriminationAgainstElectronMVA6_cfi import * +from RecoTauTag.RecoTau.pfRecoTauDiscriminationAgainstElectronMVA6_cfi import * from RecoTauTag.RecoTau.pfRecoTauDiscriminationAgainstElectronDeadECAL_cfi import * from RecoTauTag.RecoTau.PFRecoTauDiscriminationAgainstMuon_cfi import * from RecoTauTag.RecoTau.pfRecoTauDiscriminationAgainstMuon2Container_cfi import * @@ -220,6 +220,7 @@ ## ByMVA6rawElectronRejection hpsPFTauDiscriminationByMVA6rawElectronRejection = pfRecoTauDiscriminationAgainstElectronMVA6.clone( PFTauProducer = cms.InputTag('hpsPFTauProducer'), + srcElectrons = cms.InputTag('gedGsfElectrons'), Prediscriminants = requireDecayMode.clone(), loadMVAfromDB = cms.bool(True), vetoEcalCracks = cms.bool(False), diff --git a/RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronMVA6.cc b/RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronMVA6.cc deleted file mode 100644 index da13164b82b2b..0000000000000 --- a/RecoTauTag/RecoTau/plugins/PATTauDiscriminationAgainstElectronMVA6.cc +++ /dev/null @@ -1,229 +0,0 @@ -/* class PATTauDiscriminationAgainstElectronMVA6 - * created : Apr 14 2016, - * revised : , - * Authorss : Anne-Catherine Le Bihan (IPHC) - */ - -#include "FWCore/Utilities/interface/Exception.h" -#include "FWCore/ParameterSet/interface/FileInPath.h" - -#include -#include - -#include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h" -#include "RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h" - -#include "DataFormats/Math/interface/deltaR.h" -#include "DataFormats/PatCandidates/interface/Tau.h" -#include "DataFormats/PatCandidates/interface/PATTauDiscriminator.h" -#include "DataFormats/Candidate/interface/Candidate.h" - -#include -#include -#include - -using namespace pat; - -class PATTauDiscriminationAgainstElectronMVA6 : public PATTauDiscriminationContainerProducerBase { -public: - explicit PATTauDiscriminationAgainstElectronMVA6(const edm::ParameterSet& cfg) - : PATTauDiscriminationContainerProducerBase(cfg), mva_() { - mva_ = std::make_unique(cfg); - - srcElectrons = cfg.getParameter("srcElectrons"); - electronToken = consumes(srcElectrons); - vetoEcalCracks_ = cfg.getParameter("vetoEcalCracks"); - verbosity_ = cfg.getParameter("verbosity"); - } - - void beginEvent(const edm::Event&, const edm::EventSetup&) override; - - reco::SingleTauDiscriminatorContainer discriminate(const TauRef&) const override; - - ~PATTauDiscriminationAgainstElectronMVA6() override {} - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - -private: - bool isInEcalCrack(double) const; - - std::string moduleLabel_; - std::unique_ptr mva_; - - edm::InputTag srcElectrons; - edm::EDGetTokenT electronToken; - edm::Handle Electrons; - edm::Handle taus_; - - bool vetoEcalCracks_; - - int verbosity_; -}; - -void PATTauDiscriminationAgainstElectronMVA6::beginEvent(const edm::Event& evt, const edm::EventSetup& es) { - mva_->beginEvent(evt, es); - - evt.getByToken(Tau_token, taus_); - - evt.getByToken(electronToken, Electrons); -} - -reco::SingleTauDiscriminatorContainer PATTauDiscriminationAgainstElectronMVA6::discriminate( - const TauRef& theTauRef) const { - reco::SingleTauDiscriminatorContainer result; - result.rawValues = {1., -1.}; - double category = -1.; - bool isGsfElectronMatched = false; - float deltaRDummy = 9.9; - const float ECALBarrelEndcapEtaBorder = 1.479; - float tauEtaAtEcalEntrance = theTauRef->etaAtEcalEntrance(); - float leadChargedPFCandEtaAtEcalEntrance = theTauRef->etaAtEcalEntranceLeadChargedCand(); - - if ((*theTauRef).leadChargedHadrCand().isNonnull()) { - int numSignalPFGammaCandsInSigCone = 0; - const reco::CandidatePtrVector signalGammaCands = theTauRef->signalGammaCands(); - for (const auto& gamma : signalGammaCands) { - double dR = deltaR(gamma->p4(), theTauRef->leadChargedHadrCand()->p4()); - double signalrad = std::max(0.05, std::min(0.10, 3.0 / std::max(1.0, theTauRef->pt()))); - // gammas inside the tau signal cone - if (dR < signalrad) { - numSignalPFGammaCandsInSigCone += 1; - } - } - // loop over the electrons - for (const auto& theElectron : *Electrons) { - if (theElectron.pt() > 10.) { // CV: only take electrons above some minimal energy/Pt into account... - double deltaREleTau = deltaR(theElectron.p4(), theTauRef->p4()); - deltaRDummy = deltaREleTau; - if (deltaREleTau < 0.3) { - double mva_match = mva_->MVAValue(*theTauRef, theElectron); - bool hasGsfTrack = false; - pat::PackedCandidate const* packedLeadTauCand = - dynamic_cast(theTauRef->leadChargedHadrCand().get()); - if (abs(packedLeadTauCand->pdgId()) == 11) - hasGsfTrack = true; - if (!hasGsfTrack) - hasGsfTrack = theElectron.gsfTrack().isNonnull(); - - // veto taus that go to Ecal crack - if (vetoEcalCracks_ && - (isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance))) { - // return MVA output value - result.rawValues.at(0) = -99; - return result; - } - // Veto taus that go to Ecal crack - if (std::abs(tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { // Barrel - if (numSignalPFGammaCandsInSigCone == 0 && hasGsfTrack) { - category = 5.; - } else if (numSignalPFGammaCandsInSigCone >= 1 && hasGsfTrack) { - category = 7.; - } - } else { // Endcap - if (numSignalPFGammaCandsInSigCone == 0 && hasGsfTrack) { - category = 13.; - } else if (numSignalPFGammaCandsInSigCone >= 1 && hasGsfTrack) { - category = 15.; - } - } - result.rawValues.at(0) = std::min(result.rawValues.at(0), float(mva_match)); - isGsfElectronMatched = true; - } // deltaR < 0.3 - } // electron pt > 10 - } // end of loop over electrons - - if (!isGsfElectronMatched) { - result.rawValues.at(0) = mva_->MVAValue(*theTauRef); - bool hasGsfTrack = false; - pat::PackedCandidate const* packedLeadTauCand = - dynamic_cast(theTauRef->leadChargedHadrCand().get()); - if (abs(packedLeadTauCand->pdgId()) == 11) - hasGsfTrack = true; - - // veto taus that go to Ecal crack - if (vetoEcalCracks_ && - (isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance))) { - // add category index - result.rawValues.at(1) = category; - // return MVA output value - result.rawValues.at(0) = -99; - return result; - } - // veto taus that go to Ecal crack - if (std::abs(tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { // Barrel - if (numSignalPFGammaCandsInSigCone == 0 && !hasGsfTrack) { - category = 0.; - } else if (numSignalPFGammaCandsInSigCone >= 1 && !hasGsfTrack) { - category = 2.; - } - } else { // Endcap - if (numSignalPFGammaCandsInSigCone == 0 && !hasGsfTrack) { - category = 8.; - } else if (numSignalPFGammaCandsInSigCone >= 1 && !hasGsfTrack) { - category = 10.; - } - } - } - } - if (verbosity_) { - edm::LogPrint("PATTauAgainstEleMVA6") << ":"; - edm::LogPrint("PATTauAgainstEleMVA6") - << " tau: Pt = " << theTauRef->pt() << ", eta = " << theTauRef->eta() << ", phi = " << theTauRef->phi(); - edm::LogPrint("PATTauAgainstEleMVA6") - << " deltaREleTau = " << deltaRDummy << ", isGsfElectronMatched = " << isGsfElectronMatched; - edm::LogPrint("PATTauAgainstEleMVA6") << " #Prongs = " << theTauRef->signalChargedHadrCands().size(); - edm::LogPrint("PATTauAgainstEleMVA6") << " MVA = " << result.rawValues.at(0) << ", category = " << category; - } - // add category index - result.rawValues.at(1) = category; - // return MVA output value - return result; -} - -bool PATTauDiscriminationAgainstElectronMVA6::isInEcalCrack(double eta) const { - double absEta = fabs(eta); - return (absEta > 1.460 && absEta < 1.558); -} - -void PATTauDiscriminationAgainstElectronMVA6::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - // patTauDiscriminationAgainstElectronMVA6 - edm::ParameterSetDescription desc; - desc.add("minMVANoEleMatchWOgWOgsfBL", 0.0); - desc.add("minMVANoEleMatchWgWOgsfBL", 0.0); - desc.add("vetoEcalCracks", true); - desc.add("usePhiAtEcalEntranceExtrapolation", false); - desc.add("mvaName_wGwGSF_EC", "gbr_wGwGSF_EC"); - desc.add("minMVAWgWgsfBL", 0.0); - desc.add("mvaName_woGwGSF_EC", "gbr_woGwGSF_EC"); - desc.add("minMVAWOgWgsfEC", 0.0); - desc.add("mvaName_wGwGSF_BL", "gbr_wGwGSF_BL"); - desc.add("mvaName_woGwGSF_BL", "gbr_woGwGSF_BL"); - desc.add("returnMVA", true); - desc.add("loadMVAfromDB", true); - { - edm::ParameterSetDescription psd0; - psd0.add("BooleanOperator", "and"); - { - edm::ParameterSetDescription psd1; - psd1.add("cut"); - psd1.add("Producer"); - psd0.addOptional("leadTrack", psd1); - } - desc.add("Prediscriminants", psd0); - } - desc.add("mvaName_NoEleMatch_woGwoGSF_BL", "gbr_NoEleMatch_woGwoGSF_BL"); - desc.add("srcElectrons", edm::InputTag("slimmedElectrons")); - desc.add("minMVANoEleMatchWOgWOgsfEC", 0.0); - desc.add("mvaName_NoEleMatch_wGwoGSF_BL", "gbr_NoEleMatch_wGwoGSF_BL"); - desc.add("PATTauProducer", edm::InputTag("slimmedTaus")); - desc.add("minMVAWOgWgsfBL", 0.0); - desc.add("minMVAWgWgsfEC", 0.0); - desc.add("verbosity", 0); - desc.add("mvaName_NoEleMatch_wGwoGSF_EC", "gbr_NoEleMatch_wGwoGSF_EC"); - desc.add("method", "BDTG"); - desc.add("mvaName_NoEleMatch_woGwoGSF_EC", "gbr_NoEleMatch_woGwoGSF_EC"); - desc.add("minMVANoEleMatchWgWOgsfEC", 0.0); - descriptions.add("patTauDiscriminationAgainstElectronMVA6", desc); -} - -DEFINE_FWK_MODULE(PATTauDiscriminationAgainstElectronMVA6); diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA6.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA6.cc deleted file mode 100644 index ebd1a9594151b..0000000000000 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA6.cc +++ /dev/null @@ -1,280 +0,0 @@ -/* class PFRecoTauDiscriminationAgainstElectronMVA6 - * created : Nov 2 2015, - * revised : , - * Authorss : Fabio Colombo (KIT) - */ - -#include "FWCore/Utilities/interface/Exception.h" -#include "FWCore/ParameterSet/interface/FileInPath.h" - -#include -#include - -#include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h" -#include "RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h" - -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" -#include "DataFormats/TrackReco/interface/Track.h" -#include "DataFormats/GsfTrackReco/interface/GsfTrack.h" -#include "DataFormats/MuonReco/interface/Muon.h" -#include "DataFormats/Math/interface/deltaR.h" - -#include -#include -#include - -using namespace reco; - -class PFRecoTauDiscriminationAgainstElectronMVA6 : public PFTauDiscriminationContainerProducerBase { -public: - explicit PFRecoTauDiscriminationAgainstElectronMVA6(const edm::ParameterSet& cfg) - : PFTauDiscriminationContainerProducerBase(cfg), mva_() { - mva_ = std::make_unique(cfg); - - srcGsfElectrons_ = cfg.getParameter("srcGsfElectrons"); - GsfElectrons_token = consumes(srcGsfElectrons_); - vetoEcalCracks_ = cfg.getParameter("vetoEcalCracks"); - - verbosity_ = cfg.getParameter("verbosity"); - } - - void beginEvent(const edm::Event&, const edm::EventSetup&) override; - - reco::SingleTauDiscriminatorContainer discriminate(const PFTauRef&) const override; - - ~PFRecoTauDiscriminationAgainstElectronMVA6() override {} - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - -private: - bool isInEcalCrack(double) const; - - std::string moduleLabel_; - std::unique_ptr mva_; - - edm::InputTag srcGsfElectrons_; - edm::EDGetTokenT GsfElectrons_token; - edm::Handle gsfElectrons_; - edm::Handle taus_; - - bool vetoEcalCracks_; - - int verbosity_; -}; - -void PFRecoTauDiscriminationAgainstElectronMVA6::beginEvent(const edm::Event& evt, const edm::EventSetup& es) { - mva_->beginEvent(evt, es); - - evt.getByToken(Tau_token, taus_); - - evt.getByToken(GsfElectrons_token, gsfElectrons_); -} - -reco::SingleTauDiscriminatorContainer PFRecoTauDiscriminationAgainstElectronMVA6::discriminate( - const PFTauRef& thePFTauRef) const { - reco::SingleTauDiscriminatorContainer result; - result.rawValues = {1., -1.}; - double category = -1.; - bool isGsfElectronMatched = false; - - float deltaRDummy = 9.9; - - const float ECALBarrelEndcapEtaBorder = 1.479; - float tauEtaAtEcalEntrance = -99.; - float sumEtaTimesEnergy = 0.; - float sumEnergy = 0.; - for (const auto& pfCandidate : thePFTauRef->signalPFCands()) { - sumEtaTimesEnergy += (pfCandidate->positionAtECALEntrance().eta() * pfCandidate->energy()); - sumEnergy += pfCandidate->energy(); - } - if (sumEnergy > 0.) { - tauEtaAtEcalEntrance = sumEtaTimesEnergy / sumEnergy; - } - - float leadChargedPFCandEtaAtEcalEntrance = -99.; - float leadChargedPFCandPt = -99.; - for (const auto& pfCandidate : thePFTauRef->signalPFCands()) { - const reco::Track* track = nullptr; - if (pfCandidate->trackRef().isNonnull()) - track = pfCandidate->trackRef().get(); - else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->innerTrack().isNonnull()) - track = pfCandidate->muonRef()->innerTrack().get(); - else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->globalTrack().isNonnull()) - track = pfCandidate->muonRef()->globalTrack().get(); - else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->outerTrack().isNonnull()) - track = pfCandidate->muonRef()->outerTrack().get(); - else if (pfCandidate->gsfTrackRef().isNonnull()) - track = pfCandidate->gsfTrackRef().get(); - if (track) { - if (track->pt() > leadChargedPFCandPt) { - leadChargedPFCandEtaAtEcalEntrance = pfCandidate->positionAtECALEntrance().eta(); - leadChargedPFCandPt = track->pt(); - } - } - } - - if ((*thePFTauRef).leadChargedHadrCand().isNonnull()) { - int numSignalGammaCandsInSigCone = 0; - const std::vector& signalGammaCands = thePFTauRef->signalGammaCands(); - - for (const auto& pfGamma : signalGammaCands) { - double dR = deltaR(pfGamma->p4(), thePFTauRef->leadChargedHadrCand()->p4()); - double signalrad = std::max(0.05, std::min(0.10, 3.0 / std::max(1.0, thePFTauRef->pt()))); - - // pfGammas inside the tau signal cone - if (dR < signalrad) { - numSignalGammaCandsInSigCone += 1; - } - } - - // loop over the electrons - for (const auto& theGsfElectron : *gsfElectrons_) { - if (theGsfElectron.pt() > 10.) { // CV: only take electrons above some minimal energy/Pt into account... - double deltaREleTau = deltaR(theGsfElectron.p4(), thePFTauRef->p4()); - deltaRDummy = deltaREleTau; - if (deltaREleTau < 0.3) { - double mva_match = mva_->MVAValue(*thePFTauRef, theGsfElectron); - const reco::PFCandidatePtr& lpfch = thePFTauRef->leadPFChargedHadrCand(); - bool hasGsfTrack = false; - if (lpfch.isNonnull()) { - hasGsfTrack = lpfch->gsfTrackRef().isNonnull(); - } - if (!hasGsfTrack) - hasGsfTrack = theGsfElectron.gsfTrack().isNonnull(); - - //// Veto taus that go to Ecal crack - if (vetoEcalCracks_ && - (isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance))) { - // return MVA output value - result.rawValues.at(0) = -99.; - return result; - } - //// Veto taus that go to Ecal crack - - if (std::abs(tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { // Barrel - if (numSignalGammaCandsInSigCone == 0 && hasGsfTrack) { - category = 5.; - } else if (numSignalGammaCandsInSigCone >= 1 && hasGsfTrack) { - category = 7.; - } - } else { // Endcap - if (numSignalGammaCandsInSigCone == 0 && hasGsfTrack) { - category = 13.; - } else if (numSignalGammaCandsInSigCone >= 1 && hasGsfTrack) { - category = 15.; - } - } - - result.rawValues.at(0) = std::min(result.rawValues.at(0), float(mva_match)); - isGsfElectronMatched = true; - } // deltaR < 0.3 - } // electron pt > 10 - } // end of loop over electrons - - if (!isGsfElectronMatched) { - result.rawValues.at(0) = mva_->MVAValue(*thePFTauRef); - const reco::PFCandidatePtr& lpfch = thePFTauRef->leadPFChargedHadrCand(); - bool hasGsfTrack = false; - if (lpfch.isNonnull()) { - hasGsfTrack = lpfch->gsfTrackRef().isNonnull(); - } - - //// Veto taus that go to Ecal crack - if (vetoEcalCracks_ && - (isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance))) { - // add category index - result.rawValues.at(1) = category; - // return MVA output value - result.rawValues.at(0) = -99.; - return result; - } - //// Veto taus that go to Ecal crack - - if (std::abs(tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { // Barrel - if (numSignalGammaCandsInSigCone == 0 && !hasGsfTrack) { - category = 0.; - } else if (numSignalGammaCandsInSigCone >= 1 && !hasGsfTrack) { - category = 2.; - } - } else { // Endcap - if (numSignalGammaCandsInSigCone == 0 && !hasGsfTrack) { - category = 8.; - } else if (numSignalGammaCandsInSigCone >= 1 && !hasGsfTrack) { - category = 10.; - } - } - } - } - - if (verbosity_) { - edm::LogPrint("PFTauAgainstEleMVA6") << ":"; - edm::LogPrint("PFTauAgainstEleMVA6") << " tau: Pt = " << thePFTauRef->pt() << ", eta = " << thePFTauRef->eta() - << ", phi = " << thePFTauRef->phi(); - edm::LogPrint("PFTauAgainstEleMVA6") << " deltaREleTau = " << deltaRDummy - << ", isGsfElectronMatched = " << isGsfElectronMatched; - edm::LogPrint("PFTauAgainstEleMVA6") << " #Prongs = " << thePFTauRef->signalChargedHadrCands().size(); - edm::LogPrint("PFTauAgainstEleMVA6") << " MVA = " << result.rawValues.at(0) << ", category = " << category; - } - - // add category index - result.rawValues.at(1) = category; - // return MVA output value - return result; -} - -bool PFRecoTauDiscriminationAgainstElectronMVA6::isInEcalCrack(double eta) const { - double absEta = fabs(eta); - return (absEta > 1.460 && absEta < 1.558); -} - -void PFRecoTauDiscriminationAgainstElectronMVA6::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - // pfRecoTauDiscriminationAgainstElectronMVA6 - edm::ParameterSetDescription desc; - desc.add("minMVANoEleMatchWOgWOgsfBL", 0.0); - desc.add("PFTauProducer", edm::InputTag("pfTauProducer")); - desc.add("minMVANoEleMatchWgWOgsfBL", 0.0); - desc.add("mvaName_wGwGSF_EC", "gbr_wGwGSF_EC"); - desc.add("minMVAWgWgsfBL", 0.0); - desc.add("mvaName_woGwGSF_EC", "gbr_woGwGSF_EC"); - desc.add("minMVAWOgWgsfEC", 0.0); - desc.add("mvaName_wGwGSF_BL", "gbr_wGwGSF_BL"); - desc.add("mvaName_woGwGSF_BL", "gbr_woGwGSF_BL"); - desc.add("returnMVA", true); - desc.add("loadMVAfromDB", true); - { - edm::ParameterSetDescription pset_Prediscriminants; - pset_Prediscriminants.add("BooleanOperator", "and"); - { - edm::ParameterSetDescription psd1; - psd1.add("cut"); - psd1.add("Producer"); - pset_Prediscriminants.addOptional("leadTrack", psd1); - } - { - // encountered this at - // RecoTauTag/Configuration/python/HPSPFTaus_cff.py - edm::ParameterSetDescription psd1; - psd1.add("cut"); - psd1.add("Producer"); - pset_Prediscriminants.addOptional("decayMode", psd1); - } - desc.add("Prediscriminants", pset_Prediscriminants); - } - desc.add("mvaName_NoEleMatch_woGwoGSF_BL", "gbr_NoEleMatch_woGwoGSF_BL"); - desc.add("vetoEcalCracks", true); - desc.add("usePhiAtEcalEntranceExtrapolation", false); - desc.add("mvaName_NoEleMatch_wGwoGSF_BL", "gbr_NoEleMatch_wGwoGSF_BL"); - desc.add("minMVANoEleMatchWOgWOgsfEC", 0.0); - desc.add("minMVAWOgWgsfBL", 0.0); - desc.add("minMVAWgWgsfEC", 0.0); - desc.add("verbosity", 0); - desc.add("mvaName_NoEleMatch_wGwoGSF_EC", "gbr_NoEleMatch_wGwoGSF_EC"); - desc.add("method", "BDTG"); - desc.add("srcGsfElectrons", edm::InputTag("gedGsfElectrons")); - desc.add("mvaName_NoEleMatch_woGwoGSF_EC", "gbr_NoEleMatch_woGwoGSF_EC"); - desc.add("minMVANoEleMatchWgWOgsfEC", 0.0); - descriptions.add("pfRecoTauDiscriminationAgainstElectronMVA6", desc); -} - -DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstElectronMVA6); diff --git a/RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronMVA6_cfi.py b/RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronMVA6_cfi.py deleted file mode 100644 index ac6a52ccc9df6..0000000000000 --- a/RecoTauTag/RecoTau/python/PATTauDiscriminationAgainstElectronMVA6_cfi.py +++ /dev/null @@ -1,40 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -from RecoTauTag.RecoTau.TauDiscriminatorTools import requireLeadTrack - -patTauDiscriminationAgainstElectronMVA6 = cms.EDProducer("PATTauDiscriminationAgainstElectronMVA6", - # tau collection to discriminate - PATTauProducer = cms.InputTag('slimmedTaus'), - - # Require leading pion ensures that: - # 1) these is at least one track above threshold (0.5 GeV) in the signal cone - # 2) a track OR a pi-zero in the signal cone has pT > 5 GeV - Prediscriminants = requireLeadTrack, - - method = cms.string("BDTG"), - loadMVAfromDB = cms.bool(True), - returnMVA = cms.bool(True), - - mvaName_NoEleMatch_woGwoGSF_BL = cms.string("gbr_NoEleMatch_woGwoGSF_BL"), - mvaName_NoEleMatch_wGwoGSF_BL = cms.string("gbr_NoEleMatch_wGwoGSF_BL"), - mvaName_woGwGSF_BL = cms.string("gbr_woGwGSF_BL"), - mvaName_wGwGSF_BL = cms.string("gbr_wGwGSF_BL"), - mvaName_NoEleMatch_woGwoGSF_EC = cms.string("gbr_NoEleMatch_woGwoGSF_EC"), - mvaName_NoEleMatch_wGwoGSF_EC = cms.string("gbr_NoEleMatch_wGwoGSF_EC"), - mvaName_woGwGSF_EC = cms.string("gbr_woGwGSF_EC"), - mvaName_wGwGSF_EC = cms.string("gbr_wGwGSF_EC"), - - minMVANoEleMatchWOgWOgsfBL = cms.double(0.0), - minMVANoEleMatchWgWOgsfBL = cms.double(0.0), - minMVAWOgWgsfBL = cms.double(0.0), - minMVAWgWgsfBL = cms.double(0.0), - minMVANoEleMatchWOgWOgsfEC = cms.double(0.0), - minMVANoEleMatchWgWOgsfEC = cms.double(0.0), - minMVAWOgWgsfEC = cms.double(0.0), - minMVAWgWgsfEC = cms.double(0.0), - - srcElectrons = cms.InputTag('slimmedElectrons'), - vetoEcalCracks = cms.bool(True), - usePhiAtEcalEntranceExtrapolation = cms.bool(False), - verbosity = cms.int32(0) -) diff --git a/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronMVA6_cfi.py b/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronMVA6_cfi.py deleted file mode 100644 index 1fbb78e9f8577..0000000000000 --- a/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronMVA6_cfi.py +++ /dev/null @@ -1,41 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -from RecoTauTag.RecoTau.TauDiscriminatorTools import requireLeadTrack - -pfRecoTauDiscriminationAgainstElectronMVA6 = cms.EDProducer("PFRecoTauDiscriminationAgainstElectronMVA6", - - # tau collection to discriminate - PFTauProducer = cms.InputTag('pfTauProducer'), - - # Require leading pion ensures that: - # 1) these is at least one track above threshold (0.5 GeV) in the signal cone - # 2) a track OR a pi-zero in the signal cone has pT > 5 GeV - Prediscriminants = requireLeadTrack, - - method = cms.string("BDTG"), - loadMVAfromDB = cms.bool(True), - returnMVA = cms.bool(True), - - mvaName_NoEleMatch_woGwoGSF_BL = cms.string("gbr_NoEleMatch_woGwoGSF_BL"), - mvaName_NoEleMatch_wGwoGSF_BL = cms.string("gbr_NoEleMatch_wGwoGSF_BL"), - mvaName_woGwGSF_BL = cms.string("gbr_woGwGSF_BL"), - mvaName_wGwGSF_BL = cms.string("gbr_wGwGSF_BL"), - mvaName_NoEleMatch_woGwoGSF_EC = cms.string("gbr_NoEleMatch_woGwoGSF_EC"), - mvaName_NoEleMatch_wGwoGSF_EC = cms.string("gbr_NoEleMatch_wGwoGSF_EC"), - mvaName_woGwGSF_EC = cms.string("gbr_woGwGSF_EC"), - mvaName_wGwGSF_EC = cms.string("gbr_wGwGSF_EC"), - - minMVANoEleMatchWOgWOgsfBL = cms.double(0.0), - minMVANoEleMatchWgWOgsfBL = cms.double(0.0), - minMVAWOgWgsfBL = cms.double(0.0), - minMVAWgWgsfBL = cms.double(0.0), - minMVANoEleMatchWOgWOgsfEC = cms.double(0.0), - minMVANoEleMatchWgWOgsfEC = cms.double(0.0), - minMVAWOgWgsfEC = cms.double(0.0), - minMVAWgWgsfEC = cms.double(0.0), - - srcGsfElectrons = cms.InputTag('gedGsfElectrons'), - vetoEcalCracks = cms.bool(True), - usePhiAtEcalEntranceExtrapolation = cms.bool(False), - verbosity = cms.int32(0) -) diff --git a/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py b/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py index ee6e5c9c0ebd6..39abe3e00d741 100644 --- a/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py +++ b/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py @@ -770,9 +770,11 @@ def runTauID(self): antiElectronDiscrMVA6_version = "MVA6v3_noeveto" ### Define new anti-e discriminants ## Raw - from RecoTauTag.RecoTau.PATTauDiscriminationAgainstElectronMVA6_cfi import patTauDiscriminationAgainstElectronMVA6 + from RecoTauTag.RecoTau.patTauDiscriminationAgainstElectronMVA6_cfi import patTauDiscriminationAgainstElectronMVA6 self.process.patTauDiscriminationByElectronRejectionMVA62018Raw = patTauDiscriminationAgainstElectronMVA6.clone( + PATTauProducer = cms.InputTag('slimmedTaus'), Prediscriminants = noPrediscriminants, #already selected for MiniAOD + srcElectrons = cms.InputTag('slimmedElectrons'), vetoEcalCracks = cms.bool(False), #keep taus in EB-EE cracks mvaName_NoEleMatch_wGwoGSF_BL = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_BL', mvaName_NoEleMatch_wGwoGSF_EC = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_EC', diff --git a/RecoTauTag/RecoTau/test/rerunMVAIsolationOnMiniAOD.py b/RecoTauTag/RecoTau/test/rerunMVAIsolationOnMiniAOD.py index 34af14efc2098..1342776f98a2d 100644 --- a/RecoTauTag/RecoTau/test/rerunMVAIsolationOnMiniAOD.py +++ b/RecoTauTag/RecoTau/test/rerunMVAIsolationOnMiniAOD.py @@ -30,7 +30,7 @@ from RecoTauTag.RecoTau.TauDiscriminatorTools import noPrediscriminants process.load('RecoTauTag.Configuration.loadRecoTauTagMVAsFromPrepDB_cfi') from RecoTauTag.RecoTau.PATTauDiscriminationByMVAIsolationRun2_cff import * -from RecoTauTag.RecoTau.PATTauDiscriminationAgainstElectronMVA6_cfi import * +from RecoTauTag.RecoTau.patTauDiscriminationAgainstElectronMVA6_cfi import * process.rerunDiscriminationByIsolationMVArun2v1raw = patDiscriminationByIsolationMVArun2v1raw.clone( PATTauProducer = cms.InputTag('slimmedTaus'), @@ -71,6 +71,7 @@ PATTauProducer = cms.InputTag('slimmedTaus'), Prediscriminants = noPrediscriminants, #Prediscriminants = requireLeadTrack, + srcElectrons = cms.InputTag('slimmedElectrons'), loadMVAfromDB = cms.bool(True), vetoEcalCracks = cms.bool(False), returnMVA = cms.bool(True), @@ -91,7 +92,6 @@ minMVANoEleMatchWgWOgsfEC = cms.double(0.0), minMVAWOgWgsfEC = cms.double(0.0), minMVAWgWgsfEC = cms.double(0.0), - srcElectrons = cms.InputTag('slimmedElectrons'), usePhiAtEcalEntranceExtrapolation = cms.bool(True) ) From 2ab132bdeb6a7cdfc92b5e444934f8ec75a346df Mon Sep 17 00:00:00 2001 From: Michal Bluj Date: Fri, 3 Jul 2020 18:31:27 +0200 Subject: [PATCH 3/6] Intialise members of helper structs, small fixes and cleaning --- .../RecoTau/interface/AntiElectronIDMVA6.h | 82 +-- .../TauDiscriminationAgainstElectronMVA6.cc | 20 +- RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc | 531 +++++++++--------- 3 files changed, 315 insertions(+), 318 deletions(-) diff --git a/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h b/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h index bb169a71db71d..50e492a843a87 100644 --- a/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h +++ b/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h @@ -34,18 +34,18 @@ #include struct TauVars { - float tauPt; - float tauEtaAtEcalEntrance; - float tauPhi; - float tauLeadChargedPFCandPt; - float tauLeadChargedPFCandEtaAtEcalEntrance; - float tauEmFraction; - float tauLeadPFChargedHadrHoP; - float tauLeadPFChargedHadrEoP; - float tauVisMassIn; - float taudCrackEta; - float taudCrackPhi; - float tauHasGsf; + float pt = 0; + float etaAtEcalEntrance = 0; + float phi = 0; + float leadChargedPFCandPt = 0; + float leadChargedPFCandEtaAtEcalEntrance = 0; + float emFraction = 0; + float leadPFChargedHadrHoP = 0; + float leadPFChargedHadrEoP = 0; + float visMassIn = 0; + float dCrackEta = 0; + float dCrackPhi = 0; + float hasGsf = 0; }; struct TauGammaVecs { std::vector gammasdEtaInSigCone; @@ -56,33 +56,33 @@ struct TauGammaVecs { std::vector gammasPtOutSigCone; }; struct TauGammaMoms { - int tauSignalPFGammaCandsIn; - int tauSignalPFGammaCandsOut; - float tauGammaEtaMomIn; - float tauGammaEtaMomOut; - float tauGammaPhiMomIn; - float tauGammaPhiMomOut; - float tauGammaEnFracIn; - float tauGammaEnFracOut; + int signalPFGammaCandsIn = 0; + int signalPFGammaCandsOut = 0; + float gammaEtaMomIn = 0; + float gammaEtaMomOut = 0; + float gammaPhiMomIn = 0; + float gammaPhiMomOut = 0; + float gammaEnFracIn = 0; + float gammaEnFracOut = 0; }; -struct EleVars { - float elecEta; - float elecPhi; - float elecEtotOverPin; - float elecChi2NormGSF; - float elecChi2NormKF; - float elecGSFNumHits; - float elecKFNumHits; - float elecGSFTrackResol; - float elecGSFTracklnPt; - float elecPin; - float elecPout; - float elecEecal; - float elecDeltaEta; - float elecDeltaPhi; - float elecMvaInSigmaEtaEta; - float elecMvaInHadEnergy; - float elecMvaInDeltaEta; +struct ElecVars { + float eta = 0; + float phi = 0; + float eTotOverPin = 0; + float chi2NormGSF = 0; + float chi2NormKF = 0; + float gsfNumHits = 0; + float kfNumHits = 0; + float gsfTrackResol = 0; + float gsfTracklnPt = 0; + float pIn = 0; + float pOut = 0; + float eEcal = 0; + float deltaEta = 0; + float deltaPhi = 0; + float mvaInSigmaEtaEta = 0; + float mvaInHadEnergy = 0; + float mvaInDeltaEta = 0; }; template @@ -95,11 +95,11 @@ class AntiElectronIDMVA6 { double MVAValue(const TauVars& tauVars, const TauGammaVecs& tauGammaVecs, - const EleVars& eleVars); + const ElecVars& elecVars); double MVAValue(const TauVars& tauVars, const TauGammaMoms& tauGammaMoms, - const EleVars& eleVars); + const ElecVars& elecVars); // this function can be called for all categories double MVAValue(const TauType& theTau, const ElectronType& theEle); @@ -111,7 +111,7 @@ class AntiElectronIDMVA6 { TauVars getTauVarsTypeSpecific(const pat::Tau& theTau); TauVars getTauVars(const TauType& theTau); TauGammaVecs getTauGammaVecs(const TauType& theTau); - EleVars getEleVars(const ElectronType& theEle); + ElecVars getElecVars(const ElectronType& theEle); // track extrapolation to ECAL entrance (used to re-calculate variables that might not be available on miniAOD) bool atECalEntrance(const reco::Candidate* part, math::XYZPoint& pos); diff --git a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronMVA6.cc b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronMVA6.cc index db4726df8eda1..60aa457143465 100644 --- a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronMVA6.cc +++ b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronMVA6.cc @@ -84,9 +84,9 @@ TauDiscriminationAgainstElectronMVA6::d if ((*theTauRef).leadChargedHadrCand().isNonnull()) { int numSignalGammaCandsInSigCone = 0; + double signalrad = std::clamp(3.0 / std::max(1.0, theTauRef->pt()), 0.05, 0.10); for (const auto& gamma : theTauRef->signalGammaCands()) { double dR = deltaR(gamma->p4(), theTauRef->leadChargedHadrCand()->p4()); - double signalrad = std::max(0.05, std::min(0.10, 3.0 / std::max(1.0, theTauRef->pt()))); // pfGammas inside the tau signal cone if (dR < signalrad) { numSignalGammaCandsInSigCone += 1; @@ -96,14 +96,14 @@ TauDiscriminationAgainstElectronMVA6::d bool hasGsfTrack = false; const reco::CandidatePtr& leadChCand = theTauRef->leadChargedHadrCand(); if (leadChCand.isNonnull()) { - const reco::PFCandidate* pfLeadChCand = - dynamic_cast(leadChCand.get()); - if (pfLeadChCand != nullptr) { - hasGsfTrack = pfLeadChCand->gsfTrackRef().isNonnull(); + const pat::PackedCandidate* packedLeadChCand = + dynamic_cast(leadChCand.get()); + if (packedLeadChCand != nullptr) { + hasGsfTrack = (std::abs(packedLeadChCand->pdgId()) == 11); } else { - pat::PackedCandidate const* packedLeadChCand = - dynamic_cast(leadChCand.get()); - hasGsfTrack = (packedLeadChCand != nullptr && std::abs(packedLeadChCand->pdgId())==11); + const reco::PFCandidate* pfLeadChCand = + dynamic_cast(leadChCand.get()); + hasGsfTrack = (pfLeadChCand != nullptr && pfLeadChCand->gsfTrackRef().isNonnull()); } } @@ -149,7 +149,7 @@ TauDiscriminationAgainstElectronMVA6::d } // end of loop over electrons if (!isGsfElectronMatched) { - result.rawValues.at(0) = mva_->MVAValue(*theTauRef); + double mva_nomatch = mva_->MVAValue(*theTauRef); // veto taus that go to ECal crack if (vetoEcalCracks_ && @@ -175,6 +175,8 @@ TauDiscriminationAgainstElectronMVA6::d category = 10.; } } + + result.rawValues.at(0) = std::min(result.rawValues.at(0), float(mva_nomatch)); } } diff --git a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc index 96e781a6468df..18a91a13f7c17 100644 --- a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc +++ b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc @@ -138,13 +138,12 @@ void AntiElectronIDMVA6::beginEvent(const edm::Event& evt template double AntiElectronIDMVA6::MVAValue(const TauVars& tauVars, const TauGammaVecs& tauGammaVecs, - const EleVars& eleVars) { + const ElecVars& elecVars) { TauGammaMoms tauGammaMoms; double sumPt = 0.; double dEta2 = 0.; double dPhi2 = 0.; - double sumPt2 = 0.; - tauGammaMoms.tauSignalPFGammaCandsIn = tauGammaVecs.gammasPtInSigCone.size(); + tauGammaMoms.signalPFGammaCandsIn = tauGammaVecs.gammasPtInSigCone.size(); for (size_t i = 0; i < tauGammaVecs.gammasPtInSigCone.size(); ++i) { double pt_i = tauGammaVecs.gammasPtInSigCone[i]; double phi_i = tauGammaVecs.gammasdPhiInSigCone[i]; @@ -154,27 +153,25 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar phi_i = tauGammaVecs.gammasdPhiInSigCone[i] + 2 * M_PI; double eta_i = tauGammaVecs.gammasdEtaInSigCone[i]; sumPt += pt_i; - sumPt2 += (pt_i * pt_i); dEta2 += (pt_i * eta_i * eta_i); dPhi2 += (pt_i * phi_i * phi_i); } - tauGammaMoms.tauGammaEnFracIn = -99.; - if (tauVars.tauPt > 0.) { - tauGammaMoms.tauGammaEnFracIn = sumPt / tauVars.tauPt; + tauGammaMoms.gammaEnFracIn = -99.; + if (tauVars.pt > 0.) { + tauGammaMoms.gammaEnFracIn = sumPt / tauVars.pt; } if (sumPt > 0.) { dEta2 /= sumPt; dPhi2 /= sumPt; } - tauGammaMoms.tauGammaEtaMomIn = std::sqrt(dEta2) * std::sqrt(tauGammaMoms.tauGammaEnFracIn) * tauVars.tauPt; - tauGammaMoms.tauGammaPhiMomIn = std::sqrt(dPhi2) * std::sqrt(tauGammaMoms.tauGammaEnFracIn) * tauVars.tauPt; + tauGammaMoms.gammaEtaMomIn = std::sqrt(dEta2) * std::sqrt(tauGammaMoms.gammaEnFracIn) * tauVars.pt; + tauGammaMoms.gammaPhiMomIn = std::sqrt(dPhi2) * std::sqrt(tauGammaMoms.gammaEnFracIn) * tauVars.pt; sumPt = 0.; dEta2 = 0.; dPhi2 = 0.; - sumPt2 = 0.; - tauGammaMoms.tauSignalPFGammaCandsOut = tauGammaVecs.gammasPtOutSigCone.size(); + tauGammaMoms.signalPFGammaCandsOut = tauGammaVecs.gammasPtOutSigCone.size(); for (size_t i = 0; i < tauGammaVecs.gammasPtOutSigCone.size(); ++i) { double pt_i = tauGammaVecs.gammasPtOutSigCone[i]; double phi_i = tauGammaVecs.gammasdPhiOutSigCone[i]; @@ -184,29 +181,28 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar phi_i = tauGammaVecs.gammasdPhiOutSigCone[i] + 2 * M_PI; double eta_i = tauGammaVecs.gammasdEtaOutSigCone[i]; sumPt += pt_i; - sumPt2 += (pt_i * pt_i); dEta2 += (pt_i * eta_i * eta_i); dPhi2 += (pt_i * phi_i * phi_i); } - tauGammaMoms.tauGammaEnFracOut = -99.; - if (tauVars.tauPt > 0.) { - tauGammaMoms.tauGammaEnFracOut = sumPt / tauVars.tauPt; + tauGammaMoms.gammaEnFracOut = -99.; + if (tauVars.pt > 0.) { + tauGammaMoms.gammaEnFracOut = sumPt / tauVars.pt; } if (sumPt > 0.) { dEta2 /= sumPt; dPhi2 /= sumPt; } - tauGammaMoms.tauGammaEtaMomOut = std::sqrt(dEta2) * std::sqrt(tauGammaMoms.tauGammaEnFracOut) * tauVars.tauPt; - tauGammaMoms.tauGammaPhiMomOut = std::sqrt(dPhi2) * std::sqrt(tauGammaMoms.tauGammaEnFracOut) * tauVars.tauPt; + tauGammaMoms.gammaEtaMomOut = std::sqrt(dEta2) * std::sqrt(tauGammaMoms.gammaEnFracOut) * tauVars.pt; + tauGammaMoms.gammaPhiMomOut = std::sqrt(dPhi2) * std::sqrt(tauGammaMoms.gammaEnFracOut) * tauVars.pt; - return MVAValue(tauVars, tauGammaMoms, eleVars); + return MVAValue(tauVars, tauGammaMoms, elecVars); } template double AntiElectronIDMVA6::MVAValue(const TauVars& tauVars, const TauGammaMoms& tauGammaMoms, - const EleVars& eleVars) { + const ElecVars& elecVars) { if (!isInitialized_) { throw cms::Exception("ClassNotInitialized") << " AntiElectronMVA6 not properly initialized !!\n"; } @@ -214,200 +210,199 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar double mvaValue = -99.; const float ECALBarrelEndcapEtaBorder = 1.479; - float elecDeltaPinPoutOverPin = (eleVars.elecPin > 0.0) ? (std::abs(eleVars.elecPin - eleVars.elecPout) / eleVars.elecPin) : 1.0; - float elecEecalOverPout = (eleVars.elecPout > 0.0) ? (eleVars.elecEecal / eleVars.elecPout) : 20.0; - float elecNumHitsDiffOverSum = ((eleVars.elecGSFNumHits + eleVars.elecKFNumHits) > 0.0) - ? ((eleVars.elecGSFNumHits - eleVars.elecKFNumHits) / (eleVars.elecGSFNumHits + eleVars.elecKFNumHits)) + float elecDeltaPinPoutOverPin = (elecVars.pIn > 0.0) ? (std::abs(elecVars.pIn - elecVars.pOut) / elecVars.pIn) : 1.0; + float elecEecalOverPout = (elecVars.pOut > 0.0) ? (elecVars.eEcal / elecVars.pOut) : 20.0; + float elecNumHitsDiffOverSum = ((elecVars.gsfNumHits + elecVars.kfNumHits) > 0.0) + ? ((elecVars.gsfNumHits - elecVars.kfNumHits) / (elecVars.gsfNumHits + elecVars.kfNumHits)) : 1.0; - if (deltaR(tauVars.tauEtaAtEcalEntrance, tauVars.tauPhi, eleVars.elecEta, eleVars.elecPhi) > 0.3 && tauGammaMoms.tauSignalPFGammaCandsIn == 0 && tauVars.tauHasGsf < 0.5) { - if (std::abs(tauVars.tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { - Var_NoEleMatch_woGwoGSF_Barrel_[0] = tauVars.tauEtaAtEcalEntrance; - Var_NoEleMatch_woGwoGSF_Barrel_[1] = tauVars.tauLeadChargedPFCandEtaAtEcalEntrance; - Var_NoEleMatch_woGwoGSF_Barrel_[2] = std::min(float(2.), tauVars.tauLeadChargedPFCandPt / std::max(float(1.), tauVars.tauPt)); - Var_NoEleMatch_woGwoGSF_Barrel_[3] = std::log(std::max(float(1.), tauVars.tauPt)); - Var_NoEleMatch_woGwoGSF_Barrel_[4] = tauVars.tauEmFraction; - Var_NoEleMatch_woGwoGSF_Barrel_[5] = tauVars.tauLeadPFChargedHadrHoP; - Var_NoEleMatch_woGwoGSF_Barrel_[6] = tauVars.tauLeadPFChargedHadrEoP; - Var_NoEleMatch_woGwoGSF_Barrel_[7] = tauVars.tauVisMassIn; - Var_NoEleMatch_woGwoGSF_Barrel_[8] = tauVars.taudCrackEta; - Var_NoEleMatch_woGwoGSF_Barrel_[9] = tauVars.taudCrackPhi; + if (deltaR(tauVars.etaAtEcalEntrance, tauVars.phi, elecVars.eta, elecVars.phi) > 0.3 && tauGammaMoms.signalPFGammaCandsIn == 0 && tauVars.hasGsf < 0.5) { + if (std::abs(tauVars.etaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { + Var_NoEleMatch_woGwoGSF_Barrel_[0] = tauVars.etaAtEcalEntrance; + Var_NoEleMatch_woGwoGSF_Barrel_[1] = tauVars.leadChargedPFCandEtaAtEcalEntrance; + Var_NoEleMatch_woGwoGSF_Barrel_[2] = std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); + Var_NoEleMatch_woGwoGSF_Barrel_[3] = std::log(std::max(float(1.), tauVars.pt)); + Var_NoEleMatch_woGwoGSF_Barrel_[4] = tauVars.emFraction; + Var_NoEleMatch_woGwoGSF_Barrel_[5] = tauVars.leadPFChargedHadrHoP; + Var_NoEleMatch_woGwoGSF_Barrel_[6] = tauVars.leadPFChargedHadrEoP; + Var_NoEleMatch_woGwoGSF_Barrel_[7] = tauVars.visMassIn; + Var_NoEleMatch_woGwoGSF_Barrel_[8] = tauVars.dCrackEta; + Var_NoEleMatch_woGwoGSF_Barrel_[9] = tauVars.dCrackPhi; mvaValue = mva_NoEleMatch_woGwoGSF_BL_->GetClassifier(Var_NoEleMatch_woGwoGSF_Barrel_); } else { - Var_NoEleMatch_woGwoGSF_Endcap_[0] = tauVars.tauEtaAtEcalEntrance; - Var_NoEleMatch_woGwoGSF_Endcap_[1] = tauVars.tauLeadChargedPFCandEtaAtEcalEntrance; - Var_NoEleMatch_woGwoGSF_Endcap_[2] = std::min(float(2.), tauVars.tauLeadChargedPFCandPt / std::max(float(1.), tauVars.tauPt)); - Var_NoEleMatch_woGwoGSF_Endcap_[3] = std::log(std::max(float(1.), tauVars.tauPt)); - Var_NoEleMatch_woGwoGSF_Endcap_[4] = tauVars.tauEmFraction; - Var_NoEleMatch_woGwoGSF_Endcap_[5] = tauVars.tauLeadPFChargedHadrHoP; - Var_NoEleMatch_woGwoGSF_Endcap_[6] = tauVars.tauLeadPFChargedHadrEoP; - Var_NoEleMatch_woGwoGSF_Endcap_[7] = tauVars.tauVisMassIn; - Var_NoEleMatch_woGwoGSF_Endcap_[8] = tauVars.taudCrackEta; + Var_NoEleMatch_woGwoGSF_Endcap_[0] = tauVars.etaAtEcalEntrance; + Var_NoEleMatch_woGwoGSF_Endcap_[1] = tauVars.leadChargedPFCandEtaAtEcalEntrance; + Var_NoEleMatch_woGwoGSF_Endcap_[2] = std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); + Var_NoEleMatch_woGwoGSF_Endcap_[3] = std::log(std::max(float(1.), tauVars.pt)); + Var_NoEleMatch_woGwoGSF_Endcap_[4] = tauVars.emFraction; + Var_NoEleMatch_woGwoGSF_Endcap_[5] = tauVars.leadPFChargedHadrHoP; + Var_NoEleMatch_woGwoGSF_Endcap_[6] = tauVars.leadPFChargedHadrEoP; + Var_NoEleMatch_woGwoGSF_Endcap_[7] = tauVars.visMassIn; + Var_NoEleMatch_woGwoGSF_Endcap_[8] = tauVars.dCrackEta; mvaValue = mva_NoEleMatch_woGwoGSF_EC_->GetClassifier(Var_NoEleMatch_woGwoGSF_Endcap_); } - } else if (deltaR(tauVars.tauEtaAtEcalEntrance, tauVars.tauPhi, eleVars.elecEta, eleVars.elecPhi) > 0.3 && - tauGammaMoms.tauSignalPFGammaCandsIn > 0 && - tauVars.tauHasGsf < 0.5) { - if (std::abs(tauVars.tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { - Var_NoEleMatch_wGwoGSF_Barrel_[0] = tauVars.tauEtaAtEcalEntrance; - Var_NoEleMatch_wGwoGSF_Barrel_[1] = tauVars.tauLeadChargedPFCandEtaAtEcalEntrance; - Var_NoEleMatch_wGwoGSF_Barrel_[2] = std::min(float(2.), tauVars.tauLeadChargedPFCandPt / std::max(float(1.), tauVars.tauPt)); - Var_NoEleMatch_wGwoGSF_Barrel_[3] = std::log(std::max(float(1.), tauVars.tauPt)); - Var_NoEleMatch_wGwoGSF_Barrel_[4] = tauVars.tauEmFraction; - Var_NoEleMatch_wGwoGSF_Barrel_[5] = tauGammaMoms.tauSignalPFGammaCandsIn; - Var_NoEleMatch_wGwoGSF_Barrel_[6] = tauGammaMoms.tauSignalPFGammaCandsOut; - Var_NoEleMatch_wGwoGSF_Barrel_[7] = tauVars.tauLeadPFChargedHadrHoP; - Var_NoEleMatch_wGwoGSF_Barrel_[8] = tauVars.tauLeadPFChargedHadrEoP; - Var_NoEleMatch_wGwoGSF_Barrel_[9] = tauVars.tauVisMassIn; - Var_NoEleMatch_wGwoGSF_Barrel_[10] = tauGammaMoms.tauGammaEtaMomIn; - Var_NoEleMatch_wGwoGSF_Barrel_[11] = tauGammaMoms.tauGammaEtaMomOut; - Var_NoEleMatch_wGwoGSF_Barrel_[12] = tauGammaMoms.tauGammaPhiMomIn; - Var_NoEleMatch_wGwoGSF_Barrel_[13] = tauGammaMoms.tauGammaPhiMomOut; - Var_NoEleMatch_wGwoGSF_Barrel_[14] = tauGammaMoms.tauGammaEnFracIn; - Var_NoEleMatch_wGwoGSF_Barrel_[15] = tauGammaMoms.tauGammaEnFracOut; - Var_NoEleMatch_wGwoGSF_Barrel_[16] = tauVars.taudCrackEta; - Var_NoEleMatch_wGwoGSF_Barrel_[17] = tauVars.taudCrackPhi; + } else if (deltaR(tauVars.etaAtEcalEntrance, tauVars.phi, elecVars.eta, elecVars.phi) > 0.3 && + tauGammaMoms.signalPFGammaCandsIn > 0 && tauVars.hasGsf < 0.5) { + if (std::abs(tauVars.etaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { + Var_NoEleMatch_wGwoGSF_Barrel_[0] = tauVars.etaAtEcalEntrance; + Var_NoEleMatch_wGwoGSF_Barrel_[1] = tauVars.leadChargedPFCandEtaAtEcalEntrance; + Var_NoEleMatch_wGwoGSF_Barrel_[2] = std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); + Var_NoEleMatch_wGwoGSF_Barrel_[3] = std::log(std::max(float(1.), tauVars.pt)); + Var_NoEleMatch_wGwoGSF_Barrel_[4] = tauVars.emFraction; + Var_NoEleMatch_wGwoGSF_Barrel_[5] = tauGammaMoms.signalPFGammaCandsIn; + Var_NoEleMatch_wGwoGSF_Barrel_[6] = tauGammaMoms.signalPFGammaCandsOut; + Var_NoEleMatch_wGwoGSF_Barrel_[7] = tauVars.leadPFChargedHadrHoP; + Var_NoEleMatch_wGwoGSF_Barrel_[8] = tauVars.leadPFChargedHadrEoP; + Var_NoEleMatch_wGwoGSF_Barrel_[9] = tauVars.visMassIn; + Var_NoEleMatch_wGwoGSF_Barrel_[10] = tauGammaMoms.gammaEtaMomIn; + Var_NoEleMatch_wGwoGSF_Barrel_[11] = tauGammaMoms.gammaEtaMomOut; + Var_NoEleMatch_wGwoGSF_Barrel_[12] = tauGammaMoms.gammaPhiMomIn; + Var_NoEleMatch_wGwoGSF_Barrel_[13] = tauGammaMoms.gammaPhiMomOut; + Var_NoEleMatch_wGwoGSF_Barrel_[14] = tauGammaMoms.gammaEnFracIn; + Var_NoEleMatch_wGwoGSF_Barrel_[15] = tauGammaMoms.gammaEnFracOut; + Var_NoEleMatch_wGwoGSF_Barrel_[16] = tauVars.dCrackEta; + Var_NoEleMatch_wGwoGSF_Barrel_[17] = tauVars.dCrackPhi; mvaValue = mva_NoEleMatch_wGwoGSF_BL_->GetClassifier(Var_NoEleMatch_wGwoGSF_Barrel_); } else { - Var_NoEleMatch_wGwoGSF_Endcap_[0] = tauVars.tauEtaAtEcalEntrance; - Var_NoEleMatch_wGwoGSF_Endcap_[1] = tauVars.tauLeadChargedPFCandEtaAtEcalEntrance; - Var_NoEleMatch_wGwoGSF_Endcap_[2] = std::min(float(2.), tauVars.tauLeadChargedPFCandPt / std::max(float(1.), tauVars.tauPt)); - Var_NoEleMatch_wGwoGSF_Endcap_[3] = std::log(std::max(float(1.), tauVars.tauPt)); - Var_NoEleMatch_wGwoGSF_Endcap_[4] = tauVars.tauEmFraction; - Var_NoEleMatch_wGwoGSF_Endcap_[5] = tauGammaMoms.tauSignalPFGammaCandsIn; - Var_NoEleMatch_wGwoGSF_Endcap_[6] = tauGammaMoms.tauSignalPFGammaCandsOut; - Var_NoEleMatch_wGwoGSF_Endcap_[7] = tauVars.tauLeadPFChargedHadrHoP; - Var_NoEleMatch_wGwoGSF_Endcap_[8] = tauVars.tauLeadPFChargedHadrEoP; - Var_NoEleMatch_wGwoGSF_Endcap_[9] = tauVars.tauVisMassIn; - Var_NoEleMatch_wGwoGSF_Endcap_[10] = tauGammaMoms.tauGammaEtaMomIn; - Var_NoEleMatch_wGwoGSF_Endcap_[11] = tauGammaMoms.tauGammaEtaMomOut; - Var_NoEleMatch_wGwoGSF_Endcap_[12] = tauGammaMoms.tauGammaPhiMomIn; - Var_NoEleMatch_wGwoGSF_Endcap_[13] = tauGammaMoms.tauGammaPhiMomOut; - Var_NoEleMatch_wGwoGSF_Endcap_[14] = tauGammaMoms.tauGammaEnFracIn; - Var_NoEleMatch_wGwoGSF_Endcap_[15] = tauGammaMoms.tauGammaEnFracOut; - Var_NoEleMatch_wGwoGSF_Endcap_[16] = tauVars.taudCrackEta; + Var_NoEleMatch_wGwoGSF_Endcap_[0] = tauVars.etaAtEcalEntrance; + Var_NoEleMatch_wGwoGSF_Endcap_[1] = tauVars.leadChargedPFCandEtaAtEcalEntrance; + Var_NoEleMatch_wGwoGSF_Endcap_[2] = std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); + Var_NoEleMatch_wGwoGSF_Endcap_[3] = std::log(std::max(float(1.), tauVars.pt)); + Var_NoEleMatch_wGwoGSF_Endcap_[4] = tauVars.emFraction; + Var_NoEleMatch_wGwoGSF_Endcap_[5] = tauGammaMoms.signalPFGammaCandsIn; + Var_NoEleMatch_wGwoGSF_Endcap_[6] = tauGammaMoms.signalPFGammaCandsOut; + Var_NoEleMatch_wGwoGSF_Endcap_[7] = tauVars.leadPFChargedHadrHoP; + Var_NoEleMatch_wGwoGSF_Endcap_[8] = tauVars.leadPFChargedHadrEoP; + Var_NoEleMatch_wGwoGSF_Endcap_[9] = tauVars.visMassIn; + Var_NoEleMatch_wGwoGSF_Endcap_[10] = tauGammaMoms.gammaEtaMomIn; + Var_NoEleMatch_wGwoGSF_Endcap_[11] = tauGammaMoms.gammaEtaMomOut; + Var_NoEleMatch_wGwoGSF_Endcap_[12] = tauGammaMoms.gammaPhiMomIn; + Var_NoEleMatch_wGwoGSF_Endcap_[13] = tauGammaMoms.gammaPhiMomOut; + Var_NoEleMatch_wGwoGSF_Endcap_[14] = tauGammaMoms.gammaEnFracIn; + Var_NoEleMatch_wGwoGSF_Endcap_[15] = tauGammaMoms.gammaEnFracOut; + Var_NoEleMatch_wGwoGSF_Endcap_[16] = tauVars.dCrackEta; mvaValue = mva_NoEleMatch_wGwoGSF_EC_->GetClassifier(Var_NoEleMatch_wGwoGSF_Endcap_); } - } else if (tauGammaMoms.tauSignalPFGammaCandsIn == 0 && tauVars.tauHasGsf > 0.5) { - if (std::abs(tauVars.tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { - Var_woGwGSF_Barrel_[0] = std::max(float(-0.1), eleVars.elecEtotOverPin); - Var_woGwGSF_Barrel_[1] = std::log(std::max(float(0.01), eleVars.elecChi2NormGSF)); - Var_woGwGSF_Barrel_[2] = eleVars.elecGSFNumHits; - Var_woGwGSF_Barrel_[3] = std::log(std::max(float(0.01), eleVars.elecGSFTrackResol)); - Var_woGwGSF_Barrel_[4] = eleVars.elecGSFTracklnPt; + } else if (tauGammaMoms.signalPFGammaCandsIn == 0 && tauVars.hasGsf > 0.5) { + if (std::abs(tauVars.etaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { + Var_woGwGSF_Barrel_[0] = std::max(float(-0.1), elecVars.eTotOverPin); + Var_woGwGSF_Barrel_[1] = std::log(std::max(float(0.01), elecVars.chi2NormGSF)); + Var_woGwGSF_Barrel_[2] = elecVars.gsfNumHits; + Var_woGwGSF_Barrel_[3] = std::log(std::max(float(0.01), elecVars.gsfTrackResol)); + Var_woGwGSF_Barrel_[4] = elecVars.gsfTracklnPt; Var_woGwGSF_Barrel_[5] = elecNumHitsDiffOverSum; - Var_woGwGSF_Barrel_[6] = std::log(std::max(float(0.01), eleVars.elecChi2NormKF)); + Var_woGwGSF_Barrel_[6] = std::log(std::max(float(0.01), elecVars.chi2NormKF)); Var_woGwGSF_Barrel_[7] = std::min(elecDeltaPinPoutOverPin, float(1.)); Var_woGwGSF_Barrel_[8] = std::min(elecEecalOverPout, float(20.)); - Var_woGwGSF_Barrel_[9] = eleVars.elecDeltaEta; - Var_woGwGSF_Barrel_[10] = eleVars.elecDeltaPhi; - Var_woGwGSF_Barrel_[11] = std::min(eleVars.elecMvaInSigmaEtaEta, float(0.01)); - Var_woGwGSF_Barrel_[12] = std::min(eleVars.elecMvaInHadEnergy, float(20.)); - Var_woGwGSF_Barrel_[13] = std::min(eleVars.elecMvaInDeltaEta, float(0.1)); - Var_woGwGSF_Barrel_[14] = tauVars.tauEtaAtEcalEntrance; - Var_woGwGSF_Barrel_[15] = tauVars.tauLeadChargedPFCandEtaAtEcalEntrance; - Var_woGwGSF_Barrel_[16] = std::min(float(2.), tauVars.tauLeadChargedPFCandPt / std::max(float(1.), tauVars.tauPt)); - Var_woGwGSF_Barrel_[17] = std::log(std::max(float(1.), tauVars.tauPt)); - Var_woGwGSF_Barrel_[18] = tauVars.tauEmFraction; - Var_woGwGSF_Barrel_[19] = tauVars.tauLeadPFChargedHadrHoP; - Var_woGwGSF_Barrel_[20] = tauVars.tauLeadPFChargedHadrEoP; - Var_woGwGSF_Barrel_[21] = tauVars.tauVisMassIn; - Var_woGwGSF_Barrel_[22] = tauVars.taudCrackEta; - Var_woGwGSF_Barrel_[23] = tauVars.taudCrackPhi; + Var_woGwGSF_Barrel_[9] = elecVars.deltaEta; + Var_woGwGSF_Barrel_[10] = elecVars.deltaPhi; + Var_woGwGSF_Barrel_[11] = std::min(elecVars.mvaInSigmaEtaEta, float(0.01)); + Var_woGwGSF_Barrel_[12] = std::min(elecVars.mvaInHadEnergy, float(20.)); + Var_woGwGSF_Barrel_[13] = std::min(elecVars.mvaInDeltaEta, float(0.1)); + Var_woGwGSF_Barrel_[14] = tauVars.etaAtEcalEntrance; + Var_woGwGSF_Barrel_[15] = tauVars.leadChargedPFCandEtaAtEcalEntrance; + Var_woGwGSF_Barrel_[16] = std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); + Var_woGwGSF_Barrel_[17] = std::log(std::max(float(1.), tauVars.pt)); + Var_woGwGSF_Barrel_[18] = tauVars.emFraction; + Var_woGwGSF_Barrel_[19] = tauVars.leadPFChargedHadrHoP; + Var_woGwGSF_Barrel_[20] = tauVars.leadPFChargedHadrEoP; + Var_woGwGSF_Barrel_[21] = tauVars.visMassIn; + Var_woGwGSF_Barrel_[22] = tauVars.dCrackEta; + Var_woGwGSF_Barrel_[23] = tauVars.dCrackPhi; mvaValue = mva_woGwGSF_BL_->GetClassifier(Var_woGwGSF_Barrel_); } else { - Var_woGwGSF_Endcap_[0] = std::max(float(-0.1), eleVars.elecEtotOverPin); - Var_woGwGSF_Endcap_[1] = std::log(std::max(float(0.01), eleVars.elecChi2NormGSF)); - Var_woGwGSF_Endcap_[2] = eleVars.elecGSFNumHits; - Var_woGwGSF_Endcap_[3] = std::log(std::max(float(0.01), eleVars.elecGSFTrackResol)); - Var_woGwGSF_Endcap_[4] = eleVars.elecGSFTracklnPt; + Var_woGwGSF_Endcap_[0] = std::max(float(-0.1), elecVars.eTotOverPin); + Var_woGwGSF_Endcap_[1] = std::log(std::max(float(0.01), elecVars.chi2NormGSF)); + Var_woGwGSF_Endcap_[2] = elecVars.gsfNumHits; + Var_woGwGSF_Endcap_[3] = std::log(std::max(float(0.01), elecVars.gsfTrackResol)); + Var_woGwGSF_Endcap_[4] = elecVars.gsfTracklnPt; Var_woGwGSF_Endcap_[5] = elecNumHitsDiffOverSum; - Var_woGwGSF_Endcap_[6] = std::log(std::max(float(0.01), eleVars.elecChi2NormKF)); + Var_woGwGSF_Endcap_[6] = std::log(std::max(float(0.01), elecVars.chi2NormKF)); Var_woGwGSF_Endcap_[7] = std::min(elecDeltaPinPoutOverPin, float(1.)); Var_woGwGSF_Endcap_[8] = std::min(elecEecalOverPout, float(20.)); - Var_woGwGSF_Endcap_[9] = eleVars.elecDeltaEta; - Var_woGwGSF_Endcap_[10] = eleVars.elecDeltaPhi; - Var_woGwGSF_Endcap_[11] = std::min(eleVars.elecMvaInSigmaEtaEta, float(0.01)); - Var_woGwGSF_Endcap_[12] = std::min(eleVars.elecMvaInHadEnergy, float(20.)); - Var_woGwGSF_Endcap_[13] = std::min(eleVars.elecMvaInDeltaEta, float(0.1)); - Var_woGwGSF_Endcap_[14] = tauVars.tauEtaAtEcalEntrance; - Var_woGwGSF_Endcap_[15] = tauVars.tauLeadChargedPFCandEtaAtEcalEntrance; - Var_woGwGSF_Endcap_[16] = std::min(float(2.), tauVars.tauLeadChargedPFCandPt / std::max(float(1.), tauVars.tauPt)); - Var_woGwGSF_Endcap_[17] = std::log(std::max(float(1.), tauVars.tauPt)); - Var_woGwGSF_Endcap_[18] = tauVars.tauEmFraction; - Var_woGwGSF_Endcap_[19] = tauVars.tauLeadPFChargedHadrHoP; - Var_woGwGSF_Endcap_[20] = tauVars.tauLeadPFChargedHadrEoP; - Var_woGwGSF_Endcap_[21] = tauVars.tauVisMassIn; - Var_woGwGSF_Endcap_[22] = tauVars.taudCrackEta; + Var_woGwGSF_Endcap_[9] = elecVars.deltaEta; + Var_woGwGSF_Endcap_[10] = elecVars.deltaPhi; + Var_woGwGSF_Endcap_[11] = std::min(elecVars.mvaInSigmaEtaEta, float(0.01)); + Var_woGwGSF_Endcap_[12] = std::min(elecVars.mvaInHadEnergy, float(20.)); + Var_woGwGSF_Endcap_[13] = std::min(elecVars.mvaInDeltaEta, float(0.1)); + Var_woGwGSF_Endcap_[14] = tauVars.etaAtEcalEntrance; + Var_woGwGSF_Endcap_[15] = tauVars.leadChargedPFCandEtaAtEcalEntrance; + Var_woGwGSF_Endcap_[16] = std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); + Var_woGwGSF_Endcap_[17] = std::log(std::max(float(1.), tauVars.pt)); + Var_woGwGSF_Endcap_[18] = tauVars.emFraction; + Var_woGwGSF_Endcap_[19] = tauVars.leadPFChargedHadrHoP; + Var_woGwGSF_Endcap_[20] = tauVars.leadPFChargedHadrEoP; + Var_woGwGSF_Endcap_[21] = tauVars.visMassIn; + Var_woGwGSF_Endcap_[22] = tauVars.dCrackEta; mvaValue = mva_woGwGSF_EC_->GetClassifier(Var_woGwGSF_Endcap_); } - } else if (tauGammaMoms.tauSignalPFGammaCandsIn > 0 && tauVars.tauHasGsf > 0.5) { - if (std::abs(tauVars.tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { - Var_wGwGSF_Barrel_[0] = std::max(float(-0.1), eleVars.elecEtotOverPin); - Var_wGwGSF_Barrel_[1] = std::log(std::max(float(0.01), eleVars.elecChi2NormGSF)); - Var_wGwGSF_Barrel_[2] = eleVars.elecGSFNumHits; - Var_wGwGSF_Barrel_[3] = std::log(std::max(float(0.01), eleVars.elecGSFTrackResol)); - Var_wGwGSF_Barrel_[4] = eleVars.elecGSFTracklnPt; + } else if (tauGammaMoms.signalPFGammaCandsIn > 0 && tauVars.hasGsf > 0.5) { + if (std::abs(tauVars.etaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { + Var_wGwGSF_Barrel_[0] = std::max(float(-0.1), elecVars.eTotOverPin); + Var_wGwGSF_Barrel_[1] = std::log(std::max(float(0.01), elecVars.chi2NormGSF)); + Var_wGwGSF_Barrel_[2] = elecVars.gsfNumHits; + Var_wGwGSF_Barrel_[3] = std::log(std::max(float(0.01), elecVars.gsfTrackResol)); + Var_wGwGSF_Barrel_[4] = elecVars.gsfTracklnPt; Var_wGwGSF_Barrel_[5] = elecNumHitsDiffOverSum; - Var_wGwGSF_Barrel_[6] = std::log(std::max(float(0.01), eleVars.elecChi2NormKF)); + Var_wGwGSF_Barrel_[6] = std::log(std::max(float(0.01), elecVars.chi2NormKF)); Var_wGwGSF_Barrel_[7] = std::min(elecDeltaPinPoutOverPin, float(1.)); Var_wGwGSF_Barrel_[8] = std::min(elecEecalOverPout, float(20.)); - Var_wGwGSF_Barrel_[9] = eleVars.elecDeltaEta; - Var_wGwGSF_Barrel_[10] = eleVars.elecDeltaPhi; - Var_wGwGSF_Barrel_[11] = std::min(eleVars.elecMvaInSigmaEtaEta, float(0.01)); - Var_wGwGSF_Barrel_[12] = std::min(eleVars.elecMvaInHadEnergy, float(20.)); - Var_wGwGSF_Barrel_[13] = std::min(eleVars.elecMvaInDeltaEta, float(0.1)); - Var_wGwGSF_Barrel_[14] = tauVars.tauEtaAtEcalEntrance; - Var_wGwGSF_Barrel_[15] = tauVars.tauLeadChargedPFCandEtaAtEcalEntrance; - Var_wGwGSF_Barrel_[16] = std::min(float(2.), tauVars.tauLeadChargedPFCandPt / std::max(float(1.), tauVars.tauPt)); - Var_wGwGSF_Barrel_[17] = std::log(std::max(float(1.), tauVars.tauPt)); - Var_wGwGSF_Barrel_[18] = tauVars.tauEmFraction; - Var_wGwGSF_Barrel_[19] = tauGammaMoms.tauSignalPFGammaCandsIn; - Var_wGwGSF_Barrel_[20] = tauGammaMoms.tauSignalPFGammaCandsOut; - Var_wGwGSF_Barrel_[21] = tauVars.tauLeadPFChargedHadrHoP; - Var_wGwGSF_Barrel_[22] = tauVars.tauLeadPFChargedHadrEoP; - Var_wGwGSF_Barrel_[23] = tauVars.tauVisMassIn; - Var_wGwGSF_Barrel_[24] = tauGammaMoms.tauGammaEtaMomIn; - Var_wGwGSF_Barrel_[25] = tauGammaMoms.tauGammaEtaMomOut; - Var_wGwGSF_Barrel_[26] = tauGammaMoms.tauGammaPhiMomIn; - Var_wGwGSF_Barrel_[27] = tauGammaMoms.tauGammaPhiMomOut; - Var_wGwGSF_Barrel_[28] = tauGammaMoms.tauGammaEnFracIn; - Var_wGwGSF_Barrel_[29] = tauGammaMoms.tauGammaEnFracOut; - Var_wGwGSF_Barrel_[30] = tauVars.taudCrackEta; - Var_wGwGSF_Barrel_[31] = tauVars.taudCrackPhi; + Var_wGwGSF_Barrel_[9] = elecVars.deltaEta; + Var_wGwGSF_Barrel_[10] = elecVars.deltaPhi; + Var_wGwGSF_Barrel_[11] = std::min(elecVars.mvaInSigmaEtaEta, float(0.01)); + Var_wGwGSF_Barrel_[12] = std::min(elecVars.mvaInHadEnergy, float(20.)); + Var_wGwGSF_Barrel_[13] = std::min(elecVars.mvaInDeltaEta, float(0.1)); + Var_wGwGSF_Barrel_[14] = tauVars.etaAtEcalEntrance; + Var_wGwGSF_Barrel_[15] = tauVars.leadChargedPFCandEtaAtEcalEntrance; + Var_wGwGSF_Barrel_[16] = std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); + Var_wGwGSF_Barrel_[17] = std::log(std::max(float(1.), tauVars.pt)); + Var_wGwGSF_Barrel_[18] = tauVars.emFraction; + Var_wGwGSF_Barrel_[19] = tauGammaMoms.signalPFGammaCandsIn; + Var_wGwGSF_Barrel_[20] = tauGammaMoms.signalPFGammaCandsOut; + Var_wGwGSF_Barrel_[21] = tauVars.leadPFChargedHadrHoP; + Var_wGwGSF_Barrel_[22] = tauVars.leadPFChargedHadrEoP; + Var_wGwGSF_Barrel_[23] = tauVars.visMassIn; + Var_wGwGSF_Barrel_[24] = tauGammaMoms.gammaEtaMomIn; + Var_wGwGSF_Barrel_[25] = tauGammaMoms.gammaEtaMomOut; + Var_wGwGSF_Barrel_[26] = tauGammaMoms.gammaPhiMomIn; + Var_wGwGSF_Barrel_[27] = tauGammaMoms.gammaPhiMomOut; + Var_wGwGSF_Barrel_[28] = tauGammaMoms.gammaEnFracIn; + Var_wGwGSF_Barrel_[29] = tauGammaMoms.gammaEnFracOut; + Var_wGwGSF_Barrel_[30] = tauVars.dCrackEta; + Var_wGwGSF_Barrel_[31] = tauVars.dCrackPhi; mvaValue = mva_wGwGSF_BL_->GetClassifier(Var_wGwGSF_Barrel_); } else { - Var_wGwGSF_Endcap_[0] = std::max(float(-0.1), eleVars.elecEtotOverPin); - Var_wGwGSF_Endcap_[1] = std::log(std::max(float(0.01), eleVars.elecChi2NormGSF)); - Var_wGwGSF_Endcap_[2] = eleVars.elecGSFNumHits; - Var_wGwGSF_Endcap_[3] = std::log(std::max(float(0.01), eleVars.elecGSFTrackResol)); - Var_wGwGSF_Endcap_[4] = eleVars.elecGSFTracklnPt; + Var_wGwGSF_Endcap_[0] = std::max(float(-0.1), elecVars.eTotOverPin); + Var_wGwGSF_Endcap_[1] = std::log(std::max(float(0.01), elecVars.chi2NormGSF)); + Var_wGwGSF_Endcap_[2] = elecVars.gsfNumHits; + Var_wGwGSF_Endcap_[3] = std::log(std::max(float(0.01), elecVars.gsfTrackResol)); + Var_wGwGSF_Endcap_[4] = elecVars.gsfTracklnPt; Var_wGwGSF_Endcap_[5] = elecNumHitsDiffOverSum; - Var_wGwGSF_Endcap_[6] = std::log(std::max(float(0.01), eleVars.elecChi2NormKF)); + Var_wGwGSF_Endcap_[6] = std::log(std::max(float(0.01), elecVars.chi2NormKF)); Var_wGwGSF_Endcap_[7] = std::min(elecDeltaPinPoutOverPin, float(1.)); Var_wGwGSF_Endcap_[8] = std::min(elecEecalOverPout, float(20.)); - Var_wGwGSF_Endcap_[9] = eleVars.elecDeltaEta; - Var_wGwGSF_Endcap_[10] = eleVars.elecDeltaPhi; - Var_wGwGSF_Endcap_[11] = std::min(eleVars.elecMvaInSigmaEtaEta, float(0.01)); - Var_wGwGSF_Endcap_[12] = std::min(eleVars.elecMvaInHadEnergy, float(20.)); - Var_wGwGSF_Endcap_[13] = std::min(eleVars.elecMvaInDeltaEta, float(0.1)); - Var_wGwGSF_Endcap_[14] = tauVars.tauEtaAtEcalEntrance; - Var_wGwGSF_Endcap_[15] = tauVars.tauLeadChargedPFCandEtaAtEcalEntrance; - Var_wGwGSF_Endcap_[16] = std::min(float(2.), tauVars.tauLeadChargedPFCandPt / std::max(float(1.), tauVars.tauPt)); - Var_wGwGSF_Endcap_[17] = std::log(std::max(float(1.), tauVars.tauPt)); - Var_wGwGSF_Endcap_[18] = tauVars.tauEmFraction; - Var_wGwGSF_Endcap_[19] = tauGammaMoms.tauSignalPFGammaCandsIn; - Var_wGwGSF_Endcap_[20] = tauGammaMoms.tauSignalPFGammaCandsOut; - Var_wGwGSF_Endcap_[21] = tauVars.tauLeadPFChargedHadrHoP; - Var_wGwGSF_Endcap_[22] = tauVars.tauLeadPFChargedHadrEoP; - Var_wGwGSF_Endcap_[23] = tauVars.tauVisMassIn; - Var_wGwGSF_Endcap_[24] = tauGammaMoms.tauGammaEtaMomIn; - Var_wGwGSF_Endcap_[25] = tauGammaMoms.tauGammaEtaMomOut; - Var_wGwGSF_Endcap_[26] = tauGammaMoms.tauGammaPhiMomIn; - Var_wGwGSF_Endcap_[27] = tauGammaMoms.tauGammaPhiMomOut; - Var_wGwGSF_Endcap_[28] = tauGammaMoms.tauGammaEnFracIn; - Var_wGwGSF_Endcap_[29] = tauGammaMoms.tauGammaEnFracOut; - Var_wGwGSF_Endcap_[30] = tauVars.taudCrackEta; + Var_wGwGSF_Endcap_[9] = elecVars.deltaEta; + Var_wGwGSF_Endcap_[10] = elecVars.deltaPhi; + Var_wGwGSF_Endcap_[11] = std::min(elecVars.mvaInSigmaEtaEta, float(0.01)); + Var_wGwGSF_Endcap_[12] = std::min(elecVars.mvaInHadEnergy, float(20.)); + Var_wGwGSF_Endcap_[13] = std::min(elecVars.mvaInDeltaEta, float(0.1)); + Var_wGwGSF_Endcap_[14] = tauVars.etaAtEcalEntrance; + Var_wGwGSF_Endcap_[15] = tauVars.leadChargedPFCandEtaAtEcalEntrance; + Var_wGwGSF_Endcap_[16] = std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); + Var_wGwGSF_Endcap_[17] = std::log(std::max(float(1.), tauVars.pt)); + Var_wGwGSF_Endcap_[18] = tauVars.emFraction; + Var_wGwGSF_Endcap_[19] = tauGammaMoms.signalPFGammaCandsIn; + Var_wGwGSF_Endcap_[20] = tauGammaMoms.signalPFGammaCandsOut; + Var_wGwGSF_Endcap_[21] = tauVars.leadPFChargedHadrHoP; + Var_wGwGSF_Endcap_[22] = tauVars.leadPFChargedHadrEoP; + Var_wGwGSF_Endcap_[23] = tauVars.visMassIn; + Var_wGwGSF_Endcap_[24] = tauGammaMoms.gammaEtaMomIn; + Var_wGwGSF_Endcap_[25] = tauGammaMoms.gammaEtaMomOut; + Var_wGwGSF_Endcap_[26] = tauGammaMoms.gammaPhiMomIn; + Var_wGwGSF_Endcap_[27] = tauGammaMoms.gammaPhiMomOut; + Var_wGwGSF_Endcap_[28] = tauGammaMoms.gammaEnFracIn; + Var_wGwGSF_Endcap_[29] = tauGammaMoms.gammaEnFracOut; + Var_wGwGSF_Endcap_[30] = tauVars.dCrackEta; mvaValue = mva_wGwGSF_EC_->GetClassifier(Var_wGwGSF_Endcap_); } } @@ -423,9 +418,9 @@ double AntiElectronIDMVA6::MVAValue(const TauType& theTau TauGammaVecs tauGammaVecs = AntiElectronIDMVA6::getTauGammaVecs(theTau); // === electron variables === - EleVars eleVars = AntiElectronIDMVA6::getEleVars(theEle); + ElecVars elecVars = AntiElectronIDMVA6::getElecVars(theEle); - return MVAValue(tauVars, tauGammaVecs, eleVars); + return MVAValue(tauVars, tauGammaVecs, elecVars); } template @@ -435,10 +430,10 @@ double AntiElectronIDMVA6::MVAValue(const TauType& theTau TauGammaVecs tauGammaVecs = AntiElectronIDMVA6::getTauGammaVecs(theTau); // === electron variables === - EleVars eleVars; - eleVars.elecEta = 9.9; //Dummy value used in MVA training + ElecVars elecVars; + elecVars.eta = 9.9; //Dummy value used in MVA training - return MVAValue(tauVars, tauGammaVecs, eleVars); + return MVAValue(tauVars, tauGammaVecs, elecVars); } template @@ -450,18 +445,12 @@ TauVars AntiElectronIDMVA6::getTauVars(const TauType& the else throw cms::Exception("AntiElectronIDMVA6") << "Unsupported TauType used. You must use either reco::PFTau or pat::Tau."; - tauVars.tauPt = theTau.pt(); - + + tauVars.pt = theTau.pt(); + reco::Candidate::LorentzVector pfGammaSum(0, 0, 0, 0); reco::Candidate::LorentzVector pfChargedSum(0, 0, 0, 0); - float signalrad = std::max(0.05, std::min(0.10, 3.0 / std::max(1.0, theTau.pt()))); - for (const auto& charged : theTau.signalChargedHadrCands()) { - float dR = deltaR(charged->p4(), theTau.leadChargedHadrCand()->p4()); - // charged particles inside the tau signal cone - if (dR < signalrad) { - pfChargedSum += charged->p4(); - } - } + float signalrad = std::clamp(3.0 / std::max(1.0, theTau.pt()), 0.05, 0.10); for (const auto& gamma : theTau.signalGammaCands()) { float dR = deltaR(gamma->p4(), theTau.leadChargedHadrCand()->p4()); // pfGammas inside the tau signal cone @@ -469,25 +458,31 @@ TauVars AntiElectronIDMVA6::getTauVars(const TauType& the pfGammaSum += gamma->p4(); } } - tauVars.tauVisMassIn = (pfGammaSum + pfChargedSum).mass(); + for (const auto& charged : theTau.signalChargedHadrCands()) { + float dR = deltaR(charged->p4(), theTau.leadChargedHadrCand()->p4()); + // charged particles inside the tau signal cone + if (dR < signalrad) { + pfChargedSum += charged->p4(); + } + } + tauVars.visMassIn = (pfGammaSum + pfChargedSum).mass(); - tauVars.tauHasGsf = 0; + tauVars.hasGsf = 0; if (theTau.leadChargedHadrCand().isNonnull()) { - pat::PackedCandidate const* packedLeadTauCand = - dynamic_cast(theTau.leadChargedHadrCand().get()); - if (packedLeadTauCand != nullptr) { - if (std::abs(packedLeadTauCand->pdgId()) == 11) - tauVars.tauHasGsf = 1; + const pat::PackedCandidate* packedLeadChCand = + dynamic_cast(theTau.leadChargedHadrCand().get()); + if (packedLeadChCand != nullptr) { + if (std::abs(packedLeadChCand->pdgId()) == 11) + tauVars.hasGsf = 1; } else { - reco::PFCandidate const* pfLeadTauCand = - dynamic_cast(theTau.leadChargedHadrCand().get()); - if (pfLeadTauCand != nullptr && pfLeadTauCand->gsfTrackRef().isNonnull()) { - tauVars.tauHasGsf = 1; - } + const reco::PFCandidate* pfLeadChCand = + dynamic_cast(theTau.leadChargedHadrCand().get()); + if (pfLeadChCand != nullptr && pfLeadChCand->gsfTrackRef().isNonnull()) + tauVars.hasGsf = 1; } } - tauVars.taudCrackPhi = dCrackPhi(tauVars.tauPhi, tauVars.tauEtaAtEcalEntrance); - tauVars.taudCrackEta = dCrackEta(tauVars.tauEtaAtEcalEntrance); + tauVars.dCrackPhi = dCrackPhi(tauVars.phi, tauVars.etaAtEcalEntrance); + tauVars.dCrackEta = dCrackEta(tauVars.etaAtEcalEntrance); return tauVars; } @@ -496,7 +491,7 @@ template TauGammaVecs AntiElectronIDMVA6::getTauGammaVecs(const TauType& theTau){ TauGammaVecs tauGammaVecs; - float signalrad = std::max(0.05, std::min(0.10, 3.0 / std::max(1.0, theTau.pt()))); + float signalrad = std::clamp(3.0 / std::max(1.0, theTau.pt()), 0.05, 0.10); for (const auto& gamma : theTau.signalGammaCands()) { float dR = deltaR(gamma->p4(), theTau.leadChargedHadrCand()->p4()); // pfGammas inside the tau signal cone @@ -516,12 +511,12 @@ TauGammaVecs AntiElectronIDMVA6::getTauGammaVecs(const Ta } template -EleVars AntiElectronIDMVA6::getEleVars(const ElectronType& theEle){ +ElecVars AntiElectronIDMVA6::getElecVars(const ElectronType& theEle){ - EleVars eleVars; + ElecVars elecVars; - eleVars.elecEta = theEle.eta(); - eleVars.elecPhi = theEle.phi(); + elecVars.eta = theEle.eta(); + elecVars.phi = theEle.phi(); // Variables related to the electron Cluster float elecEe = 0.; @@ -539,39 +534,39 @@ EleVars AntiElectronIDMVA6::getEleVars(const ElectronType } } - eleVars.elecPin = std::sqrt(theEle.trackMomentumAtVtx().Mag2()); - eleVars.elecPout = std::sqrt(theEle.trackMomentumOut().Mag2()); - eleVars.elecEtotOverPin = (eleVars.elecPin > 0.0) ? ((elecEe + elecEgamma) / eleVars.elecPin) : -0.1; - eleVars.elecEecal = theEle.ecalEnergy(); - eleVars.elecDeltaEta = theEle.deltaEtaSeedClusterTrackAtCalo(); - eleVars.elecDeltaPhi = theEle.deltaPhiSeedClusterTrackAtCalo(); - eleVars.elecMvaInSigmaEtaEta = theEle.mvaInput().sigmaEtaEta; - eleVars.elecMvaInHadEnergy = theEle.mvaInput().hadEnergy; - eleVars.elecMvaInDeltaEta = theEle.mvaInput().deltaEta; + elecVars.pIn = std::sqrt(theEle.trackMomentumAtVtx().Mag2()); + elecVars.pOut = std::sqrt(theEle.trackMomentumOut().Mag2()); + elecVars.eTotOverPin = (elecVars.pIn > 0.0) ? ((elecEe + elecEgamma) / elecVars.pIn) : -0.1; + elecVars.eEcal = theEle.ecalEnergy(); + elecVars.deltaEta = theEle.deltaEtaSeedClusterTrackAtCalo(); + elecVars.deltaPhi = theEle.deltaPhiSeedClusterTrackAtCalo(); + elecVars.mvaInSigmaEtaEta = theEle.mvaInput().sigmaEtaEta; + elecVars.mvaInHadEnergy = theEle.mvaInput().hadEnergy; + elecVars.mvaInDeltaEta = theEle.mvaInput().deltaEta; // Variables related to the GsfTrack - eleVars.elecChi2NormGSF = -99.; - eleVars.elecGSFNumHits = -99.; - eleVars.elecGSFTrackResol = -99.; - eleVars.elecGSFTracklnPt = -99.; + elecVars.chi2NormGSF = -99.; + elecVars.gsfNumHits = -99.; + elecVars.gsfTrackResol = -99.; + elecVars.gsfTracklnPt = -99.; if (theEle.gsfTrack().isNonnull()) { - eleVars.elecChi2NormGSF = theEle.gsfTrack()->normalizedChi2(); - eleVars.elecGSFNumHits = theEle.gsfTrack()->numberOfValidHits(); + elecVars.chi2NormGSF = theEle.gsfTrack()->normalizedChi2(); + elecVars.gsfNumHits = theEle.gsfTrack()->numberOfValidHits(); if (theEle.gsfTrack()->pt() > 0.) { - eleVars.elecGSFTrackResol = theEle.gsfTrack()->ptError() / theEle.gsfTrack()->pt(); - eleVars.elecGSFTracklnPt = log(theEle.gsfTrack()->pt()) * M_LN10; + elecVars.gsfTrackResol = theEle.gsfTrack()->ptError() / theEle.gsfTrack()->pt(); + elecVars.gsfTracklnPt = log(theEle.gsfTrack()->pt()) * M_LN10; } } // Variables related to the CtfTrack - eleVars.elecChi2NormKF = -99.; - eleVars.elecKFNumHits = -99.; + elecVars.chi2NormKF = -99.; + elecVars.kfNumHits = -99.; if (theEle.closestCtfTrackRef().isNonnull()) { - eleVars.elecChi2NormKF = theEle.closestCtfTrackRef()->normalizedChi2(); - eleVars.elecKFNumHits = theEle.closestCtfTrackRef()->numberOfValidHits(); + elecVars.chi2NormKF = theEle.closestCtfTrackRef()->normalizedChi2(); + elecVars.kfNumHits = theEle.closestCtfTrackRef()->numberOfValidHits(); } - return eleVars; + return elecVars; } template @@ -674,12 +669,12 @@ double AntiElectronIDMVA6::dCrackEta(double eta) { template TauVars AntiElectronIDMVA6::getTauVarsTypeSpecific(const pat::Tau& theTau) { TauVars tauVars; - tauVars.tauEtaAtEcalEntrance = theTau.etaAtEcalEntrance(); - tauVars.tauLeadChargedPFCandEtaAtEcalEntrance = theTau.etaAtEcalEntranceLeadChargedCand(); - tauVars.tauLeadChargedPFCandPt = theTau.ptLeadChargedCand(); - tauVars.tauPhi = theTau.phi(); + tauVars.etaAtEcalEntrance = theTau.etaAtEcalEntrance(); + tauVars.leadChargedPFCandEtaAtEcalEntrance = theTau.etaAtEcalEntranceLeadChargedCand(); + tauVars.leadChargedPFCandPt = theTau.ptLeadChargedCand(); + tauVars.phi = theTau.phi(); if (!usePhiAtEcalEntranceExtrapolation_) { - tauVars.tauPhi = theTau.phiAtEcalEntrance(); + tauVars.phi = theTau.phiAtEcalEntrance(); } else { float sumPhiTimesEnergy = 0.; float sumEnergy = 0.; @@ -695,15 +690,15 @@ TauVars AntiElectronIDMVA6::getTauVarsTypeSpecific(const sumEnergy += candidate->energy(); } if (sumEnergy > 0.) { - tauVars.tauPhi = sumPhiTimesEnergy / sumEnergy; + tauVars.phi = sumPhiTimesEnergy / sumEnergy; } } - tauVars.tauEmFraction = std::max(theTau.emFraction_MVA(), (float)0.); - tauVars.tauLeadPFChargedHadrHoP = 0.; - tauVars.tauLeadPFChargedHadrEoP = 0.; + tauVars.emFraction = std::max(theTau.emFraction_MVA(), (float)0.); + tauVars.leadPFChargedHadrHoP = 0.; + tauVars.leadPFChargedHadrEoP = 0.; if (theTau.leadChargedHadrCand()->p() > 0.) { - tauVars.tauLeadPFChargedHadrHoP = theTau.hcalEnergyLeadChargedHadrCand() / theTau.leadChargedHadrCand()->p(); - tauVars.tauLeadPFChargedHadrEoP = theTau.ecalEnergyLeadChargedHadrCand() / theTau.leadChargedHadrCand()->p(); + tauVars.leadPFChargedHadrHoP = theTau.hcalEnergyLeadChargedHadrCand() / theTau.leadChargedHadrCand()->p(); + tauVars.leadPFChargedHadrEoP = theTau.ecalEnergyLeadChargedHadrCand() / theTau.leadChargedHadrCand()->p(); } return tauVars; @@ -713,13 +708,13 @@ TauVars AntiElectronIDMVA6::getTauVarsTypeSpecific(const template TauVars AntiElectronIDMVA6::getTauVarsTypeSpecific(const reco::PFTau& theTau) { TauVars tauVars; - tauVars.tauEtaAtEcalEntrance = -99.; - tauVars.tauLeadChargedPFCandEtaAtEcalEntrance = -99.; - tauVars.tauLeadChargedPFCandPt = -99.; + tauVars.etaAtEcalEntrance = -99.; + tauVars.leadChargedPFCandEtaAtEcalEntrance = -99.; + tauVars.leadChargedPFCandPt = -99.; float sumEtaTimesEnergy = 0.; float sumPhiTimesEnergy = 0.; float sumEnergy = 0.; - tauVars.tauPhi = theTau.phi(); + tauVars.phi = theTau.phi(); // Check type of candidates building tau to avoid dynamic casts further bool isFromPFCands = (theTau.leadCand().isNonnull() && dynamic_cast(theTau.leadCand().get()) != nullptr); @@ -764,9 +759,9 @@ TauVars AntiElectronIDMVA6::getTauVarsTypeSpecific(const track = candidate->bestTrack(); } if (track != nullptr) { - if (track->pt() > tauVars.tauLeadChargedPFCandPt) { - tauVars.tauLeadChargedPFCandEtaAtEcalEntrance = etaAtECalEntrance; - tauVars.tauLeadChargedPFCandPt = track->pt(); + if (track->pt() > tauVars.leadChargedPFCandPt) { + tauVars.leadChargedPFCandEtaAtEcalEntrance = etaAtECalEntrance; + tauVars.leadChargedPFCandPt = track->pt(); } } sumEtaTimesEnergy += etaAtECalEntrance * candidate->energy(); @@ -774,29 +769,29 @@ TauVars AntiElectronIDMVA6::getTauVarsTypeSpecific(const sumEnergy += candidate->energy(); } if (sumEnergy > 0.) { - tauVars.tauEtaAtEcalEntrance = sumEtaTimesEnergy / sumEnergy; - tauVars.tauPhi = sumPhiTimesEnergy / sumEnergy; + tauVars.etaAtEcalEntrance = sumEtaTimesEnergy / sumEnergy; + tauVars.phi = sumPhiTimesEnergy / sumEnergy; } - tauVars.tauEmFraction = std::max(theTau.emFraction(), (float)0.); - tauVars.tauLeadPFChargedHadrHoP = 0.; - tauVars.tauLeadPFChargedHadrEoP = 0.; + tauVars.emFraction = std::max(theTau.emFraction(), (float)0.); + tauVars.leadPFChargedHadrHoP = 0.; + tauVars.leadPFChargedHadrEoP = 0.; if (theTau.leadChargedHadrCand()->p() > 0.) { if (isFromPFCands) { const reco::PFCandidate* pfLeadCandiate = static_cast(theTau.leadChargedHadrCand().get()); - tauVars.tauLeadPFChargedHadrHoP = pfLeadCandiate->hcalEnergy() / + tauVars.leadPFChargedHadrHoP = pfLeadCandiate->hcalEnergy() / pfLeadCandiate->p(); - tauVars.tauLeadPFChargedHadrEoP = pfLeadCandiate->ecalEnergy() / + tauVars.leadPFChargedHadrEoP = pfLeadCandiate->ecalEnergy() / pfLeadCandiate->p(); } else { const pat::PackedCandidate* patLeadCandiate = dynamic_cast(theTau.leadChargedHadrCand().get()); if (patLeadCandiate != nullptr) { - tauVars.tauLeadPFChargedHadrHoP = patLeadCandiate->caloFraction() * + tauVars.leadPFChargedHadrHoP = patLeadCandiate->caloFraction() * patLeadCandiate->energy() * patLeadCandiate->hcalFraction() / patLeadCandiate->p(); - tauVars.tauLeadPFChargedHadrHoP = patLeadCandiate->caloFraction() * + tauVars.leadPFChargedHadrHoP = patLeadCandiate->caloFraction() * patLeadCandiate->energy() * (1. - patLeadCandiate->hcalFraction()) / patLeadCandiate->p(); } From aff43e13350892159f5391bd8c7217b3169c9934 Mon Sep 17 00:00:00 2001 From: Michal Bluj Date: Tue, 7 Jul 2020 15:16:55 +0200 Subject: [PATCH 4/6] Code quality fixes --- .../RecoTau/interface/AntiElectronIDMVA6.h | 10 +- .../TauDiscriminationAgainstElectronMVA6.cc | 132 +++++++++--------- RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc | 121 ++++++++-------- 3 files changed, 126 insertions(+), 137 deletions(-) diff --git a/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h b/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h index 50e492a843a87..94bad9f42c679 100644 --- a/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h +++ b/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h @@ -93,13 +93,9 @@ class AntiElectronIDMVA6 { void beginEvent(const edm::Event&, const edm::EventSetup&); - double MVAValue(const TauVars& tauVars, - const TauGammaVecs& tauGammaVecs, - const ElecVars& elecVars); + double MVAValue(const TauVars& tauVars, const TauGammaVecs& tauGammaVecs, const ElecVars& elecVars); - double MVAValue(const TauVars& tauVars, - const TauGammaMoms& tauGammaMoms, - const ElecVars& elecVars); + double MVAValue(const TauVars& tauVars, const TauGammaMoms& tauGammaMoms, const ElecVars& elecVars); // this function can be called for all categories double MVAValue(const TauType& theTau, const ElectronType& theEle); @@ -112,7 +108,7 @@ class AntiElectronIDMVA6 { TauVars getTauVars(const TauType& theTau); TauGammaVecs getTauGammaVecs(const TauType& theTau); ElecVars getElecVars(const ElectronType& theEle); - + // track extrapolation to ECAL entrance (used to re-calculate variables that might not be available on miniAOD) bool atECalEntrance(const reco::Candidate* part, math::XYZPoint& pos); diff --git a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronMVA6.cc b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronMVA6.cc index 60aa457143465..b5583fd036b3e 100644 --- a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronMVA6.cc +++ b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronMVA6.cc @@ -12,19 +12,26 @@ #include "DataFormats/Math/interface/deltaR.h" template -class TauDiscriminationAgainstElectronMVA6 : public TauDiscriminationProducerBase { +class TauDiscriminationAgainstElectronMVA6 : public TauDiscriminationProducerBase { public: typedef std::vector TauCollection; typedef edm::Ref TauRef; typedef std::vector ElectronCollection; explicit TauDiscriminationAgainstElectronMVA6(const edm::ParameterSet& cfg) - : TauDiscriminationProducerBase::TauDiscriminationProducerBase(cfg), - moduleLabel_(cfg.getParameter("@module_label")), - mva_(std::make_unique >(cfg)), - Electron_token(edm::EDConsumerBase::consumes(cfg.getParameter("srcElectrons"))), //MB: full specification with prefix mandatory - vetoEcalCracks_(cfg.getParameter("vetoEcalCracks")), - verbosity_(cfg.getParameter("verbosity")) {} + : TauDiscriminationProducerBase::TauDiscriminationProducerBase(cfg), + moduleLabel_(cfg.getParameter("@module_label")), + mva_(std::make_unique >(cfg)), + Electron_token(edm::EDConsumerBase::consumes( + cfg.getParameter("srcElectrons"))), //MB: full specification with prefix mandatory + vetoEcalCracks_(cfg.getParameter("vetoEcalCracks")), + verbosity_(cfg.getParameter("verbosity")) {} void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override { mva_->beginEvent(evt, es); @@ -42,10 +49,10 @@ class TauDiscriminationAgainstElectronMVA6 : public TauDiscriminationProducerBas private: bool isInEcalCrack(double) const; - // Overloaded method with explicit type specification to avoid partial - //implementation of full class - std::pair getTauEtaAtECalEntrance(const reco::PFTauRef& theTauRef) const; - std::pair getTauEtaAtECalEntrance(const pat::TauRef& theTauRef) const; + // Overloaded method with explicit type specification to avoid partial + //implementation of full class + std::pair getTauEtaAtECalEntrance(const reco::PFTauRef& theTauRef) const; + std::pair getTauEtaAtECalEntrance(const pat::TauRef& theTauRef) const; std::string moduleLabel_; std::unique_ptr > mva_; @@ -62,9 +69,9 @@ class TauDiscriminationAgainstElectronMVA6 : public TauDiscriminationProducerBas }; template -reco::SingleTauDiscriminatorContainer -TauDiscriminationAgainstElectronMVA6::discriminate(const TauRef& theTauRef) const { - +reco::SingleTauDiscriminatorContainer +TauDiscriminationAgainstElectronMVA6::discriminate( + const TauRef& theTauRef) const { reco::SingleTauDiscriminatorContainer result; result.rawValues = {1., -1.}; double category = -1.; @@ -74,13 +81,12 @@ TauDiscriminationAgainstElectronMVA6::d const float ECalBarrelEndcapEtaBorder = 1.479; - std::pair tauEtaAtECalEntrance; - if (std::is_same::value || - std::is_same::value) + std::pair tauEtaAtECalEntrance; + if (std::is_same::value || std::is_same::value) tauEtaAtECalEntrance = getTauEtaAtECalEntrance(theTauRef); else throw cms::Exception("TauDiscriminationAgainstElectronMVA6") - << "Unsupported TauType used. You must use either reco::PFTau or pat::Tau."; + << "Unsupported TauType used. You must use either reco::PFTau or pat::Tau."; if ((*theTauRef).leadChargedHadrCand().isNonnull()) { int numSignalGammaCandsInSigCone = 0; @@ -96,14 +102,12 @@ TauDiscriminationAgainstElectronMVA6::d bool hasGsfTrack = false; const reco::CandidatePtr& leadChCand = theTauRef->leadChargedHadrCand(); if (leadChCand.isNonnull()) { - const pat::PackedCandidate* packedLeadChCand = - dynamic_cast(leadChCand.get()); + const pat::PackedCandidate* packedLeadChCand = dynamic_cast(leadChCand.get()); if (packedLeadChCand != nullptr) { - hasGsfTrack = (std::abs(packedLeadChCand->pdgId()) == 11); + hasGsfTrack = (std::abs(packedLeadChCand->pdgId()) == 11); } else { - const reco::PFCandidate* pfLeadChCand = - dynamic_cast(leadChCand.get()); - hasGsfTrack = (pfLeadChCand != nullptr && pfLeadChCand->gsfTrackRef().isNonnull()); + const reco::PFCandidate* pfLeadChCand = dynamic_cast(leadChCand.get()); + hasGsfTrack = (pfLeadChCand != nullptr && pfLeadChCand->gsfTrackRef().isNonnull()); } } @@ -120,10 +124,10 @@ TauDiscriminationAgainstElectronMVA6::d // veto taus that go to ECal crack if (vetoEcalCracks_ && (isInEcalCrack(tauEtaAtECalEntrance.first) || isInEcalCrack(tauEtaAtECalEntrance.second))) { - // add category index - result.rawValues.at(1) = category; - // return MVA output value - result.rawValues.at(0) = -99.; + // add category index + result.rawValues.at(1) = category; + // return MVA output value + result.rawValues.at(0) = -99.; return result; } // veto taus that go to ECal crack @@ -182,17 +186,15 @@ TauDiscriminationAgainstElectronMVA6::d if (verbosity_) { edm::LogPrint(this->getTauTypeString() + "AgainstEleMVA6") - << "<" + this->getTauTypeString() + "AgainstElectronMVA6::discriminate>:"; + << "<" + this->getTauTypeString() + "AgainstElectronMVA6::discriminate>:"; edm::LogPrint(this->getTauTypeString() + "AgainstEleMVA6") - << " tau: Pt = " << theTauRef->pt() << ", eta = " << theTauRef->eta() - << ", phi = " << theTauRef->phi(); + << " tau: Pt = " << theTauRef->pt() << ", eta = " << theTauRef->eta() << ", phi = " << theTauRef->phi(); edm::LogPrint(this->getTauTypeString() + "AgainstEleMVA6") - << " deltaREleTau = " << deltaRDummy - << ", isGsfElectronMatched = " << isGsfElectronMatched; + << " deltaREleTau = " << deltaRDummy << ", isGsfElectronMatched = " << isGsfElectronMatched; edm::LogPrint(this->getTauTypeString() + "AgainstEleMVA6") - << " #Prongs = " << theTauRef->signalChargedHadrCands().size(); + << " #Prongs = " << theTauRef->signalChargedHadrCands().size(); edm::LogPrint(this->getTauTypeString() + "AgainstEleMVA6") - << " MVA = " << result.rawValues.at(0) << ", category = " << category; + << " MVA = " << result.rawValues.at(0) << ", category = " << category; } // add category index @@ -202,15 +204,15 @@ TauDiscriminationAgainstElectronMVA6::d } template -bool TauDiscriminationAgainstElectronMVA6::isInEcalCrack( -double eta) const { +bool TauDiscriminationAgainstElectronMVA6::isInEcalCrack(double eta) const { double absEta = std::abs(eta); return (absEta > 1.460 && absEta < 1.558); } template -std::pair TauDiscriminationAgainstElectronMVA6::getTauEtaAtECalEntrance(const reco::PFTauRef& theTauRef) const { - +std::pair +TauDiscriminationAgainstElectronMVA6::getTauEtaAtECalEntrance( + const reco::PFTauRef& theTauRef) const { float tauEtaAtECalEntrance = -99; float leadChargedCandEtaAtECalEntrance = -99; float sumEtaTimesEnergy = 0; @@ -220,36 +222,31 @@ std::pair TauDiscriminationAgainstElectronMVA6signalCands()) { float etaAtECalEntrance = candidate->eta(); const reco::Track* track = nullptr; - const reco::PFCandidate* pfCandidate = - dynamic_cast(candidate.get()); + const reco::PFCandidate* pfCandidate = dynamic_cast(candidate.get()); if (pfCandidate != nullptr) { - etaAtECalEntrance = pfCandidate->positionAtECALEntrance().eta(); + etaAtECalEntrance = pfCandidate->positionAtECALEntrance().eta(); if (pfCandidate->trackRef().isNonnull()) - track = pfCandidate->trackRef().get(); - else if (pfCandidate->muonRef().isNonnull() && - pfCandidate->muonRef()->innerTrack().isNonnull()) - track = pfCandidate->muonRef()->innerTrack().get(); - else if (pfCandidate->muonRef().isNonnull() && - pfCandidate->muonRef()->globalTrack().isNonnull()) - track = pfCandidate->muonRef()->globalTrack().get(); - else if (pfCandidate->muonRef().isNonnull() && - pfCandidate->muonRef()->outerTrack().isNonnull()) - track = pfCandidate->muonRef()->outerTrack().get(); + track = pfCandidate->trackRef().get(); + else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->innerTrack().isNonnull()) + track = pfCandidate->muonRef()->innerTrack().get(); + else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->globalTrack().isNonnull()) + track = pfCandidate->muonRef()->globalTrack().get(); + else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->outerTrack().isNonnull()) + track = pfCandidate->muonRef()->outerTrack().get(); else if (pfCandidate->gsfTrackRef().isNonnull()) - track = pfCandidate->gsfTrackRef().get(); + track = pfCandidate->gsfTrackRef().get(); } else { bool success = false; - reco::Candidate::Point posAtECal = - positionAtECalEntrance_(candidate.get(), success); + reco::Candidate::Point posAtECal = positionAtECalEntrance_(candidate.get(), success); if (success) { - etaAtECalEntrance = posAtECal.eta(); + etaAtECalEntrance = posAtECal.eta(); } track = candidate->bestTrack(); } if (track != nullptr) { if (track->pt() > leadChargedCandPt) { - leadChargedCandEtaAtECalEntrance = etaAtECalEntrance; - leadChargedCandPt = track->pt(); + leadChargedCandEtaAtECalEntrance = etaAtECalEntrance; + leadChargedCandPt = track->pt(); } } sumEtaTimesEnergy += etaAtECalEntrance * candidate->energy(); @@ -258,19 +255,19 @@ std::pair TauDiscriminationAgainstElectronMVA6 0.) { tauEtaAtECalEntrance = sumEtaTimesEnergy / sumEnergy; } - return std::pair(tauEtaAtECalEntrance, - leadChargedCandEtaAtECalEntrance); + return std::pair(tauEtaAtECalEntrance, leadChargedCandEtaAtECalEntrance); } template -std::pair TauDiscriminationAgainstElectronMVA6::getTauEtaAtECalEntrance(const pat::TauRef& theTauRef) const { - return std::pair(theTauRef->etaAtEcalEntrance(), - theTauRef->etaAtEcalEntranceLeadChargedCand()); +std::pair +TauDiscriminationAgainstElectronMVA6::getTauEtaAtECalEntrance( + const pat::TauRef& theTauRef) const { + return std::pair(theTauRef->etaAtEcalEntrance(), theTauRef->etaAtEcalEntranceLeadChargedCand()); } template void TauDiscriminationAgainstElectronMVA6::fillDescriptions( -edm::ConfigurationDescriptions& descriptions) { + edm::ConfigurationDescriptions& descriptions) { // {pfReco,pat}TauDiscriminationAgainstElectronMVA6 edm::ParameterSetDescription desc; @@ -299,8 +296,11 @@ edm::ConfigurationDescriptions& descriptions) { desc.add("vetoEcalCracks", true); desc.add("usePhiAtEcalEntranceExtrapolation", false); desc.add("verbosity", 0); - - TauDiscriminationProducerBase::fillProducerDescriptions(desc); // inherited from the base-class + + TauDiscriminationProducerBase::fillProducerDescriptions(desc); // inherited from the base-class descriptions.addWithDefaultLabel(desc); } diff --git a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc index 18a91a13f7c17..49193fbdd828a 100644 --- a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc +++ b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc @@ -137,8 +137,8 @@ void AntiElectronIDMVA6::beginEvent(const edm::Event& evt template double AntiElectronIDMVA6::MVAValue(const TauVars& tauVars, - const TauGammaVecs& tauGammaVecs, - const ElecVars& elecVars) { + const TauGammaVecs& tauGammaVecs, + const ElecVars& elecVars) { TauGammaMoms tauGammaMoms; double sumPt = 0.; double dEta2 = 0.; @@ -156,7 +156,7 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar dEta2 += (pt_i * eta_i * eta_i); dPhi2 += (pt_i * phi_i * phi_i); } - + tauGammaMoms.gammaEnFracIn = -99.; if (tauVars.pt > 0.) { tauGammaMoms.gammaEnFracIn = sumPt / tauVars.pt; @@ -201,8 +201,8 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar template double AntiElectronIDMVA6::MVAValue(const TauVars& tauVars, - const TauGammaMoms& tauGammaMoms, - const ElecVars& elecVars) { + const TauGammaMoms& tauGammaMoms, + const ElecVars& elecVars) { if (!isInitialized_) { throw cms::Exception("ClassNotInitialized") << " AntiElectronMVA6 not properly initialized !!\n"; } @@ -212,15 +212,18 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar const float ECALBarrelEndcapEtaBorder = 1.479; float elecDeltaPinPoutOverPin = (elecVars.pIn > 0.0) ? (std::abs(elecVars.pIn - elecVars.pOut) / elecVars.pIn) : 1.0; float elecEecalOverPout = (elecVars.pOut > 0.0) ? (elecVars.eEcal / elecVars.pOut) : 20.0; - float elecNumHitsDiffOverSum = ((elecVars.gsfNumHits + elecVars.kfNumHits) > 0.0) - ? ((elecVars.gsfNumHits - elecVars.kfNumHits) / (elecVars.gsfNumHits + elecVars.kfNumHits)) - : 1.0; + float elecNumHitsDiffOverSum = + ((elecVars.gsfNumHits + elecVars.kfNumHits) > 0.0) + ? ((elecVars.gsfNumHits - elecVars.kfNumHits) / (elecVars.gsfNumHits + elecVars.kfNumHits)) + : 1.0; - if (deltaR(tauVars.etaAtEcalEntrance, tauVars.phi, elecVars.eta, elecVars.phi) > 0.3 && tauGammaMoms.signalPFGammaCandsIn == 0 && tauVars.hasGsf < 0.5) { + if (deltaR(tauVars.etaAtEcalEntrance, tauVars.phi, elecVars.eta, elecVars.phi) > 0.3 && + tauGammaMoms.signalPFGammaCandsIn == 0 && tauVars.hasGsf < 0.5) { if (std::abs(tauVars.etaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { Var_NoEleMatch_woGwoGSF_Barrel_[0] = tauVars.etaAtEcalEntrance; Var_NoEleMatch_woGwoGSF_Barrel_[1] = tauVars.leadChargedPFCandEtaAtEcalEntrance; - Var_NoEleMatch_woGwoGSF_Barrel_[2] = std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); + Var_NoEleMatch_woGwoGSF_Barrel_[2] = + std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); Var_NoEleMatch_woGwoGSF_Barrel_[3] = std::log(std::max(float(1.), tauVars.pt)); Var_NoEleMatch_woGwoGSF_Barrel_[4] = tauVars.emFraction; Var_NoEleMatch_woGwoGSF_Barrel_[5] = tauVars.leadPFChargedHadrHoP; @@ -232,7 +235,8 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar } else { Var_NoEleMatch_woGwoGSF_Endcap_[0] = tauVars.etaAtEcalEntrance; Var_NoEleMatch_woGwoGSF_Endcap_[1] = tauVars.leadChargedPFCandEtaAtEcalEntrance; - Var_NoEleMatch_woGwoGSF_Endcap_[2] = std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); + Var_NoEleMatch_woGwoGSF_Endcap_[2] = + std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); Var_NoEleMatch_woGwoGSF_Endcap_[3] = std::log(std::max(float(1.), tauVars.pt)); Var_NoEleMatch_woGwoGSF_Endcap_[4] = tauVars.emFraction; Var_NoEleMatch_woGwoGSF_Endcap_[5] = tauVars.leadPFChargedHadrHoP; @@ -242,11 +246,12 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar mvaValue = mva_NoEleMatch_woGwoGSF_EC_->GetClassifier(Var_NoEleMatch_woGwoGSF_Endcap_); } } else if (deltaR(tauVars.etaAtEcalEntrance, tauVars.phi, elecVars.eta, elecVars.phi) > 0.3 && - tauGammaMoms.signalPFGammaCandsIn > 0 && tauVars.hasGsf < 0.5) { + tauGammaMoms.signalPFGammaCandsIn > 0 && tauVars.hasGsf < 0.5) { if (std::abs(tauVars.etaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { Var_NoEleMatch_wGwoGSF_Barrel_[0] = tauVars.etaAtEcalEntrance; Var_NoEleMatch_wGwoGSF_Barrel_[1] = tauVars.leadChargedPFCandEtaAtEcalEntrance; - Var_NoEleMatch_wGwoGSF_Barrel_[2] = std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); + Var_NoEleMatch_wGwoGSF_Barrel_[2] = + std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); Var_NoEleMatch_wGwoGSF_Barrel_[3] = std::log(std::max(float(1.), tauVars.pt)); Var_NoEleMatch_wGwoGSF_Barrel_[4] = tauVars.emFraction; Var_NoEleMatch_wGwoGSF_Barrel_[5] = tauGammaMoms.signalPFGammaCandsIn; @@ -266,7 +271,8 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar } else { Var_NoEleMatch_wGwoGSF_Endcap_[0] = tauVars.etaAtEcalEntrance; Var_NoEleMatch_wGwoGSF_Endcap_[1] = tauVars.leadChargedPFCandEtaAtEcalEntrance; - Var_NoEleMatch_wGwoGSF_Endcap_[2] = std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); + Var_NoEleMatch_wGwoGSF_Endcap_[2] = + std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); Var_NoEleMatch_wGwoGSF_Endcap_[3] = std::log(std::max(float(1.), tauVars.pt)); Var_NoEleMatch_wGwoGSF_Endcap_[4] = tauVars.emFraction; Var_NoEleMatch_wGwoGSF_Endcap_[5] = tauGammaMoms.signalPFGammaCandsIn; @@ -414,7 +420,7 @@ double AntiElectronIDMVA6::MVAValue(const TauType& theTau { // === tau variables === - TauVars tauVars = AntiElectronIDMVA6::getTauVars(theTau); + TauVars tauVars = AntiElectronIDMVA6::getTauVars(theTau); TauGammaVecs tauGammaVecs = AntiElectronIDMVA6::getTauGammaVecs(theTau); // === electron variables === @@ -431,20 +437,19 @@ double AntiElectronIDMVA6::MVAValue(const TauType& theTau // === electron variables === ElecVars elecVars; - elecVars.eta = 9.9; //Dummy value used in MVA training + elecVars.eta = 9.9; // Dummy value used in MVA training return MVAValue(tauVars, tauGammaVecs, elecVars); } template -TauVars AntiElectronIDMVA6::getTauVars(const TauType& theTau){ +TauVars AntiElectronIDMVA6::getTauVars(const TauType& theTau) { TauVars tauVars; - if (std::is_same::value || - std::is_same::value) + if (std::is_same::value || std::is_same::value) tauVars = getTauVarsTypeSpecific(theTau); else throw cms::Exception("AntiElectronIDMVA6") - << "Unsupported TauType used. You must use either reco::PFTau or pat::Tau."; + << "Unsupported TauType used. You must use either reco::PFTau or pat::Tau."; tauVars.pt = theTau.pt(); @@ -470,13 +475,13 @@ TauVars AntiElectronIDMVA6::getTauVars(const TauType& the tauVars.hasGsf = 0; if (theTau.leadChargedHadrCand().isNonnull()) { const pat::PackedCandidate* packedLeadChCand = - dynamic_cast(theTau.leadChargedHadrCand().get()); + dynamic_cast(theTau.leadChargedHadrCand().get()); if (packedLeadChCand != nullptr) { if (std::abs(packedLeadChCand->pdgId()) == 11) tauVars.hasGsf = 1; } else { const reco::PFCandidate* pfLeadChCand = - dynamic_cast(theTau.leadChargedHadrCand().get()); + dynamic_cast(theTau.leadChargedHadrCand().get()); if (pfLeadChCand != nullptr && pfLeadChCand->gsfTrackRef().isNonnull()) tauVars.hasGsf = 1; } @@ -488,7 +493,7 @@ TauVars AntiElectronIDMVA6::getTauVars(const TauType& the } template -TauGammaVecs AntiElectronIDMVA6::getTauGammaVecs(const TauType& theTau){ +TauGammaVecs AntiElectronIDMVA6::getTauGammaVecs(const TauType& theTau) { TauGammaVecs tauGammaVecs; float signalrad = std::clamp(3.0 / std::max(1.0, theTau.pt()), 0.05, 0.10); @@ -511,8 +516,7 @@ TauGammaVecs AntiElectronIDMVA6::getTauGammaVecs(const Ta } template -ElecVars AntiElectronIDMVA6::getElecVars(const ElectronType& theEle){ - +ElecVars AntiElectronIDMVA6::getElecVars(const ElectronType& theEle) { ElecVars elecVars; elecVars.eta = theEle.eta(); @@ -681,8 +685,7 @@ TauVars AntiElectronIDMVA6::getTauVarsTypeSpecific(const for (const auto& candidate : theTau.signalCands()) { float phiAtECalEntrance = candidate->phi(); bool success = false; - reco::Candidate::Point posAtECal = - positionAtECalEntrance_(candidate.get(), success); + reco::Candidate::Point posAtECal = positionAtECalEntrance_(candidate.get(), success); if (success) { phiAtECalEntrance = posAtECal.phi(); } @@ -706,7 +709,7 @@ TauVars AntiElectronIDMVA6::getTauVarsTypeSpecific(const // reco::PFTau template -TauVars AntiElectronIDMVA6::getTauVarsTypeSpecific(const reco::PFTau& theTau) { +TauVars AntiElectronIDMVA6::getTauVarsTypeSpecific(const reco::PFTau& theTau) { TauVars tauVars; tauVars.etaAtEcalEntrance = -99.; tauVars.leadChargedPFCandEtaAtEcalEntrance = -99.; @@ -715,9 +718,9 @@ TauVars AntiElectronIDMVA6::getTauVarsTypeSpecific(const float sumPhiTimesEnergy = 0.; float sumEnergy = 0.; tauVars.phi = theTau.phi(); - // Check type of candidates building tau to avoid dynamic casts further - bool isFromPFCands = (theTau.leadCand().isNonnull() && - dynamic_cast(theTau.leadCand().get()) != nullptr); + // Check type of candidates building tau to avoid dynamic casts further + bool isFromPFCands = + (theTau.leadCand().isNonnull() && dynamic_cast(theTau.leadCand().get()) != nullptr); for (const auto& candidate : theTau.signalCands()) { float etaAtECalEntrance = candidate->eta(); float phiAtECalEntrance = candidate->phi(); @@ -726,32 +729,27 @@ TauVars AntiElectronIDMVA6::getTauVarsTypeSpecific(const const reco::PFCandidate* pfCandidate = static_cast(candidate.get()); etaAtECalEntrance = pfCandidate->positionAtECALEntrance().eta(); if (!usePhiAtEcalEntranceExtrapolation_) { - phiAtECalEntrance = pfCandidate->positionAtECALEntrance().phi(); + phiAtECalEntrance = pfCandidate->positionAtECALEntrance().phi(); } else { - bool success = false; - reco::Candidate::Point posAtECal = - positionAtECalEntrance_(candidate.get(), success); - if (success) { - phiAtECalEntrance = posAtECal.phi(); - } + bool success = false; + reco::Candidate::Point posAtECal = positionAtECalEntrance_(candidate.get(), success); + if (success) { + phiAtECalEntrance = posAtECal.phi(); + } } if (pfCandidate->trackRef().isNonnull()) - track = pfCandidate->trackRef().get(); - else if (pfCandidate->muonRef().isNonnull() && - pfCandidate->muonRef()->innerTrack().isNonnull()) - track = pfCandidate->muonRef()->innerTrack().get(); - else if (pfCandidate->muonRef().isNonnull() && - pfCandidate->muonRef()->globalTrack().isNonnull()) - track = pfCandidate->muonRef()->globalTrack().get(); - else if (pfCandidate->muonRef().isNonnull() && - pfCandidate->muonRef()->outerTrack().isNonnull()) - track = pfCandidate->muonRef()->outerTrack().get(); + track = pfCandidate->trackRef().get(); + else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->innerTrack().isNonnull()) + track = pfCandidate->muonRef()->innerTrack().get(); + else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->globalTrack().isNonnull()) + track = pfCandidate->muonRef()->globalTrack().get(); + else if (pfCandidate->muonRef().isNonnull() && pfCandidate->muonRef()->outerTrack().isNonnull()) + track = pfCandidate->muonRef()->outerTrack().get(); else if (pfCandidate->gsfTrackRef().isNonnull()) - track = pfCandidate->gsfTrackRef().get(); + track = pfCandidate->gsfTrackRef().get(); } else { bool success = false; - reco::Candidate::Point posAtECal = - positionAtECalEntrance_(candidate.get(), success); + reco::Candidate::Point posAtECal = positionAtECalEntrance_(candidate.get(), success); if (success) { etaAtECalEntrance = posAtECal.eta(); phiAtECalEntrance = posAtECal.phi(); @@ -779,21 +777,17 @@ TauVars AntiElectronIDMVA6::getTauVarsTypeSpecific(const if (theTau.leadChargedHadrCand()->p() > 0.) { if (isFromPFCands) { const reco::PFCandidate* pfLeadCandiate = - static_cast(theTau.leadChargedHadrCand().get()); - tauVars.leadPFChargedHadrHoP = pfLeadCandiate->hcalEnergy() / - pfLeadCandiate->p(); - tauVars.leadPFChargedHadrEoP = pfLeadCandiate->ecalEnergy() / - pfLeadCandiate->p(); + static_cast(theTau.leadChargedHadrCand().get()); + tauVars.leadPFChargedHadrHoP = pfLeadCandiate->hcalEnergy() / pfLeadCandiate->p(); + tauVars.leadPFChargedHadrEoP = pfLeadCandiate->ecalEnergy() / pfLeadCandiate->p(); } else { const pat::PackedCandidate* patLeadCandiate = - dynamic_cast(theTau.leadChargedHadrCand().get()); + dynamic_cast(theTau.leadChargedHadrCand().get()); if (patLeadCandiate != nullptr) { - tauVars.leadPFChargedHadrHoP = patLeadCandiate->caloFraction() * - patLeadCandiate->energy() * patLeadCandiate->hcalFraction() / - patLeadCandiate->p(); - tauVars.leadPFChargedHadrHoP = patLeadCandiate->caloFraction() * - patLeadCandiate->energy() * (1. - patLeadCandiate->hcalFraction()) / - patLeadCandiate->p(); + tauVars.leadPFChargedHadrHoP = patLeadCandiate->caloFraction() * patLeadCandiate->energy() * + patLeadCandiate->hcalFraction() / patLeadCandiate->p(); + tauVars.leadPFChargedHadrHoP = patLeadCandiate->caloFraction() * patLeadCandiate->energy() * + (1. - patLeadCandiate->hcalFraction()) / patLeadCandiate->p(); } } } @@ -804,4 +798,3 @@ TauVars AntiElectronIDMVA6::getTauVarsTypeSpecific(const // compile desired types and make available to linker template class AntiElectronIDMVA6; template class AntiElectronIDMVA6; - From 4ee40aa848e0aad30086018ddcacc7e5860dcca7 Mon Sep 17 00:00:00 2001 From: Michal Bluj Date: Thu, 9 Jul 2020 20:54:36 +0200 Subject: [PATCH 5/6] namespace to protect anti-e MVA6 variable blocks --- .../RecoTau/interface/AntiElectronIDMVA6.h | 122 +++++++++--------- RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc | 2 + 2 files changed, 66 insertions(+), 58 deletions(-) diff --git a/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h b/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h index 94bad9f42c679..16b3cf07d6382 100644 --- a/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h +++ b/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h @@ -33,57 +33,59 @@ #include -struct TauVars { - float pt = 0; - float etaAtEcalEntrance = 0; - float phi = 0; - float leadChargedPFCandPt = 0; - float leadChargedPFCandEtaAtEcalEntrance = 0; - float emFraction = 0; - float leadPFChargedHadrHoP = 0; - float leadPFChargedHadrEoP = 0; - float visMassIn = 0; - float dCrackEta = 0; - float dCrackPhi = 0; - float hasGsf = 0; -}; -struct TauGammaVecs { - std::vector gammasdEtaInSigCone; - std::vector gammasdPhiInSigCone; - std::vector gammasPtInSigCone; - std::vector gammasdEtaOutSigCone; - std::vector gammasdPhiOutSigCone; - std::vector gammasPtOutSigCone; -}; -struct TauGammaMoms { - int signalPFGammaCandsIn = 0; - int signalPFGammaCandsOut = 0; - float gammaEtaMomIn = 0; - float gammaEtaMomOut = 0; - float gammaPhiMomIn = 0; - float gammaPhiMomOut = 0; - float gammaEnFracIn = 0; - float gammaEnFracOut = 0; -}; -struct ElecVars { - float eta = 0; - float phi = 0; - float eTotOverPin = 0; - float chi2NormGSF = 0; - float chi2NormKF = 0; - float gsfNumHits = 0; - float kfNumHits = 0; - float gsfTrackResol = 0; - float gsfTracklnPt = 0; - float pIn = 0; - float pOut = 0; - float eEcal = 0; - float deltaEta = 0; - float deltaPhi = 0; - float mvaInSigmaEtaEta = 0; - float mvaInHadEnergy = 0; - float mvaInDeltaEta = 0; -}; +namespace antiElecIDMVA6_blocks { + struct TauVars { + float pt = 0; + float etaAtEcalEntrance = 0; + float phi = 0; + float leadChargedPFCandPt = 0; + float leadChargedPFCandEtaAtEcalEntrance = 0; + float emFraction = 0; + float leadPFChargedHadrHoP = 0; + float leadPFChargedHadrEoP = 0; + float visMassIn = 0; + float dCrackEta = 0; + float dCrackPhi = 0; + float hasGsf = 0; + }; + struct TauGammaVecs { + std::vector gammasdEtaInSigCone; + std::vector gammasdPhiInSigCone; + std::vector gammasPtInSigCone; + std::vector gammasdEtaOutSigCone; + std::vector gammasdPhiOutSigCone; + std::vector gammasPtOutSigCone; + }; + struct TauGammaMoms { + int signalPFGammaCandsIn = 0; + int signalPFGammaCandsOut = 0; + float gammaEtaMomIn = 0; + float gammaEtaMomOut = 0; + float gammaPhiMomIn = 0; + float gammaPhiMomOut = 0; + float gammaEnFracIn = 0; + float gammaEnFracOut = 0; + }; + struct ElecVars { + float eta = 0; + float phi = 0; + float eTotOverPin = 0; + float chi2NormGSF = 0; + float chi2NormKF = 0; + float gsfNumHits = 0; + float kfNumHits = 0; + float gsfTrackResol = 0; + float gsfTracklnPt = 0; + float pIn = 0; + float pOut = 0; + float eEcal = 0; + float deltaEta = 0; + float deltaPhi = 0; + float mvaInSigmaEtaEta = 0; + float mvaInHadEnergy = 0; + float mvaInDeltaEta = 0; + }; +} // namespace antiElecIDMVA6_blocks template class AntiElectronIDMVA6 { @@ -93,9 +95,13 @@ class AntiElectronIDMVA6 { void beginEvent(const edm::Event&, const edm::EventSetup&); - double MVAValue(const TauVars& tauVars, const TauGammaVecs& tauGammaVecs, const ElecVars& elecVars); + double MVAValue(const antiElecIDMVA6_blocks::TauVars& tauVars, + const antiElecIDMVA6_blocks::TauGammaVecs& tauGammaVecs, + const antiElecIDMVA6_blocks::ElecVars& elecVars); - double MVAValue(const TauVars& tauVars, const TauGammaMoms& tauGammaMoms, const ElecVars& elecVars); + double MVAValue(const antiElecIDMVA6_blocks::TauVars& tauVars, + const antiElecIDMVA6_blocks::TauGammaMoms& tauGammaMoms, + const antiElecIDMVA6_blocks::ElecVars& elecVars); // this function can be called for all categories double MVAValue(const TauType& theTau, const ElectronType& theEle); @@ -103,11 +109,11 @@ class AntiElectronIDMVA6 { double MVAValue(const TauType& theTau); // overloaded method with explicit tau type to avoid partial imlementation of full class - TauVars getTauVarsTypeSpecific(const reco::PFTau& theTau); - TauVars getTauVarsTypeSpecific(const pat::Tau& theTau); - TauVars getTauVars(const TauType& theTau); - TauGammaVecs getTauGammaVecs(const TauType& theTau); - ElecVars getElecVars(const ElectronType& theEle); + antiElecIDMVA6_blocks::TauVars getTauVarsTypeSpecific(const reco::PFTau& theTau); + antiElecIDMVA6_blocks::TauVars getTauVarsTypeSpecific(const pat::Tau& theTau); + antiElecIDMVA6_blocks::TauVars getTauVars(const TauType& theTau); + antiElecIDMVA6_blocks::TauGammaVecs getTauGammaVecs(const TauType& theTau); + antiElecIDMVA6_blocks::ElecVars getElecVars(const ElectronType& theEle); // track extrapolation to ECAL entrance (used to re-calculate variables that might not be available on miniAOD) bool atECalEntrance(const reco::Candidate* part, math::XYZPoint& pos); diff --git a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc index 49193fbdd828a..be310476313a7 100644 --- a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc +++ b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc @@ -14,6 +14,8 @@ #include #include +using namespace antiElecIDMVA6_blocks; + template AntiElectronIDMVA6::AntiElectronIDMVA6(const edm::ParameterSet& cfg) : isInitialized_(false), From aa849162d9f50f22257215ab652160bed5e2c3af Mon Sep 17 00:00:00 2001 From: Michal Bluj Date: Thu, 16 Jul 2020 18:27:20 +0200 Subject: [PATCH 6/6] small improvements --- RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc | 116 +++++++++---------- 1 file changed, 56 insertions(+), 60 deletions(-) diff --git a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc index be310476313a7..cf79e4f3dcf12 100644 --- a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc +++ b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc @@ -167,8 +167,8 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar dEta2 /= sumPt; dPhi2 /= sumPt; } - tauGammaMoms.gammaEtaMomIn = std::sqrt(dEta2) * std::sqrt(tauGammaMoms.gammaEnFracIn) * tauVars.pt; - tauGammaMoms.gammaPhiMomIn = std::sqrt(dPhi2) * std::sqrt(tauGammaMoms.gammaEnFracIn) * tauVars.pt; + tauGammaMoms.gammaEtaMomIn = std::sqrt(dEta2 * tauGammaMoms.gammaEnFracIn) * tauVars.pt; + tauGammaMoms.gammaPhiMomIn = std::sqrt(dPhi2 * tauGammaMoms.gammaEnFracIn) * tauVars.pt; sumPt = 0.; dEta2 = 0.; @@ -195,8 +195,8 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar dEta2 /= sumPt; dPhi2 /= sumPt; } - tauGammaMoms.gammaEtaMomOut = std::sqrt(dEta2) * std::sqrt(tauGammaMoms.gammaEnFracOut) * tauVars.pt; - tauGammaMoms.gammaPhiMomOut = std::sqrt(dPhi2) * std::sqrt(tauGammaMoms.gammaEnFracOut) * tauVars.pt; + tauGammaMoms.gammaEtaMomOut = std::sqrt(dEta2 * tauGammaMoms.gammaEnFracOut) * tauVars.pt; + tauGammaMoms.gammaPhiMomOut = std::sqrt(dPhi2 * tauGammaMoms.gammaEnFracOut) * tauVars.pt; return MVAValue(tauVars, tauGammaMoms, elecVars); } @@ -224,9 +224,8 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar if (std::abs(tauVars.etaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { Var_NoEleMatch_woGwoGSF_Barrel_[0] = tauVars.etaAtEcalEntrance; Var_NoEleMatch_woGwoGSF_Barrel_[1] = tauVars.leadChargedPFCandEtaAtEcalEntrance; - Var_NoEleMatch_woGwoGSF_Barrel_[2] = - std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); - Var_NoEleMatch_woGwoGSF_Barrel_[3] = std::log(std::max(float(1.), tauVars.pt)); + Var_NoEleMatch_woGwoGSF_Barrel_[2] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt)); + Var_NoEleMatch_woGwoGSF_Barrel_[3] = std::log(std::max(1.f, tauVars.pt)); Var_NoEleMatch_woGwoGSF_Barrel_[4] = tauVars.emFraction; Var_NoEleMatch_woGwoGSF_Barrel_[5] = tauVars.leadPFChargedHadrHoP; Var_NoEleMatch_woGwoGSF_Barrel_[6] = tauVars.leadPFChargedHadrEoP; @@ -237,9 +236,8 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar } else { Var_NoEleMatch_woGwoGSF_Endcap_[0] = tauVars.etaAtEcalEntrance; Var_NoEleMatch_woGwoGSF_Endcap_[1] = tauVars.leadChargedPFCandEtaAtEcalEntrance; - Var_NoEleMatch_woGwoGSF_Endcap_[2] = - std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); - Var_NoEleMatch_woGwoGSF_Endcap_[3] = std::log(std::max(float(1.), tauVars.pt)); + Var_NoEleMatch_woGwoGSF_Endcap_[2] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt)); + Var_NoEleMatch_woGwoGSF_Endcap_[3] = std::log(std::max(1.f, tauVars.pt)); Var_NoEleMatch_woGwoGSF_Endcap_[4] = tauVars.emFraction; Var_NoEleMatch_woGwoGSF_Endcap_[5] = tauVars.leadPFChargedHadrHoP; Var_NoEleMatch_woGwoGSF_Endcap_[6] = tauVars.leadPFChargedHadrEoP; @@ -252,9 +250,8 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar if (std::abs(tauVars.etaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { Var_NoEleMatch_wGwoGSF_Barrel_[0] = tauVars.etaAtEcalEntrance; Var_NoEleMatch_wGwoGSF_Barrel_[1] = tauVars.leadChargedPFCandEtaAtEcalEntrance; - Var_NoEleMatch_wGwoGSF_Barrel_[2] = - std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); - Var_NoEleMatch_wGwoGSF_Barrel_[3] = std::log(std::max(float(1.), tauVars.pt)); + Var_NoEleMatch_wGwoGSF_Barrel_[2] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt)); + Var_NoEleMatch_wGwoGSF_Barrel_[3] = std::log(std::max(1.f, tauVars.pt)); Var_NoEleMatch_wGwoGSF_Barrel_[4] = tauVars.emFraction; Var_NoEleMatch_wGwoGSF_Barrel_[5] = tauGammaMoms.signalPFGammaCandsIn; Var_NoEleMatch_wGwoGSF_Barrel_[6] = tauGammaMoms.signalPFGammaCandsOut; @@ -273,9 +270,8 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar } else { Var_NoEleMatch_wGwoGSF_Endcap_[0] = tauVars.etaAtEcalEntrance; Var_NoEleMatch_wGwoGSF_Endcap_[1] = tauVars.leadChargedPFCandEtaAtEcalEntrance; - Var_NoEleMatch_wGwoGSF_Endcap_[2] = - std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); - Var_NoEleMatch_wGwoGSF_Endcap_[3] = std::log(std::max(float(1.), tauVars.pt)); + Var_NoEleMatch_wGwoGSF_Endcap_[2] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt)); + Var_NoEleMatch_wGwoGSF_Endcap_[3] = std::log(std::max(1.f, tauVars.pt)); Var_NoEleMatch_wGwoGSF_Endcap_[4] = tauVars.emFraction; Var_NoEleMatch_wGwoGSF_Endcap_[5] = tauGammaMoms.signalPFGammaCandsIn; Var_NoEleMatch_wGwoGSF_Endcap_[6] = tauGammaMoms.signalPFGammaCandsOut; @@ -293,24 +289,24 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar } } else if (tauGammaMoms.signalPFGammaCandsIn == 0 && tauVars.hasGsf > 0.5) { if (std::abs(tauVars.etaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { - Var_woGwGSF_Barrel_[0] = std::max(float(-0.1), elecVars.eTotOverPin); - Var_woGwGSF_Barrel_[1] = std::log(std::max(float(0.01), elecVars.chi2NormGSF)); + Var_woGwGSF_Barrel_[0] = std::max(-0.1f, elecVars.eTotOverPin); + Var_woGwGSF_Barrel_[1] = std::log(std::max(0.01f, elecVars.chi2NormGSF)); Var_woGwGSF_Barrel_[2] = elecVars.gsfNumHits; - Var_woGwGSF_Barrel_[3] = std::log(std::max(float(0.01), elecVars.gsfTrackResol)); + Var_woGwGSF_Barrel_[3] = std::log(std::max(0.01f, elecVars.gsfTrackResol)); Var_woGwGSF_Barrel_[4] = elecVars.gsfTracklnPt; Var_woGwGSF_Barrel_[5] = elecNumHitsDiffOverSum; - Var_woGwGSF_Barrel_[6] = std::log(std::max(float(0.01), elecVars.chi2NormKF)); - Var_woGwGSF_Barrel_[7] = std::min(elecDeltaPinPoutOverPin, float(1.)); - Var_woGwGSF_Barrel_[8] = std::min(elecEecalOverPout, float(20.)); + Var_woGwGSF_Barrel_[6] = std::log(std::max(0.01f, elecVars.chi2NormKF)); + Var_woGwGSF_Barrel_[7] = std::min(elecDeltaPinPoutOverPin, 1.f); + Var_woGwGSF_Barrel_[8] = std::min(elecEecalOverPout, 20.f); Var_woGwGSF_Barrel_[9] = elecVars.deltaEta; Var_woGwGSF_Barrel_[10] = elecVars.deltaPhi; - Var_woGwGSF_Barrel_[11] = std::min(elecVars.mvaInSigmaEtaEta, float(0.01)); - Var_woGwGSF_Barrel_[12] = std::min(elecVars.mvaInHadEnergy, float(20.)); - Var_woGwGSF_Barrel_[13] = std::min(elecVars.mvaInDeltaEta, float(0.1)); + Var_woGwGSF_Barrel_[11] = std::min(elecVars.mvaInSigmaEtaEta, 0.01f); + Var_woGwGSF_Barrel_[12] = std::min(elecVars.mvaInHadEnergy, 20.f); + Var_woGwGSF_Barrel_[13] = std::min(elecVars.mvaInDeltaEta, 0.1f); Var_woGwGSF_Barrel_[14] = tauVars.etaAtEcalEntrance; Var_woGwGSF_Barrel_[15] = tauVars.leadChargedPFCandEtaAtEcalEntrance; - Var_woGwGSF_Barrel_[16] = std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); - Var_woGwGSF_Barrel_[17] = std::log(std::max(float(1.), tauVars.pt)); + Var_woGwGSF_Barrel_[16] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt)); + Var_woGwGSF_Barrel_[17] = std::log(std::max(1.f, tauVars.pt)); Var_woGwGSF_Barrel_[18] = tauVars.emFraction; Var_woGwGSF_Barrel_[19] = tauVars.leadPFChargedHadrHoP; Var_woGwGSF_Barrel_[20] = tauVars.leadPFChargedHadrEoP; @@ -319,24 +315,24 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar Var_woGwGSF_Barrel_[23] = tauVars.dCrackPhi; mvaValue = mva_woGwGSF_BL_->GetClassifier(Var_woGwGSF_Barrel_); } else { - Var_woGwGSF_Endcap_[0] = std::max(float(-0.1), elecVars.eTotOverPin); - Var_woGwGSF_Endcap_[1] = std::log(std::max(float(0.01), elecVars.chi2NormGSF)); + Var_woGwGSF_Endcap_[0] = std::max(-0.1f, elecVars.eTotOverPin); + Var_woGwGSF_Endcap_[1] = std::log(std::max(0.01f, elecVars.chi2NormGSF)); Var_woGwGSF_Endcap_[2] = elecVars.gsfNumHits; - Var_woGwGSF_Endcap_[3] = std::log(std::max(float(0.01), elecVars.gsfTrackResol)); + Var_woGwGSF_Endcap_[3] = std::log(std::max(0.01f, elecVars.gsfTrackResol)); Var_woGwGSF_Endcap_[4] = elecVars.gsfTracklnPt; Var_woGwGSF_Endcap_[5] = elecNumHitsDiffOverSum; - Var_woGwGSF_Endcap_[6] = std::log(std::max(float(0.01), elecVars.chi2NormKF)); - Var_woGwGSF_Endcap_[7] = std::min(elecDeltaPinPoutOverPin, float(1.)); - Var_woGwGSF_Endcap_[8] = std::min(elecEecalOverPout, float(20.)); + Var_woGwGSF_Endcap_[6] = std::log(std::max(0.01f, elecVars.chi2NormKF)); + Var_woGwGSF_Endcap_[7] = std::min(elecDeltaPinPoutOverPin, 1.f); + Var_woGwGSF_Endcap_[8] = std::min(elecEecalOverPout, 20.f); Var_woGwGSF_Endcap_[9] = elecVars.deltaEta; Var_woGwGSF_Endcap_[10] = elecVars.deltaPhi; - Var_woGwGSF_Endcap_[11] = std::min(elecVars.mvaInSigmaEtaEta, float(0.01)); - Var_woGwGSF_Endcap_[12] = std::min(elecVars.mvaInHadEnergy, float(20.)); - Var_woGwGSF_Endcap_[13] = std::min(elecVars.mvaInDeltaEta, float(0.1)); + Var_woGwGSF_Endcap_[11] = std::min(elecVars.mvaInSigmaEtaEta, 0.01f); + Var_woGwGSF_Endcap_[12] = std::min(elecVars.mvaInHadEnergy, 20.f); + Var_woGwGSF_Endcap_[13] = std::min(elecVars.mvaInDeltaEta, 0.1f); Var_woGwGSF_Endcap_[14] = tauVars.etaAtEcalEntrance; Var_woGwGSF_Endcap_[15] = tauVars.leadChargedPFCandEtaAtEcalEntrance; - Var_woGwGSF_Endcap_[16] = std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); - Var_woGwGSF_Endcap_[17] = std::log(std::max(float(1.), tauVars.pt)); + Var_woGwGSF_Endcap_[16] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt)); + Var_woGwGSF_Endcap_[17] = std::log(std::max(1.f, tauVars.pt)); Var_woGwGSF_Endcap_[18] = tauVars.emFraction; Var_woGwGSF_Endcap_[19] = tauVars.leadPFChargedHadrHoP; Var_woGwGSF_Endcap_[20] = tauVars.leadPFChargedHadrEoP; @@ -346,24 +342,24 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar } } else if (tauGammaMoms.signalPFGammaCandsIn > 0 && tauVars.hasGsf > 0.5) { if (std::abs(tauVars.etaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { - Var_wGwGSF_Barrel_[0] = std::max(float(-0.1), elecVars.eTotOverPin); - Var_wGwGSF_Barrel_[1] = std::log(std::max(float(0.01), elecVars.chi2NormGSF)); + Var_wGwGSF_Barrel_[0] = std::max(-0.1f, elecVars.eTotOverPin); + Var_wGwGSF_Barrel_[1] = std::log(std::max(0.01f, elecVars.chi2NormGSF)); Var_wGwGSF_Barrel_[2] = elecVars.gsfNumHits; - Var_wGwGSF_Barrel_[3] = std::log(std::max(float(0.01), elecVars.gsfTrackResol)); + Var_wGwGSF_Barrel_[3] = std::log(std::max(0.01f, elecVars.gsfTrackResol)); Var_wGwGSF_Barrel_[4] = elecVars.gsfTracklnPt; Var_wGwGSF_Barrel_[5] = elecNumHitsDiffOverSum; - Var_wGwGSF_Barrel_[6] = std::log(std::max(float(0.01), elecVars.chi2NormKF)); - Var_wGwGSF_Barrel_[7] = std::min(elecDeltaPinPoutOverPin, float(1.)); - Var_wGwGSF_Barrel_[8] = std::min(elecEecalOverPout, float(20.)); + Var_wGwGSF_Barrel_[6] = std::log(std::max(0.01f, elecVars.chi2NormKF)); + Var_wGwGSF_Barrel_[7] = std::min(elecDeltaPinPoutOverPin, 1.f); + Var_wGwGSF_Barrel_[8] = std::min(elecEecalOverPout, 20.f); Var_wGwGSF_Barrel_[9] = elecVars.deltaEta; Var_wGwGSF_Barrel_[10] = elecVars.deltaPhi; - Var_wGwGSF_Barrel_[11] = std::min(elecVars.mvaInSigmaEtaEta, float(0.01)); - Var_wGwGSF_Barrel_[12] = std::min(elecVars.mvaInHadEnergy, float(20.)); - Var_wGwGSF_Barrel_[13] = std::min(elecVars.mvaInDeltaEta, float(0.1)); + Var_wGwGSF_Barrel_[11] = std::min(elecVars.mvaInSigmaEtaEta, 0.01f); + Var_wGwGSF_Barrel_[12] = std::min(elecVars.mvaInHadEnergy, 20.f); + Var_wGwGSF_Barrel_[13] = std::min(elecVars.mvaInDeltaEta, 0.1f); Var_wGwGSF_Barrel_[14] = tauVars.etaAtEcalEntrance; Var_wGwGSF_Barrel_[15] = tauVars.leadChargedPFCandEtaAtEcalEntrance; - Var_wGwGSF_Barrel_[16] = std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); - Var_wGwGSF_Barrel_[17] = std::log(std::max(float(1.), tauVars.pt)); + Var_wGwGSF_Barrel_[16] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt)); + Var_wGwGSF_Barrel_[17] = std::log(std::max(1.f, tauVars.pt)); Var_wGwGSF_Barrel_[18] = tauVars.emFraction; Var_wGwGSF_Barrel_[19] = tauGammaMoms.signalPFGammaCandsIn; Var_wGwGSF_Barrel_[20] = tauGammaMoms.signalPFGammaCandsOut; @@ -380,24 +376,24 @@ double AntiElectronIDMVA6::MVAValue(const TauVars& tauVar Var_wGwGSF_Barrel_[31] = tauVars.dCrackPhi; mvaValue = mva_wGwGSF_BL_->GetClassifier(Var_wGwGSF_Barrel_); } else { - Var_wGwGSF_Endcap_[0] = std::max(float(-0.1), elecVars.eTotOverPin); - Var_wGwGSF_Endcap_[1] = std::log(std::max(float(0.01), elecVars.chi2NormGSF)); + Var_wGwGSF_Endcap_[0] = std::max(-0.1f, elecVars.eTotOverPin); + Var_wGwGSF_Endcap_[1] = std::log(std::max(0.01f, elecVars.chi2NormGSF)); Var_wGwGSF_Endcap_[2] = elecVars.gsfNumHits; - Var_wGwGSF_Endcap_[3] = std::log(std::max(float(0.01), elecVars.gsfTrackResol)); + Var_wGwGSF_Endcap_[3] = std::log(std::max(0.01f, elecVars.gsfTrackResol)); Var_wGwGSF_Endcap_[4] = elecVars.gsfTracklnPt; Var_wGwGSF_Endcap_[5] = elecNumHitsDiffOverSum; - Var_wGwGSF_Endcap_[6] = std::log(std::max(float(0.01), elecVars.chi2NormKF)); - Var_wGwGSF_Endcap_[7] = std::min(elecDeltaPinPoutOverPin, float(1.)); - Var_wGwGSF_Endcap_[8] = std::min(elecEecalOverPout, float(20.)); + Var_wGwGSF_Endcap_[6] = std::log(std::max(0.01f, elecVars.chi2NormKF)); + Var_wGwGSF_Endcap_[7] = std::min(elecDeltaPinPoutOverPin, 1.f); + Var_wGwGSF_Endcap_[8] = std::min(elecEecalOverPout, 20.f); Var_wGwGSF_Endcap_[9] = elecVars.deltaEta; Var_wGwGSF_Endcap_[10] = elecVars.deltaPhi; - Var_wGwGSF_Endcap_[11] = std::min(elecVars.mvaInSigmaEtaEta, float(0.01)); - Var_wGwGSF_Endcap_[12] = std::min(elecVars.mvaInHadEnergy, float(20.)); - Var_wGwGSF_Endcap_[13] = std::min(elecVars.mvaInDeltaEta, float(0.1)); + Var_wGwGSF_Endcap_[11] = std::min(elecVars.mvaInSigmaEtaEta, 0.01f); + Var_wGwGSF_Endcap_[12] = std::min(elecVars.mvaInHadEnergy, 20.f); + Var_wGwGSF_Endcap_[13] = std::min(elecVars.mvaInDeltaEta, 0.1f); Var_wGwGSF_Endcap_[14] = tauVars.etaAtEcalEntrance; Var_wGwGSF_Endcap_[15] = tauVars.leadChargedPFCandEtaAtEcalEntrance; - Var_wGwGSF_Endcap_[16] = std::min(float(2.), tauVars.leadChargedPFCandPt / std::max(float(1.), tauVars.pt)); - Var_wGwGSF_Endcap_[17] = std::log(std::max(float(1.), tauVars.pt)); + Var_wGwGSF_Endcap_[16] = std::min(2.f, tauVars.leadChargedPFCandPt / std::max(1.f, tauVars.pt)); + Var_wGwGSF_Endcap_[17] = std::log(std::max(1.f, tauVars.pt)); Var_wGwGSF_Endcap_[18] = tauVars.emFraction; Var_wGwGSF_Endcap_[19] = tauGammaMoms.signalPFGammaCandsIn; Var_wGwGSF_Endcap_[20] = tauGammaMoms.signalPFGammaCandsOut;