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