1 | #!/usr/bin/python -itt
|
---|
2 |
|
---|
3 | ##############################################
|
---|
4 | # by Q. Weitzel and T. Kraehenbuehl
|
---|
5 | #
|
---|
6 | # plot rates and DTs for all runs of one night
|
---|
7 | # in addition, plot DT outliers
|
---|
8 | #
|
---|
9 | # adapt base_path to select the night
|
---|
10 | # (and change title and zoom of the graph)
|
---|
11 | ##############################################
|
---|
12 |
|
---|
13 | from array import array
|
---|
14 | import os
|
---|
15 | import re
|
---|
16 | import numpy as np
|
---|
17 | import sys
|
---|
18 |
|
---|
19 | from pyfact import SlowData
|
---|
20 | from plotters import CamPlotter
|
---|
21 |
|
---|
22 | from ROOT import TCanvas, TPad, TGraph
|
---|
23 | from ROOT import gROOT
|
---|
24 | from ROOT import gStyle
|
---|
25 |
|
---|
26 | gROOT.SetStyle("Plain")
|
---|
27 |
|
---|
28 | base_path = sys.argv[1]
|
---|
29 |
|
---|
30 | filelist = []
|
---|
31 |
|
---|
32 | for base,subdirs,files in os.walk(base_path):
|
---|
33 | for filename in files:
|
---|
34 | #include only run files
|
---|
35 | regex = re.search(r'\d\d\d\d\d\d\d\d\.FTM_CONTROL_TRIGGER_RATES',filename)
|
---|
36 | #include run files and also the nightly file
|
---|
37 | #regex = re.search(r'FTM_CONTROL_TRIGGER_RATES',filename)
|
---|
38 | if regex:
|
---|
39 | filelist.append(os.path.join(base,filename))
|
---|
40 |
|
---|
41 | filelist2 = []
|
---|
42 |
|
---|
43 | for base,subdirs,files in os.walk(base_path):
|
---|
44 | for filename in files:
|
---|
45 | regex = re.search(r'\d\d\d\d\d\d\d\d\.FTM_CONTROL_STATIC_DATA',filename)
|
---|
46 | if regex:
|
---|
47 | filelist2.append(os.path.join(base,filename))
|
---|
48 |
|
---|
49 | trigger_rate_array = array("d",[])
|
---|
50 | time_array = array("d",[])
|
---|
51 |
|
---|
52 | for filename in filelist:
|
---|
53 |
|
---|
54 | print filename
|
---|
55 |
|
---|
56 | file_handle = SlowData(filename)
|
---|
57 |
|
---|
58 | file_handle.register("TriggerRate")
|
---|
59 | file_handle.register("Time")
|
---|
60 | file_handle.register("FTMtimeStamp")
|
---|
61 |
|
---|
62 | ftm_ts_old = 1E10
|
---|
63 |
|
---|
64 | for row in file_handle:
|
---|
65 | if row.FTMtimeStamp>ftm_ts_old:#needed to remove negative rate in first report
|
---|
66 | trigger_rate_array.append(float(row.TriggerRate))
|
---|
67 | time_array.append(float(row.Time)*24*3600)
|
---|
68 | ftm_ts_old = row.FTMtimeStamp
|
---|
69 |
|
---|
70 | dt_min_array = array("d", [])
|
---|
71 | dt_max_array = array("d", [])
|
---|
72 | dt_avg_array = array("d", [])
|
---|
73 | time_array2 = array("d", [])
|
---|
74 |
|
---|
75 | #trick to get the same x-axis range for all graphs
|
---|
76 | time_array2.append(min(time_array))
|
---|
77 | dt_min_array.append(float(-1))
|
---|
78 | dt_max_array.append(float(-1))
|
---|
79 | dt_avg_array.append(float(-1))
|
---|
80 |
|
---|
81 | mycamplotter = CamPlotter('Outlier Search Plot', map_file_path = '../map_dn.txt', vmin=0, vmax=10)
|
---|
82 | pixel_outlier_array = np.zeros(1440)
|
---|
83 | patch_outlier_array = np.zeros(160)
|
---|
84 |
|
---|
85 | for filename in filelist2:
|
---|
86 |
|
---|
87 | print filename
|
---|
88 |
|
---|
89 | file_handle = SlowData(filename)
|
---|
90 |
|
---|
91 | file_handle.register("PatchThresh")
|
---|
92 | file_handle.register("Time")
|
---|
93 | file_handle.register("FTMtimeStamp")
|
---|
94 |
|
---|
95 | ftm_ts_old = 1E10
|
---|
96 |
|
---|
97 | tmp_outliers = np.zeros(160)
|
---|
98 |
|
---|
99 | for row in file_handle:
|
---|
100 | if row.FTMtimeStamp>ftm_ts_old:#just do the same cut as for the rates
|
---|
101 | time_array2.append(float(row.Time)*24*3600)
|
---|
102 | dt_min_array.append(float(min(row.PatchThresh)))
|
---|
103 | dt_max_array.append(float(max(row.PatchThresh)))
|
---|
104 | dt_avg_array.append(float(sum(row.PatchThresh))/len(row.PatchThresh))
|
---|
105 | tmp_outliers = row.PatchThresh > dt_avg_array[-1] + 15
|
---|
106 | ftm_ts_old = row.FTMtimeStamp
|
---|
107 |
|
---|
108 | patch_outlier_array += tmp_outliers
|
---|
109 |
|
---|
110 | for i,value in enumerate(patch_outlier_array):
|
---|
111 | for j in range(9):
|
---|
112 | pixel_outlier_array[i*9 + j] = value
|
---|
113 |
|
---|
114 | #trick to get the same x-axis range for all graphs
|
---|
115 | time_array2.append(max(time_array))
|
---|
116 | dt_min_array.append(float(-1))
|
---|
117 | dt_max_array.append(float(-1))
|
---|
118 | dt_avg_array.append(float(-1))
|
---|
119 |
|
---|
120 | canv = TCanvas("canv","canv",600,50,1000,600)
|
---|
121 | pad1 = TPad("pad1","",0,0,1,1)
|
---|
122 | pad2 = TPad("pad2","",0,0,1,1)
|
---|
123 | pad3 = TPad("pad3","",0,0,1,1)
|
---|
124 | pad4 = TPad("pad4","",0,0,1,1)
|
---|
125 | pad2.SetFillStyle(4000);#will be transparent
|
---|
126 | pad2.SetFrameFillStyle(0);
|
---|
127 | pad3.SetFillStyle(4000);#will be transparent
|
---|
128 | pad3.SetFrameFillStyle(0);
|
---|
129 | pad4.SetFillStyle(4000);#will be transparent
|
---|
130 | pad4.SetFrameFillStyle(0);
|
---|
131 |
|
---|
132 | graph = TGraph(len(trigger_rate_array),time_array,trigger_rate_array)
|
---|
133 | graph2 = TGraph(len(dt_min_array),time_array2,dt_min_array)
|
---|
134 | graph3 = TGraph(len(dt_max_array),time_array2,dt_max_array)
|
---|
135 | graph4 = TGraph(len(dt_avg_array),time_array2,dt_avg_array)
|
---|
136 |
|
---|
137 | #change the time format to human readable
|
---|
138 | graph.GetXaxis().SetTimeDisplay(1);
|
---|
139 | graph2.GetXaxis().SetTimeDisplay(1);
|
---|
140 | graph3.GetXaxis().SetTimeDisplay(1);
|
---|
141 | graph4.GetXaxis().SetTimeDisplay(1);
|
---|
142 | graph.GetXaxis().SetTimeFormat("%H:%M%F1970-01-01 00:00:00")
|
---|
143 | graph2.GetXaxis().SetTimeFormat("%H:%M%F1970-01-01 00:00:00")
|
---|
144 | graph3.GetXaxis().SetTimeFormat("%H:%M%F1970-01-01 00:00:00")
|
---|
145 | graph4.GetXaxis().SetTimeFormat("%H:%M%F1970-01-01 00:00:00")
|
---|
146 |
|
---|
147 | #define markers, titles, etc.
|
---|
148 | graph.SetMarkerStyle(7)
|
---|
149 | graph2.SetMarkerStyle(7)
|
---|
150 | graph3.SetMarkerStyle(7)
|
---|
151 | graph4.SetMarkerStyle(7)
|
---|
152 | graph.SetMarkerSize(1)
|
---|
153 | graph2.SetMarkerSize(1)
|
---|
154 | graph3.SetMarkerSize(1)
|
---|
155 | graph4.SetMarkerSize(1)
|
---|
156 | graph.SetMarkerColor(2)
|
---|
157 | graph2.SetMarkerColor(3)
|
---|
158 | graph3.SetMarkerColor(6)
|
---|
159 | graph4.SetMarkerColor(4)
|
---|
160 | graph.SetTitle("Night " + base_path)
|
---|
161 | graph2.SetTitle("")
|
---|
162 | graph3.SetTitle("")
|
---|
163 | graph4.SetTitle("")
|
---|
164 | graph.GetYaxis().SetRangeUser(0,250)#zoom to be adapted for each night
|
---|
165 | graph2.GetYaxis().SetRangeUser(150,495)#zoom to be adapted for each night
|
---|
166 | graph3.GetYaxis().SetRangeUser(150,495)#zoom to be adapted for each night
|
---|
167 | graph4.GetYaxis().SetRangeUser(150,495)#zoom to be adapted for each night
|
---|
168 | graph.GetXaxis().SetTitleOffset(1.2)
|
---|
169 | graph2.GetXaxis().SetTitleOffset(1.2)
|
---|
170 | graph3.GetXaxis().SetTitleOffset(1.2)
|
---|
171 | graph4.GetXaxis().SetTitleOffset(1.2)
|
---|
172 | graph.GetXaxis().SetTitle("UTC+4h (hh:mm)")#for summer time
|
---|
173 | graph2.GetXaxis().SetTitle("")#for summer time
|
---|
174 | graph3.GetXaxis().SetTitle("")#for summer time
|
---|
175 | graph4.GetXaxis().SetTitle("")#for summer time
|
---|
176 | graph.GetYaxis().SetTitle("Trigger Rate (Hz)")
|
---|
177 | graph2.GetYaxis().SetTitle("Patch Threshold (DAC Counts)")
|
---|
178 | graph3.GetYaxis().SetTitle("")
|
---|
179 | graph4.GetYaxis().SetTitle("")
|
---|
180 |
|
---|
181 | pad1.Draw();
|
---|
182 | pad1.cd();
|
---|
183 | graph.Draw("ap");
|
---|
184 |
|
---|
185 | pad2.Draw();
|
---|
186 | pad2.cd();
|
---|
187 | graph2.Draw("apY+");
|
---|
188 |
|
---|
189 | pad3.Draw();
|
---|
190 | pad3.cd();
|
---|
191 | graph3.Draw("apY+");
|
---|
192 |
|
---|
193 | pad4.Draw();
|
---|
194 | pad4.cd();
|
---|
195 | graph4.Draw("apY+");
|
---|
196 |
|
---|
197 | mycamplotter(pixel_outlier_array)
|
---|