File indexing completed on 2025-01-18 09:12:08
0001
0002 from pathlib import Path
0003
0004 import acts
0005 import acts.examples
0006
0007 u = acts.UnitConstants
0008
0009
0010 def RootBFieldWrite(bField, fileName, treeName="solenoid", level=acts.logging.VERBOSE):
0011 cfg = acts.examples.RootBFieldWriter.Config()
0012 cfg.bField = bField
0013 cfg.gridType = acts.examples.RootBFieldWriter.GridType.rz
0014 cfg.fileName = str(fileName)
0015 cfg.treeName = treeName
0016 acts.examples.RootBFieldWriter.run(cfg, level)
0017 return cfg
0018
0019
0020 def CsvBFieldWrite(bField, fileName, level=acts.logging.VERBOSE):
0021 cfg = acts.examples.CsvBFieldWriter.ConfigRzGrid()
0022 cfg.bField = bField
0023 cfg.fileName = str(fileName)
0024 acts.examples.CsvBFieldWriter.runRzGrid(cfg, level)
0025 return cfg
0026
0027
0028 def runBFieldWriting(outputDir: Path, rewrites: int = 0):
0029 solenoid = acts.SolenoidBField(
0030 radius=1200 * u.mm, length=6000 * u.mm, bMagCenter=2 * u.T, nCoils=1194
0031 )
0032 field = acts.solenoidFieldMap(
0033 rlim=(0, 1200 * u.mm),
0034 zlim=(-5000 * u.mm, 5000 * u.mm),
0035 nbins=(10, 10),
0036 field=solenoid,
0037 )
0038
0039 print("Solenoid ready")
0040
0041 cfg = RootBFieldWrite(field, outputDir / "solenoid.root")
0042 CsvBFieldWrite(field, outputDir / "solenoid.csv")
0043
0044 for i in range(rewrites):
0045 print(f"Now read back {cfg.fileName}")
0046
0047 field2 = acts.examples.MagneticFieldMapRz(cfg.fileName, tree="solenoid")
0048 cfg2 = RootBFieldWrite(field2, outputDir / f"solenoid{i+2}.root")
0049 CsvBFieldWrite(field2, outputDir / f"solenoid{i+2}.csv")
0050 cfg = cfg2
0051
0052 print("Done")
0053
0054
0055 if "__main__" == __name__:
0056 runBFieldWriting(Path.cwd())