1
# Author: Christopher Tunnell <tunnell@hep.uchicago.edu>
6
from src.ReadGenericCalibration import *
7
from src.region import *
10
class ReadCIS(ReadGenericCalibration):
11
"Read in CIS calibration factors and quality flags from CIS calibration ntuples"
13
def __init__(self, processingDir='/afs/cern.ch/user/t/tilecali/w0/ntuples/cis', turnOffStatCuts=False):
14
self.processingDir = processingDir
15
self.ftDict = {} # Used for linear constant. Each element is a [TTree, TFile]
17
self.turnOffStatCuts = turnOffStatCuts
19
def get_index(self, ros, mod, chan, gain):
25
def ProcessStart(self):
28
def ProcessStop(self):
31
def ProcessRegion(self, region):
34
if 'gain' not in region.GetHash():
35
for event in region.GetEvents():
36
if event.runType != 'staging':
38
region.SetEvents(newevents)
42
foundEventToProcess = False
43
for event in region.GetEvents():
44
if event.runType == 'staging':
45
foundEventToProcess = True
47
if event.runNumber and\
48
not self.ftDict.has_key(event.runNumber):
49
f, t = self.getFileTree('tileCalibCIS_%s_CIS.0.root' % event.runNumber, 'h3000')
51
if [f, t] == [None, None]:
52
f, t = self.getFileTree('tileCalibCIS_%s_0.root' % event.runNumber, 'h3000')
54
if [f, t] == [None, None]:
55
f, t = self.getFileTree('tileCalibTool_%s_CIS.0.root' % event.runNumber, 'h3000')
57
if [f, t] == [None, None]:
58
if event.runNumber not in self.badRuns:
59
print "Error: ReadCISFile couldn't load run", event.runNumber, "..."
60
self.badRuns.add(event.runNumber)
62
if hasattr(t, 'nDigitalErrors'):
63
self.ftDict[event.runNumber] = [f, t]
64
#elif event.runNumber not in self.badRuns:
65
# print '\tRun %s has old format' % event.runNumber
66
# self.badRuns.add(event.runNumber)
68
if not foundEventToProcess:
71
for event in region.GetEvents():
72
if event.runType != 'staging':
75
# Load up the tree, file
76
if not self.ftDict.has_key(event.runNumber):
78
[f, t] = self.ftDict[event.runNumber]
81
# Get the index of this region within the file
82
[x, y, z, w] = region.GetNumber()
83
index = self.get_index(x, y - 1, z, w)
85
# See if there were even injections
86
if int(t.qflag[index]) & 3 != 3:
89
# Start filling the data for this event
92
data['calibration'] = t.calib[index]
94
data['quality_flag'] = int(t.qflag[index]) #tk remove me temoporary backward compatibility!
96
# if event.runNumber < 100489 and\
97
# int(t.qflag[index]) & 7 == 7:
98
# data['isBad'] = False
99
# elif event.runNumber >= 100489 and\
100
# int(t.qflag[index]) & 27 == 27:
101
# data['isBad'] = False
103
# data['isBad'] = True
105
data['nDigitalErrors'] = int(t.nDigitalErrors[index])
107
# Define problems for the channel
110
data['chi2'] = t.chi2[index]
112
# Check for digital errors
113
if int(t.qflag[index]) & 64 != 64:
114
assert(data['nDigitalErrors'] != 0)
115
problems['Digital Errors'] = True
117
problems['Digital Errors'] = False
119
# Maximum point in fit range
120
if int(t.qflag[index]) & 16 != 16:
121
problems['Fail Max. Point'] = True
123
problems['Fail Max. Point'] = False
125
# Maximum point in fit range
126
if int(t.qflag[index]) & 8 != 8:
127
problems['Fail Likely Calib.'] = True
129
problems['Fail Likely Calib.'] = False
131
if not self.turnOffStatCuts:
133
if int(t.qflag[index]) & 32 != 32:
134
problems['Large Injection RMS'] = True
136
problems['Large Injection RMS'] = False
139
if int(t.qflag[index]) & 128 != 128:
140
problems['Low Chi2'] = True
142
problems['Low Chi2'] = False
144
if int(t.qflag[index]) & 256 != 256:
145
problems['Edge Sample'] = True
147
problems['Edge Sample'] = False
149
if int(t.qflag[index]) & 512 != 512:
150
problems['Next To Edge Sample'] = True
152
problems['Next To Edge Sample'] = False
154
if ('low' in region.GetHash() and t.calib[index] < 0.14) or\
155
('high' in region.GetHash() and t.calib[index] < 10):
156
problems['No Response'] = True
158
problems['No Response'] = False
160
data['problems'] = problems
162
if abs(t.calib[index] - 1.29) > 0.000001 and abs(t.calib[index] - 81.8) > 0.000001:
163
newevents.add(Event('CIS', event.runNumber, data, event.time))
165
region.SetEvents(newevents)