Dear Michele,
You can generalize the Poisson in the real domain as:
f(k,\lambda)=\frac{\lambda^{k} e^{-\lambda}}{k!}=\frac{e^{k \ln{\lambda}-\lambda}}{\Gamma{(k+1)}}
One possible way is to use TF1:GetRandom() :
Double_t PoissonReal(const Double_t *k, const Double_t *lambda) {
return TMath::Exp(k[0]*TMath::Log(lambda[0])-lambda[0]) /
TMath::Gamma(k[0]+1.);
}
//Max. argument expected, depends on your application. Cannot be too big
to avoid overflow in TMath::Gamma
Double_t MaxPoissArg = 99.;
TF1 MyPoisson("MyPoisson", PoissonReal,0.,MaxPoissArg,1)
//Then you should set \lambda :
MyPoisson.SetParameters(SomeLambdaValue);
//To assign a random number to variable X X = MyPoisson.GetRandom();
Cheers,
Vassili
On 03/16/2012 12:27 PM, Michele Selvaggi wrote:
> Dear ROOT experts,
>
> I am trying to generate random numbers according to a poisson
> distribution. I need non integer values. I thought the PoissonD method
> does the job, but i seem do get only int as an output.
>
> TRandom *rd = new TRandom();
> cout<<rd->Poisson(5)<<endl;
>
> I get as expected an integer, but if I do
>
> cout<<rd->PoissonD(5)<<endl;
>
> then I also get an integer.. Maybe I am using the wrong method? Isn't
> the continuous version of a poissonian still called a poissonian?
>
> Thanks
>
> Michele
Received on Fri Mar 16 2012 - 13:57:01 CET
This archive was generated by hypermail 2.2.0 : Fri Mar 16 2012 - 17:50:11 CET