Re: [ROOT] Re: Poisson fitting

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Jan 28 2003 - 12:05:49 MET


Hi Stanislas,

I have added TMath::Poisson in the CVS head.
Your example can now be run like shown below

Rene Brun

Double_t
poissonf(Double_t*x,Double_t*par)                                         
{                                                                              
  return par[0]*TMath::Poisson(x[0],par[1]);
}                                                                              
                                                                               
void poisson() {                                                               
   TF1 pois("pois",poissonf,0,10,2); // x in [0;10], 2
parameters                  
   
   pois->SetParName(0,"Const");                                                
   pois->SetParName(1,"#mu");                                                  
   // Create histogram with poisson distribution                               
   TH1F*testhi = new TH1F("testhi","Poisson distribution",100,0,5);            
   pois->SetParameter(0,3.75654);                                              
   pois->SetParameter(1,2.95437);                                              
   testhi->FillRandom("pois",20000);                                           
                                                                               
   // Fitting it                                                               
   pois->SetParameter(0,1); // not the best shots                             
                            // 'cause we fill with 20000 events                
                            // so constant will be in 1000 times bigger        
   pois->SetParameter(1,1); // :)                                             
   TCanvas *c1 = new TCanvas("c1","Canvas",600,600);                           
   
   gStyle->SetOptStat(0);                                                      
   gStyle->SetOptFit(111);
  
   testhi->Fit("pois");                                                        
   
   testhi->Draw();                                                             
}


Stanislav Nesterov wrote:
> 
> dennis@physics.msuiit.edu.ph wrote:
> 
> >Hi rooters!
> >
> >How can i use a user-defined function such as Poisson for fitting a
> >histogram? I tried using myfit.C of the tutorials but encountered
> >problems. I hope someone could give an example. This would be a great
> >help.
> >
> >Thanks
> >
> >
> >Dennis Arogancia
> >MSU-ILigan City
> >
> >
> >
> >
> Hi Dennis,
> 
> It is very simple: exactly like in tutorial examples you should create
> wrapper function and put it in TF1 object.
> 
> See example below (or attachment) for Poisson distribution:
> 
> Double_t
> func(Double_t*x,Double_t*par)
> {
>   Double_t res=0.,
> xx=x[0];
>   if (xx<=0) return
> 0;
>   // Poisson
> distribution
>   // par[1] - distribution
> parameter
>   return
> par[0]*TMath::Power(par[1],xx)/TMath::Gamma(xx+1)/TMath::Exp(par[1]);
> }
> 
> void
> poisson()
> {
>    TF1 pois("pois",func,0,10,2); // x in [0;10], 2
> parameters
> 
> pois->SetParName(0,"Const");
> 
> pois->SetParName(1,"#mu");
>    // Create histogram with poisson
> distribution
>    TH1F*testhi = new TH1F("testhi","Poisson
> distribution",100,0,5);
> 
> pois->SetParameter(0,3.75654);
> 
> pois->SetParameter(1,2.95437);
> 
> testhi->FillRandom("pois",20000);
> 
>    // Fitting
> it
>    pois->SetParameter(0,1);  // not the best
> shots
>                             // 'cause we fill with 20000
> events
>                             // so constant will be in 1000 times
> bigger
>    pois->SetParameter(1,1);  //
> :)
>    TCanvas *cc = new
> TCanvas("cc","Canvas",600,600);
> 
> gStyle->SetOptStat(0);
>    gStyle->SetOptFit(111);
> 
>  testhi->Fit("pois");
> 
> testhi->Draw();
> }
> 
>                                                 Best reagards,
> 
>  Stanislav.
> 
>   --------------------------------------------------------------------------------
>                 Name: poisson.C
>    poisson.C    Type: Plain Text (text/plain)
>             Encoding: 7bit



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:08 MET