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