73 :
RooAbsPdf(
name, title), _varList(
"varList",
"List of variables", this),
74 _rhoList(
"rhoList",
"List of rho parameters", this), _data(&data), _options(options), _widthFactor(rho),
75 _nSigma(nSigma), _weights(&_weights0), _rotate(rotate), _sortInput(sortInput), _nAdpt(1), _tracker(0)
79 for (
const auto var : varList) {
82 <<
" is not of type RooAbsReal" << endl ;
97 :
RooAbsPdf(
name, title), _varList(
"varList",
"List of variables", this),
98 _rhoList(
"rhoList",
"List of rho parameters", this), _ownedData(createDatasetFromHist(varList, hist)), _data(_ownedData.get()),
99 _options(options), _widthFactor(rho), _nSigma(nSigma), _weights(&_weights0), _rotate(rotate),
100 _sortInput(sortInput), _nAdpt(1), _tracker(0)
102 for (
const auto var : varList) {
105 <<
" is not of type RooAbsReal" << endl;
120 :
RooAbsPdf(
name, title), _varList(
"varList",
"List of variables", this),
121 _rhoList(
"rhoList",
"List of rho parameters", this), _data(&data), _options(options), _widthFactor(-1.0),
122 _nSigma(nSigma), _weights(&_weights0), _rotate(rotate), _sortInput(sortInput), _nAdpt(1), _tracker(0)
124 for (
const auto var : varList) {
127 <<
" is not of type RooAbsReal" << endl;
137 <<
"ERROR: RooNDKeysPdf::RooNDKeysPdf() : The vector-size of rho is different from that of varList."
138 <<
"Unable to create the PDF." << endl;
159 :
RooAbsPdf(
name, title), _varList(
"varList",
"List of variables", this),
160 _rhoList(
"rhoList",
"List of rho parameters", this), _data(&data), _options(options), _widthFactor(-1.0),
161 _nSigma(nSigma), _weights(&_weights0), _rotate(rotate), _sortInput(sortInput), _nAdpt(1)
163 for (
const auto var : varList) {
166 <<
" is not of type RooAbsReal" << endl;
175 for (
unsigned int i=0; i < rhoList.
size(); ++i) {
176 const auto rho = rhoList.
at(i);
179 <<
" is not of type RooRealVar" << endl;
188 coutE(
InputArguments) <<
"ERROR: RooNDKeysPdf::RooNDKeysPdf() : The size of rhoList is different from varList."
189 <<
"Unable to create the PDF." << endl;
205 :
RooAbsPdf(
name, title), _varList(
"varList",
"List of variables", this),
206 _rhoList(
"rhoList",
"List of rho parameters", this), _ownedData(createDatasetFromHist(varList, hist)), _data(_ownedData.get()),
207 _options(options), _widthFactor(-1), _nSigma(nSigma), _weights(&_weights0), _rotate(rotate), _sortInput(sortInput),
210 for (
const auto var : varList) {
213 <<
" is not of type RooAbsReal" << endl;
223 for (
unsigned int i=0; i < rhoList.
size(); ++i) {
224 const auto rho = rhoList.
at(i);
227 <<
" is not of type RooRealVar" << endl;
235 coutE(
InputArguments) <<
"ERROR: RooNDKeysPdf::RooNDKeysPdf() : The size of rhoList is different from varList."
236 <<
"Unable to create the PDF." << endl;
252 :
RooAbsPdf(
name, title), _varList(
"varList",
"List of variables", this),
253 _rhoList(
"rhoList",
"List of rho parameters", this), _data(&data), _options(
"a"), _widthFactor(rho),
254 _nSigma(nSigma), _weights(&_weights0), _rotate(rotate), _sortInput(sortInput), _nAdpt(1), _tracker(0)
261 coutW(
InputArguments) <<
"RooNDKeysPdf::RooNDKeysPdf() : Warning : asymmetric mirror(s) no longer supported."
275 :
RooAbsPdf(
name, title), _varList(
"varList",
"List of variables", this),
276 _rhoList(
"rhoList",
"List of rho parameters", this), _data(&data), _options(options), _widthFactor(rho),
277 _nSigma(nSigma), _weights(&_weights0), _rotate(rotate), _sortInput(sortInput), _nAdpt(1), _tracker(0)
290 :
RooAbsPdf(other,
name), _varList(
"varList", this, other._varList), _rhoList(
"rhoList", this, other._rhoList),
291 _ownedData(other._ownedData ? new
RooDataSet(*other._ownedData) : nullptr),
292 _data(_ownedData ? _ownedData.get() : other._data), _options(other._options), _widthFactor(other._widthFactor),
293 _nSigma(other._nSigma), _weights(&_weights0), _rotate(other._rotate), _sortInput(other._sortInput),
436 <<
"\n\tdebug = " <<
_debug
442 <<
"Calculated normalization could be too large."
469 coutE(
InputArguments) <<
"ERROR: RooNDKeysPdf::initialize() : The observable list is empty. "
470 <<
"Unable to begin generating the PDF." << endl;
475 coutE(
InputArguments) <<
"ERROR: RooNDKeysPdf::initialize() : The input data set is empty. "
476 <<
"Unable to begin generating the PDF." << endl;
545 vector<RooRealVar*> dVars(
_nDim);
556 vector<Double_t>& point =
_dataPts[i];
565 mat(j,k) += dVars[j]->getVal() * dVars[k]->getVal() * myweight;
569 point[j] = pointV[j] = dVars[j]->getVal();
571 _x0[j] += 1. * myweight;
572 _x1[j] += point[j] * myweight ;
573 _x2[j] += point[j] * point[j] * myweight ;
574 if (
_x2[j]!=
_x2[j]) exit(3);
607 for (
Int_t j=0; j<
_nDim; j++) { sigmaRraw[j] =
sqrt(sigmaRraw[j]); }
646 coutI(
Contents) <<
"RooNDKeysPdf::loadDataSet(" <<
this <<
")"
647 <<
"\n Number of events in dataset: " <<
_nEvents
648 <<
"\n Weighted number of events in dataset: " <<
_nEventsW << endl;
675 vector<vector<Double_t> > mpoints(size,
dummy);
676 vector<vector<Int_t> > mjdcs(size);
681 vector<Int_t>& mjdxK = mjdcs[0];
682 vector<Double_t>& mpointK = mpoints[0];
694 vector<Int_t>& mjdx0 = mjdcs[0];
696 if (size==1 && mjdx0.size()==0)
continue;
700 vector<Int_t>& mjdx = mjdcs[0];
701 vector<Double_t>& mpoint = mpoints[0];
704 Int_t eMir = 1 << mjdx.size();
705 vector<vector<Double_t> > epoints(eMir,
x);
712 epoints[
l] = epoints[
l-size1];
714 vector<Double_t>& epoint = epoints[
l];
715 epoint[mjdx[
Int_t(mjdx.size()-1)-
m]] = mpoint[mjdx[
Int_t(mjdx.size()-1)-
m]];
721 epoints.erase(epoints.begin());
730 for (
Int_t j=0; j<
_nDim; j++) { pointR[j] = (epoints[
m])[j]; }
759 coutI(
Contents) <<
"RooNDKeysPdf::loadWeightSet(" <<
this <<
") : Number of weighted events : " <<
_wMap.size() << endl;
785 map<Int_t,Double_t>::iterator wMapItr =
_wMap.begin();
788 for (; wMapItr!=
_wMap.end(); ++wMapItr) {
789 Int_t i = (*wMapItr).first;
798 inVarRange = inVarRange &&
kTRUE;
799 }
else { inVarRange = inVarRange &&
kFALSE; }
802 inVarRangePlusShell = inVarRangePlusShell &&
kTRUE;
803 }
else { inVarRangePlusShell = inVarRangePlusShell &&
kFALSE; }
808 bi->
bIdcs.push_back(i);
812 if (inVarRangePlusShell) {
822 if (inShell) bi->
sIdcs.push_back(i);
830 <<
"\n Events in shell " << bi->
sIdcs.size()
831 <<
"\n Events in box " << bi->
bIdcs.size()
832 <<
"\n Events in box and shell " << bi->
bpsIdcs.size()
850 cxcoutD(
Eval) <<
"RooNDKeysPdf::calculatePreNorm() : "
864 for (
unsigned int i = 0; i <
_dataPtsR.size(); ++i) {
871 vector<TVectorD>::iterator dpRItr =
_dataPtsR.begin();
876 itrVecR.push_back(
itPair(i, dpRItr));
878 itrVecR.push_back(
itPair(i, dpRItr));
884 sort(itrVecR.begin(), itrVecR.end(), [=](
const itPair&
a,
const itPair&
b) {
885 return (*a.second)[j] < (*b.second)[j];
891 cxcoutD(
Eval) <<
"RooNDKeysPdf::sortDataIndices() : Number of sorted events : " <<
_sortTVIdcs[j].size() << endl;
899 cxcoutD(
Eval) <<
"RooNDKeysPdf::calculateBandWidth()" << endl;
905 cxcoutD(
Eval) <<
"RooNDKeysPdf::calculateBandWidth() Using static bandwidth." << endl;
912 weight[j] =
_n * (*_sigmaR)[j];
919 cxcoutD(
Eval) <<
"RooNDKeysPdf::calculateBandWidth() Using adaptive bandwidth." << endl;
921 double sqrt12 =
sqrt(12.);
927 std::vector<std::vector<Double_t>> *weights_prev(0);
928 std::vector<std::vector<Double_t>> *weights_new(0);
949 vector<Double_t> &weight = (*weights_new)[i];
951 Double_t norm = (
_n * (*_sigmaR)[j]) / sqrtSigmaAvgR;
952 weight[j] = norm *
f / sqrt12;
971 map<Int_t,Bool_t> ibMap;
981 map<Int_t, Bool_t>::iterator ibMapItr, ibMapEnd;
985 for (; ibMapItr != ibMapEnd; ++ibMapItr) {
986 Int_t i = (*ibMapItr).first;
994 const vector<Double_t> &point =
_dataPts[i];
995 const vector<Double_t> &weight = weights[
_idx[i]];
998 (*_dx)[j] =
x[j] - point[j];
1007 Double_t c = 1. / (2. * weight[j] * weight[j]);
1012 g *= 1. / (sqrt2pi * weight[j]);
1029 xRm[j] = xRp[j] =
x[j];
1037 xRm[j] -=
_nSigma * (
_n * (*_sigmaR)[j]);
1038 xRp[j] +=
_nSigma * (
_n * (*_sigmaR)[j]);
1043 vector<TVectorD> xvecRm(1,xRm);
1044 vector<TVectorD> xvecRp(1,xRp);
1046 map<Int_t,Bool_t> ibMapRT;
1051 return (*
a.second)[j] < (*
b.second)[j];
1059 if (
_nDim==1) {
for (it=lo; it!=
hi; ++it) ibMap[(*it).first] =
kTRUE; }
1060 else {
for (it=lo; it!=
hi; ++it) ibMapRT[(*it).first] =
kTRUE; }
1064 for (it=lo; it!=
hi; ++it)
1065 if (ibMapRT.find((*it).first)!=ibMapRT.end()) { ibMap[(*it).first] =
kTRUE; }
1068 if (j!=
_nDim-1) { ibMapRT = ibMap; }
1099 bi->
xVarLo[j] = var->getMin(rangeName);
1100 bi->
xVarHi[j] = var->getMax(rangeName);
1102 bi->
xVarLo[j] = var->getVal() ;
1103 bi->
xVarHi[j] = var->getVal() ;
1121 _x[j] = var->getVal(nset);
1137 if (rangeName)
return 0 ;
1150 cxcoutD(
Eval) <<
"Calling RooNDKeysPdf::analyticalIntegral(" <<
GetName() <<
") with code " << code
1151 <<
" and rangeName " << (rangeName?rangeName:
"<none>") << endl;
1163 string rangeNameStr(rangeName) ;
1176 if ((var->getMin(rangeName)-bi->
xVarLo[j]!=0) ||
1177 (var->getMax(rangeName)-bi->
xVarHi[j]!=0)) {
1184 cxcoutD(
Eval) <<
"RooNDKeysPdf::analyticalIntegral() : Found new boundaries ... " << (rangeName?rangeName:
"<none>") << endl;
1189 if (!bi->
filled || newBounds) {
1202 cxcoutD(
Eval) <<
"RooNDKeysPdf::analyticalIntegral() : Using mirrored normalization : " << bi->
nEventsBW << endl;
1209 if (norm<0.) norm=0.;
1214 const vector<Double_t>& weight = (*_weights)[
_idx[bi->
sIdcs[i]]];
1216 vector<Double_t> chi(
_nDim,100.);
1219 if(!doInt[j])
continue;
1222 chi[j] = (
x[j]-bi->
xVarLo[j])/weight[j];
1224 chi[j] = (bi->
xVarHi[j]-
x[j])/weight[j];
1235 cxcoutD(
Eval) <<
"RooNDKeysPdf::analyticalIntegral() : Final normalization : " << norm <<
" " << bi->
nEventsBW << endl;
1245 std::vector<RooRealVar *> varVec;
1248 for (
const auto var : varList) {
1251 << var->GetName() <<
" is not of type RooRealVar. Skip." << endl;
1254 varsAndWeightSet.
add(*var);
1255 varVec.push_back(
static_cast<RooRealVar *
>(var));
1259 RooRealVar weight(
"weight",
"event weight", 0);
1260 varsAndWeightSet.
add(weight);
1263 unsigned int histndim(0);
1264 std::string classname = hist.
ClassName();
1265 if (classname.find(
"TH1") == 0) {
1267 }
else if (classname.find(
"TH2") == 0) {
1269 }
else if (classname.find(
"TH3") == 0) {
1272 assert(histndim == varVec.size());
1274 if (histndim > 3 || histndim <= 0) {
1276 <<
") ERROR: input histogram dimension not between [1-3]: " << histndim << endl;
1284 for (
int i = 1; i <= hist.
GetXaxis()->GetNbins(); ++i) {
1288 varVec[0]->setVal(xval);
1290 if (varVec.size() == 1) {
1293 dataFromHist->
add(varsAndWeightSet, fval);
1296 for (
int j = 1; j <= hist.
GetYaxis()->GetNbins(); ++j) {
1298 varVec[1]->setVal(yval);
1300 if (varVec.size() == 2) {
1303 dataFromHist->
add(varsAndWeightSet, fval);
1306 for (
int k = 1; k <= hist.
GetZaxis()->GetNbins(); ++k) {
1308 varVec[2]->setVal(zval);
1312 dataFromHist->
add(varsAndWeightSet, fval);
1319 return dataFromHist;
1330 cxcoutD(
Eval) <<
"RooNDKeysPdf::getWeights() Return evaluated weights." << endl;
1338 vector<Double_t> &weight = (*_weights)[i];
1339 mref(i,
_nDim) = weight[k];
1350 _rho[j] = rho->getVal();
1357 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
TIterator end() or range-based loops.")
Storage_t::size_type size() const
RooAbsArg * find(const char *name) const
Find object with given name in list.
virtual Int_t numEntries() const
const RooArgSet * nset() const
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
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().
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
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 changed since last call with clearState=kTRUE.
RooDataSet is a container class to hold unbinned data.
virtual const RooArgSet * get(Int_t index) const override
Return RooArgSet with coordinates of event 'index'.
virtual void add(const RooArgSet &row, Double_t weight=1.0, Double_t weightError=0) override
Add a data point, with its coordinates specified in the 'data' argset, to the data set.
virtual Double_t weight() const override
Return event weight of current event.
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.
std::vector< Int_t > _sIdcs
void initialize()
initialization
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
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 createPdf(Bool_t firstCall=kTRUE)
evaluation order of constructor.
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
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
void sortDataIndices(BoxInfo *bi=0)
sort entries, as needed for loopRange()
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
TString _options
do not persist
std::vector< std::vector< Double_t > > * _weights
TMatrixD getWeights(const int &k) const
Return evaluated weights.
std::vector< Double_t > _xVarHiM3s
Double_t evaluate() const
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
std::map< Int_t, Bool_t > _ibNoSort
std::vector< std::vector< Double_t > > _weights0
void mirrorDataSet() const
determine mirror dataset.
void setOptions()
set the configuration
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()
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 variable that can be changed from the outside.
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.
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)
constexpr Double_t TwoPi()
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