3 from pathlib
import Path
17 AssertCollectionExistsAlg,
22 from common
import getOpenDataDetectorDirectory
24 from acts
import PlanarModuleStepper, UnitConstants
as u
28 ObjPropagationStepsWriter,
29 TrackFinderPerformanceWriter,
30 SeedingPerformanceWriter,
31 RootPropagationStepsWriter,
33 RootTrackParameterWriter,
34 RootMaterialTrackWriter,
36 RootPlanarClusterWriter,
38 RootTrajectoryStatesWriter,
39 RootTrajectorySummaryWriter,
40 VertexPerformanceWriter,
41 RootMeasurementWriter,
43 CsvPlanarClusterWriter,
45 CsvMultiTrajectoryWriter,
46 CsvTrackingGeometryWriter,
48 PlanarSteppingAlgorithm,
58 with pytest.raises(TypeError):
59 ObjPropagationStepsWriter()
61 obj = tmp_path /
"obj"
66 ObjPropagationStepsWriter,
68 collection=alg.config.propagationStepCollection,
76 assert len([f
for f
in obj.iterdir()
if f.is_file()]) == s.config.events
77 for f
in obj.iterdir():
78 assert f.stat().st_size > 1024
83 s = Sequencer(numThreads=1, events=10)
86 out = tmp_path /
"csv"
94 inputParticles=evGen.config.outputParticles,
95 outputStem=
"particle",
102 assert len([f
for f
in out.iterdir()
if f.is_file()]) == s.config.events
103 assert all(f.stat().st_size > 200
for f
in out.iterdir())
108 tmp_path, trk_geo, conf_const, basic_prop_seq, assert_root_hash
110 with pytest.raises(TypeError):
111 RootPropagationStepsWriter()
113 file = tmp_path /
"prop_steps.root"
114 assert not file.exists()
118 RootPropagationStepsWriter,
120 collection=alg.config.propagationStepCollection,
129 assert file.stat().st_size > 2**10 * 50
135 s = Sequencer(numThreads=1, events=10)
138 file = tmp_path /
"particles.root"
140 assert not file.exists()
146 inputParticles=evGen.config.outputParticles,
154 assert file.stat().st_size > 1024 * 10
160 s = Sequencer(numThreads=1, events=10)
161 evGen, simAlg, digiAlg =
fatras(s)
163 out = tmp_path /
"meas.root"
165 assert not out.exists()
167 config = RootMeasurementWriter.Config(
168 inputMeasurements=digiAlg.config.outputMeasurements,
169 inputClusters=digiAlg.config.outputClusters,
170 inputSimHits=simAlg.config.outputSimHits,
171 inputMeasurementSimHitsMap=digiAlg.config.outputMeasurementSimHitsMap,
173 trackingGeometry=trk_geo,
175 config.addBoundIndicesFromDigiConfig(digiAlg.config)
176 s.addWriter(RootMeasurementWriter(level=acts.logging.INFO, config=config))
180 assert out.stat().st_size > 40000
186 s = Sequencer(numThreads=1, events=10)
187 evGen, simAlg, digiAlg =
fatras(s)
189 out = tmp_path /
"meas.root"
191 assert not out.exists()
196 level=acts.logging.INFO,
197 inputSimHits=simAlg.config.outputSimHits,
204 assert out.stat().st_size > 2e4
210 tmp_path, fatras, conf_const, trk_geo, rng, assert_root_hash
212 s = Sequencer(numThreads=1, events=10)
213 evGen, simAlg, _ =
fatras(s)
214 s = Sequencer(numThreads=1, events=10)
216 s.addAlgorithm(simAlg)
217 digiAlg = PlanarSteppingAlgorithm(
218 level=acts.logging.INFO,
219 inputSimHits=simAlg.config.outputSimHits,
220 outputClusters=
"clusters",
221 outputSourceLinks=
"sourcelinks",
222 outputDigiSourceLinks=
"digi_sourcelinks",
223 outputMeasurements=
"measurements",
224 outputMeasurementParticlesMap=
"meas_ptcl_map",
225 outputMeasurementSimHitsMap=
"meas_sh_map",
226 trackingGeometry=trk_geo,
228 planarModuleStepper=PlanarModuleStepper(),
230 s.addAlgorithm(digiAlg)
232 out = tmp_path /
"clusters.root"
234 assert not out.exists()
238 RootPlanarClusterWriter,
239 level=acts.logging.INFO,
241 inputSimHits=simAlg.config.outputSimHits,
242 inputClusters=digiAlg.config.outputClusters,
243 trackingGeometry=trk_geo,
249 assert out.stat().st_size > 2**10 * 50
255 s = Sequencer(numThreads=1, events=10)
256 evGen, simAlg, digiAlg =
fatras(s)
258 out = tmp_path /
"csv"
263 CsvMeasurementWriter,
264 level=acts.logging.INFO,
265 inputMeasurements=digiAlg.config.outputMeasurements,
266 inputClusters=digiAlg.config.outputClusters,
267 inputMeasurementSimHitsMap=digiAlg.config.outputMeasurementSimHitsMap,
273 assert len([f
for f
in out.iterdir()
if f.is_file()]) == s.config.events * 3
274 assert all(f.stat().st_size > 10
for f
in out.iterdir())
279 s = Sequencer(numThreads=1, events=10)
280 evGen, simAlg, digiAlg =
fatras(s)
282 out = tmp_path /
"csv"
288 level=acts.logging.INFO,
289 inputSimHits=simAlg.config.outputSimHits,
296 assert len([f
for f
in out.iterdir()
if f.is_file()]) == s.config.events
297 assert all(f.stat().st_size > 200
for f
in out.iterdir())
302 s = Sequencer(numThreads=1, events=10)
303 evGen, simAlg, _ =
fatras(s)
304 s = Sequencer(numThreads=1, events=10)
306 s.addAlgorithm(simAlg)
307 digiAlg = PlanarSteppingAlgorithm(
308 level=acts.logging.WARNING,
309 inputSimHits=simAlg.config.outputSimHits,
310 outputClusters=
"clusters",
311 outputSourceLinks=
"sourcelinks",
312 outputDigiSourceLinks=
"digi_sourcelinks",
313 outputMeasurements=
"measurements",
314 outputMeasurementParticlesMap=
"meas_ptcl_map",
315 outputMeasurementSimHitsMap=
"meas_sh_map",
316 trackingGeometry=trk_geo,
318 planarModuleStepper=PlanarModuleStepper(),
320 s.addAlgorithm(digiAlg)
322 out = tmp_path /
"csv"
327 CsvPlanarClusterWriter,
328 level=acts.logging.WARNING,
330 inputSimHits=simAlg.config.outputSimHits,
331 inputClusters=digiAlg.config.outputClusters,
332 trackingGeometry=trk_geo,
337 assert len([f
for f
in out.iterdir()
if f.is_file()]) == s.config.events * 3
338 assert all(f.stat().st_size > 1024
for f
in out.iterdir())
341 @pytest.mark.parametrize(
344 RootPropagationStepsWriter,
346 TrackFinderPerformanceWriter,
347 SeedingPerformanceWriter,
348 RootTrackParameterWriter,
349 RootMaterialTrackWriter,
350 RootMeasurementWriter,
352 RootPlanarClusterWriter,
354 RootTrajectoryStatesWriter,
355 RootTrajectorySummaryWriter,
356 VertexPerformanceWriter,
357 SeedingPerformanceWriter,
362 assert hasattr(writer,
"Config")
364 config = writer.Config
366 assert hasattr(config,
"filePath")
367 assert hasattr(config,
"fileMode")
369 f = tmp_path /
"target.root"
370 assert not f.exists()
372 kw = {
"level": acts.logging.INFO,
"filePath":
str(f)}
374 for k, _
in inspect.getmembers(config):
375 if k.startswith(
"input"):
377 if k ==
"trackingGeometry":
385 @pytest.mark.parametrize(
389 CsvMeasurementWriter,
390 CsvPlanarClusterWriter,
392 CsvMultiTrajectoryWriter,
393 CsvTrackingGeometryWriter,
398 assert hasattr(writer,
"Config")
400 config = writer.Config
402 assert hasattr(config,
"outputDir")
404 kw = {
"level": acts.logging.INFO,
"outputDir":
str(tmp_path)}
406 for k, _
in inspect.getmembers(config):
407 if k.startswith(
"input"):
409 if k ==
"trackingGeometry":
411 if k ==
"outputStem":
419 @pytest.mark.skipif(
not dd4hepEnabled, reason=
"DD4hep not set up")
423 detector, trackingGeometry, _ = DD4hepDetector.create(
427 out = tmp_path /
"material.root"
429 assert not out.exists()
431 rmw = RootMaterialWriter(level=acts.logging.WARNING, filePath=
str(out))
433 assert out.stat().st_size > 0
and out.stat().st_size < 500
434 rmw.write(trackingGeometry)
436 assert out.stat().st_size > 1000
442 @pytest.mark.parametrize(
"fmt", [JsonFormat.Json, JsonFormat.Cbor])
443 @pytest.mark.skipif(
not dd4hepEnabled, reason=
"DD4hep not set up")
447 detector, trackingGeometry, _ = DD4hepDetector.create(
451 out = (tmp_path /
"material").with_suffix(
"." + fmt.name.lower())
453 assert not out.exists()
455 jmw = JsonMaterialWriter(
456 level=acts.logging.WARNING, fileName=
str(out.with_suffix(
"")), writeFormat=fmt
458 assert not out.exists()
459 jmw.write(trackingGeometry)
461 assert out.stat().st_size > 1000
466 detector, trackingGeometry, decorators = GenericDetector.create()
467 field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
469 from truth_tracking_kalman
import runTruthTrackingKalman
471 s = Sequencer(numThreads=1, events=10)
477 Path(__file__).parent.parent.parent.parent
478 /
"Examples/Algorithms/Digitization/share/default-smearing-config-generic.json"
485 csv_dir = tmp_path /
"csv"
488 CsvMultiTrajectoryWriter(
489 level=acts.logging.INFO,
490 inputTrajectories=
"trajectories",
491 inputMeasurementParticlesMap=
"measurement_particles_map",
492 outputDir=
str(csv_dir),
497 assert len([f
for f
in csv_dir.iterdir()
if f.is_file()]) == 10
498 assert all(f.stat().st_size > 20
for f
in csv_dir.iterdir())
501 @pytest.fixture(scope=
"session")
506 Path(__file__).parent.parent.parent.parent
510 /
"event_recording.py"
512 assert script.exists()
514 with tempfile.TemporaryDirectory()
as tmp_path:
515 env = os.environ.copy()
517 subprocess.check_call([sys.executable,
str(script)], cwd=tmp_path, env=env)
519 outfile = Path(tmp_path) /
"hepmc3/event000000000-events.hepmc3"
525 assert outfile.exists()
532 dest = tmp_path / hepmc_data_impl.name
533 shutil.copy(hepmc_data_impl, dest)
538 @pytest.mark.skipif(
not hepmc3Enabled, reason=
"HepMC3 plugin not available")
539 @pytest.mark.skipif(
not dd4hepEnabled, reason=
"DD4hep not set up")
540 @pytest.mark.skipif(
not geant4Enabled, reason=
"Geant4 not set up")
546 HepMCProcessExtractor,
549 s = Sequencer(numThreads=1)
553 level=acts.logging.INFO,
554 inputDir=
str(hepmc_data.parent),
556 outputEvents=
"hepmc-events",
561 HepMCProcessExtractor(
562 level=acts.logging.INFO,
563 inputEvents=
"hepmc-events",
564 extractionProcess=
"Inelastic",
575 alg = AssertCollectionExistsAlg(
576 "hepmc-events", name=
"check_alg", level=acts.logging.INFO
584 @pytest.mark.skipif(
not edm4hepEnabled, reason=
"EDM4hep is not set up")
588 s = Sequencer(numThreads=1, events=10)
589 _, simAlg, digiAlg =
fatras(s)
591 out = tmp_path /
"measurements_edm4hep.root"
594 EDM4hepMeasurementWriter(
595 level=acts.logging.VERBOSE,
596 inputMeasurements=digiAlg.config.outputMeasurements,
597 inputClusters=digiAlg.config.outputClusters,
604 assert os.path.isfile(out)
605 assert os.stat(out).st_size > 10
609 @pytest.mark.skipif(
not edm4hepEnabled, reason=
"EDM4hep is not set up")
613 s = Sequencer(numThreads=1, events=10)
616 out = tmp_path /
"simhits_edm4hep.root"
621 level=acts.logging.INFO,
622 inputSimHits=simAlg.config.outputSimHits,
629 assert os.path.isfile(out)
630 assert os.stat(out).st_size > 200
634 @pytest.mark.skipif(
not edm4hepEnabled, reason=
"EDM4hep is not set up")
638 s = Sequencer(numThreads=1, events=10)
641 out = tmp_path /
"particles_edm4hep.root"
647 EDM4hepParticleWriter,
649 inputParticles=evGen.config.outputParticles,
656 assert os.path.isfile(out)
657 assert os.stat(out).st_size > 200
661 @pytest.mark.skipif(
not edm4hepEnabled, reason=
"EDM4hep is not set up")
665 detector, trackingGeometry, decorators = GenericDetector.create()
666 field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
668 from truth_tracking_kalman
import runTruthTrackingKalman
670 s = Sequencer(numThreads=1, events=10)
676 Path(__file__).parent.parent.parent.parent
677 /
"Examples/Algorithms/Digitization/share/default-smearing-config-generic.json"
684 out = tmp_path /
"trajectories_edm4hep.root"
687 EDM4hepMultiTrajectoryWriter(
688 level=acts.logging.VERBOSE,
689 inputTrajectories=
"trajectories",
690 inputMeasurementParticlesMap=
"measurement_particles_map",
697 assert os.path.isfile(out)
698 assert os.stat(out).st_size > 200
702 @pytest.mark.skipif(
not edm4hepEnabled, reason=
"EDM4hep is not set up")
706 detector, trackingGeometry, decorators = GenericDetector.create()
707 field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))
709 from truth_tracking_kalman
import runTruthTrackingKalman
711 s = Sequencer(numThreads=1, events=10)
717 Path(__file__).parent.parent.parent.parent
718 /
"Examples/Algorithms/Digitization/share/default-smearing-config-generic.json"
725 out = tmp_path /
"tracks_edm4hep.root"
729 level=acts.logging.VERBOSE,
730 inputTracks=
"kfTracks",
738 assert os.path.isfile(out)
739 assert os.stat(out).st_size > 200
745 "edm4hep output checks were skipped, because podio was not on the python path"
749 from podio.root_io
import Reader
752 reader = Reader(
str(out))
756 for frame
in reader.get(
"events"):
757 tracks = frame.get(
"ActsTracks")
760 (track.getChi2(), track.getNdf(), len(track.getTrackStates()))
766 for ts
in track.getTrackStates():
767 if ts.location == cppyy.gbl.edm4hep.TrackState.AtIP:
770 locs.append(ts.location)
772 rp = ts.referencePoint
773 r = math.sqrt(rp.x**2 + rp.y**2)
776 assert locs[0] == cppyy.gbl.edm4hep.TrackState.AtLastHit
777 assert locs[-1] == cppyy.gbl.edm4hep.TrackState.AtFirstHit
779 assert perigee
is not None
780 rp = perigee.referencePoint
784 assert abs(perigee.D0) < 1e0
785 assert abs(perigee.Z0) < 1e1