Skip to content

Commit

Permalink
ÃL1 matching module for VBFÂ+dijet HLT
Browse files Browse the repository at this point in the history
  • Loading branch information
portalesHEP committed Mar 8, 2023
1 parent 2f899a2 commit 8ae3b6d
Show file tree
Hide file tree
Showing 2 changed files with 250 additions and 0 deletions.
243 changes: 243 additions & 0 deletions RecoTauTag/HLTProducers/interface/L1TJetsMatchingVBFPlus2CentralJets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
// -*- C++ -*-
//
// Package: RecoTauTag/HLTProducers
// Class: L1TJetsMatchingVBFPlus2CentralJetsVBFPlus2CentralJets
//
/**\class L1TJetsMatchingVBFPlus2CentralJets L1TJetsMatchingVBFPlus2CentralJets.h
RecoTauTag/HLTProducers/interface/L1TJetsMatchingVBFPlus2CentralJets.h
Description:
Matching L1 to PF/Calo Jets. Used for HLT_VBF paths.
*Matches PF/Calo Jets to L1 jets from the dedicated seed
*Adds selection criteria to the leading/subleading jets as well as the maximum dijet mass
*Separates collections of PF/Calo jets into two categories
*/
//
// Original Author: Vukasin Milosevic
// Created: Thu, 01 Jun 2017 17:23:00 GMT
//
//

#ifndef RecoTauTag_HLTProducers_L1TJetsMatchingVBFPlus2CentralJets_h
#define RecoTauTag_HLTProducers_L1TJetsMatchingVBFPlus2CentralJets_h

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/JetReco/interface/PFJetCollection.h"
#include "DataFormats/TauReco/interface/PFTauFwd.h"
#include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"

#include "Math/GenVector/VectorUtil.h"
#include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include "DataFormats/JetReco/interface/PFJet.h"

#include "HLTrigger/HLTcore/interface/defaultModuleLabel.h"
#include "DataFormats/Math/interface/deltaR.h"

#include <map>
#include <vector>

template <typename T>
class L1TJetsMatchingVBFPlus2CentralJets : public edm::global::EDProducer<> {
public:
explicit L1TJetsMatchingVBFPlus2CentralJets(const edm::ParameterSet&);
~L1TJetsMatchingVBFPlus2CentralJets() override;
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
const edm::EDGetTokenT<std::vector<T>> jetSrc_;
const edm::EDGetTokenT<trigger::TriggerFilterObjectWithRefs> jetTrigger_;
const double pt1Min_;
const double pt2Min_;
const double pt3Min_;
const double mjjMin_;
const double matchingR_;
const double matchingR2_;
};
//
// class decleration
//
template <typename T>

std::tuple<std::vector<T>, std::vector<T>, std::vector<T> > categorise(const std::vector<T>& pfMatchedJets, double pt1, double pt2, double pt3, double Mjj) {//60, 30, 50, 500
std::tuple<std::vector<T>, std::vector<T>, std::vector<T>> 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<T> vec4jets;
std::vector<T> vec5jets;
std::vector<T> vec6jets;

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<unsigned int> 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.at(0)];
const T& fifthjet = (pfMatchedJets)[idx_jets.at(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.at(0)];
const T& fifthjet = (pfMatchedJets)[idx_jets.at(1)];
const T& sixthjet = (pfMatchedJets)[idx_jets.at(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 <typename T>
L1TJetsMatchingVBFPlus2CentralJets<T>::L1TJetsMatchingVBFPlus2CentralJets(const edm::ParameterSet& iConfig)
: jetSrc_(consumes<std::vector<T>>(iConfig.getParameter<edm::InputTag>("JetSrc"))),
jetTrigger_(consumes<trigger::TriggerFilterObjectWithRefs>(iConfig.getParameter<edm::InputTag>("L1JetTrigger"))),
pt1Min_(iConfig.getParameter<double>("pt1Min")),
pt2Min_(iConfig.getParameter<double>("pt2Min")),
pt3Min_(iConfig.getParameter<double>("pt3Min")),
mjjMin_(iConfig.getParameter<double>("mjjMin")),
matchingR_(iConfig.getParameter<double>("matchingR")),
matchingR2_(matchingR_ * matchingR_) {
produces<std::vector<T>>("FourJets");
produces<std::vector<T>>("FiveJets");
produces<std::vector<T>>("SixJets");
}
template <typename T>
L1TJetsMatchingVBFPlus2CentralJets<T>::~L1TJetsMatchingVBFPlus2CentralJets() {}

template <typename T>
void L1TJetsMatchingVBFPlus2CentralJets<T>::produce(edm::StreamID iSId, edm::Event& iEvent, const edm::EventSetup& iES) const {
unique_ptr<std::vector<T>> pfMatchedJets(new std::vector<T>);
std::tuple<std::vector<T>, std::vector<T>, std::vector<T> > output;

// Getting HLT jets to be matched
edm::Handle<std::vector<T>> pfJets;
iEvent.getByToken(jetSrc_, pfJets);

edm::Handle<trigger::TriggerFilterObjectWithRefs> l1TriggeredJets;
iEvent.getByToken(jetTrigger_, l1TriggeredJets);

l1t::JetVectorRef jetCandRefVec;
l1TriggeredJets->getObjects(trigger::TriggerL1Jet, jetCandRefVec);

math::XYZPoint a(0., 0., 0.);

//std::cout<<"PFsize= "<<pfJets->size()<<endl<<" L1size= "<<jetCandRefVec.size()<<std::endl;
for (unsigned int iJet = 0; iJet < pfJets->size(); iJet++) {
const T& myJet = (*pfJets)[iJet];
for (unsigned int iL1Jet = 0; iL1Jet < jetCandRefVec.size(); iL1Jet++) {
if ((reco::deltaR2(myJet.p4(), jetCandRefVec[iL1Jet]->p4()) < matchingR2_) && (myJet.pt() > pt2Min_)) {
pfMatchedJets->push_back(myJet);
break;
}
}
}

output = categorise(*pfMatchedJets, pt1Min_, pt2Min_, pt3Min_, mjjMin_);
unique_ptr<std::vector<T>> output1(new std::vector<T>(std::get<0>(output)));
unique_ptr<std::vector<T>> output2(new std::vector<T>(std::get<1>(output)));
unique_ptr<std::vector<T>> output3(new std::vector<T>(std::get<2>(output)));

iEvent.put(std::move(output1), "FourJets");
iEvent.put(std::move(output2), "FiveJets");
iEvent.put(std::move(output3), "SixJets");
}
template <typename T>
void L1TJetsMatchingVBFPlus2CentralJets<T>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("L1JetTrigger", edm::InputTag("hltL1DiJetVBF"))->setComment("Name of trigger filter");
desc.add<edm::InputTag>("JetSrc", edm::InputTag("hltAK4PFJetsTightIDCorrected"))
->setComment("Input collection of PFJets");
desc.add<double>("pt1Min", 80.0)->setComment("Minimal pT1 of PFJets to match");
desc.add<double>("pt2Min", 30.0)->setComment("Minimal pT2 of PFJets to match");
desc.add<double>("pt3Min", 50.0)->setComment("Minimum pT3 of PFJets to match");
desc.add<double>("mjjMin", 500.0)->setComment("Minimal mjj of matched PFjets");
desc.add<double>("matchingR", 0.5)->setComment("dR value used for matching");
descriptions.setComment(
"This module produces collection of PFJets matched to L1 Jets passing a HLT filter (Only p4 and vertex "
"of returned PFJetss are set).");
descriptions.add(defaultModuleLabel<L1TJetsMatchingVBFPlus2CentralJets<T>>(), desc);
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "FWCore/Framework/interface/MakerMacros.h"

#include "DataFormats/JetReco/interface/PFJet.h"
#include "RecoTauTag/HLTProducers/interface/L1TJetsMatchingVBFPlus2CentralJets.h"

typedef L1TJetsMatchingVBFPlus2CentralJets<reco::PFJet> L1TPFJetsMatchingVBFPlus2CentralJets;
DEFINE_FWK_MODULE(L1TPFJetsMatchingVBFPlus2CentralJets);

0 comments on commit 8ae3b6d

Please sign in to comment.