Repository navigation
Expand file tree
/
Copy pathConfigureJobs.py
More file actions
286 lines (282 loc) · 10.2 KB
/
Copy pathConfigureJobs.py
File metadata and controls
286 lines (282 loc) · 10.2 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import datetime
import UserInput
import fnmatch
import glob
import os
import json
import array
import string
import configparser
def get2DBinning(xvar="mjj", yvar="etajj", analysis='WZ'):
#return (array.array('d', [500, 1000,1500, 2000, 2500]),
# [0, 150, 300, 450] # for MT(WZ)
# return (array.array('d', [500, 1000, 1350, 1750, 2000, 2500]),
xbinning = []
ybinning = []
if xvar == "mjj":
xbinning = array.array('d', [500, 1000,1500, 2000, 2500])
#xbinning = array.array('d', [500, 1000, 1350, 1750, 2500])
if yvar == 'etajj':
ybinning = [2.5, 4, 5, 20]
#if yvar == 'etajj':
# ybinning = [2.5, 4, 5.5, 20]
elif yvar == 'dRjj':
ybinning = [0, 5, 6, 20]
return (xbinning, ybinning)
def getChannels(analysis='ZZ'):
if analysis == 'ZZ':
return ["eeee", "eemm", "mmee", "mmmm"]
def getManagerPath():
config = configparser.ConfigParser()
config.read_file(open("Templates/config.%s" % os.environ["USER"]))
if "dataset_manager_path" not in config['Setup']:
raise ValueError("dataset_manager_path not specified in config file Template/config.%s"
% os.environ["USER"])
return config['Setup']['dataset_manager_path'] + "/"
def getCombinePath():
config = configparser.ConfigParser()
config.read_file(open("Templates/config.%s" % os.environ["USER"]))
if "combine_path" not in config['Setup']:
raise ValueError("dataset_manager_path not specified in config file Template/config.%s"
% os.environ["USER"])
return config['Setup']['combine_path'] + "/"
def getListOfEWKFilenames():
return [
#"wz3lnu-amcnlo",#old 2018 ntuples
"wz3lnu-powheg",#New 2018 ntuples
# Use jet binned WZ samples for subtraction by default
#"wz3lnu-mgmlm-0j",
#"wz3lnu-mgmlm-1j",
#"wz3lnu-mgmlm-2j",
#"wz3lnu-mgmlm-3j",
#"wlljj-ewk",
"zz4l-powheg",
#"zz4ljj-ewk",
#"zz2l2vjj-ewk",
#"tzq",
#"ttz",
#"ttw",
#"zzz",
#"wwz",
#"www",
#"ww",
#"zg",
"ggZZ4e",
"ggZZ4m",
"ggZZ4t",
"ggZZ2e2mu",
"ggZZ2e2tau",
"ggZZ2mu2tau",
]
def getListOfEWK():
return [
"zz4l-powheg",
"ggZZ4e",
"ggZZ4m",
"ggZZ4t",
"ggZZ2e2mu",
"ggZZ2e2tau",
"ggZZ2mu2tau",
]
def getListOfDYFilenames():
return[
"DYJetsToLL_M10to50",
"DYJetsToLLM-50",
]
def getListOfNonpromptFilenames():
return ["tt-lep",
"tt-jets",
#"st-schan",
#"st-tchan-t",
#"st-tchan-tbar",
#"st-tw",
#"st-tbarw",
##"DYm50",
#"DYm50-1j",
#"DYm50-2j",
#"DYm50-3j",
#"DYm50-4j",
]
def getListOfHZZFilenames():
return ["ggHZZ",
"vbfHZZ",
"ttH_HToZZ_4L",
"WminusHToZZ",
"WplusHToZZ",
"ZHToZZ_4L"
]
def getListOfggZZFilenames():
return ["ggZZ4e",
"ggZZ4m",
"ggZZ4t",
"ggZZ2e2mu",
"ggZZ2e2tau",
"ggZZ2mu2tau"
]
def getJobName(sample_name, analysis, selection, version):
date = '{:%Y-%m-%d}'.format(datetime.date.today())
selection = selection.replace(";",",")
selections = selection.split(",")
selection_name = "To".join([selections[0],selections[-1]]) \
if len(selections) > 1 else selections[0]
return '-'.join([date, sample_name, analysis, selection_name,
("v%s" % version) if version.isdigit() else version])
def getNumberAndSizeOfLocalFiles(path_to_files):
file_list = glob.glob(path_to_files)
return (len(file_list), sum([os.path.getsize(f)/1000000 for f in file_list]))
def getNumberAndSizeOfHDFSFiles(file_path):
file_info = []
for line in out.splitlines():
split = line.split()
if len(split) != 9:
continue
file_info.append(float(split[4].rstrip("mkg")))
return (0,0) if len(file_info) == 0 else (len(file_info), sum(file_info))
def getListOfHDFSFiles(file_path):
try:
out = subprocess.check_output(["hdfs", "dfs", "-ls", file_path.replace("/hdfs", "")])
except subprocess.CalledProcessError as error:
logging.warning(error)
return []
files = []
for line in out.splitlines():
split = line.split(" ", 1)
if len(split) != 2:
continue
elif "root" in split[1]:
files.append("/"+split[1])
return files
def getListOfFiles(filelist, selection, manager_path=""):
if manager_path is "":
manager_path = getManagerPath()
data_path = "%s/ZZ4lRun2DatasetManager/FileInfo" % manager_path
data_info = UserInput.readAllJson("/".join([data_path, "%s.json" % "data/*"]))
mc_info = UserInput.readAllJson("/".join([data_path, "%s.json" % "montecarlo/*"]))
valid_names = data_info.keys() + mc_info.keys()
names = []
for name in filelist:
if "ZZ4l2016" in name:
dataset_file = manager_path + \
"ZZ4lRun2DatasetManager/FileInfo/ZZ4l2016/%s.json" % selection
allnames = json.load(open(dataset_file)).keys()
print allnames
if "nodata" in name:
nodata = [x for x in allnames if "data" not in x]
names += nodata
elif "data" in name:
names += [x for x in allnames if "data" in x]
else:
names += allnames
elif "ZZ4l2017" in name:
dataset_file = manager_path + \
"ZZ4lRun2DatasetManager/FileInfo/ZZ4l2017/%s.json" % selection
allnames = json.load(open(dataset_file)).keys()
print allnames
if "nodata" in name:
nodata = [x for x in allnames if "data" not in x]
names += nodata
elif "data" in name:
names += [x for x in allnames if "data" in x]
else:
names += allnames
elif "ZZ4l2018" in name:
dataset_file = manager_path + \
"ZZ4lRun2DatasetManager/FileInfo/ZZ4l2018/%s.json" % selection
allnames = json.load(open(dataset_file)).keys()
print allnames
if "nodata" in name:
nodata = [x for x in allnames if "data" not in x]
names += nodata
elif "data" in name:
names += [x for x in allnames if "data" in x]
else:
names += allnames
elif "*" in name:
names += fnmatch.filter(valid_names, name)
else:
if name.split("__")[0] not in valid_names:
print "%s is not a valid name" % name
continue
names += [name]
return [str(i) for i in names]
def fillTemplatedFile(template_file_name, out_file_name, template_dict):
with open(template_file_name, "r") as templateFile:
source = string.Template(templateFile.read())
result = source.substitute(template_dict)
with open(out_file_name, "w") as outFile:
outFile.write(result)
def getListOfFilesWithXSec(filelist, manager_path=""):
if manager_path is "":
manager_path = getManagerPath()
data_path = "%s/ZZ4lRun2DatasetManager/FileInfo" % manager_path
files = getListOfFiles(filelist, "ntuples", manager_path)
#files = getListOfFiles(filelist, "2018Data", manager_path)
mc_info = UserInput.readAllJson("/".join([data_path, "%s.json" % "montecarlo/*"]))
info = {}
for file_name in files:
if "data" in file_name:
info.update({file_name : 1})
else:
file_info = mc_info[file_name.split("__")[0]]
kfac = file_info["kfactor"] if "kfactor" in file_info.keys() else 1
info.update({file_name : file_info["cross_section"]*kfac})
return info
def getPreviousStep(selection, analysis):
selection_map = {}
if analysis == "ZZ4l2016":
selection_map = { "ntuples" : "ntuples",
"preselection" : "ntuples",
"4lCRBase" : "ntuples"
}
elif analysis == "ZplusL2016":
selection_map = { "ntuples": "ntuples",
"ZplusLBase" : "ntuples"
}
elif analysis == "ZZ4l2017":
selection_map = { "ntuples" : "ntuples",
"preselection" : "ntuples",
"4lCRBase" : "ntuples"
}
elif analysis == "ZplusL2017":
selection_map = { "ntuples": "ntuples",
"ZplusLBase" : "ntuples"
}
elif analysis == "ZZ4l2018":
selection_map = { "ntuples" : "ntuples",
"preselection" : "ntuples",
"4lCRBase" : "ntuples"
}
elif analysis == "ZplusL2018":
selection_map = { "ntuples": "ntuples",
"ZplusLBase" : "ntuples"
}
selection = selection.replace(";",",")
first_selection = selection.split(",")[0].strip()
if first_selection not in selection_map.keys():
if "preselection" in first_selection:
first_selection = "preselection"
else:
raise ValueError("Invalid selection '%s'. Valid selections are:"
"%s" % (first_selection, selection_map.keys()))
return selection_map[first_selection]
def getInputFilesPath(sample_name, selection, analysis, manager_path=""):
if manager_path is "":
manager_path = getManagerPath()
data_path = "%s/ZZ4lRun2DatasetManager/FileInfo" % manager_path
input_file_name = "/".join([data_path, analysis, "%s.json" %
selection])
input_files = UserInput.readJson(input_file_name)
if sample_name not in input_files.keys():
raise ValueError("Invalid input file %s. Input file must correspond"
" to a definition in %s" % (sample_name, input_file_name))
filename = input_files[sample_name]['file_path']
return filename
def getCutsJsonName(selection, analysis):
return "/".join(["Cuts", analysis, selection + ".json"])
def getTriggerName(sample_name, analysis, selection):
trigger_names = ["MuonEG", "DoubleMuon", "DoubleEG", "SingleMuon", "SingleElectron"]
if "data" in sample_name and getPreviousStep(selection, analysis) == "ntuples":
for name in trigger_names:
if name in sample_name:
return "-t " + name
return "-t MonteCarlo"