54 print (
'Create map {0} from {1} using cmScale = {2}'.format(rootFileName,
56 if storeCoords
is True:
57 print (
'We will also store the x,y,z field coordinates in {0}'.format(rootFileName))
62 theFile = ROOT.TFile.Open(rootFileName,
'recreate')
64 rangeTree = ROOT.TTree(
'Range',
'Range')
65 rangeTree.SetDirectory(theFile)
68 rStruct = ROOT.rangeStruct()
69 rangeTree.Branch(
'xMin', ROOT.AddressOf(rStruct,
'xMin'),
'xMin/F')
70 rangeTree.Branch(
'xMax', ROOT.AddressOf(rStruct,
'xMax'),
'xMax/F')
71 rangeTree.Branch(
'dx', ROOT.AddressOf(rStruct,
'dx'),
'dx/F')
72 rangeTree.Branch(
'yMin', ROOT.AddressOf(rStruct,
'yMin'),
'yMin/F')
73 rangeTree.Branch(
'yMax', ROOT.AddressOf(rStruct,
'yMax'),
'yMax/F')
74 rangeTree.Branch(
'dy', ROOT.AddressOf(rStruct,
'dy'),
'dy/F')
75 rangeTree.Branch(
'zMin', ROOT.AddressOf(rStruct,
'zMin'),
'zMin/F')
76 rangeTree.Branch(
'zMax', ROOT.AddressOf(rStruct,
'zMax'),
'zMax/F')
77 rangeTree.Branch(
'dz', ROOT.AddressOf(rStruct,
'dz'),
'dz/F')
79 rStruct.xMin = rangeInfo[
'xMin']
80 rStruct.xMax = rangeInfo[
'xMax']
81 rStruct.dx = rangeInfo[
'dx']
82 rStruct.yMin = rangeInfo[
'yMin']
83 rStruct.yMax = rangeInfo[
'yMax']
84 rStruct.dy = rangeInfo[
'dy']
85 rStruct.zMin = rangeInfo[
'zMin']
86 rStruct.zMax = rangeInfo[
'zMax']
87 rStruct.dz = rangeInfo[
'dz']
92 z0 = 0.5 * (rStruct.zMin + rStruct.zMax)
99 print (
'Centering field map using co-ordinate shift {0} {1} {2} cm'.format(x0, y0, z0))
102 rStruct.xMin = rStruct.xMin - x0
103 rStruct.xMax = rStruct.xMax - x0
105 rStruct.yMin = rStruct.yMin - y0
106 rStruct.yMax = rStruct.yMax - y0
108 rStruct.zMin = rStruct.zMin - z0
109 rStruct.zMax = rStruct.zMax - z0
111 print (
'x range = {0} to {1}'.format(rStruct.xMin, rStruct.xMax))
112 print (
'y range = {0} to {1}'.format(rStruct.yMin, rStruct.yMax))
113 print (
'z range = {0} to {1}'.format(rStruct.zMin, rStruct.zMax))
119 dataTree = ROOT.TTree(
'Data',
'Data')
120 dataTree.SetDirectory(theFile)
126 dStruct = ROOT.dataStruct()
127 if storeCoords
is True:
128 dataTree.Branch(
'x', ROOT.AddressOf(dStruct,
'x'),
'x/F')
129 dataTree.Branch(
'y', ROOT.AddressOf(dStruct,
'y'),
'y/F')
130 dataTree.Branch(
'z', ROOT.AddressOf(dStruct,
'z'),
'z/F')
132 dataTree.Branch(
'Bx', ROOT.AddressOf(dStruct,
'Bx'),
'Bx/F')
133 dataTree.Branch(
'By', ROOT.AddressOf(dStruct,
'By'),
'By/F')
134 dataTree.Branch(
'Bz', ROOT.AddressOf(dStruct,
'Bz'),
'Bz/F')
138 inData = pd.read_csv(inFileName, delim_whitespace=
True, header=
None)
139 inData.columns=[
"x",
"y",
"z",
"bx",
"by",
"bz"]
140 inData = inData.sort_values(by=[
"x",
"y",
"z"])
141 inData = inData.astype(float)
144 data_shape = float(inData.shape[0])
145 for row
in inData.itertuples():
146 if row.Index / data_shape >= count:
147 print(
"Processed: {} %".format(count * 100))
151 if storeCoords
is True:
152 dStruct.x = row.x * cmScale - x0
153 dStruct.y = row.y * cmScale - y0
154 dStruct.z = row.z * cmScale - z0