1
# Author: Christopher Tunnell <tunnell@hep.uchicago.edu>
6
from src.ReadGenericCalibration import *
7
from src.region import *
8
from array import array
9
from src.MakeCanvas import *
11
class GetSamples(ReadGenericCalibration):
12
"Get the samples for a scan and the distribution of fit energy for fixed-charges"
14
def __init__(self, processingDir='rfio:/castor/cern.ch/grid/atlas/atlasgroupdisk/det-tile/2009/',\
15
getSamples=True, getInjDist=True, all=False):
16
self.processingDir = processingDir
17
self.getSamples = getSamples
18
self.getInjDist = getInjDist
20
self.ftDict = {} # Used for linear constant. Each element is a [TTree, TFile]
22
self.dir = getPlotDirectory() + '/cis/samples'
24
self.c1 = MakeCanvas()
25
self.c1.SetHighLightColor(2)
28
def ProcessStart(self):
31
def ProcessStop(self):
34
def ProcessRegion(self, region):
36
if 'gain' not in region.GetHash():
39
dirstr = '%s%02d' % (region.GetHash().split('_')[1], int(region.GetHash().split('_')[2][1:]))
42
foundEventToProcess = False
43
for event in region.GetEvents():
44
if event.runType == 'CIS':
45
if not event.data.has_key('moreInfo') and not self.all:
48
if not self.all and not event.data['moreInfo']:
51
foundEventToProcess = True
53
if event.runNumber and\
54
not self.ftDict.has_key(event.runNumber):
55
#print '%s%s/tiletb_%s_CIS.%s.0.aan.root' % (self.processingDir, dirstr, event.runNumber, dirstr)
56
f, t = self.getFileTree('%s/tiletb_%s_CIS.%s.0.aan.root' % (dirstr, event.runNumber, dirstr), 'h1000')
58
if [f, t] == [None, None]:
59
if event.runNumber not in self.badRuns:
60
print "Error: GetSamples couldn't load run", event.runNumber, ' for %s...' % dirstr
61
self.badRuns.add(event.runNumber)
64
self.ftDict[event.runNumber] = [f, t]
67
if not foundEventToProcess:
70
map = {'LBA': 'A', 'LBC': 'C', 'EBA': 'D', 'EBC': 'E'}
71
if 'lowgain' in region.GetHash():
75
module = int(region.GetHash().split('_')[2][1:])
76
chan = int(region.GetHash(1).split('_')[3][1:]) - 1
77
partition = region.GetHash().split('_')[1]
80
for event in region.GetEvents():
81
hists = [[[] for i in range(16)] for j in range(15)]
86
if event.runType == 'CIS':
88
(event.data.has_key('moreInfo') and not event.data['moreInfo']):
90
# Load up the tree, file and scans for this run
91
if not self.ftDict.has_key(event.runNumber):
93
[f, t] = self.ftDict[event.runNumber]
97
for i in range(t.GetEntries()):
98
if t.GetEntry(i) <= 0:
102
if t.m_cispar[7] != 100:
105
phase = t.m_cispar[5]
108
charge = 2.0*4.096*100.0/1023.0 * dac # From TileCisDefaultCalibTool.cxx
110
if gain == 'lo' and not 300 < charge < 700:
112
elif gain == 'hi' and not 3 < charge < 10:
115
if not hasattr(t, 'efit%s%02d%s' % (map[partition], module, gain)) or\
116
not hasattr(t, 'tfit%s%02d%s' % (map[partition], module, gain)) or\
117
not hasattr(t, 'pedfit%s%02d%s' % (map[partition], module, gain)) or\
118
not hasattr(t, 'sample%s%02d%s' % (map[partition], module, gain)):
121
e_of_fit = getattr(t, 'efit%s%02d%s' % (map[partition], module, gain))
122
t_of_fit = getattr(t, 'tfit%s%02d%s' % (map[partition], module, gain))
123
p_of_fit = getattr(t, 'pedfit%s%02d%s' % (map[partition], module, gain))
124
samples = getattr(t, 'sample%s%02d%s' % (map[partition], module, gain))
136
if nphase > maxphase:
139
h = ROOT.TH1F('h_%f_%f_%f_%d' % (charge, phase, e_of_fit[chan], self.h_index), '', 7, 0, 7)
144
h.Fill(j, samples[chan*9 + j])
151
h.GetXaxis().SetTitle("Sample Number")
152
h.GetYaxis().SetTitle("ADC counts")
153
h.GetXaxis().SetTitleOffset(0.93)
154
h.GetXaxis().SetTitleSize(0.05)
155
h.GetYaxis().SetTitleSize(0.05)
156
h.GetYaxis().SetTitleOffset(0.99)
160
#h.SetFillStyle(3002)
164
tl1 = ROOT.TLatex(0.10, 0.92, "Fit Energy: %f" % e_of_fit[chan])
165
tl2 = ROOT.TLatex(0.53, 0.92, "Fit Time: %f" % t_of_fit[chan])
166
tl3 = ROOT.TLatex(0.40, 0.84, "Fit Pedestal: %f" % p_of_fit[chan])
168
for tl in [tl1, tl2, tl3]:
173
#self.c1.Print("%s/sample_%s_%f_%f_%f.ps" % (self.dir, region.GetHash(), charge, phase, e_of_fit[chan]))
174
#self.c1.Print("%s/sample_%s_%f_%f_%f.root" % (self.dir, region.GetHash(), charge, phase, e_of_fit[chan]))
175
#print samples[chan*9 + j],
178
#print nphase, ndac, gain, dac
179
# print hists[nphase]
180
# print hists[nphase][ndac]
181
hists[nphase][ndac].append(h)
183
if not injections.has_key(charge):
184
injections[charge] = []
185
injections[charge].append(e_of_fit[chan])
187
event.data['samples'] = hists
190
for z, w in injections.iteritems(): # z charge, w arrany
191
dx = max([(max(w) - min(w))*0.1, 2.5])
193
h = ROOT.TH1F('%s_%f_%d' % (region.GetHash(), z, event.runNumber), '', 10, min(w)-dx, max(w)+dx)
199
event.data['injections'] = inj_hists
200
event.data['maxphase'] = maxphase
201
event.data['maxdac'] = maxdac
205
region.SetEvents(newevents)
208
# arrow1 = ROOT.TArrow(0.03,0.3,0.03,0.60,0.02,"|>")
209
# arrow1.SetAngle(90)
210
# arrow2 = ROOT.TArrow(0.4,0.03,0.55,0.03,0.02,"|>")
212
# for arrow in [arrow1, arrow2]:
213
# arrow.SetLineWidth(1)