~vpec/maus/tof_calib_read

« back to all changes in this revision

Viewing changes to workers/CIS/.svn/text-base/CompareCISCuts.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.GenericWorker import *
 
7
from src.oscalls import *
 
8
import src.MakeCanvas
 
9
import os, datetime
 
10
 
 
11
class CompareCISCuts(GenericWorker):
 
12
    "Compare CIS cuts of Chi2/RMS versus Likely Calib/Max-response"
 
13
 
 
14
    c1 = src.MakeCanvas.MakeCanvas()
 
15
 
 
16
    def __init__(self):
 
17
        pass
 
18
 
 
19
 
 
20
    def ProcessStart(self):
 
21
        self.nPP = 0
 
22
        self.nPF = 0
 
23
        self.nFP = 0
 
24
        self.nFF = 0
 
25
 
 
26
        self.n = 0
 
27
        
 
28
    def ProcessStop(self):
 
29
        if self.n:
 
30
            print 'Total number of calibrations:              ', self.n
 
31
            print 'Pass ChiRMS Pass QFlag', self.nPP, 'or', float(self.nPP)/self.n*100, '%'
 
32
            print 'Pass ChiRMS Fail QFlag', self.nPF, 'or', float(self.nPF)/self.n*100, '%'
 
33
            print 'Fail ChiRMS Pass QFlag', self.nFP, 'or', float(self.nFP)/self.n*100, '%'
 
34
            print 'Fail ChiRMS Fail QFlag', self.nFF, 'or', float(self.nFF)/self.n*100, '%'
 
35
    
 
36
    def ProcessRegion(self, region):
 
37
        # Only look at each gain within some channel
 
38
        if 'gain' not in region.GetHash():
 
39
            return
 
40
 
 
41
        newevents = set()
 
42
        for event in region.GetEvents():
 
43
            pass_chirms = True
 
44
            pass_qflag  = True
 
45
 
 
46
            if event.runType == 'CIS':
 
47
                assert(event.data.has_key('problems'))
 
48
                assert(isinstance(event.data['problems'], dict))
 
49
 
 
50
                problems = event.data['problems']
 
51
                
 
52
                if problems['Digital Errors']:
 
53
                    continue
 
54
                
 
55
                if problems['Large Injection RMS']:
 
56
                    pass_chirms = False
 
57
                
 
58
                if problems['Low Chi2']:
 
59
                    pass_chirms = False
 
60
                
 
61
                if problems['Fail Max. Point']:
 
62
                    pass_qflag = False
 
63
                
 
64
                if problems['Fail Likely Calib.']:
 
65
                    pass_qflag = False
 
66
                
 
67
                self.n += 1
 
68
 
 
69
                if pass_chirms and pass_qflag:
 
70
                    self.nPP += 1
 
71
                elif pass_chirms and not pass_qflag:
 
72
                    self.nPF += 1
 
73
                    #print 'Pass ChiRms Fail Qflag', region.GetHash(), region.GetHash(1)
 
74
                elif not pass_chirms and pass_qflag:
 
75
                    self.nFP += 1
 
76
                    #print 'Fail ChiRms Pass Qflag', region.GetHash(), region.GetHash(1)
 
77
                elif not pass_chirms and not pass_qflag:
 
78
                    self.nFF += 1
 
79
                                
 
80
                event.data['comp_chi_rms'] = [pass_chirms, pass_qflag]
 
81
 
 
82
            newevents.add(event)
 
83
        region.SetEvents(newevents)
 
84
        
 
85