-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrun_stage1.py
More file actions
288 lines (257 loc) · 7.36 KB
/
run_stage1.py
File metadata and controls
288 lines (257 loc) · 7.36 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
287
288
import time
import argparse
import traceback
from coffea.processor import DaskExecutor, Runner
from coffea.nanoevents import NanoAODSchema
from stage1.processor import DimuonProcessor
from stage1.preprocessor import load_samples
from python.io import (
mkdir,
save_stage1_output_to_parquet,
delete_existing_stage1_output,
)
from config.jec_parameters import jec_parameters as jec_pars
import dask
from dask.distributed import Client
from functools import partial
__all__ = ["dask"]
parser = argparse.ArgumentParser()
# Slurm cluster IP to use. If not specified, will create a local cluster
parser.add_argument(
"-sl",
"--slurm",
dest="slurm_port",
default=None,
action="store",
help="Slurm cluster port (if not specified, " "will create a local cluster)",
)
parser.add_argument(
"-y",
"--year",
dest="year",
default="2016",
action="store",
help="Year to process (2016, 2017 or 2018)",
)
parser.add_argument(
"-l",
"--label",
dest="label",
default="test",
action="store",
help="Unique run label (to create output path)",
)
parser.add_argument(
"-ch",
"--chunksize",
dest="chunksize",
default=100000,
action="store",
help="Approximate chunk size",
)
parser.add_argument(
"-mch",
"--maxchunks",
dest="maxchunks",
default=-1,
action="store",
help="Max. number of chunks",
)
parser.add_argument(
"-jec",
"--jec",
dest="jec_unc",
default=False,
action="store_true",
help="Enable JEC/JER uncertainties",
)
args = parser.parse_args()
node_ip = "128.211.149.133" # hammer-c000
# node_ip = '128.211.149.140' # hammer-c007
dash_local = f"{node_ip}:34875"
if args.slurm_port is None:
local_cluster = True
slurm_cluster_ip = ""
else:
local_cluster = False
slurm_cluster_ip = f"{node_ip}:{args.slurm_port}"
# max number of data chunks (per dataset) to process.
# by default processing all chunks
mch = None if int(args.maxchunks) < 0 else int(args.maxchunks)
# systematic variations of jet pT
if args.jec_unc:
pt_variations = (
["nominal"]
+ jec_pars["jec_variations"][args.year]
+ jec_pars["jer_variations"][args.year]
)
else:
pt_variations = ["nominal"]
parameters = {
# < general settings >
"year": args.year,
"label": args.label,
"local_cluster": local_cluster,
"slurm_cluster_ip": slurm_cluster_ip,
"global_path": "/depot/cms/hmm/copperhead/",
#
# < input data settings >
# 'xrootd': True,
# 'server': 'root://xrootd.rcac.purdue.edu/', # Purdue xrootd
# 'server': 'root://cmsxrootd.fnal.gov/', # FNAL xrootd
"xrootd": False,
"server": "/mnt/hadoop/",
"datasets_from": "purdue",
"chunksize": int(args.chunksize),
"maxchunks": mch,
#
# < processing settings >
"regions": ["h-sidebands", "h-peak"], # , "z-peak"]
"pt_variations": pt_variations,
"do_btag_syst": False,
"save_output": True,
"do_timer": False,
}
# submit processing jobs using coffea's DaskExecutor
def submit_job(parameters):
# mkdir(parameters["out_path"])
out_dir = parameters["global_path"]
mkdir(out_dir)
out_dir += "/" + parameters["label"]
mkdir(out_dir)
out_dir += "/" + "stage1_output"
mkdir(out_dir)
out_dir += "/" + parameters["year"]
mkdir(out_dir)
executor_args = {"client": parameters["client"], "retries": 0}
processor_args = {
"samp_info": parameters["samp_infos"],
"do_timer": parameters["do_timer"],
"do_btag_syst": parameters["do_btag_syst"],
"regions": parameters["regions"],
"pt_variations": parameters["pt_variations"],
"apply_to_output": partial(save_stage1_output_to_parquet, out_dir=out_dir),
}
executor = DaskExecutor(**executor_args)
run = Runner(
executor=executor,
schema=NanoAODSchema,
chunksize=parameters["chunksize"],
maxchunks=parameters["maxchunks"],
)
try:
run(
parameters["samp_infos"].fileset,
"Events",
processor_instance=DimuonProcessor(**processor_args),
)
except Exception as e:
tb = traceback.format_exc()
return "Failed: " + str(e) + " " + tb
return "Success!"
if __name__ == "__main__":
tick = time.time()
timings = {}
# prepare Dask client
if parameters["local_cluster"]:
# create local cluster
parameters["client"] = Client(
processes=True,
n_workers=40,
dashboard_address=dash_local,
threads_per_worker=1,
memory_limit="12GB",
)
else:
# connect to existing Slurm cluster
parameters["client"] = Client(parameters["slurm_cluster_ip"])
print("Client created")
# datasets to process (split into groups for convenience)
smp = {
# 'single_file': [
# 'test_file',
# ],
"data": [
# 'test_file_data_A',
"data_A",
"data_B",
"data_C",
"data_D",
"data_E",
"data_F",
"data_G",
"data_H",
],
"signal": [
"ggh_amcPS",
"vbf_powhegPS",
"vbf_powheg_herwig",
"vbf_powheg_dipole",
"tth",
"wph",
"wmh",
"zh",
],
"main_mc": [
"dy_m105_160_amc",
# "dy_m105_160_mg",
"dy_m105_160_vbf_amc",
# "ewk_lljj_mll105_160_py",
"ewk_lljj_mll105_160_ptj0",
"ewk_lljj_mll105_160_py_dipole",
"ttjets_dl",
# "ewk_m50"
],
"other_mc": [
"ttjets_sl",
"ttz",
"ttw",
"st_tw_top",
"st_tw_antitop",
"ww_2l2nu",
"wz_2l2q",
"wz_3lnu",
"wz_1l1nu2q",
"zz",
],
}
# select which datasets to process
datasets_mc = []
datasets_data = []
for group, samples in smp.items():
for sample in samples:
# if sample != 'data_B':
# if sample != 'dy_m105_160_amc':
# if sample != "vbf_powheg_dipole":
# continue
if group == "data":
# if 'test' not in sample:
# continue
# continue
datasets_data.append(sample)
else:
continue
# if (group != "main_mc") & (group != "signal"):
# if (group != "signal"):
# if (group != "main_mc"):
# continue
datasets_mc.append(sample)
to_process = {"MC": datasets_mc, "DATA": datasets_data}
for lbl, datasets in to_process.items():
if len(datasets) == 0:
continue
print(f"Processing {lbl}")
tick1 = time.time()
# load lists of ROOT files, compute lumi weights
parameters["samp_infos"] = load_samples(datasets, parameters)
timings[f"load {lbl}"] = time.time() - tick1
tick2 = time.time()
# run main processing
delete_existing_stage1_output(datasets, parameters)
out = submit_job(parameters)
timings[f"process {lbl}"] = time.time() - tick2
print(out)
elapsed = round(time.time() - tick, 3)
print(f"Finished everything in {elapsed} s.")
print("Timing breakdown:")
print(timings)