Logo ROOT   6.07/09
Reference Guide
RooNDKeysPdf.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitModels *
4  * File: $Id: RooNDKeysPdf.cxx 31258 2009-11-17 22:41:06Z wouter $
5  * Authors: *
6  * Max Baak, CERN, mbaak@cern.ch *
7  * *
8  * Redistribution and use in source and binary forms, *
9  * with or without modification, are permitted according to the terms *
10  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
11  *****************************************************************************/
12 #include <iostream>
13 #include <algorithm>
14 #include <string>
15 
16 #include "TMath.h"
17 #include "TMatrixDSymEigen.h"
18 #include "RooNDKeysPdf.h"
19 #include "RooAbsReal.h"
20 #include "RooRealVar.h"
21 #include "RooRandom.h"
22 #include "RooDataSet.h"
23 #include "RooHist.h"
24 #include "RooMsgService.h"
25 
26 /**
27 \file RooNDKeysPdf.cxx
28 \class RooNDKeysPdf
29 \ingroup Roofit
30 
31 Generic N-dimensional implementation of a kernel estimation p.d.f. This p.d.f. models the distribution
32 of an arbitrary input dataset as a superposition of Gaussian kernels, one for each data point,
33 each contributing 1/N to the total integral of the p.d.f.
34 If the 'adaptive mode' is enabled, the width of the Gaussian is adaptively calculated from the
35 local density of events, i.e. narrow for regions with high event density to preserve details and
36 wide for regions with log event density to promote smoothness. The details of the general algorithm
37 are described in the following paper:
38 Cranmer KS, Kernel Estimation in High-Energy Physics.
39  Computer Physics Communications 136:198-207,2001 - e-Print Archive: hep ex/0011057
40 For multi-dimensional datasets, the kernels are modeled by multidimensional Gaussians. The kernels are
41 constructed such that they reflect the correlation coefficients between the observables
42 in the input dataset.
43 **/
44 
45 #include "TError.h"
46 
47 using namespace std;
48 
50 
51 
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Construct N-dimensional kernel estimation p.d.f. in observables 'varList'
55 /// from dataset 'data'. Options can be
56 ///
57 /// 'a' = Use adaptive kernels (width varies with local event density)
58 /// 'm' = Mirror data points over observable boundaries. Improves modeling
59 /// behavior at edges for distributions that are not close to zero
60 /// at edge
61 /// 'd' = Debug flag
62 /// 'v' = Verbose flag
63 ///
64 /// The parameter rho (default = 1) provides an overall scale factor that can
65 /// be applied to the bandwith calculated for each kernel. The nSigma parameter
66 /// determines the size of the box that is used to search for contributing kernels
67 /// around a given point in observable space. The nSigma parameters is used
68 /// in case of non-adaptive bandwidths and for the 1st non-adaptive pass for
69 /// the calculation of adaptive keys p.d.f.s.
70 ///
71 /// The optional weight arguments allows to specify an observable or function
72 /// expression in observables that specifies the weight of each event.
73 
74 RooNDKeysPdf::RooNDKeysPdf(const char *name, const char *title,
75  const RooArgList& varList, RooDataSet& data,
76  TString options, Double_t rho, Double_t nSigma, Bool_t rotate) :
77  RooAbsPdf(name,title),
78  _varList("varList","List of variables",this),
79  _data(data),
80  _options(options),
81  _widthFactor(rho),
82  _nSigma(nSigma),
83  _weights(&_weights0),
84  _rotate(rotate)
85 {
86  // Constructor
87  _varItr = _varList.createIterator() ;
88 
89  TIterator* varItr = varList.createIterator() ;
90  RooAbsArg* var ;
91  for (Int_t i=0; (var = (RooAbsArg*)varItr->Next()); ++i) {
92  if (!dynamic_cast<RooAbsReal*>(var)) {
93  coutE(InputArguments) << "RooNDKeysPdf::ctor(" << GetName() << ") ERROR: variable " << var->GetName()
94  << " is not of type RooAbsReal" << endl ;
95  R__ASSERT(0) ;
96  }
97  _varList.add(*var) ;
98  _varName.push_back(var->GetName());
99  }
100  delete varItr ;
101 
102  createPdf();
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// Constructor
107 
108 RooNDKeysPdf::RooNDKeysPdf(const char *name, const char *title,
109  const RooArgList& varList, RooDataSet& data, const TVectorD& rho,
110  TString options, Double_t nSigma, Bool_t rotate) :
111  RooAbsPdf(name,title),
112  _varList("varList","List of variables",this),
113  _data(data),
114  _options(options),
115  _widthFactor(-1.0),
116  _nSigma(nSigma),
117  _weights(&_weights0),
118  _rotate(rotate)
119 {
121 
122  TIterator* varItr = varList.createIterator() ;
123  RooAbsArg* var ;
124  for (Int_t i=0; (var = (RooAbsArg*)varItr->Next()); ++i) {
125  if (!dynamic_cast<RooAbsReal*>(var)) {
126  coutE(InputArguments) << "RhhNDKeysPdf::ctor(" << GetName() << ") ERROR: variable " << var->GetName()
127  << " is not of type RooAbsReal" << endl ;
128  R__ASSERT(0) ;
129  }
130  _varList.add(*var) ;
131  _varName.push_back(var->GetName());
132  }
133  delete varItr ;
134 
135  // copy rho widths
136  if( _varList.getSize() != rho.GetNrows() ) {
137  coutE(InputArguments) << "ERROR: RhhNDKeysPdf::RhhNDKeysPdf() : The vector-size of rho is different from that of varList."
138  << "Unable to create the PDF." << endl;
139  R__ASSERT ( _varList.getSize()==rho.GetNrows() );
140  }
141 
142  // negative width factor will serve as a switch in initialize()
143  // negative value means that a vector has been provided as input,
144  // and that _rho has already been set ...
145  _rho.resize( rho.GetNrows() );
146  for (Int_t j=0; j<rho.GetNrows(); j++) { _rho[j]=rho[j]; /*cout<<"RooNDKeysPdf c'tor, _rho["<<j<<"]="<<_rho[j]<<endl;*/ }
147 
148  createPdf(); // calls initialize ...
149 }
150 
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Backward compatibility constructor for (1-dim) RooKeysPdf. If you are a new user,
154 /// please use the first constructor form.
155 
156 RooNDKeysPdf::RooNDKeysPdf(const char *name, const char *title,
157  RooAbsReal& x, RooDataSet& data,
158  Mirror mirror, Double_t rho, Double_t nSigma, Bool_t rotate) :
159  RooAbsPdf(name,title),
160  _varList("varList","List of variables",this),
161  _data(data),
162  _options("a"),
163  _widthFactor(rho),
164  _nSigma(nSigma),
166  _rotate(rotate)
167 {
169 
170  _varList.add(x) ;
171  _varName.push_back(x.GetName());
172 
173  if (mirror!=NoMirror) {
174  if (mirror!=MirrorBoth)
175  coutW(InputArguments) << "RooNDKeysPdf::RooNDKeysPdf() : Warning : asymmetric mirror(s) no longer supported." << endl;
176  _options="m";
177  }
178 
179  createPdf();
180 }
181 
182 
183 
184 ////////////////////////////////////////////////////////////////////////////////
185 /// Backward compatibility constructor for Roo2DKeysPdf. If you are a new user,
186 /// please use the first constructor form.
187 
188 RooNDKeysPdf::RooNDKeysPdf(const char *name, const char *title, RooAbsReal& x, RooAbsReal & y,
189  RooDataSet& data, TString options, Double_t rho, Double_t nSigma, Bool_t rotate) :
190  RooAbsPdf(name,title),
191  _varList("varList","List of variables",this),
192  _data(data),
193  _options(options),
194  _widthFactor(rho),
195  _nSigma(nSigma),
197  _rotate(rotate)
198 {
200 
201  _varList.add(RooArgSet(x,y)) ;
202  _varName.push_back(x.GetName());
203  _varName.push_back(y.GetName());
204 
205  createPdf();
206 }
207 
208 
209 
210 ////////////////////////////////////////////////////////////////////////////////
211 /// Constructor
212 
213 RooNDKeysPdf::RooNDKeysPdf(const RooNDKeysPdf& other, const char* name) :
214  RooAbsPdf(other,name),
215  _varList("varList",this,other._varList),
216  _data(other._data),
217  _options(other._options),
218  _widthFactor(other._widthFactor),
219  _nSigma(other._nSigma),
221  _rotate(other._rotate)
222 {
224 
225  _fixedShape = other._fixedShape;
226  _mirror = other._mirror;
227  _debug = other._debug;
228  _verbose = other._verbose;
229  _sqrt2pi = other._sqrt2pi;
230  _nDim = other._nDim;
231  _nEvents = other._nEvents;
232  _nEventsM = other._nEventsM;
233  _nEventsW = other._nEventsW;
234  _d = other._d;
235  _n = other._n;
236  _dataPts = other._dataPts;
237  _dataPtsR = other._dataPtsR;
238  _weights0 = other._weights0;
239  _weights1 = other._weights1;
240  if (_options.Contains("a")) { _weights = &_weights1; }
241  //_sortIdcs = other._sortIdcs;
242  _sortTVIdcs = other._sortTVIdcs;
243  _varName = other._varName;
244  _rho = other._rho;
245  _x = other._x;
246  _x0 = other._x0 ;
247  _x1 = other._x1 ;
248  _x2 = other._x2 ;
249  _xDatLo = other._xDatLo;
250  _xDatHi = other._xDatHi;
251  _xDatLo3s = other._xDatLo3s;
252  _xDatHi3s = other._xDatHi3s;
253  _mean = other._mean;
254  _sigma = other._sigma;
255 
256  // BoxInfo
257  _netFluxZ = other._netFluxZ;
258  _nEventsBW = other._nEventsBW;
259  _nEventsBMSW = other._nEventsBMSW;
260  _xVarLo = other._xVarLo;
261  _xVarHi = other._xVarHi;
262  _xVarLoM3s = other._xVarLoM3s;
263  _xVarLoP3s = other._xVarLoP3s;
264  _xVarHiM3s = other._xVarHiM3s;
265  _xVarHiP3s = other._xVarHiP3s;
266  _bpsIdcs = other._bpsIdcs;
267  _sIdcs = other._sIdcs;
268  _bIdcs = other._bIdcs;
269  _bmsIdcs = other._bmsIdcs;
270 
272  _fullBoxInfo = other._fullBoxInfo ;
273 
274  _idx = other._idx;
275  _minWeight = other._minWeight;
276  _maxWeight = other._maxWeight;
277  _wMap = other._wMap;
278 
279  _covMat = new TMatrixDSym(*other._covMat);
280  _corrMat = new TMatrixDSym(*other._corrMat);
281  _rotMat = new TMatrixD(*other._rotMat);
282  _sigmaR = new TVectorD(*other._sigmaR);
283  _dx = new TVectorD(*other._dx);
284  _sigmaAvgR = other._sigmaAvgR;
285 }
286 
287 
288 
289 ////////////////////////////////////////////////////////////////////////////////
290 
292 {
293  if (_varItr) delete _varItr;
294  if (_covMat) delete _covMat;
295  if (_corrMat) delete _corrMat;
296  if (_rotMat) delete _rotMat;
297  if (_sigmaR) delete _sigmaR;
298  if (_dx) delete _dx;
299 
300  // delete all the boxinfos map
301  while ( !_rangeBoxInfo.empty() ) {
302  map<pair<string,int>,BoxInfo*>::iterator iter = _rangeBoxInfo.begin();
303  BoxInfo* box= (*iter).second;
304  _rangeBoxInfo.erase(iter);
305  delete box;
306  }
307 
308  _dataPts.clear();
309  _dataPtsR.clear();
310  _weights0.clear();
311  _weights1.clear();
312  //_sortIdcs.clear();
313  _sortTVIdcs.clear();
314 }
315 
316 
317 void
318 
319 ////////////////////////////////////////////////////////////////////////////////
320 /// evaluation order of constructor.
321 
323 {
324  if (firstCall) {
325  // set options
326  setOptions();
327  // initialization
328  initialize();
329  }
330 
331 
332  // copy dataset, calculate sigma_i's, determine min and max event weight
333  loadDataSet(firstCall);
334 
335  // mirror dataset around dataset boundaries -- does not depend on event weights
336  if (_mirror) mirrorDataSet();
337 
338  // store indices and weights of events with high enough weights
339  loadWeightSet();
340 
341 
342  // store indices of events in variable boundaries and box shell.
343 //calculateShell(&_fullBoxInfo);
344  // calculate normalization needed in analyticalIntegral()
345 //calculatePreNorm(&_fullBoxInfo);
346 
347  // lookup table for determining which events contribute to a certain coordinate
348  sortDataIndices();
349 
350  // determine static and/or adaptive bandwidth
352 
353 }
354 
355 
356 void
357 
358 ////////////////////////////////////////////////////////////////////////////////
359 /// set the configuration
360 
362 {
363  _options.ToLower();
364 
365  if( _options.Contains("a") ) { _weights = &_weights1; }
366  else { _weights = &_weights0; }
367  if( _options.Contains("m") ) _mirror = true;
368  else _mirror = false;
369  if( _options.Contains("d") ) _debug = true;
370  else _debug = false;
371  if( _options.Contains("v") ) { _debug = true; _verbose = true; }
372  else { _debug = false; _verbose = false; }
373 
374  cxcoutD(InputArguments) << "RooNDKeysPdf::setOptions() options = " << _options
375  << "\n\tbandWidthType = " << _options.Contains("a")
376  << "\n\tmirror = " << _mirror
377  << "\n\tdebug = " << _debug
378  << "\n\tverbose = " << _verbose
379  << endl;
380 
381  if (_nSigma<2.0) {
382  coutW(InputArguments) << "RooNDKeysPdf::setOptions() : Warning : nSigma = " << _nSigma << " < 2.0. "
383  << "Calculated normalization could be too large."
384  << endl;
385  }
386 }
387 
388 
389 void
390 
391 ////////////////////////////////////////////////////////////////////////////////
392 /// initialization
393 
395 {
396  _sqrt2pi = sqrt(2.0*TMath::Pi()) ;
397  _nDim = _varList.getSize();
401 
402  _netFluxZ = kFALSE;
403  _nEventsBW = 0;
404  _nEventsBMSW = 0;
405 
406  if(_nDim==0) {
407  coutE(InputArguments) << "ERROR: RooNDKeysPdf::initialize() : The observable list is empty. "
408  << "Unable to begin generating the PDF." << endl;
409  R__ASSERT (_nDim!=0);
410  }
411 
412  if(_nEvents==0) {
413  coutE(InputArguments) << "ERROR: RooNDKeysPdf::initialize() : The input data set is empty. "
414  << "Unable to begin generating the PDF." << endl;
415  R__ASSERT (_nEvents!=0);
416  }
417 
418  _d = static_cast<Double_t>(_nDim);
419 
420  vector<Double_t> dummy(_nDim,0.);
421  _dataPts.resize(_nEvents,dummy);
422  _weights0.resize(_nEvents,dummy);
423  //_sortIdcs.resize(_nDim);
424  _sortTVIdcs.resize(_nDim);
425 
426  //rdh _rho.resize(_nDim,_widthFactor);
427 
428  if (_widthFactor>0) { _rho.resize(_nDim,_widthFactor); }
429  // else: _rho has been provided as external input
430 
431  _x.resize(_nDim,0.);
432  _x0.resize(_nDim,0.);
433  _x1.resize(_nDim,0.);
434  _x2.resize(_nDim,0.);
435 
436  _mean.resize(_nDim,0.);
437  _sigma.resize(_nDim,0.);
438 
439  _xDatLo.resize(_nDim,0.);
440  _xDatHi.resize(_nDim,0.);
441  _xDatLo3s.resize(_nDim,0.);
442  _xDatHi3s.resize(_nDim,0.);
443 
444  boxInfoInit(&_fullBoxInfo,0,0xFFFF);
445 
446  _minWeight=0;
447  _maxWeight=0;
448  _wMap.clear();
449 
450  _covMat = 0;
451  _corrMat= 0;
452  _rotMat = 0;
453  _sigmaR = 0;
454  _dx = new TVectorD(_nDim); _dx->Zero();
455  _dataPtsR.resize(_nEvents,*_dx);
456 
457  _varItr->Reset() ;
458  RooRealVar* var ;
459  for(Int_t j=0; (var=(RooRealVar*)_varItr->Next()); ++j) {
460  _xDatLo[j] = var->getMin();
461  _xDatHi[j] = var->getMax();
462  }
463 }
464 
465 
466 void
467 
468 ////////////////////////////////////////////////////////////////////////////////
469 /// copy the dataset and calculate some useful variables
470 
472 {
473  // first some initialization
474  _nEventsW=0.;
475 
476  TMatrixD mat(_nDim,_nDim);
477  if (!_covMat) _covMat = new TMatrixDSym(_nDim);
478  if (!_corrMat) _corrMat= new TMatrixDSym(_nDim);
479  if (!_rotMat) _rotMat = new TMatrixD(_nDim,_nDim);
480  if (!_sigmaR) _sigmaR = new TVectorD(_nDim);
481 
482  mat.Zero();
483  _covMat->Zero();
484  _corrMat->Zero();
485  _rotMat->Zero();
486  _sigmaR->Zero();
487 
488  const RooArgSet* values= _data.get();
489  vector<RooRealVar*> dVars(_nDim);
490  for (Int_t j=0; j<_nDim; j++) {
491  dVars[j] = (RooRealVar*)values->find(_varName[j].c_str());
492  _x0[j]=_x1[j]=_x2[j]=0.;
493  }
494 
495  _idx.clear();
496  for (Int_t i=0; i<_nEvents; i++) {
497 
498  _data.get(i); // fills dVars
499  _idx.push_back(i);
500  vector<Double_t>& point = _dataPts[i];
501  TVectorD& pointV = _dataPtsR[i];
502 
503  Double_t myweight = _data.weight(); // default is one?
504  if ( TMath::Abs(myweight)>_maxWeight ) { _maxWeight = TMath::Abs(myweight); }
505  _nEventsW += myweight;
506 
507  for (Int_t j=0; j<_nDim; j++) {
508  for (Int_t k=0; k<_nDim; k++) {
509  mat(j,k) += dVars[j]->getVal() * dVars[k]->getVal() * myweight;
510  }
511  // only need to do once
512  if (firstCall)
513  point[j] = pointV[j] = dVars[j]->getVal();
514 
515  _x0[j] += 1. * myweight;
516  _x1[j] += point[j] * myweight ;
517  _x2[j] += point[j] * point[j] * myweight ;
518  if (_x2[j]!=_x2[j]) exit(3);
519 
520  // only need to do once
521  if (firstCall) {
522  if (point[j]<_xDatLo[j]) { _xDatLo[j]=point[j]; }
523  if (point[j]>_xDatHi[j]) { _xDatHi[j]=point[j]; }
524  }
525  }
526  }
527 
528  _n = TMath::Power(4./(_nEventsW*(_d+2.)), 1./(_d+4.)) ;
529  // = (4/[n(dim(R) + 2)])^1/(dim(R)+4); dim(R) = 2
530  _minWeight = (0.5 - TMath::Erf(_nSigma/sqrt(2.))/2.) * _maxWeight;
531 
532  for (Int_t j=0; j<_nDim; j++) {
533  _mean[j] = _x1[j]/_x0[j];
534  _sigma[j] = sqrt(_x2[j]/_x0[j]-_mean[j]*_mean[j]);
535  }
536 
537  TMatrixDSym covMatRho(_nDim); // covariance matrix times rho parameters
538  for (Int_t j=0; j<_nDim; j++) {
539  for (Int_t k=0; k<_nDim; k++) {
540  (*_covMat)(j,k) = mat(j,k)/_x0[j] - _mean[j]*_mean[k];
541  covMatRho(j,k) = (mat(j,k)/_x0[j] - _mean[j]*_mean[k]) * _rho[j] * _rho[k];
542  }
543  }
544 
545  // find decorrelation matrix and eigenvalues (R)
546  TMatrixDSymEigen evCalculatorRho(covMatRho);
547  *_rotMat = evCalculatorRho.GetEigenVectors();
548  *_rotMat = _rotMat->T(); // transpose
549  *_sigmaR = evCalculatorRho.GetEigenValues();
550 
551 
552  // set rho = 1 because sigmaR now contains rho
553  for (Int_t j=0; j<_nDim; j++) { _rho[j] = 1.; }
554 
555  for (Int_t j=0; j<_nDim; j++) { (*_sigmaR)[j] = sqrt((*_sigmaR)[j]); }
556 
557  for (Int_t j=0; j<_nDim; j++) {
558  for (Int_t k=0; k<_nDim; k++)
559  (*_corrMat)(j,k) = (*_covMat)(j,k)/(_sigma[j]*_sigma[k]) ;
560  }
561 
562  if (_verbose) {
563  //_covMat->Print();
564  _rotMat->Print();
565  _corrMat->Print();
566  _sigmaR->Print();
567  }
568 
569  if (!_rotate) {
570  _rotMat->Print();
571  _sigmaR->Print();
572  TMatrixD haar(_nDim,_nDim);
573  TMatrixD unit(TMatrixD::kUnit,haar);
574  *_rotMat = unit;
575  for (Int_t j=0; j<_nDim; j++) { (*_sigmaR)[j] = _sigma[j]; }
576  _rotMat->Print();
577  _sigmaR->Print();
578  }
579 
580  // use raw sigmas (without rho) for sigmaAvgR
581  TMatrixDSymEigen evCalculator(*_covMat);
582  TVectorD sigmaRraw = evCalculator.GetEigenValues();
583  for (Int_t j=0; j<_nDim; j++) { sigmaRraw[j] = sqrt(sigmaRraw[j]); }
584 
585  _sigmaAvgR=1.;
586  //for (Int_t j=0; j<_nDim; j++) { _sigmaAvgR *= (*_sigmaR)[j]; }
587  for (Int_t j=0; j<_nDim; j++) { _sigmaAvgR *= sigmaRraw[j]; }
589 
590  for (Int_t i=0; i<_nEvents; i++) {
591 
592  TVectorD& pointR = _dataPtsR[i];
593  pointR *= *_rotMat;
594  }
595 
596  coutI(Contents) << "RooNDKeysPdf::loadDataSet(" << this << ")"
597  << "\n Number of events in dataset: " << _nEvents
598  << "\n Weighted number of events in dataset: " << _nEventsW
599  << endl;
600 }
601 
602 
603 void
604 
605 ////////////////////////////////////////////////////////////////////////////////
606 /// determine mirror dataset.
607 /// mirror points are added around the physical boundaries of the dataset
608 /// Two steps:
609 /// 1. For each entry, determine if it should be mirrored (the mirror configuration).
610 /// 2. For each mirror configuration, make the mirror points.
611 
613 {
614  for (Int_t j=0; j<_nDim; j++) {
615  _xDatLo3s[j] = _xDatLo[j] + _nSigma * (_rho[j] * _n * _sigma[j]);
616  _xDatHi3s[j] = _xDatHi[j] - _nSigma * (_rho[j] * _n * _sigma[j]);
617 
618  //cout<<"xDatLo3s["<<j<<"]="<<_xDatLo3s[j]<<endl;
619  //cout<<"xDatHi3s["<<j<<"]="<<_xDatHi3s[j]<<endl;
620  }
621 
622  vector<Double_t> dummy(_nDim,0.);
623 
624  // 1.
625  for (Int_t i=0; i<_nEvents; i++) {
626  vector<Double_t>& x = _dataPts[i];
627 
628  Int_t size = 1;
629  vector<vector<Double_t> > mpoints(size,dummy);
630  vector<vector<Int_t> > mjdcs(size);
631 
632  // create all mirror configurations for event i
633  for (Int_t j=0; j<_nDim; j++) {
634 
635  vector<Int_t>& mjdxK = mjdcs[0];
636  vector<Double_t>& mpointK = mpoints[0];
637 
638  // single mirror *at physical boundaries*
639  if ((x[j]>_xDatLo[j] && x[j]<_xDatLo3s[j]) && x[j]<(_xDatLo[j]+_xDatHi[j])/2.) {
640  mpointK[j] = 2.*_xDatLo[j]-x[j];
641  mjdxK.push_back(j);
642  } else if ((x[j]<_xDatHi[j] && x[j]>_xDatHi3s[j]) && x[j]>(_xDatLo[j]+_xDatHi[j])/2.) {
643  mpointK[j] = 2.*_xDatHi[j]-x[j];
644  mjdxK.push_back(j);
645  }
646  }
647 
648  vector<Int_t>& mjdx0 = mjdcs[0];
649  // no mirror point(s) for this event
650  if (size==1 && mjdx0.size()==0) continue;
651 
652  // 2.
653  // generate all mirror points for event i
654  vector<Int_t>& mjdx = mjdcs[0];
655  vector<Double_t>& mpoint = mpoints[0];
656 
657  // number of mirror points for this mirror configuration
658  Int_t eMir = 1 << mjdx.size();
659  vector<vector<Double_t> > epoints(eMir,x);
660 
661  for (Int_t m=0; m<Int_t(mjdx.size()); m++) {
662  Int_t size1 = 1 << m;
663  Int_t size2 = 1 << (m+1);
664  // copy all previous mirror points
665  for (Int_t l=size1; l<size2; ++l) {
666  epoints[l] = epoints[l-size1];
667  // fill high mirror points
668  vector<Double_t>& epoint = epoints[l];
669  epoint[mjdx[Int_t(mjdx.size()-1)-m]] = mpoint[mjdx[Int_t(mjdx.size()-1)-m]];
670  }
671  }
672 
673  // remove duplicate mirror points
674  // note that: first epoint == x
675  epoints.erase(epoints.begin());
676 
677  // add mirror points of event i to total dataset
678  TVectorD pointR(_nDim);
679 
680  for (Int_t m=0; m<Int_t(epoints.size()); m++) {
681  _idx.push_back(i);
682  _dataPts.push_back(epoints[m]);
683  //_weights0.push_back(_weights0[i]);
684  for (Int_t j=0; j<_nDim; j++) { pointR[j] = (epoints[m])[j]; }
685  pointR *= *_rotMat;
686  _dataPtsR.push_back(pointR);
687  }
688 
689  epoints.clear();
690  mpoints.clear();
691  mjdcs.clear();
692  } // end of event loop
693 
694  _nEventsM = Int_t(_dataPts.size());
695 }
696 
697 
698 void
699 ////////////////////////////////////////////////////////////////////////////////
700 
702 {
703  _wMap.clear();
704 
705  for (Int_t i=0; i<_nEventsM; i++) {
706  _data.get(_idx[i]);
707  Double_t myweight = _data.weight();
708  //if ( TMath::Abs(myweight)>_minWeight ) {
709  _wMap[i] = myweight;
710  //}
711  }
712 
713  coutI(Contents) << "RooNDKeysPdf::loadWeightSet(" << this << ") : Number of weighted events : " << _wMap.size() << endl;
714 }
715 
716 
717 void
718 ////////////////////////////////////////////////////////////////////////////////
719 /// determine points in +/- nSigma shell around the box determined by the variable
720 /// ranges. These points are needed in the normalization, to determine probability
721 /// leakage in and out of the box.
722 
724 {
725  for (Int_t j=0; j<_nDim; j++) {
726  if (bi->xVarLo[j]==_xDatLo[j] && bi->xVarHi[j]==_xDatHi[j]) {
727  bi->netFluxZ = bi->netFluxZ && kTRUE;
728  } else { bi->netFluxZ = kFALSE; }
729 
730  bi->xVarLoM3s[j] = bi->xVarLo[j] - _nSigma * (_rho[j] * _n * _sigma[j]);
731  bi->xVarLoP3s[j] = bi->xVarLo[j] + _nSigma * (_rho[j] * _n * _sigma[j]);
732  bi->xVarHiM3s[j] = bi->xVarHi[j] - _nSigma * (_rho[j] * _n * _sigma[j]);
733  bi->xVarHiP3s[j] = bi->xVarHi[j] + _nSigma * (_rho[j] * _n * _sigma[j]);
734 
735  //cout<<"bi->xVarLoM3s["<<j<<"]="<<bi->xVarLoM3s[j]<<endl;
736  //cout<<"bi->xVarLoP3s["<<j<<"]="<<bi->xVarLoP3s[j]<<endl;
737  //cout<<"bi->xVarHiM3s["<<j<<"]="<<bi->xVarHiM3s[j]<<endl;
738  //cout<<"bi->xVarHiM3s["<<j<<"]="<<bi->xVarHiM3s[j]<<endl;
739  }
740 
741  map<Int_t,Double_t>::iterator wMapItr = _wMap.begin();
742 
743  //for (Int_t i=0; i<_nEventsM; i++) {
744  for (; wMapItr!=_wMap.end(); ++wMapItr) {
745  Int_t i = (*wMapItr).first;
746 
747  const vector<Double_t>& x = _dataPts[i];
748  Bool_t inVarRange(kTRUE);
749  Bool_t inVarRangePlusShell(kTRUE);
750 
751  for (Int_t j=0; j<_nDim; j++) {
752 
753  if (x[j]>bi->xVarLo[j] && x[j]<bi->xVarHi[j]) {
754  inVarRange = inVarRange && kTRUE;
755  } else { inVarRange = inVarRange && kFALSE; }
756 
757  if (x[j]>bi->xVarLoM3s[j] && x[j]<bi->xVarHiP3s[j]) {
758  inVarRangePlusShell = inVarRangePlusShell && kTRUE;
759  } else { inVarRangePlusShell = inVarRangePlusShell && kFALSE; }
760  }
761 
762  // event in range?
763  if (inVarRange) {
764  bi->bIdcs.push_back(i);
765  }
766 
767  // event in shell?
768  if (inVarRangePlusShell) {
769  bi->bpsIdcs[i] = kTRUE;
770  Bool_t inShell(kFALSE);
771  for (Int_t j=0; j<_nDim; j++) {
772  if ((x[j]>bi->xVarLoM3s[j] && x[j]<bi->xVarLoP3s[j]) && x[j]<(bi->xVarLo[j]+bi->xVarHi[j])/2.) {
773  inShell = kTRUE;
774  } else if ((x[j]>bi->xVarHiM3s[j] && x[j]<bi->xVarHiP3s[j]) && x[j]>(bi->xVarLo[j]+bi->xVarHi[j])/2.) {
775  inShell = kTRUE;
776  }
777  }
778  if (inShell) bi->sIdcs.push_back(i); // needed for normalization
779  else {
780  bi->bmsIdcs.push_back(i); // idem
781  }
782  }
783  }
784 
785  coutI(Contents) << "RooNDKeysPdf::calculateShell() : "
786  << "\n Events in shell " << bi->sIdcs.size()
787  << "\n Events in box " << bi->bIdcs.size()
788  << "\n Events in box and shell " << bi->bpsIdcs.size()
789  << endl;
790 }
791 
792 
793 void
794 ////////////////////////////////////////////////////////////////////////////////
795 ///bi->nEventsBMSW=0.;
796 ///bi->nEventsBW=0.;
797 
799 {
800  // box minus shell
801  for (Int_t i=0; i<Int_t(bi->bmsIdcs.size()); i++)
802  bi->nEventsBMSW += _wMap[bi->bmsIdcs[i]];
803 
804  // box
805  for (Int_t i=0; i<Int_t(bi->bIdcs.size()); i++)
806  bi->nEventsBW += _wMap[bi->bIdcs[i]];
807 
808  cxcoutD(Eval) << "RooNDKeysPdf::calculatePreNorm() : "
809  << "\n nEventsBMSW " << bi->nEventsBMSW
810  << "\n nEventsBW " << bi->nEventsBW
811  << endl;
812 }
813 
814 
815 void
816 ////////////////////////////////////////////////////////////////////////////////
817 /// sort entries, as needed for loopRange()
818 
820 {
821  itVec itrVecR;
822  vector<TVectorD>::iterator dpRItr = _dataPtsR.begin();
823  for (Int_t i=0; dpRItr!=_dataPtsR.end(); ++dpRItr, ++i) {
824  if (bi) {
825  if (bi->bpsIdcs.find(i)!=bi->bpsIdcs.end())
826  //if (_wMap.find(i)!=_wMap.end())
827  itrVecR.push_back(itPair(i,dpRItr));
828  } else itrVecR.push_back(itPair(i,dpRItr));
829  }
830 
831  for (Int_t j=0; j<_nDim; j++) {
832  _sortTVIdcs[j].clear();
833  sort(itrVecR.begin(),itrVecR.end(),SorterTV_L2H(j));
834  _sortTVIdcs[j] = itrVecR;
835  }
836 
837  for (Int_t j=0; j<_nDim; j++) {
838  cxcoutD(Eval) << "RooNDKeysPdf::sortDataIndices() : Number of sorted events : " << _sortTVIdcs[j].size() << endl;
839  }
840 }
841 
842 
843 void
844 ////////////////////////////////////////////////////////////////////////////////
845 
847 {
848  cxcoutD(Eval) << "RooNDKeysPdf::calculateBandWidth()" << endl;
849 
850  // non-adaptive bandwidth
851  // (default, and needed to calculate adaptive bandwidth)
852 
853  if(!_options.Contains("a")) {
854  cxcoutD(Eval) << "RooNDKeysPdf::calculateBandWidth() Using static bandwidth." << endl;
855  }
856 
857  for (Int_t i=0; i<_nEvents; i++) {
858  vector<Double_t>& weight = _weights0[i];
859  for (Int_t j=0; j<_nDim; j++) {
860  weight[j] = _rho[j] * _n * (*_sigmaR)[j] ;
861  //cout<<"j: "<<j<<", rho="<<_rho[j]<<", _n: "<<_n<<", sigmaR="<<(*_sigmaR)[j]<<", weight="<<weight[j]<<endl;
862  }
863  }
864 
865 
866  // adaptive width
867  if(_options.Contains("a")) {
868  cxcoutD(Eval) << "RooNDKeysPdf::calculateBandWidth() Using adaptive bandwidth." << endl;
869 
870  double sqrt12=sqrt(12.);
871  double sqrtSigmaAvgR=sqrt(_sigmaAvgR);
872 
873  vector<Double_t> dummy(_nDim,0.);
874  _weights1.resize(_nEvents,dummy);
875 
876  for(Int_t i=0; i<_nEvents; ++i) {
877 
878  vector<Double_t>& x = _dataPts[i];
879  Double_t f = TMath::Power( gauss(x,_weights0)/_nEventsW , -1./(2.*_d) ) ;
880 
881  vector<Double_t>& weight = _weights1[i];
882  for (Int_t j=0; j<_nDim; j++) {
883  Double_t norm = (_rho[j]*_n*(*_sigmaR)[j]) / sqrtSigmaAvgR ;
884  //cout<<"norm["<<j<<"]="<<norm<<endl;
885  weight[j] = norm * f / sqrt12 ; // note additional factor of sqrt(12) compared with HEP-EX/0011057
886  }
887  }
888  _weights = &_weights1;
889  }
890 }
891 
892 
893 Double_t
894 ////////////////////////////////////////////////////////////////////////////////
895 /// loop over all closest point to x, as determined by loopRange()
896 
897 RooNDKeysPdf::gauss(vector<Double_t>& x, vector<vector<Double_t> >& weights) const
898 {
899  if(_nEvents==0) return 0.;
900 
901  Double_t z=0.;
902  map<Int_t,Bool_t> ibMap;
903  ibMap.clear();
904 
905  // determine loop range for event x
906  loopRange(x,ibMap);
907 
908  map<Int_t,Bool_t>::iterator ibMapItr = ibMap.begin();
909 
910  for (; ibMapItr!=ibMap.end(); ++ibMapItr) {
911  Int_t i = (*ibMapItr).first;
912 
913  Double_t g(1.);
914 
915  if(i>=(Int_t)_idx.size()) {continue;} //---> 1.myline
916 
917  const vector<Double_t>& point = _dataPts[i];
918  const vector<Double_t>& weight = weights[_idx[i]];
919 
920  for (Int_t j=0; j<_nDim; j++) {
921  (*_dx)[j] = x[j]-point[j];
922  }
923 
924  if (_nDim>1) {
925  *_dx *= *_rotMat; // rotate to decorrelated frame!
926  }
927 
928  for (Int_t j=0; j<_nDim; j++) {
929  Double_t r = (*_dx)[j]; //x[j] - point[j];
930  Double_t c = 1./(2.*weight[j]*weight[j]);
931 
932  g *= exp( -c*r*r );
933  g *= 1./(_sqrt2pi*weight[j]);
934  }
935  z += (g*_wMap[_idx[i]]);
936  }
937  return z;
938 }
939 
940 
941 void
942 ////////////////////////////////////////////////////////////////////////////////
943 /// determine closest points to x, to loop over in evaluate()
944 
945 RooNDKeysPdf::loopRange(vector<Double_t>& x, map<Int_t,Bool_t>& ibMap) const
946 {
947  TVectorD xRm(_nDim);
948  TVectorD xRp(_nDim);
949 
950  for (Int_t j=0; j<_nDim; j++) { xRm[j] = xRp[j] = x[j]; }
951 
952  xRm *= *_rotMat;
953  xRp *= *_rotMat;
954  for (Int_t j=0; j<_nDim; j++) {
955  xRm[j] -= _nSigma * (_rho[j] * _n * (*_sigmaR)[j]);
956  xRp[j] += _nSigma * (_rho[j] * _n * (*_sigmaR)[j]);
957  //cout<<"xRm["<<j<<"]="<<xRm[j]<<endl;
958  //cout<<"xRp["<<j<<"]="<<xRp[j]<<endl;
959  }
960 
961  vector<TVectorD> xvecRm(1,xRm);
962  vector<TVectorD> xvecRp(1,xRp);
963 
964  map<Int_t,Bool_t> ibMapRT;
965 
966  for (Int_t j=0; j<_nDim; j++) {
967  ibMap.clear();
968  itVec::iterator lo = lower_bound(_sortTVIdcs[j].begin(), _sortTVIdcs[j].end(),
969  itPair(0,xvecRm.begin()), SorterTV_L2H(j));
970  itVec::iterator hi = upper_bound(_sortTVIdcs[j].begin(), _sortTVIdcs[j].end(),
971  itPair(0,xvecRp.begin()), SorterTV_L2H(j));
972  itVec::iterator it=lo;
973  if (j==0) {
974  if (_nDim==1) { for (it=lo; it!=hi; ++it) ibMap[(*it).first] = kTRUE; }
975  else { for (it=lo; it!=hi; ++it) ibMapRT[(*it).first] = kTRUE; }
976  continue;
977  }
978 
979  for (it=lo; it!=hi; ++it)
980  if (ibMapRT.find((*it).first)!=ibMapRT.end()) { ibMap[(*it).first] = kTRUE; }
981 
982  ibMapRT.clear();
983  if (j!=_nDim-1) { ibMapRT = ibMap; }
984  }
985 }
986 
987 
988 void
989 ////////////////////////////////////////////////////////////////////////////////
990 
991 RooNDKeysPdf::boxInfoInit(BoxInfo* bi, const char* rangeName, Int_t /*code*/) const
992 {
993  vector<Bool_t> doInt(_nDim,kTRUE);
994 
995  bi->filled = kFALSE;
996 
997  bi->xVarLo.resize(_nDim,0.);
998  bi->xVarHi.resize(_nDim,0.);
999  bi->xVarLoM3s.resize(_nDim,0.);
1000  bi->xVarLoP3s.resize(_nDim,0.);
1001  bi->xVarHiM3s.resize(_nDim,0.);
1002  bi->xVarHiP3s.resize(_nDim,0.);
1003 
1004  bi->netFluxZ = kTRUE;
1005  bi->bpsIdcs.clear();
1006  bi->bIdcs.clear();
1007  bi->sIdcs.clear();
1008  bi->bmsIdcs.clear();
1009 
1010  bi->nEventsBMSW=0.;
1011  bi->nEventsBW=0.;
1012 
1013  _varItr->Reset() ;
1014  RooRealVar* var ;
1015  for(Int_t j=0; (var=(RooRealVar*)_varItr->Next()); ++j) {
1016  if (doInt[j]) {
1017  bi->xVarLo[j] = var->getMin(rangeName);
1018  bi->xVarHi[j] = var->getMax(rangeName);
1019  } else {
1020  bi->xVarLo[j] = var->getVal() ;
1021  bi->xVarHi[j] = var->getVal() ;
1022  }
1023  }
1024 }
1025 
1026 
1027 Double_t
1028 ////////////////////////////////////////////////////////////////////////////////
1029 
1031 {
1032  _varItr->Reset() ;
1033  RooAbsReal* var ;
1034  const RooArgSet* nset = _varList.nset() ;
1035  for(Int_t j=0; (var=(RooAbsReal*)_varItr->Next()); ++j) {
1036  _x[j] = var->getVal(nset);
1037  }
1038 
1039  Double_t val = gauss(_x,*_weights);
1040  //cout<<"returning "<<val<<endl;
1041 
1042  if (val>=1E-20)
1043  return val ;
1044  else
1045  return (1E-20) ;
1046 }
1047 
1048 
1049 Int_t
1050 ////////////////////////////////////////////////////////////////////////////////
1051 
1052 RooNDKeysPdf::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName) const
1053 {
1054  if (rangeName) return 0 ;
1055 
1056  Int_t code=0;
1057  if (matchArgs(allVars,analVars,RooArgSet(_varList))) { code=1; }
1058 
1059  return code;
1060 
1061 }
1062 
1063 
1064 Double_t
1065 ////////////////////////////////////////////////////////////////////////////////
1066 
1067 RooNDKeysPdf::analyticalIntegral(Int_t code, const char* rangeName) const
1068 {
1069  cxcoutD(Eval) << "Calling RooNDKeysPdf::analyticalIntegral(" << GetName() << ") with code " << code
1070  << " and rangeName " << (rangeName?rangeName:"<none>") << endl;
1071 
1072  // determine which observables need to be integrated over ...
1073  Int_t nComb = 1 << (_nDim);
1074  R__ASSERT(code>=1 && code<nComb) ;
1075 
1076  vector<Bool_t> doInt(_nDim,kTRUE);
1077 
1078  // get BoxInfo
1079  BoxInfo* bi(0);
1080 
1081  if (rangeName) {
1082  string rangeNameStr(rangeName) ;
1083  bi = _rangeBoxInfo[make_pair(rangeNameStr,code)] ;
1084  if (!bi) {
1085  bi = new BoxInfo ;
1086  _rangeBoxInfo[make_pair(rangeNameStr,code)] = bi ;
1087  boxInfoInit(bi,rangeName,code);
1088  }
1089  } else bi= &_fullBoxInfo ;
1090 
1091  // have boundaries changed?
1092  Bool_t newBounds(kFALSE);
1093  _varItr->Reset() ;
1094  RooRealVar* var ;
1095  for(Int_t j=0; (var=(RooRealVar*)_varItr->Next()); ++j) {
1096  if ((var->getMin(rangeName)-bi->xVarLo[j]!=0) ||
1097  (var->getMax(rangeName)-bi->xVarHi[j]!=0)) {
1098  newBounds = kTRUE;
1099  }
1100  }
1101 
1102  // reset
1103  if (newBounds) {
1104  cxcoutD(Eval) << "RooNDKeysPdf::analyticalIntegral() : Found new boundaries ... " << (rangeName?rangeName:"<none>") << endl;
1105  boxInfoInit(bi,rangeName,code);
1106  }
1107 
1108  // recalculates netFluxZero and nEventsIR
1109  if (!bi->filled || newBounds) {
1110  // Fill box info with contents
1111  calculateShell(bi);
1112  calculatePreNorm(bi);
1113  bi->filled = kTRUE;
1114  sortDataIndices(bi);
1115  }
1116 
1117  // first guess
1118  Double_t norm=bi->nEventsBW;
1119 
1120  if (_mirror && bi->netFluxZ) {
1121  // KEYS expression is self-normalized
1122  cxcoutD(Eval) << "RooNDKeysPdf::analyticalIntegral() : Using mirrored normalization : " << bi->nEventsBW << endl;
1123  return bi->nEventsBW;
1124  }
1125  // calculate leakage in and out of variable range box
1126  else
1127  {
1128  norm = bi->nEventsBMSW;
1129  if (norm<0.) norm=0.;
1130 
1131  for (Int_t i=0; i<Int_t(bi->sIdcs.size()); ++i) {
1132  Double_t prob=1.;
1133  const vector<Double_t>& x = _dataPts[bi->sIdcs[i]];
1134  const vector<Double_t>& weight = (*_weights)[_idx[bi->sIdcs[i]]];
1135 
1136  vector<Double_t> chi(_nDim,100.);
1137 
1138  for (Int_t j=0; j<_nDim; j++) {
1139  if(!doInt[j]) continue;
1140 
1141  if ((x[j]>bi->xVarLoM3s[j] && x[j]<bi->xVarLoP3s[j]) && x[j]<(bi->xVarLo[j]+bi->xVarHi[j])/2.)
1142  chi[j] = (x[j]-bi->xVarLo[j])/weight[j];
1143  else if ((x[j]>bi->xVarHiM3s[j] && x[j]<bi->xVarHiP3s[j]) && x[j]>(bi->xVarLo[j]+bi->xVarHi[j])/2.)
1144  chi[j] = (bi->xVarHi[j]-x[j])/weight[j];
1145 
1146  if (chi[j]>0) // inVarRange
1147  prob *= (0.5 + TMath::Erf(fabs(chi[j])/sqrt(2.))/2.);
1148  else // outside Var range
1149  prob *= (0.5 - TMath::Erf(fabs(chi[j])/sqrt(2.))/2.);
1150  }
1151 
1152  norm += prob * _wMap[_idx[bi->sIdcs[i]]];
1153  }
1154 
1155  cxcoutD(Eval) << "RooNDKeysPdf::analyticalIntegral() : Final normalization : " << norm << " " << bi->nEventsBW << endl;
1156  return norm;
1157  }
1158 }
1159 
1160 
Double_t _n
Definition: RooNDKeysPdf.h:135
Bool_t _rotate
Definition: RooNDKeysPdf.h:184
for(Int_t i=0;i< n;i++)
Definition: legend1.C:18
const TVectorD & GetEigenValues() const
std::vector< itPair > itVec
Definition: RooNDKeysPdf.h:40
const RooArgSet * nset() const
Definition: RooAbsProxy.h:47
#define coutE(a)
Definition: RooMsgService.h:35
RooListProxy _varList
Definition: RooNDKeysPdf.h:99
std::vector< Double_t > xVarHi
Definition: RooNDKeysPdf.h:89
std::vector< Double_t > _xVarLo
Definition: RooNDKeysPdf.h:162
Double_t _nEventsW
Definition: RooNDKeysPdf.h:133
TMatrixDSym * _corrMat
Definition: RooNDKeysPdf.h:178
Double_t _nSigma
Definition: RooNDKeysPdf.h:122
virtual void Reset()=0
virtual TMatrixTBase< Element > & Zero()
Set matrix elements to zero.
return c
std::vector< std::string > _varName
Definition: RooNDKeysPdf.h:150
#define coutI(a)
Definition: RooMsgService.h:32
std::vector< Int_t > bIdcs
Definition: RooNDKeysPdf.h:93
#define cxcoutD(a)
Definition: RooMsgService.h:80
void boxInfoInit(BoxInfo *bi, const char *rangeName, Int_t code) const
Int_t GetNrows() const
Definition: TVectorT.h:81
TVectorD * _dx
Definition: RooNDKeysPdf.h:181
Bool_t _netFluxZ
Definition: RooNDKeysPdf.h:159
#define R__ASSERT(e)
Definition: TError.h:98
std::vector< Int_t > _bIdcs
Definition: RooNDKeysPdf.h:166
Basic string class.
Definition: TString.h:137
virtual Double_t getMin(const char *name=0) const
std::vector< Double_t > _xDatLo
Definition: RooNDKeysPdf.h:156
TMatrixT< Element > & T()
Definition: TMatrixT.h:151
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1089
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Double_t evaluate() const
do not persist
STL namespace.
RooDataSet & _data
Definition: RooNDKeysPdf.h:119
#define coutW(a)
Definition: RooMsgService.h:34
TMatrixD * _rotMat
Definition: RooNDKeysPdf.h:179
virtual ~RooNDKeysPdf()
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
std::vector< Double_t > _x1
Definition: RooNDKeysPdf.h:154
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
Double_t _widthFactor
Definition: RooNDKeysPdf.h:121
Iterator abstract base class.
Definition: TIterator.h:32
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Definition: TMath.h:501
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported...
TMatrixDSymEigen.
Bool_t _verbose
Definition: RooNDKeysPdf.h:127
std::vector< Double_t > _xDatHi
Definition: RooNDKeysPdf.h:156
std::vector< Double_t > _xVarLoM3s
Definition: RooNDKeysPdf.h:163
std::vector< std::vector< Double_t > > _weights1
Definition: RooNDKeysPdf.h:142
double sqrt(double)
std::vector< Double_t > _xVarHiM3s
Definition: RooNDKeysPdf.h:163
Double_t x[n]
Definition: legend1.C:17
void loopRange(std::vector< Double_t > &x, std::map< Int_t, Bool_t > &ibMap) const
determine closest points to x, to loop over in evaluate()
std::list< Elem > List
Definition: ModulekNN.h:107
std::map< Int_t, Double_t > _wMap
Definition: RooNDKeysPdf.h:175
void calculateBandWidth() const
TIterator * createIterator(Bool_t dir=kIterForward) const
std::map< std::pair< std::string, int >, BoxInfo * > _rangeBoxInfo
Definition: RooNDKeysPdf.h:169
friend class RooArgSet
Definition: RooAbsArg.h:469
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
TVectorD * _sigmaR
Definition: RooNDKeysPdf.h:180
std::vector< Double_t > _xDatLo3s
Definition: RooNDKeysPdf.h:157
TVectorT< Double_t > TVectorD
Definition: TVectorDfwd.h:24
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
std::vector< std::vector< Double_t > > * _weights
Definition: RooNDKeysPdf.h:143
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
TMatrixT< Double_t > TMatrixD
Definition: TMatrixDfwd.h:24
void sortDataIndices(BoxInfo *bi=0) const
sort entries, as needed for loopRange()
void Print(Option_t *name="") const
Print the matrix as a table of elements.
void Print(Option_t *option="") const
Print the vector as a list of elements.
Definition: TVectorT.cxx:1361
std::vector< Double_t > xVarHiP3s
Definition: RooNDKeysPdf.h:90
void calculatePreNorm(BoxInfo *bi) const
bi->nEventsBMSW=0.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
std::vector< Double_t > _x
Definition: RooNDKeysPdf.h:153
TRandom2 r(17)
RooAbsArg * find(const char *name) const
Find object with given name in list.
virtual Double_t weight() const
Return event weight of current event.
std::vector< itVec > _sortTVIdcs
Definition: RooNDKeysPdf.h:147
Double_t Erf(Double_t x)
Computation of the error function erf(x).
Definition: TMath.cxx:187
void setOptions() const
set the configuration
virtual Int_t numEntries() const
Definition: RooAbsData.cxx:269
Double_t _maxWeight
Definition: RooNDKeysPdf.h:174
void createPdf(Bool_t firstCall=kTRUE) const
evaluation order of constructor.
TVectorT< Element > & Zero()
Set vector elements to zero.
Definition: TVectorT.cxx:451
TMarker * m
Definition: textangle.C:8
Double_t _minWeight
Definition: RooNDKeysPdf.h:173
Double_t _sigmaAvgR
Definition: RooNDKeysPdf.h:182
Double_t E()
Definition: TMath.h:54
TLine * l
Definition: textangle.C:4
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
TMatrixDSym * _covMat
Definition: RooNDKeysPdf.h:177
std::vector< Double_t > xVarHiM3s
Definition: RooNDKeysPdf.h:90
RooNDKeysPdf(const char *name, const char *title, const RooArgList &varList, RooDataSet &data, TString options="a", Double_t rho=1, Double_t nSigma=3, Bool_t rotate=kTRUE)
Construct N-dimensional kernel estimation p.d.f.
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
std::vector< Double_t > _x0
Definition: RooNDKeysPdf.h:154
Generic N-dimensional implementation of a kernel estimation p.d.f.
Definition: RooNDKeysPdf.h:45
Double_t _nEventsBW
Definition: RooNDKeysPdf.h:160
TString _options
Definition: RooNDKeysPdf.h:120
BoxInfo _fullBoxInfo
Definition: RooNDKeysPdf.h:170
Double_t Pi()
Definition: TMath.h:44
std::vector< Double_t > _mean
Definition: RooNDKeysPdf.h:155
std::vector< Double_t > _xVarHiP3s
Definition: RooNDKeysPdf.h:163
Double_t _nEventsBMSW
Definition: RooNDKeysPdf.h:161
#define ClassImp(name)
Definition: Rtypes.h:279
double f(double x)
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
const TMatrixD & GetEigenVectors() const
std::map< Int_t, Bool_t > _bpsIdcs
Definition: RooNDKeysPdf.h:164
std::vector< Int_t > sIdcs
Definition: RooNDKeysPdf.h:92
void mirrorDataSet() const
determine mirror dataset.
TMatrixTSym< Double_t > TMatrixDSym
static RooMathCoreReg dummy
std::vector< Double_t > xVarLoP3s
Definition: RooNDKeysPdf.h:90
Double_t y[n]
Definition: legend1.C:17
std::vector< Double_t > _xVarHi
Definition: RooNDKeysPdf.h:162
std::vector< Int_t > _idx
Definition: RooNDKeysPdf.h:172
std::pair< Int_t, VecTVecDouble::iterator > itPair
Definition: RooNDKeysPdf.h:39
std::vector< Double_t > _xDatHi3s
Definition: RooNDKeysPdf.h:157
std::vector< Int_t > _sIdcs
Definition: RooNDKeysPdf.h:165
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
std::map< Int_t, Bool_t > bpsIdcs
Definition: RooNDKeysPdf.h:91
virtual Double_t getMax(const char *name=0) const
std::vector< Int_t > bmsIdcs
Definition: RooNDKeysPdf.h:94
std::vector< Double_t > _rho
Definition: RooNDKeysPdf.h:151
void initialize() const
initialization
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
Double_t analyticalIntegral(Int_t code, const char *rangeName=0) const
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral. ...
Bool_t _fixedShape
Definition: RooNDKeysPdf.h:124
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
virtual TObject * Next()=0
void calculateShell(BoxInfo *bi) const
determine points in +/- nSigma shell around the box determined by the variable ranges.
Double_t _sqrt2pi
Definition: RooNDKeysPdf.h:129
std::vector< TVectorD > _dataPtsR
Definition: RooNDKeysPdf.h:140
std::vector< std::vector< Double_t > > _dataPts
Definition: RooNDKeysPdf.h:139
std::vector< std::vector< Double_t > > _weights0
Definition: RooNDKeysPdf.h:141
void loadWeightSet() const
TIterator * _varItr
Definition: RooNDKeysPdf.h:100
float type_of_call hi(const int &, const int &)
void loadDataSet(Bool_t firstCall) const
copy the dataset and calculate some useful variables
Bool_t matchArgs(const RooArgSet &allDeps, RooArgSet &numDeps, const RooArgProxy &a) const
Utility function for use in getAnalyticalIntegral().
Int_t getSize() const
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
double exp(double)
const Bool_t kTRUE
Definition: Rtypes.h:91
std::vector< Double_t > _xVarLoP3s
Definition: RooNDKeysPdf.h:163
Bool_t _mirror
Definition: RooNDKeysPdf.h:125
double norm(double *x, double *p)
Definition: unuranDistr.cxx:40
std::vector< Double_t > _sigma
Definition: RooNDKeysPdf.h:155
virtual const RooArgSet * get(Int_t index) const
Return RooArgSet with coordinates of event &#39;index&#39;.
std::vector< Double_t > xVarLo
Definition: RooNDKeysPdf.h:89
void variables(TString dataset, TString fin="TMVA.root", TString dirName="InputVariables_Id", TString title="TMVA Input Variables", Bool_t isRegression=kFALSE, Bool_t useTMVAStyle=kTRUE)
Definition: variables.cxx:10
std::vector< Int_t > _bmsIdcs
Definition: RooNDKeysPdf.h:167
Double_t gauss(std::vector< Double_t > &x, std::vector< std::vector< Double_t > > &weights) const
loop over all closest point to x, as determined by loopRange()
char name[80]
Definition: TGX11.cxx:109
std::vector< Double_t > xVarLoM3s
Definition: RooNDKeysPdf.h:90
Double_t _d
Definition: RooNDKeysPdf.h:134
std::vector< Double_t > _x2
Definition: RooNDKeysPdf.h:154