File indexing completed on 2026-04-07 07:50:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 import subprocess
0013 import os
0014
0015 def setup_environment():
0016 """
0017 Updates the LD_LIBRARY_PATH environment variable to include custom library paths.
0018 """
0019
0020 current_ld_library_path = os.environ.get('LD_LIBRARY_PATH', '')
0021
0022
0023 prefix_path = '/var/project/prefix/lib'
0024
0025
0026 new_ld_library_path = (prefix_path + ':' + current_ld_library_path) if current_ld_library_path else prefix_path
0027
0028
0029 os.environ['LD_LIBRARY_PATH'] = new_ld_library_path
0030 print("Updated LD_LIBRARY_PATH:", os.environ['LD_LIBRARY_PATH'])
0031
0032 def run_command(command):
0033 """
0034 Executes a given command in the shell and prints the output as it appears.
0035
0036 Parameters:
0037 command (list): A list containing the command and its arguments.
0038 """
0039 print("Executing:", " ".join(command))
0040 process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
0041
0042
0043 while True:
0044 output = process.stdout.readline()
0045 if output == '' and process.poll() is not None:
0046 break
0047 if output:
0048 print(output.strip())
0049
0050
0051 err = process.stderr.read()
0052 if err:
0053 print("Error:", err)
0054
0055
0056 process.wait()
0057 print("Command completed with return code:", process.returncode)
0058 print("\n" + "-"*50 + "\n")
0059
0060 def get_hepmc_path(beam, minq2):
0061 return f"root://dtn-eic.jlab.org//volatile/eic/EPIC/EVGEN/DIS/NC/{beam}/minQ2={minq2}/pythia8NCDIS_{beam}_minQ2={minq2}_beamEffects_xAngle=-0.025_hiDiv_1.hepmc3.tree.root"
0062
0063 def get_base_name(beam, minq2, event_num):
0064 return f"py8dis-nc_{beam}_minq2-{minq2}_minp-250mev_nevt-{event_num}"
0065
0066 def run_simulation(beam, minq2, event_num, detector_path, steering_file):
0067 """
0068 Runs the simulation for a given beam, Q2 value, and event number, then converts the output file.
0069
0070 Parameters:
0071 beam (str): The energy configuration for the beam.
0072 minq2 (int): The minimum Q2 value.
0073 event_num (int): The number of events to simulate.
0074 detector_path (str): Path to the detector configuration XML file.
0075 """
0076
0077 url = get_hepmc_path(beam, minq2)
0078
0079
0080 output_base = get_base_name(beam, minq2, event_num)
0081 output_edm4hep = output_base + ".edm4hep.root"
0082 output_evttxt = output_base + ".evt.txt"
0083 event_prefix = f"CC_{beam}_minq2_{minq2}"
0084
0085
0086
0087 npsim_command = [
0088 "npsim",
0089 "--compactFile", detector_path,
0090 "-N", str(event_num),
0091 "--inputFiles", url,
0092 "--random.seed", "1",
0093 "--outputFile", output_edm4hep,
0094
0095 "--steeringFile", steering_file
0096
0097
0098
0099
0100
0101
0102
0103
0104 ]
0105
0106
0107 run_command(npsim_command)
0108
0109
0110 reconstruction_command = [
0111 "eicrecon",
0112 f"-Pjana:debug_plugin_loading=1",
0113 f"-Pjana:nevents={event_num}",
0114 f"-Pjana:timeout=0",
0115 f"-Ppodio:output_file={output_base}.edm4eic.root",
0116 f"-Pdd4hep:xml_files={detector_path}",
0117 f"{output_base}.edm4hep.root"
0118 ]
0119
0120
0121 run_command(reconstruction_command)
0122
0123
0124
0125 setup_environment()
0126
0127
0128 DETECTOR_PATH = os.getenv('DETECTOR_PATH', '/opt/detector/epic-main/share/epic/')
0129
0130
0131 beams = ['5x41', '10x100', '18x275']
0132 minq2s = [1, 100, 1000]
0133
0134
0135 for beam in beams:
0136 for minq2 in minq2s:
0137 print("\n---------------------------------------------------------------------------------"*5)
0138 run_simulation(beam, minq2, 5, f'{DETECTOR_PATH}/epic_craterlake_{beam}.xml', '/mnt/dd4hep-plugin/firebird_steering.py')
0139 print("\n/////////////////////////////////////////////////////////////////////////////////"*5)