ATLAS Offline Software
Loading...
Searching...
No Matches
RatesOverlapAnalysis.py
Go to the documentation of this file.
1#!/usr/bin/env python
2#
3# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4#
5
6from glob import glob
7import os, shutil
8import argparse
9import json
10import pandas as pd
11import re
12
13# ------------------------------------------------------------------------------------------------------
14# SET UP
15# ------------------------------------------------------------------------------------------------------
16
17parser = argparse.ArgumentParser(description='Compare the rates of different streams')
18parser.add_argument('--HLTMenu', type=str, help='HLT Menu File as input')
19parser.add_argument('--workdir', type=str, default='stream_analysis', help='Working directory')
20parser.add_argument('--targetlumi', type=float, default=2.0e34, help='Target luminosity')
21parser.add_argument('--maxEvents', type=int, default=-1, help='Max events')
22parser.add_argument('aod_dir', type=str, help='Directory containing AOD files from a rate reprocessing')
23parser.add_argument('--l1_ps', type=str, help='L1 PSK JSON file from the Rulebook')
24parser.add_argument('--hlt_in', type=str, help='JSON file from the Rulebook with the PSK values')
25parser.add_argument('--hlt_ps_stream0', '-psS0', type=str, default='HLTPrescale_stream0.json',
26 help='JSON file with the HLT PS for a single stream selected')
27parser.add_argument('--hlt_ps_stream', '-psS', type=str, default='HLTPrescale_stream.json',
28 help='JSON with the HLT PS for both stream selected')
29parser.add_argument('--hlt_ps_chain', '-psC',type=str, default='HLTPrescale_chain.json',
30 help='JSON with the HLT PS when the chosen chain is disabled')
31parser.add_argument('--hlt_ps_chain_set', '-psCS', type=str, default='HLTPrescale_chainSet.json',
32 help='JSON with the HLT PS for the chain set chosen')
33parser.add_argument('--hlt_ps_chain_ref', '-psCR', type=str, default='HLTPrescale_chain_ref.json',
34 help='JSON with the HLT PS for the reference chain in chain comparison')
35parser.add_argument('--hlt_ps_chain_comp', '-psCC', type=str, default='HLTPrescale_chain_comp.json',
36 help='JSON with the HLT PS for the compared chain in chain comparison')
37parser.add_argument('--stream0', type=str, default='Main',
38 help='Reference stream for stream and chain analysis, default is Main')
39parser.add_argument('--stream', nargs='+', type=str, default=' ',
40 help='List of streams to compare to stream0')
41parser.add_argument('--chain', nargs='+', type=str, default=' ',
42 help='List of chains to compare to stream0')
43parser.add_argument('--chain_set', nargs='+', type=str, default=' ',
44 help='Set of chains get the unique rate of')
45parser.add_argument('--chain_comp', nargs='+', type=str, default=' ',
46 help='List of chains to compare to the first chain in the list')
47parser.add_argument('--stream_out', type=str, default='streamRates.txt',
48 help='output stream analysis file as a txt file')
49parser.add_argument('--chain_out', type=str, default='chainRates.txt',
50 help='output chain analysis file as a txt file')
51parser.add_argument('--chain_comp_out', type=str, default='chainCompRates.csv',
52 help='output chain comparison file as a csv file')
53parser.add_argument("--force", "-f", default=False, action="store_true", help="Overwrite existing output directory")
54
55
56args = parser.parse_args()
57
58
59# Make working dir if needed
60try:
61 os.mkdir(args.workdir)
62except OSError:
63 if args.force:
64 shutil.rmtree(args.workdir)
65 os.mkdir(args.workdir)
66 if not args.force:
67 print("\nthe output directory already exists, please clean up or be more creative :)")
68 print("or use --force if you want to overwirte the existing output directory.\n")
69 exit()
70
71
72
73# Glob input files with abs path
74filesIn = glob(f'{os.path.abspath(args.aod_dir)}/*')
75print(f"Found {len(filesIn)} input files in '{args.aod_dir}'")
76
77HLTMenu_filen = args.HLTMenu.split('/', 1)[1] if '/' in args.HLTMenu else args.HLTMenu
78hlt_in_filen = args.hlt_in.split('/', 1)[1] if '/' in args.hlt_in else args.hlt_in
79l1_ps_filen = args.l1_ps.split('/', 1)[1] if '/' in args.l1_ps else args.l1_ps
80
81hlt_ps_stream0_filen = args.hlt_ps_stream0.split('/', 1)[1] if '/' in args.hlt_ps_stream0 else args.hlt_ps_stream0
82hlt_ps_stream_filen = args.hlt_ps_stream.split('/', 1)[1] if '/' in args.hlt_ps_stream else args.hlt_ps_stream
83hlt_ps_chain_filen = args.hlt_ps_chain.split('/', 1)[1] if '/' in args.hlt_ps_chain else args.hlt_ps_chain
84hlt_ps_chain_set_filen = args.hlt_ps_chain_set.split('/', 1)[1] if '/' in args.hlt_ps_chain_set else args.hlt_ps_chain_set
85hlt_ps_chain_ref_filen = args.hlt_ps_chain_ref.split('/', 1)[1] if '/' in args.hlt_ps_chain_ref else args.hlt_ps_chain_ref
86hlt_ps_chain_comp_filen = args.hlt_ps_chain_comp.split('/', 1)[1] if '/' in args.hlt_ps_chain_comp else args.hlt_ps_chain_comp
87
88stream0_filen = args.stream0.split('/', 1)[1] if '/' in args.stream0 else args.stream0
89stream_filen = args.stream.split('/', 1)[1] if '/' in args.stream else args.stream
90chain_filen = args.chain.split('/', 1)[1] if '/' in args.chain else args.chain
91chain_set_filen = args.chain_set.split('/', 1)[1] if '/' in args.chain_set else args.chain_set
92chain_comp_filen = args.chain_comp.split('/', 1)[1] if '/' in args.chain_comp else args.chain_comp
93
94output_stream_filen = args.stream_out.split('/', 1)[1] if '/' in args.stream_out else args.stream_out
95output_chain_filen = args.chain_out.split('/', 1)[1] if '/' in args.chain_out else args.chain_out
96output_chain_comp_filen = args.chain_comp_out.split('/', 1)[1] if '/' in args.chain_comp_out else args.chain_comp_out
97
98shutil.copy(args.HLTMenu, f"{args.workdir}/{HLTMenu_filen}")
99shutil.copy(args.l1_ps, f"{args.workdir}/{l1_ps_filen}")
100shutil.copy(args.hlt_in, f"{args.workdir}/{hlt_in_filen}")
101
102origdir = os.getcwd()
103os.chdir(args.workdir)
104
105cmd_total = [
106 '--inputPrescalesHLTJSON', hlt_in_filen,
107 '--outputPrescalesHLTJSON1', hlt_ps_stream0_filen,
108 '--outputPrescalesHLTJSON2', hlt_ps_stream_filen,
109 '--stream0', stream0_filen,
110 '--stream', stream_filen,
111 '--chain', chain_filen,
112 '--chainSet', chain_set_filen,
113 '--chainComp', chain_comp_filen,
114 ]
115
116# ------------------------------------------------------------------------------------------------------
117# STREAM AND CHAIN SELECTION PART OF THE CODE
118# ------------------------------------------------------------------------------------------------------
119
120def stream_json(menu_in, psks_in, stream1, stream2):
121 f = open(menu_in)
122 menu = json.load(f)
123
124 h = open(psks_in)
125 psks = json.load(h)
126
127 dict_stream1 = {}
128 dict_stream2 = {}
129 for i in menu['chains']: # go through all the chains
130 for k in psks['prescales']: # go through all the chains in the psk_in (k)
131 if i == k: # make sure you work with the same chains
132 for j in menu['chains'][i]['streams']:
133 if j == stream1:
134 dict_stream1[i] = {"hash": menu['chains'][i]['nameHash'], "prescale": psks['prescales'][k]['prescale'],
135 "enabled": True}
136 dict_stream2[i] = {"hash": menu['chains'][i]['nameHash'], "prescale": psks['prescales'][k]['prescale'],
137 "enabled": True}
138 elif j == stream2:
139 dict_stream2[i] = {"hash": menu['chains'][i]['nameHash'], "prescale": psks['prescales'][k]['prescale'],
140 "enabled": True}
141 dict_stream1[i] = {"hash": menu['chains'][i]['nameHash'], "prescale": -1, "enabled": False}
142 else:
143 dict_stream1[i] = {"hash": menu['chains'][i]['nameHash'], "prescale": -1, "enabled": False}
144 dict_stream2[i] = {"hash": menu['chains'][i]['nameHash'], "prescale": -1, "enabled": False}
145 return dict_stream1, dict_stream2
146
147def chain_json(menu_in, psks_in, chain, stream):
148 dict_stream = {}
149 dict_chain = {}
150
151 f = open(menu_in)
152 menu = json.load(f)
153
154 h = open(psks_in)
155 psks = json.load(h)
156
157 for i in menu['chains']: # go through all the chains
158 for k in psks['prescales']: # go through all the chains in the psk_in (k)
159 if i == k: # make sure you work with the same chains
160 for j in menu['chains'][i]['streams']: # go through all the streams
161 if j == stream:
162 dict_stream[i] = {"hash": menu['chains'][i]['nameHash'], "prescale": psks['prescales'][k]['prescale'],
163 "enabled": True}
164 dict_chain[i] = {"hash": menu['chains'][i]['nameHash'], "prescale": psks['prescales'][k]['prescale'],
165 "enabled": True}
166 if k == chain:
167 dict_stream[i] = {"hash": menu['chains'][i]['nameHash'],
168 "prescale": psks['prescales'][k]['prescale'], "enabled": True}
169 dict_chain[i] = {"hash": menu['chains'][i]['nameHash'], "prescale": -1, "enabled": False} # here chain is the one when it is DISABLED
170 return dict_stream, dict_chain
171
172def chain_comp_json(menu_in, ref_chain, comp_chain):
173 # PSKs are set to 1! no need for input prescales
174 f = open(menu_in)
175 menu = json.load(f)
176
177 dict_chain = {}
178
179 for i in menu['chains']:
180 if i == ref_chain:
181 dict_chain[i] = {"hash": menu['chains'][i]['nameHash'], "prescale": 1, "enabled": True}
182 elif i == comp_chain:
183 dict_chain[i] = {"hash": menu['chains'][i]['nameHash'], "prescale": 1, "enabled": True}
184 else:
185 dict_chain[i] = {"hash": menu['chains'][i]['nameHash'], "prescale": -1, "enabled": False}
186
187 return dict_chain
188
189def chain_ref_json(menu_in, chain):
190 # PSKs are set to 1! no need for input prescales
191 f = open(menu_in)
192 menu = json.load(f)
193
194 dict_chain = {}
195
196 for i in menu['chains']:
197 if i == chain:
198 dict_chain[i] = {"hash": menu['chains'][i]['nameHash'], "prescale": 1, "enabled": True}
199 else:
200 dict_chain[i] = {"hash": menu['chains'][i]['nameHash'], "prescale": -1, "enabled": False}
201
202 return dict_chain
203
204def psk_file(dict, psk_file):
205 psk_dict = {
206 "filetype": "hltprescale",
207 "name": "Physics_pp_2.0e+34_2340b",
208 "prescales":dict
209 }
210
211 with open(psk_file, 'w') as file:
212 json.dump(psk_dict, file, indent=4)
213
214def chain_set_json(menu_in, psks_in, chains):
215 f = open(menu_in)
216 menu = json.load(f)
217
218 h = open(psks_in)
219 psks = json.load(h)
220
221 dict_chain_set = {}
222
223 for i in menu['chains']: # go through all the chains
224 for k in psks['prescales']: # go through all the chains in the psk_in (k)
225 if i == k:
226 dict_chain_set[i] = {"hash": menu['chains'][i]['nameHash'], "prescale": psks['prescales'][k]['prescale'],
227 "enabled": True}
228 for j in range(len(chains)):
229 if i == chains[j]:
230 dict_chain_set[i] = {"hash": menu['chains'][i]['nameHash'], "prescale": -1, "enabled": False}
231
232 return dict_chain_set
233
234
235# ------------------------------------------------------------------------------------------------------------
236# GETTING REGEX INPUTS
237# ------------------------------------------------------------------------------------------------------------
238
239def chain_regex(menu_in):
240
241 f = open(menu_in)
242 menu = json.load(f)
243
244 while True:
245 regex_input = input("RegEx expression: ")
246
247 list_of_chains = []
248 chains_to_analyse = []
249
250 for i in menu['chains']:
251 list_of_chains.append(i)
252
253 m = 0
254 for chain in list_of_chains:
255 if re.match(regex_input, chain):
256 m += 1
257 chains_to_analyse.append(chain)
258 else:
259 continue
260
261 if m != 0:
262 print('These are the chains you are trying to compare: ', "\n".join(chains_to_analyse))
263 user_conf = input('Are you sure you want to continue? [y/n]')
264 if user_conf.lower() in ["yes", "y"]:
265 print("sure, let's go")
266 return chains_to_analyse
267 if user_conf.lower() in ["no", 'n']:
268 print("alright, then try again")
269 else:
270 print('Are you sure you are RegEx entering the expression correctly? Try again :)')
271
272# -------------------------------------------------------------------------------------------------------------------
273# RATES ANALYSIS
274# -------------------------------------------------------------------------------------------------------------------
275
276# Run full rates analysis using RatesAnalysisProcessingWrapper.py
277def exec_rates(hlt_ps, dir):
278
279 #filesIn_str = "','".join(filesIn)
280
281 cmd_rates = [
282 'RatesAnalysisProcessingWrapper.py',
283 '--hlt_ps', hlt_ps,
284 '--l1_ps', l1_ps_filen,
285 '--targetlumi', str(args.targetlumi),
286 args.aod_dir,
287 '--workdir', dir
288 ]
289
290 if args.maxEvents>0:
291 cmd_rates += ['--maxEvents',str(args.maxEvents)]
292
293 command = ' '.join(cmd_rates)
294
295 status = os.WEXITSTATUS(os.system(command))
296 if status != 0:
297 exit('fail')
298
299# ------------------------------------------------------------------------------------------------------------
300# GETTING THE STREAM AND CHAIN RATE - CSVs
301# ------------------------------------------------------------------------------------------------------------
302
303def stream_rate(stream1, stream2, dir):
304
305 df_stream0 = pd.read_csv(f"{dir}/output/csv/Table_Rate_Group_HLT_All.csv")
306 df_stream0.set_index('Name', inplace=True)
307 rate0 = float(df_stream0.loc['RATE_GLOBAL_HLT']['Weighted PS Rate [Hz]'])
308 rate0err = float(df_stream0.loc['RATE_GLOBAL_HLT']['Weighted PS Rate Err [Hz]'])
309
310 df_global = pd.read_csv(f"{stream2}/output/csv/Table_Rate_Group_HLT_All.csv")
311 df_global.set_index('Name', inplace=True)
312 rateglobal = float(df_global.loc['RATE_GLOBAL_HLT']['Weighted PS Rate [Hz]'])
313 rateglobalerr = float(df_global.loc['RATE_GLOBAL_HLT']['Weighted PS Rate Err [Hz]'])
314
315 df_stream2 = pd.read_csv(f"{stream2}/output/csv/Table_Rate_ChainHLT_HLT_All.csv")
316 df_stream2.set_index('Name', inplace=True)
317 rate2 = float(df_global.loc[f"STREAM:{stream2}"]['Weighted PS Rate [Hz]'])
318 rate2err = float(df_global.loc[f"STREAM:{stream2}"]['Weighted PS Rate Err [Hz]'])
319
320 unique_rate = rateglobal - rate0
321
322 try:
323 percentage = (rate2 - unique_rate)/rate2 * 100
324 except ZeroDivisionError:
325 print("Cannot compute streams' overlap percentage (ZeroDivisionError): percentage set to None")
326 percentage = None
327
328
329 with open(output_stream_filen, 'w') as f:
330 print('Computing the unique rate of a stream w.r.t. a different stream', file=f)
331 print('Reference Stream: ', stream1, file=f)
332 print('Compared Stream: ', stream2, file=f)
333 table = [[rate0, rate0err],
334 [rateglobal, rateglobalerr],
335 [rate2, rate2err],
336 [unique_rate, ' ']]
337 df_out = pd.DataFrame(table, index = [f'Total rate of {stream1}' ,'Rate of the two streams including overlap', f'Total rate of {stream2}', f"Unique rate of {stream2}"],
338 columns = ['Weighted PS Rate [Hz]', "Weighted PS Rate Err [Hz]"])
339 print(df_out, file=f)
340 print(f"The overlap between {stream1} and {stream2} is {percentage}", file=f)
341
342def chain_rate(chain, stream, dir):
343 # df where the chain is disabled - get the menu rate when this is alone
344 df = pd.read_csv(f"{chain}/output/csv/Table_Rate_Group_HLT_All.csv")
345 df.set_index('Name', inplace=True)
346
347 df_chain = pd.read_csv(f"{dir}/output/csv/Table_Rate_ChainHLT_HLT_All.csv")
348 df_stream = pd.read_csv(f"{dir}/output/csv/Table_Rate_Group_HLT_All.csv")
349 df_chain.set_index('Name', inplace=True)
350 df_stream.set_index('Name', inplace=True)
351
352 chain_rate = float(df_chain.loc[chain]['Unique Rate [Hz]'])
353 chain_rate_err = float(df_chain.loc[chain]['Unique Rate Err [Hz]'])
354
355 global_rate = float(df_stream.loc[f"STREAM:{stream}"]['Weighted PS Rate [Hz]'])
356 global_rate_err = float(df_stream.loc[f"STREAM:{stream}"]['Weighted PS Rate Err [Hz]'])
357
358 global_dis_rate = float(df.loc['RATE_GLOBAL_HLT']['Weighted PS Rate [Hz]']) # chain is disabled
359 global_dis_rate_err = float(df.loc['RATE_GLOBAL_HLT']['Weighted PS Rate Err [Hz]']) # chain is disabled
360
361 unique_contri = global_rate - global_dis_rate
362 percentage = unique_contri/global_rate * 100
363
364 with open(output_chain_filen, 'w') as f:
365 print('Computing the unique rate of a chain w.r.t. a stream', file=f)
366 print('Reference Stream: ', stream, file=f)
367 print('Compared Chain: ', chain, file=f)
368 table = [[chain_rate, chain_rate_err],
369 [global_rate, global_rate_err],
370 [global_dis_rate, global_dis_rate_err],
371 [unique_contri, '---']]
372 df_out = pd.DataFrame(table, index = ['Chain Unique Rate', 'Stream and Chain Rate',
373 'Stream without Chain Rate', 'Unique Contribution'],
374 columns = ['Rate [Hz]', 'Rate Error [Hz]'])
375 print(df_out, file=f)
376 print(f"{chain} has a unique contribution of", percentage, '% to ' f"{stream}", file=f)
377
378def chain_comp_rate(chain1, chain2):
379
380 df1 = pd.read_csv(f"{chain1}/output/csv/Table_Rate_ChainHLT_HLT_All.csv")
381 df1.set_index('Name', inplace=True)
382
383 df2 = pd.read_csv(f"{chain2}/output/csv/Table_Rate_ChainHLT_HLT_All.csv")
384 df2.set_index('Name', inplace=True)
385
386 # rate where only one chain is enabled
387 wrate1 = float(df1.loc[chain1]['Weighted PS Rate [Hz]'])
388 urate1 = float(df1.loc[chain1]['Unique Rate [Hz]'])
389 wrate1err = float(df1.loc[chain1]['Weighted PS Rate Err [Hz]'])
390 urate1err = float(df1.loc[chain1]['Unique Rate Err [Hz]'])
391
392 # rate when both chains are enabled
393 wrate1_comb = float(df2.loc[chain1]['Weighted PS Rate [Hz]'])
394 urate1_comb = float(df2.loc[chain1]['Unique Rate [Hz]'])
395 wrate2 = float(df2.loc[chain2]['Weighted PS Rate [Hz]'])
396 urate2 = float(df2.loc[chain2]['Unique Rate [Hz]'])
397 wrate1_comb_err = float(df2.loc[chain1]['Weighted PS Rate Err [Hz]'])
398 urate1_comb_err = float(df2.loc[chain1]['Unique Rate Err [Hz]'])
399 wrate2err = float(df2.loc[chain2]['Weighted PS Rate Err [Hz]'])
400 urate2err = float(df2.loc[chain2]['Unique Rate Err [Hz]'])
401
402 try:
403 percentage = wrate2/wrate1_comb * 100
404 except ZeroDivisionError:
405 print("Cannot compute chains' overlap percentage (ZeroDivisionError): percentage set to None")
406 percentage = None
407
408 with open(f"ChainComp_{i}", 'w') as f:
409 table = [[wrate1, wrate1err, urate1, urate1err],
410 [wrate1_comb, wrate1_comb_err, urate1_comb, urate1_comb_err],
411 [wrate2, wrate2err, urate2, urate2err]]
412 pd.set_option('display.max_colwidth', None)
413 df_out = pd.DataFrame(table, columns = ['Weighted PS Rate', 'Weighted PS Rate Error', 'Unique Rate', 'Unique Rate Error'],
414 index = ['Reference Chain Only', 'Reference Chain', 'Comparison Chain'])
415 print(df_out, file=f)
416 print('The overlap between ' f"{chain1} and " f"{chain2} is", percentage, '%', file=f)
417
418def chain_set_rate(chains):
419 df1 = pd.read_csv("fullMenu/output/csv/Table_Rate_Group_HLT_All.csv")
420 df1.set_index('Name', inplace=True)
421
422 df2 = pd.read_csv("setMenu/output/csv/Table_Rate_Group_HLT_All.csv")
423 df2.set_index('Name', inplace=True)
424
425 # Global HLT Rate
426 fullrate = float(df1.loc['RATE_GLOBAL_HLT']['Weighted PS Rate [Hz]'])
427 setrate = float(df2.loc['RATE_GLOBAL_HLT']['Weighted PS Rate [Hz]'])
428 fullrate_err = float(df1.loc['RATE_GLOBAL_HLT']['Weighted PS Rate Err [Hz]'])
429 setrate_err = float(df2.loc['RATE_GLOBAL_HLT']['Weighted PS Rate Err [Hz]'])
430
431 unique_rate = fullrate - setrate
432 percentage = unique_rate/setrate * 100
433
434 with open("SetMonitoring.txt", 'w') as f:
435 table = [[fullrate, fullrate_err],
436 [setrate, setrate_err]]
437 pd.set_option('display.max_colwidth', None)
438 df_out = pd.DataFrame(table, columns = ['Global HLT Rate', 'Global HLT Rate Error'],
439 index = ['Full Menu', 'Chains disabled'])
440 print("The chains that have been disabled are: ", file=f)
441 for i in range(len(chains)):
442 print(f"{chains[i]}", file=f)
443 print("-------------------------------------------------------", file=f)
444 print(df_out, file=f)
445 print("-------------------------------------------------------", file=f)
446 print('Unique rate of the set: ', unique_rate, file=f)
447 print('The set has a contribution of', percentage, '% to the Global HLT Rate', file=f)
448
449def pretty_csvs(chains_list):
450
451 # csv part goes here now
452 with open('ChainAnalysisSummary.txt', 'w') as t:
453
454 pd.set_option('max_colwidth', 400)
455
456 print('The reference chain is ',chains_list[0] , file=t)
457 print('--------------------------------------------------------------------------------', file=t)
458 print('--------------------------------------------------------------------------------', file=t)
459
460 for p in range(1, len(chains_list)):
461
462 print('For chain', chains_list[p], ':' , file=t)
463 df = pd.read_csv(f"ChainComp_{p}")
464 print(df.drop([0]), file=t)
465 print('--------------------------------------------------------------------------------', file=t)
466
467# ------------------------------------------------------------------------------------------------------------
468# CALLING THE FUNCTIONS
469# ------------------------------------------------------------------------------------------------------------
470
471if stream_filen != ' ':
472
473 s = 0
474 streamdir = os.getcwd()
475
476 for j in range(len(stream_filen)):
477 s += 1
478 os.makedirs(f"stream_{s}")
479
480 shutil.copy(args.HLTMenu, f"stream_{s}/{HLTMenu_filen}")
481 shutil.copy(args.l1_ps, f"stream_{s}/{l1_ps_filen}")
482 shutil.copy(args.hlt_in, f"stream_{s}/{hlt_in_filen}")
483
484 os.chdir(f"stream_{s}")
485
486 #choosing the streams
487 dict_stream0 = stream_json(HLTMenu_filen, hlt_in_filen, stream0_filen, stream_filen[j])[0]
488 dict_stream = stream_json(HLTMenu_filen, hlt_in_filen, stream0_filen, stream_filen[j])[1]
489 # dumping the json
490 psk_file(dict_stream0, hlt_ps_stream0_filen)
491 psk_file(dict_stream, hlt_ps_stream_filen)
492 # rates analysis
493 exec_rates(hlt_ps_stream0_filen, f"{stream0_filen}")
494 exec_rates(hlt_ps_stream_filen, stream_filen[j])
495 #csv part
496 stream_rate(stream0_filen, stream_filen[j], f"{stream0_filen}")
497
498 os.chdir(streamdir)
499
500if chain_filen == ['regex']:
501 s = 0
502 chaindir = os.getcwd()
503 print(chaindir)
504
505 regex_chains = chain_regex(HLTMenu_filen)
506
507 for i in range(len(regex_chains)):
508 s += 1
509
510 os.makedirs(f"chain_{s}")
511
512 shutil.copy(args.HLTMenu, f"chain_{s}/{HLTMenu_filen}")
513 shutil.copy(args.l1_ps, f"chain_{s}/{l1_ps_filen}")
514 shutil.copy(args.hlt_in, f"chain_{s}/{hlt_in_filen}")
515
516 os.chdir(f"chain_{s}")
517
518 #choosing the chains
519 dict_stream0 = chain_json(HLTMenu_filen, hlt_in_filen, regex_chains[i], stream0_filen)[0]
520 dict_chain = chain_json(HLTMenu_filen, hlt_in_filen, regex_chains[i], stream0_filen)[1]
521
522 # dumping the json
523 psk_file(dict_stream0, hlt_ps_stream0_filen)
524 psk_file(dict_chain, hlt_ps_chain_filen)
525 # rates analysis
526 exec_rates(hlt_ps_stream0_filen, f"{stream0_filen}")
527 exec_rates(hlt_ps_chain_filen, regex_chains[i])
528 # csv part
529 chain_rate(regex_chains[i], stream0_filen, f"{stream0_filen}")
530
531 # cleanup to remove the duplicate files
532 os.remove(HLTMenu_filen)
533 os.remove(l1_ps_filen)
534 os.remove(hlt_in_filen)
535 os.remove(hlt_ps_chain_filen)
536 os.remove(hlt_ps_stream0_filen)
537
538 os.chdir(chaindir)
539
540elif chain_filen != ' ':
541 c = 0
542 chaindir = os.getcwd()
543
544 for i in range(len(chain_filen)):
545 c += 1
546
547 os.makedirs(f"chain_{c}")
548
549 shutil.copy(args.HLTMenu, f"chain_{c}/{HLTMenu_filen}")
550 shutil.copy(args.l1_ps, f"chain_{c}/{l1_ps_filen}")
551 shutil.copy(args.hlt_in, f"chain_{c}/{hlt_in_filen}")
552
553 os.chdir(f"chain_{c}")
554
555 #choosing the chains
556 dict_stream0 = chain_json(HLTMenu_filen, hlt_in_filen, chain_filen[i], stream0_filen)[0]
557 dict_chain = chain_json(HLTMenu_filen, hlt_in_filen, chain_filen[i], stream0_filen)[1]
558
559 # dumping the json
560 psk_file(dict_stream0, hlt_ps_stream0_filen)
561 psk_file(dict_chain, hlt_ps_chain_filen)
562 # rates analysis
563 exec_rates(hlt_ps_stream0_filen, f"{stream0_filen}")
564 exec_rates(hlt_ps_chain_filen, chain_filen[i])
565
566 # csv part
567 chain_rate(chain_filen[i], stream0_filen, f"{stream0_filen}")
568
569 # cleanup to remove the duplicate files
570 os.remove(HLTMenu_filen)
571 os.remove(l1_ps_filen)
572 os.remove(hlt_in_filen)
573 os.remove(hlt_ps_chain_filen)
574 os.remove(hlt_ps_stream0_filen)
575
576 os.chdir(chaindir)
577
578if chain_comp_filen == ['regex']:
579
580 regex_chainsComp = chain_regex(HLTMenu_filen)
581 os.makedirs('chain_comp')
582
583 shutil.copy(args.HLTMenu, f"chain_comp/{HLTMenu_filen}")
584 shutil.copy(args.l1_ps, f"chain_comp/{l1_ps_filen}")
585 shutil.copy(args.hlt_in, f"chain_comp/{hlt_in_filen}")
586
587 os.chdir('chain_comp')
588 chain_comp_dir = os.getcwd()
589
590 # executing the commands
591 dict_chain_ref = chain_ref_json(HLTMenu_filen, regex_chainsComp[0])
592 psk_file(dict_chain_ref, hlt_ps_chain_ref_filen)
593 exec_rates(hlt_ps_chain_ref_filen, regex_chainsComp[0])
594 os.remove(hlt_ps_chain_ref_filen)
595
596 for i in range(1, len(regex_chainsComp)):
597
598 dict_chain_comp = chain_comp_json(HLTMenu_filen, regex_chainsComp[0], regex_chainsComp[i])
599 psk_file(dict_chain_comp, hlt_ps_chain_comp_filen)
600 exec_rates(hlt_ps_chain_comp_filen, regex_chainsComp[i])
601 chain_comp_rate(regex_chainsComp[0], regex_chainsComp[i])
602
603 os.chdir(chain_comp_dir)
604
605 # cleanup to remove the duplicate files
606 os.remove(HLTMenu_filen)
607 os.remove(l1_ps_filen)
608 os.remove(hlt_in_filen)
609 os.remove(hlt_ps_chain_comp_filen)
610
611 # creating the csv files
612 pretty_csvs(regex_chainsComp)
613
614elif chain_comp_filen != ' ':
615
616 os.makedirs('chain_comp')
617
618 shutil.copy(args.HLTMenu, f"chain_comp/{HLTMenu_filen}")
619 shutil.copy(args.l1_ps, f"chain_comp/{l1_ps_filen}")
620 shutil.copy(args.hlt_in, f"chain_comp/{hlt_in_filen}")
621 os.chdir('chain_comp')
622 chain_comp_dir = os.getcwd()
623
624 # executing the commands
625 dict_chain_ref = chain_ref_json(HLTMenu_filen, chain_comp_filen[0])
626 psk_file(dict_chain_ref, hlt_ps_chain_ref_filen)
627 exec_rates(hlt_ps_chain_ref_filen, chain_comp_filen[0])
628 os.remove(hlt_ps_chain_ref_filen)
629
630 for i in range(1, len(chain_comp_filen)):
631 dict_chain_comp = chain_comp_json(HLTMenu_filen, chain_comp_filen[0], chain_comp_filen[i])
632 psk_file(dict_chain_comp, hlt_ps_chain_comp_filen)
633 exec_rates(hlt_ps_chain_comp_filen, chain_comp_filen[i])
634 chain_comp_rate(chain_comp_filen[0], chain_comp_filen[i])
635
636 os.chdir(chain_comp_dir)
637
638 # cleanup to remove the duplicate files
639 os.remove(HLTMenu_filen)
640 os.remove(l1_ps_filen)
641 os.remove(hlt_in_filen)
642 os.remove(hlt_ps_chain_comp_filen)
643
644 # creating the csv files
645 pretty_csvs(chain_comp_filen)
646
647if chain_set_filen == ['regex']:
648
649 regex_chainsSet = chain_regex(HLTMenu_filen)
650
651 os.makedirs('chain_set')
652
653 shutil.copy(args.HLTMenu, f"chain_set/{HLTMenu_filen}")
654 shutil.copy(args.l1_ps, f"chain_set/{l1_ps_filen}")
655 shutil.copy(args.hlt_in, f"chain_set/{hlt_in_filen}")
656 os.chdir('chain_set')
657 chain_set_dir = os.getcwd()
658
659 #rates analysis on the full menu
660 exec_rates(hlt_in_filen, 'fullMenu')
661 dict_chain_set = chain_set_json(HLTMenu_filen, hlt_in_filen, regex_chainsSet)
662 psk_file(dict_chain_set, hlt_ps_chain_set_filen)
663 exec_rates(hlt_ps_chain_set_filen, 'setMenu')
664 chain_set_rate(regex_chainsSet)
665
666elif chain_set_filen != ' ':
667
668 os.makedirs('chain_set')
669
670 shutil.copy(args.HLTMenu, f"chain_set/{HLTMenu_filen}")
671 shutil.copy(args.l1_ps, f"chain_set/{l1_ps_filen}")
672 shutil.copy(args.hlt_in, f"chain_set/{hlt_in_filen}")
673 os.chdir('chain_set')
674 chain_set_dir = os.getcwd()
675
676 # rates analysis on the full menu
677 exec_rates(hlt_in_filen, 'fullMenu')
678 dict_chain_set = chain_set_json(HLTMenu_filen, hlt_in_filen, chain_set_filen)
679 psk_file(dict_chain_set, hlt_ps_chain_set_filen)
680 exec_rates(hlt_ps_chain_set_filen, 'setMenu')
681 chain_set_rate(chain_set_filen)
void print(char *figname, TCanvas *c1)
stream_rate(stream1, stream2, dir)
stream_json(menu_in, psks_in, stream1, stream2)
chain_comp_rate(chain1, chain2)
chain_json(menu_in, psks_in, chain, stream)
chain_rate(chain, stream, dir)
chain_comp_json(menu_in, ref_chain, comp_chain)
chain_set_json(menu_in, psks_in, chains)