Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AJJGenJet filter added. #35547

Merged
merged 7 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions GeneratorInterface/GenFilters/plugins/AJJGenJetFilter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#include "GeneratorInterface/GenFilters/plugins/AJJGenJetFilter.h"

#include "DataFormats/Math/interface/deltaPhi.h"
#include "DataFormats/Math/interface/deltaR.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CommonTools/UtilAlgos/interface/TFileService.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include <HepMC/GenVertex.h>

// ROOT includes
#include "TMath.h"
#include "TH1.h"
#include "TH2.h"

// C++ includes
#include <iostream>
#include <vector>

using namespace edm;
using namespace std;

AJJGenJetFilter::AJJGenJetFilter(const edm::ParameterSet& iConfig)
: ptMin(iConfig.getUntrackedParameter<double>("minPt", 0)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need to add default values here since you already specify them in the fillDescriptions function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, shouldn’t these all be tracked parameters as you want to record what cuts were being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your comments, I have tried to address both of them

etaMin(iConfig.getUntrackedParameter<double>("minEta", -4.5)),
etaMax(iConfig.getUntrackedParameter<double>("maxEta", 4.5)),
minDeltaEta(iConfig.getUntrackedParameter<double>("minDeltaEta", 0.0)),
maxDeltaEta(iConfig.getUntrackedParameter<double>("maxDeltaEta", 99999.0)),
deltaRJetLep(iConfig.getUntrackedParameter<double>("deltaRJetLep", 0.0)),
maxPhotonEta(iConfig.getUntrackedParameter<double>("maxPhotonEta", 5)),
minPhotonPt(iConfig.getUntrackedParameter<double>("minPhotonPt", 50)),
maxPhotonPt(iConfig.getUntrackedParameter<double>("maxPhotonPt", 10000)),
mininvmass(iConfig.getUntrackedParameter<double>("MinInvMass", 0.0)) {
m_GenJetCollection = consumes<reco::GenJetCollection>(iConfig.getParameter<edm::InputTag>("GenJetCollection"));
m_GenParticleCollection = consumes<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("genParticles"));

edm::LogInfo("AJJGenJetFilter") << "Parameters:"
<< "jPtMin:" << ptMin << ",jEta:" << etaMin << "--" << etaMax << ",minDR(j,lep)"
<< deltaRJetLep << ",deltaEta(j1,j2)" << minDeltaEta << "--" << maxDeltaEta
<< "m(j1,j2) < " << mininvmass << "PhotonPt" << minPhotonPt << "--" << maxPhotonPt
<< "PhotonEta" << maxPhotonEta;
}

AJJGenJetFilter::~AJJGenJetFilter() {}

vector<const reco::GenParticle*> AJJGenJetFilter::filterGenLeptons(const vector<reco::GenParticle>* particles) {
vector<const reco::GenParticle*> out;

for (const auto& p : *particles) {
int absPdgId = std::abs(p.pdgId());

if (((absPdgId == 11) || (absPdgId == 13) || (absPdgId == 15)) && p.isHardProcess()) {
out.push_back(&p);
}
}
return out;
}

vector<const reco::GenParticle*> AJJGenJetFilter::filterGenPhotons(const vector<reco::GenParticle>* particles) {
vector<const reco::GenParticle*> out;

for (const auto& p : *particles) {
int absPdgId = std::abs(p.pdgId());

if ((absPdgId == 22) && p.isHardProcess()) {
if (abs(p.eta()) < maxPhotonEta && p.pt() > minPhotonPt && p.pt() <= maxPhotonPt) {
hbakhshi marked this conversation as resolved.
Show resolved Hide resolved
out.push_back(&p);
} else {
edm::LogInfo("AJJPhoton") << "photon rejected, pt:" << p.pt() << " , eta:" << p.eta();
}
}
}

return out;
}

vector<const reco::GenJet*> AJJGenJetFilter::filterGenJets(const vector<reco::GenJet>* jets) {
vector<const reco::GenJet*> out;

for (unsigned i = 0; i < jets->size(); i++) {
hbakhshi marked this conversation as resolved.
Show resolved Hide resolved
const reco::GenJet* j = &((*jets)[i]);

if (j->p4().pt() > ptMin && j->p4().eta() > etaMin && j->p4().eta() < etaMax) {
out.push_back(j);
} else {
edm::LogInfo("AJJJets") << "Jet rejected, pt:" << j->p4().pt() << " eta:" << j->p4().eta();
}
}

return out;
}

// ------------ method called to skim the data ------------
bool AJJGenJetFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
using namespace edm;

Handle<vector<reco::GenJet> > handleGenJets;
iEvent.getByToken(m_GenJetCollection, handleGenJets);
const vector<reco::GenJet>* genJets = handleGenJets.product();
// Getting filtered generator jets
vector<const reco::GenJet*> filGenJets = filterGenJets(genJets);

Handle<reco::GenParticleCollection> genParticelesCollection;
iEvent.getByToken(m_GenParticleCollection, genParticelesCollection);
hbakhshi marked this conversation as resolved.
Show resolved Hide resolved
const vector<reco::GenParticle>* genParticles = genParticelesCollection.product();
vector<const reco::GenParticle*> filGenLep = filterGenLeptons(genParticles);

// Getting p4 of jet with no lepton
vector<math::XYZTLorentzVector> genJetsWithoutLeptonsP4;
unsigned int jetIdx = 0;
unsigned int nGoodJets = 0;
while (jetIdx < filGenJets.size()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this just a for loop?
for(unsigned int jetIdx = 0; jetIdx < filGenJets.size(); ++jetIdx) {

for loops are a safer construct than while because of the code is later changed, it is possible the while loop will never end.

bool jetWhitoutLep = true;

const math::XYZTLorentzVector& p4J = (filGenJets[jetIdx])->p4();
for (unsigned int i = 0; i < filGenLep.size() && jetWhitoutLep; ++i) {
if (reco::deltaR2((filGenLep[i])->p4(), p4J) < deltaRJetLep * deltaRJetLep)
jetWhitoutLep = false;
}
if (jetWhitoutLep) {
if (genJetsWithoutLeptonsP4.size() < 2) {
genJetsWithoutLeptonsP4.push_back(p4J);
}
nGoodJets++;
};
++jetIdx;
}

vector<const reco::GenParticle*> filGenPhotons = filterGenPhotons(genParticles);

if (filGenPhotons.size() != 1) {
edm::LogInfo("AJJPhoton") << "Events rejected, number of photons:" << filGenPhotons.size();
return false;
}

if (ptMin < 0)
return true;

//If we do not find at least 2 jets veto the event
if (nGoodJets < 2) {
edm::LogInfo("AJJJets") << "Events rejected, number of jets:" << nGoodJets;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be better to make this a LogDebug statement.

return false;
}

double dEta = fabs(genJetsWithoutLeptonsP4[0].eta() - genJetsWithoutLeptonsP4[1].eta());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use std::abs for consistency.

float invMassLeadingJet = (genJetsWithoutLeptonsP4[0] + genJetsWithoutLeptonsP4[1]).M();

if (dEta >= minDeltaEta && dEta <= maxDeltaEta && invMassLeadingJet > mininvmass) {
return true;
}

edm::LogInfo("AJJJets") << "Events rejected, dEta:" << dEta << ", mjj:" << invMassLeadingJet;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better as LogDebug

return false;
}
//define this as a plug-in
DEFINE_FWK_MODULE(AJJGenJetFilter);
68 changes: 68 additions & 0 deletions GeneratorInterface/GenFilters/plugins/AJJGenJetFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#ifndef AJJGenJetAnalyzer_h
#define AJJGenJetAnalyzer_h

// CMSSW include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDFilter.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/Service.h"

#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"

#include "DataFormats/JetReco/interface/GenJetCollection.h"
#include "DataFormats/HepMCCandidate/interface/GenParticle.h"
#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"

// ROOT includes
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"

// C++ include files
#include <memory>
#include <map>
#include <vector>

using namespace edm;
using namespace std;
//
// class declaration
//

class AJJGenJetFilter : public edm::EDFilter {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a thread friendly base class.

public:
explicit AJJGenJetFilter(const edm::ParameterSet& pset);
~AJJGenJetFilter() override;

//void analyze(edm::Event&, const edm::EventSetup&)
bool filter(edm::Event&, const edm::EventSetup&) override;

private:
// ----------memeber function----------------------
std::vector<const reco::GenJet*> filterGenJets(const vector<reco::GenJet>* jets);
std::vector<const reco::GenParticle*> filterGenLeptons(const std::vector<reco::GenParticle>* particles);
std::vector<const reco::GenParticle*> filterGenPhotons(const std::vector<reco::GenParticle>* particles);

//**************************
// Private Member data *****
private:
// Dijet cut
double ptMin;
double etaMin;
double etaMax;
double minDeltaEta;
double maxDeltaEta;
double deltaRJetLep;
double maxPhotonEta;
double minPhotonPt;
double maxPhotonPt;
double mininvmass;

// Input tags
edm::EDGetTokenT<reco::GenJetCollection> m_GenJetCollection;
edm::EDGetTokenT<reco::GenParticleCollection> m_GenParticleCollection;
};

#endif
12 changes: 12 additions & 0 deletions GeneratorInterface/GenFilters/python/AJJGenJetFilter_cff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import FWCore.ParameterSet.Config as cms

from GeneratorInterface.GenFilters.VJJGenJetFilter_cfi import *
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is AJJGenJetFilter_cff then why is it loading VJJGenJetFilter_cfi?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the comments, I tried to address them in the new commit. I would appreciate if you could have a look @Dr15Jones

from RecoJets.Configuration.GenJetParticles_cff import *
from RecoJets.Configuration.RecoGenJets_cff import *

vjjGenJetFilterSeq = cms.Sequence(
genParticlesForJetsNoNu*
ak4GenJetsNoNu*
vjjGenJetFilterPhotonInBarrelMjj300
)

44 changes: 44 additions & 0 deletions GeneratorInterface/GenFilters/python/AJJGenJetFilter_cfi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import FWCore.ParameterSet.Config as cms

ajjGenJetFilterPhotonInBarrelMjj300 = cms.EDFilter("AJJGenJetFilter",
GenJetCollection = cms.InputTag('ak4GenJetsNoNu'),
genParticles = cms.InputTag("genParticles"),

#following cuts are applied to select jets
minPt = cms.untracked.double( 40 ),
minEta = cms.untracked.double( -4.5 ),
maxEta = cms.untracked.double( 4.5 ),
deltaRJetLep = cms.untracked.double( 0.3 ),

#following cuts are applied on the first two leading jets
minDeltaEta = cms.untracked.double( 3.0 ),
maxDeltaEta = cms.untracked.double( 999.0 ),
MinInvMass = cms.untracked.double( 300 ),

#the cut on the photon eta
maxPhotonEta = cms.untracked.double( 1.48 ),
minPhotonPt = cms.untracked.double( 50 ),
maxPhotonPt = cms.untracked.double( 10000 )
)

ajjGenJetFilterPhoton = cms.EDFilter("AJJGenJetFilter",
GenJetCollection = cms.InputTag('ak4GenJetsNoNu'),
genParticles = cms.InputTag("genParticles"),

#following cuts are applied to select jets
#if minPt is negative, no criteri on jets (including njets and delta_eta and invmasss) is applied
minPt = cms.untracked.double( -1 ),
minEta = cms.untracked.double( -4.5 ),
maxEta = cms.untracked.double( 4.5 ),
deltaRJetLep = cms.untracked.double( 0.3 ),

#following cuts are applied on the first two leading jets
minDeltaEta = cms.untracked.double( 3.0 ),
maxDeltaEta = cms.untracked.double( 999.0 ),
MinInvMass = cms.untracked.double( 300 ),

#the cut on the photon eta
maxPhotonEta = cms.untracked.double( 1.48 ),
minPhotonPt = cms.untracked.double( 50 ),
maxPhotonPt = cms.untracked.double( 10000 )
)