Addition of histograms with different bins derived from TTree's GetHIstogram()


ROOT Version: 6.10/09
Platform: Ubuntu 16.04
Compiler: gcc530


Hi, I have a root file with TTree with branch of let’s say… AODCaloJetPt…
I can simply create a TH1F object of the histogram with

        mytree16 = _file0.Get("Ntuple/EventTree")
        mytree16.Draw("AODCaloJetPt")
        temp = TH1F()
        temp = mytree16.GetHistogram()

I am looping over multiple Ntuplized files and want to look at the added histogram for the variable of AODCaloJetPt.

I believed it could be simply done with

h16 = TH1F()

for i in range (10):
        filename = DY16dir[i]
        _file0 = TFile.Open(filename,'read')
        #myfile = TFile.Open(_file0)
        mytree16 = _file0.Get("Ntuple/EventTree")
        mytree16.Draw("AODCaloJetPt")
        temp = TH1F()
        temp = mytree16.GetHistogram()
        h16.Add(temp)
        temp.Delete()

However, since the tree’s GetHistogram does not have defined binning and dependent on its maximum value of branch content, It has different binning.
So, it gives these messages…

Info in TH1F::Add: Attempt to add histograms with different number of bins

Is there an ingenious way to accomplish the goals without looping over all contents of the branch and filling the histogram? (Takes too much time in python script…)
If you could instruct me how to do this in pandas or uproot… I would sincerely appreciate as well!

Thank you.!

hi,

here you find several examples of analyses using rdataframe also in python. it will be very fast since only the columns you use are read and you can transparently parallelise your workflow: https://root.cern/doc/master/group__tutorial__dataframe.html

in particular this is how you can create a histogram: https://root.cern/doc/master/classROOT_1_1RDF_1_1RInterface.html#a247ca3aeb7ce5b95015b7fae72983055

cheers
P

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.