File indexing completed on 2025-01-30 09:14:56
0001 import pytest
0002 import random
0003
0004 import acts
0005 import acts.examples
0006
0007 u = acts.UnitConstants
0008
0009
0010 def test_null_bfield():
0011 nb = acts.NullBField()
0012 assert nb
0013
0014 ct = acts.MagneticFieldContext()
0015 assert ct
0016
0017 fc = nb.makeCache(ct)
0018 assert fc
0019
0020 for i in range(100):
0021 x = random.uniform(-10000.0, 10000.0)
0022 y = random.uniform(-10000.0, 10000.0)
0023 z = random.uniform(-10000.0, 10000.0)
0024
0025 rv = nb.getField(acts.Vector3(x, y, z), fc)
0026
0027 assert rv[0] == pytest.approx(0.0)
0028 assert rv[1] == pytest.approx(0.0)
0029 assert rv[2] == pytest.approx(0.0)
0030
0031
0032 def test_constant_bfield():
0033 with pytest.raises(TypeError):
0034 acts.ConstantBField()
0035
0036 v = acts.Vector3(1, 2, 3)
0037 cb = acts.ConstantBField(v)
0038 assert cb
0039
0040 ct = acts.MagneticFieldContext()
0041 assert ct
0042
0043 fc = cb.makeCache(ct)
0044 assert fc
0045
0046 for i in range(100):
0047 x = random.uniform(-10000.0, 10000.0)
0048 y = random.uniform(-10000.0, 10000.0)
0049 z = random.uniform(-10000.0, 10000.0)
0050
0051 rv = cb.getField(acts.Vector3(x, y, z), fc)
0052
0053 assert rv[0] == pytest.approx(1.0)
0054 assert rv[1] == pytest.approx(2.0)
0055 assert rv[2] == pytest.approx(3.0)
0056
0057
0058 def test_solenoid(conf_const):
0059 solenoid = conf_const(
0060 acts.SolenoidBField,
0061 radius=1200 * u.mm,
0062 length=6000 * u.mm,
0063 bMagCenter=2 * u.T,
0064 nCoils=1194,
0065 )
0066
0067 field = acts.solenoidFieldMap(
0068 rlim=(0, 1200 * u.mm),
0069 zlim=(-5000 * u.mm, 5000 * u.mm),
0070 nbins=(10, 10),
0071 field=solenoid,
0072 )
0073
0074 assert isinstance(field, acts.examples.InterpolatedMagneticField2)
0075
0076
0077 def test_multiregion_bfield():
0078 with pytest.raises(TypeError):
0079 acts.MultiRangeBField()
0080
0081 rs = [
0082 (acts.RangeXDDim3((0, 3), (0, 3), (0, 3)), acts.Vector3(0.0, 0.0, 2.0)),
0083 (acts.RangeXDDim3((1, 2), (1, 2), (1, 10)), acts.Vector3(2.0, 0.0, 0.0)),
0084 ]
0085 f = acts.MultiRangeBField(rs)
0086 assert f
0087
0088 ctx = acts.MagneticFieldContext()
0089 assert ctx
0090
0091 fc = f.makeCache(ctx)
0092 assert fc
0093
0094 rv = f.getField(acts.Vector3(0.5, 0.5, 0.5), fc)
0095 assert rv[0] == pytest.approx(0.0)
0096 assert rv[1] == pytest.approx(0.0)
0097 assert rv[2] == pytest.approx(2.0)
0098
0099 rv = f.getField(acts.Vector3(1.5, 1.5, 5.0), fc)
0100 assert rv[0] == pytest.approx(2.0)
0101 assert rv[1] == pytest.approx(0.0)
0102 assert rv[2] == pytest.approx(0.0)
0103
0104 rv = f.getField(acts.Vector3(2.5, 2.5, 2.5), fc)
0105 assert rv[0] == pytest.approx(0.0)
0106 assert rv[1] == pytest.approx(0.0)
0107 assert rv[2] == pytest.approx(2.0)
0108
0109 rv = f.getField(acts.Vector3(1.5, 1.5, 1.5), fc)
0110 assert rv[0] == pytest.approx(2.0)
0111 assert rv[1] == pytest.approx(0.0)
0112 assert rv[2] == pytest.approx(0.0)