Skip to content

Commit

Permalink
Merge branch 'master' of github_:/cms-nanoAOD/nanoAOD-tools
Browse files Browse the repository at this point in the history
  • Loading branch information
vrbouza committed Oct 20, 2022
2 parents 883593f + c32f055 commit 6995aa2
Show file tree
Hide file tree
Showing 51 changed files with 118 additions and 29 deletions.
Binary file added data/jme/Summer19UL16APV_V7_DATA.tgz
Binary file not shown.
Binary file added data/jme/Summer19UL16APV_V7_MC.tgz
Binary file not shown.
Binary file added data/jme/Summer19UL16_V7_DATA.tgz
Binary file not shown.
Binary file added data/jme/Summer19UL16_V7_MC.tgz
Binary file not shown.
Binary file added data/jme/Summer19UL17_RunB_V5_DATA.tgz
Binary file not shown.
Binary file removed data/jme/Summer19UL17_RunB_V6_DATA.tar.gz
Binary file not shown.
Binary file removed data/jme/Summer19UL17_RunB_V6_DATA.tgz
Binary file not shown.
Binary file added data/jme/Summer19UL17_RunC_V5_DATA.tgz
Binary file not shown.
Binary file removed data/jme/Summer19UL17_RunC_V6_DATA.tar.gz
Binary file not shown.
Binary file removed data/jme/Summer19UL17_RunC_V6_DATA.tgz
Binary file not shown.
Binary file added data/jme/Summer19UL17_RunD_V5_DATA.tgz
Binary file not shown.
Binary file removed data/jme/Summer19UL17_RunD_V6_DATA.tar.gz
Binary file not shown.
Binary file removed data/jme/Summer19UL17_RunD_V6_DATA.tgz
Binary file not shown.
Binary file added data/jme/Summer19UL17_RunE_V5_DATA.tgz
Binary file not shown.
Binary file removed data/jme/Summer19UL17_RunE_V6_DATA.tar.gz
Binary file not shown.
Binary file removed data/jme/Summer19UL17_RunE_V6_DATA.tgz
Binary file not shown.
Binary file added data/jme/Summer19UL17_RunF_V5_DATA.tgz
Binary file not shown.
Binary file removed data/jme/Summer19UL17_RunF_V6_DATA.tar.gz
Binary file not shown.
Binary file removed data/jme/Summer19UL17_RunF_V6_DATA.tgz
Binary file not shown.
Binary file removed data/jme/Summer19UL17_V6_DATA.tgz
Binary file not shown.
Binary file removed data/jme/Summer19UL17_V6_MC.tar.gz
Binary file not shown.
Binary file removed data/jme/Summer19UL17_V6_MC.tgz
Binary file not shown.
Binary file added data/jme/Summer20UL16APV_JRV3_MC.tgz
Binary file not shown.
Binary file added data/jme/Summer20UL16_JRV3_MC.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified python/postprocessing/data/pileup/mcPileupUL2018.root
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 4 additions & 1 deletion python/postprocessing/framework/postprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ def run(self):
inTree.SetEntryList(elist)
else:
# initialize reader
inTree = InputTree(inTree, elist)
if elist:
inTree = InputTree(inTree, elist)
else:
inTree = InputTree(inTree)

# prepare output file
if not self.noOut:
Expand Down
4 changes: 2 additions & 2 deletions python/postprocessing/framework/treeReaderArrayTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ROOT.PyConfig.IgnoreCommandLineOptions = True


def InputTree(tree, entrylist=None):
def InputTree(tree, entrylist=ROOT.MakeNullPointer(ROOT.TEntryList)):
"""add to the PyROOT wrapper of a TTree a TTreeReader and methods readBranch, arrayReader, valueReader"""
if hasattr(tree, '_ttreereader'):
return tree # don't initialize twice
Expand Down Expand Up @@ -116,7 +116,7 @@ def _makeValueReader(tree, typ, nam):


def _remakeAllReaders(tree):
_ttreereader = ROOT.TTreeReader(tree, getattr(tree, '_entrylist', None))
_ttreereader = ROOT.TTreeReader(tree, getattr(tree, '_entrylist', ROOT.MakeNullPointer(ROOT.TEntryList)))
_ttreereader._isClean = True
_ttrvs = {}
for k in tree._ttrvs.keys():
Expand Down
59 changes: 40 additions & 19 deletions python/postprocessing/helpers/TauIDSFTool.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Author: Izaak Neutelings (July 2019)
# https://twiki.cern.ch/twiki/bin/viewauth/CMS/TauIDRecommendationForRun2
# Source: https://github.com/cms-tau-pog/TauIDSFs
from __future__ import print_function
import os
from math import sqrt
from PhysicsTools.NanoAODTools.postprocessing.tools import ensureTFile, extractTH1
datapath = os.path.join(os.environ.get('CMSSW_BASE','CMSSW_BASE'),"src/PhysicsTools/NanoAODTools/python/postprocessing/data/tau")
campaigns = ['2016Legacy','2017ReReco','2018ReReco']

campaigns = [
'2016Legacy','2017ReReco','2018ReReco',
'UL2016_preVFP', 'UL2016_postVFP', 'UL2017', 'UL2018',
]


class TauIDSFTool:
Expand All @@ -20,14 +23,17 @@ def __init__(self, year, id, wp='Tight', dm=False, emb=False,
emb: use SFs for embedded samples
otherVSlepWP: extra uncertainty if you are using a different DeepTauVSe/mu WP than used in the measurement
"""
assert year in campaigns, "You must choose a year from %s."%(', '.join(campaigns))
if "UL" in year and "VSmu" in id:
print(">>> TauIDSFTool: Warning! Using pre-UL (%r) SFs for %s..."%(year,id))
year = '2016Legacy' if '2016' in year else '2017ReReco' if '2017' in year else '2018ReReco'
assert year in campaigns, "You must choose a year from %s! Got %r."%(', '.join(campaigns),year)
self.ID = id
self.WP = wp
self.verbose = verbose
self.extraUnc = None

if id in ['MVAoldDM2017v2','DeepTau2017v2p1VSjet']:
if dm:
if dm: # DM-dependent SFs
if emb:
if 'oldDM' in id:
raise IOError("Scale factors for embedded samples not available for ID '%s'!"%id)
Expand All @@ -46,7 +52,7 @@ def __init__(self, year, id, wp='Tight', dm=False, emb=False,
self.extraUnc = 0.05
else:
self.extraUnc = 0.03
else:
else: # pT-dependent SFs
if emb:
if 'oldDM' in id:
raise IOError("Scale factors for embedded samples not available for ID '%s'!"%id)
Expand Down Expand Up @@ -93,7 +99,8 @@ def getSFvsPT(self, pt, genmatch=5, unc=None):
elif unc=='Up':
return sf+errUp
elif unc=='Down':
return sf-errDown
sfDown = (sf-errDown) if errDown<sf else 0.0 # prevent negative SF
return sfDown
else:
if unc=='All':
return self.func['Down'].Eval(pt), self.func[None].Eval(pt), self.func['Up'].Eval(pt)
Expand All @@ -113,9 +120,10 @@ def getSFvsDM(self, pt, dm, genmatch=5, unc=None):
if unc=='Up':
sf += err
elif unc=='Down':
sf -= err
sf = (sf-err) if err<sf else 0.0 # prevent negative SF
elif unc=='All':
return sf-err, sf, sf+err
sfDown = (sf-err) if err<sf else 0.0 # prevent negative SF
return sfDown, sf, sf+err
return sf
elif unc=='All':
return 1.0, 1.0, 1.0
Expand All @@ -133,9 +141,10 @@ def getSFvsEta(self, eta, genmatch, unc=None):
if unc=='Up':
sf += err
elif unc=='Down':
sf -= err
sf = (sf-err) if err<sf else 0.0 # prevent negative SF
elif unc=='All':
return sf-err, sf, sf+err
sfDown = (sf-err) if err<sf else 0.0 # prevent negative SF
return sfDown, sf, sf+err
return sf
elif unc=='All':
return 1.0, 1.0, 1.0
Expand All @@ -149,9 +158,15 @@ def disabled(*args,**kwargs):
class TauESTool:
def __init__(self, year, id='DeepTau2017v2p1VSjet', path=datapath):
"""Choose the IDs and WPs for SFs."""
assert year in campaigns, "You must choose a year from %s."%(', '.join(campaigns))
if "UL" in year:
print(">>> TauESTool: Warning! Using pre-UL (%r) TESs at high pT (for uncertainties only)..."%(year))
year_highpt = '2016Legacy' if '2016' in year else '2017ReReco' if '2017' in year else '2018ReReco'
else:
year_highpt = year
assert year in campaigns, "You must choose a year from %s! Got %r."%(', '.join(campaigns),year)
assert year_highpt in campaigns, "You must choose a year from %s! Got %r."%(', '.join(campaigns),year_highpt)
file_lowpt = ensureTFile(os.path.join(path,"TauES_dm_%s_%s.root"%(id,year)))
file_highpt = ensureTFile(os.path.join(path,"TauES_dm_%s_%s_ptgt100.root"%(id,year)))
file_highpt = ensureTFile(os.path.join(path,"TauES_dm_%s_%s_ptgt100.root"%(id,year_highpt)))
self.hist_lowpt = extractTH1(file_lowpt,'tes')
self.hist_highpt = extractTH1(file_highpt,'tes')
self.hist_lowpt.SetDirectory(0)
Expand Down Expand Up @@ -181,9 +196,10 @@ def getTES(self, pt, dm, genmatch=5, unc=None):
if unc=='Up':
tes += err
elif unc=='Down':
tes -= err
tes = (tes-err) if err<tes else 0.0 # prevent negative TES
elif unc=='All':
return tes-err, tes, tes+err
tesDown = (tes-err) if err<tes else 0.0 # prevent negative TES
return tesDown, tes, tes+err
return tes
elif unc=='All':
return 1.0, 1.0, 1.0
Expand All @@ -194,12 +210,14 @@ def getTES_highpt(self, dm, genmatch=5, unc=None):
if genmatch==5 and dm in self.DMs:
bin = self.hist_highpt.GetXaxis().FindBin(dm)
tes = self.hist_highpt.GetBinContent(bin)
err = self.hist_highpt.GetBinError(bin)
if unc=='Up':
tes += self.hist_highpt.GetBinError(bin)
tes += err
elif unc=='Down':
tes -= self.hist_highpt.GetBinError(bin)
tes = (tes-err) if err<tes else 0.0 # prevent negative TES
elif unc=='All':
return tes-self.hist_highpt.GetBinError(bin), tes, tes+self.hist_highpt.GetBinError(bin)
tesDown = (tes-err) if err<tes else 0.0 # prevent negative TES
return tesDown, tes, tes+err
return tes
elif unc=='All':
return 1.0, 1.0, 1.0
Expand All @@ -210,7 +228,10 @@ class TauFESTool:

def __init__(self, year, id='DeepTau2017v2p1VSe', path=datapath):
"""Choose the IDs and WPs for SFs."""
assert year in campaigns, "You must choose a year from %s."%(', '.join(campaigns))
if "UL" in year:
print(">>> TauFESTool: Warning! Using pre-UL (%r) energy scales for e -> tau fakes..."%(year))
year = '2016Legacy' if '2016' in year else '2017ReReco' if '2017' in year else '2018ReReco'
assert year in campaigns, "You must choose a year from %s! Got %r."%(', '.join(campaigns),year)
file = ensureTFile(os.path.join(path,"TauFES_eta-dm_%s_%s.root"%(id,year)))
graph = file.Get('fes')
FESs = { 'barrel': { }, 'endcap': { } }
Expand All @@ -221,7 +242,7 @@ def __init__(self, year, id='DeepTau2017v2p1VSe', path=datapath):
y = graph.GetY()[i]
yup = graph.GetErrorYhigh(i)
ylow = graph.GetErrorYlow(i)
FESs[region][dm] = (y-ylow,y,y+yup)
FESs[region][dm] = (max(0,y-ylow),y,y+yup) # prevent negative FES
i += 1
file.Close()
self.FESs = FESs
Expand Down
44 changes: 44 additions & 0 deletions python/postprocessing/modules/common/puWeightProducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,47 @@ def analyze(self, event):
doSysVar=True)
puAutoWeight_2018 = lambda: puWeightProducer(
"auto", pufile_data2018, "pu_mc", "pileup", verbose=False)

# Ultra legacy

# 2016
pufile_dataUL2016 = "%s/src/PhysicsTools/NanoAODTools/python/postprocessing/data/pileup/PileupHistogram-UL2016-100bins_withVar.root" % os.environ[
'CMSSW_BASE']
pufile_mcUL2016 = "%s/src/PhysicsTools/NanoAODTools/python/postprocessing/data/pileup/mcPileupUL2016.root" % os.environ[
'CMSSW_BASE']
puWeight_UL2016 = lambda: puWeightProducer(pufile_mcUL2016,
pufile_dataUL2016,
"pu_mc",
"pileup",
verbose=False,
doSysVar=True)
puAutoWeight_UL2016 = lambda: puWeightProducer(
"auto", pufile_dataUL2016, "pu_mc", "pileup", verbose=False)

# 2017
pufile_dataUL2017 = "%s/src/PhysicsTools/NanoAODTools/python/postprocessing/data/pileup/PileupHistogram-UL2017-100bins_withVar.root" % os.environ[
'CMSSW_BASE']
pufile_mcUL2017 = "%s/src/PhysicsTools/NanoAODTools/python/postprocessing/data/pileup/mcPileupUL2017.root" % os.environ[
'CMSSW_BASE']
puWeight_UL2017 = lambda: puWeightProducer(pufile_mcUL2017,
pufile_dataUL2017,
"pu_mc",
"pileup",
verbose=False,
doSysVar=True)
puAutoWeight_UL2017 = lambda: puWeightProducer(
"auto", pufile_dataUL2017, "pu_mc", "pileup", verbose=False)

# 2018
pufile_dataUL2018 = "%s/src/PhysicsTools/NanoAODTools/python/postprocessing/data/pileup/PileupHistogram-UL2018-100bins_withVar.root" % os.environ[
'CMSSW_BASE']
pufile_mcUL2018 = "%s/src/PhysicsTools/NanoAODTools/python/postprocessing/data/pileup/mcPileupUL2018.root" % os.environ[
'CMSSW_BASE']
puWeight_UL2018 = lambda: puWeightProducer(pufile_mcUL2018,
pufile_dataUL2018,
"pu_mc",
"pileup",
verbose=False,
doSysVar=True)
puAutoWeight_UL2018 = lambda: puWeightProducer(
"auto", pufile_dataUL2018, "pu_mc", "pileup", verbose=False)
35 changes: 28 additions & 7 deletions python/postprocessing/modules/jme/jetmetHelperRun2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
from PhysicsTools.NanoAODTools.postprocessing.modules.jme.fatJetUncertainties import *

# JEC dict
# https://twiki.cern.ch/twiki/bin/viewauth/CMS/JECDataMC#Recommended_for_MC
jecTagsMC = {
'2016': 'Summer16_07Aug2017_V11_MC',
'2017': 'Fall17_17Nov2017_V32_MC',
'2018': 'Autumn18_V19_MC',
'UL2017': 'Summer19UL17_V6_MC',
'UL2016_preVFP': 'Summer19UL16APV_V7_MC',
'UL2016': 'Summer19UL16_V7_MC',
'UL2017': 'Summer19UL17_V5_MC',
'UL2018': 'Summer19UL18_V5_MC',
}

Expand All @@ -21,11 +24,14 @@
'2018': 'Autumn18_FastSimV1_MC',
}

# https://twiki.cern.ch/twiki/bin/viewauth/CMS/JECDataMC#Recommended_for_Data
archiveTagsDATA = {
'2016': 'Summer16_07Aug2017_V11_DATA',
'2017': 'Fall17_17Nov2017_V32_DATA',
'2018': 'Autumn18_V19_DATA',
'UL2017': 'Summer19UL17_V6_DATA',
'UL2016_preVFP': 'Summer19UL16APV_V7_DATA',
'UL2016': 'Summer19UL16_V7_DATA',
'UL2017': 'Summer19UL17_V5_DATA',
'UL2018': 'Summer19UL18_V5_DATA'
}

Expand All @@ -46,21 +52,32 @@
'2018B': 'Autumn18_RunB_V19_DATA',
'2018C': 'Autumn18_RunC_V19_DATA',
'2018D': 'Autumn18_RunD_V19_DATA',
'UL2017B': 'Summer19UL17_RunB_V6_DATA',
'UL2017C': 'Summer19UL17_RunC_V6_DATA',
'UL2017D': 'Summer19UL17_RunD_V6_DATA',
'UL2017E': 'Summer19UL17_RunE_V6_DATA',
'UL2017F': 'Summer19UL17_RunF_V6_DATA',
'UL2016_preVFPB': 'Summer19UL16APV_RunBCD_V7_DATA',
'UL2016_preVFPC': 'Summer19UL16APV_RunBCD_V7_DATA',
'UL2016_preVFPD': 'Summer19UL16APV_RunBCD_V7_DATA',
'UL2016_preVFPE': 'Summer19UL16APV_RunEF_V7_DATA',
'UL2016_preVFPF': 'Summer19UL16APV_RunEF_V7_DATA',
'UL2016F': 'Summer19UL16_RunFGH_V7_DATA',
'UL2016G': 'Summer19UL16_RunFGH_V7_DATA',
'UL2016H': 'Summer19UL16_RunFGH_V7_DATA',
'UL2017B': 'Summer19UL17_RunB_V5_DATA',
'UL2017C': 'Summer19UL17_RunC_V5_DATA',
'UL2017D': 'Summer19UL17_RunD_V5_DATA',
'UL2017E': 'Summer19UL17_RunE_V5_DATA',
'UL2017F': 'Summer19UL17_RunF_V5_DATA',
'UL2018A': 'Summer19UL18_RunA_V5_DATA',
'UL2018B': 'Summer19UL18_RunB_V5_DATA',
'UL2018C': 'Summer19UL18_RunC_V5_DATA',
'UL2018D': 'Summer19UL18_RunD_V5_DATA',
}

# https://twiki.cern.ch/twiki/bin/view/CMS/JetResolution
jerTagsMC = {
'2016': 'Summer16_25nsV1_MC',
'2017': 'Fall17_V3_MC',
'2018': 'Autumn18_V7b_MC',
'UL2016_preVFP': 'Summer20UL16APV_JRV3_MC',
'UL2016': 'Summer20UL16_JRV3_MC',
'UL2017': 'Summer19UL17_JRV2_MC',
'UL2018': 'Summer19UL18_JRV2_MC',
}
Expand All @@ -72,6 +89,8 @@
'2017': [1.09, 1.14, 1.04],
# Use 2017 values for 2018 until 2018 are released
'2018': [1.09, 1.14, 1.04],
'UL2016_preVFP': [1.00, 1.00, 1.00], # placeholder
'UL2016': [1.00, 1.00, 1.00], # placeholder
'UL2017': [1.00, 1.00, 1.00], # placeholder
'UL2018': [1.00, 1.00, 1.00], # placeholder
}
Expand All @@ -84,6 +103,8 @@
'2017': [0.982, 0.978, 0.986],
# Use 2017 values for 2018 until 2018 are released
'2018': [0.982, 0.978, 0.986],
'UL2016_preVFP': [1.000, 1.000, 1.000], # placeholder
'UL2016': [1.000, 1.000, 1.000], # placeholder
'UL2017': [1.000, 1.000, 1.000], # placeholder
'UL2018': [1.000, 1.000, 1.000], # placeholder
}
Expand Down

0 comments on commit 6995aa2

Please sign in to comment.