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

946  def __init__(self, name, xhistoName, yhistoName, zaxis=False):
947  """Constructor.
948 
949  Arguments:
950  name -- String for the name of the resulting histogram
951  xhistoName -- String for the name of the x-axis histogram (or another "creator" object)
952  yhistoName -- String for the name of the y-axis histogram (or another "creator" object)
953 
954  Keyword arguments:
955  zaxis -- If set to True (default False), create a TGraph2D with z axis showing the cut value (recommended drawStyle 'pcolz')
956  """
957  self._name = name
958  self._xhistoName = xhistoName
959  self._yhistoName = yhistoName
960  self._zaxis = zaxis
961 
def __init__(self, name, xhistoName, yhistoName, zaxis=False)
Definition: plotting.py:946

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

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

966  def create(self, tdirectory):
967  """Create and return the histogram from a TDirectory"""
968  xhisto = _getOrCreateObject(tdirectory, self._xhistoName)
969  yhisto = _getOrCreateObject(tdirectory, self._yhistoName);
970  if xhisto is None or yhisto is None:
971  return None
972 
973  x = []
974  xerrup = []
975  xerrdown = []
976  y = []
977  yerrup = []
978  yerrdown = []
979  z = []
980 
981  for i in xrange(1, xhisto.GetNbinsX()+1):
982  x.append(xhisto.GetBinContent(i))
983  xerrup.append(xhisto.GetBinError(i))
984  xerrdown.append(xhisto.GetBinError(i))
985 
986  y.append(yhisto.GetBinContent(i))
987  yerrup.append(yhisto.GetBinError(i))
988  yerrdown.append(yhisto.GetBinError(i))
989 
990  z.append(xhisto.GetXaxis().GetBinUpEdge(i))
991 
992  # If either axis has only zeroes, no graph makes no point
993  if x.count(0.0) == len(x) or y.count(0.0) == len(y):
994  return None
995 
996  arr = lambda v: array.array("d", v)
997  gr = None
998  if self._zaxis:
999  gr = ROOT.TGraph2D(len(x), arr(x), arr(y), arr(z))
1000  else:
1001  gr = ROOT.TGraphAsymmErrors(len(x), arr(x), arr(y), arr(xerrdown), arr(xerrup), arr(yerrdown), arr(yerrup))
1002  gr.SetTitle("")
1003  return gr
1004 
1005 
1006 # Plot styles
def _getOrCreateObject(tdirectory, nameOrCreator)
Definition: plotting.py:53
def create(self, tdirectory)
Definition: plotting.py:966

Member Data Documentation

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

Definition at line 958 of file plotting.py.

Referenced by plotting.ROC.create().

plotting.ROC._yhistoName
private

Definition at line 959 of file plotting.py.

Referenced by plotting.ROC.create().

plotting.ROC._zaxis
private

Definition at line 960 of file plotting.py.

Referenced by plotting.ROC.create().