From b80afcb50b62c55eb5074d28c9acabfab85f8b04 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 13 Sep 2023 18:09:52 +0200 Subject: [PATCH 1/4] Implemented TauTagFilter for PNet-based tau HLT paths --- RecoTauTag/HLTProducers/src/TauTagFilter.cc | 105 ++++++++++++++++++ RecoTauTag/RecoTau/interface/TauWPThreshold.h | 66 +++++++++++ RecoTauTag/RecoTau/plugins/DeepTauId.cc | 53 +-------- 3 files changed, 173 insertions(+), 51 deletions(-) create mode 100644 RecoTauTag/HLTProducers/src/TauTagFilter.cc create mode 100644 RecoTauTag/RecoTau/interface/TauWPThreshold.h diff --git a/RecoTauTag/HLTProducers/src/TauTagFilter.cc b/RecoTauTag/HLTProducers/src/TauTagFilter.cc new file mode 100644 index 0000000000000..e9c15c63c52ff --- /dev/null +++ b/RecoTauTag/HLTProducers/src/TauTagFilter.cc @@ -0,0 +1,105 @@ +/* + * \class TauTagFilter + * + * Filter tau candidates based on tagger scores. + * + * \author Konstantin Androsov, EPFL and ETHZ + */ + +#include "DataFormats/BTauReco/interface/JetTag.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Utilities/interface/Exception.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Utilities/interface/InputTag.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "HLTrigger/HLTcore/interface/HLTFilter.h" +#include "RecoTauTag/RecoTau/interface/TauWPThreshold.h" + +class TauTagFilter : public HLTFilter { +public: + using TauCollection = reco::PFJetCollection; + using TauTagCollection = reco::JetTagCollection; + using TauRef = reco::PFJetRef; + using Selector = tau::TauWPThreshold; + + explicit TauTagFilter(const edm::ParameterSet& cfg) + : HLTFilter(cfg), + nExpected_(cfg.getParameter("nExpected")), + tausSrc_(cfg.getParameter("taus")), + tausToken_(consumes(tausSrc_)), + tauTagsToken_(consumes(cfg.getParameter("tauTags"))), + tauPtCorrToken_(mayConsume(cfg.getParameter("tauPtCorr"))), + selector_(cfg.getParameter("selection")), + minPt_(cfg.getParameter("minPt")), + maxEta_(cfg.getParameter("maxEta")), + usePtCorr_(cfg.getParameter("usePtCorr")) {} + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + makeHLTFilterDescription(desc); + desc.add("nExpected", 2)->setComment("number of expected taus per event"); + desc.add("taus", edm::InputTag(""))->setComment("input collection of taus"); + desc.add("tauTags", edm::InputTag(""))->setComment("input collection of tau tagger scores"); + desc.add("tauPtCorr", edm::InputTag(""))->setComment("input collection of multiplicative tau pt corrections"); + desc.add("selector", "0")->setComment("selection formula"); + desc.add("minPt", 20)->setComment("minimal tau pt"); + desc.add("maxEta", 2.5)->setComment("maximal tau abs(eta)"); + desc.add("usePtCorr", false)->setComment("use multiplicative tau pt corrections"); + descriptions.addWithDefaultLabel(desc); + } + + bool hltFilter(edm::Event& event, + const edm::EventSetup& eventsetup, + trigger::TriggerFilterObjectWithRefs& filterproduct) const override { + if (saveTags()) + filterproduct.addCollectionTag(tausSrc_); + + int nTauPassed = 0; + + const auto tausHandle = event.getHandle(tausToken_); + const auto& taus = *tausHandle; + + const auto& tauTags = event.get(tauTagsToken_); + const TauTagCollection* tauPtCorr = nullptr; + if (usePtCorr_) + tauPtCorr = &event.get(tauPtCorrToken_); + + if (taus.size() != tauTags.size()) + throw cms::Exception("Inconsistent Data", "PNetTauTagFilter::hltFilter") << "taus.size() != tauTags.size()"; + if (usePtCorr_ && taus.size() != tauPtCorr->size()) + throw cms::Exception("Inconsistent Data", "PNetTauTagFilter::hltFilter") << "taus.size() != tauPtCorr.size()"; + + for (size_t tau_idx = 0; tau_idx < taus.size(); ++tau_idx) { + const auto& tau = taus[tau_idx]; + double pt = tau.pt(); + if(usePtCorr_) + pt *= (*tauPtCorr)[tau_idx].second; + const double eta = std::abs(tau.eta()); + + if (pt > minPt_ && eta < maxEta_) { + const double tag = tauTags[tau_idx].second; + const double tag_thr = selector_(tau); + if (tag > tag_thr) { + filterproduct.addObject(nTauPassed, TauRef(tausHandle, tau_idx)); + nTauPassed++; + } + } + } + + return nTauPassed >= nExpected_; + } + +private: + const int nExpected_; + const edm::InputTag tausSrc_; + const edm::EDGetTokenT tausToken_; + const edm::EDGetTokenT tauTagsToken_, tauPtCorrToken_; + const Selector selector_; + const double minPt_, maxEta_; + const bool usePtCorr_; +}; + +//define this as a plug-in +#include "FWCore/Framework/interface/MakerMacros.h" +DEFINE_FWK_MODULE(TauTagFilter); diff --git a/RecoTauTag/RecoTau/interface/TauWPThreshold.h b/RecoTauTag/RecoTau/interface/TauWPThreshold.h new file mode 100644 index 0000000000000..8050ded4fb3da --- /dev/null +++ b/RecoTauTag/RecoTau/interface/TauWPThreshold.h @@ -0,0 +1,66 @@ +#ifndef RecoTauTag_RecoTau_TauWPThreshold_h +#define RecoTauTag_RecoTau_TauWPThreshold_h + +#include "DataFormats/TauReco/interface/BaseTau.h" +#include "DataFormats/PatCandidates/interface/Tau.h" +#include + +namespace tau { + class TauWPThreshold { + public: + explicit TauWPThreshold(const std::string& cut_str) { + bool simple_value = false; + try { + size_t pos = 0; + value_ = std::stod(cut_str, &pos); + simple_value = (pos == cut_str.size()); + } catch (std::invalid_argument&) { + } catch (std::out_of_range&) { + } + if (!simple_value) { + static const std::string prefix = + "[&](double *x, double *p) { const int decayMode = p[0];" + "const double pt = p[1]; const double eta = p[2];"; + static const int n_params = 3; + static const auto handler = [](int, Bool_t, const char*, const char*) -> void {}; + + std::string fn_str = prefix; + if (cut_str.find("return") == std::string::npos) + fn_str += " return " + cut_str + ";}"; + else + fn_str += cut_str + "}"; + auto old_handler = SetErrorHandler(handler); + fn_ = std::make_unique("fn_", fn_str.c_str(), 0, 1, n_params); + SetErrorHandler(old_handler); + if (!fn_->IsValid()) + throw cms::Exception("TauWPThreshold: invalid formula") << "Invalid WP cut formula = '" << cut_str << "'."; + } + } + + double operator()(int dm, double pt, double eta) const { + if (!fn_) + return value_; + + fn_->SetParameter(0, dm); + fn_->SetParameter(1, pt); + fn_->SetParameter(2, eta); + return fn_->Eval(0); + } + + double operator()(const reco::BaseTau& tau, bool isPFTau) const { + const int dm = isPFTau ? dynamic_cast(tau).decayMode() + : dynamic_cast(tau).decayMode(); + return (*this)(dm, tau.pt(), tau.eta()); + } + + double operator()(const reco::Candidate& tau) const { + return (*this)(-1, tau.pt(), tau.eta()); + } + + private: + std::unique_ptr fn_; + double value_; + }; +} + +#endif \ No newline at end of file diff --git a/RecoTauTag/RecoTau/plugins/DeepTauId.cc b/RecoTauTag/RecoTau/plugins/DeepTauId.cc index 676476a2ce5f0..3bba626b56854 100644 --- a/RecoTauTag/RecoTau/plugins/DeepTauId.cc +++ b/RecoTauTag/RecoTau/plugins/DeepTauId.cc @@ -20,6 +20,7 @@ #include "DataFormats/PatCandidates/interface/PATTauDiscriminator.h" #include "CommonTools/Utils/interface/StringObjectFunction.h" #include "RecoTauTag/RecoTau/interface/PFRecoTauClusterVariables.h" +#include "RecoTauTag/RecoTau/interface/TauWPThreshold.h" #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "DataFormats/Common/interface/View.h" @@ -27,7 +28,6 @@ #include "DataFormats/Provenance/interface/ProductProvenance.h" #include "DataFormats/Provenance/interface/ProcessHistoryID.h" #include "FWCore/Common/interface/Provenance.h" -#include #include #include "RecoTauTag/RecoTau/interface/DeepTauScaling.h" #include "FWCore/Utilities/interface/isFinite.h" @@ -47,55 +47,6 @@ namespace deep_tau { PUcorrPtSum }; - class TauWPThreshold { - public: - explicit TauWPThreshold(const std::string& cut_str) { - bool simple_value = false; - try { - size_t pos = 0; - value_ = std::stod(cut_str, &pos); - simple_value = (pos == cut_str.size()); - } catch (std::invalid_argument&) { - } catch (std::out_of_range&) { - } - if (!simple_value) { - static const std::string prefix = - "[&](double *x, double *p) { const int decayMode = p[0];" - "const double pt = p[1]; const double eta = p[2];"; - static const int n_params = 3; - static const auto handler = [](int, Bool_t, const char*, const char*) -> void {}; - - std::string fn_str = prefix; - if (cut_str.find("return") == std::string::npos) - fn_str += " return " + cut_str + ";}"; - else - fn_str += cut_str + "}"; - auto old_handler = SetErrorHandler(handler); - fn_ = std::make_unique("fn_", fn_str.c_str(), 0, 1, n_params); - SetErrorHandler(old_handler); - if (!fn_->IsValid()) - throw cms::Exception("TauWPThreshold: invalid formula") << "Invalid WP cut formula = '" << cut_str << "'."; - } - } - double operator()(const reco::BaseTau& tau, bool isPFTau) const { - if (!fn_) { - return value_; - } - - if (isPFTau) - fn_->SetParameter(0, dynamic_cast(tau).decayMode()); - else - fn_->SetParameter(0, dynamic_cast(tau).decayMode()); - fn_->SetParameter(1, tau.pt()); - fn_->SetParameter(2, tau.eta()); - return fn_->Eval(0); - } - - private: - std::unique_ptr fn_; - double value_; - }; - class DeepTauCache { public: using GraphPtr = std::shared_ptr; @@ -951,7 +902,7 @@ class DeepTauId : public edm::stream::EDProducer>; - using Cutter = deep_tau::TauWPThreshold; + using Cutter = tau::TauWPThreshold; using CutterPtr = std::unique_ptr; using WPList = std::vector; From 3ddf342fc31a1698e70b98124c0a9c631c6baa58 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 5 Oct 2023 17:00:37 +0200 Subject: [PATCH 2/4] TauTagFilter: added possibility to match with seeds --- RecoTauTag/HLTProducers/src/TauTagFilter.cc | 61 +++++++++++++++++++-- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/RecoTauTag/HLTProducers/src/TauTagFilter.cc b/RecoTauTag/HLTProducers/src/TauTagFilter.cc index e9c15c63c52ff..508d962487367 100644 --- a/RecoTauTag/HLTProducers/src/TauTagFilter.cc +++ b/RecoTauTag/HLTProducers/src/TauTagFilter.cc @@ -7,6 +7,7 @@ */ #include "DataFormats/BTauReco/interface/JetTag.h" +#include "DataFormats/HLTReco/interface/TriggerTypeDefs.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Utilities/interface/Exception.h" #include "FWCore/Framework/interface/Frameworkfwd.h" @@ -16,12 +17,16 @@ #include "HLTrigger/HLTcore/interface/HLTFilter.h" #include "RecoTauTag/RecoTau/interface/TauWPThreshold.h" +namespace { +} + class TauTagFilter : public HLTFilter { public: using TauCollection = reco::PFJetCollection; using TauTagCollection = reco::JetTagCollection; using TauRef = reco::PFJetRef; using Selector = tau::TauWPThreshold; + using LorentzVectorM = math::PtEtaPhiMLorentzVector; explicit TauTagFilter(const edm::ParameterSet& cfg) : HLTFilter(cfg), @@ -30,10 +35,14 @@ class TauTagFilter : public HLTFilter { tausToken_(consumes(tausSrc_)), tauTagsToken_(consumes(cfg.getParameter("tauTags"))), tauPtCorrToken_(mayConsume(cfg.getParameter("tauPtCorr"))), + seedsSrc_(mayConsume(cfg.getParameter("seeds"))), + seedTypes_(cfg.getParameter>("seedTypes")), selector_(cfg.getParameter("selection")), minPt_(cfg.getParameter("minPt")), maxEta_(cfg.getParameter("maxEta")), - usePtCorr_(cfg.getParameter("usePtCorr")) {} + usePtCorr_(cfg.getParameter("usePtCorr")), + matchWithSeeds_(cfg.getParameter("matchWithSeeds")), + matchingdR2_(std::pow(cfg.getParameter("matchingdR"), 2)) {} static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; @@ -42,10 +51,16 @@ class TauTagFilter : public HLTFilter { desc.add("taus", edm::InputTag(""))->setComment("input collection of taus"); desc.add("tauTags", edm::InputTag(""))->setComment("input collection of tau tagger scores"); desc.add("tauPtCorr", edm::InputTag(""))->setComment("input collection of multiplicative tau pt corrections"); - desc.add("selector", "0")->setComment("selection formula"); + desc.add("seeds", edm::InputTag(""))->setComment("input collection of seeds"); + desc.add>("seedTypes", + { trigger::TriggerL1Tau, trigger::TriggerL1Jet, + trigger::TriggerTau, trigger::TriggerJet })->setComment("list of seed object types"); + desc.add("selection", "0")->setComment("selection formula"); desc.add("minPt", 20)->setComment("minimal tau pt"); desc.add("maxEta", 2.5)->setComment("maximal tau abs(eta)"); desc.add("usePtCorr", false)->setComment("use multiplicative tau pt corrections"); + desc.add("matchWithSeeds", false)->setComment("apply match with seeds"); + desc.add("matchingdR", 0.5)->setComment("deltaR for matching with seeds"); descriptions.addWithDefaultLabel(desc); } @@ -60,6 +75,30 @@ class TauTagFilter : public HLTFilter { const auto tausHandle = event.getHandle(tausToken_); const auto& taus = *tausHandle; + std::vector seed_p4s; + if(matchWithSeeds_) { + const auto& seeds = event.get(seedsSrc_); + for (const int seedType : seedTypes_) { + if(seedType == trigger::TriggerL1Tau) { + extractMomenta(seeds, seedType, seed_p4s); + } else if(seedType == trigger::TriggerL1Jet) { + extractMomenta(seeds, seedType, seed_p4s); + } else if(seedType == trigger::TriggerTau) { + extractMomenta>(seeds, seedType, seed_p4s); + } else if(seedType == trigger::TriggerJet) { + extractMomenta>(seeds, seedType, seed_p4s); + } else + throw cms::Exception("Invalid seed type", "PNetTauTagFilter::hltFilter") << "Invalid seed type: " << seedType; + } + } + auto hasMatch = [&](const LorentzVectorM& p4) { + for(const auto& seed_p4 : seed_p4s) { + if(reco::deltaR2(p4, seed_p4) < matchingdR2_) + return true; + } + return false; + }; + const auto& tauTags = event.get(tauTagsToken_); const TauTagCollection* tauPtCorr = nullptr; if (usePtCorr_) @@ -76,8 +115,7 @@ class TauTagFilter : public HLTFilter { if(usePtCorr_) pt *= (*tauPtCorr)[tau_idx].second; const double eta = std::abs(tau.eta()); - - if (pt > minPt_ && eta < maxEta_) { + if (pt > minPt_ && eta < maxEta_ && (!matchWithSeeds_ || hasMatch(tau.polarP4()))) { const double tag = tauTags[tau_idx].second; const double tag_thr = selector_(tau); if (tag > tag_thr) { @@ -90,14 +128,29 @@ class TauTagFilter : public HLTFilter { return nTauPassed >= nExpected_; } +private: + template + static void extractMomenta(const trigger::TriggerRefsCollections& triggerObjects, int objType, + std::vector& p4s) { + Collection objects; + triggerObjects.getObjects(objType, objects); + for (const auto& obj : objects) + p4s.push_back(obj->polarP4()); + } + + private: const int nExpected_; const edm::InputTag tausSrc_; const edm::EDGetTokenT tausToken_; const edm::EDGetTokenT tauTagsToken_, tauPtCorrToken_; + const edm::EDGetTokenT seedsSrc_; + const std::vector seedTypes_; const Selector selector_; const double minPt_, maxEta_; const bool usePtCorr_; + const bool matchWithSeeds_; + const double matchingdR2_; }; //define this as a plug-in From 3cbc2d70f157fd115a79ab5104ebab0a646e95b7 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Fri, 6 Oct 2023 17:44:27 +0200 Subject: [PATCH 3/4] Correctly set obj id for outputs of (L2)TauTagFilter, better handle type of objs to match, address case of matching dR<0 and code-formatting --- RecoTauTag/HLTProducers/src/L2TauTagFilter.cc | 2 +- RecoTauTag/HLTProducers/src/TauTagFilter.cc | 83 +++++++++++-------- RecoTauTag/RecoTau/interface/TauWPThreshold.h | 10 +-- 3 files changed, 53 insertions(+), 42 deletions(-) diff --git a/RecoTauTag/HLTProducers/src/L2TauTagFilter.cc b/RecoTauTag/HLTProducers/src/L2TauTagFilter.cc index bcc21c9e7ace8..dd812ca1a52b7 100644 --- a/RecoTauTag/HLTProducers/src/L2TauTagFilter.cc +++ b/RecoTauTag/HLTProducers/src/L2TauTagFilter.cc @@ -56,7 +56,7 @@ class L2TauTagFilter : public HLTFilter { } for (size_t l1_idx = 0; l1_idx < l1Taus.size(); l1_idx++) { if (L2Outcomes[l1_idx] >= discrWP_ || l1Taus[l1_idx]->pt() > l1PtTh_) { - filterproduct.addObject(nTauPassed, l1Taus[l1_idx]); + filterproduct.addObject(trigger::TriggerL1Tau, l1Taus[l1_idx]); nTauPassed++; } } diff --git a/RecoTauTag/HLTProducers/src/TauTagFilter.cc b/RecoTauTag/HLTProducers/src/TauTagFilter.cc index 508d962487367..c9305f556605c 100644 --- a/RecoTauTag/HLTProducers/src/TauTagFilter.cc +++ b/RecoTauTag/HLTProducers/src/TauTagFilter.cc @@ -17,9 +17,6 @@ #include "HLTrigger/HLTcore/interface/HLTFilter.h" #include "RecoTauTag/RecoTau/interface/TauWPThreshold.h" -namespace { -} - class TauTagFilter : public HLTFilter { public: using TauCollection = reco::PFJetCollection; @@ -41,8 +38,13 @@ class TauTagFilter : public HLTFilter { minPt_(cfg.getParameter("minPt")), maxEta_(cfg.getParameter("maxEta")), usePtCorr_(cfg.getParameter("usePtCorr")), - matchWithSeeds_(cfg.getParameter("matchWithSeeds")), - matchingdR2_(std::pow(cfg.getParameter("matchingdR"), 2)) {} + matchWithSeeds_(cfg.getParameter("matchWithSeeds") && cfg.getParameter("matchingdR") >= 0), + matchingdR2_(std::pow(cfg.getParameter("matchingdR"), 2)) { + if (cfg.getParameter("matchWithSeeds") && cfg.getParameter("matchingdR") < 0) + edm::LogWarning("TauTagFilter") << "Matching with seeds is disabled because matchingdR < 0"; + + extractMomenta(); // checking that all seed types are supported + } static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; @@ -50,11 +52,12 @@ class TauTagFilter : public HLTFilter { desc.add("nExpected", 2)->setComment("number of expected taus per event"); desc.add("taus", edm::InputTag(""))->setComment("input collection of taus"); desc.add("tauTags", edm::InputTag(""))->setComment("input collection of tau tagger scores"); - desc.add("tauPtCorr", edm::InputTag(""))->setComment("input collection of multiplicative tau pt corrections"); + desc.add("tauPtCorr", edm::InputTag("")) + ->setComment("input collection of multiplicative tau pt corrections"); desc.add("seeds", edm::InputTag(""))->setComment("input collection of seeds"); desc.add>("seedTypes", - { trigger::TriggerL1Tau, trigger::TriggerL1Jet, - trigger::TriggerTau, trigger::TriggerJet })->setComment("list of seed object types"); + {trigger::TriggerL1Tau, trigger::TriggerL1Jet, trigger::TriggerTau, trigger::TriggerJet}) + ->setComment("list of seed object types"); desc.add("selection", "0")->setComment("selection formula"); desc.add("minPt", 20)->setComment("minimal tau pt"); desc.add("maxEta", 2.5)->setComment("maximal tau abs(eta)"); @@ -75,25 +78,10 @@ class TauTagFilter : public HLTFilter { const auto tausHandle = event.getHandle(tausToken_); const auto& taus = *tausHandle; - std::vector seed_p4s; - if(matchWithSeeds_) { - const auto& seeds = event.get(seedsSrc_); - for (const int seedType : seedTypes_) { - if(seedType == trigger::TriggerL1Tau) { - extractMomenta(seeds, seedType, seed_p4s); - } else if(seedType == trigger::TriggerL1Jet) { - extractMomenta(seeds, seedType, seed_p4s); - } else if(seedType == trigger::TriggerTau) { - extractMomenta>(seeds, seedType, seed_p4s); - } else if(seedType == trigger::TriggerJet) { - extractMomenta>(seeds, seedType, seed_p4s); - } else - throw cms::Exception("Invalid seed type", "PNetTauTagFilter::hltFilter") << "Invalid seed type: " << seedType; - } - } + const std::vector seed_p4s = extractMomenta(&event); auto hasMatch = [&](const LorentzVectorM& p4) { - for(const auto& seed_p4 : seed_p4s) { - if(reco::deltaR2(p4, seed_p4) < matchingdR2_) + for (const auto& seed_p4 : seed_p4s) { + if (reco::deltaR2(p4, seed_p4) < matchingdR2_) return true; } return false; @@ -112,14 +100,14 @@ class TauTagFilter : public HLTFilter { for (size_t tau_idx = 0; tau_idx < taus.size(); ++tau_idx) { const auto& tau = taus[tau_idx]; double pt = tau.pt(); - if(usePtCorr_) + if (usePtCorr_) pt *= (*tauPtCorr)[tau_idx].second; const double eta = std::abs(tau.eta()); if (pt > minPt_ && eta < maxEta_ && (!matchWithSeeds_ || hasMatch(tau.polarP4()))) { const double tag = tauTags[tau_idx].second; const double tag_thr = selector_(tau); if (tag > tag_thr) { - filterproduct.addObject(nTauPassed, TauRef(tausHandle, tau_idx)); + filterproduct.addObject(trigger::TriggerTau, TauRef(tausHandle, tau_idx)); nTauPassed++; } } @@ -129,15 +117,40 @@ class TauTagFilter : public HLTFilter { } private: - template - static void extractMomenta(const trigger::TriggerRefsCollections& triggerObjects, int objType, - std::vector& p4s) { - Collection objects; - triggerObjects.getObjects(objType, objects); - for (const auto& obj : objects) - p4s.push_back(obj->polarP4()); + std::vector extractMomenta(const edm::Event* event = nullptr) const { + std::vector seed_p4s; + if (matchWithSeeds_) { + const trigger::TriggerFilterObjectWithRefs* seeds = nullptr; + if (event) + seeds = &event->get(seedsSrc_); + for (const int seedType : seedTypes_) { + if (seedType == trigger::TriggerL1Tau) { + extractMomenta(seeds, seedType, seed_p4s); + } else if (seedType == trigger::TriggerL1Jet) { + extractMomenta(seeds, seedType, seed_p4s); + } else if (seedType == trigger::TriggerTau) { + extractMomenta>(seeds, seedType, seed_p4s); + } else if (seedType == trigger::TriggerJet) { + extractMomenta>(seeds, seedType, seed_p4s); + } else + throw cms::Exception("Invalid seed type", "PNetTauTagFilter::hltFilter") + << "Unsupported seed type: " << seedType; + } + } + return seed_p4s; } + template + static void extractMomenta(const trigger::TriggerRefsCollections* triggerObjects, + int objType, + std::vector& p4s) { + if (triggerObjects) { + Collection objects; + triggerObjects->getObjects(objType, objects); + for (const auto& obj : objects) + p4s.push_back(obj->polarP4()); + } + } private: const int nExpected_; diff --git a/RecoTauTag/RecoTau/interface/TauWPThreshold.h b/RecoTauTag/RecoTau/interface/TauWPThreshold.h index 8050ded4fb3da..2cd4dd7bb5222 100644 --- a/RecoTauTag/RecoTau/interface/TauWPThreshold.h +++ b/RecoTauTag/RecoTau/interface/TauWPThreshold.h @@ -48,19 +48,17 @@ namespace tau { } double operator()(const reco::BaseTau& tau, bool isPFTau) const { - const int dm = isPFTau ? dynamic_cast(tau).decayMode() - : dynamic_cast(tau).decayMode(); + const int dm = + isPFTau ? dynamic_cast(tau).decayMode() : dynamic_cast(tau).decayMode(); return (*this)(dm, tau.pt(), tau.eta()); } - double operator()(const reco::Candidate& tau) const { - return (*this)(-1, tau.pt(), tau.eta()); - } + double operator()(const reco::Candidate& tau) const { return (*this)(-1, tau.pt(), tau.eta()); } private: std::unique_ptr fn_; double value_; }; -} +} // namespace tau #endif \ No newline at end of file From 0cffcda03d50486ed9c9954cf1c7c995aacb1a29 Mon Sep 17 00:00:00 2001 From: Michal Bluj Date: Wed, 25 Oct 2023 15:07:47 +0200 Subject: [PATCH 4/4] Correct exception messages to match with actual class name --- RecoTauTag/HLTProducers/src/TauTagFilter.cc | 6 +++--- RecoTauTag/RecoTau/interface/TauWPThreshold.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/RecoTauTag/HLTProducers/src/TauTagFilter.cc b/RecoTauTag/HLTProducers/src/TauTagFilter.cc index c9305f556605c..1755063a70153 100644 --- a/RecoTauTag/HLTProducers/src/TauTagFilter.cc +++ b/RecoTauTag/HLTProducers/src/TauTagFilter.cc @@ -93,9 +93,9 @@ class TauTagFilter : public HLTFilter { tauPtCorr = &event.get(tauPtCorrToken_); if (taus.size() != tauTags.size()) - throw cms::Exception("Inconsistent Data", "PNetTauTagFilter::hltFilter") << "taus.size() != tauTags.size()"; + throw cms::Exception("Inconsistent Data", "TauTagFilter::hltFilter") << "taus.size() != tauTags.size()"; if (usePtCorr_ && taus.size() != tauPtCorr->size()) - throw cms::Exception("Inconsistent Data", "PNetTauTagFilter::hltFilter") << "taus.size() != tauPtCorr.size()"; + throw cms::Exception("Inconsistent Data", "TauTagFilter::hltFilter") << "taus.size() != tauPtCorr.size()"; for (size_t tau_idx = 0; tau_idx < taus.size(); ++tau_idx) { const auto& tau = taus[tau_idx]; @@ -133,7 +133,7 @@ class TauTagFilter : public HLTFilter { } else if (seedType == trigger::TriggerJet) { extractMomenta>(seeds, seedType, seed_p4s); } else - throw cms::Exception("Invalid seed type", "PNetTauTagFilter::hltFilter") + throw cms::Exception("Invalid seed type", "TauTagFilter::extractMomenta") << "Unsupported seed type: " << seedType; } } diff --git a/RecoTauTag/RecoTau/interface/TauWPThreshold.h b/RecoTauTag/RecoTau/interface/TauWPThreshold.h index 2cd4dd7bb5222..07332bb46bd1e 100644 --- a/RecoTauTag/RecoTau/interface/TauWPThreshold.h +++ b/RecoTauTag/RecoTau/interface/TauWPThreshold.h @@ -61,4 +61,4 @@ namespace tau { }; } // namespace tau -#endif \ No newline at end of file +#endif