-
Notifications
You must be signed in to change notification settings - Fork 4
/
doSkim_stockNanoV5.py
executable file
·135 lines (120 loc) · 5.06 KB
/
doSkim_stockNanoV5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python2
import argparse
from PhysicsTools.NanoAODTools.postprocessing.framework.postprocessor import (
PostProcessor,
)
# this takes care of converting the input files from CRAB
from PhysicsTools.NanoAODTools.postprocessing.framework.crabhelper import (
inputFiles,
runsAndLumis,
)
from PhysicsTools.NanoAODTools.postprocessing.modules.btv.btagSFProducer import *
from PhysicsTools.NanoAODTools.postprocessing.modules.jme.jetmetHelperRun2 import *
from PhysicsTools.NanoAODTools.postprocessing.modules.common.puWeightProducer import *
# from PhysicsTools.NanoAODTools.postprocessing.modules.common.pdfWeightProducer import *
from PhysicsTools.NanoAODTools.postprocessing.framework.postprocessor import (
PostProcessor,
)
from PhysicsTools.NanoAODTools.postprocessing.modules.common.PrefireCorr import PrefCorr
from Leptoquarks.submitJobsWithCrabV2.eventCounterHistogramModule import *
import utils
parser = argparse.ArgumentParser("")
parser.add_argument(
"-isMC",
"--ismc",
type=lambda x: (str(x).lower() == "true"),
default=True,
dest="isMC",
help="",
)
# parser.add_argument('-isMC','--mc', dest='isMC', action='store_true')
# parser.add_argument('-isData','--data', dest='isMC', action='store_false')
# parser.set_defaults(isMC=True)
# parser.add_argument('-jobNum', '--jobNum', type=int, default=1, help="")
parser.add_argument("-era", "--era", type=str, default="2016", help="")
parser.add_argument("-dataRun", "--dataRun", type=str, default="X", help="")
# parser.add_argument('-haddFileName', '--haddFileName', type=str, default="tree.root", help="")
# parser.add_argument('-inputList', '--inputList', type=str, default="", help="")
parser.add_argument(
"-dataset", "--dataset", type=str, default="/myTestDataset/testSecondary/NANOAODSIM", help=""
)
args = parser.parse_args()
print "args = ", args
isMC = args.isMC
era = args.era
dataRun = args.dataRun
# haddFileName = args.haddFileName
# inputList = args.inputList
dataset = args.dataset
print "isMC =", isMC, "era =", era, "dataRun =", dataRun, "dataset=", dataset
if isMC:
jetmetCorrector = createJMECorrector(isMC=True, dataYear=era, jesUncert="All", redojec=True)
else:
jetmetCorrector = createJMECorrector(isMC=False, dataYear=era, runPeriod=dataRun)
modulesToRun = []
modulesToRun.append(jetmetCorrector())
modulesToRun.append(PrefCorr())
# modulesToRun.append( pdfWeightProducer() )
jsonFile = None
# files=utils.GetFileList(inputList)
# print 'files=',files
if isMC:
if era == "2016":
modulesToRun.extend(
[puAutoWeight_2016(), btagSFProducer(era="Legacy2016", algo="deepcsv", selectedWPs=['L', 'M']), btagSFProducer(era="Legacy2016", algo="deepjet", selectedWPs=['L', 'M'])]
)
elif era == "2017":
modulesToRun.extend([puAutoWeight_2017(), btagSFProducer(era="2017", algo="deepcsv", selectedWPs=['L', 'M']), btagSFProducer(era="2017", algo="deepjet", selectedWPs=['L', 'M'])])
elif era == "2018":
modulesToRun.extend([puAutoWeight_2018(), btagSFProducer(era="2018", algo="deepcsv", selectedWPs=['L', 'M']), btagSFProducer(era="2018", algo="deepjet", selectedWPs=['L', 'M'])])
else:
if era == "2016":
# jsonFile='/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions16/13TeV/ReReco/Final/Cert_271036-284044_13TeV_ReReco_07Aug2017_Collisions16_JSON.txt'
pass
elif era == "2017":
# jsonFile='/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions17/13TeV/ReReco/Cert_294927-306462_13TeV_EOY2017ReReco_Collisions17_JSON.txt'
pass
elif era == "2018":
# jsonFile='/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions18/13TeV/ReReco/Cert_314472-325175_13TeV_17SeptEarlyReReco2018ABC_PromptEraD_Collisions18_JSON.txt'
pass
else:
print "ERROR: Did not understand the given era! Should be one of 2016,2017,2018. Quitting."
exit(-1)
modulesToRun.append(eventCounterHistogramModule())
# Require lead electron SCEt > 35 GeV to keep the event
# preselection="(Electron_caloEnergy[0]/cosh(Electron_scEta[0]))>35"
# for stock, use regular Pt
#preselection = "Electron_pt[0] > 35"
# preselection="Electron_pt[0] > 100"
preselection="Electron_pt[0] > 45"
# preselection="Electron_pt[0]>45 || Muon_pt[0]>45 || (Muon_pt[0]>15 && Muon_pt[1]>8 && nJet>2 && Jet_pt[0]>23) || (Electron_pt[0]>17 && Electron_pt[1]>12 && nJet>2 && Jet_pt[0]>23)"
# remove preselection, as preselection is done in the custom2016SkimModule
keepAndDrop = "keepAndDrop.txt"
haddFileName = utils.GetOutputFilename(dataset, isMC)
# for crab
p = PostProcessor(
".",
inputFiles(),
cut=preselection,
outputbranchsel=keepAndDrop,
modules=modulesToRun,
provenance=True,
fwkJobReport=True,
jsonInput=runsAndLumis(),
haddFileName=haddFileName,
)
# interactive testing
#inputList = 'inputList_test.txt'
#p = PostProcessor(
# ".",
# utils.GetFileList(inputList),
# cut=preselection,
# outputbranchsel=keepAndDrop,
# branchsel=keepAndDrop,
# modules=modulesToRun,
# provenance=True,
# fwkJobReport=True,
# jsonInput=runsAndLumis(),
# haddFileName=haddFileName,
#)
p.run()