Rebin histogram

Hi, I need to rebin histograms of my macro. Running I would like a bin width =1 …Looking the plot that I got by running the macro I see the range is [-600;600], so I wrote:

`htemp->Rebin(1200);                                          
  htemp->Scale(1/htemp->Integral());`

But it didn’t work, so I also tried to force the x range writing

htemp->Rebin(1200);                                         
  			htemp->SetAxisRange(-600.,600.,"X");                
  			htemp->Scale(1/htemp->Integral());

but it didn’t work too. In both situations I get this error

and I get plots having the ROOT automatically binning ( bin width =50).
Isn’t possible to set an user binning? Obiuvlsy if it’s possible to get a width=1 without knowing the range it should be better!

calo.cpp (20.6 KB)


ROOT Version: 5.34/38
Platform: Windows


TH1::Rebin can only increase the bin width.
You need to create your histogram with the fine binning, e.g.:

t->Draw(Form("Calo_Time[%d]-Calo_Time[%d] >> htemp(1200, -600., 600.)", a, b));

Hi @Wile_E_Coyote ,i used your code for the re-binning and it worked, but I had also to cut some data and I need 2 use 2 gaussian fit. Following your reply in this topic Fitting with two gaussian curves , I got a good 2 gaussian fit. Anyway, in the statistical box, I get the mean value of the 2 separated fits, instead I’d like to get also the mean and sigma values of the produced by your code of the total fit.
Should it be possible?
Following @couet reply to this topic Adding text to statistics box I wrote

TPaveStats *statsgdeltatime = (TPaveStats*)htemp->GetListOfFunctions()->FindObject("stats");
   		statsgdeltatime->SetTextColor(kBlue);
   		statsgdeltatime->SetX1NDC(0.80); statsgdeltatime->SetX2NDC(0.98);
   		statsgdeltatime->SetY1NDC(0.77); statsgdeltatime->SetY2NDC(0.92);
   		statsgdeltatime->AddText("Mean	%lf \n #sigma	%lf",mean,sigma);
   		statsgdeltatime->DrawClone();
   		gPad->Update();

but I get error.

Make sure that, before the line with FindObject("stats"), you execute: gPad->Modified(); gPad->Update();

Hi wile, before that line I had

c->Update();

I also added

gPad->Modified(); gPad->Update();

but I get the same error (see attachment)

anyway it looks like that the error is due to the variables because if I write for example

statsgdeltatime->AddText("Mean ");

it works.


calo.cpp (22.7 KB)

Try:

statsgdeltatime->AddText(TString::Format("Mean	%g \n #sigma	%g", mean, sigma));

Thanky you wile. your code works, I had just to modify it to

tatsgdeltatime->AddText(TString::Format("Mean	%g", mean));
			statsgdeltatime->AddText(TString::Format("Sigma	%g", sigma));

because the
\n
command didn’t work and I also tried

\r\n

but it didn’t work too.

But I’ve 1 more question please currently it center all the text, should it be possible to get “Mean” on the left and the value on the right (similiar to what ROOT does)?
thanks

// Note that "=" is a control character
statsgdeltatime->AddText(TString::Format("Mean = %g", mean));
statsgdeltatime->AddText(TString::Format("Sigma	= %g", sigma));

Thank you wile! sorry! I didn’t write the “=”

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