7
An example of extracting information from the special virtual planes
10
# pylint: disable = E1101, C0103, C0301, W0611, R0914, R0915
18
def generate_simulation(outfile):
20
Run the simulation to make a data file for consideration
22
analysis = os.path.join\
23
(os.environ["MAUS_ROOT_DIR"],"bin","simulate_mice.py")
24
proc = subprocess.Popen(['python', analysis, \
25
'--output_root_file_name', outfile,
26
'--simulation_geometry_file', 'Stage4.dat'])
31
""" extract information from the special virtual planes
32
from the maus_output.root file in the current directory """
36
h = ROOT.TH1D("hrate", \
37
";Position along Z axis (m);Particles at Virtual Plane", \
39
hf = ROOT.TH2D("hfield", \
40
";Position along Z axis (m); Field Magnitude", \
42
hp = ROOT.TH2D("hp", \
43
";Position along Z axis (m); Momentum (MeV/c)", \
45
hp200 = ROOT.TH2D("hp200", \
46
";Position along Z axis (m); Momentum (MeV/c)", \
48
hr = ROOT.TH2D("hr", \
49
";Position along Z axis (m); Radial Position (m)", \
50
240,0,24,100,0.0, 0.5)
51
hbt = ROOT.TH2D("hbt", \
52
";Position along Z axis (m); Transverse #beta", \
58
rfile = ROOT.TFile(str(fp),"R")
61
data = ROOT.MAUS.Data()
62
tree = rfile.Get("Spill")
65
tree.SetBranchAddress("data", data)
66
print "Evaluating "+str(fp)
67
for i in range(tree.GetEntries()):
69
spill = data.GetSpill()
71
if spill.GetDaqEventType() == "physics_event":
72
for j in range(spill.GetMCEvents().size()):
73
# if this is not the largest set of virtual hit go to the
75
if spill.GetMCEvents()[j].GetPrimary().GetParticleId() != -13:
77
nvirthits = spill.GetMCEvents()[j].GetVirtualHits().size()
78
for k in range(nvirthits):
79
h.Fill(spill.GetMCEvents()[j] \
80
.GetVirtualHits()[k].GetPosition().z() / 1000)
81
r = math.sqrt((spill.GetMCEvents()[j] \
82
.GetVirtualHits()[k].GetPosition().x())**2 +
83
(spill.GetMCEvents()[j] \
84
.GetVirtualHits()[k].GetPosition().y())**2 )
87
spill.GetMCEvents()[j] \
88
.GetVirtualHits()[k].GetPosition().z() / 1000,
89
spill.GetMCEvents()[j] \
90
.GetVirtualHits()[k].GetBField().z() * 1000)
92
spill.GetMCEvents()[j] \
93
.GetVirtualHits()[k].GetPosition().z() / 1000,
94
spill.GetMCEvents()[j] \
95
.GetVirtualHits()[k].GetMomentum().mag())
96
hp.Fill(spill.GetMCEvents()[j] \
97
.GetVirtualHits()[k].GetPosition().z() / 1000,
98
spill.GetMCEvents()[j] \
99
.GetVirtualHits()[k].GetMomentum().mag())
100
hr.Fill(spill.GetMCEvents()[j]\
101
.GetVirtualHits()[k].GetPosition().z() / 1000,
102
math.sqrt((spill.GetMCEvents()[j] \
103
.GetVirtualHits()[k].GetPosition().x())**2 +
104
(spill.GetMCEvents()[j] \
105
.GetVirtualHits()[k].GetPosition().y())**2 )/ 1000.)
106
hbt.Fill(spill.GetMCEvents()[j] \
107
.GetVirtualHits()[k].GetPosition().z() / 1000,
108
math.sqrt((spill.GetMCEvents()[j] \
109
.GetVirtualHits()[k].GetMomentum().x())**2 +
110
(spill.GetMCEvents()[j] \
111
.GetVirtualHits()[k].GetMomentum().y())**2 )/
112
math.sqrt((spill.GetMCEvents()[j] \
113
.GetVirtualHits()[k].GetMomentum().mag())**2 \
115
if maxsize < nvirthits:
116
maxsize = spill.GetMCEvents()[j].GetVirtualHits().size()
118
# reinitialize the Bfiled and zpos objects
121
for k in range(maxsize):
122
Bfield.append(spill.GetMCEvents()[j] \
123
.GetVirtualHits()[k].GetBField().z() * 1000)
124
zpos.append(spill.GetMCEvents()[j] \
125
.GetVirtualHits()[k].GetPosition().z() / 1000)
127
g = ROOT.TGraph(maxsize)
128
for i in range(maxsize):
129
g.SetPoint(i, zpos[i], Bfield[i])
132
g.SetTitle("; Position on Z axis (m); Field Magnitude (Tesla)")
136
c.Print("Bfield_v_z.eps")
140
c1.Print("Bfield_v_z_hist.eps")
146
c3.Print("Momentum_v_z_hist.eps")
148
c3_1 = ROOT.TCanvas()
149
hp_px = hp.ProjectionX()
151
c3_1.Print("Momentum_v_z_projx.eps")
153
c3_2 = ROOT.TCanvas()
154
hp_pfx = hp.ProfileX()
156
c3_2.Print("Momentum_v_z_prflx.eps")
158
c3_3 = ROOT.TCanvas()
161
c3_3.Print("Momentum_v_z_hist_lt200mm.eps")
163
c3_4 = ROOT.TCanvas()
164
hp200_px = hp200.ProjectionX()
166
c3_4.Print("Momentum_v_z_projx_lt200mm.eps")
168
c3_5 = ROOT.TCanvas()
169
hp200_pfx = hp200.ProfileX()
171
c3_5.Print("Momentum_v_z_prflx_lt200mm.eps")
177
c4.Print("BeamRadius_v_z_hist.eps")
182
c5.Print("TransverseBeta_v_z_hist.eps")
188
c6.Print("MuonRate_v_z_hist.eps")
191
if __name__ == "__main__":
192
if len(sys.argv) > 1:
195
ofile = os.path.join\
196
(os.environ['MAUS_ROOT_DIR'],
197
'tmp','example_simulation_file.root')
198
generate_simulation(ofile)