Rebinning of histograms

Hi all.

I want to draw several histograms with several different binnings from a tree using TTree:Draw(). For some reason, I want to pipe the output of Draw into a histogram (say “htemp”) and then add this histogram to an empty one later on. So first I need to make sure that this htemp has the proper binning; i need to rebin it. But that only works if I first give a general binning (e.g. per integer or half integer of the variable that I plot, e.g. 1000 bins from 0 to 1000) to the htemp. That I can do in the draw command with “htemp(1000,0,1000)”. However, as I want to have a general code and - in general - the binning of the final histogram may be not uniform, I need to rebin every histogram using an array rather than xmin and xmax. But ROOT ignores this case, i.e. I cannot rebin a histogram using an array if this histogram was initialized with xmin,xmax. Is there still a clever way to do this?

Thank you.


If you create your histogram in advance:
TH1F *h = new TH1F(“MyHIsto”, “Something”, …your preferred binning …);
then you can simply use it later:
MyTree->Draw(“something >> MyHIsto”, …); // note the name of the histogram

Hi Wile.

Thank you for your answer. I thought about that solution.
However, due to some code strucure and reasons I do not want
to explain in too much detail (mainly of aesthetic nature), I’d prefer
to have the drawing and the binning separate. Is there no
other, elegant way to do this?