Average over bins with the errors in histogram

Hello
I have a TProfile histogram with 100 bins. I want to take average of each of consecutive 5 bins with the content and error also. So I will get 20 average values. Now I want to fill these values in another histogram with the error bars. I tried to do the following…

TProfile *tprof = new TProfile ("tprof","tprof",100,0,4);
TH1D *h2 = new TH1D ("h2","h2",20,0,4);
  float px, py, pz;
  for ( int i=0; i<25000; i++) {
    gRandom->Rannor(px,py);
    pz = px*px + py*py;
    tprof->Fill(px,pz,1);
  }
  double sum= 0 ; 
double avg = 0;
for (i=0; i<20 ; i++)
{ for (int j=1; j<=5 ; j++)
  { sum += tprof->GetBinContent(5.* i + j);}
  avg = sum/5.; h2 -> Fill(avg);
  sum = 0 ; avg = 0;
}
h2->Draw();
}    

But I can’t superimpose the corresponding error bars.
Is there any way I can do it ?
Shall I use a Tprofile histogram in place of h2 ?

Thank you

Try:

TProfile *h5 = tprof->Rebin(5, "h5");
// h5->Scale(1. / 5.);
h5->Draw();
1 Like

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