From 232ba2dff4c26a360f8c8487fb32ae54a4c8bd21 Mon Sep 17 00:00:00 2001 From: Louis Portales Date: Wed, 8 Mar 2023 19:02:08 +0100 Subject: [PATCH] L1 matching module for VBF+dijet HLT (Squashed commits) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ÃL1 matching module for VBFÂ+dijet HLT code-format Merging new module into L1TJetsMatching Splitting VBF+dijet specific matching from the 2-3 jet matching default implementing comments minor change throwing exception when incorrect input option categorise functions as class members --- .../HLTProducers/interface/L1TJetsMatching.h | 169 ++++++++++++++++-- 1 file changed, 154 insertions(+), 15 deletions(-) diff --git a/RecoTauTag/HLTProducers/interface/L1TJetsMatching.h b/RecoTauTag/HLTProducers/interface/L1TJetsMatching.h index a11323107f503..0a192331b2b68 100644 --- a/RecoTauTag/HLTProducers/interface/L1TJetsMatching.h +++ b/RecoTauTag/HLTProducers/interface/L1TJetsMatching.h @@ -37,14 +37,16 @@ #include "Math/GenVector/VectorUtil.h" #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h" -#include "FWCore/Utilities/interface/EDMException.h" +#include "FWCore/Utilities/interface/Exception.h" #include "DataFormats/JetReco/interface/PFJet.h" #include "HLTrigger/HLTcore/interface/defaultModuleLabel.h" #include "DataFormats/Math/interface/deltaR.h" -#include #include +#include +#include +#include template class L1TJetsMatching : public edm::global::EDProducer<> { @@ -53,10 +55,15 @@ class L1TJetsMatching : public edm::global::EDProducer<> { ~L1TJetsMatching() override; void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + std::pair, std::vector> categorise( + const std::vector& pfMatchedJets, double pt1, double pt2, double pt3, double Mjj) const; + std::tuple, std::vector, std::vector> categoriseVBFPlus2CentralJets( + const std::vector& pfMatchedJets, double pt1, double pt2, double pt3, double Mjj) const; private: const edm::EDGetTokenT> jetSrc_; const edm::EDGetTokenT jetTrigger_; + const std::string matchingMode_; const double pt1Min_; const double pt2Min_; const double pt3Min_; @@ -65,11 +72,11 @@ class L1TJetsMatching : public edm::global::EDProducer<> { const double matchingR2_; }; // -// class decleration +// class declaration // template -std::pair, std::vector> categorise( - const std::vector& pfMatchedJets, double pt1, double pt2, double pt3, double Mjj) { +std::pair, std::vector> L1TJetsMatching::categorise( + const std::vector& pfMatchedJets, double pt1, double pt2, double pt3, double Mjj) const { std::pair, std::vector> output; unsigned int i1 = 0; unsigned int i2 = 0; @@ -111,18 +118,133 @@ std::pair, std::vector> categorise( return output; } +template +std::tuple, std::vector, std::vector> L1TJetsMatching::categoriseVBFPlus2CentralJets( + const std::vector& pfMatchedJets, double pt1, double pt2, double pt3, double Mjj) const { //60, 30, 50, 500 + std::tuple, std::vector, std::vector> output; + unsigned int i1 = 0; + unsigned int i2 = 0; + + double mjj = 0; + if (pfMatchedJets.size() > 1) { + for (unsigned int i = 0; i < pfMatchedJets.size() - 1; i++) { + const T& myJet1 = (pfMatchedJets)[i]; + + for (unsigned int j = i + 1; j < pfMatchedJets.size(); j++) { + const T& myJet2 = (pfMatchedJets)[j]; + + const double mjj_test = (myJet1.p4() + myJet2.p4()).M(); + + if (mjj_test > mjj) { + mjj = mjj_test; + i1 = i; + i2 = j; + } + } + } + + const T& myJet1 = (pfMatchedJets)[i1]; + const T& myJet2 = (pfMatchedJets)[i2]; + + std::vector vec4jets; + vec4jets.reserve(4); + std::vector vec5jets; + vec5jets.reserve(5); + std::vector vec6jets; + vec6jets.reserve(6); + if (pfMatchedJets.size() > 3) { + if ((mjj > Mjj) && (myJet1.pt() >= pt3) && (myJet2.pt() > pt2)) { + vec4jets.push_back(myJet1); + vec4jets.push_back(myJet2); + unsigned int i3 = 0; + unsigned int i4 = 0; + bool filledi3 = false; + for (unsigned int i = 0; i < pfMatchedJets.size(); i++) { + if (i == i1) + continue; + if (i == i2) + continue; + if (!filledi3) { + i3 = i; + filledi3 = true; + } else { + i4 = i; + break; + } + } + const T& myJet3 = pfMatchedJets[i3]; + const T& myJet4 = pfMatchedJets[i4]; + vec4jets.push_back(myJet3); + vec4jets.push_back(myJet4); + } + + if ((mjj > Mjj) && (myJet1.pt() < pt1) && (myJet1.pt() < pt3) && (myJet1.pt() > pt2) && + (myJet2.pt() > pt2)) { //60, 30, 50, 500 + + std::vector idx_jets; + idx_jets.clear(); + + for (unsigned int i = 1; i < pfMatchedJets.size(); i++) { //skip highest pT jet + if (i == i1 || i == i2) + continue; + if ((pfMatchedJets)[i].pt() > pt2) { + idx_jets.push_back(i); + } + } + if (idx_jets.size() == 2) { + const T& thirdjet = pfMatchedJets[0]; + const T& fourthjet = pfMatchedJets[idx_jets[0]]; + const T& fifthjet = pfMatchedJets[idx_jets[1]]; + + vec5jets.push_back(myJet1); + vec5jets.push_back(myJet2); + vec5jets.push_back(thirdjet); + vec5jets.push_back(fourthjet); + vec5jets.push_back(fifthjet); + } else if (idx_jets.size() > 2) { + const T& thirdjet = pfMatchedJets[0]; + const T& fourthjet = pfMatchedJets[idx_jets[0]]; + const T& fifthjet = pfMatchedJets[idx_jets[1]]; + const T& sixthjet = pfMatchedJets[idx_jets[2]]; + + vec6jets.push_back(myJet1); + vec6jets.push_back(myJet2); + vec6jets.push_back(thirdjet); + vec6jets.push_back(fourthjet); + vec6jets.push_back(fifthjet); + vec6jets.push_back(sixthjet); + } + } + } + + output = std::make_tuple(vec4jets, vec5jets, vec6jets); + } + + return output; +} + template L1TJetsMatching::L1TJetsMatching(const edm::ParameterSet& iConfig) : jetSrc_(consumes>(iConfig.getParameter("JetSrc"))), jetTrigger_(consumes(iConfig.getParameter("L1JetTrigger"))), + matchingMode_(iConfig.getParameter("matchingMode")), pt1Min_(iConfig.getParameter("pt1Min")), pt2Min_(iConfig.getParameter("pt2Min")), pt3Min_(iConfig.getParameter("pt3Min")), mjjMin_(iConfig.getParameter("mjjMin")), matchingR_(iConfig.getParameter("matchingR")), matchingR2_(matchingR_ * matchingR_) { - produces>("TwoJets"); - produces>("ThreeJets"); + if (matchingMode_ == "VBF") { // Default + produces>("TwoJets"); + produces>("ThreeJets"); + } else if (matchingMode_ == "VBFPlus2CentralJets") { + produces>("FourJets"); + produces>("FiveJets"); + produces>("SixJets"); + } else { + throw cms::Exception("InvalidConfiguration") << "invalid value for \"matchingMode\": " << matchingMode_ + << " (valid values are \"VBF\" and \"VBFPlus2CentralJets\")"; + } } template L1TJetsMatching::~L1TJetsMatching() {} @@ -130,7 +252,6 @@ L1TJetsMatching::~L1TJetsMatching() {} template void L1TJetsMatching::produce(edm::StreamID iSId, edm::Event& iEvent, const edm::EventSetup& iES) const { unique_ptr> pfMatchedJets(new std::vector); - std::pair, std::vector> output; // Getting HLT jets to be matched edm::Handle> pfJets; @@ -157,28 +278,46 @@ void L1TJetsMatching::produce(edm::StreamID iSId, edm::Event& iEvent, const e } } } + // order pfMatchedJets by pT + std::sort(pfMatchedJets->begin(), pfMatchedJets->end(), [](const T& j1, const T& j2) { return j1.pt() > j2.pt(); }); + + if (matchingMode_ == "VBF") { // Default + std::pair, std::vector> output = categorise(*pfMatchedJets, pt1Min_, pt2Min_, pt3Min_, mjjMin_); + auto output1 = std::make_unique>(output.first); + auto output2 = std::make_unique>(output.second); - output = categorise(*pfMatchedJets, pt1Min_, pt2Min_, pt3Min_, mjjMin_); - unique_ptr> output1(new std::vector(output.first)); - unique_ptr> output2(new std::vector(output.second)); + iEvent.put(std::move(output1), "TwoJets"); + iEvent.put(std::move(output2), "ThreeJets"); - iEvent.put(std::move(output1), "TwoJets"); - iEvent.put(std::move(output2), "ThreeJets"); + } else if (matchingMode_ == "VBFPlus2CentralJets") { + std::tuple, std::vector, std::vector> output = + categoriseVBFPlus2CentralJets(*pfMatchedJets, pt1Min_, pt2Min_, pt3Min_, mjjMin_); + auto output1 = std::make_unique>(std::get<0>(output)); + auto output2 = std::make_unique>(std::get<1>(output)); + auto output3 = std::make_unique>(std::get<2>(output)); + + iEvent.put(std::move(output1), "FourJets"); + iEvent.put(std::move(output2), "FiveJets"); + iEvent.put(std::move(output3), "SixJets"); + } } + template void L1TJetsMatching::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; desc.add("L1JetTrigger", edm::InputTag("hltL1DiJetVBF"))->setComment("Name of trigger filter"); desc.add("JetSrc", edm::InputTag("hltAK4PFJetsTightIDCorrected")) ->setComment("Input collection of PFJets"); + desc.add("matchingMode", "VBF") + ->setComment("Switch from Di/tri-jet (VBF) to Multi-jet (VBFPlus2CentralJets) matching"); desc.add("pt1Min", 110.0)->setComment("Minimal pT1 of PFJets to match"); desc.add("pt2Min", 35.0)->setComment("Minimal pT2 of PFJets to match"); desc.add("pt3Min", 110.0)->setComment("Minimum pT3 of PFJets to match"); desc.add("mjjMin", 650.0)->setComment("Minimal mjj of matched PFjets"); desc.add("matchingR", 0.5)->setComment("dR value used for matching"); descriptions.setComment( - "This module produces collection of PFJetss matched to L1 Taus / Jets passing a HLT filter (Only p4 and vertex " - "of returned PFJetss are set)."); + "This module produces collection of PFJets matched to L1 Taus / Jets passing a HLT filter (Only p4 and vertex " + "of returned PFJets are set)."); descriptions.add(defaultModuleLabel>(), desc); }