forked from cms-jet/PFNano
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindexpfnano.py
308 lines (253 loc) · 12.6 KB
/
indexpfnano.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
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
import os
import subprocess
import json
import argparse
parser = argparse.ArgumentParser(description="""
Index PFNano files. To add new files, add the LFN [1] to the
folders_to_index dictionary, following the existing structure.
Note: the file naming must follow a strict folder scheme,
since this script uses several of the intermediate folders
to deduce the metadata. This should be automatic, if you don't
alter the PFNano submission scripts. Examples:
Data:
/store/user/lpcpfnano/dryu/v2_2/2017/SingleMu2017/SingleMuon/SingleMuon_Run2017C/211102_162942/0000/*root
MC:
/store/user/lpcpfnano/jekrupa/v2_2/2017/WJetsToQQ/WJetsToQQ_HT-800toInf_TuneCP5_13TeV-madgraphMLM-pythia8/WJetsToQQ_HT-800toInf/211108_171840/0000/*root
[1] LFN = logical file name, which is a path starting with /store/group/lpcpfnano/...
""")
parser.add_argument("-v", "--version", type=str, required=True, help="Version string, e.g. v2_2 or v2_3")
args = parser.parse_args()
def get_children(parent):
#print(f"DEBUG : Call to get_children({parent})")
command = f"eos root://cmseos.fnal.gov ls -F {parent}"
#print(command)
result = subprocess.getoutput(command)#, stdout=subprocess.PIPE)
#print(result)
return result.split("\n")
def get_subfolders(parent):
subfolders = []
for x in get_children(parent):
if len(x) == 0:
continue
if x[-1] == "/":
subfolders.append(x)
return subfolders
folders_to_index = {
"v2_2": [
"/store/group/lpcpfnano/jdickins/v2_2/2016APV/ttHToBB",
"/store/group/lpcpfnano/jdickins/v2_2/2016/ttHToBB",
"/store/group/lpcpfnano/jdickins/v2_2/2017/ttHToBB",
"/store/group/lpcpfnano/jdickins/v2_2/2018/ttHToBB",
"/store/user/lpcpfnano/dryu/v2_2_1/2016/SingleMu2016",
"/store/user/lpcpfnano/dryu/v2_2_1/2017/SingleMu2017",
"/store/user/lpcpfnano/dryu/v2_2/2018/SingleMu2018",
"/store/user/lpcpfnano/jekrupa/v2_2/2016/JetHT2016",
"/store/user/lpcpfnano/jekrupa/v2_2/2017/JetHT2017",
"/store/user/lpcpfnano/jekrupa/v2_2/2018/JetHT2018",
"/store/user/lpcpfnano/cmantill/v2_2/2016/MET2016",
"/store/user/lpcpfnano/cmantill/v2_2/2017/MET2017",
"/store/user/lpcpfnano/cmantill/v2_2/2018/MET2018",
"/store/user/lpcpfnano/drankin/v2_2/2016/SingleElectron2016",
"/store/user/lpcpfnano/drankin/v2_2/2017/SingleElectron2017",
"/store/user/lpcpfnano/drankin/v2_2/2018/SingleElectron2018",
"/store/user/lpcpfnano/drankin/v2_2/2016/EGamma2016",
"/store/user/lpcpfnano/drankin/v2_2/2017/EGamma2017",
"/store/user/lpcpfnano/drankin/v2_2/2018/EGamma2018",
"/store/user/lpcpfnano/jekrupa/v2_2/2016APV/TTbar",
"/store/user/lpcpfnano/jekrupa/v2_2/2016/TTbar",
"/store/user/lpcpfnano/jekrupa/v2_2/2017/TTbar",
"/store/user/lpcpfnano/emoreno/v2_2/2018/TTbar",
"/store/user/lpcpfnano/drankin/v2_2/2016/TTbar",
"/store/user/lpcpfnano/drankin/v2_2/2016APV/TTbar",
"/store/user/lpcpfnano/drankin/v2_2/2017/TTbar",
"/store/user/lpcpfnano/drankin/v2_2/2018/TTbar",
"/store/user/lpcpfnano/yihan/v2_2/2016/TTbar",
"/store/user/lpcpfnano/yihan/v2_2/2016APV/TTbar",
"/store/user/lpcpfnano/yihan/v2_2/2017/TTbar",
"/store/user/lpcpfnano/yihan/v2_2/2018/TTbar",
"/store/user/lpcpfnano/yihan/v2_2/2016/QCD",
"/store/user/lpcpfnano/yihan/v2_2/2016APV/QCD",
"/store/user/lpcpfnano/jekrupa/v2_2/2017/QCD",
"/store/user/lpcpfnano/jekrupa/v2_2/2018/QCD",
"/store/user/lpcpfnano/jekrupa/v2_2/2016/WJetsToQQ",
"/store/user/lpcpfnano/jekrupa/v2_2/2016APV/WJetsToQQ",
"/store/user/lpcpfnano/jekrupa/v2_2/2017/WJetsToQQ",
"/store/user/lpcpfnano/jekrupa/v2_2/2018/WJetsToQQ",
"/store/user/lpcpfnano/jekrupa/v2_2/2016/ZJetsToQQ",
"/store/user/lpcpfnano/jekrupa/v2_2/2016APV/ZJetsToQQ",
"/store/user/lpcpfnano/jekrupa/v2_2/2017/ZJetsToQQ",
"/store/user/lpcpfnano/jekrupa/v2_2/2018/ZJetsToQQ",
"/store/user/lpcpfnano/pharris/v2_2/2016/SingleTop",
#"/store/user/lpcpfnano/pharris/v2_2/2016APV/SingleTop",
"/store/user/lpcpfnano/dryu/v2_2/2016APV/SingleTop",
"/store/user/lpcpfnano/pharris/v2_2/2017/SingleTop",
"/store/user/lpcpfnano/pharris/v2_2/2018/SingleTop",
"/store/user/lpcpfnano/drankin/v2_2/2016/WJetsToLNu",
"/store/user/lpcpfnano/drankin/v2_2/2016APV/WJetsToLNu",
"/store/user/lpcpfnano/drankin/v2_2/2017/WJetsToLNu",
"/store/user/lpcpfnano/drankin/v2_2/2018/WJetsToLNu",
"/store/user/lpcpfnano/cmantill/v2_2/2016/DYJetsToLL",
"/store/user/lpcpfnano/cmantill/v2_2/2016APV/DYJetsToLL",
"/store/user/lpcpfnano/cmantill/v2_2/2017/DYJetsToLL",
"/store/user/lpcpfnano/cmantill/v2_2/2018/DYJetsToLL",
"/store/user/lpcpfnano/cmantill/v2_2/2016/HWW",
"/store/user/lpcpfnano/cmantill/v2_2/2016APV/HWW",
"/store/user/lpcpfnano/cmantill/v2_2/2017/HWW",
"/store/user/lpcpfnano/cmantill/v2_2/2018/HWW",
"/store/user/lpcpfnano/cmantill/v2_2/2016/HTT",
"/store/user/lpcpfnano/cmantill/v2_2/2016APV/HTT",
"/store/user/lpcpfnano/cmantill/v2_2/2017/HTT",
"/store/user/lpcpfnano/cmantill/v2_2/2018/HTT",
"/store/user/lpcpfnano/dryu/v2_2/2016/VectorZPrime",
"/store/user/lpcpfnano/jekrupa/v2_2/2016APV/VectorZPrime",
"/store/user/lpcpfnano/jekrupa/v2_2/2017/VectorZPrime",
"/store/user/lpcpfnano/dryu/v2_2/2018/VectorZPrime",
"/store/group/lpcpfnano/jdickins/v2_2/2016APV/Diboson",
"/store/group/lpcpfnano/jdickins/v2_2/2016/Diboson",
"/store/group/lpcpfnano/jdickins/v2_2/2017/Diboson",
"/store/group/lpcpfnano/jdickins/v2_2/2018/Diboson",
"/store/group/lpcpfnano/jdickins/v2_2/2016APV/VBFHToBB",
"/store/group/lpcpfnano/jdickins/v2_2/2016/VBFHToBB",
"/store/group/lpcpfnano/jdickins/v2_2/2017/VBFHToBB",
"/store/group/lpcpfnano/jdickins/v2_2/2018/VBFHToBB",
"/store/group/lpcpfnano/jdickins/v2_2/2016APV/EWKV",
"/store/group/lpcpfnano/jdickins/v2_2/2016/EWKV",
"/store/group/lpcpfnano/jdickins/v2_2/2017/EWKV",
"/store/group/lpcpfnano/jdickins/v2_2/2018/EWKV",
"/store/group/lpcpfnano/jdickins/v2_2/2016APV/GluGluHToBB",
"/store/group/lpcpfnano/jdickins/v2_2/2016/GluGluHToBB",
"/store/group/lpcpfnano/jdickins/v2_2/2017/GluGluHToBB",
"/store/group/lpcpfnano/jdickins/v2_2/2018/GluGluHToBB",
],
"v2_3": [
"/store/group/lpcpfnano/cmantill/v2_3/2016/JetHT2016",
"/store/group/lpcpfnano/cmantill/v2_3/2016/ZGamma",
"/store/group/lpcpfnano/cmantill/v2_3/2016/HH",
"/store/group/lpcpfnano/cmantill/v2_3/2016/SingleTop",
"/store/group/lpcpfnano/cmantill/v2_3/2016/QCD",
"/store/group/lpcpfnano/cmantill/v2_3/2016/TTbar",
"/store/group/lpcpfnano/cmantill/v2_3/2016/HWW",
"/store/group/lpcpfnano/cmantill/v2_3/2016/ZJetsToQQ",
"/store/group/lpcpfnano/cmantill/v2_3/2016/WJetsToQQ",
"/store/group/lpcpfnano/cmantill/v2_3/2018/JetHT2018",
"/store/group/lpcpfnano/cmantill/v2_3/2018/ZGamma",
"/store/group/lpcpfnano/cmantill/v2_3/2018/TTbar",
"/store/group/lpcpfnano/cmantill/v2_3/2018/HH",
"/store/group/lpcpfnano/cmantill/v2_3/2018/SingleTop",
"/store/group/lpcpfnano/cmantill/v2_3/2018/QCD",
"/store/group/lpcpfnano/cmantill/v2_3/2018/HWW",
"/store/group/lpcpfnano/cmantill/v2_3/2018/WJetsToQQ",
"/store/group/lpcpfnano/cmantill/v2_3/2018/ZJetsToQQ",
"/store/group/lpcpfnano/cmantill/v2_3/2017/JetHT2017",
"/store/group/lpcpfnano/cmantill/v2_3/2017/HH",
"/store/group/lpcpfnano/cmantill/v2_3/2017/QCD",
"/store/group/lpcpfnano/cmantill/v2_3/2017/ZGamma",
"/store/group/lpcpfnano/cmantill/v2_3/2017/HWW",
"/store/group/lpcpfnano/cmantill/v2_3/2017/XHYPrivate",
"/store/group/lpcpfnano/cmantill/v2_3/2017/HH_gen",
"/store/group/lpcpfnano/cmantill/v2_3/2017/ZJetsToQQ",
"/store/group/lpcpfnano/cmantill/v2_3/2017/WJetsToQQ",
"/store/group/lpcpfnano/cmantill/v2_3/2016APV/ZGamma",
"/store/group/lpcpfnano/cmantill/v2_3/2016APV/TTbar",
"/store/group/lpcpfnano/cmantill/v2_3/2016APV/ZJetsToQQ",
"/store/group/lpcpfnano/cmantill/v2_3/2016APV/SingleTop",
"/store/group/lpcpfnano/cmantill/v2_3/2016APV/HH",
"/store/group/lpcpfnano/cmantill/v2_3/2016APV/QCD",
"/store/group/lpcpfnano/cmantill/v2_3/2016APV/HWW",
"/store/group/lpcpfnano/cmantill/v2_3/2016APV/WJetsToQQ",
"/store/group/lpcpfnano/cmantill/v2_3/2016APV/DYJetsToLL",
"/store/group/lpcpfnano/jdickins/v2_3/2016APV/TTbarBoosted",
"/store/group/lpcpfnano/jdickins/v2_3/2016/TTbarBoosted",
"/store/group/lpcpfnano/jdickins/v2_3/2017/TTbarBoosted",
"/store/group/lpcpfnano/jdickins/v2_3/2018/TTbarBoosted",
"/store/group/lpcpfnano/rkansal/v2_3/2016APV/GluGluHToBB",
"/store/group/lpcpfnano/rkansal/v2_3/2016APV/Diboson",
"/store/group/lpcpfnano/rkansal/v2_3/2016/GluGluHToBB",
"/store/group/lpcpfnano/rkansal/v2_3/2016/Diboson",
"/store/group/lpcpfnano/rkansal/v2_3/2018/GluGluHToBB",
"/store/group/lpcpfnano/rkansal/v2_3/2018/Diboson",
"/store/group/lpcpfnano/rkansal/v2_3/2017/SingleTop",
"/store/group/lpcpfnano/rkansal/v2_3/2017/ZJetsToQQ",
"/store/group/lpcpfnano/rkansal/v2_3/2017/QCD",
"/store/group/lpcpfnano/rkansal/v2_3/2017/TTbar",
"/store/group/lpcpfnano/rkansal/v2_3/2017/GluGluHToBB",
"/store/group/lpcpfnano/rkansal/v2_3/2017/Diboson",
"/store/group/lpcpfnano/rkansal/v2_3/2017/WJetsToQQ",
"/store/group/lpcpfnano/rkansal/v2_3/2017/XHYPrivate",
"/store/group/lpcpfnano/rkansal/v2_3/2017/HWW",
"/store/group/lpcpfnano/rkansal/v2_3/2017/HWW_backup",
"/store/group/lpcpfnano/jiyoo/v2_3/2016/DoubleEG2016",
"/store/group/lpcpfnano/jiyoo/v2_3/2016/DoubleMu2016",
"/store/group/lpcpfnano/jiyoo/v2_3/2016/MuonEG2016",
"/store/group/lpcpfnano/jiyoo/v2_3/2017/DoubleMu2017",
"/store/group/lpcpfnano/jiyoo/v2_3/2017/DoubleEG2017",
"/store/group/lpcpfnano/jiyoo/v2_3/2017/MuonEG2017",
"/store/group/lpcpfnano/jiyoo/v2_3/2018/DoubleMu2018",
"/store/group/lpcpfnano/jiyoo/v2_3/2018/MuonEG2018",
"/store/group/lpcpfnano/jiyoo/v2_3/2018/DoubleEG2018",
]
}
skip_list = [
"/store/group/lpcpfnano/jdickins/v2_2/2016APV/ttHToBB/ttHTobb_M125_TuneCP5_13TeV-powheg-pythia8/ttHToBB/220221_155934",
"/store/group/lpcpfnano/jdickins/v2_2/2016/ttHToBB/ttHTobb_M125_TuneCP5_13TeV-powheg-pythia8/ttHToBB/220217_210545",
"/store/group/lpcpfnano/jdickins/v2_2/2017/ttHToBB/ttHTobb_M125_TuneCP5_13TeV-powheg-pythia8/ttHToBB/220221_160323",
"/store/group/lpcpfnano/jdickins/v2_2/2018/ttHToBB/ttHTobb_M125_TuneCP5_13TeV-powheg-pythia8/ttHToBB/220221_160545",
]
skip_list = [os.path.normpath(x) for x in skip_list]
# Data path:
# .......................f1........................|...f2.....|..........f3.......|.....f4......|.f5.|....
# /store/user/lpcpfnano/dryu/v2_2/2017/SingleMu2017/SingleMuon/SingleMuon_Run2017C/211102_162942/0000/*root
#
# MC path:
# .......................f1........................|.......................f2..............................|..........f3.........|.....f4......|.f5.|....
# /store/user/lpcpfnano/jekrupa/v2_2/2017/WJetsToQQ/WJetsToQQ_HT-800toInf_TuneCP5_13TeV-madgraphMLM-pythia8/WJetsToQQ_HT-800toInf/211108_171840/0000/*root
# /store/user/lpcpfnano/cmantill/v2_2/2016/HWW/
index = {}
for f1 in folders_to_index[args.version]:
f1 = f1.rstrip("/")
print(f1)
year = f1.split("/")[-2]
sample_short = f1.split("/")[-1]
if not year in ["2016", "2016APV", "2017", "2018"]:
raise ValueError(f"I couldn't find the year in path {f1}")
if not year in index:
index[year] = {}
if not sample_short in index[year]:
index[year][sample_short] = {}
f1_subfolders = get_subfolders(f"{f1}")
for f2 in f1_subfolders:
print(f"\t/{f2}")
subsample_long = f2.replace("/", "") # This should be the actual dataset name
f2_subfolders = get_subfolders(f"{f1}/{f2}")
for f3 in f2_subfolders:
print(f"\t\t/{f3}")
subsample_short = f3.replace("/", "")
if not subsample_short in index[year][sample_short]:
index[year][sample_short][subsample_short] = []
f3_subfolders = get_subfolders(f"{f1}/{f2}/{f3}")
if len(f3_subfolders) >= 2:
print(f"WARNING : Found multiple timestamps for {f1}/{f2}/{f3}:")
# Remove anything in the skip list
filtered_list = []
this_skipped_list = []
for f3_subfolder in f3_subfolders:
full_path_norm = os.path.normpath(f"{f1}/{f2}/{f3}/{f3_subfolder}")
if not full_path_norm in skip_list:
filtered_list.append(f3_subfolder)
else:
this_skipped_list.append(full_path_norm)
f3_subfolders = filtered_list
if len(f3_subfolders) >= 2:
print(f3_subfolders)
print(f"WARNING: I'm keeping them all, but double check and add bad folders to skip_list if needed.")
else:
print(f"WARNING: One timestamp remaining after filtering, all good. The following folders were skipped:")
print(this_skipped_list)
for f4 in f3_subfolders: # Timestamp
f4_subfolders = get_subfolders(f"{f1}/{f2}/{f3}/{f4}")
for f5 in f4_subfolders: # 0000, 0001, ...
f5_children = get_children((f"{f1}/{f2}/{f3}/{f4}/{f5}"))
root_files = [f"{f1}/{f2}/{f3}/{f4}/{f5}/{x}".replace("//", "/") for x in f5_children if x[-5:] == ".root"]
index[year][sample_short][subsample_short].extend(root_files)
with open(f"pfnanoindex_{args.version}.json", "w") as f:
json.dump(index, f, sort_keys=True, indent=2)