def getMatplotlibData(self, key): ''' Get root_numpy data converted into python object most useful for plotting with matplotlib :param key: ROOT name of object :return: root object converted to format most useful for plotting with matplotlib ''' if self._rootType[key] == "TH1": return _Root.TH1(self.getRootData(key)) elif self._rootType[key] == "TTree": return _Root.TTree(self.getRootNumpyData(key))
def make1DHistogram(self, command, selector="", name="hist", title="hist", nbins=-1, xlow=-1., xhigh=1.): ''' Use TTree.Draw to create a histogram, useful when the size of the data cannot be extracted using getNumpyBranch :param command: :param selector: :param name: histogram name :param title: histogram title :param nbins: number of bins :param xlow: histogram lowest edge :param xhigh: histogram highest edge :return: Root.TH1 object ''' # just in case _ROOT.TH1.AddDirectory(True) # check for existing histogram h = _ROOT.gDirectory.Get(name) if h != None: _ROOT.gDirectory.Delete(name) # make histogram if bins are defined if nbins != -1: h = _ROOT.TH1D(name, title, nbins, xlow, xhigh) nSelected = self._tree.Draw(command + " >> " + name, selector, "goff") rootH = _gDirectory.Get(name) # root histogram object maplH = _Root.TH1(rootH) # matplotlib histogram object return maplH