55 print(
'Create map {0} from {1} using cmScale = {2}'.format(rootFileName,
57 if storeCoords
is True:
58 print(
'We will also store the x,y,z field coordinates in {0}'.format(rootFileName))
63 theFile = ROOT.TFile.Open(rootFileName,
'recreate')
65 rangeTree = ROOT.TTree(
'Range',
'Range')
66 rangeTree.SetDirectory(theFile)
69 rStruct = ROOT.rangeStruct()
70 rangeTree.Branch(
'xMin', ROOT.AddressOf(rStruct,
'xMin'),
'xMin/F')
71 rangeTree.Branch(
'xMax', ROOT.AddressOf(rStruct,
'xMax'),
'xMax/F')
72 rangeTree.Branch(
'dx', ROOT.AddressOf(rStruct,
'dx'),
'dx/F')
73 rangeTree.Branch(
'yMin', ROOT.AddressOf(rStruct,
'yMin'),
'yMin/F')
74 rangeTree.Branch(
'yMax', ROOT.AddressOf(rStruct,
'yMax'),
'yMax/F')
75 rangeTree.Branch(
'dy', ROOT.AddressOf(rStruct,
'dy'),
'dy/F')
76 rangeTree.Branch(
'zMin', ROOT.AddressOf(rStruct,
'zMin'),
'zMin/F')
77 rangeTree.Branch(
'zMax', ROOT.AddressOf(rStruct,
'zMax'),
'zMax/F')
78 rangeTree.Branch(
'dz', ROOT.AddressOf(rStruct,
'dz'),
'dz/F')
80 rStruct.xMin = rangeInfo[
'xMin']
81 rStruct.xMax = rangeInfo[
'xMax']
82 rStruct.dx = rangeInfo[
'dx']
83 rStruct.yMin = rangeInfo[
'yMin']
84 rStruct.yMax = rangeInfo[
'yMax']
85 rStruct.dy = rangeInfo[
'dy']
86 rStruct.zMin = rangeInfo[
'zMin']
87 rStruct.zMax = rangeInfo[
'zMax']
88 rStruct.dz = rangeInfo[
'dz']
91 x0 = 0.5*(rStruct.xMin + rStruct.xMax)
92 y0 = 0.5*(rStruct.yMin + rStruct.yMax)
93 z0 = 0.5*(rStruct.zMin + rStruct.zMax)
100 print(
'Centering field map using co-ordinate shift {0} {1} {2} cm'.format(x0, y0, z0))
103 rStruct.xMin = rStruct.xMin - x0
104 rStruct.xMax = rStruct.xMax - x0
106 rStruct.yMin = rStruct.yMin - y0
107 rStruct.yMax = rStruct.yMax - y0
109 rStruct.zMin = rStruct.zMin - z0
110 rStruct.zMax = rStruct.zMax - z0
112 print(
'x range = {0} to {1}'.format(rStruct.xMin, rStruct.xMax))
113 print(
'y range = {0} to {1}'.format(rStruct.yMin, rStruct.yMax))
114 print(
'z range = {0} to {1}'.format(rStruct.zMin, rStruct.zMax))
120 dataTree = ROOT.TTree(
'Data',
'Data')
121 dataTree.SetDirectory(theFile)
127 dStruct = ROOT.dataStruct()
128 if storeCoords
is True:
129 dataTree.Branch(
'x', ROOT.AddressOf(dStruct,
'x'),
'x/F')
130 dataTree.Branch(
'y', ROOT.AddressOf(dStruct,
'y'),
'y/F')
131 dataTree.Branch(
'z', ROOT.AddressOf(dStruct,
'z'),
'z/F')
133 dataTree.Branch(
'Bx', ROOT.AddressOf(dStruct,
'Bx'),
'Bx/F')
134 dataTree.Branch(
'By', ROOT.AddressOf(dStruct,
'By'),
'By/F')
135 dataTree.Branch(
'Bz', ROOT.AddressOf(dStruct,
'Bz'),
'Bz/F')
138 with open(inFileName,
'r')
as f:
149 if storeCoords
is True:
150 dStruct.x = float(sLine[0])*cmScale - x0
151 dStruct.y = float(sLine[1])*cmScale - y0
152 dStruct.z = float(sLine[2])*cmScale - z0
155 dStruct.Bx = float(sLine[3])
156 dStruct.By = float(sLine[4])
157 dStruct.Bz = float(sLine[5])