Skip to content

Commit

Permalink
- replaced string "nanoAOD_vvVBS" to "nanoAOD_skim" in few files
Browse files Browse the repository at this point in the history
- Fix the json bug (For MC we don't need to provide)
- Added modules createJMECorrector, btagSFProducer, etc
  • Loading branch information
ram1123 committed Sep 26, 2023
1 parent 7937296 commit 9973c87
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 25 deletions.
20 changes: 10 additions & 10 deletions JetSFMaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ROOT

from PhysicsTools.NanoAODTools.postprocessing.framework.eventloop import Module
from PhysicsTools.NanoAODTools.postprocessing.framework.datamodel import Collection
from PhysicsTools.NanoAODTools.postprocessing.framework.datamodel import Collection

class JetSFMaker(Module):
#----------------------------------------------------------------------------
Expand All @@ -13,11 +13,11 @@ class JetSFMaker(Module):
#weight. Same for up/down variations (weights).
#----------------------------------------------------------------------------

def __init__(self, cmssw, puid_sf_config='PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_vvVBS/data/JetPUID_cfg.py'):
def __init__(self, cmssw, puid_sf_config='PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_skim/data/JetPUID_cfg.py'):
cmssw_base = os.getenv('CMSSW_BASE')
with open(cmssw_base + '/src/' + puid_sf_config) as src:
exec(src)

puid_sf_cfg = jet_puid_sf[cmssw]

source = ROOT.TFile.Open(cmssw_base + '/src/' + puid_sf_cfg['source'])
Expand Down Expand Up @@ -77,7 +77,7 @@ def analyze(self, event):
up = 1 + abs(sf-1)
down = 1 - abs(sf-1)
puid_upjw = up
puid_downjw = down
puid_downjw = down
else:
puid_jw = (1.-sf*eff)/(1.-eff)
if (jtype == 'real') or (jtype == 'pu' and abs(jet.eta)>=2.5):
Expand All @@ -87,28 +87,28 @@ def analyze(self, event):
up = 1 + abs(sf-1)
down = 1 - abs(sf-1)
puid_upjw = (1.-up*eff)/(1.-eff)
puid_downjw = (1.-down*eff)/(1.-eff)
puid_downjw = (1.-down*eff)/(1.-eff)

#store per jet weights and variations
sfs[wp].append(puid_jw)
sfs_up[wp].append(puid_upjw)
sfs_down[wp].append(puid_downjw)

for wp in ['loose', 'medium', 'tight']:
self.out.fillBranch('Jet_PUIDSF_%s' % wp, sfs[wp])
self.out.fillBranch('Jet_PUIDSF_%s' % wp, sfs[wp])
self.out.fillBranch('Jet_PUIDSF_%s_up' % wp, sfs_up[wp])
self.out.fillBranch('Jet_PUIDSF_%s_down' % wp, sfs_down[wp])

return True

def get_sf_and_eff(self, jtype, wp, jet):
sf_map = self.sf_maps['%s_%s' % (jtype, wp)]
sf_uncty_map = self.sf_uncty_maps['%s_%s_uncty' % (jtype, wp)]
sf_uncty_map = self.sf_uncty_maps['%s_%s_uncty' % (jtype, wp)]
eff_map = self.eff_maps['%s_mc_%s' % (jtype, wp)]

if jet.pt < 30. or jet.pt > 50. or abs(jet.eta) > 4.7:
#do not apply SF outside CleanJet region and where PUID was not applied
return 1.,0.,0.,0.
if jet.pt < 30. or jet.pt > 50. or abs(jet.eta) > 4.7:
#do not apply SF outside CleanJet region and where PUID was not applied
return 1.,0.,0.,0.

ix = min(max(1, sf_map.GetXaxis().FindFixBin(jet.pt)), sf_map.GetNbinsX())
iy = min(max(1, sf_map.GetYaxis().FindFixBin(jet.eta)), sf_map.GetNbinsY())
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ nanoAOD skiming code for H->ZZ->2l2Q studies.
1. In the file [condor_setup_lxplus.py](condor_setup_lxplus.py), specify the correct input text file (present inside directory [input_data_Files](input_data_Files)) from which you need to take input NanoAOD DAS names. Also, updated the output EOS path. Then do the following:

```bash
cd $CMSSW_BASE/src/PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_vvVBS
cd $CMSSW_BASE/src/PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_skim
# Use the arguments that you need.
python condor_setup_lxplus.py --input-file sample_list_v9.dat
# Set proxy before submitting the condor jobs.
Expand Down
2 changes: 1 addition & 1 deletion crab/crab_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

config.section_("General")
config.General.requestName = 'nanoAOD_testing_2'
config.General.workArea = '/uscms/home/rasharma/nobackup/nanoAOD/CMSSW_10_2_22/src/PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_vvVBS/crab/crab_projects_sendPythonFolderFalse'
config.General.workArea = '/uscms/home/rasharma/nobackup/nanoAOD/CMSSW_10_2_22/src/PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_skim/crab/crab_projects_sendPythonFolderFalse'
config.General.transferLogs=True
config.General.transferOutputs = True
config.section_("JobType")
Expand Down
2 changes: 1 addition & 1 deletion crab/crab_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#this takes care of converting the input files from CRAB
from PhysicsTools.NanoAODTools.postprocessing.framework.crabhelper import inputFiles,runsAndLumis
from PhysicsTools.NanoAODTools.postprocessing.analysis.nanoAOD_vvVBS.wvAnalysisModule import wvAnalysisModule
from PhysicsTools.NanoAODTools.postprocessing.analysis.nanoAOD_skim.wvAnalysisModule import wvAnalysisModule

from PhysicsTools.NanoAODTools.postprocessing.modules.jme.jetmetHelperRun2 import *

Expand Down
2 changes: 1 addition & 1 deletion crab/crab_scriptMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#this takes care of converting the input files from CRAB
from PhysicsTools.NanoAODTools.postprocessing.framework.crabhelper import inputFiles,runsAndLumis
from PhysicsTools.NanoAODTools.postprocessing.analysis.nanoAOD_vvVBS.wvAnalysisModule import wvAnalysisModule
from PhysicsTools.NanoAODTools.postprocessing.analysis.nanoAOD_skim.wvAnalysisModule import wvAnalysisModule

from PhysicsTools.NanoAODTools.postprocessing.modules.jme.jetmetHelperRun2 import *

Expand Down
10 changes: 5 additions & 5 deletions data/JetPUID_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
# /afs/cern.ch/work/l/lathomas/public/PileUpIDScaleFactor_PreliminaryRun2/
# see twiki https://twiki.cern.ch/twiki/bin/viewauth/CMS/PileupJetID
# following Laurent's updated talk in
# https://indico.cern.ch/event/860457/
# https://indico.cern.ch/event/860457/

_jet_puid_sf = {
'2016': {'source': 'PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_vvVBS/data/PUID_80XTraining_EffSFandUncties.root'},
'2017': {'source': 'PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_vvVBS/data/PUID_80XTraining_EffSFandUncties.root'},
'2018': {'source': 'PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_vvVBS/data/PUID_80XTraining_EffSFandUncties.root'}
'2016': {'source': 'PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_skim/data/PUID_80XTraining_EffSFandUncties.root'},
'2017': {'source': 'PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_skim/data/PUID_80XTraining_EffSFandUncties.root'},
'2018': {'source': 'PhysicsTools/NanoAODTools/python/postprocessing/analysis/nanoAOD_skim/data/PUID_80XTraining_EffSFandUncties.root'}
}

for jet, jetTag in [('real','eff'), ('pu','mistag')]:
Expand All @@ -20,7 +20,7 @@
jcfg['%s_%s' % (jet, wp)] = 'h2_%s_sf%s_%s' % (jetTag, year, iwp)
jcfg['%s_mc_%s' % (jet, wp)] = 'h2_%s_mc%s_%s' % (jetTag, year, iwp)
jcfg['%s_%s_uncty' % (jet, wp)] = 'h2_%s_sf%s_%s_Systuncty' % (jetTag, year, iwp)

jet_puid_sf = {}

jet_puid_sf['2016'] = _jet_puid_sf['2016']
Expand Down
23 changes: 17 additions & 6 deletions post_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from H4LCppModule import *
from PhysicsTools.NanoAODTools.postprocessing.modules.jme.jetmetHelperRun2 import *
from PhysicsTools.NanoAODTools.postprocessing.modules.btv.btagSFProducer import *
from JetSFMaker import *

ifRunningOnCondor = False

Expand All @@ -32,35 +33,45 @@

isMC = True
isFSR = False

outputbranchsel = "keep_and_drop.txt"
jsonFileName = ""
# Keep DownloadFileToLocalThenRun=True this should reduce the file read error from eos.
DownloadFileToLocalThenRun=True

if testfilelist[0].find("/data/") != -1:
isMC = False
outputbranchsel = "keep_and_drop_data.txt"

if testfilelist[0].find("UL18") != -1 or testfilelist[0].find("UL2018") != -1: # UL2018 for identification of 2018 UL data and UL18 for identification of 2018 UL MC
year = 2018
cfgFile = 'Input_2018.yml'
jsonFileName="golden_Json/Cert_314472-325175_13TeV_Legacy2018_Collisions18_JSON.txt"
sfFileName="DeepCSV_102XSF_V2.csv"

if testfilelist[0].find("UL17") != -1 or testfilelist[0].find("UL2017") != -1:
year = 2017
cfgFile = 'Input_2017.yml'
jsonFileName="golden_Json/Cert_294927-306462_13TeV_UL2017_Collisions17_GoldenJSON.txt"
sfFileName="DeepCSV_94XSF_V5_B_F.csv"

if testfilelist[0].find("UL16") != -1 or testfilelist[0].find("UL2016") != -1:
sfFileName="DeepCSV_2016LegacySF_V1.csv"

H4LCppModule = lambda: HZZAnalysisCppProducer(year,cfgFile, isMC, isFSR)
print("Input json file: {}".format(jsonFileName))
print("Input cfg file: {}".format(cfgFile))
print("output branch: {}".format(outputbranchsel))
print("isMC: {}".format(isMC))
print("isFSR: {}".format(isFSR))

#p=PostProcessor(".",[testfile],"",None,[H4LCppModule()],provenance=True,fwkJobReport=False,haddFileName="nano_M125.root",maxEntries=entriesToRun,prefetch=DownloadFileToLocalThenRun,outputbranchsel="keep_and_drop.txt")
p=PostProcessor(".",testfilelist,"",None,[H4LCppModule()],provenance=True,fwkJobReport=False,haddFileName="nano_M125_cpp.root", jsonInput=jsonFileName, maxEntries=entriesToRun, prefetch=DownloadFileToLocalThenRun, outputbranchsel=outputbranchsel)
if isMC:
jetmetCorrector = createJMECorrector(isMC=isMC, dataYear=year, jesUncert="All", jetType = "AK4PFchs")
fatJetCorrector = createJMECorrector(isMC=isMC, dataYear=year, jesUncert="All", jetType = "AK8PFPuppi")
btagSF = lambda: btagSFProducer("UL"+str(year), algo="deepjet",selectedWPs=['L','M','T','shape_corr'], sfFileName=sfFileName)
puidSF = lambda: JetSFMaker("%s" % year)
# p=PostProcessor(".",testfilelist, None, None,[H4LCppModule(), jetmetCorrector(), fatJetCorrector(), btagSF(), puidSF()], provenance=True,fwkJobReport=False,haddFileName="nano_M125_cpp.root", maxEntries=entriesToRun, prefetch=DownloadFileToLocalThenRun, outputbranchsel="keep_and_drop.txt")
p=PostProcessor(".",testfilelist, None, None,[H4LCppModule(), jetmetCorrector(), fatJetCorrector(), puidSF()], provenance=True,fwkJobReport=False,haddFileName="nano_M125_cpp.root", maxEntries=entriesToRun, prefetch=DownloadFileToLocalThenRun, outputbranchsel="keep_and_drop.txt")
else:
jetmetCorrector = createJMECorrector(isMC=isMC, dataYear=year, jesUncert="All", jetType = "AK4PFchs")
fatJetCorrector = createJMECorrector(isMC=isMC, dataYear=year, jesUncert="All", jetType = "AK8PFPuppi")
p=PostProcessor(".",testfilelist, None, None,[H4LCppModule(), jetmetCorrector(), fatJetCorrector()], provenance=False, fwkJobReport=False,haddFileName="nano_M125_cpp.root", jsonInput=jsonFileName, maxEntries=entriesToRun, prefetch=DownloadFileToLocalThenRun, outputbranchsel="keep_and_drop_data.txt")

p.run()
print "DONE"

0 comments on commit 9973c87

Please sign in to comment.