ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimPlotHits.py
Go to the documentation of this file.
1#!/usr/bin/env python
2
3"""
4@file FPGATrackSimPlotHits.py
5@author Riley Xu - riley.xu@cern.ch
6@date April 8th, 2021
7@brief Plots the hits from a specific event
8
9FPGATrackSimPlotHits.py input_wrapper event
10"""
11
12import sys
13sys.argv.append('-b') # Batch mode
14
15import ROOT
16ROOT.gStyle.SetOptStat(00000000)
17ROOT.gROOT.ForceStyle();
18
19import numpy as np
20
21def plot(filename, event):
22 print("Plotting event " + str(event) + " from file " + filename)
23
24 f = ROOT.TFile(sys.argv[1], "READ")
25 c = ROOT.TCanvas("c1","c1",1200,900)
26 c.Divide(2,2)
27
28 t = f.Get("FPGATrackSimEventTree")
29 if event >= t.GetEntries():
30 raise IndexError("Bad entry " + str(event))
31 t.GetEntry(event)
32
33 hits = t.FPGATrackSimEventInputHeader.hits()
34 nhits = len(hits)
35 coords = np.empty((nhits, 3))
36 colors = np.empty(nhits, dtype=int)
37 styles = np.empty(nhits, dtype=int)
38 for i in range(nhits):
39 h = hits[i]
40 coords[i] = (h.getX(), h.getY(), h.getZ())
41 colors[i] = 1 + h.getLayerDisk() % 9
42 if colors[i] == 5:
43 colors[i] = 28 # yellow -> brown
44 styles[i] = ROOT.kCircle if h.getSide() else ROOT.kMultiply
45
46 rs = np.sqrt(np.power(coords[:, 0], 2) + np.power(coords[:, 1], 2))
47
48 c.cd(1)
49 g = ROOT.TGraph(nhits, coords[:, 2].astype("float"), rs)
50 g.SetTitle("r vs z")
51 g.GetXaxis().SetTitle("z (mm)")
52 g.GetYaxis().SetTitle("r (mm)")
53 g.SetMarkerColor(0)
54 g.Draw("AP")
55
56 g._markers = []
57 for i in range(nhits):
58 x = ROOT.Double()
59 y = ROOT.Double()
60 g.GetPoint(i, x, y)
61 m = ROOT.TMarker(x, y, styles[i])
62 m.SetMarkerColor(colors[i])
63 m.Draw()
64 g._markers.append(m) # otherwise python will garbage collect the marker
65
66 c.cd(2)
67 g2 = ROOT.TGraph(nhits, coords[:, 0].astype("float"), coords[:, 1].astype("float"))
68 g2.SetTitle("y vs x")
69 g2.GetXaxis().SetTitle("x (mm)")
70 g2.GetYaxis().SetTitle("y (mm)")
71 g2.SetMarkerColor(0)
72 g2.Draw("AP")
73
74 g2._markers = []
75 for i in range(nhits):
76 x = ROOT.Double()
77 y = ROOT.Double()
78 g2.GetPoint(i, x, y)
79 m = ROOT.TMarker(x, y, styles[i])
80 m.SetMarkerColor(colors[i])
81 m.Draw()
82 g2._markers.append(m) # otherwise python will garbage collect the marker
83
84
85 offline = t.FPGATrackSimEventInputHeader.optional().getOfflineClusters()
86 noff = len(offline)
87 off_coords = np.empty((noff, 3))
88 off_colors = np.empty(noff, dtype=int)
89 off_styles = np.empty(noff, dtype=int)
90 for i in range(noff):
91 h = offline[i].getClusterEquiv()
92 off_coords[i] = (h.getX(), h.getY(), h.getZ())
93 off_colors[i] = 1 + h.getLayerDisk() % 9
94 if off_colors[i] == 5:
95 off_colors[i] = 28 # yellow -> brown
96 off_styles[i] = ROOT.kCircle if h.getSide() else ROOT.kMultiply
97
98 off_rs = np.sqrt(np.power(off_coords[:, 0], 2) + np.power(off_coords[:, 1], 2))
99
100
101 c.cd(3)
102 off_g = ROOT.TGraph(noff, off_coords[:, 2].astype("float"), off_rs)
103 off_g.SetTitle("offline r vs z")
104 off_g.GetXaxis().SetTitle("z (mm)")
105 off_g.GetYaxis().SetTitle("r (mm)")
106 off_g.SetMarkerColor(0)
107 off_g.Draw("AP")
108
109 off_g._markers = []
110 for i in range(noff):
111 x = ROOT.Double()
112 y = ROOT.Double()
113 off_g.GetPoint(i, x, y)
114 m = ROOT.TMarker(x, y, off_styles[i])
115 m.SetMarkerColor(off_colors[i])
116 m.Draw()
117 off_g._markers.append(m) # otherwise python will garbage collect the marker
118
119 c.cd(4)
120 off_g2 = ROOT.TGraph(noff, off_coords[:, 0].astype("float"), off_coords[:, 1].astype("float"))
121 off_g2.SetTitle("offline y vs x")
122 off_g2.GetXaxis().SetTitle("x (mm)")
123 off_g2.GetYaxis().SetTitle("y (mm)")
124 off_g2.SetMarkerColor(0)
125 off_g2.Draw("AP")
126
127 off_g2._markers = []
128 for i in range(noff):
129 x = ROOT.Double()
130 y = ROOT.Double()
131 off_g2.GetPoint(i, x, y)
132 m = ROOT.TMarker(x, y, off_styles[i])
133 m.SetMarkerColor(off_colors[i])
134 m.Draw()
135 off_g2._markers.append(m) # otherwise python will garbage collect the marker
136
137 c.Print("Event_" + str(event) + ".png")
138
139if __name__ == "__main__":
140 plot(sys.argv[1], int(sys.argv[2]))
void print(char *figname, TCanvas *c1)