// Poisson pdf
// END_HTML
#include <iostream>
#include "RooPoisson.h"
#include "RooAbsReal.h"
#include "RooAbsCategory.h"
#include "RooRandom.h"
#include "RooMath.h"
#include "TMath.h"
ClassImp(RooPoisson)
RooPoisson::RooPoisson(const char *name, const char *title,
RooAbsReal& _x,
RooAbsReal& _mean) :
RooAbsPdf(name,title),
x("x","x",this,_x),
mean("mean","mean",this,_mean)
{
}
RooPoisson::RooPoisson(const RooPoisson& other, const char* name) :
RooAbsPdf(other,name),
x("x",this,other.x),
mean("mean",this,other.mean)
{
}
Double_t RooPoisson::evaluate() const
{
Double_t k = floor(x);
return TMath::Poisson(k,mean) ;
}
Int_t RooPoisson::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* ) const
{
if (matchArgs(allVars,analVars,x)) return 1 ;
return 0 ;
}
Double_t RooPoisson::analyticalIntegral(Int_t code, const char* rangeName) const
{
assert(code==1) ;
Double_t xmin = x.min(rangeName) ;
Double_t xmax = x.max(rangeName) ;
Int_t ixmin = Int_t (xmin) ;
Int_t ixmax = Int_t (xmax)+1 ;
Double_t fracLoBin = 1-(xmin-ixmin) ;
Double_t fracHiBin = ixmax-xmax ;
Double_t sum(0) ;
sum += TMath::Poisson(ixmin,mean)*fracLoBin ;
for (int i=ixmin+1 ; i<ixmax-1 ; i++) {
sum += TMath::Poisson(i,mean) ;
}
sum += TMath::Poisson(ixmax-1,mean)*fracHiBin ;
return sum ;
}
Int_t RooPoisson::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t ) const
{
if (matchArgs(directVars,generateVars,x)) return 1 ;
return 0 ;
}
void RooPoisson::generateEvent(Int_t code)
{
assert(code==1) ;
Double_t xgen ;
while(1) {
xgen = RooRandom::randomGenerator()->Poisson(mean);
if (xgen<x.max() && xgen>x.min()) {
x = xgen ;
break;
}
}
return;
}
Last change: Mon Sep 15 14:12:09 2008
Last generated: 2008-09-15 14:12
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.