15ROOT.gROOT.ProcessLine(
34ROOT.gROOT.ProcessLine(
43def run(inFileName: str =
"test07_10cm_grid.table", outFileName: str =
"MuonFilterBFieldMap1.txt") ->
None:
48 rootFileName = outFileName.replace(
".txt",
".root")
53 print(f
"Creating text map {outFileName} from {inFileName}")
55 tmpFileName =
"tmpFile.txt"
87 with open(inFileName)
as inFile,
open(tmpFileName,
"w")
as tmpFile:
91 if iLine >= firstDataLine:
92 words = inLine.split()
95 x = float(words[0]) * m2cm
96 y = float(words[1]) * m2cm
97 z = float(words[2]) * m2cm
108 newLine = f
"{BxWord} {ByWord} {BzWord}\n"
110 tmpFile.write(newLine)
113 if iLine == firstDataLine:
137 if gotdx == 0
and x != xOld:
140 if gotdy == 0
and y != yOld:
143 if gotdz == 0
and z != zOld:
147 print(f
"dx = {dx}, dy = {dy}, dz = {dz}")
148 print(f
"x = {xMin} to {xMax}, y = {yMin} to {yMax}, z = {zMin} to {zMax}")
151 with open(tmpFileName)
as tmpFile2,
open(outFileName,
"w")
as outFile:
153 f
"CLimits {xMin:.0f} {xMax:.0f} {dx:.0f} {yMin:.0f} {yMax:.0f} {dy:.0f} {zMin:.0f} {zMax:.0f} {dz:.0f}\n"
155 outFile.write(outLine)
161 outLine =
"Bx(T) By(T) Bz(T)\n"
163 outFile.write(outLine)
166 for tLine
in tmpFile2:
186 print(f
"Create ROOT map {outFileName} from {inFileName}")
189 theFile = ROOT.TFile.Open(outFileName,
"recreate")
191 rangeTree = ROOT.TTree(
"Range",
"Range")
192 rangeTree.SetDirectory(theFile)
195 rStruct = ROOT.rangeStruct()
196 rangeTree.Branch(
"xMin", ROOT.addressof(rStruct,
"xMin"),
"xMin/F")
197 rangeTree.Branch(
"xMax", ROOT.addressof(rStruct,
"xMax"),
"xMax/F")
198 rangeTree.Branch(
"dx", ROOT.addressof(rStruct,
"dx"),
"dx/F")
199 rangeTree.Branch(
"yMin", ROOT.addressof(rStruct,
"yMin"),
"yMin/F")
200 rangeTree.Branch(
"yMax", ROOT.addressof(rStruct,
"yMax"),
"yMax/F")
201 rangeTree.Branch(
"dy", ROOT.addressof(rStruct,
"dy"),
"dy/F")
202 rangeTree.Branch(
"zMin", ROOT.addressof(rStruct,
"zMin"),
"zMin/F")
203 rangeTree.Branch(
"zMax", ROOT.addressof(rStruct,
"zMax"),
"zMax/F")
204 rangeTree.Branch(
"dz", ROOT.addressof(rStruct,
"dz"),
"dz/F")
206 dataTree = ROOT.TTree(
"Data",
"Data")
207 dataTree.SetDirectory(theFile)
213 dStruct = ROOT.dataStruct()
214 dataTree.Branch(
"Bx", ROOT.addressof(dStruct,
"Bx"),
"Bx/F")
215 dataTree.Branch(
"By", ROOT.addressof(dStruct,
"By"),
"By/F")
216 dataTree.Branch(
"Bz", ROOT.addressof(dStruct,
"Bz"),
"Bz/F")
226 with open(inFileName)
as f:
233 rStruct.xMin = float(sLine[1])
234 rStruct.xMax = float(sLine[2])
235 rStruct.dx = float(sLine[3])
236 rStruct.yMin = float(sLine[4])
237 rStruct.yMax = float(sLine[5])
238 rStruct.dy = float(sLine[6])
239 rStruct.zMin = float(sLine[7])
240 rStruct.zMax = float(sLine[8])
241 rStruct.dz = float(sLine[9])
243 Nx = int(((rStruct.xMax - rStruct.xMin) / rStruct.dx) + 1.0)
244 Ny = int(((rStruct.yMax - rStruct.yMin) / rStruct.dy) + 1.0)
245 Nz = int(((rStruct.zMax - rStruct.zMin) / rStruct.dz) + 1.0)
247 print(f
"Nx = {Nx}, Ny = {Ny}, Nz = {Nz}")
253 dStruct.Bx = float(sLine[0])
254 dStruct.By = float(sLine[1])
255 dStruct.Bz = float(sLine[2])
275if __name__ ==
"__main__":
276 run(
"test07_10cm_grid.table",
"MuonFilterBFieldMap1.txt")
None createRootMap(inFileName, outFileName)
None createTextMap(inFileName, outFileName)
None run(str inFileName="test07_10cm_grid.table", str outFileName="MuonFilterBFieldMap1.txt")
str formatNumber(float x)
int open(const char *, int)
Opens a file descriptor.