File indexing completed on 2026-03-28 07:46:23
0001
0002
0003 import pytest
0004 import tempfile
0005 import pathlib
0006 import os
0007
0008
0009 try:
0010 pytest.importorskip("acts.ActsPythonBindingsDD4hep")
0011 HAS_DD4HEP = True
0012 except pytest.skip.Exception:
0013 HAS_DD4HEP = False
0014
0015 try:
0016 pytest.importorskip("acts.ActsPythonBindingsGeoModel")
0017 HAS_GEOMODEL = True
0018 except pytest.skip.Exception:
0019 HAS_GEOMODEL = False
0020
0021 import acts
0022 import acts.examples
0023
0024
0025 if HAS_DD4HEP:
0026 try:
0027 import acts.examples.dd4hep
0028 import acts.examples.geant4
0029 import acts.examples.geant4.dd4hep
0030 except ImportError:
0031 pass
0032
0033 if HAS_GEOMODEL:
0034 try:
0035 import acts.examples.geomodel
0036 except ImportError:
0037 pass
0038
0039 u = acts.UnitConstants
0040
0041
0042 def test_toroidal_field_basic():
0043 """Test basic ToroidField functionality."""
0044
0045
0046 config = acts.ToroidField.Config()
0047 field = acts.ToroidField(config)
0048 assert field is not None
0049
0050
0051 ctx = acts.MagneticFieldContext()
0052 cache = field.makeCache(ctx)
0053
0054
0055 position = acts.Vector3(6000.0, 0.0, 0.0)
0056 field_value = field.getField(position, cache)
0057
0058
0059 assert (
0060 abs(field_value[0]) > 0.0
0061 or abs(field_value[1]) > 0.0
0062 or abs(field_value[2]) > 0.0
0063 )
0064
0065
0066 def test_toroidal_field_custom():
0067 """Test ToroidField with custom parameters."""
0068
0069 config = acts.ToroidField.Config()
0070
0071
0072 config.barrel.R_in = 5.0
0073 config.barrel.R_out = 9.0
0074 config.barrel.I = 15000.0
0075
0076 field = acts.ToroidField(config)
0077 assert field is not None
0078
0079
0080 ctx = acts.MagneticFieldContext()
0081 cache = field.makeCache(ctx)
0082
0083 position = acts.Vector3(7000.0, 0.0, 0.0)
0084 field_value = field.getField(position, cache)
0085
0086
0087 assert hasattr(field_value, "__getitem__")
0088 assert field_value[0] is not None
0089 assert field_value[1] is not None
0090 assert field_value[2] is not None
0091
0092
0093 def test_toroidal_field_symmetry():
0094 """Test that the field has expected symmetries."""
0095
0096 config = acts.ToroidField.Config()
0097 field = acts.ToroidField(config)
0098 ctx = acts.MagneticFieldContext()
0099 cache = field.makeCache(ctx)
0100
0101
0102 radius = 7000.0
0103 z = 1000.0
0104
0105 pos1 = acts.Vector3(radius, 0.0, z)
0106 pos2 = acts.Vector3(0.0, radius, z)
0107
0108 field1 = field.getField(pos1, cache)
0109 field2 = field.getField(pos2, cache)
0110
0111
0112 mag1 = (field1[0] ** 2 + field1[1] ** 2 + field1[2] ** 2) ** 0.5
0113 mag2 = (field2[0] ** 2 + field2[1] ** 2 + field2[2] ** 2) ** 0.5
0114
0115 assert abs(mag1 - mag2) / max(mag1, mag2, 1e-10) < 0.1
0116
0117
0118 def test_toroidal_field_regions():
0119 """Test field behavior in different regions (barrel vs endcap)."""
0120
0121 config = acts.ToroidField.Config()
0122 field = acts.ToroidField(config)
0123 ctx = acts.MagneticFieldContext()
0124 cache = field.makeCache(ctx)
0125
0126
0127 pos_barrel = acts.Vector3(7000.0, 0.0, 1000.0)
0128 field_barrel = field.getField(pos_barrel, cache)
0129 mag_barrel = (
0130 field_barrel[0] ** 2 + field_barrel[1] ** 2 + field_barrel[2] ** 2
0131 ) ** 0.5
0132
0133
0134 pos_endcap = acts.Vector3(2000.0, 0.0, 15000.0)
0135 field_endcap = field.getField(pos_endcap, cache)
0136 mag_endcap = (
0137 field_endcap[0] ** 2 + field_endcap[1] ** 2 + field_endcap[2] ** 2
0138 ) ** 0.5
0139
0140
0141 assert mag_barrel > 0.0
0142 assert mag_endcap > 0.0
0143
0144
0145 def test_toroidal_field_configuration():
0146 """Test configuration classes."""
0147
0148
0149 barrel_config = acts.ToroidField.BarrelConfig()
0150 assert barrel_config.R_in > 0
0151 assert barrel_config.R_out > barrel_config.R_in
0152 assert barrel_config.I > 0
0153
0154
0155 ect_config = acts.ToroidField.EctConfig()
0156 assert ect_config.R_in > 0
0157 assert ect_config.R_out > ect_config.R_in
0158 assert ect_config.I > 0
0159
0160
0161 layout_config = acts.ToroidField.LayoutConfig()
0162 assert layout_config.nCoils > 0
0163 assert layout_config.nArc > 0
0164 assert layout_config.nStraight > 0
0165
0166
0167 if __name__ == "__main__":
0168
0169 test_toroidal_field_basic()
0170 test_toroidal_field_custom()
0171 test_toroidal_field_symmetry()
0172 test_toroidal_field_regions()
0173 test_toroidal_field_configuration()
0174 print("All ToroidField tests passed!")