diff --git a/DataFormats/JetReco/src/classes_def_3.xml b/DataFormats/JetReco/src/classes_def_3.xml index 0d2f651598d82..3984dba45a20c 100644 --- a/DataFormats/JetReco/src/classes_def_3.xml +++ b/DataFormats/JetReco/src/classes_def_3.xml @@ -124,4 +124,10 @@ + + + + + + diff --git a/DataFormats/PatCandidates/interface/Tau.h b/DataFormats/PatCandidates/interface/Tau.h index f473cce07430c..4bf85d03ebde2 100644 --- a/DataFormats/PatCandidates/interface/Tau.h +++ b/DataFormats/PatCandidates/interface/Tau.h @@ -23,6 +23,7 @@ #include "DataFormats/PatCandidates/interface/Lepton.h" #include "DataFormats/JetReco/interface/GenJetCollection.h" #include "DataFormats/Candidate/interface/Candidate.h" +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" #include "DataFormats/PatCandidates/interface/TauPFSpecific.h" #include "DataFormats/PatCandidates/interface/TauCaloSpecific.h" @@ -160,7 +161,7 @@ namespace pat { const pat::tau::TauPFEssential & pfEssential() const; /// Method copied from reco::PFTau. /// Throws an exception if this pat::Tau was not made from a reco::PFTau - const reco::PFJetRef & pfJetRef() const { return pfSpecific().pfJetRef_; } + const reco::JetBaseRef & pfJetRef() const { return pfSpecific().pfJetRef_; } /// Method copied from reco::PFTau. /// Throws an exception if this pat::Tau was not made from a reco::PFTau reco::PFRecoTauChargedHadronRef leadTauChargedHadronCandidate() const; @@ -452,6 +453,8 @@ namespace pat { private: + /// helper to avoid code duplication in constructors + void initFromBaseTau(const reco::BaseTau& aTau); // ---- for content embedding ---- bool embeddedIsolationTracks_; std::vector isolationTracks_; diff --git a/DataFormats/PatCandidates/interface/TauPFSpecific.h b/DataFormats/PatCandidates/interface/TauPFSpecific.h index 87bf760d8082b..6da4fe67653ba 100644 --- a/DataFormats/PatCandidates/interface/TauPFSpecific.h +++ b/DataFormats/PatCandidates/interface/TauPFSpecific.h @@ -6,7 +6,7 @@ /** \class pat::tau::PFSpecific TauPFSpecific.h "DataFormats/PatCandidates/interface/TauPFSpecific.h" - \brief Structure to hold information specific to a PFTau inside a pat::Tau + \brief Structure to hold information specific to a PFTau made from PFCandidates inside a pat::Tau \author Giovanni Petrucciani */ @@ -24,8 +24,8 @@ struct TauPFSpecific { // constructor from PFTau TauPFSpecific(const reco::PFTau& tau); // datamembers - reco::PFJetRef pfJetRef_; - reco::PFCandidatePtr leadPFChargedHadrCand_; + reco::JetBaseRef pfJetRef_; + reco::CandidatePtr leadPFChargedHadrCand_; float leadPFChargedHadrCandsignedSipt_; reco::PFCandidatePtr leadPFNeutralCand_; reco::PFCandidatePtr leadPFCand_; diff --git a/DataFormats/PatCandidates/src/Tau.cc b/DataFormats/PatCandidates/src/Tau.cc index 012e6d30c2c95..f0fc3896bfa4b 100644 --- a/DataFormats/PatCandidates/src/Tau.cc +++ b/DataFormats/PatCandidates/src/Tau.cc @@ -3,6 +3,7 @@ #include "DataFormats/PatCandidates/interface/Tau.h" #include "DataFormats/JetReco/interface/GenJet.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" #include #include @@ -47,13 +48,7 @@ Tau::Tau(const reco::BaseTau & aTau) : ,embeddedIsolationPFNeutralHadrCands_(false) ,embeddedIsolationPFGammaCands_(false) { - const reco::PFTau * pfTau = dynamic_cast(&aTau); - if (pfTau != nullptr){ - pfSpecific_.push_back(pat::tau::TauPFSpecific(*pfTau)); - pfEssential_.push_back(pat::tau::TauPFEssential(*pfTau)); - } - const reco::CaloTau * caloTau = dynamic_cast(&aTau); - if (caloTau != nullptr) caloSpecific_.push_back(pat::tau::TauCaloSpecific(*caloTau)); + initFromBaseTau(aTau); } /// constructor from ref to reco::BaseTau @@ -74,13 +69,7 @@ Tau::Tau(const edm::RefToBase & aTauRef) : ,embeddedIsolationPFNeutralHadrCands_(false) ,embeddedIsolationPFGammaCands_(false) { - const reco::PFTau * pfTau = dynamic_cast(aTauRef.get()); - if (pfTau != nullptr){ - pfSpecific_.push_back(pat::tau::TauPFSpecific(*pfTau)); - pfEssential_.push_back(pat::tau::TauPFEssential(*pfTau)); - } - const reco::CaloTau * caloTau = dynamic_cast(aTauRef.get()); - if (caloTau != nullptr) caloSpecific_.push_back(pat::tau::TauCaloSpecific(*caloTau)); + initFromBaseTau(*aTauRef); } /// constructor from ref to reco::BaseTau @@ -101,12 +90,40 @@ Tau::Tau(const edm::Ptr & aTauRef) : ,embeddedIsolationPFNeutralHadrCands_(false) ,embeddedIsolationPFGammaCands_(false) { - const reco::PFTau * pfTau = dynamic_cast(aTauRef.get()); + initFromBaseTau(*aTauRef); +} + +void Tau::initFromBaseTau(const reco::BaseTau& aTau) { + const reco::PFTau * pfTau = dynamic_cast(&aTau); if (pfTau != nullptr){ - pfSpecific_.push_back(pat::tau::TauPFSpecific(*pfTau)); + // If PFTau is made from PackedCandidates, directly fill slimmed version + // without PFSpecific + const pat::PackedCandidate* pc = dynamic_cast(pfTau->leadChargedHadrCand().get()); + if (pc != nullptr) { + for (const auto& ptr : pfTau->signalChargedHadrCands()) + signalChargedHadrCandPtrs_.push_back(ptr); + + for (const auto& ptr : pfTau->signalNeutrHadrCands()) + signalNeutralHadrCandPtrs_.push_back(ptr); + + for (const auto& ptr : pfTau->signalGammaCands()) + signalGammaCandPtrs_.push_back(ptr); + + for (const auto& ptr : pfTau->isolationChargedHadrCands()) + isolationChargedHadrCandPtrs_.push_back(ptr); + + for (const auto& ptr : pfTau->isolationNeutrHadrCands()) + isolationNeutralHadrCandPtrs_.push_back(ptr); + + for (const auto& ptr : pfTau->isolationGammaCands()) + isolationGammaCandPtrs_.push_back(ptr); + } + else { + pfSpecific_.push_back(pat::tau::TauPFSpecific(*pfTau)); + } pfEssential_.push_back(pat::tau::TauPFEssential(*pfTau)); } - const reco::CaloTau * caloTau = dynamic_cast(aTauRef.get()); + const reco::CaloTau * caloTau = dynamic_cast(&aTau); if (caloTau != nullptr) caloSpecific_.push_back(pat::tau::TauCaloSpecific(*caloTau)); } @@ -326,7 +343,7 @@ void Tau::embedLeadPFCand() { } leadPFCand_.clear(); if (pfSpecific_[0].leadPFCand_.isNonnull() ) { - leadPFCand_.push_back(*pfSpecific_[0].leadPFCand_); //already set in C-tor + leadPFCand_.push_back(*static_cast(&*pfSpecific_[0].leadPFCand_)); //already set in C-tor embeddedLeadPFCand_ = true; } } @@ -337,7 +354,7 @@ void Tau::embedLeadPFChargedHadrCand() { } leadPFChargedHadrCand_.clear(); if (pfSpecific_[0].leadPFChargedHadrCand_.isNonnull() ) { - leadPFChargedHadrCand_.push_back(*pfSpecific_[0].leadPFChargedHadrCand_); //already set in C-tor + leadPFChargedHadrCand_.push_back(*static_cast(&*pfSpecific_[0].leadPFChargedHadrCand_)); //already set in C-tor embeddedLeadPFChargedHadrCand_ = true; } } @@ -348,7 +365,7 @@ void Tau::embedLeadPFNeutralCand() { } leadPFNeutralCand_.clear(); if (pfSpecific_[0].leadPFNeutralCand_.isNonnull() ) { - leadPFNeutralCand_.push_back(*pfSpecific_[0].leadPFNeutralCand_); //already set in C-tor + leadPFNeutralCand_.push_back(*static_cast(&*pfSpecific_[0].leadPFNeutralCand_)); //already set in C-tor embeddedLeadPFNeutralCand_ = true; } } @@ -359,7 +376,7 @@ void Tau::embedSignalPFCands() { } std::vector candPtrs = pfSpecific_[0].selectedSignalPFCands_; for (unsigned int i = 0; i < candPtrs.size(); i++) { - signalPFCands_.push_back(*candPtrs.at(i)); + signalPFCands_.push_back(candPtrs.at(i)); } embeddedSignalPFCands_ = true; } @@ -369,7 +386,7 @@ void Tau::embedSignalPFChargedHadrCands() { } std::vector candPtrs = pfSpecific_[0].selectedSignalPFChargedHadrCands_; for (unsigned int i = 0; i < candPtrs.size(); i++) { - signalPFChargedHadrCands_.push_back(*candPtrs.at(i)); + signalPFChargedHadrCands_.push_back(candPtrs.at(i)); } embeddedSignalPFChargedHadrCands_ = true; } @@ -379,7 +396,7 @@ void Tau::embedSignalPFNeutralHadrCands() { } std::vector candPtrs = pfSpecific_[0].selectedSignalPFNeutrHadrCands_; for (unsigned int i = 0; i < candPtrs.size(); i++) { - signalPFNeutralHadrCands_.push_back(*candPtrs.at(i)); + signalPFNeutralHadrCands_.push_back(candPtrs.at(i)); } embeddedSignalPFNeutralHadrCands_ = true; } @@ -389,7 +406,7 @@ void Tau::embedSignalPFGammaCands() { } std::vector candPtrs = pfSpecific_[0].selectedSignalPFGammaCands_; for (unsigned int i = 0; i < candPtrs.size(); i++) { - signalPFGammaCands_.push_back(*candPtrs.at(i)); + signalPFGammaCands_.push_back(candPtrs.at(i)); } embeddedSignalPFGammaCands_ = true; } @@ -400,7 +417,7 @@ void Tau::embedIsolationPFCands() { } std::vector candPtrs = pfSpecific_[0].selectedIsolationPFCands_; for (unsigned int i = 0; i < candPtrs.size(); i++) { - isolationPFCands_.push_back(*candPtrs.at(i)); + isolationPFCands_.push_back(candPtrs.at(i)); } embeddedIsolationPFCands_ = true; } @@ -411,7 +428,7 @@ void Tau::embedIsolationPFChargedHadrCands() { } std::vector candPtrs = pfSpecific_[0].selectedIsolationPFChargedHadrCands_; for (unsigned int i = 0; i < candPtrs.size(); i++) { - isolationPFChargedHadrCands_.push_back(*candPtrs.at(i)); + isolationPFChargedHadrCands_.push_back(candPtrs.at(i)); } embeddedIsolationPFChargedHadrCands_ = true; } @@ -421,7 +438,7 @@ void Tau::embedIsolationPFNeutralHadrCands() { } std::vector candPtrs = pfSpecific_[0].selectedIsolationPFNeutrHadrCands_; for (unsigned int i = 0; i < candPtrs.size(); i++) { - isolationPFNeutralHadrCands_.push_back(*candPtrs.at(i)); + isolationPFNeutralHadrCands_.push_back(candPtrs.at(i)); } embeddedIsolationPFNeutralHadrCands_ = true; } @@ -431,7 +448,7 @@ void Tau::embedIsolationPFGammaCands() { } std::vector candPtrs = pfSpecific_[0].selectedIsolationPFGammaCands_; for (unsigned int i = 0; i < candPtrs.size(); i++) { - isolationPFGammaCands_.push_back(*candPtrs.at(i)); + isolationPFGammaCands_.push_back(candPtrs.at(i)); } embeddedIsolationPFGammaCands_ = true; } @@ -445,10 +462,17 @@ reco::PFRecoTauChargedHadronRef Tau::leadTauChargedHadronCandidate() const { } } +const reco::PFCandidatePtr convertToPFCandidatePtr(const reco::CandidatePtr& ptr) { + const reco::PFCandidate* pf_cand = dynamic_cast(&*ptr); + if (pf_cand) + return edm::Ptr(ptr); + return reco::PFCandidatePtr(); +} + const reco::PFCandidatePtr Tau::leadPFChargedHadrCand() const { if(!embeddedLeadPFChargedHadrCand_){ if(pfSpecific_.empty()) return reco::PFCandidatePtr(); - else return pfSpecific().leadPFChargedHadrCand_; + else return convertToPFCandidatePtr(pfSpecific().leadPFChargedHadrCand_); }else return reco::PFCandidatePtr(&leadPFChargedHadrCand_,0); } @@ -456,7 +480,7 @@ const reco::PFCandidatePtr Tau::leadPFChargedHadrCand() const { const reco::PFCandidatePtr Tau::leadPFNeutralCand() const { if(!embeddedLeadPFNeutralCand_){ if(pfSpecific_.empty()) return reco::PFCandidatePtr(); - else return pfSpecific().leadPFNeutralCand_; + else return convertToPFCandidatePtr(pfSpecific().leadPFNeutralCand_); }else return reco::PFCandidatePtr(&leadPFNeutralCand_,0); } @@ -464,7 +488,7 @@ const reco::PFCandidatePtr Tau::leadPFNeutralCand() const { const reco::PFCandidatePtr Tau::leadPFCand() const { if(!embeddedLeadPFCand_){ if(pfSpecific_.empty()) return reco::PFCandidatePtr(); - return pfSpecific().leadPFCand_; + return convertToPFCandidatePtr(pfSpecific().leadPFCand_); }else return reco::PFCandidatePtr(&leadPFCand_,0); } @@ -484,8 +508,10 @@ const std::vector& Tau::signalPFCands() const { if(pfSpecific_.empty() || pfSpecific().selectedSignalPFCands_.empty() || !pfSpecific().selectedSignalPFCands_.front().isAvailable()){ // this part of code is called when reading from patTuple or miniAOD // it returns empty collection in correct format so it can be substituted by reco::Candidates if available - std::unique_ptr > aPtrs{new std::vector{}}; - signalPFCandsTransientPtrs_.set(std::move(aPtrs)); + if (!signalPFCandsTransientPtrs_.isSet()) { + std::unique_ptr > aPtrs{new std::vector{}}; + signalPFCandsTransientPtrs_.set(std::move(aPtrs)); + } return *signalPFCandsTransientPtrs_; } else return pfSpecific().selectedSignalPFCands_; } @@ -506,8 +532,10 @@ const std::vector& Tau::signalPFChargedHadrCands() const { if(pfSpecific_.empty() || pfSpecific().selectedSignalPFChargedHadrCands_.empty() || !pfSpecific().selectedSignalPFChargedHadrCands_.front().isAvailable()){ // this part of code is called when reading from patTuple or miniAOD // it returns empty collection in correct format so it can be substituted by reco::Candidates if available - std::unique_ptr > aPtrs{new std::vector{}}; - signalPFChargedHadrCandsTransientPtrs_.set(std::move(aPtrs)); + if (!signalPFChargedHadrCandsTransientPtrs_.isSet()) { + std::unique_ptr > aPtrs{new std::vector{}}; + signalPFChargedHadrCandsTransientPtrs_.set(std::move(aPtrs)); + } return *signalPFChargedHadrCandsTransientPtrs_; } else return pfSpecific().selectedSignalPFChargedHadrCands_; } @@ -528,8 +556,10 @@ const std::vector& Tau::signalPFNeutrHadrCands() const { if(pfSpecific_.empty() || pfSpecific().selectedSignalPFNeutrHadrCands_.empty() || !pfSpecific().selectedSignalPFNeutrHadrCands_.front().isAvailable()){ // this part of code is called when reading from patTuple or miniAOD // it returns empty collection in correct format so it can be substituted by reco::Candidates if available - std::unique_ptr > aPtrs{new std::vector{}}; - signalPFNeutralHadrCandsTransientPtrs_.set(std::move(aPtrs)); + if (!signalPFNeutralHadrCandsTransientPtrs_.isSet()) { + std::unique_ptr > aPtrs{new std::vector{}}; + signalPFNeutralHadrCandsTransientPtrs_.set(std::move(aPtrs)); + } return *signalPFNeutralHadrCandsTransientPtrs_; } else return pfSpecific().selectedSignalPFNeutrHadrCands_; } @@ -550,8 +580,10 @@ const std::vector& Tau::signalPFGammaCands() const { if(pfSpecific_.empty() || pfSpecific().selectedSignalPFGammaCands_.empty() || !pfSpecific().selectedSignalPFGammaCands_.front().isAvailable()){ // this part of code is called when reading from patTuple or miniAOD // it returns empty collection in correct format so it can be substituted by reco::Candidates if available - std::unique_ptr > aPtrs{new std::vector{}}; - signalPFGammaCandsTransientPtrs_.set(std::move(aPtrs)); + if (!signalPFGammaCandsTransientPtrs_.isSet()) { + std::unique_ptr > aPtrs{new std::vector{}}; + signalPFGammaCandsTransientPtrs_.set(std::move(aPtrs)); + } return *signalPFGammaCandsTransientPtrs_; } else return pfSpecific().selectedSignalPFGammaCands_; } @@ -582,8 +614,10 @@ const std::vector& Tau::isolationPFCands() const { if(pfSpecific_.empty() || pfSpecific().selectedIsolationPFCands_.empty() || !pfSpecific().selectedIsolationPFCands_.front().isAvailable()){ // this part of code is called when reading from patTuple or miniAOD // it returns empty collection in correct format so it can be substituted by reco::Candidates if available - std::unique_ptr > aPtrs{new std::vector{}}; - isolationPFCandsTransientPtrs_.set(std::move(aPtrs)); + if (!isolationPFCandsTransientPtrs_.isSet()) { + std::unique_ptr > aPtrs{new std::vector{}}; + isolationPFCandsTransientPtrs_.set(std::move(aPtrs)); + } return *isolationPFCandsTransientPtrs_; } else return pfSpecific().selectedIsolationPFCands_; } @@ -604,8 +638,10 @@ const std::vector& Tau::isolationPFChargedHadrCands() cons if(pfSpecific_.empty() || pfSpecific().selectedIsolationPFChargedHadrCands_.empty() || !pfSpecific().selectedIsolationPFChargedHadrCands_.front().isAvailable()){ // this part of code is called when reading from patTuple or miniAOD // it returns empty collection in correct format so it can be substituted by reco::Candidates if available - std::unique_ptr > aPtrs{new std::vector{}}; - isolationPFChargedHadrCandsTransientPtrs_.set(std::move(aPtrs)); + if (!isolationPFChargedHadrCandsTransientPtrs_.isSet()) { + std::unique_ptr > aPtrs{new std::vector{}}; + isolationPFChargedHadrCandsTransientPtrs_.set(std::move(aPtrs)); + } return *isolationPFChargedHadrCandsTransientPtrs_; } else return pfSpecific().selectedIsolationPFChargedHadrCands_; } @@ -626,8 +662,10 @@ const std::vector& Tau::isolationPFNeutrHadrCands() const if(pfSpecific_.empty() || pfSpecific().selectedIsolationPFNeutrHadrCands_.empty() || !pfSpecific().selectedIsolationPFNeutrHadrCands_.front().isAvailable()){ // this part of code is called when reading from patTuple or miniAOD // it returns empty collection in correct format so it can be substituted by reco::Candidates if available - std::unique_ptr > aPtrs{new std::vector{}}; - isolationPFNeutralHadrCandsTransientPtrs_.set(std::move(aPtrs)); + if (!isolationPFNeutralHadrCandsTransientPtrs_.isSet()) { + std::unique_ptr > aPtrs{new std::vector{}}; + isolationPFNeutralHadrCandsTransientPtrs_.set(std::move(aPtrs)); + } return *isolationPFNeutralHadrCandsTransientPtrs_; } else return pfSpecific().selectedIsolationPFNeutrHadrCands_; } @@ -648,8 +686,10 @@ const std::vector& Tau::isolationPFGammaCands() const { if(pfSpecific_.empty() || pfSpecific().selectedIsolationPFGammaCands_.empty() || !pfSpecific().selectedIsolationPFGammaCands_.front().isAvailable()){ // this part of code is called when reading from patTuple or miniAOD // it returns empty collection in correct format so it can be substituted by reco::Candidates if available - std::unique_ptr > aPtrs{new std::vector{}}; - isolationPFGammaCandsTransientPtrs_.set(std::move(aPtrs)); + if (!isolationPFGammaCandsTransientPtrs_.isSet()) { + std::unique_ptr > aPtrs{new std::vector{}}; + isolationPFGammaCandsTransientPtrs_.set(std::move(aPtrs)); + } return *isolationPFGammaCandsTransientPtrs_; } else return pfSpecific().selectedIsolationPFGammaCands_; } diff --git a/DataFormats/PatCandidates/src/classes_def_objects.xml b/DataFormats/PatCandidates/src/classes_def_objects.xml index 5392ee53572b2..528ecfb3191f4 100644 --- a/DataFormats/PatCandidates/src/classes_def_objects.xml +++ b/DataFormats/PatCandidates/src/classes_def_objects.xml @@ -164,7 +164,8 @@ - + + @@ -173,6 +174,7 @@ + @@ -617,6 +619,16 @@ + + + + + + + + + + diff --git a/DataFormats/PatCandidates/src/classes_objects.h b/DataFormats/PatCandidates/src/classes_objects.h index 10065b7cd826c..1d3384eae3a93 100644 --- a/DataFormats/PatCandidates/src/classes_objects.h +++ b/DataFormats/PatCandidates/src/classes_objects.h @@ -1,5 +1,6 @@ #include "DataFormats/Common/interface/ValueMap.h" #include "DataFormats/Common/interface/Association.h" +#include "DataFormats/Common/interface/AssociationMap.h" #include "DataFormats/Common/interface/Wrapper.h" #include "DataFormats/Common/interface/PtrVector.h" #include "DataFormats/Common/interface/FwdPtr.h" diff --git a/DataFormats/TauReco/interface/JetPiZeroAssociation.h b/DataFormats/TauReco/interface/JetPiZeroAssociation.h index bf351a682b42b..697cb283e2cf1 100644 --- a/DataFormats/TauReco/interface/JetPiZeroAssociation.h +++ b/DataFormats/TauReco/interface/JetPiZeroAssociation.h @@ -3,12 +3,12 @@ #include "DataFormats/Common/interface/AssociationVector.h" #include "DataFormats/TauReco/interface/RecoTauPiZero.h" -#include "DataFormats/JetReco/interface/PFJetCollection.h" +#include "DataFormats/JetReco/interface/JetCollection.h" namespace reco { // This base class improves the readability of the ROOT class name by hiding // the template crap - typedef edm::AssociationVector > > + typedef edm::AssociationVector > > JetPiZeroAssociationBase; class JetPiZeroAssociation : public JetPiZeroAssociationBase { @@ -17,7 +17,7 @@ namespace reco { JetPiZeroAssociationBase() { } - JetPiZeroAssociation(const reco::PFJetRefProd & ref) : + JetPiZeroAssociation(const JetRefBaseProd & ref) : JetPiZeroAssociationBase(ref) { } diff --git a/DataFormats/TauReco/interface/PFJetChargedHadronAssociation.h b/DataFormats/TauReco/interface/PFJetChargedHadronAssociation.h index 28a13e4f67aed..4a5f2f6acba2e 100644 --- a/DataFormats/TauReco/interface/PFJetChargedHadronAssociation.h +++ b/DataFormats/TauReco/interface/PFJetChargedHadronAssociation.h @@ -3,13 +3,13 @@ #include "DataFormats/Common/interface/AssociationVector.h" #include "DataFormats/TauReco/interface/PFRecoTauChargedHadron.h" -#include "DataFormats/JetReco/interface/PFJetCollection.h" +#include "DataFormats/JetReco/interface/JetCollection.h" namespace reco { // This base class improves the readability of the ROOT class name by hiding // the template crap - typedef edm::AssociationVector > > PFJetChargedHadronAssociationBase; + typedef edm::AssociationVector > > PFJetChargedHadronAssociationBase; class PFJetChargedHadronAssociation : public PFJetChargedHadronAssociationBase { @@ -18,7 +18,7 @@ namespace reco : PFJetChargedHadronAssociationBase() {} - PFJetChargedHadronAssociation(const reco::PFJetRefProd& ref) + PFJetChargedHadronAssociation(const reco::JetRefBaseProd& ref) : PFJetChargedHadronAssociationBase(ref) {} diff --git a/DataFormats/TauReco/interface/PFRecoTauChargedHadron.h b/DataFormats/TauReco/interface/PFRecoTauChargedHadron.h index 1b00b64f058e2..833bc806a280e 100644 --- a/DataFormats/TauReco/interface/PFRecoTauChargedHadron.h +++ b/DataFormats/TauReco/interface/PFRecoTauChargedHadron.h @@ -2,14 +2,15 @@ #define DataFormats_TauReco_PFRecoTauChargedHadron_h #include "DataFormats/Candidate/interface/CompositePtrCandidate.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "DataFormats/Candidate/interface/CandidateFwd.h" #include "DataFormats/TrackReco/interface/Track.h" #include "DataFormats/Common/interface/Ptr.h" #include "DataFormats/Math/interface/Point3D.h" namespace reco { namespace tau { + template + class PFRecoTauChargedHadronFromGenericTrackPlugin; class PFRecoTauChargedHadronFromPFCandidatePlugin; - class PFRecoTauChargedHadronFromTrackPlugin; class RecoTauConstructor; class PFRecoTauEnergyAlgorithmPlugin; }} @@ -47,13 +48,16 @@ class PFRecoTauChargedHadron : public CompositePtrCandidate ~PFRecoTauChargedHadron() override; /// reference to "charged" PFCandidate (either charged PFCandidate or PFNeutralHadron) - const PFCandidatePtr& getChargedPFCandidate() const; + const CandidatePtr& getChargedPFCandidate() const; /// reference to reco::Track const TrackPtr& getTrack() const; + /// reference to "lostTrack Candidate" when chadron built with tracks stored as pat::PackedCandidates + const CandidatePtr& getLostTrackCandidate() const; + /// references to additional neutral PFCandidates - const std::vector& getNeutralPFCandidates() const; + const std::vector& getNeutralPFCandidates() const; /// position at ECAL entrance const math::XYZPointF& positionAtECALEntrance() const; @@ -68,16 +72,18 @@ class PFRecoTauChargedHadron : public CompositePtrCandidate private: friend class tau::PFRecoTauChargedHadronFromPFCandidatePlugin; - friend class tau::PFRecoTauChargedHadronFromTrackPlugin; + template + friend class tau::PFRecoTauChargedHadronFromGenericTrackPlugin; friend class tau::RecoTauConstructor; friend class tau::PFRecoTauEnergyAlgorithmPlugin; friend class ::PFRecoTauChargedHadronProducer; PFRecoTauChargedHadronAlgorithm algo_; - PFCandidatePtr chargedPFCandidate_; + CandidatePtr chargedPFCandidate_; + CandidatePtr lostTrackCandidate_; TrackPtr track_; - std::vector neutralPFCandidates_; + std::vector neutralPFCandidates_; math::XYZPointF positionAtECALEntrance_; }; diff --git a/DataFormats/TauReco/interface/PFTau.h b/DataFormats/TauReco/interface/PFTau.h index cd8c28fc87b53..65f0f8fb2f902 100644 --- a/DataFormats/TauReco/interface/PFTau.h +++ b/DataFormats/TauReco/interface/PFTau.h @@ -13,9 +13,9 @@ #include "DataFormats/TauReco/interface/BaseTau.h" #include "DataFormats/TauReco/interface/PFTauFwd.h" #include "DataFormats/TauReco/interface/PFTauTagInfo.h" -#include "DataFormats/JetReco/interface/PFJetCollection.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "DataFormats/JetReco/interface/JetCollection.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "DataFormats/Candidate/interface/CandidateFwd.h" #include "DataFormats/TauReco/interface/RecoTauPiZero.h" #include "DataFormats/TauReco/interface/RecoTauPiZeroFwd.h" #include "DataFormats/TauReco/interface/PFRecoTauChargedHadron.h" @@ -58,59 +58,72 @@ class PFTau : public BaseTau { ~PFTau() override {}; PFTau* clone() const override; - const PFJetRef& jetRef() const; - void setjetRef(const PFJetRef&); + const JetBaseRef& jetRef() const; + void setjetRef(const JetBaseRef&); // functions to access the PFTauTagInfoRef used by HLT const PFTauTagInfoRef& pfTauTagInfoRef() const; void setpfTauTagInfoRef(const PFTauTagInfoRef); PFRecoTauChargedHadronRef leadTauChargedHadronCandidate() const; - const PFCandidatePtr& leadPFChargedHadrCand() const; - const PFCandidatePtr& leadPFNeutralCand() const; + const CandidatePtr& leadChargedHadrCand() const; + const CandidatePtr& leadNeutralCand() const; //Can be either the charged or the neutral one - const PFCandidatePtr& leadPFCand() const; + const CandidatePtr& leadCand() const; - void setleadPFChargedHadrCand(const PFCandidatePtr&); - void setleadPFNeutralCand(const PFCandidatePtr&); - void setleadPFCand(const PFCandidatePtr&); + void setleadChargedHadrCand(const CandidatePtr&); + void setleadNeutralCand(const CandidatePtr&); + void setleadCand(const CandidatePtr&); /// Signed transverse impact parameter significance of the Track /// associated to the leading charged PFCandidate float leadPFChargedHadrCandsignedSipt() const; void setleadPFChargedHadrCandsignedSipt(const float&); - /// PFCandidates in signal region - const std::vector& signalPFCands() const; - void setsignalPFCands(const std::vector&); + /// Candidates in signal region + const std::vector& signalCands() const; + void setsignalCands(const std::vector&); /// Charged hadrons in signal region - const std::vector& signalPFChargedHadrCands() const; - void setsignalPFChargedHadrCands(const std::vector&); + const std::vector& signalChargedHadrCands() const; + void setsignalChargedHadrCands(const std::vector&); /// Neutral hadrons in signal region - const std::vector& signalPFNeutrHadrCands() const; - void setsignalPFNeutrHadrCands(const std::vector&); + const std::vector& signalNeutrHadrCands() const; + void setsignalNeutrHadrCands(const std::vector&); /// Gamma candidates in signal region - const std::vector& signalPFGammaCands() const; - void setsignalPFGammaCands(const std::vector&); + const std::vector& signalGammaCands() const; + void setsignalGammaCands(const std::vector&); - /// PFCandidates in isolation region - const std::vector& isolationPFCands() const; - void setisolationPFCands(const std::vector&); + /// Candidates in isolation region + const std::vector& isolationCands() const; + void setisolationCands(const std::vector&); /// Charged candidates in isolation region - const std::vector& isolationPFChargedHadrCands() const; - void setisolationPFChargedHadrCands(const std::vector&); + const std::vector& isolationChargedHadrCands() const; + void setisolationChargedHadrCands(const std::vector&); //// Neutral hadrons in isolation region - const std::vector& isolationPFNeutrHadrCands() const; - void setisolationPFNeutrHadrCands(const std::vector&); + const std::vector& isolationNeutrHadrCands() const; + void setisolationNeutrHadrCands(const std::vector&); /// Gamma candidates in isolation region + const std::vector& isolationGammaCands() const; + void setisolationGammaCands(const std::vector&); + + /// Getters for different PFCandidates for PFTaus made from PFCandidates + const PFCandidatePtr leadPFChargedHadrCand() const; + const PFCandidatePtr leadPFNeutralCand() const; + const PFCandidatePtr leadPFCand() const; + const std::vector& signalPFCands() const; + const std::vector& signalPFChargedHadrCands() const; + const std::vector& signalPFNeutrHadrCands() const; + const std::vector& signalPFGammaCands() const; + const std::vector& isolationPFCands() const; + const std::vector& isolationPFChargedHadrCands() const; + const std::vector& isolationPFNeutrHadrCands() const; const std::vector& isolationPFGammaCands() const; - void setisolationPFGammaCands(const std::vector&); /// Sum of charged hadron candidate PT in isolation cone; returns NaN /// if isolation region is undefined. @@ -244,24 +257,39 @@ class PFTau : public BaseTau { float signalConeSize_; - reco::PFJetRef jetRef_; + reco::JetBaseRef jetRef_; PFTauTagInfoRef PFTauTagInfoRef_; - reco::PFCandidatePtr leadPFChargedHadrCand_; - reco::PFCandidatePtr leadPFNeutralCand_; - reco::PFCandidatePtr leadPFCand_; + reco::CandidatePtr leadChargedHadrCand_; + reco::CandidatePtr leadNeutralCand_; + reco::CandidatePtr leadCand_; reco::TrackRef electronPreIDTrack_; // Signal candidates - std::vector selectedSignalPFCands_; - std::vector selectedSignalPFChargedHadrCands_; - std::vector selectedSignalPFNeutrHadrCands_; - std::vector selectedSignalPFGammaCands_; + std::vector selectedSignalCands_; + std::vector selectedSignalChargedHadrCands_; + std::vector selectedSignalNeutrHadrCands_; + std::vector selectedSignalGammaCands_; // Isolation candidates - std::vector selectedIsolationPFCands_; - std::vector selectedIsolationPFChargedHadrCands_; - std::vector selectedIsolationPFNeutrHadrCands_; - std::vector selectedIsolationPFGammaCands_; + std::vector selectedIsolationCands_; + std::vector selectedIsolationChargedHadrCands_; + std::vector selectedIsolationNeutrHadrCands_; + std::vector selectedIsolationGammaCands_; + + // Transient caches for PFCandidate-based accessors + edm::AtomicPtrCache leadPFChargedHadrCand_; + edm::AtomicPtrCache leadPFNeutralCand_; + edm::AtomicPtrCache leadPFCand_; + + edm::AtomicPtrCache > selectedTransientSignalPFCands_; + edm::AtomicPtrCache > selectedTransientSignalPFChargedHadrCands_; + edm::AtomicPtrCache > selectedTransientSignalPFNeutrHadrCands_; + edm::AtomicPtrCache > selectedTransientSignalPFGammaCands_; + + edm::AtomicPtrCache > selectedTransientIsolationPFCands_; + edm::AtomicPtrCache > selectedTransientIsolationPFChargedHadrCands_; + edm::AtomicPtrCache > selectedTransientIsolationPFNeutrHadrCands_; + edm::AtomicPtrCache > selectedTransientIsolationPFGammaCands_; RecoTauPiZeroRefVector signalPiZeroCandidatesRefs_; RecoTauPiZeroRefVector isolationPiZeroCandidatesRefs_; diff --git a/DataFormats/TauReco/interface/PFTauTagInfo.h b/DataFormats/TauReco/interface/PFTauTagInfo.h index 6b6df4c20603b..7f4e6f82b3912 100644 --- a/DataFormats/TauReco/interface/PFTauTagInfo.h +++ b/DataFormats/TauReco/interface/PFTauTagInfo.h @@ -11,7 +11,7 @@ #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" -#include "DataFormats/JetReco/interface/PFJetCollection.h" +#include "DataFormats/JetReco/interface/JetCollection.h" #include "DataFormats/TauReco/interface/PFTauTagInfoFwd.h" #include "DataFormats/TauReco/interface/BaseTauTagInfo.h" @@ -24,22 +24,22 @@ namespace reco{ virtual PFTauTagInfo* clone()const; //get the PFCandidates which compose the PF jet and were filtered by RecoTauTag/TauTagTools/ TauTagTools::filteredPFChargedHadrCands(.,...), filteredPFNeutrHadrCands(.), filteredPFGammaCands(.) functions through RecoTauTag/RecoTauTag/ PFRecoTauTagInfoProducer EDProducer - std::vector PFCands()const; - const std::vector& PFChargedHadrCands()const; - void setPFChargedHadrCands(const std::vector&); - const std::vector& PFNeutrHadrCands()const; - void setPFNeutrHadrCands(const std::vector&); - const std::vector& PFGammaCands()const; - void setPFGammaCands(const std::vector&); + std::vector PFCands()const; + const std::vector& PFChargedHadrCands()const; + void setPFChargedHadrCands(const std::vector&); + const std::vector& PFNeutrHadrCands()const; + void setPFNeutrHadrCands(const std::vector&); + const std::vector& PFGammaCands()const; + void setPFGammaCands(const std::vector&); //the reference to the PFJet - const PFJetRef& pfjetRef()const; - void setpfjetRef(const PFJetRef); + const JetBaseRef& pfjetRef()const; + void setpfjetRef(const JetBaseRef); private: - PFJetRef PFJetRef_; - std::vector PFChargedHadrCands_; - std::vector PFNeutrHadrCands_; - std::vector PFGammaCands_; + JetBaseRef PFJetRef_; + std::vector PFChargedHadrCands_; + std::vector PFNeutrHadrCands_; + std::vector PFGammaCands_; }; } #endif diff --git a/DataFormats/TauReco/src/PFRecoTauChargedHadron.cc b/DataFormats/TauReco/src/PFRecoTauChargedHadron.cc index 898a4aa582b6e..be50d24d05472 100644 --- a/DataFormats/TauReco/src/PFRecoTauChargedHadron.cc +++ b/DataFormats/TauReco/src/PFRecoTauChargedHadron.cc @@ -39,7 +39,7 @@ PFRecoTauChargedHadron::PFRecoTauChargedHadron(const Candidate& c, PFRecoTauChar PFRecoTauChargedHadron::~PFRecoTauChargedHadron() {} -const PFCandidatePtr& PFRecoTauChargedHadron::getChargedPFCandidate() const +const CandidatePtr& PFRecoTauChargedHadron::getChargedPFCandidate() const { return chargedPFCandidate_; } @@ -49,7 +49,12 @@ const PFRecoTauChargedHadron::TrackPtr& PFRecoTauChargedHadron::getTrack() const return track_; } -const std::vector& PFRecoTauChargedHadron::getNeutralPFCandidates() const +const CandidatePtr& PFRecoTauChargedHadron::getLostTrackCandidate() const +{ + return lostTrackCandidate_; +} + +const std::vector& PFRecoTauChargedHadron::getNeutralPFCandidates() const { return neutralPFCandidates_; } @@ -69,22 +74,6 @@ bool PFRecoTauChargedHadron::algoIs(PFRecoTauChargedHadron::PFRecoTauChargedHadr return (algo_ == algo); } -namespace -{ - std::string getPFCandidateType(reco::PFCandidate::ParticleType pfCandidateType) - { - if ( pfCandidateType == reco::PFCandidate::X ) return "undefined"; - else if ( pfCandidateType == reco::PFCandidate::h ) return "PFChargedHadron"; - else if ( pfCandidateType == reco::PFCandidate::e ) return "PFElectron"; - else if ( pfCandidateType == reco::PFCandidate::mu ) return "PFMuon"; - else if ( pfCandidateType == reco::PFCandidate::gamma ) return "PFGamma"; - else if ( pfCandidateType == reco::PFCandidate::h0 ) return "PFNeutralHadron"; - else if ( pfCandidateType == reco::PFCandidate::h_HF ) return "HF_had"; - else if ( pfCandidateType == reco::PFCandidate::egamma_HF ) return "HF_em"; - else assert(0); - } -} - void PFRecoTauChargedHadron::print(std::ostream& stream) const { stream << " Pt = " << this->pt() << ", eta = " << this->eta() << ", phi = " << this->phi() << " (mass = " << this->mass() << ")" << std::endl; @@ -93,13 +82,16 @@ void PFRecoTauChargedHadron::print(std::ostream& stream) const if ( chargedPFCandidate_.isNonnull() ) { stream << " (" << chargedPFCandidate_.id() << ":" << chargedPFCandidate_.key() << "):" << " Pt = " << chargedPFCandidate_->pt() << ", eta = " << chargedPFCandidate_->eta() << ", phi = " << chargedPFCandidate_->phi() - << " (type = " << getPFCandidateType(chargedPFCandidate_->particleId()) << ")" << std::endl; + << " (pdgId = " << chargedPFCandidate_->pdgId() << ")" << std::endl; } else { stream << ": N/A" << std::endl; } stream << "reco::Track: "; if ( track_.isNonnull() ) { stream << "Pt = " << track_->pt() << " +/- " << track_->ptError() << ", eta = " << track_->eta() << ", phi = " << track_->phi() << std::endl; + } else if ( lostTrackCandidate_.isNonnull() ) { + stream << "(lostTrackCandidate: " << lostTrackCandidate_.id() << ":" << lostTrackCandidate_.key() << "):" + << " Pt = " << lostTrackCandidate_->pt() << ", eta = " << lostTrackCandidate_->eta() << ", phi = " << lostTrackCandidate_->phi() << std::endl; } else { stream << "N/A" << std::endl; } @@ -107,11 +99,11 @@ void PFRecoTauChargedHadron::print(std::ostream& stream) const if ( !neutralPFCandidates_.empty() ) { stream << std::endl; int idx = 0; - for ( std::vector::const_iterator neutralPFCandidate = neutralPFCandidates_.begin(); + for ( std::vector::const_iterator neutralPFCandidate = neutralPFCandidates_.begin(); neutralPFCandidate != neutralPFCandidates_.end(); ++neutralPFCandidate ) { stream << " #" << idx << " (" << neutralPFCandidate->id() << ":" << neutralPFCandidate->key() << "):" << " Pt = " << (*neutralPFCandidate)->pt() << ", eta = " << (*neutralPFCandidate)->eta() << ", phi = " << (*neutralPFCandidate)->phi() - << " (type = " << getPFCandidateType((*neutralPFCandidate)->particleId()) << ")" << std::endl; + << " (pdgId = " << (*neutralPFCandidate)->pdgId() << ")" << std::endl; ++idx; } } else { diff --git a/DataFormats/TauReco/src/PFTau.cc b/DataFormats/TauReco/src/PFTau.cc index 2beeec970273e..ddb1551d416c7 100644 --- a/DataFormats/TauReco/src/PFTau.cc +++ b/DataFormats/TauReco/src/PFTau.cc @@ -55,8 +55,8 @@ PFTau::PFTau(Charge q, const LorentzVector& p4, const Point& vtx) PFTau* PFTau::clone() const { return new PFTau(*this); } // Constituent getters and setters -const PFJetRef& PFTau::jetRef() const { return jetRef_; } -void PFTau::setjetRef(const PFJetRef& x) { jetRef_ = x; } +const JetBaseRef& PFTau::jetRef() const { return jetRef_; } +void PFTau::setjetRef(const JetBaseRef& x) { jetRef_ = x; } const PFTauTagInfoRef& PFTau::pfTauTagInfoRef() const { return PFTauTagInfoRef_; @@ -64,34 +64,34 @@ const PFTauTagInfoRef& PFTau::pfTauTagInfoRef() const { void PFTau::setpfTauTagInfoRef(const PFTauTagInfoRef x) { PFTauTagInfoRef_ = x; } -const PFCandidatePtr& PFTau::leadPFChargedHadrCand() const { return leadPFChargedHadrCand_; } -const PFCandidatePtr& PFTau::leadPFNeutralCand() const { return leadPFNeutralCand_; } -const PFCandidatePtr& PFTau::leadPFCand() const { return leadPFCand_; } +const CandidatePtr& PFTau::leadChargedHadrCand() const { return leadChargedHadrCand_; } +const CandidatePtr& PFTau::leadNeutralCand() const { return leadNeutralCand_; } +const CandidatePtr& PFTau::leadCand() const { return leadCand_; } -void PFTau::setleadPFChargedHadrCand(const PFCandidatePtr& myLead) { leadPFChargedHadrCand_ = myLead;} -void PFTau::setleadPFNeutralCand(const PFCandidatePtr& myLead) { leadPFNeutralCand_ = myLead;} -void PFTau::setleadPFCand(const PFCandidatePtr& myLead) { leadPFCand_ = myLead;} +void PFTau::setleadChargedHadrCand(const CandidatePtr& myLead) { leadChargedHadrCand_ = myLead;} +void PFTau::setleadNeutralCand(const CandidatePtr& myLead) { leadNeutralCand_ = myLead;} +void PFTau::setleadCand(const CandidatePtr& myLead) { leadCand_ = myLead;} float PFTau::leadPFChargedHadrCandsignedSipt() const { return leadPFChargedHadrCandsignedSipt_; } void PFTau::setleadPFChargedHadrCandsignedSipt(const float& x){ leadPFChargedHadrCandsignedSipt_ = x; } -const std::vector& PFTau::signalPFCands() const { return selectedSignalPFCands_; } -void PFTau::setsignalPFCands(const std::vector& myParts) { selectedSignalPFCands_ = myParts; } -const std::vector& PFTau::signalPFChargedHadrCands() const { return selectedSignalPFChargedHadrCands_; } -void PFTau::setsignalPFChargedHadrCands(const std::vector& myParts) { selectedSignalPFChargedHadrCands_ = myParts; } -const std::vector& PFTau::signalPFNeutrHadrCands() const {return selectedSignalPFNeutrHadrCands_; } -void PFTau::setsignalPFNeutrHadrCands(const std::vector& myParts) { selectedSignalPFNeutrHadrCands_ = myParts; } -const std::vector& PFTau::signalPFGammaCands() const { return selectedSignalPFGammaCands_; } -void PFTau::setsignalPFGammaCands(const std::vector& myParts) { selectedSignalPFGammaCands_ = myParts; } - -const std::vector& PFTau::isolationPFCands() const { return selectedIsolationPFCands_; } -void PFTau::setisolationPFCands(const std::vector& myParts) { selectedIsolationPFCands_ = myParts;} -const std::vector& PFTau::isolationPFChargedHadrCands() const { return selectedIsolationPFChargedHadrCands_; } -void PFTau::setisolationPFChargedHadrCands(const std::vector& myParts) { selectedIsolationPFChargedHadrCands_ = myParts; } -const std::vector& PFTau::isolationPFNeutrHadrCands() const { return selectedIsolationPFNeutrHadrCands_; } -void PFTau::setisolationPFNeutrHadrCands(const std::vector& myParts) { selectedIsolationPFNeutrHadrCands_ = myParts; } -const std::vector& PFTau::isolationPFGammaCands() const { return selectedIsolationPFGammaCands_; } -void PFTau::setisolationPFGammaCands(const std::vector& myParts) { selectedIsolationPFGammaCands_ = myParts; } +const std::vector& PFTau::signalCands() const { return selectedSignalCands_; } +void PFTau::setsignalCands(const std::vector& myParts) { selectedSignalCands_ = myParts; } +const std::vector& PFTau::signalChargedHadrCands() const { return selectedSignalChargedHadrCands_; } +void PFTau::setsignalChargedHadrCands(const std::vector& myParts) { selectedSignalChargedHadrCands_ = myParts; } +const std::vector& PFTau::signalNeutrHadrCands() const {return selectedSignalNeutrHadrCands_; } +void PFTau::setsignalNeutrHadrCands(const std::vector& myParts) { selectedSignalNeutrHadrCands_ = myParts; } +const std::vector& PFTau::signalGammaCands() const { return selectedSignalGammaCands_; } +void PFTau::setsignalGammaCands(const std::vector& myParts) { selectedSignalGammaCands_ = myParts; } + +const std::vector& PFTau::isolationCands() const { return selectedIsolationCands_; } +void PFTau::setisolationCands(const std::vector& myParts) { selectedIsolationCands_ = myParts;} +const std::vector& PFTau::isolationChargedHadrCands() const { return selectedIsolationChargedHadrCands_; } +void PFTau::setisolationChargedHadrCands(const std::vector& myParts) { selectedIsolationChargedHadrCands_ = myParts; } +const std::vector& PFTau::isolationNeutrHadrCands() const { return selectedIsolationNeutrHadrCands_; } +void PFTau::setisolationNeutrHadrCands(const std::vector& myParts) { selectedIsolationNeutrHadrCands_ = myParts; } +const std::vector& PFTau::isolationGammaCands() const { return selectedIsolationGammaCands_; } +void PFTau::setisolationGammaCands(const std::vector& myParts) { selectedIsolationGammaCands_ = myParts; } namespace { @@ -121,8 +121,111 @@ namespace { oCache.reset(); oCache.set( std::make_unique(std::move(iFrom))); } + + 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) { + std::unique_ptr > newSignalPFCands{new std::vector{}}; + bool isPF = false; + for (auto& cand : cands) { + // Check for first Candidate if it is a PFCandidate; if yes, skip for the rest + if (!isPF) { + const reco::PFCandidate* pf_cand = dynamic_cast(&*cand); + if (pf_cand != nullptr) { + isPF = true; + newSignalPFCands->reserve(cands.size()); + } else throw cms::Exception("Type Mismatch") << "This PFTau was not made from PFCandidates, but it is being tried to access PFCandidates.\n"; + } + const auto& newPtr = edm::Ptr(cand); + newSignalPFCands->push_back(newPtr); + } + return newSignalPFCands; + } +} + +const PFCandidatePtr PFTau::leadPFChargedHadrCand() const { + if (!leadPFChargedHadrCand_.isSet()) + leadPFChargedHadrCand_.set(convertToPFPtr(leadChargedHadrCand_)); + return *leadPFChargedHadrCand_; +} + +const PFCandidatePtr PFTau::leadPFNeutralCand() const { + if (!leadPFNeutralCand_.isSet()) + leadPFNeutralCand_.set(convertToPFPtr(leadNeutralCand_)); + return *leadPFNeutralCand_; +} + +const PFCandidatePtr PFTau::leadPFCand() const { + if (!leadPFCand_.isSet()) + leadPFCand_.set(convertToPFPtr(leadCand_)); + return *leadPFCand_; +} + +const std::vector& PFTau::signalPFCands() const { + if (!selectedTransientSignalPFCands_.isSet()) { + selectedTransientSignalPFCands_.set(convertToPFPtrs(selectedSignalCands_)); + } + return *selectedTransientSignalPFCands_; } +const std::vector& PFTau::signalPFChargedHadrCands() const { + if (!selectedTransientSignalPFChargedHadrCands_.isSet()) { + selectedTransientSignalPFChargedHadrCands_.set(convertToPFPtrs(selectedSignalChargedHadrCands_)); + } + return *selectedTransientSignalPFChargedHadrCands_; +} + +const std::vector& PFTau::signalPFNeutrHadrCands() const { + if (!selectedTransientSignalPFNeutrHadrCands_.isSet()) { + selectedTransientSignalPFNeutrHadrCands_.set(convertToPFPtrs(selectedSignalNeutrHadrCands_)); + } + return *selectedTransientSignalPFNeutrHadrCands_; +} + +const std::vector& PFTau::signalPFGammaCands() const { + if (!selectedTransientSignalPFGammaCands_.isSet()) { + selectedTransientSignalPFGammaCands_.set(convertToPFPtrs(selectedSignalGammaCands_)); + } + return *selectedTransientSignalPFGammaCands_; +} + +const std::vector& PFTau::isolationPFCands() const { + if (!selectedTransientIsolationPFCands_.isSet()) { + selectedTransientIsolationPFCands_.set(convertToPFPtrs(selectedIsolationCands_)); + } + return *selectedTransientIsolationPFCands_; +} + +const std::vector& PFTau::isolationPFChargedHadrCands() const { + if (!selectedTransientIsolationPFChargedHadrCands_.isSet()) { + selectedTransientIsolationPFChargedHadrCands_.set(convertToPFPtrs(selectedIsolationChargedHadrCands_)); + } + return *selectedTransientIsolationPFChargedHadrCands_; +} + +const std::vector& PFTau::isolationPFNeutrHadrCands() const { + if (!selectedTransientIsolationPFNeutrHadrCands_.isSet()) { + selectedTransientIsolationPFNeutrHadrCands_.set(convertToPFPtrs(selectedIsolationNeutrHadrCands_)); + } + return *selectedTransientIsolationPFNeutrHadrCands_; +} + +const std::vector& PFTau::isolationPFGammaCands() const { + if (!selectedTransientIsolationPFGammaCands_.isSet()) { + selectedTransientIsolationPFGammaCands_.set(convertToPFPtrs(selectedIsolationGammaCands_)); + } + return *selectedTransientIsolationPFGammaCands_; +} + + // PiZero and decay mode information const std::vector& PFTau::signalPiZeroCandidates() const { // Check if the signal pi zeros are already filled @@ -246,11 +349,14 @@ void PFTau::setelectronPreIDDecision(const bool& x) {electronPreIDDecision_ = x; // Muon variables bool PFTau::hasMuonReference() const { // check if muon ref exists - if( leadPFChargedHadrCand_.isNull() ) return false; - else if( leadPFChargedHadrCand_.isNonnull() ){ - reco::MuonRef muonRef = leadPFChargedHadrCand_->muonRef(); - if( muonRef.isNull() ) return false; - else if( muonRef.isNonnull() ) return true; + if( leadChargedHadrCand_.isNull() ) return false; + else if( leadChargedHadrCand_.isNonnull() ){ + const reco::PFCandidate* pf_cand = dynamic_cast(&*leadChargedHadrCand_); + if (pf_cand) { + reco::MuonRef muonRef = pf_cand->muonRef(); + if( muonRef.isNull() ) return false; + else if( muonRef.isNonnull() ) return true; + } } return false; } @@ -264,7 +370,7 @@ void PFTau::setMuonDecision(const bool& x) {muonDecision_ = x;} CandidatePtr PFTau::sourceCandidatePtr( size_type i ) const { if ( i!=0 ) return CandidatePtr(); - return refToPtr(jetRef()); + return jetRef().castTo(); } @@ -284,31 +390,23 @@ void PFTau::dump(std::ostream& out) const { out<<"# PF neutral hadr. cand's "<PFNeutrHadrCands().size()<PFGammaCands().size()<chargedHadronMultiplicity()<neutralHadronMultiplicity()<photonMultiplicity()<electronMultiplicity()< PFTauTagInfo::PFCands()const{ - std::vector thePFCands; - for (std::vector::const_iterator iPFCand=PFChargedHadrCands_.begin();iPFCand!=PFChargedHadrCands_.end();iPFCand++) thePFCands.push_back(*iPFCand); - for (std::vector::const_iterator iPFCand=PFNeutrHadrCands_.begin();iPFCand!=PFNeutrHadrCands_.end();iPFCand++) thePFCands.push_back(*iPFCand); - for (std::vector::const_iterator iPFCand=PFGammaCands_.begin();iPFCand!=PFGammaCands_.end();iPFCand++) thePFCands.push_back(*iPFCand); +std::vector PFTauTagInfo::PFCands()const{ + std::vector thePFCands; + for (std::vector::const_iterator iPFCand=PFChargedHadrCands_.begin();iPFCand!=PFChargedHadrCands_.end();iPFCand++) thePFCands.push_back(*iPFCand); + for (std::vector::const_iterator iPFCand=PFNeutrHadrCands_.begin();iPFCand!=PFNeutrHadrCands_.end();iPFCand++) thePFCands.push_back(*iPFCand); + for (std::vector::const_iterator iPFCand=PFGammaCands_.begin();iPFCand!=PFGammaCands_.end();iPFCand++) thePFCands.push_back(*iPFCand); return thePFCands; } -const std::vector& PFTauTagInfo::PFChargedHadrCands() const {return PFChargedHadrCands_;} -void PFTauTagInfo::setPFChargedHadrCands(const std::vector& x){PFChargedHadrCands_=x;} -const std::vector& PFTauTagInfo::PFNeutrHadrCands() const {return PFNeutrHadrCands_;} -void PFTauTagInfo::setPFNeutrHadrCands(const std::vector& x){PFNeutrHadrCands_=x;} -const std::vector& PFTauTagInfo::PFGammaCands() const {return PFGammaCands_;} -void PFTauTagInfo::setPFGammaCands(const std::vector& x){PFGammaCands_=x;} +const std::vector& PFTauTagInfo::PFChargedHadrCands() const {return PFChargedHadrCands_;} +void PFTauTagInfo::setPFChargedHadrCands(const std::vector& x){PFChargedHadrCands_=x;} +const std::vector& PFTauTagInfo::PFNeutrHadrCands() const {return PFNeutrHadrCands_;} +void PFTauTagInfo::setPFNeutrHadrCands(const std::vector& x){PFNeutrHadrCands_=x;} +const std::vector& PFTauTagInfo::PFGammaCands() const {return PFGammaCands_;} +void PFTauTagInfo::setPFGammaCands(const std::vector& x){PFGammaCands_=x;} -const PFJetRef& PFTauTagInfo::pfjetRef()const{return PFJetRef_;} -void PFTauTagInfo::setpfjetRef(const PFJetRef x){PFJetRef_=x;} +const JetBaseRef& PFTauTagInfo::pfjetRef()const{return PFJetRef_;} +void PFTauTagInfo::setpfjetRef(const JetBaseRef x){PFJetRef_=x;} diff --git a/DataFormats/TauReco/src/classes_3.h b/DataFormats/TauReco/src/classes_3.h index 3461669048c91..51e5510aa9839 100644 --- a/DataFormats/TauReco/src/classes_3.h +++ b/DataFormats/TauReco/src/classes_3.h @@ -31,8 +31,11 @@ #include "DataFormats/TauReco/interface/PFTau3ProngSummaryFwd.h" #include "DataFormats/TauReco/interface/PFTau3ProngSummaryAssociation.h" #include "DataFormats/JetReco/interface/PFJet.h" +#include "DataFormats/JetReco/interface/Jet.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "DataFormats/PatCandidates/interface/Jet.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" #include #include diff --git a/DataFormats/TauReco/src/classes_def_1.xml b/DataFormats/TauReco/src/classes_def_1.xml index 4a30f6c431e2e..809ca1e05c138 100644 --- a/DataFormats/TauReco/src/classes_def_1.xml +++ b/DataFormats/TauReco/src/classes_def_1.xml @@ -29,7 +29,8 @@ - + + @@ -42,6 +43,39 @@ + + + + + + (cand));]]> + + + + (cand));]]> + + + + (cand));]]> + + - + + + + + + + + + + + + + @@ -39,27 +51,98 @@ - - + + & cand : onfile.selectedSignalPFCands_) { + selectedSignalCands_.push_back(edm::Ptr(cand));} + + selectedSignalChargedHadrCands_.clear(); + selectedSignalChargedHadrCands_.reserve(onfile.selectedSignalPFChargedHadrCands_.size()); + for (const auto& cand : onfile.selectedSignalPFChargedHadrCands_) + selectedSignalChargedHadrCands_.push_back(edm::Ptr(cand)); + + selectedSignalNeutrHadrCands_.clear(); + selectedSignalNeutrHadrCands_.reserve(onfile.selectedSignalPFNeutrHadrCands_.size()); + for (const auto& cand : onfile.selectedSignalPFNeutrHadrCands_) + selectedSignalNeutrHadrCands_.push_back(edm::Ptr(cand));; + + selectedSignalGammaCands_.clear(); + selectedSignalGammaCands_.reserve(onfile.selectedSignalPFGammaCands_.size()); + for (const auto& cand : onfile.selectedSignalPFGammaCands_) + selectedSignalGammaCands_.push_back(edm::Ptr(cand)); + + selectedIsolationCands_.clear(); + selectedIsolationCands_.reserve(onfile.selectedIsolationPFCands_.size()); + for (const auto& cand : onfile.selectedIsolationPFCands_) + selectedIsolationCands_.push_back(edm::Ptr(cand)); + + selectedIsolationChargedHadrCands_.clear(); + selectedIsolationChargedHadrCands_.reserve(onfile.selectedIsolationPFChargedHadrCands_.size()); + for (const auto& cand : onfile.selectedIsolationPFChargedHadrCands_) + selectedIsolationChargedHadrCands_.push_back(edm::Ptr(cand)); + + selectedIsolationNeutrHadrCands_.clear(); + selectedIsolationNeutrHadrCands_.reserve(onfile.selectedIsolationPFNeutrHadrCands_.size()); + for (const auto& cand : onfile.selectedIsolationPFNeutrHadrCands_) + selectedIsolationNeutrHadrCands_.push_back(edm::Ptr(cand)); + + selectedIsolationGammaCands_.clear(); + selectedIsolationGammaCands_.reserve(onfile.selectedIsolationPFGammaCands_.size()); + for (const auto& cand : onfile.selectedIsolationPFGammaCands_) + selectedIsolationGammaCands_.push_back(edm::Ptr(cand)); + + if (selectedSignalChargedHadrCands_.size() > 0) { + leadChargedHadrCand_ = selectedSignalChargedHadrCands_[0]; + } else { + leadChargedHadrCand_ = edm::Ptr(); + } + if (selectedSignalGammaCands_.size() > 0) { + leadNeutralCand_ = selectedSignalGammaCands_[0]; + } else { + leadNeutralCand_ = edm::Ptr(); + } + if (selectedSignalCands_.size() > 0) { + leadCand_ = selectedSignalCands_[0]; + } else { + leadCand_ = edm::Ptr(); + } + + leadPFChargedHadrCand_.reset(); + leadPFNeutralCand_.reset(); + leadPFCand_.reset(); + ]]> - - + + - - + + + + + + + + + + @@ -67,12 +150,12 @@ for(auto const& ref : onfile.selectedSignalPFCands_) { @@ -80,12 +163,12 @@ for(auto const& ref : onfile.selectedSignalPFChargedHadrCands_) { @@ -93,12 +176,12 @@ for(auto const& ref : onfile.selectedSignalPFNeutrHadrCands_) { @@ -106,12 +189,12 @@ for(auto const& ref : onfile.selectedSignalPFGammaCands_) { @@ -119,12 +202,12 @@ for(auto const& ref : onfile.selectedIsolationPFCands_) { @@ -132,12 +215,12 @@ for(auto const& ref : onfile.selectedIsolationPFChargedHadrCands_) { @@ -145,20 +228,35 @@ for(auto const& ref : onfile.selectedIsolationPFNeutrHadrCands_) { - - - + + + - + + @@ -298,6 +397,18 @@ isolationTauChargedHadronCandidates_.reset(); + + (onfile.chargedPFCandidate_);]]> + + + + (cand));]]> + + + diff --git a/DataFormats/TauReco/src/classes_def_3.xml b/DataFormats/TauReco/src/classes_def_3.xml index d09c7465ec4b6..c6ba555d75946 100644 --- a/DataFormats/TauReco/src/classes_def_3.xml +++ b/DataFormats/TauReco/src/classes_def_3.xml @@ -58,10 +58,11 @@ - + - + + @@ -71,14 +72,18 @@ + + + - + - + + @@ -88,6 +93,9 @@ + + + @@ -229,5 +237,4 @@ - diff --git a/Fireworks/Calo/plugins/FWPFTauProxyBuilder.cc b/Fireworks/Calo/plugins/FWPFTauProxyBuilder.cc index a9ccdfe78af24..848782d4dee1c 100644 --- a/Fireworks/Calo/plugins/FWPFTauProxyBuilder.cc +++ b/Fireworks/Calo/plugins/FWPFTauProxyBuilder.cc @@ -63,7 +63,7 @@ FWPFTauProxyBuilder::buildViewType( const FWEventItem* iItem, TEveElementList* p // prepare phi-list and theta range try { const reco::PFTauTagInfo *tauTagInfo = dynamic_cast( (*it).pfTauTagInfoRef().get() ); - const reco::PFJet *jet = dynamic_cast( tauTagInfo->pfjetRef().get() ); + const reco::Jet *jet = tauTagInfo->pfjetRef().get(); m_minTheta = 100; m_maxTheta = -100; std::vector phis; diff --git a/PhysicsTools/IsolationAlgos/plugins/PFTauExtractor.cc b/PhysicsTools/IsolationAlgos/plugins/PFTauExtractor.cc index 0bedd9fe57286..de60d23ec5b8e 100644 --- a/PhysicsTools/IsolationAlgos/plugins/PFTauExtractor.cc +++ b/PhysicsTools/IsolationAlgos/plugins/PFTauExtractor.cc @@ -4,8 +4,8 @@ #include "DataFormats/Common/interface/Handle.h" #include "DataFormats/RecoCandidate/interface/IsoDepositDirection.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "DataFormats/Candidate/interface/CandidateFwd.h" #include "DataFormats/Math/interface/deltaR.h" @@ -65,8 +65,8 @@ reco::IsoDeposit PFTauExtractor::depositFromObject(const edm::Event& evt, const //--- check that the candidate is not associated to one of the tau decay products // within the signal cone of the PFTau bool isSignalCone = false; - for ( std::vector::const_iterator tauSignalConeConstituent = pfTau_matched->signalPFCands().begin(); - tauSignalConeConstituent != pfTau_matched->signalPFCands().end(); ++tauSignalConeConstituent ) { + for ( std::vector::const_iterator tauSignalConeConstituent = pfTau_matched->signalCands().begin(); + tauSignalConeConstituent != pfTau_matched->signalCands().end(); ++tauSignalConeConstituent ) { double dR = deltaR(candidate->momentum(), (*tauSignalConeConstituent)->momentum()); if ( dR <= dRvetoPFTauSignalConeConstituents_ ) isSignalCone = true; } diff --git a/PhysicsTools/PatAlgos/plugins/PATTauProducer.cc b/PhysicsTools/PatAlgos/plugins/PATTauProducer.cc index f9afee237a756..0a8a08d343c71 100755 --- a/PhysicsTools/PatAlgos/plugins/PATTauProducer.cc +++ b/PhysicsTools/PatAlgos/plugins/PATTauProducer.cc @@ -18,6 +18,7 @@ #include "DataFormats/TauReco/interface/PFTauTransverseImpactParameterAssociation.h" #include "DataFormats/TauReco/interface/PFTauTransverseImpactParameter.h" #include "DataFormats/PatCandidates/interface/TauPFSpecific.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" @@ -371,7 +372,7 @@ void PATTauProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup } // extraction of variables needed to rerun MVA isolation and anti-electron discriminator on MiniAOD - if( aTau.isPFTau() ) { + if( !aTau.pfEssential_.empty() ) { edm::Handle pfTaus; iEvent.getByToken(pfTauToken_, pfTaus); reco::PFTauRef pfTauRef(pfTaus, idx); @@ -383,26 +384,40 @@ void PATTauProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup float sumEnergy = 0.; float leadChargedCandPt = -99; float leadChargedCandEtaAtEcalEntrance = -99; - const std::vector& signalCands = pfTauRef->signalPFCands(); - for(std::vector::const_iterator it = signalCands.begin(); it != signalCands.end(); ++it) { - const reco::PFCandidatePtr& icand = *it; - ecalEnergy += icand->ecalEnergy(); - hcalEnergy += icand->hcalEnergy(); - sumPhiTimesEnergy += icand->positionAtECALEntrance().phi()*icand->energy(); - sumEtaTimesEnergy += icand->positionAtECALEntrance().eta()*icand->energy(); - sumEnergy += icand->energy(); - const reco::Track* track = nullptr; - if ( icand->trackRef().isNonnull() ) track = icand->trackRef().get(); - else if ( icand->muonRef().isNonnull() && icand->muonRef()->innerTrack().isNonnull() ) track = icand->muonRef()->innerTrack().get(); - else if ( icand->muonRef().isNonnull() && icand->muonRef()->globalTrack().isNonnull() ) track = icand->muonRef()->globalTrack().get(); - else if ( icand->muonRef().isNonnull() && icand->muonRef()->outerTrack().isNonnull() ) track = icand->muonRef()->outerTrack().get(); - else if ( icand->gsfTrackRef().isNonnull() ) track = icand->gsfTrackRef().get(); - if( track ) { - if( track->pt() > leadChargedCandPt ) { - leadChargedCandEtaAtEcalEntrance = icand->positionAtECALEntrance().eta(); - leadChargedCandPt = track->pt(); - } - } + const std::vector& signalCands = pfTauRef->signalCands(); + for(const auto& it : signalCands) { + const reco::PFCandidate* icand = dynamic_cast(it.get()); + if (icand != nullptr) { + ecalEnergy += icand->ecalEnergy(); + hcalEnergy += icand->hcalEnergy(); + sumPhiTimesEnergy += icand->positionAtECALEntrance().phi()*icand->energy(); + sumEtaTimesEnergy += icand->positionAtECALEntrance().eta()*icand->energy(); + sumEnergy += icand->energy(); + const reco::Track* track = nullptr; + if ( icand->trackRef().isNonnull() ) track = icand->trackRef().get(); + else if ( icand->muonRef().isNonnull() && icand->muonRef()->innerTrack().isNonnull() ) track = icand->muonRef ()->innerTrack().get(); + else if ( icand->muonRef().isNonnull() && icand->muonRef()->globalTrack().isNonnull() ) track = icand->muonRef ()->globalTrack().get(); + else if ( icand->muonRef().isNonnull() && icand->muonRef()->outerTrack().isNonnull() ) track = icand->muonRef ()->outerTrack().get(); + else if ( icand->gsfTrackRef().isNonnull() ) track = icand->gsfTrackRef().get(); + if( track ) { + if( track->pt() > leadChargedCandPt ) { + leadChargedCandEtaAtEcalEntrance = icand->positionAtECALEntrance().eta(); + leadChargedCandPt = track->pt(); + } + } + } + else { + // TauReco@MiniAOD: individual ECAL and HCAL energies currently not available for PackedCandidates + // (see above implementation for PFCandidates). + // Should be added if available, as well as on-the-fly computation of position at ECAL entrance + sumEnergy += it->energy(); + const reco::Track* track = it->bestTrack(); + if( track != nullptr ) { + if( track->pt() > leadChargedCandPt ) { + leadChargedCandPt = track->pt(); + } + } + } } aTauPFEssential.ecalEnergy_ = ecalEnergy; aTauPFEssential.hcalEnergy_ = hcalEnergy; @@ -422,26 +437,40 @@ void PATTauProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup float emFraction = -1.; float myHCALenergy = 0.; float myECALenergy = 0.; - const reco::PFCandidatePtr& leadingPFCharged = pfTauRef->leadPFChargedHadrCand(); - if(leadingPFCharged.isNonnull()) { - ecalEnergyLeadChargedHadrCand = leadingPFCharged->ecalEnergy(); - hcalEnergyLeadChargedHadrCand = leadingPFCharged->hcalEnergy(); - reco::TrackRef trackRef = leadingPFCharged->trackRef(); - if( trackRef.isNonnull() ) { - leadingTrackNormChi2 = trackRef->normalizedChi2(); - for( std::vector::const_iterator tauIt = pfTauRef->isolationPFCands().begin(); tauIt!=pfTauRef->isolationPFCands().end(); ++tauIt ){ - myHCALenergy += (*tauIt)->hcalEnergy(); - myECALenergy += (*tauIt)->ecalEnergy(); - } - for( std::vector::const_iterator tauIt = pfTauRef->signalPFCands().begin(); tauIt!=pfTauRef->signalPFCands().end(); ++tauIt ){ - myHCALenergy += (*tauIt)->hcalEnergy(); - myECALenergy += (*tauIt)->ecalEnergy(); - } - if( myHCALenergy + myECALenergy != 0. ) { - emFraction = myECALenergy/( myHCALenergy + myECALenergy); - } + const reco::CandidatePtr& leadingPFCharged = pfTauRef->leadChargedHadrCand(); + if(leadingPFCharged.isNonnull()) { + const reco::PFCandidate* pfCandPtr = dynamic_cast(leadingPFCharged.get()); + if(pfCandPtr != nullptr) { // PFTau made from PFCandidates + ecalEnergyLeadChargedHadrCand = pfCandPtr->ecalEnergy(); + hcalEnergyLeadChargedHadrCand = pfCandPtr->hcalEnergy(); + reco::TrackRef trackRef = pfCandPtr->trackRef(); + if( trackRef.isNonnull() ) { + leadingTrackNormChi2 = trackRef->normalizedChi2(); + for(const auto& isoPFCand : pfTauRef->isolationPFCands()){ + myHCALenergy += isoPFCand->hcalEnergy(); + myECALenergy += isoPFCand->ecalEnergy(); + } + for(const auto& signalPFCand : pfTauRef->signalPFCands()){ + myHCALenergy += signalPFCand->hcalEnergy(); + myECALenergy += signalPFCand->ecalEnergy(); + } + if( myHCALenergy + myECALenergy != 0. ) { + emFraction = myECALenergy/( myHCALenergy + myECALenergy); + } + } } + else { + const pat::PackedCandidate* packedCandPtr = dynamic_cast(leadingPFCharged.get()); + if (packedCandPtr != nullptr) { + // TauReco@MiniAOD: Update code below if ecal/hcal energies are available. + const reco::Track* track = packedCandPtr->hasTrackDetails() ? &packedCandPtr->pseudoTrack() : nullptr; + if (track != nullptr) { + leadingTrackNormChi2 = track->normalizedChi2(); + } + } + } } + aTauPFEssential.emFraction_ = emFraction; aTauPFEssential.leadingTrackNormChi2_ = leadingTrackNormChi2; aTauPFEssential.ecalEnergyLeadChargedHadrCand_ = ecalEnergyLeadChargedHadrCand; diff --git a/RecoMET/METAlgorithms/interface/SignAlgoResolutions.h b/RecoMET/METAlgorithms/interface/SignAlgoResolutions.h index 037c51610c69b..9b3853253822f 100644 --- a/RecoMET/METAlgorithms/interface/SignAlgoResolutions.h +++ b/RecoMET/METAlgorithms/interface/SignAlgoResolutions.h @@ -50,7 +50,7 @@ namespace metsig { double eval(const resolutionType & type, const resolutionFunc & func, const double & et, const double & phi, const double & eta, const double &p) const; // for example getvalue(caloHF,ET,et,phi,eta,p); double eval(const resolutionType & type, const resolutionFunc & func, const double & et, const double & phi, const double & eta) const; // for example getvalue(caloHF,ET,et,phi,eta,p); metsig::SigInputObj evalPF(const reco::PFCandidate* candidate) const; - metsig::SigInputObj evalPFJet(const reco::PFJet *jet) const; + metsig::SigInputObj evalPFJet(const reco::Jet *jet) const; bool isFilled() const {return !functionmap_.empty();} private: diff --git a/RecoMET/METAlgorithms/src/SignAlgoResolutions.cc b/RecoMET/METAlgorithms/src/SignAlgoResolutions.cc index 1778196a41c46..3cdf7c3240adb 100644 --- a/RecoMET/METAlgorithms/src/SignAlgoResolutions.cc +++ b/RecoMET/METAlgorithms/src/SignAlgoResolutions.cc @@ -106,7 +106,7 @@ metsig::SigInputObj metsig::SignAlgoResolutions::evalPF(const reco::PFCandidate metsig::SigInputObj -metsig::SignAlgoResolutions::evalPFJet(const reco::PFJet *jet) const{ +metsig::SignAlgoResolutions::evalPFJet(const reco::Jet *jet) const{ double jpt = jet->pt(); double jphi = jet->phi(); diff --git a/RecoMET/METPUSubtraction/interface/PFMEtSignInterfaceBase.h b/RecoMET/METPUSubtraction/interface/PFMEtSignInterfaceBase.h index abc835232923a..39249d63155cd 100755 --- a/RecoMET/METPUSubtraction/interface/PFMEtSignInterfaceBase.h +++ b/RecoMET/METPUSubtraction/interface/PFMEtSignInterfaceBase.h @@ -100,11 +100,9 @@ class PFMEtSignInterfaceBase // (until PFTau specific resolutions are available) if ( dynamic_cast(particle) != nullptr ) { const pat::Tau* pfTau = dynamic_cast(particle); - //std::cout << "tau: pt = " << pt << ", eta = " << eta << ", phi = " << phi << std::endl; return pfMEtResolution_->evalPFJet(pfTau->pfJetRef().get()); } else if ( dynamic_cast(particle) != nullptr ) { const reco::PFTau* pfTau = dynamic_cast(particle); - //std::cout << "tau: pt = " << pt << ", eta = " << eta << ", phi = " << phi << std::endl; return pfMEtResolution_->evalPFJet(pfTau->jetRef().get()); } else assert(0); } else if ( dynamic_cast(particle) != nullptr || diff --git a/RecoMET/METPUSubtraction/plugins/PFMETProducerMVA.cc b/RecoMET/METPUSubtraction/plugins/PFMETProducerMVA.cc index e72eef26d84b9..8c8c930556739 100644 --- a/RecoMET/METPUSubtraction/plugins/PFMETProducerMVA.cc +++ b/RecoMET/METPUSubtraction/plugins/PFMETProducerMVA.cc @@ -315,10 +315,10 @@ double PFMETProducerMVA::chargedEnFrac(const reco::Candidate *iCand, const reco::PFTau *lPFTau = nullptr; lPFTau = dynamic_cast(iCand); if(lPFTau != nullptr) { - for (UInt_t i0 = 0; i0 < lPFTau->signalPFCands().size(); i0++) { - lPtTot += (lPFTau->signalPFCands())[i0]->pt(); - if((lPFTau->signalPFCands())[i0]->charge() == 0) continue; - lPtCharged += (lPFTau->signalPFCands())[i0]->pt(); + for (UInt_t i0 = 0; i0 < lPFTau->signalCands().size(); i0++) { + lPtTot += (lPFTau->signalCands())[i0]->pt(); + if((lPFTau->signalCands())[i0]->charge() == 0) continue; + lPtCharged += (lPFTau->signalCands())[i0]->pt(); } } else { diff --git a/RecoParticleFlow/Benchmark/src/PFTauElecRejectionBenchmark.cc b/RecoParticleFlow/Benchmark/src/PFTauElecRejectionBenchmark.cc index e58afd09d181c..3fdb782be4ed0 100644 --- a/RecoParticleFlow/Benchmark/src/PFTauElecRejectionBenchmark.cc +++ b/RecoParticleFlow/Benchmark/src/PFTauElecRejectionBenchmark.cc @@ -44,6 +44,7 @@ void PFTauElecRejectionBenchmark::write() { } + void PFTauElecRejectionBenchmark::setup( string Filename, string benchmarkLabel, @@ -256,10 +257,11 @@ void PFTauElecRejectionBenchmark::process(edm::Handle mcevt, if ((*thePFTau).et() > minRecoPt_ && std::abs((*thePFTau).eta()) < maxRecoAbsEta_) { // Check if track goes to Ecal crack - TrackRef myleadTk; - if(thePFTau->leadPFChargedHadrCand().isNonnull()){ - myleadTk=thePFTau->leadPFChargedHadrCand()->trackRef(); - myleadTkEcalPos = thePFTau->leadPFChargedHadrCand()->positionAtECALEntrance(); + reco::TrackRef myleadTk; + const reco::PFCandidatePtr& pflch = thePFTau->leadPFChargedHadrCand(); + if(pflch.isNonnull()){ + myleadTk=pflch->trackRef(); + myleadTkEcalPos = pflch->positionAtECALEntrance(); if(myleadTk.isNonnull()){ if (applyEcalCrackCut_ && isInEcalCrack(std::abs((double)myleadTkEcalPos.eta()))) { @@ -321,14 +323,17 @@ void PFTauElecRejectionBenchmark::process(edm::Handle mcevt, } // Loop over all PFCands for cluster plots - std::vector myPFCands=(*thePFTau).pfTauTagInfoRef()->PFCands(); + std::vector myPFCands=(*thePFTau).pfTauTagInfoRef()->PFCands(); for(int i=0;i<(int)myPFCands.size();i++){ - + const reco::PFCandidate* pfCand = dynamic_cast(myPFCands[i].get()); + if (pfCand == nullptr) + continue; + math::XYZPointF candPos; - if (myPFCands[i]->particleId()==1 || myPFCands[i]->particleId()==2) // if charged hadron or electron - candPos = myPFCands[i]->positionAtECALEntrance(); + if (std::abs(pfCand->pdgId()) == 211 || std::abs(pfCand->pdgId()) == 11) // if charged hadron or electron + candPos = pfCand->positionAtECALEntrance(); else - candPos = math::XYZPointF(myPFCands[i]->px(),myPFCands[i]->py(),myPFCands[i]->pz()); + candPos = math::XYZPointF(pfCand->px(),pfCand->py(),pfCand->pz()); //double deltaR = ROOT::Math::VectorUtil::DeltaR(myleadTkEcalPos,candPos); double deltaPhi = ROOT::Math::VectorUtil::DeltaPhi(myleadTkEcalPos,candPos); @@ -336,9 +341,9 @@ void PFTauElecRejectionBenchmark::process(edm::Handle mcevt, double deltaPhiOverQ = deltaPhi/(double)myleadTk->charge(); hpfcand_deltaEta->Fill(deltaEta); - hpfcand_deltaEta_weightE->Fill(deltaEta*myPFCands[i]->ecalEnergy()); + hpfcand_deltaEta_weightE->Fill(deltaEta*pfCand->ecalEnergy()); hpfcand_deltaPhiOverQ->Fill(deltaPhiOverQ); - hpfcand_deltaPhiOverQ_weightE->Fill(deltaPhiOverQ*myPFCands[i]->ecalEnergy()); + hpfcand_deltaPhiOverQ_weightE->Fill(deltaPhiOverQ*pfCand->ecalEnergy()); } diff --git a/RecoTauTag/Configuration/python/tools/adaptToRunAtMiniAOD.py b/RecoTauTag/Configuration/python/tools/adaptToRunAtMiniAOD.py new file mode 100644 index 0000000000000..ef9bbde729194 --- /dev/null +++ b/RecoTauTag/Configuration/python/tools/adaptToRunAtMiniAOD.py @@ -0,0 +1,215 @@ +import FWCore.ParameterSet.Config as cms + +###### +# Tools to adapt Tau sequences to run tau ReReco+PAT at MiniAOD samples +# M. Bluj, NCBJ Warsaw +# based on work of J. Steggemann, CERN +# Created: 9 Nov. 2017 +###### + +##### +def addTauReReco(process): + #PAT + process.load('PhysicsTools.PatAlgos.producersLayer1.tauProducer_cff') + process.load('PhysicsTools.PatAlgos.selectionLayer1.tauSelector_cfi') + process.selectedPatTaus.cut="pt > 18. && tauID(\'decayModeFindingNewDMs\')> 0.5" #Cut as in MiniAOD + #Tau RECO + process.load("RecoTauTag.Configuration.RecoPFTauTag_cff") + #Task/Sequence for tau rereco + process.miniAODTausTask = cms.Task( + process.PFTauTask, + process.makePatTausTask, + process.selectedPatTaus + ) + process.miniAODTausSequence = cms.Sequence(process.miniAODTausTask) + #Path with tau rereco (Needed?) + process.TauReco = cms.Path(process.miniAODTausSequence) + +##### +def convertModuleToMiniAODInput(process, name): + module = getattr(process, name) + if hasattr(module, 'particleFlowSrc'): + module.particleFlowSrc = cms.InputTag("packedPFCandidates", "", "") + if hasattr(module, 'vertexSrc'): + module.vertexSrc = cms.InputTag('offlineSlimmedPrimaryVertices') + if hasattr(module, 'qualityCuts') and hasattr(module.qualityCuts, 'primaryVertexSrc'): + module.qualityCuts.primaryVertexSrc = cms.InputTag('offlineSlimmedPrimaryVertices') + +##### +def adaptTauToMiniAODReReco(process, reclusterJets=True): + # TRYING TO MAKE THINGS MINIAOD COMPATIBLE, FROM THE START, TO THE END, 1 BY 1 + #print '[adaptTauToMiniAODReReco]: Start' + + jetCollection = 'slimmedJets' + # Add new jet collections if reclustering is demanded + if reclusterJets: + jetCollection = 'patJetsPAT' + from RecoJets.JetProducers.ak4PFJets_cfi import ak4PFJets + process.ak4PFJetsPAT = ak4PFJets.clone( + src=cms.InputTag("packedPFCandidates") + ) + # trivial PATJets + from PhysicsTools.PatAlgos.producersLayer1.jetProducer_cfi import _patJets + process.patJetsPAT = _patJets.clone( + jetSource = cms.InputTag("ak4PFJetsPAT"), + addJetCorrFactors = cms.bool(False), + jetCorrFactorsSource = cms.VInputTag(), + addBTagInfo = cms.bool(False), + addDiscriminators = cms.bool(False), + discriminatorSources = cms.VInputTag(), + addAssociatedTracks = cms.bool(False), + addJetCharge = cms.bool(False), + addGenPartonMatch = cms.bool(False), + embedGenPartonMatch = cms.bool(False), + addGenJetMatch = cms.bool(False), + getJetMCFlavour = cms.bool(False), + addJetFlavourInfo = cms.bool(False), + ) + process.miniAODTausTask.add(process.ak4PFJetsPAT) + process.miniAODTausTask.add(process.patJetsPAT) + + # so this adds all tracks to jet in some deltaR region. we don't have tracks so don't need it :D + # process.ak4PFJetTracksAssociatorAtVertex.jets = cms.InputTag(jetCollection) + + # Remove ak4PFJetTracksAssociatorAtVertex from recoTauCommonSequence + # Remove pfRecoTauTagInfoProducer from recoTauCommonSequence since it uses the jet-track association + # HOWEVER, may use https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookMiniAOD2017#Isolated_Tracks + # probably needs recovery of the two modules above + + process.recoTauAK4Jets08RegionPAT = cms.EDProducer("RecoTauPatJetRegionProducer", + deltaR = process.recoTauAK4PFJets08Region.deltaR, + maxJetAbsEta = process.recoTauAK4PFJets08Region.maxJetAbsEta, + minJetPt = process.recoTauAK4PFJets08Region.minJetPt, + pfCandAssocMapSrc = cms.InputTag(""), + pfCandSrc = cms.InputTag("packedPFCandidates"), + src = cms.InputTag(jetCollection) + ) + + process.recoTauPileUpVertices.src = cms.InputTag("offlineSlimmedPrimaryVertices") + # Redefine recoTauCommonTask + # with redefined region and PU vertices, and w/o track-to-vertex associator and tauTagInfo (the two latter are probably obsolete and not needed at all) + process.recoTauCommonTask = cms.Task( + process.recoTauAK4Jets08RegionPAT, + process.recoTauPileUpVertices + ) + + for moduleName in process.TauReco.moduleNames(): + convertModuleToMiniAODInput(process, moduleName) + + + # Adapt TauPiZeros producer + process.ak4PFJetsLegacyHPSPiZeros.builders[0].qualityCuts.primaryVertexSrc = cms.InputTag("offlineSlimmedPrimaryVertices") + process.ak4PFJetsLegacyHPSPiZeros.jetSrc = cms.InputTag(jetCollection) + + # Adapt TauChargedHadrons producer + for builder in process.ak4PFJetsRecoTauChargedHadrons.builders: + builder.qualityCuts.primaryVertexSrc = cms.InputTag("offlineSlimmedPrimaryVertices") + if builder.name.value() == 'tracks': #replace plugin based on generalTracks by one based on lostTracks + builder.name = 'lostTracks' + builder.plugin = 'PFRecoTauChargedHadronFromLostTrackPlugin' + builder.srcTracks = cms.InputTag("lostTracks") + process.ak4PFJetsRecoTauChargedHadrons.jetSrc = cms.InputTag(jetCollection) + + # Adapt combinatoricRecoTau producer + process.combinatoricRecoTaus.jetRegionSrc = 'recoTauAK4Jets08RegionPAT' + process.combinatoricRecoTaus.jetSrc = jetCollection + # Adapt builders + for builder in process.combinatoricRecoTaus.builders: + for name,value in builder.parameters_().iteritems(): + if name == 'qualityCuts': + builder.qualityCuts.primaryVertexSrc = 'offlineSlimmedPrimaryVertices' + elif name == 'pfCandSrc': + builder.pfCandSrc = 'packedPFCandidates' + # Adapt supported modifiers and remove unsupported ones + modifiersToRemove_ = cms.VPSet() + for mod in process.combinatoricRecoTaus.modifiers: + if mod.name.value() == 'elec_rej': + modifiersToRemove_.append(mod) + continue + elif mod.name.value() == 'TTIworkaround': + modifiersToRemove_.append(mod) + continue + for name,value in mod.parameters_().iteritems(): + if name == 'qualityCuts': + mod.qualityCuts.primaryVertexSrc = 'offlineSlimmedPrimaryVertices' + for mod in modifiersToRemove_: + process.combinatoricRecoTaus.modifiers.remove(mod) + #print "\t\t Removing '%s' modifier from 'combinatoricRecoTaus'" %mod.name.value() + + # Redefine tau PV producer + process.hpsPFTauPrimaryVertexProducer.__dict__['_TypedParameterizable__type'] = 'PFTauMiniAODPrimaryVertexProducer' + process.hpsPFTauPrimaryVertexProducer.PVTag = 'offlineSlimmedPrimaryVertices' + process.hpsPFTauPrimaryVertexProducer.packedCandidatesTag = cms.InputTag("packedPFCandidates") + process.hpsPFTauPrimaryVertexProducer.lostCandidatesTag = cms.InputTag("lostTracks") + + # Redefine tau SV producer + process.hpsPFTauSecondaryVertexProducer = cms.EDProducer("PFTauSecondaryVertexProducer", + PFTauTag = cms.InputTag("hpsPFTauProducer") + ) + + # Remove RecoTau producers which are not supported (yet?), i.e. against-e/mu discriminats + for moduleName in process.TauReco.moduleNames(): + if 'ElectronRejection' in moduleName or 'MuonRejection' in moduleName: + process.miniAODTausTask.remove(getattr(process, moduleName)) + + # Instead add against-mu discriminants which are MiniAOD compatible + from RecoTauTag.RecoTau.hpsPFTauDiscriminationByAMuonRejectionSimple_cff import hpsPFTauDiscriminationByLooseMuonRejectionSimple, hpsPFTauDiscriminationByTightMuonRejectionSimple + + process.hpsPFTauDiscriminationByLooseMuonRejectionSimple = hpsPFTauDiscriminationByLooseMuonRejectionSimple + process.hpsPFTauDiscriminationByTightMuonRejectionSimple = hpsPFTauDiscriminationByTightMuonRejectionSimple + process.miniAODTausTask.add(process.hpsPFTauDiscriminationByLooseMuonRejectionSimple) + process.miniAODTausTask.add(process.hpsPFTauDiscriminationByTightMuonRejectionSimple) + + ##### + # PAT part in the following + + process.tauGenJets.GenParticles = cms.InputTag("prunedGenParticles") + process.tauMatch.matched = cms.InputTag("prunedGenParticles") + + # Remove unsupported tauIDs + for name, src in process.patTaus.tauIDSources.parameters_().iteritems(): + if name.find('againstElectron') > -1 or name.find('againstMuon') > -1: + delattr(process.patTaus.tauIDSources,name) + # Add MiniAOD specific ones + setattr(process.patTaus.tauIDSources,'againstMuonLooseSimple',cms.InputTag('hpsPFTauDiscriminationByLooseMuonRejectionSimple')) + setattr(process.patTaus.tauIDSources,'againstMuonTightSimple',cms.InputTag('hpsPFTauDiscriminationByTightMuonRejectionSimple')) + + #print '[adaptTauToMiniAODReReco]: Done!' + +##### +def setOutputModule(mode=0): + #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), plus a few additional collections (charged hadrons, pi zeros, combinatoric reco taus) + + import Configuration.EventContent.EventContent_cff as evtContent + output = cms.OutputModule( + 'PoolOutputModule', + fileName=cms.untracked.string('miniAOD_TauReco.root'), + fastCloning=cms.untracked.bool(False), + dataset=cms.untracked.PSet( + dataTier=cms.untracked.string('MINIAODSIM'), + filterName=cms.untracked.string('') + ), + outputCommands = evtContent.MINIAODSIMEventContent.outputCommands, + SelectEvents=cms.untracked.PSet( + SelectEvents=cms.vstring('*',) + ) + ) + output.outputCommands.append('keep *_selectedPatTaus_*_*') + if mode==1: + for prod in evtContent.RecoTauTagAOD.outputCommands: + if prod.find('ElectronRejection') > -1: + continue + if prod.find('MuonRejection') > -1: + continue + output.outputCommands.append(prod) + output.outputCommands.append('keep *_hpsPFTauDiscriminationByLooseMuonRejectionSimple_*_*') + output.outputCommands.append('keep *_hpsPFTauDiscriminationByTightMuonRejectionSimple_*_*') + output.outputCommands.append('keep *_combinatoricReco*_*_*') + output.outputCommands.append('keep *_ak4PFJetsRecoTauChargedHadrons_*_*') + output.outputCommands.append('keep *_ak4PFJetsLegacyHPSPiZeros_*_*') + output.outputCommands.append('keep *_patJetsPAT_*_*') + + return output + +##### diff --git a/RecoTauTag/Configuration/test/ZTT-validation.txt b/RecoTauTag/Configuration/test/ZTT-validation.txt index 85f6d7773f55b..e2c47481b2f98 100644 --- a/RecoTauTag/Configuration/test/ZTT-validation.txt +++ b/RecoTauTag/Configuration/test/ZTT-validation.txt @@ -1,2 +1,3 @@ #/store/relval/CMSSW_9_2_2/RelValProdTTbar_13/AODSIM/91X_mcRun2_asymptotic_v3-v1/10000/EEB99F74-DA4D-E711-A41C-0025905A48F2.root -/store/relval/CMSSW_10_0_0_pre1/RelValTTbar_13/GEN-SIM-RECO/94X_mc2017_realistic_v10-v1/10000/5873841C-9DCB-E711-8E9F-0CC47A7C357A.root +#/store/relval/CMSSW_10_0_0_pre1/RelValTTbar_13/GEN-SIM-RECO/94X_mc2017_realistic_v10-v1/10000/5873841C-9DCB-E711-8E9F-0CC47A7C357A.root +/store/relval/CMSSW_10_1_0_pre1/RelValTTbar_13/GEN-SIM-RECO/PUpmx25ns_100X_upgrade2018_realistic_v10-v1/20000/2AA898A5-9713-E811-8471-0CC47A4D7636.root diff --git a/RecoTauTag/HLTProducers/src/L1HLTTauMatching.cc b/RecoTauTag/HLTProducers/src/L1HLTTauMatching.cc index 350c1696ca2cf..1105dc0243d7d 100644 --- a/RecoTauTag/HLTProducers/src/L1HLTTauMatching.cc +++ b/RecoTauTag/HLTProducers/src/L1HLTTauMatching.cc @@ -61,8 +61,8 @@ void L1HLTTauMatching::produce(edm::StreamID iSId, edm::Event& iEvent, const edm deltaR = ROOT::Math::VectorUtil::DeltaR(myJet.p4().Vect(), (tauCandRefVec[iL1Tau]->p4()).Vect()); if(deltaR < matchingR ) { // LeafCandidate myLC(myJet); - if(myJet.leadPFChargedHadrCand().isNonnull()){ - a = myJet.leadPFChargedHadrCand()->vertex(); + if(myJet.leadChargedHadrCand().isNonnull()){ + a = myJet.leadChargedHadrCand()->vertex(); } PFTau myPFTau(std::numeric_limits::quiet_NaN(), myJet.p4(), a); if(myJet.pt() > mEt_Min) { @@ -83,8 +83,8 @@ void L1HLTTauMatching::produce(edm::StreamID iSId, edm::Event& iEvent, const edm deltaR = ROOT::Math::VectorUtil::DeltaR(myJet.p4().Vect(), (jetCandRefVec[iL1Tau]->p4()).Vect()); if(deltaR < matchingR ) { // LeafCandidate myLC(myJet); - if(myJet.leadPFChargedHadrCand().isNonnull()){ - a = myJet.leadPFChargedHadrCand()->vertex(); + if(myJet.leadChargedHadrCand().isNonnull()){ + a = myJet.leadChargedHadrCand()->vertex(); } PFTau myPFTau(std::numeric_limits::quiet_NaN(), myJet.p4(),a); diff --git a/RecoTauTag/HLTProducers/src/L1THLTTauMatching.cc b/RecoTauTag/HLTProducers/src/L1THLTTauMatching.cc index 2511d2eb45abc..c5bab006e15f4 100644 --- a/RecoTauTag/HLTProducers/src/L1THLTTauMatching.cc +++ b/RecoTauTag/HLTProducers/src/L1THLTTauMatching.cc @@ -47,8 +47,8 @@ void L1THLTTauMatching::produce(edm::StreamID iSId, edm::Event& iEvent, const ed const PFTau & myJet = (*tauJets)[iJet]; deltaR = ROOT::Math::VectorUtil::DeltaR(myJet.p4().Vect(), (tauCandRefVec[iL1Tau]->p4()).Vect()); if(deltaR < matchingR ) { - if(myJet.leadPFChargedHadrCand().isNonnull()){ - a = myJet.leadPFChargedHadrCand()->vertex(); + if(myJet.leadChargedHadrCand().isNonnull()){ + a = myJet.leadChargedHadrCand()->vertex(); } PFTau myPFTau(std::numeric_limits::quiet_NaN(), myJet.p4(), a); if(myJet.pt() > mEt_Min) { diff --git a/RecoTauTag/HLTProducers/src/PFTauToJetProducer.cc b/RecoTauTag/HLTProducers/src/PFTauToJetProducer.cc index b3a8904d03aae..d10b519f2dbb1 100644 --- a/RecoTauTag/HLTProducers/src/PFTauToJetProducer.cc +++ b/RecoTauTag/HLTProducers/src/PFTauToJetProducer.cc @@ -29,7 +29,6 @@ void PFTauToJetProducer::produce(edm::Event& iEvent, const edm::EventSetup& iES) iEvent.getByToken( tauSrc_, tauJets ); PFTauCollection::const_iterator i = tauJets->begin(); for(;i !=tauJets->end(); i++ ) { - // cout <<"Tau Tracks " << i->signalPFChargedHadrCands().size()<p4(),i->vertex(),specific); jet.setPdgId(15); jetCollectionTmp->push_back(jet); diff --git a/RecoTauTag/ImpactParameter/plugins/PFTau3ProngReco.cc b/RecoTauTag/ImpactParameter/plugins/PFTau3ProngReco.cc index 85b542a6db932..9496294d94719 100644 --- a/RecoTauTag/ImpactParameter/plugins/PFTau3ProngReco.cc +++ b/RecoTauTag/ImpactParameter/plugins/PFTau3ProngReco.cc @@ -36,6 +36,7 @@ #include "DataFormats/Common/interface/RefToBase.h" #include "DataFormats/EgammaCandidates/interface/Electron.h" #include "DataFormats/EgammaCandidates/interface/ElectronFwd.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" #include "DataFormats/Common/interface/Association.h" #include "DataFormats/Common/interface/AssociationVector.h" @@ -122,6 +123,23 @@ PFTau3ProngReco::~PFTau3ProngReco(){ } +namespace { + inline const reco::Track* getTrack(const reco::Candidate& cand) + { + const reco::PFCandidate* pfCandPtr = dynamic_cast(&cand); + if (pfCandPtr) { + if ( pfCandPtr->trackRef().isNonnull() ) return pfCandPtr->trackRef().get(); + else if ( pfCandPtr->gsfTrackRef().isNonnull() ) return pfCandPtr->gsfTrackRef().get(); + else return nullptr; + } + const pat::PackedCandidate* packedCand = dynamic_cast(&cand); + if (packedCand != nullptr) + return packedCand->bestTrack(); + + return nullptr; + } +} + void PFTau3ProngReco::produce(edm::Event& iEvent,const edm::EventSetup& iSetup){ // Obtain Collections edm::ESHandle transTrackBuilder; @@ -207,16 +225,14 @@ void PFTau3ProngReco::produce(edm::Event& iEvent,const edm::EventSetup& iSetup){ // use Track Helix std::vector pions; GlobalPoint pvpoint(primaryVertex->position().x(),primaryVertex->position().y(),primaryVertex->position().z()); - const std::vector > cands = tau->signalPFChargedHadrCands(); - for (std::vector >::const_iterator iter = cands.begin(); iter!=cands.end(); ++iter) { - if(iter->get()->trackRef().isNonnull()){ - reco::TransientTrack transTrk=transTrackBuilder->build(iter->get()->trackRef()); + const std::vector > cands = tau->signalChargedHadrCands(); + for (std::vector >::const_iterator iter = cands.begin(); iter!=cands.end(); ++iter) { + const reco::Track* track = getTrack(**iter); + if (track != nullptr) { + reco::TransientTrack transTrk=transTrackBuilder->build(*track); pions.push_back(ParticleBuilder::createTrackParticle(transTrk,pvpoint,true,true)); } - else if(iter->get()->gsfTrackRef().isNonnull()){ - //reco::TransientTrack transTrk=transTrackBuilder->build(iter->get()->gsfTrackRef()); - //pions.push_back(ParticleBuilder::CreateTrackParticle(transTrk,pvpoint,true,true)); - } + } TVector3 pv(secVtx->position().x(),secVtx->position().y(),secVtx->position().z()); Chi2VertexFitter chi2v(pions,pv); diff --git a/RecoTauTag/RecoTau/interface/AntiElectronIDCut2.h b/RecoTauTag/RecoTau/interface/AntiElectronIDCut2.h index 143e35eca6d1e..5a48cbbd0e72b 100644 --- a/RecoTauTag/RecoTau/interface/AntiElectronIDCut2.h +++ b/RecoTauTag/RecoTau/interface/AntiElectronIDCut2.h @@ -82,11 +82,11 @@ class AntiElectronIDCut2 std::vector GammasdEta; std::vector GammasdPhi; std::vector GammasPt; - for ( unsigned i = 0 ; i < thePFTau.signalPFGammaCands().size(); ++i ) { - reco::PFCandidatePtr gamma = thePFTau.signalPFGammaCands().at(i); - if ( thePFTau.leadPFChargedHadrCand().isNonnull() ) { - GammasdEta.push_back(gamma->eta() - thePFTau.leadPFChargedHadrCand()->eta()); - GammasdPhi.push_back(gamma->phi() - thePFTau.leadPFChargedHadrCand()->phi()); + for ( unsigned i = 0 ; i < thePFTau.signalGammaCands().size(); ++i ) { + reco::CandidatePtr gamma = thePFTau.signalGammaCands().at(i); + if ( thePFTau.leadChargedHadrCand().isNonnull() ) { + GammasdEta.push_back(gamma->eta() - thePFTau.leadChargedHadrCand()->eta()); + GammasdPhi.push_back(gamma->phi() - thePFTau.leadChargedHadrCand()->phi()); } else { GammasdEta.push_back(gamma->eta() - thePFTau.eta()); GammasdPhi.push_back(gamma->phi() - thePFTau.phi()); diff --git a/RecoTauTag/RecoTau/interface/ConeTools.h b/RecoTauTag/RecoTau/interface/ConeTools.h index f30e4f573a87e..2725f8ddc3fa4 100644 --- a/RecoTauTag/RecoTau/interface/ConeTools.h +++ b/RecoTauTag/RecoTau/interface/ConeTools.h @@ -48,6 +48,10 @@ typedef DeltaRPtrFilter PFCandPtrDRFilter; typedef boost::filter_iterator< PFCandPtrDRFilter, std::vector::const_iterator> PFCandPtrDRFilterIter; +typedef DeltaRPtrFilter CandPtrDRFilter; +typedef boost::filter_iterator< CandPtrDRFilter, + std::vector::const_iterator> CandPtrDRFilterIter; + typedef DeltaRFilter ChargedHadronDRFilter; typedef boost::filter_iterator< ChargedHadronDRFilter, std::vector::const_iterator> ChargedHadronDRFilterIter; diff --git a/RecoTauTag/RecoTau/interface/HPSPFRecoTauAlgorithm.h b/RecoTauTag/RecoTau/interface/HPSPFRecoTauAlgorithm.h index 68a1ecbf050ee..37ff5194b8375 100644 --- a/RecoTauTag/RecoTau/interface/HPSPFRecoTauAlgorithm.h +++ b/RecoTauTag/RecoTau/interface/HPSPFRecoTauAlgorithm.h @@ -42,10 +42,10 @@ class HPSPFRecoTauAlgorithm : public PFRecoTauAlgorithmBase //* Helper Methods *// //Creators of the Decay Modes - void buildOneProng(const reco::PFTauTagInfoRef&,const std::vector& ); - void buildOneProngStrip(const reco::PFTauTagInfoRef&,const std::vector>&,const std::vector&); - void buildOneProngTwoStrips(const reco::PFTauTagInfoRef&,const std::vector>&,const std::vector&); - void buildThreeProngs(const reco::PFTauTagInfoRef&,const std::vector&); + void buildOneProng(const reco::PFTauTagInfoRef&,const std::vector& ); + void buildOneProngStrip(const reco::PFTauTagInfoRef&,const std::vector>&,const std::vector&); + void buildOneProngTwoStrips(const reco::PFTauTagInfoRef&,const std::vector>&,const std::vector&); + void buildThreeProngs(const reco::PFTauTagInfoRef&,const std::vector&); //Narrowness selection bool isNarrowTau(const reco::PFTau&,double); @@ -60,9 +60,9 @@ class HPSPFRecoTauAlgorithm : public PFRecoTauAlgorithmBase void applyElectronRejection(reco::PFTau&,double); //Method to create a candidate from the merged EM Candidates vector; - math::XYZTLorentzVector createMergedLorentzVector(const std::vector&); + math::XYZTLorentzVector createMergedLorentzVector(const std::vector&); - void removeCandidateFromRefVector(const reco::PFCandidatePtr&,std::vector&); + void removeCandidateFromRefVector(const reco::CandidatePtr&,std::vector&); void applyMassConstraint(math::XYZTLorentzVector&,double ); bool refitThreeProng(reco::PFTau&); diff --git a/RecoTauTag/RecoTau/interface/PFRecoTauChargedHadronPlugins.h b/RecoTauTag/RecoTau/interface/PFRecoTauChargedHadronPlugins.h index 06fc0543f22be..7b0ac9b2a1771 100644 --- a/RecoTauTag/RecoTau/interface/PFRecoTauChargedHadronPlugins.h +++ b/RecoTauTag/RecoTau/interface/PFRecoTauChargedHadronPlugins.h @@ -8,7 +8,7 @@ * * Base classes for plugins that construct and rank PFRecoTauChargedHadron * objects from a jet. The builder plugin has an abstract function - * that takes a PFJet and returns a list of reconstructed photons in + * that takes a Jet and returns a list of reconstructed photons in * the jet. * * The quality plugin has an abstract function that takes a reference @@ -27,7 +27,7 @@ namespace reco { // Forward declarations -class PFJet; +class Jet; class PFRecoTauChargedHadron; namespace tau { @@ -45,7 +45,7 @@ class PFRecoTauChargedHadronBuilderPlugin : public RecoTauEventHolderPlugin {} ~PFRecoTauChargedHadronBuilderPlugin() override {} /// Build a collection of chargedHadrons from objects in the input jet - virtual return_type operator()(const PFJet&) const = 0; + virtual return_type operator()(const Jet&) const = 0; /// Hook called at the beginning of the event. void beginEvent() override {} }; diff --git a/RecoTauTag/RecoTau/interface/PFRecoTauClusterVariables.h b/RecoTauTag/RecoTau/interface/PFRecoTauClusterVariables.h index 08852d591a086..773b1e86c4616 100644 --- a/RecoTauTag/RecoTau/interface/PFRecoTauClusterVariables.h +++ b/RecoTauTag/RecoTau/interface/PFRecoTauClusterVariables.h @@ -15,6 +15,7 @@ #include "DataFormats/TauReco/interface/PFTau.h" #include "DataFormats/PatCandidates/interface/Tau.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" namespace reco { namespace tau { /// return chi2 of the leading track ==> deprecated? <== diff --git a/RecoTauTag/RecoTau/interface/PFRecoTauTagInfoAlgorithm.h b/RecoTauTag/RecoTau/interface/PFRecoTauTagInfoAlgorithm.h index 72b093556fa19..587eeb6fb0c75 100644 --- a/RecoTauTag/RecoTau/interface/PFRecoTauTagInfoAlgorithm.h +++ b/RecoTauTag/RecoTau/interface/PFRecoTauTagInfoAlgorithm.h @@ -17,7 +17,7 @@ class PFRecoTauTagInfoAlgorithm { PFRecoTauTagInfoAlgorithm(){} PFRecoTauTagInfoAlgorithm(const edm::ParameterSet&); ~PFRecoTauTagInfoAlgorithm(){} - reco::PFTauTagInfo buildPFTauTagInfo(const reco::PFJetRef&,const std::vector&,const reco::TrackRefVector&,const reco::Vertex&) const; + reco::PFTauTagInfo buildPFTauTagInfo(const reco::JetBaseRef&,const std::vector&,const reco::TrackRefVector&,const reco::Vertex&) const; private: double ChargedHadrCand_tkminPt_; int ChargedHadrCand_tkminPixelHitsn_; diff --git a/RecoTauTag/RecoTau/interface/PFTauPrimaryVertexProducerBase.h b/RecoTauTag/RecoTau/interface/PFTauPrimaryVertexProducerBase.h new file mode 100644 index 0000000000000..0dc07b74028f0 --- /dev/null +++ b/RecoTauTag/RecoTau/interface/PFTauPrimaryVertexProducerBase.h @@ -0,0 +1,85 @@ +#ifndef RecoTauTag_RecoTau_PFTauPrimaryVertexProducerBase_H_ +#define RecoTauTag_RecoTau_PFTauPrimaryVertexProducerBase_H_ + +/* class PFTauPrimaryVertexProducerBase + * EDProducer of the + * authors: Ian M. Nugent + * This work is based on the impact parameter work by Rosamaria Venditti and reconstructing the 3 prong taus. + * The idea of the fully reconstructing the tau using a kinematic fit comes from + * Lars Perchalla and Philip Sauerland Theses under Achim Stahl supervision. This + * work was continued by Ian M. Nugent and Vladimir Cherepanov. + * Thanks goes to Christian Veelken and Evan Klose Friis for their help and suggestions. + */ + +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" + +#include "DataFormats/TauReco/interface/PFTau.h" +#include "DataFormats/TauReco/interface/PFTauFwd.h" +#include "DataFormats/MuonReco/interface/Muon.h" +#include "DataFormats/MuonReco/interface/MuonFwd.h" +#include "DataFormats/EgammaCandidates/interface/Electron.h" +#include "DataFormats/EgammaCandidates/interface/ElectronFwd.h" +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" +#include "DataFormats/BeamSpot/interface/BeamSpot.h" +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/TrackReco/interface/TrackFwd.h" + +#include "DataFormats/TauReco/interface/PFTauDiscriminator.h" +#include "CommonTools/Utils/interface/StringCutObjectSelector.h" +#include "RecoTauTag/RecoTau/interface/RecoTauVertexAssociator.h" + +#include + +class PFTauPrimaryVertexProducerBase : public edm::stream::EDProducer<> { + public: + enum Alg{useInputPV=0, useFrontPV}; + + struct DiscCutPair{ + DiscCutPair():discr_(nullptr),cutFormula_(nullptr){} + ~DiscCutPair(){delete cutFormula_;} + const reco::PFTauDiscriminator* discr_; + edm::EDGetTokenT inputToken_; + double cut_; + TFormula* cutFormula_; + }; + typedef std::vector DiscCutPairVec; + + explicit PFTauPrimaryVertexProducerBase(const edm::ParameterSet& iConfig); + ~PFTauPrimaryVertexProducerBase() override; + void produce(edm::Event&,const edm::EventSetup&) override; + + static edm::ParameterSetDescription getDescriptionsBase(); + + // called at the beginning of every event - override if necessary + virtual void beginEvent(const edm::Event&, const edm::EventSetup&) {} + + protected: + // abstract function implemented in derived classes + virtual void nonTauTracksInPV(const reco::VertexRef&, + const std::vector >&, + std::vector&) = 0; + + private: + edm::EDGetTokenT > pftauToken_; + edm::EDGetTokenT > electronToken_; + edm::EDGetTokenT > muonToken_; + edm::EDGetTokenT pvToken_; + edm::EDGetTokenT beamSpotToken_; + int algorithm_; + edm::ParameterSet qualityCutsPSet_; + bool useBeamSpot_; + bool useSelectedTaus_; + bool removeMuonTracks_; + bool removeElectronTracks_; + DiscCutPairVec discriminators_; + std::unique_ptr > cut_; + std::unique_ptr vertexAssociator_; +}; + +#endif diff --git a/RecoTauTag/RecoTau/interface/RecoTauBinnedIsolationPlugin.h b/RecoTauTag/RecoTau/interface/RecoTauBinnedIsolationPlugin.h index 46550e0f4fad3..172ff31089610 100644 --- a/RecoTauTag/RecoTau/interface/RecoTauBinnedIsolationPlugin.h +++ b/RecoTauTag/RecoTau/interface/RecoTauBinnedIsolationPlugin.h @@ -17,7 +17,7 @@ */ #include "RecoTauTag/RecoTau/interface/RecoTauDiscriminantPlugins.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "DataFormats/Candidate/interface/CandidateFwd.h" namespace reco { namespace tau { @@ -28,7 +28,7 @@ class RecoTauDiscriminationBinnedIsolation : public RecoTauDiscriminantPlugin { void beginEvent() override; std::vector operator()(const reco::PFTauRef& tau) const override; // Pure abstract function to extract objects to isolate with - virtual std::vector extractIsoObjects( + virtual std::vector extractIsoObjects( const reco::PFTauRef& tau) const = 0; private: diff --git a/RecoTauTag/RecoTau/interface/RecoTauBuilderPlugins.h b/RecoTauTag/RecoTau/interface/RecoTauBuilderPlugins.h index 6388f996f632e..5c1b0bcaa6396 100644 --- a/RecoTauTag/RecoTau/interface/RecoTauBuilderPlugins.h +++ b/RecoTauTag/RecoTau/interface/RecoTauBuilderPlugins.h @@ -37,7 +37,7 @@ #include "FWCore/Framework/interface/ConsumesCollector.h" #include "DataFormats/VertexReco/interface/VertexFwd.h" -#include "DataFormats/JetReco/interface/PFJetCollection.h" +#include "DataFormats/JetReco/interface/JetCollection.h" #include "DataFormats/TauReco/interface/PFTau.h" #include "DataFormats/TauReco/interface/PFRecoTauChargedHadron.h" #include "DataFormats/TauReco/interface/RecoTauPiZero.h" @@ -51,7 +51,7 @@ namespace reco { namespace tau { -/* Class that constructs PFTau(s) from a PFJet and its associated PiZeros */ +/* Class that constructs PFTau(s) from a Jet and its associated PiZeros */ class RecoTauBuilderPlugin : public RecoTauEventHolderPlugin { public: @@ -64,7 +64,7 @@ class RecoTauBuilderPlugin : public RecoTauEventHolderPlugin vertexAssociator_(pset.getParameter("qualityCuts"),std::move(iC)) { pfCandSrc_ = pset.getParameter("pfCandSrc"); - pfCand_token = iC.consumes(pfCandSrc_); + pfCand_token = iC.consumes >(pfCandSrc_); }; ~RecoTauBuilderPlugin() override {} @@ -73,16 +73,16 @@ class RecoTauBuilderPlugin : public RecoTauEventHolderPlugin /// reconstructed PiZeros and regional extras i.e. objects in a 0.8 cone /// about the jet virtual return_type operator()( - const reco::PFJetRef&, const + const reco::JetBaseRef&, const std::vector&, const std::vector&, - const std::vector&) const = 0; + const std::vector&) const = 0; /// Hack to be able to convert Ptrs to Refs - const edm::Handle& getPFCands() const { return pfCands_; }; + const edm::Handle >& getPFCands() const { return pfCands_; }; /// Get primary vertex associated to this jet - reco::VertexRef primaryVertex(const reco::PFJetRef& jet) const { return vertexAssociator_.associatedVertex(*jet); } + reco::VertexRef primaryVertex(const reco::JetBaseRef& jet) const { return vertexAssociator_.associatedVertex(*jet); } /// Get primary vertex associated to this tau reco::VertexRef primaryVertex(const reco::PFTau& tau, bool useJet=false) const { return vertexAssociator_.associatedVertex(tau, useJet); } @@ -93,9 +93,9 @@ class RecoTauBuilderPlugin : public RecoTauEventHolderPlugin private: edm::InputTag pfCandSrc_; // Handle to PFCandidates needed to build Refs - edm::Handle pfCands_; + edm::Handle > pfCands_; reco::tau::RecoTauVertexAssociator vertexAssociator_; - edm::EDGetTokenT pfCand_token; + edm::EDGetTokenT > pfCand_token; }; /* Class that updates a PFTau's members (i.e. electron variables) */ diff --git a/RecoTauTag/RecoTau/interface/RecoTauCommonUtilities.h b/RecoTauTag/RecoTau/interface/RecoTauCommonUtilities.h index 886b7ad7941ff..f76f24612b8bc 100644 --- a/RecoTauTag/RecoTau/interface/RecoTauCommonUtilities.h +++ b/RecoTauTag/RecoTau/interface/RecoTauCommonUtilities.h @@ -9,13 +9,16 @@ * */ +#include +#include +#include + +#include "DataFormats/Candidate/interface/CandidateFwd.h" +#include "DataFormats/Candidate/interface/Candidate.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" #include "DataFormats/TauReco/interface/PFTau.h" #include "DataFormats/VertexReco/interface/VertexFwd.h" -#include -#include -#include // Boost helpers #include @@ -28,20 +31,20 @@ namespace reco { namespace tau { class SortPFCandsDescendingPt { public: - bool operator()(const PFCandidatePtr& a, const PFCandidatePtr& b) const { + bool operator()(const CandidatePtr& a, const CandidatePtr& b) const { return a->pt() > b->pt(); } }; -/// Filter a collection of objects that are convertible to PFCandidatePtrs +/// Filter a collection of objects that are convertible to CandidatePtrs /// by PFCandidate ID -template std::vector +template std::vector filterPFCandidates(const Iterator& begin, const Iterator& end, - int particleId, bool sort=true) { - std::vector output; + int pdgId, bool sort=true) { + std::vector output; for(Iterator iter = begin; iter != end; ++iter) { - reco::PFCandidatePtr ptr(*iter); - if (ptr->particleId() == particleId) + reco::CandidatePtr ptr(*iter); + if (std::abs(ptr->pdgId()) == pdgId) output.push_back(ptr); } if (sort) std::sort(output.begin(), output.end(), SortPFCandsDescendingPt()); @@ -49,24 +52,34 @@ filterPFCandidates(const Iterator& begin, const Iterator& end, } /// Extract pfCandidates of a given particle Id from a PFJet. If sort is true, -/// candidates will be sorted by descending PT -std::vector pfCandidates(const PFJet& jet, +/// candidates will be sorted by descending PT. Internally translates to pdgId +std::vector pfCandidates(const Jet& jet, int particleId, bool sort=true); /// Extract pfCandidates of a that match a list of particle Ids from a PFJet -std::vector pfCandidates(const PFJet& jet, +std::vector pfCandidates(const Jet& jet, const std::vector& particleIds, bool sort=true); +/// Extract pfCandidates of a given PDG Id from a PFJet. If sort is true, +/// candidates will be sorted by descending PT +std::vector pfCandidatesByPdgId(const Jet& jet, + int pdgId, bool sort=true); + +/// Extract pfCandidates of a that match a list of PDG Ids from a PFJet +std::vector pfCandidatesByPdgId(const Jet& jet, + const std::vector& pdgIds, + bool sort=true); + /// Extract all non-neutral candidates from a PFJet -std::vector pfChargedCands(const PFJet& jet, bool sort=true); +std::vector pfChargedCands(const Jet& jet, bool sort=true); /// Extract all pfGammas from a PFJet -std::vector pfGammas(const PFJet& jet, bool sort=true); +std::vector pfGammas(const Jet& jet, bool sort=true); /// Flatten a list of pi zeros into a list of there constituent PFCandidates -std::vector flattenPiZeros(const std::vector::const_iterator&, const std::vector::const_iterator&); -std::vector flattenPiZeros(const std::vector&); +std::vector flattenPiZeros(const std::vector::const_iterator&, const std::vector::const_iterator&); +std::vector flattenPiZeros(const std::vector&); /// Convert a BaseView (View) to a TRefVector template @@ -87,6 +100,7 @@ RefVectorType castView(const edm::Handle& view) { return output; } + /* *Given a range over a container of type C, return a new 'end' iterator such *that at max elements are taken. If there are less than N elements in the @@ -112,23 +126,23 @@ template template reco::Candidate::LorentzVector sumPFCandP4( InputIterator begin, InputIterator end) { - return sumPFVector(begin, end, &PFCandidate::p4, + return sumPFVector(begin, end, &Candidate::p4, reco::Candidate::LorentzVector()); } /// Sum the pT of a collection of PFCandidates template double sumPFCandPt(InputIterator begin, InputIterator end) { - return sumPFVector(begin, end, &PFCandidate::pt, 0.0); + return sumPFVector(begin, end, &Candidate::pt, 0.0); } /// Sum the charge of a collection of PFCandidates template int sumPFCandCharge(InputIterator begin, InputIterator end) { - return sumPFVector(begin, end, &PFCandidate::charge, 0); + return sumPFVector(begin, end, &Candidate::charge, 0); } -template InputIterator leadPFCand(InputIterator begin, +template InputIterator leadCand(InputIterator begin, InputIterator end) { double max_pt = 0; InputIterator max_cand = begin; @@ -140,5 +154,8 @@ template InputIterator leadPFCand(InputIterator begin, } return max_cand; } + +math::XYZPointF atECALEntrance(const reco::Candidate* part, double bField); + }} // end namespace reco::tau #endif diff --git a/RecoTauTag/RecoTau/interface/RecoTauConstructor.h b/RecoTauTag/RecoTau/interface/RecoTauConstructor.h index 9e138cbea84fa..87319ad1f56f5 100644 --- a/RecoTauTag/RecoTau/interface/RecoTauConstructor.h +++ b/RecoTauTag/RecoTau/interface/RecoTauConstructor.h @@ -27,7 +27,7 @@ #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" #include "DataFormats/TauReco/interface/PFTau.h" -#include "DataFormats/JetReco/interface/PFJetCollection.h" +#include "DataFormats/JetReco/interface/JetCollection.h" #include "DataFormats/TauReco/interface/PFRecoTauChargedHadron.h" #include "DataFormats/TauReco/interface/RecoTauPiZero.h" #include "CommonTools/Utils/interface/StringObjectFunction.h" @@ -52,8 +52,8 @@ class RecoTauConstructor { }; /// Constructor with PFCandidate Handle - RecoTauConstructor(const PFJetRef& jetRef, - const edm::Handle& pfCands, + RecoTauConstructor(const JetBaseRef& jetRef, + const edm::Handle >& pfCands, bool copyGammasFromPiZeros = false, const StringObjectFunction* signalConeSize = nullptr, double minAbsPhotonSumPt_insideSignalCone = 2.5, double minRelPhotonSumPt_insideSignalCone = 0., @@ -66,23 +66,22 @@ class RecoTauConstructor { */ /// Set leading PFChargedHadron candidate - template void setleadPFChargedHadrCand(const T& cand) { - tau_->setleadPFChargedHadrCand(convertToPtr(cand)); + template void setleadChargedHadrCand(const T& cand) { + tau_->setleadChargedHadrCand(convertToPtr(cand)); } /// Set leading PFGamma candidate - template void setleadPFNeutralCand(const T& cand) { - tau_->setleadPFNeutralCand(convertToPtr(cand)); + template void setleadNeutralCand(const T& cand) { + tau_->setleadNeutralCand(convertToPtr(cand)); } /// Set leading PF candidate - template void setleadPFCand(const T& cand) { - tau_->setleadPFCand(convertToPtr(cand)); + template void setleadCand(const T& cand) { + tau_->setleadCand(convertToPtr(cand)); } /// Append a PFCandidateRef/Ptr to a given collection - void addPFCand(Region region, ParticleType type, const PFCandidateRef& ref, bool skipAddToP4 = false); - void addPFCand(Region region, ParticleType type, const PFCandidatePtr& ptr, 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 void reserve(Region region, ParticleType type, size_t size); @@ -132,8 +131,8 @@ class RecoTauConstructor { private: typedef std::pair CollectionKey; - typedef std::map*> CollectionMap; - typedef boost::shared_ptr > SortedListPtr; + typedef std::map*> CollectionMap; + typedef boost::shared_ptr > SortedListPtr; typedef std::map SortedCollectionMap; bool copyGammas_; @@ -145,18 +144,17 @@ class RecoTauConstructor { double minRelPhotonSumPt_outsideSignalCone_; // Retrieve collection associated to signal/iso and type - std::vector* getCollection(Region region, ParticleType type); + std::vector* getCollection(Region region, ParticleType type); SortedListPtr getSortedCollection(Region region, ParticleType type); // Sort all our collections by PT and copy them into the tau void sortAndCopyIntoTau(); // Helper functions for dealing with refs - PFCandidatePtr convertToPtr(const PFCandidatePtr& pfPtr) const; - PFCandidatePtr convertToPtr(const CandidatePtr& candPtr) const; - PFCandidatePtr convertToPtr(const PFCandidateRef& pfRef) const; + CandidatePtr convertToPtr(const PFCandidatePtr& pfPtr) const; + CandidatePtr convertToPtr(const CandidatePtr& candPtr) const; - const edm::Handle& pfCands_; + const edm::Handle >& pfCands_; std::auto_ptr tau_; CollectionMap collections_; diff --git a/RecoTauTag/RecoTau/interface/RecoTauCrossCleaning.h b/RecoTauTag/RecoTau/interface/RecoTauCrossCleaning.h index 159f1d1ba255f..3ebd224b17012 100644 --- a/RecoTauTag/RecoTau/interface/RecoTauCrossCleaning.h +++ b/RecoTauTag/RecoTau/interface/RecoTauCrossCleaning.h @@ -102,7 +102,7 @@ class FilterPFCandByParticleId { public: FilterPFCandByParticleId(int particleId): id_(particleId){}; - template + template bool operator()(const PFCandCompatiblePtrType& ptr) const { return ptr->particleId() == id_; } @@ -110,6 +110,19 @@ class FilterPFCandByParticleId { int id_; }; +// Predicate to filter CandPtrs by the abs(pdgId) +class FilterCandByAbsPdgId { + public: + FilterCandByAbsPdgId(int pdgId): + id_(pdgId){}; + template + bool operator()(const CandCompatiblePtrType& ptr) const { + return std::abs(ptr->pdgId()) == id_; + } + private: + int id_; +}; + // Create the AND of two predicates template class PredicateAND { diff --git a/RecoTauTag/RecoTau/interface/RecoTauDiscriminantFunctions.h b/RecoTauTag/RecoTau/interface/RecoTauDiscriminantFunctions.h index fd5647d3d7b05..75404c9ae553e 100644 --- a/RecoTauTag/RecoTau/interface/RecoTauDiscriminantFunctions.h +++ b/RecoTauTag/RecoTau/interface/RecoTauDiscriminantFunctions.h @@ -26,7 +26,7 @@ typedef std::vector VDouble; /// For three prong events, take the track that has charge opposite to the /// composite charge. -PFCandidatePtr mainTrack(const PFTau& tau); +CandidatePtr mainTrack(const PFTau& tau); // HPStanc variables double JetPt(Tau tau); diff --git a/RecoTauTag/RecoTau/interface/RecoTauIsolationMasking.h b/RecoTauTag/RecoTau/interface/RecoTauIsolationMasking.h index 84b4b34b51943..8210c33945a7d 100644 --- a/RecoTauTag/RecoTau/interface/RecoTauIsolationMasking.h +++ b/RecoTauTag/RecoTau/interface/RecoTauIsolationMasking.h @@ -25,8 +25,8 @@ class RecoTauIsolationMasking { public: // Structure containing new, maksed isolation collections struct IsoMaskResult { - std::list gammas; - std::list h0s; + std::list gammas; + std::list h0s; }; RecoTauIsolationMasking(const edm::ParameterSet& pset); ~RecoTauIsolationMasking(); @@ -36,10 +36,10 @@ class RecoTauIsolationMasking { void setMaxSigmas(double maxSigmas) {maxSigmas_ = maxSigmas;} private: // Get the energy resoltuion of a gamma or h0 candidate - double resolution(const reco::PFCandidate& cand) const; + double resolution(const reco::Candidate& cand) const; // Check if the candidate is in the correct cone bool inCone(const reco::PFCandidate& track, - const reco::PFCandidate& cand) const; + const reco::Candidate& cand) const; double ecalCone_; double hcalCone_; diff --git a/RecoTauTag/RecoTau/interface/RecoTauMuonTools.h b/RecoTauTag/RecoTau/interface/RecoTauMuonTools.h new file mode 100644 index 0000000000000..1c4d6246f5c18 --- /dev/null +++ b/RecoTauTag/RecoTau/interface/RecoTauMuonTools.h @@ -0,0 +1,19 @@ +#ifndef RecoTauTag_RecoTau_RecoTauMuonTools_h +#define RecoTauTag_RecoTau_RecoTauMuonTools_h + +/* + * RecoTauMuonTools - utilities for muon->tau discrimination. + + */ + +#include + +#include "DataFormats/PatCandidates/interface/Muon.h" + +namespace reco { namespace tau { + void countHits(const reco::Muon& muon, std::vector& numHitsDT, std::vector& numHitsCSC, std::vector& numHitsRPC); + void countMatches(const reco::Muon& muon, std::vector& numMatchesDT, std::vector& numMatchesCSC, std::vector& numMatchesRPC); + std::string format_vint(const std::vector& vi); +}} // end namespace reco::tau + +#endif diff --git a/RecoTauTag/RecoTau/interface/RecoTauPiZeroPlugins.h b/RecoTauTag/RecoTau/interface/RecoTauPiZeroPlugins.h index 057478dfc1854..ce946155d44b9 100644 --- a/RecoTauTag/RecoTau/interface/RecoTauPiZeroPlugins.h +++ b/RecoTauTag/RecoTau/interface/RecoTauPiZeroPlugins.h @@ -26,7 +26,7 @@ namespace reco { // Forward declarations -class PFJet; +class Jet; class RecoTauPiZero; namespace tau { @@ -41,7 +41,7 @@ class RecoTauPiZeroBuilderPlugin : public RecoTauEventHolderPlugin { RecoTauEventHolderPlugin(pset) {} ~RecoTauPiZeroBuilderPlugin() override {} /// Build a collection of piZeros from objects in the input jet - virtual return_type operator()(const PFJet&) const = 0; + virtual return_type operator()(const Jet&) const = 0; /// Hook called at the beginning of the event. void beginEvent() override {}; }; diff --git a/RecoTauTag/RecoTau/interface/RecoTauQualityCuts.h b/RecoTauTag/RecoTau/interface/RecoTauQualityCuts.h index e1db68456a5e1..ad6d06f8be22e 100644 --- a/RecoTauTag/RecoTau/interface/RecoTauQualityCuts.h +++ b/RecoTauTag/RecoTau/interface/RecoTauQualityCuts.h @@ -6,10 +6,10 @@ * * Author: Evan K. Friis * - * Constructs a number of independent requirements on PFCandidates by building + * Constructs a number of independent requirements on Candidates by building * binary predicate functions. These are held in a number of lists of - * functions. Each of these lists is mapped to a PFCandidate particle type - * (like hadron, gamma, etc). When a PFCandidate is passed to filter(), + * functions. Each of these lists is mapped to a Candidate particle type + * (like hadron, gamma, etc). When a Candidate is passed to filter(), * the correct list is looked up, and the result is the AND of all the predicate * functions. See the .cc files for the QCut functions. * @@ -20,8 +20,8 @@ */ #include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "DataFormats/Candidate/interface/CandidateFwd.h" #include "DataFormats/TrackReco/interface/Track.h" #include "DataFormats/TrackReco/interface/TrackFwd.h" #include "DataFormats/VertexReco/interface/VertexFwd.h" @@ -34,11 +34,11 @@ class RecoTauQualityCuts { public: // Quality cut types - typedef std::function TrackQCutFunc; + typedef std::function TrackQCutFunc; typedef std::vector TrackQCutFuncCollection; - typedef std::function CandQCutFunc; + typedef std::function CandQCutFunc; typedef std::vector CandQCutFuncCollection; - typedef std::map CandQCutFuncMap; + typedef std::map CandQCutFuncMap; explicit RecoTauQualityCuts(const edm::ParameterSet& qcuts); @@ -46,16 +46,19 @@ class RecoTauQualityCuts void setPV(const reco::VertexRef& vtx) const { pv_ = vtx; } /// Update the leading track - void setLeadTrack(const reco::TrackRef& leadTrack) const; - void setLeadTrack(const reco::PFCandidate& leadCand) const; + void setLeadTrack(const reco::Track& leadTrack) const; + void setLeadTrack(const reco::Candidate& leadCand) const; /// Update the leading track (using reference) /// If null, this will set the lead track ref null. - void setLeadTrack(const reco::PFCandidateRef& leadCand) const; + void setLeadTrack(const reco::CandidateRef& leadCand) const; /// Filter a single Track bool filterTrack(const reco::TrackBaseRef& track) const; bool filterTrack(const reco::TrackRef& track) const; + bool filterTrack(const reco::Track& track) const; + /// or a single charged candidate + bool filterChargedCand(const reco::Candidate& cand) const; /// Filter a collection of Tracks template @@ -68,14 +71,14 @@ class RecoTauQualityCuts return output; } - /// Filter a single PFCandidate - bool filterCand(const reco::PFCandidate& cand) const; + /// Filter a single Candidate + bool filterCand(const reco::Candidate& cand) const; - /// Filter a PFCandidate held by a smart pointer or Ref - template - bool filterCandRef(const PFCandRefType& cand) const { return filterCand(*cand); } + /// Filter a Candidate held by a smart pointer or Ref + template + bool filterCandRef(const CandRefType& cand) const { return filterCand(*cand); } - /// Filter a ref vector of PFCandidates + /// Filter a ref vector of Candidates template Coll filterCandRefs(const Coll& refcoll, bool invert = false) const { @@ -87,15 +90,15 @@ class RecoTauQualityCuts } private: - template bool filterTrack_(const T& trackRef) const; - bool filterGammaCand(const reco::PFCandidate& cand) const; - bool filterNeutralHadronCand(const reco::PFCandidate& cand) const; - bool filterCandByType(const reco::PFCandidate& cand) const; + bool filterTrack_(const reco::Track* track) const; + bool filterGammaCand(const reco::Candidate& cand) const; + bool filterNeutralHadronCand(const reco::Candidate& cand) const; + bool filterCandByType(const reco::Candidate& cand) const; // The current primary vertex mutable reco::VertexRef pv_; // The current lead track references - mutable reco::TrackBaseRef leadTrack_; + mutable const reco::Track* leadTrack_; double minTrackPt_; double maxTrackChi2_; diff --git a/RecoTauTag/RecoTau/interface/RecoTauVertexAssociator.h b/RecoTauTag/RecoTau/interface/RecoTauVertexAssociator.h index c364edfd84809..7eec4702f159e 100644 --- a/RecoTauTag/RecoTau/interface/RecoTauVertexAssociator.h +++ b/RecoTauTag/RecoTau/interface/RecoTauVertexAssociator.h @@ -25,7 +25,7 @@ #include "RecoTauTag/RecoTau/interface/RecoTauQualityCuts.h" #include "DataFormats/Common/interface/AssociationMap.h" -#include "DataFormats/JetReco/interface/PFJetCollection.h" +#include "DataFormats/JetReco/interface/JetCollection.h" #include "CommonTools/Utils/interface/StringCutObjectSelector.h" @@ -41,7 +41,7 @@ namespace edm { namespace reco { class PFTau; - class PFJet; + class Jet; } namespace reco { namespace tau { @@ -59,16 +59,19 @@ class RecoTauVertexAssociator { virtual ~RecoTauVertexAssociator(); /// Get the primary vertex associated to a given jet. /// Returns a null Ref if no vertex is found. - reco::VertexRef associatedVertex(const PFJet& jet) const; + reco::VertexRef associatedVertex(const Jet& jet) const; /// Convenience function to get the PV associated to the jet that /// seeded this tau (useJet=true, old behaviour) /// or leaging charged hadron if set (useJet=false). reco::VertexRef associatedVertex(const PFTau& tau, bool useJet=false) const; reco::VertexRef associatedVertex(const TrackBaseRef& track) const; + reco::VertexRef associatedVertex(const Track* track) const; /// Load the vertices from the event. void setEvent(const edm::Event& evt); - reco::TrackBaseRef getLeadTrack(const PFJet& jet) const; + const Track* getLeadTrack(const Jet&) const; + const TrackBaseRef getLeadTrackRef(const Jet&) const; + const CandidatePtr getLeadCand(const Jet&) const; private: edm::InputTag vertexTag_; @@ -84,7 +87,7 @@ class RecoTauVertexAssociator { int leadingTrkOrPFCandOption_; edm::EDGetTokenT vxToken_; // containers for holding vertices associated to jets - std::map* jetToVertexAssociation_; + std::map* jetToVertexAssociation_; edm::EventNumber_t lastEvent_; int verbosity_; }; diff --git a/RecoTauTag/RecoTau/interface/pfRecoTauChargedHadronAuxFunctions.h b/RecoTauTag/RecoTau/interface/pfRecoTauChargedHadronAuxFunctions.h index 0a4e724d64c3b..1c858bbc02807 100644 --- a/RecoTauTag/RecoTau/interface/pfRecoTauChargedHadronAuxFunctions.h +++ b/RecoTauTag/RecoTau/interface/pfRecoTauChargedHadronAuxFunctions.h @@ -7,6 +7,7 @@ namespace reco { namespace tau { + const reco::Track* getTrackFromChargedHadron(const reco::PFRecoTauChargedHadron& chargedHadron); void setChargedHadronP4(reco::PFRecoTauChargedHadron& chargedHadron, double scaleFactor_neutralPFCands = 1.0); reco::Candidate::LorentzVector compChargedHadronP4fromPxPyPz(double, double, double); reco::Candidate::LorentzVector compChargedHadronP4fromPThetaPhi(double, double, double); diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromTrackPlugin.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromGenericTrackPlugin.cc similarity index 50% rename from RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromTrackPlugin.cc rename to RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromGenericTrackPlugin.cc index 53818afe6d602..3b4d34a9478e6 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromTrackPlugin.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromGenericTrackPlugin.cc @@ -1,11 +1,16 @@ /* - * PFRecoTauChargedHadronFromTrackPlugin + * 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 original implementation + * by Michal Bluj, NCBJ, Poland */ #include "RecoTauTag/RecoTau/interface/PFRecoTauChargedHadronPlugins.h" @@ -18,6 +23,7 @@ #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" #include "DataFormats/TrackReco/interface/Track.h" #include "DataFormats/TrackReco/interface/TrackFwd.h" #include "DataFormats/VertexReco/interface/Vertex.h" @@ -40,28 +46,33 @@ #include #include +#include namespace reco { namespace tau { -class PFRecoTauChargedHadronFromTrackPlugin : public PFRecoTauChargedHadronBuilderPlugin +template +class PFRecoTauChargedHadronFromGenericTrackPlugin : public PFRecoTauChargedHadronBuilderPlugin { public: - explicit PFRecoTauChargedHadronFromTrackPlugin(const edm::ParameterSet&, edm::ConsumesCollector && iC); - ~PFRecoTauChargedHadronFromTrackPlugin() override; + explicit PFRecoTauChargedHadronFromGenericTrackPlugin(const edm::ParameterSet&, edm::ConsumesCollector && iC); + ~PFRecoTauChargedHadronFromGenericTrackPlugin() override; // Return type is auto_ptr - return_type operator()(const reco::PFJet&) const override; + return_type operator()(const reco::Jet&) const override; // Hook to update PV information void beginEvent() override; private: - typedef std::vector PFCandPtrs; + bool filterTrack(const edm::Handle >&, size_t iTrack) const; + void setChargedHadronTrack(PFRecoTauChargedHadron& chargedHadron, const edm::Ptr& track) const; + double getTrackPtError(const TrackClass& track) const; + XYZTLorentzVector getTrackPos(const TrackClass& track) const; RecoTauVertexAssociator vertexAssociator_; RecoTauQualityCuts* qcuts_; edm::InputTag srcTracks_; - edm::EDGetTokenT Tracks_token; + edm::EDGetTokenT > Tracks_token; double dRcone_; bool dRconeLimitedToJetArea_; @@ -76,7 +87,8 @@ class PFRecoTauChargedHadronFromTrackPlugin : public PFRecoTauChargedHadronBuild int verbosity_; }; - PFRecoTauChargedHadronFromTrackPlugin::PFRecoTauChargedHadronFromTrackPlugin(const edm::ParameterSet& pset, edm::ConsumesCollector && iC) +template +PFRecoTauChargedHadronFromGenericTrackPlugin::PFRecoTauChargedHadronFromGenericTrackPlugin(const edm::ParameterSet& pset, edm::ConsumesCollector && iC) : PFRecoTauChargedHadronBuilderPlugin(pset,std::move(iC)), vertexAssociator_(pset.getParameter("qualityCuts"),std::move(iC)), qcuts_(nullptr) @@ -85,7 +97,7 @@ class PFRecoTauChargedHadronFromTrackPlugin : public PFRecoTauChargedHadronBuild qcuts_ = new RecoTauQualityCuts(qcuts_pset); srcTracks_ = pset.getParameter("srcTracks"); - Tracks_token = iC.consumes(srcTracks_); + Tracks_token = iC.consumes >(srcTracks_); dRcone_ = pset.getParameter("dRcone"); dRconeLimitedToJetArea_ = pset.getParameter("dRconeLimitedToJetArea"); @@ -97,40 +109,102 @@ class PFRecoTauChargedHadronFromTrackPlugin : public PFRecoTauChargedHadronBuild verbosity_ = pset.getParameter("verbosity"); } - -PFRecoTauChargedHadronFromTrackPlugin::~PFRecoTauChargedHadronFromTrackPlugin() + +template +PFRecoTauChargedHadronFromGenericTrackPlugin::~PFRecoTauChargedHadronFromGenericTrackPlugin() { delete qcuts_; } // Update the primary vertex -void PFRecoTauChargedHadronFromTrackPlugin::beginEvent() +template +void PFRecoTauChargedHadronFromGenericTrackPlugin::beginEvent() { vertexAssociator_.setEvent(*this->evt()); edm::ESHandle magneticField; - evtSetup()->get().get(magneticField); + const edm::EventSetup* evtSetup(this->evtSetup()); + evtSetup->get().get(magneticField); magneticFieldStrength_ = magneticField->inTesla(GlobalPoint(0.,0.,0.)); } +template<> +bool PFRecoTauChargedHadronFromGenericTrackPlugin::filterTrack(const edm::Handle >& tracks, size_t iTrack) const { +// ignore tracks which fail quality cuts + reco::TrackRef trackRef(tracks, iTrack); + return qcuts_->filterTrack(trackRef); +} + +template<> +bool PFRecoTauChargedHadronFromGenericTrackPlugin::filterTrack(const edm::Handle >& tracks, size_t iTrack) const { + // ignore tracks which fail quality cuts + const pat::PackedCandidate& cand = (*tracks)[iTrack]; + if (cand.charge() == 0) + return false; + + return qcuts_->filterChargedCand(cand); +} + +template<> +void PFRecoTauChargedHadronFromGenericTrackPlugin::setChargedHadronTrack(PFRecoTauChargedHadron& chargedHadron, const edm::Ptr& track) const { + chargedHadron.track_ = track; +} + +template<> +void PFRecoTauChargedHadronFromGenericTrackPlugin::setChargedHadronTrack(PFRecoTauChargedHadron& chargedHadron, const edm::Ptr& track) const { + chargedHadron.lostTrackCandidate_ = track; +} + +template<> +double PFRecoTauChargedHadronFromGenericTrackPlugin::getTrackPtError(const reco::Track& track) const { + return track.ptError(); +} + +template<> +double PFRecoTauChargedHadronFromGenericTrackPlugin::getTrackPtError(const pat::PackedCandidate& cand) const { + double trackPtError = 0.06; // MB: Approximate avarage track PtError by 2.5% (barrel), 4% (transition), 6% (endcaps) lostTracks w/o detailed track information available (after TRK-11-001) + const reco::Track* track(cand.bestTrack()); + if(track != nullptr) { + trackPtError = track->ptError(); + } else { + if( std::abs(cand.eta()) < 0.9 ) + trackPtError = 0.025; + else if( std::abs(cand.eta()) < 1.4 ) + trackPtError = 0.04; + } + return trackPtError; +} + +template<> +XYZTLorentzVector PFRecoTauChargedHadronFromGenericTrackPlugin::getTrackPos(const reco::Track& track) const { + return XYZTLorentzVector(track.referencePoint().x(), track.referencePoint().y(), track.referencePoint().z(), 0.); +} + +template<> +XYZTLorentzVector PFRecoTauChargedHadronFromGenericTrackPlugin::getTrackPos(const pat::PackedCandidate& track) const { + return XYZTLorentzVector(track.vertex().x(), track.vertex().y(), track.vertex().z(), 0.); +} + + namespace { - struct PFCandidate_withDistance + struct Candidate_withDistance { - reco::PFCandidatePtr pfCandidate_; + reco::CandidatePtr pfCandidate_; double distance_; }; - bool isSmallerDistance(const PFCandidate_withDistance& cand1, const PFCandidate_withDistance& cand2) + bool isSmallerDistance(const Candidate_withDistance& cand1, const Candidate_withDistance& cand2) { return (cand1.distance_ < cand2.distance_); } } -PFRecoTauChargedHadronFromTrackPlugin::return_type PFRecoTauChargedHadronFromTrackPlugin::operator()(const reco::PFJet& jet) const +template +typename PFRecoTauChargedHadronFromGenericTrackPlugin::return_type PFRecoTauChargedHadronFromGenericTrackPlugin::operator()(const reco::Jet& jet) const { if ( verbosity_ ) { - edm::LogPrint("TauChHFromTrack") << ":" ; + edm::LogPrint("TauChHFromTrack") << ":" ; edm::LogPrint("TauChHFromTrack") << " pluginName = " << name() ; } @@ -138,7 +212,7 @@ PFRecoTauChargedHadronFromTrackPlugin::return_type PFRecoTauChargedHadronFromTra const edm::Event& evt = (*this->evt()); - edm::Handle tracks; + edm::Handle > tracks; evt.getByToken(Tracks_token, tracks); qcuts_->setPV(vertexAssociator_.associatedVertex(jet)); @@ -146,18 +220,18 @@ PFRecoTauChargedHadronFromTrackPlugin::return_type PFRecoTauChargedHadronFromTra float jPhi=jet.phi(); size_t numTracks = tracks->size(); for ( size_t iTrack = 0; iTrack < numTracks; ++iTrack ) { - reco::TrackRef track(tracks, iTrack); + const TrackClass& track = (*tracks)[iTrack]; // consider tracks in vicinity of tau-jet candidate only - double dR = deltaR(track->eta(), track->phi(), jEta,jPhi); + double dR = deltaR(track.eta(), track.phi(), jEta,jPhi); double dRmatch = dRcone_; if ( dRconeLimitedToJetArea_ ) { double jetArea = jet.jetArea(); if ( jetArea > 0. ) { - dRmatch = TMath::Min(dRmatch, TMath::Sqrt(jetArea/TMath::Pi())); + dRmatch = std::min(dRmatch, sqrt(jetArea/M_PI)); } else { if ( numWarnings_ < maxWarnings_ ) { - edm::LogInfo("PFRecoTauChargedHadronFromTrackPlugin::operator()") + edm::LogInfo("PFRecoTauChargedHadronFromGenericTrackPlugin::operator()") << "Jet: Pt = " << jet.pt() << ", eta = " << jet.eta() << ", phi = " << jet.phi() << " has area = " << jetArea << " !!" << std::endl; ++numWarnings_; } @@ -166,23 +240,23 @@ PFRecoTauChargedHadronFromTrackPlugin::return_type PFRecoTauChargedHadronFromTra } if ( dR > dRmatch ) continue; - // ignore tracks which fail quality cuts - if ( !qcuts_->filterTrack(track) ) continue; + if (!this->filterTrack(tracks, iTrack)) continue; reco::Candidate::Charge trackCharge_int = 0; - if ( track->charge() > 0. ) trackCharge_int = +1; - else if ( track->charge() < 0. ) trackCharge_int = -1; + if ( track.charge() > 0. ) trackCharge_int = +1; + else if ( track.charge() < 0. ) trackCharge_int = -1; const double chargedPionMass = 0.13957; // GeV - double chargedPionP = track->p(); + double chargedPionP = track.p(); double chargedPionEn = TMath::Sqrt(chargedPionP*chargedPionP + chargedPionMass*chargedPionMass); - reco::Candidate::LorentzVector chargedPionP4(track->px(), track->py(), track->pz(), chargedPionEn); + reco::Candidate::LorentzVector chargedPionP4(track.px(), track.py(), track.pz(), chargedPionEn); reco::Vertex::Point vtx(0.,0.,0.); if ( vertexAssociator_.associatedVertex(jet).isNonnull() ) vtx = vertexAssociator_.associatedVertex(jet)->position(); std::auto_ptr chargedHadron(new PFRecoTauChargedHadron(trackCharge_int, chargedPionP4, vtx, 0, true, PFRecoTauChargedHadron::kTrack)); - chargedHadron->track_ = edm::Ptr(tracks, iTrack); + + setChargedHadronTrack(*chargedHadron, edm::Ptr(tracks, iTrack)); // CV: Take code for propagating track to ECAL entrance // from RecoParticleFlow/PFTracking/src/PFTrackTransformer.cc @@ -194,50 +268,48 @@ PFRecoTauChargedHadronFromTrackPlugin::return_type PFRecoTauChargedHadronFromTra // in order to run on AOD input // (outerMomentum and outerPosition require access to reco::TrackExtra objects, which are available in RECO only) // - XYZTLorentzVector chargedPionPos(track->referencePoint().x(), track->referencePoint().y(), track->referencePoint().z(), 0.); + XYZTLorentzVector chargedPionPos(getTrackPos(track)); RawParticle p(chargedPionP4, chargedPionPos); - p.setCharge(track->charge()); + p.setCharge(track.charge()); BaseParticlePropagator trackPropagator(p, 0., 0., magneticFieldStrength_.z()); trackPropagator.propagateToEcalEntrance(false); if ( trackPropagator.getSuccess() != 0 ) { chargedHadron->positionAtECALEntrance_ = trackPropagator.particle().vertex(); } else { if ( chargedPionP4.pt() > 2. and std::abs(chargedPionP4.eta()) < 3. ) { - edm::LogWarning("PFRecoTauChargedHadronFromTrackPlugin::operator()") - << "Failed to propagate track: Pt = " << track->pt() << ", eta = " << track->eta() << ", phi = " << track->phi() << " to ECAL entrance !!" << std::endl; + edm::LogWarning("PFRecoTauChargedHadronFromGenericTrackPlugin::operator()") + << "Failed to propagate track: Pt = " << track.pt() << ", eta = " << track.eta() << ", phi = " << track.phi() << " to ECAL entrance !!" << std::endl; } chargedHadron->positionAtECALEntrance_ = math::XYZPointF(0.,0.,0.); } - std::vector neutralJetConstituents_withDistance; - std::vector jetConstituents = jet.getPFConstituents(); - for ( std::vector::const_iterator jetConstituent = jetConstituents.begin(); - jetConstituent != jetConstituents.end(); ++jetConstituent ) { - reco::PFCandidate::ParticleType jetConstituentType = (*jetConstituent)->particleId(); - if ( !(jetConstituentType == reco::PFCandidate::h0 || jetConstituentType == reco::PFCandidate::gamma) ) continue; - double dR = deltaR((*jetConstituent)->positionAtECALEntrance(), chargedHadron->positionAtECALEntrance_); + std::vector neutralJetConstituents_withDistance; + 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_); double dRmerge = -1.; - if ( jetConstituentType == reco::PFCandidate::h0 ) dRmerge = dRmergeNeutralHadron_; - else if ( jetConstituentType == reco::PFCandidate::gamma ) dRmerge = dRmergePhoton_; + if ( pdgId == 130 ) dRmerge = dRmergeNeutralHadron_; + else if ( pdgId == 22 ) dRmerge = dRmergePhoton_; if ( dR < dRmerge ) { - PFCandidate_withDistance jetConstituent_withDistance; - jetConstituent_withDistance.pfCandidate_ = (*jetConstituent); + Candidate_withDistance jetConstituent_withDistance; + jetConstituent_withDistance.pfCandidate_ = jetConstituent; jetConstituent_withDistance.distance_ = dR; neutralJetConstituents_withDistance.push_back(jetConstituent_withDistance); - chargedHadron->addDaughter(*jetConstituent); + chargedHadron->addDaughter(jetConstituent); } } std::sort(neutralJetConstituents_withDistance.begin(), neutralJetConstituents_withDistance.end(), isSmallerDistance); const double caloResolutionCoeff = 1.0; // CV: approximate ECAL + HCAL calorimeter resolution for hadrons by 100%*sqrt(E) - double resolutionTrackP = track->p()*(track->ptError()/track->pt()); + double resolutionTrackP = track.p()*(getTrackPtError(track)/track.pt()); double neutralEnSum = 0.; - for ( std::vector::const_iterator nextNeutral = neutralJetConstituents_withDistance.begin(); + for ( std::vector::const_iterator nextNeutral = neutralJetConstituents_withDistance.begin(); nextNeutral != neutralJetConstituents_withDistance.end(); ++nextNeutral ) { double nextNeutralEn = nextNeutral->pfCandidate_->energy(); double resolutionCaloEn = caloResolutionCoeff*sqrt(neutralEnSum + nextNeutralEn); double resolution = sqrt(resolutionTrackP*resolutionTrackP + resolutionCaloEn*resolutionCaloEn); - if ( (neutralEnSum + nextNeutralEn) < (track->p() + 2.*resolution) ) { + if ( (neutralEnSum + nextNeutralEn) < (track.p() + 2.*resolution) ) { chargedHadron->neutralPFCandidates_.push_back(nextNeutral->pfCandidate_); neutralEnSum += nextNeutralEn; } else { @@ -257,8 +329,12 @@ PFRecoTauChargedHadronFromTrackPlugin::return_type PFRecoTauChargedHadronFromTra return output.release(); } +typedef PFRecoTauChargedHadronFromGenericTrackPlugin PFRecoTauChargedHadronFromTrackPlugin; +typedef PFRecoTauChargedHadronFromGenericTrackPlugin PFRecoTauChargedHadronFromLostTrackPlugin; + }} // end namespace reco::tau #include "FWCore/Framework/interface/MakerMacros.h" DEFINE_EDM_PLUGIN(PFRecoTauChargedHadronBuilderPluginFactory, reco::tau::PFRecoTauChargedHadronFromTrackPlugin, "PFRecoTauChargedHadronFromTrackPlugin"); +DEFINE_EDM_PLUGIN(PFRecoTauChargedHadronBuilderPluginFactory, reco::tau::PFRecoTauChargedHadronFromLostTrackPlugin, "PFRecoTauChargedHadronFromLostTrackPlugin"); diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromPFCandidatePlugin.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromPFCandidatePlugin.cc index 602ebd5fe147d..48321f97476d6 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromPFCandidatePlugin.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromPFCandidatePlugin.cc @@ -21,15 +21,20 @@ #include "DataFormats/MuonReco/interface/Muon.h" #include "DataFormats/MuonReco/interface/MuonFwd.h" #include "DataFormats/TauReco/interface/PFRecoTauChargedHadron.h" -#include "DataFormats/JetReco/interface/PFJet.h" +#include "DataFormats/JetReco/interface/Jet.h" #include "DataFormats/Math/interface/deltaR.h" #include "DataFormats/Common/interface/RefToPtr.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "MagneticField/Engine/interface/MagneticField.h" +#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" + #include "RecoTauTag/RecoTau/interface/RecoTauCommonUtilities.h" #include "RecoTauTag/RecoTau/interface/RecoTauQualityCuts.h" #include "RecoTauTag/RecoTau/interface/RecoTauVertexAssociator.h" #include "RecoTauTag/RecoTau/interface/pfRecoTauChargedHadronAuxFunctions.h" + #include namespace reco @@ -44,18 +49,18 @@ class PFRecoTauChargedHadronFromPFCandidatePlugin : public PFRecoTauChargedHadro explicit PFRecoTauChargedHadronFromPFCandidatePlugin(const edm::ParameterSet&, edm::ConsumesCollector &&iC); ~PFRecoTauChargedHadronFromPFCandidatePlugin() override; // Return type is auto_ptr - return_type operator()(const reco::PFJet&) const override; + return_type operator()(const reco::Jet&) const override; // Hook to update PV information void beginEvent() override; private: - typedef std::vector PFCandPtrs; + typedef std::vector CandPtrs; RecoTauVertexAssociator vertexAssociator_; RecoTauQualityCuts* qcuts_; - std::vector inputPdgIds_; // type of candidates to clusterize + std::vector inputParticleIds_; // type of candidates to clusterize double dRmergeNeutralHadronWrtChargedHadron_; double dRmergeNeutralHadronWrtNeutralHadron_; @@ -73,6 +78,8 @@ class PFRecoTauChargedHadronFromPFCandidatePlugin : public PFRecoTauChargedHadro double minMergeGammaEt_; double minMergeChargedHadronPt_; + double bField_; + int verbosity_; }; @@ -84,7 +91,7 @@ class PFRecoTauChargedHadronFromPFCandidatePlugin : public PFRecoTauChargedHadro edm::ParameterSet qcuts_pset = pset.getParameterSet("qualityCuts").getParameterSet("signalQualityCuts"); qcuts_ = new RecoTauQualityCuts(qcuts_pset); - inputPdgIds_ = pset.getParameter >("chargedHadronCandidatesParticleIds"); + inputParticleIds_ = pset.getParameter >("chargedHadronCandidatesParticleIds"); dRmergeNeutralHadronWrtChargedHadron_ = pset.getParameter("dRmergeNeutralHadronWrtChargedHadron"); dRmergeNeutralHadronWrtNeutralHadron_ = pset.getParameter("dRmergeNeutralHadronWrtNeutralHadron"); @@ -114,23 +121,14 @@ PFRecoTauChargedHadronFromPFCandidatePlugin::~PFRecoTauChargedHadronFromPFCandid void PFRecoTauChargedHadronFromPFCandidatePlugin::beginEvent() { vertexAssociator_.setEvent(*evt()); + + edm::ESHandle pSetup; + evtSetup()->get().get(pSetup); + bField_ = pSetup->inTesla(GlobalPoint(0,0,0)).z(); } namespace { - std::string getPFCandidateType(reco::PFCandidate::ParticleType pfCandidateType) - { - if ( pfCandidateType == reco::PFCandidate::X ) return "undefined"; - else if ( pfCandidateType == reco::PFCandidate::h ) return "PFChargedHadron"; - else if ( pfCandidateType == reco::PFCandidate::e ) return "PFElectron"; - else if ( pfCandidateType == reco::PFCandidate::mu ) return "PFMuon"; - else if ( pfCandidateType == reco::PFCandidate::gamma ) return "PFGamma"; - else if ( pfCandidateType == reco::PFCandidate::h0 ) return "PFNeutralHadron"; - else if ( pfCandidateType == reco::PFCandidate::h_HF ) return "HF_had"; - else if ( pfCandidateType == reco::PFCandidate::egamma_HF ) return "HF_em"; - else assert(0); - } - bool isMatchedByBlockElement(const reco::PFCandidate& pfCandidate1, const reco::PFCandidate& pfCandidate2, int minMatches1, int minMatches2, int maxUnmatchedBlockElements1plus2) { reco::PFCandidate::ElementsInBlocks blockElements1 = pfCandidate1.elementsInBlocks(); @@ -162,7 +160,7 @@ namespace } } -PFRecoTauChargedHadronFromPFCandidatePlugin::return_type PFRecoTauChargedHadronFromPFCandidatePlugin::operator()(const reco::PFJet& jet) const +PFRecoTauChargedHadronFromPFCandidatePlugin::return_type PFRecoTauChargedHadronFromPFCandidatePlugin::operator()(const reco::Jet& jet) const { if ( verbosity_ ) { edm::LogPrint("TauChHadronFromPF") << ":"; @@ -173,67 +171,81 @@ PFRecoTauChargedHadronFromPFCandidatePlugin::return_type PFRecoTauChargedHadronF // Get the candidates passing our quality cuts qcuts_->setPV(vertexAssociator_.associatedVertex(jet)); - PFCandPtrs candsVector = qcuts_->filterCandRefs(pfCandidates(jet, inputPdgIds_)); + CandPtrs candsVector = qcuts_->filterCandRefs(pfCandidates(jet, inputParticleIds_)); - for ( PFCandPtrs::iterator cand = candsVector.begin(); + for ( CandPtrs::iterator cand = candsVector.begin(); cand != candsVector.end(); ++cand ) { if ( verbosity_ ) { edm::LogPrint("TauChHadronFromPF") << "processing PFCandidate: Pt = " << (*cand)->pt() << ", eta = " << (*cand)->eta() << ", phi = " << (*cand)->phi() - << " (type = " << getPFCandidateType((*cand)->particleId()) << ", charge = " << (*cand)->charge() << ")" ; + << " (pdgId = " << (*cand)->pdgId() << ", charge = " << (*cand)->charge() << ")" ; } PFRecoTauChargedHadron::PFRecoTauChargedHadronAlgorithm algo = PFRecoTauChargedHadron::kUndefined; if ( std::abs((*cand)->charge()) > 0.5 ) algo = PFRecoTauChargedHadron::kChargedPFCandidate; else algo = PFRecoTauChargedHadron::kPFNeutralHadron; std::auto_ptr chargedHadron(new PFRecoTauChargedHadron(**cand, algo)); - if ( (*cand)->trackRef().isNonnull() ) chargedHadron->track_ = edm::refToPtr((*cand)->trackRef()); - else if ( (*cand)->muonRef().isNonnull() && (*cand)->muonRef()->innerTrack().isNonnull() ) chargedHadron->track_ = edm::refToPtr((*cand)->muonRef()->innerTrack()); - else if ( (*cand)->muonRef().isNonnull() && (*cand)->muonRef()->globalTrack().isNonnull() ) chargedHadron->track_ = edm::refToPtr((*cand)->muonRef()->globalTrack()); - else if ( (*cand)->muonRef().isNonnull() && (*cand)->muonRef()->outerTrack().isNonnull() ) chargedHadron->track_ = edm::refToPtr((*cand)->muonRef()->outerTrack()); - else if ( (*cand)->gsfTrackRef().isNonnull() ) chargedHadron->track_ = edm::refToPtr((*cand)->gsfTrackRef()); + + const reco::PFCandidate* pfCand = dynamic_cast(&**cand); + if (pfCand) { + if ( pfCand->trackRef().isNonnull() ) chargedHadron->track_ = edm::refToPtr(pfCand->trackRef()); + else if ( pfCand->muonRef().isNonnull() && pfCand->muonRef()->innerTrack().isNonnull() ) chargedHadron->track_ = edm::refToPtr(pfCand->muonRef()->innerTrack()); + else if ( pfCand->muonRef().isNonnull() && pfCand->muonRef()->globalTrack().isNonnull() ) chargedHadron->track_ = edm::refToPtr(pfCand->muonRef()->globalTrack()); + else if ( pfCand->muonRef().isNonnull() && pfCand->muonRef()->outerTrack().isNonnull() ) chargedHadron->track_ = edm::refToPtr(pfCand->muonRef()->outerTrack()); + else if ( pfCand->gsfTrackRef().isNonnull() ) chargedHadron->track_ = edm::refToPtr(pfCand->gsfTrackRef()); + } // TauReco@MiniAOD: Tracks only available dynamically, so no possiblity to save ref here; checked by code downstream + + chargedHadron->positionAtECALEntrance_ = atECALEntrance(&**cand, bField_); chargedHadron->chargedPFCandidate_ = (*cand); chargedHadron->addDaughter(*cand); - - chargedHadron->positionAtECALEntrance_ = (*cand)->positionAtECALEntrance(); - - reco::PFCandidate::ParticleType chargedPFCandidateType = chargedHadron->chargedPFCandidate_->particleId(); + + int pdgId = std::abs(chargedHadron->chargedPFCandidate_->pdgId()); if ( chargedHadron->pt() > minMergeChargedHadronPt_ ) { - std::vector jetConstituents = jet.getPFConstituents(); - 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(); - if ( !(jetConstituentType == reco::PFCandidate::h0 || jetConstituentType == reco::PFCandidate::gamma) ) continue; + int jetConstituentPdgId = std::abs(jetConstituent->pdgId()); + if ( !(jetConstituentPdgId == 130 || jetConstituentPdgId == 22) ) continue; - double dR = deltaR((*jetConstituent)->positionAtECALEntrance(), chargedHadron->positionAtECALEntrance_); + double dR = deltaR(atECALEntrance(jetConstituent.get(), bField_), atECALEntrance(chargedHadron->chargedPFCandidate_.get(), bField_)); double dRmerge = -1.; int minBlockElementMatches = 1000; int maxUnmatchedBlockElements = 0; double minMergeEt = 1.e+6; - if ( jetConstituentType == reco::PFCandidate::h0 ) { - if ( chargedPFCandidateType == reco::PFCandidate::h ) dRmerge = dRmergeNeutralHadronWrtChargedHadron_; - else if ( chargedPFCandidateType == reco::PFCandidate::h0 ) dRmerge = dRmergeNeutralHadronWrtNeutralHadron_; - else if ( chargedPFCandidateType == reco::PFCandidate::e ) dRmerge = dRmergeNeutralHadronWrtElectron_; + if ( jetConstituentPdgId == 130 ) { + if ( pdgId == 211 ) dRmerge = dRmergeNeutralHadronWrtChargedHadron_; + else if ( pdgId == 130 ) dRmerge = dRmergeNeutralHadronWrtNeutralHadron_; + else if ( pdgId == 11 ) dRmerge = dRmergeNeutralHadronWrtElectron_; else dRmerge = dRmergeNeutralHadronWrtOther_; minBlockElementMatches = minBlockElementMatchesNeutralHadron_; maxUnmatchedBlockElements = maxUnmatchedBlockElementsNeutralHadron_; minMergeEt = minMergeNeutralHadronEt_; - } else if ( jetConstituentType == reco::PFCandidate::gamma ) { - if ( chargedPFCandidateType == reco::PFCandidate::h ) dRmerge = dRmergePhotonWrtChargedHadron_; - else if ( chargedPFCandidateType == reco::PFCandidate::h0 ) dRmerge = dRmergePhotonWrtNeutralHadron_; - else if ( chargedPFCandidateType == reco::PFCandidate::e ) dRmerge = dRmergePhotonWrtElectron_; + } else if ( jetConstituentPdgId == 22 ) { + if ( pdgId == 211 ) dRmerge = dRmergePhotonWrtChargedHadron_; + else if ( pdgId == 130 ) dRmerge = dRmergePhotonWrtNeutralHadron_; + else if ( pdgId == 11 ) dRmerge = dRmergePhotonWrtElectron_; else dRmerge = dRmergePhotonWrtOther_; minBlockElementMatches = minBlockElementMatchesPhoton_; maxUnmatchedBlockElements = maxUnmatchedBlockElementsPhoton_; minMergeEt = minMergeGammaEt_; } - if ( (*jetConstituent)->et() > minMergeEt && - (dR < dRmerge || isMatchedByBlockElement(**jetConstituent, *chargedHadron->chargedPFCandidate_, minBlockElementMatches, minBlockElementMatches, maxUnmatchedBlockElements)) ) { - chargedHadron->neutralPFCandidates_.push_back(*jetConstituent); - chargedHadron->addDaughter(*jetConstituent); + + if (jetConstituent->et() > minMergeEt) { + if (dR < dRmerge) { + 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* 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/PFRecoTauChargedHadronProducer.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronProducer.cc index 521a4c63eb0cf..1f428a38438bc 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronProducer.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronProducer.cc @@ -77,7 +77,7 @@ class PFRecoTauChargedHadronProducer : public edm::stream::EDProducer<> // input jet collection edm::InputTag srcJets_; - edm::EDGetTokenT Jets_token; + edm::EDGetTokenT Jets_token; double minJetPt_; double maxJetAbsEta_; @@ -98,7 +98,7 @@ PFRecoTauChargedHadronProducer::PFRecoTauChargedHadronProducer(const edm::Parame : moduleLabel_(cfg.getParameter("@module_label")) { srcJets_ = cfg.getParameter("jetSrc"); - Jets_token = consumes(srcJets_); + Jets_token = consumes(srcJets_); minJetPt_ = cfg.getParameter("minJetPt"); maxJetAbsEta_ = cfg.getParameter("maxJetAbsEta"); verbosity_ = cfg.getParameter("verbosity"); @@ -148,26 +148,28 @@ void PFRecoTauChargedHadronProducer::produce(edm::Event& evt, const edm::EventSe } // get a view of our jets via the base candidates - edm::Handle jets; + edm::Handle jets; evt.getByToken(Jets_token, jets); // convert the view to a RefVector of actual PFJets - reco::PFJetRefVector pfJets = reco::tau::castView(jets); + edm::RefToBaseVector pfJets; + size_t nElements = jets->size(); + for (size_t i = 0; i < nElements; ++i) { + pfJets.push_back(jets->refAt(i)); + } // make our association std::unique_ptr pfJetChargedHadronAssociations; if ( !pfJets.empty() ) { - edm::Handle pfJetCollectionHandle; - evt.get(pfJets.id(), pfJetCollectionHandle); - pfJetChargedHadronAssociations = std::make_unique(reco::PFJetRefProd(pfJetCollectionHandle)); + pfJetChargedHadronAssociations = std::make_unique(reco::JetRefBaseProd(jets)); } else { pfJetChargedHadronAssociations = std::make_unique(); } // loop over our jets - for(auto const& pfJet : pfJets ) { + for(const auto& pfJet : pfJets ) { if(pfJet->pt() - minJetPt_ < 1e-5) continue; if(std::abs(pfJet->eta()) - maxJetAbsEta_ > -1e-5) continue; @@ -201,7 +203,7 @@ void PFRecoTauChargedHadronProducer::produce(edm::Event& evt, const edm::EventSe // keep track of neutral PFCandidates, charged PFCandidates and tracks "used" by ChargedHadron candidates in the clean collection typedef std::pair etaPhiPair; std::list tracksInCleanCollection; - std::set neutralPFCandsInCleanCollection; + std::set neutralPFCandsInCleanCollection; while ( !uncleanedChargedHadrons.empty() ) { @@ -217,12 +219,14 @@ void PFRecoTauChargedHadronProducer::produce(edm::Event& evt, const edm::EventSe const reco::Track* track = nullptr; if ( nextChargedHadron->getChargedPFCandidate().isNonnull() ) { - const reco::PFCandidatePtr& chargedPFCand = nextChargedHadron->getChargedPFCandidate(); - if ( chargedPFCand->trackRef().isNonnull() ) track = chargedPFCand->trackRef().get(); - else if ( chargedPFCand->muonRef().isNonnull() && chargedPFCand->muonRef()->innerTrack().isNonnull() ) track = chargedPFCand->muonRef()->innerTrack().get(); - else if ( chargedPFCand->muonRef().isNonnull() && chargedPFCand->muonRef()->globalTrack().isNonnull() ) track = chargedPFCand->muonRef()->globalTrack().get(); - else if ( chargedPFCand->muonRef().isNonnull() && chargedPFCand->muonRef()->outerTrack().isNonnull() ) track = chargedPFCand->muonRef()->outerTrack().get(); - else if ( chargedPFCand->gsfTrackRef().isNonnull() ) track = chargedPFCand->gsfTrackRef().get(); + const reco::PFCandidate* chargedPFCand = dynamic_cast (&*nextChargedHadron->getChargedPFCandidate()); + if (chargedPFCand) { + if ( chargedPFCand->trackRef().isNonnull() ) track = chargedPFCand->trackRef().get(); + else if ( chargedPFCand->muonRef().isNonnull() && chargedPFCand->muonRef()->innerTrack().isNonnull() ) track = chargedPFCand->muonRef()->innerTrack().get(); + else if ( chargedPFCand->muonRef().isNonnull() && chargedPFCand->muonRef()->globalTrack().isNonnull() ) track = chargedPFCand->muonRef()->globalTrack().get(); + else if ( chargedPFCand->muonRef().isNonnull() && chargedPFCand->muonRef()->outerTrack().isNonnull() ) track = chargedPFCand->muonRef()->outerTrack().get(); + else if ( chargedPFCand->gsfTrackRef().isNonnull() ) track = chargedPFCand->gsfTrackRef().get(); + } } if ( nextChargedHadron->getTrack().isNonnull() && !track ) { track = nextChargedHadron->getTrack().get(); @@ -247,9 +251,10 @@ void PFRecoTauChargedHadronProducer::produce(edm::Event& evt, const edm::EventSe // discard ChargedHadron candidates without track in case they are close to neutral PFCandidates "used" by ChargedHadron candidates in the clean collection bool isNeutralPFCand_overlap = false; if ( nextChargedHadron->algoIs(reco::PFRecoTauChargedHadron::kPFNeutralHadron) ) { - for ( std::set::const_iterator neutralPFCandInCleanCollection = neutralPFCandsInCleanCollection.begin(); + for ( std::set::const_iterator neutralPFCandInCleanCollection = neutralPFCandsInCleanCollection.begin(); neutralPFCandInCleanCollection != neutralPFCandsInCleanCollection.end(); ++neutralPFCandInCleanCollection ) { - if ( (*neutralPFCandInCleanCollection) == nextChargedHadron->getChargedPFCandidate() ) isNeutralPFCand_overlap = true; + if ( (*neutralPFCandInCleanCollection) == nextChargedHadron->getChargedPFCandidate() ) isNeutralPFCand_overlap = true; + } } if ( verbosity_ ) { @@ -258,7 +263,7 @@ void PFRecoTauChargedHadronProducer::produce(edm::Event& evt, const edm::EventSe if ( isNeutralPFCand_overlap ) continue; // find neutral PFCandidates that are not "used" by any ChargedHadron in the clean collection - std::vector uniqueNeutralPFCands; + std::vector uniqueNeutralPFCands; std::set_difference(nextChargedHadron->getNeutralPFCandidates().begin(), nextChargedHadron->getNeutralPFCandidates().end(), neutralPFCandsInCleanCollection.begin(), diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectron2.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectron2.cc index 09d64bda36a69..2a3468686ac7e 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectron2.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectron2.cc @@ -163,7 +163,7 @@ double PFRecoTauDiscriminationAgainstElectron2::discriminate(const PFTauRef& the // ensure tau has at least one charged object - if( (*thePFTauRef).leadPFChargedHadrCand().isNull() ) + if( (*thePFTauRef).leadChargedHadrCand().isNull() ) { return 0.; } @@ -178,7 +178,7 @@ double PFRecoTauDiscriminationAgainstElectron2::discriminate(const PFTauRef& the std::cout << ":" << std::endl; std::cout << " tau: Pt = " << thePFTauRef->pt() << ", eta = " << thePFTauRef->eta() << ", phi = " << thePFTauRef->phi() << std::endl; std::cout << " discriminator value = " << discriminator << std::endl; - std::cout << " Prongs in tau: " << thePFTauRef->signalPFChargedHadrCands().size() << std::endl; + std::cout << " Prongs in tau: " << thePFTauRef->signalChargedHadrCands().size() << std::endl; } return discriminator; diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA5.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA5.cc index 06a1499845451..276dc9a5445a0 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA5.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA5.cc @@ -217,7 +217,7 @@ double PFRecoTauDiscriminationAgainstElectronMVA5::discriminate(const PFTauRef& edm::LogPrint("PFTauAgainstEleMVA5") << ":" ; edm::LogPrint("PFTauAgainstEleMVA5") << " tau: Pt = " << thePFTauRef->pt() << ", eta = " << thePFTauRef->eta() << ", phi = " << thePFTauRef->phi(); edm::LogPrint("PFTauAgainstEleMVA5") << " deltaREleTau = " << deltaRDummy << ", isGsfElectronMatched = " << isGsfElectronMatched; - edm::LogPrint("PFTauAgainstEleMVA5") << " #Prongs = " << thePFTauRef->signalPFChargedHadrCands().size(); + edm::LogPrint("PFTauAgainstEleMVA5") << " #Prongs = " << thePFTauRef->signalChargedHadrCands().size(); edm::LogPrint("PFTauAgainstEleMVA5") << " MVA = " << mvaValue << ", category = " << category; } diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA6.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA6.cc index b76da8b014122..1dc85466a3eb7 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA6.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronMVA6.cc @@ -97,8 +97,7 @@ double PFRecoTauDiscriminationAgainstElectronMVA6::discriminate(const PFTauRef& float tauEtaAtEcalEntrance = -99.; float sumEtaTimesEnergy = 0.; float sumEnergy = 0.; - const std::vector& signalPFCands = thePFTauRef->signalPFCands(); - for ( const auto & pfCandidate : signalPFCands ) { + for ( const auto & pfCandidate : thePFTauRef->signalPFCands() ) { sumEtaTimesEnergy += (pfCandidate->positionAtECALEntrance().eta()*pfCandidate->energy()); sumEnergy += pfCandidate->energy(); } @@ -108,7 +107,7 @@ double PFRecoTauDiscriminationAgainstElectronMVA6::discriminate(const PFTauRef& float leadChargedPFCandEtaAtEcalEntrance = -99.; float leadChargedPFCandPt = -99.; - for ( const auto & pfCandidate : signalPFCands ) { + 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(); @@ -123,19 +122,19 @@ double PFRecoTauDiscriminationAgainstElectronMVA6::discriminate(const PFTauRef& } } - if( (*thePFTauRef).leadPFChargedHadrCand().isNonnull()) { + if( (*thePFTauRef).leadChargedHadrCand().isNonnull()) { - int numSignalPFGammaCandsInSigCone = 0; - const std::vector& signalPFGammaCands = thePFTauRef->signalPFGammaCands(); + int numSignalGammaCandsInSigCone = 0; + const std::vector& signalGammaCands = thePFTauRef->signalGammaCands(); - for ( const auto & pfGamma : signalPFGammaCands ) { + for ( const auto & pfGamma : signalGammaCands ) { - double dR = deltaR(pfGamma->p4(), thePFTauRef->leadPFChargedHadrCand()->p4()); + 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) { - numSignalPFGammaCandsInSigCone += 1; + numSignalGammaCandsInSigCone += 1; } } @@ -146,7 +145,11 @@ double PFRecoTauDiscriminationAgainstElectronMVA6::discriminate(const PFTauRef& deltaRDummy = deltaREleTau; if ( deltaREleTau < 0.3 ) { double mva_match = mva_->MVAValue(*thePFTauRef, theGsfElectron); - bool hasGsfTrack = thePFTauRef->leadPFChargedHadrCand()->gsfTrackRef().isNonnull(); + const reco::PFCandidatePtr& lpfch = thePFTauRef->leadPFChargedHadrCand(); + bool hasGsfTrack = false; + if (lpfch.isNonnull()) { + hasGsfTrack = lpfch->gsfTrackRef().isNonnull(); + } if ( !hasGsfTrack ) hasGsfTrack = theGsfElectron.gsfTrack().isNonnull(); @@ -160,17 +163,17 @@ double PFRecoTauDiscriminationAgainstElectronMVA6::discriminate(const PFTauRef& //// Veto taus that go to Ecal crack if ( std::abs(tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder ) { // Barrel - if ( numSignalPFGammaCandsInSigCone == 0 && hasGsfTrack ) { + if ( numSignalGammaCandsInSigCone == 0 && hasGsfTrack ) { category = 5.; } - else if ( numSignalPFGammaCandsInSigCone >= 1 && hasGsfTrack ) { + else if ( numSignalGammaCandsInSigCone >= 1 && hasGsfTrack ) { category = 7.; } } else { // Endcap - if ( numSignalPFGammaCandsInSigCone == 0 && hasGsfTrack ) { + if ( numSignalGammaCandsInSigCone == 0 && hasGsfTrack ) { category = 13.; } - else if ( numSignalPFGammaCandsInSigCone >= 1 && hasGsfTrack ) { + else if ( numSignalGammaCandsInSigCone >= 1 && hasGsfTrack ) { category = 15.; } } @@ -183,7 +186,11 @@ double PFRecoTauDiscriminationAgainstElectronMVA6::discriminate(const PFTauRef& if ( !isGsfElectronMatched ) { mvaValue = mva_->MVAValue(*thePFTauRef); - bool hasGsfTrack = thePFTauRef->leadPFChargedHadrCand()->gsfTrackRef().isNonnull(); + 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)) ) { @@ -195,17 +202,17 @@ double PFRecoTauDiscriminationAgainstElectronMVA6::discriminate(const PFTauRef& //// Veto taus that go to Ecal crack if ( std::abs(tauEtaAtEcalEntrance) < ECALBarrelEndcapEtaBorder ) { // Barrel - if ( numSignalPFGammaCandsInSigCone == 0 && !hasGsfTrack ) { + if ( numSignalGammaCandsInSigCone == 0 && !hasGsfTrack ) { category = 0.; } - else if ( numSignalPFGammaCandsInSigCone >= 1 && !hasGsfTrack ) { + else if ( numSignalGammaCandsInSigCone >= 1 && !hasGsfTrack ) { category = 2.; } } else { // Endcap - if ( numSignalPFGammaCandsInSigCone == 0 && !hasGsfTrack ) { + if ( numSignalGammaCandsInSigCone == 0 && !hasGsfTrack ) { category = 8.; } - else if ( numSignalPFGammaCandsInSigCone >= 1 && !hasGsfTrack ) { + else if ( numSignalGammaCandsInSigCone >= 1 && !hasGsfTrack ) { category = 10.; } } @@ -216,7 +223,7 @@ double PFRecoTauDiscriminationAgainstElectronMVA6::discriminate(const PFTauRef& 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->signalPFChargedHadrCands().size(); + edm::LogPrint("PFTauAgainstEleMVA6") << " #Prongs = " << thePFTauRef->signalChargedHadrCands().size(); edm::LogPrint("PFTauAgainstEleMVA6") << " MVA = " << mvaValue << ", category = " << category; } diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuon.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuon.cc index 3fce88078a04c..f19b2d17f6ac0 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuon.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuon.cc @@ -12,9 +12,7 @@ #include "DataFormats/MuonReco/interface/MuonFwd.h" #include "DataFormats/MuonReco/interface/MuonSelectors.h" - -#include "DataFormats/MuonReco/interface/MuonSelectors.h" - +#include "DataFormats/JetReco/interface/PFJet.h" #include @@ -72,7 +70,11 @@ double PFRecoTauDiscriminationAgainstMuon::discriminate(const PFTauRef& thePFTau if ( muonref->isGlobalMuon() ) muType = 1; else if ( muonref->isCaloMuon() ) muType = 2; else if ( muonref->isTrackerMuon() ) muType = 3; - double muonEnergyFraction = thePFTauRef->pfTauTagInfoRef()->pfjetRef()->chargedMuEnergyFraction(); + float muonEnergyFraction = 0.; + const reco::PFJet* pfJetPtr = dynamic_cast(thePFTauRef->pfTauTagInfoRef()->pfjetRef().get()); + if (pfJetPtr) { + muonEnergyFraction = pfJetPtr->chargedMuEnergyFraction(); + } else throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFJets, and this outdated algorithm was not updated to cope with PFTaus made from other Jets.\n"; bool eta_veto = false; bool phi_veto = false; if ( fabs(muonref->eta()) > 2.3 || (fabs(muonref->eta()) > 1.4 && fabs(muonref->eta()) < 1.6)) eta_veto = true; diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuon2.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuon2.cc index 5691d69debbef..df17a5de3ddd7 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuon2.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuon2.cc @@ -24,10 +24,14 @@ #include "DataFormats/GsfTrackReco/interface/GsfTrack.h" #include "DataFormats/Math/interface/deltaR.h" +#include "RecoTauTag/RecoTau/interface/RecoTauMuonTools.h" + #include #include #include +using reco::tau::format_vint; + namespace { class PFRecoTauDiscriminationAgainstMuon2 final : public PFTauDiscriminationProducerBase @@ -104,56 +108,6 @@ void PFRecoTauDiscriminationAgainstMuon2::beginEvent(const edm::Event& evt, cons } } -namespace -{ - void countHits(const reco::Muon& muon, std::vector& numHitsDT, std::vector& numHitsCSC, std::vector& numHitsRPC) - { - if ( muon.outerTrack().isNonnull() ) { - const reco::HitPattern &muonHitPattern = muon.outerTrack()->hitPattern(); - for (int iHit = 0; iHit < muonHitPattern.numberOfAllHits(reco::HitPattern::TRACK_HITS); ++iHit) { - uint32_t hit = muonHitPattern.getHitPattern(reco::HitPattern::TRACK_HITS, iHit); - if ( hit == 0 ) break; - if ( muonHitPattern.muonHitFilter(hit) && (muonHitPattern.getHitType(hit) == TrackingRecHit::valid || muonHitPattern.getHitType(hit) == TrackingRecHit::bad) ) { - int muonStation = muonHitPattern.getMuonStation(hit) - 1; // CV: map into range 0..3 - if ( muonStation >= 0 && muonStation < 4 ) { - if ( muonHitPattern.muonDTHitFilter(hit) ) ++numHitsDT[muonStation]; - else if ( muonHitPattern.muonCSCHitFilter(hit) ) ++numHitsCSC[muonStation]; - else if ( muonHitPattern.muonRPCHitFilter(hit) ) ++numHitsRPC[muonStation]; - } - } - } - } - } - - std::string format_vint(const std::vector& vi) - { - std::ostringstream os; - os << "{ "; - unsigned numEntries = vi.size(); - for ( unsigned iEntry = 0; iEntry < numEntries; ++iEntry ) { - os << vi[iEntry]; - if ( iEntry < (numEntries - 1) ) os << ", "; - } - os << " }"; - return os.str(); - } - - void countMatches(const reco::Muon& muon, std::vector& numMatchesDT, std::vector& numMatchesCSC, std::vector& numMatchesRPC) - { - const std::vector& muonSegments = muon.matches(); - for ( std::vector::const_iterator muonSegment = muonSegments.begin(); - muonSegment != muonSegments.end(); ++muonSegment ) { - if ( muonSegment->segmentMatches.empty() ) continue; - int muonDetector = muonSegment->detector(); - int muonStation = muonSegment->station() - 1; - assert(muonStation >= 0 && muonStation <= 3); - if ( muonDetector == MuonSubdetId::DT ) ++numMatchesDT[muonStation]; - else if ( muonDetector == MuonSubdetId::CSC ) ++numMatchesCSC[muonStation]; - else if ( muonDetector == MuonSubdetId::RPC ) ++numMatchesRPC[muonStation]; - } - } -} - double PFRecoTauDiscriminationAgainstMuon2::discriminate(const reco::PFTauRef& pfTau) const { if ( verbosity_ ) { @@ -179,11 +133,11 @@ double PFRecoTauDiscriminationAgainstMuon2::discriminate(const reco::PFTauRef& p const reco::PFCandidatePtr& pfLeadChargedHadron = pfTau->leadPFChargedHadrCand(); if ( pfLeadChargedHadron.isNonnull() ) { - reco::MuonRef muonRef = pfLeadChargedHadron->muonRef(); + reco::MuonRef muonRef = pfLeadChargedHadron->muonRef(); if ( muonRef.isNonnull() ) { if ( verbosity_ ) edm::LogPrint("PFTauAgainstMuon2") << " has muonRef." ; - countMatches(*muonRef, numMatchesDT, numMatchesCSC, numMatchesRPC); - countHits(*muonRef, numHitsDT, numHitsCSC, numHitsRPC); + reco::tau::countMatches(*muonRef, numMatchesDT, numMatchesCSC, numMatchesRPC); + reco::tau::countHits(*muonRef, numHitsDT, numHitsCSC, numHitsRPC); } } @@ -196,9 +150,12 @@ double PFRecoTauDiscriminationAgainstMuon2::discriminate(const reco::PFTauRef& p if ( verbosity_ ){ edm::LogPrint("PFTauAgainstMuon2") << " fails Pt cut --> skipping it." ;} continue; } - if ( pfLeadChargedHadron.isNonnull() && pfLeadChargedHadron->muonRef().isNonnull() && muon == pfLeadChargedHadron->muonRef() ) { - if ( verbosity_ ){ edm::LogPrint("PFTauAgainstMuon2") << " matches muonRef of tau --> skipping it." ;} - continue; + if ( pfLeadChargedHadron.isNonnull()) { + 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_; @@ -218,8 +175,8 @@ double PFRecoTauDiscriminationAgainstMuon2::discriminate(const reco::PFTauRef& p } if ( dR < dRmatch ) { if ( verbosity_ ) edm::LogPrint("PFTauAgainstMuon2") << " overlaps with tau, dR = " << dR ; - countMatches(*muon, numMatchesDT, numMatchesCSC, numMatchesRPC); - countHits(*muon, numHitsDT, numHitsCSC, numHitsRPC); + reco::tau::countMatches(*muon, numMatchesDT, numMatchesCSC, numMatchesRPC); + reco::tau::countHits(*muon, numHitsDT, numHitsCSC, numHitsRPC); } } } @@ -251,7 +208,7 @@ double PFRecoTauDiscriminationAgainstMuon2::discriminate(const reco::PFTauRef& p bool passesCaloMuonVeto = true; if ( pfLeadChargedHadron.isNonnull() ) { - double energyECALplusHCAL = pfLeadChargedHadron->ecalEnergy() + pfLeadChargedHadron->hcalEnergy(); + 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() ; @@ -260,9 +217,12 @@ double PFRecoTauDiscriminationAgainstMuon2::discriminate(const reco::PFTauRef& p } } 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; + 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/PFRecoTauDiscriminationAgainstMuonSimple.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuonSimple.cc new file mode 100644 index 0000000000000..9acb3e06de95e --- /dev/null +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuonSimple.cc @@ -0,0 +1,256 @@ +/** \class PFRecoTauDiscriminationAgainstMuonSimple + * + * Compute tau Id. discriminator against muons for MiniAOD. + * + * \author Michal Bluj, NCBJ Warsaw + * based on PFRecoTauDiscriminationAgainstMuon2 by Christian Veelken + * + * Note: it is not granted that information on muon track is/will be always + * accesible with MiniAOD, if not one can consider to veto muons which are + * not only Trk by also STA or RPC muons, i.e. have many (>=2) good muon segments + */ + +#include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h" + +#include "FWCore/Utilities/interface/Exception.h" + +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" +#include "DataFormats/PatCandidates/interface/Muon.h" +#include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/TrackReco/interface/HitPattern.h" +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/GsfTrackReco/interface/GsfTrack.h" +#include "DataFormats/Math/interface/deltaR.h" + +#include "RecoTauTag/RecoTau/interface/RecoTauMuonTools.h" + +#include +#include +#include + +using reco::tau::format_vint; + +namespace { + +class PFRecoTauDiscriminationAgainstMuonSimple final : public PFTauDiscriminationProducerBase +{ + public: + explicit PFRecoTauDiscriminationAgainstMuonSimple(const edm::ParameterSet& cfg) + : PFTauDiscriminationProducerBase(cfg), + moduleLabel_(cfg.getParameter("@module_label")) + { + hop_ = cfg.getParameter("HoPMin"); + doCaloMuonVeto_ = cfg.getParameter("doCaloMuonVeto"); + srcPatMuons_ = cfg.getParameter("srcPatMuons"); + Muons_token = consumes(srcPatMuons_); + dRmuonMatch_ = cfg.getParameter("dRmuonMatch"); + dRmuonMatchLimitedToJetArea_ = cfg.getParameter("dRmuonMatchLimitedToJetArea"); + minPtMatchedMuon_ = cfg.getParameter("minPtMatchedMuon"); + maxNumberOfMatches_ = cfg.getParameter("maxNumberOfMatches"); + maxNumberOfHitsLast2Stations_ = cfg.getParameter("maxNumberOfHitsLast2Stations"); + typedef std::vector vint; + maskMatchesDT_ = cfg.getParameter("maskMatchesDT"); + maskMatchesCSC_ = cfg.getParameter("maskMatchesCSC"); + maskMatchesRPC_ = cfg.getParameter("maskMatchesRPC"); + maskHitsDT_ = cfg.getParameter("maskHitsDT"); + maskHitsCSC_ = cfg.getParameter("maskHitsCSC"); + maskHitsRPC_ = cfg.getParameter("maskHitsRPC"); + maxNumberOfSTAMuons_ = cfg.getParameter("maxNumberOfSTAMuons"); + maxNumberOfRPCMuons_ = cfg.getParameter("maxNumberOfRPCMuons"); + + numWarnings_ = 0; + maxWarnings_ = 3; + verbosity_ = cfg.exists("verbosity") ? cfg.getParameter("verbosity") : 0; + } + ~PFRecoTauDiscriminationAgainstMuonSimple() override {} + + void beginEvent(const edm::Event&, const edm::EventSetup&) override; + + double discriminate(const reco::PFTauRef&) const override; + + private: + std::string moduleLabel_; + int discriminatorOption_; + double hop_; + bool doCaloMuonVeto_; + edm::InputTag srcPatMuons_; + edm::Handle muons_; + edm::EDGetTokenT Muons_token; + double dRmuonMatch_; + bool dRmuonMatchLimitedToJetArea_; + double minPtMatchedMuon_; + int maxNumberOfMatches_; + std::vector maskMatchesDT_; + std::vector maskMatchesCSC_; + std::vector maskMatchesRPC_; + int maxNumberOfHitsLast2Stations_; + std::vector maskHitsDT_; + std::vector maskHitsCSC_; + std::vector maskHitsRPC_; + int maxNumberOfSTAMuons_, maxNumberOfRPCMuons_; + + mutable int numWarnings_; + int maxWarnings_; + int verbosity_; +}; + +void PFRecoTauDiscriminationAgainstMuonSimple::beginEvent(const edm::Event& evt, const edm::EventSetup& es) +{ + evt.getByToken(Muons_token, muons_); +} + +double PFRecoTauDiscriminationAgainstMuonSimple::discriminate(const reco::PFTauRef& pfTau) const +{ + if ( verbosity_ ) { + edm::LogPrint("PFTauAgainstMuonSimple") << ":" ; + edm::LogPrint("PFTauAgainstMuonSimple") << " moduleLabel = " << moduleLabel_ ; + edm::LogPrint("PFTauAgainstMuonSimple") << "tau #" << pfTau.key() << ": Pt = " << pfTau->pt() << ", eta = " << pfTau->eta() << ", phi = " << pfTau->phi() << ", decay mode = " << pfTau->decayMode() ; + } + + //if (pfTau->decayMode() >= 5) return true; //MB: accept all multi-prongs?? + + const reco::CandidatePtr& pfLeadChargedHadron = pfTau->leadChargedHadrCand(); + bool passesCaloMuonVeto = true; + if ( pfLeadChargedHadron.isNonnull() ) { + const pat::PackedCandidate* pCand = dynamic_cast(pfLeadChargedHadron.get()); + if ( pCand != nullptr ) { + double rawCaloEnergyFraction = pCand->rawCaloFraction(); + //if ( !(rawCaloEnergyFraction > 0.) ) rawCaloEnergyFraction = 99; //MB: hack against cases when rawCaloEnergyFraction is not stored; it makes performance of the H/P cut rather poor + if ( verbosity_ ) { + edm::LogPrint("PFTauAgainstMuonSimple") << "decayMode = " << pfTau->decayMode() << ", rawCaloEnergy(ECAL+HCAL)Fraction = " << rawCaloEnergyFraction << ", leadPFChargedHadronP = " << pCand->p() << ", leadPFChargedHadron pdgId = " << pCand->pdgId(); + } + if ( pfTau->decayMode() == 0 && rawCaloEnergyFraction < hop_ ) passesCaloMuonVeto = false; + } + } + if ( doCaloMuonVeto_ && !passesCaloMuonVeto ) { + if ( verbosity_ ) edm::LogPrint("PFTauAgainstMuonSimple") << "--> CaloMuonVeto failed, returning 0"; + return 0.; + } + + //iterate over muons to find ones to use for discrimination + std::vector muonsToCheck; + size_t numMuons = muons_->size(); + for ( size_t idxMuon = 0; idxMuon < numMuons; ++idxMuon ) { + bool matched = false; + const pat::MuonRef muon(muons_, idxMuon); + if ( verbosity_ ) edm::LogPrint("PFTauAgainstMuonSimple") << "muon #" << muon.key() << ": Pt = " << muon->pt() << ", eta = " << muon->eta() << ", phi = " << muon->phi() ; + //firsty check if the muon corrsponds with the leading tau particle + for ( size_t iCand = 0; iCand < muon->numberOfSourceCandidatePtrs(); ++iCand) { + const reco::CandidatePtr& srcCand = muon->sourceCandidatePtr(iCand); + if (srcCand.isNonnull() && pfLeadChargedHadron.isNonnull() && + srcCand.id()==pfLeadChargedHadron.id() && + srcCand.key()==pfLeadChargedHadron.key() ) { + muonsToCheck.push_back(muon.get()); + matched = true; + if ( verbosity_ ) edm::LogPrint("PFTauAgainstMuonSimple") << " tau has muonRef." ; + break; + } + } + if (matched) continue; + //check dR matching + if ( !(muon->pt() > minPtMatchedMuon_) ) { + if ( verbosity_ ){ edm::LogPrint("PFTauAgainstMuonSimple") << " fails Pt cut --> skipping it." ;} + continue; + } + double dR = deltaR(muon->p4(), pfTau->p4()); + double dRmatch = dRmuonMatch_; + if ( dRmuonMatchLimitedToJetArea_ ) { + double jetArea = 0.; + if ( pfTau->jetRef().isNonnull() ) jetArea = pfTau->jetRef()->jetArea(); + if ( jetArea > 0. ) { + dRmatch = TMath::Min(dRmatch, TMath::Sqrt(jetArea/TMath::Pi())); + } else { + if ( numWarnings_ < maxWarnings_ ) { + edm::LogInfo("PFRecoTauDiscriminationAgainstMuonSimple::discriminate") + << "Jet associated to Tau: Pt = " << pfTau->pt() << ", eta = " << pfTau->eta() << ", phi = " << pfTau->phi() << " has area = " << jetArea << " !!" ; + ++numWarnings_; + } + dRmatch = pfTau->signalConeSize(); + } + dRmatch = TMath::Max(dRmatch,pfTau->signalConeSize()); + if ( dR < dRmatch ) { + if ( verbosity_ ) edm::LogPrint("PFTauAgainstMuonSimple") << " overlaps with tau, dR = " << dR ; + muonsToCheck.push_back(muon.get()); + } + } + } + //now examine selected muons + bool pass = true; + std::vector numMatchesDT(4); + std::vector numMatchesCSC(4); + std::vector numMatchesRPC(4); + std::vector numHitsDT(4); + std::vector numHitsCSC(4); + std::vector numHitsRPC(4); + //MB: clear counters of matched segments and hits globally as in the AgainstMuon2 discriminant, but note that they will sum for all matched muons. However it is not likely that there is more than one matched muon. + for ( int iStation = 0; iStation < 4; ++iStation ) { + numMatchesDT[iStation] = 0; + numMatchesCSC[iStation] = 0; + numMatchesRPC[iStation] = 0; + numHitsDT[iStation] = 0; + numHitsCSC[iStation] = 0; + numHitsRPC[iStation] = 0; + } + int numSTAMuons=0, numRPCMuons=0; + if ( verbosity_ && !muonsToCheck.empty() ) edm::LogPrint("PFTauAgainstMuonSimple") << "Muons to check (" << muonsToCheck.size() << "):"; + size_t iMu = 0; + for (const auto &mu: muonsToCheck) { + if ( mu->isStandAloneMuon() ) numSTAMuons++; + if ( mu->muonID("RPCMuLoose") ) numRPCMuons++; + reco::tau::countMatches(*mu, numMatchesDT, numMatchesCSC, numMatchesRPC); + int numStationsWithMatches = 0; + for ( int iStation = 0; iStation < 4; ++iStation ) { + if ( numMatchesDT[iStation] > 0 && !maskMatchesDT_[iStation] ) ++numStationsWithMatches; + if ( numMatchesCSC[iStation] > 0 && !maskMatchesCSC_[iStation] ) ++numStationsWithMatches; + if ( numMatchesRPC[iStation] > 0 && !maskMatchesRPC_[iStation] ) ++numStationsWithMatches; + } + reco::tau::countHits(*mu, numHitsDT, numHitsCSC, numHitsRPC); + int numLast2StationsWithHits = 0; + for ( int iStation = 2; iStation < 4; ++iStation ) { + if ( numHitsDT[iStation] > 0 && !maskHitsDT_[iStation] ) ++numLast2StationsWithHits; + if ( numHitsCSC[iStation] > 0 && !maskHitsCSC_[iStation] ) ++numLast2StationsWithHits; + if ( numHitsRPC[iStation] > 0 && !maskHitsRPC_[iStation] ) ++numLast2StationsWithHits; + } + if ( verbosity_ ) + edm::LogPrint("PFTauAgainstMuonSimple") + << "\t" << iMu << ": Pt = " << mu->pt() << ", eta = " << mu->eta() << ", phi = " << mu->phi() + << "\n\t" + << " isSTA: "<isStandAloneMuon() + << ", isRPCLoose: "<muonID("RPCMuLoose") + << "\n\t numMatchesDT = " << format_vint(numMatchesDT) + << "\n\t numMatchesCSC = " << format_vint(numMatchesCSC) + << "\n\t numMatchesRPC = " << format_vint(numMatchesRPC) + << "\n\t --> numStationsWithMatches = " << numStationsWithMatches + << "\n\t numHitsDT = " << format_vint(numHitsDT) + << "\n\t numHitsCSC = " << format_vint(numHitsCSC) + << "\n\t numHitsRPC = " << format_vint(numHitsRPC) + << "\n\t --> numLast2StationsWithHits = " << numLast2StationsWithHits ; + if ( maxNumberOfMatches_ >= 0 && numStationsWithMatches > maxNumberOfMatches_ ) { + pass = false; + break; + } + if ( maxNumberOfHitsLast2Stations_ >= 0 && numLast2StationsWithHits > maxNumberOfHitsLast2Stations_ ) { + pass = false; + break; + } + if ( maxNumberOfSTAMuons_ >= 0 && numSTAMuons > maxNumberOfSTAMuons_ ) { + pass = false; + break; + } + if ( maxNumberOfRPCMuons_ >= 0 && numRPCMuons > maxNumberOfRPCMuons_ ) { + pass = false; + break; + } + iMu++; + } + + double discriminatorValue = pass ? 1.: 0.; + if ( verbosity_ ) edm::LogPrint("PFTauAgainstMuonSimple") << "--> returning discriminatorValue = " << discriminatorValue ; + + return discriminatorValue; +} + +} + +DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstMuonSimple); + diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByCharge.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByCharge.cc index 0fda0a4f29dbb..cdab3e46127cf 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByCharge.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByCharge.cc @@ -30,7 +30,7 @@ class PFRecoTauDiscriminationByCharge : public PFTauDiscriminationProducerBase double PFRecoTauDiscriminationByCharge::discriminate(const PFTauRef& thePFTauRef) const { - uint16_t nSigTk = thePFTauRef->signalPFChargedHadrCands().size(); + uint16_t nSigTk = thePFTauRef->signalChargedHadrCands().size(); bool chargeok = (std::abs(thePFTauRef->charge()) == int(chargeReq_)); bool oneOrThreeProngOK = ( (nSigTk==1) || (nSigTk==3) || !oneOrThreeProng_ ); diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByDeltaE.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByDeltaE.cc index c6268abe75a43..934f0dd360140 100755 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByDeltaE.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByDeltaE.cc @@ -52,7 +52,7 @@ double PFRecoTauDiscriminationByDeltaE::discriminate(const PFTauRef& tau) const{ double PFRecoTauDiscriminationByDeltaE::DeltaE(const PFTauRef& tau) const { double tracksE = 0; - const std::vector& signalTracks = tau->signalPFChargedHadrCands(); + const std::vector& signalTracks = tau->signalChargedHadrCands(); for(size_t i = 0; i < signalTracks.size(); ++i){ TLorentzVector p4; p4.SetXYZM(signalTracks[i]->px(), diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByFlightPathSignificance.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByFlightPathSignificance.cc index 98da3dc8ab216..d530df0e41111 100755 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByFlightPathSignificance.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByFlightPathSignificance.cc @@ -86,17 +86,14 @@ double PFRecoTauDiscriminationByFlightPathSignificance::threeProngFlightPathSig( } //Secondary vertex - const vector& pfSignalCandidates = tau->signalPFChargedHadrCands(); vector transientTracks; - vector::const_iterator iTrack; - for(iTrack = pfSignalCandidates.begin(); iTrack!= pfSignalCandidates.end(); iTrack++){ - const PFCandidate& pfCand = *(iTrack->get()); - if(pfCand.trackRef().isNonnull()){ - const TransientTrack transientTrack = transientTrackBuilder->build(pfCand.trackRef()); + for(const auto& pfSignalCand : tau->signalPFChargedHadrCands()){ + if(pfSignalCand->trackRef().isNonnull()){ + const TransientTrack transientTrack = transientTrackBuilder->build(pfSignalCand->trackRef()); transientTracks.push_back(transientTrack); } - else if(pfCand.gsfTrackRef().isNonnull()){ - const TransientTrack transientTrack = transientTrackBuilder->build(pfCand.gsfTrackRef()); + else if(pfSignalCand->gsfTrackRef().isNonnull()){ + const TransientTrack transientTrack = transientTrackBuilder->build(pfSignalCand->gsfTrackRef()); transientTracks.push_back(transientTrack); } } diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByHPSSelection.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByHPSSelection.cc index e2d77e24954b4..a4cc983985358 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByHPSSelection.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByHPSSelection.cc @@ -9,6 +9,7 @@ #include "DataFormats/TauReco/interface/PFRecoTauChargedHadron.h" #include "DataFormats/TauReco/interface/PFRecoTauChargedHadronFwd.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" namespace { // Apply a hypothesis on the mass of the strips. @@ -110,6 +111,23 @@ PFRecoTauDiscriminationByHPSSelection::~PFRecoTauDiscriminationByHPSSelection() } } +namespace { + inline const reco::Track* getTrack(const reco::Candidate& cand) + { + const reco::PFCandidate* pfCandPtr = dynamic_cast(&cand); + if (pfCandPtr) { + if ( pfCandPtr->trackRef().isNonnull() ) return pfCandPtr->trackRef().get(); + else if ( pfCandPtr->gsfTrackRef().isNonnull() ) return pfCandPtr->gsfTrackRef().get(); + else return nullptr; + } + const pat::PackedCandidate* packedCand = dynamic_cast(&cand); + if (packedCand && packedCand->hasTrackDetails()) + return &packedCand->pseudoTrack(); + + return nullptr; + } +} + double PFRecoTauDiscriminationByHPSSelection::discriminate(const reco::PFTauRef& tau) const { @@ -300,13 +318,9 @@ PFRecoTauDiscriminationByHPSSelection::discriminate(const reco::PFTauRef& tau) c if ( minPixelHits_ > 0 ) { int numPixelHits = 0; - const std::vector& chargedHadrCands = tau->signalPFChargedHadrCands(); - for ( std::vector::const_iterator chargedHadrCand = chargedHadrCands.begin(); - chargedHadrCand != chargedHadrCands.end(); ++chargedHadrCand ) { - const reco::Track* track = nullptr; - if ( (*chargedHadrCand)->trackRef().isNonnull() ) track = (*chargedHadrCand)->trackRef().get(); - else if ( (*chargedHadrCand)->gsfTrackRef().isNonnull() ) track = (*chargedHadrCand)->gsfTrackRef().get(); - if ( track ) { + for (const auto& chargedHadrCand : tau->signalChargedHadrCands()) { + const reco::Track* track = getTrack(*chargedHadrCand); + if (track != nullptr) { numPixelHits += track->hitPattern().numberOfValidPixelHits(); } } diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByInvMass.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByInvMass.cc index 8f7a88ef19338..a33da84b9b09f 100755 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByInvMass.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByInvMass.cc @@ -51,7 +51,7 @@ class PFRecoTauDiscriminationByInvMass: public PFTauDiscriminationProducerBase { double PFRecoTauDiscriminationByInvMass::discriminate(const reco::PFTauRef& tau) const { double mass = tau->mass(); - unsigned int charged = tau->signalPFChargedHadrCands().size(); + unsigned int charged = tau->signalChargedHadrCands().size(); unsigned int pizeros = tau->signalPiZeroCandidates().size(); DecayModeCutMap::const_iterator specificCut = decayModeCuts_.find( std::make_pair(charged, pizeros)); diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByIsolation.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByIsolation.cc index fbeac1288625e..e6e37cbb79894 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByIsolation.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByIsolation.cc @@ -154,7 +154,7 @@ class PFRecoTauDiscriminationByIsolation : public PFTauDiscriminationProducerBas puFactorizedIsoQCuts.second)); pfCandSrc_ = pset.getParameter("particleFlowSrc"); - pfCand_token = consumes(pfCandSrc_); + pfCand_token = consumes >(pfCandSrc_); vertexSrc_ = pset.getParameter("vertexSrc"); vertex_token = consumes(vertexSrc_); deltaBetaCollectionCone_ = pset.getParameter( @@ -185,7 +185,7 @@ class PFRecoTauDiscriminationByIsolation : public PFTauDiscriminationProducerBas void beginEvent(const edm::Event& evt, const edm::EventSetup& evtSetup) override; double discriminate(const PFTauRef& pfTau) const override; - inline double weightedSum(const std::vector& inColl_, double eta, double phi) const { + inline double weightedSum(const std::vector& inColl_, double eta, double phi) const { double out = 1.0; for (auto const & inObj_ : inColl_){ double sum = (inObj_->pt()*inObj_->pt())/(deltaR2(eta,phi,inObj_->eta(),inObj_->phi())); @@ -254,11 +254,11 @@ class PFRecoTauDiscriminationByIsolation : public PFTauDiscriminationProducerBas // Delta Beta correction bool applyDeltaBeta_; edm::InputTag pfCandSrc_; - edm::EDGetTokenT pfCand_token; + edm::EDGetTokenT > pfCand_token; // Keep track of how many vertices are in the event edm::InputTag vertexSrc_; edm::EDGetTokenT vertex_token; - std::vector chargedPFCandidatesInEvent_; + std::vector chargedPFCandidatesInEvent_; // Size of cone used to collect PU tracks double deltaBetaCollectionCone_; std::auto_ptr deltaBetaFormula_; @@ -290,13 +290,13 @@ void PFRecoTauDiscriminationByIsolation::beginEvent(const edm::Event& event, con // candidates from the event so we can find the PU tracks. if ( applyDeltaBeta_ || calculateWeights_ ) { // Collect all the PF pile up tracks - edm::Handle pfCandidates; + edm::Handle > pfCandidates; event.getByToken(pfCand_token, pfCandidates); chargedPFCandidatesInEvent_.clear(); chargedPFCandidatesInEvent_.reserve(pfCandidates->size()); size_t numPFCandidates = pfCandidates->size(); for ( size_t i = 0; i < numPFCandidates; ++i ) { - reco::PFCandidatePtr pfCandidate(pfCandidates, i); + reco::CandidatePtr pfCandidate(pfCandidates, i); if ( pfCandidate->charge() != 0 ) { chargedPFCandidatesInEvent_.push_back(pfCandidate); } @@ -324,15 +324,15 @@ PFRecoTauDiscriminationByIsolation::discriminate(const PFTauRef& pfTau) const LogDebug("discriminate") << *pfTau ; // collect the objects we are working with (ie tracks, tracks+gammas, etc) - std::vector isoCharged_; - std::vector isoNeutral_; - std::vector isoPU_; - PFCandidateCollection isoNeutralWeight_; - std::vector chPV_; - isoCharged_.reserve(pfTau->isolationPFChargedHadrCands().size()); - isoNeutral_.reserve(pfTau->isolationPFGammaCands().size()); + std::vector isoCharged_; + std::vector isoNeutral_; + std::vector isoPU_; + CandidateCollection isoNeutralWeight_; + std::vector chPV_; + isoCharged_.reserve(pfTau->isolationChargedHadrCands().size()); + isoNeutral_.reserve(pfTau->isolationGammaCands().size()); isoPU_.reserve(std::min(100UL, chargedPFCandidatesInEvent_.size())); - isoNeutralWeight_.reserve(pfTau->isolationPFGammaCands().size()); + isoNeutralWeight_.reserve(pfTau->isolationGammaCands().size()); chPV_.reserve(std::min(50UL, chargedPFCandidatesInEvent_.size())); @@ -346,32 +346,32 @@ PFRecoTauDiscriminationByIsolation::discriminate(const PFTauRef& pfTau) const } else { LogTrace("discriminate") << "pv: N/A" ; } - if ( pfTau->leadPFChargedHadrCand().isNonnull() ) { + if ( pfTau->leadChargedHadrCand().isNonnull() ) { LogTrace("discriminate") << "leadPFChargedHadron:" - << " Pt = " << pfTau->leadPFChargedHadrCand()->pt() << "," - << " eta = " << pfTau->leadPFChargedHadrCand()->eta() << "," - << " phi = " << pfTau->leadPFChargedHadrCand()->phi() ; + << " Pt = " << pfTau->leadChargedHadrCand()->pt() << "," + << " eta = " << pfTau->leadChargedHadrCand()->eta() << "," + << " phi = " << pfTau->leadChargedHadrCand()->phi() ; } else { LogTrace("discriminate") << "leadPFChargedHadron: N/A" ; } } // CV: isolation is not well defined in case primary vertex or leading charged hadron do not exist - if ( !(pv.isNonnull() && pfTau->leadPFChargedHadrCand().isNonnull()) ) return 0.; + if ( !(pv.isNonnull() && pfTau->leadChargedHadrCand().isNonnull()) ) return 0.; qcuts_->setPV(pv); - qcuts_->setLeadTrack(pfTau->leadPFChargedHadrCand()); + qcuts_->setLeadTrack(*pfTau->leadChargedHadrCand()); if ( applyDeltaBeta_ || calculateWeights_) { pileupQcutsGeneralQCuts_->setPV(pv); - pileupQcutsGeneralQCuts_->setLeadTrack(pfTau->leadPFChargedHadrCand()); + pileupQcutsGeneralQCuts_->setLeadTrack(*pfTau->leadChargedHadrCand()); pileupQcutsPUTrackSelection_->setPV(pv); - pileupQcutsPUTrackSelection_->setLeadTrack(pfTau->leadPFChargedHadrCand()); + pileupQcutsPUTrackSelection_->setLeadTrack(*pfTau->leadChargedHadrCand()); } // Load the tracks if they are being used. if ( includeTracks_ ) { - for( auto const & cand : pfTau->isolationPFChargedHadrCands() ) { + for( auto const & cand : pfTau->isolationChargedHadrCands() ) { if ( qcuts_->filterCandRef(cand) ) { LogTrace("discriminate") << "adding charged iso cand with pt " << cand->pt() ; isoCharged_.push_back(cand); @@ -379,7 +379,7 @@ PFRecoTauDiscriminationByIsolation::discriminate(const PFTauRef& pfTau) const } } if ( includeGammas_ || calculateWeights_ ) { - for( auto const & cand : pfTau->isolationPFGammaCands() ) { + for( auto const & cand : pfTau->isolationGammaCands() ) { if ( qcuts_->filterCandRef(cand) ) { LogTrace("discriminate") << "adding neutral iso cand with pt " << cand->pt() ; isoNeutral_.push_back(cand); @@ -387,8 +387,8 @@ PFRecoTauDiscriminationByIsolation::discriminate(const PFTauRef& pfTau) const } } - typedef reco::tau::cone::DeltaRPtrFilter DRFilter; - typedef reco::tau::cone::DeltaRFilter DRFilter2; + typedef reco::tau::cone::DeltaRPtrFilter DRFilter; + typedef reco::tau::cone::DeltaRFilter DRFilter2; // If desired, get PU tracks. if ( applyDeltaBeta_ || calculateWeights_) { @@ -397,21 +397,21 @@ PFRecoTauDiscriminationByIsolation::discriminate(const PFTauRef& pfTau) const std::cout << "Initial PFCands: " << chargedPFCandidatesInEvent_.size() << std::endl; } - std::vector allPU = + std::vector allPU = pileupQcutsPUTrackSelection_->filterCandRefs( chargedPFCandidatesInEvent_, true); - std::vector allNPU = + std::vector allNPU = pileupQcutsPUTrackSelection_->filterCandRefs( chargedPFCandidatesInEvent_); LogTrace("discriminate") << "After track cuts: " << allPU.size() ; // Now apply the rest of the cuts, like pt, and TIP, tracker hits, etc if ( !useAllPFCands_ ) { - std::vector cleanPU = + std::vector cleanPU = pileupQcutsGeneralQCuts_->filterCandRefs(allPU); - std::vector cleanNPU = + std::vector cleanNPU = pileupQcutsGeneralQCuts_->filterCandRefs(allNPU); LogTrace("discriminate") << "After cleaning cuts: " << cleanPU.size() ; @@ -445,7 +445,7 @@ PFRecoTauDiscriminationByIsolation::discriminate(const PFTauRef& pfTau) const double sumNPU = 0.5*log(weightedSum(chPV_, eta, phi)); double sumPU = 0.5*log(weightedSum(isoPU_, eta, phi)); - PFCandidate neutral = (*isoObject); + LeafCandidate neutral(*isoObject); if ( (sumNPU + sumPU) > 0 ) neutral.setP4(((sumNPU)/(sumNPU + sumPU))*neutral.p4()); isoNeutralWeight_.push_back(neutral); @@ -456,9 +456,9 @@ PFRecoTauDiscriminationByIsolation::discriminate(const PFTauRef& pfTau) const if ( customIsoCone_ >= 0. ) { DRFilter filter(pfTau->p4(), 0, customIsoCone_); DRFilter2 filter2(pfTau->p4(), 0, customIsoCone_); - std::vector isoCharged_filter; - std::vector isoNeutral_filter; - PFCandidateCollection isoNeutralWeight_filter; + std::vector isoCharged_filter; + std::vector isoNeutral_filter; + CandidateCollection isoNeutralWeight_filter; // Remove all the objects not in our iso cone for( auto const & isoObject : isoCharged_ ) { if ( filter(isoObject) ) isoCharged_filter.push_back(isoObject); @@ -564,11 +564,11 @@ PFRecoTauDiscriminationByIsolation::discriminate(const PFTauRef& pfTau) const bool failsPhotonPtSumOutsideSignalConeCut = false; double photonSumPt_outsideSignalCone = 0.; if ( applyPhotonPtSumOutsideSignalConeCut_ || storeRawPhotonSumPt_outsideSignalCone_ ) { - const std::vector& signalPFGammas = pfTau->signalPFGammaCands(); - for ( std::vector::const_iterator signalPFGamma = signalPFGammas.begin(); - signalPFGamma != signalPFGammas.end(); ++signalPFGamma ) { - double dR = deltaR(pfTau->eta(), pfTau->phi(), (*signalPFGamma)->eta(), (*signalPFGamma)->phi()); - if ( dR > pfTau->signalConeSize() ) photonSumPt_outsideSignalCone += (*signalPFGamma)->pt(); + const std::vector& signalGammas = pfTau->signalGammaCands(); + for ( std::vector::const_iterator signalGamma = signalGammas.begin(); + signalGamma != signalGammas.end(); ++signalGamma ) { + double dR = deltaR(pfTau->eta(), pfTau->phi(), (*signalGamma)->eta(), (*signalGamma)->phi()); + if ( dR > pfTau->signalConeSize() ) photonSumPt_outsideSignalCone += (*signalGamma)->pt(); } if ( photonSumPt_outsideSignalCone > maxAbsPhotonSumPt_outsideSignalCone_ || photonSumPt_outsideSignalCone > (maxRelPhotonSumPt_outsideSignalCone_*pfTau->pt()) ) { failsPhotonPtSumOutsideSignalConeCut = true; diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByLeadingObjectPtCut.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByLeadingObjectPtCut.cc index 9123a604d92a5..775114eea00f6 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByLeadingObjectPtCut.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByLeadingObjectPtCut.cc @@ -30,23 +30,23 @@ double PFRecoTauDiscriminationByLeadingObjectPtCut::discriminate(const PFTauRef& double leadObjectPt = -1.; if( chargedOnly_ ) { - // consider only charged hadrons. note that the leadPFChargedHadrCand is the highest pt + // consider only charged hadrons. note that the leadChargedHadrCand is the highest pt // charged signal cone object above the quality cut level (typically 0.5 GeV). - if( thePFTauRef->leadPFChargedHadrCand().isNonnull() ) + if( thePFTauRef->leadChargedHadrCand().isNonnull() ) { - leadObjectPt = thePFTauRef->leadPFChargedHadrCand()->pt(); + leadObjectPt = thePFTauRef->leadChargedHadrCand()->pt(); } } else { // If using the 'leading pion' option, require that: - // 1) at least one charged hadron exists above threshold (thePFTauRef->leadPFChargedHadrCand().isNonnull()) + // 1) at least one charged hadron exists above threshold (thePFTauRef->leadChargedHadrCand().isNonnull()) // 2) the lead PFCand exists. In the case that the highest pt charged hadron is above the PFRecoTauProducer threshold - // (typically 5 GeV), the leadPFCand and the leadPFChargedHadrCand are the same object. If the leadPFChargedHadrCand - // is below 5GeV, but there exists a neutral PF particle > 5 GeV, it is set to be the leadPFCand - if( thePFTauRef->leadPFCand().isNonnull() && thePFTauRef->leadPFChargedHadrCand().isNonnull() ) + // (typically 5 GeV), the leadCand and the leadChargedHadrCand are the same object. If the leadChargedHadrCand + // is below 5GeV, but there exists a neutral PF particle > 5 GeV, it is set to be the leadCand + if( thePFTauRef->leadCand().isNonnull() && thePFTauRef->leadChargedHadrCand().isNonnull() ) { - leadObjectPt = thePFTauRef->leadPFCand()->pt(); + leadObjectPt = thePFTauRef->leadCand()->pt(); } } @@ -69,32 +69,3 @@ PFRecoTauDiscriminationByLeadingObjectPtCut::fillDescriptions(edm::Configuration } 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.leadPFCand() || !thePFTau.leadPFChargedHadrCand()) - { - theleadTrackPtCutDiscriminator=0.; - } - else if(thePFTau.leadPFCand()->pt() > minPtLeadTrack_) theleadTrackPtCutDiscriminator=1.; - - thePFTauDiscriminatorByLeadingPionPtCut->setValue(iPFTau,theleadTrackPtCutDiscriminator); - } - - iEvent.put(std::move(thePFTauDiscriminatorByLeadingPionPtCut)); - -} - -*/ diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByMVAIsolation2.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByMVAIsolation2.cc index 1774b66575d44..e6153c4cd1734 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByMVAIsolation2.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByMVAIsolation2.cc @@ -178,7 +178,7 @@ double PFRecoTauDiscriminationByIsolationMVA2::discriminate(const PFTauRef& tau) category_output_->setValue(tauIndex_, category); // CV: computation of MVA value requires presence of leading charged hadron - if ( tau->leadPFChargedHadrCand().isNull() ) return 0.; + if ( tau->leadChargedHadrCand().isNull() ) return 0.; int tauDecayMode = tau->decayMode(); diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByMVAIsolationRun2.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByMVAIsolationRun2.cc index 96c5c09f9ae65..c7d3c799b9311 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByMVAIsolationRun2.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByMVAIsolationRun2.cc @@ -196,7 +196,7 @@ double PFRecoTauDiscriminationByMVAIsolationRun2::discriminate(const PFTauRef& t category_output_->setValue(tauIndex_, category); // CV: computation of MVA value requires presence of leading charged hadron - if ( tau->leadPFChargedHadrCand().isNull() ) return 0.; + if ( tau->leadChargedHadrCand().isNull() ) return 0.; int tauDecayMode = tau->decayMode(); diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByNProngs.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByNProngs.cc index 32ceb75ac26d2..05d2961a74525 100755 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByNProngs.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByNProngs.cc @@ -54,14 +54,14 @@ void PFRecoTauDiscriminationByNProngs::beginEvent(const Event& iEvent, const Eve double PFRecoTauDiscriminationByNProngs::discriminate(const PFTauRef& tau) const{ reco::VertexRef pv = vertexAssociator_->associatedVertex(*tau); - const PFCandidatePtr leadingTrack = tau->leadPFChargedHadrCand(); + const CandidatePtr leadingTrack = tau->leadChargedHadrCand(); uint np = 0; if(leadingTrack.isNonnull() && pv.isNonnull()){ qcuts_->setPV(pv); - qcuts_->setLeadTrack(tau->leadPFChargedHadrCand()); + qcuts_->setLeadTrack(*tau->leadChargedHadrCand()); - for(auto const& cand : tau->signalPFChargedHadrCands() ) { + for(auto const& cand : tau->signalChargedHadrCands() ) { if ( qcuts_->filterCandRef(cand) ) np++; } } diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByTauPolarization.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByTauPolarization.cc index 6a70c94ad0c44..d22f07d7fb022 100755 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByTauPolarization.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationByTauPolarization.cc @@ -42,8 +42,8 @@ PFRecoTauDiscriminationByTauPolarization::discriminate(const PFTauRef& tau) cons // rtau for PFTau has to be calculated for leading PF charged hadronic candidate // calculating it from leadingTrack can (and will) give rtau > 1! if(tau.isNonnull() && tau->p() > 0 - && tau->leadPFChargedHadrCand().isNonnull()) { - rTau = tau->leadPFChargedHadrCand()->p()/tau->p(); + && tau->leadChargedHadrCand().isNonnull()) { + rTau = tau->leadChargedHadrCand()->p()/tau->p(); } if(booleanOutput) return ( rTau > rTauMin ? 1. : 0. ); diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauEnergyAlgorithmPlugin.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauEnergyAlgorithmPlugin.cc index fb60c8bc20245..bfe30eadeadbe 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauEnergyAlgorithmPlugin.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauEnergyAlgorithmPlugin.cc @@ -17,6 +17,7 @@ #include "RecoTauTag/RecoTau/interface/RecoTauBuilderPlugins.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" #include "DataFormats/JetReco/interface/PFJet.h" #include "DataFormats/TrackReco/interface/Track.h" #include "DataFormats/Common/interface/Ptr.h" @@ -39,7 +40,7 @@ class PFRecoTauEnergyAlgorithmPlugin : public RecoTauModifierPlugin explicit PFRecoTauEnergyAlgorithmPlugin(const edm::ParameterSet&, edm::ConsumesCollector &&iC); ~PFRecoTauEnergyAlgorithmPlugin() override; - void operator()(PFTau&) const override; + void operator()(reco::PFTau&) const override; void beginEvent() override; void endEvent() override; @@ -53,7 +54,7 @@ class PFRecoTauEnergyAlgorithmPlugin : public RecoTauModifierPlugin int verbosity_; }; - PFRecoTauEnergyAlgorithmPlugin::PFRecoTauEnergyAlgorithmPlugin(const edm::ParameterSet& cfg, edm::ConsumesCollector &&iC) +PFRecoTauEnergyAlgorithmPlugin::PFRecoTauEnergyAlgorithmPlugin(const edm::ParameterSet& cfg, edm::ConsumesCollector &&iC) : RecoTauModifierPlugin(cfg, std::move(iC)), dRaddNeutralHadron_(cfg.getParameter("dRaddNeutralHadron")), minNeutralHadronEt_(cfg.getParameter("minNeutralHadronEt")), @@ -76,7 +77,7 @@ namespace return trackPerr*trackPerr; } - void updateTauP4(PFTau& tau, double sf, const reco::Candidate::LorentzVector& addP4) + void updateTauP4(reco::PFTau& tau, double sf, const reco::Candidate::LorentzVector& addP4) { // preserve tau candidate mass when adding extra neutral energy double tauPx_modified = tau.px() + sf*addP4.px(); @@ -88,7 +89,7 @@ namespace tau.setP4(tauP4_modified); } - void killTau(PFTau& tau) + void killTau(reco::PFTau& tau) { reco::Candidate::LorentzVector tauP4_modified(0.,0.,0.,0.); tau.setP4(tauP4_modified); @@ -96,7 +97,17 @@ namespace } } -void PFRecoTauEnergyAlgorithmPlugin::operator()(PFTau& tau) const +template +bool isPtrEqual(const edm::Ptr& b, const edm::Ptr& d) { + return edm::Ptr(b) == d; +} + +template +bool isPtrEqual(const edm::Ptr& b, const edm::Ptr& d) { + return b == d; +} + +void PFRecoTauEnergyAlgorithmPlugin::operator()(reco::PFTau& tau) const { if ( verbosity_ ) { std::cout << ":" << std::endl; @@ -104,30 +115,29 @@ void PFRecoTauEnergyAlgorithmPlugin::operator()(PFTau& tau) const } // Add high Pt PFNeutralHadrons and PFGammas that are not "used" by tau decay mode object - std::vector addNeutrals; + std::vector addNeutrals; reco::Candidate::LorentzVector addNeutralsSumP4; - std::vector jetConstituents = tau.jetRef()->getPFConstituents(); - for ( std::vector::const_iterator jetConstituent = jetConstituents.begin(); - jetConstituent != jetConstituents.end(); ++jetConstituent ) { - reco::PFCandidate::ParticleType jetConstituentType = (*jetConstituent)->particleId(); - if ( !((jetConstituentType == reco::PFCandidate::h0 && (*jetConstituent)->et() > minNeutralHadronEt_) || - (jetConstituentType == reco::PFCandidate::gamma && (*jetConstituent)->et() > minGammaEt_ )) ) continue; + const auto& jetConstituents = tau.jetRef()->daughterPtrVector(); + for (const auto& jetConstituent : jetConstituents) { + + int jetConstituentPdgId = std::abs(jetConstituent->pdgId()); + if ( !((jetConstituentPdgId == 130 && jetConstituent->et() > minNeutralHadronEt_) || + (jetConstituentPdgId == 22 && jetConstituent->et() > minGammaEt_ )) ) continue; - bool isSignalPFCand = false; - const std::vector& signalPFCands = tau.signalPFCands(); - for ( std::vector::const_iterator signalPFCand = signalPFCands.begin(); - signalPFCand != signalPFCands.end(); ++signalPFCand ) { - if ( (*jetConstituent) == (*signalPFCand) ) isSignalPFCand = true; + bool isSignalCand = false; + const auto& signalCands = tau.signalCands(); + for (const auto& signalCand : signalCands) { + if ( isPtrEqual(jetConstituent, signalCand) ) isSignalCand = true; } - if ( isSignalPFCand ) continue; + if ( isSignalCand ) continue; - double dR = deltaR((*jetConstituent)->p4(), tau.p4()); + double dR = deltaR(jetConstituent->p4(), tau.p4()); double dRadd = -1.; - if ( jetConstituentType == reco::PFCandidate::h0 ) dRadd = dRaddNeutralHadron_; - else if ( jetConstituentType == reco::PFCandidate::gamma ) dRadd = dRaddPhoton_; + if ( jetConstituentPdgId == 130 ) dRadd = dRaddNeutralHadron_; + else if ( jetConstituentPdgId == 22 ) dRadd = dRaddPhoton_; if ( dR < dRadd ) { - addNeutrals.push_back(*jetConstituent); - addNeutralsSumP4 += (*jetConstituent)->p4(); + addNeutrals.push_back(jetConstituent); + addNeutralsSumP4 += jetConstituent->p4(); } } if ( verbosity_ ) { @@ -142,9 +152,11 @@ void PFRecoTauEnergyAlgorithmPlugin::operator()(PFTau& tau) const chargedHadron != chargedHadrons.end(); ++chargedHadron ) { if ( chargedHadron->algoIs(PFRecoTauChargedHadron::kTrack) ) { ++numNonPFCandTracks; - const edm::Ptr& chargedHadronTrack = chargedHadron->getTrack(); - nonPFCandTracksSumP += chargedHadronTrack->p(); - nonPFCandTracksSumPerr2 += getTrackPerr2(*chargedHadronTrack); + const reco::Track* chargedHadronTrack = getTrackFromChargedHadron(*chargedHadron); + if ( chargedHadronTrack != nullptr ) { + nonPFCandTracksSumP += chargedHadronTrack->p(); + nonPFCandTracksSumPerr2 += getTrackPerr2(*chargedHadronTrack); + } } } if ( verbosity_ ) { @@ -185,13 +197,13 @@ void PFRecoTauEnergyAlgorithmPlugin::operator()(PFTau& tau) const // Determine which neutral PFCandidates are close to PFChargedHadrons // and have been merged into ChargedHadrons - std::vector mergedNeutrals; + std::vector mergedNeutrals; reco::Candidate::LorentzVector mergedNeutralsSumP4; for ( std::vector::const_iterator chargedHadron = chargedHadrons.begin(); chargedHadron != chargedHadrons.end(); ++chargedHadron ) { if ( chargedHadron->algoIs(PFRecoTauChargedHadron::kTrack) ) { - const std::vector& neutralPFCands = chargedHadron->getNeutralPFCandidates(); - for ( std::vector::const_iterator neutralPFCand = neutralPFCands.begin(); + const std::vector& neutralPFCands = chargedHadron->getNeutralPFCandidates(); + for ( std::vector::const_iterator neutralPFCand = neutralPFCands.begin(); neutralPFCand != neutralPFCands.end(); ++neutralPFCand ) { mergedNeutrals.push_back(*neutralPFCand); mergedNeutralsSumP4 += (*neutralPFCand)->p4(); @@ -232,7 +244,7 @@ void PFRecoTauEnergyAlgorithmPlugin::operator()(PFTau& tau) const // Determine energy sum of all PFNeutralHadrons interpreted as ChargedHadrons with missing track unsigned numChargedHadronNeutrals = 0; - std::vector chargedHadronNeutrals; + std::vector chargedHadronNeutrals; reco::Candidate::LorentzVector chargedHadronNeutralsSumP4; for ( std::vector::const_iterator chargedHadron = chargedHadrons.begin(); chargedHadron != chargedHadrons.end(); ++chargedHadron ) { @@ -264,7 +276,7 @@ void PFRecoTauEnergyAlgorithmPlugin::operator()(PFTau& tau) const if ( chargedHadron.algoIs(PFRecoTauChargedHadron::kPFNeutralHadron) ) { PFRecoTauChargedHadron chargedHadron_modified = chargedHadron; chargedHadron_modified.neutralPFCandidates_.clear(); - const PFCandidatePtr& chargedPFCand = chargedHadron.getChargedPFCandidate(); + const CandidatePtr& chargedPFCand = chargedHadron.getChargedPFCandidate(); double chargedHadronPx_modified = scaleFactor*chargedPFCand->px(); double chargedHadronPy_modified = scaleFactor*chargedPFCand->py(); double chargedHadronPz_modified = scaleFactor*chargedPFCand->pz(); @@ -286,13 +298,13 @@ void PFRecoTauEnergyAlgorithmPlugin::operator()(PFTau& tau) const for ( std::vector::const_iterator chargedHadron = chargedHadrons.begin(); chargedHadron != chargedHadrons.end(); ++chargedHadron ) { if ( chargedHadron->algoIs(PFRecoTauChargedHadron::kChargedPFCandidate) || chargedHadron->algoIs(PFRecoTauChargedHadron::kTrack) ) { - const edm::Ptr& chargedHadronTrack = chargedHadron->getTrack(); - if ( chargedHadronTrack.isNonnull() ) { + const reco::Track* chargedHadronTrack = getTrackFromChargedHadron(*chargedHadron); + if ( chargedHadronTrack != nullptr ) { allTracksSumP += chargedHadronTrack->p(); allTracksSumPerr2 += getTrackPerr2(*chargedHadronTrack); } else { - edm::LogWarning("PFRecoTauEnergyAlgorithmPlugin::operator()") - << "PFRecoTauChargedHadron has no associated reco::Track !!" << std::endl; + edm::LogInfo("PFRecoTauEnergyAlgorithmPlugin::operator()") + << "PFRecoTauChargedHadron has no associated reco::Track !!"; if ( verbosity_ ) { chargedHadron->print(); } @@ -303,20 +315,25 @@ void PFRecoTauEnergyAlgorithmPlugin::operator()(PFTau& tau) const std::cout << "allTracksSumP = " << allTracksSumP << " +/- " << sqrt(allTracksSumPerr2) << std::endl; } double allNeutralsSumEn = 0.; - const std::vector& signalPFCands = tau.signalPFCands(); - for ( std::vector::const_iterator signalPFCand = signalPFCands.begin(); - signalPFCand != signalPFCands.end(); ++signalPFCand ) { + const auto& signalCands = tau.signalCands(); + for (const auto& signalCand : signalCands) { if ( verbosity_ ) { - std::cout << "PFCandidate #" << signalPFCand->id() << ":" << signalPFCand->key() << ":" - << " Pt = " << (*signalPFCand)->pt() << ", eta = " << (*signalPFCand)->eta() << ", phi = " << (*signalPFCand)->phi() << std::endl; - std::cout << "calorimeter energy:" - << " ECAL = " << (*signalPFCand)->ecalEnergy() << "," - << " HCAL = " << (*signalPFCand)->hcalEnergy() << "," - << " HO = " << (*signalPFCand)->hoEnergy() << std::endl; - } - if ( edm::isFinite((*signalPFCand)->ecalEnergy()) ) allNeutralsSumEn += (*signalPFCand)->ecalEnergy(); - if ( edm::isFinite((*signalPFCand)->hcalEnergy()) ) allNeutralsSumEn += (*signalPFCand)->hcalEnergy(); - if ( edm::isFinite((*signalPFCand)->hoEnergy()) ) allNeutralsSumEn += (*signalPFCand)->hoEnergy(); + std::cout << "Candidate #" << signalCand.id() << ":" << signalCand.key() << ":" + << " Pt = " << (signalCand)->pt() << ", eta = " << (signalCand)->eta() << ", phi = " << (signalCand)->phi() << std::endl; + } + const PFCandidate* pfCand = dynamic_cast(&*signalCand); + if (pfCand) { + if (verbosity_) { + std::cout << "calorimeter energy:" + << " ECAL = " << (pfCand)->ecalEnergy() << "," + << " HCAL = " << (pfCand)->hcalEnergy() << "," + << " HO = " << (pfCand)->hoEnergy() << std::endl; + } + // TauReco@MiniAOD: This info is not yet available in miniAOD. + if ( edm::isFinite(pfCand->ecalEnergy()) ) allNeutralsSumEn += pfCand->ecalEnergy(); + if ( edm::isFinite(pfCand->hcalEnergy()) ) allNeutralsSumEn += pfCand->hcalEnergy(); + if ( edm::isFinite(pfCand->hoEnergy()) ) allNeutralsSumEn += pfCand->hoEnergy(); + } } allNeutralsSumEn += addNeutralsSumP4.energy(); if ( allNeutralsSumEn < 0. ) allNeutralsSumEn = 0.; @@ -340,11 +357,11 @@ void PFRecoTauEnergyAlgorithmPlugin::operator()(PFTau& tau) const PFRecoTauChargedHadron chargedHadron_modified = chargedHadron; chargedHadron_modified.neutralPFCandidates_.clear(); reco::Candidate::LorentzVector chargedHadronP4_modified(0.,0.,0.,0.); - if ( (chargedHadron.getTrack()).isNonnull() ) { - const Track& chargedHadronTrack = *(chargedHadron.getTrack()); - double chargedHadronPx_modified = chargedHadronTrack.px(); - double chargedHadronPy_modified = chargedHadronTrack.py(); - double chargedHadronPz_modified = chargedHadronTrack.pz(); + const reco::Track* chTrack = getTrackFromChargedHadron(chargedHadron); + if ( chTrack != nullptr ) { + double chargedHadronPx_modified = chTrack->px(); + double chargedHadronPy_modified = chTrack->py(); + double chargedHadronPz_modified = chTrack->pz(); chargedHadronP4_modified = compChargedHadronP4fromPxPyPz(chargedHadronPx_modified, chargedHadronPy_modified, chargedHadronPz_modified); } else { edm::LogWarning("PFRecoTauEnergyAlgorithmPlugin::operator()") @@ -376,8 +393,8 @@ void PFRecoTauEnergyAlgorithmPlugin::operator()(PFTau& tau) const PFRecoTauChargedHadron chargedHadron_modified = chargedHadron; chargedHadron_modified.neutralPFCandidates_.clear(); reco::Candidate::LorentzVector chargedHadronP4_modified(0.,0.,0.,0.); - const edm::Ptr& chargedHadronTrack = chargedHadron.getTrack(); - if ( chargedHadronTrack.isNonnull() ) { + const reco::Track* chargedHadronTrack = getTrackFromChargedHadron(chargedHadron); + if ( chargedHadronTrack != nullptr ) { double trackP = chargedHadronTrack->p(); double trackPerr2 = getTrackPerr2(*chargedHadronTrack); if ( verbosity_ ) { @@ -408,8 +425,8 @@ void PFRecoTauEnergyAlgorithmPlugin::operator()(PFTau& tau) const double chargedHadronPz_modified = scaleFactor*chargedHadronTrack->pz(); chargedHadronP4_modified = compChargedHadronP4fromPxPyPz(chargedHadronPx_modified, chargedHadronPy_modified, chargedHadronPz_modified); } else { - edm::LogWarning("PFRecoTauEnergyAlgorithmPlugin::operator()") - << "PFRecoTauChargedHadron has no associated reco::Track !!" << std::endl; + edm::LogInfo("PFRecoTauEnergyAlgorithmPlugin::operator()") + << "PFRecoTauChargedHadron has no associated reco::Track !!"; if ( verbosity_ ) { chargedHadron.print(); } diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauTagInfoProducer.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauTagInfoProducer.cc index c30f65fcfb890..e1fd6d2570be7 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauTagInfoProducer.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauTagInfoProducer.cc @@ -78,9 +78,9 @@ void PFRecoTauTagInfoProducer::produce(edm::StreamID, edm::Event& iEvent, const // *** access the PFCandidateCollection in the event in order to retrieve the PFCandidateRefVector which constitutes each PFJet edm::Handle thePFCandidateCollection; iEvent.getByToken(PFCandidate_token,thePFCandidateCollection); - vector thePFCandsInTheEvent; + vector thePFCandsInTheEvent; for(unsigned int i_PFCand=0;i_PFCand!=thePFCandidateCollection->size();i_PFCand++) { - thePFCandsInTheEvent.push_back(PFCandidatePtr(thePFCandidateCollection,i_PFCand)); + thePFCandsInTheEvent.push_back(CandidatePtr(thePFCandidateCollection,i_PFCand)); } // *** // query a rec/sim PV @@ -102,7 +102,7 @@ else{ auto resultExt = std::make_unique(); for(JetTracksAssociationCollection::const_iterator iAssoc=thePFJetTracksAssociatorCollection->begin();iAssoc!=thePFJetTracksAssociatorCollection->end();iAssoc++){ - PFTauTagInfo myPFTauTagInfo=PFRecoTauTagInfoAlgo_->buildPFTauTagInfo((*iAssoc).first.castTo(),thePFCandsInTheEvent,(*iAssoc).second,thePV); + PFTauTagInfo myPFTauTagInfo=PFRecoTauTagInfoAlgo_->buildPFTauTagInfo(JetBaseRef((*iAssoc).first),thePFCandsInTheEvent,(*iAssoc).second,thePV); resultExt->push_back(myPFTauTagInfo); } diff --git a/RecoTauTag/RecoTau/plugins/PFTauMiniAODPrimaryVertexProducer.cc b/RecoTauTag/RecoTau/plugins/PFTauMiniAODPrimaryVertexProducer.cc new file mode 100644 index 0000000000000..a414dc720869f --- /dev/null +++ b/RecoTauTag/RecoTau/plugins/PFTauMiniAODPrimaryVertexProducer.cc @@ -0,0 +1,101 @@ +#include "RecoTauTag/RecoTau/interface/PFTauPrimaryVertexProducerBase.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" +#include "DataFormats/Math/interface/deltaR.h" + +/// MiniAOD implementation of the PFTauPrimaryVertexProducer plugin +class PFTauMiniAODPrimaryVertexProducer final : public PFTauPrimaryVertexProducerBase { + + public: + explicit PFTauMiniAODPrimaryVertexProducer(const edm::ParameterSet& iConfig); + ~PFTauMiniAODPrimaryVertexProducer() override; + + void beginEvent(const edm::Event&, const edm::EventSetup&) override; + static void fillDescriptions(edm::ConfigurationDescriptions & descriptions); + + protected: + void nonTauTracksInPV(const reco::VertexRef&, + const std::vector >&, + std::vector&) override; + + private: + void nonTauTracksInPVFromPackedCands(const size_t&, + const pat::PackedCandidateCollection&, + const std::vector >&, + std::vector &); + + edm::EDGetTokenT packedCandsToken_, lostCandsToken_; + edm::Handle packedCands_, lostCands_; + +}; + +PFTauMiniAODPrimaryVertexProducer::PFTauMiniAODPrimaryVertexProducer(const edm::ParameterSet& iConfig): + PFTauPrimaryVertexProducerBase::PFTauPrimaryVertexProducerBase(iConfig), + packedCandsToken_(consumes(iConfig.getParameter("packedCandidatesTag"))), + lostCandsToken_(consumes(iConfig.getParameter("lostCandidatesTag"))) {} + +PFTauMiniAODPrimaryVertexProducer::~PFTauMiniAODPrimaryVertexProducer(){} + +void PFTauMiniAODPrimaryVertexProducer::beginEvent(const edm::Event& iEvent, const edm::EventSetup& iSetup){ + + //Get candidate collections + iEvent.getByToken(packedCandsToken_, packedCands_); + iEvent.getByToken(lostCandsToken_, lostCands_); +} + +void PFTauMiniAODPrimaryVertexProducer::nonTauTracksInPV(const reco::VertexRef &thePVRef, + const std::vector > &tauTracks, + std::vector &nonTauTracks){ + + //Find non-tau tracks associated to thePV + //PackedCandidates first... + if(packedCands_.isValid()) { + nonTauTracksInPVFromPackedCands(thePVRef.key(),*packedCands_,tauTracks,nonTauTracks); + } + //then lostCandidates + if(lostCands_.isValid()) { + nonTauTracksInPVFromPackedCands(thePVRef.key(),*lostCands_,tauTracks,nonTauTracks); + } +} + +void PFTauMiniAODPrimaryVertexProducer::nonTauTracksInPVFromPackedCands(const size_t &thePVkey, + const pat::PackedCandidateCollection &cands, + const std::vector > &tauTracks, + std::vector &nonTauTracks){ + + //Find candidates/tracks associated to thePV + for(const auto& cand: cands){ + if(cand.vertexRef().isNull()) continue; + int quality = cand.pvAssociationQuality(); + if(cand.vertexRef().key()!=thePVkey || + (quality!=pat::PackedCandidate::UsedInFitTight && + quality!=pat::PackedCandidate::UsedInFitLoose)) continue; + const reco::Track *track = cand.bestTrack(); + if(track == nullptr) continue; + //Remove signal (tau) tracks + //MB: Only deltaR deltaPt overlap removal possible (?) + //MB: It should be fine as pat objects stores same track info with same presision + bool matched = false; + for(const auto& tauTrack: tauTracks){ + if(std::abs(tauTrack->eta()-track->eta())<0.005 + && std::abs(deltaPhi(tauTrack->phi(),track->phi()))<0.005 + && std::abs(tauTrack->pt()/track->pt()-1.)<0.005 + ){ + matched = true; + break; + } + } + if( !matched ) nonTauTracks.push_back(track); + } +} + +void +PFTauMiniAODPrimaryVertexProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + auto desc = PFTauPrimaryVertexProducerBase::getDescriptionsBase(); + desc.add("lostCandidatesTag", edm::InputTag("lostTracks")); + desc.add("packedCandidatesTag", edm::InputTag("packedPFCandidates")); + + descriptions.add("pfTauMiniAODPrimaryVertexProducer", desc); +} + +DEFINE_FWK_MODULE(PFTauMiniAODPrimaryVertexProducer); diff --git a/RecoTauTag/RecoTau/plugins/PFTauPrimaryVertexProducer.cc b/RecoTauTag/RecoTau/plugins/PFTauPrimaryVertexProducer.cc index 58c095399dd73..50783393c6ab2 100644 --- a/RecoTauTag/RecoTau/plugins/PFTauPrimaryVertexProducer.cc +++ b/RecoTauTag/RecoTau/plugins/PFTauPrimaryVertexProducer.cc @@ -1,352 +1,49 @@ -/* class PFTauPrimaryVertexProducer - * EDProducer of the - * authors: Ian M. Nugent - * This work is based on the impact parameter work by Rosamaria Venditti and reconstructing the 3 prong taus. - * The idea of the fully reconstructing the tau using a kinematic fit comes from - * Lars Perchalla and Philip Sauerland Theses under Achim Stahl supervision. This - * work was continued by Ian M. Nugent and Vladimir Cherepanov. - * Thanks goes to Christian Veelken and Evan Klose Friis for their help and suggestions. - */ - - -#include "FWCore/Framework/interface/EventSetup.h" -#include "FWCore/Framework/interface/ESHandle.h" -#include "FWCore/Framework/interface/Event.h" +#include "RecoTauTag/RecoTau/interface/PFTauPrimaryVertexProducerBase.h" #include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/Utilities/interface/Exception.h" - -#include -#include - -#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" -#include "TrackingTools/Records/interface/TransientTrackRecord.h" -#include "RecoVertex/VertexPrimitives/interface/TransientVertex.h" -#include "RecoVertex/AdaptiveVertexFit/interface/AdaptiveVertexFitter.h" -#include "RecoTauTag/RecoTau/interface/RecoTauVertexAssociator.h" - -#include "DataFormats/TauReco/interface/PFTau.h" -#include "DataFormats/TauReco/interface/PFTauFwd.h" -#include "DataFormats/BeamSpot/interface/BeamSpot.h" -#include "DataFormats/MuonReco/interface/Muon.h" -#include "DataFormats/MuonReco/interface/MuonFwd.h" -#include "DataFormats/VertexReco/interface/Vertex.h" -#include "DataFormats/VertexReco/interface/VertexFwd.h" -#include "DataFormats/TrackReco/interface/Track.h" -#include "DataFormats/TrackReco/interface/TrackFwd.h" -#include "DataFormats/GsfTrackReco/interface/GsfTrack.h" -#include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h" -#include "DataFormats/Common/interface/RefToBase.h" -#include "DataFormats/EgammaCandidates/interface/Electron.h" -#include "DataFormats/EgammaCandidates/interface/ElectronFwd.h" -#include "DataFormats/Common/interface/Association.h" -#include "DataFormats/Common/interface/AssociationVector.h" -#include "DataFormats/Common/interface/RefProd.h" +/// RECO/AOD implementation of the PFTauPrimaryVertexProducer plugin +class PFTauPrimaryVertexProducer final : public PFTauPrimaryVertexProducerBase { -#include "DataFormats/TauReco/interface/PFTauDiscriminator.h" -#include "CommonTools/Utils/interface/StringCutObjectSelector.h" -#include -#include - -#include - -using namespace reco; -using namespace edm; -using namespace std; - -class PFTauPrimaryVertexProducer final : public edm::stream::EDProducer<> { public: - enum Alg{useInputPV=0, useFontPV}; - - struct DiscCutPair{ - DiscCutPair():discr_(nullptr),cutFormula_(nullptr){} - ~DiscCutPair(){delete cutFormula_;} - const reco::PFTauDiscriminator* discr_; - edm::EDGetTokenT inputToken_; - double cut_; - TFormula* cutFormula_; - }; - typedef std::vector DiscCutPairVec; - explicit PFTauPrimaryVertexProducer(const edm::ParameterSet& iConfig); ~PFTauPrimaryVertexProducer() override; - void produce(edm::Event&,const edm::EventSetup&) override; static void fillDescriptions(edm::ConfigurationDescriptions & descriptions); - private: - edm::InputTag PFTauTag_; - edm::EDGetTokenT >PFTauToken_; - edm::InputTag ElectronTag_; - edm::EDGetTokenT >ElectronToken_; - edm::InputTag MuonTag_; - edm::EDGetTokenT >MuonToken_; - edm::InputTag PVTag_; - edm::EDGetTokenT PVToken_; - edm::InputTag beamSpotTag_; - edm::EDGetTokenT beamSpotToken_; - int Algorithm_; - edm::ParameterSet qualityCutsPSet_; - bool useBeamSpot_; - bool useSelectedTaus_; - bool RemoveMuonTracks_; - bool RemoveElectronTracks_; - DiscCutPairVec discriminators_; - std::unique_ptr > cut_; - std::unique_ptr vertexAssociator_; + protected: + void nonTauTracksInPV(const reco::VertexRef&, + const std::vector >&, + std::vector&) override; + }; -PFTauPrimaryVertexProducer::PFTauPrimaryVertexProducer(const edm::ParameterSet& iConfig): - PFTauTag_(iConfig.getParameter("PFTauTag")), - PFTauToken_(consumes >(PFTauTag_)), - ElectronTag_(iConfig.getParameter("ElectronTag")), - ElectronToken_(consumes >(ElectronTag_)), - MuonTag_(iConfig.getParameter("MuonTag")), - MuonToken_(consumes >(MuonTag_)), - PVTag_(iConfig.getParameter("PVTag")), - PVToken_(consumes(PVTag_)), - beamSpotTag_(iConfig.getParameter("beamSpot")), - beamSpotToken_(consumes(beamSpotTag_)), - Algorithm_(iConfig.getParameter("Algorithm")), - qualityCutsPSet_(iConfig.getParameter("qualityCuts")), - useBeamSpot_(iConfig.getParameter("useBeamSpot")), - useSelectedTaus_(iConfig.getParameter("useSelectedTaus")), - RemoveMuonTracks_(iConfig.getParameter("RemoveMuonTracks")), - RemoveElectronTracks_(iConfig.getParameter("RemoveElectronTracks")) -{ - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - std::vector discriminators =iConfig.getParameter >("discriminators"); - // Build each of our cuts - for(auto const& pset : discriminators) { - DiscCutPair* newCut = new DiscCutPair(); - newCut->inputToken_ =consumes(pset.getParameter("discriminator")); - if ( pset.existsAs("selectionCut") ) newCut->cutFormula_ = new TFormula("selectionCut", pset.getParameter("selectionCut").data()); - else newCut->cut_ = pset.getParameter("selectionCut"); - discriminators_.push_back(newCut); - } - // Build a string cut - cut_.reset(new StringCutObjectSelector(iConfig.getParameter( "cut" ))); - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - produces > >(); - produces("PFTauPrimaryVertices"); - - vertexAssociator_.reset(new tau::RecoTauVertexAssociator(qualityCutsPSet_,consumesCollector())); -} +PFTauPrimaryVertexProducer::PFTauPrimaryVertexProducer(const edm::ParameterSet& iConfig): + PFTauPrimaryVertexProducerBase::PFTauPrimaryVertexProducerBase(iConfig) {} PFTauPrimaryVertexProducer::~PFTauPrimaryVertexProducer(){} -void PFTauPrimaryVertexProducer::produce(edm::Event& iEvent,const edm::EventSetup& iSetup){ - // Obtain Collections - edm::ESHandle transTrackBuilder; - iSetup.get().get("TransientTrackBuilder",transTrackBuilder); - - edm::Handle > Tau; - iEvent.getByToken(PFTauToken_,Tau); - - edm::Handle > Electron; - iEvent.getByToken(ElectronToken_,Electron); - - edm::Handle > Mu; - iEvent.getByToken(MuonToken_,Mu); - - edm::Handle PV; - iEvent.getByToken(PVToken_,PV); - - edm::Handle beamSpot; - iEvent.getByToken(beamSpotToken_,beamSpot); - - // Set Association Map - auto AVPFTauPV = std::make_unique>>(PFTauRefProd(Tau)); - auto VertexCollection_out = std::make_unique(); - reco::VertexRefProd VertexRefProd_out = iEvent.getRefBeforePut("PFTauPrimaryVertices"); - - // Load each discriminator - for(auto& disc : discriminators_) { - edm::Handle discr; - iEvent.getByToken(disc->inputToken_, discr); - disc->discr_ = &(*discr); - } - - // Set event for VerexAssociator if needed - if(useInputPV==Algorithm_) - vertexAssociator_->setEvent(iEvent); - - // For each Tau Run Algorithim - if(Tau.isValid()){ - for(reco::PFTauCollection::size_type iPFTau = 0; iPFTau < Tau->size(); iPFTau++) { - reco::PFTauRef tau(Tau, iPFTau); - reco::Vertex thePV; - if(useInputPV==Algorithm_){ - thePV =(*( vertexAssociator_->associatedVertex(*tau))); - } - else if(useFontPV==Algorithm_){ - thePV=PV->front(); +void PFTauPrimaryVertexProducer::nonTauTracksInPV(const reco::VertexRef &thePVRef, + const std::vector > &tauTracks, + std::vector &nonTauTracks){ + + //Find non-tau tracks associated to thePV + for(reco::Vertex::trackRef_iterator vtxTrkRef=thePVRef->tracks_begin();vtxTrkRef!=thePVRef->tracks_end();vtxTrkRef++){ + bool matched = false; + for(const auto& tauTrack : tauTracks){ + if (tauTrack.id() == vtxTrkRef->id() && tauTrack.key() == vtxTrkRef->key()) { + matched = true; + break; } - /////////////////////// - // Check if it passed all the discrimiantors - bool passed(true); - for(auto const& disc : discriminators_) { - // Check this discriminator passes - bool passedDisc = true; - if ( disc->cutFormula_ )passedDisc = (disc->cutFormula_->Eval((*disc->discr_)[tau]) > 0.5); - else passedDisc = ((*disc->discr_)[tau] > disc->cut_); - if ( !passedDisc ){passed = false; break;} - } - if (passed && cut_.get()){passed = (*cut_)(*tau);} - if (passed){ - std::vector SignalTracks; - for(reco::PFTauCollection::size_type jPFTau = 0; jPFTau < Tau->size(); jPFTau++) { - if(useSelectedTaus_ || iPFTau==jPFTau){ - reco::PFTauRef RefPFTau(Tau, jPFTau); - /////////////////////////////////////////////////////////////////////////////////////////////// - // Get tracks from PFTau daugthers - const std::vector > cands = RefPFTau->signalPFChargedHadrCands(); - for (std::vector >::const_iterator iter = cands.begin(); iter!=cands.end(); iter++){ - if(iter->get()->trackRef().isNonnull()) SignalTracks.push_back(reco::TrackBaseRef(iter->get()->trackRef())); - else if(iter->get()->gsfTrackRef().isNonnull()){SignalTracks.push_back(reco::TrackBaseRef(((iter)->get()->gsfTrackRef())));} - } - } - } - // Get Muon tracks - if(RemoveMuonTracks_){ - - if(Mu.isValid()) { - for(reco::MuonCollection::size_type iMuon = 0; iMuon< Mu->size(); iMuon++){ - reco::MuonRef RefMuon(Mu, iMuon); - if(RefMuon->track().isNonnull()) SignalTracks.push_back(reco::TrackBaseRef(RefMuon->track())); - } - } - } - // Get Electron Tracks - if(RemoveElectronTracks_){ - if(Electron.isValid()) { - for(reco::ElectronCollection::size_type iElectron = 0; iElectronsize(); iElectron++){ - reco::ElectronRef RefElectron(Electron, iElectron); - if(RefElectron->track().isNonnull()) SignalTracks.push_back(reco::TrackBaseRef(RefElectron->track())); - } - } - } - /////////////////////////////////////////////////////////////////////////////////////////////// - // Get Non-Tau tracks - reco::TrackCollection nonTauTracks; - for(std::vector::const_iterator vtxTrkRef=thePV.tracks_begin();vtxTrkRef transTracks; - for (reco::TrackCollection::iterator iter=nonTauTracks.begin(); iter!=nonTauTracks.end(); ++iter){ - transTracks.push_back(transTrackBuilder->build(*iter)); - } - bool FitOk(true); - if ( transTracks.size() >= 2 ) { - AdaptiveVertexFitter avf; - avf.setWeightThreshold(0.1); //weight per track. allow almost every fit, else --> exception - try { - if ( !useBeamSpot_ ){ - transVtx = avf.vertex(transTracks); - } else { - transVtx = avf.vertex(transTracks, *beamSpot); - } - } catch (...) { - FitOk = false; - } - } else FitOk = false; - if ( FitOk ) thePV = transVtx; - } - VertexRef VRef = reco::VertexRef(VertexRefProd_out, VertexCollection_out->size()); - VertexCollection_out->push_back(thePV); - AVPFTauPV->setValue(iPFTau, VRef); } + if( !matched ) nonTauTracks.push_back((*vtxTrkRef).get()); } - iEvent.put(std::move(VertexCollection_out),"PFTauPrimaryVertices"); - iEvent.put(std::move(AVPFTauPV)); } void PFTauPrimaryVertexProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - // PFTauPrimaryVertexProducer - edm::ParameterSetDescription desc; - - { - edm::ParameterSetDescription vpsd1; - vpsd1.add("discriminator"); - vpsd1.add("selectionCut"); - desc.addVPSet("discriminators", vpsd1); - } - - { - edm::ParameterSetDescription pset_signalQualityCuts; - pset_signalQualityCuts.add("maxDeltaZ", 0.4); - pset_signalQualityCuts.add("minTrackPt", 0.5); - pset_signalQualityCuts.add("minTrackVertexWeight", -1.0); - pset_signalQualityCuts.add("maxTrackChi2", 100.0); - pset_signalQualityCuts.add("minTrackPixelHits", 0); - pset_signalQualityCuts.add("minGammaEt", 1.0); - pset_signalQualityCuts.add("minTrackHits", 3); - pset_signalQualityCuts.add("minNeutralHadronEt", 30.0); - pset_signalQualityCuts.add("maxTransverseImpactParameter", 0.1); - pset_signalQualityCuts.addOptional("useTracksInsteadOfPFHadrons"); - - edm::ParameterSetDescription pset_vxAssocQualityCuts; - pset_vxAssocQualityCuts.add("minTrackPt", 0.5); - pset_vxAssocQualityCuts.add("minTrackVertexWeight", -1.0); - pset_vxAssocQualityCuts.add("maxTrackChi2", 100.0); - pset_vxAssocQualityCuts.add("minTrackPixelHits", 0); - pset_vxAssocQualityCuts.add("minGammaEt", 1.0); - pset_vxAssocQualityCuts.add("minTrackHits", 3); - pset_vxAssocQualityCuts.add("maxTransverseImpactParameter", 0.1); - pset_vxAssocQualityCuts.addOptional("useTracksInsteadOfPFHadrons"); - - edm::ParameterSetDescription pset_isolationQualityCuts; - pset_isolationQualityCuts.add("maxDeltaZ", 0.2); - pset_isolationQualityCuts.add("minTrackPt", 1.0); - pset_isolationQualityCuts.add("minTrackVertexWeight", -1.0); - pset_isolationQualityCuts.add("maxTrackChi2", 100.0); - pset_isolationQualityCuts.add("minTrackPixelHits", 0); - pset_isolationQualityCuts.add("minGammaEt", 1.5); - pset_isolationQualityCuts.add("minTrackHits", 8); - pset_isolationQualityCuts.add("maxTransverseImpactParameter", 0.03); - pset_isolationQualityCuts.addOptional("useTracksInsteadOfPFHadrons"); - - edm::ParameterSetDescription pset_qualityCuts; - pset_qualityCuts.add("signalQualityCuts", pset_signalQualityCuts); - pset_qualityCuts.add("vxAssocQualityCuts", pset_vxAssocQualityCuts); - pset_qualityCuts.add("isolationQualityCuts", pset_isolationQualityCuts); - pset_qualityCuts.add("leadingTrkOrPFCandOption", "leadPFCand"); - pset_qualityCuts.add("pvFindingAlgo", "closestInDeltaZ"); - pset_qualityCuts.add("primaryVertexSrc", edm::InputTag("offlinePrimaryVertices")); - pset_qualityCuts.add("vertexTrackFiltering", false); - pset_qualityCuts.add("recoverLeadingTrk", false); - - desc.add("qualityCuts", pset_qualityCuts); - } - - desc.add("cut", "pt > 18.0 & abs(eta)<2.3"); - desc.add("Algorithm", 0); - desc.add("RemoveElectronTracks", false); - desc.add("RemoveMuonTracks", false); - desc.add("useBeamSpot", true); - desc.add("useSelectedTaus", false); - desc.add("beamSpot", edm::InputTag("offlineBeamSpot")); - desc.add("ElectronTag", edm::InputTag("MyElectrons")); - desc.add("PFTauTag", edm::InputTag("hpsPFTauProducer")); - desc.add("MuonTag", edm::InputTag("MyMuons")); - desc.add("PVTag", edm::InputTag("offlinePrimaryVertices")); - - descriptions.add("PFTauPrimaryVertexProducer", desc); + auto desc = PFTauPrimaryVertexProducerBase::getDescriptionsBase(); + descriptions.add("pfTauPrimaryVertexProducer", desc); } DEFINE_FWK_MODULE(PFTauPrimaryVertexProducer); diff --git a/RecoTauTag/RecoTau/plugins/PFTauSecondaryVertexProducer.cc b/RecoTauTag/RecoTau/plugins/PFTauSecondaryVertexProducer.cc index 57d216146a9a0..e0ab1bc5764fb 100644 --- a/RecoTauTag/RecoTau/plugins/PFTauSecondaryVertexProducer.cc +++ b/RecoTauTag/RecoTau/plugins/PFTauSecondaryVertexProducer.cc @@ -39,6 +39,7 @@ #include "DataFormats/GsfTrackReco/interface/GsfTrack.h" #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h" #include "DataFormats/Common/interface/RefToBase.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" #include "DataFormats/Common/interface/Association.h" #include "DataFormats/Common/interface/AssociationVector.h" @@ -76,6 +77,21 @@ PFTauSecondaryVertexProducer::~PFTauSecondaryVertexProducer(){ } +namespace { + const reco::Track* getTrack(const reco::Candidate& cand) { + const reco::PFCandidate* pfCand = dynamic_cast(&cand); + if (pfCand != nullptr) { + if (pfCand->trackRef().isNonnull()) + return &*pfCand->trackRef(); + else if (pfCand->gsfTrackRef().isNonnull()) + return &*pfCand->gsfTrackRef(); + } + const pat::PackedCandidate* pCand = dynamic_cast(&cand); + if (pCand != nullptr && pCand->hasTrackDetails()) + return &pCand->pseudoTrack(); + return nullptr; + } +} void PFTauSecondaryVertexProducer::produce(edm::StreamID, edm::Event& iEvent,const edm::EventSetup& iSetup) const { // Obtain edm::ESHandle transTrackBuilder; @@ -99,21 +115,19 @@ void PFTauSecondaryVertexProducer::produce(edm::StreamID, edm::Event& iEvent,con // Get tracks form PFTau daugthers std::vector transTrk; TransientVertex transVtx; - const std::vector > cands = RefPFTau->signalPFChargedHadrCands(); - for (std::vector >::const_iterator iter = cands.begin(); iter!=cands.end(); ++iter) { - if(iter->get()->trackRef().isNonnull())transTrk.push_back(transTrackBuilder->build(iter->get()->trackRef())); - else if(iter->get()->gsfTrackRef().isNonnull())transTrk.push_back(transTrackBuilder->build(iter->get()->gsfTrackRef())); + const std::vector > cands = RefPFTau->signalChargedHadrCands(); + for (const auto& cand : cands) { + if (cand.isNull()) continue; + const reco::Track* track = getTrack(*cand); + if (track != nullptr) + transTrk.push_back(transTrackBuilder->build(*track)); } /////////////////////////////////////////////////////////////////////////////////////////////// // Fit the secondary vertex bool FitOk(true); KalmanVertexFitter kvf(true); if(transTrk.size() > 1) { - try{ - transVtx = kvf.vertex(transTrk); //KalmanVertexFitter - }catch(...){ - FitOk=false; - } + transVtx = kvf.vertex(transTrk); //KalmanVertexFitter } else { FitOk = false; } diff --git a/RecoTauTag/RecoTau/plugins/PFTauTransverseImpactParameters.cc b/RecoTauTag/RecoTau/plugins/PFTauTransverseImpactParameters.cc index e02f78b438abe..ac5a1886fcc32 100644 --- a/RecoTauTag/RecoTau/plugins/PFTauTransverseImpactParameters.cc +++ b/RecoTauTag/RecoTau/plugins/PFTauTransverseImpactParameters.cc @@ -39,6 +39,7 @@ #include "DataFormats/TrackReco/interface/TrackFwd.h" #include "DataFormats/TauReco/interface/PFTauTransverseImpactParameter.h" #include "DataFormats/TauReco/interface/PFTauTransverseImpactParameterFwd.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" #include "DataFormats/Common/interface/Association.h" #include "DataFormats/Common/interface/AssociationVector.h" @@ -80,6 +81,23 @@ PFTauTransverseImpactParameters::~PFTauTransverseImpactParameters(){ } +namespace { + inline const reco::Track* getTrack(const Candidate& cand) + { + const PFCandidate* pfCandPtr = dynamic_cast(&cand); + if (pfCandPtr != nullptr) { + if ( pfCandPtr->trackRef().isNonnull() ) return pfCandPtr->trackRef().get(); + else if ( pfCandPtr->gsfTrackRef().isNonnull() ) return pfCandPtr->gsfTrackRef().get(); + else return nullptr; + } + const pat::PackedCandidate* packedCand = dynamic_cast(&cand); + if (packedCand != nullptr && packedCand->hasTrackDetails()) + return &packedCand->pseudoTrack(); + + return nullptr; + } +} + void PFTauTransverseImpactParameters::produce(edm::Event& iEvent,const edm::EventSetup& iSetup){ // Obtain Collections edm::ESHandle transTrackBuilder; @@ -109,12 +127,8 @@ void PFTauTransverseImpactParameters::produce(edm::Event& iEvent,const edm::Even reco::Vertex::Point poca(0,0,0); double ip3d(-999), ip3d_err(-999); reco::Vertex::Point ip3d_poca(0,0,0); - if(RefPFTau->leadPFChargedHadrCand().isNonnull()){ - const reco::Track* track = nullptr; - if(RefPFTau->leadPFChargedHadrCand()->trackRef().isNonnull()) - track = RefPFTau->leadPFChargedHadrCand()->trackRef().get(); - else if(RefPFTau->leadPFChargedHadrCand()->gsfTrackRef().isNonnull()) - track = RefPFTau->leadPFChargedHadrCand()->gsfTrackRef().get(); + if(RefPFTau->leadChargedHadrCand().isNonnull()){ + const reco::Track* track = getTrack(*RefPFTau->leadChargedHadrCand()); if(track != nullptr){ if(useFullCalculation_){ reco::TransientTrack transTrk=transTrackBuilder->build(*track); diff --git a/RecoTauTag/RecoTau/plugins/RecoTauBuilderCombinatoricPlugin.cc b/RecoTauTag/RecoTau/plugins/RecoTauBuilderCombinatoricPlugin.cc index 804420722520e..2038c96ae2208 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauBuilderCombinatoricPlugin.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauBuilderCombinatoricPlugin.cc @@ -32,10 +32,10 @@ class RecoTauBuilderCombinatoricPlugin : public RecoTauBuilderPlugin ~RecoTauBuilderCombinatoricPlugin() override {} return_type operator()( - const reco::PFJetRef&, + const reco::JetBaseRef&, const std::vector&, const std::vector&, - const std::vector&) const override; + const std::vector&) const override; private: RecoTauQualityCuts qcuts_; @@ -166,10 +166,10 @@ namespace RecoTauBuilderCombinatoricPlugin::return_type RecoTauBuilderCombinatoricPlugin::operator()( - const reco::PFJetRef& jet, + const reco::JetBaseRef& jet, const std::vector& chargedHadrons, const std::vector& piZeros, - const std::vector& regionalExtras) const + const std::vector& regionalExtras) const { if ( verbosity_ ) { std::cout << ":" << std::endl; @@ -184,7 +184,7 @@ RecoTauBuilderCombinatoricPlugin::operator()( // the base class. qcuts_.setPV( primaryVertex(jet) ); - typedef std::vector PFCandPtrs; + typedef std::vector CandPtrs; if ( verbosity_ ) { std::cout << "#chargedHadrons = " << chargedHadrons.size() << std::endl; @@ -205,13 +205,13 @@ RecoTauBuilderCombinatoricPlugin::operator()( } } - PFCandPtrs pfchs = qcuts_.filterCandRefs(pfChargedCands(*jet)); - PFCandPtrs pfnhs = qcuts_.filterCandRefs(pfCandidates(*jet, reco::PFCandidate::h0)); - PFCandPtrs pfgammas = qcuts_.filterCandRefs(pfCandidates(*jet, reco::PFCandidate::gamma)); + CandPtrs pfchs = qcuts_.filterCandRefs(pfChargedCands(*jet)); + CandPtrs pfnhs = qcuts_.filterCandRefs(pfCandidatesByPdgId(*jet, 130)); + CandPtrs pfgammas = qcuts_.filterCandRefs(pfCandidatesByPdgId(*jet, 22)); /// Apply quality cuts to the regional junk around the jet. Note that the /// particle contents of the junk is exclusive to the jet content. - PFCandPtrs regionalJunk = qcuts_.filterCandRefs(regionalExtras); + CandPtrs regionalJunk = qcuts_.filterCandRefs(regionalExtras); // Loop over the decay modes we want to build for ( std::vector::const_iterator decayMode = decayModesToBuild_.begin(); @@ -238,7 +238,7 @@ RecoTauBuilderCombinatoricPlugin::operator()( // Build our track combo generator ChargedHadronCombo trackCombos(chargedHadron_begin, chargedHadron_end, tracksToBuild); - PFCandPtrs::iterator pfch_end = pfchs.end(); + CandPtrs::iterator pfch_end = pfchs.end(); pfch_end = takeNElements(pfchs.begin(), pfch_end, decayMode->maxPFCHs_); //------------------------------------------------------- @@ -348,7 +348,7 @@ RecoTauBuilderCombinatoricPlugin::operator()( // Now build isolation collections // Load our isolation tools using namespace reco::tau::cone; - PFCandPtrDRFilter isolationConeFilter(tau.p4(), -0.1, isolationConeSize_); + CandPtrDRFilter isolationConeFilter(tau.p4(), -0.1, isolationConeSize_); // Cross cleaning predicate: Remove any PFCandidatePtrs that are contained within existing ChargedHadrons or PiZeros. // The predicate will return false for any object that overlaps with chargedHadrons or cleanPiZeros. @@ -356,29 +356,29 @@ RecoTauBuilderCombinatoricPlugin::operator()( typedef xclean::CrossCleanPtrs pfChargedHadronXCleanerType; pfChargedHadronXCleanerType pfChargedHadronXCleaner_comboChargedHadrons(trackCombo->combo_begin(), trackCombo->combo_end()); // And this cleaning filter predicate with our Iso cone filter - xclean::PredicateAND pfCandFilter_comboChargedHadrons(isolationConeFilter, pfChargedHadronXCleaner_comboChargedHadrons); + xclean::PredicateAND pfCandFilter_comboChargedHadrons(isolationConeFilter, pfChargedHadronXCleaner_comboChargedHadrons); // 2.) to select neutral PFCandidates within jet xclean::CrossCleanPtrs pfChargedHadronXCleaner_allChargedHadrons(chargedHadrons.begin(), chargedHadrons.end()); xclean::CrossCleanPtrs piZeroXCleaner(piZeros.begin(), piZeros.end()); typedef xclean::PredicateAND, xclean::CrossCleanPtrs > pfCandXCleanerType; pfCandXCleanerType pfCandXCleaner_allChargedHadrons(pfChargedHadronXCleaner_allChargedHadrons, piZeroXCleaner); // And this cleaning filter predicate with our Iso cone filter - xclean::PredicateAND pfCandFilter_allChargedHadrons(isolationConeFilter, pfCandXCleaner_allChargedHadrons); + xclean::PredicateAND pfCandFilter_allChargedHadrons(isolationConeFilter, pfCandXCleaner_allChargedHadrons); ChargedHadronDRFilter isolationConeFilterChargedHadron(tau.p4(), -0.1, isolationConeSize_); PiZeroDRFilter isolationConeFilterPiZero(tau.p4(), -0.1, isolationConeSize_); // Additionally make predicates to select the different PF object types // of the regional junk objects to add - typedef xclean::PredicateAND RegionalJunkConeAndIdFilter; - - xclean::FilterPFCandByParticleId - pfchCandSelector(reco::PFCandidate::h); - xclean::FilterPFCandByParticleId - pfgammaCandSelector(reco::PFCandidate::gamma); - xclean::FilterPFCandByParticleId - pfnhCandSelector(reco::PFCandidate::h0); + typedef xclean::PredicateAND RegionalJunkConeAndIdFilter; + + xclean::FilterCandByAbsPdgId + pfchCandSelector(211); + xclean::FilterCandByAbsPdgId + pfgammaCandSelector(22); + xclean::FilterCandByAbsPdgId + pfnhCandSelector(130); RegionalJunkConeAndIdFilter pfChargedJunk( pfchCandSelector, // select charged stuff from junk diff --git a/RecoTauTag/RecoTau/plugins/RecoTauBuilderConePlugin.cc b/RecoTauTag/RecoTau/plugins/RecoTauBuilderConePlugin.cc index 45a779f69247c..142d37d6a732e 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauBuilderConePlugin.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauBuilderConePlugin.cc @@ -36,10 +36,10 @@ class RecoTauBuilderConePlugin : public RecoTauBuilderPlugin { explicit RecoTauBuilderConePlugin(const edm::ParameterSet& pset,edm::ConsumesCollector &&iC); ~RecoTauBuilderConePlugin() override {} // Build a tau from a jet - return_type operator()(const reco::PFJetRef& jet, + return_type operator()(const reco::JetBaseRef& jet, const std::vector& chargedHadrons, const std::vector& piZeros, - const std::vector& regionalExtras) const override; + const std::vector& regionalExtras) const override; private: RecoTauQualityCuts qcuts_; @@ -48,7 +48,7 @@ class RecoTauBuilderConePlugin : public RecoTauBuilderPlugin { double leadObjecPtThreshold_; /* String function to extract values from PFJets */ - typedef StringObjectFunction JetFunc; + typedef StringObjectFunction JetFunc; // Cone defintions JetFunc matchingCone_; @@ -107,10 +107,10 @@ namespace xclean { // define template specialization for cross-cleaning template<> - inline void CrossCleanPiZeros::initialize(const cone::PFCandPtrDRFilterIter& signalTracksBegin, const cone::PFCandPtrDRFilterIter& signalTracksEnd) + inline void CrossCleanPiZeros::initialize(const cone::CandPtrDRFilterIter& signalTracksBegin, const cone::CandPtrDRFilterIter& signalTracksEnd) { // Get the list of objects we need to clean - for ( cone::PFCandPtrDRFilterIter signalTrack = signalTracksBegin; signalTrack != signalTracksEnd; ++signalTrack ) { + for ( cone::CandPtrDRFilterIter signalTrack = signalTracksBegin; signalTrack != signalTracksEnd; ++signalTrack ) { toRemove_.insert(reco::CandidatePtr(*signalTrack)); } } @@ -134,9 +134,9 @@ void RecoTauBuilderConePlugin::setTauQuantities(reco::PFTau& aTau, // Set charge int charge = 0; - int leadCharge = aTau.leadPFChargedHadrCand().isNonnull() ? aTau.leadPFChargedHadrCand()->charge() : 0; - const std::vector& pfChs = aTau.signalPFChargedHadrCands(); - for(const reco::PFCandidatePtr& pfCh : pfChs){ + int leadCharge = aTau.leadChargedHadrCand().isNonnull() ? aTau.leadChargedHadrCand()->charge() : 0; + const std::vector& pfChs = aTau.signalChargedHadrCands(); + for(const reco::CandidatePtr& pfCh : pfChs){ charge += pfCh->charge(); } charge = charge==0 ? leadCharge : charge; @@ -185,10 +185,10 @@ void RecoTauBuilderConePlugin::setTauQuantities(reco::PFTau& aTau, } RecoTauBuilderConePlugin::return_type RecoTauBuilderConePlugin::operator()( - const reco::PFJetRef& jet, + const reco::JetBaseRef& jet, const std::vector& chargedHadrons, const std::vector& piZeros, - const std::vector& regionalExtras) const { + const std::vector& regionalExtras) const { //std::cout << ":" << std::endl; //std::cout << " jet: Pt = " << jet->pt() << ", eta = " << jet->eta() << ", phi = " << jet->phi() << std::endl; @@ -206,12 +206,12 @@ RecoTauBuilderConePlugin::return_type RecoTauBuilderConePlugin::operator()( // Setup our quality cuts to use the current vertex (supplied by base class) qcuts_.setPV(primaryVertex(jet)); - typedef std::vector PFCandPtrs; + typedef std::vector CandPtrs; // Get the PF Charged hadrons + quality cuts - PFCandPtrs pfchs; + CandPtrs pfchs; if (!usePFLeptonsAsChargedHadrons_) { - pfchs = qcuts_.filterCandRefs(pfCandidates(*jet, reco::PFCandidate::h)); + pfchs = qcuts_.filterCandRefs(pfCandidatesByPdgId(*jet, 211)); } else { // Check if we want to include electrons in muons in "charged hadron" // collection. This is the preferred behavior, as the PF lepton selections @@ -223,14 +223,14 @@ RecoTauBuilderConePlugin::return_type RecoTauBuilderConePlugin::operator()( std::sort(pfchs.begin(), pfchs.end(), SortPFCandsDescendingPt()); // Get the PF gammas - PFCandPtrs pfGammas = qcuts_.filterCandRefs( - pfCandidates(*jet, reco::PFCandidate::gamma)); + CandPtrs pfGammas = qcuts_.filterCandRefs( + pfCandidatesByPdgId(*jet, 22)); // Neutral hadrons - PFCandPtrs pfnhs = qcuts_.filterCandRefs( - pfCandidates(*jet, reco::PFCandidate::h0)); + CandPtrs pfnhs = qcuts_.filterCandRefs( + pfCandidatesByPdgId(*jet, 130)); // All the extra junk - PFCandPtrs regionalJunk = qcuts_.filterCandRefs(regionalExtras); + CandPtrs regionalJunk = qcuts_.filterCandRefs(regionalExtras); /*********************************************** ****** Lead Candidate Finding ********** @@ -238,19 +238,19 @@ RecoTauBuilderConePlugin::return_type RecoTauBuilderConePlugin::operator()( // Define our matching cone and filters double matchingCone = matchingCone_(*jet); - PFCandPtrDRFilter matchingConeFilter(jet->p4(), 0, matchingCone); + CandPtrDRFilter matchingConeFilter(jet->p4(), 0, matchingCone); // Find the maximum PFCharged hadron in the matching cone. The call to // PFCandidates always a sorted list, so we can just take the first if it // if it exists. - PFCandidatePtr leadPFCH; - PFCandPtrs::iterator leadPFCH_iter = + CandidatePtr leadPFCH; + CandPtrs::iterator leadPFCH_iter = std::find_if(pfchs.begin(), pfchs.end(), matchingConeFilter); if (leadPFCH_iter != pfchs.end()) { leadPFCH = *leadPFCH_iter; // Set leading candidate - tau.setleadPFChargedHadrCand(leadPFCH); + tau.setleadChargedHadrCand(leadPFCH); } else { // If there is no leading charged candidate at all, return nothing - the // producer class that owns the plugin will build a null tau if desired. @@ -258,17 +258,17 @@ RecoTauBuilderConePlugin::return_type RecoTauBuilderConePlugin::operator()( } // Find the leading neutral candidate - PFCandidatePtr leadPFGamma; - PFCandPtrs::iterator leadPFGamma_iter = + CandidatePtr leadPFGamma; + CandPtrs::iterator leadPFGamma_iter = std::find_if(pfGammas.begin(), pfGammas.end(), matchingConeFilter); if (leadPFGamma_iter != pfGammas.end()) { leadPFGamma = *leadPFGamma_iter; // Set leading neutral candidate - tau.setleadPFNeutralCand(leadPFGamma); + tau.setleadNeutralCand(leadPFGamma); } - PFCandidatePtr leadPFCand; + CandidatePtr leadPFCand; // Always use the leadPFCH if it is above our threshold if (leadPFCH.isNonnull() && leadPFCH->pt() > leadObjecPtThreshold_) { leadPFCand = leadPFCH; @@ -281,7 +281,7 @@ RecoTauBuilderConePlugin::return_type RecoTauBuilderConePlugin::operator()( leadPFCand = leadPFCH; } - tau.setleadPFCand(leadPFCand); + tau.setleadCand(leadPFCand); // Our cone axis is defined about the lead charged hadron reco::Candidate::LorentzVector coneAxis = leadPFCH->p4(); @@ -293,29 +293,29 @@ RecoTauBuilderConePlugin::return_type RecoTauBuilderConePlugin::operator()( // Define the signal and isolation cone sizes for this jet and build filters // to select elements in the given DeltaR regions - PFCandPtrDRFilter signalConePFCHFilter( + CandPtrDRFilter signalConePFCHFilter( coneAxis, -0.1, signalConeChargedHadrons_(*jet)); - PFCandPtrDRFilter signalConePFNHFilter( + CandPtrDRFilter signalConePFNHFilter( coneAxis, -0.1, signalConeNeutralHadrons_(*jet)); PiZeroDRFilter signalConePiZeroFilter( coneAxis, -0.1, signalConePiZeros_(*jet)); - PFCandPtrDRFilter isoConePFCHFilter( + CandPtrDRFilter isoConePFCHFilter( coneAxis, signalConeChargedHadrons_(*jet), isoConeChargedHadrons_(*jet)); - PFCandPtrDRFilter isoConePFGammaFilter( + CandPtrDRFilter isoConePFGammaFilter( coneAxis, signalConePiZeros_(*jet), isoConePiZeros_(*jet)); - PFCandPtrDRFilter isoConePFNHFilter( + CandPtrDRFilter isoConePFNHFilter( coneAxis, signalConeNeutralHadrons_(*jet), isoConeNeutralHadrons_(*jet)); PiZeroDRFilter isoConePiZeroFilter( coneAxis, signalConePiZeros_(*jet), isoConePiZeros_(*jet)); // Additionally make predicates to select the different PF object types // of the regional junk objects to add to the iso cone. - typedef xclean::PredicateAND RegionalJunkConeAndIdFilter; + typedef xclean::PredicateAND RegionalJunkConeAndIdFilter; - xclean::FilterPFCandByParticleId pfchCandSelector(reco::PFCandidate::h); - xclean::FilterPFCandByParticleId pfgammaCandSelector(reco::PFCandidate::gamma); - xclean::FilterPFCandByParticleId pfnhCandSelector(reco::PFCandidate::h0); + xclean::FilterCandByAbsPdgId pfchCandSelector(211); + xclean::FilterCandByAbsPdgId pfgammaCandSelector(22); + xclean::FilterCandByAbsPdgId pfnhCandSelector(130); // Predicate to select the regional junk in the iso cone by PF id RegionalJunkConeAndIdFilter pfChargedJunk( @@ -334,15 +334,15 @@ RecoTauBuilderConePlugin::return_type RecoTauBuilderConePlugin::operator()( ); // Build filter iterators select the signal charged stuff. - PFCandPtrDRFilterIter signalPFCHCands_begin( + CandPtrDRFilterIter signalPFCHCands_begin( signalConePFCHFilter, pfchs.begin(), pfchs.end()); - PFCandPtrDRFilterIter signalPFCHCands_end( + CandPtrDRFilterIter signalPFCHCands_end( signalConePFCHFilter, pfchs.end(), pfchs.end()); - PFCandPtrs signalPFCHs; + CandPtrs signalPFCHs; int numSignalPFCHs = 0; - PFCandPtrs isolationPFCHs; + CandPtrs isolationPFCHs; int numIsolationPFCHs = 0; - for ( PFCandPtrDRFilterIter iter = signalPFCHCands_begin; iter != signalPFCHCands_end; ++iter ) { + for ( CandPtrDRFilterIter iter = signalPFCHCands_begin; iter != signalPFCHCands_end; ++iter ) { if ( numSignalPFCHs < maxSignalConeChargedHadrons_ || maxSignalConeChargedHadrons_ == -1 ) { //std::cout << "adding signalPFCH #" << numSignalPFCHs << ": Pt = " << (*iter)->pt() << ", eta = " << (*iter)->eta() << ", phi = " << (*iter)->phi() << std::endl; signalPFCHs.push_back(*iter); @@ -354,11 +354,11 @@ RecoTauBuilderConePlugin::return_type RecoTauBuilderConePlugin::operator()( ++numIsolationPFCHs; } } - PFCandPtrs::const_iterator signalPFCHs_begin = signalPFCHs.begin(); - PFCandPtrs::const_iterator signalPFCHs_end = signalPFCHs.end(); + CandPtrs::const_iterator signalPFCHs_begin = signalPFCHs.begin(); + CandPtrs::const_iterator signalPFCHs_end = signalPFCHs.end(); // Cross clean pi zero content using signal cone charged hadron constituents. - xclean::CrossCleanPiZeros piZeroXCleaner( + xclean::CrossCleanPiZeros piZeroXCleaner( signalPFCHCands_begin, signalPFCHCands_end); std::vector cleanPiZeros = piZeroXCleaner(piZeros); @@ -379,8 +379,8 @@ RecoTauBuilderConePlugin::return_type RecoTauBuilderConePlugin::operator()( isolationPFCHs.push_back(*iter); ++numIsolationPFCHs; } - PFCandPtrs::const_iterator isolationPFCHs_begin = isolationPFCHs.begin(); - PFCandPtrs::const_iterator isolationPFCHs_end = isolationPFCHs.end(); + CandPtrs::const_iterator isolationPFCHs_begin = isolationPFCHs.begin(); + CandPtrs::const_iterator isolationPFCHs_end = isolationPFCHs.end(); // Build signal charged hadrons tau.addPFCands(RecoTauConstructor::kSignal, diff --git a/RecoTauTag/RecoTau/plugins/RecoTauCleaner.cc b/RecoTauTag/RecoTau/plugins/RecoTauCleaner.cc index 36b76617a2b40..943b36be75e69 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauCleaner.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauCleaner.cc @@ -180,13 +180,13 @@ namespace const reco::RecoTauPiZero& piZero = signalPiZeroCandidates.at(iPiZero); std::cout << " piZero #" << iPiZero << ": Pt = " << piZero.pt() << ", eta = " << piZero.eta() << ", phi = " << piZero.phi() << ", mass = " << piZero.mass() << std::endl; } - const std::vector& isolationPFCands = tauRef_->isolationPFCands(); - size_t numPFCands = isolationPFCands.size(); - std::cout << "isolationPFCands = " << numPFCands << std::endl; - for ( size_t iPFCand = 0; iPFCand < numPFCands; ++iPFCand ) { - const reco::PFCandidatePtr& pfCand = isolationPFCands.at(iPFCand); - std::cout << " pfCand #" << iPFCand << " (" << pfCand.id() << ":" << pfCand.key() << "):" - << " Pt = " << pfCand->pt() << ", eta = " << pfCand->eta() << ", phi = " << pfCand->phi() << std::endl; + const auto& isolationCands = tauRef_->isolationCands(); + size_t numCands = isolationCands.size(); + std::cout << "isolationCands = " << numCands << std::endl; + for ( size_t iCand = 0; iCand < numCands; ++iCand ) { + const auto& cand = isolationCands.at(iCand); + std::cout << " pfCand #" << iCand << " (" << cand.id() << ":" << cand.key() << "):" + << " Pt = " << cand->pt() << ", eta = " << cand->eta() << ", phi = " << cand->phi() << std::endl; } std::cout << " ranks = " << format_vT(ranks_) << std::endl; std::cout << " tolerances = " << format_vT(tolerances_) << std::endl; diff --git a/RecoTauTag/RecoTau/plugins/RecoTauDecayModeCutMultiplexer.cc b/RecoTauTag/RecoTau/plugins/RecoTauDecayModeCutMultiplexer.cc index 627d447975cae..3cc59145fdd77 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauDecayModeCutMultiplexer.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauDecayModeCutMultiplexer.cc @@ -53,7 +53,7 @@ double RecoTauDecayModeCutMultiplexer::discriminate(const reco::PFTauRef& tau) const { double disc_result = (*handle_)[tau]; DecayModeCutMap::const_iterator cutIter = - decayModeCuts_.find(std::make_pair(tau->signalPFChargedHadrCands().size(), + decayModeCuts_.find(std::make_pair(tau->signalChargedHadrCands().size(), tau->signalPiZeroCandidates().size())); // Return null if it doesn't exist diff --git a/RecoTauTag/RecoTau/plugins/RecoTauEnergyRecoveryPlugin2.cc b/RecoTauTag/RecoTau/plugins/RecoTauEnergyRecoveryPlugin2.cc index 97995f96e0045..c476cdfd05672 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauEnergyRecoveryPlugin2.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauEnergyRecoveryPlugin2.cc @@ -1,4 +1,4 @@ -/* + /* * ============================================================================= * Filename: RecoTauEnergyRecoveryPlugin2.cc * @@ -63,8 +63,8 @@ void RecoTauEnergyRecoveryPlugin2::operator()(PFTau& tau) const { reco::Candidate::LorentzVector tauAltP4(0.,0.,0.,0.); - std::vector pfJetConstituents = tau.jetRef()->getPFConstituents(); - for ( std::vector::const_iterator pfJetConstituent = pfJetConstituents.begin(); + std::vector pfJetConstituents = tau.jetRef()->getJetConstituents(); + for ( std::vector::const_iterator pfJetConstituent = pfJetConstituents.begin(); pfJetConstituent != pfJetConstituents.end(); ++pfJetConstituent ) { double dR = deltaR((*pfJetConstituent)->p4(), tau.p4()); if ( dR < dRcone_ ) tauAltP4 += (*pfJetConstituent)->p4(); diff --git a/RecoTauTag/RecoTau/plugins/RecoTauJetRegionProducer.cc b/RecoTauTag/RecoTau/plugins/RecoTauGenericJetRegionProducer.cc similarity index 59% rename from RecoTauTag/RecoTau/plugins/RecoTauJetRegionProducer.cc rename to RecoTauTag/RecoTau/plugins/RecoTauGenericJetRegionProducer.cc index b17b03dc2bbe4..458d1e17ffe86 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauJetRegionProducer.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauGenericJetRegionProducer.cc @@ -1,8 +1,8 @@ /* * RecoTauJetRegionProducer * - * Given a set of PFJets, make new jets with the same p4 but collect all the - * PFCandidates from a cone of a given size into the constituents. + * Given a set of Jets, make new jets with the same p4 but collect all the + * particle-flow candidates from a cone of a given size into the constituents. * * Author: Evan K. Friis, UC Davis * @@ -11,9 +11,11 @@ #include #include "DataFormats/JetReco/interface/PFJet.h" +#include "DataFormats/PatCandidates/interface/Jet.h" #include "DataFormats/Common/interface/Association.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" #include "DataFormats/Common/interface/AssociationMap.h" #include "RecoTauTag/RecoTau/interface/ConeTools.h" @@ -23,6 +25,7 @@ #include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/makeRefToBaseProdFrom.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" @@ -32,17 +35,19 @@ #include #include -class RecoTauJetRegionProducer : public edm::stream::EDProducer<> +template +class RecoTauGenericJetRegionProducer : public edm::stream::EDProducer<> { public: - typedef edm::Association PFJetMatchMap; - typedef edm::AssociationMap, std::vector, unsigned int> > JetToPFCandidateAssociation; - explicit RecoTauJetRegionProducer(const edm::ParameterSet& pset); - ~RecoTauJetRegionProducer() override {} + typedef edm::AssociationMap > JetMatchMap; + typedef edm::AssociationMap, std::vector, unsigned int> > JetToCandidateAssociation; + explicit RecoTauGenericJetRegionProducer(const edm::ParameterSet& pset); + ~RecoTauGenericJetRegionProducer() override {} void produce(edm::Event& evt, const edm::EventSetup& es) override; static void fillDescriptions(edm::ConfigurationDescriptions & descriptions); + static void fillDescriptionsBase(edm::ConfigurationDescriptions & descriptions, const std::string& name); private: std::string moduleLabel_; @@ -51,9 +56,9 @@ class RecoTauJetRegionProducer : public edm::stream::EDProducer<> edm::InputTag pfCandSrc_; edm::InputTag pfCandAssocMapSrc_; - edm::EDGetTokenT pf_token; + edm::EDGetTokenT > pf_token; edm::EDGetTokenT Jets_token; - edm::EDGetTokenT pfCandAssocMap_token; + edm::EDGetTokenT pfCandAssocMap_token; double minJetPt_; double maxJetAbsEta_; @@ -62,16 +67,17 @@ class RecoTauJetRegionProducer : public edm::stream::EDProducer<> int verbosity_; }; -RecoTauJetRegionProducer::RecoTauJetRegionProducer(const edm::ParameterSet& cfg) +template +RecoTauGenericJetRegionProducer::RecoTauGenericJetRegionProducer(const edm::ParameterSet& cfg) : moduleLabel_(cfg.getParameter("@module_label")) { inputJets_ = cfg.getParameter("src"); pfCandSrc_ = cfg.getParameter("pfCandSrc"); pfCandAssocMapSrc_ = cfg.getParameter("pfCandAssocMapSrc"); - pf_token = consumes(pfCandSrc_); + pf_token = consumes >(pfCandSrc_); Jets_token = consumes(inputJets_); - pfCandAssocMap_token = consumes(pfCandAssocMapSrc_); + pfCandAssocMap_token = consumes(pfCandAssocMapSrc_); double deltaR = cfg.getParameter("deltaR"); deltaR2_ = deltaR*deltaR; @@ -80,11 +86,12 @@ RecoTauJetRegionProducer::RecoTauJetRegionProducer(const edm::ParameterSet& cfg) verbosity_ = cfg.getParameter("verbosity"); - produces("jets"); - produces(); + produces >("jets"); + produces(); } -void RecoTauJetRegionProducer::produce(edm::Event& evt, const edm::EventSetup& es) +template +void RecoTauGenericJetRegionProducer::produce(edm::Event& evt, const edm::EventSetup& es) { if ( verbosity_ ) { std::cout << ":" << std::endl; @@ -93,34 +100,34 @@ void RecoTauJetRegionProducer::produce(edm::Event& evt, const edm::EventSetup& e std::cout << " pfCandAssocMapSrc_ = " << pfCandAssocMapSrc_ << std::endl; } - edm::Handle pfCandsHandle; + edm::Handle > pfCandsHandle; evt.getByToken(pf_token, pfCandsHandle); // Build Ptrs for all the PFCandidates - typedef edm::Ptr PFCandPtr; - std::vector pfCands; + typedef edm::Ptr CandPtr; + std::vector pfCands; pfCands.reserve(pfCandsHandle->size()); for ( size_t icand = 0; icand < pfCandsHandle->size(); ++icand ) { - pfCands.push_back(PFCandPtr(pfCandsHandle, icand)); + pfCands.push_back(CandPtr(pfCandsHandle, icand)); } // Get the jets edm::Handle jetView; evt.getByToken(Jets_token, jetView); - // Convert to a vector of PFJetRefs - reco::PFJetRefVector jets = reco::tau::castView(jetView); + // Convert to a vector of JetRefs + edm::RefVector > jets = reco::tau::castView > >(jetView); size_t nJets = jets.size(); - // Get the association map matching jets to PFCandidates + // Get the association map matching jets to Candidates // (needed for reconstruction of boosted taus) - edm::Handle jetToPFCandMap; + edm::Handle jetToPFCandMap; std::vector > fastJetToPFCandMap; if ( !pfCandAssocMapSrc_.label().empty() ) { evt.getByToken(pfCandAssocMap_token, jetToPFCandMap); fastJetToPFCandMap.resize(nJets); for ( size_t ijet = 0; ijet < nJets; ++ijet ) { // Get a ref to jet - const reco::PFJetRef& jetRef = jets[ijet]; + const edm::Ref >& jetRef = jets[ijet]; const auto& pfCandsMappedToJet = (*jetToPFCandMap)[jetRef]; for ( const auto& pfCandMappedToJet : pfCandsMappedToJet ) { fastJetToPFCandMap[ijet].emplace(pfCandMappedToJet.key()); @@ -131,7 +138,7 @@ void RecoTauJetRegionProducer::produce(edm::Event& evt, const edm::EventSetup& e // Get the original product, so we can match against it - otherwise the // indices don't match up. edm::ProductID originalId = jets.id(); - edm::Handle originalJets; + edm::Handle > originalJets; size_t nOriginalJets = 0; // We have to make sure that we have some selected jets, otherwise we don't // actually have a valid product ID to the original jets. @@ -148,7 +155,7 @@ void RecoTauJetRegionProducer::produce(edm::Event& evt, const edm::EventSetup& e nOriginalJets = originalJets->size(); } - auto newJets = std::make_unique(); + auto newJets = std::make_unique >(); // Keep track of the indices of the current jet and the old (original) jet // -1 indicates no match. @@ -157,12 +164,12 @@ void RecoTauJetRegionProducer::produce(edm::Event& evt, const edm::EventSetup& e size_t nNewJets = 0; for ( size_t ijet = 0; ijet < nJets; ++ijet ) { // Get a ref to jet - const reco::PFJetRef& jetRef = jets[ijet]; + const edm::Ref >& jetRef = jets[ijet]; if(jetRef->pt() - minJetPt_ < 1e-5) continue; if(std::abs(jetRef->eta()) - maxJetAbsEta_ > -1e-5) continue; // Make an initial copy. newJets->emplace_back(*jetRef); - reco::PFJet& newJet = newJets->back(); + JetType& newJet = newJets->back(); // Clear out all the constituents newJet.clearDaughters(); // Loop over all the PFCands @@ -183,11 +190,11 @@ void RecoTauJetRegionProducer::produce(edm::Event& evt, const edm::EventSetup& e if ( verbosity_ ) { std::cout << "jet #" << ijet << ": Pt = " << jetRef->pt() << ", eta = " << jetRef->eta() << ", phi = " << jetRef->eta() << "," << " mass = " << jetRef->mass() << ", area = " << jetRef->jetArea() << std::endl; - std::vector jetConstituents = newJet.getPFConstituents(); + auto jetConstituents = newJet.daughterPtrVector(); int idx = 0; - for ( std::vector::const_iterator jetConstituent = jetConstituents.begin(); - jetConstituent != jetConstituents.end(); ++jetConstituent ) { - std::cout << " constituent #" << idx << ": Pt = " << (*jetConstituent)->pt() << ", eta = " << (*jetConstituent)->eta() << ", phi = " << (*jetConstituent)->phi() << std::endl; + for ( const auto& jetConstituent : jetConstituents) { + std::cout << " constituent #" << idx << ": Pt = " << jetConstituent->pt() << ", eta = " << jetConstituent->eta() << ", phi = " << jetConstituent->phi() << std::endl; + ++idx; } } // Match the index of the jet we just made to the index into the original @@ -197,22 +204,21 @@ void RecoTauJetRegionProducer::produce(edm::Event& evt, const edm::EventSetup& e nNewJets++; } - // Put our new jets into the event - edm::OrphanHandle newJetsInEvent = evt.put(std::move(newJets), "jets"); - + // Put our new jets into the event + edm::OrphanHandle > newJetsInEvent = evt.put(std::move(newJets), "jets"); + // Create a matching between original jets -> extra collection - auto matching = std::make_unique(newJetsInEvent); - if ( nJets ) { - PFJetMatchMap::Filler filler(*matching); - filler.insert(originalJets, matchInfo.begin(), matchInfo.end()); - filler.fill(); + auto matching = (nJets !=0) ? std::make_unique(edm::makeRefToBaseProdFrom(edm::RefToBase(jets[0]), evt), newJetsInEvent) : std::make_unique(); + for (size_t ijet = 0; ijet < nJets; ++ijet) { + matching->insert(edm::RefToBase(jets[ijet]), edm::RefToBase(edm::Ref >(newJetsInEvent, matchInfo[ijet]))); } evt.put(std::move(matching)); } +template void -RecoTauJetRegionProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - // RecoTauJetRegionProducer +RecoTauGenericJetRegionProducer::fillDescriptionsBase(edm::ConfigurationDescriptions& descriptions, const std::string& name) { + // RecoTauGenericJetRegionProducer edm::ParameterSetDescription desc; desc.add("src", edm::InputTag("ak4PFJets")); desc.add("deltaR", 0.8); @@ -221,8 +227,28 @@ RecoTauJetRegionProducer::fillDescriptions(edm::ConfigurationDescriptions& descr desc.add("maxJetAbsEta", 2.5); desc.add("minJetPt", 14.0); desc.add("pfCandSrc", edm::InputTag("particleFlow")); - descriptions.add("RecoTauJetRegionProducer", desc); + descriptions.add(name, desc); +} + + +template<> +void +RecoTauGenericJetRegionProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + // RecoTauGenericJetRegionProducer + RecoTauGenericJetRegionProducer::fillDescriptionsBase(descriptions, "RecoTauJetRegionProducer"); + +} + +template<> +void +RecoTauGenericJetRegionProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + // RecoTauGenericJetRegionProducer + RecoTauGenericJetRegionProducer::fillDescriptionsBase(descriptions, "RecoTauPatJetRegionProducer"); } +typedef RecoTauGenericJetRegionProducer RecoTauJetRegionProducer; +typedef RecoTauGenericJetRegionProducer RecoTauPatJetRegionProducer; + #include "FWCore/Framework/interface/MakerMacros.h" DEFINE_FWK_MODULE(RecoTauJetRegionProducer); +DEFINE_FWK_MODULE(RecoTauPatJetRegionProducer); diff --git a/RecoTauTag/RecoTau/plugins/RecoTauImpactParameterSignificancePlugin.cc b/RecoTauTag/RecoTau/plugins/RecoTauImpactParameterSignificancePlugin.cc index 5c2e65843f56d..87f0656bf267d 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauImpactParameterSignificancePlugin.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauImpactParameterSignificancePlugin.cc @@ -14,6 +14,7 @@ #include "RecoTauTag/RecoTau/interface/RecoTauBuilderPlugins.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" #include "DataFormats/VertexReco/interface/Vertex.h" #include "DataFormats/VertexReco/interface/VertexFwd.h" @@ -52,11 +53,31 @@ void RecoTauImpactParameterSignificancePlugin::beginEvent() { builder_= myTransientTrackBuilder.product(); } +namespace +{ + inline const reco::Track* getTrack(const Candidate& cand) + { + const PFCandidate* pfCandPtr = dynamic_cast(&cand); + if (pfCandPtr) { + if (pfCandPtr->trackRef().isNonnull()) + return pfCandPtr->trackRef().get(); + else + return nullptr; + } + + const pat::PackedCandidate* packedCand = dynamic_cast(&cand); + if (packedCand && packedCand->hasTrackDetails()) + return &packedCand->pseudoTrack(); + + return nullptr; + } +} + void RecoTauImpactParameterSignificancePlugin::operator()(PFTau& tau) const { // Get the transient lead track - if (tau.leadPFChargedHadrCand().isNonnull()) { - TrackRef leadTrack = tau.leadPFChargedHadrCand()->trackRef(); - if (leadTrack.isNonnull()) { + if (tau.leadChargedHadrCand().isNonnull()) { + const reco::Track* leadTrack = getTrack(*tau.leadChargedHadrCand()); + if (leadTrack != nullptr) { const TransientTrack track = builder_->build(leadTrack); GlobalVector direction(tau.jetRef()->px(), tau.jetRef()->py(), tau.jetRef()->pz()); diff --git a/RecoTauTag/RecoTau/plugins/RecoTauIsolationDiscriminantPlugins.cc b/RecoTauTag/RecoTau/plugins/RecoTauIsolationDiscriminantPlugins.cc index 4dd738a57edf8..1169cb609b4d6 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauIsolationDiscriminantPlugins.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauIsolationDiscriminantPlugins.cc @@ -9,7 +9,7 @@ class RecoTauDiscriminationBinnedIsolationImpl public: RecoTauDiscriminationBinnedIsolationImpl(const edm::ParameterSet& pset) :RecoTauDiscriminationBinnedIsolation(pset),extractor_(pset) {} - std::vector extractIsoObjects( + std::vector extractIsoObjects( const reco::PFTauRef& tau) const override { return extractor_(tau); } @@ -26,16 +26,16 @@ namespace { class TrackExtractor { public: TrackExtractor(const edm::ParameterSet& pset){}; - std::vector operator()(const reco::PFTauRef& tau) const { - return tau->isolationPFChargedHadrCands(); + std::vector operator()(const reco::PFTauRef& tau) const { + return tau->isolationChargedHadrCands(); } }; class ECALExtractor { public: ECALExtractor(const edm::ParameterSet& pset){}; - std::vector operator()(const reco::PFTauRef& tau) const { - return tau->isolationPFGammaCands(); + std::vector operator()(const reco::PFTauRef& tau) const { + return tau->isolationGammaCands(); } }; @@ -43,8 +43,8 @@ class MaskedECALExtractor { public: MaskedECALExtractor(const edm::ParameterSet& pset) :mask_(pset.getParameter("mask")){}; - std::vector operator()(const reco::PFTauRef& tau) const { - std::vector output; + std::vector operator()(const reco::PFTauRef& tau) const { + std::vector output; reco::tau::RecoTauIsolationMasking::IsoMaskResult result = mask_.mask(*tau); output.reserve(result.gammas.size()); @@ -60,8 +60,8 @@ class MaskedECALExtractor { class HCALExtractor { public: HCALExtractor(const edm::ParameterSet& pset){}; - std::vector operator()(const reco::PFTauRef& tau) const { - return tau->isolationPFNeutrHadrCands(); + std::vector operator()(const reco::PFTauRef& tau) const { + return tau->isolationNeutrHadrCands(); } }; @@ -69,8 +69,8 @@ class MaskedHCALExtractor { public: MaskedHCALExtractor(const edm::ParameterSet& pset) :mask_(pset.getParameter("mask")){}; - std::vector operator()(const reco::PFTauRef& tau) const { - std::vector output; + std::vector operator()(const reco::PFTauRef& tau) const { + std::vector output; reco::tau::RecoTauIsolationMasking::IsoMaskResult result = mask_.mask(*tau); output.reserve(result.h0s.size()); diff --git a/RecoTauTag/RecoTau/plugins/RecoTauPhotonFilter.cc b/RecoTauTag/RecoTau/plugins/RecoTauPhotonFilter.cc index e0cb4e156a0fe..2e3cd6d9f38cc 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauPhotonFilter.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauPhotonFilter.cc @@ -53,6 +53,7 @@ bool RecoTauPhotonFilter::filter( const RecoTauPiZero* piZero, return piZero->pt()/total.pt() < minPtFractionSinglePhotons_; } + void RecoTauPhotonFilter::operator()(PFTau& tau) const { std::vector signalPiZeros; for(auto const& piZero : tau.signalPiZeroCandidates()) { @@ -102,7 +103,7 @@ void RecoTauPhotonFilter::operator()(PFTau& tau) const { tau.setisolationPiZeroCandidates(newIsolation); // Now we need to deal with the gamma candidates underlying moved pizeros. - std::vector pfcandsToMove = flattenPiZeros(toMove); + std::vector pfcandsToMove = flattenPiZeros(toMove); // Copy the keys to move std::set keysToMove; @@ -110,30 +111,30 @@ void RecoTauPhotonFilter::operator()(PFTau& tau) const { keysToMove.insert(ptr.key()); } - std::vector newSignalPFGammas; - std::vector newSignalPFCands; - std::vector newIsolationPFGammas = tau.isolationPFGammaCands(); - std::vector newIsolationPFCands = tau.isolationPFCands(); + std::vector newSignalGammas; + std::vector newSignalCands; + std::vector newIsolationGammas = tau.isolationGammaCands(); + std::vector newIsolationCands = tau.isolationCands(); // Move the necessary signal pizeros - what a mess! - for(auto const& ptr : tau.signalPFCands()) { + for(auto const& ptr : tau.signalCands()) { if (keysToMove.count(ptr.key())) - newIsolationPFCands.push_back(ptr); + newIsolationCands.push_back(ptr); else - newSignalPFCands.push_back(ptr); + newSignalCands.push_back(ptr); } - for(auto const& ptr : tau.signalPFGammaCands()) { + for(auto const& ptr : tau.signalGammaCands()) { if (keysToMove.count(ptr.key())) - newIsolationPFGammas.push_back(ptr); + newIsolationGammas.push_back(ptr); else - newSignalPFGammas.push_back(ptr); + newSignalGammas.push_back(ptr); } - tau.setsignalPFCands(newSignalPFCands); - tau.setsignalPFCands(newSignalPFGammas); - tau.setisolationPFGammaCands(newIsolationPFGammas); - tau.setisolationPFCands(newIsolationPFCands); + tau.setsignalCands(newSignalCands); + tau.setsignalCands(newSignalGammas); + tau.setisolationGammaCands(newIsolationGammas); + tau.setisolationCands(newIsolationCands); } } } // end namespace reco::tau diff --git a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroCombinatoricPlugin.cc b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroCombinatoricPlugin.cc index b6d66e079733f..fb64f92e83808 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroCombinatoricPlugin.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroCombinatoricPlugin.cc @@ -13,8 +13,8 @@ #include "RecoTauTag/RecoTau/interface/RecoTauPiZeroPlugins.h" #include "DataFormats/TauReco/interface/RecoTauPiZero.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/Candidate/interface/CandidateFwd.h" +#include "DataFormats/Candidate/interface/Candidate.h" #include "DataFormats/JetReco/interface/PFJet.h" #include "RecoTauTag/RecoTau/interface/RecoTauCommonUtilities.h" @@ -30,7 +30,7 @@ class RecoTauPiZeroCombinatoricPlugin : public RecoTauPiZeroBuilderPlugin { explicit RecoTauPiZeroCombinatoricPlugin(const edm::ParameterSet& pset, edm::ConsumesCollector &&iC); ~RecoTauPiZeroCombinatoricPlugin() override {} // Return type is unique_ptr - return_type operator()(const reco::PFJet& jet) const override; + return_type operator()(const reco::Jet& jet) const override; private: RecoTauQualityCuts qcuts_; @@ -53,26 +53,26 @@ RecoTauPiZeroCombinatoricPlugin::RecoTauPiZeroCombinatoricPlugin( RecoTauPiZeroCombinatoricPlugin::return_type RecoTauPiZeroCombinatoricPlugin::operator()( - const reco::PFJet& jet) const { + const reco::Jet& jet) const { // Get list of gamma candidates - typedef std::vector PFCandPtrs; - typedef PFCandPtrs::const_iterator PFCandIter; + typedef std::vector CandPtrs; + typedef CandPtrs::const_iterator CandIter; PiZeroVector output; - PFCandPtrs pfGammaCands = qcuts_.filterCandRefs(pfGammas(jet)); + CandPtrs pfGammaCands = qcuts_.filterCandRefs(pfGammas(jet)); // Check if we have anything to do... if (pfGammaCands.size() < choose_) return output.release(); // Define the valid range of gammas to use - PFCandIter start_iter = pfGammaCands.begin(); - PFCandIter end_iter = pfGammaCands.end(); + CandIter start_iter = pfGammaCands.begin(); + CandIter end_iter = pfGammaCands.end(); // Only take the desired number of piZeros end_iter = takeNElements(start_iter, end_iter, maxInputGammas_); // Build the combinatoric generator - typedef CombinatoricGenerator ComboGenerator; + typedef CombinatoricGenerator ComboGenerator; ComboGenerator generator(start_iter, end_iter, choose_); // Find all possible combinations diff --git a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroProducer.cc b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroProducer.cc index 65d49a7e81d39..9ce5023d2b4bf 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroProducer.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroProducer.cc @@ -70,7 +70,7 @@ class RecoTauPiZeroProducer : public edm::stream::EDProducer<> { outputSelector_; //consumes interface - edm::EDGetTokenT cand_token; + edm::EDGetTokenT cand_token; double minJetPt_; double maxJetAbsEta_; @@ -80,7 +80,7 @@ class RecoTauPiZeroProducer : public edm::stream::EDProducer<> { RecoTauPiZeroProducer::RecoTauPiZeroProducer(const edm::ParameterSet& pset) { - cand_token = consumes( pset.getParameter("jetSrc")); + cand_token = consumes( pset.getParameter("jetSrc")); minJetPt_ = pset.getParameter("minJetPt"); maxJetAbsEta_ = pset.getParameter("maxJetAbsEta"); @@ -129,7 +129,7 @@ RecoTauPiZeroProducer::RecoTauPiZeroProducer(const edm::ParameterSet& pset) void RecoTauPiZeroProducer::produce(edm::Event& evt, const edm::EventSetup& es) { // Get a view of our jets via the base candidates - edm::Handle jetView; + edm::Handle jetView; evt.getByToken(cand_token, jetView); // Give each of our plugins a chance at doing something with the edm::Event @@ -137,22 +137,15 @@ void RecoTauPiZeroProducer::produce(edm::Event& evt, const edm::EventSetup& es) builder.setup(evt, es); } - // Convert the view to a RefVector of actual PFJets - reco::PFJetRefVector jetRefs = - reco::tau::castView(jetView); // Make our association std::unique_ptr association; - if (!jetRefs.empty()) { - edm::Handle pfJetCollectionHandle; - evt.get(jetRefs.id(), pfJetCollectionHandle); - association = std::make_unique(reco::PFJetRefProd(pfJetCollectionHandle)); - } else { - association = std::make_unique(); - } + association = std::make_unique(reco::JetRefBaseProd(jetView)); // Loop over our jets - for(auto const& jet : jetRefs) { + size_t nJets = jetView->size(); + for (size_t i = 0; i < nJets; ++i) { + const reco::JetBaseRef jet(jetView->refAt(i)); if(jet->pt() - minJetPt_ < 1e-5) continue; if(std::abs(jet->eta()) - maxJetAbsEta_ > -1e-5) continue; diff --git a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin.cc b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin.cc index 9e1eb1b7c08b6..ceae0756dd8b0 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin.cc @@ -16,8 +16,8 @@ #include "RecoTauTag/RecoTau/interface/RecoTauPiZeroPlugins.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/Candidate/interface/CandidateFwd.h" +#include "DataFormats/Candidate/interface/Candidate.h" #include "DataFormats/VertexReco/interface/Vertex.h" #include "DataFormats/VertexReco/interface/VertexFwd.h" #include "DataFormats/TauReco/interface/RecoTauPiZero.h" @@ -48,7 +48,7 @@ class RecoTauPiZeroStripPlugin : public RecoTauPiZeroBuilderPlugin { explicit RecoTauPiZeroStripPlugin(const edm::ParameterSet& pset, edm::ConsumesCollector && iC); ~RecoTauPiZeroStripPlugin() override {} // Return type is unique_ptr - return_type operator()(const reco::PFJet& jet) const override; + return_type operator()(const reco::Jet& jet) const override; // Hook to update PV information void beginEvent() override; @@ -56,7 +56,7 @@ class RecoTauPiZeroStripPlugin : public RecoTauPiZeroBuilderPlugin { RecoTauQualityCuts qcuts_; RecoTauVertexAssociator vertexAssociator_; - std::vector inputPdgIds_; //type of candidates to clusterize + std::vector inputParticleIds_; //type of candidates to clusterize double etaAssociationDistance_;//eta Clustering Association Distance double phiAssociationDistance_;//phi Clustering Association Distance @@ -74,7 +74,7 @@ RecoTauPiZeroStripPlugin::RecoTauPiZeroStripPlugin( qcuts_(pset.getParameterSet( "qualityCuts").getParameterSet("signalQualityCuts")), vertexAssociator_(pset.getParameter("qualityCuts"),std::move(iC)) { - inputPdgIds_ = pset.getParameter >( + inputParticleIds_ = pset.getParameter >( "stripCandidatesParticleIds"); etaAssociationDistance_ = pset.getParameter( "stripEtaAssociationDistance"); @@ -94,26 +94,26 @@ void RecoTauPiZeroStripPlugin::beginEvent() { } RecoTauPiZeroStripPlugin::return_type RecoTauPiZeroStripPlugin::operator()( - const reco::PFJet& jet) const { + const reco::Jet& jet) const { // Get list of gamma candidates - typedef std::vector PFCandPtrs; - typedef PFCandPtrs::iterator PFCandIter; + typedef std::vector CandPtrs; + typedef CandPtrs::iterator CandIter; PiZeroVector output; // Get the candidates passing our quality cuts qcuts_.setPV(vertexAssociator_.associatedVertex(jet)); - PFCandPtrs candsVector = qcuts_.filterCandRefs(pfCandidates(jet, inputPdgIds_)); + CandPtrs candsVector = qcuts_.filterCandRefs(pfCandidates(jet, inputParticleIds_)); //PFCandPtrs candsVector = qcuts_.filterCandRefs(pfGammas(jet)); // Convert to stl::list to allow fast deletions - typedef std::list PFCandPtrList; - typedef std::list::iterator PFCandPtrListIter; - PFCandPtrList cands; + typedef std::list CandPtrList; + typedef std::list::iterator CandPtrListIter; + CandPtrList cands; cands.insert(cands.end(), candsVector.begin(), candsVector.end()); while (!cands.empty()) { // Seed this new strip, and delete it from future strips - PFCandidatePtr seed = cands.front(); + CandidatePtr seed = cands.front(); cands.pop_front(); // Add a new candidate to our collection using this seed @@ -122,7 +122,7 @@ RecoTauPiZeroStripPlugin::return_type RecoTauPiZeroStripPlugin::operator()( strip->addDaughter(seed); // Find all other objects in the strip - PFCandPtrListIter stripCand = cands.begin(); + CandPtrListIter stripCand = cands.begin(); while(stripCand != cands.end()) { if( fabs(strip->eta() - (*stripCand)->eta()) < etaAssociationDistance_ && fabs(deltaPhi(*strip, **stripCand)) < phiAssociationDistance_ ) { diff --git a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin2.cc b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin2.cc index 6a01f7bab70bd..13d72efe10a11 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin2.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin2.cc @@ -18,8 +18,8 @@ #include "RecoTauTag/RecoTau/interface/RecoTauPiZeroPlugins.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/Candidate/interface/CandidateFwd.h" +#include "DataFormats/Candidate/interface/Candidate.h" #include "DataFormats/VertexReco/interface/Vertex.h" #include "DataFormats/VertexReco/interface/VertexFwd.h" #include "DataFormats/TauReco/interface/RecoTauPiZero.h" @@ -56,13 +56,13 @@ class RecoTauPiZeroStripPlugin2 : public RecoTauPiZeroBuilderPlugin explicit RecoTauPiZeroStripPlugin2(const edm::ParameterSet&, edm::ConsumesCollector &&iC); ~RecoTauPiZeroStripPlugin2() override; // Return type is auto_ptr - return_type operator()(const reco::PFJet&) const override; + return_type operator()(const reco::Jet&) const override; // Hook to update PV information void beginEvent() override; private: - typedef std::vector PFCandPtrs; - void addCandsToStrip(RecoTauPiZero&, PFCandPtrs&, const std::vector&, std::set&, bool&) const; + typedef std::vector CandPtrs; + void addCandsToStrip(RecoTauPiZero&, CandPtrs&, const std::vector&, std::set&, bool&) const; RecoTauVertexAssociator vertexAssociator_; @@ -73,7 +73,7 @@ class RecoTauPiZeroStripPlugin2 : public RecoTauPiZeroBuilderPlugin double minStripEt_; - std::vector inputPdgIds_; // type of candidates to clusterize + std::vector inputParticleIds_; // type of candidates to clusterize double etaAssociationDistance_; // size of strip clustering window in eta direction double phiAssociationDistance_; // size of strip clustering window in phi direction @@ -118,7 +118,7 @@ RecoTauPiZeroStripPlugin2::RecoTauPiZeroStripPlugin2(const edm::ParameterSet& ps qcuts_pset.addParameter("minGammaEt", std::min(minGammaEtStripSeed_, minGammaEtStripAdd_)); qcuts_ = new RecoTauQualityCuts(qcuts_pset); - inputPdgIds_ = pset.getParameter >("stripCandidatesParticleIds"); + inputParticleIds_ = pset.getParameter >("stripCandidatesParticleIds"); etaAssociationDistance_ = pset.getParameter("stripEtaAssociationDistance"); phiAssociationDistance_ = pset.getParameter("stripPhiAssociationDistance"); @@ -145,7 +145,7 @@ void RecoTauPiZeroStripPlugin2::beginEvent() vertexAssociator_.setEvent(*evt()); } -void RecoTauPiZeroStripPlugin2::addCandsToStrip(RecoTauPiZero& strip, PFCandPtrs& cands, const std::vector& candFlags, +void RecoTauPiZeroStripPlugin2::addCandsToStrip(RecoTauPiZero& strip, CandPtrs& cands, const std::vector& candFlags, std::set& candIdsCurrentStrip, bool& isCandAdded) const { if ( verbosity_ >= 1 ) { @@ -154,7 +154,7 @@ void RecoTauPiZeroStripPlugin2::addCandsToStrip(RecoTauPiZero& strip, PFCandPtrs size_t numCands = cands.size(); for ( size_t candId = 0; candId < numCands; ++candId ) { if ( (!candFlags[candId]) && candIdsCurrentStrip.find(candId) == candIdsCurrentStrip.end() ) { // do not include same cand twice - reco::PFCandidatePtr cand = cands[candId]; + reco::CandidatePtr cand = cands[candId]; if ( fabs(strip.eta() - cand->eta()) < etaAssociationDistance_ && // check if cand is within eta-phi window centered on strip fabs(strip.phi() - cand->phi()) < phiAssociationDistance_ ) { if ( verbosity_ >= 2 ) { @@ -178,16 +178,21 @@ namespace candFlags[*candId] = true; } } - - inline const reco::TrackBaseRef getTrack(const PFCandidate& cand) + + inline const reco::TrackBaseRef getTrack(const Candidate& cand) { - if ( cand.trackRef().isNonnull() ) return reco::TrackBaseRef(cand.trackRef()); - else if ( cand.gsfTrackRef().isNonnull() ) return reco::TrackBaseRef(cand.gsfTrackRef()); - else return reco::TrackBaseRef(); + const PFCandidate* pfCandPtr = dynamic_cast(&cand); + if (pfCandPtr) { + if ( pfCandPtr->trackRef().isNonnull() ) return reco::TrackBaseRef(pfCandPtr->trackRef()); + else if ( pfCandPtr->gsfTrackRef().isNonnull() ) return reco::TrackBaseRef(pfCandPtr->gsfTrackRef()); + else return reco::TrackBaseRef(); + } + + return reco::TrackBaseRef(); } } -RecoTauPiZeroStripPlugin2::return_type RecoTauPiZeroStripPlugin2::operator()(const reco::PFJet& jet) const +RecoTauPiZeroStripPlugin2::return_type RecoTauPiZeroStripPlugin2::operator()(const reco::Jet& jet) const { if ( verbosity_ >= 1 ) { edm::LogPrint("RecoTauPiZeroStripPlugin2") << ":" ; @@ -200,13 +205,13 @@ RecoTauPiZeroStripPlugin2::return_type RecoTauPiZeroStripPlugin2::operator()(con // Get the candidates passing our quality cuts qcuts_->setPV(vertexAssociator_.associatedVertex(jet)); - PFCandPtrs candsVector = qcuts_->filterCandRefs(pfCandidates(jet, inputPdgIds_)); + CandPtrs candsVector = qcuts_->filterCandRefs(pfCandidates(jet, inputParticleIds_)); // Convert to stl::list to allow fast deletions - PFCandPtrs seedCands; - PFCandPtrs addCands; + CandPtrs seedCands; + CandPtrs addCands; int idx = 0; - for ( PFCandPtrs::iterator cand = candsVector.begin(); + for ( CandPtrs::iterator cand = candsVector.begin(); cand != candsVector.end(); ++cand ) { if ( verbosity_ >= 1 ) { edm::LogPrint("RecoTauPiZeroStripPlugin2") << "PFGamma #" << idx << " (" << cand->id() << ":" << cand->key() << "): Et = " << (*cand)->et() << ", eta = " << (*cand)->eta() << ", phi = " << (*cand)->phi() ; @@ -214,17 +219,13 @@ RecoTauPiZeroStripPlugin2::return_type RecoTauPiZeroStripPlugin2::operator()(con if ( (*cand)->et() > minGammaEtStripSeed_ ) { if ( verbosity_ >= 2 ) { edm::LogPrint("RecoTauPiZeroStripPlugin2") << "--> assigning seedCandId = " << seedCands.size() ; - const reco::TrackBaseRef candTrack = getTrack(*cand); + const reco::TrackBaseRef candTrack = getTrack(**cand); if ( candTrack.isNonnull() ) { edm::LogPrint("RecoTauPiZeroStripPlugin2") << "track: Pt = " << candTrack->pt() << " eta = " << candTrack->eta() << ", phi = " << candTrack->phi() << ", charge = " << candTrack->charge() ; edm::LogPrint("RecoTauPiZeroStripPlugin2") << " (dZ = " << candTrack->dz(vertexAssociator_.associatedVertex(jet)->position()) << ", dXY = " << candTrack->dxy(vertexAssociator_.associatedVertex(jet)->position()) << "," << " numHits = " << candTrack->hitPattern().numberOfValidTrackerHits() << ", numPxlHits = " << candTrack->hitPattern().numberOfValidPixelHits() << "," << " chi2 = " << candTrack->normalizedChi2() << ", dPt/Pt = " << (candTrack->ptError()/candTrack->pt()) << ")" ; } - edm::LogPrint("RecoTauPiZeroStripPlugin2") << "ECAL Et: calibrated = " << (*cand)->ecalEnergy()*sin((*cand)->theta()) << "," - << " raw = " << (*cand)->rawEcalEnergy()*sin((*cand)->theta()) ; - edm::LogPrint("RecoTauPiZeroStripPlugin2") << "HCAL Et: calibrated = " << (*cand)->hcalEnergy()*sin((*cand)->theta()) << "," - << " raw = " << (*cand)->rawHcalEnergy()*sin((*cand)->theta()) ; } seedCands.push_back(*cand); } else if ( (*cand)->et() > minGammaEtStripAdd_ ) { diff --git a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin3.cc b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin3.cc index 3f93130d60db9..bb8052ae01ca0 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin3.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin3.cc @@ -59,13 +59,13 @@ class RecoTauPiZeroStripPlugin3 : public RecoTauPiZeroBuilderPlugin explicit RecoTauPiZeroStripPlugin3(const edm::ParameterSet&, edm::ConsumesCollector &&iC); ~RecoTauPiZeroStripPlugin3() override; // Return type is auto_ptr - return_type operator()(const reco::PFJet&) const override; + return_type operator()(const reco::Jet&) const override; // Hook to update PV information void beginEvent() override; private: - typedef std::vector PFCandPtrs; - void addCandsToStrip(RecoTauPiZero&, PFCandPtrs&, const std::vector&, std::set&, bool&) const; + typedef std::vector CandPtrs; + void addCandsToStrip(RecoTauPiZero&, CandPtrs&, const std::vector&, std::set&, bool&) const; RecoTauVertexAssociator vertexAssociator_; @@ -76,7 +76,7 @@ class RecoTauPiZeroStripPlugin3 : public RecoTauPiZeroBuilderPlugin double minStripEt_; - std::vector inputPdgIds_; // type of candidates to clusterize + std::vector inputParticleIds_; // type of candidates to clusterize std::unique_ptr etaAssociationDistance_; // size of strip clustering window in eta direction std::unique_ptr phiAssociationDistance_; // size of strip clustering window in phi direction @@ -140,7 +140,7 @@ RecoTauPiZeroStripPlugin3::RecoTauPiZeroStripPlugin3(const edm::ParameterSet& ps qcuts_.reset(new RecoTauQualityCuts(qcuts_pset)); - inputPdgIds_ = pset.getParameter >("stripCandidatesParticleIds"); + inputParticleIds_ = pset.getParameter >("stripCandidatesParticleIds"); const edm::ParameterSet& stripSize_eta_pset = pset.getParameterSet("stripEtaAssociationDistanceFunc"); etaAssociationDistance_ = makeFunction("etaAssociationDistance", stripSize_eta_pset); const edm::ParameterSet& stripSize_phi_pset = pset.getParameterSet("stripPhiAssociationDistanceFunc"); @@ -167,7 +167,7 @@ void RecoTauPiZeroStripPlugin3::beginEvent() vertexAssociator_.setEvent(*evt()); } -void RecoTauPiZeroStripPlugin3::addCandsToStrip(RecoTauPiZero& strip, PFCandPtrs& cands, const std::vector& candFlags, +void RecoTauPiZeroStripPlugin3::addCandsToStrip(RecoTauPiZero& strip, CandPtrs& cands, const std::vector& candFlags, std::set& candIdsCurrentStrip, bool& isCandAdded) const { if ( verbosity_ >= 1 ) { @@ -176,7 +176,7 @@ void RecoTauPiZeroStripPlugin3::addCandsToStrip(RecoTauPiZero& strip, PFCandPtrs size_t numCands = cands.size(); for ( size_t candId = 0; candId < numCands; ++candId ) { if ( (!candFlags[candId]) && candIdsCurrentStrip.find(candId) == candIdsCurrentStrip.end() ) { // do not include same cand twice - reco::PFCandidatePtr cand = cands[candId]; + reco::CandidatePtr cand = cands[candId]; double etaAssociationDistance_value = etaAssociationDistance_->Eval(strip.pt()) + etaAssociationDistance_->Eval(cand->pt()); double phiAssociationDistance_value = phiAssociationDistance_->Eval(strip.pt()) + phiAssociationDistance_->Eval(cand->pt()); if ( fabs(strip.eta() - cand->eta()) < etaAssociationDistance_value && // check if cand is within eta-phi window centered on strip @@ -203,15 +203,23 @@ namespace } } - inline const reco::TrackBaseRef getTrack(const PFCandidate& cand) + // The following method has not been adapted to work with PackedCandidates, + // however, it is only used for printing/debugging and can be adapted when + // needed. + inline const reco::TrackBaseRef getTrack(const Candidate& cand) { - if ( cand.trackRef().isNonnull() ) return reco::TrackBaseRef(cand.trackRef()); - else if ( cand.gsfTrackRef().isNonnull() ) return reco::TrackBaseRef(cand.gsfTrackRef()); - else return reco::TrackBaseRef(); + const PFCandidate* pfCandPtr = dynamic_cast(&cand); + if (pfCandPtr) { + if ( pfCandPtr->trackRef().isNonnull() ) return reco::TrackBaseRef(pfCandPtr->trackRef()); + else if ( pfCandPtr->gsfTrackRef().isNonnull() ) return reco::TrackBaseRef(pfCandPtr->gsfTrackRef()); + else return reco::TrackBaseRef(); + } + + return reco::TrackBaseRef(); } } -RecoTauPiZeroStripPlugin3::return_type RecoTauPiZeroStripPlugin3::operator()(const reco::PFJet& jet) const +RecoTauPiZeroStripPlugin3::return_type RecoTauPiZeroStripPlugin3::operator()(const reco::Jet& jet) const { if ( verbosity_ >= 1 ) { edm::LogPrint("RecoTauPiZeroStripPlugin3") << ":" ; @@ -224,13 +232,13 @@ RecoTauPiZeroStripPlugin3::return_type RecoTauPiZeroStripPlugin3::operator()(con // Get the candidates passing our quality cuts qcuts_->setPV(vertexAssociator_.associatedVertex(jet)); - PFCandPtrs candsVector = qcuts_->filterCandRefs(pfCandidates(jet, inputPdgIds_)); + CandPtrs candsVector = qcuts_->filterCandRefs(pfCandidates(jet, inputParticleIds_)); // Convert to stl::list to allow fast deletions - PFCandPtrs seedCands; - PFCandPtrs addCands; + CandPtrs seedCands; + CandPtrs addCands; int idx = 0; - for ( PFCandPtrs::iterator cand = candsVector.begin(); + for ( CandPtrs::iterator cand = candsVector.begin(); cand != candsVector.end(); ++cand ) { if ( verbosity_ >= 1 ) { edm::LogPrint("RecoTauPiZeroStripPlugin3") << "PFGamma #" << idx << " (" << cand->id() << ":" << cand->key() << "): Et = " << (*cand)->et() << ", eta = " << (*cand)->eta() << ", phi = " << (*cand)->phi() ; @@ -238,17 +246,13 @@ RecoTauPiZeroStripPlugin3::return_type RecoTauPiZeroStripPlugin3::operator()(con if ( (*cand)->et() > minGammaEtStripSeed_ ) { if ( verbosity_ >= 2 ) { edm::LogPrint("RecoTauPiZeroStripPlugin3") << "--> assigning seedCandId = " << seedCands.size() ; - const reco::TrackBaseRef candTrack = getTrack(*cand); + const reco::TrackBaseRef candTrack = getTrack(**cand); if ( candTrack.isNonnull() ) { edm::LogPrint("RecoTauPiZeroStripPlugin3") << "track: Pt = " << candTrack->pt() << " eta = " << candTrack->eta() << ", phi = " << candTrack->phi() << ", charge = " << candTrack->charge() ; edm::LogPrint("RecoTauPiZeroStripPlugin3") << " (dZ = " << candTrack->dz(vertexAssociator_.associatedVertex(jet)->position()) << ", dXY = " << candTrack->dxy(vertexAssociator_.associatedVertex(jet)->position()) << "," << " numHits = " << candTrack->hitPattern().numberOfValidTrackerHits() << ", numPxlHits = " << candTrack->hitPattern().numberOfValidPixelHits() << "," << " chi2 = " << candTrack->normalizedChi2() << ", dPt/Pt = " << (candTrack->ptError()/candTrack->pt()) << ")" ; } - edm::LogPrint("RecoTauPiZeroStripPlugin3") << "ECAL Et: calibrated = " << (*cand)->ecalEnergy()*sin((*cand)->theta()) << "," - << " raw = " << (*cand)->rawEcalEnergy()*sin((*cand)->theta()) ; - edm::LogPrint("RecoTauPiZeroStripPlugin3") << "HCAL Et: calibrated = " << (*cand)->hcalEnergy()*sin((*cand)->theta()) << "," - << " raw = " << (*cand)->rawHcalEnergy()*sin((*cand)->theta()) ; } seedCands.push_back(*cand); } else if ( (*cand)->et() > minGammaEtStripAdd_ ) { diff --git a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroTrivialPlugin.cc b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroTrivialPlugin.cc index a8d69cfe4dd64..2524de46e1d3a 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroTrivialPlugin.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroTrivialPlugin.cc @@ -11,8 +11,8 @@ */ #include "RecoTauTag/RecoTau/interface/RecoTauPiZeroPlugins.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/Candidate/interface/CandidateFwd.h" +#include "DataFormats/Candidate/interface/Candidate.h" #include "DataFormats/JetReco/interface/PFJet.h" #include "DataFormats/TauReco/interface/RecoTauPiZero.h" @@ -25,7 +25,7 @@ class RecoTauPiZeroTrivialPlugin : public RecoTauPiZeroBuilderPlugin { public: explicit RecoTauPiZeroTrivialPlugin(const edm::ParameterSet& pset, edm::ConsumesCollector &&iC); ~RecoTauPiZeroTrivialPlugin() override {} - return_type operator()(const reco::PFJet& jet) const override; + return_type operator()(const reco::Jet& jet) const override; private: RecoTauQualityCuts qcuts_; }; @@ -36,8 +36,8 @@ RecoTauPiZeroTrivialPlugin::RecoTauPiZeroTrivialPlugin( "qualityCuts").getParameterSet("signalQualityCuts")) {} RecoTauPiZeroBuilderPlugin::return_type RecoTauPiZeroTrivialPlugin::operator()( - const reco::PFJet& jet) const { - std::vector pfGammaCands = qcuts_.filterCandRefs(pfGammas(jet)); + const reco::Jet& jet) const { + std::vector pfGammaCands = qcuts_.filterCandRefs(pfGammas(jet)); PiZeroVector output; output.reserve(pfGammaCands.size()); diff --git a/RecoTauTag/RecoTau/plugins/RecoTauProducer.cc b/RecoTauTag/RecoTau/plugins/RecoTauProducer.cc index 46acd131360b3..6250dd32ae7d5 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauProducer.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauProducer.cc @@ -38,7 +38,7 @@ #include "DataFormats/TauReco/interface/PFRecoTauChargedHadron.h" #include "DataFormats/TauReco/interface/JetPiZeroAssociation.h" #include "DataFormats/TauReco/interface/PFTau.h" -#include "DataFormats/Candidate/interface/CandidateFwd.h" +#include "DataFormats/JetReco/interface/JetCollection.h" #include "DataFormats/Common/interface/Association.h" #include "CommonTools/Utils/interface/StringCutObjectSelector.h" @@ -66,8 +66,8 @@ class RecoTauProducer : public edm::stream::EDProducer<> double minJetPt_; double maxJetAbsEta_; //token definition - edm::EDGetTokenT jet_token; - edm::EDGetTokenT > jetRegion_token; + edm::EDGetTokenT jet_token; + edm::EDGetTokenT > > jetRegion_token; edm::EDGetTokenT chargedHadron_token; edm::EDGetTokenT piZero_token; @@ -91,8 +91,8 @@ RecoTauProducer::RecoTauProducer(const edm::ParameterSet& pset) minJetPt_ = pset.getParameter("minJetPt"); maxJetAbsEta_ = pset.getParameter("maxJetAbsEta"); //consumes definition - jet_token=consumes(jetSrc_); - jetRegion_token = consumes >(jetRegionSrc_); + jet_token=consumes(jetSrc_); + jetRegion_token = consumes > >(jetRegionSrc_); chargedHadron_token = consumes(chargedHadronSrc_); piZero_token = consumes(piZeroSrc_); @@ -129,14 +129,11 @@ RecoTauProducer::RecoTauProducer(const edm::ParameterSet& pset) void RecoTauProducer::produce(edm::Event& evt, const edm::EventSetup& es) { // Get the jet input collection via a view of Candidates - edm::Handle jetView; + edm::Handle jetView; evt.getByToken(jet_token, jetView); - - // Convert to a vector of PFJetRefs - reco::PFJetRefVector jets = reco::tau::castView(jetView); - + // Get the jet region producer - edm::Handle > jetRegionHandle; + edm::Handle > > jetRegionHandle; evt.getByToken(jetRegion_token, jetRegionHandle); // Get the charged hadron input collection @@ -157,26 +154,27 @@ void RecoTauProducer::produce(edm::Event& evt, const edm::EventSetup& es) // Create output collection auto output = std::make_unique(); - output->reserve(jets.size()); + output->reserve(jetView->size()); // Loop over the jets and build the taus for each jet - for(auto const& jetRef : jets ) { + for (size_t i_j = 0; i_j < jetView->size(); ++i_j) { + const auto& jetRef = jetView->refAt(i_j); // Get the jet with extra constituents from an area around the jet if(jetRef->pt() - minJetPt_ < 1e-5) continue; if(std::abs(jetRef->eta()) - maxJetAbsEta_ > -1e-5) continue; - reco::PFJetRef jetRegionRef = (*jetRegionHandle)[jetRef]; + reco::JetBaseRef jetRegionRef = (*jetRegionHandle)[jetRef]; if ( jetRegionRef.isNull() ) { throw cms::Exception("BadJetRegionRef") << "No jet region can be found for the current jet: " << jetRef.id(); } // Remove all the jet constituents from the jet extras - std::vector jetCands = jetRef->getPFConstituents(); - std::vector allRegionalCands = jetRegionRef->getPFConstituents(); + std::vector jetCands = jetRef->daughterPtrVector(); + std::vector allRegionalCands = jetRegionRef->daughterPtrVector(); // Sort both by ref key std::sort(jetCands.begin(), jetCands.end()); std::sort(allRegionalCands.begin(), allRegionalCands.end()); // Get the regional junk candidates not in the jet. - std::vector uniqueRegionalCands; + std::vector uniqueRegionalCands; // This can actually be less than zero, if the jet has really crazy soft // stuff really far away from the jet axis. @@ -199,8 +197,9 @@ void RecoTauProducer::produce(edm::Event& evt, const edm::EventSetup& es) for ( const auto& builder: builders_ ) { // Get a ptr_vector of taus from the builder reco::tau::RecoTauBuilderPlugin::output_type taus((*builder)(jetRef, chargedHadrons, piZeros, uniqueRegionalCands)); + // Make sure all taus have their jetref set correctly - std::for_each(taus.begin(), taus.end(), boost::bind(&reco::PFTau::setjetRef, _1, jetRef)); + std::for_each(taus.begin(), taus.end(), boost::bind(&reco::PFTau::setjetRef, _1, reco::JetBaseRef(jetRef))); // Copy without selection if ( !outputSelector_.get() ) { output->insert(output->end(), taus.begin(), taus.end()); @@ -220,7 +219,7 @@ void RecoTauProducer::produce(edm::Event& evt, const edm::EventSetup& es) // jet. if ( !nTausBuilt && buildNullTaus_ ) { reco::PFTau nullTau(std::numeric_limits::quiet_NaN(), jetRef->p4()); - nullTau.setjetRef(jetRef); + nullTau.setjetRef(reco::JetBaseRef(jetRef)); output->push_back(nullTau); } } diff --git a/RecoTauTag/RecoTau/plugins/RecoTauSoftTwoProngTausCleanerPlugin.cc b/RecoTauTag/RecoTau/plugins/RecoTauSoftTwoProngTausCleanerPlugin.cc index 6dcd50450b03c..467eab28ada2a 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauSoftTwoProngTausCleanerPlugin.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauSoftTwoProngTausCleanerPlugin.cc @@ -8,6 +8,7 @@ #include "RecoTauTag/RecoTau/interface/RecoTauBuilderPlugins.h" #include "DataFormats/TauReco/interface/PFTauDiscriminator.h" +#include "RecoTauTag/RecoTau/interface/pfRecoTauChargedHadronAuxFunctions.h" namespace reco { namespace tau { @@ -35,7 +36,8 @@ double RecoTauSoftTwoProngTausCleanerPlugin::operator()(const reco::PFTauRef& ta if ( chargedHadrons.size() == 2 ) { for ( std::vector::const_iterator chargedHadron = chargedHadrons.begin(); chargedHadron != chargedHadrons.end(); ++chargedHadron ) { - if ( !(chargedHadron->getTrack().get() && chargedHadron->getTrack()->pt() > minTrackPt_) ) result += 1.e+3; + const reco::Track* track = getTrackFromChargedHadron(*chargedHadron); + if ( !(track != nullptr && track->pt() > minTrackPt_) ) result += 1.e+3; } } return result; diff --git a/RecoTauTag/RecoTau/plugins/RecoTauTauTagInfoWorkaroundModifier.cc b/RecoTauTag/RecoTau/plugins/RecoTauTauTagInfoWorkaroundModifier.cc index 3340ee7af150e..760cb8653bc54 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauTauTagInfoWorkaroundModifier.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauTauTagInfoWorkaroundModifier.cc @@ -43,11 +43,11 @@ void RecoTauTagInfoWorkaroundModifer::beginEvent() { void RecoTauTagInfoWorkaroundModifer::operator()(PFTau& tau) const { // Find the PFTauTagInfo that comes from the same PFJet - PFJetRef tauJetRef = tau.jetRef(); + JetBaseRef tauJetRef = tau.jetRef(); for(size_t iInfo = 0; iInfo < infos_->size(); ++iInfo) { // Get jet ref from tau tag info PFTauTagInfoRef infoRef = PFTauTagInfoRef(infos_, iInfo); - PFJetRef infoJetRef = infoRef->pfjetRef(); + JetBaseRef infoJetRef = infoRef->pfjetRef(); // Check if they come from the same jet if (infoJetRef == tauJetRef) { // This tau "comes" from this PFJetRef diff --git a/RecoTauTag/RecoTau/plugins/RecoTauTwoProngFilter.cc b/RecoTauTag/RecoTau/plugins/RecoTauTwoProngFilter.cc index b68a38fe44ef5..f507e810759f3 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauTwoProngFilter.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauTwoProngFilter.cc @@ -18,10 +18,10 @@ namespace reco { namespace tau { namespace { // Delete an element from a ptr vector - std::vector deleteFrom(const PFCandidatePtr& ptr, const std::vector& collection) + std::vector deleteFrom(const CandidatePtr& ptr, const std::vector& collection) { - std::vector output; - for ( std::vector::const_iterator cand = collection.begin(); + std::vector output; + for ( std::vector::const_iterator cand = collection.begin(); cand != collection.end(); ++cand ) { if ( (*cand) != ptr) output.push_back(*cand); } @@ -43,8 +43,8 @@ class RecoTauTwoProngFilter : public RecoTauModifierPlugin { } void RecoTauTwoProngFilter::operator()(PFTau& tau) const { - if (tau.signalPFChargedHadrCands().size() == 2) { - const std::vector& signalCharged = tau.signalPFChargedHadrCands(); + if (tau.signalChargedHadrCands().size() == 2) { + const std::vector& signalCharged = tau.signalChargedHadrCands(); size_t indexOfHighestPt = (signalCharged[0]->pt() > signalCharged[1]->pt()) ? 0 : 1; size_t indexOfLowerPt = ( indexOfHighestPt ) ? 0 : 1; @@ -52,18 +52,18 @@ void RecoTauTwoProngFilter::operator()(PFTau& tau) const { signalCharged[indexOfHighestPt]->pt(); if (ratio < minPtFractionForSecondProng_) { - PFCandidatePtr keep = signalCharged[indexOfHighestPt]; - PFCandidatePtr filter = signalCharged[indexOfLowerPt]; + CandidatePtr keep = signalCharged[indexOfHighestPt]; + CandidatePtr filter = signalCharged[indexOfLowerPt]; // Make our new signal charged candidate collection - std::vector newSignalCharged; + std::vector newSignalCharged; newSignalCharged.push_back(keep); - std::vector newSignal = deleteFrom(filter, tau.signalPFCands()); + std::vector newSignal = deleteFrom(filter, tau.signalCands()); // Copy our filtered cand to isolation - std::vector newIsolationCharged = - tau.isolationPFChargedHadrCands(); + std::vector newIsolationCharged = + tau.isolationChargedHadrCands(); newIsolationCharged.push_back(filter); - std::vector newIsolation = tau.isolationPFCands(); + std::vector newIsolation = tau.isolationCands(); newIsolation.push_back(filter); // Update tau members @@ -72,10 +72,10 @@ void RecoTauTwoProngFilter::operator()(PFTau& tau) const { tau.isolationPFChargedHadrCandsPtSum() - filter->pt()); tau.setCharge(tau.charge() - filter->charge()); // Update tau constituents - tau.setsignalPFChargedHadrCands(newSignalCharged); - tau.setsignalPFCands(newSignal); - tau.setisolationPFChargedHadrCands(newIsolationCharged); - tau.setisolationPFCands(newIsolation); + tau.setsignalChargedHadrCands(newSignalCharged); + tau.setsignalCands(newSignal); + tau.setisolationChargedHadrCands(newIsolationCharged); + tau.setisolationCands(newIsolation); } } } diff --git a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstCaloMuon.cc b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstCaloMuon.cc index dbbe61fc643bb..1143c7a47b69b 100644 --- a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstCaloMuon.cc +++ b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstCaloMuon.cc @@ -82,8 +82,8 @@ class TauLeadTrackExtractor double getTrackPtSum(const reco::PFTau& tau) const { double trackPtSum = 0.; - for ( std::vector::const_iterator signalTrack = tau.signalPFChargedHadrCands().begin(); - signalTrack != tau.signalPFChargedHadrCands().end(); ++signalTrack ) { + for ( std::vector::const_iterator signalTrack = tau.signalChargedHadrCands().begin(); + signalTrack != tau.signalChargedHadrCands().end(); ++signalTrack ) { trackPtSum += (*signalTrack)->pt(); } return trackPtSum; diff --git a/RecoTauTag/RecoTau/python/RecoTauCleanerPlugins.py b/RecoTauTag/RecoTau/python/RecoTauCleanerPlugins.py index a67ff5eebb0f1..0065ec4bd6ebc 100644 --- a/RecoTauTag/RecoTau/python/RecoTauCleanerPlugins.py +++ b/RecoTauTag/RecoTau/python/RecoTauCleanerPlugins.py @@ -23,7 +23,7 @@ name = cms.string("UnitCharge"), plugin = cms.string("RecoTauStringCleanerPlugin"), # Only effects three prongs - selection = cms.string("signalPFChargedHadrCands().size() = 3"), + selection = cms.string("signalChargedHadrCands().size() = 3"), # As 1 is lower than 3, this will always prefer those with unit charge selectionPassFunction = cms.string("abs(charge())-1"), # If it is a one prong, consider it just as good as a @@ -74,7 +74,7 @@ name = cms.string("Pt"), plugin = cms.string("RecoTauStringCleanerPlugin"), # Require that cones were built by ensuring the a leadCand exits - selection = cms.string("leadPFCand().isNonnull()"), + selection = cms.string("leadCand().isNonnull()"), selectionPassFunction = cms.string("-pt()"), # CV: negative sign means that we prefer candidates of high pT selectionFailValue = cms.double(1e3), tolerance = cms.double(1.e-2) # CV: consider candidates with almost equal pT to be of the same rank (to avoid sensitivity to rounding errors) @@ -90,7 +90,7 @@ name = cms.string("StripMultiplicity"), plugin = cms.string("RecoTauStringCleanerPlugin"), # Require that cones were built by ensuring the a leadCand exits - selection = cms.string("leadPFCand().isNonnull()"), + selection = cms.string("leadCand().isNonnull()"), selectionPassFunction = cms.string("-signalPiZeroCandidates().size()"), selectionFailValue = cms.double(1e3), tolerance = tolerance_default, @@ -100,7 +100,7 @@ name = cms.string("CombinedIsolation"), plugin = cms.string("RecoTauStringCleanerPlugin"), # Require that cones were built by ensuring the a leadCand exits - selection = cms.string("leadPFCand().isNonnull()"), + selection = cms.string("leadCand().isNonnull()"), selectionPassFunction = cms.string("isolationPFChargedHadrCandsPtSum() + isolationPFGammaCandsEtSum()"), selectionFailValue = cms.double(1e3), tolerance = tolerance_default, @@ -110,7 +110,7 @@ name = cms.string("ChargeIsolation"), plugin = cms.string("RecoTauStringCleanerPlugin"), # Require that cones were built by ensuring the a leadCand exits - selection = cms.string("leadPFCand().isNonnull()"), + selection = cms.string("leadCand().isNonnull()"), # Prefer lower isolation activity selectionPassFunction = cms.string("isolationPFChargedHadrCandsPtSum()"), selectionFailValue = cms.double(1e3), @@ -121,7 +121,7 @@ name = cms.string("GammaIsolation"), plugin = cms.string("RecoTauStringCleanerPlugin"), # Require that cones were built by ensuring the a leadCand exits - selection = cms.string("leadPFCand().isNonnull()"), + selection = cms.string("leadCand().isNonnull()"), # Prefer lower isolation activity selectionPassFunction = cms.string("isolationPFGammaCandsEtSum()"), selectionFailValue = cms.double(1e3), diff --git a/RecoTauTag/RecoTau/python/RecoTauCombinatoricProducer_cfi.py b/RecoTauTag/RecoTau/python/RecoTauCombinatoricProducer_cfi.py index c849ae67a7400..723798559aa6f 100644 --- a/RecoTauTag/RecoTau/python/RecoTauCombinatoricProducer_cfi.py +++ b/RecoTauTag/RecoTau/python/RecoTauCombinatoricProducer_cfi.py @@ -138,7 +138,7 @@ chargedHadronSrc = cms.InputTag('ak4PFJetsRecoTauChargedHadrons'), piZeroSrc = cms.InputTag("ak4PFJetsRecoTauPiZeros"), buildNullTaus = cms.bool(False), - outputSelection = cms.string("leadPFChargedHadrCand().isNonnull()"), # MB: always require that leading PFChargedHadron candidate exists + outputSelection = cms.string("leadChargedHadrCand().isNonnull()"), # MB: always require that leading PFChargedHadron candidate exists # Make maximum size from which to collect isolation cone objects, w.r.t to # the axis of the signal cone objects builders = cms.VPSet( diff --git a/RecoTauTag/RecoTau/python/RecoTauPiZeroBuilderPlugins_cfi.py b/RecoTauTag/RecoTau/python/RecoTauPiZeroBuilderPlugins_cfi.py index 40f475cb2a4dd..8cb36c8e50b2c 100644 --- a/RecoTauTag/RecoTau/python/RecoTauPiZeroBuilderPlugins_cfi.py +++ b/RecoTauTag/RecoTau/python/RecoTauPiZeroBuilderPlugins_cfi.py @@ -75,6 +75,7 @@ modStrips2 = cms.PSet( name = cms.string("s"), plugin = cms.string('RecoTauPiZeroStripPlugin3'), + qualityCuts = PFTauQualityCuts, applyElecTrackQcuts = cms.bool(False), # Clusterize photons and electrons (PF numbering) stripCandidatesParticleIds = cms.vint32(2, 4), 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 676d42a239133..16cd819603b08 100644 --- a/RecoTauTag/RecoTau/src/AntiElectronIDMVA5.cc +++ b/RecoTauTag/RecoTau/src/AntiElectronIDMVA5.cc @@ -737,9 +737,9 @@ double AntiElectronIDMVA5::MVAValue(const reco::PFTau& thePFTau, std::vector GammasPt; for ( unsigned i = 0 ; i < thePFTau.signalPFGammaCands().size(); ++i ) { reco::PFCandidatePtr gamma = thePFTau.signalPFGammaCands().at(i); - if ( thePFTau.leadPFChargedHadrCand().isNonnull() ) { - GammasdEta.push_back(gamma->eta() - thePFTau.leadPFChargedHadrCand()->eta()); - GammasdPhi.push_back(gamma->phi() - thePFTau.leadPFChargedHadrCand()->phi()); + if ( thePFTau.leadChargedHadrCand().isNonnull() ) { + GammasdEta.push_back(gamma->eta() - thePFTau.leadChargedHadrCand()->eta()); + GammasdPhi.push_back(gamma->phi() - thePFTau.leadChargedHadrCand()->phi()); } else { GammasdEta.push_back(gamma->eta() - thePFTau.eta()); GammasdPhi.push_back(gamma->phi() - thePFTau.phi()); @@ -777,7 +777,7 @@ double AntiElectronIDMVA5::MVAValue(const reco::PFTau& thePFTau, } Float_t TaudCrackPhi = dCrackPhi(TauPhi, TauEtaAtEcalEntrance); Float_t TaudCrackEta = dCrackEta(TauEtaAtEcalEntrance); - Float_t TauSignalPFChargedCands = thePFTau.signalPFChargedHadrCands().size(); + Float_t TauSignalPFChargedCands = thePFTau.signalChargedHadrCands().size(); Float_t TauHasGsf = thePFTau.leadPFChargedHadrCand()->gsfTrackRef().isNonnull(); Float_t ElecEta = theGsfEle.eta(); @@ -902,9 +902,9 @@ double AntiElectronIDMVA5::MVAValue(const reco::PFTau& thePFTau) std::vector GammasPt; for ( unsigned i = 0 ; i < thePFTau.signalPFGammaCands().size(); ++i ) { reco::PFCandidatePtr gamma = thePFTau.signalPFGammaCands().at(i); - if ( thePFTau.leadPFChargedHadrCand().isNonnull() ) { - GammasdEta.push_back(gamma->eta() - thePFTau.leadPFChargedHadrCand()->eta()); - GammasdPhi.push_back(gamma->phi() - thePFTau.leadPFChargedHadrCand()->phi()); + if ( thePFTau.leadChargedHadrCand().isNonnull() ) { + GammasdEta.push_back(gamma->eta() - thePFTau.leadChargedHadrCand()->eta()); + GammasdPhi.push_back(gamma->phi() - thePFTau.leadChargedHadrCand()->phi()); } else { GammasdEta.push_back(gamma->eta() - thePFTau.eta()); GammasdPhi.push_back(gamma->phi() - thePFTau.phi()); @@ -942,7 +942,7 @@ double AntiElectronIDMVA5::MVAValue(const reco::PFTau& thePFTau) } Float_t TaudCrackPhi = dCrackPhi(TauPhi,TauEtaAtEcalEntrance) ; Float_t TaudCrackEta = dCrackEta(TauEtaAtEcalEntrance) ; - Float_t TauSignalPFChargedCands = thePFTau.signalPFChargedHadrCands().size(); + Float_t TauSignalPFChargedCands = thePFTau.signalChargedHadrCands().size(); Float_t TauHasGsf = thePFTau.leadPFChargedHadrCand()->gsfTrackRef().isNonnull(); Float_t dummyElecEta = 9.9; diff --git a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc index 5c2ae188e6354..33857cff1d02d 100644 --- a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc +++ b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc @@ -569,15 +569,15 @@ double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau, reco::Candidate::LorentzVector pfGammaSum(0,0,0,0); reco::Candidate::LorentzVector pfChargedSum(0,0,0,0); - for ( const auto & gamma : thePFTau.signalPFGammaCands() ) { - float dR = deltaR(gamma->p4(), thePFTau.leadPFChargedHadrCand()->p4()); + 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.leadPFChargedHadrCand().isNonnull() ) { - GammasdEtaInSigCone.push_back(gamma->eta() - thePFTau.leadPFChargedHadrCand()->eta()); - GammasdPhiInSigCone.push_back(gamma->phi() - thePFTau.leadPFChargedHadrCand()->phi()); + 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()); @@ -588,9 +588,9 @@ double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau, } // pfGammas outside the tau signal cone else { - if ( thePFTau.leadPFChargedHadrCand().isNonnull() ) { - GammasdEtaOutSigCone.push_back(gamma->eta() - thePFTau.leadPFChargedHadrCand()->eta()); - GammasdPhiOutSigCone.push_back(gamma->phi() - thePFTau.leadPFChargedHadrCand()->phi()); + 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()); @@ -600,8 +600,8 @@ double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau, } } - for ( const auto & charged : thePFTau.signalPFChargedHadrCands() ) { - float dR = deltaR(charged->p4(), thePFTau.leadPFChargedHadrCand()->p4()); + for ( const auto & charged : thePFTau.signalChargedHadrCands() ) { + float dR = deltaR(charged->p4(), thePFTau.leadChargedHadrCand()->p4()); float signalrad = std::max(0.05, std::min(0.10, 3.0/std::max(1.0, thePFTau.pt()))); // charged particles inside the tau signal cone @@ -640,7 +640,6 @@ double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau, Float_t TaudCrackPhi = dCrackPhi(TauPhi, TauEtaAtEcalEntrance); Float_t TaudCrackEta = dCrackEta(TauEtaAtEcalEntrance); Float_t TauHasGsf = thePFTau.leadPFChargedHadrCand()->gsfTrackRef().isNonnull(); - // === electron variables === Float_t ElecEta = theGsfEle.eta(); @@ -780,15 +779,15 @@ double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau) reco::Candidate::LorentzVector pfGammaSum(0,0,0,0); reco::Candidate::LorentzVector pfChargedSum(0,0,0,0); - for ( const auto & gamma : thePFTau.signalPFGammaCands() ) { - float dR = deltaR(gamma->p4(), thePFTau.leadPFChargedHadrCand()->p4()); + 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.leadPFChargedHadrCand().isNonnull() ) { - GammasdEtaInSigCone.push_back(gamma->eta() - thePFTau.leadPFChargedHadrCand()->eta()); - GammasdPhiInSigCone.push_back(gamma->phi() - thePFTau.leadPFChargedHadrCand()->phi()); + 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()); @@ -799,9 +798,9 @@ double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau) } // pfGammas outside the tau signal cone else { - if ( thePFTau.leadPFChargedHadrCand().isNonnull() ) { - GammasdEtaOutSigCone.push_back(gamma->eta() - thePFTau.leadPFChargedHadrCand()->eta()); - GammasdPhiOutSigCone.push_back(gamma->phi() - thePFTau.leadPFChargedHadrCand()->phi()); + 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()); @@ -811,8 +810,8 @@ double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau) } } - for ( const auto & charged : thePFTau.signalPFChargedHadrCands() ) { - float dR = deltaR(charged->p4(), thePFTau.leadPFChargedHadrCand()->p4()); + for ( const auto & charged : thePFTau.signalChargedHadrCands() ) { + float dR = deltaR(charged->p4(), thePFTau.leadChargedHadrCand()->p4()); float signalrad = std::max(0.05, std::min(0.10, 3.0/std::max(1.0, thePFTau.pt()))); // charged particles inside the tau signal cone diff --git a/RecoTauTag/RecoTau/src/HPSPFRecoTauAlgorithm.cc b/RecoTauTag/RecoTau/src/HPSPFRecoTauAlgorithm.cc index 58907c7e00614..189f5d3869884 100644 --- a/RecoTauTag/RecoTau/src/HPSPFRecoTauAlgorithm.cc +++ b/RecoTauTag/RecoTau/src/HPSPFRecoTauAlgorithm.cc @@ -26,11 +26,11 @@ HPSPFRecoTauAlgorithm::buildPFTau(const PFTauTagInfoRef& tagInfo,const Vertex& v pfTaus_.clear(); //make the strips globally. - std::vector> strips = candidateMerger_->mergeCandidates(tagInfo->PFCands()); + std::vector > strips = candidateMerger_->mergeCandidates(tagInfo->PFCands()); //Sort the hadrons globally and once! - std::vector hadrons = tagInfo->PFChargedHadrCands(); + std::vector hadrons = tagInfo->PFChargedHadrCands(); if(hadrons.size()>1) TauTagTools::sortRefVectorByPt(hadrons); @@ -64,7 +64,7 @@ HPSPFRecoTauAlgorithm::buildPFTau(const PFTauTagInfoRef& tagInfo,const Vertex& v const TransientTrack leadTrack=TransientTrackBuilder_->build(pfTau.leadPFChargedHadrCand()->trackRef()); if(pfTau.pfTauTagInfoRef().isNonnull()) if(pfTau.pfTauTagInfoRef()->pfjetRef().isNonnull()) { - PFJetRef jet = pfTau.pfTauTagInfoRef()->pfjetRef(); + JetBaseRef jet = pfTau.pfTauTagInfoRef()->pfjetRef(); GlobalVector jetDir(jet->px(),jet->py(),jet->pz()); if(IPTools::signedTransverseImpactParameter(leadTrack,jetDir,vertex).first) pfTau.setleadPFChargedHadrCandsignedSipt(IPTools::signedTransverseImpactParameter(leadTrack,jetDir,vertex).second.significance()); @@ -85,13 +85,13 @@ HPSPFRecoTauAlgorithm::buildPFTau(const PFTauTagInfoRef& tagInfo,const Vertex& v //Create one prong tau void -HPSPFRecoTauAlgorithm::buildOneProng(const reco::PFTauTagInfoRef& tagInfo,const std::vector& hadrons) +HPSPFRecoTauAlgorithm::buildOneProng(const reco::PFTauTagInfoRef& tagInfo,const std::vector& hadrons) { PFTauCollection taus; if(!hadrons.empty()) for(unsigned int h=0;h signal; + std::vector signal; signal.push_back(hadron); //Set The signal candidates of the PF Tau - tau.setsignalPFChargedHadrCands(signal); - tau.setsignalPFCands(signal); - tau.setleadPFChargedHadrCand(hadron); - tau.setleadPFCand(hadron); + tau.setsignalChargedHadrCands(signal); + tau.setsignalCands(signal); + tau.setleadChargedHadrCand(hadron); + tau.setleadCand(hadron); //Fill isolation variables associateIsolationCandidates(tau,0.0); @@ -135,7 +135,7 @@ HPSPFRecoTauAlgorithm::buildOneProng(const reco::PFTauTagInfoRef& tagInfo,const //Build one Prong + Strip void -HPSPFRecoTauAlgorithm::buildOneProngStrip(const reco::PFTauTagInfoRef& tagInfo,const std::vector >& strips,const std::vector & hadrons) +HPSPFRecoTauAlgorithm::buildOneProngStrip(const reco::PFTauTagInfoRef& tagInfo,const std::vector >& strips,const std::vector & hadrons) { //Create output Collection @@ -147,12 +147,12 @@ HPSPFRecoTauAlgorithm::buildOneProngStrip(const reco::PFTauTagInfoRef& tagInfo,c //make taus like this only if there is at least one hadron+ 1 strip if(!hadrons.empty()&&!strips.empty()){ //Combinatorics between strips and clusters - for(std::vector>::const_iterator candVector=strips.begin();candVector!=strips.end();++candVector) - for(std::vector::const_iterator hadron=hadrons.begin();hadron!=hadrons.end();++hadron) { + for(std::vector>::const_iterator candVector=strips.begin();candVector!=strips.end();++candVector) + for(std::vector::const_iterator hadron=hadrons.begin();hadron!=hadrons.end();++hadron) { //First Cross cleaning ! If you asked to clusterize the candidates //with tracks too then you should not double count the track - std::vector emConstituents = *candVector; + std::vector emConstituents = *candVector; removeCandidateFromRefVector(*hadron,emConstituents); //Create a LorentzVector for the strip @@ -174,9 +174,9 @@ HPSPFRecoTauAlgorithm::buildOneProngStrip(const reco::PFTauTagInfoRef& tagInfo,c tau.setpfTauTagInfoRef(tagInfo); //Create the signal vectors - std::vector signal; - std::vector signalH; - std::vector signalG; + std::vector signal; + std::vector signalH; + std::vector signalG; //Store the hadron in the PFTau signalH.push_back(*hadron); @@ -192,23 +192,23 @@ HPSPFRecoTauAlgorithm::buildOneProngStrip(const reco::PFTauTagInfoRef& tagInfo,c ROOT::Math::VectorUtil::DeltaR(tau.p4(),strip)); if(!emConstituents.empty()) - for(std::vector::const_iterator j=emConstituents.begin();j!=emConstituents.end();++j) { + for(std::vector::const_iterator j=emConstituents.begin();j!=emConstituents.end();++j) { signal.push_back(*j); signalG.push_back(*j); } //Set the PFTau - tau.setsignalPFChargedHadrCands(signalH); - tau.setsignalPFGammaCands(signalG); - tau.setsignalPFCands(signal); - tau.setleadPFChargedHadrCand(*hadron); - tau.setleadPFNeutralCand(emConstituents[0]); + tau.setsignalChargedHadrCands(signalH); + tau.setsignalGammaCands(signalG); + tau.setsignalCands(signal); + tau.setleadChargedHadrCand(*hadron); + tau.setleadNeutralCand(emConstituents[0]); //Set the lead Candidate->Can be the hadron or the leading PFGamma(When we clear the Dataformat we will put the strip) if((*hadron)->pt()>emConstituents[0]->pt()) - tau.setleadPFCand(*hadron); + tau.setleadCand(*hadron); else - tau.setleadPFCand(emConstituents[0]); + tau.setleadCand(emConstituents[0]); //Apply the signal cone size formula if(isNarrowTau(tau,tauCone)) { @@ -231,7 +231,7 @@ HPSPFRecoTauAlgorithm::buildOneProngStrip(const reco::PFTauTagInfoRef& tagInfo,c } void -HPSPFRecoTauAlgorithm::buildOneProngTwoStrips(const reco::PFTauTagInfoRef& tagInfo,const std::vector >& strips,const std::vector& hadrons) +HPSPFRecoTauAlgorithm::buildOneProngTwoStrips(const reco::PFTauTagInfoRef& tagInfo,const std::vector >& strips,const std::vector& hadrons) { @@ -242,13 +242,13 @@ HPSPFRecoTauAlgorithm::buildOneProngTwoStrips(const reco::PFTauTagInfoRef& tagIn //Combinatorics between strips and clusters for(unsigned int Nstrip1=0;Nstrip1::const_iterator hadron=hadrons.begin();hadron!=hadrons.end();++hadron) { + for(std::vector::const_iterator hadron=hadrons.begin();hadron!=hadrons.end();++hadron) { //Create the strips and the vectors .Again cross clean the track if associated - std::vector emConstituents1 = strips[Nstrip1]; - std::vector emConstituents2 = strips[Nstrip2]; + std::vector emConstituents1 = strips[Nstrip1]; + std::vector emConstituents2 = strips[Nstrip2]; removeCandidateFromRefVector(*hadron,emConstituents1); removeCandidateFromRefVector(*hadron,emConstituents2); @@ -278,9 +278,9 @@ HPSPFRecoTauAlgorithm::buildOneProngTwoStrips(const reco::PFTauTagInfoRef& tagIn //Create the signal vectors - std::vector signal; - std::vector signalH; - std::vector signalG; + std::vector signal; + std::vector signalH; + std::vector signalG; //Store the hadron in the PFTau signalH.push_back(*hadron); @@ -300,27 +300,27 @@ HPSPFRecoTauAlgorithm::buildOneProngTwoStrips(const reco::PFTauTagInfoRef& tagIn } - for(std::vector::const_iterator j=emConstituents1.begin();j!=emConstituents1.end();++j) { + for(std::vector::const_iterator j=emConstituents1.begin();j!=emConstituents1.end();++j) { signal.push_back(*j); signalG.push_back(*j); } - for(std::vector::const_iterator j=emConstituents2.begin();j!=emConstituents2.end();++j) { + for(std::vector::const_iterator j=emConstituents2.begin();j!=emConstituents2.end();++j) { signal.push_back(*j); signalG.push_back(*j); } //Set the PFTau - tau.setsignalPFChargedHadrCands(signalH); - tau.setsignalPFGammaCands(signalG); - tau.setsignalPFCands(signal); - tau.setleadPFChargedHadrCand(*hadron); + tau.setsignalChargedHadrCands(signalH); + tau.setsignalGammaCands(signalG); + tau.setsignalCands(signal); + tau.setleadChargedHadrCand(*hadron); //Set the lead Candidate->Can be the hadron or the leading PFGamma(When we clear the Dataformat we will put the strip) if((*hadron)->pt()>emConstituents1[0]->pt()) - tau.setleadPFCand(*hadron); + tau.setleadCand(*hadron); else - tau.setleadPFCand(emConstituents1[0]); + tau.setleadCand(emConstituents1[0]); //Apply the cone size formula if(isNarrowTau(tau,tauCone)) { @@ -351,7 +351,7 @@ HPSPFRecoTauAlgorithm::buildOneProngTwoStrips(const reco::PFTauTagInfoRef& tagIn void -HPSPFRecoTauAlgorithm::buildThreeProngs(const reco::PFTauTagInfoRef& tagInfo,const std::vector& hadrons) +HPSPFRecoTauAlgorithm::buildThreeProngs(const reco::PFTauTagInfoRef& tagInfo,const std::vector& hadrons) { PFTauCollection taus; //get Hadrons @@ -363,9 +363,16 @@ HPSPFRecoTauAlgorithm::buildThreeProngs(const reco::PFTauTagInfoRef& tagInfo,con for(unsigned int b=a+1;b(c_h1.get()); + const reco::PFCandidate* h2 = dynamic_cast(c_h2.get()); + const reco::PFCandidate* h3 = dynamic_cast(c_h3.get()); + if (h1 == nullptr || h2 == nullptr || h3 == nullptr) { + throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFCandidates, and this outdated algorithm as not updated to cope with PFTaus made from other Candidates.\n"; + } //check charge Compatibility and lead track int charge=h1->charge()+h2->charge()+h3->charge(); @@ -381,10 +388,10 @@ HPSPFRecoTauAlgorithm::buildThreeProngs(const reco::PFTauTagInfoRef& tagInfo,con if(tau.pt()>tauThreshold_)//Threshold if(ROOT::Math::VectorUtil::DeltaR(tau.p4(),tagInfo->pfjetRef()->p4()) signal; - signal.push_back(h1); - signal.push_back(h2); - signal.push_back(h3); + std::vector signal; + signal.push_back(c_h1); + signal.push_back(c_h2); + signal.push_back(c_h3); //calculate the tau cone by getting the maximum distance double tauCone = 10000.0; if(coneMetric_=="DR") @@ -401,10 +408,10 @@ HPSPFRecoTauAlgorithm::buildThreeProngs(const reco::PFTauTagInfoRef& tagInfo,con } //Set The PFTau - tau.setsignalPFChargedHadrCands(signal); - tau.setsignalPFCands(signal); - tau.setleadPFChargedHadrCand(h1); - tau.setleadPFCand(h1); + tau.setsignalChargedHadrCands(signal); + tau.setsignalCands(signal); + tau.setleadChargedHadrCand(c_h1); + tau.setleadCand(c_h1); if(isNarrowTau(tau,tauCone)) { //calculate the isolation Deposits @@ -457,31 +464,31 @@ HPSPFRecoTauAlgorithm::associateIsolationCandidates(reco::PFTau& tau, if(tau.pfTauTagInfoRef().isNull()) return; - std::vector hadrons; - std::vector gammas; - std::vector neutral; + std::vector hadrons; + std::vector gammas; + std::vector neutral; //Remove candidates outside the cones if(useIsolationAnnulus_) { - const std::vector& pfChargedHadrCands = tau.pfTauTagInfoRef()->PFChargedHadrCands(); + const std::vector& pfChargedHadrCands = tau.pfTauTagInfoRef()->PFChargedHadrCands(); double tauEta=tau.eta(); double tauPhi=tau.phi(); - for ( std::vector::const_iterator pfChargedHadrCand = pfChargedHadrCands.begin(); + for ( std::vector::const_iterator pfChargedHadrCand = pfChargedHadrCands.begin(); pfChargedHadrCand != pfChargedHadrCands.end(); ++pfChargedHadrCand ) { double dR = reco::deltaR(tauEta, tauPhi, (*pfChargedHadrCand)->eta(), (*pfChargedHadrCand)->phi()); if ( dR > tauCone && dR < chargeIsolationCone_ ) hadrons.push_back(*pfChargedHadrCand); } - const std::vector& pfGammaCands = tau.pfTauTagInfoRef()->PFGammaCands(); - for ( std::vector::const_iterator pfGammaCand = pfGammaCands.begin(); + const std::vector& pfGammaCands = tau.pfTauTagInfoRef()->PFGammaCands(); + for ( std::vector::const_iterator pfGammaCand = pfGammaCands.begin(); pfGammaCand != pfGammaCands.end(); ++pfGammaCand ) { double dR = reco::deltaR(tauEta, tauPhi, (*pfGammaCand)->eta(), (*pfGammaCand)->phi()); if ( dR > tauCone && dR < gammaIsolationCone_ ) gammas.push_back(*pfGammaCand); } - const std::vector& pfNeutralHadrCands = tau.pfTauTagInfoRef()->PFNeutrHadrCands(); - for ( std::vector::const_iterator pfNeutralHadrCand = pfNeutralHadrCands.begin(); + const std::vector& pfNeutralHadrCands = tau.pfTauTagInfoRef()->PFNeutrHadrCands(); + for ( std::vector::const_iterator pfNeutralHadrCand = pfNeutralHadrCands.begin(); pfNeutralHadrCand != pfNeutralHadrCands.end(); ++pfNeutralHadrCand ) { double dR = reco::deltaR(tauEta, tauPhi, (*pfNeutralHadrCand)->eta(), (*pfNeutralHadrCand)->phi()); if ( dR > tauCone && dR < neutrHadrIsolationCone_ ) hadrons.push_back(*pfNeutralHadrCand); @@ -489,22 +496,22 @@ HPSPFRecoTauAlgorithm::associateIsolationCandidates(reco::PFTau& tau, } else { double tauEta=tau.eta(); double tauPhi=tau.phi(); - const std::vector& pfChargedHadrCands = tau.pfTauTagInfoRef()->PFChargedHadrCands(); - for ( std::vector::const_iterator pfChargedHadrCand = pfChargedHadrCands.begin(); + const std::vector& pfChargedHadrCands = tau.pfTauTagInfoRef()->PFChargedHadrCands(); + for ( std::vector::const_iterator pfChargedHadrCand = pfChargedHadrCands.begin(); pfChargedHadrCand != pfChargedHadrCands.end(); ++pfChargedHadrCand ) { double dR = reco::deltaR(tauEta, tauPhi, (*pfChargedHadrCand)->eta(), (*pfChargedHadrCand)->phi()); if ( dR < chargeIsolationCone_ ) hadrons.push_back(*pfChargedHadrCand); } - const std::vector& pfGammaCands = tau.pfTauTagInfoRef()->PFGammaCands(); - for ( std::vector::const_iterator pfGammaCand = pfGammaCands.begin(); + const std::vector& pfGammaCands = tau.pfTauTagInfoRef()->PFGammaCands(); + for ( std::vector::const_iterator pfGammaCand = pfGammaCands.begin(); pfGammaCand != pfGammaCands.end(); ++pfGammaCand ) { double dR = reco::deltaR(tauEta, tauPhi, (*pfGammaCand)->eta(), (*pfGammaCand)->phi()); if ( dR < gammaIsolationCone_ ) gammas.push_back(*pfGammaCand); } - const std::vector& pfNeutralHadrCands = tau.pfTauTagInfoRef()->PFNeutrHadrCands(); - for ( std::vector::const_iterator pfNeutralHadrCand = pfNeutralHadrCands.begin(); + const std::vector& pfNeutralHadrCands = tau.pfTauTagInfoRef()->PFNeutrHadrCands(); + for ( std::vector::const_iterator pfNeutralHadrCand = pfNeutralHadrCands.begin(); pfNeutralHadrCand != pfNeutralHadrCands.end(); ++pfNeutralHadrCand ) { double dR = reco::deltaR(tauEta, tauPhi, (*pfNeutralHadrCand)->eta(), (*pfNeutralHadrCand)->phi()); if ( dR < neutrHadrIsolationCone_ ) hadrons.push_back(*pfNeutralHadrCand); @@ -512,12 +519,12 @@ HPSPFRecoTauAlgorithm::associateIsolationCandidates(reco::PFTau& tau, } //remove the signal Constituents from the collections - for(std::vector::const_iterator i=tau.signalPFChargedHadrCands().begin();i!=tau.signalPFChargedHadrCands().end();++i) + for(std::vector::const_iterator i=tau.signalChargedHadrCands().begin();i!=tau.signalChargedHadrCands().end();++i) { removeCandidateFromRefVector(*i,hadrons); } - for(std::vector::const_iterator i=tau.signalPFGammaCands().begin();i!=tau.signalPFGammaCands().end();++i) + for(std::vector::const_iterator i=tau.signalGammaCands().begin();i!=tau.signalGammaCands().end();++i) { removeCandidateFromRefVector(*i,gammas); removeCandidateFromRefVector(*i,hadrons);//special case where we included a hadron if the strip! @@ -538,18 +545,18 @@ HPSPFRecoTauAlgorithm::associateIsolationCandidates(reco::PFTau& tau, tau.setisolationPFChargedHadrCandsPtSum(sumPT); tau.setisolationPFGammaCandsEtSum(sumET); - tau.setisolationPFChargedHadrCands(hadrons); - tau.setisolationPFNeutrHadrCands(neutral); - tau.setisolationPFGammaCands(gammas); + tau.setisolationChargedHadrCands(hadrons); + tau.setisolationNeutrHadrCands(neutral); + tau.setisolationGammaCands(gammas); - std::vector isoAll = hadrons; + std::vector isoAll = hadrons; for(unsigned int i=0;i& cands) +HPSPFRecoTauAlgorithm::createMergedLorentzVector(const std::vector& cands) { math::XYZTLorentzVector sum; for(unsigned int i=0;i& vec) +HPSPFRecoTauAlgorithm::removeCandidateFromRefVector(const reco::CandidatePtr& cand,std::vector& vec) { - std::vector newVec; + std::vector newVec; - std::vector::iterator it; + std::vector::iterator it; it = std::find(vec.begin(),vec.end(),cand); if(it!=vec.end()) vec.erase(it); @@ -771,4 +778,3 @@ HPSPFRecoTauAlgorithm::getBestTauCandidate(reco::PFTauCollection& taus) return *it; } - diff --git a/RecoTauTag/RecoTau/src/PFRecoTauAlgorithm.cc b/RecoTauTag/RecoTau/src/PFRecoTauAlgorithm.cc index 4921bab02081c..e946872859a02 100644 --- a/RecoTauTag/RecoTau/src/PFRecoTauAlgorithm.cc +++ b/RecoTauTag/RecoTau/src/PFRecoTauAlgorithm.cc @@ -94,29 +94,32 @@ PFRecoTauAlgorithm::PFRecoTauAlgorithm(const edm::ParameterSet& iConfig):PFRecoT PFTau PFRecoTauAlgorithm::buildPFTau(const PFTauTagInfoRef& myPFTauTagInfoRef, const Vertex& myPV) { - PFJetRef myPFJet=(*myPFTauTagInfoRef).pfjetRef(); // catch a ref to the initial PFJet + JetBaseRef myPFJet=(*myPFTauTagInfoRef).pfjetRef(); // catch a ref to the initial PFJet PFTau myPFTau(std::numeric_limits::quiet_NaN(),myPFJet->p4()); // create the PFTau myPFTau.setpfTauTagInfoRef(myPFTauTagInfoRef); - std::vector myPFCands=(*myPFTauTagInfoRef).PFCands(); + std::vector myPFCands=(*myPFTauTagInfoRef).PFCands(); PFTauElementsOperators myPFTauElementsOperators(myPFTau); double myMatchingConeSize=myPFTauElementsOperators.computeConeSize(myMatchingConeSizeTFormula,MatchingConeSize_min_,MatchingConeSize_max_); - PFCandidatePtr myleadPFChargedCand=myPFTauElementsOperators.leadPFChargedHadrCand(MatchingConeMetric_,myMatchingConeSize,PFTauAlgo_PFCand_minPt_); + CandidatePtr myleadPFChargedCand=myPFTauElementsOperators.leadChargedHadrCand(MatchingConeMetric_,myMatchingConeSize,PFTauAlgo_PFCand_minPt_); // These two quantities always taken from the signal cone - PFCandidatePtr myleadPFNeutralCand; - PFCandidatePtr myleadPFCand; + CandidatePtr myleadPFNeutralCand; + CandidatePtr myleadPFCand; bool myleadPFCand_rectkavailable = false; double myleadPFCand_rectkDZ = 0.; // Determine the SIPT of the lead track if(myleadPFChargedCand.isNonnull()) { - myPFTau.setleadPFChargedHadrCand(myleadPFChargedCand); - TrackRef myleadPFCand_rectk=(*myleadPFChargedCand).trackRef(); + myPFTau.setleadChargedHadrCand(myleadPFChargedCand); + const reco::PFCandidate* pflch = dynamic_cast(myleadPFChargedCand.get()); + if (pflch == nullptr) + 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"; + TrackRef myleadPFCand_rectk=pflch->trackRef(); if(myleadPFCand_rectk.isNonnull()) { myleadPFCand_rectkavailable=true; myleadPFCand_rectkDZ=(*myleadPFCand_rectk).dz(myPV.position()); @@ -137,12 +140,12 @@ PFTau PFRecoTauAlgorithm::buildPFTau(const PFTauTagInfoRef& myPFTauTagInfoRef, c // Compute energy of the PFTau considering only inner constituents // (inner == pfcandidates inside a cone which is equal to the maximum value of the signal cone) // The axis is built about the lead charged hadron - std::vector myTmpPFCandsInSignalCone = + std::vector myTmpPFCandsInSignalCone = myPFTauElementsOperators.PFCandsInCone(tauAxis,TrackerSignalConeMetric_,TrackerSignalConeSize_max_,0.5); math::XYZTLorentzVector tmpLorentzVect(0.,0.,0.,0.); double jetOpeningAngle = 0.0; - for (std::vector::const_iterator iCand = myTmpPFCandsInSignalCone.begin(); + for (std::vector::const_iterator iCand = myTmpPFCandsInSignalCone.begin(); iCand != myTmpPFCandsInSignalCone.end(); iCand++) { //find the maximum opening angle of the jet (now a parameter in available TFormulas) @@ -173,7 +176,7 @@ PFTau PFRecoTauAlgorithm::buildPFTau(const PFTauTagInfoRef& myPFTauTagInfoRef, c myHCALIsolConeSizeTFormula, HCALIsolConeSize_min_, HCALIsolConeSize_max_, transverseEnergy, energy, jetOpeningAngle); // Signal cone collections - std::vector mySignalPFChargedHadrCands, mySignalPFNeutrHadrCands, mySignalPFGammaCands, mySignalPFCands; + std::vector mySignalPFChargedHadrCands, mySignalPFNeutrHadrCands, mySignalPFGammaCands, mySignalPFCands; if (UseChargedHadrCandLeadChargedHadrCand_tksDZconstraint_ && myleadPFCand_rectkavailable) { mySignalPFChargedHadrCands=myPFTauElementsOperators.PFChargedHadrCandsInCone(tauAxis, @@ -186,19 +189,19 @@ PFTau PFRecoTauAlgorithm::buildPFTau(const PFTauTagInfoRef& myPFTauTagInfoRef, c } // Set the Charged hadronics that live in the signal cones - myPFTau.setsignalPFChargedHadrCands(mySignalPFChargedHadrCands); + myPFTau.setsignalChargedHadrCands(mySignalPFChargedHadrCands); // Set the neurtral hadrons that live in the signal cone mySignalPFNeutrHadrCands=myPFTauElementsOperators.PFNeutrHadrCandsInCone(tauAxis, HCALSignalConeMetric_, myHCALSignalConeSize, PFTauAlgo_NeutrHadrCand_minPt_); - myPFTau.setsignalPFNeutrHadrCands(mySignalPFNeutrHadrCands); + myPFTau.setsignalNeutrHadrCands(mySignalPFNeutrHadrCands); // Compute the gammas that live in the signal cone mySignalPFGammaCands=myPFTauElementsOperators.PFGammaCandsInCone(tauAxis, ECALSignalConeMetric_,myECALSignalConeSize,PFTauAlgo_GammaCand_minPt_); - myPFTau.setsignalPFGammaCands(mySignalPFGammaCands); + myPFTau.setsignalGammaCands(mySignalPFGammaCands); // Add charged objects to signal cone, and calculate charge if(!mySignalPFChargedHadrCands.empty()) { @@ -224,9 +227,9 @@ PFTau PFRecoTauAlgorithm::buildPFTau(const PFTauTagInfoRef& myPFTauTagInfoRef, c } mySignalPFCands.push_back(mySignalPFGammaCands[i]); } - myPFTau.setsignalPFCands(mySignalPFCands); + myPFTau.setsignalCands(mySignalPFCands); // Set leading gamma - myPFTau.setleadPFNeutralCand(myleadPFNeutralCand); + myPFTau.setleadNeutralCand(myleadPFNeutralCand); // Logic to determine lead PFCand. If the lead charged object // is above the threshold, take that. If the lead charged object is less @@ -234,13 +237,13 @@ PFTau PFRecoTauAlgorithm::buildPFTau(const PFTauTagInfoRef& myPFTauTagInfoRef, c // take the gamma as the leadPFCand. Otherwise it is null. if(myleadPFChargedCand->pt() > LeadPFCand_minPt_) { - myPFTau.setleadPFCand(myleadPFChargedCand); + myPFTau.setleadCand(myleadPFChargedCand); } else if (maxSignalGammaPt > LeadPFCand_minPt_) { - myPFTau.setleadPFCand(myleadPFNeutralCand); + myPFTau.setleadCand(myleadPFNeutralCand); } // Declare isolation collections - std::vector myUnfilteredIsolPFChargedHadrCands, myIsolPFNeutrHadrCands, myIsolPFGammaCands, myIsolPFCands; + std::vector myUnfilteredIsolPFChargedHadrCands, myIsolPFNeutrHadrCands, myIsolPFGammaCands, myIsolPFCands; // Build unfiltered isolation collection if(UseChargedHadrCandLeadChargedHadrCand_tksDZconstraint_ && myleadPFCand_rectkavailable) { @@ -255,23 +258,23 @@ PFTau PFRecoTauAlgorithm::buildPFTau(const PFTauTagInfoRef& myPFTauTagInfoRef, c // Filter isolation annulus charge dhadrons with additional nHits quality cut // (note that other cuts [pt, chi2, are already cut on]) - std::vector myIsolPFChargedHadrCands; + std::vector myIsolPFChargedHadrCands; myIsolPFChargedHadrCands = TauTagTools::filteredPFChargedHadrCandsByNumTrkHits( myUnfilteredIsolPFChargedHadrCands, ChargedHadrCand_IsolAnnulus_minNhits_); - myPFTau.setisolationPFChargedHadrCands(myIsolPFChargedHadrCands); + myPFTau.setisolationChargedHadrCands(myIsolPFChargedHadrCands); // Fill neutral hadrons myIsolPFNeutrHadrCands = myPFTauElementsOperators.PFNeutrHadrCandsInAnnulus( tauAxis, HCALSignalConeMetric_, myHCALSignalConeSize, HCALIsolConeMetric_, myHCALIsolConeSize, PFTauAlgo_NeutrHadrCand_minPt_); - myPFTau.setisolationPFNeutrHadrCands(myIsolPFNeutrHadrCands); + myPFTau.setisolationNeutrHadrCands(myIsolPFNeutrHadrCands); // Fill gamma candidates myIsolPFGammaCands = myPFTauElementsOperators.PFGammaCandsInAnnulus( tauAxis, ECALSignalConeMetric_, myECALSignalConeSize, ECALIsolConeMetric_, myECALIsolConeSize, PFTauAlgo_GammaCand_minPt_); - myPFTau.setisolationPFGammaCands(myIsolPFGammaCands); + myPFTau.setisolationGammaCands(myIsolPFGammaCands); //Incorporate converted gammas from isolation ellipse into signal ... ELLL //Get pair with in/out elements using the isoPFGammaCandidates set by default @@ -282,20 +285,20 @@ PFTau PFRecoTauAlgorithm::buildPFTau(const PFTauTagInfoRef& myPFTauTagInfoRef, c else rPhi = Rphi_; - std::pair,std::vector> elementsInOutEllipse = + std::pair,std::vector> elementsInOutEllipse = myPFTauElementsOperators.PFGammaCandsInOutEllipse(myIsolPFGammaCands, *myleadPFCand, rPhi, myECALSignalConeSize, MaxEtInEllipse_); - std::vector elementsInEllipse = elementsInOutEllipse.first; - std::vector elementsOutEllipse = elementsInOutEllipse.second; + std::vector elementsInEllipse = elementsInOutEllipse.first; + std::vector elementsOutEllipse = elementsInOutEllipse.second; //add the inside elements to signal PFCandidates and reset signal PFCands - for(std::vector::const_iterator inEllipseIt = elementsInEllipse.begin(); inEllipseIt != elementsInEllipse.end(); inEllipseIt++){ + for(std::vector::const_iterator inEllipseIt = elementsInEllipse.begin(); inEllipseIt != elementsInEllipse.end(); inEllipseIt++){ mySignalPFCands.push_back(*inEllipseIt); mySignalPFGammaCands.push_back(*inEllipseIt); } - myPFTau.setsignalPFCands(mySignalPFCands); + myPFTau.setsignalCands(mySignalPFCands); //redefine isoPFGammaCandidates to be the outside elements myIsolPFGammaCands=elementsOutEllipse; - myPFTau.setisolationPFGammaCands(myIsolPFGammaCands); + myPFTau.setisolationGammaCands(myIsolPFGammaCands); } @@ -318,16 +321,16 @@ PFTau PFRecoTauAlgorithm::buildPFTau(const PFTauTagInfoRef& myPFTauTagInfoRef, c myIsolPFCands.push_back(myIsolPFGammaCands[i]); } myPFTau.setisolationPFGammaCandsEtSum(myIsolPFGammaCands_Etsum); - myPFTau.setisolationPFCands(myIsolPFCands); + myPFTau.setisolationCands(myIsolPFCands); //Making the alternateLorentzVector, i.e. direction with only signal components math::XYZTLorentzVector alternatLorentzVect(0.,0.,0.,0.); - for (std::vector::const_iterator iGammaCand = mySignalPFGammaCands.begin(); + for (std::vector::const_iterator iGammaCand = mySignalPFGammaCands.begin(); iGammaCand != mySignalPFGammaCands.end(); iGammaCand++) { alternatLorentzVect+=(**iGammaCand).p4(); } - for (std::vector::const_iterator iChargedHadrCand = mySignalPFChargedHadrCands.begin(); + for (std::vector::const_iterator iChargedHadrCand = mySignalPFChargedHadrCands.begin(); iChargedHadrCand != mySignalPFChargedHadrCands.end(); iChargedHadrCand++) { alternatLorentzVect+=(**iChargedHadrCand).p4(); } @@ -336,7 +339,7 @@ PFTau PFRecoTauAlgorithm::buildPFTau(const PFTauTagInfoRef& myPFTauTagInfoRef, c // Optionally add the neutral hadrons to the p4 if (putNeutralHadronsInP4_) { - for (std::vector::const_iterator iNeutralHadrCand = mySignalPFNeutrHadrCands.begin(); + for (std::vector::const_iterator iNeutralHadrCand = mySignalPFNeutrHadrCands.begin(); iNeutralHadrCand != mySignalPFNeutrHadrCands.end(); iNeutralHadrCand++) { alternatLorentzVect+=(**iNeutralHadrCand).p4(); } @@ -391,42 +394,48 @@ PFTau PFRecoTauAlgorithm::buildPFTau(const PFTauTagInfoRef& myPFTauTagInfoRef, c //Use the electron rejection only in case there is a charged leading pion if(myleadPFChargedCand.isNonnull()){ - myElectronPreIDOutput = myleadPFChargedCand->mva_e_pi(); + const reco::PFCandidate* pflch = dynamic_cast(myleadPFChargedCand.get()); + if (pflch == nullptr) + 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"; + myElectronPreIDOutput = pflch->mva_e_pi(); - math::XYZPointF myElecTrkEcalPos = myleadPFChargedCand->positionAtECALEntrance(); - myElecTrk = myleadPFChargedCand->trackRef();//Electron candidate + math::XYZPointF myElecTrkEcalPos = pflch->positionAtECALEntrance(); + myElecTrk = pflch->trackRef();//Electron candidate if(myElecTrk.isNonnull()) { //FROM AOD if(DataType_ == "AOD"){ // Corrected Cluster energies for(int i=0;i<(int)myPFCands.size();i++){ - myHCALenergy += myPFCands[i]->hcalEnergy(); - myECALenergy += myPFCands[i]->ecalEnergy(); + const reco::PFCandidate* myPFCand = dynamic_cast(myPFCands[i].get()); + if (myPFCand == nullptr) + 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"; + myHCALenergy += myPFCand->hcalEnergy(); + myECALenergy += myPFCand->ecalEnergy(); math::XYZPointF candPos; - if (myPFCands[i]->particleId()==1 || myPFCands[i]->particleId()==2)//if charged hadron or electron - candPos = myPFCands[i]->positionAtECALEntrance(); + if (myPFCand->particleId()==1 || myPFCand->particleId()==2)//if charged hadron or electron + candPos = myPFCand->positionAtECALEntrance(); else - candPos = math::XYZPointF(myPFCands[i]->px(),myPFCands[i]->py(),myPFCands[i]->pz()); + candPos = math::XYZPointF(myPFCand->px(),myPFCand->py(),myPFCand->pz()); double deltaR = ROOT::Math::VectorUtil::DeltaR(myElecTrkEcalPos,candPos); double deltaPhi = ROOT::Math::VectorUtil::DeltaPhi(myElecTrkEcalPos,candPos); double deltaEta = std::abs(myElecTrkEcalPos.eta()-candPos.eta()); double deltaPhiOverQ = deltaPhi/(double)myElecTrk->charge(); - if (myPFCands[i]->ecalEnergy() >= EcalStripSumE_minClusEnergy_ && deltaEta < EcalStripSumE_deltaEta_ && + if (myPFCand->ecalEnergy() >= EcalStripSumE_minClusEnergy_ && deltaEta < EcalStripSumE_deltaEta_ && deltaPhiOverQ > EcalStripSumE_deltaPhiOverQ_minValue_ && deltaPhiOverQ < EcalStripSumE_deltaPhiOverQ_maxValue_) { - myStripClusterE += myPFCands[i]->ecalEnergy(); + myStripClusterE += myPFCand->ecalEnergy(); } if (deltaR<0.184) { - myHCALenergy3x3 += myPFCands[i]->hcalEnergy(); + myHCALenergy3x3 += myPFCand->hcalEnergy(); } - if (myPFCands[i]->hcalEnergy()>myMaximumHCALPFClusterE) { - myMaximumHCALPFClusterE = myPFCands[i]->hcalEnergy(); + if (myPFCand->hcalEnergy()>myMaximumHCALPFClusterE) { + myMaximumHCALPFClusterE = myPFCand->hcalEnergy(); } - if ((myPFCands[i]->hcalEnergy()*fabs(sin(candPos.Theta())))>myMaximumHCALPFClusterEt) { - myMaximumHCALPFClusterEt = (myPFCands[i]->hcalEnergy()*fabs(sin(candPos.Theta()))); + if ((myPFCand->hcalEnergy()*fabs(sin(candPos.Theta())))>myMaximumHCALPFClusterEt) { + myMaximumHCALPFClusterEt = (myPFCand->hcalEnergy()*fabs(sin(candPos.Theta()))); } } @@ -435,7 +444,10 @@ PFTau PFRecoTauAlgorithm::buildPFTau(const PFTauTagInfoRef& myPFTauTagInfoRef, c std::vector hcalPosV; hcalPosV.clear(); std::vector ecalPosV; ecalPosV.clear(); for(int i=0;i<(int)myPFCands.size();i++){ - const ElementsInBlocks& elts = myPFCands[i]->elementsInBlocks(); + const reco::PFCandidate* myPFCand = dynamic_cast(myPFCands[i].get()); + if (myPFCand == nullptr) + 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"; + const ElementsInBlocks& elts = myPFCand->elementsInBlocks(); for(ElementsInBlocks::const_iterator it=elts.begin(); it!=elts.end(); ++it) { const reco::PFBlock& block = *(it->first); unsigned indexOfElementInBlock = it->second; @@ -529,4 +541,4 @@ PFRecoTauAlgorithm::checkPos(const std::vector& CalPos,const mat } return flag; //return false; -} +} \ No newline at end of file diff --git a/RecoTauTag/RecoTau/src/PFRecoTauClusterVariables.cc b/RecoTauTag/RecoTau/src/PFRecoTauClusterVariables.cc index 25698bae7c227..a6d06e67e854f 100644 --- a/RecoTauTag/RecoTau/src/PFRecoTauClusterVariables.cc +++ b/RecoTauTag/RecoTau/src/PFRecoTauClusterVariables.cc @@ -1,7 +1,7 @@ #include "RecoTauTag/RecoTau/interface/PFRecoTauClusterVariables.h" namespace { - struct PFTau_traits{ typedef reco::PFTau Tau_t; typedef const std::vector& Ret_t; }; + struct PFTau_traits{ typedef reco::PFTau Tau_t; typedef const std::vector& Ret_t; }; struct PATTau_traits{ typedef pat::Tau Tau_t; typedef reco::CandidatePtrVector Ret_t; }; template @@ -10,11 +10,11 @@ namespace { } /// return pf photon candidates that are associated to signal template<> - const std::vector& getGammas_T(const reco::PFTau& tau, bool signal) { + const std::vector& getGammas_T(const reco::PFTau& tau, bool signal) { if (signal){ - return tau.signalPFGammaCands(); + return tau.signalGammaCands(); } - return tau.isolationPFGammaCands(); + return tau.isolationGammaCands(); } template<> @@ -44,11 +44,20 @@ namespace reco { namespace tau { /// return chi2 of the leading track ==> deprecated? <== float lead_track_chi2(const reco::PFTau& tau) { float LeadingTracknormalizedChi2 = 0; - const reco::PFCandidatePtr& leadingPFCharged = tau.leadPFChargedHadrCand() ; - if (leadingPFCharged.isNonnull()) { - reco::TrackRef tref = leadingPFCharged -> trackRef(); - if (tref.isNonnull()) { - LeadingTracknormalizedChi2 = (float)(tref -> normalizedChi2()); + const reco::CandidatePtr& leadingCharged = tau.leadChargedHadrCand(); + if (leadingCharged.isNonnull()) { + const reco::PFCandidate* pfcand = dynamic_cast(leadingCharged.get()); + if (pfcand != nullptr) { + reco::TrackRef tref = pfcand->trackRef(); + if (tref.isNonnull()) { + LeadingTracknormalizedChi2 = tref->normalizedChi2(); + } + } + else { + const pat::PackedCandidate* patcand = dynamic_cast(leadingCharged.get()); + if (patcand != nullptr && patcand->hasTrackDetails()) { + LeadingTracknormalizedChi2 = patcand->pseudoTrack().normalizedChi2(); + } } } return LeadingTracknormalizedChi2; @@ -57,13 +66,17 @@ namespace reco { namespace tau { float eratio(const reco::PFTau& tau) { float ecal_en_in_signal_pf_cands = 0; float hcal_en_in_signal_pf_cands = 0; - for (const auto& signal_cand : tau.signalPFCands()) { - ecal_en_in_signal_pf_cands += signal_cand->ecalEnergy(); - hcal_en_in_signal_pf_cands += signal_cand->hcalEnergy(); + for (const auto& signal_cand : tau.signalCands()) { + const reco::PFCandidate* signal_pfcand = dynamic_cast(signal_cand.get()); + if (signal_pfcand != nullptr) { + ecal_en_in_signal_pf_cands += signal_pfcand->ecalEnergy(); + hcal_en_in_signal_pf_cands += signal_pfcand->hcalEnergy(); + } + // TauReco@MiniAOD: recalculate for PackedCandidate if added to MiniAOD event content } float total = ecal_en_in_signal_pf_cands + hcal_en_in_signal_pf_cands; - if(total==0){ - return -1; + if(total == 0.){ + return -1.; } return ecal_en_in_signal_pf_cands/total; } @@ -71,8 +84,8 @@ namespace reco { namespace tau { float ecal_en_in_signal_cands = tau.ecalEnergy(); float hcal_en_in_signal_cands = tau.hcalEnergy(); float total = ecal_en_in_signal_cands + hcal_en_in_signal_cands; - if(total == 0){ - return -1; + if(total == 0.){ + return -1.; } return ecal_en_in_signal_cands/total; } @@ -132,11 +145,11 @@ namespace reco { namespace tau { /// 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; - for (auto& cand : tau.signalPFGammaCands()) { + for (auto& cand : tau.signalGammaCands()) { if (cand->pt() > 0.5) ++n_photons; } - for (auto& cand : tau.isolationPFGammaCands()) { + for (auto& cand : tau.isolationGammaCands()) { if (cand->pt() > 0.5) ++n_photons; } diff --git a/RecoTauTag/RecoTau/src/PFRecoTauTagInfoAlgorithm.cc b/RecoTauTag/RecoTau/src/PFRecoTauTagInfoAlgorithm.cc index 3a93f26a67707..c38649b18bcd2 100644 --- a/RecoTauTag/RecoTau/src/PFRecoTauTagInfoAlgorithm.cc +++ b/RecoTauTag/RecoTau/src/PFRecoTauTagInfoAlgorithm.cc @@ -26,11 +26,11 @@ PFRecoTauTagInfoAlgorithm::PFRecoTauTagInfoAlgorithm(const edm::ParameterSet& pa tkPVmaxDZ_ = parameters.getParameter("tkPVmaxDZ"); } -PFTauTagInfo PFRecoTauTagInfoAlgorithm::buildPFTauTagInfo(const PFJetRef& thePFJet,const std::vector& thePFCandsInEvent, const TrackRefVector& theTracks,const Vertex& thePV) const { +PFTauTagInfo PFRecoTauTagInfoAlgorithm::buildPFTauTagInfo(const JetBaseRef& thePFJet,const std::vector& thePFCandsInEvent, const TrackRefVector& theTracks,const Vertex& thePV) const { PFTauTagInfo resultExtended; resultExtended.setpfjetRef(thePFJet); - std::vector thePFCands; + std::vector thePFCands; const float jetPhi = (*thePFJet).phi(); const float jetEta = (*thePFJet).eta(); auto dr2 = [jetPhi,jetEta](float phi, float eta) { return reco::deltaR2(jetEta,jetPhi,eta,phi);}; @@ -40,7 +40,7 @@ PFTauTagInfo PFRecoTauTagInfoAlgorithm::buildPFTauTagInfo(const PFJetRef& thePFJ } bool pvIsFake = (thePV.z() < -500.); - std::vector theFilteredPFChargedHadrCands; + std::vector theFilteredPFChargedHadrCands; if (UsePVconstraint_ && !pvIsFake) theFilteredPFChargedHadrCands=TauTagTools::filteredPFChargedHadrCands(thePFCands,ChargedHadrCand_tkminPt_,ChargedHadrCand_tkminPixelHitsn_,ChargedHadrCand_tkminTrackerHitsn_,ChargedHadrCand_tkmaxipt_,ChargedHadrCand_tkmaxChi2_,ChargedHadrCand_tkPVmaxDZ_, thePV, thePV.z()); else theFilteredPFChargedHadrCands=TauTagTools::filteredPFChargedHadrCands(thePFCands,ChargedHadrCand_tkminPt_,ChargedHadrCand_tkminPixelHitsn_,ChargedHadrCand_tkminTrackerHitsn_,ChargedHadrCand_tkmaxipt_,ChargedHadrCand_tkmaxChi2_, thePV); resultExtended.setPFChargedHadrCands(theFilteredPFChargedHadrCands); diff --git a/RecoTauTag/RecoTau/src/PFTauPrimaryVertexProducerBase.cc b/RecoTauTag/RecoTau/src/PFTauPrimaryVertexProducerBase.cc new file mode 100644 index 0000000000000..eedf548ce3252 --- /dev/null +++ b/RecoTauTag/RecoTau/src/PFTauPrimaryVertexProducerBase.cc @@ -0,0 +1,269 @@ +#include "RecoTauTag/RecoTau/interface/PFTauPrimaryVertexProducerBase.h" + +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" +#include "TrackingTools/Records/interface/TransientTrackRecord.h" +#include "RecoVertex/VertexPrimitives/interface/TransientVertex.h" +#include "RecoVertex/AdaptiveVertexFit/interface/AdaptiveVertexFitter.h" + +#include "DataFormats/Common/interface/AssociationVector.h" +#include "DataFormats/Common/interface/RefProd.h" +#include "DataFormats/Common/interface/RefToPtr.h" + +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" + +#include + +PFTauPrimaryVertexProducerBase::PFTauPrimaryVertexProducerBase(const edm::ParameterSet& iConfig): + pftauToken_(consumes >(iConfig.getParameter("PFTauTag"))), + electronToken_(consumes >(iConfig.getParameter("ElectronTag"))), + muonToken_(consumes >(iConfig.getParameter("MuonTag"))), + pvToken_(consumes(iConfig.getParameter("PVTag"))), + beamSpotToken_(consumes(iConfig.getParameter("beamSpot"))), + algorithm_(iConfig.getParameter("Algorithm")), + qualityCutsPSet_(iConfig.getParameter("qualityCuts")), + useBeamSpot_(iConfig.getParameter("useBeamSpot")), + useSelectedTaus_(iConfig.getParameter("useSelectedTaus")), + removeMuonTracks_(iConfig.getParameter("RemoveMuonTracks")), + removeElectronTracks_(iConfig.getParameter("RemoveElectronTracks")) +{ + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + std::vector discriminators = iConfig.getParameter >("discriminators"); + // Build each of our cuts + for(auto const& pset : discriminators) { + DiscCutPair* newCut = new DiscCutPair(); + newCut->inputToken_ =consumes(pset.getParameter("discriminator")); + + if ( pset.existsAs("selectionCut") ) newCut->cutFormula_ = new TFormula("selectionCut", pset.getParameter("selectionCut").data()); + else newCut->cut_ = pset.getParameter("selectionCut"); + discriminators_.push_back(newCut); + } + // Build a string cut if desired + if (iConfig.exists("cut")) cut_.reset(new StringCutObjectSelector(iConfig.getParameter( "cut" ))); + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + produces > >(); + produces("PFTauPrimaryVertices"); + + vertexAssociator_.reset(new reco::tau::RecoTauVertexAssociator(qualityCutsPSet_,consumesCollector())); +} + +PFTauPrimaryVertexProducerBase::~PFTauPrimaryVertexProducerBase(){} + +namespace { + edm::Ptr getTrack(const reco::Candidate& cand) { + const reco::PFCandidate* pfCandPtr = dynamic_cast(&cand); + if (pfCandPtr) { + if ( pfCandPtr->trackRef().isNonnull() ) return edm::refToPtr(pfCandPtr->trackRef()); + else if ( pfCandPtr->gsfTrackRef().isNonnull() ) return edm::refToPtr(pfCandPtr->gsfTrackRef()); + else return edm::Ptr(); + } + const pat::PackedCandidate* pCand = dynamic_cast(&cand); + if (pCand && pCand->hasTrackDetails()) { + const reco::TrackBase* trkPtr = pCand->bestTrack(); + return edm::Ptr(trkPtr,0); + } + return edm::Ptr(); + } +} + +void PFTauPrimaryVertexProducerBase::produce(edm::Event& iEvent,const edm::EventSetup& iSetup){ + + beginEvent(iEvent, iSetup); + + // Obtain Collections + edm::ESHandle transTrackBuilder; + iSetup.get().get("TransientTrackBuilder",transTrackBuilder); + + edm::Handle > pfTaus; + iEvent.getByToken(pftauToken_,pfTaus); + + edm::Handle > electrons; + if(removeElectronTracks_) iEvent.getByToken(electronToken_,electrons); + + edm::Handle > muons; + if(removeMuonTracks_) iEvent.getByToken(muonToken_,muons); + + edm::Handle vertices; + iEvent.getByToken(pvToken_,vertices); + + edm::Handle beamSpot; + if(useBeamSpot_) iEvent.getByToken(beamSpotToken_,beamSpot); + + // Set Association Map + auto avPFTauPV = std::make_unique>>(reco::PFTauRefProd(pfTaus)); + auto vertexCollection_out = std::make_unique(); + reco::VertexRefProd vertexRefProd_out = iEvent.getRefBeforePut("PFTauPrimaryVertices"); + + // Load each discriminator + for(auto& disc : discriminators_) { + edm::Handle discr; + iEvent.getByToken(disc->inputToken_, discr); + disc->discr_ = &(*discr); + } + + // Set event for VerexAssociator if needed + if(useInputPV==algorithm_) + vertexAssociator_->setEvent(iEvent); + + // For each Tau Run Algorithim + if(pfTaus.isValid()){ + for(reco::PFTauCollection::size_type iPFTau = 0; iPFTau < pfTaus->size(); iPFTau++) { + reco::PFTauRef tau(pfTaus, iPFTau); + reco::VertexRef thePVRef; + if(useInputPV==algorithm_){ + thePVRef = vertexAssociator_->associatedVertex(*tau); + } + else if(useFrontPV==algorithm_){ + thePVRef = reco::VertexRef(vertices,0); + } + reco::Vertex thePV = *thePVRef; + /////////////////////// + // Check if it passed all the discrimiantors + bool passed(true); + for(auto const& disc : discriminators_) { + // Check this discriminator passes + bool passedDisc = true; + if ( disc->cutFormula_ )passedDisc = (disc->cutFormula_->Eval((*disc->discr_)[tau]) > 0.5); + else passedDisc = ((*disc->discr_)[tau] > disc->cut_); + if ( !passedDisc ){passed = false; break;} + } + if (passed && cut_.get()){passed = (*cut_)(*tau);} + if (passed){ + std::vector > signalTracks; + for(reco::PFTauCollection::size_type jPFTau = 0; jPFTau < pfTaus->size(); jPFTau++) { + if(useSelectedTaus_ || iPFTau==jPFTau){ + reco::PFTauRef pfTauRef(pfTaus, jPFTau); + /////////////////////////////////////////////////////////////////////////////////////////////// + // Get tracks from PFTau daughters + for(const auto& pfcand : pfTauRef->signalChargedHadrCands()) { + if(pfcand.isNull()) continue; + const edm::Ptr& trackPtr = getTrack(*pfcand); + if(trackPtr.isNonnull()) signalTracks.push_back(trackPtr); + } + } + } + // Get Muon tracks + if(removeMuonTracks_){ + if(muons.isValid()) { + for(const auto& muon: *muons){ + if(muon.track().isNonnull()) signalTracks.push_back(edm::refToPtr(muon.track())); + } + } + } + // Get Electron Tracks + if(removeElectronTracks_){ + if(electrons.isValid()) { + for(const auto& electron: *electrons){ + if(electron.track().isNonnull()) signalTracks.push_back(edm::refToPtr(electron.track())); + if(electron.gsfTrack().isNonnull()) signalTracks.push_back(edm::refToPtr(electron.gsfTrack())); + } + } + } + /////////////////////////////////////////////////////////////////////////////////////////////// + // Get Non-Tau tracks + std::vector nonTauTracks; + nonTauTracksInPV(thePVRef,signalTracks,nonTauTracks); + + /////////////////////////////////////////////////////////////////////////////////////////////// + // Refit the vertex + TransientVertex transVtx; + std::vector transTracks; + for(const auto track: nonTauTracks){ + transTracks.push_back(transTrackBuilder->build(*track)); + } + bool fitOK(true); + if ( transTracks.size() >= 2 ) { + AdaptiveVertexFitter avf; + avf.setWeightThreshold(0.1); //weight per track. allow almost every fit, else --> exception + if ( !useBeamSpot_ ){ + transVtx = avf.vertex(transTracks); + } else { + transVtx = avf.vertex(transTracks, *beamSpot); + } + } else fitOK = false; + if ( fitOK ) thePV = transVtx; + } + reco::VertexRef vtxRef = reco::VertexRef(vertexRefProd_out, vertexCollection_out->size()); + vertexCollection_out->push_back(thePV); + avPFTauPV->setValue(iPFTau, vtxRef); + } + } + iEvent.put(std::move(vertexCollection_out),"PFTauPrimaryVertices"); + iEvent.put(std::move(avPFTauPV)); +} + +edm::ParameterSetDescription PFTauPrimaryVertexProducerBase::getDescriptionsBase() { + // PFTauPrimaryVertexProducerBase + edm::ParameterSetDescription desc; + + { + edm::ParameterSetDescription vpsd1; + vpsd1.add("discriminator"); + vpsd1.add("selectionCut"); + desc.addVPSet("discriminators", vpsd1); + } + + { + edm::ParameterSetDescription pset_signalQualityCuts; + pset_signalQualityCuts.add("maxDeltaZ", 0.4); + pset_signalQualityCuts.add("minTrackPt", 0.5); + pset_signalQualityCuts.add("minTrackVertexWeight", -1.0); + pset_signalQualityCuts.add("maxTrackChi2", 100.0); + pset_signalQualityCuts.add("minTrackPixelHits", 0); + pset_signalQualityCuts.add("minGammaEt", 1.0); + pset_signalQualityCuts.add("minTrackHits", 3); + pset_signalQualityCuts.add("minNeutralHadronEt", 30.0); + pset_signalQualityCuts.add("maxTransverseImpactParameter", 0.1); + pset_signalQualityCuts.addOptional("useTracksInsteadOfPFHadrons"); + + edm::ParameterSetDescription pset_vxAssocQualityCuts; + pset_vxAssocQualityCuts.add("minTrackPt", 0.5); + pset_vxAssocQualityCuts.add("minTrackVertexWeight", -1.0); + pset_vxAssocQualityCuts.add("maxTrackChi2", 100.0); + pset_vxAssocQualityCuts.add("minTrackPixelHits", 0); + pset_vxAssocQualityCuts.add("minGammaEt", 1.0); + pset_vxAssocQualityCuts.add("minTrackHits", 3); + pset_vxAssocQualityCuts.add("maxTransverseImpactParameter", 0.1); + pset_vxAssocQualityCuts.addOptional("useTracksInsteadOfPFHadrons"); + + edm::ParameterSetDescription pset_isolationQualityCuts; + pset_isolationQualityCuts.add("maxDeltaZ", 0.2); + pset_isolationQualityCuts.add("minTrackPt", 1.0); + pset_isolationQualityCuts.add("minTrackVertexWeight", -1.0); + pset_isolationQualityCuts.add("maxTrackChi2", 100.0); + pset_isolationQualityCuts.add("minTrackPixelHits", 0); + pset_isolationQualityCuts.add("minGammaEt", 1.5); + pset_isolationQualityCuts.add("minTrackHits", 8); + pset_isolationQualityCuts.add("maxTransverseImpactParameter", 0.03); + pset_isolationQualityCuts.addOptional("useTracksInsteadOfPFHadrons"); + + edm::ParameterSetDescription pset_qualityCuts; + pset_qualityCuts.add("signalQualityCuts", pset_signalQualityCuts); + pset_qualityCuts.add("vxAssocQualityCuts", pset_vxAssocQualityCuts); + pset_qualityCuts.add("isolationQualityCuts", pset_isolationQualityCuts); + pset_qualityCuts.add("leadingTrkOrPFCandOption", "leadPFCand"); + pset_qualityCuts.add("pvFindingAlgo", "closestInDeltaZ"); + pset_qualityCuts.add("primaryVertexSrc", edm::InputTag("offlinePrimaryVertices")); + pset_qualityCuts.add("vertexTrackFiltering", false); + pset_qualityCuts.add("recoverLeadingTrk", false); + + desc.add("qualityCuts", pset_qualityCuts); + } + + desc.add("cut", "pt > 18.0 & abs(eta)<2.3"); + desc.add("Algorithm", 0); + desc.add("RemoveElectronTracks", false); + desc.add("RemoveMuonTracks", false); + desc.add("useBeamSpot", true); + desc.add("useSelectedTaus", false); + desc.add("beamSpot", edm::InputTag("offlineBeamSpot")); + desc.add("ElectronTag", edm::InputTag("MyElectrons")); + desc.add("PFTauTag", edm::InputTag("hpsPFTauProducer")); + desc.add("MuonTag", edm::InputTag("MyMuons")); + desc.add("PVTag", edm::InputTag("offlinePrimaryVertices")); + + return desc; +} diff --git a/RecoTauTag/RecoTau/src/RecoTauBinnedIsolationPlugin.cc b/RecoTauTag/RecoTau/src/RecoTauBinnedIsolationPlugin.cc index 89317bad0d290..784ac07a6999f 100644 --- a/RecoTauTag/RecoTau/src/RecoTauBinnedIsolationPlugin.cc +++ b/RecoTauTag/RecoTau/src/RecoTauBinnedIsolationPlugin.cc @@ -1,6 +1,6 @@ #include "RecoTauTag/RecoTau/interface/RecoTauBinnedIsolationPlugin.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/Candidate/interface/CandidateFwd.h" +#include "DataFormats/Candidate/interface/Candidate.h" #include "DataFormats/VertexReco/interface/VertexFwd.h" #include "DataFormats/VertexReco/interface/Vertex.h" @@ -72,7 +72,7 @@ std::vector RecoTauDiscriminationBinnedIsolation::operator()( // Create our output spectrum std::vector output(bins->size(), 0.0); // Get the desired isolation objects - std::vector isoObjects = extractIsoObjects(tau); + std::vector isoObjects = extractIsoObjects(tau); // Loop over each and histogram their pt for(auto const& cand : isoObjects) { int highestBinLessThan = -1; diff --git a/RecoTauTag/RecoTau/src/RecoTauCommonUtilities.cc b/RecoTauTag/RecoTau/src/RecoTauCommonUtilities.cc index 1ffafeb4f086b..671bc413353e0 100644 --- a/RecoTauTag/RecoTau/src/RecoTauCommonUtilities.cc +++ b/RecoTauTag/RecoTau/src/RecoTauCommonUtilities.cc @@ -1,69 +1,102 @@ #include "RecoTauTag/RecoTau/interface/RecoTauCommonUtilities.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "DataFormats/Candidate/interface/CandidateFwd.h" +#include "DataFormats/Candidate/interface/Candidate.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" -#include "DataFormats/JetReco/interface/PFJet.h" +#include "DataFormats/JetReco/interface/Jet.h" #include "DataFormats/VertexReco/interface/Vertex.h" +#include "CommonTools/BaseParticlePropagator/interface/BaseParticlePropagator.h" + #include -typedef std::vector PFCandPtrs; -typedef PFCandPtrs::iterator PFCandIter; +typedef std::vector CandPtrs; +typedef CandPtrs::iterator CandIter; namespace reco { namespace tau { -std::vector +namespace { + // Re-implemented from PFCandidate.cc + int translateTypeToAbsPdgId(int type) { + switch( type ) { + case reco::PFCandidate::h: return 211; // pi+ + case reco::PFCandidate::e: return 11; + case reco::PFCandidate::mu: return 13; + case reco::PFCandidate::gamma: return 22; + case reco::PFCandidate::h0: return 130; // K_L0 + case reco::PFCandidate::h_HF: return 1; // dummy pdg code + case reco::PFCandidate::egamma_HF: return 2; // dummy pdg code + case reco::PFCandidate::X: + default: return 0; + } + } +} +std::vector flattenPiZeros(const std::vector::const_iterator& piZerosBegin, const std::vector::const_iterator& piZerosEnd) { - std::vector output; + std::vector output; for(std::vector::const_iterator piZero = piZerosBegin; piZero != piZerosEnd; ++piZero) { for(size_t iDaughter = 0; iDaughter < piZero->numberOfDaughters(); ++iDaughter) { - output.push_back(PFCandidatePtr(piZero->daughterPtr(iDaughter))); + output.push_back(CandidatePtr(piZero->daughterPtr(iDaughter))); } } return output; } -std::vector +std::vector flattenPiZeros(const std::vector& piZeros) { return flattenPiZeros(piZeros.begin(), piZeros.end()); } -std::vector pfCandidates(const reco::PFJet& jet, +std::vector pfCandidates(const reco::Jet& jet, int particleId, bool sort) { - PFCandPtrs pfCands = jet.getPFConstituents(); - PFCandPtrs selectedPFCands = filterPFCandidates( - pfCands.begin(), pfCands.end(), particleId, sort); + return pfCandidatesByPdgId(jet, translateTypeToAbsPdgId(particleId), sort); +} + +std::vector pfCandidates(const Jet& jet, + const std::vector& particleIds, + bool sort) { + std::vector pdgIds; + for (auto particleId : particleIds) + pdgIds.push_back(translateTypeToAbsPdgId(particleId)); + return pfCandidatesByPdgId(jet, pdgIds, sort); +} + +std::vector pfCandidatesByPdgId(const reco::Jet& jet, + int pdgId, bool sort) { + CandPtrs pfCands = jet.daughterPtrVector(); + CandPtrs selectedPFCands = filterPFCandidates( + pfCands.begin(), pfCands.end(), pdgId, sort); return selectedPFCands; } -std::vector pfCandidates(const reco::PFJet& jet, - const std::vector& particleIds, bool sort) { - PFCandPtrs&& pfCands = jet.getPFConstituents(); - PFCandPtrs output; +std::vector pfCandidatesByPdgId(const reco::Jet& jet, + const std::vector& pdgIds, bool sort) { + const CandPtrs& pfCands = jet.daughterPtrVector(); + CandPtrs output; // Get each desired candidate type, unsorted for now - for(std::vector::const_iterator particleId = particleIds.begin(); - particleId != particleIds.end(); ++particleId) { - PFCandPtrs&& selectedPFCands = filterPFCandidates(pfCands.begin(), pfCands.end(), *particleId, false); + for(std::vector::const_iterator pdgId = pdgIds.begin(); + pdgId != pdgIds.end(); ++pdgId) { + CandPtrs&& selectedPFCands = filterPFCandidates(pfCands.begin(), pfCands.end(), *pdgId, false); output.insert(output.end(), selectedPFCands.begin(), selectedPFCands.end()); } if (sort) std::sort(output.begin(), output.end(), SortPFCandsDescendingPt()); return output; } -std::vector pfGammas(const reco::PFJet& jet, bool sort) { - return pfCandidates(jet, reco::PFCandidate::gamma, sort); +std::vector pfGammas(const reco::Jet& jet, bool sort) { + return pfCandidates(jet, 22, sort); } -std::vector pfChargedCands(const reco::PFJet& jet, +std::vector pfChargedCands(const reco::Jet& jet, bool sort) { - PFCandPtrs&& pfCands = jet.getPFConstituents(); - PFCandPtrs output; - PFCandPtrs&& mus = filterPFCandidates(pfCands.begin(), pfCands.end(), reco::PFCandidate::mu, false); - PFCandPtrs&& es = filterPFCandidates(pfCands.begin(), pfCands.end(), reco::PFCandidate::e, false); - PFCandPtrs&& chs = filterPFCandidates(pfCands.begin(), pfCands.end(), reco::PFCandidate::h, false); + const CandPtrs& pfCands = jet.daughterPtrVector(); + CandPtrs output; + CandPtrs&& mus = filterPFCandidates(pfCands.begin(), pfCands.end(), 13, false); + CandPtrs&& es = filterPFCandidates(pfCands.begin(), pfCands.end(), 11, false); + CandPtrs&& chs = filterPFCandidates(pfCands.begin(), pfCands.end(), 211, false); output.reserve(mus.size() + es.size() + chs.size()); output.insert(output.end(), mus.begin(), mus.end()); output.insert(output.end(), es.begin(), es.end()); @@ -72,4 +105,29 @@ std::vector pfChargedCands(const reco::PFJet& jet, return output; } +math::XYZPointF atECALEntrance(const reco::Candidate* part, double bField) { + const reco::PFCandidate* pfCand = dynamic_cast(part); + if (pfCand) + return pfCand->positionAtECALEntrance(); + + math::XYZPointF pos; + BaseParticlePropagator theParticle = + BaseParticlePropagator(RawParticle(math::XYZTLorentzVector(part->px(), + part->py(), + part->pz(), + part->energy()), + math::XYZTLorentzVector(part->vertex().x(), + part->vertex().y(), + part->vertex().z(), + 0.)), + part->charge(), + 0.,0.,bField); + theParticle.propagateToEcalEntrance(false); + if(theParticle.getSuccess()!=0){ + pos = math::XYZPointF(theParticle.particle().vertex()); + } + return pos; +} + + } } diff --git a/RecoTauTag/RecoTau/src/RecoTauConstructor.cc b/RecoTauTag/RecoTau/src/RecoTauConstructor.cc index 9443c74c56336..866ee095a5dcb 100644 --- a/RecoTauTag/RecoTau/src/RecoTauConstructor.cc +++ b/RecoTauTag/RecoTau/src/RecoTauConstructor.cc @@ -9,7 +9,7 @@ namespace reco::tau { -RecoTauConstructor::RecoTauConstructor(const PFJetRef& jet, const edm::Handle& pfCands, +RecoTauConstructor::RecoTauConstructor(const JetBaseRef& jet, const edm::Handle >& pfCands, bool copyGammasFromPiZeros, const StringObjectFunction* signalConeSize, double minAbsPhotonSumPt_insideSignalCone, double minRelPhotonSumPt_insideSignalCone, @@ -27,22 +27,22 @@ RecoTauConstructor::RecoTauConstructor(const PFJetRef& jet, const edm::HandleselectedSignalPFChargedHadrCands_; + &tau_->selectedSignalChargedHadrCands_; collections_[std::make_pair(kSignal, kGamma)] = - &tau_->selectedSignalPFGammaCands_; + &tau_->selectedSignalGammaCands_; collections_[std::make_pair(kSignal, kNeutralHadron)] = - &tau_->selectedSignalPFNeutrHadrCands_; + &tau_->selectedSignalNeutrHadrCands_; collections_[std::make_pair(kSignal, kAll)] = - &tau_->selectedSignalPFCands_; + &tau_->selectedSignalCands_; collections_[std::make_pair(kIsolation, kChargedHadron)] = - &tau_->selectedIsolationPFChargedHadrCands_; + &tau_->selectedIsolationChargedHadrCands_; collections_[std::make_pair(kIsolation, kGamma)] = - &tau_->selectedIsolationPFGammaCands_; + &tau_->selectedIsolationGammaCands_; collections_[std::make_pair(kIsolation, kNeutralHadron)] = - &tau_->selectedIsolationPFNeutrHadrCands_; + &tau_->selectedIsolationNeutrHadrCands_; collections_[std::make_pair(kIsolation, kAll)] = - &tau_->selectedIsolationPFCands_; + &tau_->selectedIsolationCands_; // Build our temporary sorted collections, since you can't use stl sorts on // RefVectors @@ -55,22 +55,7 @@ RecoTauConstructor::RecoTauConstructor(const PFJetRef& jet, const edm::HandlesetjetRef(jet); } -void RecoTauConstructor::addPFCand(Region region, ParticleType type, const PFCandidateRef& ref, bool skipAddToP4) { - LogDebug("TauConstructorAddPFCand") << " region = " << region << ", type = " << type << ": Pt = " << ref->pt() << ", eta = " << ref->eta() << ", phi = " << ref->phi(); - if ( region == kSignal ) { - // Keep track of the four vector of the signal vector products added so far. - // If a photon add it if we are not using PiZeros to build the gammas - if ( ((type != kGamma) || !copyGammas_) && !skipAddToP4 ) { - LogDebug("TauConstructorAddPFCand") << "--> adding PFCand to tauP4." ; - p4_ += ref->p4(); - } - } - getSortedCollection(region, type)->push_back(edm::refToPtr(ref)); - // Add to global collection - getSortedCollection(region, kAll)->push_back(edm::refToPtr(ref)); -} - -void RecoTauConstructor::addPFCand(Region region, ParticleType type, const PFCandidatePtr& ptr, bool skipAddToP4) { +void RecoTauConstructor::addPFCand(Region region, ParticleType type, const CandidatePtr& ptr, bool skipAddToP4) { LogDebug("TauConstructorAddPFCand") << " region = " << region << ", type = " << type << ": Pt = " << ptr->pt() << ", eta = " << ptr->eta() << ", phi = " << ptr->phi(); if ( region == kSignal ) { // Keep track of the four vector of the signal vector products added so far. @@ -99,26 +84,27 @@ void RecoTauConstructor::reserveTauChargedHadron(Region region, size_t size) { if ( region == kSignal ) { tau_->signalTauChargedHadronCandidatesRestricted().reserve(size); - tau_->selectedSignalPFChargedHadrCands_.reserve(size); + tau_->selectedSignalChargedHadrCands_.reserve(size); } else { tau_->isolationTauChargedHadronCandidatesRestricted().reserve(size); - tau_->selectedIsolationPFChargedHadrCands_.reserve(size); + tau_->selectedIsolationChargedHadrCands_.reserve(size); } } namespace { - void checkOverlap(const PFCandidatePtr& neutral, const std::vector& pfGammas, bool& isUnique) + void checkOverlap(const CandidatePtr& neutral, const std::vector& pfGammas, bool& isUnique) { LogDebug("TauConstructorCheckOverlap") << " pfGammas: #entries = " << pfGammas.size(); - for ( std::vector::const_iterator pfGamma = pfGammas.begin(); + for ( std::vector::const_iterator pfGamma = pfGammas.begin(); pfGamma != pfGammas.end(); ++pfGamma ) { LogDebug("TauConstructorCheckOverlap") << "pfGamma = " << pfGamma->id() << ":" << pfGamma->key(); - if ( (*pfGamma) == neutral ) isUnique = false; + if ( (*pfGamma).refCore() == neutral.refCore() && (*pfGamma).key() == neutral.key() ) isUnique = false; } } - void checkOverlap(const PFCandidatePtr& neutral, const std::vector& piZeros, bool& isUnique) + + void checkOverlap(const CandidatePtr& neutral, const std::vector& piZeros, bool& isUnique) { LogDebug("TauConstructorCheckOverlap") << " piZeros: #entries = " << piZeros.size(); for ( std::vector::const_iterator piZero = piZeros.begin(); @@ -137,9 +123,9 @@ void RecoTauConstructor::addTauChargedHadron(Region region, const PFRecoTauCharg { LogDebug("TauConstructorAddChH") << " region = " << region << ": Pt = " << chargedHadron.pt() << ", eta = " << chargedHadron.eta() << ", phi = " << chargedHadron.phi(); // CV: need to make sure that PFGammas merged with ChargedHadrons are not part of PiZeros - const std::vector& neutrals = chargedHadron.getNeutralPFCandidates(); - std::vector neutrals_cleaned; - for ( std::vector::const_iterator neutral = neutrals.begin(); + const std::vector& neutrals = chargedHadron.getNeutralPFCandidates(); + std::vector neutrals_cleaned; + for ( std::vector::const_iterator neutral = neutrals.begin(); neutral != neutrals.end(); ++neutral ) { LogDebug("TauConstructorAddChH") << "neutral = " << neutral->id() << ":" << neutral->key(); bool isUnique = true; @@ -161,25 +147,25 @@ void RecoTauConstructor::addTauChargedHadron(Region region, const PFRecoTauCharg tau_->signalTauChargedHadronCandidatesRestricted().push_back(chargedHadron_cleaned); p4_ += chargedHadron_cleaned.p4(); if ( chargedHadron_cleaned.getChargedPFCandidate().isNonnull() ) { - addPFCand(kSignal, kChargedHadron, chargedHadron_cleaned.getChargedPFCandidate(), true); + addPFCand(kSignal, kChargedHadron, convertToPtr(chargedHadron_cleaned.getChargedPFCandidate()), true); } - const std::vector& neutrals = chargedHadron_cleaned.getNeutralPFCandidates(); - for ( std::vector::const_iterator neutral = neutrals.begin(); + const std::vector& neutrals = chargedHadron_cleaned.getNeutralPFCandidates(); + for ( std::vector::const_iterator neutral = neutrals.begin(); neutral != neutrals.end(); ++neutral ) { - if ( (*neutral)->particleId() == reco::PFCandidate::gamma ) addPFCand(kSignal, kGamma, *neutral, true); - else if ( (*neutral)->particleId() == reco::PFCandidate::h0 ) addPFCand(kSignal, kNeutralHadron, *neutral, true); + if ( std::abs((*neutral)->pdgId()) == 22 ) addPFCand(kSignal, kGamma, convertToPtr(*neutral), true); + else if ( std::abs((*neutral)->pdgId()) == 130 ) addPFCand(kSignal, kNeutralHadron, convertToPtr(*neutral), true); }; } else { tau_->isolationTauChargedHadronCandidatesRestricted().push_back(chargedHadron_cleaned); if ( chargedHadron_cleaned.getChargedPFCandidate().isNonnull() ) { - if ( chargedHadron_cleaned.getChargedPFCandidate()->particleId() == reco::PFCandidate::h ) addPFCand(kIsolation, kChargedHadron, chargedHadron_cleaned.getChargedPFCandidate()); - else if ( chargedHadron_cleaned.getChargedPFCandidate()->particleId() == reco::PFCandidate::h0 ) addPFCand(kIsolation, kNeutralHadron, chargedHadron_cleaned.getChargedPFCandidate()); + if ( std::abs(chargedHadron_cleaned.getChargedPFCandidate()->pdgId()) == 211 ) addPFCand(kIsolation, kChargedHadron, convertToPtr(chargedHadron_cleaned.getChargedPFCandidate())); + else if ( std::abs(chargedHadron_cleaned.getChargedPFCandidate()->pdgId()) == 130 ) addPFCand(kIsolation, kNeutralHadron, convertToPtr(chargedHadron_cleaned.getChargedPFCandidate())); } - const std::vector& neutrals = chargedHadron_cleaned.getNeutralPFCandidates(); - for ( std::vector::const_iterator neutral = neutrals.begin(); + const std::vector& neutrals = chargedHadron_cleaned.getNeutralPFCandidates(); + for ( std::vector::const_iterator neutral = neutrals.begin(); neutral != neutrals.end(); ++neutral ) { - if ( (*neutral)->particleId() == reco::PFCandidate::gamma ) addPFCand(kIsolation, kGamma, *neutral); - else if ( (*neutral)->particleId() == reco::PFCandidate::h0 ) addPFCand(kIsolation, kNeutralHadron, *neutral); + if ( std::abs((*neutral)->pdgId()) == 22 ) addPFCand(kIsolation, kGamma, convertToPtr(*neutral)); + else if ( std::abs((*neutral)->pdgId()) == 130 ) addPFCand(kIsolation, kNeutralHadron, convertToPtr(*neutral)); }; } } @@ -219,7 +205,7 @@ void RecoTauConstructor::addPiZero(Region region, const RecoTauPiZero& piZero) } } -std::vector* +std::vector* RecoTauConstructor::getCollection(Region region, ParticleType type) { return collections_[std::make_pair(region, type)]; } @@ -230,8 +216,8 @@ RecoTauConstructor::getSortedCollection(Region region, ParticleType type) { } // Trivial converter needed for polymorphism -PFCandidatePtr RecoTauConstructor::convertToPtr( - const PFCandidatePtr& pfPtr) const { +CandidatePtr RecoTauConstructor::convertToPtr( + const CandidatePtr& pfPtr) const { return pfPtr; } @@ -248,20 +234,12 @@ void checkMatchedProductIds(const T1& t1, const T2& t2) { } } -PFCandidatePtr RecoTauConstructor::convertToPtr( - const PFCandidateRef& pfRef) const { - if(pfRef.isNonnull()) { - checkMatchedProductIds(pfRef, pfCands_); - return PFCandidatePtr(pfCands_, pfRef.key()); - } else return PFCandidatePtr(); -} - // Convert from a CandidateRef to a Ptr -PFCandidatePtr RecoTauConstructor::convertToPtr( - const CandidatePtr& candPtr) const { +CandidatePtr RecoTauConstructor::convertToPtr( + const PFCandidatePtr& candPtr) const { if(candPtr.isNonnull()) { checkMatchedProductIds(candPtr, pfCands_); - return PFCandidatePtr(pfCands_, candPtr.key()); + return CandidatePtr(pfCands_, candPtr.key()); } else return PFCandidatePtr(); } @@ -295,9 +273,9 @@ void RecoTauConstructor::sortAndCopyIntoTau() { SortedListPtr sortedCollection = sortedCollections_[colkey.first]; std::sort(sortedCollection->begin(), sortedCollection->end(), - ptDescendingPtr); + ptDescendingPtr); // Copy into the real tau collection - for ( std::vector::const_iterator particle = sortedCollection->begin(); + for ( std::vector::const_iterator particle = sortedCollection->begin(); particle != sortedCollection->end(); ++particle ) { colkey.second->push_back(*particle); } @@ -416,30 +394,30 @@ std::auto_ptr RecoTauConstructor::get(bool setupLeadingObjects) getCollection(kSignal, kGamma)->end()) / tau_->pt()); if ( setupLeadingObjects ) { - typedef std::vector::const_iterator Iter; + typedef std::vector::const_iterator Iter; // Find the highest PT object in the signal cone - Iter leadingCand = leadPFCand( + Iter leadingCand = leadCand( getCollection(kSignal, kAll)->begin(), getCollection(kSignal, kAll)->end()); if ( leadingCand != getCollection(kSignal, kAll)->end() ) - tau_->setleadPFCand(*leadingCand); + tau_->setleadCand(*leadingCand); // Hardest charged object in signal cone - Iter leadingChargedCand = leadPFCand( + Iter leadingChargedCand = leadCand( getCollection(kSignal, kChargedHadron)->begin(), getCollection(kSignal, kChargedHadron)->end()); if ( leadingChargedCand != getCollection(kSignal, kChargedHadron)->end() ) - tau_->setleadPFChargedHadrCand(*leadingChargedCand); + tau_->setleadChargedHadrCand(*leadingChargedCand); // Hardest gamma object in signal cone - Iter leadingGammaCand = leadPFCand( + Iter leadingGammaCand = leadCand( getCollection(kSignal, kGamma)->begin(), getCollection(kSignal, kGamma)->end()); if(leadingGammaCand != getCollection(kSignal, kGamma)->end()) - tau_->setleadPFNeutralCand(*leadingGammaCand); + tau_->setleadNeutralCand(*leadingGammaCand); } return tau_; } diff --git a/RecoTauTag/RecoTau/src/RecoTauDiscriminantFunctions.cc b/RecoTauTag/RecoTau/src/RecoTauDiscriminantFunctions.cc index 480bdc1629774..e947cf463a4c6 100644 --- a/RecoTauTag/RecoTau/src/RecoTauDiscriminantFunctions.cc +++ b/RecoTauTag/RecoTau/src/RecoTauDiscriminantFunctions.cc @@ -1,8 +1,8 @@ #include "RecoTauTag/RecoTau/interface/RecoTauDiscriminantFunctions.h" #include "DataFormats/Math/interface/deltaR.h" #include "DataFormats/Math/interface/angle.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "DataFormats/Candidate/interface/CandidateFwd.h" #include "DataFormats/TauReco/interface/RecoTauPiZero.h" #include @@ -36,22 +36,22 @@ class DeltaRToAxis { } // end helper functions -PFCandidatePtr mainTrack(Tau tau) { - if (tau.signalPFChargedHadrCands().size() == 3) { +CandidatePtr mainTrack(Tau tau) { + if (tau.signalChargedHadrCands().size() == 3) { for (size_t itrk = 0; itrk < 3; ++itrk) { - if (tau.signalPFChargedHadrCands()[itrk]->charge() * tau.charge() < 0) - return tau.signalPFChargedHadrCands()[itrk]; + if (tau.signalChargedHadrCands()[itrk]->charge() * tau.charge() < 0) + return tau.signalChargedHadrCands()[itrk]; } } - return tau.leadPFChargedHadrCand(); + return tau.leadChargedHadrCand(); } -std::vector notMainTrack(Tau tau) +std::vector notMainTrack(Tau tau) { - const PFCandidatePtr& mainTrackPtr = mainTrack(tau); - std::vector output; - output.reserve(tau.signalPFChargedHadrCands().size() - 1); - for(auto const& ptr : tau.signalPFChargedHadrCands()) { + const CandidatePtr& mainTrackPtr = mainTrack(tau); + std::vector output; + output.reserve(tau.signalChargedHadrCands().size() - 1); + for(auto const& ptr : tau.signalChargedHadrCands()) { if (ptr != mainTrackPtr) output.push_back(ptr); } @@ -105,7 +105,7 @@ double IsolationECALPtFraction(Tau tau) { double IsolationNeutralHadronPtFraction(Tau tau) { double sum = 0.0; - for(auto const& cand : tau.isolationPFNeutrHadrCands()) { + for(auto const& cand : tau.isolationNeutrHadrCands()) { sum += cand->pt(); } return sum/tau.jetRef()->pt(); @@ -119,7 +119,7 @@ double ScaledEtaJetCollimation(Tau tau) { double OpeningDeltaR(Tau tau) { double sumEt = 0; double weightedDeltaR = 0; - for(auto const& cand : tau.signalPFCands()) { + for(auto const& cand : tau.signalCands()) { double candEt = cand->et(); double candDeltaR = reco::deltaR(cand->p4(), tau.p4()); sumEt += candEt; @@ -131,7 +131,7 @@ double OpeningDeltaR(Tau tau) { double OpeningAngle3D(Tau tau) { double sumE = 0; double weightedAngle = 0; - for(auto const& cand : tau.signalPFCands()) { + for(auto const& cand : tau.signalCands()) { double candE = cand->energy(); double candAngle = angle(cand->p4(), tau.p4()); sumE += candE; @@ -142,7 +142,7 @@ double OpeningAngle3D(Tau tau) { double ScaledOpeningDeltaR(Tau tau) { double max = 0.0; - const std::vector& cands = tau.signalPFCands(); + const std::vector& cands = tau.signalCands(); for (size_t i = 0; i < cands.size()-1; ++i) { for (size_t j = i+1; j < cands.size(); ++j) { double deltaRVal = deltaR(cands[i]->p4(), cands[j]->p4()); @@ -164,10 +164,10 @@ double ScaledPhiJetCollimation(Tau tau) { } double IsolationChargedAveragePtFraction(Tau tau) { - size_t nIsoCharged = tau.isolationPFChargedHadrCands().size(); + size_t nIsoCharged = tau.isolationChargedHadrCands().size(); double averagePt = (nIsoCharged) ? tau.isolationPFChargedHadrCandsPtSum()/nIsoCharged : 0; - return averagePt/tau.leadPFChargedHadrCand()->pt(); + return averagePt/tau.leadChargedHadrCand()->pt(); } double MainTrackPtFraction(Tau tau) { @@ -175,8 +175,8 @@ double MainTrackPtFraction(Tau tau) { } VDouble Dalitz2(Tau tau) { - PFCandidatePtr theMainTrack = mainTrack(tau); - std::vector otherSignalTracks = notMainTrack(tau); + CandidatePtr theMainTrack = mainTrack(tau); + std::vector otherSignalTracks = notMainTrack(tau); const std::vector &pizeros = tau.signalPiZeroCandidates(); VDouble output; output.reserve(otherSignalTracks.size() + pizeros.size()); @@ -194,7 +194,7 @@ VDouble Dalitz2(Tau tau) { } double IsolationChargedSumHard(Tau tau) { - VDouble isocands = extract(tau.isolationPFChargedHadrCands(), std::mem_fn(&PFCandidate::pt)); + VDouble isocands = extract(tau.isolationChargedHadrCands(), std::mem_fn(&Candidate::pt)); double output = 0.0; for(double pt : isocands) { if (pt > 1.0) @@ -204,7 +204,7 @@ double IsolationChargedSumHard(Tau tau) { } double IsolationChargedSumSoft(Tau tau) { - VDouble isocands = extract(tau.isolationPFChargedHadrCands(), std::mem_fn(&PFCandidate::pt)); + VDouble isocands = extract(tau.isolationChargedHadrCands(), std::mem_fn(&Candidate::pt)); double output = 0.0; for(double pt : isocands) { if (pt < 1.0) @@ -223,7 +223,7 @@ double IsolationChargedSumSoftRelative(Tau tau) { } double IsolationECALSumHard(Tau tau) { - VDouble isocands = extract(tau.isolationPFGammaCands(), std::mem_fn(&PFCandidate::pt)); + VDouble isocands = extract(tau.isolationGammaCands(), std::mem_fn(&Candidate::pt)); double output = 0.0; for(double pt : isocands) { if (pt > 1.5) @@ -233,7 +233,7 @@ double IsolationECALSumHard(Tau tau) { } double IsolationECALSumSoft(Tau tau) { - VDouble isocands = extract(tau.isolationPFGammaCands(), std::mem_fn(&PFCandidate::pt)); + VDouble isocands = extract(tau.isolationGammaCands(), std::mem_fn(&Candidate::pt)); double output = 0.0; for(double pt : isocands) { if (pt < 1.5) @@ -253,7 +253,7 @@ double IsolationECALSumSoftRelative(Tau tau) { double EMFraction(Tau tau) { //double result = tau.emFraction(); reco::Candidate::LorentzVector gammaP4; - for(auto const& gamma : tau.signalPFGammaCands()) { + for(auto const& gamma : tau.signalGammaCands()) { gammaP4 += gamma->p4(); } double result = gammaP4.pt()/tau.pt(); @@ -262,12 +262,12 @@ double EMFraction(Tau tau) { LogDebug("TauDiscFunctions") << "EM fraction = " << result << tau ; LogDebug("TauDiscFunctions") << "charged" ; - for(auto const& cand : tau.signalPFChargedHadrCands()) { - LogDebug("TauDiscFunctions") << " pt: " << cand->pt() << " type: " << cand->particleId() << " key: " << cand.key() ; + for(auto const& cand : tau.signalChargedHadrCands()) { + LogDebug("TauDiscFunctions") << " pt: " << cand->pt() << " pdgId: " << cand->pdgId() << " key: " << cand.key() ; } LogDebug("TauDiscFunctions") << "gammas" ; - for(auto const& cand : tau.signalPFGammaCands()) { - LogDebug("TauDiscFunctions") << " pt: " << cand->pt() << " type: " << cand->particleId() << " key: " << cand.key() ; + for(auto const& cand : tau.signalGammaCands()) { + LogDebug("TauDiscFunctions") << " pt: " << cand->pt() << " pdgId: " << cand->pdgId() << " key: " << cand.key() ; } } return result; @@ -278,26 +278,26 @@ double ImpactParameterSignificance(Tau tau) { } double OutlierN(Tau tau) { - return tau.isolationPFChargedHadrCands().size() + - tau.isolationPFGammaCands().size(); + return tau.isolationChargedHadrCands().size() + + tau.isolationGammaCands().size(); } double OutlierNCharged(Tau tau) { - return tau.isolationPFChargedHadrCands().size(); + return tau.isolationChargedHadrCands().size(); } double MainTrackPt(Tau tau) { - PFCandidatePtr trk = mainTrack(tau); + CandidatePtr trk = mainTrack(tau); return (!trk) ? 0.0 : trk->pt(); } double MainTrackEta(Tau tau) { - PFCandidatePtr trk = mainTrack(tau); + CandidatePtr trk = mainTrack(tau); return (!trk) ? 0.0 : trk->eta(); } double MainTrackAngle(Tau tau) { - PFCandidatePtr trk = mainTrack(tau); + CandidatePtr trk = mainTrack(tau); return (!trk) ? 0.0 : deltaR(trk->p4(), tau.p4()); } @@ -316,11 +316,11 @@ double NeutralOutlierSumPt(Tau tau) { // Quantities associated to tracks - that are not the main track VDouble TrackPt(Tau tau) { - return extract(notMainTrack(tau), std::mem_fn(&PFCandidate::pt)); + return extract(notMainTrack(tau), std::mem_fn(&Candidate::pt)); } VDouble TrackEta(Tau tau) { - return extract(notMainTrack(tau), std::mem_fn(&PFCandidate::eta)); + return extract(notMainTrack(tau), std::mem_fn(&Candidate::eta)); } VDouble TrackAngle(Tau tau) { @@ -342,27 +342,27 @@ VDouble PiZeroAngle(Tau tau) { // Isolation quantities VDouble OutlierPt(Tau tau) { - return extract(tau.isolationPFCands(), std::mem_fn(&PFCandidate::pt)); + return extract(tau.isolationCands(), std::mem_fn(&Candidate::pt)); } VDouble OutlierAngle(Tau tau) { - return extract(tau.isolationPFCands(), DeltaRToAxis(tau.p4())); + return extract(tau.isolationCands(), DeltaRToAxis(tau.p4())); } VDouble ChargedOutlierPt(Tau tau) { - return extract(tau.isolationPFChargedHadrCands(), std::mem_fn(&PFCandidate::pt)); + return extract(tau.isolationChargedHadrCands(), std::mem_fn(&Candidate::pt)); } VDouble ChargedOutlierAngle(Tau tau) { - return extract(tau.isolationPFChargedHadrCands(), DeltaRToAxis(tau.p4())); + return extract(tau.isolationChargedHadrCands(), DeltaRToAxis(tau.p4())); } VDouble NeutralOutlierPt(Tau tau) { - return extract(tau.isolationPFGammaCands(), std::mem_fn(&PFCandidate::pt)); + return extract(tau.isolationGammaCands(), std::mem_fn(&Candidate::pt)); } VDouble NeutralOutlierAngle(Tau tau) { - return extract(tau.isolationPFGammaCands(), DeltaRToAxis(tau.p4())); + return extract(tau.isolationGammaCands(), DeltaRToAxis(tau.p4())); } // Invariant mass of main track with other combinations diff --git a/RecoTauTag/RecoTau/src/RecoTauIsolationMasking.cc b/RecoTauTag/RecoTau/src/RecoTauIsolationMasking.cc index 5e4eaafc1fe13..2503e662187e3 100644 --- a/RecoTauTag/RecoTau/src/RecoTauIsolationMasking.cc +++ b/RecoTauTag/RecoTau/src/RecoTauIsolationMasking.cc @@ -31,7 +31,7 @@ class PtSorter { // Check if an object is within DR of a track collection class MultiTrackDRFilter { public: - MultiTrackDRFilter(double deltaR, const std::vector& trks) + MultiTrackDRFilter(double deltaR, const std::vector& trks) :deltaR_(deltaR),tracks_(trks){} template bool operator()(const T& t) const { @@ -43,7 +43,7 @@ class MultiTrackDRFilter { } private: double deltaR_; - const std::vector& tracks_; + const std::vector& tracks_; }; double square(double x) { return x*x; } @@ -74,15 +74,15 @@ RecoTauIsolationMasking::IsoMaskResult RecoTauIsolationMasking::mask(const reco::PFTau& tau) const { IsoMaskResult output; - typedef std::list PFCandList; + typedef std::list CandList; // Copy original iso collections. - std::copy(tau.isolationPFGammaCands().begin(), - tau.isolationPFGammaCands().end(), std::back_inserter(output.gammas)); - std::copy(tau.isolationPFNeutrHadrCands().begin(), - tau.isolationPFNeutrHadrCands().end(), + std::copy(tau.isolationGammaCands().begin(), + tau.isolationGammaCands().end(), std::back_inserter(output.gammas)); + std::copy(tau.isolationNeutrHadrCands().begin(), + tau.isolationNeutrHadrCands().end(), std::back_inserter(output.h0s)); - std::vector courses; + std::vector courses; courses.push_back(&(output.h0s)); courses.push_back(&(output.gammas)); // Mask using each one of the tracks @@ -109,11 +109,11 @@ RecoTauIsolationMasking::mask(const reco::PFTau& tau) const { for(auto* course : courses) { // Sort by deltaR to the current track course->sort(sorter); - PFCandList::iterator toEatIter = course->begin(); + CandList::iterator toEatIter = course->begin(); // While there are still candidates to eat in this course and they are // within the cone. while (toEatIter != course->end()) { - const reco::PFCandidate& toEat = **toEatIter; + const reco::Candidate& toEat = **toEatIter; double toEatEnergy = toEat.energy(); double toEatErrorSq = square(resolution(toEat)); // Check if we can absorb this candidate into the track. @@ -134,42 +134,41 @@ RecoTauIsolationMasking::mask(const reco::PFTau& tau) const { // This removes upward fluctuating HCAL objects if (finalHcalCone_ > 0) { MultiTrackDRFilter hcalFinalFilter(finalHcalCone_, - tau.signalPFChargedHadrCands()); + tau.signalChargedHadrCands()); std::remove_if(output.h0s.begin(), output.h0s.end(), hcalFinalFilter); } return output; } double RecoTauIsolationMasking::resolution( - const reco::PFCandidate& cand) const { - if (cand.particleId() == reco::PFCandidate::h0) { + const reco::Candidate& cand) const { + if (cand.pdgId() == 130) { // NB for HCAL it returns relative energy return cand.energy()*resolutions_->getEnergyResolutionHad(cand.energy(), cand.eta(), cand.phi()); - } else if (cand.particleId() == reco::PFCandidate::gamma) { + } else if (cand.pdgId() == 22) { return resolutions_->getEnergyResolutionEm(cand.energy(), cand.eta()); - } else if (cand.particleId() == reco::PFCandidate::e) { + } else if (std::abs(cand.pdgId()) == 11) { // FIXME what is the electron resolution?? return 0.15; } else { edm::LogWarning("IsoMask::res (bad pf id)") - << "Unknown PF ID: " << cand.particleId(); + << "Unknown PF PDG ID: " << cand.pdgId(); } return -1; } bool RecoTauIsolationMasking::inCone(const reco::PFCandidate& track, - const reco::PFCandidate& cand) const { + const reco::Candidate& cand) const { double openingDR = reco::deltaR(track.positionAtECALEntrance(), cand.p4()); - if (cand.particleId() == reco::PFCandidate::h0) { + if (cand.pdgId() == 130) { return (openingDR < hcalCone_); - } else if (cand.particleId() == reco::PFCandidate::gamma || - cand.particleId() == reco::PFCandidate::e) { + } else if (cand.pdgId() == 22 || + abs(cand.pdgId()) == 11) { return openingDR < ecalCone_; } else { edm::LogWarning("IsoMask::inCone (bad pf id)") - << "Unknown PF ID: " << cand.particleId() - << " " << reco::PFCandidate::e; + << "Unknown PF PDG ID: " << cand.pdgId(); } return -1; } diff --git a/RecoTauTag/RecoTau/src/RecoTauMuonTools.cc b/RecoTauTag/RecoTau/src/RecoTauMuonTools.cc new file mode 100644 index 0000000000000..38aaceb4ba6ff --- /dev/null +++ b/RecoTauTag/RecoTau/src/RecoTauMuonTools.cc @@ -0,0 +1,53 @@ +#include "RecoTauTag/RecoTau/interface/RecoTauMuonTools.h" + +#include "DataFormats/TrackReco/interface/HitPattern.h" + +namespace reco { namespace tau { + void countHits(const reco::Muon& muon, std::vector& numHitsDT, std::vector& numHitsCSC, std::vector& numHitsRPC) + { + if ( muon.outerTrack().isNonnull() ) { + const reco::HitPattern &muonHitPattern = muon.outerTrack()->hitPattern(); + for (int iHit = 0; iHit < muonHitPattern.numberOfAllHits(reco::HitPattern::TRACK_HITS); ++iHit) { + uint32_t hit = muonHitPattern.getHitPattern(reco::HitPattern::TRACK_HITS, iHit); + if ( hit == 0 ) break; + if ( muonHitPattern.muonHitFilter(hit) && (muonHitPattern.getHitType(hit) == TrackingRecHit::valid || muonHitPattern.getHitType(hit) == TrackingRecHit::bad) ) { + int muonStation = muonHitPattern.getMuonStation(hit) - 1; // CV: map into range 0..3 + if ( muonStation >= 0 && muonStation < 4 ) { + if ( muonHitPattern.muonDTHitFilter(hit) ) ++numHitsDT[muonStation]; + else if ( muonHitPattern.muonCSCHitFilter(hit) ) ++numHitsCSC[muonStation]; + else if ( muonHitPattern.muonRPCHitFilter(hit) ) ++numHitsRPC[muonStation]; + } + } + } + } + } + + std::string format_vint(const std::vector& vi) + { + std::ostringstream os; + os << "{ "; + unsigned numEntries = vi.size(); + for ( unsigned iEntry = 0; iEntry < numEntries; ++iEntry ) { + os << vi[iEntry]; + if ( iEntry < (numEntries - 1) ) os << ", "; + } + os << " }"; + return os.str(); + } + + void countMatches(const reco::Muon& muon, std::vector& numMatchesDT, std::vector& numMatchesCSC, std::vector& numMatchesRPC) + { + const std::vector& muonSegments = muon.matches(); + for ( std::vector::const_iterator muonSegment = muonSegments.begin(); + muonSegment != muonSegments.end(); ++muonSegment ) { + if ( muonSegment->segmentMatches.empty() ) continue; + int muonDetector = muonSegment->detector(); + int muonStation = muonSegment->station() - 1; + assert(muonStation >= 0 && muonStation <= 3); + if ( muonDetector == MuonSubdetId::DT ) ++numMatchesDT[muonStation]; + else if ( muonDetector == MuonSubdetId::CSC ) ++numMatchesCSC[muonStation]; + else if ( muonDetector == MuonSubdetId::RPC ) ++numMatchesRPC[muonStation]; + } + } + +}} // end namespace reco::tau diff --git a/RecoTauTag/RecoTau/src/RecoTauQualityCuts.cc b/RecoTauTag/RecoTau/src/RecoTauQualityCuts.cc index 1bb8f8ebdc414..46f5bc6ded6f5 100644 --- a/RecoTauTag/RecoTau/src/RecoTauQualityCuts.cc +++ b/RecoTauTag/RecoTau/src/RecoTauQualityCuts.cc @@ -3,18 +3,49 @@ #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "DataFormats/GsfTrackReco/interface/GsfTrack.h" #include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" namespace reco::tau { namespace { - // Get the KF track if it exists. Otherwise, see if PFCandidate has a GSF track. - const reco::TrackBaseRef getTrackRef(const PFCandidate& cand) + const reco::Track* getTrack(const Candidate& cand) + { + const PFCandidate* pfCandPtr = dynamic_cast(&cand); + if (pfCandPtr) { + // Get the KF track if it exists. Otherwise, see if PFCandidate has a GSF track. + if ( pfCandPtr->trackRef().isNonnull() ) return pfCandPtr->trackRef().get(); + else if ( pfCandPtr->gsfTrackRef().isNonnull() ) return pfCandPtr->gsfTrackRef().get(); + else return nullptr; + } + + const pat::PackedCandidate* packedCand = dynamic_cast(&cand); + if (packedCand && packedCand->hasTrackDetails()) + return &packedCand->pseudoTrack(); + + return nullptr; + } + + const reco::TrackRef getTrackRef(const Candidate& cand) { - if ( cand.trackRef().isNonnull() ) return reco::TrackBaseRef(cand.trackRef()); - else if ( cand.gsfTrackRef().isNonnull() ) return reco::TrackBaseRef(cand.gsfTrackRef()); - else return reco::TrackBaseRef(); + const PFCandidate* pfCandPtr = dynamic_cast(&cand); + if (pfCandPtr) + return pfCandPtr->trackRef(); + + return reco::TrackRef(); + } + + const reco::TrackBaseRef getGsfTrackRef(const Candidate& cand) + { + const PFCandidate* pfCandPtr = dynamic_cast(&cand); + if (pfCandPtr) { + return reco::TrackBaseRef(pfCandPtr->gsfTrackRef()); + } + return reco::TrackBaseRef(); + } + // Translate GsfTrackRef to TrackBaseRef template reco::TrackBaseRef convertRef(const T& ref) { @@ -31,30 +62,30 @@ bool ptMin(const TrackBaseRef& track, double cut) return (track->pt() > cut); } -bool ptMin_cand(const PFCandidate& cand, double cut) +bool ptMin_cand(const Candidate& cand, double cut) { LogDebug("TauQCuts") << ": Pt = " << cand.pt() << ", cut = " << cut ; return (cand.pt() > cut); } -bool etMin_cand(const PFCandidate& cand, double cut) +bool etMin_cand(const Candidate& cand, double cut) { LogDebug("TauQCuts") << ": Et = " << cand.et() << ", cut = " << cut ; return (cand.et() > cut); } -bool trkPixelHits(const TrackBaseRef& track, int cut) +bool trkPixelHits(const Track* track, int cut) { // For some reason, the number of hits is signed LogDebug("TauQCuts") << ": #Pxl hits = " << track->hitPattern().numberOfValidPixelHits() << ", cut = " << cut ; return (track->hitPattern().numberOfValidPixelHits() >= cut); } -bool trkPixelHits_cand(const PFCandidate& cand, int cut) +bool trkPixelHits_cand(const Candidate& cand, int cut) { // For some reason, the number of hits is signed - auto track = getTrackRef(cand); - if ( track.isNonnull() ) { + auto track = getTrack(cand); + if ( track ) { LogDebug("TauQCuts") << ": #Pxl hits = " << trkPixelHits(track, cut) << ", cut = " << cut ; return trkPixelHits(track, cut); } else { @@ -63,16 +94,16 @@ bool trkPixelHits_cand(const PFCandidate& cand, int cut) } } -bool trkTrackerHits(const TrackBaseRef& track, int cut) +bool trkTrackerHits(const Track* track, int cut) { LogDebug("TauQCuts") << ": #Trk hits = " << track->hitPattern().numberOfValidHits() << ", cut = " << cut ; return (track->hitPattern().numberOfValidHits() >= cut); } -bool trkTrackerHits_cand(const PFCandidate& cand, int cut) +bool trkTrackerHits_cand(const Candidate& cand, int cut) { - auto track = getTrackRef(cand); - if ( track.isNonnull() ) { + auto track = getTrack(cand); + if ( track ) { LogDebug("TauQCuts") << ": #Trk hits = " << track->hitPattern().numberOfValidHits() << ", cut = " << cut ; return trkTrackerHits(track, cut); } else { @@ -81,7 +112,7 @@ bool trkTrackerHits_cand(const PFCandidate& cand, int cut) } } -bool trkTransverseImpactParameter(const TrackBaseRef& track, const reco::VertexRef* pv, double cut) +bool trkTransverseImpactParameter(const Track* track, const reco::VertexRef* pv, double cut) { if ( pv->isNull() ) { edm::LogError("QCutsNoPrimaryVertex") << "Primary vertex Ref in " << @@ -94,10 +125,10 @@ bool trkTransverseImpactParameter(const TrackBaseRef& track, const reco::VertexR return (std::fabs(track->dxy((*pv)->position())) <= cut); } -bool trkTransverseImpactParameter_cand(const PFCandidate& cand, const reco::VertexRef* pv, double cut) +bool trkTransverseImpactParameter_cand(const Candidate& cand, const reco::VertexRef* pv, double cut) { - auto track = getTrackRef(cand); - if ( track.isNonnull() ) { + auto track = getTrack(cand); + if ( track ) { return trkTransverseImpactParameter(track, pv, cut); } else { LogDebug("TauQCuts") << ": dXY = N/A, cut = " << cut ; @@ -105,7 +136,7 @@ bool trkTransverseImpactParameter_cand(const PFCandidate& cand, const reco::Vert } } -bool trkLongitudinalImpactParameter(const TrackBaseRef& track, const reco::VertexRef* pv, double cut) +bool trkLongitudinalImpactParameter(const TrackBase* track, const reco::VertexRef* pv, double cut) { if ( pv->isNull() ) { edm::LogError("QCutsNoPrimaryVertex") << "Primary vertex Ref in " << @@ -118,10 +149,10 @@ bool trkLongitudinalImpactParameter(const TrackBaseRef& track, const reco::Verte return (std::fabs(track->dz((*pv)->position())) <= cut); } -bool trkLongitudinalImpactParameter_cand(const PFCandidate& cand, const reco::VertexRef* pv, double cut) +bool trkLongitudinalImpactParameter_cand(const Candidate& cand, const reco::VertexRef* pv, double cut) { - auto track = getTrackRef(cand); - if ( track.isNonnull() ) { + auto track = getTrack(cand); + if ( track ) { return trkLongitudinalImpactParameter(track, pv, cut); } else { LogDebug("TauQCuts") << ": dZ = N/A, cut = " << cut ; @@ -130,20 +161,20 @@ bool trkLongitudinalImpactParameter_cand(const PFCandidate& cand, const reco::Ve } /// DZ cut, with respect to the current lead rack -bool trkLongitudinalImpactParameterWrtTrack(const TrackBaseRef& track, const reco::TrackBaseRef* leadTrack, const reco::VertexRef* pv, double cut) +bool trkLongitudinalImpactParameterWrtTrack(const Track* track, const Track* leadTrack, const reco::VertexRef* pv, double cut) { - if ( leadTrack->isNull()) { + if (!leadTrack) { edm::LogError("QCutsNoValidLeadTrack") << "Lead track Ref in " << "RecoTauQualityCuts is invalid. - trkLongitudinalImpactParameterWrtTrack"; return false; } - return (std::fabs(track->dz((*pv)->position()) - (*leadTrack)->dz((*pv)->position())) <= cut); + return (std::fabs(track->dz((*pv)->position()) - leadTrack->dz((*pv)->position())) <= cut); } -bool trkLongitudinalImpactParameterWrtTrack_cand(const PFCandidate& cand, const reco::TrackBaseRef* leadTrack, const reco::VertexRef* pv, double cut) +bool trkLongitudinalImpactParameterWrtTrack_cand(const Candidate& cand, const reco::Track* leadTrack, const reco::VertexRef* pv, double cut) { - auto track = getTrackRef(cand); - if ( track.isNonnull() ) return trkLongitudinalImpactParameterWrtTrack(track, leadTrack, pv, cut); + auto track = getTrack(cand); + if ( track ) return trkLongitudinalImpactParameterWrtTrack(track, leadTrack, pv, cut); else return false; } @@ -160,27 +191,68 @@ bool minTrackVertexWeight(const TrackBaseRef& track, const reco::VertexRef* pv, return ((*pv)->trackWeight(track) >= cut); } -bool minTrackVertexWeight_cand(const PFCandidate& cand, const reco::VertexRef* pv, double cut) +bool minTrackVertexWeight(const TrackRef& track, const reco::VertexRef* pv, double cut) +{ + if ( pv->isNull() ) { + edm::LogError("QCutsNoPrimaryVertex") << "Primary vertex Ref in " << + "RecoTauQualityCuts is invalid. - minTrackVertexWeight"; + return false; + } + LogDebug("TauQCuts") << " track: Pt = " << track->pt() << ", eta = " << track->eta() << ", phi = " << track->phi() ; + LogDebug("TauQCuts") << " vertex: x = " << (*pv)->position().x() << ", y = " << (*pv)->position().y() << ", z = " << (*pv)->position().z() ; + LogDebug("TauQCuts") << "--> trackWeight = " << (*pv)->trackWeight(track) << " (cut = " << cut << ")" ; + return ((*pv)->trackWeight(track) >= cut); +} + +bool minPackedCandVertexWeight(const pat::PackedCandidate& pCand, const reco::VertexRef* pv, double cut) { + + if ( pv->isNull() ) { + edm::LogError("QCutsNoPrimaryVertex") << "Primary vertex Ref in " << + "RecoTauQualityCuts is invalid. - minPackedCandVertexWeight"; + return false; + } + //there is some low granular information on track weight in the vertex available with packed cands + double weight = -9.9; + if( pCand.vertexRef().isNonnull() && pCand.vertexRef().key() == pv->key() ){ + int quality = pCand.pvAssociationQuality(); + if( quality == pat::PackedCandidate::UsedInFitTight ) weight = 0.6;//0.6 as proxy for weight above 0.5 + else if( quality == pat::PackedCandidate::UsedInFitLoose ) weight = 0.1;//0.6 as proxy for weight below 0.5 + } + LogDebug("TauQCuts") << " packedCand: Pt = " << pCand.pt() << ", eta = " << pCand.eta() << ", phi = " << pCand.phi() ; + LogDebug("TauQCuts") << " vertex: x = " << (*pv)->position().x() << ", y = " << (*pv)->position().y() << ", z = " << (*pv)->position().z() ; + LogDebug("TauQCuts") << "--> trackWeight from packedCand = " << weight << " (cut = " << cut << ")" ; + return (weight >= cut); +} + +bool minTrackVertexWeight_cand(const Candidate& cand, const reco::VertexRef* pv, double cut) { auto track = getTrackRef(cand); if ( track.isNonnull() ) { return minTrackVertexWeight(track, pv, cut); - } else { - LogDebug("TauQCuts") << ": weight = N/A, cut = " << cut ; - return false; } + auto gsfTrack = getGsfTrackRef(cand); + if ( gsfTrack.isNonnull() ) { + return minTrackVertexWeight(gsfTrack, pv, cut); + } + + const pat::PackedCandidate* pCand = dynamic_cast(&cand); + if( pCand != nullptr && cand.charge() != 0) { + return minPackedCandVertexWeight(*pCand, pv, cut); + } + LogDebug("TauQCuts") << ": weight = N/A, cut = " << cut ; + return false; } -bool trkChi2(const TrackBaseRef& track, double cut) +bool trkChi2(const Track* track, double cut) { LogDebug("TauQCuts") << ": chi^2 = " << track->normalizedChi2() << ", cut = " << cut ; return (track->normalizedChi2() <= cut); } -bool trkChi2_cand(const PFCandidate& cand, double cut) +bool trkChi2_cand(const Candidate& cand, double cut) { - auto track = getTrackRef(cand); - if ( track.isNonnull() ) { + auto track = getTrack(cand); + if ( track ) { LogDebug("TauQCuts") << ": chi^2 = " << track->normalizedChi2() << ", cut = " << cut ; return trkChi2(track, cut); } else { @@ -198,7 +270,7 @@ bool AND(const TrackBaseRef& track, const RecoTauQualityCuts::TrackQCutFuncColle return true; } -bool AND_cand(const PFCandidate& cand, const RecoTauQualityCuts::CandQCutFuncCollection& cuts) +bool AND_cand(const Candidate& cand, const RecoTauQualityCuts::CandQCutFuncCollection& cuts) { for(auto const& func : cuts ) { if ( !func(cand) ) return false; @@ -207,10 +279,10 @@ bool AND_cand(const PFCandidate& cand, const RecoTauQualityCuts::CandQCutFuncCol } // Get the set of Q cuts for a given type (i.e. gamma) -bool mapAndCutByType(const PFCandidate& cand, const RecoTauQualityCuts::CandQCutFuncMap& funcMap) +bool mapAndCutByType(const Candidate& cand, const RecoTauQualityCuts::CandQCutFuncMap& funcMap) { // Find the cuts that for this particle type - RecoTauQualityCuts::CandQCutFuncMap::const_iterator cuts = funcMap.find(cand.particleId()); + RecoTauQualityCuts::CandQCutFuncMap::const_iterator cuts = funcMap.find(std::abs(cand.pdgId())); // Return false if we dont' know how to deal with this particle type if ( cuts == funcMap.end() ) return false; return AND_cand(cand, cuts->second); // Otherwise AND all the cuts @@ -332,18 +404,27 @@ std::pair factorizePUQCuts(const edm::Para bool RecoTauQualityCuts::filterTrack(const reco::TrackBaseRef& track) const { - return filterTrack_(track); + if (!filterTrack_(track.get())) + return false; + if(minTrackVertexWeight_ >= 0. && !(pv_->trackWeight(convertRef(track)) >= minTrackVertexWeight_)) return false; + return true; } bool RecoTauQualityCuts::filterTrack(const reco::TrackRef& track) const { - return filterTrack_(track); + if (!filterTrack_(track.get())) + return false; + if(minTrackVertexWeight_ >= 0. && !(pv_->trackWeight(convertRef(track)) >= minTrackVertexWeight_)) return false; + return true; +} + +bool RecoTauQualityCuts::filterTrack(const reco::Track& track) const +{ + return filterTrack_(&track); } -template -bool RecoTauQualityCuts::filterTrack_(const T& trackRef) const +bool RecoTauQualityCuts::filterTrack_(const reco::Track* track) const { - const Track *track = trackRef.get(); if(minTrackPt_ >= 0 && !(track->pt() > minTrackPt_)) return false; if(maxTrackChi2_ >= 0 && !(track->normalizedChi2() <= maxTrackChi2_)) return false; if(checkHitPattern_) { @@ -362,7 +443,7 @@ bool RecoTauQualityCuts::filterTrack_(const T& trackRef) const return false; if(maxDeltaZ_ >= 0 && !(std::fabs(track->dz(pv_->position())) <= maxDeltaZ_)) return false; if(maxDeltaZToLeadTrack_ >= 0) { - if ( leadTrack_.isNull()) { + if ( !leadTrack_) { edm::LogError("QCutsNoValidLeadTrack") << "Lead track Ref in " << "RecoTauQualityCuts is invalid. - filterTrack"; return false; @@ -371,31 +452,74 @@ bool RecoTauQualityCuts::filterTrack_(const T& trackRef) const if(!(std::fabs(track->dz(pv_->position()) - leadTrack_->dz(pv_->position())) <= maxDeltaZToLeadTrack_)) return false; } - if(minTrackVertexWeight_ > -1.0 && !(pv_->trackWeight(convertRef(trackRef)) >= minTrackVertexWeight_)) return false; return true; } -bool RecoTauQualityCuts::filterGammaCand(const reco::PFCandidate& cand) const { +bool RecoTauQualityCuts::filterChargedCand(const reco::Candidate& cand) const { + + if (cand.charge() == 0) + return true; + const pat::PackedCandidate* pCand = dynamic_cast(&cand); + if (pCand == nullptr) + return true; + + //Get track, it should be present for cands with pT(charged)>0.5GeV + //and check track quality critera other than vertex weight + auto track = getTrack(cand); + if (track != nullptr){ + if (!filterTrack(*track)) + return false; + } else {//Candidates without track (pT(charged)<0.5GeV): Can still check pT and calculate dxy and dz + if(minTrackPt_ >= 0 && !(pCand->pt() > minTrackPt_)) return false; + if(checkPV_ && pv_.isNull()) { + edm::LogError("QCutsNoPrimaryVertex") << "Primary vertex Ref in " << + "RecoTauQualityCuts is invalid. - filterChargedCand"; + return false; + } + + if(maxTransverseImpactParameter_ >= 0 && + !(std::fabs(pCand->dxy(pv_->position())) <= maxTransverseImpactParameter_)) + return false; + if(maxDeltaZ_ >= 0 && !(std::fabs(pCand->dz(pv_->position())) <= maxDeltaZ_)) return false; + if(maxDeltaZToLeadTrack_ >= 0) { + if ( leadTrack_ == nullptr) { + edm::LogError("QCutsNoValidLeadTrack") << "Lead track Ref in " << + "RecoTauQualityCuts is invalid. - filterChargedCand"; + return false; + } + + if(!(std::fabs(pCand->dz(pv_->position()) - leadTrack_->dz(pv_->position())) <= maxDeltaZToLeadTrack_)) + return false; + } + } + if(minTrackVertexWeight_ >= 0. && + !(qcuts::minPackedCandVertexWeight(*pCand, &pv_, minTrackVertexWeight_))) + return false; + + return true; +} + +bool RecoTauQualityCuts::filterGammaCand(const reco::Candidate& cand) const { if(minGammaEt_ >= 0 && !(cand.et() > minGammaEt_)) return false; return true; } -bool RecoTauQualityCuts::filterNeutralHadronCand(const reco::PFCandidate& cand) const { +bool RecoTauQualityCuts::filterNeutralHadronCand(const reco::Candidate& cand) const { if(minNeutralHadronEt_ >= 0 && !(cand.et() > minNeutralHadronEt_)) return false; return true; } -bool RecoTauQualityCuts::filterCandByType(const reco::PFCandidate& cand) const { - switch(cand.particleId()) { - case PFCandidate::gamma: +bool RecoTauQualityCuts::filterCandByType(const reco::Candidate& cand) const { + switch(std::abs(cand.pdgId())) { + case 22: return filterGammaCand(cand); - case PFCandidate::h0: + case 130: return filterNeutralHadronCand(cand); // We use the same qcuts for muons/electrons and charged hadrons. - case PFCandidate::h: - case PFCandidate::e: - case PFCandidate::mu: + case 211: + case 11: + case 13: // no cuts ATM (track cuts applied in filterCand) return true; // Return false if we dont' know how to deal with this particle type @@ -405,41 +529,46 @@ bool RecoTauQualityCuts::filterCandByType(const reco::PFCandidate& cand) const { return false; } -bool RecoTauQualityCuts::filterCand(const reco::PFCandidate& cand) const +bool RecoTauQualityCuts::filterCand(const reco::Candidate& cand) const { - auto trackRef = cand.trackRef(); + auto trackRef = getTrackRef(cand); bool result = true; - if(trackRef.isNonnull()) { - result = filterTrack_(trackRef); - } + + if (trackRef.isNonnull()) { + result = filterTrack(trackRef); + } else { - auto gsfTrackRef = cand.gsfTrackRef(); - if(gsfTrackRef.isNonnull()) { - result = filterTrack_(gsfTrackRef); + auto gsfTrackRef = getGsfTrackRef(cand); + if (gsfTrackRef.isNonnull()) + result = filterTrack(gsfTrackRef); + else if (cand.charge() != 0) { + result = filterChargedCand(cand); } } + if(result) result = filterCandByType(cand); + return result; } -void RecoTauQualityCuts::setLeadTrack(const reco::TrackRef& leadTrack) const +void RecoTauQualityCuts::setLeadTrack(const reco::Track& leadTrack) const { - leadTrack_ = reco::TrackBaseRef(leadTrack); + leadTrack_ = &leadTrack; } -void RecoTauQualityCuts::setLeadTrack(const reco::PFCandidate& leadCand) const +void RecoTauQualityCuts::setLeadTrack(const reco::Candidate& leadCand) const { - leadTrack_ = getTrackRef(leadCand); + leadTrack_ = getTrack(leadCand); } -void RecoTauQualityCuts::setLeadTrack(const reco::PFCandidateRef& leadCand) const +void RecoTauQualityCuts::setLeadTrack(const reco::CandidateRef& leadCand) const { if ( leadCand.isNonnull() ) { - leadTrack_ = getTrackRef(*leadCand); + leadTrack_ = getTrack(*leadCand); } else { // Set null - leadTrack_ = reco::TrackBaseRef(); + leadTrack_ = nullptr; } } diff --git a/RecoTauTag/RecoTau/src/RecoTauVertexAssociator.cc b/RecoTauTag/RecoTau/src/RecoTauVertexAssociator.cc index 9e06ef4264a12..dae7990818046 100644 --- a/RecoTauTag/RecoTau/src/RecoTauVertexAssociator.cc +++ b/RecoTauTag/RecoTau/src/RecoTauVertexAssociator.cc @@ -5,6 +5,7 @@ #include "DataFormats/TauReco/interface/PFTau.h" #include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "RecoTauTag/RecoTau/interface/RecoTauCommonUtilities.h" @@ -15,11 +16,42 @@ namespace reco { namespace tau { +namespace { + inline const reco::Track* getTrack(const Candidate& cand) + { + const PFCandidate* pfCandPtr = dynamic_cast(&cand); + if (pfCandPtr != nullptr) { + if ( pfCandPtr->trackRef().isNonnull() ) return pfCandPtr->trackRef().get(); + else if ( pfCandPtr->gsfTrackRef().isNonnull() ) return pfCandPtr->gsfTrackRef().get(); + else return nullptr; + } + const pat::PackedCandidate* packedCand = dynamic_cast(&cand); + if (packedCand != nullptr && packedCand->hasTrackDetails()) + return &packedCand->pseudoTrack(); + + return nullptr; + } + + inline const reco::TrackBaseRef getTrackRef(const Candidate& cand) + { + // TauReco@MiniAOD: This version does not work on top of MiniAOD, however, + // it is only used for non-default track-vertex associations + const PFCandidate* pfCandPtr = dynamic_cast(&cand); + if (pfCandPtr != nullptr) { + if ( pfCandPtr->trackRef().isNonnull() ) return reco::TrackBaseRef(pfCandPtr->trackRef()); + else if ( pfCandPtr->gsfTrackRef().isNonnull() ) return reco::TrackBaseRef(pfCandPtr->gsfTrackRef()); + else return reco::TrackBaseRef(); + } + + return reco::TrackBaseRef(); + } +} + // Get the highest pt track in a jet. // Get the KF track if it exists. Otherwise, see if it has a GSF track. -reco::TrackBaseRef RecoTauVertexAssociator::getLeadTrack(const PFJet& jet) const +const reco::CandidatePtr RecoTauVertexAssociator::getLeadCand(const Jet& jet) const { - std::vector chargedPFCands = pfChargedCands(jet, true); + std::vector chargedPFCands = pfChargedCands(jet, true); if ( verbosity_ >= 1 ) { std::cout << ":" << std::endl; std::cout << " jet: Pt = " << jet.pt() << ", eta = " << jet.eta() << ", phi = " << jet.phi() << std::endl; @@ -28,10 +60,10 @@ reco::TrackBaseRef RecoTauVertexAssociator::getLeadTrack(const PFJet& jet) const } if ( chargedPFCands.empty() ) { - return reco::TrackBaseRef(); + return reco::CandidatePtr(nullptr, 0); } - - std::vector selectedPFCands; + + std::vector selectedPFCands; if ( vxTrkFiltering_ ) { selectedPFCands = qcuts_->filterCandRefs(chargedPFCands); } else { @@ -40,58 +72,64 @@ reco::TrackBaseRef RecoTauVertexAssociator::getLeadTrack(const PFJet& jet) const if ( verbosity_ >= 1 ) { std::cout << " num. selectedPFCands = " << selectedPFCands.size() << std::endl; } - - PFCandidatePtr leadPFCand; + + CandidatePtr leadCand; if ( !selectedPFCands.empty() ) { double leadTrackPt = 0.; - if ( leadingTrkOrPFCandOption_ == kFirstTrack){ leadPFCand=selectedPFCands[0];} - else - { - for ( std::vector::const_iterator pfCand = selectedPFCands.begin(); - pfCand != selectedPFCands.end(); ++pfCand ) { - const reco::Track* track = nullptr; - if ( (*pfCand)->trackRef().isNonnull() ) track = (*pfCand)->trackRef().get(); - else if ( (*pfCand)->gsfTrackRef().isNonnull() ) track = (*pfCand)->gsfTrackRef().get(); - if ( !track ) continue; + if ( leadingTrkOrPFCandOption_ == kFirstTrack){ leadCand=selectedPFCands[0];} + else { + for ( std::vector::const_iterator pfCand = selectedPFCands.begin(); + pfCand != selectedPFCands.end(); ++pfCand ) { + const reco::Track* track = getTrack(**pfCand); + double actualTrackPt = 0.; + if ( track != nullptr ) + actualTrackPt = track->pt(); double trackPt = 0.; if ( leadingTrkOrPFCandOption_ == kLeadTrack ) { - //double trackPt = track->pt(); - trackPt = track->pt() - 2.*track->ptError(); + //double trackPt = track->pt(); + trackPt = actualTrackPt - 2.*track->ptError(); } else if ( leadingTrkOrPFCandOption_ == kLeadPFCand ) { trackPt = (*pfCand)->pt(); } else if ( leadingTrkOrPFCandOption_ == kMinLeadTrackOrPFCand ) { - trackPt = TMath::Min(track->pt(), (double)(*pfCand)->pt()); + trackPt = TMath::Min(actualTrackPt, (double)(*pfCand)->pt()); } else assert(0); if ( trackPt > leadTrackPt ) { - leadPFCand = (*pfCand); + leadCand = (*pfCand); leadTrackPt = trackPt; } } } } - if ( leadPFCand.isNull() ) { + if ( leadCand.isNull() ) { if ( recoverLeadingTrk_ ) { - leadPFCand = chargedPFCands[0]; + leadCand = chargedPFCands[0]; } else { - return reco::TrackBaseRef(); + return reco::CandidatePtr(nullptr, 0); } } if ( verbosity_ >= 1 ) { - std::cout << "leadPFCand: Pt = " << leadPFCand->pt() << ", eta = " << leadPFCand->eta() << ", phi = " << leadPFCand->phi() << std::endl; + std::cout << "leadCand: Pt = " << leadCand->pt() << ", eta = " << leadCand->eta() << ", phi = " << leadCand->phi() << std::endl; } - - if ( leadPFCand->trackRef().isNonnull() ) { - return reco::TrackBaseRef(leadPFCand->trackRef()); - } else if ( leadPFCand->gsfTrackRef().isNonnull() ) { - return reco::TrackBaseRef(leadPFCand->gsfTrackRef()); - } - return reco::TrackBaseRef(); + return leadCand; +} + +const reco::Track* RecoTauVertexAssociator::getLeadTrack(const Jet& jet) const { + auto leadCand = getLeadCand(jet); + if(leadCand.isNull()) return nullptr; + const reco::Track* track = getTrack(*leadCand); + return track; +} + +const reco::TrackBaseRef RecoTauVertexAssociator::getLeadTrackRef(const Jet& jet) const { + auto leadCand = getLeadCand(jet); + if(leadCand.isNull()) return reco::TrackBaseRef(); + return getTrackRef(*leadCand); } namespace { // Define functors which extract the relevant information from a collection of // vertices. - double dzToTrack(const reco::VertexRef& vtx, const reco::TrackBaseRef& trk) + double dzToTrack(const reco::VertexRef& vtx, const reco::Track* trk) { if ( !trk || !vtx ) { return std::numeric_limits::infinity(); @@ -211,7 +249,7 @@ void RecoTauVertexAssociator::setEvent(const edm::Event& evt) } edm::EventNumber_t currentEvent = evt.id().event(); if ( currentEvent != lastEvent_ || !jetToVertexAssociation_ ) { - if ( !jetToVertexAssociation_ ) jetToVertexAssociation_ = new std::map; + if ( !jetToVertexAssociation_ ) jetToVertexAssociation_ = new std::map; else jetToVertexAssociation_->clear(); lastEvent_ = currentEvent; } @@ -220,32 +258,30 @@ void RecoTauVertexAssociator::setEvent(const edm::Event& evt) reco::VertexRef RecoTauVertexAssociator::associatedVertex(const PFTau& tau, bool useJet) const { - if ( !useJet ) { - if ( tau.leadPFChargedHadrCand().isNonnull() ) { - if ( tau.leadPFChargedHadrCand()->trackRef().isNonnull() ) - return associatedVertex( reco::TrackBaseRef( tau.leadPFChargedHadrCand()->trackRef() ) ); - else if ( tau.leadPFChargedHadrCand()->gsfTrackRef().isNonnull() ) - return associatedVertex( reco::TrackBaseRef( tau.leadPFChargedHadrCand()->gsfTrackRef() ) ); + if ( tau.leadChargedHadrCand().isNonnull() ) { + const reco::Track* track = getTrack(*tau.leadChargedHadrCand()); + if (track != nullptr) + return associatedVertex(track); } } // MB: use vertex associated to a given jet if explicitely requested or in case of missing leading track - reco::PFJetRef jetRef = tau.jetRef(); + reco::JetBaseRef jetRef = tau.jetRef(); // FIXME workaround for HLT which does not use updated data format if ( jetRef.isNull() ) jetRef = tau.pfTauTagInfoRef()->pfjetRef(); return associatedVertex(*jetRef); } reco::VertexRef -RecoTauVertexAssociator::associatedVertex(const TrackBaseRef& track) const +RecoTauVertexAssociator::associatedVertex(const Track* track) const { - reco::VertexRef trkVertex = ( !selectedVertices_.empty() ) ? selectedVertices_[0] : reco::VertexRef(); + // algos kHighestWeigtForLeadTrack and kCombined not supported if ( algo_ == kHighestPtInEvent ) { if ( !selectedVertices_.empty() ) trkVertex = selectedVertices_[0]; } else if ( algo_ == kClosestDeltaZ ) { - if ( track.isNonnull() ) { + if ( track ) { double closestDistance = 1.e+6; // Find the vertex that has the lowest dZ to the track int idxVertex = 0; @@ -263,7 +299,23 @@ RecoTauVertexAssociator::associatedVertex(const TrackBaseRef& track) const ++idxVertex; } } - } else if ( algo_ == kHighestWeigtForLeadTrack || algo_ == kCombined ) { + } + + if ( verbosity_ >= 1 ) { + std::cout << "--> returning vertex: x = " << trkVertex->position().x() << ", y = " << trkVertex->position().y() << ", z = " << trkVertex->position().z() << std::endl; + } + + return trkVertex; +} + + +reco::VertexRef +RecoTauVertexAssociator::associatedVertex(const TrackBaseRef& track) const +{ + + reco::VertexRef trkVertex = ( !selectedVertices_.empty() ) ? selectedVertices_[0] : reco::VertexRef(); + + if ( algo_ == kHighestWeigtForLeadTrack || algo_ == kCombined ) { if ( track.isNonnull() ) { double largestWeight = -1.; // Find the vertex that has the highest association probability to the track @@ -291,7 +343,7 @@ RecoTauVertexAssociator::associatedVertex(const TrackBaseRef& track) const int idxVertex = 0; for ( std::vector::const_iterator selectedVertex = selectedVertices_.begin(); selectedVertex != selectedVertices_.end(); ++selectedVertex ) { - double dZ = dzToTrack(*selectedVertex, track); + double dZ = dzToTrack(*selectedVertex, track.get()); if ( verbosity_ ) { std::cout << "vertex #" << idxVertex << ": x = " << (*selectedVertex)->position().x() << ", y = " << (*selectedVertex)->position().y() << ", z = " << (*selectedVertex)->position().z() << " --> dZ = " << dZ << std::endl; @@ -314,9 +366,9 @@ RecoTauVertexAssociator::associatedVertex(const TrackBaseRef& track) const } reco::VertexRef -RecoTauVertexAssociator::associatedVertex(const PFJet& jet) const +RecoTauVertexAssociator::associatedVertex(const Jet& jet) const { - if ( verbosity_ >= 1 ) { +if ( verbosity_ >= 1 ) { std::cout << ":" << std::endl; std::cout << " jet: Pt = " << jet.pt() << ", eta = " << jet.eta() << ", phi = " << jet.phi() << std::endl; std::cout << " num. Vertices = " << selectedVertices_.size() << std::endl; @@ -327,31 +379,40 @@ RecoTauVertexAssociator::associatedVertex(const PFJet& jet) const } reco::VertexRef jetVertex = ( !selectedVertices_.empty() ) ? selectedVertices_[0] : reco::VertexRef(); - const PFJet* jetPtr = &jet; + const Jet* jetPtr = &jet; // check if jet-vertex association has been determined for this jet before - std::map::iterator vertexPtr = jetToVertexAssociation_->find(jetPtr); + std::map::iterator vertexPtr = jetToVertexAssociation_->find(jetPtr); if ( vertexPtr != jetToVertexAssociation_->end() ) { jetVertex = vertexPtr->second; } else { // no jet-vertex association exists for this jet yet, compute it! if ( algo_ == kHighestPtInEvent ) { if ( !selectedVertices_.empty() ) jetVertex = selectedVertices_[0]; - } else if ( algo_ == kClosestDeltaZ || - algo_ == kHighestWeigtForLeadTrack || - algo_ == kCombined ) { + } else if ( algo_ == kClosestDeltaZ ) { + // find "leading" (highest Pt) track in jet + const reco::Track* leadTrack = getLeadTrack(jet); + if ( verbosity_ ) { + if ( leadTrack != nullptr ) std::cout << "leadTrack: Pt = " << leadTrack->pt() << ", eta = " << leadTrack->eta() << ", phi = " << leadTrack->phi() << std::endl; + else std::cout << "leadTrack: N/A" << std::endl; + } + if ( leadTrack != nullptr ) { + jetVertex = associatedVertex(leadTrack); + } + } else if (algo_ == kHighestWeigtForLeadTrack || + algo_ == kCombined ) { // find "leading" (highest Pt) track in jet - reco::TrackBaseRef leadTrack = getLeadTrack(jet); + const reco::TrackBaseRef leadTrack = getLeadTrackRef(jet); if ( verbosity_ ) { if ( leadTrack.isNonnull() ) std::cout << "leadTrack: Pt = " << leadTrack->pt() << ", eta = " << leadTrack->eta() << ", phi = " << leadTrack->phi() << std::endl; else std::cout << "leadTrack: N/A" << std::endl; } - if ( leadTrack.isNonnull() ) { + if ( leadTrack.isNonnull()) { jetVertex = associatedVertex(leadTrack); } } - jetToVertexAssociation_->insert(std::pair(jetPtr, jetVertex)); + jetToVertexAssociation_->insert(std::pair(jetPtr, jetVertex)); } if ( verbosity_ >= 1 ) { diff --git a/RecoTauTag/RecoTau/src/pfRecoTauChargedHadronAuxFunctions.cc b/RecoTauTag/RecoTau/src/pfRecoTauChargedHadronAuxFunctions.cc index 9f87a6bf9a597..52f2b73f0322e 100644 --- a/RecoTauTag/RecoTau/src/pfRecoTauChargedHadronAuxFunctions.cc +++ b/RecoTauTag/RecoTau/src/pfRecoTauChargedHadronAuxFunctions.cc @@ -1,12 +1,30 @@ #include "RecoTauTag/RecoTau/interface/pfRecoTauChargedHadronAuxFunctions.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "DataFormats/Candidate/interface/CandidateFwd.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" #include namespace reco { namespace tau { +const reco::Track* getTrackFromChargedHadron(const reco::PFRecoTauChargedHadron& chargedHadron) { + // Charged hadron made from track (reco::Track) - RECO/AOD only + if ( chargedHadron.getTrack().isNonnull()) { + return chargedHadron.getTrack().get(); + } + // In MiniAOD, even isolated tracks are saved as candidates, so the track Ptr doesn't exist + const pat::PackedCandidate* chargedPFPCand = dynamic_cast (&*chargedHadron.getChargedPFCandidate()); + if (chargedPFPCand != nullptr) { + return chargedPFPCand->bestTrack(); + } + const pat::PackedCandidate* lostTrackCand = dynamic_cast (&*chargedHadron.getLostTrackCandidate()); + if (lostTrackCand != nullptr) { + return lostTrackCand->bestTrack(); + } + return nullptr; +} + void setChargedHadronP4(reco::PFRecoTauChargedHadron& chargedHadron, double scaleFactor_neutralPFCands) { double chargedHadronP = 0.; @@ -16,22 +34,30 @@ void setChargedHadronP4(reco::PFRecoTauChargedHadron& chargedHadron, double scal double SumNeutrals = 0.; if ( chargedHadron.algoIs(reco::PFRecoTauChargedHadron::kChargedPFCandidate) || chargedHadron.algoIs(reco::PFRecoTauChargedHadron::kPFNeutralHadron) ) { - const reco::PFCandidatePtr& chargedPFCand = chargedHadron.getChargedPFCandidate(); + const reco::CandidatePtr& chargedPFCand = chargedHadron.getChargedPFCandidate(); assert(chargedPFCand.isNonnull()); chargedHadronP += chargedPFCand->p(); chargedHadronPx = chargedPFCand->px(); chargedHadronPy = chargedPFCand->py(); chargedHadronPz = chargedPFCand->pz(); } else if ( chargedHadron.algoIs(reco::PFRecoTauChargedHadron::kTrack) ) { - const reco::PFRecoTauChargedHadron::TrackPtr& track = chargedHadron.getTrack(); - assert(track.isNonnull()); - chargedHadronP += track->p(); - chargedHadronPx = track->px(); - chargedHadronPy = track->py(); - chargedHadronPz = track->pz(); + const reco::Track* track = getTrackFromChargedHadron(chargedHadron); + if (track != nullptr) { + chargedHadronP += track->p(); + chargedHadronPx = track->px(); + chargedHadronPy = track->py(); + chargedHadronPz = track->pz(); + } else { // lost tracks from MiniAOD that don't have track information saved + const reco::CandidatePtr& lostTrack = chargedHadron.getLostTrackCandidate(); + assert(lostTrack.isNonnull()); + chargedHadronP += lostTrack->p(); + chargedHadronPx = lostTrack->px(); + chargedHadronPy = lostTrack->py(); + chargedHadronPz = lostTrack->pz(); + } } else assert(0); - const std::vector& neutralPFCands = chargedHadron.getNeutralPFCandidates(); - for ( std::vector::const_iterator neutralPFCand = neutralPFCands.begin(); + const std::vector& neutralPFCands = chargedHadron.getNeutralPFCandidates(); + for ( std::vector::const_iterator neutralPFCand = neutralPFCands.begin(); neutralPFCand != neutralPFCands.end(); ++neutralPFCand ) { SumNeutrals += (*neutralPFCand)->p(); } diff --git a/RecoTauTag/RecoTau/test/BuildFile.xml b/RecoTauTag/RecoTau/test/BuildFile.xml index 7b61d3bf3fb24..d77453efb4df5 100644 --- a/RecoTauTag/RecoTau/test/BuildFile.xml +++ b/RecoTauTag/RecoTau/test/BuildFile.xml @@ -16,3 +16,9 @@ + + + + + + diff --git a/RecoTauTag/RecoTau/test/rerunTauRecoOnMiniAOD.py b/RecoTauTag/RecoTau/test/rerunTauRecoOnMiniAOD.py new file mode 100644 index 0000000000000..d49d22be832a6 --- /dev/null +++ b/RecoTauTag/RecoTau/test/rerunTauRecoOnMiniAOD.py @@ -0,0 +1,120 @@ +import FWCore.ParameterSet.Config as cms +###### +# Configuration to run tau ReReco+PAT at MiniAOD samples +# M. Bluj, NCBJ Warsaw +# based on work of J. Steggemann, CERN +# Created: 9 Nov. 2017 +###### + +###### +runSignal = True +# runSignal=False +maxEvents = 100 +# maxEvents=-1 + + +# 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 + +# 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) + +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_2018 +if phase2: + 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") +else: + process.load('Configuration.Geometry.GeometryExtended2023D17Reco_cff') + +##### +readFiles = cms.untracked.vstring() +secFiles = cms.untracked.vstring() +process.source = cms.Source( + "PoolSource", fileNames=readFiles, secondaryFileNames=secFiles) + +process.maxEvents = cms.untracked.PSet( + 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_5_0_pre1/RelValZTT_13/MINIAODSIM/PU25ns_103X_upgrade2018_realistic_v8-v1/20000/EA29017F-9967-3F41-BB8A-22C44A454235.root' + ]) +else: + readFiles.extend([ + #'file:patMiniAOD_standard.root' + '/store/relval/CMSSW_10_5_0_pre1/RelValQCD_FlatPt_15_3000HS_13/MINIAODSIM/PU25ns_103X_mcRun2_asymptotic_v3-v1/20000/A5CBC261-E3AB-C842-896F-E6AFB38DD22F.root' + ]) + +##### +import RecoTauTag.Configuration.tools.adaptToRunAtMiniAOD as tauAtMiniTools + +##### +tauAtMiniTools.addTauReReco(process) + +##### +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') +from Configuration.AlCa.GlobalTag import GlobalTag +if not phase2: + process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase1_2018_realistic', '') +else: + 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) +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' +else: + process.output.fileName = 'miniAOD_TauReco_QCD.root' + if reclusterJets: + process.output.fileName = 'miniAOD_TauReco_ak4PFJets_QCD.root' +process.out = cms.EndPath(process.output) + +##### +tauAtMiniTools.adaptTauToMiniAODReReco(process, reclusterJets) + +##### +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 + +##### +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 = cms.untracked.PSet( + process.options, + wantSummary=cms.untracked.bool(True) +) diff --git a/RecoTauTag/RecoTau/test/runtestRecoTauTagRecoTau.cpp b/RecoTauTag/RecoTau/test/runtestRecoTauTagRecoTau.cpp new file mode 100644 index 0000000000000..b2991bd18ae57 --- /dev/null +++ b/RecoTauTag/RecoTau/test/runtestRecoTauTagRecoTau.cpp @@ -0,0 +1,3 @@ +#include "FWCore/Utilities/interface/TestHelper.h" + +RUNTEST() diff --git a/RecoTauTag/RecoTau/test/runtests.sh b/RecoTauTag/RecoTau/test/runtests.sh new file mode 100755 index 0000000000000..8a0a2d274efe9 --- /dev/null +++ b/RecoTauTag/RecoTau/test/runtests.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +function die { echo $1: status $2 ; exit $2; } + +cmsRun ${LOCAL_TEST_DIR}/rerunTauRecoOnMiniAOD.py || die 'Failure using rerunTauRecoOnMiniAOD.py' $? + diff --git a/RecoTauTag/TauTagTools/interface/PFCandidateMergerBase.h b/RecoTauTag/TauTagTools/interface/PFCandidateMergerBase.h index 89d92941d79ac..022cedda54c33 100644 --- a/RecoTauTag/TauTagTools/interface/PFCandidateMergerBase.h +++ b/RecoTauTag/TauTagTools/interface/PFCandidateMergerBase.h @@ -13,7 +13,7 @@ class PFCandidateMergerBase virtual ~PFCandidateMergerBase()=0; - virtual std::vector > mergeCandidates(const std::vector&) =0; + virtual std::vector > mergeCandidates(const std::vector&) =0; }; diff --git a/RecoTauTag/TauTagTools/interface/PFCandidateStripMerger.h b/RecoTauTag/TauTagTools/interface/PFCandidateStripMerger.h index db011a32858a0..c25e7d352e44b 100644 --- a/RecoTauTag/TauTagTools/interface/PFCandidateStripMerger.h +++ b/RecoTauTag/TauTagTools/interface/PFCandidateStripMerger.h @@ -19,7 +19,7 @@ class PFCandidateStripMerger : public PFCandidateMergerBase PFCandidateStripMerger(const edm::ParameterSet&); ~PFCandidateStripMerger() override; - std::vector> mergeCandidates(const std::vector&) override; + std::vector> mergeCandidates(const std::vector&) override; private: @@ -29,7 +29,7 @@ class PFCandidateStripMerger : public PFCandidateMergerBase //Private Methods - bool candidateMatches(const reco::PFCandidatePtr&); + bool candidateMatches(const reco::CandidatePtr&); }; diff --git a/RecoTauTag/TauTagTools/interface/PFTauElementsOperators.h b/RecoTauTag/TauTagTools/interface/PFTauElementsOperators.h index eab44a7164879..0c5aa2be20cee 100644 --- a/RecoTauTag/TauTagTools/interface/PFTauElementsOperators.h +++ b/RecoTauTag/TauTagTools/interface/PFTauElementsOperators.h @@ -34,45 +34,45 @@ class PFTauElementsOperators : public TauElementsOperators { ~PFTauElementsOperators(){} void setAreaMetricrecoElementsmaxabsEta( double x); //return the leading PFCandidate in a given cone around the jet axis or a given direction - reco::PFCandidatePtr leadPFCand(const std::string matchingcone_metric,const double matchingcone_size,const double minPt)const; - reco::PFCandidatePtr leadPFCand(const math::XYZVector& myVector,const std::string matchingcone_metric,const double matchingcone_size,const double minPt)const; - reco::PFCandidatePtr leadPFChargedHadrCand(const std::string matchingcone_metric,const double matchingcone_size,const double minPt)const; - reco::PFCandidatePtr leadPFChargedHadrCand(const math::XYZVector& myVector,const std::string matchingcone_metric,const double matchingcone_size,const double minPt)const; - reco::PFCandidatePtr leadPFNeutrHadrCand(const std::string matchingcone_metric,const double matchingcone_size,const double minPt)const; - reco::PFCandidatePtr leadPFNeutrHadrCand(const math::XYZVector& myVector,const std::string matchingcone_metric,const double matchingcone_size,const double minPt)const; - reco::PFCandidatePtr leadPFGammaCand(const std::string matchingcone_metric,const double matchingcone_size,const double minPt)const; - reco::PFCandidatePtr leadPFGammaCand(const math::XYZVector& myVector,const std::string matchingcone_metric,const double matchingcone_size,const double minPt)const; + reco::CandidatePtr leadCand(const std::string matchingcone_metric,const double matchingcone_size,const double minPt)const; + reco::CandidatePtr leadCand(const math::XYZVector& myVector,const std::string matchingcone_metric,const double matchingcone_size,const double minPt)const; + reco::CandidatePtr leadChargedHadrCand(const std::string matchingcone_metric,const double matchingcone_size,const double minPt)const; + reco::CandidatePtr leadChargedHadrCand(const math::XYZVector& myVector,const std::string matchingcone_metric,const double matchingcone_size,const double minPt)const; + reco::CandidatePtr leadNeutrHadrCand(const std::string matchingcone_metric,const double matchingcone_size,const double minPt)const; + reco::CandidatePtr leadNeutrHadrCand(const math::XYZVector& myVector,const std::string matchingcone_metric,const double matchingcone_size,const double minPt)const; + reco::CandidatePtr leadGammaCand(const std::string matchingcone_metric,const double matchingcone_size,const double minPt)const; + reco::CandidatePtr leadGammaCand(const math::XYZVector& myVector,const std::string matchingcone_metric,const double matchingcone_size,const double minPt)const; // return all PFCandidates in a cone of metric* "cone_metric" and size "conesize" around a direction "myVector" - std::vector PFCandsInCone(const std::vector& PFCands,const math::XYZVector& myVector,const std::string conemetric,const double conesize,const double minPt)const; - std::vector PFCandsInCone(const math::XYZVector& myVector,const std::string conemetric,const double conesize,const double minPt)const; - std::vector PFChargedHadrCandsInCone(const math::XYZVector& myVector,const std::string conemetric,const double conesize,const double minPt)const; - std::vector PFChargedHadrCandsInCone(const math::XYZVector& myVector,const std::string conemetric,const double conesize,const double minPt,const double PFChargedHadrCand_tracktorefpoint_maxDZ,const double refpoint_Z, const reco::Vertex &mPV)const; - std::vector PFNeutrHadrCandsInCone(const math::XYZVector& myVector,const std::string conemetric,const double conesize,const double minPt)const; - std::vector PFGammaCandsInCone(const math::XYZVector& myVector,const std::string conemetric,const double conesize,const double minPt)const; + std::vector PFCandsInCone(const std::vector& PFCands,const math::XYZVector& myVector,const std::string conemetric,const double conesize,const double minPt)const; + std::vector PFCandsInCone(const math::XYZVector& myVector,const std::string conemetric,const double conesize,const double minPt)const; + std::vector PFChargedHadrCandsInCone(const math::XYZVector& myVector,const std::string conemetric,const double conesize,const double minPt)const; + std::vector PFChargedHadrCandsInCone(const math::XYZVector& myVector,const std::string conemetric,const double conesize,const double minPt,const double PFChargedHadrCand_tracktorefpoint_maxDZ,const double refpoint_Z, const reco::Vertex &mPV)const; + std::vector PFNeutrHadrCandsInCone(const math::XYZVector& myVector,const std::string conemetric,const double conesize,const double minPt)const; + std::vector PFGammaCandsInCone(const math::XYZVector& myVector,const std::string conemetric,const double conesize,const double minPt)const; // return all PFCandidates in a annulus defined by inner(metric* "innercone_metric" and size "innercone_size") and outer(metric* "outercone_metric" and size "outercone_size") cones around a direction "myVector" - std::vector PFCandsInAnnulus(const std::vector& PFCands,const math::XYZVector& myVector,const std::string innercone_metric,const double innercone_size,const std::string outercone_metric,const double outercone_size,const double minPt)const; - std::vector PFCandsInAnnulus(const math::XYZVector& myVector,const std::string innercone_metric,const double innercone_size,const std::string outercone_metric,const double outercone_size,const double minPt)const; - std::vector PFChargedHadrCandsInAnnulus(const math::XYZVector& myVector,const std::string innercone_metric,const double innercone_size,const std::string outercone_metric,const double outercone_size,const double minPt)const; - std::vector PFChargedHadrCandsInAnnulus(const math::XYZVector& myVector,const std::string innercone_metric,const double innercone_size,const std::string outercone_metric,const double outercone_size,const double minPt,const double PFChargedHadrCand_tracktorefpoint_maxDZ,const double refpoint_Z, const reco::Vertex &myPV)const; - std::vector PFNeutrHadrCandsInAnnulus(const math::XYZVector& myVector,const std::string innercone_metric,const double innercone_size,const std::string outercone_metric,const double outercone_size,const double minPt)const; - std::vector PFGammaCandsInAnnulus(const math::XYZVector& myVector,const std::string innercone_metric,const double innercone_size,const std::string outercone_metric,const double outercone_size,const double minPt)const; + std::vector PFCandsInAnnulus(const std::vector& PFCands,const math::XYZVector& myVector,const std::string innercone_metric,const double innercone_size,const std::string outercone_metric,const double outercone_size,const double minPt)const; + std::vector PFCandsInAnnulus(const math::XYZVector& myVector,const std::string innercone_metric,const double innercone_size,const std::string outercone_metric,const double outercone_size,const double minPt)const; + std::vector PFChargedHadrCandsInAnnulus(const math::XYZVector& myVector,const std::string innercone_metric,const double innercone_size,const std::string outercone_metric,const double outercone_size,const double minPt)const; + std::vector PFChargedHadrCandsInAnnulus(const math::XYZVector& myVector,const std::string innercone_metric,const double innercone_size,const std::string outercone_metric,const double outercone_size,const double minPt,const double PFChargedHadrCand_tracktorefpoint_maxDZ,const double refpoint_Z, const reco::Vertex &myPV)const; + std::vector PFNeutrHadrCandsInAnnulus(const math::XYZVector& myVector,const std::string innercone_metric,const double innercone_size,const std::string outercone_metric,const double outercone_size,const double minPt)const; + std::vector PFGammaCandsInAnnulus(const math::XYZVector& myVector,const std::string innercone_metric,const double innercone_size,const std::string outercone_metric,const double outercone_size,const double minPt)const; //Put function to get elements inside ellipse here ... EELL - std::pair,std::vector> PFGammaCandsInOutEllipse(const std::vector&, const reco::PFCandidate&, double rPhi, double rEta, double maxPt) const; + std::pair,std::vector> PFGammaCandsInOutEllipse(const std::vector&, const reco::Candidate&, double rPhi, double rEta, double maxPt) const; //EELL /// append elements of theInputCands that pass Pt requirement to the end of theOutputCands - void copyCandRefsFilteredByPt(const std::vector& theInputCands, std::vector& theOutputCands, const double minPt); + void copyCandRefsFilteredByPt(const std::vector& theInputCands, std::vector& theOutputCands, const double minPt); /// compute size of cone using the Inside-Out cone (Author Evan Friis, UC Davis) - void computeInsideOutContents(const std::vector& theChargedCands, const std::vector& theGammaCands, const math::XYZVector& leadTrackVector, + void computeInsideOutContents(const std::vector& theChargedCands, const std::vector& theGammaCands, const math::XYZVector& leadTrackVector, const TFormula& coneSizeFormula, double (*ptrToMetricFunction)(const math::XYZVector&, const math::XYZVector&), // determines grow function, and the metric to compare the opening angle to const double minChargedSize, const double maxChargedSize, const double minNeutralSize, const double maxNeutralSize, const double minChargedPt, const double minNeutralPt, const std::string& outlierCollectorConeMetric, const double outlierCollectorConeSize, - std::vector& signalChargedObjects, std::vector& outlierChargedObjects, - std::vector& signalGammaObjects, std::vector& outlierGammaObjects, bool useScanningAxis); //these last two quantities are the return values + std::vector& signalChargedObjects, std::vector& outlierChargedObjects, + std::vector& signalGammaObjects, std::vector& outlierGammaObjects, bool useScanningAxis); //these last two quantities are the return values // return 1 if no/low PFCandidates activity in an isolation annulus around a leading PFCandidate, 0 otherwise; // different possible metrics* for the matching, signal and isolation cones; @@ -101,28 +101,28 @@ class PFTauElementsOperators : public TauElementsOperators { double discriminatorByIsolPFGammaCandsEtSum(std::string matchingcone_metric,double matchingcone_size,std::string signalcone_metric,double signalcone_size,std::string isolcone_metric,double isolcone_size,bool useOnlyChargedHadrforleadPFCand,double minPt_leadPFCand,double minPt_PFCand,double IsolPFCands_maxEtSum=0); double discriminatorByIsolPFGammaCandsEtSum(const math::XYZVector& myVector,std::string matchingcone_metric,double matchingcone_size,std::string signalcone_metric,double signalcone_size,std::string isolcone_metric,double isolcone_size,bool useOnlyChargedHadrforleadPFCand,double minPt_leadPFCand,double minPt_PFCand,double IsolPFCands_maxEtSum=0); private: - reco::PFJetRef PFJetRef_; + reco::JetBaseRef PFJetRef_; double AreaMetric_recoElements_maxabsEta_; - std::vector PFCands_; - std::vector IsolPFCands_; - std::vector PFChargedHadrCands_; - std::vector IsolPFChargedHadrCands_; - std::vector PFNeutrHadrCands_; - std::vector IsolPFNeutrHadrCands_; - std::vector PFGammaCands_; - std::vector IsolPFGammaCands_; + std::vector PFCands_; + std::vector IsolPFCands_; + std::vector PFChargedHadrCands_; + std::vector IsolPFChargedHadrCands_; + std::vector PFNeutrHadrCands_; + std::vector IsolPFNeutrHadrCands_; + std::vector PFGammaCands_; + std::vector IsolPFGammaCands_; // template objects for DR and Angle metrics DeltaR metricDR_; Angle metricAngle_; double computeDeltaR(const math::XYZVector& vec1, const math::XYZVector& vec2); double computeAngle(const math::XYZVector& vec1, const math::XYZVector& vec2); - ElementsInCone,reco::PFCandidate> PFCandsinCone_DRmetric_; - ElementsInCone,reco::PFCandidate> PFCandsinCone_Anglemetric_; - ElementsInAnnulus,DeltaR,reco::PFCandidate> PFCandsinAnnulus_innerDRouterDRmetrics_; - ElementsInAnnulus,Angle,reco::PFCandidate> PFCandsinAnnulus_innerDRouterAnglemetrics_; - ElementsInAnnulus,Angle,reco::PFCandidate> PFCandsinAnnulus_innerAngleouterAnglemetrics_; - ElementsInAnnulus,DeltaR,reco::PFCandidate> PFCandsinAnnulus_innerAngleouterDRmetrics_; - ElementsInEllipse PFCandidatesInEllipse_; + ElementsInCone,reco::Candidate> PFCandsinCone_DRmetric_; + ElementsInCone,reco::Candidate> PFCandsinCone_Anglemetric_; + ElementsInAnnulus,DeltaR,reco::Candidate> PFCandsinAnnulus_innerDRouterDRmetrics_; + ElementsInAnnulus,Angle,reco::Candidate> PFCandsinAnnulus_innerDRouterAnglemetrics_; + ElementsInAnnulus,Angle,reco::Candidate> PFCandsinAnnulus_innerAngleouterAnglemetrics_; + ElementsInAnnulus,DeltaR,reco::Candidate> PFCandsinAnnulus_innerAngleouterDRmetrics_; + ElementsInEllipse PFCandidatesInEllipse_; }; #endif diff --git a/RecoTauTag/TauTagTools/interface/TauTagTools.h b/RecoTauTag/TauTagTools/interface/TauTagTools.h index 77d44d4deb93c..f4ff96eea726a 100644 --- a/RecoTauTag/TauTagTools/interface/TauTagTools.h +++ b/RecoTauTag/TauTagTools/interface/TauTagTools.h @@ -3,8 +3,8 @@ #include "DataFormats/GeometryVector/interface/GlobalPoint.h" #include "DataFormats/GeometryVector/interface/GlobalVector.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "DataFormats/Candidate/interface/CandidateFwd.h" #include "DataFormats/ParticleFlowReco/interface/PFBlock.h" #include "DataFormats/ParticleFlowReco/interface/PFBlockElement.h" #include "DataFormats/TrackReco/interface/Track.h" @@ -27,11 +27,11 @@ namespace TauTagTools{ reco::TrackRefVector filteredTracks(const reco::TrackRefVector& theInitialTracks,double tkminPt,int tkminPixelHitsn,int tkminTrackerHitsn,double tkmaxipt,double tkmaxChi2, reco::Vertex pV); reco::TrackRefVector filteredTracks(const reco::TrackRefVector& theInitialTracks,double tkminPt,int tkminPixelHitsn,int tkminTrackerHitsn,double tkmaxipt,double tkmaxChi2,double tktorefpointmaxDZ,reco::Vertex pV,double refpoint_Z); - std::vector filteredPFChargedHadrCandsByNumTrkHits(const std::vector& theInitialPFCands, int ChargedHadrCand_tkminTrackerHitsn); - std::vector filteredPFChargedHadrCands(const std::vector& theInitialPFCands,double ChargedHadrCand_tkminPt,int ChargedHadrCand_tkminPixelHitsn,int ChargedHadrCand_tkminTrackerHitsn,double ChargedHadrCand_tkmaxipt,double ChargedHadrCand_tkmaxChi2, reco::Vertex pV); - std::vector filteredPFChargedHadrCands(const std::vector& theInitialPFCands,double ChargedHadrCand_tkminPt,int ChargedHadrCand_tkminPixelHitsn,int ChargedHadrCand_tkminTrackerHitsn,double ChargedHadrCand_tkmaxipt,double ChargedHadrCand_tkmaxChi2,double ChargedHadrCand_tktorefpointmaxDZ,reco::Vertex pV, double refpoint_Z); - std::vector filteredPFNeutrHadrCands(const std::vector& theInitialPFCands,double NeutrHadrCand_HcalclusMinEt); - std::vector filteredPFGammaCands(const std::vector& theInitialPFCands,double GammaCand_EcalclusMinEt); + std::vector filteredPFChargedHadrCandsByNumTrkHits(const std::vector& theInitialPFCands, int ChargedHadrCand_tkminTrackerHitsn); + std::vector filteredPFChargedHadrCands(const std::vector& theInitialPFCands,double ChargedHadrCand_tkminPt,int ChargedHadrCand_tkminPixelHitsn,int ChargedHadrCand_tkminTrackerHitsn,double ChargedHadrCand_tkmaxipt,double ChargedHadrCand_tkmaxChi2, reco::Vertex pV); + std::vector filteredPFChargedHadrCands(const std::vector& theInitialPFCands,double ChargedHadrCand_tkminPt,int ChargedHadrCand_tkminPixelHitsn,int ChargedHadrCand_tkminTrackerHitsn,double ChargedHadrCand_tkmaxipt,double ChargedHadrCand_tkmaxChi2,double ChargedHadrCand_tktorefpointmaxDZ,reco::Vertex pV, double refpoint_Z); + std::vector filteredPFNeutrHadrCands(const std::vector& theInitialPFCands,double NeutrHadrCand_HcalclusMinEt); + std::vector filteredPFGammaCands(const std::vector& theInitialPFCands,double GammaCand_EcalclusMinEt); math::XYZPoint propagTrackECALSurfContactPoint(const MagneticField*,reco::TrackRef); TFormula computeConeSizeTFormula(const std::string& ConeSizeFormula,const char* errorMessage); @@ -41,32 +41,32 @@ namespace TauTagTools{ double computeAngle(const math::XYZVector& vec1, const math::XYZVector& vec2); //MIKE: Sort a reference vector - void sortRefVectorByPt(std::vector&); + void sortRefVectorByPt(std::vector&); //binary predicate classes for sorting a list of indexes corresponding to PFPtrVectors...(as they can't use STL??) class sortRefsByOpeningDistance { public: - sortRefsByOpeningDistance(const math::XYZVector& theAxis, double (*ptrToMetricFunction)(const math::XYZVector&, const math::XYZVector&), const std::vector& myInputVector):myMetricFunction(ptrToMetricFunction),axis(theAxis),myVector(myInputVector){}; + sortRefsByOpeningDistance(const math::XYZVector& theAxis, double (*ptrToMetricFunction)(const math::XYZVector&, const math::XYZVector&), const std::vector& myInputVector):myMetricFunction(ptrToMetricFunction),axis(theAxis),myVector(myInputVector){}; bool operator()(uint32_t indexA, uint32_t indexB) { - const reco::PFCandidatePtr candA = myVector.at(indexA); - const reco::PFCandidatePtr candB = myVector.at(indexB); + const reco::CandidatePtr candA = myVector.at(indexA); + const reco::CandidatePtr candB = myVector.at(indexB); return (myMetricFunction(axis, candA->momentum()) < myMetricFunction(axis, candB->momentum())); } private: double (*myMetricFunction)(const math::XYZVector&, const math::XYZVector&); math::XYZVector axis; //axis about which candidates are sorted - const std::vector myVector; + const std::vector myVector; }; class filterChargedAndNeutralsByPt { public: - filterChargedAndNeutralsByPt(double minNeutralPt, double minChargedPt, const std::vector& myInputVector):minNeutralPt_(minNeutralPt),minChargedPt_(minChargedPt),myVector(myInputVector){}; + filterChargedAndNeutralsByPt(double minNeutralPt, double minChargedPt, const std::vector& myInputVector):minNeutralPt_(minNeutralPt),minChargedPt_(minChargedPt),myVector(myInputVector){}; bool operator()(uint32_t candIndex) { - const reco::PFCandidatePtr cand = myVector.at(candIndex); + const reco::CandidatePtr cand = myVector.at(candIndex); bool output = true; unsigned char charge = std::abs(cand->charge()); double thePt = cand->pt(); @@ -79,12 +79,12 @@ namespace TauTagTools{ private: double minNeutralPt_; double minChargedPt_; - const std::vector& myVector; + const std::vector& myVector; }; class refVectorPtSorter { public: - refVectorPtSorter(const std::vector& vec) + refVectorPtSorter(const std::vector& vec) { vec_ = vec; } @@ -102,7 +102,7 @@ namespace TauTagTools{ } private: - std::vector vec_; + std::vector vec_; }; diff --git a/RecoTauTag/TauTagTools/plugins/RecoTauDifferenceAnalyzer.cc b/RecoTauTag/TauTagTools/plugins/RecoTauDifferenceAnalyzer.cc index 58bc127931c84..6ba495a4a68a1 100644 --- a/RecoTauTag/TauTagTools/plugins/RecoTauDifferenceAnalyzer.cc +++ b/RecoTauTag/TauTagTools/plugins/RecoTauDifferenceAnalyzer.cc @@ -46,7 +46,7 @@ RecoTauDifferenceAnalyzer::RecoTauDifferenceAnalyzer( } namespace { - reco::PFJetRef getJetRef(const reco::PFTau& tau) { + reco::JetBaseRef getJetRef(const reco::PFTau& tau) { if (tau.jetRef().isNonnull()) return tau.jetRef(); else if (tau.pfTauTagInfoRef()->pfjetRef().isNonnull()) @@ -80,8 +80,8 @@ bool RecoTauDifferenceAnalyzer::filter( double bestDeltaR = -1; for (size_t iTau2 = 0; iTau2 < taus2->size(); ++iTau2) { reco::PFTauRef tau2(taus2, iTau2); - reco::PFJetRef jet1 = getJetRef(*tau1); - reco::PFJetRef jet2 = getJetRef(*tau2); + reco::JetBaseRef jet1 = getJetRef(*tau1); + reco::JetBaseRef jet2 = getJetRef(*tau2); double deltaRVal = deltaR(jet2->p4(), jet1->p4()); if (bestMatch.isNull() || deltaRVal < bestDeltaR) { bestMatch = tau2; diff --git a/RecoTauTag/TauTagTools/plugins/RecoTauDumper.cc b/RecoTauTag/TauTagTools/plugins/RecoTauDumper.cc index ba04600fce9b4..0f1b561bc17e7 100644 --- a/RecoTauTag/TauTagTools/plugins/RecoTauDumper.cc +++ b/RecoTauTag/TauTagTools/plugins/RecoTauDumper.cc @@ -17,6 +17,7 @@ #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "DataFormats/TauReco/interface/PFTau.h" +#include "DataFormats/JetReco/interface/PFJet.h" #include "DataFormats/Candidate/interface/Candidate.h" // Methods to write the different types diff --git a/RecoTauTag/TauTagTools/plugins/RecoTauObjectEmbedderPlugin.cc b/RecoTauTag/TauTagTools/plugins/RecoTauObjectEmbedderPlugin.cc index 75767377c64ea..d8e5528c383dd 100644 --- a/RecoTauTag/TauTagTools/plugins/RecoTauObjectEmbedderPlugin.cc +++ b/RecoTauTag/TauTagTools/plugins/RecoTauObjectEmbedderPlugin.cc @@ -43,7 +43,7 @@ unsigned int nGammas(const GenJet& jet) { } unsigned int nCharged(const PFTau& tau) { - return tau.signalPFChargedHadrCands().size(); + return tau.signalChargedHadrCands().size(); } unsigned int nGammas(const PFTau& tau) { return tau.signalPiZeroCandidates().size(); diff --git a/RecoTauTag/TauTagTools/plugins/RecoTauPiZeroFlattener.cc b/RecoTauTag/TauTagTools/plugins/RecoTauPiZeroFlattener.cc index de9d103fac94e..c1e968516113b 100644 --- a/RecoTauTag/TauTagTools/plugins/RecoTauPiZeroFlattener.cc +++ b/RecoTauTag/TauTagTools/plugins/RecoTauPiZeroFlattener.cc @@ -60,7 +60,7 @@ RecoTauPiZeroFlattener::produce(edm::Event& evt, const edm::EventSetup& es) { // Loop over the jets and append the pizeros for each jet to our output // collection. for(auto const& jetRef : jets) { - const std::vector& pizeros = (*piZeroAssoc)[jetRef]; + const std::vector& pizeros = (*piZeroAssoc)[reco::JetBaseRef(jetRef)]; output->reserve(output->size() + pizeros.size()); output->insert(output->end(), pizeros.begin(), pizeros.end()); } diff --git a/RecoTauTag/TauTagTools/src/PFCandidateStripMerger.cc b/RecoTauTag/TauTagTools/src/PFCandidateStripMerger.cc index 99dbea4e7a867..bdee5a8673ab1 100644 --- a/RecoTauTag/TauTagTools/src/PFCandidateStripMerger.cc +++ b/RecoTauTag/TauTagTools/src/PFCandidateStripMerger.cc @@ -22,7 +22,7 @@ PFCandidateStripMerger::~PFCandidateStripMerger() bool -PFCandidateStripMerger::candidateMatches(const reco::PFCandidatePtr& cand) +PFCandidateStripMerger::candidateMatches(const reco::CandidatePtr& cand) { bool matches = false; for(unsigned int i=0; i < inputPdgIds_.size(); ++i) { @@ -39,12 +39,12 @@ PFCandidateStripMerger::candidateMatches(const reco::PFCandidatePtr& cand) -vector> -PFCandidateStripMerger::mergeCandidates(const vector& candidates) +vector> +PFCandidateStripMerger::mergeCandidates(const vector& candidates) { //Copy the input getting the relevant candidates and sort by pt - vector cands; + vector cands; for(unsigned int i=0;i& candidates if(cands.size()>1) TauTagTools::sortRefVectorByPt(cands); - std::vector> strips; + std::vector> strips; //Repeat while there are still unclusterized gammas while(!cands.empty()) { //save the non associated candidates to a different collection - vector notAssociated; + vector notAssociated; //Create a cluster from the Seed Photon - vector strip; + vector strip; math::XYZTLorentzVector stripVector; strip.push_back(cands.at(0)); stripVector=cands.at(0)->p4(); diff --git a/RecoTauTag/TauTagTools/src/PFTauElementsOperators.cc b/RecoTauTag/TauTagTools/src/PFTauElementsOperators.cc index c5ff01c087a46..9e187e7257caa 100644 --- a/RecoTauTag/TauTagTools/src/PFTauElementsOperators.cc +++ b/RecoTauTag/TauTagTools/src/PFTauElementsOperators.cc @@ -9,20 +9,20 @@ using std::string; PFChargedHadrCands_=thePFTau.pfTauTagInfoRef()->PFChargedHadrCands(); PFNeutrHadrCands_=thePFTau.pfTauTagInfoRef()->PFNeutrHadrCands(); PFGammaCands_=thePFTau.pfTauTagInfoRef()->PFGammaCands(); - IsolPFCands_=thePFTau.isolationPFCands(); - IsolPFChargedHadrCands_=thePFTau.isolationPFChargedHadrCands(); - IsolPFNeutrHadrCands_=thePFTau.isolationPFNeutrHadrCands(); - IsolPFGammaCands_=thePFTau.isolationPFGammaCands(); + IsolPFCands_=thePFTau.isolationCands(); + IsolPFChargedHadrCands_=thePFTau.isolationChargedHadrCands(); + IsolPFNeutrHadrCands_=thePFTau.isolationNeutrHadrCands(); + IsolPFGammaCands_=thePFTau.isolationGammaCands(); Tracks_=thePFTau.pfTauTagInfoRef()->Tracks(); } void PFTauElementsOperators::setAreaMetricrecoElementsmaxabsEta( double x) {AreaMetric_recoElements_maxabsEta_=x;} -std::vector PFTauElementsOperators::PFCandsInCone(const std::vector& thePFCands,const math::XYZVector& myVector,const string conemetric,const double conesize,const double minPt)const{ - std::vector theFilteredPFCands; - for (std::vector::const_iterator iPFCand=thePFCands.begin();iPFCand!=thePFCands.end();++iPFCand) { +std::vector PFTauElementsOperators::PFCandsInCone(const std::vector& thePFCands,const math::XYZVector& myVector,const string conemetric,const double conesize,const double minPt)const{ + std::vector theFilteredPFCands; + for (std::vector::const_iterator iPFCand=thePFCands.begin();iPFCand!=thePFCands.end();++iPFCand) { if ((**iPFCand).pt()>minPt)theFilteredPFCands.push_back(*iPFCand); } - std::vector theFilteredPFCandsInCone; + std::vector theFilteredPFCandsInCone; if (conemetric=="DR"){ theFilteredPFCandsInCone=PFCandsinCone_DRmetric_(myVector,metricDR_,conesize,theFilteredPFCands); }else if(conemetric=="angle"){ @@ -34,59 +34,60 @@ std::vector PFTauElementsOperators::PFCandsInCone(const st double coneangle=theFixedAreaCone(myVector.theta(),myVector.phi(),0,conesize,errorFlag); if (errorFlag!=0)return theFilteredPFCandsInCone; theFilteredPFCandsInCone=PFCandsinCone_Anglemetric_(myVector,metricAngle_,coneangle,theFilteredPFCands); - }else return std::vector(); + }else return std::vector(); return theFilteredPFCandsInCone; } -std::vector PFTauElementsOperators::PFCandsInCone(const math::XYZVector& myVector,const string conemetric,const double conesize,const double minPt)const{ - std::vector theFilteredPFCandsInCone=PFCandsInCone(PFCands_,myVector,conemetric,conesize,minPt); +std::vector PFTauElementsOperators::PFCandsInCone(const math::XYZVector& myVector,const string conemetric,const double conesize,const double minPt)const{ + std::vector theFilteredPFCandsInCone=PFCandsInCone(PFCands_,myVector,conemetric,conesize,minPt); return theFilteredPFCandsInCone; } -std::vector PFTauElementsOperators::PFChargedHadrCandsInCone(const math::XYZVector& myVector,const string conemetric,const double conesize,const double minPt)const{ - std::vector theFilteredPFCandsInCone=PFCandsInCone(PFChargedHadrCands_,myVector,conemetric,conesize,minPt); +std::vector PFTauElementsOperators::PFChargedHadrCandsInCone(const math::XYZVector& myVector,const string conemetric,const double conesize,const double minPt)const{ + std::vector theFilteredPFCandsInCone=PFCandsInCone(PFChargedHadrCands_,myVector,conemetric,conesize,minPt); return theFilteredPFCandsInCone; } -std::vector PFTauElementsOperators::PFChargedHadrCandsInCone(const math::XYZVector& myVector,const string conemetric,const double conesize,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++){ - TrackRef PFChargedHadrCand_track=(**iPFCand).trackRef(); - if (!PFChargedHadrCand_track)continue; - if (fabs((*PFChargedHadrCand_track).dz(myPV.position())-refpoint_Z)<=PFChargedHadrCand_tracktorefpoint_maxDZ) filteredPFChargedHadrCands.push_back(*iPFCand); +std::vector PFTauElementsOperators::PFChargedHadrCandsInCone(const math::XYZVector& myVector,const string conemetric,const double conesize,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::Track* PFChargedHadrCand_track = (*iPFCand)->bestTrack(); + if (PFChargedHadrCand_track == nullptr) continue; + if (fabs(PFChargedHadrCand_track->dz(myPV.position())-refpoint_Z)<=PFChargedHadrCand_tracktorefpoint_maxDZ) filteredPFChargedHadrCands.push_back(*iPFCand); + } - std::vector theFilteredPFCandsInCone=PFCandsInCone(filteredPFChargedHadrCands,myVector,conemetric,conesize,minPt); + std::vector theFilteredPFCandsInCone=PFCandsInCone(filteredPFChargedHadrCands,myVector,conemetric,conesize,minPt); return theFilteredPFCandsInCone; } -std::vector PFTauElementsOperators::PFNeutrHadrCandsInCone(const math::XYZVector& myVector,const string conemetric,const double conesize,const double minPt)const{ - std::vector theFilteredPFCandsInCone=PFCandsInCone(PFNeutrHadrCands_,myVector,conemetric,conesize,minPt); +std::vector PFTauElementsOperators::PFNeutrHadrCandsInCone(const math::XYZVector& myVector,const string conemetric,const double conesize,const double minPt)const{ + std::vector theFilteredPFCandsInCone=PFCandsInCone(PFNeutrHadrCands_,myVector,conemetric,conesize,minPt); return theFilteredPFCandsInCone; } - std::vector PFTauElementsOperators::PFGammaCandsInCone(const math::XYZVector& myVector,const string conemetric,const double conesize,const double minPt)const{ - std::vector theFilteredPFCandsInCone=PFCandsInCone(PFGammaCands_,myVector,conemetric,conesize,minPt); + std::vector PFTauElementsOperators::PFGammaCandsInCone(const math::XYZVector& myVector,const string conemetric,const double conesize,const double minPt)const{ + std::vector theFilteredPFCandsInCone=PFCandsInCone(PFGammaCands_,myVector,conemetric,conesize,minPt); return theFilteredPFCandsInCone; } // Function to get elements inside ellipse here ... EELL -std::pair, std::vector> PFTauElementsOperators::PFGammaCandsInOutEllipse(const std::vector& PFGammaCands_, const PFCandidate& leadCand_, double rPhi, double rEta, double maxPt) const{ - std::pair,std::vector> myPFGammaCandsInEllipse = PFCandidatesInEllipse_(leadCand_, rPhi, rEta, PFGammaCands_); - std::vector thePFGammaCandsInEllipse = myPFGammaCandsInEllipse.first; - std::vector thePFGammaCandsOutEllipse = myPFGammaCandsInEllipse.second; - std::vector theFilteredPFGammaCandsInEllipse; - for(std::vector::const_iterator iPFGammaCand = thePFGammaCandsInEllipse.begin(); iPFGammaCand != thePFGammaCandsInEllipse.end(); ++iPFGammaCand){ +std::pair, std::vector> PFTauElementsOperators::PFGammaCandsInOutEllipse(const std::vector& PFGammaCands_, const Candidate& leadCand_, double rPhi, double rEta, double maxPt) const{ + std::pair,std::vector> myPFGammaCandsInEllipse = PFCandidatesInEllipse_(leadCand_, rPhi, rEta, PFGammaCands_); + std::vector thePFGammaCandsInEllipse = myPFGammaCandsInEllipse.first; + std::vector thePFGammaCandsOutEllipse = myPFGammaCandsInEllipse.second; + std::vector theFilteredPFGammaCandsInEllipse; + for(std::vector::const_iterator iPFGammaCand = thePFGammaCandsInEllipse.begin(); iPFGammaCand != thePFGammaCandsInEllipse.end(); ++iPFGammaCand){ if((**iPFGammaCand).pt() <= maxPt) theFilteredPFGammaCandsInEllipse.push_back(*iPFGammaCand); else thePFGammaCandsOutEllipse.push_back(*iPFGammaCand); } - std::pair, std::vector> theFilteredPFGammaCandsInOutEllipse(theFilteredPFGammaCandsInEllipse, thePFGammaCandsOutEllipse); + std::pair, std::vector> theFilteredPFGammaCandsInOutEllipse(theFilteredPFGammaCandsInEllipse, thePFGammaCandsOutEllipse); return theFilteredPFGammaCandsInOutEllipse; } // EELL - std::vector PFTauElementsOperators::PFCandsInAnnulus(const std::vector& thePFCands,const math::XYZVector& myVector,const string innercone_metric,const double innercone_size,const string outercone_metric,const double outercone_size,const double minPt)const{ - std::vector theFilteredPFCands; - for (std::vector::const_iterator iPFCand=thePFCands.begin();iPFCand!=thePFCands.end();++iPFCand) { + std::vector PFTauElementsOperators::PFCandsInAnnulus(const std::vector& thePFCands,const math::XYZVector& myVector,const string innercone_metric,const double innercone_size,const string outercone_metric,const double outercone_size,const double minPt)const{ + std::vector theFilteredPFCands; + for (std::vector::const_iterator iPFCand=thePFCands.begin();iPFCand!=thePFCands.end();++iPFCand) { if ((**iPFCand).pt()>minPt)theFilteredPFCands.push_back(*iPFCand); } - std::vector theFilteredPFCandsInAnnulus; + std::vector theFilteredPFCandsInAnnulus; if (outercone_metric=="DR"){ if (innercone_metric=="DR"){ theFilteredPFCandsInAnnulus=PFCandsinAnnulus_innerDRouterDRmetrics_(myVector,metricDR_,innercone_size,metricDR_,outercone_size,theFilteredPFCands); @@ -99,7 +100,7 @@ std::pair, std::vector> double innercone_angle=theFixedAreaSignalCone(myVector.theta(),myVector.phi(),0,innercone_size,errorFlag); if (errorFlag!=0)return theFilteredPFCandsInAnnulus; theFilteredPFCandsInAnnulus=PFCandsinAnnulus_innerAngleouterDRmetrics_(myVector,metricAngle_,innercone_angle,metricDR_,outercone_size,theFilteredPFCands); - }else return std::vector(); + }else return std::vector(); }else if(outercone_metric=="angle"){ if (innercone_metric=="DR"){ theFilteredPFCandsInAnnulus=PFCandsinAnnulus_innerDRouterAnglemetrics_(myVector,metricDR_,innercone_size,metricAngle_,outercone_size,theFilteredPFCands); @@ -112,7 +113,7 @@ std::pair, std::vector> double innercone_angle=theFixedAreaSignalCone(myVector.theta(),myVector.phi(),0,innercone_size,errorFlag); if (errorFlag!=0)return theFilteredPFCandsInAnnulus; theFilteredPFCandsInAnnulus=PFCandsinAnnulus_innerAngleouterAnglemetrics_(myVector,metricAngle_,innercone_angle,metricAngle_,outercone_size,theFilteredPFCands); - }else return std::vector(); + }else return std::vector(); }else if(outercone_metric=="area"){ int errorFlag=0; FixedAreaIsolationCone theFixedAreaSignalCone; @@ -129,44 +130,45 @@ std::pair, std::vector> double outercone_angle=theFixedAreaSignalCone(myVector.theta(),myVector.phi(),innercone_angle,outercone_size,errorFlag); if (errorFlag!=0)return theFilteredPFCandsInAnnulus; theFilteredPFCandsInAnnulus=PFCandsinAnnulus_innerAngleouterAnglemetrics_(myVector,metricAngle_,innercone_angle,metricAngle_,outercone_angle,theFilteredPFCands); - }else return std::vector(); + }else return std::vector(); } return theFilteredPFCandsInAnnulus; } - std::vector PFTauElementsOperators::PFCandsInAnnulus(const math::XYZVector& myVector,const string innercone_metric,const double innercone_size,const string outercone_metric,const double outercone_size,const double minPt)const{ - std::vector theFilteredPFCandsInAnnulus=PFCandsInAnnulus(PFCands_,myVector,innercone_metric,innercone_size,outercone_metric,outercone_size,minPt); + std::vector PFTauElementsOperators::PFCandsInAnnulus(const math::XYZVector& myVector,const string innercone_metric,const double innercone_size,const string outercone_metric,const double outercone_size,const double minPt)const{ + std::vector theFilteredPFCandsInAnnulus=PFCandsInAnnulus(PFCands_,myVector,innercone_metric,innercone_size,outercone_metric,outercone_size,minPt); return theFilteredPFCandsInAnnulus; } - 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{ - std::vector theFilteredPFCandsInAnnulus=PFCandsInAnnulus(PFChargedHadrCands_,myVector,innercone_metric,innercone_size,outercone_metric,outercone_size,minPt); + 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{ + std::vector theFilteredPFCandsInAnnulus=PFCandsInAnnulus(PFChargedHadrCands_,myVector,innercone_metric,innercone_size,outercone_metric,outercone_size,minPt); return theFilteredPFCandsInAnnulus; } -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++){ - TrackRef PFChargedHadrCand_track=(**iPFCand).trackRef(); - if (!PFChargedHadrCand_track)continue; - if (fabs((*PFChargedHadrCand_track).dz(myPV.position())-refpoint_Z)<=PFChargedHadrCand_tracktorefpoint_maxDZ) filteredPFChargedHadrCands.push_back(*iPFCand); +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::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("Missing information") << "No associated track information is saved in charged hadron candidate.\n"; } - std::vector theFilteredPFCandsInAnnulus=PFCandsInAnnulus(filteredPFChargedHadrCands,myVector,innercone_metric,innercone_size,outercone_metric,outercone_size,minPt); + std::vector theFilteredPFCandsInAnnulus=PFCandsInAnnulus(filteredPFChargedHadrCands,myVector,innercone_metric,innercone_size,outercone_metric,outercone_size,minPt); return theFilteredPFCandsInAnnulus; } - std::vector PFTauElementsOperators::PFNeutrHadrCandsInAnnulus(const math::XYZVector& myVector,const string innercone_metric,const double innercone_size,const string outercone_metric,const double outercone_size,const double minPt)const{ - std::vector theFilteredPFCandsInAnnulus=PFCandsInAnnulus(PFNeutrHadrCands_,myVector,innercone_metric,innercone_size,outercone_metric,outercone_size,minPt); + std::vector PFTauElementsOperators::PFNeutrHadrCandsInAnnulus(const math::XYZVector& myVector,const string innercone_metric,const double innercone_size,const string outercone_metric,const double outercone_size,const double minPt)const{ + std::vector theFilteredPFCandsInAnnulus=PFCandsInAnnulus(PFNeutrHadrCands_,myVector,innercone_metric,innercone_size,outercone_metric,outercone_size,minPt); return theFilteredPFCandsInAnnulus; } - std::vector PFTauElementsOperators::PFGammaCandsInAnnulus(const math::XYZVector& myVector,const string innercone_metric,const double innercone_size,const string outercone_metric,const double outercone_size,const double minPt)const{ - std::vector theFilteredPFCandsInAnnulus=PFCandsInAnnulus(PFGammaCands_,myVector,innercone_metric,innercone_size,outercone_metric,outercone_size,minPt); + std::vector PFTauElementsOperators::PFGammaCandsInAnnulus(const math::XYZVector& myVector,const string innercone_metric,const double innercone_size,const string outercone_metric,const double outercone_size,const double minPt)const{ + std::vector theFilteredPFCandsInAnnulus=PFCandsInAnnulus(PFGammaCands_,myVector,innercone_metric,innercone_size,outercone_metric,outercone_size,minPt); return theFilteredPFCandsInAnnulus; } -PFCandidatePtr PFTauElementsOperators::leadPFCand(const string matchingcone_metric,const double matchingcone_size,const double minPt)const{ - PFCandidatePtr myleadPFCand; +CandidatePtr PFTauElementsOperators::leadCand(const string matchingcone_metric,const double matchingcone_size,const double minPt)const{ + CandidatePtr myleadPFCand; if (!PFJetRef_) return myleadPFCand; math::XYZVector PFJet_XYZVector=(*PFJetRef_).momentum(); - const std::vector theFilteredPFCandsInCone=PFCandsInCone(PFJet_XYZVector,matchingcone_metric,matchingcone_size,minPt); + const std::vector theFilteredPFCandsInCone=PFCandsInCone(PFJet_XYZVector,matchingcone_metric,matchingcone_size,minPt); double pt_cut=minPt; if (theFilteredPFCandsInCone.size()>0.){ - for(std::vector::const_iterator iPFCand =theFilteredPFCandsInCone.begin();iPFCand!=theFilteredPFCandsInCone.end();iPFCand++){ + for(std::vector::const_iterator iPFCand =theFilteredPFCandsInCone.begin();iPFCand!=theFilteredPFCandsInCone.end();iPFCand++){ if((*iPFCand)->pt()>pt_cut) { myleadPFCand=*iPFCand; pt_cut=(**iPFCand).pt(); @@ -175,12 +177,12 @@ PFCandidatePtr PFTauElementsOperators::leadPFCand(const string matchingcone_metr } return myleadPFCand; } -PFCandidatePtr PFTauElementsOperators::leadPFCand(const math::XYZVector& myVector,const string matchingcone_metric,const double matchingcone_size,const double minPt)const{ - PFCandidatePtr myleadPFCand; - const std::vector theFilteredPFCandsInCone=PFCandsInCone(myVector,matchingcone_metric,matchingcone_size,minPt); +CandidatePtr PFTauElementsOperators::leadCand(const math::XYZVector& myVector,const string matchingcone_metric,const double matchingcone_size,const double minPt)const{ + CandidatePtr myleadPFCand; + const std::vector theFilteredPFCandsInCone=PFCandsInCone(myVector,matchingcone_metric,matchingcone_size,minPt); double pt_cut=minPt; if (!theFilteredPFCandsInCone.empty()){ - for(std::vector::const_iterator iPFCand=theFilteredPFCandsInCone.begin();iPFCand!=theFilteredPFCandsInCone.end();iPFCand++){ + for(std::vector::const_iterator iPFCand=theFilteredPFCandsInCone.begin();iPFCand!=theFilteredPFCandsInCone.end();iPFCand++){ if((*iPFCand)->pt()>pt_cut) { myleadPFCand=*iPFCand; pt_cut=(**iPFCand).pt(); @@ -189,14 +191,14 @@ PFCandidatePtr PFTauElementsOperators::leadPFCand(const math::XYZVector& myVecto } return myleadPFCand; } -PFCandidatePtr PFTauElementsOperators::leadPFChargedHadrCand(const string matchingcone_metric,const double matchingcone_size,const double minPt)const{ - PFCandidatePtr myleadPFCand; +CandidatePtr PFTauElementsOperators::leadChargedHadrCand(const string matchingcone_metric,const double matchingcone_size,const double minPt)const{ + CandidatePtr myleadPFCand; if (!PFJetRef_) return myleadPFCand; math::XYZVector PFJet_XYZVector=(*PFJetRef_).momentum(); - const std::vector theFilteredPFCandsInCone=PFChargedHadrCandsInCone(PFJet_XYZVector,matchingcone_metric,matchingcone_size,minPt); + const std::vector theFilteredPFCandsInCone=PFChargedHadrCandsInCone(PFJet_XYZVector,matchingcone_metric,matchingcone_size,minPt); double pt_cut=minPt; if (theFilteredPFCandsInCone.size()>0.){ - for(std::vector::const_iterator iPFCand =theFilteredPFCandsInCone.begin();iPFCand!=theFilteredPFCandsInCone.end();iPFCand++){ + for(std::vector::const_iterator iPFCand =theFilteredPFCandsInCone.begin();iPFCand!=theFilteredPFCandsInCone.end();iPFCand++){ if((*iPFCand)->pt()>pt_cut) { myleadPFCand=*iPFCand; pt_cut=(**iPFCand).pt(); @@ -205,12 +207,12 @@ PFCandidatePtr PFTauElementsOperators::leadPFChargedHadrCand(const string matchi } return myleadPFCand; } -PFCandidatePtr PFTauElementsOperators::leadPFChargedHadrCand(const math::XYZVector& myVector,const string matchingcone_metric,const double matchingcone_size,const double minPt)const{ - PFCandidatePtr myleadPFCand; - const std::vector theFilteredPFCandsInCone=PFChargedHadrCandsInCone(myVector,matchingcone_metric,matchingcone_size,minPt); +CandidatePtr PFTauElementsOperators::leadChargedHadrCand(const math::XYZVector& myVector,const string matchingcone_metric,const double matchingcone_size,const double minPt)const{ + CandidatePtr myleadPFCand; + const std::vector theFilteredPFCandsInCone=PFChargedHadrCandsInCone(myVector,matchingcone_metric,matchingcone_size,minPt); double pt_cut=minPt; if (!theFilteredPFCandsInCone.empty()){ - for(std::vector::const_iterator iPFCand=theFilteredPFCandsInCone.begin();iPFCand!=theFilteredPFCandsInCone.end();iPFCand++){ + for(std::vector::const_iterator iPFCand=theFilteredPFCandsInCone.begin();iPFCand!=theFilteredPFCandsInCone.end();iPFCand++){ if((*iPFCand)->pt()>pt_cut) { myleadPFCand=*iPFCand; pt_cut=(**iPFCand).pt(); @@ -219,14 +221,14 @@ PFCandidatePtr PFTauElementsOperators::leadPFChargedHadrCand(const math::XYZVect } return myleadPFCand; } -PFCandidatePtr PFTauElementsOperators::leadPFNeutrHadrCand(const string matchingcone_metric,const double matchingcone_size,const double minPt)const{ - PFCandidatePtr myleadPFCand; +CandidatePtr PFTauElementsOperators::leadNeutrHadrCand(const string matchingcone_metric,const double matchingcone_size,const double minPt)const{ + CandidatePtr myleadPFCand; if (!PFJetRef_) return myleadPFCand; math::XYZVector PFJet_XYZVector=(*PFJetRef_).momentum(); - const std::vector theFilteredPFCandsInCone=PFNeutrHadrCandsInCone(PFJet_XYZVector,matchingcone_metric,matchingcone_size,minPt); + const std::vector theFilteredPFCandsInCone=PFNeutrHadrCandsInCone(PFJet_XYZVector,matchingcone_metric,matchingcone_size,minPt); double pt_cut=minPt; if (theFilteredPFCandsInCone.size()>0.){ - for(std::vector::const_iterator iPFCand =theFilteredPFCandsInCone.begin();iPFCand!=theFilteredPFCandsInCone.end();iPFCand++){ + for(std::vector::const_iterator iPFCand =theFilteredPFCandsInCone.begin();iPFCand!=theFilteredPFCandsInCone.end();iPFCand++){ if((*iPFCand)->pt()>pt_cut) { myleadPFCand=*iPFCand; pt_cut=(**iPFCand).pt(); @@ -235,12 +237,12 @@ PFCandidatePtr PFTauElementsOperators::leadPFNeutrHadrCand(const string matching } return myleadPFCand; } -PFCandidatePtr PFTauElementsOperators::leadPFNeutrHadrCand(const math::XYZVector& myVector,const string matchingcone_metric,const double matchingcone_size,const double minPt)const{ - PFCandidatePtr myleadPFCand; - const std::vector theFilteredPFCandsInCone=PFNeutrHadrCandsInCone(myVector,matchingcone_metric,matchingcone_size,minPt); +CandidatePtr PFTauElementsOperators::leadNeutrHadrCand(const math::XYZVector& myVector,const string matchingcone_metric,const double matchingcone_size,const double minPt)const{ + CandidatePtr myleadPFCand; + const std::vector theFilteredPFCandsInCone=PFNeutrHadrCandsInCone(myVector,matchingcone_metric,matchingcone_size,minPt); double pt_cut=minPt; if (!theFilteredPFCandsInCone.empty()){ - for(std::vector::const_iterator iPFCand=theFilteredPFCandsInCone.begin();iPFCand!=theFilteredPFCandsInCone.end();iPFCand++){ + for(std::vector::const_iterator iPFCand=theFilteredPFCandsInCone.begin();iPFCand!=theFilteredPFCandsInCone.end();iPFCand++){ if((*iPFCand)->pt()>pt_cut) { myleadPFCand=*iPFCand; pt_cut=(**iPFCand).pt(); @@ -249,14 +251,14 @@ PFCandidatePtr PFTauElementsOperators::leadPFNeutrHadrCand(const math::XYZVector } return myleadPFCand; } -PFCandidatePtr PFTauElementsOperators::leadPFGammaCand(const string matchingcone_metric,const double matchingcone_size,const double minPt)const{ - PFCandidatePtr myleadPFCand; +CandidatePtr PFTauElementsOperators::leadGammaCand(const string matchingcone_metric,const double matchingcone_size,const double minPt)const{ + CandidatePtr myleadPFCand; if (!PFJetRef_) return myleadPFCand; math::XYZVector PFJet_XYZVector=(*PFJetRef_).momentum(); - const std::vector theFilteredPFCandsInCone=PFGammaCandsInCone(PFJet_XYZVector,matchingcone_metric,matchingcone_size,minPt); + const std::vector theFilteredPFCandsInCone=PFGammaCandsInCone(PFJet_XYZVector,matchingcone_metric,matchingcone_size,minPt); double pt_cut=minPt; if (theFilteredPFCandsInCone.size()>0.){ - for(std::vector::const_iterator iPFCand =theFilteredPFCandsInCone.begin();iPFCand!=theFilteredPFCandsInCone.end();iPFCand++){ + for(std::vector::const_iterator iPFCand =theFilteredPFCandsInCone.begin();iPFCand!=theFilteredPFCandsInCone.end();iPFCand++){ if((*iPFCand)->pt()>pt_cut) { myleadPFCand=*iPFCand; pt_cut=(**iPFCand).pt(); @@ -265,12 +267,12 @@ PFCandidatePtr PFTauElementsOperators::leadPFGammaCand(const string matchingcone } return myleadPFCand; } -PFCandidatePtr PFTauElementsOperators::leadPFGammaCand(const math::XYZVector& myVector,const string matchingcone_metric,const double matchingcone_size,const double minPt)const{ - PFCandidatePtr myleadPFCand; - const std::vector theFilteredPFCandsInCone=PFGammaCandsInCone(myVector,matchingcone_metric,matchingcone_size,minPt); +CandidatePtr PFTauElementsOperators::leadGammaCand(const math::XYZVector& myVector,const string matchingcone_metric,const double matchingcone_size,const double minPt)const{ + CandidatePtr myleadPFCand; + const std::vector theFilteredPFCandsInCone=PFGammaCandsInCone(myVector,matchingcone_metric,matchingcone_size,minPt); double pt_cut=minPt; if (!theFilteredPFCandsInCone.empty()){ - for(std::vector::const_iterator iPFCand=theFilteredPFCandsInCone.begin();iPFCand!=theFilteredPFCandsInCone.end();iPFCand++){ + for(std::vector::const_iterator iPFCand=theFilteredPFCandsInCone.begin();iPFCand!=theFilteredPFCandsInCone.end();iPFCand++){ if((*iPFCand)->pt()>pt_cut) { myleadPFCand=*iPFCand; pt_cut=(**iPFCand).pt(); @@ -281,9 +283,9 @@ PFCandidatePtr PFTauElementsOperators::leadPFGammaCand(const math::XYZVector& my } void -PFTauElementsOperators::copyCandRefsFilteredByPt(const std::vector& theInputCands, std::vector& theOutputCands, const double minPt) +PFTauElementsOperators::copyCandRefsFilteredByPt(const std::vector& theInputCands, std::vector& theOutputCands, const double minPt) { - for(std::vector::const_iterator iPFCand = theInputCands.begin(); + for(std::vector::const_iterator iPFCand = theInputCands.begin(); iPFCand != theInputCands.end(); ++iPFCand) { @@ -295,18 +297,18 @@ PFTauElementsOperators::copyCandRefsFilteredByPt(const std::vector& theChargedCands, const std::vector& theGammaCands, +PFTauElementsOperators::computeInsideOutContents(const std::vector& theChargedCands, const std::vector& theGammaCands, const math::XYZVector& leadTrackVector, const TFormula& coneSizeFormula, double (*ptrToMetricFunction)(const math::XYZVector&, const math::XYZVector&), const double minChargedSize, const double maxChargedSize, const double minNeutralSize, const double maxNeutralSize, const double minChargedPt, const double minNeutralPt, const string& outlierCollectorConeMetric, const double outlierCollectionMaxSize, - std::vector& signalChargedObjects, std::vector& outlierChargedObjects, - std::vector& signalGammaObjects, std::vector& outlierGammaObjects, bool useScanningAxis) + std::vector& signalChargedObjects, std::vector& outlierChargedObjects, + std::vector& signalGammaObjects, std::vector& outlierGammaObjects, bool useScanningAxis) { if (theChargedCands.empty() && theGammaCands.empty()) return; //copy the vector of PFCands filtering by Pt - std::vector filteredCands; + std::vector filteredCands; filteredCands.reserve(theChargedCands.size() + theGammaCands.size()); copyCandRefsFilteredByPt(theChargedCands, filteredCands, minChargedPt); @@ -327,7 +329,7 @@ PFTauElementsOperators::computeInsideOutContents(const std::vector sortedCands; + std::vector sortedCands; for(std::vector::const_iterator theSortedIndex = filteredCandIndexes.begin(); theSortedIndex != filteredCandIndexes.end(); ++theSortedIndex) @@ -336,7 +338,7 @@ PFTauElementsOperators::computeInsideOutContents(const std::vector::const_iterator signalObjectCandidate = sortedCands.begin(); + std::vector::const_iterator signalObjectCandidate = sortedCands.begin(); double totalEnergySoFar = (**signalObjectCandidate).energy(); double totalEtSoFar = (**signalObjectCandidate).et(); math::XYZVector axisVectorSoFar = leadTrackVector; @@ -386,7 +388,7 @@ PFTauElementsOperators::computeInsideOutContents(const std::vector::const_iterator iterCand = sortedCands.begin(); + for (std::vector::const_iterator iterCand = sortedCands.begin(); iterCand != signalObjectCandidate; ++iterCand) { @@ -434,7 +436,7 @@ PFTauElementsOperators::computeInsideOutContents(const std::vector::const_iterator iterCand = signalObjectCandidate; + for (std::vector::const_iterator iterCand = signalObjectCandidate; iterCand != sortedCands.end(); ++iterCand) { @@ -459,25 +461,25 @@ double PFTauElementsOperators::discriminatorByIsolPFCandsN(int IsolPFCands_maxN) } double PFTauElementsOperators::discriminatorByIsolPFCandsN(string matchingcone_metric,double matchingcone_size,string signalcone_metric,double signalcone_size,string isolcone_metric,double isolcone_size,bool useOnlyChargedHadrforleadPFCand,double minPt_leadPFCand,double minPt_PFCand,int IsolPFCands_maxN){ double myDiscriminator=0.; - PFCandidatePtr myleadPFCand; - if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadPFChargedHadrCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); - else myleadPFCand=leadPFCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); + CandidatePtr myleadPFCand; + if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadChargedHadrCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); + else myleadPFCand=leadCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); if(!myleadPFCand)return myDiscriminator; //if(signalcone_size>=isolcone_size) return 1.; math::XYZVector leadPFCand_XYZVector=(*myleadPFCand).momentum() ; - const std::vector isolPFCands=PFCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); + const std::vector isolPFCands=PFCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); if ((int)isolPFCands.size()<=IsolPFCands_maxN) myDiscriminator=1; return myDiscriminator; } double PFTauElementsOperators::discriminatorByIsolPFCandsN(const math::XYZVector& myVector,string matchingcone_metric,double matchingcone_size,string signalcone_metric,double signalcone_size,string isolcone_metric,double isolcone_size,bool useOnlyChargedHadrforleadPFCand,double minPt_leadPFCand,double minPt_PFCand,int IsolPFCands_maxN){ double myDiscriminator=0; - PFCandidatePtr myleadPFCand; - if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadPFChargedHadrCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); - else myleadPFCand=leadPFCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); + CandidatePtr myleadPFCand; + if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadChargedHadrCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); + else myleadPFCand=leadCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); if(!myleadPFCand)return myDiscriminator; //if(signalcone_size>=isolcone_size) return 1.; math::XYZVector leadPFCand_XYZVector=(*myleadPFCand).momentum() ; - const std::vector isolPFCands=PFCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); + const std::vector isolPFCands=PFCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); if ((int)isolPFCands.size()<=IsolPFCands_maxN) myDiscriminator=1; return myDiscriminator; } @@ -488,25 +490,25 @@ double PFTauElementsOperators::discriminatorByIsolPFChargedHadrCandsN(int IsolPF } double PFTauElementsOperators::discriminatorByIsolPFChargedHadrCandsN(string matchingcone_metric,double matchingcone_size,string signalcone_metric,double signalcone_size,string isolcone_metric,double isolcone_size,bool useOnlyChargedHadrforleadPFCand,double minPt_leadPFCand,double minPt_PFCand,int IsolPFChargedHadrCands_maxN){ double myDiscriminator=0.; - PFCandidatePtr myleadPFCand; - if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadPFChargedHadrCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); - else myleadPFCand=leadPFCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); + CandidatePtr myleadPFCand; + if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadChargedHadrCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); + else myleadPFCand=leadCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); if(!myleadPFCand)return myDiscriminator; //if(signalcone_size>=isolcone_size) return 1.; math::XYZVector leadPFCand_XYZVector=(*myleadPFCand).momentum() ; - std::vector isolPFChargedHadrCands=PFChargedHadrCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); + std::vector isolPFChargedHadrCands=PFChargedHadrCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); if ((int)isolPFChargedHadrCands.size()<=IsolPFChargedHadrCands_maxN) myDiscriminator=1; return myDiscriminator; } double PFTauElementsOperators::discriminatorByIsolPFChargedHadrCandsN(const math::XYZVector& myVector,string matchingcone_metric,double matchingcone_size,string signalcone_metric,double signalcone_size,string isolcone_metric,double isolcone_size,bool useOnlyChargedHadrforleadPFCand,double minPt_leadPFCand,double minPt_PFCand,int IsolPFChargedHadrCands_maxN){ double myDiscriminator=0; - PFCandidatePtr myleadPFCand; - if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadPFChargedHadrCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); - else myleadPFCand=leadPFCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); + CandidatePtr myleadPFCand; + if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadChargedHadrCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); + else myleadPFCand=leadCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); if(!myleadPFCand)return myDiscriminator; //if(signalcone_size>=isolcone_size) return 1.; math::XYZVector leadPFCand_XYZVector=(*myleadPFCand).momentum() ; - std::vector isolPFChargedHadrCands=PFChargedHadrCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); + std::vector isolPFChargedHadrCands=PFChargedHadrCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); if ((int)isolPFChargedHadrCands.size()<=IsolPFChargedHadrCands_maxN) myDiscriminator=1; return myDiscriminator; } @@ -517,25 +519,25 @@ double PFTauElementsOperators::discriminatorByIsolPFNeutrHadrCandsN(int IsolPFNe } double PFTauElementsOperators::discriminatorByIsolPFNeutrHadrCandsN(string matchingcone_metric,double matchingcone_size,string signalcone_metric,double signalcone_size,string isolcone_metric,double isolcone_size,bool useOnlyChargedHadrforleadPFCand,double minPt_leadPFCand,double minPt_PFCand,int IsolPFNeutrHadrCands_maxN){ double myDiscriminator=0.; - PFCandidatePtr myleadPFCand; - if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadPFChargedHadrCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); - else myleadPFCand=leadPFCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); + CandidatePtr myleadPFCand; + if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadChargedHadrCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); + else myleadPFCand=leadCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); if(!myleadPFCand)return myDiscriminator; //if(signalcone_size>=isolcone_size) return 1.; math::XYZVector leadPFCand_XYZVector=(*myleadPFCand).momentum() ; - std::vector isolPFNeutrHadrCands=PFNeutrHadrCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); + std::vector isolPFNeutrHadrCands=PFNeutrHadrCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); if ((int)isolPFNeutrHadrCands.size()<=IsolPFNeutrHadrCands_maxN) myDiscriminator=1; return myDiscriminator; } double PFTauElementsOperators::discriminatorByIsolPFNeutrHadrCandsN(const math::XYZVector& myVector,string matchingcone_metric,double matchingcone_size,string signalcone_metric,double signalcone_size,string isolcone_metric,double isolcone_size,bool useOnlyChargedHadrforleadPFCand,double minPt_leadPFCand,double minPt_PFCand,int IsolPFNeutrHadrCands_maxN){ double myDiscriminator=0; - PFCandidatePtr myleadPFCand; - if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadPFChargedHadrCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); - else myleadPFCand=leadPFCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); + CandidatePtr myleadPFCand; + if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadChargedHadrCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); + else myleadPFCand=leadCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); if(!myleadPFCand)return myDiscriminator; //if(signalcone_size>=isolcone_size) return 1.; math::XYZVector leadPFCand_XYZVector=(*myleadPFCand).momentum() ; - std::vector isolPFNeutrHadrCands=PFNeutrHadrCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); + std::vector isolPFNeutrHadrCands=PFNeutrHadrCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); if ((int)isolPFNeutrHadrCands.size()<=IsolPFNeutrHadrCands_maxN) myDiscriminator=1; return myDiscriminator; } @@ -546,165 +548,165 @@ double PFTauElementsOperators::discriminatorByIsolPFGammaCandsN(int IsolPFGammaC } double PFTauElementsOperators::discriminatorByIsolPFGammaCandsN(string matchingcone_metric,double matchingcone_size,string signalcone_metric,double signalcone_size,string isolcone_metric,double isolcone_size,bool useOnlyChargedHadrforleadPFCand,double minPt_leadPFCand,double minPt_PFCand,int IsolPFGammaCands_maxN){ double myDiscriminator=0.; - PFCandidatePtr myleadPFCand; - if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadPFChargedHadrCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); - else myleadPFCand=leadPFCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); + CandidatePtr myleadPFCand; + if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadChargedHadrCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); + else myleadPFCand=leadCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); if(!myleadPFCand)return myDiscriminator; //if(signalcone_size>=isolcone_size) return 1.; math::XYZVector leadPFCand_XYZVector=(*myleadPFCand).momentum() ; - std::vector isolPFGammaCands=PFGammaCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); + std::vector isolPFGammaCands=PFGammaCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); if ((int)isolPFGammaCands.size()<=IsolPFGammaCands_maxN) myDiscriminator=1; return myDiscriminator; } double PFTauElementsOperators::discriminatorByIsolPFGammaCandsN(const math::XYZVector& myVector,string matchingcone_metric,double matchingcone_size,string signalcone_metric,double signalcone_size,string isolcone_metric,double isolcone_size,bool useOnlyChargedHadrforleadPFCand,double minPt_leadPFCand,double minPt_PFCand,int IsolPFGammaCands_maxN){ double myDiscriminator=0; - PFCandidatePtr myleadPFCand; - if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadPFChargedHadrCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); - else myleadPFCand=leadPFCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); + CandidatePtr myleadPFCand; + if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadChargedHadrCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); + else myleadPFCand=leadCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); if(!myleadPFCand)return myDiscriminator; //if(signalcone_size>=isolcone_size) return 1.; math::XYZVector leadPFCand_XYZVector=(*myleadPFCand).momentum() ; - std::vector isolPFGammaCands=PFGammaCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); + std::vector isolPFGammaCands=PFGammaCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); if ((int)isolPFGammaCands.size()<=IsolPFGammaCands_maxN) myDiscriminator=1; return myDiscriminator; } double PFTauElementsOperators::discriminatorByIsolPFCandsEtSum(double IsolPFCands_maxEtSum){ double myIsolPFCandsEtSum=0.; double myDiscriminator=0.; - for(std::vector::const_iterator iPFCand=IsolPFCands_.begin();iPFCand!=IsolPFCands_.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); + for(std::vector::const_iterator iPFCand=IsolPFCands_.begin();iPFCand!=IsolPFCands_.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); if (myIsolPFCandsEtSum<=IsolPFCands_maxEtSum) myDiscriminator=1; return myDiscriminator; } double PFTauElementsOperators::discriminatorByIsolPFCandsEtSum(string matchingcone_metric,double matchingcone_size,string signalcone_metric,double signalcone_size,string isolcone_metric,double isolcone_size,bool useOnlyChargedHadrforleadPFCand,double minPt_leadPFCand,double minPt_PFCand,double IsolPFCands_maxEtSum){ double myIsolPFCandsEtSum=0.; double myDiscriminator=0.; - PFCandidatePtr myleadPFCand; - if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadPFChargedHadrCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); - else myleadPFCand=leadPFCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); + CandidatePtr myleadPFCand; + if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadChargedHadrCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); + else myleadPFCand=leadCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); if(!myleadPFCand)return myDiscriminator; //if(signalcone_size>=isolcone_size) return 1.; math::XYZVector leadPFCand_XYZVector=(*myleadPFCand).momentum() ; - std::vector isolPFCands=PFCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); - for(std::vector::const_iterator iPFCand=isolPFCands.begin();iPFCand!=isolPFCands.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); + std::vector isolPFCands=PFCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); + for(std::vector::const_iterator iPFCand=isolPFCands.begin();iPFCand!=isolPFCands.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); if (myIsolPFCandsEtSum<=IsolPFCands_maxEtSum) myDiscriminator=1; return myDiscriminator; } double PFTauElementsOperators::discriminatorByIsolPFCandsEtSum(const math::XYZVector& myVector,string matchingcone_metric,double matchingcone_size,string signalcone_metric,double signalcone_size,string isolcone_metric,double isolcone_size,bool useOnlyChargedHadrforleadPFCand,double minPt_leadPFCand,double minPt_PFCand,double IsolPFCands_maxEtSum){ double myIsolPFCandsEtSum=0.; double myDiscriminator=0; - PFCandidatePtr myleadPFCand; - if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadPFChargedHadrCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); - else myleadPFCand=leadPFCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); + CandidatePtr myleadPFCand; + if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadChargedHadrCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); + else myleadPFCand=leadCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); if(!myleadPFCand)return myDiscriminator; //if(signalcone_size>=isolcone_size) return 1.; math::XYZVector leadPFCand_XYZVector=(*myleadPFCand).momentum() ; - std::vector isolPFCands=PFCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); - for(std::vector::const_iterator iPFCand=isolPFCands.begin();iPFCand!=isolPFCands.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); + std::vector isolPFCands=PFCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); + for(std::vector::const_iterator iPFCand=isolPFCands.begin();iPFCand!=isolPFCands.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); if (myIsolPFCandsEtSum<=IsolPFCands_maxEtSum) myDiscriminator=1; return myDiscriminator; } double PFTauElementsOperators::discriminatorByIsolPFChargedHadrCandsEtSum(double IsolPFChargedHadrCands_maxEtSum){ double myIsolPFCandsEtSum=0.; double myDiscriminator=0.; - for(std::vector::const_iterator iPFCand=IsolPFChargedHadrCands_.begin();iPFCand!=IsolPFChargedHadrCands_.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); + for(std::vector::const_iterator iPFCand=IsolPFChargedHadrCands_.begin();iPFCand!=IsolPFChargedHadrCands_.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); if (myIsolPFCandsEtSum<=IsolPFChargedHadrCands_maxEtSum) myDiscriminator=1; return myDiscriminator; } double PFTauElementsOperators::discriminatorByIsolPFChargedHadrCandsEtSum(string matchingcone_metric,double matchingcone_size,string signalcone_metric,double signalcone_size,string isolcone_metric,double isolcone_size,bool useOnlyChargedHadrforleadPFCand,double minPt_leadPFCand,double minPt_PFCand,double IsolPFChargedHadrCands_maxEtSum){ double myIsolPFCandsEtSum=0.; double myDiscriminator=0.; - PFCandidatePtr myleadPFCand; - if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadPFChargedHadrCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); - else myleadPFCand=leadPFCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); + CandidatePtr myleadPFCand; + if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadChargedHadrCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); + else myleadPFCand=leadCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); if(!myleadPFCand)return myDiscriminator; //if(signalcone_size>=isolcone_size) return 1.; math::XYZVector leadPFCand_XYZVector=(*myleadPFCand).momentum() ; - std::vector isolPFChargedHadrCands=PFChargedHadrCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); - for(std::vector::const_iterator iPFCand=isolPFChargedHadrCands.begin();iPFCand!=isolPFChargedHadrCands.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); + std::vector isolPFChargedHadrCands=PFChargedHadrCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); + for(std::vector::const_iterator iPFCand=isolPFChargedHadrCands.begin();iPFCand!=isolPFChargedHadrCands.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); if (myIsolPFCandsEtSum<=IsolPFChargedHadrCands_maxEtSum) myDiscriminator=1; return myDiscriminator; } double PFTauElementsOperators::discriminatorByIsolPFChargedHadrCandsEtSum(const math::XYZVector& myVector,string matchingcone_metric,double matchingcone_size,string signalcone_metric,double signalcone_size,string isolcone_metric,double isolcone_size,bool useOnlyChargedHadrforleadPFCand,double minPt_leadPFCand,double minPt_PFCand,double IsolPFChargedHadrCands_maxEtSum){ double myIsolPFCandsEtSum=0.; double myDiscriminator=0; - PFCandidatePtr myleadPFCand; - if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadPFChargedHadrCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); - else myleadPFCand=leadPFCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); + CandidatePtr myleadPFCand; + if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadChargedHadrCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); + else myleadPFCand=leadCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); if(!myleadPFCand)return myDiscriminator; //if(signalcone_size>=isolcone_size) return 1.; math::XYZVector leadPFCand_XYZVector=(*myleadPFCand).momentum() ; - std::vector isolPFChargedHadrCands=PFChargedHadrCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); - for(std::vector::const_iterator iPFCand=isolPFChargedHadrCands.begin();iPFCand!=isolPFChargedHadrCands.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); + std::vector isolPFChargedHadrCands=PFChargedHadrCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); + for(std::vector::const_iterator iPFCand=isolPFChargedHadrCands.begin();iPFCand!=isolPFChargedHadrCands.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); if (myIsolPFCandsEtSum<=IsolPFChargedHadrCands_maxEtSum) myDiscriminator=1; return myDiscriminator; } double PFTauElementsOperators::discriminatorByIsolPFNeutrHadrCandsEtSum(double IsolPFNeutrHadrCands_maxEtSum){ double myIsolPFCandsEtSum=0.; double myDiscriminator=0.; - for(std::vector::const_iterator iPFCand=IsolPFNeutrHadrCands_.begin();iPFCand!=IsolPFNeutrHadrCands_.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); + for(std::vector::const_iterator iPFCand=IsolPFNeutrHadrCands_.begin();iPFCand!=IsolPFNeutrHadrCands_.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); if (myIsolPFCandsEtSum<=IsolPFNeutrHadrCands_maxEtSum) myDiscriminator=1; return myDiscriminator; } double PFTauElementsOperators::discriminatorByIsolPFNeutrHadrCandsEtSum(string matchingcone_metric,double matchingcone_size,string signalcone_metric,double signalcone_size,string isolcone_metric,double isolcone_size,bool useOnlyChargedHadrforleadPFCand,double minPt_leadPFCand,double minPt_PFCand,double IsolPFNeutrHadrCands_maxEtSum){ double myIsolPFCandsEtSum=0.; double myDiscriminator=0.; - PFCandidatePtr myleadPFCand; - if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadPFChargedHadrCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); - else myleadPFCand=leadPFCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); + CandidatePtr myleadPFCand; + if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadChargedHadrCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); + else myleadPFCand=leadCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); if(!myleadPFCand)return myDiscriminator; //if(signalcone_size>=isolcone_size) return 1.; math::XYZVector leadPFCand_XYZVector=(*myleadPFCand).momentum() ; - std::vector isolPFNeutrHadrCands=PFNeutrHadrCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); - for(std::vector::const_iterator iPFCand=isolPFNeutrHadrCands.begin();iPFCand!=isolPFNeutrHadrCands.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); + std::vector isolPFNeutrHadrCands=PFNeutrHadrCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); + for(std::vector::const_iterator iPFCand=isolPFNeutrHadrCands.begin();iPFCand!=isolPFNeutrHadrCands.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); if (myIsolPFCandsEtSum<=IsolPFNeutrHadrCands_maxEtSum) myDiscriminator=1; return myDiscriminator; } double PFTauElementsOperators::discriminatorByIsolPFNeutrHadrCandsEtSum(const math::XYZVector& myVector,string matchingcone_metric,double matchingcone_size,string signalcone_metric,double signalcone_size,string isolcone_metric,double isolcone_size,bool useOnlyChargedHadrforleadPFCand,double minPt_leadPFCand,double minPt_PFCand,double IsolPFNeutrHadrCands_maxEtSum){ double myIsolPFCandsEtSum=0.; double myDiscriminator=0; - PFCandidatePtr myleadPFCand; - if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadPFChargedHadrCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); - else myleadPFCand=leadPFCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); + CandidatePtr myleadPFCand; + if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadChargedHadrCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); + else myleadPFCand=leadCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); if(!myleadPFCand)return myDiscriminator; //if(signalcone_size>=isolcone_size) return 1.; math::XYZVector leadPFCand_XYZVector=(*myleadPFCand).momentum() ; - std::vector isolPFNeutrHadrCands=PFNeutrHadrCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); - for(std::vector::const_iterator iPFCand=isolPFNeutrHadrCands.begin();iPFCand!=isolPFNeutrHadrCands.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); + std::vector isolPFNeutrHadrCands=PFNeutrHadrCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); + for(std::vector::const_iterator iPFCand=isolPFNeutrHadrCands.begin();iPFCand!=isolPFNeutrHadrCands.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); if (myIsolPFCandsEtSum<=IsolPFNeutrHadrCands_maxEtSum) myDiscriminator=1; return myDiscriminator; } double PFTauElementsOperators::discriminatorByIsolPFGammaCandsEtSum(double IsolPFGammaCands_maxEtSum){ double myIsolPFCandsEtSum=0.; double myDiscriminator=0.; - for(std::vector::const_iterator iPFCand=IsolPFGammaCands_.begin();iPFCand!=IsolPFGammaCands_.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); + for(std::vector::const_iterator iPFCand=IsolPFGammaCands_.begin();iPFCand!=IsolPFGammaCands_.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); if (myIsolPFCandsEtSum<=IsolPFGammaCands_maxEtSum) myDiscriminator=1; return myDiscriminator; } double PFTauElementsOperators::discriminatorByIsolPFGammaCandsEtSum(string matchingcone_metric,double matchingcone_size,string signalcone_metric,double signalcone_size,string isolcone_metric,double isolcone_size,bool useOnlyChargedHadrforleadPFCand,double minPt_leadPFCand,double minPt_PFCand,double IsolPFGammaCands_maxEtSum){ double myIsolPFCandsEtSum=0.; double myDiscriminator=0.; - PFCandidatePtr myleadPFCand; - if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadPFChargedHadrCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); - else myleadPFCand=leadPFCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); + CandidatePtr myleadPFCand; + if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadChargedHadrCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); + else myleadPFCand=leadCand(matchingcone_metric,matchingcone_size,minPt_leadPFCand); if(!myleadPFCand)return myDiscriminator; if(signalcone_size>=isolcone_size) return 1.; math::XYZVector leadPFCand_XYZVector=(*myleadPFCand).momentum() ; - std::vector isolPFGammaCands=PFGammaCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); - for(std::vector::const_iterator iPFCand=isolPFGammaCands.begin();iPFCand!=isolPFGammaCands.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); + std::vector isolPFGammaCands=PFGammaCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); + for(std::vector::const_iterator iPFCand=isolPFGammaCands.begin();iPFCand!=isolPFGammaCands.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); if (myIsolPFCandsEtSum<=IsolPFGammaCands_maxEtSum) myDiscriminator=1; return myDiscriminator; } double PFTauElementsOperators::discriminatorByIsolPFGammaCandsEtSum(const math::XYZVector& myVector,string matchingcone_metric,double matchingcone_size,string signalcone_metric,double signalcone_size,string isolcone_metric,double isolcone_size,bool useOnlyChargedHadrforleadPFCand,double minPt_leadPFCand,double minPt_PFCand,double IsolPFGammaCands_maxEtSum){ double myIsolPFCandsEtSum=0.; double myDiscriminator=0; - PFCandidatePtr myleadPFCand; - if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadPFChargedHadrCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); - else myleadPFCand=leadPFCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); + CandidatePtr myleadPFCand; + if (useOnlyChargedHadrforleadPFCand) myleadPFCand=leadChargedHadrCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); + else myleadPFCand=leadCand(myVector,matchingcone_metric,matchingcone_size,minPt_leadPFCand); if(!myleadPFCand)return myDiscriminator; //if(signalcone_size>=isolcone_size) return 1.; math::XYZVector leadPFCand_XYZVector=(*myleadPFCand).momentum() ; - std::vector isolPFGammaCands=PFGammaCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); - for(std::vector::const_iterator iPFCand=isolPFGammaCands.begin();iPFCand!=isolPFGammaCands.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); + std::vector isolPFGammaCands=PFGammaCandsInAnnulus(leadPFCand_XYZVector,signalcone_metric,signalcone_size,isolcone_metric,isolcone_size,minPt_PFCand); + for(std::vector::const_iterator iPFCand=isolPFGammaCands.begin();iPFCand!=isolPFGammaCands.end();iPFCand++) myIsolPFCandsEtSum+=(**iPFCand).et(); if (myIsolPFCandsEtSum<=IsolPFGammaCands_maxEtSum) myDiscriminator=1; return myDiscriminator; } diff --git a/RecoTauTag/TauTagTools/src/TauTagTools.cc b/RecoTauTag/TauTagTools/src/TauTagTools.cc index 2ceed32cb1dbf..061902db99227 100644 --- a/RecoTauTag/TauTagTools/src/TauTagTools.cc +++ b/RecoTauTag/TauTagTools/src/TauTagTools.cc @@ -101,64 +101,64 @@ void replaceSubStr(string& s,const string& oldSubStr,const string& newSubStr){ return filteredTracks; } - std::vector filteredPFChargedHadrCandsByNumTrkHits(const std::vector& theInitialPFCands, int ChargedHadrCand_tkminTrackerHitsn){ - std::vector filteredPFChargedHadrCands; - for(std::vector::const_iterator iPFCand=theInitialPFCands.begin();iPFCand!=theInitialPFCands.end();iPFCand++){ - if (PFCandidate::ParticleType((**iPFCand).particleId())==PFCandidate::h || PFCandidate::ParticleType((**iPFCand).particleId())==PFCandidate::mu || PFCandidate::ParticleType((**iPFCand).particleId())==PFCandidate::e){ + std::vector filteredPFChargedHadrCandsByNumTrkHits(const std::vector& theInitialPFCands, int ChargedHadrCand_tkminTrackerHitsn){ + std::vector filteredPFChargedHadrCands; + 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. - TrackRef PFChargedHadrCand_rectk = (**iPFCand).trackRef(); - - if (!PFChargedHadrCand_rectk)continue; - if ( (*PFChargedHadrCand_rectk).numberOfValidHits()>=ChargedHadrCand_tkminTrackerHitsn ) - filteredPFChargedHadrCands.push_back(*iPFCand); + const reco::Track* PFChargedHadrCand_rectk = (*iPFCand)->bestTrack(); + if (PFChargedHadrCand_rectk != nullptr) { + if ( (*PFChargedHadrCand_rectk).numberOfValidHits()>=ChargedHadrCand_tkminTrackerHitsn ) + filteredPFChargedHadrCands.push_back(*iPFCand); + } } } return filteredPFChargedHadrCands; } - std::vector filteredPFChargedHadrCands(const std::vector& theInitialPFCands,double ChargedHadrCand_tkminPt,int ChargedHadrCand_tkminPixelHitsn,int ChargedHadrCand_tkminTrackerHitsn,double ChargedHadrCand_tkmaxipt,double ChargedHadrCand_tkmaxChi2, Vertex pv){ - std::vector filteredPFChargedHadrCands; - for(std::vector::const_iterator iPFCand=theInitialPFCands.begin();iPFCand!=theInitialPFCands.end();iPFCand++){ - if (PFCandidate::ParticleType((**iPFCand).particleId())==PFCandidate::h || PFCandidate::ParticleType((**iPFCand).particleId())==PFCandidate::mu || PFCandidate::ParticleType((**iPFCand).particleId())==PFCandidate::e){ + std::vector filteredPFChargedHadrCands(const std::vector& theInitialPFCands,double ChargedHadrCand_tkminPt,int ChargedHadrCand_tkminPixelHitsn,int ChargedHadrCand_tkminTrackerHitsn,double ChargedHadrCand_tkmaxipt,double ChargedHadrCand_tkmaxChi2, Vertex pv){ + std::vector filteredPFChargedHadrCands; + 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. - TrackRef PFChargedHadrCand_rectk = (**iPFCand).trackRef(); - - - if (!PFChargedHadrCand_rectk)continue; - if ((*PFChargedHadrCand_rectk).pt()>=ChargedHadrCand_tkminPt && - (*PFChargedHadrCand_rectk).normalizedChi2()<=ChargedHadrCand_tkmaxChi2 && - fabs((*PFChargedHadrCand_rectk).dxy(pv.position()))<=ChargedHadrCand_tkmaxipt && - (*PFChargedHadrCand_rectk).numberOfValidHits()>=ChargedHadrCand_tkminTrackerHitsn && - (*PFChargedHadrCand_rectk).hitPattern().numberOfValidPixelHits()>=ChargedHadrCand_tkminPixelHitsn) - filteredPFChargedHadrCands.push_back(*iPFCand); + const reco::Track* PFChargedHadrCand_rectk = (*iPFCand)->bestTrack(); + if (PFChargedHadrCand_rectk != nullptr) { + if ((*PFChargedHadrCand_rectk).pt()>=ChargedHadrCand_tkminPt && + (*PFChargedHadrCand_rectk).normalizedChi2()<=ChargedHadrCand_tkmaxChi2 && + fabs((*PFChargedHadrCand_rectk).dxy(pv.position()))<=ChargedHadrCand_tkmaxipt && + (*PFChargedHadrCand_rectk).numberOfValidHits()>=ChargedHadrCand_tkminTrackerHitsn && + (*PFChargedHadrCand_rectk).hitPattern().numberOfValidPixelHits()>=ChargedHadrCand_tkminPixelHitsn) + filteredPFChargedHadrCands.push_back(*iPFCand); + } } } return filteredPFChargedHadrCands; } - std::vector filteredPFChargedHadrCands(const std::vector& theInitialPFCands,double ChargedHadrCand_tkminPt,int ChargedHadrCand_tkminPixelHitsn,int ChargedHadrCand_tkminTrackerHitsn,double ChargedHadrCand_tkmaxipt,double ChargedHadrCand_tkmaxChi2,double ChargedHadrCand_tktorefpointmaxDZ,Vertex pv, double refpoint_Z){ + std::vector filteredPFChargedHadrCands(const std::vector& theInitialPFCands,double ChargedHadrCand_tkminPt,int ChargedHadrCand_tkminPixelHitsn,int ChargedHadrCand_tkminTrackerHitsn,double ChargedHadrCand_tkmaxipt,double ChargedHadrCand_tkmaxChi2,double ChargedHadrCand_tktorefpointmaxDZ,Vertex pv, double refpoint_Z){ if(pv.isFake()) ChargedHadrCand_tktorefpointmaxDZ = 30.; - std::vector filteredPFChargedHadrCands; - for(std::vector::const_iterator iPFCand=theInitialPFCands.begin();iPFCand!=theInitialPFCands.end();iPFCand++){ - if (PFCandidate::ParticleType((**iPFCand).particleId())==PFCandidate::h || PFCandidate::ParticleType((**iPFCand).particleId())==PFCandidate::mu || PFCandidate::ParticleType((**iPFCand).particleId())==PFCandidate::e){ + std::vector filteredPFChargedHadrCands; + 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. - TrackRef PFChargedHadrCand_rectk = (**iPFCand).trackRef(); - if (!PFChargedHadrCand_rectk)continue; - if ((*PFChargedHadrCand_rectk).pt()>=ChargedHadrCand_tkminPt && - (*PFChargedHadrCand_rectk).normalizedChi2()<=ChargedHadrCand_tkmaxChi2 && - fabs((*PFChargedHadrCand_rectk).dxy(pv.position()))<=ChargedHadrCand_tkmaxipt && - (*PFChargedHadrCand_rectk).numberOfValidHits()>=ChargedHadrCand_tkminTrackerHitsn && - (*PFChargedHadrCand_rectk).hitPattern().numberOfValidPixelHits()>=ChargedHadrCand_tkminPixelHitsn && - fabs((*PFChargedHadrCand_rectk).dz(pv.position()))<=ChargedHadrCand_tktorefpointmaxDZ) - filteredPFChargedHadrCands.push_back(*iPFCand); + const reco::Track* PFChargedHadrCand_rectk = (*iPFCand)->bestTrack(); + if (PFChargedHadrCand_rectk != nullptr) { + if ((*PFChargedHadrCand_rectk).pt()>=ChargedHadrCand_tkminPt && + (*PFChargedHadrCand_rectk).normalizedChi2()<=ChargedHadrCand_tkmaxChi2 && + fabs((*PFChargedHadrCand_rectk).dxy(pv.position()))<=ChargedHadrCand_tkmaxipt && + (*PFChargedHadrCand_rectk).numberOfValidHits()>=ChargedHadrCand_tkminTrackerHitsn && + (*PFChargedHadrCand_rectk).hitPattern().numberOfValidPixelHits()>=ChargedHadrCand_tkminPixelHitsn && + fabs((*PFChargedHadrCand_rectk).dz(pv.position()))<=ChargedHadrCand_tktorefpointmaxDZ) + filteredPFChargedHadrCands.push_back(*iPFCand); + } } } return filteredPFChargedHadrCands; } - std::vector filteredPFNeutrHadrCands(const std::vector& theInitialPFCands,double NeutrHadrCand_HcalclusMinEt){ - std::vector filteredPFNeutrHadrCands; - for(std::vector::const_iterator iPFCand=theInitialPFCands.begin();iPFCand!=theInitialPFCands.end();iPFCand++){ - if (PFCandidate::ParticleType((**iPFCand).particleId())==PFCandidate::h0){ + std::vector filteredPFNeutrHadrCands(const std::vector& theInitialPFCands,double NeutrHadrCand_HcalclusMinEt){ + std::vector filteredPFNeutrHadrCands; + for(std::vector::const_iterator iPFCand=theInitialPFCands.begin();iPFCand!=theInitialPFCands.end();iPFCand++){ + if (std::abs((*iPFCand)->pdgId()) == 130){ // *** Whether the neutral hadron candidate will be selected or not depends on its rec. HCAL cluster properties. if ((**iPFCand).et()>=NeutrHadrCand_HcalclusMinEt){ filteredPFNeutrHadrCands.push_back(*iPFCand); @@ -168,10 +168,10 @@ void replaceSubStr(string& s,const string& oldSubStr,const string& newSubStr){ return filteredPFNeutrHadrCands; } - std::vector filteredPFGammaCands(const std::vector& theInitialPFCands,double GammaCand_EcalclusMinEt){ - std::vector filteredPFGammaCands; - for(std::vector::const_iterator iPFCand=theInitialPFCands.begin();iPFCand!=theInitialPFCands.end();iPFCand++){ - if (PFCandidate::ParticleType((**iPFCand).particleId())==PFCandidate::gamma){ + std::vector filteredPFGammaCands(const std::vector& theInitialPFCands,double GammaCand_EcalclusMinEt){ + std::vector filteredPFGammaCands; + for(std::vector::const_iterator iPFCand=theInitialPFCands.begin();iPFCand!=theInitialPFCands.end();iPFCand++){ + if (std::abs((*iPFCand)->pdgId()) == 22){ // *** Whether the gamma candidate will be selected or not depends on its rec. ECAL cluster properties. if ((**iPFCand).et()>=GammaCand_EcalclusMinEt){ filteredPFGammaCands.push_back(*iPFCand); @@ -239,7 +239,7 @@ void replaceSubStr(string& s,const string& oldSubStr,const string& newSubStr){ void - sortRefVectorByPt(std::vector& vec) + sortRefVectorByPt(std::vector& vec) { std::vector indices; @@ -251,7 +251,7 @@ void replaceSubStr(string& s,const string& oldSubStr,const string& newSubStr){ std::sort(indices.begin(),indices.end(),sorter); - std::vector sorted; + std::vector sorted; sorted.reserve(vec.size()); for(unsigned int i=0;i 5.0'), + 'leadPFChargedHadrCand().muonRef().isNull() &leadCand().pt() > 5.0'), # We can skip events where no taus pass this requirement filter = cms.bool(True), ) diff --git a/Validation/RecoTau/Tools/makeLayoutFileForGui.py b/Validation/RecoTau/Tools/makeLayoutFileForGui.py index 5b1c719609c4c..bcf03b875526c 100644 --- a/Validation/RecoTau/Tools/makeLayoutFileForGui.py +++ b/Validation/RecoTau/Tools/makeLayoutFileForGui.py @@ -127,7 +127,7 @@ def sizeSumpt(locpath,dataType,var): return stdFill.substitute(locpath=locpath,rows=strow) variables = {'a%s':'pt','b%s':'pileup','c%s':'eta','d%s':'phi'} -sumVar = dict( list(zip(string.letters,[elem for elem in ['signalPFCands','isolationPFChargedHadrCands','isolationPFGammaCands','isolationPFNeutrHadrCands'] ])) ) +sumVar = dict( list(zip(string.letters,[elem for elem in ['signalCands','isolationChargedHadrCands','isolationGammaCands','isolationNeutrHadrCands'] ])) ) # diff --git a/Validation/RecoTau/interface/TauTagValidation.h b/Validation/RecoTau/interface/TauTagValidation.h index 223d9c2be838f..432349b04d96c 100644 --- a/Validation/RecoTau/interface/TauTagValidation.h +++ b/Validation/RecoTau/interface/TauTagValidation.h @@ -83,7 +83,7 @@ class TauTagValidation : public DQMEDAnalyzer{ /// label of the current module std::string moduleLabel_; ///sum the transversal momentum of all candidates - double getSumPt(const std::vector > & candidates); + double getSumPt(const std::vector > & candidates); ///get rid of redundant parts to shorten the label bool stripDiscriminatorLabel(const std::string& discriminatorLabel, std::string & newLabel); diff --git a/Validation/RecoTau/src/TauTagValidation.cc b/Validation/RecoTau/src/TauTagValidation.cc index c3f2a29123129..395f896ef8ad5 100644 --- a/Validation/RecoTau/src/TauTagValidation.cc +++ b/Validation/RecoTau/src/TauTagValidation.cc @@ -266,27 +266,27 @@ void TauTagValidation::bookHistograms(DQMStore::IBooker & ibooker, edm::Run cons xaxisLabel = ";size"; yaxislabel = ";Frequency"; bins = 20; - plotName = plotType + "signalPFCands"; + plotName = plotType + "signalCands"; tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins-0.5); plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) ); - plotName = plotType + "signalPFChargedHadrCands"; + plotName = plotType + "signalChargedHadrCands"; tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins-0.5); plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) ); - plotName = plotType + "signalPFNeutrHadrCands"; + plotName = plotType + "signalNeutrHadrCands"; tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins-0.5); plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) ); - plotName = plotType + "isolationPFCands"; + plotName = plotType + "isolationCands"; tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins-0.5); plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) ); - plotName = plotType + "isolationPFChargedHadrCands"; + plotName = plotType + "isolationChargedHadrCands"; bins = 10; tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins-0.5); plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) ); - plotName = plotType + "isolationPFNeutrHadrCands"; + plotName = plotType + "isolationNeutrHadrCands"; tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins-0.5); plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) ); - plotName = plotType + "isolationPFGammaCands"; + plotName = plotType + "isolationGammaCands"; tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins-0.5); plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) ); @@ -294,25 +294,25 @@ void TauTagValidation::bookHistograms(DQMStore::IBooker & ibooker, edm::Run cons xaxisLabel = ";p_{T}^{sum}/ GeV"; yaxislabel = ";Frequency"; bins = 20; - plotName = plotType + "signalPFCands"; + plotName = plotType + "signalCands"; tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.); plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) ); - plotName = plotType + "signalPFChargedHadrCands"; + plotName = plotType + "signalChargedHadrCands"; tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.); plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) ); - plotName = plotType + "signalPFNeutrHadrCands"; + plotName = plotType + "signalNeutrHadrCands"; tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.); plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) ); - plotName = plotType + "isolationPFCands"; + plotName = plotType + "isolationCands"; tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.); plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) ); - plotName = plotType + "isolationPFChargedHadrCands"; + plotName = plotType + "isolationChargedHadrCands"; tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 10.); plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) ); - plotName = plotType + "isolationPFNeutrHadrCands"; + plotName = plotType + "isolationNeutrHadrCands"; tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 30.); plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) ); - plotName = plotType + "isolationPFGammaCands"; + plotName = plotType + "isolationGammaCands"; tmpME = ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 20.); plotMap_.insert( std::make_pair( DiscriminatorLabel + plotName, tmpME ) ); @@ -542,53 +542,53 @@ void TauTagValidation::analyze(const edm::Event& iEvent, const edm::EventSetup& } //fill: size and sumPt within tau isolation std::string plotType = "_Size_"; - element = plotMap_.find( currentDiscriminatorLabel + plotType + "signalPFCands" ); - if( element != plotMap_.end() ) element->second->Fill( thePFTau->signalPFCands().size() ); - element = plotMap_.find( currentDiscriminatorLabel + plotType + "signalPFChargedHadrCands" ); - if( element != plotMap_.end() ) element->second->Fill( thePFTau->signalPFChargedHadrCands().size() ); - element = plotMap_.find( currentDiscriminatorLabel + plotType + "signalPFNeutrHadrCands" ); - if( element != plotMap_.end() ) element->second->Fill( thePFTau->signalPFNeutrHadrCands().size() ); - element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationPFCands" ); - if( element != plotMap_.end() ) element->second->Fill( thePFTau->isolationPFCands().size() ); - element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationPFChargedHadrCands" ); - if( element != plotMap_.end() ) element->second->Fill( thePFTau->isolationPFChargedHadrCands().size() ); - element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationPFNeutrHadrCands" ); - if( element != plotMap_.end() ) element->second->Fill( thePFTau->isolationPFNeutrHadrCands().size() ); - element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationPFGammaCands" ); - if( element != plotMap_.end() ) element->second->Fill( thePFTau->isolationPFGammaCands().size() ); + element = plotMap_.find( currentDiscriminatorLabel + plotType + "signalCands" ); + if( element != plotMap_.end() ) element->second->Fill( thePFTau->signalCands().size() ); + element = plotMap_.find( currentDiscriminatorLabel + plotType + "signalChargedHadrCands" ); + if( element != plotMap_.end() ) element->second->Fill( thePFTau->signalChargedHadrCands().size() ); + element = plotMap_.find( currentDiscriminatorLabel + plotType + "signalNeutrHadrCands" ); + if( element != plotMap_.end() ) element->second->Fill( thePFTau->signalNeutrHadrCands().size() ); + element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationCands" ); + if( element != plotMap_.end() ) element->second->Fill( thePFTau->isolationCands().size() ); + element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationChargedHadrCands" ); + if( element != plotMap_.end() ) element->second->Fill( thePFTau->isolationChargedHadrCands().size() ); + element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationNeutrHadrCands" ); + if( element != plotMap_.end() ) element->second->Fill( thePFTau->isolationNeutrHadrCands().size() ); + element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationGammaCands" ); + if( element != plotMap_.end() ) element->second->Fill( thePFTau->isolationGammaCands().size() ); plotType = "_SumPt_"; - element = plotMap_.find( currentDiscriminatorLabel + plotType + "signalPFCands" ); - if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->signalPFCands() ) ); - element = plotMap_.find( currentDiscriminatorLabel + plotType + "signalPFChargedHadrCands" ); - if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->signalPFChargedHadrCands() ) ); - element = plotMap_.find( currentDiscriminatorLabel + plotType + "signalPFNeutrHadrCands" ); - if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->signalPFNeutrHadrCands() ) ); - element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationPFCands" ); - if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->isolationPFCands() ) ); - element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationPFChargedHadrCands" ); - if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->isolationPFChargedHadrCands() ) ); - element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationPFNeutrHadrCands" ); - if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->isolationPFNeutrHadrCands() ) ); - element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationPFGammaCands" ); - if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->isolationPFGammaCands() ) ); + element = plotMap_.find( currentDiscriminatorLabel + plotType + "signalCands" ); + if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->signalCands() ) ); + element = plotMap_.find( currentDiscriminatorLabel + plotType + "signalChargedHadrCands" ); + if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->signalChargedHadrCands() ) ); + element = plotMap_.find( currentDiscriminatorLabel + plotType + "signalNeutrHadrCands" ); + if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->signalNeutrHadrCands() ) ); + element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationCands" ); + if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->isolationCands() ) ); + element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationChargedHadrCands" ); + if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->isolationChargedHadrCands() ) ); + element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationNeutrHadrCands" ); + if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->isolationNeutrHadrCands() ) ); + element = plotMap_.find( currentDiscriminatorLabel + plotType + "isolationGammaCands" ); + if( element != plotMap_.end() ) element->second->Fill( getSumPt( thePFTau->isolationGammaCands() ) ); //deprecated if( TauProducer_.find("PFTau") != string::npos ){ if ( currentDiscriminatorLabel.find("LeadingTrackPtCut") != string::npos){ - nPFJet_LeadingChargedHadron_ChargedHadronsSignal_->Fill((*thePFTau).signalPFChargedHadrCands().size()); - nPFJet_LeadingChargedHadron_ChargedHadronsIsolAnnulus_->Fill((*thePFTau).isolationPFChargedHadrCands().size()); - nPFJet_LeadingChargedHadron_GammasSignal_->Fill((*thePFTau).signalPFGammaCands().size()); - nPFJet_LeadingChargedHadron_GammasIsolAnnulus_->Fill((*thePFTau).isolationPFGammaCands().size()); - nPFJet_LeadingChargedHadron_NeutralHadronsSignal_->Fill((*thePFTau).signalPFNeutrHadrCands().size()); - nPFJet_LeadingChargedHadron_NeutralHadronsIsolAnnulus_->Fill((*thePFTau).isolationPFNeutrHadrCands().size()); + nPFJet_LeadingChargedHadron_ChargedHadronsSignal_->Fill((*thePFTau).signalChargedHadrCands().size()); + nPFJet_LeadingChargedHadron_ChargedHadronsIsolAnnulus_->Fill((*thePFTau).isolationChargedHadrCands().size()); + nPFJet_LeadingChargedHadron_GammasSignal_->Fill((*thePFTau).signalGammaCands().size()); + nPFJet_LeadingChargedHadron_GammasIsolAnnulus_->Fill((*thePFTau).isolationGammaCands().size()); + nPFJet_LeadingChargedHadron_NeutralHadronsSignal_->Fill((*thePFTau).signalNeutrHadrCands().size()); + nPFJet_LeadingChargedHadron_NeutralHadronsIsolAnnulus_->Fill((*thePFTau).isolationNeutrHadrCands().size()); } else if ( currentDiscriminatorLabel.find("ByIsolation") != string::npos ){ - nIsolated_NoChargedNoGammas_ChargedHadronsSignal_->Fill((*thePFTau).signalPFChargedHadrCands().size()); - nIsolated_NoChargedNoGammas_GammasSignal_->Fill((*thePFTau).signalPFGammaCands().size()); - nIsolated_NoChargedNoGammas_NeutralHadronsSignal_->Fill((*thePFTau).signalPFNeutrHadrCands().size()); - nIsolated_NoChargedNoGammas_NeutralHadronsIsolAnnulus_->Fill((*thePFTau).isolationPFNeutrHadrCands().size()); + nIsolated_NoChargedNoGammas_ChargedHadronsSignal_->Fill((*thePFTau).signalChargedHadrCands().size()); + nIsolated_NoChargedNoGammas_GammasSignal_->Fill((*thePFTau).signalGammaCands().size()); + nIsolated_NoChargedNoGammas_NeutralHadronsSignal_->Fill((*thePFTau).signalNeutrHadrCands().size()); + nIsolated_NoChargedNoGammas_NeutralHadronsIsolAnnulus_->Fill((*thePFTau).isolationNeutrHadrCands().size()); } } } @@ -617,9 +617,9 @@ void TauTagValidation::analyze(const edm::Event& iEvent, const edm::EventSetup& }//End of PFTau Collection If Loop } -double TauTagValidation::getSumPt(const std::vector > & candidates ){ +double TauTagValidation::getSumPt(const std::vector > & candidates ){ double sumPt = 0.; - for (std::vector >::const_iterator candidate = candidates.begin(); candidate!=candidates.end(); ++candidate) { + for (std::vector >::const_iterator candidate = candidates.begin(); candidate!=candidates.end(); ++candidate) { sumPt += (*candidate)->pt(); } return sumPt;