diff --git a/DataFormats/TauReco/interface/PFTau.h b/DataFormats/TauReco/interface/PFTau.h index 32803d600c92a..65f0f8fb2f902 100644 --- a/DataFormats/TauReco/interface/PFTau.h +++ b/DataFormats/TauReco/interface/PFTau.h @@ -276,7 +276,11 @@ class PFTau : public BaseTau { std::vector selectedIsolationNeutrHadrCands_; std::vector selectedIsolationGammaCands_; - // Caches for PFCandidate-based accessors + // Transient caches for PFCandidate-based accessors + edm::AtomicPtrCache leadPFChargedHadrCand_; + edm::AtomicPtrCache leadPFNeutralCand_; + edm::AtomicPtrCache leadPFCand_; + edm::AtomicPtrCache > selectedTransientSignalPFCands_; edm::AtomicPtrCache > selectedTransientSignalPFChargedHadrCands_; edm::AtomicPtrCache > selectedTransientSignalPFNeutrHadrCands_; diff --git a/DataFormats/TauReco/src/PFTau.cc b/DataFormats/TauReco/src/PFTau.cc index e865af739e8c1..05e2e0fd60fa9 100644 --- a/DataFormats/TauReco/src/PFTau.cc +++ b/DataFormats/TauReco/src/PFTau.cc @@ -122,12 +122,14 @@ namespace { oCache.set( std::make_unique(std::move(iFrom))); } - reco::PFCandidatePtr convertToPFPtr(const reco::CandidatePtr& ptr) { - const reco::PFCandidate* pf_cand = dynamic_cast(&*ptr); - if (pf_cand != nullptr) { - return edm::Ptr(ptr); - } else throw cms::Exception("Type Mismatch") << "This PFTau was not made from PFCandidates, but it is being tried to access a PFCandidate.\n"; - return reco::PFCandidatePtr(); + std::unique_ptr convertToPFPtr(const reco::CandidatePtr& ptr) { + if (ptr.isNonnull()) { + const reco::PFCandidate* pf_cand = dynamic_cast(&*ptr); + if (pf_cand != nullptr) { + return std::unique_ptr(new reco::PFCandidatePtr(ptr)); + } else throw cms::Exception("Type Mismatch") << "This PFTau was not made from PFCandidates, but it is being tried to access a PFCandidate.\n"; + } + return std::unique_ptr(new reco::PFCandidatePtr()); } std::unique_ptr > convertToPFPtrs(const std::vector& cands) { @@ -150,21 +152,21 @@ namespace { } const PFCandidatePtr PFTau::leadPFChargedHadrCand() const { - if (leadChargedHadrCand_.isNonnull()) - return convertToPFPtr(leadChargedHadrCand_); - return PFCandidatePtr(); + if (!leadPFChargedHadrCand_.isSet()) + leadPFChargedHadrCand_.set(std::move(convertToPFPtr(leadChargedHadrCand_))); + return *leadPFChargedHadrCand_; } const PFCandidatePtr PFTau::leadPFNeutralCand() const { - if (leadNeutralCand_.isNonnull()) - return convertToPFPtr(leadNeutralCand_); - return PFCandidatePtr(); + if (!leadPFNeutralCand_.isSet()) + leadPFNeutralCand_.set(std::move(convertToPFPtr(leadNeutralCand_))); + return *leadPFNeutralCand_; } const PFCandidatePtr PFTau::leadPFCand() const { - if (leadCand_.isNonnull()) - return convertToPFPtr(leadCand_); - return PFCandidatePtr(); + if (!leadPFCand_.isSet()) + leadPFCand_.set(std::move(convertToPFPtr(leadCand_))); + return *leadPFCand_; } const std::vector& PFTau::signalPFCands() const { diff --git a/DataFormats/TauReco/src/classes_def_2.xml b/DataFormats/TauReco/src/classes_def_2.xml index f4c4c946db843..41e06684bc960 100644 --- a/DataFormats/TauReco/src/classes_def_2.xml +++ b/DataFormats/TauReco/src/classes_def_2.xml @@ -2,6 +2,9 @@ + + + diff --git a/RecoTauTag/Configuration/python/tools/adaptToRunAtMiniAOD.py b/RecoTauTag/Configuration/python/tools/adaptToRunAtMiniAOD.py index 53aa247a9447c..ef9bbde729194 100644 --- a/RecoTauTag/Configuration/python/tools/adaptToRunAtMiniAOD.py +++ b/RecoTauTag/Configuration/python/tools/adaptToRunAtMiniAOD.py @@ -153,7 +153,7 @@ def adaptTauToMiniAODReReco(process, reclusterJets=True): process.miniAODTausTask.remove(getattr(process, moduleName)) # Instead add against-mu discriminants which are MiniAOD compatible - from RecoTauTag.RecoTau.PFRecoTauDiscriminationAgainstMuonSimple_cfi import hpsPFTauDiscriminationByLooseMuonRejectionSimple, hpsPFTauDiscriminationByTightMuonRejectionSimple + from RecoTauTag.RecoTau.hpsPFTauDiscriminationByAMuonRejectionSimple_cff import hpsPFTauDiscriminationByLooseMuonRejectionSimple, hpsPFTauDiscriminationByTightMuonRejectionSimple process.hpsPFTauDiscriminationByLooseMuonRejectionSimple = hpsPFTauDiscriminationByLooseMuonRejectionSimple process.hpsPFTauDiscriminationByTightMuonRejectionSimple = hpsPFTauDiscriminationByTightMuonRejectionSimple diff --git a/RecoTauTag/HLTProducers/src/HLTPFTauPairLeadTrackDzMatchFilter.cc b/RecoTauTag/HLTProducers/src/HLTPFTauPairLeadTrackDzMatchFilter.cc index b3b3a8fe81bf9..9b748f28200ed 100644 --- a/RecoTauTag/HLTProducers/src/HLTPFTauPairLeadTrackDzMatchFilter.cc +++ b/RecoTauTag/HLTProducers/src/HLTPFTauPairLeadTrackDzMatchFilter.cc @@ -111,4 +111,4 @@ bool HLTPFTauPairLeadTrackDzMatchFilter::hltFilter(edm::Event& ev, const edm::Ev // return truth if at least one good pair found return npairs>0; -} \ No newline at end of file +} diff --git a/RecoTauTag/RecoTau/interface/AntiElectronIDCut2.h b/RecoTauTag/RecoTau/interface/AntiElectronIDCut2.h index dccf7ff8a63fc..5a48cbbd0e72b 100644 --- a/RecoTauTag/RecoTau/interface/AntiElectronIDCut2.h +++ b/RecoTauTag/RecoTau/interface/AntiElectronIDCut2.h @@ -179,4 +179,4 @@ class AntiElectronIDCut2 int verbosity_; }; -#endif \ No newline at end of file +#endif diff --git a/RecoTauTag/RecoTau/interface/PFRecoTauClusterVariables.h b/RecoTauTag/RecoTau/interface/PFRecoTauClusterVariables.h index 916189002f909..a0286df1abd62 100644 --- a/RecoTauTag/RecoTau/interface/PFRecoTauClusterVariables.h +++ b/RecoTauTag/RecoTau/interface/PFRecoTauClusterVariables.h @@ -25,8 +25,8 @@ class TauIdMVAAuxiliaries { float LeadingTracknormalizedChi2 = 0; const reco::CandidatePtr& leadingPFCharged = tau.leadChargedHadrCand(); if (leadingPFCharged.isNonnull()) { - const reco::PFCandidate* pfcand = dynamic_cast(leadingPFCharged.get()); - if (pfcand != nullptr) { + const reco::PFCandidate* pfcand = dynamic_cast(leadingPFCharged.get()); + if (pfcand != nullptr) { reco::TrackRef tref = pfcand->trackRef(); if (tref.isNonnull()) { LeadingTracknormalizedChi2 = tref->normalizedChi2(); diff --git a/RecoTauTag/RecoTau/interface/RecoTauConstructor.h b/RecoTauTag/RecoTau/interface/RecoTauConstructor.h index e03a9bd228929..87319ad1f56f5 100644 --- a/RecoTauTag/RecoTau/interface/RecoTauConstructor.h +++ b/RecoTauTag/RecoTau/interface/RecoTauConstructor.h @@ -81,7 +81,6 @@ class RecoTauConstructor { } /// Append a PFCandidateRef/Ptr to a given collection - // void addPFCand(Region region, ParticleType type, const CandidateRef& ref, bool skipAddToP4 = false); void addPFCand(Region region, ParticleType type, const CandidatePtr& ptr, bool skipAddToP4 = false); /// Reserve a set amount of space for a given RefVector @@ -154,7 +153,6 @@ class RecoTauConstructor { // Helper functions for dealing with refs CandidatePtr convertToPtr(const PFCandidatePtr& pfPtr) const; CandidatePtr convertToPtr(const CandidatePtr& candPtr) const; - // CandidatePtr convertToPtr(const PFCandidateRef& pfRef) const; const edm::Handle >& pfCands_; std::auto_ptr tau_; diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromTrackPlugin.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromGenericTrackPlugin.cc similarity index 96% rename from RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromTrackPlugin.cc rename to RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromGenericTrackPlugin.cc index 20c3c6d2cfec5..000ac0440301c 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromTrackPlugin.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromGenericTrackPlugin.cc @@ -2,12 +2,15 @@ * PFRecoTauChargedHadronFromGenericTrackPlugin * * Build PFRecoTauChargedHadron objects - * using charged PFCandidates as input + * using tracks as input, from either collection of RECO/AOD reco::Tracks + * (PFRecoTauChargedHadronFromTrackPlugin) or from a collection of MINIAOD + * pat::PackedCandidates (PFRecoTauChargedHadronFromLostTrackPlugin), typically + * using the 'lostTracks' collection * * Author: Christian Veelken, LLR * - * inclusion of lost tracks based on - * PFRecoTauChargedHadronFromLostTrackPlugin by Michal Bluj, NCBJ, Poland + * inclusion of lost tracks based on original implementation + * by Michal Bluj, NCBJ, Poland */ #include "RecoTauTag/RecoTau/interface/PFRecoTauChargedHadronPlugins.h" @@ -281,8 +284,7 @@ typename PFRecoTauChargedHadronFromGenericTrackPlugin::return_type P } std::vector neutralJetConstituents_withDistance; - std::vector jetConstituents = jet.daughterPtrVector(); - for ( const auto& jetConstituent : jetConstituents ) { + for ( const auto& jetConstituent : jet.daughterPtrVector() ) { int pdgId = jetConstituent->pdgId(); if ( !(pdgId == 130 || pdgId == 22) ) continue; double dR = deltaR(atECALEntrance(&*jetConstituent, magneticFieldStrength_.z()), chargedHadron->positionAtECALEntrance_); @@ -327,9 +329,7 @@ typename PFRecoTauChargedHadronFromGenericTrackPlugin::return_type P return output.release(); } -template class PFRecoTauChargedHadronFromGenericTrackPlugin; typedef PFRecoTauChargedHadronFromGenericTrackPlugin PFRecoTauChargedHadronFromTrackPlugin; -template class PFRecoTauChargedHadronFromGenericTrackPlugin; typedef PFRecoTauChargedHadronFromGenericTrackPlugin PFRecoTauChargedHadronFromLostTrackPlugin; }} // end namespace reco::tau diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromPFCandidatePlugin.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromPFCandidatePlugin.cc index 5fe4b667b680d..7c95023e2e20f 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromPFCandidatePlugin.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromPFCandidatePlugin.cc @@ -199,22 +199,17 @@ PFRecoTauChargedHadronFromPFCandidatePlugin::return_type PFRecoTauChargedHadronF chargedHadron->chargedPFCandidate_ = (*cand); chargedHadron->addDaughter(*cand); - - // reco::PFCandidate::ParticleType chargedPFCandidateType = chargedHadron->chargedPFCandidate_->particleId(); int pdgId = std::abs(chargedHadron->chargedPFCandidate_->pdgId()); if ( chargedHadron->pt() > minMergeChargedHadronPt_ ) { - std::vector jetConstituents = jet.daughterPtrVector(); - for ( std::vector::const_iterator jetConstituent = jetConstituents.begin(); - jetConstituent != jetConstituents.end(); ++jetConstituent ) { + for (const auto& jetConstituent : jet.daughterPtrVector()) { // CV: take care of not double-counting energy in case "charged" PFCandidate is in fact a PFNeutralHadron - if ( (*jetConstituent) == chargedHadron->chargedPFCandidate_ ) continue; + if ( jetConstituent == chargedHadron->chargedPFCandidate_ ) continue; - // reco::PFCandidate::ParticleType jetConstituentType = (*jetConstituent)->particleId(); - int jetConstituentPdgId = std::abs((*jetConstituent)->pdgId()); + int jetConstituentPdgId = std::abs(jetConstituent->pdgId()); if ( !(jetConstituentPdgId == 130 || jetConstituentPdgId == 22) ) continue; - double dR = deltaR(atECALEntrance(&**jetConstituent, bField_), atECALEntrance(&*chargedHadron, bField_)); + double dR = deltaR(atECALEntrance(jetConstituent.get(), bField_), atECALEntrance(&*chargedHadron, bField_)); double dRmerge = -1.; int minBlockElementMatches = 1000; int maxUnmatchedBlockElements = 0; @@ -237,19 +232,18 @@ PFRecoTauChargedHadronFromPFCandidatePlugin::return_type PFRecoTauChargedHadronF minMergeEt = minMergeGammaEt_; } - if ((*jetConstituent)->et() > minMergeEt) { + if (jetConstituent->et() > minMergeEt) { if (dR < dRmerge) { - chargedHadron->neutralPFCandidates_.push_back(*jetConstituent); - chargedHadron->addDaughter(*jetConstituent); + chargedHadron->neutralPFCandidates_.push_back(jetConstituent); + chargedHadron->addDaughter(jetConstituent); } else { // TauReco@MiniAOD: No access to PF blocks at MiniAOD level, but the code below seems to have very minor impact - const reco::PFCandidate* pfCHCand = dynamic_cast(&*chargedHadron->chargedPFCandidate_); - const reco::PFCandidate* pfJetConstituent = dynamic_cast(&**jetConstituent); - if (pfCHCand != nullptr && pfJetConstituent != nullptr) { - if (isMatchedByBlockElement(*pfJetConstituent, *pfCHCand, minBlockElementMatches, minBlockElementMatches, maxUnmatchedBlockElements)) { - chargedHadron->neutralPFCandidates_.push_back(*jetConstituent); - chargedHadron->addDaughter(*jetConstituent); + const reco::PFCandidate* pfJetConstituent = dynamic_cast(jetConstituent.get()); + if (pfCand != nullptr && pfJetConstituent != nullptr) { + if (isMatchedByBlockElement(*pfJetConstituent, *pfCand, minBlockElementMatches, minBlockElementMatches, maxUnmatchedBlockElements)) { + chargedHadron->neutralPFCandidates_.push_back(jetConstituent); + chargedHadron->addDaughter(jetConstituent); } } } diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectron.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectron.cc index f8e8dbbb7cf6a..9062d88608105 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectron.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectron.cc @@ -242,4 +242,4 @@ PFRecoTauDiscriminationAgainstElectron::isInEcalCrack(double eta) const } } -DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstElectron); \ No newline at end of file +DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstElectron); diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA5.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA5.cc index 00c2f1a014797..cc66700d8de4a 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA5.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA5.cc @@ -237,4 +237,4 @@ PFRecoTauDiscriminationAgainstElectronMVA5::isInEcalCrack(double eta) const return (absEta > 1.460 && absEta < 1.558); } -DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstElectronMVA5); \ No newline at end of file +DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstElectronMVA5); diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA6.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA6.cc index 15e641cec2348..d9a15163028e4 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA6.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA6.cc @@ -147,11 +147,11 @@ double PFRecoTauDiscriminationAgainstElectronMVA6::discriminate(const PFTauRef& deltaRDummy = deltaREleTau; if ( deltaREleTau < 0.3 ) { double mva_match = mva_->MVAValue(*thePFTauRef, *theGsfElectron, usePhiAtEcalEntranceExtrapolation_); - const reco::PFCandidate* lpfch = dynamic_cast(thePFTauRef->leadChargedHadrCand().get()); + const reco::PFCandidatePtr& lpfch = thePFTauRef->leadPFChargedHadrCand(); bool hasGsfTrack = false; - if (lpfch != nullptr) { + if (lpfch.isNonnull()) { hasGsfTrack = lpfch->gsfTrackRef().isNonnull(); - } else throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFCandidates, and PFRecoTauDiscriminationAgainstElectronMVA6 only works with PFTaus made from PFCandidates."; + } if ( !hasGsfTrack ) hasGsfTrack = theGsfElectron->gsfTrack().isNonnull(); @@ -189,11 +189,11 @@ double PFRecoTauDiscriminationAgainstElectronMVA6::discriminate(const PFTauRef& if ( !isGsfElectronMatched ) { mvaValue = mva_->MVAValue(*thePFTauRef, usePhiAtEcalEntranceExtrapolation_); - const reco::PFCandidate* lpfch = dynamic_cast(thePFTauRef->leadChargedHadrCand().get()); + const reco::PFCandidatePtr& lpfch = thePFTauRef->leadPFChargedHadrCand(); bool hasGsfTrack = false; - if (lpfch != nullptr) { + if (lpfch.isNonnull()) { hasGsfTrack = lpfch->gsfTrackRef().isNonnull(); - } else throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFCandidates, and PFRecoTauDiscriminationAgainstElectronMVA6 only works with PFTaus made from PFCandidates."; + } //// Veto taus that go to Ecal crack if ( isInEcalCrack(tauEtaAtEcalEntrance) || isInEcalCrack(leadChargedPFCandEtaAtEcalEntrance) ) { diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuon.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuon.cc index 6291e22e2a423..4fae057948084 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuon.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuon.cc @@ -97,4 +97,4 @@ double PFRecoTauDiscriminationAgainstMuon::discriminate(const PFTauRef& thePFTau return (decision ? 1. : 0.); } -DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstMuon); \ No newline at end of file +DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstMuon); diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuon2.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuon2.cc index 55fa3e0248961..c25cb5db1116e 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuon2.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuon2.cc @@ -128,17 +128,14 @@ double PFRecoTauDiscriminationAgainstMuon2::discriminate(const reco::PFTauRef& p numHitsRPC[iStation] = 0; } - const reco::CandidatePtr& pfLeadChargedHadron = pfTau->leadChargedHadrCand(); + const reco::PFCandidatePtr& pfLeadChargedHadron = pfTau->leadPFChargedHadrCand(); if ( pfLeadChargedHadron.isNonnull() ) { - const reco::PFCandidate* pflch = dynamic_cast(pfLeadChargedHadron.get()); - if (pflch != nullptr) { - reco::MuonRef muonRef = pflch->muonRef(); - if ( muonRef.isNonnull() ) { - if ( verbosity_ ) edm::LogPrint("PFTauAgainstMuon2") << " has muonRef." ; - reco::tau::countMatches(*muonRef, numMatchesDT, numMatchesCSC, numMatchesRPC); - reco::tau::countHits(*muonRef, numHitsDT, numHitsCSC, numHitsRPC); - } - } else throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFCandidates, and PFRecoTauDiscriminationAgainstMuon2 only works with PFTaus made from PFCandidates. Please use PFRecoTauDiscriminationAgainstMuonSimple instead.\n"; + reco::MuonRef muonRef = pfLeadChargedHadron->muonRef(); + if ( muonRef.isNonnull() ) { + if ( verbosity_ ) edm::LogPrint("PFTauAgainstMuon2") << " has muonRef." ; + reco::tau::countMatches(*muonRef, numMatchesDT, numMatchesCSC, numMatchesRPC); + reco::tau::countHits(*muonRef, numHitsDT, numHitsCSC, numHitsRPC); + } } if ( !srcMuons_.label().empty() ) { @@ -151,14 +148,11 @@ double PFRecoTauDiscriminationAgainstMuon2::discriminate(const reco::PFTauRef& p continue; } if ( pfLeadChargedHadron.isNonnull()) { - const reco::PFCandidate* pflch = dynamic_cast(pfLeadChargedHadron.get()); - if (pflch != nullptr) { - reco::MuonRef muonRef = pflch->muonRef(); - if (muonRef.isNonnull() && muon == pflch->muonRef() ) { - if ( verbosity_ ) { edm::LogPrint("PFTauAgainstMuon2") << " matches muonRef of tau --> skipping it."; } - continue; - } - } else throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFCandidates, and PFRecoTauDiscriminationAgainstMuon2 only works with PFTaus made from PFCandidates. Please use PFRecoTauDiscriminationAgainstMuonSimple instead.\n"; + reco::MuonRef muonRef = pfLeadChargedHadron->muonRef(); + if (muonRef.isNonnull() && muon == pfLeadChargedHadron->muonRef() ) { + if ( verbosity_ ) { edm::LogPrint("PFTauAgainstMuon2") << " matches muonRef of tau --> skipping it."; } + continue; + } } double dR = deltaR(muon->p4(), pfTau->p4()); double dRmatch = dRmuonMatch_; @@ -211,26 +205,21 @@ double PFRecoTauDiscriminationAgainstMuon2::discriminate(const reco::PFTauRef& p bool passesCaloMuonVeto = true; if ( pfLeadChargedHadron.isNonnull() ) { - const reco::PFCandidate* pflch = dynamic_cast(pfLeadChargedHadron.get()); - if (pflch != nullptr) { - double energyECALplusHCAL = pflch->ecalEnergy() + pflch->hcalEnergy(); - if ( verbosity_ ) { - if ( pflch->trackRef().isNonnull() ) { - edm::LogPrint("PFTauAgainstMuon2") << "decayMode = " << pfTau->decayMode() << ", energy(ECAL+HCAL) = " << energyECALplusHCAL << ", leadPFChargedHadronP = " << pflch->trackRef()->p() ; - } else if ( pflch->gsfTrackRef().isNonnull() ) { - edm::LogPrint("PFTauAgainstMuon2") << "decayMode = " << pfTau->decayMode() << ", energy(ECAL+HCAL) = " << energyECALplusHCAL << ", leadPFChargedHadronP = " << pflch->gsfTrackRef()->p() ; - } + double energyECALplusHCAL = pfLeadChargedHadron->ecalEnergy() + pfLeadChargedHadron->hcalEnergy(); + if ( verbosity_ ) { + if ( pfLeadChargedHadron->trackRef().isNonnull() ) { + edm::LogPrint("PFTauAgainstMuon2") << "decayMode = " << pfTau->decayMode() << ", energy(ECAL+HCAL) = " << energyECALplusHCAL << ", leadPFChargedHadronP = " << pfLeadChargedHadron->trackRef()->p() ; + } else if ( pfLeadChargedHadron->gsfTrackRef().isNonnull() ) { + edm::LogPrint("PFTauAgainstMuon2") << "decayMode = " << pfTau->decayMode() << ", energy(ECAL+HCAL) = " << energyECALplusHCAL << ", leadPFChargedHadronP = " << pfLeadChargedHadron->gsfTrackRef()->p() ; } - const reco::Track* leadTrack = nullptr; - if ( pflch->trackRef().isNonnull() ) - leadTrack = pflch->trackRef().get(); - else if ( pflch->gsfTrackRef().isNonnull() ) - leadTrack = pflch->gsfTrackRef().get(); - if ( pfTau->decayMode() == 0 && leadTrack && energyECALplusHCAL < (hop_*leadTrack->p()) ) - passesCaloMuonVeto = false; - } else { - throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFCandidates, and PFRecoTauDiscriminationAgainstMuon2 only works with PFTaus made from PFCandidates. Please use PFRecoTauDiscriminationAgainstMuonSimple instead.\n"; } + const reco::Track* leadTrack = nullptr; + if ( pfLeadChargedHadron->trackRef().isNonnull() ) + leadTrack = pfLeadChargedHadron->trackRef().get(); + else if ( pfLeadChargedHadron->gsfTrackRef().isNonnull() ) + leadTrack = pfLeadChargedHadron->gsfTrackRef().get(); + if ( pfTau->decayMode() == 0 && leadTrack && energyECALplusHCAL < (hop_*leadTrack->p()) ) + passesCaloMuonVeto = false; } double discriminatorValue = 0.; diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuonMVA.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuonMVA.cc index 0e4dcbac0d3ec..6d1edbe9e06ec 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuonMVA.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuonMVA.cc @@ -244,4 +244,4 @@ void PFRecoTauDiscriminationAgainstMuonMVA::endEvent(edm::Event& evt) } -DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstMuonMVA); \ No newline at end of file +DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstMuonMVA); diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByLeadingObjectPtCut.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByLeadingObjectPtCut.cc index 24b639ecea594..452efa1f15f2d 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByLeadingObjectPtCut.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByLeadingObjectPtCut.cc @@ -51,32 +51,3 @@ double PFRecoTauDiscriminationByLeadingObjectPtCut::discriminate(const PFTauRef& } DEFINE_FWK_MODULE(PFRecoTauDiscriminationByLeadingObjectPtCut); - -/* -void PFRecoTauDiscriminationByLeadingPionPtCut::produce(edm::Event& iEvent,const edm::EventSetup& iEventSetup){ - edm::Handle thePFTauCollection; - iEvent.getByLabel(PFTauProducer_,thePFTauCollection); - - - auto thePFTauDiscriminatorByLeadingPionPtCut = std::make_unique(thePFTauCollection)); - - //loop over the PFTau candidates - for(size_t iPFTau=0;iPFTausize();++iPFTau) { - PFTauRef thePFTauRef(thePFTauCollection,iPFTau); - PFTau thePFTau=*thePFTauRef; - double theleadTrackPtCutDiscriminator = 0.; - // fill the AssociationVector object - if (!thePFTau.leadCand() || !thePFTau.leadChargedHadrCand()) - { - theleadTrackPtCutDiscriminator=0.; - } - else if(thePFTau.leadCand()->pt() > minPtLeadTrack_) theleadTrackPtCutDiscriminator=1.; - - thePFTauDiscriminatorByLeadingPionPtCut->setValue(iPFTau,theleadTrackPtCutDiscriminator); - } - - iEvent.put(std::move(thePFTauDiscriminatorByLeadingPionPtCut)); - -} - -*/ diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByMVAIsolationRun2.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByMVAIsolationRun2.cc index 41f0e2fa54ff7..afdfe088b6195 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByMVAIsolationRun2.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByMVAIsolationRun2.cc @@ -224,7 +224,6 @@ double PFRecoTauDiscriminationByMVAIsolationRun2::discriminate(const PFTauRef& t float ptWeightedDphiStrip = clusterVariables_.tau_pt_weighted_dphi_strip(*tau, tauDecayMode); float ptWeightedDrSignal = clusterVariables_.tau_pt_weighted_dr_signal(*tau, tauDecayMode); float ptWeightedDrIsolation = clusterVariables_.tau_pt_weighted_dr_iso(*tau, tauDecayMode); - float leadingTrackChi2 = clusterVariables_.tau_leadTrackChi2(*tau); float eRatio = clusterVariables_.tau_Eratio(*tau); // Difference between measured and maximally allowed Gottfried-Jackson angle @@ -275,7 +274,7 @@ double PFRecoTauDiscriminationByMVAIsolationRun2::discriminate(const PFTauRef& t mvaInput_[9] = std::min(0.5f, ptWeightedDphiStrip); mvaInput_[10] = std::min(0.5f, ptWeightedDrSignal); mvaInput_[11] = std::min(0.5f, ptWeightedDrIsolation); - mvaInput_[12] = std::min(100.f, leadingTrackChi2); + mvaInput_[12] = std::min(100.f, clusterVariables_.tau_leadTrackChi2(*tau)); mvaInput_[13] = std::min(1.f, eRatio); mvaInput_[14] = std::copysign(+1.f, (float)tauLifetimeInfo.dxy()); mvaInput_[15] = std::sqrt(std::min(1.f, std::abs((float)tauLifetimeInfo.dxy()))); @@ -299,7 +298,7 @@ double PFRecoTauDiscriminationByMVAIsolationRun2::discriminate(const PFTauRef& t mvaInput_[9] = std::min(0.5f, ptWeightedDphiStrip); mvaInput_[10] = std::min(0.5f, ptWeightedDrSignal); mvaInput_[11] = std::min(0.5f, ptWeightedDrIsolation); - mvaInput_[12] = std::min(100.f, leadingTrackChi2); + mvaInput_[12] = std::min(100.f, clusterVariables_.tau_leadTrackChi2(*tau)); mvaInput_[13] = std::min(1.f, eRatio); mvaInput_[14] = std::copysign(+1.f, (float)tauLifetimeInfo.dxy()); mvaInput_[15] = std::sqrt(std::min(1.f, std::abs((float)tauLifetimeInfo.dxy()))); diff --git a/RecoTauTag/RecoTau/plugins/PFTauMiniAODPrimaryVertexProducer.cc b/RecoTauTag/RecoTau/plugins/PFTauMiniAODPrimaryVertexProducer.cc index cf36d45d724e1..cee8fa267fdf6 100644 --- a/RecoTauTag/RecoTau/plugins/PFTauMiniAODPrimaryVertexProducer.cc +++ b/RecoTauTag/RecoTau/plugins/PFTauMiniAODPrimaryVertexProducer.cc @@ -77,7 +77,7 @@ void PFTauMiniAODPrimaryVertexProducer::nonTauTracksInPVFromPackedCands(const si bool matched = false; for(const auto& tauTrack: tauTracks){ if(std::abs(tauTrack->eta()-track->eta())<0.005 - && deltaPhi(tauTrack->phi(),track->phi())<0.005 + && std::abs(deltaPhi(tauTrack->phi(),track->phi()))<0.005 && std::abs(tauTrack->pt()/track->pt()-1.)<0.005 ){ matched = true; diff --git a/RecoTauTag/RecoTau/plugins/PFTauPrimaryVertexProducer.cc b/RecoTauTag/RecoTau/plugins/PFTauPrimaryVertexProducer.cc index ec5321a632b76..91550972e7400 100644 --- a/RecoTauTag/RecoTau/plugins/PFTauPrimaryVertexProducer.cc +++ b/RecoTauTag/RecoTau/plugins/PFTauPrimaryVertexProducer.cc @@ -28,9 +28,8 @@ void PFTauPrimaryVertexProducer::nonTauTracksInPV(const reco::VertexRef &thePVRe //Find non-tau tracks associated to thePV for(reco::Vertex::trackRef_iterator vtxTrkRef=thePVRef->tracks_begin();vtxTrkRef!=thePVRef->tracks_end();vtxTrkRef++){ bool matched = false; - edm::Ptr vtxTrkPtr = edm::refToPtr((*vtxTrkRef).castTo > >()); - for(const auto& tauTrack: tauTracks){ - if( vtxTrkPtr == tauTrack ) { + for(const auto& tauTrack : tauTracks){ + if (tauTrack.id() == vtxTrkRef->id() && tauTrack.key() == vtxTrkRef->key()) { matched = true; break; } diff --git a/RecoTauTag/RecoTau/plugins/RecoTauElectronRejectionPlugin.cc b/RecoTauTag/RecoTau/plugins/RecoTauElectronRejectionPlugin.cc index 1a2581459a1cd..855dcd635a54a 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauElectronRejectionPlugin.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauElectronRejectionPlugin.cc @@ -223,4 +223,4 @@ void RecoTauElectronRejectionPlugin::operator()(PFTau& tau) const { #include "FWCore/Framework/interface/MakerMacros.h" DEFINE_EDM_PLUGIN(RecoTauModifierPluginFactory, reco::tau::RecoTauElectronRejectionPlugin, - "RecoTauElectronRejectionPlugin"); \ No newline at end of file + "RecoTauElectronRejectionPlugin"); diff --git a/RecoTauTag/RecoTau/plugins/RecoTauJetRegionProducer.cc b/RecoTauTag/RecoTau/plugins/RecoTauGenericJetRegionProducer.cc similarity index 98% rename from RecoTauTag/RecoTau/plugins/RecoTauJetRegionProducer.cc rename to RecoTauTag/RecoTau/plugins/RecoTauGenericJetRegionProducer.cc index 01d92d2318df6..70cfd106bde90 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauJetRegionProducer.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauGenericJetRegionProducer.cc @@ -209,9 +209,8 @@ void RecoTauGenericJetRegionProducer::produce(edm::Event& evt } evt.put(std::move(matching)); } -template class RecoTauGenericJetRegionProducer; + typedef RecoTauGenericJetRegionProducer RecoTauJetRegionProducer; -template class RecoTauGenericJetRegionProducer; typedef RecoTauGenericJetRegionProducer RecoTauPatJetRegionProducer; #include "FWCore/Framework/interface/MakerMacros.h" diff --git a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstCaloMuon.cc b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstCaloMuon.cc index 86ad7d76b4ea6..98654730b7ace 100644 --- a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstCaloMuon.cc +++ b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstCaloMuon.cc @@ -308,4 +308,4 @@ typedef TauDiscriminationAgainstCaloMuon PFRecoTauDis typedef TauDiscriminationAgainstCaloMuon CaloRecoTauDiscriminationAgainstCaloMuon; DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstCaloMuon); -DEFINE_FWK_MODULE(CaloRecoTauDiscriminationAgainstCaloMuon); \ No newline at end of file +DEFINE_FWK_MODULE(CaloRecoTauDiscriminationAgainstCaloMuon); diff --git a/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstMuonSimple_cfi.py b/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstMuonSimple_cfi.py deleted file mode 100644 index 0d6df96aed3f9..0000000000000 --- a/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstMuonSimple_cfi.py +++ /dev/null @@ -1,29 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -from RecoTauTag.Configuration.HPSPFTaus_cff import hpsPFTauDiscriminationByLooseMuonRejection3, hpsPFTauDiscriminationByTightMuonRejection3 - -hpsPFTauDiscriminationByLooseMuonRejectionSimple = cms.EDProducer("PFRecoTauDiscriminationAgainstMuonSimple", - PFTauProducer = cms.InputTag("hpsPFTauProducer"), - Prediscriminants = hpsPFTauDiscriminationByLooseMuonRejection3.Prediscriminants, - HoPMin = cms.double(0.1), #use smaller value that with AOD as raw energy is used - doCaloMuonVeto = cms.bool(False), #do not use it until tuned - srcPatMuons = cms.InputTag("slimmedMuons"), - minPtMatchedMuon = hpsPFTauDiscriminationByLooseMuonRejection3.minPtMatchedMuon, - dRmuonMatch = hpsPFTauDiscriminationByLooseMuonRejection3.dRmuonMatch, - dRmuonMatchLimitedToJetArea = hpsPFTauDiscriminationByLooseMuonRejection3.dRmuonMatchLimitedToJetArea, - maskHitsCSC = hpsPFTauDiscriminationByLooseMuonRejection3.maskHitsCSC, - maskHitsDT = hpsPFTauDiscriminationByLooseMuonRejection3.maskHitsDT, - maskHitsRPC = hpsPFTauDiscriminationByLooseMuonRejection3.maskHitsRPC, - maxNumberOfHitsLast2Stations = hpsPFTauDiscriminationByLooseMuonRejection3.maxNumberOfHitsLast2Stations, - maskMatchesCSC = hpsPFTauDiscriminationByLooseMuonRejection3.maskMatchesCSC, - maskMatchesDT = hpsPFTauDiscriminationByLooseMuonRejection3.maskMatchesDT, - maskMatchesRPC = hpsPFTauDiscriminationByLooseMuonRejection3.maskMatchesRPC, - maxNumberOfMatches = hpsPFTauDiscriminationByLooseMuonRejection3.maxNumberOfMatches, - maxNumberOfSTAMuons = cms.int32(-1), - maxNumberOfRPCMuons = cms.int32(-1), - verbosity = cms.int32(0) -) - -hpsPFTauDiscriminationByTightMuonRejectionSimple = hpsPFTauDiscriminationByLooseMuonRejectionSimple.clone( - maxNumberOfHitsLast2Stations = hpsPFTauDiscriminationByTightMuonRejection3.maxNumberOfHitsLast2Stations -) diff --git a/RecoTauTag/RecoTau/python/hpsPFTauDiscriminationByAMuonRejectionSimple_cff.py b/RecoTauTag/RecoTau/python/hpsPFTauDiscriminationByAMuonRejectionSimple_cff.py new file mode 100644 index 0000000000000..2a984a5072de4 --- /dev/null +++ b/RecoTauTag/RecoTau/python/hpsPFTauDiscriminationByAMuonRejectionSimple_cff.py @@ -0,0 +1,22 @@ +import FWCore.ParameterSet.Config as cms + +from RecoTauTag.Configuration.HPSPFTaus_cff import hpsPFTauDiscriminationByLooseMuonRejection3, hpsPFTauDiscriminationByTightMuonRejection3 + +hpsPFTauDiscriminationByLooseMuonRejectionSimple = hpsPFTauDiscriminationByLooseMuonRejection3.clone( + PFTauProducer=cms.InputTag("hpsPFTauProducer"), + HoPMin=cms.double(0.1), #use smaller value than with AOD as raw energy is used + doCaloMuonVeto=cms.bool(False), #do not use it until tuned + srcPatMuons=cms.InputTag("slimmedMuons"), + maxNumberOfSTAMuons=cms.int32(-1), + maxNumberOfRPCMuons=cms.int32(-1) + ) + +hpsPFTauDiscriminationByLooseMuonRejectionSimple.__dict__['_TypedParameterizable__type'] = "PFRecoTauDiscriminationAgainstMuonSimple" + +for attr in ['discriminatorOption', 'srcMuons']: + delattr(hpsPFTauDiscriminationByLooseMuonRejectionSimple, attr) + + +hpsPFTauDiscriminationByTightMuonRejectionSimple = hpsPFTauDiscriminationByLooseMuonRejectionSimple.clone( + maxNumberOfHitsLast2Stations=hpsPFTauDiscriminationByTightMuonRejection3.maxNumberOfHitsLast2Stations +) diff --git a/RecoTauTag/RecoTau/src/AntiElectronIDMVA5.cc b/RecoTauTag/RecoTau/src/AntiElectronIDMVA5.cc index 09ab19c4692ea..16cd819603b08 100644 --- a/RecoTauTag/RecoTau/src/AntiElectronIDMVA5.cc +++ b/RecoTauTag/RecoTau/src/AntiElectronIDMVA5.cc @@ -1079,4 +1079,4 @@ double AntiElectronIDMVA5::dCrackEta(double eta) } return std::abs(retVal); -} \ No newline at end of file +} diff --git a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc index 90af59f8ac183..de3c8485341cb 100644 --- a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc +++ b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc @@ -553,12 +553,9 @@ double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau, Float_t TauEmFraction = std::max(thePFTau.emFraction(), (Float_t)0.); Float_t TauLeadPFChargedHadrHoP = 0.; Float_t TauLeadPFChargedHadrEoP = 0.; - if ( thePFTau.leadChargedHadrCand()->p() > 0. ) { - const reco::PFCandidate* pflch = dynamic_cast(thePFTau.leadChargedHadrCand().get()); - if (pflch != nullptr) { - TauLeadPFChargedHadrHoP = pflch->hcalEnergy()/pflch->p(); - TauLeadPFChargedHadrEoP = pflch->ecalEnergy()/pflch->p(); - } else throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFCandidates, and this algorithm was not yet updated to cope with PFTaus made from other Candidates.\n"; + if ( thePFTau.leadPFChargedHadrCand()->p() > 0. ) { + TauLeadPFChargedHadrHoP = thePFTau.leadPFChargedHadrCand()->hcalEnergy()/thePFTau.leadPFChargedHadrCand()->p(); + TauLeadPFChargedHadrEoP = thePFTau.leadPFChargedHadrCand()->ecalEnergy()/thePFTau.leadPFChargedHadrCand()->p(); } std::vector GammasdEtaInSigCone; @@ -642,12 +639,7 @@ double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau, } Float_t TaudCrackPhi = dCrackPhi(TauPhi, TauEtaAtEcalEntrance); Float_t TaudCrackEta = dCrackEta(TauEtaAtEcalEntrance); - Float_t TauHasGsf = false; - const reco::PFCandidate* pflch = dynamic_cast(thePFTau.leadChargedHadrCand().get()); - if (pflch != nullptr) { - TauHasGsf = pflch->gsfTrackRef().isNonnull(); - } else { - throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFCandidates, and this algorithm was not yet updated to cope with PFTaus made from other Candidates.\n"; } + Float_t TauHasGsf = thePFTau.leadPFChargedHadrCand()->gsfTrackRef().isNonnull(); // === electron variables === Float_t ElecEta = theGsfEle.eta(); @@ -773,12 +765,9 @@ double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau, bool usePhiAtEc Float_t TauEmFraction = std::max(thePFTau.emFraction(), (Float_t)0.); Float_t TauLeadPFChargedHadrHoP = 0.; Float_t TauLeadPFChargedHadrEoP = 0.; - if ( thePFTau.leadChargedHadrCand()->p() > 0. ) { - const reco::PFCandidate* pflch = dynamic_cast(thePFTau.leadChargedHadrCand().get()); - if (pflch != nullptr) { - TauLeadPFChargedHadrHoP = pflch->hcalEnergy()/pflch->p(); - TauLeadPFChargedHadrEoP = pflch->ecalEnergy()/pflch->p(); - } else { throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFCandidates, and this algorithm was not yet updated to cope with PFTaus made from other Candidates.\n"; } + if ( thePFTau.leadPFChargedHadrCand()->p() > 0. ) { + TauLeadPFChargedHadrHoP = thePFTau.leadPFChargedHadrCand()->hcalEnergy()/thePFTau.leadPFChargedHadrCand()->p(); + TauLeadPFChargedHadrEoP = thePFTau.leadPFChargedHadrCand()->ecalEnergy()/thePFTau.leadPFChargedHadrCand()->p(); } std::vector GammasdEtaInSigCone; @@ -862,12 +851,7 @@ double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau, bool usePhiAtEc } Float_t TaudCrackPhi = dCrackPhi(TauPhi, TauEtaAtEcalEntrance); Float_t TaudCrackEta = dCrackEta(TauEtaAtEcalEntrance); - Float_t TauHasGsf = false; - const reco::PFCandidate* pflch = dynamic_cast(thePFTau.leadChargedHadrCand().get()); - if (pflch != nullptr) { - TauHasGsf = pflch->gsfTrackRef().isNonnull(); - } else { - throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFCandidates, and this algorithm was not yet updated to cope with PFTaus made from other Candidates.\n"; } + Float_t TauHasGsf = thePFTau.leadPFChargedHadrCand()->gsfTrackRef().isNonnull(); // === electron variables === diff --git a/RecoTauTag/RecoTau/src/RecoTauMuonTools.cc b/RecoTauTag/RecoTau/src/RecoTauMuonTools.cc index 8a75d06eb2bec..38aaceb4ba6ff 100644 --- a/RecoTauTag/RecoTau/src/RecoTauMuonTools.cc +++ b/RecoTauTag/RecoTau/src/RecoTauMuonTools.cc @@ -50,4 +50,4 @@ namespace reco { namespace tau { } } -}} // end namespace reco::tau \ No newline at end of file +}} // end namespace reco::tau diff --git a/RecoTauTag/RecoTau/src/RecoTauQualityCuts.cc b/RecoTauTag/RecoTau/src/RecoTauQualityCuts.cc index bf98ccc851755..915de084c23b9 100644 --- a/RecoTauTag/RecoTau/src/RecoTauQualityCuts.cc +++ b/RecoTauTag/RecoTau/src/RecoTauQualityCuts.cc @@ -574,4 +574,4 @@ void RecoTauQualityCuts::setLeadTrack(const reco::CandidateRef& leadCand) const } } -}} // end namespace reco::tau \ No newline at end of file +}} // end namespace reco::tau diff --git a/RecoTauTag/RecoTau/test/rerunTauRecoOnMiniAOD.py b/RecoTauTag/RecoTau/test/rerunTauRecoOnMiniAOD.py index e702cc489acc1..9bcedbf27ad30 100644 --- a/RecoTauTag/RecoTau/test/rerunTauRecoOnMiniAOD.py +++ b/RecoTauTag/RecoTau/test/rerunTauRecoOnMiniAOD.py @@ -7,66 +7,68 @@ ###### ###### -runSignal=True -#runSignal=False -maxEvents=100 -#maxEvents=-1 +runSignal = True +# runSignal=False +maxEvents = 100 +# maxEvents=-1 -# If 'reclusterJets' set true a new collection of uncorrected ak4PFJets is + +# If 'reclusterJets' set true a new collection of uncorrected ak4PFJets is # built to seed taus (as at RECO), otherwise standard slimmedJets are used -reclusterJets=True -#reclusterJets=False +reclusterJets = True +# reclusterJets = False -#set true for upgrade studies -phase2=False -#phase2=True +# set true for upgrade studies +phase2 = False +# phase2 = True -#Output mode -outMode = 0 #store original MiniAOD and new selectedPatTaus -#outMode = 1 #store original MiniAOD, new selectedPatTaus, and all PFtau products as in AOD (except of unsuported ones) +# Output mode +outMode = 0 # store original MiniAOD and new selectedPatTaus +# outMode = 1 #store original MiniAOD, new selectedPatTaus, and all PFtau products as in AOD (except of unsuported ones) print 'Running Tau reco&id with MiniAOD inputs:' print '\t Run on signal:', runSignal print '\t Recluster jets:', reclusterJets print '\t Use Phase2 settings:', phase2 print '\t Output mode:', outMode - + ##### from Configuration.StandardSequences.Eras import eras era = eras.Run2_2017 if phase2: - era = eras.Phase2_timing -process = cms.Process("TAURECO",era) -process.load("Configuration.StandardSequences.MagneticField_cff") # for CH reco + era = eras.Phase2_timing +process = cms.Process("TAURECO", era) +# for CH reco +process.load("Configuration.StandardSequences.MagneticField_cff") if not phase2: - process.load("Configuration.Geometry.GeometryRecoDB_cff") + process.load("Configuration.Geometry.GeometryRecoDB_cff") else: - process.load('Configuration.Geometry.GeometryExtended2023D17Reco_cff') + process.load('Configuration.Geometry.GeometryExtended2023D17Reco_cff') ##### readFiles = cms.untracked.vstring() -secFiles = cms.untracked.vstring() -process.source = cms.Source ("PoolSource",fileNames = readFiles, secondaryFileNames = secFiles) +secFiles = cms.untracked.vstring() +process.source = cms.Source( + "PoolSource", fileNames=readFiles, secondaryFileNames=secFiles) process.maxEvents = cms.untracked.PSet( - input = cms.untracked.int32(maxEvents) + input=cms.untracked.int32(maxEvents) ) print '\t Max events:', process.maxEvents.input.value() if runSignal: - readFiles.extend( [ - #'file:patMiniAOD_standard.root' - '/store/relval/CMSSW_10_1_0_pre3/RelValZTT_13UP18/MINIAODSIM/PUpmx25ns_101X_upgrade2018_realistic_v3_cc7-v1/10000/2808A251-DE31-E811-BFBC-0242AC130002.root' - #'/store/relval/CMSSW_10_1_0_pre3/RelValZTT_13UP18/MINIAODSIM/PUpmx25ns_101X_upgrade2018_realistic_v3_cc7-v1/10000/2808A251-DE31-E811-BFBC-0242AC130002.root' - #'root://cms-xrd-global.cern.ch///store/relval/CMSSW_10_0_0_pre2/RelValZTT_13/MINIAODSIM/PUpmx25ns_100X_mc2017_realistic_v1-v1/20000/B01F0774-17E1-E711-9826-0CC47A4D7654.root', - ] ) + readFiles.extend([ + #'file:patMiniAOD_standard.root' + '/store/relval/CMSSW_10_1_0_pre3/RelValZTT_13UP18/MINIAODSIM/PUpmx25ns_101X_upgrade2018_realistic_v3_cc7-v1/10000/2808A251-DE31-E811-BFBC-0242AC130002.root' + #'root://cms-xrd-global.cern.ch///store/relval/CMSSW_10_0_0_pre2/RelValZTT_13/MINIAODSIM/PUpmx25ns_100X_mc2017_realistic_v1-v1/20000/B01F0774-17E1-E711-9826-0CC47A4D7654.root', + ]) else: - readFiles.extend( [ - #'file:patMiniAOD_standard.root' - '/store/relval/CMSSW_10_1_0_pre3/RelValZTT_13UP18/MINIAODSIM/PUpmx25ns_101X_upgrade2018_realistic_v3_cc7-v1/10000/2808A251-DE31-E811-BFBC-0242AC130002.root' - #'root://cms-xrd-global.cern.ch///store/relval/CMSSW_10_0_0_pre2/RelValQCD_FlatPt_15_3000HS_13/MINIAODSIM/PUpmx25ns_100X_mcRun2_asymptotic_v2_FastSim-v1/20000/78318DC3-40E0-E711-BCFE-0CC47A4D763C.root', - #'root://cms-xrd-global.cern.ch///store/relval/CMSSW_10_0_0_pre2/RelValQCD_FlatPt_15_3000HS_13/MINIAODSIM/PUpmx25ns_100X_mcRun2_asymptotic_v2_FastSim-v1/20000/E6F528C8-40E0-E711-9F06-0CC47A4C8E56.root', - ] ) + readFiles.extend([ + #'file:patMiniAOD_standard.root' + '/store/relval/CMSSW_10_1_0_pre3/RelValZTT_13UP18/MINIAODSIM/PUpmx25ns_101X_upgrade2018_realistic_v3_cc7-v1/10000/2808A251-DE31-E811-BFBC-0242AC130002.root' + #'root://cms-xrd-global.cern.ch///store/relval/CMSSW_10_0_0_pre2/RelValQCD_FlatPt_15_3000HS_13/MINIAODSIM/PUpmx25ns_100X_mcRun2_asymptotic_v2_FastSim-v1/20000/78318DC3-40E0-E711-BCFE-0CC47A4D763C.root', + #'root://cms-xrd-global.cern.ch///store/relval/CMSSW_10_0_0_pre2/RelValQCD_FlatPt_15_3000HS_13/MINIAODSIM/PUpmx25ns_100X_mcRun2_asymptotic_v2_FastSim-v1/20000/E6F528C8-40E0-E711-9F06-0CC47A4C8E56.root', + ]) ##### import RecoTauTag.Configuration.tools.adaptToRunAtMiniAOD as tauAtMiniTools @@ -78,23 +80,24 @@ process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') from Configuration.AlCa.GlobalTag import GlobalTag if not phase2: - process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc', '') - process.GlobalTag.globaltag = '94X_mc2017_realistic_v1' + process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc', '') + process.GlobalTag.globaltag = '94X_mc2017_realistic_v1' else: - process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase2_realistic', '') + process.GlobalTag = GlobalTag( + process.GlobalTag, 'auto:phase2_realistic', '') ##### -#mode = 0: store original MiniAOD and new selectedPatTaus -#mode = 1: store original MiniAOD, new selectedPatTaus, and all PFtau products as in AOD (except of unsuported ones) +# mode = 0: store original MiniAOD and new selectedPatTaus +# mode = 1: store original MiniAOD, new selectedPatTaus, and all PFtau products as in AOD (except of unsuported ones) process.output = tauAtMiniTools.setOutputModule(mode=outMode) if runSignal: - process.output.fileName='miniAOD_TauReco_ggH.root' - if reclusterJets: - process.output.fileName='miniAOD_TauReco_ak4PFJets_ggH.root' + process.output.fileName = 'miniAOD_TauReco_ggH.root' + if reclusterJets: + process.output.fileName = 'miniAOD_TauReco_ak4PFJets_ggH.root' else: - process.output.fileName='miniAOD_TauReco_QCD.root' - if reclusterJets: - process.output.fileName='miniAOD_TauReco_ak4PFJets_QCD.root' + process.output.fileName = 'miniAOD_TauReco_QCD.root' + if reclusterJets: + process.output.fileName = 'miniAOD_TauReco_ak4PFJets_QCD.root' process.out = cms.EndPath(process.output) ##### @@ -102,20 +105,20 @@ ##### process.load('FWCore.MessageService.MessageLogger_cfi') -if process.maxEvents.input.value()>10: - process.MessageLogger.cerr.FwkReport.reportEvery = process.maxEvents.input.value()//10 -if process.maxEvents.input.value()>10000 or process.maxEvents.input.value()<0: - process.MessageLogger.cerr.FwkReport.reportEvery = 1000 +if process.maxEvents.input.value() > 10: + process.MessageLogger.cerr.FwkReport.reportEvery = process.maxEvents.input.value()//10 +if process.maxEvents.input.value() > 10000 or process.maxEvents.input.value() < 0: + process.MessageLogger.cerr.FwkReport.reportEvery = 1000 ##### process.options = cms.untracked.PSet( ) -process.options.numberOfThreads=cms.untracked.uint32(4) -#process.options.numberOfThreads=cms.untracked.uint32(1) -process.options.numberOfStreams=cms.untracked.uint32(0) -print '\t No. of threads:', process.options.numberOfThreads.value(),', no. of streams:',process.options.numberOfStreams.value() +process.options.numberOfThreads = cms.untracked.uint32(4) +# process.options.numberOfThreads=cms.untracked.uint32(1) +process.options.numberOfStreams = cms.untracked.uint32(0) +print '\t No. of threads:', process.options.numberOfThreads.value(), ', no. of streams:', process.options.numberOfStreams.value() process.options = cms.untracked.PSet( - process.options, - wantSummary = cms.untracked.bool(True) + process.options, + wantSummary=cms.untracked.bool(True) ) diff --git a/RecoTauTag/TauTagTools/src/PFTauElementsOperators.cc b/RecoTauTag/TauTagTools/src/PFTauElementsOperators.cc index 4a11d6085c4bc..de69230079d7b 100644 --- a/RecoTauTag/TauTagTools/src/PFTauElementsOperators.cc +++ b/RecoTauTag/TauTagTools/src/PFTauElementsOperators.cc @@ -145,10 +145,8 @@ std::pair, std::vector> PFTa std::vector PFTauElementsOperators::PFChargedHadrCandsInAnnulus(const math::XYZVector& myVector,const string innercone_metric,const double innercone_size,const string outercone_metric,const double outercone_size,const double minPt,const double PFChargedHadrCand_tracktorefpoint_maxDZ,const double refpoint_Z, const Vertex &myPV)const{ std::vector filteredPFChargedHadrCands; for(std::vector::const_iterator iPFCand=PFChargedHadrCands_.begin();iPFCand!=PFChargedHadrCands_.end();iPFCand++){ - const reco::PFCandidate* pfcand = dynamic_cast(iPFCand->get()); - if (pfcand != nullptr) { - TrackRef PFChargedHadrCand_track = pfcand->trackRef(); - if (!PFChargedHadrCand_track)continue; + const reco::Track* PFChargedHadrCand_track = (*iPFCand)->bestTrack(); + if (PFChargedHadrCand_track != nullptr) { if (fabs((*PFChargedHadrCand_track).dz(myPV.position())-refpoint_Z)<=PFChargedHadrCand_tracktorefpoint_maxDZ) filteredPFChargedHadrCands.push_back(*iPFCand); } else throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFCandidates, and this outdated algorithm was not updated to cope with PFTaus made from other Candidates.\n"; } diff --git a/RecoTauTag/TauTagTools/src/TauTagTools.cc b/RecoTauTag/TauTagTools/src/TauTagTools.cc index 80e8ee3163888..a41de426342ff 100644 --- a/RecoTauTag/TauTagTools/src/TauTagTools.cc +++ b/RecoTauTag/TauTagTools/src/TauTagTools.cc @@ -107,14 +107,11 @@ void replaceSubStr(string& s,const string& oldSubStr,const string& newSubStr){ for(std::vector::const_iterator iPFCand=theInitialPFCands.begin();iPFCand!=theInitialPFCands.end();iPFCand++){ if (std::abs((*iPFCand)->pdgId()) == 211 || std::abs((*iPFCand)->pdgId()) == 13 || std::abs((*iPFCand)->pdgId()) == 11){ // *** Whether the charged hadron candidate will be selected or not depends on its rec. tk properties. - const reco::PFCandidate* pfcand = dynamic_cast(iPFCand->get()); - if (pfcand != nullptr) { - TrackRef PFChargedHadrCand_rectk = pfcand->trackRef(); - - if (!PFChargedHadrCand_rectk)continue; + const reco::Track* PFChargedHadrCand_rectk = (*iPFCand)->bestTrack(); + if (PFChargedHadrCand_rectk != nullptr) { if ( (*PFChargedHadrCand_rectk).numberOfValidHits()>=ChargedHadrCand_tkminTrackerHitsn ) filteredPFChargedHadrCands.push_back(*iPFCand); - } else throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFCandidates, and this outdated algorithm was not updated to cope with PFTaus made from other Candidates.\n"; + } } } return filteredPFChargedHadrCands;