What is the ProfileX BinError/StdError


Here is an example about the TProfile.
A 1d-histogram (TH1D *h1) is obtained by TProfileX of a TH2D *h2.
I want to know the binerror of the TH1D *h1, which I guess is equal to the std Dev(ProjectionY in each x bin) / sqrt(sum of the each x-axis bin counts). But the results shown in the figure doesn’t look that way.

The code is:

#include "TF2.h"
#include "TH2.h"
#include "TMath.h"
double g2(double *x, double *par) {
   double r1 = double((x[0]-par[1])/par[2]);
   double r2 = double((x[1]-par[3])/par[4]);
   return par[0]*TMath::Exp(-0.5*(r1*r1+r2*r2));
double fun2(double *x, double *par) {
   double *p1 = &par[0];
   double *p2 = &par[5];
   double *p3 = &par[10];
   double result = g2(x,p1) + g2(x,p2) + g2(x,p3);
   return result;
void example_profile() {
   const int npar = 15;
   double f2params[npar] =
   TF2 *f2 = new TF2("f2",fun2,-10,10,-10,10, npar);
   //Create an histogram and fill it randomly with f2
   TH2F *h2 = new TH2F("h2","from f2",10,-5,5,10,-5,5);
   int nentries = 2000;

   TCanvas *c1 = new TCanvas("","",400,600);

	 TH1D *h1 = h2->ProfileX();


The results is:

binx = 7 ---- the std Dev = 1.992 (calculated by projectionY)
but the profilex results in the lower left figure is not equal to 1.992 or 1.992/sqrt(125).

Besides, I want to get the TH1D *h1 bin error by
But, the error message is:

Best regards,

h1 is not known outside the C++ script.

1 Like


I got it. But one more question:
How to calculate the bin error of a TH1D obtained by TProfile?

@moneta will know better.
(In any case it is better to put the GetBinError call in the script itself)

1 Like

Thank you, couet.
I have solved the problem by call the GetBinError in my script, the bin error of the profileX histogram is equal to sigma(i)/sqrt(ni), where i is the binx.

TH2::ProfileX returns a TProfile, not a TH1.

Thank you for pointing this. You’re right. The function called in my cript is right.

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