diff --git a/RecoTauTag/RecoTau/interface/PFRecoTauClusterVariables.h b/RecoTauTag/RecoTau/interface/PFRecoTauClusterVariables.h index bef833e3238f6..000110a50ff49 100644 --- a/RecoTauTag/RecoTau/interface/PFRecoTauClusterVariables.h +++ b/RecoTauTag/RecoTau/interface/PFRecoTauClusterVariables.h @@ -16,6 +16,42 @@ #include "DataFormats/PatCandidates/interface/Tau.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +namespace { + template + PhotonVectorType getGammas(const TauType& tau, bool signal); + + /// return pf photon candidates that are associated to signal + template<> + const std::vector& getGammas&>(const reco::PFTau& tau, bool signal) { + if (signal){ + return tau.signalPFGammaCands(); + } + return tau.isolationPFGammaCands(); + } + + template<> + reco::CandidatePtrVector getGammas(const pat::Tau& tau, bool signal) { + if(signal){ + return tau.signalGammaCands(); + } + return tau.isolationGammaCands(); + } + + /// decide if photon candidate is inside the cone to be associated to the tau signal + bool isInside(float photon_pt, float deta, float dphi) { + constexpr double stripEtaAssociationDistance_0p95_p0 = 0.197077; + constexpr double stripEtaAssociationDistance_0p95_p1 = 0.658701; + constexpr double stripPhiAssociationDistance_0p95_p0 = 0.352476; + constexpr double stripPhiAssociationDistance_0p95_p1 = 0.707716; + if(photon_pt==0){ + return false; + } if((dphi<0.3 && dphi deprecated? <== float lead_track_chi2(const reco::PFTau& tau); @@ -24,39 +60,82 @@ namespace reco { namespace tau { float eratio(const pat::Tau& tau); /// return sum of pt weighted values of distance to tau candidate for all pf photon candidates, /// which are associated to signal; depending on var the distance is in 0=:dr, 1=:deta, 2=:dphi - float pt_weighted_dx(const reco::PFTau& tau, int mode = 0, int var = 0, int decaymode = -1); - float pt_weighted_dx(const pat::Tau& tau, int mode = 0, int var = 0, int decaymode = -1); + template + float pt_weighted_dx(const TauType& tau, int mode = 0, int var = 0, int decaymode = -1) { + float sum_pt = 0.; + float sum_dx_pt = 0.; + float signalrad = std::max(0.05, std::min(0.1, 3./std::max(1., tau.pt()))); + int is3prong = (decaymode==10); + const auto& cands = getGammas(tau, mode < 2); + for (const auto& cand : cands) { + // only look at electrons/photons with pT > 0.5 + if (cand->pt() < 0.5){ + continue; + } + float dr = reco::deltaR(cand->eta(), cand->phi(), tau.eta(), tau.phi()); + float deta = std::abs(cand->eta() - tau.eta()); + float dphi = std::abs(reco::deltaPhi(cand->phi(), tau.phi())); + float pt = cand->pt(); + bool flag = isInside(pt, deta, dphi); + if(is3prong==0){ + if (mode == 2 || (mode == 0 && dr < signalrad) || (mode == 1 && dr > signalrad)) { + sum_pt += pt; + if (var == 0) + sum_dx_pt += pt * dr; + else if (var == 1) + sum_dx_pt += pt * deta; + else if (var == 2) + sum_dx_pt += pt * dphi; + } + } + else if(is3prong==1){ + if( (mode==2 && flag==false) || (mode==1 && flag==true) || mode==0){ + sum_pt += pt; + if (var == 0) + sum_dx_pt += pt * dr; + else if (var == 1) + sum_dx_pt += pt * deta; + else if (var == 2) + sum_dx_pt += pt * dphi; + } + } + } + if (sum_pt > 0.){ + return sum_dx_pt/sum_pt; + } + return 0.; + } /// return sum of pt weighted values of dr relative to tau candidate for all pf photon candidates, /// which are associated to signal inline float pt_weighted_dr_signal(const reco::PFTau& tau, int dm) { - return pt_weighted_dx(tau, 0, 0, dm); + return pt_weighted_dx&>(tau, 0, 0, dm); } inline float pt_weighted_dr_signal(const pat::Tau& tau, int dm) { - return pt_weighted_dx(tau, 0, 0, dm); + return pt_weighted_dx(tau, 0, 0, dm); } /// return sum of pt weighted values of deta relative to tau candidate for all pf photon candidates, /// which are associated to signal inline float pt_weighted_deta_strip(const reco::PFTau& tau, int dm) { - return pt_weighted_dx(tau, dm==10 ? 2 : 1, 1, dm); + return pt_weighted_dx&>(tau, dm==10 ? 2 : 1, 1, dm); } inline float pt_weighted_deta_strip(const pat::Tau& tau, int dm) { - return pt_weighted_dx(tau, dm==10 ? 2 : 1, 1, dm); + return pt_weighted_dx(tau, dm==10 ? 2 : 1, 1, dm); } /// return sum of pt weighted values of dphi relative to tau candidate for all pf photon candidates, /// which are associated to signal inline float pt_weighted_dphi_strip(const reco::PFTau& tau, int dm) { - return pt_weighted_dx(tau, dm==10 ? 2 : 1, 2, dm); + return pt_weighted_dx&>(tau, dm==10 ? 2 : 1, 2, dm); } inline float pt_weighted_dphi_strip(const pat::Tau& tau, int dm) { - return pt_weighted_dx(tau, dm==10 ? 2 : 1, 2, dm); + return pt_weighted_dx(tau, dm==10 ? 2 : 1, 2, dm); } /// return sum of pt weighted values of dr relative to tau candidate for all pf photon candidates, /// which are inside an isolation conde but not associated to signal inline float pt_weighted_dr_iso(const reco::PFTau& tau, int dm) { - return pt_weighted_dx(tau, 2, 0, dm); + return pt_weighted_dx&>(tau, 2, 0, dm); } inline float pt_weighted_dr_iso(const pat::Tau& tau, int dm) { - return pt_weighted_dx(tau, 2, 0, dm); + return pt_weighted_dx(tau, 2, 0, dm); } /// return sum of pt weighted values of dr relative to tau candidate for all pf photon candidates, /// which are inside an isolation conde but not associated to signal diff --git a/RecoTauTag/RecoTau/src/PFRecoTauClusterVariables.cc b/RecoTauTag/RecoTau/src/PFRecoTauClusterVariables.cc index 2e4d663c06994..bd59ee361925a 100644 --- a/RecoTauTag/RecoTau/src/PFRecoTauClusterVariables.cc +++ b/RecoTauTag/RecoTau/src/PFRecoTauClusterVariables.cc @@ -1,35 +1,5 @@ #include "RecoTauTag/RecoTau/interface/PFRecoTauClusterVariables.h" -namespace { - - /// return pf photon candidates that are associated to signal - const std::vector& getPFGammas(const reco::PFTau& tau, bool signal) { - if (signal){ - return tau.signalPFGammaCands(); - } - return tau.isolationPFGammaCands(); - } - reco::CandidatePtrVector getGammas(const pat::Tau& tau, bool signal) { - if(signal){ - return tau.signalGammaCands(); - } - return tau.isolationGammaCands(); - } - /// decide if photon candidate is inside the cone to be associated to the tau signal - bool isInside(float photon_pt, float deta, float dphi) { - constexpr double stripEtaAssociationDistance_0p95_p0 = 0.197077; - constexpr double stripEtaAssociationDistance_0p95_p1 = 0.658701; - constexpr double stripPhiAssociationDistance_0p95_p0 = 0.352476; - constexpr double stripPhiAssociationDistance_0p95_p1 = 0.707716; - if(photon_pt==0){ - return false; - } if((dphi<0.3 && dphi deprecated? <== float lead_track_chi2(const reco::PFTau& tau) { @@ -66,96 +36,6 @@ namespace reco { namespace tau { } return ecal_en_in_signal_cands/total; } - /// return sum of pt weighted values of distance to tau candidate for all pf photon candidates, - /// which are associated to signal; depending on var the distance is in 0=:dr, 1=:deta, 2=:dphi - float pt_weighted_dx(const reco::PFTau& tau, int mode, int var, int decaymode) { - float sum_pt = 0.; - float sum_dx_pt = 0.; - float signalrad = std::max(0.05, std::min(0.1, 3./std::max(1., tau.pt()))); - int is3prong = (decaymode==10); - const auto& cands = getPFGammas(tau, mode < 2); - for (const auto& cand : cands) { - // only look at electrons/photons with pT > 0.5 - if ((float)cand->pt() < 0.5){ - continue; - } - float dr = reco::deltaR((float)cand->eta(),(float)cand->phi(),(float)tau.eta(),(float)tau.phi()); - float deta = std::abs((float)cand->eta() - (float)tau.eta()); - float dphi = std::abs(reco::deltaPhi((float)cand->phi(), (float)tau.phi())); - float pt = cand->pt(); - bool flag = isInside(pt, deta, dphi); - if(is3prong==0){ - if (mode == 2 || (mode == 0 && dr < signalrad) || (mode == 1 && dr > signalrad)) { - sum_pt += pt; - if (var == 0) - sum_dx_pt += pt * dr; - else if (var == 1) - sum_dx_pt += pt * deta; - else if (var == 2) - sum_dx_pt += pt * dphi; - } - } - else if(is3prong==1){ - if( (mode==2 && flag==false) || (mode==1 && flag==true) || mode==0){ - sum_pt += pt; - if (var == 0) - sum_dx_pt += pt * dr; - else if (var == 1) - sum_dx_pt += pt * deta; - else if (var == 2) - sum_dx_pt += pt * dphi; - } - } - } - if (sum_pt > 0.){ - return sum_dx_pt/sum_pt; - } - return 0.; - } - float pt_weighted_dx(const pat::Tau& tau, int mode, int var, int decaymode) { - float sum_pt = 0.; - float sum_dx_pt = 0.; - float signalrad = std::max(0.05, std::min(0.1, 3./std::max(1., tau.pt()))); - int is3prong = (decaymode==10); - const auto cands = getGammas(tau, mode < 2); - for (const auto& cand : cands) { - // only look at electrons/photons with pT > 0.5 - if (cand->pt() < 0.5){ - continue; - } - float dr = reco::deltaR(*cand, tau); - float deta = std::abs(cand->eta() - tau.eta()); - float dphi = std::abs(reco::deltaPhi(cand->phi(), tau.phi())); - float pt = cand->pt(); - bool flag = isInside(pt, deta, dphi); - if(is3prong==0){ - if (mode == 2 || (mode == 0 && dr < signalrad) || (mode == 1 && dr > signalrad)) { - sum_pt += pt; - if (var == 0) - sum_dx_pt += pt * dr; - else if (var == 1) - sum_dx_pt += pt * deta; - else if (var == 2) - sum_dx_pt += pt * dphi; - } - } - else if(is3prong==1){ - if( (mode==2 && flag==false) || (mode==1 && flag==true) || mode==0){ - sum_pt += pt; - if (var == 0) - sum_dx_pt += pt * dr; - else if (var == 1) - sum_dx_pt += pt * deta; - else if (var == 2) - sum_dx_pt += pt * dphi; - } - } - } - if (sum_pt > 0.){ - return sum_dx_pt/sum_pt; - } - return 0.; - } /// return total number of pf photon candidates with pT>500 MeV, which are associated to signal unsigned int n_photons_total(const reco::PFTau& tau) { unsigned int n_photons = 0;