Issue when rebin a TH2F


I am having troubles, wouldn’t you mind to help me please :
I am trying to rebin the TH2F I draw below (basically because I have too much data points and I want to group them 5 by 5 for instance).

TTree *t1 = new TTree("t1", "a tree 2");
t1->Draw("FOM_energy:e_energy"," SOME SELECTION "," SOME OPTION ");

I tried the rebin() method, but it works only with TH1F. Then I tried to cast my draw in a TH2F with few bins, but it doesn’t work neither… would you have any idea on how to proceed ? Thanks

ROOT 6.10/08


1 Like

Hi Pierre,

the documentation on the TTree has the following example in the “Saving the result of Draw to an histogram” section:

     // plot sqrt(x) against sin(y)
     // 100 bins in x-direction; lower limit on x-axis is 10; upper limit is 60
     //  50 bins in y-direction; lower limit on y-axis is .1; upper limit is .5
1 Like

Thanks for the TTree doc you shared I have missed an info : I have already been trying that option of casting an histogram into another one yet I forgot to retrieve the “hsqrt”. It works now !

t1->Draw("FOM_energy:e_energy>>hsqrt(100,0.,1.,1000,0.,0.002)"," SOME SELECTION"," SOME OPTION");
TH2F *hsqrt = (TH2F*)gDirectory->Get("hsqrt");   //missed that line

Thanks both.

Well, turns out that one does not even need the last two line … hum…

Of course not. You have already drawn the histogram with t1->Draw(...), so why would you want to do it once again?

1 Like

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