Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-27 07:28:14

0001 """Tests for epic stack utilities."""
0002 
0003 from aid2e.utilities.epic_utils.epic_stack import (
0004     EpicGeoLayer,
0005     EpicSimLayer,
0006     EpicRecLayer,
0007     EpicAnaLayer,
0008     EpicStack
0009 )
0010 
0011 
0012 def _make_epic_stack_payload() -> dict:
0013     """Build a dictionary of epic stack layer inputs, outputs, and arguments for tests."""
0014     return {
0015         "geo_input" : [
0016             "./epic/my_epic.xml",
0017         ],
0018         "geo_output" : [
0019             "overlap_output.log",
0020         ],
0021         "geo_args" : [
0022             "--tolerance 0.01",
0023         ],
0024         "sim_input" : [
0025             "steering_input.py",
0026             "hepmc_input.hepmc",
0027             "hepmc_tree_input.hepmc3.root",
0028             "macro_input.mac",
0029         ],
0030         "sim_output" : [
0031             "sim_output.edm4hep.root",
0032         ],
0033         "sim_args" : [
0034             "--numberOfEvents 100",
0035             "--skipNEvents 10",
0036         ],
0037         "rec_output" : [
0038             "rec_output.edm4eic.root",
0039         ],
0040         "rec_args" : [
0041             "-Pnthreads=8",
0042             "-Pjana:global_loglevel=debug",
0043         ],
0044     }
0045 
0046 
0047 def test_epic_geo_layer():
0048     """EpicGeoLayer functionality"""
0049     payload  = _make_epic_stack_payload()
0050     geolayer = EpicGeoLayer()
0051     command  = geolayer.make_command(
0052         payload["geo_input"],
0053         payload["geo_output"],
0054         payload["geo_args"]
0055     )
0056     assert command == 'checkOverlaps --tolerance 0.01 ./epic/my_epic.xml >& overlap_output.log\ngrep -F "Number of illegal overlaps/extrusions : " overlap_output.log | while IFS= read -r line; do\n lastChar="${line: -1}"\n if [[ $lastChar =~ ^[0-9]$ ]]; then\n  if (( lastChar > 0 )); then\n   exit 9\n  fi\n fi\ndone'
0057 
0058 
0059 def test_epic_sim_layer():
0060     """Validate EpicSimLayer functionality"""
0061     payload  = _make_epic_stack_payload()
0062     simlayer = EpicSimLayer()
0063     command  = simlayer.make_command(
0064         payload["sim_input"],
0065         payload["sim_output"],
0066         payload["sim_args"]
0067     )
0068     assert command == "npsim --numberOfEvents 100 --skipNEvents 10 --steeringFile steering_input.py -I hepmc_input.hepmc -I hepmc_tree_input.hepmc3.root --macroFile macro_input.mac --outputFile sim_output.edm4hep.root"
0069 
0070 
0071 def test_epic_rec_layer():
0072     """Validate EpicRecLayer functionality"""
0073     payload  = _make_epic_stack_payload()
0074     reclayer = EpicRecLayer()
0075     command  = reclayer.make_command(
0076         payload["sim_output"],
0077         payload["rec_output"],
0078         payload["rec_args"]
0079     )
0080     assert command == "eicrecon -Pnthreads=8 -Pjana:global_loglevel=debug -Ppodio:output_file=rec_output.edm4eic.root sim_output.edm4hep.root"
0081 
0082 
0083 def test_epic_stack():
0084     """Validate EpicStack functionality"""
0085     payload = _make_epic_stack_payload()
0086     epstack = EpicStack()
0087     assert isinstance(epstack, EpicStack)
0088     assert isinstance(epstack["geo"], EpicGeoLayer)
0089     assert isinstance(epstack["sim"], EpicSimLayer)
0090     assert isinstance(epstack["rec"], EpicRecLayer)
0091     assert isinstance(epstack["ana"], EpicAnaLayer)
0092 
0093     geocomm = epstack["geo"].make_command(
0094         payload["geo_input"],
0095         payload["geo_output"],
0096         payload["geo_args"]
0097     )
0098     simcomm = epstack["sim"].make_command(
0099         payload["sim_input"],
0100         payload["sim_output"],
0101         payload["sim_args"]
0102     )
0103     reccomm = epstack["rec"].make_command(
0104         payload["sim_output"],
0105         payload["rec_output"],
0106         payload["rec_args"]
0107     )
0108     assert geocomm == 'checkOverlaps --tolerance 0.01 ./epic/my_epic.xml >& overlap_output.log\ngrep -F "Number of illegal overlaps/extrusions : " overlap_output.log | while IFS= read -r line; do\n lastChar="${line: -1}"\n if [[ $lastChar =~ ^[0-9]$ ]]; then\n  if (( lastChar > 0 )); then\n   exit 9\n  fi\n fi\ndone'
0109     assert simcomm == "npsim --numberOfEvents 100 --skipNEvents 10 --steeringFile steering_input.py -I hepmc_input.hepmc -I hepmc_tree_input.hepmc3.root --macroFile macro_input.mac --outputFile sim_output.edm4hep.root"
0110     assert reccomm == "eicrecon -Pnthreads=8 -Pjana:global_loglevel=debug -Ppodio:output_file=rec_output.edm4eic.root sim_output.edm4hep.root"