~vpec/maus/tof_calib_read

« back to all changes in this revision

Viewing changes to workers/CIS/ShowResiduals.py

  • 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.GenericWorker import *
 
7
from src.oscalls import *
 
8
import src.MakeCanvas
 
9
import os, datetime
 
10
 
 
11
class ShowResiduals(GenericWorker):
 
12
    "Make a plot of the CIS fit residuals"
 
13
 
 
14
    def __init__(self):
 
15
        self.c1 = src.MakeCanvas.MakeCanvas()
 
16
 
 
17
        self.dir = getPlotDirectory() + "/cis"
 
18
        createDir('%s/residuals' % self.dir)
 
19
        self.dir = '%s/residuals' % self.dir
 
20
 
 
21
    def ProcessRegion(self, region):
 
22
        # Only look at each gain within some channel
 
23
        if 'gain' not in region.GetHash():
 
24
            return
 
25
 
 
26
        self.c1.cd()
 
27
 
 
28
        for event in region.GetEvents():
 
29
            if event.runType == 'CIS' and event.data.has_key('scan'):
 
30
                scan = event.data['scan']
 
31
                gnln = ROOT.TGraphErrors()
 
32
                gnlni = 0
 
33
                for i in range(scan.GetN()):
 
34
                    if 'high' in region.GetHash() and not 3.<scan.GetX()[i]<10.:
 
35
                        continue
 
36
                    elif 'low' in region.GetHash() and not 300.<scan.GetX()[i]<700.:
 
37
                        continue
 
38
 
 
39
                    gnln.SetPoint(gnlni, scan.GetX()[i], scan.GetY()[i] - event.data['calibration']*scan.GetX()[i])
 
40
                    gnln.SetPointError(gnlni, 0, scan.GetErrorY(i))
 
41
                    gnlni += 1
 
42
 
 
43
                gnln.Draw("ALP")
 
44
                gnln.SetFillColor(0)
 
45
                gnln.GetXaxis().SetTitle("Injected Charge (pC)")
 
46
                gnln.GetYaxis().SetTitle("Data - Fit (ADC counts)")
 
47
                gnln.GetYaxis().SetLabelSize(0.05)
 
48
                gnln.GetYaxis().SetTitleSize(0.05)
 
49
                gnln.GetXaxis().SetLabelOffset(0.02)
 
50
                gnln.GetXaxis().SetLabelOffset(0.01)
 
51
                gnln.GetXaxis().SetLabelSize(0.05)
 
52
                gnln.GetXaxis().SetTitleSize(0.05)
 
53
                gnln.GetXaxis().SetTitleOffset(0.93)
 
54
                gnln.SetLineWidth(3)
 
55
                gnln.SetMarkerSize(1.6)
 
56
                gnln.SetMarkerStyle(20)
 
57
                gnln.Draw('ALP')
 
58
                self.c1.Print("%s/uncalib_%s.ps" % (self.dir, region.GetHash()))
 
59
                
 
60
                                                                                                
 
61
        
 
62