forked from fnal/FPIXUtils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Comparison.py
124 lines (94 loc) · 3.5 KB
/
Comparison.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#! /usr/bin/env python
"""
Author: John Stupak ([email protected])
Date: 5-2-15
Usage: ./checkPretest.py <input dir>
"""
import ROOT
ROOT.gErrorIgnoreLevel = ROOT.kWarning
from ROOT import *
#gStyle.SetOptStat(0)
import math
from config import *
################################################################
################################################################
################################################################
goodModules=[]
def click(moduleNo):
global goodModules
if gPad.GetEvent()==11:
if moduleNo in goodModules:
goodModules.remove(moduleNo)
testPad.cd(moduleNo+1)
gPad.SetFillColor(kRed)
gPad.Modified()
gPad.Update()
else:
goodModules+=[moduleNo]
goodModules.sort()
testPad.cd(moduleNo+1)
gPad.SetFillColor(kGreen)
gPad.Modified()
gPad.Update()
return None
################################################################
################################################################
################################################################
class Comparison:
def __init__(self, hName, refName, referenceFile, outputDir, info='All plots should resemble the reference plot'):
self.hName=hName
self.refFile=TFile(referenceFile)
self.outputDir=outputDir
self.info=info
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def do(self, testFiles):
print testFiles
testFiles=[TFile(f) for f in testFiles]
#moduleNames=['_'.join(f.GetName().split('/')[-3].split('_')[:-4]) for f in testFiles]
nModules=len(moduleNames)
global goodModules
goodModules=[]
c=TCanvas('c','',1000,850)
refPad=TPad('refPad','Reference Plot',.666,0.25,1,0.75)
refPad.Draw()
refPad.cd()
print self.hName
ref=self.refFile.Get(self.hName).Clone('REF__'+self.hName.split('/')[-1])
is2D=(type(ref)==type(TH2D()))
ref.Draw('COLZ'*is2D)
c.cd()
testPad=TPad('testPad','',0,0,.666,1)
testPad.Divide(int(math.ceil(nModules/2.)),2)
testPad.Draw()
histograms=[]
for i in range(nModules):
testPad.cd(i+1)
print self.hName, moduleNames[i]
h=testFiles[i].Get(self.hName).Clone(moduleNames[i]+'__'+self.hName.split('/')[-1])
h.SetTitle(moduleNames[i]+': '+h.GetTitle())
h.Draw('COLZ'*is2D)
histograms.append(h)
gPad.Modified()
gPad.Update()
gPad.SetFillColor(kRed)
gPad.Modified()
gPad.Update()
gPad.AddExec('exec','TPython::Exec( "click('+str(i)+')" );')
c.Modified()
c.Update()
while True:
input=raw_input('\n'+self.info+'\n\n'+'Press enter to submit results\n'+'Enter "-1" to go back a test\n\n')
if input=='-1':
refPad.Close()
testPad.Close()
c.Close()
return -1
if input=='':
badModules=[x for x in range(nModules) if x not in goodModules]
for i in badModules:
testPad.GetPad(i+1).SaveAs(self.outputDir+'/'+histograms[i].GetName()+'.pdf')
badModuleNames=[moduleNames[i] for i in badModules]
refPad.Close()
testPad.Close()
c.Close()
return badModuleNames