Classes | Functions | Variables
plotConfusion Namespace Reference

Classes

class  HistSet
 

Functions

def diagonal (hist)
 
def sliceOf3D (hist3D, zBin)
 
def copy1DSliceTo2D (src, dest, k)
 
def effAndPurVsZ (hist3D)
 
def efficiency (h2)
 
def purity (h2)
 
def makePlots (input, output="plots/")
 

Variables

list keepers = []
 
 parser = argparse.ArgumentParser(description='Dump a tree to text.')
 
 type
 
 help
 
 action
 
 args = parser.parse_args()
 
string outdir = "/dev/null"
 

Function Documentation

def plotConfusion.copy1DSliceTo2D (   src,
  dest,
  k 
)

Definition at line 69 of file plotConfusion.py.

Referenced by effAndPurVsZ().

69 def copy1DSliceTo2D(src, dest, k):
70  for i in rcvne(1, src.GetNbinsX()+1):
71  dest.SetBinContent(k, i, src.GetBinContent(i))
72 
73 
def copy1DSliceTo2D(src, dest, k)
def plotConfusion.diagonal (   hist)

Definition at line 42 of file plotConfusion.py.

Referenced by efficiency(), makePlots(), and purity().

42 def diagonal(hist):
43  nBins = hist.GetNbinsX()
44  nBinsY = hist.GetNbinsY()
45  if nBins != nBinsY:
46  raise Exception("Number of bins not equal on x and y axis, can't take diag")
47 
48  diag = TH1F(hist.GetName() + "_diagonal", hist.GetTitle(), nBins, 0, nBins)
49 
50  for i in rcvne(1, nBins+1):
51  diag.SetBinContent(i, hist.GetBinContent(i, i))
52  return diag
53 
54 
def diagonal(hist)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
def plotConfusion.effAndPurVsZ (   hist3D)

Definition at line 74 of file plotConfusion.py.

References copy1DSliceTo2D(), efficiency(), canMan.newCan(), purity(), and sliceOf3D().

Referenced by makePlots().

74 def effAndPurVsZ(hist3D):
75  global keepers
76  nBins = hist3D.GetNbinsX()
77  nBinsY = hist3D.GetNbinsY()
78  nBinsZ = hist3D.GetNbinsZ()
79 
80 
81  eff = TH2F(hist3D.GetName() + "_efficiency", hist3D.GetTitle(),
82  nBinsZ, hist3D.GetZaxis().GetXmin(), hist3D.GetZaxis().GetXmax(),
83  nBins, 0, nBins)
84  keepers.append(eff)
85  pur = TH2F(hist3D.GetName() + "_purity", hist3D.GetTitle(),
86  nBinsZ, hist3D.GetZaxis().GetXmin(), hist3D.GetZaxis().GetXmax(),
87  nBins, 0, nBins)
88  keepers.append(pur)
89 
90  for k in rcvne(1,nBinsZ + 1):
91  slice = sliceOf3D(hist3D, k)
92  copy1DSliceTo2D(efficiency(slice), eff, k)
93  copy1DSliceTo2D(purity(slice), pur, k)
94 
95  canMan.newCan(eff.GetName())
96  eff.Draw("colz")
97  eff.SetDirectory(0)
98  canMan.newCan(pur.GetName())
99  pur.Draw("colz")
100  pur.SetDirectory(0)
101  print keepers
102 
103 
104 
105 
106 
107 
def sliceOf3D(hist3D, zBin)
def effAndPurVsZ(hist3D)
def efficiency(h2)
def copy1DSliceTo2D(src, dest, k)
def newCan(title)
Definition: canMan.py:19
def plotConfusion.efficiency (   h2)

Definition at line 108 of file plotConfusion.py.

References diagonal().

Referenced by effAndPurVsZ(), and makePlots().

108 def efficiency(h2):
109  # This is the denominator for efficiency
110  projX = h2.ProjectionX()
111  diag = diagonal(h2)
112  eff = TH1F(diag)
113  eff.Divide(projX)
114  eff.SetTitle("Efficiency")
115  eff.SetDirectory(0)
116  return eff
117 
def efficiency(h2)
def diagonal(hist)
def plotConfusion.makePlots (   input,
  output = "plots/" 
)

Definition at line 129 of file plotConfusion.py.

References canMan.canUp(), diagonal(), effAndPurVsZ(), efficiency(), canMan.newCan(), purity(), and canMan.saveCans().

129 def makePlots(input, output="plots/"):
130  f = TFile(input, "READ")
131 
132  d = f.Get("cvnana")
133 
134 
135  hSet = HistSet(d)
136  del f
137  cm = hSet.h2["ConfusionMatrix"]
138  canMan.newCan("ConfusionMatrix")
139  cm.Draw("colz")
140 
141  canMan.newCan("ProjectionX")
142  # This is the denominator for efficiency
143  projX = cm.ProjectionX()
144  projX.Draw()
145 
146  canMan.newCan("ProjectionY")
147  # This is the denominator for purity
148  projY = cm.ProjectionY()
149  projY.Draw()
150 
151  canMan.newCan("Diagonal")
152  diag = diagonal(cm)
153  diag.Draw()
154 
155 
156 
157  canMan.newCan("Efficiency")
158  eff = efficiency(cm)
159 
160  eff.Draw()
161 
162  canMan.newCan("Purity")
163  pur = purity(cm)
164  pur.Draw()
165 
166 
167 
168  for k, h3 in hSet.h3.items():
169  effAndPurVsZ(h3)
170 
171  canMan.canUp()
172  canMan.saveCans(os.path.join(output,""), ".png")
173 
174 
175 
176 
def effAndPurVsZ(hist3D)
def canUp()
Definition: canMan.py:33
def efficiency(h2)
def diagonal(hist)
def makePlots(input, output="plots/")
def saveCans(prefix="", suffix=".pdf")
Definition: canMan.py:39
def newCan(title)
Definition: canMan.py:19
def plotConfusion.purity (   h2)
def plotConfusion.sliceOf3D (   hist3D,
  zBin 
)

Definition at line 55 of file plotConfusion.py.

Referenced by effAndPurVsZ().

55 def sliceOf3D(hist3D, zBin):
56  nBins = hist3D.GetNbinsX()
57  nBinsY = hist3D.GetNbinsY()
58 
59  slice = TH2F(hist3D.GetName() + "_slice_%s" % (zBin), hist3D.GetTitle()
60  , nBins, 0, nBins, nBinsY, 0, nBinsY)
61 
62  for i in rcvne(1,nBins + 1):
63  for j in rcvne(1,nBinsY + 1):
64  slice.SetBinContent(i, j, hist3D.GetBinContent(i,j,zBin))
65  return slice
66 
67 
68 
def sliceOf3D(hist3D, zBin)

Variable Documentation

plotConfusion.action

Definition at line 185 of file plotConfusion.py.

plotConfusion.args = parser.parse_args()

Definition at line 188 of file plotConfusion.py.

plotConfusion.help

Definition at line 180 of file plotConfusion.py.

list plotConfusion.keepers = []

Definition at line 11 of file plotConfusion.py.

plotConfusion.outdir = "/dev/null"

Definition at line 190 of file plotConfusion.py.

plotConfusion.parser = argparse.ArgumentParser(description='Dump a tree to text.')

Definition at line 178 of file plotConfusion.py.

plotConfusion.type

Definition at line 179 of file plotConfusion.py.