1111import glob
1212import random
1313from datetime import datetime
14- from common import bcolors , msg , fatal_msg , verbose_msg , run_in_parallel , set_verbose_mode , get_default_parser , warning_msg
15-
16-
17- def run_cmd (cmd , comment = "" , check_status = True ):
18- """
19- Function to run a command in bash, allows to check the status of the command and to log the command output
20- """
21- verbose_msg ("Running" , f"'{ cmd } '" , bcolors .BOKBLUE + comment )
22- try :
23- to_run = cmd
24- if check_status :
25- to_run = f"{ cmd } && echo OK"
26- content = os .popen (to_run ).read ()
27- if content :
28- content = content .strip ()
29- for i in content .strip ().split ("\n " ):
30- verbose_msg ("++" , i )
31- if "Encountered error" in content :
32- warning_msg ("Error encountered runtime error in" , cmd )
33- if check_status :
34- if "OK" not in content and "root" not in cmd :
35- fatal_msg ("Command" , cmd , "does not have the OK tag" , content )
36- except :
37- fatal_msg ("Error while running" , f"'{ cmd } '" )
14+ from common import bcolors , msg , fatal_msg , verbose_msg , run_in_parallel , set_verbose_mode , get_default_parser , run_cmd
3815
3916
4017def process_run (run_number ):
@@ -60,7 +37,8 @@ def main(configuration_file,
6037 clean_delphes_files ,
6138 create_luts ,
6239 turn_off_vertexing ,
63- append_production ):
40+ append_production ,
41+ use_nuclei ):
6442 arguments = locals () # List of arguments to put into the log
6543 parser = configparser .RawConfigParser ()
6644 parser .read (configuration_file )
@@ -125,6 +103,9 @@ def do_copy(in_file, out_file=".", in_path=None):
125103
126104 lut_path = opt ("lut_path" )
127105 lut_tag = opt ("lut_tag" )
106+ lut_particles = ["el" , "mu" , "pi" , "ka" , "pr" ]
107+ if use_nuclei :
108+ lut_particles += ["de" , "he3" ]
128109 if create_luts :
129110 # Creating LUTs
130111 minimum_track_radius = opt ("minimum_track_radius" )
@@ -135,12 +116,13 @@ def do_copy(in_file, out_file=".", in_path=None):
135116 else :
136117 # Fetching LUTs
137118 verbose_msg (f"Fetching LUTs with tag { lut_tag } from path { lut_path } " )
138- for i in [ "el" , "mu" , "pi" , "ka" , "pr" ] :
119+ for i in lut_particles :
139120 lut_bg = "{}kG" .format (bField ).replace ("." , "" )
140- do_copy (f"lutCovm.{ i } .{ lut_bg } .{ lut_tag } .dat" , f"lutCovm.{ i } .dat" , in_path = lut_path )
121+ do_copy (f"lutCovm.{ i } .{ lut_bg } .{ lut_tag } .dat" ,
122+ f"lutCovm.{ i } .dat" , in_path = lut_path )
141123
142124 # Checking that we actually have LUTs
143- for i in [ "el" , "mu" , "pi" , "ka" , "pr" ] :
125+ for i in lut_particles :
144126 i = f"lutCovm.{ i } .dat"
145127 if not os .path .isfile (i ):
146128 fatal_msg ("Did not find LUT file" , i )
@@ -236,6 +218,9 @@ def set_config(config_file, config, value):
236218 if turn_off_vertexing :
237219 set_config ("createO2tables.C" ,
238220 "const bool do_vertexing = " , "false\;/" )
221+ if use_nuclei :
222+ set_config ("createO2tables.C" ,
223+ "const bool enable_nuclei = " , "true\;/" )
239224 else : # Check that the geometry file for the vertexing is there
240225 if not os .path .isfile ("o2sim_grp.root" ) or not os .path .isfile ("o2sim_geometry.root" ):
241226 run_cmd ("mkdir tmpo2sim && cd tmpo2sim && o2-sim -m PIPE ITS MFT -g boxgen -n 1 -j 1 --configKeyValues 'BoxGun.number=1' && cp o2sim_grp.root .. && cp o2sim_geometry.root .. && cd .. && rm -r tmpo2sim" )
@@ -359,7 +344,10 @@ def copy_and_link(file_name):
359344 log_file = aod_log_file ,
360345 check_status = True )
361346 # Check that there were no O2 errors
362- write_to_runner (f"if grep -q \" \[ERROR\]\" { aod_log_file } ; then echo \" : got some errors in '{ aod_log_file } '\" && exit 1; fi" )
347+ write_to_runner (
348+ f"if grep -q \" \[ERROR\]\" { aod_log_file } ; then echo \" : got some errors in '{ aod_log_file } '\" && exit 1; fi" )
349+ write_to_runner (
350+ f"if grep -q \" \[FATAL\]\" { aod_log_file } ; then echo \" : got some fatals in '{ aod_log_file } '\" && exit 1; fi" )
363351 # Rename the temporary AODs to standard AODs
364352 write_to_runner (f"mv tmp_{ aod_file } { aod_file } " , check_status = True )
365353 if not clean_delphes_files :
@@ -481,6 +469,9 @@ def write_config(entry, prefix=""):
481469 parser .add_argument ("--append" , "-a" ,
482470 action = "store_true" ,
483471 help = "Option to append the results instead of starting over by shifting the AOD indexing. N.B. the user is responsible of the compatibility between appended AODs. Only works in conjuction by specifying an output path (option '-o')" )
472+ parser .add_argument ("--nuclei" ,
473+ action = "store_true" ,
474+ help = "Option use nuclei LUTs" )
484475 parser .add_argument ("--use-preexisting-luts" , "-l" ,
485476 action = "store_true" ,
486477 help = "Option to use preexisting LUTs instead of creating new ones, in this case LUTs with the requested tag are fetched from the LUT path. By default new LUTs are created at each run." )
@@ -501,4 +492,5 @@ def write_config(entry, prefix=""):
501492 qa = args .qa ,
502493 create_luts = not args .use_preexisting_luts ,
503494 turn_off_vertexing = args .no_vertexing ,
504- append_production = args .append )
495+ append_production = args .append ,
496+ use_nuclei = args .nuclei )
0 commit comments