1
|
#!/usr/env python
|
2
|
|
3
|
import os
|
4
|
import subprocess
|
5
|
|
6
|
import ROOT
|
7
|
|
8
|
import xboa.Bunch
|
9
|
from xboa.Bunch import Bunch
|
10
|
import xboa.Common as Common
|
11
|
|
12
|
IDEAL_FIELD = None
|
13
|
|
14
|
def run_sim():
|
15
|
erit_root_dir = os.getenv('ERIT_ROOT')
|
16
|
sim_path = os.path.join(erit_root_dir, 'maus', 'simulate_erit.py')
|
17
|
conf_path = os.path.join(erit_root_dir, 'maus', 'tests', 'test_field', 'field_configuration.py')
|
18
|
print sim_path
|
19
|
print conf_path
|
20
|
subproc = subprocess.Popen(['python', sim_path, '-configuration_file', \
|
21
|
conf_path])
|
22
|
subproc.wait()
|
23
|
|
24
|
def plot_output():
|
25
|
global IDEAL_FIELD
|
26
|
primary_bunch = Bunch.new_from_read_builtin('maus_primary', 'simulation.out')
|
27
|
primary_bunch.root_scatter_graph('x', 'z', 'm', 'm')
|
28
|
|
29
|
virtual_hits = Bunch.new_from_read_builtin('maus_virtual_hit', 'simulation.out')
|
30
|
virtual_hits.root_scatter_graph('x', 'z', 'm', 'm')
|
31
|
|
32
|
virtual_hits_by_station = Bunch.new_list_from_read_builtin('maus_virtual_hit', 'simulation.out')
|
33
|
for bunch in virtual_hits_by_station:
|
34
|
if abs(bunch.mean(['z'])['z']) < 1e-9:
|
35
|
(canvas, hist, graph) = bunch.root_scatter_graph('x', 'by', 'm', 'T', ymin=0.5, ymax=1.0)
|
36
|
graph.Draw('l')
|
37
|
IDEAL_FIELD = ROOT.TF1("ideal_field","0.727*(2.350/x)**1.92",2.000,2.700)
|
38
|
IDEAL_FIELD.Draw('lsame')
|
39
|
canvas.Update()
|
40
|
for hit in bunch:
|
41
|
print hit['x'], hit['z'], hit['by']
|
42
|
|
43
|
#three_d_plot(virtual_hits, 'x', 'z', 'by', 'm', 'm', 'T')
|
44
|
|
45
|
def three_d_plot(bunch, x_axis, y_axis, z_axis, x_units='', y_units='', z_units=''):
|
46
|
canvas_name = x_axis+'-'+y_axis+'-'+z_axis
|
47
|
canvas = Common.make_root_canvas(canvas_name)
|
48
|
x_list, y_list, z_list = [], [], []
|
49
|
for hit in bunch:
|
50
|
x_list.append(hit[x_axis]/Common.units[x_units])
|
51
|
y_list.append(hit[y_axis]/Common.units[y_units])
|
52
|
z_list.append(hit[z_axis]/Common.units[z_units])
|
53
|
print x_list[-1], y_list[-1], z_list[-1]
|
54
|
(hist, graph_3D, graph_2D) = Common.make_root_graph_2d(canvas_name, x_list, x_axis+' ['+x_units+']', y_list, y_axis+' ['+y_units+']', z_list, z_axis+' ['+z_units+']')
|
55
|
canvas.cd()
|
56
|
hist.Draw()
|
57
|
graph_3D.Draw('CONTZ')
|
58
|
graph_2D.Draw('')
|
59
|
canvas.Update()
|
60
|
print 'done'
|
61
|
|
62
|
def main():
|
63
|
run_sim()
|
64
|
plot_output()
|
65
|
raw_input()
|
66
|
|
67
|
if __name__ == "__main__":
|
68
|
main()
|
69
|
|
70
|
|