source: fact/tools/pyscripts/sandbox/weitzel/plot_trigger_rate_and_dts.py@ 17633

Last change on this file since 17633 was 13817, checked in by weitzel, 13 years ago
new python script added to sandbox
  • Property svn:executable set to *
File size: 5.7 KB
Line 
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
13from array import array
14import os
15import re
16import numpy as np
17
18from pyfact import SlowData
19from plotters import CamPlotter
20
21from ROOT import TCanvas, TPad, TGraph
22from ROOT import gROOT
23from ROOT import gStyle
24
25gROOT.SetStyle("Plain")
26
27base_path = "/fact/aux/2012/05/20/"
28
29filelist = []
30
31for 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
40filelist2 = []
41
42for 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
48trigger_rate_array = array("d",[])
49time_array = array("d",[])
50
51for 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
69dt_min_array = array("d", [])
70dt_max_array = array("d", [])
71dt_avg_array = array("d", [])
72time_array2 = array("d", [])
73
74#trick to get the same x-axis range for all graphs
75time_array2.append(min(time_array))
76dt_min_array.append(float(-1))
77dt_max_array.append(float(-1))
78dt_avg_array.append(float(-1))
79
80mycamplotter = CamPlotter('Outlier Search Plot', map_file_path = '../map_dn.txt', vmin=0, vmax=10)
81pixel_outlier_array = np.zeros(1440)
82patch_outlier_array = np.zeros(160)
83
84for 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
109for 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
114time_array2.append(max(time_array))
115dt_min_array.append(float(-1))
116dt_max_array.append(float(-1))
117dt_avg_array.append(float(-1))
118
119canv = TCanvas("canv","canv",600,50,1000,600)
120pad1 = TPad("pad1","",0,0,1,1)
121pad2 = TPad("pad2","",0,0,1,1)
122pad3 = TPad("pad3","",0,0,1,1)
123pad4 = TPad("pad4","",0,0,1,1)
124pad2.SetFillStyle(4000);#will be transparent
125pad2.SetFrameFillStyle(0);
126pad3.SetFillStyle(4000);#will be transparent
127pad3.SetFrameFillStyle(0);
128pad4.SetFillStyle(4000);#will be transparent
129pad4.SetFrameFillStyle(0);
130
131graph = TGraph(len(trigger_rate_array),time_array,trigger_rate_array)
132graph2 = TGraph(len(dt_min_array),time_array2,dt_min_array)
133graph3 = TGraph(len(dt_max_array),time_array2,dt_max_array)
134graph4 = TGraph(len(dt_avg_array),time_array2,dt_avg_array)
135
136#change the time format to human readable
137graph.GetXaxis().SetTimeDisplay(1);
138graph2.GetXaxis().SetTimeDisplay(1);
139graph3.GetXaxis().SetTimeDisplay(1);
140graph4.GetXaxis().SetTimeDisplay(1);
141graph.GetXaxis().SetTimeFormat("%H:%M%F1970-01-01 00:00:00")
142graph2.GetXaxis().SetTimeFormat("%H:%M%F1970-01-01 00:00:00")
143graph3.GetXaxis().SetTimeFormat("%H:%M%F1970-01-01 00:00:00")
144graph4.GetXaxis().SetTimeFormat("%H:%M%F1970-01-01 00:00:00")
145
146#define markers, titles, etc.
147graph.SetMarkerStyle(7)
148graph2.SetMarkerStyle(7)
149graph3.SetMarkerStyle(7)
150graph4.SetMarkerStyle(7)
151graph.SetMarkerSize(1)
152graph2.SetMarkerSize(1)
153graph3.SetMarkerSize(1)
154graph4.SetMarkerSize(1)
155graph.SetMarkerColor(2)
156graph2.SetMarkerColor(3)
157graph3.SetMarkerColor(6)
158graph4.SetMarkerColor(4)
159graph.SetTitle("Night 20.05.2012")
160graph2.SetTitle("")
161graph3.SetTitle("")
162graph4.SetTitle("")
163graph.GetYaxis().SetRangeUser(0,250)#zoom to be adapted for each night
164graph2.GetYaxis().SetRangeUser(150,495)#zoom to be adapted for each night
165graph3.GetYaxis().SetRangeUser(150,495)#zoom to be adapted for each night
166graph4.GetYaxis().SetRangeUser(150,495)#zoom to be adapted for each night
167graph.GetXaxis().SetTitleOffset(1.2)
168graph2.GetXaxis().SetTitleOffset(1.2)
169graph3.GetXaxis().SetTitleOffset(1.2)
170graph4.GetXaxis().SetTitleOffset(1.2)
171graph.GetXaxis().SetTitle("UTC+4h (hh:mm)")#for summer time
172graph2.GetXaxis().SetTitle("")#for summer time
173graph3.GetXaxis().SetTitle("")#for summer time
174graph4.GetXaxis().SetTitle("")#for summer time
175graph.GetYaxis().SetTitle("Trigger Rate (Hz)")
176graph2.GetYaxis().SetTitle("Patch Threshold (DAC Counts)")
177graph3.GetYaxis().SetTitle("")
178graph4.GetYaxis().SetTitle("")
179
180pad1.Draw();
181pad1.cd();
182graph.Draw("ap");
183
184pad2.Draw();
185pad2.cd();
186graph2.Draw("apY+");
187
188pad3.Draw();
189pad3.cd();
190graph3.Draw("apY+");
191
192pad4.Draw();
193pad4.cd();
194graph4.Draw("apY+");
195
196mycamplotter(pixel_outlier_array)
Note: See TracBrowser for help on using the repository browser.