#include "Riostream.h" void fpol2() { //THANK YOU TO @DABAGIAN //MODIFY JULY 8/2004 BY @KRISFRAJER const Int_t n = 5; char fname[100], message[50]; ifstream in; Int_t ring=2; Int_t run=3173; Int_t chann=21; Double_t p, q; Double_t x[n], y[n]; TF1 *myfit; sprintf(fname,"fpol2.dat"); in.open(fname); c1 = new TCanvas("c1","Transmission",20,50,1200,800); c1->SetFillColor(kWhite); c1->SetGrid(); //line26 myfit = new TF1("myfit","[0]+[1]*x", 3170, 3181); //I was trying to get a square fit, so a replace the //formula on myfit object to something // like "pol2" //and "[0]+[1]*x+[2]*x^2". None of this work. What //was I doing wrong? for (Int_t i=0;i> p >> q; x[i] = p; y[i] = q; printf(" i %i %f %f \n",i,x[i],y[i]); } gr = new TGraph(n,x,y); gr->SetLineColor(1); gr->SetLineWidth(1); gr->SetMarkerColor(4); gr->SetMarkerStyle(25); sprintf(message,"detector %d",chann); //line46 gr->Fit("myfit","R"); //I found out that if I write the last line as //gr->Fit("pol2"); //my program worked! myfit->Draw(); myfit->SetTitle(message); myfit->GetXaxis()->SetTitle("runs"); myfit->GetYaxis()->SetTitle("Signal Output"); gr->Draw("CP"); // TCanvas::Update() draws the frame, after // which one can change it c1->Update(); c1->GetFrame()->SetFillColor(kWhite); c1->GetFrame()->SetBorderSize(2); c1->Modified(); in.close(); }