Average over bins with the errors in histogram

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++) {
    pz = px*px + py*py;
  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;

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


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

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