//---------this program is to draw the 2D graph of en ,angle,cs ,cserror //-------and fit them with legendre #include #include #include #include #include #include #include "TMultiGraph.h" #include #include //----------first ,construct the function using to fit //===================================================================== Double_t fit_0( Double_t *x,Double_t *y ,Double_t *par) { Double_t fitval=par[0]*TMath::Exp(par[1]*x[0])+par[2]*TMath::Exp(par[3]*x[0])+(par[4]+par[5]*x[0])/(1+par[6]*(x[0]-par[7])*(x[0]-par[7])); return fitval; } //====================================================================== //建立A1P1函数 Double_t fit_1( Double_t *x,Double_t *y ,Double_t *par) { Double_t fitval=(par[0]*TMath::Exp(par[1]*x[0])+par[2]*TMath::Exp(par[3]*x[0]))*ROOT::Math::assoc_legendre(1,0,cos(y[0]*TMath::Pi()/180)); return fitval; } //====================================================================== //建立 2 函数 Double_t fit_2( Double_t *x,Double_t *y ,Double_t *par) { Double_t fitval=(par[0]*TMath::Exp(par[1]*x[0])+par[2]*TMath::Exp(par[3]*x[0]))*ROOT::Math::assoc_legendre(2,0,cos(y[0]*TMath::Pi()/180)); return fitval; } //====================================================================== //建立 3 函数 Double_t fit_3( Double_t *x,Double_t *y ,Double_t *par) { Double_t fitval=(par[0]*TMath::Exp(par[1]*x[0])+par[2]*TMath::Exp(par[3]*x[0]))*ROOT::Math::assoc_legendre(3,0,cos(y[0]*TMath::Pi()/180)); return fitval; } //====================================================================== //建立 4 函数 Double_t fit_4( Double_t *x,Double_t *y ,Double_t *par) { Double_t fitval=(par[0]*TMath::Exp(par[1]*x[0])+par[2]*TMath::Exp(par[3]*x[0]))*ROOT::Math::assoc_legendre(4,0,cos(y[0]*TMath::Pi()/180)); return fitval; } //====================================================================== //建立 5 函数 Double_t fit_5( Double_t *x,Double_t *y ,Double_t *par) { Double_t fitval=(par[0]*TMath::Exp(par[1]*x[0])+par[2]*TMath::Exp(par[3]*x[0]))*ROOT::Math::assoc_legendre(5,0,cos(y[0]*TMath::Pi()/180)); return fitval; } //sum of the fit function Double_t fit_f( Double_t *x,Double_t *y, Double_t *par) { Double_t fitval=fit_5(x,y,&par[24])+fit_4(x,y,&par[20])+fit_3(x,y,&par[16])+fit_2(x,y,&par[12])+ fit_1(x,y,&par[8])+fit_0(x,y,par); ; return fitval; } //============================================================== //-------------------------------------------------------------- // construct the main function //-------------------------------------------------------------- //============================================================== void fit2Dg_of_diff() { int counter=71; // number of data point Double_t en[71],angle[71],cs[71],cserror[71]; Double_t ex[71]=0; Double_t ey[71]=0; double zero; int i; gSystem->Load("libMathMore.dll"); TCanvas *myc = new TCanvas("myc", "Fitting a MultiGraph of TGraphErrors"); // open the data file ifstream alldata("c:\\root\\3he\\all_normalize_data\\all_diff_data.txt"); if(!alldata) cout<<"No file"<>en[i]>>angle[i]>>cs[i]>>zero>>cserror[i]; TGraph2DErrors *f=new TGraph2DErrors(counter,en,angle,cs,ex,ey,cserror); f->Draw("surf1"); //fit TF2 *f2=new TF2("fit",fit_f,4,150,0,180,8); f->Fit("fit4"); }