source: fact/tools/pyscripts/sandbox/dneise/RateControl/plot_trigger_rate_and_dts.py@ 17689

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