def test_full_chain_odd_example(tmp_path): # This test literally only ensures that the full chain example can run without erroring out getOpenDataDetector() # just to make sure it can build script = (Path(__file__).parent.parent.parent.parent / "Examples" / "Scripts" / "Python" / "full_chain_odd.py") assert script.exists() subprocess.check_call([str(script)], cwd=tmp_path)
def test_odd(): config = acts.MaterialMapJsonConverter.Config() matDeco = acts.JsonMaterialDecorator( rConfig=config, jFileName="thirdparty/OpenDataDetector/config/odd-material-mapping-config.json", level=acts.logging.WARNING, ) detector, geo, _ = getOpenDataDetector(matDeco) assert count_surfaces(geo) == 18824
def test_truth_tracking(tmp_path, assert_root_hash, revFiltMomThresh): from truth_tracking import runTruthTracking detector, trackingGeometry, _ = getOpenDataDetector() field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T)) seq = Sequencer(events=10, numThreads=1) root_files = [ ("trackstates_fitter.root", "trackstates", 19), ("tracksummary_fitter.root", "tracksummary", 10), ("performance_track_finder.root", "track_finder_tracks", 19), ("performance_track_fitter.root", None, -1), ] for fn, _, _ in root_files: fp = tmp_path / fn assert not fp.exists() runTruthTracking( trackingGeometry, field, digiConfigFile=Path( "thirdparty/OpenDataDetector/config/odd-digi-smearing-config.json", ), outputDir=tmp_path, reverseFilteringMomThreshold=revFiltMomThresh, s=seq, ) seq.run() del seq for fn, tn, ee in root_files: fp = tmp_path / fn assert fp.exists() assert fp.stat().st_size > 1024 if tn is not None: assert_entries(fp, tn, ee) assert_root_hash(fn, fp)
def test_vertex_fitting(tmp_path): detector, trackingGeometry, decorators = getOpenDataDetector() field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T)) from vertex_fitting import runVertexFitting, VertexFinder s = Sequencer(events=100) runVertexFitting( field, vertexFinder=VertexFinder.Truth, outputDir=tmp_path, s=s, ) alg = AssertCollectionExistsAlg(["fittedVertices"], name="check_alg") s.addAlgorithm(alg) s.run() assert alg.events_seen == s.config.events
def test_ckf_tracks_example( tmp_path, assert_root_hash, truthSmeared, truthEstimated, detector ): 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 s = Sequencer(events=events, numThreads=1) # Digitization is not thread-safe root_files = [ ( "performance_ckf.root", None, ), ( "trackstates_ckf.root", "trackstates", ), ( "tracksummary_ckf.root", "tracksummary", ), ] if not truthSmeared: root_files += [ ( "performance_seeding_trees.root", "track_finder_tracks", ), ] for rf, _ in root_files: assert not (tmp_path / rf).exists() from ckf_tracks import runCKFTracks runCKFTracks( trackingGeometry, decorators, field=field, outputCsv=True, outputDir=tmp_path, geometrySelection=geometrySelection, digiConfigFile=digiConfigFile, truthSmearedSeeded=truthSmeared, truthEstimatedSeeded=truthEstimated, s=s, ) s.run() del s # files are closed in destructors, not great assert csv.exists() for rf, tn in root_files: rp = tmp_path / rf assert rp.exists() if tn is not None: assert_root_hash(rf, rp) 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_volume_material_mapping(material_recording, tmp_path, assert_root_hash): map_file = tmp_path / "material-map-volume_tracks.root" assert not map_file.exists() s = Sequencer(numThreads=1) geo_map = Path(__file__).parent / "geometry-volume-map.json" assert geo_map.exists() assert geo_map.stat().st_size > 10 with geo_map.open() as fh: assert json.load(fh) detector, trackingGeometry, decorators = getOpenDataDetector( mdecorator=acts.IMaterialDecorator.fromFile(geo_map) ) from material_mapping import runMaterialMapping runMaterialMapping( trackingGeometry, decorators, mapName="material-map-volume", outputDir=str(tmp_path), inputDir=material_recording, s=s, ) s.run() # MaterialMapping alg only writes on destruct. # See https://github.com/acts-project/acts/issues/881 del s mat_file = tmp_path / "material-map-volume.json" assert mat_file.exists() assert mat_file.stat().st_size > 10 with mat_file.open() as fh: assert json.load(fh) assert map_file.exists() assert_entries(map_file, "material-tracks", 200) assert_root_hash(map_file.name, map_file) val_file = tmp_path / "propagation-volume-material.root" assert not val_file.exists() # test the validation as well # we need to destroy the ODD to reload with material # del trackingGeometry # del detector detector, trackingGeometry, decorators = getOpenDataDetector( mdecorator=acts.IMaterialDecorator.fromFile(mat_file) ) from material_validation import runMaterialValidation s = Sequencer(events=10, numThreads=1) field = acts.NullBField() runMaterialValidation( trackingGeometry, decorators, field, outputDir=str(tmp_path), outputName="propagation-volume-material", s=s, ) s.run() assert val_file.exists() assert_root_hash(val_file.name, val_file)
writeFormat=JsonFormat.Json, ) s.addWriter( RootMaterialTrackWriter( level=acts.logging.INFO, collection=mmAlgCfg.mappingMaterialCollection, filePath=os.path.join( outputDir, mapName + "_tracks.root", ), storeSurface=True, storeVolume=True, ) ) mmAlgCfg.materialWriters = [jmw] s.addAlgorithm(MaterialMapping(level=acts.logging.INFO, config=mmAlgCfg)) return s if "__main__" == __name__: matDeco = acts.IMaterialDecorator.fromFile("geometry-map.json") detector, trackingGeometry, decorators = getOpenDataDetector(matDeco) runMaterialMapping( trackingGeometry, decorators, outputDir=os.getcwd(), inputDir=os.getcwd() ).run()
import pathlib, acts, acts.examples import acts.examples.dd4hep from common import getOpenDataDetector, getOpenDataDetectorDirectory u = acts.UnitConstants outputDir = pathlib.Path.cwd() / "odd_output" outputDir.mkdir(exist_ok=True) oddDir = getOpenDataDetectorDirectory() oddMaterialMap = oddDir / "data/odd-material-maps.root" oddDigiConfig = oddDir / "config/odd-digi-smearing-config.json" oddSeedingSel = oddDir / "config/odd-seeding-config.json" oddMaterialDeco = acts.IMaterialDecorator.fromFile(oddMaterialMap) detector, trackingGeometry, decorators = getOpenDataDetector( mdecorator=oddMaterialDeco) field = acts.ConstantBField(acts.Vector3(0.0, 0.0, 2.0 * u.T)) rnd = acts.examples.RandomNumbers(seed=42) from particle_gun import addParticleGun, MomentumConfig, EtaConfig, ParticleConfig from fatras import addFatras from digitization import addDigitization from seeding import addSeeding, SeedingAlgorithm, TruthSeedRanges from ckf_tracks import addCKFTracks s = acts.examples.Sequencer(events=100, numThreads=-1, logLevel=acts.logging.INFO) s = addParticleGun( s,