Skip to content

Commit

Permalink
tests: add simple th228 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelHu committed Dec 9, 2024
1 parent 0b064ab commit 6a5abe8
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Install pip dependencies for tests
# TODO: replace with a better way to manage test dependencies.
run: |
pip3 install --user --upgrade legend-pydataobj scipy
- name: Build project
run: |
mkdir build
Expand Down
7 changes: 6 additions & 1 deletion tests/output/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ endif()
file(
GLOB _aux
RELATIVE ${PROJECT_SOURCE_DIR}
macros/* gdml/*.gdml gdml/*.xml run-test-*.sh)
macros/* gdml/*.gdml gdml/*.xml run-test-*.sh run-test-*.py)

# copy them to the build area
foreach(_file ${_aux})
configure_file(${PROJECT_SOURCE_DIR}/${_file} ${PROJECT_BINARY_DIR}/${_file} COPYONLY)
endforeach()

# MAIN OUTPUT TESTS
set(_macros ntuple-per-det.mac ntuple-per-det-vol.mac ntuple-flat.mac)

foreach(_mac ${_macros})
Expand All @@ -35,7 +36,11 @@ endforeach()
list(TRANSFORM _macros PREPEND "output/hdf5-" OUTPUT_VARIABLE _macros_hdf5)
set_tests_properties(${_macros_hdf5} PROPERTIES LABELS extra DEPENDS output/build-test-visit-hdf5)

# SPECIAL TESTS
add_test(NAME output/th228-chain COMMAND ./run-test-th228-chain.py $<TARGET_FILE:remage-cli>)

# Geant4 <= 11.0.3 is deleting non-empty HDF5 files after a successful run, so disable the tests.
if(Geant4_VERSION VERSION_LESS "11.0.4" OR NOT RMG_HAS_HDF5)
set_tests_properties(${_macros_hdf5} PROPERTIES DISABLED True)
set_tests_properties("output/th228-chain" PROPERTIES DISABLED True)
endif()
17 changes: 17 additions & 0 deletions tests/output/gdml/geometry-box.gdml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" ?>
<gdml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd">
<define/>
<materials/>
<solids>
<box name="world" x="2" y="2" z="2" lunit="m"/>
</solids>
<structure>
<volume name="world">
<materialref ref="G4_lAr"/>
<solidref ref="world"/>
</volume>
</structure>
<setup name="Default" version="1.0">
<world ref="world"/>
</setup>
</gdml>
19 changes: 19 additions & 0 deletions tests/output/macros/th228-chain.mac
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/RMG/Geometry/GDMLDisableOverlapCheck true

/RMG/Output/ActivateOutputScheme Track

/run/initialize

# /RMG/Output/Track/AddProcessFilter Radioactivation
# /RMG/Output/Track/SetEnergyFilter 0.01 MeV

/RMG/Generator/Confine UnConfined

/RMG/Generator/Select GPS
/gps/position 0 0 0
/gps/particle ion
/gps/ion 90 228
/gps/energy 0 keV
/gps/ang/type iso

/run/beamOn 10
28 changes: 28 additions & 0 deletions tests/output/run-test-th228-chain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/env python3

import subprocess
import sys

from lgdo import lh5

rmg = sys.argv[1]
macro = "macros/th228-chain.mac"
output_lh5 = "th228-chain.lh5"

# run remage, produce lh5 output.
subprocess.run([rmg, "-g", "gdml/geometry-box.gdml", "-o", output_lh5, "-w", "--", macro])

# check that we get to stable isotopes.
tracks = lh5.read("stp/tracks", output_lh5).view_as("pd")
particle_numbers = tracks["particle"].value_counts()
assert particle_numbers[1000902280] == 10 # primaries.
assert particle_numbers[1000822080] == 10 # we should always get to Pb208.

# check that we had some common processes.
processes = lh5.read("stp/processes", output_lh5)["name"].view_as("np")
print(processes)
assert b"Radioactivation" in processes
assert b"eBrem" in processes
assert b"eIoni" in processes
assert b"phot" in processes
assert b"compt" in processes

0 comments on commit 6a5abe8

Please sign in to comment.