#include "RooFit.h"
#include "RooQuasiRandomGenerator.h"
#include "RooQuasiRandomGenerator.h"
#include "TMath.h"
#include "Riostream.h"
#include <assert.h>
ClassImp(RooQuasiRandomGenerator)
;
RooQuasiRandomGenerator::RooQuasiRandomGenerator() {
if(!_coefsCalculated) {
calculateCoefs(MaxDimension);
_coefsCalculated= kTRUE;
}
_nextq= new Int_t[MaxDimension];
reset();
}
RooQuasiRandomGenerator::~RooQuasiRandomGenerator() {
delete[] _nextq;
}
void RooQuasiRandomGenerator::reset() {
_sequenceCount= 0;
for(Int_t dim= 0; dim < MaxDimension; dim++) _nextq[dim]= 0;
}
Bool_t RooQuasiRandomGenerator::generate(UInt_t dimension, Double_t vector[]) {
static const Double_t recip = 1.0/(double)(1U << NBits);
UInt_t dim;
for(dim=0; dim < dimension; dim++) {
vector[dim] = _nextq[dim] * recip;
}
Int_t r(0),c(_sequenceCount);
while(1) {
if((c % 2) == 1) {
++r;
c /= 2;
}
else break;
}
if(r >= NBits) {
cout << "RooQuasiRandomGenerator::generate: internal error!" << endl;
return kFALSE;
}
for(dim=0; dim<dimension; dim++) {
_nextq[dim] ^= _cj[r][dim];
}
_sequenceCount++;
return kTRUE;
}
void RooQuasiRandomGenerator::calculateCoefs(UInt_t dimension) {
int ci[NBits][NBits];
int v[NBits+MaxDegree+1];
int r;
unsigned int i_dim;
for(i_dim=0; i_dim<dimension; i_dim++) {
const int poly_index = i_dim + 1;
int j, k;
int u = 0;
int pb[MaxDegree+1];
int px[MaxDegree+1];
int px_degree = _polyDegree[poly_index];
int pb_degree = 0;
for(k=0; k<=px_degree; k++) {
px[k] = _primitivePoly[poly_index][k];
pb[k] = 0;
}
pb[0] = 1;
for(j=0; j<NBits; j++) {
if(u == 0) calculateV(px, px_degree, pb, &pb_degree, v, NBits+MaxDegree);
for(r=0; r<NBits; r++) {
ci[r][j] = v[r+u];
}
++u;
if(u == px_degree) u = 0;
}
for(r=0; r<NBits; r++) {
int term = 0;
for(j=0; j<NBits; j++) {
term = 2*term + ci[r][j];
}
_cj[r][i_dim] = term;
}
}
}
void RooQuasiRandomGenerator::calculateV(const int px[], int px_degree,
int pb[], int * pb_degree, int v[], int maxv) {
const int nonzero_element = 1;
const int arbitrary_element = 1;
int ph[MaxDegree+1];
int bigm = *pb_degree;
int m;
int r, k, kj;
for(k=0; k<=MaxDegree; k++) {
ph[k] = pb[k];
}
polyMultiply(px, px_degree, pb, *pb_degree, pb, pb_degree);
m = *pb_degree;
kj = bigm;
for(r=0; r<kj; r++) {
v[r] = 0;
}
v[kj] = 1;
if(kj >= bigm) {
for(r=kj+1; r<m; r++) {
v[r] = arbitrary_element;
}
}
else {
int term = sub(0, ph[kj]);
for(r=kj+1; r<bigm; r++) {
v[r] = arbitrary_element;
term = sub(term, mul(ph[r], v[r]));
}
v[bigm] = add(nonzero_element, term);
for(r=bigm+1; r<m; r++) {
v[r] = arbitrary_element;
}
}
for(r=0; r<=maxv-m; r++) {
int term = 0;
for(k=0; k<m; k++) {
term = sub(term, mul(pb[k], v[r+k]));
}
v[r+m] = term;
}
}
void RooQuasiRandomGenerator::polyMultiply(const int pa[], int pa_degree, const int pb[],
int pb_degree, int pc[], int * pc_degree) {
int j, k;
int pt[MaxDegree+1];
int pt_degree = pa_degree + pb_degree;
for(k=0; k<=pt_degree; k++) {
int term = 0;
for(j=0; j<=k; j++) {
const int conv_term = mul(pa[k-j], pb[j]);
term = add(term, conv_term);
}
pt[k] = term;
}
for(k=0; k<=pt_degree; k++) {
pc[k] = pt[k];
}
for(k=pt_degree+1; k<=MaxDegree; k++) {
pc[k] = 0;
}
*pc_degree = pt_degree;
}
Int_t RooQuasiRandomGenerator::_cj[RooQuasiRandomGenerator::NBits]
[RooQuasiRandomGenerator::MaxDimension];
const Int_t RooQuasiRandomGenerator::_primitivePoly[RooQuasiRandomGenerator::MaxDimension+1]
[RooQuasiRandomGenerator::MaxPrimitiveDegree+1] =
{
{ 1, 0, 0, 0, 0, 0 },
{ 0, 1, 0, 0, 0, 0 },
{ 1, 1, 0, 0, 0, 0 },
{ 1, 1, 1, 0, 0, 0 },
{ 1, 1, 0, 1, 0, 0 },
{ 1, 0, 1, 1, 0, 0 },
{ 1, 1, 0, 0, 1, 0 },
{ 1, 0, 0, 1, 1, 0 },
{ 1, 1, 1, 1, 1, 0 },
{ 1, 0, 1, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 1 },
{ 1, 1, 1, 1, 0, 1 },
{ 1, 1, 1, 0, 1, 1 }
};
const Int_t RooQuasiRandomGenerator::_polyDegree[RooQuasiRandomGenerator::MaxDimension+1] =
{
0, 1, 1, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5
};
Bool_t RooQuasiRandomGenerator::_coefsCalculated= kFALSE;
ROOT page - Class index - Class Hierarchy - Top of the page
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.