1
# Author: Christopher Tunnell <tunnell@hep.uchicago.edu>
6
from src.GenericWorker import *
7
from src.oscalls import *
13
class TimeVSMeanCalib(GenericWorker):
14
"Compute the time stability of a calibration constant"
16
def __init__(self, runType = 'CIS', parameter='calibration', example='EBC_m10_c14', syst=0.007):
17
self.runType = runType
18
self.parameter = parameter
19
self.example = example
22
self.dir = getPlotDirectory() + '/cis'
25
self.c1 = src.MakeCanvas.MakeCanvas()
27
self.factor = 60*60*24
29
def ProcessStart(self):
30
#self.glo = ROOT.TGraph()
31
#self.glo_example = ROOT.TGraph()
32
#self.ghi = ROOT.TGraph()
33
#self.ghi_example = ROOT.TGraph()
41
def ProcessStop(self):
42
#da = ROOT.TDatime(1970,01,01,12,00,00);
43
#ROOT.gStyle.SetTimeOffset(da.Convert())
44
ROOT.gStyle.SetNdivisions(304, "y")
47
for all, example, gain in [(self.lo, self.lo_example, 0), (self.hi, self.hi_example, 1)]:
48
gall = ROOT.TGraphErrors()
49
gall_axis = ROOT.TGraphErrors()
50
gall_sys = ROOT.TGraphErrors()
52
gall_sys.SetFillStyle(3004)
59
mean = ROOT.TMath.Mean(len(calibs), array('f', calibs))
60
rms = ROOT.TMath.RMS(len(calibs), array('f', calibs))
62
gall.SetPoint(i, time, mean)
63
gall_axis.SetPoint(i, time, mean)
64
gall_sys.SetPoint(i, time, mean)
65
gall.SetPointError(i, 0, rms/sqrt(len(calibs)))
66
gall_sys.SetPointError(i, 0, self.syst*mean)
70
gexample = ROOT.TGraphErrors()
71
gexample.SetMarkerStyle(23)
72
gexample.SetMarkerColor(2)
73
gexample_sys = ROOT.TGraphErrors()
74
gexample_sys.SetLineStyle(2)
75
gexample_sys.SetLineWidth(4)
76
#gexample_sys.SetFillColor(ROOT.kGray)
77
#gexample_sys.SetFillStyle(1001)
85
calibs = example[time]
86
mean = ROOT.TMath.Mean(len(calibs), array('f', calibs))
87
rms = ROOT.TMath.RMS(len(calibs), array('f', calibs))
89
gexample.SetPoint(i, time, mean)
90
gexample.SetPointError(i, 0, rms/sqrt(len(calibs)))
93
#gall_axis.Draw("ALP")
97
#print self.c1.GetUxmin(), self.c1.GetUxmax()
98
#gexample_sys.SetPoint(0, self.c1.GetUxmin(), gexample.GetMean(2))
99
#gexample_sys.SetPointError(0, 0, self.syst*gexample.GetMean(2))
100
#gexample_sys.SetPoint(1, self.c1.GetUxmax(), gexample.GetMean(2))
101
#gexample_sys.SetPointError(1, 0, self.syst*gexample.GetMean(2))
103
# gexample_sys.SetPoint(i, time, gexample.GetMean(2))
104
# gexample_sys.SetPointError(i, 0, self.syst*gexample.GetMean(2))
109
gexample_sys.Draw("A3")
114
gall_axis.GetHistogram().GetYaxis().SetTitle("Low gain Calibration (ADC counts/pC)")
116
gall_axis.GetHistogram().GetYaxis().SetTitle("High gain Calibration (ADC counts/pC)")
117
gall_axis.GetHistogram().GetXaxis().SetTitle("Time (months)")
118
gall_axis.SetMaximum(gall.GetMean(2)*1.035)
119
gall_axis.SetMinimum(gall.GetMean(2)*0.975)
120
gall_axis.GetHistogram().GetXaxis().SetLabelOffset(1.)
122
haxis = gall_axis.GetHistogram()
124
ax = gall_sys.GetHistogram().GetXaxis()
126
da = ROOT.TDatime(2008, 8,01,12,00,00).Convert()/self.factor
127
ax.SetBinLabel(ax.FindBin(da), "1 Aug" )
129
da = ROOT.TDatime(2008, 9,01,12,00,00).Convert()/self.factor
130
ax.SetBinLabel(ax.FindBin(da), "1 Sept" )
132
da = ROOT.TDatime(2008,10,01,12,00,00).Convert()/self.factor
133
ax.SetBinLabel(ax.FindBin(da), "1 Oct" )
135
da = ROOT.TDatime(2008,11,01,12,00,00).Convert()/self.factor
136
ax.SetBinLabel(ax.FindBin(da), "1 Nov" )
139
ax.SetLabelSize(0.05)
141
#ax = gall_sys.GetHistogram().GetYaxis()
143
#ax.SetBinLabel(ax.FindBin(80), "80.0" )
144
#ax.SetBinLabel(ax.FindBin(82), "82.0" )
145
#ax.SetBinLabel(ax.FindBin(84), "84.0" )
150
gall_sys.GetHistogram().GetYaxis().SetDecimals()
151
haxis.GetYaxis().SetDecimals()
152
haxis.GetXaxis().SetRangeUser(ROOT.TDatime(2008, 8,01,12,00,00).Convert()/self.factor,\
153
ROOT.TDatime(2008,11,01,12,00,00).Convert()/self.factor)
154
haxis.GetXaxis().SetNdivisions(503,0)
156
gall_sys.GetHistogram().Draw("AXISSAME")
158
##gall_sys.Draw("3") # too busy with this
159
#tpave2 = ROOT.TBox()
160
#tpave2.SetFillColor(ROOT.kGray)
161
#tpave2.SetFillStyle(1001)
162
#tpave2.SetLineColor(0)
163
#tpave2.SetBorderSize(0)
164
#print self.c1.GetUxmin(),(1-self.syst)*gexample.GetMean(2),self.c1.GetUxmax(),(1+self.syst)*gexample.GetMean(2)
165
#14091.476 81.4252918254 14184.392
166
#tpave2.DrawBox(14091.476, (1-self.syst)*gexample.GetMean(2),14184.392,(1+self.syst)*gexample.GetMean(2))
171
line.DrawLine(14091.476, (1+self.syst)*gexample.GetMean(2), 14184.392, (1+self.syst)*gexample.GetMean(2))
172
line.DrawLine(14091.476, (1-self.syst)*gexample.GetMean(2), 14184.392, (1-self.syst)*gexample.GetMean(2))
175
#gexample_sys.SetPoint(1, self.c1.GetUxmax(), gexample.GetMean(2))
176
#gexample_sys.SetPointError(1, 0, self.syst*gexample.GetMean(2))
177
#gexample_sys.Draw("3")
179
haxis.Draw("AXISSAME")
184
print 'all rms', gall.GetRMS(2)/gall.GetMean(2)
185
print 'example rms', gexample.GetRMS(2)/gexample.GetMean(2)
190
l.DrawLatex(0.1922,0.867,"ATLAS")
194
l2.DrawLatex(0.1922,0.811,"Preliminary")
196
leg = ROOT.TLegend(0.4309045,0.6765734,0.9572864,0.9213287, "", "brNDC")
197
leg.AddEntry(gall,"TileCal average","P")
198
#leg.AddEntry(gall_sys, "detector mean syst. error", "F")
199
leg.AddEntry(gexample,"Typical channel","P")
200
leg.AddEntry(gexample_sys, "\pm 0.7% channel systematic uncertainty", "L")
204
tpave.SetFillColor(0)
205
tpave.SetLineColor(0)
206
tpave.DrawPave(0.1268844,0.9562937,0.9849246,0.9965035, 0, "brNDC")
209
self.c1.Print("%s/pen_%s_%0.2f.eps" % (self.dir, self.example, gain))
210
self.c1.Print("%s/pen_%s_%0.2f.png" % (self.dir, self.example, gain))
211
self.c1.Print("%s/pen_%s_%0.2f.root" % (self.dir,self.example, gain))
214
def ProcessRegion(self, region):
215
if 'gain' not in region.GetHash():
222
calib = 0 # calibation constant
223
for event in region.GetEvents():
224
if event.runType == self.runType:
226
#print event.time, int(event.getTimeSeconds())
227
if event.data.has_key('goodRegion') and event.data['goodRegion'] and\
228
event.data.has_key('goodEvent') and event.data['goodEvent']:
230
# unix/runserver clock starts from 1970, ROOT clock starts from 1995
231
# so then 788923149 is 25 years in seconds
232
#print event.getTimeSeconds(), event.getTimeSeconds() - 788923149
233
time = int(event.getTimeSeconds())/self.factor
235
if self.example in region.GetHash():
236
if 'lowgain' in region.GetHash():
237
self.lo_example[time] = [event.data['calibration']]
239
self.hi_example[time] = [event.data['calibration']]
241
if 'lowgain' in region.GetHash():
242
if not self.lo.has_key(time):
244
self.lo[time].append(event.data['calibration'])
246
if not self.hi.has_key(time):
248
self.hi[time].append(event.data['calibration'])