ATLAS Offline Software
Loading...
Searching...
No Matches
UnbinnedHist.py
Go to the documentation of this file.
1# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
2
3import rootpy.ROOT as ROOT
4import ROOT as R
5from rootpy.plotting import Hist
6import numpy as np
7class 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_
35def 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
39def 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
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
refill(self, bins=100, range=None, inplace=False)
__new__(cls, tree, expression, selection='', options='', hist=None, create_hist=False, **kwargs)
unbinned_hist(tree, expression, selection='', options='', hist=None, create_hist=False, **kwargs)
group_eqbin(hist_list, bins=100, range=None, inplace=True)