~vpec/maus/tof_calib_read

« back to all changes in this revision

Viewing changes to workers/CIS/.svn/text-base/GetScans.py.svn-base

  • Committer: tunnell
  • Date: 2010-09-20 10:52:02 UTC
  • Revision ID: tunnell@itchy-20100920105202-ce4w9jm59zvgnsxq
moving stuff from tucs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Author: Christopher Tunnell <tunnell@hep.uchicago.edu>
 
2
#
 
3
# March 04, 2009
 
4
#
 
5
 
 
6
from src.ReadGenericCalibration import *
 
7
from src.region import *
 
8
 
 
9
class GetScans(ReadGenericCalibration):
 
10
    "Grab the graph(s) of CIS scan(s) from the CIS calibration ntuple"
 
11
 
 
12
    def __init__(self, processingDir='/afs/cern.ch/user/t/tilecali/w0/ntuples/cis', getScans=True, getScansRMS=False, all=False):
 
13
        self.all = all
 
14
        self.processingDir = processingDir
 
15
        self.getScans = getScans
 
16
        self.getScansRMS = getScansRMS
 
17
        self.ftDict = {} # Used for linear constant.  Each element is a [TTree, TFile]
 
18
        self.badRuns = set()
 
19
 
 
20
    def get_index(self, ros, mod, chan, gain):
 
21
        return ros  *64*48*2\
 
22
            + mod      *48*2\
 
23
            + chan        *2\
 
24
            + gain
 
25
 
 
26
    def ProcessStart(self):
 
27
        self.n = 0
 
28
 
 
29
    def ProcessStop(self):
 
30
        print 'Grabbed %d scans...' % self.n
 
31
    
 
32
    def ProcessRegion(self, region):
 
33
        # See if it's a gain
 
34
        if 'gain' not in region.GetHash():
 
35
            return
 
36
 
 
37
        # Prepare events
 
38
        foundEventToProcess = False
 
39
        processRequest = False
 
40
        
 
41
        for event in region.GetEvents():
 
42
            if event.runType == 'CIS':
 
43
                foundEventToProcess = True
 
44
 
 
45
                if (event.data.has_key('moreInfo') and event.data['moreInfo']) or self.all:
 
46
                    processRequest = True
 
47
                else:
 
48
                    continue
 
49
            
 
50
                if event.runNumber and\
 
51
                       not self.ftDict.has_key(event.runNumber):
 
52
                    f, t = self.getFileTree('tileCalibCIS_%s_CIS.0.root' % event.runNumber, 'h3000')
 
53
 
 
54
                    if [f, t] == [None, None]:
 
55
                        f, t = self.getFileTree('tileCalibCIS_%s_0.root' % event.runNumber, 'h3000')
 
56
 
 
57
                        if [f, t] == [None, None]:
 
58
                            f, t = self.getFileTree('tileCalibTool_%s_CIS.0.root' % event.runNumber, 'h3000')
 
59
                                                    
 
60
                            if [f, t] == [None, None]:
 
61
                                if event.runNumber not in self.badRuns:
 
62
                                    print "Error: ReadCISFile couldn't load run", event.runNumber, "..."
 
63
                                    self.badRuns.add(event.runNumber)
 
64
                                continue
 
65
 
 
66
                    scans = f.Get('cisScans')
 
67
                    scans_rms = f.Get('cisScansRMS')
 
68
                    if (self.getScans and not scans) or\
 
69
                           (self.getScansRMS and not scans_rms) or\
 
70
                        (self.getScans and scans.GetName() != 'TMap') or\
 
71
                        (self.getScansRMS and scans_rms.GetName() != 'TMap'):
 
72
                        if event.runNumber not in self.badRuns:
 
73
                            print 'GetScans: Could not find scans. Maybe use ReadOldCISFile?'
 
74
                            self.badRuns.add(event.runNumber)
 
75
                        continue
 
76
                    
 
77
                    self.ftDict[event.runNumber] = [f, t, scans, scans_rms]
 
78
 
 
79
        if not foundEventToProcess:
 
80
            return
 
81
 
 
82
        # I used the Upward Lowenheim-Skolem Theorem to determine the validity
 
83
        # of this statement.  Actually, not really. :)
 
84
        if not processRequest and not self.all:
 
85
            return
 
86
 
 
87
        # counter
 
88
        self.n += 1
 
89
 
 
90
        newevents = set()
 
91
                
 
92
        for event in region.GetEvents():
 
93
            if event.runType == 'CIS':
 
94
                # Load up the tree, file and scans for this run
 
95
                if not self.ftDict.has_key(event.runNumber):
 
96
                    continue
 
97
 
 
98
                [f, t, scans, scans_rms] = self.ftDict[event.runNumber]
 
99
                t.GetEntry(0) 
 
100
 
 
101
                x,y,z,w = region.GetNumber()
 
102
                key = 'scan%d_%d_%d_%d' % (x, y-1, z, w)
 
103
                if self.getScans and scans:
 
104
                    obj = scans.GetValue(key)
 
105
                    gscan = obj.Clone()
 
106
                    gscan.Draw("ALP")
 
107
                    #gscan.SetFillColor(0)
 
108
                    #gscan.SetLineWidth(6)
 
109
                    gscan.GetXaxis().SetTitle("Injected Charge (pC)")
 
110
                    gscan.GetXaxis().CenterTitle(True)
 
111
                    gscan.GetYaxis().SetTitle("Fit CIS Amplitude (ADC counts)")
 
112
                    gscan.SetMarkerSize(1.6)
 
113
                    gscan.SetMarkerStyle(20)
 
114
                    if gscan.GetFunction("fslope"):
 
115
                        gscan.GetFunction("fslope").SetLineWidth(5)
 
116
                        gscan.GetFunction("fslope").SetLineColor(2)
 
117
 
 
118
                    event.data['scan'] = gscan
 
119
 
 
120
                if self.getScansRMS and scans_rms:
 
121
                    event.data['scan_rms'] = (scans_rms.GetValue(key)).Clone()
 
122
                    
 
123
            newevents.add(event)
 
124
 
 
125
        region.SetEvents(newevents)