Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-12 07:52:37

0001 import pathlib, acts, acts.examples
0002 import pytest
0003 
0004 from helpers import covfieEnabled
0005 
0006 
0007 @pytest.mark.skipif(not covfieEnabled, reason="Covfie plugin not available")
0008 def test_constant_field_conversion():
0009     from acts import covfie
0010 
0011     v = acts.Vector3(1, 2, 3)
0012     af = acts.ConstantBField(v)
0013     cf = covfie.makeCovfieField(af)
0014     view = covfie.toView(cf)
0015     points = [(0, 0, 1), (1, 1, 1), (1, 0, 2)]
0016     for [x, y, z] in points:
0017         field = view.at(x, y, z)
0018         assert field.at(0) == 1
0019         assert field.at(1) == 2
0020         assert field.at(2) == 3
0021 
0022 
0023 @pytest.mark.skipif(not covfieEnabled, reason="Covfie plugin not available")
0024 def test_root_field_conversion():
0025     from acts import covfie
0026 
0027     current_file_path = pathlib.Path(__file__).resolve().parent
0028     p = (
0029         current_file_path.parent.parent.parent
0030         / "thirdparty"
0031         / "OpenDataDetector"
0032         / "data"
0033         / "odd-bfield.root"
0034     )
0035 
0036     af = acts.examples.MagneticFieldMapXyz(str(p))
0037     bc = acts.MagneticFieldContext()
0038     fc = af.makeCache(bc)
0039 
0040     cf = covfie.makeCovfieField(af)
0041     view = covfie.toView(cf)
0042     points = [
0043         (9300.0, 4700.0, 11200.0),
0044         (9999.0, 9999.0, 14300.0),
0045         (-2900.0, -4700.0, 5200.0),
0046         (-2900.0, -4800.0, 9100.0),
0047         (-2900.0, -5200.0, -8800.0),
0048         (-4400.0, 4800.0, -12700.0),
0049         (-6600.0, 1900.0, 7700.0),
0050         (-9700.0, -900.0, 12700.0),
0051         (-9999.0, -9999.0, -13000.0),
0052         (9999.0, 0, 14900.0),
0053     ]
0054 
0055     error_margin_half_width = 0.0001
0056     for x, y, z in points:
0057         rfield = af.getField(acts.Vector3(x, y, z), fc)
0058         Bx1, By1, Bz1 = rfield[0], rfield[1], rfield[2]
0059 
0060         tfield = view.at(x, y, z)
0061         Bx2, By2, Bz2 = tfield.at(0), tfield.at(1), tfield.at(2)
0062 
0063         assert (
0064             abs(Bx1 - Bx2) < error_margin_half_width
0065             and abs(By1 - By2) < error_margin_half_width
0066             and abs(Bz1 - Bz2) < error_margin_half_width
0067         )