Hi rooters, I'm trying to perform a fit within a loop and then access the fit parameters. I construct a TProfile histogram and a TF1 using my own function. I fill the TProfile and perform the fit. The fit works perfectly the first time round but I then get error messages such as "Function:myfunc cannot be compiled" where myfunc is the function I've defined. Consequently the fit doesn't work for any other passes of the loop. The function is defined by: Double_t myfit(Double_t *x, Double_t *par){ Double_t xval = x[0]; Double_t xfit = 0; if(xval<par[0]){ xfit = par[2]+(par[3]*(xval+100)); } if(xval>par[0]&&xval<par[1]){ xfit = (par[2]+par[3]*(par[0]+100))+(par[4]*(xval-par[0])); } if(xval>par[1]){ xfit = (par[2]+par[3]*(par[0]+100))+(par[4]*(par[1]-par[0]))+par[5]*(xval-par[1]); } return xfit; } And the code of interest in the macro is: for(Int_t c = 0; c<3; c++){ TProfile *xtalfit = new TProfile("xtalfit","xtalfit",1600, -200,1400,200,400); TF1 *func = new TF1("myfunc",myfit,-100,1300,6); func->SetParLimits(0,550,725); func->SetParLimits(1,750,900); Int_t nbytes = 0; Int_t noentries = h6->GetEntries(); for (Int_t i=0; i<noentries;i++) { nbytes += h6->GetEntry(i); if(channel==c&&(channel>chann || etc... //Fill the Profile histogram xtalfit->Fill(xpoint,ypoint); } } // Perform the fit xtalfit->Draw(); xtalfit->Fit("myfunc","","",-100,1300); // access the parameters param0 = func->GetParameter(0); param1 = func->GetParameter(1); // clean up - doesn't make any difference delete xtalfit; delete func; } Sorry if I'm missing something obvious but any help you can provide is much appreciated. Thanks, Dan. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Daniel Bowerman |Tel: +1-650-926-2767 Imperial College |Fax: +1-650-926-3767 Stanford Linear Accelerator Center | M/S 59, P.O. Box 4349 | Stanford, CA 94309, USA |bowerman@SLAC.Stanford.edu ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:35 MET