Skip to content

Commit

Permalink
refactor: Move add* functions to python modules (#1309)
Browse files Browse the repository at this point in the history
The add* (i.e. addFatras, addPythia8) were moved to modules
in Examples/python/acts/examples.
Two modules were made: simulation hosting generation, simulation and digization
and reconstruciton.

They can be used as follows:
from acts.examples.simulation import addFatras

Example scripts are refactored to use the new location of add* functions.

resolves #1242

FI: @timadye  @paulgessinger
  • Loading branch information
tboldagh authored Jul 27, 2022
1 parent 2256d4e commit b4dc20d
Show file tree
Hide file tree
Showing 29 changed files with 1,780 additions and 1,579 deletions.
23 changes: 16 additions & 7 deletions CI/physmon/physmon.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,27 @@
acts.logging.setFailureThreshold(acts.logging.FATAL)

from truth_tracking_kalman import runTruthTrackingKalman
from ckf_tracks import addCKFTracks, CKFPerformanceConfig
from fatras import addFatras
from digitization import addDigitization
from particle_gun import addParticleGun, EtaConfig, PhiConfig, ParticleConfig
from seeding import (
from common import getOpenDataDetectorDirectory
from acts.examples.odd import getOpenDataDetector
from acts.examples.simulation import (
addParticleGun,
EtaConfig,
PhiConfig,
ParticleConfig,
addFatras,
addDigitization,
)
from acts.examples.reconstruction import (
addSeeding,
TruthSeedRanges,
ParticleSmearingSigmas,
SeedfinderConfigArg,
SeedingAlgorithm,
TrackParamsEstimationConfig,
addCKFTracks,
CKFPerformanceConfig,
)

from common import getOpenDataDetector

parser = argparse.ArgumentParser()
parser.add_argument("outdir")
Expand All @@ -54,7 +61,9 @@
srcdir / "thirdparty/OpenDataDetector/data/odd-material-maps.root",
level=acts.logging.INFO,
)
detector, trackingGeometry, decorators = getOpenDataDetector(matDeco)
detector, trackingGeometry, decorators = getOpenDataDetector(
getOpenDataDetectorDirectory(), matDeco
)
digiConfig = srcdir / "thirdparty/OpenDataDetector/config/odd-digi-smearing-config.json"
geoSel = srcdir / "thirdparty/OpenDataDetector/config/odd-seeding-config.json"

Expand Down
4 changes: 4 additions & 0 deletions Examples/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ target_link_libraries(ActsPythonBindings PUBLIC
set(py_files
__init__.py
examples/__init__.py
examples/simulation.py
examples/reconstruction.py
examples/itk.py
examples/odd.py
_adapter.py
)

Expand Down
251 changes: 251 additions & 0 deletions Examples/Python/python/acts/examples/itk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
#!/usr/bin/env python3
import acts
from acts.examples import TGeoDetector
from pathlib import Path

u = acts.UnitConstants


def buildITkGeometry(
geo_dir: Path,
material: bool = True,
jsonconfig: bool = False,
logLevel=acts.logging.WARNING,
):

logger = acts.logging.getLogger("buildITkGeometry")

matDeco = None
if material:
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 / "itk-hgtd/ATLAS-ITk-HGTD.tgeo.root"

if jsonconfig:
jsonFile = geo_dir / "itk-hgtd/tgeo-atlas-itk-hgtd.json"
logger.info("Create geometry from %s", jsonFile.absolute())
return TGeoDetector.create(
jsonFile=str(jsonFile),
fileName=str(tgeo_fileName),
surfaceLogLevel=logLevel,
layerLogLevel=logLevel,
volumeLogLevel=logLevel,
mdecorator=matDeco,
)

Volume = TGeoDetector.Config.Volume
LayerTriplet = TGeoDetector.Config.LayerTriplet
equidistant = TGeoDetector.Config.BinningType.equidistant
arbitrary = TGeoDetector.Config.BinningType.arbitrary

return TGeoDetector.create(
fileName=str(tgeo_fileName),
mdecorator=matDeco,
buildBeamPipe=True,
unitScalor=1.0, # explicit units
beamPipeRadius=23.934 * u.mm,
beamPipeHalflengthZ=3000.0 * u.mm,
beamPipeLayerThickness=0.8 * u.mm,
surfaceLogLevel=logLevel,
layerLogLevel=logLevel,
volumeLogLevel=logLevel,
volumes=[
Volume(
name="InnerPixels",
binToleranceR=(5 * u.mm, 5 * u.mm),
binToleranceZ=(5 * u.mm, 5 * u.mm),
binTolerancePhi=(0.025 * u.mm, 0.025 * u.mm),
layers=LayerTriplet(True),
subVolumeName=LayerTriplet("Pixel::Pixel"),
sensitiveNames=LayerTriplet(["Pixel::siLog"]),
sensitiveAxes=LayerTriplet("YZX"),
rRange=LayerTriplet((0 * u.mm, 135 * u.mm)),
zRange=LayerTriplet(
negative=(-3000 * u.mm, -250 * u.mm),
central=(-250 * u.mm, 250 * u.mm),
positive=(250 * u.mm, 3000 * u.mm),
),
splitTolR=LayerTriplet(negative=-1.0, central=5 * u.mm, positive=-1.0),
splitTolZ=LayerTriplet(
negative=10 * u.mm, central=-1.0, positive=10 * u.mm
),
binning0=LayerTriplet(
negative=[(0, equidistant)],
central=[(6, equidistant), (10, equidistant)],
positive=[(0, equidistant)],
),
binning1=LayerTriplet(
negative=[(0, equidistant)],
central=[(12, equidistant), (6, equidistant)],
positive=[(0, equidistant)],
),
cylinderDiscSplit=False,
cylinderNZSegments=0,
cylinderNPhiSegments=0,
discNRSegments=0,
discNPhiSegments=0,
itkModuleSplit=False,
barrelMap={},
discMap={},
),
Volume(
name="OuterPixels",
binToleranceR=(5 * u.mm, 5 * u.mm),
binToleranceZ=(5 * u.mm, 5 * u.mm),
binTolerancePhi=(0.025 * u.mm, 0.025 * u.mm),
layers=LayerTriplet(True),
subVolumeName=LayerTriplet("Pixel::Pixel"),
sensitiveNames=LayerTriplet(["Pixel::siLog"]),
sensitiveAxes=LayerTriplet("YZX"),
rRange=LayerTriplet((135 * u.mm, 350 * u.mm)),
zRange=LayerTriplet(
negative=(-3000 * u.mm, -377 * u.mm),
central=(-377 * u.mm, 377 * u.mm),
positive=(377 * u.mm, 3000 * u.mm),
),
splitTolR=LayerTriplet(
negative=15 * u.mm, central=5 * u.mm, positive=15 * u.mm
),
splitTolZ=LayerTriplet(
negative=20 * u.mm, central=-1.0, positive=20 * u.mm
),
binning0=LayerTriplet(
negative=[(0, equidistant)],
central=[(0, equidistant)],
positive=[(0, equidistant)],
),
binning1=LayerTriplet(
negative=[(0, equidistant)],
central=[(0, equidistant)],
positive=[(0, equidistant)],
),
cylinderDiscSplit=False,
cylinderNZSegments=0,
cylinderNPhiSegments=0,
discNRSegments=0,
discNPhiSegments=0,
itkModuleSplit=False,
barrelMap={},
discMap={},
),
Volume(
name="Strips",
binToleranceR=(5 * u.mm, 5 * u.mm),
binToleranceZ=(5 * u.mm, 5 * u.mm),
binTolerancePhi=(0.025 * u.mm, 0.025 * u.mm),
layers=LayerTriplet(True),
subVolumeName=LayerTriplet(
negative="*",
central="SCT::SCT_Barrel",
positive="*",
),
sensitiveNames=LayerTriplet(
negative=["SCT::ECSensor*"],
central=["SCT::BRLSensor*"],
positive=["SCT::ECSensor*"],
),
sensitiveAxes=LayerTriplet("XYZ"),
rRange=LayerTriplet(
negative=(-1.0, 1050 * u.mm),
central=(380 * u.mm, 1050 * u.mm),
positive=(-1.0, 1050 * u.mm),
),
zRange=LayerTriplet(
negative=(-3000 * u.mm, -1400 * u.mm),
central=(-1400 * u.mm, 1400 * u.mm),
positive=(1400 * u.mm, 3000 * u.mm),
),
splitTolR=LayerTriplet(
negative=-1.0,
central=35 * u.mm,
positive=-1.0,
),
splitTolZ=LayerTriplet(
negative=35 * u.mm, central=-1.0, positive=35 * u.mm
),
binning0=LayerTriplet(
negative=[(-1, arbitrary)],
central=[(0, equidistant)],
positive=[(-1, arbitrary)],
),
binning1=LayerTriplet(
negative=[(-1, arbitrary)],
central=[(28, equidistant)] * 4,
positive=[(-1, arbitrary)],
),
cylinderDiscSplit=False,
cylinderNZSegments=0,
cylinderNPhiSegments=0,
discNRSegments=0,
discNPhiSegments=0,
itkModuleSplit=True,
barrelMap={"MS": 2, "SS": 4},
discMap={
"EC0": [
[384.5, 403.481],
[403.481, 427.462],
[427.462, 456.442],
[456.442, 488.423],
],
"EC1": [
[489.823, 507.916],
[507.916, 535.009],
[535.009, 559.101],
[559.101, 574.194],
],
"EC2": [[575.594, 606.402], [606.402, 637.209]],
"EC3": [
[638.609, 670.832],
[670.832, 697.055],
[697.055, 723.278],
[723.278, 755.501],
],
"EC4": [[756.901, 811.482], [811.482, 866.062]],
"EC5": [[867.462, 907.623], [907.623, 967.785]],
},
),
Volume(
name="HGTD",
binToleranceR=(15 * u.mm, 15 * u.mm),
binToleranceZ=(5 * u.mm, 5 * u.mm),
binTolerancePhi=(0.25 * u.mm, 0.25 * u.mm),
layers=LayerTriplet(positive=True, central=False, negative=True),
subVolumeName=LayerTriplet("HGTD::HGTD"),
sensitiveNames=LayerTriplet(["HGTD::HGTDSiSensor*"]),
sensitiveAxes=LayerTriplet("XYZ"),
rRange=LayerTriplet(
negative=(0 * u.mm, 1050 * u.mm),
positive=(0 * u.mm, 1050 * u.mm),
),
zRange=LayerTriplet(
negative=(-4000 * u.mm, -3000 * u.mm),
positive=(3000 * u.mm, 4000 * u.mm),
),
splitTolR=LayerTriplet(-1.0),
splitTolZ=LayerTriplet(negative=10 * u.mm, positive=10 * u.mm),
binning0=LayerTriplet(
negative=[(0, equidistant)],
central=[(0, equidistant)],
positive=[(0, equidistant)],
),
binning1=LayerTriplet(
negative=[(0, equidistant)],
central=[(0, equidistant)],
positive=[(0, equidistant)],
),
cylinderDiscSplit=False,
cylinderNZSegments=0,
cylinderNPhiSegments=0,
discNRSegments=0,
discNPhiSegments=0,
itkModuleSplit=False,
barrelMap={},
discMap={},
),
],
)
53 changes: 53 additions & 0 deletions Examples/Python/python/acts/examples/odd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from pathlib import Path
import sys, os


def getOpenDataDetector(odd_dir, mdecorator=None):

odd_xml = odd_dir / "xml" / "OpenDataDetector.xml"
if not odd_xml.exists():
raise RuntimeError(f"OpenDataDetector.xml not found at {odd_xml}")

env_vars = []
map_name = "libOpenDataDetector.components"
lib_name = None
if sys.platform == "linux":
env_vars = ["LD_LIBRARY_PATH"]
lib_name = "libOpenDataDetector.so"
elif sys.platform == "darwin":
env_vars = ["DYLD_LIBRARY_PATH", "DD4HEP_LIBRARY_PATH"]
lib_name = "libOpenDataDetector.dylib"

if lib_name is not None and len(env_vars) > 0:
found = False
for env_var in env_vars:
for lib_dir in os.environ.get(env_var, "").split(":"):
lib_dir = Path(lib_dir)
if (lib_dir / map_name).exists() and (lib_dir / lib_name).exists():
found = True
break
if not found:
msg = (
"Unable to find OpenDataDetector factory library. "
f"You might need to point {'/'.join(env_vars)} to build/thirdparty/OpenDataDetector/factory or other ODD install location"
)
raise RuntimeError(msg)

import acts.examples.dd4hep

dd4hepConfig = acts.examples.dd4hep.DD4hepGeometryService.Config(
xmlFileNames=[str(odd_xml)]
)
detector = acts.examples.dd4hep.DD4hepDetector()

config = acts.MaterialMapJsonConverter.Config()
if mdecorator is None:
mdecorator = acts.JsonMaterialDecorator(
rConfig=config,
jFileName=str(odd_dir / "config/odd-material-mapping-config.json"),
level=acts.logging.WARNING,
)

trackingGeometry, deco = detector.finalize(dd4hepConfig, mdecorator)

return detector, trackingGeometry, deco
Loading

0 comments on commit b4dc20d

Please sign in to comment.