Forward declaration of class TFitResult


_ROOT Version:6.08.06
_Platform:Red Hat Enterprise Linux Server release 7.7 (Maipo)
_Compiler:g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)


I tried to use the result of fitting TGraph through TFitResultPtr like:

#include <iostream>

#include "TGraph.h"
//#include "TFitResultPtr.h"                                                                 

using namespace std;

int main() {

  Double_t x[]={1.,2.,3.,4.};
  Double_t y[]={1.,2.,3.,4.};

  TGraph *g = new TGraph(4,x,y);

  cout << " test1" << endl;

  TFitResultPtr res=g->Fit("gaus","S");

  cout << " test2" << endl;

  cout << "Chi2" << res->Chi2() << endl;
  cout << "Ndf" << res->Ndf() << endl;

}

But when I compile the above, forward declaration errors are invoked.

% g++ -std=c++11 -pthread -std=c++11 -m64 -I/usr/local/gcc485/ROOT/6.08.06/include -Wall -O3 -I./include tmp.C

tmp.C: In function ‘int main()’:
tmp.C:21:24: error: invalid use of incomplete type ‘class TFitResult’
   cout << "Chi2" << res->Chi2() << endl;
                        ^
In file included from /usr/local/gcc485/ROOT/6.08.06/include/TGraph.h:51:0,
                 from tmp.C:3:
/usr/local/gcc485/ROOT/6.08.06/include/TFitResultPtr.h:29:7: error: forward declaration of ‘class TFitResult’
 class TFitResult;
       ^
tmp.C:22:23: error: invalid use of incomplete type ‘class TFitResult’
   cout << "Ndf" << res->Ndf() << endl;
                       ^
In file included from /usr/local/gcc485/ROOT/6.08.06/include/TGraph.h:51:0,
                 from tmp.C:3:
/usr/local/gcc485/ROOT/6.08.06/include/TFitResultPtr.h:29:7: error: forward declaration of ‘class TFitResult’
 class TFitResult;

I was wondering if you could give me how to avoid such errors and use the fitting results.

I myself found another way of extracting information on fit results.

  (gx is TGraphErrors)
  ...
  TF1 *fpol1_x = new TF1 (fitname,"gaus"); 
  gx->Fit(fpol1_x,"SQ");

  TF1 *fx=gx->GetFunction(fitname_x);
  //
  Double_t chi2_x=fx->GetChisquare();
  //
  Int_t ndf_x=fx->GetNDF();
  //
  return TMath::Prob(chi2_x, ndf_x);

#include "TFitResult.h"

Thanks! It works.

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