Hello,
I tried to rebin one TProfile into a new TProfile with a variable bin width;
I almost followed the root document from
case 2 xbins!=0
Double_t xbins[25] = {...};
hp->Rebin(24,"hpnew",xbins);
But, looks like the strategy doesn’t work;
Here, I pasted my minimal code:
void RebinTProfile() {
int nbins = 8;
double xlow = 0.0;
double xhigh = 8.0;
TProfile *profile = new TProfile("profile", "Example TProfile", nbins, xlow, xhigh);
// Fill the TProfile with some data
TRandom rand;
for (int i = 0; i < 10000; ++i) {
double x = rand.Uniform(xlow, xhigh);
double y = x * x + rand.Gaus(0, 1); // Example: y = x^2 + random Gaussian noise
profile->Fill(x, y);
}
Double_t xbins[3] = {0.0, 3.0, 8.0};
TProfile *rebinnedProfile = (TProfile* )profile->Clone("rebinnedProfile");
rebinnedProfile->Rebin(2, "rebinnedProfile ", xbins);
// Optionally, plot the original and rebinned TProfile histograms
TCanvas *canvas = new TCanvas("canvas", "TProfile Example", 800, 600);
canvas->Divide(1, 2);
canvas->cd(1);
profile->Draw();
canvas->cd(2);
rebinnedProfile->Draw();
}
Thanks in advance.
Best
Liuyao