CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
plotting.ROC Class Reference

Public Member Functions

def __init__ (self, name, xhistoName, yhistoName, zaxis=False)
 
def __str__ (self)
 
def create (self, tdirectory)
 

Private Attributes

 _name
 
 _xhistoName
 
 _yhistoName
 
 _zaxis
 

Detailed Description

Class to construct a ROC curve (e.g. efficiency vs. fake rate) from two histograms

Definition at line 1117 of file plotting.py.

Constructor & Destructor Documentation

def plotting.ROC.__init__ (   self,
  name,
  xhistoName,
  yhistoName,
  zaxis = False 
)
Constructor.

Arguments:
name       -- String for the name of the resulting histogram
xhistoName -- String for the name of the x-axis histogram (or another "creator" object)
yhistoName -- String for the name of the y-axis histogram (or another "creator" object)

Keyword arguments:
zaxis -- If set to True (default False), create a TGraph2D with z axis showing the cut value (recommended drawStyle 'pcolz')

Definition at line 1119 of file plotting.py.

1119  def __init__(self, name, xhistoName, yhistoName, zaxis=False):
1120  """Constructor.
1121 
1122  Arguments:
1123  name -- String for the name of the resulting histogram
1124  xhistoName -- String for the name of the x-axis histogram (or another "creator" object)
1125  yhistoName -- String for the name of the y-axis histogram (or another "creator" object)
1126 
1127  Keyword arguments:
1128  zaxis -- If set to True (default False), create a TGraph2D with z axis showing the cut value (recommended drawStyle 'pcolz')
1129  """
1130  self._name = name
1131  self._xhistoName = xhistoName
1132  self._yhistoName = yhistoName
1133  self._zaxis = zaxis
1134 
def __init__(self, name, xhistoName, yhistoName, zaxis=False)
Definition: plotting.py:1119

Member Function Documentation

def plotting.ROC.__str__ (   self)
def plotting.ROC.create (   self,
  tdirectory 
)
Create and return the histogram from a TDirectory

Definition at line 1139 of file plotting.py.

References plotting._getOrCreateObject(), plotting.ROC._xhistoName, plotting.ROC._yhistoName, and plotting.ROC._zaxis.

1139  def create(self, tdirectory):
1140  """Create and return the histogram from a TDirectory"""
1141  xhisto = _getOrCreateObject(tdirectory, self._xhistoName)
1142  yhisto = _getOrCreateObject(tdirectory, self._yhistoName);
1143  if xhisto is None or yhisto is None:
1144  return None
1145 
1146  x = []
1147  xerrup = []
1148  xerrdown = []
1149  y = []
1150  yerrup = []
1151  yerrdown = []
1152  z = []
1153 
1154  for i in xrange(1, xhisto.GetNbinsX()+1):
1155  x.append(xhisto.GetBinContent(i))
1156  xerrup.append(xhisto.GetBinError(i))
1157  xerrdown.append(xhisto.GetBinError(i))
1158 
1159  y.append(yhisto.GetBinContent(i))
1160  yerrup.append(yhisto.GetBinError(i))
1161  yerrdown.append(yhisto.GetBinError(i))
1162 
1163  z.append(xhisto.GetXaxis().GetBinUpEdge(i))
1164 
1165  # If either axis has only zeroes, no graph makes no point
1166  if x.count(0.0) == len(x) or y.count(0.0) == len(y):
1167  return None
1168 
1169  arr = lambda v: array.array("d", v)
1170  gr = None
1171  if self._zaxis:
1172  gr = ROOT.TGraph2D(len(x), arr(x), arr(y), arr(z))
1173  else:
1174  gr = ROOT.TGraphAsymmErrors(len(x), arr(x), arr(y), arr(xerrdown), arr(xerrup), arr(yerrdown), arr(yerrup))
1175  gr.SetTitle("")
1176  return gr
1177 
1178 
1179 # Plot styles
def _getOrCreateObject(tdirectory, nameOrCreator)
Definition: plotting.py:55
def create(self, tdirectory)
Definition: plotting.py:1139

Member Data Documentation

plotting.ROC._name
private
plotting.ROC._xhistoName
private

Definition at line 1131 of file plotting.py.

Referenced by plotting.ROC.create().

plotting.ROC._yhistoName
private

Definition at line 1132 of file plotting.py.

Referenced by plotting.ROC.create().

plotting.ROC._zaxis
private

Definition at line 1133 of file plotting.py.

Referenced by plotting.ROC.create().