ATLAS Offline Software
UnbinnedHist.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
2 
3 import rootpy.ROOT as ROOT
4 import ROOT as R
5 from rootpy.plotting import Hist
6 import numpy as np
7 class UnbinnedHist(ROOT.TH1F,R.TH1F):
8  def __new__(cls, tree, expression, selection='', options='', hist=None, create_hist=False, **kwargs):
9  obj = tree.Draw(expression, selection, options, hist, create_hist, **kwargs)
10  v1 = tree.get_v1()
11  v1.SetSize(obj.entries)
12  obj._raw_data = np.fromiter(v1, np.float)
13  return obj
14  def get_raw_data(self):
15  return self._raw_data
16  def __add__(self,y):
17  x = self.Clone("New")
18  x.fill_array(y.get_raw_data())
19  x._raw_data = np.append(self._raw_data, y._raw_data)
20  return x
21  def __radd__(self,y):
22  return y.__add__(self)
23  def refill(self, bins=100, range=None, inplace=False):
24  if np.iterable(bins):
25  self_ = Hist(bins)
26  else:
27  if not range:
28  range = (self.lowerbound(), self.upperbound())
29  self_ = Hist(bins, *range)
30  raw_data = self._raw_data
31  self_.fill_array(raw_data)
32  self_._raw_data = raw_data
33  self_.__class__ = UnbinnedHist
34  return self_
35 def unbinned_hist(tree, expression, selection='', options='', hist=None, create_hist=False, **kwargs):
36  obj = UnbinnedHist(tree, expression, selection, options, hist, create_hist, **kwargs)
37  obj.__class__ = UnbinnedHist
38  return obj
39 def group_eqbin(hist_list, bins=100, range=None, inplace=True):
40  if not range:
41  lowerbound = min(hist.lowerbound() for hist in hist_list)
42  upperbound = max(hist.upperbound() for hist in hist_list)
43  range = (lowerbound, upperbound)
44  hist_list = [hist.refill(bins, range, inplace) for hist in hist_list]
45  if not inplace:
46  return hist_list
47 
max
#define max(a, b)
Definition: cfImp.cxx:41
python.UnbinnedHist.unbinned_hist
def unbinned_hist(tree, expression, selection='', options='', hist=None, create_hist=False, **kwargs)
Definition: UnbinnedHist.py:35
python.UnbinnedHist.UnbinnedHist.refill
def refill(self, bins=100, range=None, inplace=False)
Definition: UnbinnedHist.py:23
python.UnbinnedHist.UnbinnedHist.__new__
def __new__(cls, tree, expression, selection='', options='', hist=None, create_hist=False, **kwargs)
Definition: UnbinnedHist.py:8
python.UnbinnedHist.UnbinnedHist.__radd__
def __radd__(self, y)
Definition: UnbinnedHist.py:21
min
#define min(a, b)
Definition: cfImp.cxx:40
python.UnbinnedHist.UnbinnedHist.get_raw_data
def get_raw_data(self)
Definition: UnbinnedHist.py:14
python.UnbinnedHist.UnbinnedHist.__add__
def __add__(self, y)
Definition: UnbinnedHist.py:16
python.UnbinnedHist.UnbinnedHist
Definition: UnbinnedHist.py:7
python.UnbinnedHist.group_eqbin
def group_eqbin(hist_list, bins=100, range=None, inplace=True)
Definition: UnbinnedHist.py:39