Skip to content

Commit

Permalink
test: Parametrize tests on geometry, add minimal GSF reproducibility …
Browse files Browse the repository at this point in the history
…test (#1292)

Uses a fixture to more elegantly parametrize the CKF tracks and truth
tracking tests with the generic detector and the ODD. Add a truth
tracking GSF test with hash checks. Also adjusts `truth_tracking_gsf.py`
slightly to mirror `truth_tracking_kalman.py` a bit more closely.
  • Loading branch information
paulgessinger committed Jun 29, 2022
1 parent a4a1b96 commit e51585c
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 82 deletions.
65 changes: 64 additions & 1 deletion Examples/Python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Dict
import warnings
import pytest_check as check
from collections import namedtuple


sys.path += [
Expand All @@ -15,7 +16,7 @@

import helpers
import helpers.hash_root
from common import getOpenDataDetectorDirectory
from common import getOpenDataDetectorDirectory, getOpenDataDetector

import pytest

Expand Down Expand Up @@ -196,6 +197,68 @@ def trk_geo(request):
yield geo


DetectorConfig = namedtuple(
"DetectorConfig",
[
"detector",
"trackingGeometry",
"decorators",
"geometrySelection",
"digiConfigFile",
],
)


@pytest.fixture(
params=[
"generic",
"odd",
]
)
def detector_config(request):
srcdir = Path(__file__).resolve().parent.parent.parent.parent

if request.param == "generic":
detector, trackingGeometry, decorators = acts.examples.GenericDetector.create()
return DetectorConfig(
detector,
trackingGeometry,
decorators,
geometrySelection=(
srcdir
/ "Examples/Algorithms/TrackFinding/share/geoSelection-genericDetector.json"
),
digiConfigFile=(
srcdir
/ "Examples/Algorithms/Digitization/share/default-smearing-config-generic.json"
),
)
elif request.param == "odd":
if not helpers.dd4hepEnabled:
pytest.skip("DD4hep not set up")

matDeco = acts.IMaterialDecorator.fromFile(
srcdir / "thirdparty/OpenDataDetector/data/odd-material-maps.root",
level=acts.logging.INFO,
)
detector, trackingGeometry, decorators = getOpenDataDetector(matDeco)
return DetectorConfig(
detector,
trackingGeometry,
decorators,
digiConfigFile=(
srcdir
/ "thirdparty/OpenDataDetector/config/odd-digi-smearing-config.json"
),
geometrySelection=(
srcdir / "thirdparty/OpenDataDetector/config/odd-seeding-config.json"
),
)

else:
raise ValueError(f"Invalid detector {detector}")


@pytest.fixture
def ptcl_gun(rng):
def _factory(s):
Expand Down
55 changes: 33 additions & 22 deletions Examples/Python/tests/root_file_hashes.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
test_ckf_tracks_example[full_seeding-generic]__trackstates_ckf.root: 67e0899d0891a0b330555c07dbd31952698d3888262b3fb827331b3a43b8e8ea
test_ckf_tracks_example[full_seeding-generic]__tracksummary_ckf.root: 9b1a1b432d6c82a60f08fdfd84f90ee566bdd2a86bee1c755cb064e71222712e
test_ckf_tracks_example[full_seeding-generic]__performance_seeding_trees.root: 4890c1f1fb8618f59d4e5c2c0338af0595f2b92847b8eaced8a24e0fc1eb2934
test_ckf_tracks_example[full_seeding-odd]__trackstates_ckf.root: 18f1328a34920b2485bc129aa7ac0ab2bd13432fbd6e379295e3c4ee3a62006f
test_ckf_tracks_example[full_seeding-odd]__tracksummary_ckf.root: f323c0d6bfa66429e74f103269489e9b70a85f92e5cf319d6b5a91834a339226
test_ckf_tracks_example[full_seeding-odd]__performance_seeding_trees.root: 74a1754b03812343dfbec54276152294ce92da3e35d6ad43a393580101b9a678
test_ckf_tracks_example[truth_estimated-generic]__trackstates_ckf.root: 9e2afb3defe3f4f32d7fe5b4ca342654e4ca97d585569985998e229dfa8f0da6
test_ckf_tracks_example[truth_estimated-generic]__tracksummary_ckf.root: 94267dea26347dea32a235c5bd034f2fc52bf5ab40be42be311aa7ef89bd7f09
test_ckf_tracks_example[truth_estimated-generic]__performance_seeding_trees.root: 471373aceff30b77fc0844eef16fd423911f46981ebe7e78a6cbb239c315d04f
test_ckf_tracks_example[truth_estimated-odd]__trackstates_ckf.root: 97addf782956d98ed77c67d8b006237beb28ff870d183d2fd5837591c23798b4
test_ckf_tracks_example[truth_estimated-odd]__tracksummary_ckf.root: 11926164d0ca1d957f45915f6b987ee0f45d371efdfb7b2743822022a2076514
test_ckf_tracks_example[truth_estimated-odd]__performance_seeding_trees.root: 8c2d04afba265cb02919100a9ec1349cb797363ed65f5e651bf7e80a5a86c9c2
test_ckf_tracks_example[truth_smeared-generic]__trackstates_ckf.root: 47bad97dbb46dc27d20de9650cc8eb7980bd1fe28e4f9e5f157ea2a284e261f5
test_ckf_tracks_example[truth_smeared-generic]__tracksummary_ckf.root: 6dc5cea98aea326115cfa7aa510f4c899e9a74f7bfc7e9f01786f6ead217a645
test_ckf_tracks_example[truth_smeared-odd]__trackstates_ckf.root: d42bdb444a67ffa560d2eec79eab5c44a4cc1599f3b4b3733d15b8495ca1bea7
test_ckf_tracks_example[truth_smeared-odd]__tracksummary_ckf.root: 0d87a3613093d6f65da8d0995d63d47583599897c91f7a1738f0544b704d2fca
test_ckf_tracks_example[generic-full_seeding]__trackstates_ckf.root: 67e0899d0891a0b330555c07dbd31952698d3888262b3fb827331b3a43b8e8ea
test_ckf_tracks_example[generic-full_seeding]__tracksummary_ckf.root: 9b1a1b432d6c82a60f08fdfd84f90ee566bdd2a86bee1c755cb064e71222712e
test_ckf_tracks_example[generic-full_seeding]__performance_seeding_trees.root: 4890c1f1fb8618f59d4e5c2c0338af0595f2b92847b8eaced8a24e0fc1eb2934
test_ckf_tracks_example[odd-full_seeding]__trackstates_ckf.root: 18f1328a34920b2485bc129aa7ac0ab2bd13432fbd6e379295e3c4ee3a62006f
test_ckf_tracks_example[odd-full_seeding]__tracksummary_ckf.root: f323c0d6bfa66429e74f103269489e9b70a85f92e5cf319d6b5a91834a339226
test_ckf_tracks_example[odd-full_seeding]__performance_seeding_trees.root: 74a1754b03812343dfbec54276152294ce92da3e35d6ad43a393580101b9a678
test_ckf_tracks_example[generic-truth_estimated]__trackstates_ckf.root: 9e2afb3defe3f4f32d7fe5b4ca342654e4ca97d585569985998e229dfa8f0da6
test_ckf_tracks_example[generic-truth_estimated]__tracksummary_ckf.root: 94267dea26347dea32a235c5bd034f2fc52bf5ab40be42be311aa7ef89bd7f09
test_ckf_tracks_example[generic-truth_estimated]__performance_seeding_trees.root: 471373aceff30b77fc0844eef16fd423911f46981ebe7e78a6cbb239c315d04f
test_ckf_tracks_example[odd-truth_estimated]__trackstates_ckf.root: 97addf782956d98ed77c67d8b006237beb28ff870d183d2fd5837591c23798b4
test_ckf_tracks_example[odd-truth_estimated]__tracksummary_ckf.root: 11926164d0ca1d957f45915f6b987ee0f45d371efdfb7b2743822022a2076514
test_ckf_tracks_example[odd-truth_estimated]__performance_seeding_trees.root: 8c2d04afba265cb02919100a9ec1349cb797363ed65f5e651bf7e80a5a86c9c2
test_ckf_tracks_example[generic-truth_smeared]__trackstates_ckf.root: 47bad97dbb46dc27d20de9650cc8eb7980bd1fe28e4f9e5f157ea2a284e261f5
test_ckf_tracks_example[generic-truth_smeared]__tracksummary_ckf.root: 6dc5cea98aea326115cfa7aa510f4c899e9a74f7bfc7e9f01786f6ead217a645
test_ckf_tracks_example[odd-truth_smeared]__trackstates_ckf.root: d42bdb444a67ffa560d2eec79eab5c44a4cc1599f3b4b3733d15b8495ca1bea7
test_ckf_tracks_example[odd-truth_smeared]__tracksummary_ckf.root: 0d87a3613093d6f65da8d0995d63d47583599897c91f7a1738f0544b704d2fca



Expand Down Expand Up @@ -55,12 +55,23 @@ test_root_clusters_writer[configKwConstructor]__clusters.root: 7e452af7243d282dd
test_root_clusters_writer[kwargsConstructor]__clusters.root: 7e452af7243d282dd0a8f5aa2844e150ef44364980bf3641718899068a1a1ecb
test_root_material_writer__material.root: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

test_truth_tracking[0.0]__trackstates_fitter.root: 58249c45808c38839513fc4e4eeb9108ede4485598526b25ec7b748c473c509d
test_truth_tracking[0.0]__tracksummary_fitter.root: 7cb528b8659102815899e0b65ecef64596f3fe3e389e6463ab0b344c6a57cad3
test_truth_tracking[0.0]__performance_track_finder.root: 76a990d595b6e097da2bed447783bd63044956e5649a5dd6fd7a6a3434786877
test_truth_tracking[1000.0]__trackstates_fitter.root: 2d07f506aeb02301311b407197167994ca43b2c2775caf80874fb0581872db81
test_truth_tracking[1000.0]__tracksummary_fitter.root: ab1dfaa084206d3a91c7038ab3a6795b1dc83f62353cb017d1e7a30e4ee5957d
test_truth_tracking[1000.0]__performance_track_finder.root: 76a990d595b6e097da2bed447783bd63044956e5649a5dd6fd7a6a3434786877
test_truth_tracking_kalman[generic-0.0]__trackstates_fitter.root: 7b9492a1f194c53b92b2b6b6f1979c1cbd8512d0f332d68454cda2c54f26d624
test_truth_tracking_kalman[generic-0.0]__tracksummary_fitter.root: 43eafc39203045dd6ee7bb3ae1ab0c6f24ff09bb6e91ee2a24fd2eaf1b3181cc
test_truth_tracking_kalman[generic-0.0]__performance_track_finder.root: 2ce5d720a0c97f3e01140efee711a4b6c5b59b97850c1f04c97aa2dcfa3106e3
test_truth_tracking_kalman[generic-1000.0]__trackstates_fitter.root: 9983c0ac8249030c6a3fcb60e43e6fadd6ffb4f9b964665adbda4fbf62047988
test_truth_tracking_kalman[generic-1000.0]__tracksummary_fitter.root: b3f1a97bf8dbd707a21dd1cd05cad94ad99772ef8597433f4c2b77449e0b5f47
test_truth_tracking_kalman[generic-1000.0]__performance_track_finder.root: 2ce5d720a0c97f3e01140efee711a4b6c5b59b97850c1f04c97aa2dcfa3106e3
test_truth_tracking_kalman[odd-0.0]__trackstates_fitter.root: ae88a75d5b2e7c2fd55392f20d52dba420e543d45e7bccf40ea441e2dd0015aa
test_truth_tracking_kalman[odd-0.0]__tracksummary_fitter.root: 030fecde00868bee06ce95fe77ab380456a357cf277da237fcd3ed6334c9aba3
test_truth_tracking_kalman[odd-0.0]__performance_track_finder.root: 76a990d595b6e097da2bed447783bd63044956e5649a5dd6fd7a6a3434786877
test_truth_tracking_kalman[odd-1000.0]__trackstates_fitter.root: 5ea6ca504f89355267e10c94408490d500d8389fe9bb043c544dfe91d3e80f20
test_truth_tracking_kalman[odd-1000.0]__tracksummary_fitter.root: c7b3ff9d8d3c19ac378ed7f7c63f396fe504674999efb3131d1009a9c5d3bf2f
test_truth_tracking_kalman[odd-1000.0]__performance_track_finder.root: 76a990d595b6e097da2bed447783bd63044956e5649a5dd6fd7a6a3434786877

test_truth_tracking_gsf[generic]__trackstates_gsf.root: 39e0b75eb4cac0e65f662dc32f7ed30e25137f94f18878a866c4fc978b25dda9
test_truth_tracking_gsf[generic]__tracksummary_gsf.root: 5acec4eac7b8046da8531b1dfda376a4789486fe835c6e462968631e028030ad
test_truth_tracking_gsf[odd]__trackstates_gsf.root: 56ba8ffc0f9b8569c4baab11724a6fae82cd0697073e8c7302c7bf5b8f39bd40
test_truth_tracking_gsf[odd]__tracksummary_gsf.root: 3ad19eb56e1b3b3717b51c89780744c05e5ea2c53d8f3a5d3631e1f716c3c2b9

test_digitization_example_input__measurements.root: ccc92f0ad538d1b62d98f19f947970bcc491843e54d8ffeed16ad2e226b8caee
test_digitization_example_input__particles.root: 78a89f365177423d0834ea6f1bd8afe1488e72b12a25066a20bd9050f5407860
Expand Down
96 changes: 49 additions & 47 deletions Examples/Python/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,12 @@ def test_event_recording(tmp_path):
assert alg.events_seen == 1


@pytest.mark.skipif(not dd4hepEnabled, reason="DD4hep not set up")
@pytest.mark.parametrize("revFiltMomThresh", [0 * u.GeV, 1 * u.TeV])
def test_truth_tracking(tmp_path, assert_root_hash, revFiltMomThresh):
def test_truth_tracking_kalman(
tmp_path, assert_root_hash, revFiltMomThresh, detector_config
):
from truth_tracking_kalman import runTruthTrackingKalman

detector, trackingGeometry, _ = getOpenDataDetector()

field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))

seq = Sequencer(events=10, numThreads=1)
Expand All @@ -397,11 +396,10 @@ def test_truth_tracking(tmp_path, assert_root_hash, revFiltMomThresh):
assert not fp.exists()

runTruthTrackingKalman(
trackingGeometry,
field,
digiConfigFile=Path(
"thirdparty/OpenDataDetector/config/odd-digi-smearing-config.json",
),
trackingGeometry=detector_config.trackingGeometry,
decorators=detector_config.decorators,
field=field,
digiConfigFile=detector_config.digiConfigFile,
outputDir=tmp_path,
reverseFilteringMomThreshold=revFiltMomThresh,
s=seq,
Expand All @@ -420,6 +418,43 @@ def test_truth_tracking(tmp_path, assert_root_hash, revFiltMomThresh):
assert_root_hash(fn, fp)


def test_truth_tracking_gsf(tmp_path, assert_root_hash, detector_config):
from truth_tracking_gsf import runTruthTrackingGsf

field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))

seq = Sequencer(events=10, numThreads=1)

root_files = [
("trackstates_gsf.root", "trackstates"),
("tracksummary_gsf.root", "tracksummary"),
]

for fn, _ in root_files:
fp = tmp_path / fn
assert not fp.exists()

runTruthTrackingGsf(
trackingGeometry=detector_config.trackingGeometry,
decorators=detector_config.decorators,
field=field,
digiConfigFile=detector_config.digiConfigFile,
outputDir=tmp_path,
s=seq,
)

seq.run()

del seq

for fn, tn in root_files:
fp = tmp_path / fn
assert fp.exists()
assert fp.stat().st_size > 1024
if tn is not None:
assert_root_hash(fn, fp)


def test_particle_gun(tmp_path, assert_root_hash):
from particle_gun import runParticleGun

Expand Down Expand Up @@ -776,13 +811,6 @@ def test_digitization_config_example(trk_geo, tmp_path):
assert len(data["entries"]) == 27


@pytest.mark.parametrize(
"detector",
[
"generic",
"odd",
],
)
@pytest.mark.parametrize(
"truthSmeared,truthEstimated",
[
Expand All @@ -793,39 +821,13 @@ def test_digitization_config_example(trk_geo, tmp_path):
ids=["full_seeding", "truth_estimated", "truth_smeared"],
)
def test_ckf_tracks_example(
tmp_path, assert_root_hash, truthSmeared, truthEstimated, detector
tmp_path, assert_root_hash, truthSmeared, truthEstimated, detector_config
):
csv = tmp_path / "csv"

assert not csv.exists()

srcdir = Path(__file__).resolve().parent.parent.parent.parent
if detector == "generic":
detector, trackingGeometry, decorators = GenericDetector.create()
geometrySelection = (
srcdir
/ "Examples/Algorithms/TrackFinding/share/geoSelection-genericDetector.json"
)
digiConfigFile = (
srcdir
/ "Examples/Algorithms/Digitization/share/default-smearing-config-generic.json"
)
elif detector == "odd":

matDeco = acts.IMaterialDecorator.fromFile(
srcdir / "thirdparty/OpenDataDetector/data/odd-material-maps.root",
level=acts.logging.INFO,
)
detector, trackingGeometry, decorators = getOpenDataDetector(matDeco)
digiConfigFile = (
srcdir / "thirdparty/OpenDataDetector/config/odd-digi-smearing-config.json"
)
geometrySelection = (
srcdir / "thirdparty/OpenDataDetector/config/odd-seeding-config.json"
)

else:
raise ValueError(f"Invalid detector {detector}")

field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
events = 100
Expand Down Expand Up @@ -860,13 +862,13 @@ def test_ckf_tracks_example(
from ckf_tracks import runCKFTracks

runCKFTracks(
trackingGeometry,
decorators,
detector_config.trackingGeometry,
detector_config.decorators,
field=field,
outputCsv=True,
outputDir=tmp_path,
geometrySelection=geometrySelection,
digiConfigFile=digiConfigFile,
geometrySelection=detector_config.geometrySelection,
digiConfigFile=detector_config.digiConfigFile,
truthSmearedSeeded=truthSmeared,
truthEstimatedSeeded=truthEstimated,
s=s,
Expand Down
17 changes: 5 additions & 12 deletions Examples/Scripts/Python/truth_tracking_gsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from acts import UnitConstants as u


def addGsfTracks(
def addTruthTrackingGsf(
s: acts.examples.Sequencer,
trackingGeometry: acts.TrackingGeometry,
field: acts.MagneticFieldProvider,
Expand Down Expand Up @@ -40,17 +40,14 @@ def addGsfTracks(
return s


def runGsfTracks(
def runTruthTrackingGsf(
trackingGeometry,
decorators,
geometrySelection: Path,
digiConfigFile: Path,
field,
outputDir: Path,
truthSmearedSeeded=False,
truthEstimatedSeeded=False,
outputCsv=True,
inputParticlePath: Optional[Path] = None,
decorators=[],
s=None,
):

Expand Down Expand Up @@ -123,7 +120,7 @@ def runGsfTracks(

s.addAlgorithm(truthTrkFndAlg)

s = addGsfTracks(s, trackingGeometry, field)
s = addTruthTrackingGsf(s, trackingGeometry, field)

# Output
s.addWriter(
Expand Down Expand Up @@ -162,17 +159,13 @@ def runGsfTracks(
if not inputParticlePath.exists():
inputParticlePath = None

runGsfTracks(
runTruthTrackingGsf(
trackingGeometry,
decorators,
field=field,
geometrySelection=srcdir
/ "Examples/Algorithms/TrackFinding/share/geoSelection-genericDetector.json",
digiConfigFile=srcdir
/ "Examples/Algorithms/Digitization/share/default-smearing-config-generic.json",
outputCsv=True,
truthSmearedSeeded=False,
truthEstimatedSeeded=False,
inputParticlePath=inputParticlePath,
outputDir=Path.cwd(),
).run()
1 change: 1 addition & 0 deletions Examples/Scripts/Python/truth_tracking_kalman.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def runTruthTrackingKalman(
field: acts.MagneticFieldProvider,
outputDir: Path,
digiConfigFile: Path,
decorators=[],
directNavigation=False,
reverseFilteringMomThreshold=0 * u.GeV,
s: acts.examples.Sequencer = None,
Expand Down

0 comments on commit e51585c

Please sign in to comment.