// Flat p.d.f. in N dimensions
// END_HTML
#include "RooFit.h"
#include "Riostream.h"
#include <math.h>
#include "RooUniform.h"
#include "RooAbsReal.h"
#include "RooRealVar.h"
#include "RooRandom.h"
#include "RooMath.h"
#include "RooArgSet.h"
ClassImp(RooUniform)
RooUniform::RooUniform(const char *name, const char *title, const RooArgSet& _x) :
RooAbsPdf(name,title),
x("x","Observables",this,kTRUE,kFALSE)
{
x.add(_x) ;
}
RooUniform::RooUniform(const RooUniform& other, const char* name) :
RooAbsPdf(other,name), x("x",this,other.x)
{
}
Double_t RooUniform::evaluate() const
{
return 1 ;
}
Int_t RooUniform::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* ) const
{
Int_t nx = x.getSize() ;
if (nx>31) {
coutW(Integration) << "RooUniform::getAnalyticalIntegral(" << GetName() << ") WARNING: p.d.f. has " << x.getSize()
<< " observables, analytical integration is only implemented for the first 31 observables" << endl ;
nx=31 ;
}
Int_t code(0) ;
for (int i=0 ; i<x.getSize() ; i++) {
if (allVars.find(x.at(i)->GetName())) {
code |= (1<<i) ;
analVars.add(*allVars.find(x.at(i)->GetName())) ;
}
}
return code ;
}
Double_t RooUniform::analyticalIntegral(Int_t code, const char* rangeName) const
{
Double_t ret(1) ;
for (int i=0 ; i<32 ; i++) {
if (code&(1<<i)) {
RooAbsRealLValue* var = (RooAbsRealLValue*)x.at(i) ;
ret *= (var->getMax(rangeName) - var->getMin(rangeName)) ;
}
}
return ret ;
}
Int_t RooUniform::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t ) const
{
Int_t nx = x.getSize() ;
if (nx>31) {
coutW(Integration) << "RooUniform::getGenerator(" << GetName() << ") WARNING: p.d.f. has " << x.getSize()
<< " observables, internal integrator is only implemented for the first 31 observables" << endl ;
nx=31 ;
}
Int_t code(0) ;
for (int i=0 ; i<x.getSize() ; i++) {
if (directVars.find(x.at(i)->GetName())) {
code |= (1<<i) ;
generateVars.add(*directVars.find(x.at(i)->GetName())) ;
}
}
return code ;
return 0 ;
}
void RooUniform::generateEvent(Int_t code)
{
for (int i=0 ; i<32 ; i++) {
if (code&(1<<i)) {
RooAbsRealLValue* var = (RooAbsRealLValue*)x.at(i) ;
var->randomize() ;
}
}
}