73 :
RooAbsPdf(name, title), _varList(
"varList",
"List of variables", this),
74 _rhoList(
"rhoList",
"List of rho parameters", this), _dataP(0), _data(data), _options(options), _widthFactor(rho),
75 _nSigma(nSigma), _weights(&_weights0), _rotate(rotate), _sortInput(sortInput), _nAdpt(1), _tracker(0)
84 if (!dynamic_cast<RooAbsReal*>(var)) {
86 <<
" is not of type RooAbsReal" << endl ;
113 if (!dynamic_cast<RooAbsReal *>(var)) {
115 <<
" is not of type RooAbsReal" << endl;
141 if (!dynamic_cast<RooAbsReal*>(var)) {
143 <<
" is not of type RooAbsReal" << endl;
154 <<
"ERROR: RooNDKeysPdf::RooNDKeysPdf() : The vector-size of rho is different from that of varList." 155 <<
"Unable to create the PDF." << endl;
186 if (!dynamic_cast<RooAbsReal *>(var)) {
188 <<
" is not of type RooAbsReal" << endl;
201 if (!dynamic_cast<RooAbsReal *>(rho)) {
203 <<
" is not of type RooRealVar" << endl;
213 coutE(
InputArguments) <<
"ERROR: RooNDKeysPdf::RooNDKeysPdf() : The size of rhoList is different from varList." 214 <<
"Unable to create the PDF." << endl;
220 (
void)_tracker->hasChanged(
true);
241 if (!dynamic_cast<RooAbsReal *>(var)) {
243 <<
" is not of type RooAbsReal" << endl;
257 if (!dynamic_cast<RooAbsReal *>(rho)) {
259 <<
" is not of type RooRealVar" << endl;
268 coutE(
InputArguments) <<
"ERROR: RooNDKeysPdf::RooNDKeysPdf() : The size of rhoList is different from varList." 269 <<
"Unable to create the PDF." << endl;
275 (
void)_tracker->hasChanged(
true);
297 coutW(
InputArguments) <<
"RooNDKeysPdf::RooNDKeysPdf() : Warning : asymmetric mirror(s) no longer supported." 490 <<
"\n\tbandWidthType = " <<
_options.Contains(
"a")
492 <<
"\n\tdebug = " <<
_debug 498 <<
"Calculated normalization could be too large." 526 coutE(
InputArguments) <<
"ERROR: RooNDKeysPdf::initialize() : The observable list is empty. " 527 <<
"Unable to begin generating the PDF." << endl;
532 coutE(
InputArguments) <<
"ERROR: RooNDKeysPdf::initialize() : The input data set is empty. " 533 <<
"Unable to begin generating the PDF." << endl;
605 vector<RooRealVar*> dVars(
_nDim);
616 vector<Double_t>& point =
_dataPts[i];
625 mat(j,k) += dVars[j]->getVal() * dVars[k]->getVal() * myweight;
629 point[j] = pointV[j] = dVars[j]->getVal();
631 _x0[j] += 1. * myweight;
632 _x1[j] += point[j] * myweight ;
633 _x2[j] += point[j] * point[j] * myweight ;
634 if (
_x2[j]!=
_x2[j]) exit(3);
667 for (
Int_t j=0; j<
_nDim; j++) { sigmaRraw[j] =
sqrt(sigmaRraw[j]); }
706 coutI(
Contents) <<
"RooNDKeysPdf::loadDataSet(" <<
this <<
")" 707 <<
"\n Number of events in dataset: " << _nEvents
708 <<
"\n Weighted number of events in dataset: " <<
_nEventsW << endl;
728 vector<Double_t>
dummy(_nDim,0.);
735 vector<vector<Double_t> > mpoints(size,dummy);
736 vector<vector<Int_t> > mjdcs(size);
741 vector<Int_t>& mjdxK = mjdcs[0];
742 vector<Double_t>& mpointK = mpoints[0];
746 mpointK[j] = 2.*
_xDatLo[j]-x[j];
749 mpointK[j] = 2.*
_xDatHi[j]-x[j];
754 vector<Int_t>& mjdx0 = mjdcs[0];
756 if (size==1 && mjdx0.size()==0)
continue;
760 vector<Int_t>& mjdx = mjdcs[0];
761 vector<Double_t>& mpoint = mpoints[0];
764 Int_t eMir = 1 << mjdx.size();
765 vector<vector<Double_t> > epoints(eMir,x);
772 epoints[
l] = epoints[
l-size1];
774 vector<Double_t>& epoint = epoints[
l];
775 epoint[mjdx[
Int_t(mjdx.size()-1)-
m]] = mpoint[mjdx[
Int_t(mjdx.size()-1)-
m]];
781 epoints.erase(epoints.begin());
790 for (
Int_t j=0; j<
_nDim; j++) { pointR[j] = (epoints[
m])[j]; }
819 coutI(
Contents) <<
"RooNDKeysPdf::loadWeightSet(" <<
this <<
") : Number of weighted events : " <<
_wMap.size() << endl;
845 map<Int_t,Double_t>::iterator wMapItr =
_wMap.begin();
848 for (; wMapItr!=
_wMap.end(); ++wMapItr) {
849 Int_t i = (*wMapItr).first;
858 inVarRange = inVarRange &&
kTRUE;
859 }
else { inVarRange = inVarRange &&
kFALSE; }
862 inVarRangePlusShell = inVarRangePlusShell &&
kTRUE;
863 }
else { inVarRangePlusShell = inVarRangePlusShell &&
kFALSE; }
868 bi->
bIdcs.push_back(i);
872 if (inVarRangePlusShell) {
882 if (inShell) bi->
sIdcs.push_back(i);
890 <<
"\n Events in shell " << bi->
sIdcs.size()
891 <<
"\n Events in box " << bi->
bIdcs.size()
892 <<
"\n Events in box and shell " << bi->
bpsIdcs.size()
910 cxcoutD(
Eval) <<
"RooNDKeysPdf::calculatePreNorm() : " 924 for (
unsigned int i = 0; i <
_dataPtsR.size(); ++i) {
931 vector<TVectorD>::iterator dpRItr =
_dataPtsR.begin();
936 itrVecR.push_back(
itPair(i, dpRItr));
938 itrVecR.push_back(
itPair(i, dpRItr));
948 cxcoutD(
Eval) <<
"RooNDKeysPdf::sortDataIndices() : Number of sorted events : " <<
_sortTVIdcs[j].size() << endl;
956 cxcoutD(
Eval) <<
"RooNDKeysPdf::calculateBandWidth()" << endl;
962 cxcoutD(
Eval) <<
"RooNDKeysPdf::calculateBandWidth() Using static bandwidth." << endl;
969 weight[j] =
_n * (*_sigmaR)[j];
976 cxcoutD(
Eval) <<
"RooNDKeysPdf::calculateBandWidth() Using adaptive bandwidth." << endl;
978 double sqrt12 =
sqrt(12.);
984 std::vector<std::vector<Double_t>> *weights_prev(0);
985 std::vector<std::vector<Double_t>> *weights_new(0);
1006 vector<Double_t> &weight = (*weights_new)[i];
1008 Double_t norm = (
_n * (*_sigmaR)[j]) / sqrtSigmaAvgR;
1009 weight[j] = norm * f / sqrt12;
1026 map<Int_t,Bool_t> ibMap;
1033 map<Int_t, Bool_t>::iterator ibMapItr, ibMapEnd;
1037 for (; ibMapItr != ibMapEnd; ++ibMapItr) {
1038 Int_t i = (*ibMapItr).first;
1046 const vector<Double_t> &point =
_dataPts[i];
1047 const vector<Double_t> &weight = weights[
_idx[i]];
1050 (*_dx)[j] = x[j] - point[j];
1059 Double_t c = 1. / (2. * weight[j] * weight[j]);
1063 g *=
exp(-c * r * r);
1066 z += (g *
_wMap[_idx[i]]);
1081 xRm[j] = xRp[j] = x[j];
1089 xRm[j] -=
_nSigma * (
_n * (*_sigmaR)[j]);
1090 xRp[j] +=
_nSigma * (
_n * (*_sigmaR)[j]);
1095 vector<TVectorD> xvecRm(1,xRm);
1096 vector<TVectorD> xvecRp(1,xRp);
1098 map<Int_t,Bool_t> ibMapRT;
1104 itVec::iterator
hi =
1106 itVec::iterator it = lo;
1109 if (_nDim==1) {
for (it=lo; it!=
hi; ++it) ibMap[(*it).first] =
kTRUE; }
1110 else {
for (it=lo; it!=
hi; ++it) ibMapRT[(*it).first] =
kTRUE; }
1114 for (it=lo; it!=
hi; ++it)
1115 if (ibMapRT.find((*it).first)!=ibMapRT.end()) { ibMap[(*it).first] =
kTRUE; }
1118 if (j!=_nDim-1) { ibMapRT = ibMap; }
1189 if (rangeName)
return 0 ;
1202 cxcoutD(
Eval) <<
"Calling RooNDKeysPdf::analyticalIntegral(" <<
GetName() <<
") with code " << code
1203 <<
" and rangeName " << (rangeName?rangeName:
"<none>") << endl;
1215 string rangeNameStr(rangeName) ;
1237 cxcoutD(
Eval) <<
"RooNDKeysPdf::analyticalIntegral() : Found new boundaries ... " << (rangeName?rangeName:
"<none>") << endl;
1242 if (!bi->
filled || newBounds) {
1255 cxcoutD(
Eval) <<
"RooNDKeysPdf::analyticalIntegral() : Using mirrored normalization : " << bi->
nEventsBW << endl;
1262 if (norm<0.) norm=0.;
1267 const vector<Double_t>& weight = (*_weights)[
_idx[bi->
sIdcs[i]]];
1269 vector<Double_t> chi(
_nDim,100.);
1272 if(!doInt[j])
continue;
1275 chi[j] = (x[j]-bi->
xVarLo[j])/weight[j];
1277 chi[j] = (bi->
xVarHi[j]-x[j])/weight[j];
1288 cxcoutD(
Eval) <<
"RooNDKeysPdf::analyticalIntegral() : Final normalization : " << norm <<
" " << bi->
nEventsBW << endl;
1298 std::vector<RooRealVar *> varVec;
1304 if (!dynamic_cast<RooRealVar *>(var)) {
1306 << var->
GetName() <<
" is not of type RooRealVar. Skip." << endl;
1309 varsAndWeightSet.
add(*var);
1310 varVec.push_back(static_cast<RooRealVar *>(var));
1315 RooRealVar weight(
"weight",
"event weight", 0);
1316 varsAndWeightSet.
add(weight);
1319 unsigned int histndim(0);
1320 std::string classname = hist.
ClassName();
1321 if (classname.find(
"TH1") == 0) {
1323 }
else if (classname.find(
"TH2") == 0) {
1325 }
else if (classname.find(
"TH3") == 0) {
1328 assert(histndim == varVec.size());
1330 if (histndim > 3 || histndim <= 0) {
1332 <<
") ERROR: input histogram dimension not between [1-3]: " << histndim << endl;
1344 varVec[0]->setVal(xval);
1346 if (varVec.size() == 1) {
1349 dataFromHist->
add(varsAndWeightSet, fval);
1354 varVec[1]->setVal(yval);
1356 if (varVec.size() == 2) {
1359 dataFromHist->
add(varsAndWeightSet, fval);
1364 varVec[2]->setVal(zval);
1368 dataFromHist->
add(varsAndWeightSet, fval);
1375 return dataFromHist;
1386 cxcoutD(
Eval) <<
"RooNDKeysPdf::getWeights() Return evaluated weights." << endl;
1394 vector<Double_t> &weight = (*_weights)[i];
1395 mref(i, _nDim) = weight[k];
1416 covMatRho(j, k) = (*_covMat)(j, k) *
_rho[j] *
_rho[k];
1421 *
_sigmaR = evCalculatorRho.GetEigenValues();
virtual Double_t getMin(const char *name=0) const
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()
virtual const char * GetName() const
Returns name of object.
std::vector< itPair > itVec
TIterator * createIterator(Bool_t dir=kIterForward) const
void setOptions() const
set the configuration
std::vector< Double_t > xVarHi
std::vector< Double_t > _xVarLo
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()
virtual Double_t getMax(const char *name=0) const
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
void calculateBandWidth() const
void boxInfoInit(BoxInfo *bi, const char *rangeName, Int_t code) const
virtual TMatrixTBase< Element > & Zero()
Set matrix elements to zero.
void loadDataSet(Bool_t firstCall) const
copy the dataset and calculate some useful variables
virtual const RooArgSet * get() const
std::vector< std::string > _varName
RooNDKeysPdf(const char *name, const char *title, const RooArgList &varList, const RooAbsData &data, TString options="ma", Double_t rho=1, Double_t nSigma=3, Bool_t rotate=kTRUE, Bool_t sortInput=kTRUE)
Construct N-dimensional kernel estimation p.d.f.
Bool_t matchArgs(const RooArgSet &allDeps, RooArgSet &numDeps, const RooArgProxy &a) const
Utility function for use in getAnalyticalIntegral().
std::vector< Int_t > bIdcs
Double_t getVal(const RooArgSet *set=0) const
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Bool_t hasChanged(Bool_t clearState)
Returns true if state has changes since last call with clearState=kTRUE If clearState is true...
void mirrorDataSet() const
determine mirror dataset.
std::vector< Int_t > _bIdcs
std::vector< Double_t > _xDatLo
TMatrixT< Element > & T()
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
void Print(Option_t *option="") const
Print the vector as a list of elements.
std::vector< Double_t > _x1
Iterator abstract base class.
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
std::vector< Double_t > _xDatHi
std::vector< Double_t > _xVarLoM3s
std::vector< std::vector< Double_t > > _weights1
std::vector< Double_t > _xVarHiM3s
virtual const char * ClassName() const
Returns name of class to which the object belongs.
void initialize() const
initialization
std::map< Int_t, Double_t > _wMap
std::map< Int_t, Bool_t > _ibNoSort
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
std::map< std::pair< std::string, int >, BoxInfo * > _rangeBoxInfo
std::vector< Double_t > _xDatLo3s
RooDataSet * createDatasetFromHist(const RooArgList &varList, const TH1 &hist) const
TVectorT< Double_t > TVectorD
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
std::vector< std::vector< Double_t > > * _weights
const RooArgSet * nset() const
RooRealVar represents a fundamental (non-derived) real valued object.
TMatrixT< Double_t > TMatrixD
RooListProxy _rhoList
do not persist
TMatrixD getWeights(const int &k) const
Return evaluated weights.
virtual void setVal(Double_t value)
Set value of variable to 'value'.
std::vector< Double_t > xVarHiP3s
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
std::vector< Double_t > _x
std::vector< itVec > _sortTVIdcs
Double_t Erf(Double_t x)
Computation of the error function erf(x).
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported...
Double_t evaluate() const
do not persist
TVectorT< Element > & Zero()
Set vector elements to zero.
std::vector< Double_t > xVarHiM3s
void calculatePreNorm(BoxInfo *bi) const
bi->nEventsBMSW=0.
RooAbsData is the common abstract base class for binned and unbinned datasets.
RooDataSet is a container class to hold unbinned data.
std::vector< Double_t > _x0
const TMatrixD & GetEigenVectors() const
Generic N-dimensional implementation of a kernel estimation p.d.f.
void createPdf(Bool_t firstCall=kTRUE) const
evaluation order of constructor.
virtual void add(const RooArgSet &row, Double_t weight=1.0, Double_t weightError=0)
Add a data point, with its coordinates specified in the 'data' argset, to the data set...
void calculateShell(BoxInfo *bi) const
determine points in +/- nSigma shell around the box determined by the variable ranges.
std::vector< Double_t > _mean
void loadWeightSet() const
std::vector< Double_t > _xVarHiP3s
const TVectorD & GetEigenValues() const
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
std::map< Int_t, Bool_t > _bpsIdcs
std::vector< Int_t > sIdcs
Double_t analyticalIntegral(Int_t code, const char *rangeName=0) const
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral. ...
TMatrixTSym< Double_t > TMatrixDSym
static RooMathCoreReg dummy
std::vector< Double_t > xVarLoP3s
std::vector< Double_t > _xVarHi
std::vector< Int_t > _idx
std::pair< Int_t, VecTVecDouble::iterator > itPair
std::vector< Double_t > _xDatHi3s
RooChangeTracker is a meta object that tracks value changes in a given set of RooAbsArgs by registeri...
std::vector< Int_t > _sIdcs
void Print(Option_t *name="") const
Print the matrix as a table of elements.
RooChangeTracker * _tracker
you should not use this method at all Int_t Int_t z
std::map< Int_t, Bool_t > bpsIdcs
std::vector< Int_t > bmsIdcs
typedef void((*Func_t)())
const RooAbsData & _data
do not persist
std::vector< Double_t > _rho
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
virtual TObject * Next()=0
virtual Double_t weight() const =0
std::vector< TVectorD > _dataPtsR
std::vector< std::vector< Double_t > > _dataPts
std::vector< std::vector< Double_t > > _weights0
float type_of_call hi(const int &, const int &)
void sortDataIndices(BoxInfo *bi=0) const
sort entries, as needed for loopRange()
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
std::vector< Double_t > _xVarLoP3s
std::vector< Double_t > _sigma
std::vector< Double_t > xVarLo
std::vector< Int_t > _bmsIdcs
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
virtual Int_t numEntries() const
std::vector< Double_t > xVarLoM3s
std::vector< Double_t > _x2
static constexpr double g