Thanks dplparo,
Here is my code:
[code]#include
#include <math.h>
#include “TFile.h”
#include “TF2.h”
#include “TH1.h”
#include “TH1F.h”
#include “TH2F.h”
#include “TCanvas.h”
#include “TFitResult.h”
#include “TMath.h”
#include “TGraphErrors.h”
#include “TGraph2DErrors.h”
#include “TLegend.h”
#include “TApplication.h”
#include “TGraphPolar.h”
#include “TLatex.h”
#include “TMinuit.h”
#include “TProfile.h”
#include “TRandom3.h”
#include “TStyle.h”
void format_line(TAttLine* line,int col,int sty){
line->SetLineWidth(5); line->SetLineColor(col);
line->SetLineStyle(sty);}
double the_model(double* vars, double* pars){
return pars[0]*std::pow(vars[0], pars[1])*std::pow((1-std::pow(vars[0], pars[2])), pars[3]);}
int myfit(){
TCanvas* c1=new TCanvas();
c1->SetGrid();
c1->SetLogy();
TGraphErrors graph_data("./ashur_input.txt", “%lg %lg %lg”);
graph_data.SetTitle(“Inclusive Differential Cross Section of Nucleon-Air Collisions; x_F; d(Sigma)/d(x_F)”);
graph_data.SetMarkerStyle(kCircle);
graph_data.SetFillColor(0);
graph_data.Print();
gStyle->SetOptTitle(0); gStyle->SetOptStat(0);
gStyle->SetOptFit(1111); gStyle->SetStatBorderSize(0);
gStyle->SetStatX(.89); gStyle->SetStatY(.89);
TF1 model(“model”, the_model,0,0.6);
double a=1; double b=1; double c=1; double d=1;
model.SetParameters(a,b,c,d);
model.SetParNames(“a”,“b”,“c”,“d”);
format_line(&model, kBlue,1);
model.SetParameter(0,1);
model.SetParameter(1,1);
model.SetParameter(2,1);
model.SetParameter(3,1);
TFitResultPtr frp = graph_data.Fit(&model, “S”);
frp->Print();
TMatrixDSym covMatrix (frp->GetCovarianceMatrix());
covMatrix.Print();
graph_data.GetYaxis()->SetRangeUser(10,1000000);
graph_data.DrawClone(“APE”);
}
#ifndef CINT
void StandaloneApplication(int argc, char** argv) {
// eventually, evaluate the application parameters argc, argv
// ==>> here the ROOT macro is called
myfit();
}
// This is the standard “main” of C++ starting
// a ROOT application
int main(int argc, char** argv) {
TApplication app(“ROOT Application”, &argc, argv);
StandaloneApplication(app.Argc(), app.Argv());
app.Run();
return 0;
}
#endif[/code]
I am not receiving any error message during compilation and linking. However, I am not getting the expected result. Here are the runtime error messages instead:
[quote]x[0]=0.00288, y[0]=581709, ex[0]=0, ey[0]=0
x[1]=0.01152, y[1]=491107, ex[1]=0, ey[1]=0
x[2]=0.02112, y[2]=400812, ex[2]=0, ey[2]=0
x[3]=0.0336, y[3]=327119, ex[3]=0, ey[3]=0
x[4]=0.04896, y[4]=249493, ex[4]=0, ey[4]=0
x[5]=0.05952, y[5]=210634, ex[5]=0, ey[5]=0
x[6]=0.07584, y[6]=166184, ex[6]=0, ey[6]=0
x[7]=0.09024, y[7]=145133, ex[7]=0, ey[7]=0
x[8]=0.10656, y[8]=114505, ex[8]=0, ey[8]=0
x[9]=0.11904, y[9]=96670.5, ex[9]=0, ey[9]=0
x[10]=0.1392, y[10]=76269.9, ex[10]=0, ey[10]=0
x[11]=0.15648, y[11]=60174.4, ex[11]=0, ey[11]=0
x[12]=0.17472, y[12]=49110.7, ex[12]=0, ey[12]=0
x[13]=0.1968, y[13]=37456.7, ex[13]=0, ey[13]=0
x[14]=0.2112, y[14]=32711.9, ex[14]=0, ey[14]=0
x[15]=0.22752, y[15]=27617, ex[15]=0, ey[15]=0
x[16]=0.24384, y[16]=23315.6, ex[16]=0, ey[16]=0
x[17]=0.26208, y[17]=18395.3, ex[17]=0, ey[17]=0
x[18]=0.28032, y[18]=15013.1, ex[18]=0, ey[18]=0
x[19]=0.29952, y[19]=12252.8, ex[19]=0, ey[19]=0
x[20]=0.31488, y[20]=10344.4, ex[20]=0, ey[20]=0
x[21]=0.33216, y[21]=8442.49, ex[21]=0, ey[21]=0
x[22]=0.34848, y[22]=7127.56, ex[22]=0, ey[22]=0
x[23]=0.36192, y[23]=6224.69, ex[23]=0, ey[23]=0
x[24]=0.37824, y[24]=5080.22, ex[24]=0, ey[24]=0
x[25]=0.39264, y[25]=4288.97, ex[25]=0, ey[25]=0
x[26]=0.41184, y[26]=3383.86, ex[26]=0, ey[26]=0
x[27]=0.42912, y[27]=2761.7, ex[27]=0, ey[27]=0
x[28]=0.4464, y[28]=2178.89, ex[28]=0, ey[28]=0
x[29]=0.45696, y[29]=1902.88, ex[29]=0, ey[29]=0
x[30]=0.47424, y[30]=1553.02, ex[30]=0, ey[30]=0
x[31]=0.49152, y[31]=1225.28, ex[31]=0, ey[31]=0
x[32]=0.5136, y[32]=873.326, ex[32]=0, ey[32]=0
x[33]=0.52992, y[33]=712.756, ex[33]=0, ey[33]=0
x[34]=0.54048, y[34]=622.469, ex[34]=0, ey[34]=0
x[35]=0.55296, y[35]=543.618, ex[35]=0, ey[35]=0
x[36]=0.56832, y[36]=428.897, ex[36]=0, ey[36]=0
x[37]=0.57888, y[37]=362.096, ex[37]=0, ey[37]=0
x[38]=0.59328, y[38]=285.682, ex[38]=0, ey[38]=0
Error in : function model has illegal number of parameters = 0
Error in : TFitResult is empty - use the fit option S
FitResult::Print - Error: Empty FitResult !
Error in : TFitResult is empty - use the fit option S
Warning in TFitResult::GetCovarianceMatrix: covariance matrix is not available
0x0 matrix is as follows
[/quote]
I am getting the data point read from the file but nothing about the fit. Can you see my mistakes?
Thanks