Skip to content

Commit

Permalink
Merge pull request cms-sw#85 from CERN-PH-CMG/80X
Browse files Browse the repository at this point in the history
Update from 80X upstream
  • Loading branch information
peruzzim authored Feb 15, 2017
2 parents 9923052 + d7d5134 commit b65d365
Show file tree
Hide file tree
Showing 369 changed files with 193,488 additions and 14,968 deletions.
57 changes: 57 additions & 0 deletions H2TauTau/cfgPython/generic/tauHLT_2016.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import PhysicsTools.HeppyCore.framework.config as cfg
from PhysicsTools.HeppyCore.framework.config import printComps
from PhysicsTools.HeppyCore.framework.heppy_loop import getHeppyOption
from PhysicsTools.HeppyCore.framework.eventsfwlite import Events

from CMGTools.RootTools.samples.ComponentCreator import ComponentCreator

from CMGTools.H2TauTau.proto.analyzers.TauHLTAnalyzer import TauHLTAnalyzer
from CMGTools.H2TauTau.proto.analyzers.HLTTauTreeProducer import HLTTauTreeProducer

production = getHeppyOption('production', True)

c = ComponentCreator()
# ggH135_0 = c.makeMCComponentFromEOS('ggH135_rawaod', 'ggH135_rawaod', '/store/group/phys_higgs/cmshtt/steggema/HPSatHLTv5/GluGluHToTauTau_M125_13TeV_powheg_pythia8/TauHPSatHLTFine/161117_103941/0000/')
# ggH135_1 = c.makeMCComponentFromEOS('ggH135_rawaod', 'ggH135_rawaod', '/store/group/phys_higgs/cmshtt/steggema/HPSatHLTv5/GluGluHToTauTau_M125_13TeV_powheg_pythia8/TauHPSatHLTFine/161117_103941/0001/')


ggH135_0 = c.makeMCComponentFromEOS('ggH135_rawaod', 'ggH135_rawaod', '/store/group/phys_tau/HLT2016/HPSatHLT/GluGluHToTauTau_M125_13TeV_powheg_pythia8/HPSatHLT/161206_134434/0000/')
ggH135_1 = c.makeMCComponentFromEOS('ggH135_rawaod_2', 'ggH135_rawaod', '/store/group/phys_tau/HLT2016/HPSatHLT/GluGluHToTauTau_M125_13TeV_powheg_pythia8/HPSatHLT/161206_134434/0001/')


selectedComponents = [ggH135_0, ggH135_1]


tauHLTAna = cfg.Analyzer(
TauHLTAnalyzer,
name='TauHLTAnalyzer',
)

tauHLTTree = cfg.Analyzer(
HLTTauTreeProducer,
name='HLTTauTreeProducer'
)

sequence = cfg.Sequence([
tauHLTAna,
tauHLTTree
])


if not production:
selectedComponents = selectedComponents[:1]
for comp in selectedComponents:
comp.splitFactor = 1
comp.fineSplitFactor = 1
# comp.files = comp.files[:1]
else:
for comp in selectedComponents:
comp.splitFactor = 200

config = cfg.Config(components=selectedComponents,
sequence=sequence,
services=[],
events_class=Events
)

printComps(config.components, True)
Binary file added H2TauTau/data/MvaMET_2016BCD.root
Binary file not shown.
Binary file added H2TauTau/data/TypeIPFMET_2016BCD.root
Binary file not shown.
2 changes: 1 addition & 1 deletion H2TauTau/python/h2TauTauMiniAOD_generic_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def createProcess(runOnMC=True, channel='tau-mu', runSVFit=False,
if numberOfFilesToProcess > 0:
process.source.fileNames = process.source.fileNames[:numberOfFilesToProcess]

print 'Run on MC?', runOnMC, process.source.fileNames[0]
print 'Run on MC?', runOnMC #, process.source.fileNames[0]

# if not runOnMC:
# from CMGTools.H2TauTau.proto.samples.spring16.htt_common import json
Expand Down
1 change: 1 addition & 0 deletions H2TauTau/python/htt_ntuple_base_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

lheWeightAna = cfg.Analyzer(
LHEWeightAnalyzer, name="LHEWeightAnalyzer",
useLumiInfo=False
)

jsonAna = cfg.Analyzer(
Expand Down
36 changes: 15 additions & 21 deletions H2TauTau/python/proto/analyzers/H2TauTauTreeProducerBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,19 @@ def __init__(self, *args):
def var(self, tree, varName, type=float):
tree.var(self.varName(varName), type)

def vars(self, tree, varNames, type=float):
for varName in varNames:
self.var(tree, varName, type)

def fill(self, tree, varName, value):
tree.fill(self.varName(varName), value)

def fillVars(self, tree, varNames, obj):
'''Fills vars that are attributes of the passed object.
Fills -999. if object doesn't have attribute'''
for varName in varNames:
tree.fill(self.varName(varName), getattr(obj, varName, -999.))

def varName(self, name):
try:
return self.varDict[name][self.varStyle]
Expand Down Expand Up @@ -219,29 +229,13 @@ def fillExtraMetInfo(self, tree, event):

# TauSpinner information
def bookTauSpinner(self, tree):
self.var(tree, 'TauSpinnerWTisValid')
self.var(tree, 'TauSpinnerWT')
self.var(tree, 'TauSpinnerWThminus')
self.var(tree, 'TauSpinnerWThplus')
self.var(tree, 'TauSpinnerTauPolFromZ')
self.var(tree, 'TauSpinnerWRight')
self.var(tree, 'TauSpinnerWLeft')
self.var(tree, 'TauSpinnerIsRightLeft')

self.vars(tree, ['TauSpinnerWTisValid', 'TauSpinnerWT', 'TauSpinnerWThminus', 'TauSpinnerWThplus', 'TauSpinnerTauPolFromZ', 'TauSpinnerWRight', 'TauSpinnerWLeft', 'TauSpinnerIsRightLeft'])

def fillTauSpinner(self, tree, event):
self.fill(tree, 'TauSpinnerWTisValid', event.TauSpinnerWTisValid)
self.fill(tree, 'TauSpinnerWT', float(event.TauSpinnerWT))
self.fill(tree, 'TauSpinnerWThminus', float(event.TauSpinnerWThminus))
self.fill(tree, 'TauSpinnerWThplus', float(event.TauSpinnerWThplus))
self.fill(tree, 'TauSpinnerTauPolFromZ', float(event.TauSpinnerTauPolFromZ))
self.fill(tree, 'TauSpinnerWRight', float(event.TauSpinnerWRight))
self.fill(tree, 'TauSpinnerWLeft', float(event.TauSpinnerWLeft))
self.fill(tree, 'TauSpinnerIsRightLeft', float(event.TauSpinnerIsRightLeft))

self.fillVars(tree, ['TauSpinnerWTisValid', 'TauSpinnerWT', 'TauSpinnerWThminus', 'TauSpinnerWThplus', 'TauSpinnerTauPolFromZ', 'TauSpinnerWRight', 'TauSpinnerWLeft', 'TauSpinnerIsRightLeft'], event)

def bookTopPtReweighting(self, tree):
self.var(tree, 'gen_top_1_pt')
self.var(tree, 'gen_top_2_pt')
self.var(tree, 'gen_top_weight')
self.vars(tree, ['gen_top_1_pt', 'gen_top_2_pt', 'gen_top_weight'])

def fillTopPtReweighting(self, tree, event):
'''FIXME: Move this to extra class - only do inline calculations here'''
Expand Down
108 changes: 108 additions & 0 deletions H2TauTau/python/proto/analyzers/HLTTauTreeProducer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
from PhysicsTools.HeppyCore.utils.deltar import deltaR
from PhysicsTools.Heppy.physicsutils.TauDecayModes import tauDecayModes
from CMGTools.H2TauTau.proto.analyzers.TauGenTreeProducer import TauGenTreeProducer
from CMGTools.H2TauTau.proto.analyzers.H2TauTauTreeProducerBase import H2TauTauTreeProducerBase

class HLTTauTreeProducer(H2TauTauTreeProducerBase):
''' Tree producer for tau POG study.
'''

def __init__(self, *args):
super(HLTTauTreeProducer, self).__init__(*args)

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


def bookTau(self, tau_name):
self.bookParticle(self.tree, tau_name)
self.bookGenParticle(self.tree, tau_name+'_gen')
self.var(self.tree, 'tau_gen_decayMode')

for var in ['ptSumIso', 'chargedPtSumIso', 'chargedPUPtSumIso', 'gammaPtSumIso', 'neutralPtSumIso', 'ptSumSignal', 'chargedCandsPtSumSignal', 'gammaCandsPtSumSignal', 'neutralCandsPtSumSignal', 'dm', 'loose_db_iso', 'nphotons', 'decayMode']:
self.var(self.tree, '_'.join([tau_name, var]))

def fillTau(self, tau, tau_name):
self.fillParticle(self.tree, tau_name, tau)
if tau.genp:
self.fillGenParticle(self.tree, tau_name+'_gen', tau.genp)
if abs(tau.genp.pdgId()) == 15:
self.fill(self.tree, 'tau_gen_decayMode', tauDecayModes.genDecayModeInt(tau.genp.daughters))

print 'From final daughters', tauDecayModes.genDecayModeInt(tau.genp.daughters)


for var in ['ptSumIso', 'chargedPtSumIso', 'chargedPUPtSumIso', 'gammaPtSumIso', 'neutralPtSumIso', 'ptSumSignal', 'chargedCandsPtSumSignal', 'gammaCandsPtSumSignal', 'neutralCandsPtSumSignal', 'dm', 'loose_db_iso', 'nphotons']:
try:
self.fill(self.tree, '_'.join([tau_name, var]), getattr(tau, var))
except TypeError:
import pdb; pdb.set_trace()
for var in ['decayMode']:
try:
self.fill(self.tree, '_'.join([tau_name, var]), getattr(tau, var)())
except TypeError:
import pdb; pdb.set_trace()

def declareVariables(self, setup):
self.bookTau('tau')
self.bookTau('hlt_tau')
self.bookTau('hlt_single_tau')
self.var(self.tree, 'rho')

def process(self, event):
# needed when doing handle.product(), goes back to
# PhysicsTools.Heppy.analyzers.core.Analyzer
self.readCollections(event.input)

if not eval(self.skimFunction):
return False


hlt_taus = [tau for tau in event.hlt_taus] # it's a vector
hlt_single_taus = [tau for tau in event.hlt_single_taus] # it's a vector
for tau in event.taus:
self.tree.reset()

self.fill(self.tree, 'rho', event.rho)

if tau.pt() < 20.:
continue
self.fillTau(tau, 'tau')

for hlt_tau in hlt_taus:
if deltaR(tau, hlt_tau) < 0.3:
self.fillTau(hlt_tau, 'hlt_tau')
hlt_taus.remove(hlt_tau)
break

for hlt_tau in hlt_single_taus:
if deltaR(tau, hlt_tau) < 0.3:
self.fillTau(hlt_tau, 'hlt_single_tau')
hlt_single_taus.remove(hlt_tau)
break


self.fillTree(event)

for hlt_tau in hlt_taus:
self.tree.reset()
self.fill(self.tree, 'rho', event.rho)

if hlt_tau.pt() < 20.:
continue
self.fillTau(hlt_tau, 'hlt_tau')
for single_tau in hlt_single_taus:
if deltaR(single_tau, hlt_tau) < 0.3:
self.fillTau(single_tau, 'hlt_single_tau')
hlt_single_taus.remove(single_tau)
break
self.fillTree(event)

for hlt_tau in hlt_single_taus:
self.tree.reset()
self.fill(self.tree, 'rho', event.rho)

if hlt_tau.pt() < 20.:
continue
self.fillTau(hlt_tau, 'hlt_single_tau')
self.fillTree(event)
8 changes: 6 additions & 2 deletions H2TauTau/python/proto/analyzers/HTTGenAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from PhysicsTools.Heppy.physicsobjects.PhysicsObject import PhysicsObject
from PhysicsTools.Heppy.physicsobjects.GenParticle import GenParticle
from PhysicsTools.Heppy.physicsutils.TauDecayModes import tauDecayModes

from CMGTools.H2TauTau.proto.analyzers.TauGenTreeProducer import TauGenTreeProducer

Expand Down Expand Up @@ -153,6 +154,8 @@ def getGenTauJets(event):

genjet = GenParticle(gentau)
genjet.setP4(p4_genjet)
genjet.daughters = c_genjet
genjet.decayMode = tauDecayModes.genDecayModeInt(c_genjet)

if p4_genjet.pt() > 15.:
event.genTauJets.append(genjet)
Expand Down Expand Up @@ -193,7 +196,8 @@ def genMatch(event, leg, ptSelGentauleps, ptSelGenleps, ptSelGenSummary,
l1match, dR2best = bestMatch(leg, event.genTauJets)
if dR2best < best_dr2:
best_dr2 = dR2best
leg.genp = GenParticle(l1match)
# leg.genp = GenParticle(l1match)
leg.genp = l1match
leg.genp.setPdgId(-15 * leg.genp.charge())
leg.isTauHad = True
# if not leg.genJet():
Expand Down Expand Up @@ -249,7 +253,7 @@ def genMatch(event, leg, ptSelGentauleps, ptSelGenleps, ptSelGenSummary,
# Now this may be a pileup lepton, or one whose ancestor doesn't
# appear in the gen summary because it's an unclear case in Pythia 8
# To check the latter, match against jets as well...
l1match, dR2best = bestMatch(leg, event.genJets)
l1match, dR2best = bestMatch(leg, getattr(event, 'genJets', []))
# Check if there's a gen jet with pT > 10 GeV (otherwise it's PU)
if dR2best < dR2 and l1match.pt() > 10.:
leg.genp = PhysicsObject(l1match)
Expand Down
Loading

0 comments on commit b65d365

Please sign in to comment.