Skip to content

Commit

Permalink
Merge pull request cms-sw#145 from CMSAlphaT/CMG_MiniAOD_Lite_V6_0_fr…
Browse files Browse the repository at this point in the history
…om-CMSSW_7_0_6_20141116

Updates to the ttHAnalysis framework from the RA1 SUSY group (alphaT)
  • Loading branch information
gpetruc committed Nov 24, 2014
2 parents eb9c8a1 + 6b08aed commit ac8d36d
Show file tree
Hide file tree
Showing 12 changed files with 494 additions and 42 deletions.
2 changes: 1 addition & 1 deletion CMGTools/RootTools/python/statistics/Tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def shortType(self, type):
if ltype.startswith('int'): return 'I'
elif ltype.startswith('float'): return 'F'
elif ltype.startswith('double'): return 'D'
elif ltype.startswith('bool'): return 'O'
else: return None

def addVar(self, type, name):
Expand All @@ -29,7 +30,6 @@ def book(self):
for var,type in self.vars.iteritems():
structcode.append('{type} {var};'.format(type=type, var=var))
structcode.append('};')
print structcode
gROOT.ProcessLine( ' '.join(structcode) )
from ROOT import struct_name
self.s = struct_name()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
ttHMetAna = cfg.Analyzer(
'ttHMetEventAnalyzer',
doTkMet = False,
doMetNoMu = False,
candidates='packedPFCandidates',
candidatesTypes='std::vector<pat::PackedCandidate>',
dzMax = 0.1,
Expand Down
65 changes: 30 additions & 35 deletions CMGTools/TTHAnalysis/python/analyzers/treeProducerSusyAlphaT.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class treeProducerSusyAlphaT( treeProducerSusyCore ):

#-----------------------------------
# TREE PRODUCER FOR SUSY MULTILEPTONS
# TREE PRODUCER FOR SUSY ALPHAT
#-----------------------------------
def __init__(self, cfg_ana, cfg_comp, looperName):
super(treeProducerSusyAlphaT,self).__init__(cfg_ana, cfg_comp, looperName)
Expand All @@ -14,67 +14,52 @@ def __init__(self, cfg_ana, cfg_comp, looperName):

#NTupleVariable("crossSection", lambda ev : ev.crossSection, help="process cross section in pb"),

#Gen level
NTupleVariable("genBin", lambda ev : ev.genBin, help="Generator level binning quantity"),
NTupleVariable("genQScale", lambda ev : ev.genQScale, help="Generator level binning quantity, QScale"),

# Energy sums
#----------------------------------------

NTupleVariable("ht", lambda ev : ev.htJet40j, help="H_{T} computed from only jets (with |eta|<2.5, pt > 40 GeV)"),
NTupleVariable("ht", lambda ev : ev.htJet50j, help="H_{T} computed from only jets (with |eta|<3, pt > 50 GeV)"),
NTupleVariable("deltaPhiMin", lambda ev : ev.deltaPhiMin_had, help="minimal deltaPhi between the MET and the four leading jets with pt>40 and eta<2.4"),
NTupleVariable("diffMetMht", lambda ev : ev.diffMetMht_had, help="abs( vec(mht) - vec(met) )"),
NTupleVariable("mht_pt", lambda ev : ev.mhtJet40j, help="H_{T}^{miss} computed from only jets (with |eta|<2.5, pt > 40 GeV)"),
NTupleVariable("mht_phi", lambda ev : ev.mhtPhiJet40j, help="H_{T}^{miss} #phi computed from onlyy jets (with |eta|<2.5, pt > 40 GeV)"),
NTupleVariable("mht_pt", lambda ev : ev.mhtJet50j, help="H_{T}^{miss} computed from only jets (with |eta|<3.0, pt > 50 GeV)"),
NTupleVariable("mht_phi", lambda ev : ev.mhtPhiJet50j, help="H_{T}^{miss} #phi computed from onlyy jets (with |eta|<3.0, pt > 50 GeV)"),
##--------------------------------------------------
NTupleVariable("biasedDPhi", lambda ev : ev.biasedDPhi, help="biased delta phi"),

# Physics object multplicities
#----------------------------------------
NTupleVariable("nMuons10", lambda ev: sum([l.pt() > 10 and abs(l.pdgId()) == 13 for l in ev.selectedLeptons]), int, help="Number of muons with pt > 10"),
NTupleVariable("nElectrons10", lambda ev: sum([l.pt() > 10 and abs(l.pdgId()) == 11 for l in ev.selectedLeptons]), int, help="Number of electrons with pt > 10"),
NTupleVariable("nMuons10", lambda ev: sum([l.pt() > 10 and abs(l.pdgId()) == 13 for l in ev.selectedLeptons]), int, help="Number of muons with at least pt > 10"),
NTupleVariable("nElectrons10", lambda ev: sum([l.pt() > 10 and abs(l.pdgId()) == 11 for l in ev.selectedLeptons]), int, help="Number of electrons with at least pt > 10"),
NTupleVariable("nTaus20", lambda ev: sum([l.pt() > 20 for l in ev.selectedTaus]), int, help="Number of taus with pt > 20"),
NTupleVariable("nGammas20", lambda ev: sum([l.pt() > 20 for l in ev.selectedPhotons]), int, help="Number of photons with pt > 20"),
NTupleVariable("nBJet40", lambda ev: sum([j.btagWP("CSVM") for j in ev.cleanJets if j.pt() > 40]), int, help="Number of jets with pt > 40 passing CSV medium"),
NTupleVariable("nGammas25", lambda ev: sum([l.pt() > 25 for l in ev.selectedPhotons]), int, help="Number of photons with at least pt > 25"),
NTupleVariable("nBJet50", lambda ev: sum([j.btagWP("CSVM") for j in ev.cleanJets if j.pt() > 50]), int, help="Number of jets with pt > 50 passing CSV medium"),

# AlphaT variables
#----------------------------------------

# NEED TO ADD:
# - M_{T}
# - metcorrected for photon, muon
# - mht/metcorrected

# NTupleVariable("nJet50", lambda ev: len(ev.cleanJets), int, help="Number of jets with pt > 50, |eta|<3"),
# NTupleVariable("nJetFwd50", lambda ev: len(ev.cleanJetsFwd), int, help="Number of jets with pt > 50, 3<|eta|<5"),
# NTupleVariable("nBJetMedium50", lambda ev: len(ev.bjetsMedium), int, help="Number of jets with pt > 50, |eta|<3 passing CSV medium"),
# NTupleVariable("htJet50", lambda ev: ev.htJet50, help="H_{T} computed from jets (with |eta|<3, pt > 50 GeV)"),
# NTupleVariable("mhtJet50", lambda ev: ev.mhtJet50, help="H_{T}^{miss} computed from jets (with |eta|<3, pt > 50 GeV)"),
# NTupleVariable("mht50OverMet", lambda ev: ev.mht50OverMet,help="H_{T}^{miss}/E_{T}^{miss} computed from jets (with |eta|<3, pt > 50 GeV)"),


NTupleVariable("alphaT", lambda ev: ev.alphaT, help="AlphaT computed using jets with pt > 50, |eta|<3"),

# # NTupleVariable("mT", lambda ev: ev.mT, help="M_{T} computed from lepton and type-1 corrected PFMET"),

# NTupleVariable("mZ1", lambda ev: ev.bestZ1[0], help="Best m(ll) SF/OS"),
# NTupleVariable("pt2l", lambda ev: ev.pt2l, help="p_{T}(ll)"),
# NTupleVariable("m2l", lambda ev: ev.m2l, help="m(ll)"),

# control sample variables
##--------------------------------------------------
# NTupleVariable("mtw", lambda ev: ev.mtw, int, help="mt(l,met)"),
# NTupleVariable("mtwTau", lambda ev: ev.mtwTau, int, help="mt(tau,met)"),
# NTupleVariable("IsoTrack_mtw", lambda ev: ev.mtwIsoTrack, int, help="mt(isoTrack,met)"),
##--------------------------------------------------
# NTupleVariable("minMWjj", lambda ev: ev.minMWjj, int, help="minMWjj"),
# NTupleVariable("minMWjjPt", lambda ev: ev.minMWjjPt, int, help="minMWjjPt"),
# NTupleVariable("bestMWjj", lambda ev: ev.bestMWjj, int, help="bestMWjj"),
# NTupleVariable("bestMWjjPt", lambda ev: ev.bestMWjjPt, int, help="bestMWjjPt"),
# NTupleVariable("bestMTopHad", lambda ev: ev.bestMTopHad, int, help="bestMTopHad"),
# NTupleVariable("bestMTopHadPt", lambda ev: ev.bestMTopHadPt, int, help="bestMTopHadPt"),
NTupleVariable("mtw", lambda ev: ev.mtw, help="mt(l,met)"),
NTupleVariable("mtwTau", lambda ev: ev.mtwTau, help="mt(tau,met)"),
NTupleVariable("IsoTrack_mtw", lambda ev: ev.mtwIsoTrack, help="mt(isoTrack,met)"),
NTupleVariable("mll", lambda ev: ev.mll, help="Invariant mass of the two lead leptons"),

##--------------------------------------------------
]

self.globalObjects.update({
# put more here
# "pseudoJet1" : NTupleObject("pseudoJet1", fourVectorType, help="pseudoJet1 for hemishphere"),
# "pseudoJet2" : NTupleObject("pseudoJet2", fourVectorType, help="pseudoJet2 for hemishphere"),
"biasedDPhiJet" : NTupleObject("biasedDPhiJet", fourVectorType, help="jet closest to missing energy vector"),
"metNoMu": NTupleObject("metNoMu",fourVectorType, help="met computed with muom momentum substracted"),
})
self.collections.update({
# put more here
Expand All @@ -83,7 +68,17 @@ def __init__(self, cfg_ana, cfg_comp, looperName):
"cleanJetsAll" : NTupleCollection("jet", jetTypeSusy, 100, help="all jets (w/ x-cleaning, w/ ID applied w/o PUID applied pt > 50 |eta| < 3) , sorted by pt", filter=lambda l : l.pt()>50 ),
"selectedPhotons" : NTupleCollection("gamma", photonTypeSusy, 50, help="photons with pt > 25 and loose cut based ID"),
"selectedIsoTrack" : NTupleCollection("isoTrack", isoTrackType, 50, help="isoTrack, sorted by pt"),

#Gen collections
"genParticles" : NTupleCollection("genPart", genParticleWithMotherId, 200, help="all pruned genparticles"),
"genJets" : NTupleCollection("genJet", genParticleType, 10, help="Generated jets (not cleaned)"),

# add stuff for testing
"selectedMuons" : NTupleCollection("muon", leptonTypeSusy, 50, help="Muons for testing"),

# dR jet lep for each lepton
# not putting in for now, maybe in future
#"minDeltaRLepJet" : NTupleCollection("minDeltaRLepJet", double, 50, help="Min deltaR between a lepton and all the jets"),
})

## Book the variables, but only if we're called explicitly and not through a base class
Expand Down
123 changes: 123 additions & 0 deletions CMGTools/TTHAnalysis/python/analyzers/ttHAlphaTControlAnalyzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import operator
import itertools
import copy
from math import *

#from ROOT import TLorentzVector, TVectorD

from CMGTools.RootTools.fwlite.Analyzer import Analyzer
from CMGTools.RootTools.fwlite.Event import Event
from CMGTools.RootTools.statistics.Counter import Counter, Counters
from CMGTools.RootTools.fwlite.AutoHandle import AutoHandle
# from CMGTools.RootTools.physicsobjects.Lepton import Lepton
# from CMGTools.RootTools.physicsobjects.Photon import Photon
# from CMGTools.RootTools.physicsobjects.Electron import Electron
# from CMGTools.RootTools.physicsobjects.Muon import Muon
# from CMGTools.RootTools.physicsobjects.Tau import Tau
from CMGTools.RootTools.physicsobjects.Jet import Jet

from CMGTools.RootTools.utils.DeltaR import deltaR

import os

# Function to calculate the transverse mass
def mtw(x1,x2):
return sqrt(2*x1.pt()*x2.pt()*(1-cos(x1.phi()-x2.phi())))

class ttHAlphaTControlAnalyzer( Analyzer ):
def __init__(self, cfg_ana, cfg_comp, looperName ):
super(ttHAlphaTControlAnalyzer,self).__init__(cfg_ana,cfg_comp,looperName)

def declareHandles(self):
super(ttHAlphaTControlAnalyzer, self).declareHandles()
#genJets
self.handles['genJets'] = AutoHandle( 'slimmedGenJets','std::vector<reco::GenJet>')

def beginLoop(self):
super(ttHAlphaTControlAnalyzer,self).beginLoop()
self.counters.addCounter('pairs')
count = self.counters.counter('pairs')
count.register('all events')


# Calculate MT_W (stolen from the MT2 code)
# Modularize this later?
def makeMT(self, event):
# print '==> INSIDE THE PRINT MT'
# print 'MET=',event.met.pt()

if len(event.selectedLeptons)>0:
for lepton in event.selectedLeptons:
event.mtw = mtw(lepton, event.met)

if len(event.selectedTaus)>0:
for myTau in event.selectedTaus:
event.mtwTau = mtw(myTau, event.met)
foundTau = True

if len(event.selectedIsoTrack)>0:
for myTrack in event.selectedIsoTrack:
event.mtwIsoTrack = mtw(myTrack, event.met)

return

# Calculate the invariant mass from two lead leptons
def makeMll(self, event):

if len(event.selectedLeptons)>=2:
event.mll = (event.selectedLeptons[0].p4()+event.selectedLeptons[1].p4()).M()

return

# Calculate the DeltaR between the lepton and the closest jet
def makeDeltaRLepJet(self, event):

event.minDeltaRLepJet = []

for lepton in event.selectedLeptons:

minDeltaR = 999

for jet in event.cleanJets:
minDeltaR=min(deltaR(lepton.eta(),lepton.phi(),jet.eta(),jet.phi()), minDeltaR)

# Fill event with the min deltaR for each lepton
event.minDeltaRLepJet.append(minDeltaR)

return

# Calculate the DeltaR between the photon and the closest jet
def makeDeltaRPhoJet(self, event):

event.minDeltaRPhoJet = []

for photon in event.selectedPhotons:

minDeltaR = 999

for jet in event.cleanJets:
minDeltaR=min(deltaR(photon.eta(),photon.phi(),jet.eta(),jet.phi()), minDeltaR)

# Fill event with the min deltaR for each photon
event.minDeltaRPhoJet.append(minDeltaR)

return

def process(self, iEvent, event):
self.readCollections( iEvent )

#W variables
event.mtw = -999
event.mtwTau = -999
event.mtwIsoTrack = -999
self.makeMT(event)

#Z variables
event.mll = -999
self.makeMll(event)

#Delta R variables
self.makeDeltaRLepJet(event)
self.makeDeltaRPhoJet(event)

return True
54 changes: 54 additions & 0 deletions CMGTools/TTHAnalysis/python/analyzers/ttHAlphaTControlSkimmer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

from CMGTools.RootTools.fwlite.Analyzer import Analyzer
from CMGTools.RootTools.fwlite.Event import Event
from CMGTools.RootTools.statistics.Counter import Counter, Counters
from CMGTools.RootTools.fwlite.AutoHandle import AutoHandle

class ttHAlphaTControlSkimmer( Analyzer ):
def __init__(self, cfg_ana, cfg_comp, looperName ):
super(ttHAlphaTControlSkimmer,self).__init__(cfg_ana,cfg_comp,looperName)

def declareHandles(self):
super(ttHAlphaTControlSkimmer, self).declareHandles()

def beginLoop(self):
super(ttHAlphaTControlSkimmer,self).beginLoop()
self.counters.addCounter('events')
count = self.counters.counter('events')
count.register('all events')
count.register('pass mtw cuts')
count.register('pass mll cuts')
count.register('pass lepton deltaR cuts')
count.register('pass photon deltaR cuts')
count.register('accepted events')


def process(self, iEvent, event):
self.readCollections( iEvent )
self.counters.counter('events').inc('all events')

#Perform W mass MTW cut
if event.mtw < self.cfg_ana.mtwCut[0] or event.mtw > self.cfg_ana.mtwCut[1]:
return False
self.counters.counter('events').inc('pass mtw cuts')

#Perform Z mass MLL cut
if event.mll < self.cfg_ana.mllCut[0] or event.mll > self.cfg_ana.mllCut[1]:
return False
self.counters.counter('events').inc('pass mll cuts')

#Perform deltaR cuts
for dR in event.minDeltaRLepJet:
if dR < self.cfg_ana.lepDeltaRCut:
return False
self.counters.counter('events').inc('pass lepton deltaR cuts')

for dR in event.minDeltaRPhoJet:
if dR < self.cfg_ana.photonDeltaRCut:
return False
self.counters.counter('events').inc('pass photon deltaR cuts')

#If everything passed return true
self.counters.counter('events').inc('accepted events')
return True

58 changes: 58 additions & 0 deletions CMGTools/TTHAnalysis/python/analyzers/ttHAlphaTSkimmer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

from CMGTools.RootTools.fwlite.Analyzer import Analyzer
from CMGTools.RootTools.fwlite.Event import Event
from CMGTools.RootTools.statistics.Counter import Counter, Counters
from CMGTools.RootTools.fwlite.AutoHandle import AutoHandle

class ttHAlphaTSkimmer( Analyzer ):
def __init__(self, cfg_ana, cfg_comp, looperName ):
super(ttHAlphaTSkimmer,self).__init__(cfg_ana,cfg_comp,looperName)

def declareHandles(self):
super(ttHAlphaTSkimmer, self).declareHandles()

def beginLoop(self):
super(ttHAlphaTSkimmer,self).beginLoop()
self.counters.addCounter('events')
count = self.counters.counter('events')
count.register('all events')
count.register('pass forwardJetVeto')
count.register('pass MHT/MET cut')
count.register('pass alphaTCuts')
count.register('accepted events')


def process(self, iEvent, event):
self.readCollections( iEvent )
self.counters.counter('events').inc('all events')

#Veto forward jets that have passed the jet requirement
if self.cfg_ana.forwardJetVeto and len(event.cleanJetsFwd) > 0:
return False
self.counters.counter('events').inc('pass forwardJetVeto')

#Veto events that don't pass the MHT/MET cut
if getattr(event, self.cfg_ana.mhtDivMetCut[0])/getattr(event, self.cfg_ana.mhtDivMetCut[1]).pt() > self.cfg_ana.mhtDivMetCut[2]:
return False
self.counters.counter('events').inc('pass MHT/MET cut')

#Check if the event passes the alphaT cut

if self.cfg_ana.invertAlphaT: #This is for the multijet enriched control region

for aTCut in self.cfg_ana.alphaTCuts:
if event.alphaT < aTCut[0] and event.htJet50j >= aTCut[1] and event.htJet50j < aTCut[2]:
self.counters.counter('events').inc('pass alphaTCuts')
self.counters.counter('events').inc('accepted events')
return True

else:

for aTCut in self.cfg_ana.alphaTCuts:
if event.alphaT > aTCut[0] and event.htJet50j >= aTCut[1] and event.htJet50j < aTCut[2]:
self.counters.counter('events').inc('pass alphaTCuts')
self.counters.counter('events').inc('accepted events')
return True

#If none of the alphaT cuts are passed, veto the event
return False
Loading

0 comments on commit ac8d36d

Please sign in to comment.