CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Private Member Functions
python.rootplot.utilities.Hist2D Class Reference

Define classes. More...

Inheritance diagram for python.rootplot.utilities.Hist2D:
python.rootplot.root2matplotlib.Hist2D

Public Member Functions

def __getitem__ (self, index)
 
def __init__ (self, hist, label="__nolabel__", title=None, xlabel=None, ylabel=None)
 
def __iter__ (self)
 
def __len__ (self)
 
def TH2F (self, name="")
 

Public Attributes

 binlabelsx
 
 binlabelsy
 
 content
 
 entries
 
 label
 
 name
 
 nbinsx
 
 nbinsy
 
 rootclass
 
 title
 
 x
 
 xedges
 
 xlabel
 
 y
 
 yedges
 
 ylabel
 

Private Member Functions

def _flat_content (self)
 

Detailed Description

Define classes.

A container to hold the parameters from a 2D ROOT histogram.

Definition at line 43 of file utilities.py.

Constructor & Destructor Documentation

def python.rootplot.utilities.Hist2D.__init__ (   self,
  hist,
  label = "__nolabel__",
  title = None,
  xlabel = None,
  ylabel = None 
)

Definition at line 46 of file utilities.py.

46  xlabel=None, ylabel=None):
47  try:
48  if not hist.InheritsFrom("TH2"):
49  raise TypeError("%s does not inherit from TH2" % hist)
50  except:
51  raise TypeError("%s is not a ROOT object" % hist)
52  self.rootclass = hist.ClassName()
53  self.name = hist.GetName()
54  self.nbinsx = nx = hist.GetNbinsX()
55  self.nbinsy = ny = hist.GetNbinsY()
56  self.binlabelsx = process_bin_labels([hist.GetXaxis().GetBinLabel(i)
57  for i in range(1, nx + 1)])
58  if self.binlabelsx:
59  self.nbinsx = nx = self.binlabelsx.index('')
60  self.binlabelsx = self.binlabelsx[:ny]
61  self.binlabelsy = process_bin_labels([hist.GetYaxis().GetBinLabel(i)
62  for i in range(1, ny + 1)])
63  if self.binlabelsy:
64  self.nbinsy = ny = self.binlabelsy.index('')
65  self.binlabelsy = self.binlabelsy[:ny]
66  self.entries = hist.GetEntries()
67  self.content = [[hist.GetBinContent(i, j) for i in range(1, nx + 1)]
68  for j in range(1, ny + 1)]
69  self.xedges = [hist.GetXaxis().GetBinLowEdge(i)
70  for i in range(1, nx + 2)]
71  self.yedges = [hist.GetYaxis().GetBinLowEdge(i)
72  for i in range(1, ny + 2)]
73  self.x = [(self.xedges[i+1] + self.xedges[i])/2
74  for i in range(nx)]
75  self.y = [(self.yedges[i+1] + self.yedges[i])/2
76  for i in range(ny)]
77  self.title = title or hist.GetTitle()
78  self.xlabel = xlabel or hist.GetXaxis().GetTitle()
79  self.ylabel = ylabel or hist.GetYaxis().GetTitle()
80  self.label = label
def process_bin_labels(binlabels)
Definition: utilities.py:486

Member Function Documentation

def python.rootplot.utilities.Hist2D.__getitem__ (   self,
  index 
)
Return contents of indexth bin: x.__getitem__(y) <==> x[y]

Definition at line 86 of file utilities.py.

References python.rootplot.utilities.Hist2D._flat_content().

86  def __getitem__(self, index):
87  """Return contents of indexth bin: x.__getitem__(y) <==> x[y]"""
88  return self._flat_content()[index]
def __getitem__(self, index)
Definition: utilities.py:86
def python.rootplot.utilities.Hist2D.__iter__ (   self)
Iterate through bins: x.__iter__() <==> iter(x)

Definition at line 92 of file utilities.py.

References python.rootplot.utilities.Hist2D._flat_content().

92  def __iter__(self):
93  """Iterate through bins: x.__iter__() <==> iter(x)"""
94  return iter(self._flat_content())
def python.rootplot.utilities.Hist2D.__len__ (   self)
Return the number of bins: x.__len__() <==> len(x)

Definition at line 89 of file utilities.py.

References python.rootplot.utilities.Hist2D._flat_content().

89  def __len__(self):
90  """Return the number of bins: x.__len__() <==> len(x)"""
91  return len(self._flat_content())
def python.rootplot.utilities.Hist2D._flat_content (   self)
private
def python.rootplot.utilities.Hist2D.TH2F (   self,
  name = "" 
)
Return a ROOT.TH2F object with contents of this Hist2D.

Definition at line 95 of file utilities.py.

References DQMChannel.content, fixedArray< T, S >.content, BlobComplexObjects.content, PhysicsTools::MVATrainerLooper::TrainerContainer.content, python.rootplot.utilities.Hist2D.content, python.rootplot.utilities.Hist2D.nbinsx, python.rootplot.utilities.Hist2D.nbinsy, classes.PlotData.title, EventStringOutputBranches::NamedBranchPtr.title, preexistingValidation.PreexistingValidation.title, TriggerOutputBranches::NamedBranchPtr.title, DB_ME.title, TableOutputBranches::NamedBranchPtr.title, cscdqm::HistoBookRequest.title, FWTriggerTableView::Column.title, DQMGenericClient::EfficOption.title, alignment.Alignment.title, DQMGenericClient::ProfileOption.title, dqmoffline::l1t::HistDefinition.title, SiPixelGenErrorHeader.title, ecaldqm::binning::AxisSpecs.title, python.rootplot.utilities.Hist2D.title, big::bigHeader.title, HistogramManager.title, SiPixelTemplateHeader2D.title, presentation.SubsectionBase.title, Geometry.title, TkAlMap.TkAlMap.title, TrackerMap.title, SiPixelTemplateHeader.title, python.rootplot.utilities.Hist2D.xedges, python.rootplot.utilities.Hist2D.xlabel, HistogramManager.xlabel, python.rootplot.utilities.Hist2D.yedges, python.rootplot.utilities.Hist2D.ylabel, HistogramManager.ylabel, and rpcdqm::utils.ylabel.

95  def TH2F(self, name=""):
96  """Return a ROOT.TH2F object with contents of this Hist2D."""
97  th2f = ROOT.TH2F(name, "",
98  self.nbinsx, array.array('f', self.xedges),
99  self.nbinsy, array.array('f', self.yedges))
100  th2f.SetTitle("%s;%s;%s" % (self.title, self.xlabel, self.ylabel))
101  for ix in range(self.nbinsx):
102  for iy in range(self.nbinsy):
103  th2f.SetBinContent(ix + 1, iy + 1, self.content[iy][ix])
104  return th2f
105 
def TH2F(self, name="")
Definition: utilities.py:95

Member Data Documentation

python.rootplot.utilities.Hist2D.binlabelsx

Definition at line 56 of file utilities.py.

Referenced by python.rootplot.root2matplotlib.Hist2D.contour().

python.rootplot.utilities.Hist2D.binlabelsy

Definition at line 61 of file utilities.py.

Referenced by python.rootplot.root2matplotlib.Hist2D.contour().

python.rootplot.utilities.Hist2D.content
python.rootplot.utilities.Hist2D.entries
python.rootplot.utilities.Hist2D.label
python.rootplot.utilities.Hist2D.name
python.rootplot.utilities.Hist2D.nbinsx
python.rootplot.utilities.Hist2D.nbinsy
python.rootplot.utilities.Hist2D.rootclass

Definition at line 52 of file utilities.py.

python.rootplot.utilities.Hist2D.title
python.rootplot.utilities.Hist2D.x
python.rootplot.utilities.Hist2D.xedges
python.rootplot.utilities.Hist2D.xlabel
python.rootplot.utilities.Hist2D.y
python.rootplot.utilities.Hist2D.yedges
python.rootplot.utilities.Hist2D.ylabel