Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:10:07

0001 import pytest
0002 
0003 from helpers import dd4hepEnabled
0004 
0005 import acts.examples
0006 from acts.examples.odd import getOpenDataDetector
0007 
0008 
0009 def count_surfaces(geo):
0010     __tracebackhide__ = True
0011     nSurfaces = 0
0012 
0013     def visit(srf):
0014         nonlocal nSurfaces
0015         nSurfaces += 1
0016 
0017     geo.visitSurfaces(visit)
0018 
0019     return nSurfaces
0020 
0021 
0022 def check_extra_odd(srf):
0023     if srf.geometryId().volume() in [28, 30, 23, 25, 16, 18]:
0024         assert srf.geometryId().extra() != 0
0025     return
0026 
0027 
0028 def test_generic_geometry():
0029     detector, geo, contextDecorators = acts.examples.GenericDetector.create()
0030     assert detector is not None
0031     assert geo is not None
0032     assert contextDecorators is not None
0033 
0034     assert count_surfaces(geo) == 18728
0035 
0036 
0037 def test_telescope_geometry():
0038     n_surfaces = 10
0039 
0040     detector, geo, contextDecorators = acts.examples.TelescopeDetector.create(
0041         bounds=[100, 100],
0042         positions=[10 * i for i in range(n_surfaces)],
0043         stereos=[0] * n_surfaces,
0044         binValue=0,
0045     )
0046 
0047     assert detector is not None
0048     assert geo is not None
0049     assert contextDecorators is not None
0050 
0051     assert count_surfaces(geo) == n_surfaces
0052 
0053 
0054 @pytest.mark.skipif(not dd4hepEnabled, reason="DD4hep is not set up")
0055 def test_odd():
0056     detector, trackingGeometry, decorators = getOpenDataDetector()
0057 
0058     trackingGeometry.visitSurfaces(check_extra_odd)
0059 
0060     assert count_surfaces(trackingGeometry) == 18824
0061 
0062 
0063 def test_aligned_detector():
0064     detector, trackingGeometry, decorators = acts.examples.AlignedDetector.create()
0065 
0066     assert detector is not None
0067     assert trackingGeometry is not None
0068     assert decorators is not None
0069 
0070     assert count_surfaces(trackingGeometry) == 18728
0071 
0072 
0073 import itertools
0074 
0075 
0076 def test_tgeo_config_triplet(monkeypatch):
0077     from acts.examples import TGeoDetector, Interval
0078 
0079     # monkeypatch the comparison operator
0080     def eq(self, other):
0081         return self.lower == other.lower and self.upper == other.upper
0082 
0083     monkeypatch.setattr(Interval, "__eq__", eq)
0084 
0085     LayerTriplet = TGeoDetector.Config.LayerTriplet
0086     c = TGeoDetector.Config
0087 
0088     def assert_combinations(value, _type):
0089         t = LayerTriplet(value)
0090         assert t.negative == value and t.central == value and t.positive == value
0091         assert isinstance(t, _type)
0092 
0093         keys = ["negative", "central", "positive"]
0094 
0095         combinations = (
0096             [(k,) for k in keys] + list(itertools.combinations(keys, 2)) + [keys]
0097         )
0098 
0099         for c in combinations:
0100             d = {k: value for k in c}
0101 
0102             t = LayerTriplet(**d)
0103             assert isinstance(t, _type)
0104             for k in c:
0105                 assert getattr(t, k) == value
0106 
0107     v = ["Some::SensorName"]
0108     assert_combinations(v, c.LayerTripletVectorString)
0109 
0110     with pytest.raises(TypeError):
0111         LayerTriplet(["Some::SensorName", 848])
0112 
0113     with pytest.raises(TypeError):
0114         LayerTriplet(("Some::SensorName", 848))
0115 
0116     for v in (True, False):
0117         assert_combinations(v, c.LayerTripletBool)
0118 
0119     assert_combinations("hallo", c.LayerTripletString)
0120 
0121     assert_combinations(5.3, c.LayerTripletDouble)
0122 
0123     assert_combinations(Interval(5.0, 9.0), c.LayerTripletInterval)
0124 
0125     with pytest.raises(TypeError):
0126         LayerTriplet(("a", 9))
0127 
0128     v = (4.4, 2.2)
0129     t = LayerTriplet(v)
0130     assert t.negative == Interval(*v)
0131     assert t.central == Interval(*v)
0132     assert t.positive == Interval(*v)
0133 
0134 
0135 def test_tgeo_config_volume(monkeypatch):
0136     from acts.examples import TGeoDetector, Interval
0137 
0138     # monkeypatch the comparison operator
0139     def eq(self, other):
0140         return self.lower == other.lower and self.upper == other.upper
0141 
0142     monkeypatch.setattr(Interval, "__eq__", eq)
0143 
0144     Volume = TGeoDetector.Config.Volume
0145 
0146     v = Volume(name="blubb")
0147     assert v
0148 
0149     for key in ("binToleranceR", "binToleranceZ", "binTolerancePhi"):
0150         v = Volume(**{key: Interval(4, 5)})
0151         assert getattr(v, key) == Interval(4, 5)
0152 
0153         v = Volume(**{key: (4, 5)})
0154         assert getattr(v, key) == Interval(4, 5)
0155 
0156         v = Volume(**{key: (None, 5)})
0157         assert getattr(v, key) == Interval(None, 5)
0158 
0159         v = Volume(**{key: (4, None)})
0160         assert getattr(v, key) == Interval(4, None)