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

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

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

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

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

Member Data Documentation

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

Definition at line 1134 of file plotting.py.

Referenced by plotting.ROC.create().

plotting.ROC._yhistoName
private

Definition at line 1135 of file plotting.py.

Referenced by plotting.ROC.create().

plotting.ROC._zaxis
private

Definition at line 1136 of file plotting.py.

Referenced by plotting.ROC.create().