52 _valid(kFALSE), _dim(0), _bins(0), _boxes(0), _vol(0), _xl(0), _xu(0), _delx(0), _d(0), _xi(0), _xin(0), _weight(0)
60 RooGrid::RooGrid(
const RooAbsFunc &
function)
61 : _valid(kTRUE), _xl(0),_xu(0),_delx(0),_xi(0)
64 if(!(_valid=
function.isValid())) {
65 oocoutE((TObject*)0,InputArguments) << ClassName() <<
": cannot initialize using an invalid function" << endl;
70 _dim=
function.getDimension();
71 _xl=
new Double_t[_dim];
72 _xu=
new Double_t[_dim];
73 _delx=
new Double_t[_dim];
74 _d=
new Double_t[_dim*maxBins];
75 _xi=
new Double_t[_dim*(maxBins+1)];
76 _xin=
new Double_t[maxBins+1];
77 _weight=
new Double_t[maxBins];
78 if(!_xl || !_xu || !_delx || !_d || !_xi || !_xin || !_weight) {
79 oocoutE((TObject*)0,Integration) << ClassName() <<
": memory allocation failed" << endl;
85 _valid= initialize(
function);
96 if(_delx)
delete[] _delx;
99 if(_xin)
delete[] _xin;
100 if(_weight)
delete[] _weight;
109 Bool_t RooGrid::initialize(
const RooAbsFunc &
function)
113 for(UInt_t index= 0; index < _dim; index++) {
114 _xl[index]=
function.getMinLimit(index);
115 if(RooNumber::isInfinite(_xl[index])) {
116 oocoutE((TObject*)0,Integration) << ClassName() <<
": lower limit of dimension " << index <<
" is infinite" << endl;
119 _xu[index]=
function.getMaxLimit(index);
120 if(RooNumber::isInfinite(_xl[index])) {
121 oocoutE((TObject*)0,Integration) << ClassName() <<
": upper limit of dimension " << index <<
" is infinite" << endl;
124 Double_t dx= _xu[index] - _xl[index];
126 oocoutE((TObject*)0,Integration) << ClassName() <<
": bad range for dimension " << index <<
": [" << _xl[index]
127 <<
"," << _xu[index] <<
"]" << endl;
145 void RooGrid::resize(UInt_t bins)
148 if(bins == _bins)
return;
151 Double_t pts_per_bin = (Double_t) _bins / (Double_t) bins;
154 for (UInt_t j = 0; j < _dim; j++) {
155 Double_t xold,xnew(0),dw(0);
160 for(k = 1; k <= _bins; k++) {
164 while(dw > pts_per_bin) {
166 newCoord(i++)= xnew - (xnew - xold) * dw;
170 for(k = 1 ; k < bins; k++) {
171 coord(k, j) = newCoord(k);
182 void RooGrid::resetValues()
184 for(UInt_t i = 0; i < _bins; i++) {
185 for (UInt_t j = 0; j < _dim; j++) {
199 void RooGrid::generatePoint(
const UInt_t box[], Double_t x[], UInt_t bin[], Double_t &vol,
200 Bool_t useQuasiRandom)
const
206 RooRandom::quasi(_dim,x);
209 RooRandom::uniform(_dim,x);
213 for(UInt_t j= 0; j < _dim; ++j) {
217 Double_t z= ((box[j] + x[j])/_boxes)*_bins;
224 Double_t y, bin_width;
226 bin_width= coord(1,j);
230 bin_width= coord(k+1,j) - coord(k,j);
231 y= coord(k,j) + (z-k)*bin_width;
234 x[j] = _xl[j] + y*_delx[j];
247 void RooGrid::firstBox(UInt_t box[])
const
249 for(UInt_t i= 0; i < _dim; i++) box[i]= 0;
259 Bool_t RooGrid::nextBox(UInt_t box[])
const
265 box[j]= (box[j] + 1) % _boxes;
266 if (0 != box[j])
return kTRUE;
278 void RooGrid::printMultiline(ostream& os, Int_t , Bool_t verbose, TString indent)
const
280 os << ClassName() <<
": volume = " << getVolume() << endl;
281 os << indent <<
" Has " << getDimension() <<
" dimension(s) each subdivided into "
282 << getNBins() <<
" bin(s) and sampled with " << _boxes <<
" box(es)" << endl;
283 for(UInt_t index= 0; index < getDimension(); index++) {
284 os << indent <<
" (" << index <<
") ["
285 << setw(10) << _xl[index] <<
"," << setw(10) << _xu[index] <<
"]" << endl;
286 if(!verbose)
continue;
287 for(UInt_t bin= 0; bin < _bins; bin++) {
288 os << indent <<
" bin-" << bin <<
" : x = " << coord(bin,index) <<
" , y = "
289 << value(bin,index) << endl;
298 void RooGrid::printName(ostream& os)
const
307 void RooGrid::printTitle(ostream& os)
const
316 void RooGrid::printClassName(ostream& os)
const
318 os << IsA()->GetName() ;
327 void RooGrid::accumulate(
const UInt_t bin[], Double_t amount)
329 for(UInt_t j = 0; j < _dim; j++) value(bin[j],j) += amount;
339 void RooGrid::refine(Double_t alpha)
341 for (UInt_t j = 0; j < _dim; j++) {
345 Double_t oldg = value(0,j);
346 Double_t newg = value(1,j);
347 value(0,j)= (oldg + newg)/2;
348 Double_t grid_tot_j = value(0,j);
352 for (i = 1; i < _bins - 1; i++) {
353 Double_t rc = oldg + newg;
356 value(i,j)= (rc + newg)/3;
357 grid_tot_j+= value(i,j);
359 value(_bins-1,j)= (newg + oldg)/2;
360 grid_tot_j+= value(_bins-1,j);
364 Double_t tot_weight(0);
365 for (i = 0; i < _bins; i++) {
367 if (value(i,j) > 0) {
368 oldg = grid_tot_j/value(i,j);
370 _weight[i] = TMath::Power(((oldg-1.0)/oldg/log(oldg)), alpha);
372 tot_weight += _weight[i];
375 Double_t pts_per_bin = tot_weight / _bins;
383 for (k = 0; k < _bins; k++) {
388 while(dw > pts_per_bin) {
390 newCoord(i++) = xnew - (xnew - xold) * dw / _weight[k];
394 for (k = 1 ; k < _bins ; k++) {
395 coord( k, j) = newCoord(k);