1
|
import os
|
2
|
import subprocess
|
3
|
import json
|
4
|
import operator
|
5
|
import glob
|
6
|
import sys
|
7
|
|
8
|
import numpy
|
9
|
import ROOT
|
10
|
|
11
|
import Configuration
|
12
|
import maus_cpp.globals
|
13
|
|
14
|
import xboa.Common as common
|
15
|
from xboa.Bunch import Bunch
|
16
|
from xboa.Hit import Hit
|
17
|
from xboa.tracking import MAUSTracking
|
18
|
|
19
|
class Tracking:
|
20
|
|
21
|
def amp(self, ellipse_inv, hit):
|
22
|
arr = numpy.matrix([hit['x'], hit['px'], hit['y'], hit['py']])
|
23
|
amplitude = arr*ellipse_inv*arr.T
|
24
|
return amplitude[0, 0]
|
25
|
|
26
|
def amp_list(self, bunch, beta, alpha, bz):
|
27
|
ellipse = Bunch.build_penn_ellipse(1., self.m_mu, beta, alpha, self.p, 0., bz, 1.)
|
28
|
ellipse_inv = numpy.linalg.inv(ellipse)
|
29
|
amplitude_list = [self.amp(ellipse_inv, hit) for hit in bunch]
|
30
|
return amplitude_list
|
31
|
|
32
|
def amp_list_6d(self, bunch):
|
33
|
bunch.set_covariance_matrix(True)
|
34
|
amp_list = [bunch.get_amplitude(bunch, hit, ['x', 'y', 'ct']) for hit in bunch]
|
35
|
bunch.set_covariance_matrix(False)
|
36
|
return amp_list
|
37
|
|
38
|
def scatter_plot_mean_rms(self, x_values, y_values, xmin, xmax, xstep):
|
39
|
nbins = 9
|
40
|
bin_low = 0.
|
41
|
bin_step = 10.
|
42
|
hist_data = []
|
43
|
for x, y in zip(x_values, y_values):
|
44
|
bin = int((x-bin_low)/bin_step)
|
45
|
while len(hist_data) - 1 < bin:
|
46
|
hist_data.append([])
|
47
|
hist_data[bin].append(y)
|
48
|
hist = ROOT.TH1D("Mean", "", nbins, bin_low, bin_low+(nbins+1)*bin_step)
|
49
|
for i, data in enumerate(hist_data):
|
50
|
mean, sigmaSqu = 0., 0.
|
51
|
if len(data) > 0:
|
52
|
mean = sum(data)/len(data)
|
53
|
if len(data) > 1:
|
54
|
sigmaSqu = sum([x**2 for x in data])/len(data)-mean**2
|
55
|
hist.SetBinContent(i+1, mean)
|
56
|
hist.SetBinError(i+1, sigmaSqu**0.5)
|
57
|
common._hist_persistent.append(hist)
|
58
|
hist.SetLineWidth(2)
|
59
|
hist.SetLineColor(8)
|
60
|
return hist
|
61
|
|
62
|
def amplitude_scatter_plot(self, bunch_in, bunch_out, predicate):
|
63
|
"""predicate takes arguments (spill_index, spills_in_bunch_out)"""
|
64
|
spills_out = set([(hit['spill'], hit['event_number']) for hit in bunch_out])
|
65
|
hits_in = [hit for hit in bunch_in if (hit['spill'], hit['event_number']) in spills_out]
|
66
|
hits_out = [hit for hit in bunch_out if (hit['spill'], hit['event_number']) in spills_out]
|
67
|
amp_in = self.amp_list(hits_in, self.beta, 0., self.bz_us)
|
68
|
amp_out = self.amp_list(hits_out, self.beta, 0., self.bz_ds)
|
69
|
delta_amp = [(amp_out[i]-amp_in[i])/amp_in[i] for i, a_in in enumerate(amp_in)]
|
70
|
if len(amp_in) == 0 or len(amp_in) != len(amp_out):
|
71
|
print "Failed to make graph:", len(amp_in), len(amp_out)
|
72
|
hist, graph = common.make_root_graph('amplitude x y', [0.], 'x-y amplitude in [mm]', [0.], 'x-y amplitude out [mm]')
|
73
|
else:
|
74
|
hist, graph = common.make_root_graph('amplitude x y', amp_in, 'x-y amplitude in [mm]', delta_amp, '(A_{out} - A_{in})/A_{in} [mm]', xmin=0., xmax=200.)
|
75
|
hist_means = self.scatter_plot_mean_rms(amp_in, delta_amp, 0., 200., 10.)
|
76
|
graph.SetMarkerStyle(7)
|
77
|
return hist, hist_means, graph
|
78
|
|
79
|
def amplitude_p_scatter_plot(self, bunch_in):
|
80
|
"""predicate takes arguments (spill_index, spills_in_bunch_out)"""
|
81
|
hits_in = [hit for hit in bunch_in]
|
82
|
amp_in = self.amp_list(hits_in, self.beta, 0., self.bz_us)
|
83
|
p_in = [hit['p'] for hit in hits_in]
|
84
|
if len(amp_in) == 0:
|
85
|
print "Failed to make graph:", len(amp_in)
|
86
|
hist, graph = common.make_root_graph('amplitude x y', [0.], 'x-y amplitude in [mm]', [0.], 'P [MeV/c]', xmin=0., xmax=200.)
|
87
|
else:
|
88
|
hist, graph = common.make_root_graph('amplitude x y', amp_in, 'x-y amplitude in [mm]', p_in, 'P [MeV/c]', xmin=0., xmax=200.)
|
89
|
hist_means = self.scatter_plot_mean_rms(amp_in, p_in, 0., 200., 10.)
|
90
|
graph.SetMarkerStyle(7)
|
91
|
return hist, hist_means, graph
|
92
|
|
93
|
def amplitude_t_scatter_plot(self, bunch_in, bunch_out, weight_cut):
|
94
|
"""predicate takes arguments (spill_index, spills_in_bunch_out)"""
|
95
|
spills_out = set([(hit['spill'], hit['event_number']) for hit in bunch_out])
|
96
|
hits_in_cut = [hit for hit in bunch_in if (hit['spill'], hit['event_number']) in spills_out and hit['weight'] > weight_cut]
|
97
|
hits_out_cut = [hit for hit in bunch_out if (hit['spill'], hit['event_number']) in spills_out and hit['weight'] > weight_cut]
|
98
|
amp_in_cut = self.amp_list(hits_in_cut, self.beta, 0., self.bz_us)
|
99
|
amp_out_cut = self.amp_list(hits_out_cut, self.beta, 0., self.bz_ds)
|
100
|
delta_t_cut = [h_o['t']-h_i['t'] for h_i, h_o in zip(hits_in_cut, hits_out_cut)]
|
101
|
if len(amp_in_cut) == 0:
|
102
|
print "Failed to make graph:", len(amp_in_cut)
|
103
|
hist, graph = common.make_root_graph('amplitude x y', [0.], 'x-y amplitude in [mm]', [0.], 'dt [ns]', xmin=0., xmax=200.)
|
104
|
else:
|
105
|
hist, graph = common.make_root_graph('amplitude x y', amp_in_cut, 'x-y amplitude in [mm]', delta_t_cut, 'dt [ns]', xmin=0., xmax=200.)
|
106
|
hist_means = self.scatter_plot_mean_rms(amp_in_cut, delta_t_cut, 0., 200., 10.)
|
107
|
graph.SetMarkerStyle(7)
|
108
|
return hist, hist_means, graph
|
109
|
|
110
|
def amplitude_6d_scatter_plot(self, bunch_in, bunch_out):
|
111
|
"""predicate takes arguments (spill_index, spills_in_bunch_out)"""
|
112
|
amp_in = self.amp_list_6d(bunch_in)
|
113
|
amp_out = self.amp_list_6d(bunch_out)
|
114
|
hist_in = common.make_root_histogram('A_{6D} in', amp_in, 'A_{6D} [mm]', 20, xmin=0., xmax=200.)
|
115
|
hist_out = common.make_root_histogram('A_{6D} out', amp_out, 'A_{6D} [mm]', 20, xmin=0., xmax=200.)
|
116
|
hist_in.SetName('A_{6D} in')
|
117
|
hist_out.SetName('A_{6D} out')
|
118
|
return hist_in, hist_out
|
119
|
|
120
|
def amplitude_6d_capture_plot(self, bunch_in, bunch_out):
|
121
|
amp_in = sorted(self.amp_list_6d(bunch_in))
|
122
|
amp_out = sorted(self.amp_list_6d(bunch_out))
|
123
|
bins = [i*10. for i in range(11)]+[i*50. for i in range(2, 5)]
|
124
|
contents_in = []
|
125
|
contents_out = []
|
126
|
|
127
|
|
128
|
def amplitude_scatter(self, bunch_in, bunch_out):
|
129
|
canvas = common.make_root_canvas('amplitude 6d hist')
|
130
|
hist_in, hist_out = self.amplitude_6d_scatter_plot(bunch_in, bunch_out)
|
131
|
hist_out.SetLineColor(4)
|
132
|
hist_out.Draw()
|
133
|
hist_in.SetLineColor(2)
|
134
|
hist_in.Draw("SAME")
|
135
|
common.make_root_legend(canvas, [hist_in, hist_out])
|
136
|
canvas.Update()
|
137
|
self.print_canvas(canvas, 'acceptance_6d_hist')
|
138
|
spills_out = set([hit['spill'] for hit in bunch_out])
|
139
|
canvas = common.make_root_canvas('amplitude x y scatter')
|
140
|
hist, hist_means, graph = self.amplitude_scatter_plot(bunch_in, bunch_out, lambda x: True)
|
141
|
hist.Draw()
|
142
|
graph.Draw('p')
|
143
|
hist_means.Draw("same")
|
144
|
canvas.Update()
|
145
|
self.print_canvas(canvas, 'acceptance')
|
146
|
canvas = common.make_root_canvas('amplitude x y p scatter')
|
147
|
hist, hist_means, graph = self.amplitude_p_scatter_plot(bunch_in)
|
148
|
hist.Draw()
|
149
|
graph.Draw('p')
|
150
|
hist_means.Draw("same")
|
151
|
canvas.Update()
|
152
|
self.print_canvas(canvas, 'acceptance_p')
|
153
|
canvas = common.make_root_canvas('amplitude x y t scatter')
|
154
|
hist, hist_means, graph_cut = self.amplitude_t_scatter_plot(bunch_in, bunch_out, 0.1)
|
155
|
hist.Draw()
|
156
|
dummy_1, dummy_2, graph_all = self.amplitude_t_scatter_plot(bunch_in, bunch_out, -0.1)
|
157
|
graph_all.SetMarkerColor(2)
|
158
|
graph_all.Draw('p')
|
159
|
graph_cut.Draw('p')
|
160
|
hist_means.Draw("same")
|
161
|
canvas.Update()
|
162
|
self.print_canvas(canvas, 'acceptance_t')
|
163
|
|
164
|
def two_d_plots(self, bunch_list, colour, canvas_list = None):
|
165
|
n_graphs = 4
|
166
|
if canvas_list == None:
|
167
|
canvas_list = [None]*n_graphs
|
168
|
graph_list = [None]*n_graphs
|
169
|
|
170
|
canvas_list[0], hist, graph_list[0] = bunch_list[0].root_scatter_graph("t", "energy", "ns", "MeV", include_weightless=False, canvas=canvas_list[0])
|
171
|
canvas_list[1], hist, graph_list[1] = bunch_list[-1].root_scatter_graph("t", "energy", "ns", "MeV", include_weightless=False, canvas=canvas_list[1])
|
172
|
canvas_list[2], hist, graph_list[2] = bunch_list[0].root_scatter_graph("r", "pt", "mm", "MeV/c", include_weightless=False, canvas=canvas_list[2])
|
173
|
canvas_list[3], hist, graph_list[3] = bunch_list[-1].root_scatter_graph("r", "pt", "mm", "MeV/c", include_weightless=False, canvas=canvas_list[3])
|
174
|
for i in range(n_graphs):
|
175
|
canvas_list[i].cd()
|
176
|
graph_list[i].SetMarkerStyle(6)
|
177
|
graph_list[i].SetMarkerColor(colour)
|
178
|
graph_list[i].Draw("p")
|
179
|
canvas_list[i].Update()
|
180
|
self.print_canvas(canvas_list[0], "time_energy_at_start")
|
181
|
self.print_canvas(canvas_list[1], "time_energy_at_end")
|
182
|
self.print_canvas(canvas_list[2], "r_pt_at_start")
|
183
|
self.print_canvas(canvas_list[3], "r_pt_at_end")
|
184
|
return canvas_list
|
185
|
|
186
|
def cut(self, bunch_list):
|
187
|
print " weights in "
|
188
|
print " no cut:", bunch_list[0].bunch_weight(), bunch_list[-1].bunch_weight()
|
189
|
for bunch in bunch_list:
|
190
|
bunch.transmission_cut(bunch_list[-1], global_cut=True)
|
191
|
bunch.transmission_cut(bunch_list[-1], global_cut=True, test_variable = ['spill', 'event_number', 'particle_number', 'pid'])
|
192
|
bunch.cut({'pid':-13}, operator.ne, global_cut=True)
|
193
|
print ' transmission cut:', bunch_list[0].bunch_weight(), bunch_list[-1].bunch_weight(), "**"
|
194
|
bunches = [bunch_list[0], bunch_list[-1]]
|
195
|
cut_stream = ['upstream', 'downstream']
|
196
|
for i in [0, 1]:
|
197
|
print ' ', cut_stream[i]
|
198
|
print ' ', 'cut ', ' u/s', ' d/s'
|
199
|
bunches[i].cut({'r':self.r_cut[i]}, operator.gt, global_cut=True)
|
200
|
print ' cut r: ', self.r_cut[i], str(bunches[0].bunch_weight()).rjust(10), str(bunches[1].bunch_weight()).rjust(10)
|
201
|
bunches[i].cut({'amplitude x y':self.amplitude_trans_cut[i]}, operator.gt, global_cut=True)
|
202
|
print ' cut amp_trans: ', str(self.amplitude_trans_cut[i]).rjust(5), str(bunches[0].bunch_weight()).rjust(10), str(bunches[1].bunch_weight()).rjust(10)
|
203
|
bunches[i].cut({'amplitude x y':self.amplitude_trans_cut[i]}, operator.gt, global_cut=True)
|
204
|
print ' cut amp_trans: ', str(self.amplitude_trans_cut[i]).rjust(5), str(bunches[0].bunch_weight()).rjust(10), str(bunches[1].bunch_weight()).rjust(10)
|
205
|
if self.do_long_cut:
|
206
|
bunches[i].cut({'amplitude ct':self.amplitude_ct_cut[i]}, operator.gt, global_cut=True)
|
207
|
print ' cut amp_long: ', str(self.amplitude_ct_cut[i]).rjust(5), str(bunches[0].bunch_weight()).rjust(10), str(bunches[1].bunch_weight()).rjust(10)
|
208
|
bunches[i].cut({'amplitude ct':self.amplitude_ct_cut[i]}, operator.gt, global_cut=True)
|
209
|
print ' cut amp_long: ', str(self.amplitude_ct_cut[i]).rjust(5), str(bunches[0].bunch_weight()).rjust(10), str(bunches[1].bunch_weight()).rjust(10)
|
210
|
mean_p = bunches[i].mean(['p'])['p']
|
211
|
bunches[i].cut({'p':mean_p+self.p_cut[i][1]}, operator.gt, global_cut=True)
|
212
|
bunches[i].cut({'p':mean_p-self.p_cut[i][0]}, operator.lt, global_cut=True)
|
213
|
print ' cut', round(mean_p-self.p_cut[i][0], 1), '< p <', round(mean_p+self.p_cut[i][1], 1), ' ', str(bunches[0].bunch_weight()).rjust(10), str(bunches[1].bunch_weight()).rjust(10)
|
214
|
|
215
|
def z_plot(self, bunch_list):
|
216
|
print "Start MOMENTS"
|
217
|
print bunch_list[0].moment(['t', 't'])
|
218
|
print bunch_list[0].moment(['pz', 't'])
|
219
|
print bunch_list[0].moment(['pz', 'pz'])
|
220
|
"""
|
221
|
for item in ['t', 'pz', 'energy']:
|
222
|
canvas = common.make_root_canvas('sigma_'+item)
|
223
|
z_list = [bunch.mean(['z'])['z'] for bunch in bunch_list]
|
224
|
item_list = [bunch.moment([item, item])**0.5 for bunch in bunch_list]
|
225
|
hist, graph = common.make_root_graph('sigma_'+item, z_list, 'mean z [mm]', item_list, '#sigma('+item+')')
|
226
|
hist.Draw()
|
227
|
graph.Draw('l')
|
228
|
self.print_canvas(canvas, 's_'+item+'_vs_z')
|
229
|
"""
|
230
|
canvas, hist, graph = Bunch.root_graph(bunch_list, 'mean', ['z'], 'mean', ['p'], 'mm', 'MeV/c')
|
231
|
self.print_canvas(canvas, 'momentum_vs_z')
|
232
|
canvas, hist, graph = Bunch.root_graph(bunch_list, 'mean', ['z'], 'beta', ['x', 'y'], 'mm', 'mm', ymin=0., ymax=2000.)
|
233
|
hist.GetXaxis().SetTitle("z [mm]")
|
234
|
hist.GetYaxis().SetTitle("Transverse #beta [mm]")
|
235
|
self.set_style(graph)
|
236
|
self.get_verticals(canvas)
|
237
|
self.print_canvas(canvas, 'beta_trans_vs_z')
|
238
|
canvas, hist, graph = Bunch.root_graph(bunch_list, 'mean', ['z'], 'emittance', ['x', 'y'], 'mm', 'mm')
|
239
|
hist.GetXaxis().SetTitle("z [mm]")
|
240
|
hist.GetYaxis().SetTitle("Transverse emittance [mm]")
|
241
|
self.set_style(graph)
|
242
|
self.get_verticals(canvas)
|
243
|
self.print_canvas(canvas, 'emittance_trans_vs_z')
|
244
|
canvas, hist, graph = Bunch.root_graph(bunch_list, 'mean', ['z'], 'beta', ['t'], 'mm', 'mm')
|
245
|
self.print_canvas(canvas, 'beta_long_vs_z')
|
246
|
canvas, hist, graph = Bunch.root_graph(bunch_list, 'mean', ['z'], 'emittance', ['ct'], 'mm', 'mm')
|
247
|
self.print_canvas(canvas, 'emittance_long_vs_z')
|
248
|
canvas, hist, graph = Bunch.root_graph(bunch_list, 'mean', ['z'], 'emittance', ['ct', 'x', 'y'], 'mm', 'mm')
|
249
|
self.print_canvas(canvas, 'emittance_6d_vs_z')
|
250
|
ref_bunch_list = [Bunch.new_from_hits([bunch[0]]) for bunch in bunch_list]
|
251
|
canvas, hist, graph = Bunch.root_graph(ref_bunch_list, 'mean', ['z'], 'mean', ['bz'], 'mm', 'T')
|
252
|
hist.GetXaxis().SetTitle("z [mm]")
|
253
|
hist.GetYaxis().SetTitle("B_{z} [T]")
|
254
|
self.set_style(graph)
|
255
|
self.get_verticals(canvas)
|
256
|
self.print_canvas(canvas, 'bz_vs_z')
|
257
|
|
258
|
def grok_filename(self, filename):
|
259
|
base = os.path.basename(filename)[12:-5]
|
260
|
emittance = base.split('_')[0]
|
261
|
emittance = float(emittance.split('=')[1])
|
262
|
a_dir = os.path.dirname(filename).split('/')
|
263
|
index = a_dir[-1].split('_')[-1]
|
264
|
base += '_'+index
|
265
|
a_dir = "/".join(a_dir[:-1])
|
266
|
print " directory", a_dir, "name", base
|
267
|
self.current = {
|
268
|
"dir":a_dir,
|
269
|
"name":base,
|
270
|
"full":filename,
|
271
|
"emittance":emittance,
|
272
|
"index":index
|
273
|
}
|
274
|
return self.current
|
275
|
|
276
|
def print_canvas(self, canvas, name):
|
277
|
for format in ["png", "root"]:
|
278
|
canvas.Print(self.current["dir"]+"/"+name+"_"+self.current["name"]+"."+format)
|
279
|
|
280
|
def single_analysis(self, filename):
|
281
|
print "Loading data", filename
|
282
|
metadata = self.grok_filename(filename)
|
283
|
bunch_list = Bunch.new_list_from_read_builtin('maus_root_virtual_hit', filename)
|
284
|
len_cut = max([len(bunch) for bunch in bunch_list])/20
|
285
|
print " Discarding bunches with fewer than", len_cut, "particles"
|
286
|
bunch_list = [bunch for bunch in bunch_list if len(bunch) > len_cut]
|
287
|
if self.z_max != None:
|
288
|
bunch_list = [bunch for bunch in bunch_list if bunch[0]['z'] < self.z_max]
|
289
|
print " Printing transmission (before cut)"
|
290
|
canvas, hist, graph = Bunch.root_graph(bunch_list, 'mean', ['z'], 'bunch_weight', [], 'mm', '')
|
291
|
self.print_canvas(canvas, 'weight_vs_z')
|
292
|
print " Making cuts"
|
293
|
#canvas_list = self.two_d_plots(bunch_list, 2)
|
294
|
self.cut(bunch_list)
|
295
|
#self.amplitude_scatter(bunch_list[0], bunch_list[-1])
|
296
|
print " Making 2d plots"
|
297
|
#self.two_d_plots(bunch_list, 1, canvas_list)
|
298
|
print " Making z plots"
|
299
|
self.z_plot(bunch_list)
|
300
|
print " Making acceptance plots"
|
301
|
self.data.append((metadata, bunch_list))
|
302
|
Bunch.clear_global_weights()
|
303
|
|
304
|
def multi_analysis(self):
|
305
|
multi_data = open(self.data[0][0]["dir"]+"/multi_analysis_"+self.current["index"]+".json", "w")
|
306
|
delta_transmission = []
|
307
|
delta_emittance_trans = []
|
308
|
nominal_emittance_trans = []
|
309
|
actual_emittance_trans = []
|
310
|
actual_emittance_long = []
|
311
|
delta_emittance_long = []
|
312
|
actual_emittance_6d = []
|
313
|
delta_emittance_6d = []
|
314
|
sigma_energy = []
|
315
|
for item in self.data:
|
316
|
self.cut(item[1])
|
317
|
try:
|
318
|
delta_trans = float(len(item[1][-1]))/float(len(item[1][0]))
|
319
|
emit_in = item[1][0].get_emittance(['x', 'y'])
|
320
|
emit_out = item[1][-1].get_emittance(['x', 'y'])
|
321
|
delta_emit_t = emit_out/emit_in-1.
|
322
|
s_energy = (item[1][0].moment(['energy', 'energy']))**0.5
|
323
|
emit_long_in = item[1][0].get_emittance(['ct'])
|
324
|
emit_long_out = item[1][-1].get_emittance(['ct'])
|
325
|
delta_emit_l = emit_long_out/emit_long_in-1.
|
326
|
emit_6d_in = item[1][0].get_emittance(['x', 'y', 'ct'])
|
327
|
emit_6d_out = item[1][-1].get_emittance(['x', 'y', 'ct'])
|
328
|
delta_emit_6d = emit_6d_out/emit_6d_in-1.
|
329
|
sigma_energy.append(s_energy)
|
330
|
actual_emittance_long.append(emit_long_in)
|
331
|
delta_emittance_long.append(delta_emit_l)
|
332
|
actual_emittance_trans.append(emit_in)
|
333
|
delta_emittance_trans.append(delta_emit_t)
|
334
|
actual_emittance_6d.append(emit_6d_in)
|
335
|
delta_emittance_6d.append(delta_emit_6d)
|
336
|
delta_transmission.append(delta_trans)
|
337
|
nominal_emittance_trans.append(item[0]['emittance'])
|
338
|
except Exception:
|
339
|
sys.excepthook(*sys.exc_info())
|
340
|
Bunch.clear_global_weights()
|
341
|
json_doc = {
|
342
|
"delta_transmission":delta_transmission,
|
343
|
"nominal_emittance_trans":nominal_emittance_trans,
|
344
|
"delta_emittance_trans":delta_emittance_trans,
|
345
|
"actual_emittance_trans":actual_emittance_trans,
|
346
|
"delta_emittance_long":delta_emittance_long,
|
347
|
"actual_emittance_long":actual_emittance_long,
|
348
|
"delta_emittance_6d":delta_emittance_6d,
|
349
|
"actual_emittance_6d":actual_emittance_6d,
|
350
|
"sigma_energy":sigma_energy,
|
351
|
}
|
352
|
print >> multi_data, json.dumps(json_doc)
|
353
|
|
354
|
def set_style(self, graph, is_alternative = None):
|
355
|
if is_alternative == None:
|
356
|
is_alternative = self.current["full"].find("alternative") > -1
|
357
|
if is_alternative:
|
358
|
graph.SetLineColor(ROOT.kBlue-4)
|
359
|
graph.SetLineStyle(2)
|
360
|
graph.SetLineWidth(1)
|
361
|
graph.SetMarkerStyle(ROOT.kFullSquare)
|
362
|
graph.SetMarkerSize(1)
|
363
|
else:
|
364
|
graph.SetLineColor(1)
|
365
|
graph.SetLineStyle(1)
|
366
|
graph.SetLineWidth(1)
|
367
|
graph.SetMarkerStyle(ROOT.kFullCircle)
|
368
|
graph.SetMarkerSize(1)
|
369
|
|
370
|
def get_verticals(self, canvas, is_alternative = None):
|
371
|
print "get_verticals", self.current["full"]
|
372
|
if is_alternative == None:
|
373
|
is_alternative = self.current["full"].find("alternative") > -1
|
374
|
canvas.cd()
|
375
|
if is_alternative:
|
376
|
afc_centre = [-1090., +1090.]
|
377
|
absorber_centre = [0.]
|
378
|
else:
|
379
|
afc_centre = [-862.75, +862.75]
|
380
|
absorber_centre = [0.]
|
381
|
canvas.cd()
|
382
|
for z in afc_centre:
|
383
|
dummy, graph = common.make_root_graph("afc", [z]*2, "", [-1.e6, 1.e6], "")
|
384
|
graph.SetLineColor(ROOT.kRed)
|
385
|
graph.SetLineStyle(3)
|
386
|
graph.SetLineWidth(1)
|
387
|
graph.Draw('l')
|
388
|
for z in absorber_centre:
|
389
|
dummy, graph = common.make_root_graph("abs", [z]*2, "", [-1.e6, 1.e6], "")
|
390
|
graph.SetLineColor(ROOT.kRed+2)
|
391
|
graph.SetLineStyle(3)
|
392
|
graph.SetLineWidth(1)
|
393
|
graph.Draw('l')
|
394
|
canvas.Update()
|
395
|
|
396
|
def __init__(self, momentum, amplitude):
|
397
|
self.data = []
|
398
|
self.current = {}
|
399
|
self.p = momentum
|
400
|
self.m_mu = common.pdg_pid_to_mass[13]
|
401
|
self.bz_us = 4.e-3
|
402
|
self.bz_ds = -4.e-3
|
403
|
self.beta = self.p/self.bz_us*2./common.constants['c_light']
|
404
|
self.z_max = 4050.1
|
405
|
self.scraped = {'__any__':[]}
|
406
|
self.r_cut = [150., 150.]
|
407
|
self.amplitude_trans_cut = [72., 72.]
|
408
|
self.do_long_cut = True
|
409
|
self.amplitude_ct_cut = [150., 150.]
|
410
|
self.p_cut = [[50., 50.], [50., 50.]]
|
411
|
file_list = glob.glob("output/output_reference/output*_13/*.root")
|
412
|
batch = len(file_list) > 2
|
413
|
ROOT.gROOT.SetBatch(batch)
|
414
|
print file_list
|
415
|
for filename in sorted(file_list):
|
416
|
try:
|
417
|
self.single_analysis(filename)
|
418
|
except Exception:
|
419
|
sys.excepthook(*sys.exc_info())
|
420
|
if batch:
|
421
|
self.multi_analysis()
|
422
|
print "Done\n\n"
|
423
|
if not batch:
|
424
|
raw_input()
|
425
|
|
426
|
def main():
|
427
|
Tracking(200., 1.)
|
428
|
|
429
|
if __name__ == "__main__":
|
430
|
main()
|