Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-16 07:48:13

0001 import pytest
0002 
0003 import acts
0004 
0005 from helpers import dd4hepEnabled
0006 
0007 # Standalone script under Examples/Scripts/Python (added to sys.path by conftest)
0008 import material_merge_rz_view as mrz
0009 
0010 mm = acts.UnitConstants.mm
0011 
0012 
0013 def _build_marker_geometry(gctx):
0014     """Build a tiny Gen3 geometry that triggers a lossy material merge.
0015 
0016     A z-stack with material designated on the (merged) OuterCylinder face of one
0017     child. Constructed in keep-going mode so the merge tags the surface with a
0018     MergedMaterialMarker instead of aborting.
0019     """
0020     bv = acts.AxisDirection
0021     abt = acts.AxisBoundaryType
0022     base = acts.Transform3.Identity()
0023 
0024     root = acts.Blueprint(
0025         envelope=acts.ExtentEnvelope(z=[20 * mm, 20 * mm], r=[0 * mm, 20 * mm])
0026     )
0027     stack = root.addCylinderContainer("Stack", direction=bv.AxisZ)
0028 
0029     mat = stack.addMaterial("Material")
0030     mat.configureFace(
0031         acts.CylinderVolumeBounds.Face.OuterCylinder,
0032         acts.DirectedProtoAxis(bv.AxisRPhi, abt.Bound, 20),
0033         acts.DirectedProtoAxis(bv.AxisZ, abt.Bound, 20),
0034     )
0035     mat.addStaticVolume(
0036         base * acts.Translation3(acts.Vector3(0, 0, -200 * mm)),
0037         acts.CylinderVolumeBounds(0, 100 * mm, 100 * mm),
0038         name="VolumeA",
0039     )
0040 
0041     stack.addStaticVolume(
0042         base * acts.Translation3(acts.Vector3(0, 0, 200 * mm)),
0043         acts.CylinderVolumeBounds(0, 100 * mm, 100 * mm),
0044         name="VolumeB",
0045     )
0046 
0047     options = acts.BlueprintOptions()
0048     options.keepGoingOnMaterialMergeFailure = True
0049     return root.construct(options, gctx, level=acts.logging.WARNING)
0050 
0051 
0052 @acts.with_log_threshold(acts.logging.FATAL)
0053 def test_rz_view_with_markers(tmp_path):
0054     pytest.importorskip("matplotlib")
0055     from acts.json import TrackingGeometryJsonConverter
0056 
0057     gctx = acts.GeometryContext.dangerouslyDefaultConstruct()
0058     trackingGeometry = _build_marker_geometry(gctx)
0059 
0060     json_path = tmp_path / "marker-geometry.json"
0061     json_path.write_text(TrackingGeometryJsonConverter().toJson(gctx, trackingGeometry))
0062 
0063     out = tmp_path / "marker_rz.svg"
0064     volumes, markers = mrz.run(json_path, out)
0065 
0066     assert out.exists()
0067     assert out.stat().st_size > 0
0068     assert len(volumes) >= 2
0069     # The merged OuterCylinder portal must show up as a marker line
0070     assert len(markers) >= 1
0071 
0072 
0073 @pytest.mark.skipif(not dd4hepEnabled, reason="DD4hep not set up")
0074 @pytest.mark.odd
0075 @pytest.mark.slow
0076 # Construction may legitimately emit keep-going WARNINGs (e.g. when ODD has a
0077 # material-on-merged-face clash), which would otherwise trip the test harness'
0078 # ACTS_LOG_FAILURE_THRESHOLD.
0079 @acts.with_log_threshold(acts.logging.FATAL)
0080 def test_rz_view_odd_gen3(tmp_path):
0081     pytest.importorskip("matplotlib")
0082     from acts.examples.odd import getOpenDataDetector
0083     from acts.json import TrackingGeometryJsonConverter
0084 
0085     gctx = acts.GeometryContext.dangerouslyDefaultConstruct()
0086 
0087     with getOpenDataDetector(gen3=True) as detector:
0088         trackingGeometry = detector.trackingGeometry()
0089         json_path = tmp_path / "odd-geometry.json"
0090         json_path.write_text(
0091             TrackingGeometryJsonConverter().toJson(gctx, trackingGeometry)
0092         )
0093 
0094     out = tmp_path / "odd_rz.svg"
0095     volumes, markers = mrz.run(json_path, out)
0096 
0097     assert out.exists()
0098     assert out.stat().st_size > 0
0099     assert len(volumes) > 0
0100     # Marker count depends on ODD's material configuration, so we don't pin it;
0101     # the script must just run end-to-end and produce an SVG.
0102     assert len(markers) >= 0