File indexing completed on 2024-04-06 12:27:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "HLTrigger/HLTcore/interface/HLTFilter.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Utilities/interface/Exception.h"
0014 #include "FWCore/Framework/interface/Frameworkfwd.h"
0015 #include "FWCore/Utilities/interface/InputTag.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0018
0019 class L2TauTagFilter : public HLTFilter {
0020 public:
0021 explicit L2TauTagFilter(const edm::ParameterSet& cfg)
0022 : HLTFilter(cfg),
0023 nExpected_(cfg.getParameter<int>("nExpected")),
0024 l1TauSrc_(cfg.getParameter<edm::InputTag>("L1TauSrc")),
0025 l1TauSrcToken_(consumes<trigger::TriggerFilterObjectWithRefs>(l1TauSrc_)),
0026 l2OutcomesToken_(consumes<std::vector<float>>(cfg.getParameter<edm::InputTag>("L2Outcomes"))),
0027 discrWP_(cfg.getParameter<double>("DiscrWP")),
0028 l1PtTh_(cfg.getParameter<double>("l1TauPtThreshold")) {}
0029 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0030 edm::ParameterSetDescription desc;
0031 makeHLTFilterDescription(desc);
0032 desc.add<int>("nExpected", 2)->setComment("number of expected taus per event");
0033 desc.add<edm::InputTag>("L1TauSrc", edm::InputTag(""))
0034 ->setComment("Which trigger should the L1 Taus collection pass");
0035 desc.add<edm::InputTag>("L2Outcomes", edm::InputTag(""))->setComment("L2 CNN outcomes");
0036 desc.add<double>("DiscrWP", 0.1227)->setComment("value of discriminator threshold");
0037 desc.add<double>("l1TauPtThreshold", 250)->setComment("value of L1Tau pass-through pt threshold");
0038 descriptions.addWithDefaultLabel(desc);
0039 }
0040
0041 bool hltFilter(edm::Event& event,
0042 const edm::EventSetup& eventsetup,
0043 trigger::TriggerFilterObjectWithRefs& filterproduct) const override {
0044 if (saveTags())
0045 filterproduct.addCollectionTag(l1TauSrc_);
0046
0047 int nTauPassed = 0;
0048
0049 l1t::TauVectorRef l1Taus;
0050 auto const& l1TriggeredTaus = event.get(l1TauSrcToken_);
0051 l1TriggeredTaus.getObjects(trigger::TriggerL1Tau, l1Taus);
0052
0053 auto const& L2Outcomes = event.get(l2OutcomesToken_);
0054 if (L2Outcomes.size() != l1Taus.size()) {
0055 throw cms::Exception("Inconsistent Data", "L2TauTagFilter::hltFilter") << "CNN output size != L1 taus size \n";
0056 }
0057 for (size_t l1_idx = 0; l1_idx < l1Taus.size(); l1_idx++) {
0058 if (L2Outcomes[l1_idx] >= discrWP_ || l1Taus[l1_idx]->pt() > l1PtTh_) {
0059 filterproduct.addObject(trigger::TriggerL1Tau, l1Taus[l1_idx]);
0060 nTauPassed++;
0061 }
0062 }
0063
0064 return nTauPassed >= nExpected_;
0065 }
0066
0067 private:
0068 const int nExpected_;
0069 const edm::InputTag l1TauSrc_;
0070 const edm::EDGetTokenT<trigger::TriggerFilterObjectWithRefs> l1TauSrcToken_;
0071 const edm::EDGetTokenT<std::vector<float>> l2OutcomesToken_;
0072 const double discrWP_;
0073 const double l1PtTh_;
0074 };
0075
0076
0077 #include "FWCore/Framework/interface/MakerMacros.h"
0078 DEFINE_FWK_MODULE(L2TauTagFilter);