Re: [ROOT] 3d fit

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue May 21 2002 - 10:06:22 MEST


Hi Pat,

an example with the file fit3d.C below.
To execute, do
root > .x fit3d.C++

Rene Brun

//file fit3d.C
#include "TF3.h"
#include "TH3.h"
   
Double_t func3(Double_t *x, Double_t *par) {
   Double_t r2 = x[0]*x[0] + x[1]*x[1] +x[2]*x[2];
   Double_t arg = (TMath::Sqrt(r2) - par[1])/par[2];
   Double_t val = par[0]*TMath::Exp(-0.5*arg*arg);
   return val;
}
void fit3d() {
   TF3 *f3 = new TF3("f3",func3,-2,2,-2,2,-2,2,3);
   f3->SetParameters(10,0,1);
   TH3F *h3 = new TH3F("h3","h3",20,-2,2,20,-2,2,20,-2,2);
   Double_t x,y,z;
   for (Int_t i=0;i<1000000;i++) {
      f3->GetRandom3(x,y,z);
      h3->Fill(x,y,z);
   }
   h3->Draw("box");
   h3->Fit(f3);
}   



Patrick Murray wrote:
> 
> Hi All,
> 
> Could someone point me in the direction of an example or send my an
> example of a 3 d fit? I want to fit some data to a surface of a sphere.
> 
> Thank you,
> 
> Pat



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:53 MET