Skip to content

Commit

Permalink
Merge pull request cms-sw#19 from pfs/ttbar_76x_dev
Browse files Browse the repository at this point in the history
TTbar specific updates for 76x
  • Loading branch information
imarches committed Jan 15, 2016
2 parents e584ac5 + bd76156 commit edc172d
Show file tree
Hide file tree
Showing 28 changed files with 1,727 additions and 1,030 deletions.
16 changes: 15 additions & 1 deletion interface/EventInfoBranches.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,13 @@ class EventInfoBranches {
float PatMuon_IP2Dsig[1000];

int ttbar_chan, ttbar_trigWord, ttbar_metfilterWord, ttbar_allmepartons, ttbar_matchmepartons;
int ttbar_ng,ttbar_gid[25];
int ttbar_nl, ttbar_lid[10], ttbar_lgid[10], ttbar_lch[10];
int ttbar_nw;
float ttbar_gpt[25],ttbar_geta[25],ttbar_gphi[25],ttbar_gm[25];
float ttbar_lpt[10], ttbar_leta[10], ttbar_lphi[10], ttbar_lm[10];
float ttbar_metpt,ttbar_metphi;
float ttbar_rho;
int ttbar_nw;
float ttbar_w[500];


Expand Down Expand Up @@ -326,6 +328,12 @@ class EventInfoBranches {
tree->Branch("ttbar_metfilterWord" , &ttbar_metfilterWord, "ttbar_metfilterWord/I");
tree->Branch("ttbar_allmepartons" , &ttbar_allmepartons, "ttbar_allmepartons/I");
tree->Branch("ttbar_matchmepartons" , &ttbar_matchmepartons, "ttbar_matchmepartons/I");
tree->Branch("ttbar_ng" , &ttbar_ng , "ttbar_ng/I");
tree->Branch("ttbar_gpt" , ttbar_gpt , "ttbar_gpt[ttbar_ng]/F");
tree->Branch("ttbar_geta" , ttbar_geta , "ttbar_geta[ttbar_ng]/F");
tree->Branch("ttbar_gphi" , ttbar_gphi , "ttbar_gphi[ttbar_ng]/F");
tree->Branch("ttbar_gm" , ttbar_gm , "ttbar_gm[ttbar_ng]/F");
tree->Branch("ttbar_gid" , ttbar_gid , "ttbar_gid[ttbar_ng]/I");
tree->Branch("ttbar_nl" , &ttbar_nl , "ttbar_nl/I");
tree->Branch("ttbar_lpt" , ttbar_lpt , "ttbar_lpt[ttbar_nl]/F");
tree->Branch("ttbar_leta" , ttbar_leta , "ttbar_leta[ttbar_nl]/F");
Expand Down Expand Up @@ -509,6 +517,12 @@ class EventInfoBranches {
void ReadTTbarTree(TTree *tree) {
tree->SetBranchAddress("ttbar_chan" , &ttbar_chan);
tree->SetBranchAddress("ttbar_trigWord" , &ttbar_trigWord);
tree->SetBranchAddress("ttbar_ng" , &ttbar_ng);
tree->SetBranchAddress("ttbar_gpt" , ttbar_gpt);
tree->SetBranchAddress("ttbar_geta" , ttbar_geta);
tree->SetBranchAddress("ttbar_gphi" , ttbar_gphi);
tree->SetBranchAddress("ttbar_gm" , ttbar_gm);
tree->SetBranchAddress("ttbar_gid" , ttbar_gid);
tree->SetBranchAddress("ttbar_nl" , &ttbar_nl);
tree->SetBranchAddress("ttbar_lpt" , ttbar_lpt);
tree->SetBranchAddress("ttbar_leta" , ttbar_leta);
Expand Down
12 changes: 11 additions & 1 deletion interface/TTbarSelectionProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@

#include "DataFormats/VertexReco/interface/Vertex.h"

#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h"
#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"

//--------------------PAT includes
#include "DataFormats/PatCandidates/interface/TriggerObjectStandAlone.h"
#include "DataFormats/PatCandidates/interface/Particle.h"
Expand Down Expand Up @@ -95,14 +99,20 @@ class TTbarSelectionProducer : public edm::EDProducer {
std::vector<int> trigChannels_;
std::vector<std::string> trigNamesToSel_;
bool doTrigSel_;

//gen particles
edm::EDGetTokenT<reco::GenParticleCollection> prunedGenParticleCollectionName_;
edm::EDGetTokenT<GenEventInfoProduct> generatorevt_;
edm::EDGetTokenT<LHEEventProduct> generatorlhe_;

//MET filters
std::vector<edm::EDGetTokenT<edm::TriggerResults> >metFilters_;
edm::EDGetTokenT<bool> RecoHBHENoiseFilter_;
std::vector<std::string> metFiltersToApply_;

//vertices
//vertices, beam spot
edm::EDGetTokenT<reco::VertexCollection> vtxToken_;
edm::EDGetTokenT<reco::BeamSpot> bsToken_;

//Configuration for electrons
edm::EDGetTokenT<edm::View<pat::Electron> > electronToken_;
Expand Down
22 changes: 21 additions & 1 deletion plugins/BTagAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ class BTagAnalyzerT : public edm::EDAnalyzer
bool storeCSVTagVariablesSubJets_;

bool use_ttbar_filter_;
edm::EDGetTokenT<edm::View<reco::GenParticle> > ttbarproducerGen_;
edm::EDGetTokenT<edm::View<pat::Electron>> ttbarproducerEle_;
edm::EDGetTokenT<edm::View<pat::Muon>> ttbarproducerMuon_;
edm::EDGetTokenT<edm::View<pat::MET>> ttbarproducerMET_;
Expand Down Expand Up @@ -503,7 +504,8 @@ BTagAnalyzerT<IPTI,VTX>::BTagAnalyzerT(const edm::ParameterSet& iConfig):
storeCSVTagVariables_ = iConfig.getParameter<bool>("storeCSVTagVariables");
storeCSVTagVariablesSubJets_ = iConfig.getParameter<bool>("storeCSVTagVariablesSubJets");

use_ttbar_filter_ = iConfig.getParameter<bool> ("use_ttbar_filter");
use_ttbar_filter_ = iConfig.getParameter<bool> ("use_ttbar_filter");
ttbarproducerGen_ = consumes<edm::View<reco::GenParticle>>(iConfig.getParameter<edm::InputTag>("ttbarproducer")),
ttbarproducerEle_ = consumes<edm::View<pat::Electron>>(iConfig.getParameter<edm::InputTag>("ttbarproducer"));
ttbarproducerMuon_ = consumes<edm::View<pat::Muon>>(iConfig.getParameter<edm::InputTag>("ttbarproducer"));
ttbarproducerMET_ = consumes<edm::View<pat::MET>>(iConfig.getParameter<edm::InputTag>("ttbarproducer"));
Expand Down Expand Up @@ -1276,12 +1278,30 @@ void BTagAnalyzerT<IPTI,VTX>::analyze(const edm::Event& iEvent, const edm::Event
// ttbar information
//------------------------------------------------------
if (use_ttbar_filter_) {

edm::Handle<int> pIn;
iEvent.getByToken(ttbartop, pIn);
EventInfo.ttbar_chan=*pIn;

edm::Handle<int> triggerIn;
iEvent.getByToken(ttbartoptrig,triggerIn);
EventInfo.ttbar_trigWord=*triggerIn;

int gctr(0);
edm::Handle<edm::View<reco::GenParticle> > selGen;
iEvent.getByToken(ttbarproducerGen_,selGen);
for (size_t i = 0; i < selGen->size(); ++i)
{
const auto g = selGen->ptrAt(i);
EventInfo.ttbar_gpt[gctr] = g->pt();
EventInfo.ttbar_geta[gctr] = g->eta();
EventInfo.ttbar_gphi[gctr] = g->phi();
EventInfo.ttbar_gm[gctr] = g->mass();
EventInfo.ttbar_gid[gctr] = g->pdgId();
gctr++;
}
EventInfo.ttbar_ng=gctr;

edm::Handle<int> metfilterIn;
iEvent.getByToken(metfilterIntoken,metfilterIn);
EventInfo.ttbar_metfilterWord=*metfilterIn;
Expand Down
10 changes: 4 additions & 6 deletions plugins/TTbarSelectionFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ class TTbarSelectionFilter : public edm::EDFilter {
~TTbarSelectionFilter();

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
edm::InputTag channel_;


edm::EDGetTokenT<int> ttbartop_;

private:
virtual void beginJob() ;
Expand Down Expand Up @@ -70,10 +68,10 @@ class TTbarSelectionFilter : public edm::EDFilter {
//
// constructors and destructor
//
TTbarSelectionFilter::TTbarSelectionFilter(const edm::ParameterSet& iConfig)
TTbarSelectionFilter::TTbarSelectionFilter(const edm::ParameterSet& iConfig):
ttbartop_(consumes<int>(edm::InputTag("ttbarselectionproducer:topChannel")))
{
//now do what ever initialization is needed
channel_ = iConfig.getParameter<edm::InputTag> ("channel");
selectChannels_ = iConfig.getParameter<std::vector<int> > ("selectChannels");
selectAll_ = iConfig.getParameter<bool > ("selectAll");
}
Expand All @@ -98,7 +96,7 @@ TTbarSelectionFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
{
using namespace edm;
Handle<int> pIn;
iEvent.getByLabel(edm::InputTag("ttbarselectionproducer:topChannel"), pIn);
iEvent.getByToken(ttbartop_, pIn);
std::vector<int>::iterator it = find (selectChannels_.begin(), selectChannels_.end(), *pIn);
return ( it!=selectChannels_.end() || selectAll_);
}
Expand Down
39 changes: 31 additions & 8 deletions plugins/TTbarSelectionProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h"
#include "RecoBTag/PerformanceMeasurements/interface/TTbarSelectionProducer.h"
#include "FWCore/Common/interface/TriggerNames.h"
#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h"
#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
#include "DataFormats/HepMCCandidate/interface/GenParticle.h"

using namespace std;
using namespace edm;
Expand All @@ -13,8 +12,12 @@ using namespace edm;

TTbarSelectionProducer::TTbarSelectionProducer(const edm::ParameterSet& iConfig) :
triggerBits_(consumes<edm::TriggerResults>(iConfig.getParameter<edm::InputTag>("triggerColl"))),
prunedGenParticleCollectionName_(consumes<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("prunedGenParticles"))),
generatorevt_(consumes<GenEventInfoProduct>(edm::InputTag("generator",""))),
generatorlhe_(consumes<LHEEventProduct>(edm::InputTag("externalLHEProducer",""))),
RecoHBHENoiseFilter_(consumes<bool>(iConfig.getParameter<edm::InputTag>("RecoHBHENoiseFilter"))),
vtxToken_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vtxColl"))),
bsToken_(consumes<reco::BeamSpot>(edm::InputTag("offlineBeamSpot",""))),
electronToken_(consumes<edm::View<pat::Electron> >(iConfig.getParameter<edm::InputTag>("electronColl"))),
conversionsToken_(mayConsume< reco::ConversionCollection >(iConfig.getParameter<edm::InputTag>("conversions"))),
electronIdMapToken_(consumes<edm::ValueMap<bool> >(iConfig.getParameter<edm::InputTag>("electronIdMap"))),
Expand Down Expand Up @@ -55,6 +58,7 @@ TTbarSelectionProducer::TTbarSelectionProducer(const edm::ParameterSet& iConfig)
produces<int>("topChannel");
produces<int>("topTrigger");
produces<int>("topMETFilter");
produces<std::vector<reco::GenParticle> >();
produces<std::vector<pat::Electron> >();
produces<std::vector<pat::Muon> >();
produces<std::vector<pat::Jet> >();
Expand Down Expand Up @@ -112,13 +116,13 @@ TTbarSelectionProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetu
if(!iEvent.isRealData())
{
edm::Handle<GenEventInfoProduct> evt;
iEvent.getByLabel("generator","", evt);
iEvent.getByToken(generatorevt_,evt);
float w0(1.0);
if(evt.isValid()) w0=evt->weight();
histos_["wgtcounter"]->Fill(0.,w0);

edm::Handle<LHEEventProduct> evet;
iEvent.getByLabel("externalLHEProducer","", evet);
iEvent.getByToken(generatorlhe_,evet);
if(evet.isValid())
{
float asdd=evet->originalXWGTUP();
Expand Down Expand Up @@ -208,9 +212,9 @@ TTbarSelectionProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetu
//get beam spot
//------------------------------------------
Handle<reco::BeamSpot> bsHandle;
iEvent.getByLabel("offlineBeamSpot", bsHandle);
iEvent.getByToken(bsToken_, bsHandle);
const reco::BeamSpot &beamspot = *bsHandle.product();

//------------------------------------------
//Selection of muons
//------------------------------------------
Expand Down Expand Up @@ -297,7 +301,7 @@ TTbarSelectionProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetu
if(dR < minDR) minDR=dR;
}
bool hasOverlap(minDR<0.4);
if(!hasOverlap) continue;
if(hasOverlap) continue;

selJets.push_back(j);
}
Expand Down Expand Up @@ -369,12 +373,31 @@ TTbarSelectionProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetu
}
else if(verbose_>5) std::cout << "\t Event is selected " << std::endl;


//select particles from the hard process for MC
std::vector<reco::GenParticle> selGen;
if(!iEvent.isRealData())
{
edm::Handle<reco::GenParticleCollection> gpHa;
iEvent.getByToken(prunedGenParticleCollectionName_,gpHa);
int genChannel(1);
for (const reco::GenParticle &g : *gpHa)
{
if(!g.isHardProcess()) continue;
if(abs(g.pdgId())==11 || abs(g.pdgId())==13) genChannel*=g.pdgId();
selGen.push_back(g);
}
if(verbose_>5) std::cout << "\t gen level channel is " << genChannel << std::endl;
}

std::auto_ptr<int> trigWordOut( new int(trigWord) );
iEvent.put(trigWordOut,"topTrigger");
std::auto_ptr<int> metfilterWordOut( new int(metfilterWord) );
iEvent.put(metfilterWordOut,"topMETFilter");
std::auto_ptr<int > chOut( new int (chsel) );
iEvent.put(chOut,"topChannel");
std::auto_ptr< vector<reco::GenParticle> > genColl( new vector<reco::GenParticle>(selGen) );
iEvent.put(genColl);
auto_ptr<vector<pat::Electron> > eleColl( new vector<pat::Electron>(selElectrons) );
iEvent.put( eleColl );
auto_ptr<vector<pat::Muon> > muColl( new vector<pat::Muon>(selMuons) );
Expand Down
1 change: 0 additions & 1 deletion python/TTbarSelectionFilter_cfi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import FWCore.ParameterSet.Config as cms

ttbarselectionfilter = cms.EDFilter('TTbarSelectionFilter',
channel = cms.InputTag("topChannel"),
selectChannels = cms.vint32(-11*11,-13*13,-11*13),
selectAll = cms.bool(False)
)
3 changes: 2 additions & 1 deletion python/TTbarSelectionProducer_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
ttbarselectionproducer = cms.EDProducer("TTbarSelectionProducer",
verbose = cms.int32(0),
triggerColl = cms.InputTag("TriggerResults","","HLT"),
prunedGenParticles = cms.InputTag('prunedGenParticles'),
metFilters = cms.VInputTag(cms.InputTag('TriggerResults','','RECO'),
cms.InputTag('TriggerResults','','PAT')),
RecoHBHENoiseFilter = cms.InputTag('hcalnoise','','RECO'),
Expand Down Expand Up @@ -32,6 +33,6 @@
jetColl = cms.InputTag("slimmedJets"),
jet_cut_pt = cms.double(20),
jet_cut_eta = cms.double(2.5),
metColl = cms.InputTag("slimmedMETsNoHF"),
metColl = cms.InputTag("slimmedMETs"),
met_cut = cms.double(0)
)
24 changes: 13 additions & 11 deletions test/runBTagAnalyzer_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,15 @@
)
if options.miniAOD:
process.source.fileNames = [
'/store/mc/RunIISpring15MiniAODv2/TTJets_DiLept_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/MINIAODSIM/74X_mcRun2_asymptotic_v2-v1/10000/FC156ADC-CA6D-E511-BC16-0022640691CC.root'
'/store/mc/RunIIFall15MiniAODv1/TT_TuneCUETP8M1_13TeV-amcatnlo-pythia8/MINIAODSIM/PU25nsData2015v1_76X_mcRun2_asymptotic_v12-v1/30000/02D2C327-8FA6-E511-9BD1-0CC47A4D7668.root'
#'/store/mc/RunIISpring15MiniAODv2/TTJets_DiLept_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/MINIAODSIM/74X_mcRun2_asymptotic_v2-v1/10000/FC156ADC-CA6D-E511-BC16-0022640691CC.root'
#'/store/mc/RunIISpring15MiniAODv2/ST_tW_antitop_5f_inclusiveDecays_13TeV-powheg-pythia8_TuneCUETP8M1/MINIAODSIM/74X_mcRun2_asymptotic_v2-v1//50000/E8B99B66-7D6F-E511-AD98-68B599B9B998.root'
]
if options.runOnData:
process.source.fileNames = [
'/store/data/Run2015D/DoubleMuon/MINIAOD/16Dec2015-v1/10000/DA6A1520-F1A7-E511-83BE-3417EBE64BE8.root'
#'/store/data/Run2015B/SingleMuon/MINIAOD/PromptReco-v1/000/251/168/00000/60FF8405-EA26-E511-A892-02163E01387D.root'
'/store/data/Run2015D/MuonEG/MINIAOD/PromptReco-v4/000/258/159/00000/64914E6C-F26B-E511-B0C8-02163E0142D1.root'
#'/store/data/Run2015D/MuonEG/MINIAOD/PromptReco-v4/000/258/159/00000/64914E6C-F26B-E511-B0C8-02163E0142D1.root'
]
if options.fastSim:
process.source.fileNames = [
Expand Down Expand Up @@ -754,14 +756,14 @@

#-------------------------------------
## Add GenParticlePruner for boosted b-tagging studies
process.prunedGenParticlesBoost = cms.EDProducer('GenParticlePruner',
src = cms.InputTag(genParticles),
select = cms.vstring(
"drop * ", #by default
"keep ( status = 3 || (status>=21 && status<=29) )", #keep hard process particles
"keep abs(pdgId) = 13 || abs(pdgId) = 15" #keep muons and taus
)
)
if not options.runOnData:
process.prunedGenParticlesBoost = cms.EDProducer('GenParticlePruner',
src = cms.InputTag(genParticles),
select = cms.vstring("drop * ", #by default
"keep ( status = 3 || (status>=21 && status<=29) )", #keep hard process particles
"keep abs(pdgId) = 13 || abs(pdgId) = 15" #keep muons and taus
)
)

#-------------------------------------

Expand Down Expand Up @@ -794,7 +796,7 @@
process.ttbarselectionproducer.electronColl = cms.InputTag('slimmedElectrons')
process.ttbarselectionproducer.muonColl = cms.InputTag('slimmedMuons')
process.ttbarselectionproducer.jetColl = cms.InputTag('selectedPatJets'+postfix)
process.ttbarselectionproducer.metColl = cms.InputTag('slimmedMETsNoHF')
process.ttbarselectionproducer.metColl = cms.InputTag('slimmedMETs')
switchOnVIDElectronIdProducer(process, DataFormat.MiniAOD)
else:
process.ttbarselectionproducer.electronColl = cms.InputTag('selectedPatElectrons'+postfix)
Expand Down
Loading

0 comments on commit edc172d

Please sign in to comment.