Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 07:47:24

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