Hello rooters, I probably didnt fully understood how one declare functions and fit with it. Having to fit several gaussian spectra, I defined the following function (simplified) : void fit_on_mean(TH1 *t,int half_width,int right_shift=0) { int binm=t->FindBin(t->GetMean()); double xmin = t->GetXaxis()->GetBinCenter(binm-half_width+right_shift); double xmax = t->GetXaxis()->GetBinCenter(binm+half_width+right_shift); TF1 *f1= new TF1("f1","gaus",xmin,xmax); t->Fit("f1","RQ"); } There's a thing I dont fully understand : why does is (seems to) work ? The appropriate "f1" function 'sticks' to the histograms, even when f1 got redefined. And maybe it is not really working and this explain why I got some strange beahvior from time to time. Then I wanted to display the function outside of it's borders even if the fit itself was restricted and I tried that : void fit_on_mean(TH1 *t,int half_width,int right_shift=0) { int binm=t->FindBin(t->GetMean()); double xmin = t->GetXaxis()->GetBinCenter(binm-half_width+right_shift); double xmax = t->GetXaxis()->GetBinCenter(binm+half_width+right_shift); TF1 *f1= new TF1("f1","gaus",xmin,xmax); t->Fit("f1","RQ"); TF1 *f2= new TF1("f2","gaus"); for (int i=0;i<3;i++) f2->SetParameter(i,f1->GetParameter(i)); f2->SetLineStyle(2); f2->Draw("same"); f1->Draw("same"); } And it didnt worked at all ! What I seems to understand is that writing t->Fit("f1") somehow 'attach' f1 to t, but i'm not sure if I can completly dispose f1 after (by redefining it like I do when calling several time my function), and how I can 'attach' a function to an histogram without making any fit (in my case I only want a dashed curve that complete the displaying of the fitted function). Yannick _/ Yannick Patois _________________ Address (home) __________________ | irc(undernet): Garp on #france25+ | La Villa des Sciences | | email : patois@ganil.fr | 12, avenue de Cambridge | | web :http://www.sura.org/~patois/ | 14200 Herouville-Saint-Clair | | Tel/Fax-home:+33 (0)2 31 94 50 32 | FRANCE | |___________________________________|__________________________________|
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:24 MET