Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 07:51:06

0001 # docker run -it --rm -v/home/romanov/dev/firebird:/mnt eicweb/eic_xl:nightly
0002 # cd /mnt/dd4hep-plugin/
0003 # mkdir build && cd build
0004 # This will create prefix/lib folder after the install
0005 # cmake .. && make && make install
0006 # cd .. && ls prefix/lib  # <= Ensure libfirebird-dd4hep.so is there
0007 # export LD_LIBRARY_PATH="/mnt/dd4hep-plugin/prefix/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
0008 # mkdir -p tmp && cd tmp
0009 # source /opt/detector/epic-main/bin/thisepic.sh
0010 # pip install --upgrade pyrobird
0011 # python3 /mnt/test/run_background.py
0012 
0013 
0014 import subprocess
0015 import os
0016 
0017 INPUT_FILE="root://dtn-eic.jlab.org//volatile/eic/EPIC/EVGEN/BACKGROUNDS/MERGED/HEPMC_merger-1.0.2/10x100/1SignalPerFrame/HEPMC_merger-1.0.2_bgmerged_1SignalPerFrame_MinBias_pythia6_10x100_egas_bgas.hepmc3.tree.root"
0018 OUTPUT_BASE="background_py6_10x100_egas_bgas"
0019 DETECTOR_PATH = os.getenv('DETECTOR_PATH', '/opt/detector/epic-main/share/epic/')
0020 DETECTOR_FILE = f'{DETECTOR_PATH}/epic_craterlake_10x100.xml'
0021 STEERING_FILE = '/mnt/dd4hep-plugin/firebird_steering.py'
0022 EVENT_NUM = 10
0023 
0024 def run_command(command):
0025     """
0026     Executes a given command in the shell and prints the output as it appears.
0027     Parameters: command (list): A list containing the command and its arguments.
0028     """
0029 
0030     print("Executing:", " ".join(command))
0031 
0032     process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
0033 
0034     # Print output as it appears
0035     while True:
0036         output = process.stdout.readline()
0037         if output == '' and process.poll() is not None:
0038             break
0039         if output:
0040             print(output.strip())
0041 
0042     # Handle errors if there are any
0043     err = process.stderr.read()
0044     if err:
0045         print("Error:", err)
0046 
0047     # Check the process return code
0048     process.wait()
0049     print("Command completed with return code:", process.returncode)
0050     print("\n" + "-"*50 + "\n")
0051 
0052 if __name__ == "__main__":
0053     print(f"INPUT_FILE     :{INPUT_FILE}")
0054     print(f"OUTPUT_BASE    :{OUTPUT_BASE}")
0055     print(f"DETECTOR_PATH  :{DETECTOR_PATH}")
0056     print(f"DETECTOR_FILE  :{DETECTOR_FILE}")
0057     print(f"STEERING_FILE  :{STEERING_FILE}")
0058 
0059 
0060     # Command for npsim
0061     npsim_command = [
0062         "npsim",
0063         "--compactFile", DETECTOR_FILE,
0064         "-N", str(EVENT_NUM),
0065         "--inputFiles", INPUT_FILE,
0066         "--random.seed", "1",
0067         "--outputFile", f"{OUTPUT_BASE}.edm4hep.root",
0068         "--steeringFile", STEERING_FILE,
0069     ]
0070 
0071     # Run the simulation
0072     #run_command(npsim_command)
0073 
0074     # Command for converting the output file to JSON format
0075     reconstruction_command = [
0076         "eicrecon",
0077         f"-Pjana:debug_plugin_loading=1",
0078         f"-Pdd4hep:xml_files={DETECTOR_FILE}",
0079         f"-Pjana:nevents={EVENT_NUM}",
0080         f"-Pjana:timeout=0",
0081         f"-Ppodio:output_file={OUTPUT_BASE}.edm4eic.root",
0082         f"{OUTPUT_BASE}.edm4hep.root"
0083     ]
0084     #run_command(reconstruction_command)
0085 
0086     # smooth trajectories
0087     run_command(["pyrobird", "smooth",
0088         f"{OUTPUT_BASE}.firebird.json",
0089         "-o", f"{OUTPUT_BASE}_smth.v04.firebird.json"
0090     ])
0091 
0092     # zip files
0093     run_command(["python3",
0094                  "-m", "zipfile",
0095                  "-c", f"{OUTPUT_BASE}_smth.v04.firebird.json.zip",
0096                  f"{OUTPUT_BASE}_smth.v04.firebird.json"
0097     ])