-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrun_stage3.py
More file actions
146 lines (130 loc) · 3.87 KB
/
run_stage3.py
File metadata and controls
146 lines (130 loc) · 3.87 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
import argparse
import dask
from dask.distributed import Client
from config.variables import variables_lookup
from stage3.plotter import plotter
from stage3.make_templates import to_templates
from stage3.make_datacards import build_datacards
__all__ = ["dask"]
parser = argparse.ArgumentParser()
parser.add_argument(
"-y", "--years", nargs="+", help="Years to process", default=["2018"]
)
parser.add_argument(
"-sl",
"--slurm",
dest="slurm_port",
default=None,
action="store",
help="Slurm cluster port (if not specified, will create a local cluster)",
)
args = parser.parse_args()
# Dask client settings
use_local_cluster = args.slurm_port is None
node_ip = "128.211.149.133"
if use_local_cluster:
ncpus_local = 40
slurm_cluster_ip = ""
dashboard_address = f"{node_ip}:34875"
else:
slurm_cluster_ip = f"{node_ip}:{args.slurm_port}"
dashboard_address = f"{node_ip}:8787"
# global parameters
parameters = {
# < general settings >
"slurm_cluster_ip": slurm_cluster_ip,
"years": args.years,
"global_path": "/depot/cms/hmm/copperhead/",
"label": "test",
"channels": ["vbf"],
"regions": ["h-peak", "h-sidebands"],
"syst_variations": ["nominal"],
#
# < plotting settings >
"plot_vars": [], # "dimuon_mass"],
"variables_lookup": variables_lookup,
"save_plots": True,
"plot_ratio": True,
"plots_path": "./plots/2022apr10/",
"dnn_models": {
"vbf": ["pytorch_test"],
},
"bdt_models": {},
#
# < templates and datacards >
"save_templates": True,
"templates_vars": [], # "dimuon_mass"],
}
parameters["grouping"] = {
"data_A": "Data",
"data_B": "Data",
"data_C": "Data",
"data_D": "Data",
"data_E": "Data",
"data_F": "Data",
"data_G": "Data",
"data_H": "Data",
"dy_m105_160_amc": "DY",
"dy_m105_160_vbf_amc": "DY",
"ewk_lljj_mll105_160_py_dipole": "EWK",
"ttjets_dl": "TT+ST",
"ttjets_sl": "TT+ST",
"ttw": "TT+ST",
"ttz": "TT+ST",
"st_tw_top": "TT+ST",
"st_tw_antitop": "TT+ST",
"ww_2l2nu": "VV",
"wz_2l2q": "VV",
"wz_1l1nu2q": "VV",
"wz_3lnu": "VV",
"zz": "VV",
"www": "VVV",
"wwz": "VVV",
"wzz": "VVV",
"zzz": "VVV",
"ggh_amcPS": "ggH",
"vbf_powheg_dipole": "VBF",
}
# parameters["grouping"] = {"vbf_powheg_dipole": "VBF",}
parameters["plot_groups"] = {
"stack": ["DY", "EWK", "TT+ST", "VV", "VVV"],
"step": ["VBF", "ggH"],
"errorbar": ["Data"],
}
if __name__ == "__main__":
if use_local_cluster:
print(
f"Creating local cluster with {ncpus_local} workers."
f" Dashboard address: {dashboard_address}"
)
client = Client(
processes=True,
dashboard_address=dashboard_address,
n_workers=ncpus_local,
threads_per_worker=1,
memory_limit="4GB",
)
else:
print(
f"Connecting to Slurm cluster at {slurm_cluster_ip}."
f" Dashboard address: {dashboard_address}"
)
client = Client(parameters["slurm_cluster_ip"])
parameters["ncpus"] = len(client.scheduler_info()["workers"])
print(f"Connected to cluster! #CPUs = {parameters['ncpus']}")
# add MVA scores to the list of variables to plot
dnn_models = list(parameters["dnn_models"].values())
bdt_models = list(parameters["bdt_models"].values())
for models in dnn_models + bdt_models:
for model in models:
parameters["plot_vars"] += ["score_" + model]
parameters["templates_vars"] += ["score_" + model]
parameters["datasets"] = parameters["grouping"].keys()
# make plots
yields = plotter(client, parameters)
print(yields)
# save templates to ROOT files
yield_df = to_templates(client, parameters)
print(yield_df)
# make datacards
build_datacards("score_pytorch_test", yield_df, parameters)