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 1118 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 1120 of file plotting.py.

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

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 1140 of file plotting.py.

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

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

Member Data Documentation

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

Definition at line 1132 of file plotting.py.

Referenced by plotting.ROC.create().

plotting.ROC._yhistoName
private

Definition at line 1133 of file plotting.py.

Referenced by plotting.ROC.create().

plotting.ROC._zaxis
private

Definition at line 1134 of file plotting.py.

Referenced by plotting.ROC.create().