Skip to content

Commit

Permalink
feat: Add python CKF example (#1032)
Browse files Browse the repository at this point in the history
This PR adds a python example for running the CKF. It can be configured to use truth smeared seeds, truth estimated seeds or full seeding. I tried to make sure the configuration paths are consistent, but I would hope a reviewer could make sure I didn't miss anything important.

Also adds a test that checks the example script's outputs (to some degree)
  • Loading branch information
paulgessinger committed Oct 19, 2021
1 parent 127089f commit 43d0b76
Show file tree
Hide file tree
Showing 2 changed files with 519 additions and 0 deletions.
163 changes: 163 additions & 0 deletions Examples/Python/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,166 @@ def test_geometry_example(geoFactory, nobj, tmp_path):
material_file = tmp_path / "geometry-map.json"
assert material_file.exists()
assert material_file.stat().st_size > 200


def test_ckf_tracks_example_full_seeding(tmp_path):
# the example as written is only compatible with the generic detector
detector, trackingGeometry, decorators = GenericDetector.create()

field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
events = 10
s = Sequencer(events=events, numThreads=1) # Digitization is not thread-safe

root_files = [
("performance_ckf.root", None, None),
("performance_seeding_trees.root", "track_finder_tracks", 368),
("performance_seeding_trees.root", "track_finder_particles", 80),
("trackstates_ckf.root", "trackstates", 368),
("tracksummary_ckf.root", "tracksummary", 10),
]

csv = tmp_path / "csv"

assert not csv.exists()
for rf, _, _ in root_files:
assert not (tmp_path / rf).exists()

from ckf_tracks import runCKFTracks

runCKFTracks(
trackingGeometry,
decorators,
field=field,
geometrySelection=Path(
"Examples/Algorithms/TrackFinding/share/geoSelection-genericDetector.json"
),
digiConfigFile=Path(
"Examples/Algorithms/Digitization/share/default-smearing-config-generic.json"
),
outputCsv=True,
outputDir=tmp_path,
truthSmearedSeeded=False,
truthEstimatedSeeded=False,
s=s,
)
s.run()

del s # files are closed in destructors, not great

assert csv.exists()
for rf, tn, nume in root_files:
rp = tmp_path / rf
assert rp.exists()
if tn is not None and nume is not None:
assert_entries(rp, tn, nume)

assert len([f for f in csv.iterdir() if f.name.endswith("CKFtracks.csv")]) == events
assert all([f.stat().st_size > 300 for f in csv.iterdir()])


def test_ckf_tracks_example_truth_estimate(tmp_path):
# the example as written is only compatible with the generic detector
detector, trackingGeometry, decorators = GenericDetector.create()

field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
events = 10
s = Sequencer(events=events, numThreads=1) # Digitization is not thread-safe

root_files = [
("performance_ckf.root", None, None),
("performance_seeding_trees.root", "track_finder_tracks", 80),
("performance_seeding_trees.root", "track_finder_particles", 80),
("trackstates_ckf.root", "trackstates", 80),
("tracksummary_ckf.root", "tracksummary", 10),
]

csv = tmp_path / "csv"

assert not csv.exists()
for rf, _, _ in root_files:
assert not (tmp_path / rf).exists()

from ckf_tracks import runCKFTracks

runCKFTracks(
trackingGeometry,
decorators,
field=field,
geometrySelection=Path(
"Examples/Algorithms/TrackFinding/share/geoSelection-genericDetector.json"
),
digiConfigFile=Path(
"Examples/Algorithms/Digitization/share/default-smearing-config-generic.json"
),
outputCsv=True,
outputDir=tmp_path,
truthSmearedSeeded=False,
truthEstimatedSeeded=True,
s=s,
)
s.run()

del s # files are closed in destructors, not great

assert csv.exists()
for rf, tn, nume in root_files:
rp = tmp_path / rf
assert rp.exists()
if tn is not None and nume is not None:
assert_entries(rp, tn, nume)

assert len([f for f in csv.iterdir() if f.name.endswith("CKFtracks.csv")]) == events
assert all([f.stat().st_size > 100 for f in csv.iterdir()])


def test_ckf_tracks_example_truth_smeared(tmp_path):
# the example as written is only compatible with the generic detector
detector, trackingGeometry, decorators = GenericDetector.create()

field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
events = 10
s = Sequencer(events=events, numThreads=1) # Digitization is not thread-safe

root_files = [
("performance_ckf.root", None, None),
("trackstates_ckf.root", "trackstates", 80),
("tracksummary_ckf.root", "tracksummary", 10),
]

csv = tmp_path / "csv"

assert not csv.exists()
for rf, _, _ in root_files:
assert not (tmp_path / rf).exists()

from ckf_tracks import runCKFTracks

runCKFTracks(
trackingGeometry,
decorators,
field=field,
geometrySelection=Path(
"Examples/Algorithms/TrackFinding/share/geoSelection-genericDetector.json"
),
digiConfigFile=Path(
"Examples/Algorithms/Digitization/share/default-smearing-config-generic.json"
),
outputCsv=True,
outputDir=tmp_path,
truthSmearedSeeded=True,
truthEstimatedSeeded=False,
s=s,
)
s.run()

del s # files are closed in destructors, not great

assert csv.exists()
for rf, tn, nume in root_files:
rp = tmp_path / rf
assert rp.exists()
if tn is not None and nume is not None:
assert_entries(rp, tn, nume)

assert len([f for f in csv.iterdir() if f.name.endswith("CKFtracks.csv")]) == events
assert all([f.stat().st_size > 300 for f in csv.iterdir()])

0 comments on commit 43d0b76

Please sign in to comment.