Skip to content

Commit

Permalink
feat: Python examples updates for CKF and ITk (#1244)
Browse files Browse the repository at this point in the history
* `addCKFTracks` args has its own `CKFPerformanceConfig` instead of borrowing `TruthSeedRanges`, which isn't the same thing.
* ATLAS ITk examples now in `acts-itk` instead of `acts-detector-examples/atlas`. The GitLab repo has moved. Ask us for access.
  • Loading branch information
timadye committed May 13, 2022
1 parent 7ae1264 commit df3e23d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
27 changes: 18 additions & 9 deletions Examples/Scripts/Python/ckf_tracks.py
@@ -1,23 +1,29 @@
#!/usr/bin/env python3
from pathlib import Path
from typing import Optional, Union
from collections import namedtuple

from acts.examples import Sequencer, GenericDetector, RootParticleReader

import acts

from acts import UnitConstants as u
from seeding import TruthSeedRanges

CKFPerformanceConfig = namedtuple(
"CKFPerformanceConfig",
["truthMatchProbMin", "nMeasurementsMin", "ptMin"],
defaults=[None] * 3,
)


@acts.examples.NamedTypeArgs(
truthSeedRanges=TruthSeedRanges,
CKFPerformanceConfigArg=CKFPerformanceConfig,
)
def addCKFTracks(
s: acts.examples.Sequencer,
trackingGeometry: acts.TrackingGeometry,
field: acts.MagneticFieldProvider,
truthSeedRanges: TruthSeedRanges = TruthSeedRanges(),
CKFPerformanceConfigArg: CKFPerformanceConfig = CKFPerformanceConfig(),
outputDirCsv: Optional[Union[Path, str]] = None,
outputDirRoot: Optional[Union[Path, str]] = None,
selectedParticles: str = "truth_seeds_selected",
Expand All @@ -30,8 +36,8 @@ def addCKFTracks(
the sequencer module to which we add the Seeding steps (returned from addSeeding)
trackingGeometry : tracking geometry
field : magnetic field
truthSeedRanges : TruthSeedRanges(nHits, pt)
CKFPerformanceWriter configuration. Each range is specified as a tuple of (min,max), though currently only the min is used.
CKFPerformanceConfigArg : CKFPerformanceConfig(truthMatchProbMin, nMeasurementsMin, ptMin)
CKFPerformanceWriter configuration.
Defaults specified in Examples/Io/Performance/ActsExamples/Io/Performance/CKFPerformanceWriter.hpp
outputDirCsv : Path|str, path, None
the output folder for the Csv output, None triggers no output
Expand Down Expand Up @@ -105,9 +111,12 @@ def addCKFTracks(
inputParticles=selectedParticles,
inputTrajectories=trackFinder.config.outputTrajectories,
inputMeasurementParticlesMap="measurement_particles_map",
# The bottom seed could be the first, second or third hits on the truth track
nMeasurementsMin=truthSeedRanges.nHits[0],
ptMin=truthSeedRanges.pt[0],
**acts.examples.defaultKWArgs(
# The bottom seed could be the first, second or third hits on the truth track
nMeasurementsMin=CKFPerformanceConfigArg.nMeasurementsMin,
ptMin=CKFPerformanceConfigArg.ptMin,
truthMatchProbMin=CKFPerformanceConfigArg.truthMatchProbMin,
),
filePath=str(outputDirRoot / "performance_ckf.root"),
)
s.addWriter(ckfPerfWriter)
Expand Down Expand Up @@ -233,7 +242,7 @@ def runCKFTracks(
s,
trackingGeometry,
field,
TruthSeedRanges(pt=(400.0 * u.MeV, None), nHits=(6, None)),
CKFPerformanceConfig(ptMin=400.0 * u.MeV, nMeasurementsMin=6),
outputDirRoot=outputDir,
outputDirCsv=outputDir / "csv" if outputCsv else None,
)
Expand Down
10 changes: 5 additions & 5 deletions Examples/Scripts/Python/full_chain_itk.py
Expand Up @@ -2,7 +2,7 @@
import pathlib, acts, acts.examples, itk

u = acts.UnitConstants
geo_dir = pathlib.Path("acts-detector-examples")
geo_dir = pathlib.Path("acts-itk")
outputDir = pathlib.Path.cwd()

detector, trackingGeometry, decorators = itk.buildITkGeometry(geo_dir)
Expand All @@ -13,7 +13,7 @@
from fatras import addFatras
from digitization import addDigitization
from seeding import addSeeding, SeedingAlgorithm, TruthSeedRanges
from ckf_tracks import addCKFTracks
from ckf_tracks import addCKFTracks, CKFPerformanceConfig

s = acts.examples.Sequencer(events=100, numThreads=-1)
s = addParticleGun(
Expand All @@ -34,7 +34,7 @@
s,
trackingGeometry,
field,
digiConfigFile=geo_dir / "atlas/itk-hgtd/itk-smearing-config.json",
digiConfigFile=geo_dir / "itk-hgtd/itk-smearing-config.json",
outputDirRoot=outputDir,
rnd=rnd,
)
Expand All @@ -43,14 +43,14 @@
trackingGeometry,
field,
TruthSeedRanges(pt=(1.0 * u.GeV, None), eta=(-4.0, 4.0), nHits=(9, None)),
geoSelectionConfigFile=geo_dir / "atlas/itk-hgtd/geoSelection-ITk.json",
geoSelectionConfigFile=geo_dir / "itk-hgtd/geoSelection-ITk.json",
outputDirRoot=outputDir,
)
s = addCKFTracks(
s,
trackingGeometry,
field,
TruthSeedRanges(pt=(400.0 * u.MeV, None), nHits=(6, None)),
CKFPerformanceConfig(ptMin=400.0 * u.MeV, nMeasurementsMin=6),
outputDirRoot=outputDir,
)

Expand Down
4 changes: 2 additions & 2 deletions Examples/Scripts/Python/full_chain_odd.py
Expand Up @@ -24,7 +24,7 @@
from fatras import addFatras
from digitization import addDigitization
from seeding import addSeeding, SeedingAlgorithm, TruthSeedRanges
from ckf_tracks import addCKFTracks
from ckf_tracks import addCKFTracks, CKFPerformanceConfig

s = acts.examples.Sequencer(events=100, numThreads=-1, logLevel=acts.logging.INFO)

Expand Down Expand Up @@ -63,7 +63,7 @@
s,
trackingGeometry,
field,
TruthSeedRanges(pt=(400.0 * u.MeV, None), nHits=(6, None)),
CKFPerformanceConfig(ptMin=400.0 * u.MeV, nMeasurementsMin=6),
outputDirRoot=outputDir,
)

Expand Down
6 changes: 3 additions & 3 deletions Examples/Scripts/Python/itk.py
Expand Up @@ -105,17 +105,17 @@ def buildITkGeometry(

matDeco = None
if material:
file = geo_dir / "atlas/itk-hgtd/material-maps-ITk-HGTD.json"
file = geo_dir / "itk-hgtd/material-maps-ITk-HGTD.json"
logger.info("Adding material from %s", file.absolute())
matDeco = acts.IMaterialDecorator.fromFile(
file,
level=acts.logging.Level(min(acts.logging.INFO.value, logLevel.value)),
)

tgeo_fileName = geo_dir / "atlas/itk-hgtd/ATLAS-ITk-HGTD.tgeo.root"
tgeo_fileName = geo_dir / "itk-hgtd/ATLAS-ITk-HGTD.tgeo.root"

if jsonconfig:
jsonFile = geo_dir / "atlas/itk-hgtd/tgeo-atlas-itk-hgtd.json"
jsonFile = geo_dir / "itk-hgtd/tgeo-atlas-itk-hgtd.json"
logger.info("Create geometry from %s", jsonFile.absolute())
return TGeoDetector.create(
jsonFile=str(jsonFile),
Expand Down

0 comments on commit df3e23d

Please sign in to comment.