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)
86 <<
" is not of type RooAbsReal" << endl ;
102 :
RooAbsPdf(
name, title), _varList(
"varList",
"List of variables", this),
103 _rhoList(
"rhoList",
"List of rho parameters", this), _dataP(createDatasetFromHist(varList, hist)), _data(*_dataP),
104 _options(options), _widthFactor(rho), _nSigma(nSigma), _weights(&_weights0), _rotate(rotate),
105 _sortInput(sortInput), _nAdpt(1), _tracker(0)
115 <<
" is not of type RooAbsReal" << endl;
131 :
RooAbsPdf(
name, title), _varList(
"varList",
"List of variables", this),
132 _rhoList(
"rhoList",
"List of rho parameters", this), _dataP(0), _data(data), _options(options), _widthFactor(-1.0),
133 _nSigma(nSigma), _weights(&_weights0), _rotate(rotate), _sortInput(sortInput), _nAdpt(1), _tracker(0)
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;
176 :
RooAbsPdf(
name, title), _varList(
"varList",
"List of variables", this),
177 _rhoList(
"rhoList",
"List of rho parameters", this), _dataP(0), _data(data), _options(options), _widthFactor(-1.0),
178 _nSigma(nSigma), _weights(&_weights0), _rotate(rotate), _sortInput(sortInput), _nAdpt(1)
188 <<
" is not of type RooAbsReal" << endl;
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;
230 :
RooAbsPdf(
name, title), _varList(
"varList",
"List of variables", this),
231 _rhoList(
"rhoList",
"List of rho parameters", this), _dataP(createDatasetFromHist(varList, hist)), _data(*_dataP),
232 _options(options), _widthFactor(-1), _nSigma(nSigma), _weights(&_weights0), _rotate(rotate), _sortInput(sortInput),
243 <<
" is not of type RooAbsReal" << endl;
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;
285 :
RooAbsPdf(
name, title), _varList(
"varList",
"List of variables", this),
286 _rhoList(
"rhoList",
"List of rho parameters", this), _dataP(0), _data(data), _options(
"a"), _widthFactor(rho),
287 _nSigma(nSigma), _weights(&_weights0), _rotate(rotate), _sortInput(sortInput), _nAdpt(1), _tracker(0)
297 coutW(
InputArguments) <<
"RooNDKeysPdf::RooNDKeysPdf() : Warning : asymmetric mirror(s) no longer supported."
311 :
RooAbsPdf(
name, title), _varList(
"varList",
"List of variables", this),
312 _rhoList(
"rhoList",
"List of rho parameters", this), _dataP(0), _data(data), _options(options), _widthFactor(rho),
313 _nSigma(nSigma), _weights(&_weights0), _rotate(rotate), _sortInput(sortInput), _nAdpt(1), _tracker(0)
329 :
RooAbsPdf(other,
name), _varList(
"varList", this, other._varList), _rhoList(
"rhoList", this, other._rhoList),
330 _dataP(other._dataP != NULL ? new
RooDataSet(*other._dataP) : NULL),
331 _data(other._dataP != NULL ? *_dataP : other._data), _options(other._options), _widthFactor(other._widthFactor),
332 _nSigma(other._nSigma), _weights(&_weights0), _rotate(other._rotate), _sortInput(other._sortInput),
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;
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];
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]);
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;
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;
1340 for (
int i = 1; i <= hist.
GetXaxis()->GetNbins(); ++i) {
1344 varVec[0]->setVal(xval);
1346 if (varVec.size() == 1) {
1349 dataFromHist->
add(varsAndWeightSet, fval);
1352 for (
int j = 1; j <= hist.
GetYaxis()->GetNbins(); ++j) {
1354 varVec[1]->setVal(yval);
1356 if (varVec.size() == 2) {
1359 dataFromHist->
add(varsAndWeightSet, fval);
1362 for (
int k = 1; k <= hist.
GetZaxis()->GetNbins(); ++k) {
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];
static RooMathCoreReg dummy
std::vector< itPair > itVec
std::pair< Int_t, VecTVecDouble::iterator > itPair
float type_of_call hi(const int &, const int &)
TMatrixTSym< Double_t > TMatrixDSym
TMatrixT< Double_t > TMatrixD
typedef void((*Func_t)())
TVectorT< Double_t > TVectorD
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
TIterator end() or range-based loops.")
TIterator * createIterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
TIterator-style iteration over contained elements.
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooAbsData is the common abstract base class for binned and unbinned datasets.
virtual const RooArgSet * get() const
virtual Double_t weight() const =0
virtual Int_t numEntries() const
const RooArgSet * nset() const
virtual Double_t getMax(const char *name=0) const
Get maximum of currently defined range.
virtual Double_t getMin(const char *name=0) const
Get miniminum of currently defined range.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Bool_t matchArgs(const RooArgSet &allDeps, RooArgSet &numDeps, const RooArgProxy &a) const
Utility function for use in getAnalyticalIntegral().
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
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...
RooChangeTracker is a meta object that tracks value changes in a given set of RooAbsArgs by registeri...
Bool_t hasChanged(Bool_t clearState)
Returns true if state has changes since last call with clearState=kTRUE If clearState is true,...
RooDataSet is a container class to hold unbinned data.
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.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
Generic N-dimensional implementation of a kernel estimation p.d.f.
void sortDataIndices(BoxInfo *bi=0) const
sort entries, as needed for loopRange()
RooListProxy _rhoList
do not persist
std::vector< Int_t > _sIdcs
std::vector< Double_t > _xVarLo
void calculatePreNorm(BoxInfo *bi) const
bi->nEventsBMSW=0.
Double_t analyticalIntegral(Int_t code, const char *rangeName=0) const
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
std::vector< Double_t > _xDatLo3s
std::vector< Double_t > _x0
std::vector< Double_t > _xVarLoP3s
void loadWeightSet() const
std::vector< Double_t > _xDatHi3s
void setOptions() const
set the configuration
std::vector< Int_t > _bIdcs
std::vector< TVectorD > _dataPtsR
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::vector< Double_t > _xVarHi
void initialize() const
initialization
void calculateShell(BoxInfo *bi) const
determine points in +/- nSigma shell around the box determined by the variable ranges.
std::vector< Double_t > _x1
std::vector< Double_t > _mean
std::vector< Int_t > _bmsIdcs
const RooAbsData & _data
do not persist
std::vector< Double_t > _rho
std::vector< Double_t > _xDatHi
std::vector< Double_t > _x
std::vector< itVec > _sortTVIdcs
void boxInfoInit(BoxInfo *bi, const char *rangeName, Int_t code) const
std::map< std::pair< std::string, int >, BoxInfo * > _rangeBoxInfo
std::vector< Double_t > _xVarLoM3s
std::vector< Int_t > _idx
std::vector< Double_t > _xDatLo
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
std::vector< std::vector< Double_t > > * _weights
TMatrixD getWeights(const int &k) const
Return evaluated weights.
std::vector< Double_t > _xVarHiM3s
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.
Double_t evaluate() const
do not persist
std::map< Int_t, Bool_t > _ibNoSort
std::vector< std::vector< Double_t > > _weights0
void mirrorDataSet() const
determine mirror dataset.
std::vector< std::vector< Double_t > > _dataPts
RooDataSet * createDatasetFromHist(const RooArgList &varList, const TH1 &hist) const
std::vector< Double_t > _sigma
std::vector< std::string > _varName
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()
void createPdf(Bool_t firstCall=kTRUE) const
evaluation order of constructor.
std::map< Int_t, Double_t > _wMap
std::vector< std::vector< Double_t > > _weights1
std::vector< Double_t > _x2
void loadDataSet(Bool_t firstCall) const
copy the dataset and calculate some useful variables
std::vector< Double_t > _xVarHiP3s
std::map< Int_t, Bool_t > _bpsIdcs
RooChangeTracker * _tracker
void calculateBandWidth() const
RooRealVar represents a fundamental (non-derived) real valued object.
virtual void setVal(Double_t value)
Set value of variable to 'value'.
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Iterator abstract base class.
virtual TObject * Next()=0
const TVectorD & GetEigenValues() const
const TMatrixD & GetEigenVectors() const
void Print(Option_t *name="") const
Print the matrix as a table of elements.
virtual TMatrixTBase< Element > & Zero()
Set matrix elements to zero.
TMatrixT< Element > & T()
virtual const char * GetName() const
Returns name of object.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
void ToLower()
Change string to lower-case.
const char * Data() const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TVectorT< Element > & Zero()
Set vector elements to zero.
void Print(Option_t *option="") const
Print the vector as a list of elements.
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
Double_t Erf(Double_t x)
Computation of the error function erf(x).
constexpr Double_t E()
Base of natural log:
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
std::vector< Double_t > xVarHiP3s
std::vector< Double_t > xVarHi
std::map< Int_t, Bool_t > bpsIdcs
std::vector< Int_t > bIdcs
std::vector< Double_t > xVarLoM3s
std::vector< Double_t > xVarHiM3s
std::vector< Double_t > xVarLoP3s
std::vector< Double_t > xVarLo
std::vector< Int_t > sIdcs
std::vector< Int_t > bmsIdcs