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/interface/AntiElectronIDMVA6.h b/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h index 0a6473d62d6ad..16b3cf07d6382 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,61 @@ #include +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 { public: AntiElectronIDMVA6(const edm::ParameterSet&); @@ -39,91 +95,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 antiElecIDMVA6_blocks::TauVars& tauVars, + const antiElecIDMVA6_blocks::TauGammaVecs& tauGammaVecs, + const antiElecIDMVA6_blocks::ElecVars& elecVars); - // 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 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 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 + 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); @@ -147,14 +138,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/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/plugins/TauDiscriminationAgainstElectronMVA6.cc b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronMVA6.cc new file mode 100644 index 0000000000000..b5583fd036b3e --- /dev/null +++ b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronMVA6.cc @@ -0,0 +1,314 @@ +/* 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; + 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()); + // pfGammas inside the tau signal cone + if (dR < signalrad) { + numSignalGammaCandsInSigCone += 1; + } + } + + bool hasGsfTrack = false; + const reco::CandidatePtr& leadChCand = theTauRef->leadChargedHadrCand(); + if (leadChCand.isNonnull()) { + const pat::PackedCandidate* packedLeadChCand = dynamic_cast(leadChCand.get()); + if (packedLeadChCand != nullptr) { + hasGsfTrack = (std::abs(packedLeadChCand->pdgId()) == 11); + } else { + const reco::PFCandidate* pfLeadChCand = dynamic_cast(leadChCand.get()); + hasGsfTrack = (pfLeadChCand != nullptr && pfLeadChCand->gsfTrackRef().isNonnull()); + } + } + + // 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) { + double mva_nomatch = 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.; + } + } + + result.rawValues.at(0) = std::min(result.rawValues.at(0), float(mva_nomatch)); + } + } + + 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/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/src/AntiElectronIDMVA6.cc b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc index 547dc14e07090..cf79e4f3dcf12 100644 --- a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc +++ b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc @@ -11,11 +11,13 @@ #include "CondFormats/DataRecord/interface/GBRWrapperRcd.h" #include "FWCore/Framework/interface/ESHandle.h" -#include #include #include -AntiElectronIDMVA6::AntiElectronIDMVA6(const edm::ParameterSet& cfg) +using namespace antiElecIDMVA6_blocks; + +template +AntiElectronIDMVA6::AntiElectronIDMVA6(const edm::ParameterSet& cfg) : isInitialized_(false), mva_NoEleMatch_woGwoGSF_BL_(nullptr), mva_NoEleMatch_wGwoGSF_BL_(nullptr), @@ -45,19 +47,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 +104,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 +137,392 @@ 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 ElecVars& elecVars) { + 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.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]; + 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.gammaEnFracIn = -99.; + if (tauVars.pt > 0.) { + tauGammaMoms.gammaEnFracIn = sumPt / tauVars.pt; } 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.gammaEtaMomIn = std::sqrt(dEta2 * tauGammaMoms.gammaEnFracIn) * tauVars.pt; + tauGammaMoms.gammaPhiMomIn = std::sqrt(dPhi2 * tauGammaMoms.gammaEnFracIn) * tauVars.pt; 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.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]; + 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.gammaEnFracOut = -99.; + if (tauVars.pt > 0.) { + tauGammaMoms.gammaEnFracOut = sumPt / tauVars.pt; + } 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.gammaEtaMomOut = std::sqrt(dEta2 * tauGammaMoms.gammaEnFracOut) * tauVars.pt; + tauGammaMoms.gammaPhiMomOut = std::sqrt(dPhi2 * tauGammaMoms.gammaEnFracOut) * tauVars.pt; + + return MVAValue(tauVars, tauGammaMoms, elecVars); } -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 ElecVars& elecVars) { 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)) - : 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; + 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.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(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; + 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] = 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.etaAtEcalEntrance; + Var_NoEleMatch_woGwoGSF_Endcap_[1] = tauVars.leadChargedPFCandEtaAtEcalEntrance; + 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; + 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(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.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(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; + 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] = 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.etaAtEcalEntrance; + Var_NoEleMatch_wGwoGSF_Endcap_[1] = tauVars.leadChargedPFCandEtaAtEcalEntrance; + 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; + 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 (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.signalPFGammaCandsIn == 0 && tauVars.hasGsf > 0.5) { + if (std::abs(tauVars.etaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { + 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(0.01f, elecVars.gsfTrackResol)); + Var_woGwGSF_Barrel_[4] = elecVars.gsfTracklnPt; + Var_woGwGSF_Barrel_[5] = elecNumHitsDiffOverSum; + 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, 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(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; + 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), 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(-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(0.01f, elecVars.gsfTrackResol)); + Var_woGwGSF_Endcap_[4] = elecVars.gsfTracklnPt; + Var_woGwGSF_Endcap_[5] = elecNumHitsDiffOverSum; + 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, 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(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; + Var_woGwGSF_Endcap_[21] = tauVars.visMassIn; + Var_woGwGSF_Endcap_[22] = tauVars.dCrackEta; 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.signalPFGammaCandsIn > 0 && tauVars.hasGsf > 0.5) { + if (std::abs(tauVars.etaAtEcalEntrance) < ECALBarrelEndcapEtaBorder) { + 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(0.01f, elecVars.gsfTrackResol)); + Var_wGwGSF_Barrel_[4] = elecVars.gsfTracklnPt; + Var_wGwGSF_Barrel_[5] = elecNumHitsDiffOverSum; + 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, 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(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; + 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), 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(-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(0.01f, elecVars.gsfTrackResol)); + Var_wGwGSF_Endcap_[4] = elecVars.gsfTracklnPt; + Var_wGwGSF_Endcap_[5] = elecNumHitsDiffOverSum; + 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, 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(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; + 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_); } } 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(); + ElecVars elecVars = AntiElectronIDMVA6::getElecVars(theEle); - //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; - } - } + return MVAValue(tauVars, tauGammaVecs, elecVars); +} - 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; - } - } +template +double AntiElectronIDMVA6::MVAValue(const TauType& theTau) { + // === tau variables === + TauVars tauVars = AntiElectronIDMVA6::getTauVars(theTau); + TauGammaVecs tauGammaVecs = AntiElectronIDMVA6::getTauGammaVecs(theTau); - //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(); - } + // === electron variables === + ElecVars elecVars; + elecVars.eta = 9.9; // Dummy value used in MVA training - 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, elecVars); } -double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau) { - // === 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(); - } - } - } +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."; - 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(); - } + tauVars.pt = theTau.pt(); - 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()))); - + 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 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()))); - + 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(); - 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(); - } - sumPhiTimesEnergy += phi * signalCand->energy(); - sumEnergy += signalCand->energy(); + tauVars.hasGsf = 0; + if (theTau.leadChargedHadrCand().isNonnull()) { + const pat::PackedCandidate* packedLeadChCand = + 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()); + if (pfLeadChCand != nullptr && pfLeadChCand->gsfTrackRef().isNonnull()) + tauVars.hasGsf = 1; } } - 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.dCrackPhi = dCrackPhi(tauVars.phi, tauVars.etaAtEcalEntrance); + tauVars.dCrackEta = dCrackEta(tauVars.etaAtEcalEntrance); - // === 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(); - - 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); +template +TauGammaVecs AntiElectronIDMVA6::getTauGammaVecs(const TauType& theTau) { + TauGammaVecs tauGammaVecs; - const reco::CandidatePtrVector signalGammaCands = theTau.signalGammaCands(); - for (const auto& gamma : signalGammaCands) { + 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()); - 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()); + tauGammaVecs.gammasdEtaOutSigCone.push_back(gamma->eta() - theTau.leadChargedHadrCand()->eta()); + tauGammaVecs.gammasdPhiOutSigCone.push_back(gamma->phi() - theTau.leadChargedHadrCand()->phi()); + tauGammaVecs.gammasPtOutSigCone.push_back(gamma->pt()); } } + return tauGammaVecs; +} - 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; - } - } 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()); - if (abs(packedLeadTauCand->pdgId()) == 11) - TauHasGsf = 1; +template +ElecVars AntiElectronIDMVA6::getElecVars(const ElectronType& theEle) { + ElecVars elecVars; - // === electron variables === - Float_t ElecEta = theEle.eta(); - Float_t ElecPhi = theEle.phi(); + elecVars.eta = theEle.eta(); + elecVars.phi = 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 +530,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.; + 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 + elecVars.chi2NormGSF = -99.; + elecVars.gsfNumHits = -99.; + elecVars.gsfTrackResol = -99.; + elecVars.gsfTracklnPt = -99.; if (theEle.gsfTrack().isNonnull()) { - ElecChi2NormGSF = (theEle).gsfTrack()->normalizedChi2(); - ElecGSFNumHits = (theEle).gsfTrack()->numberOfValidHits(); + elecVars.chi2NormGSF = theEle.gsfTrack()->normalizedChi2(); + elecVars.gsfNumHits = theEle.gsfTrack()->numberOfValidHits(); if (theEle.gsfTrack()->pt() > 0.) { - ElecGSFTrackResol = theEle.gsfTrack()->ptError() / theEle.gsfTrack()->pt(); - 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 - Float_t ElecChi2NormKF = -99.; - Float_t ElecKFNumHits = -99.; + // Variables related to the CtfTrack + elecVars.chi2NormKF = -99.; + elecVars.kfNumHits = -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(); - } + elecVars.chi2NormKF = theEle.closestCtfTrackRef()->normalizedChi2(); + elecVars.kfNumHits = 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 elecVars; } -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 +597,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 +648,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 +666,133 @@ double AntiElectronIDMVA6::dCrackEta(double eta) { return std::abs(retVal); } + +// pat::Tau +template +TauVars AntiElectronIDMVA6::getTauVarsTypeSpecific(const pat::Tau& theTau) { + TauVars tauVars; + tauVars.etaAtEcalEntrance = theTau.etaAtEcalEntrance(); + tauVars.leadChargedPFCandEtaAtEcalEntrance = theTau.etaAtEcalEntranceLeadChargedCand(); + tauVars.leadChargedPFCandPt = theTau.ptLeadChargedCand(); + tauVars.phi = theTau.phi(); + if (!usePhiAtEcalEntranceExtrapolation_) { + tauVars.phi = 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.phi = sumPhiTimesEnergy / sumEnergy; + } + } + tauVars.emFraction = std::max(theTau.emFraction_MVA(), (float)0.); + tauVars.leadPFChargedHadrHoP = 0.; + tauVars.leadPFChargedHadrEoP = 0.; + if (theTau.leadChargedHadrCand()->p() > 0.) { + tauVars.leadPFChargedHadrHoP = theTau.hcalEnergyLeadChargedHadrCand() / theTau.leadChargedHadrCand()->p(); + tauVars.leadPFChargedHadrEoP = theTau.ecalEnergyLeadChargedHadrCand() / theTau.leadChargedHadrCand()->p(); + } + + return tauVars; +} + +// reco::PFTau +template +TauVars AntiElectronIDMVA6::getTauVarsTypeSpecific(const reco::PFTau& theTau) { + TauVars tauVars; + tauVars.etaAtEcalEntrance = -99.; + tauVars.leadChargedPFCandEtaAtEcalEntrance = -99.; + tauVars.leadChargedPFCandPt = -99.; + float sumEtaTimesEnergy = 0.; + 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); + 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.leadChargedPFCandPt) { + tauVars.leadChargedPFCandEtaAtEcalEntrance = etaAtECalEntrance; + tauVars.leadChargedPFCandPt = track->pt(); + } + } + sumEtaTimesEnergy += etaAtECalEntrance * candidate->energy(); + sumPhiTimesEnergy += phiAtECalEntrance * candidate->energy(); + sumEnergy += candidate->energy(); + } + if (sumEnergy > 0.) { + tauVars.etaAtEcalEntrance = sumEtaTimesEnergy / sumEnergy; + tauVars.phi = sumPhiTimesEnergy / sumEnergy; + } + + 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.leadPFChargedHadrHoP = pfLeadCandiate->hcalEnergy() / pfLeadCandiate->p(); + tauVars.leadPFChargedHadrEoP = pfLeadCandiate->ecalEnergy() / pfLeadCandiate->p(); + } else { + const pat::PackedCandidate* patLeadCandiate = + 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(); + } + } + } + + return tauVars; +} + +// compile desired types and make available to linker +template class AntiElectronIDMVA6; +template class AntiElectronIDMVA6; 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) )