62def createRootMap(inFileName, rootFileName, cmScale, storeCoords) -> None:
63 print(f
"Create map {rootFileName} from {inFileName} using cmScale = {cmScale}")
64 if storeCoords
is True:
65 print(f
"We will also store the x,y,z field coordinates in {rootFileName}")
70 theFile = ROOT.TFile.Open(rootFileName,
"recreate")
72 rangeTree = ROOT.TTree(
"Range",
"Range")
73 rangeTree.SetDirectory(theFile)
76 rStruct = ROOT.rangeStruct()
77 rangeTree.Branch(
"xMin", ROOT.addressof(rStruct,
"xMin"),
"xMin/F")
78 rangeTree.Branch(
"xMax", ROOT.addressof(rStruct,
"xMax"),
"xMax/F")
79 rangeTree.Branch(
"dx", ROOT.addressof(rStruct,
"dx"),
"dx/F")
80 rangeTree.Branch(
"yMin", ROOT.addressof(rStruct,
"yMin"),
"yMin/F")
81 rangeTree.Branch(
"yMax", ROOT.addressof(rStruct,
"yMax"),
"yMax/F")
82 rangeTree.Branch(
"dy", ROOT.addressof(rStruct,
"dy"),
"dy/F")
83 rangeTree.Branch(
"zMin", ROOT.addressof(rStruct,
"zMin"),
"zMin/F")
84 rangeTree.Branch(
"zMax", ROOT.addressof(rStruct,
"zMax"),
"zMax/F")
85 rangeTree.Branch(
"dz", ROOT.addressof(rStruct,
"dz"),
"dz/F")
87 rStruct.xMin = rangeInfo[
"xMin"]
88 rStruct.xMax = rangeInfo[
"xMax"]
89 rStruct.dx = rangeInfo[
"dx"]
90 rStruct.yMin = rangeInfo[
"yMin"]
91 rStruct.yMax = rangeInfo[
"yMax"]
92 rStruct.dy = rangeInfo[
"dy"]
93 rStruct.zMin = rangeInfo[
"zMin"]
94 rStruct.zMax = rangeInfo[
"zMax"]
95 rStruct.dz = rangeInfo[
"dz"]
98 x0 = 0.5 * (rStruct.xMin + rStruct.xMax)
99 y0 = 0.5 * (rStruct.yMin + rStruct.yMax)
100 z0 = 0.5 * (rStruct.zMin + rStruct.zMax)
107 print(f
"Centering field map using coordinate shift {x0} {y0} {z0} cm")
110 rStruct.xMin = rStruct.xMin - x0
111 rStruct.xMax = rStruct.xMax - x0
113 rStruct.yMin = rStruct.yMin - y0
114 rStruct.yMax = rStruct.yMax - y0
116 rStruct.zMin = rStruct.zMin - z0
117 rStruct.zMax = rStruct.zMax - z0
119 print(f
"x range = {rStruct.xMin} to {rStruct.xMax}")
120 print(f
"y range = {rStruct.yMin} to {rStruct.yMax}")
121 print(f
"z range = {rStruct.zMin} to {rStruct.zMax}")
127 dataTree = ROOT.TTree(
"Data",
"Data")
128 dataTree.SetDirectory(theFile)
134 dStruct = ROOT.dataStruct()
135 if storeCoords
is True:
136 dataTree.Branch(
"x", ROOT.addressof(dStruct,
"x"),
"x/F")
137 dataTree.Branch(
"y", ROOT.addressof(dStruct,
"y"),
"y/F")
138 dataTree.Branch(
"z", ROOT.addressof(dStruct,
"z"),
"z/F")
140 dataTree.Branch(
"Bx", ROOT.addressof(dStruct,
"Bx"),
"Bx/F")
141 dataTree.Branch(
"By", ROOT.addressof(dStruct,
"By"),
"By/F")
142 dataTree.Branch(
"Bz", ROOT.addressof(dStruct,
"Bz"),
"Bz/F")
145 with open(inFileName)
as f:
153 if storeCoords
is True:
154 dStruct.x = float(sLine[0]) * cmScale - x0
155 dStruct.y = float(sLine[1]) * cmScale - y0
156 dStruct.z = float(sLine[2]) * cmScale - z0
159 dStruct.Bx = float(sLine[3])
160 dStruct.By = float(sLine[4])
161 dStruct.Bz = float(sLine[5])