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

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

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

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

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

Member Data Documentation

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

Definition at line 966 of file plotting.py.

Referenced by plotting.ROC.create().

plotting.ROC._yhistoName
private

Definition at line 967 of file plotting.py.

Referenced by plotting.ROC.create().

plotting.ROC._zaxis
private

Definition at line 968 of file plotting.py.

Referenced by plotting.ROC.create().