40 _parItr = _parList.createIterator();
41 _obsItr = _obsList.createIterator();
49 :
RooAbsPdf(
name, title), _cacheMgr(this, 10,
kTRUE,
kTRUE), _parList(
"parList",
"List of morph parameters", this),
50 _obsList(
"obsList",
"List of observables", this), _referenceGrid(referenceGrid),
51 _pdfList(
"pdfList",
"List of pdfs", this), _setting(setting), _useHorizMorph(true)
70 :
RooAbsPdf(
name, title), _cacheMgr(this, 10,
kTRUE,
kTRUE), _parList(
"parList",
"List of morph parameters", this),
71 _obsList(
"obsList",
"List of observables", this), _pdfList(
"pdfList",
"List of pdfs", this), _setting(setting),
78 for (
int i = 0; i < mrefpoints.
GetNrows(); ++i) {
80 if (mrefpoints[i] == grid.
array()[j]) {
106 :
RooAbsPdf(
name, title), _cacheMgr(this, 10,
kTRUE,
kTRUE), _parList(
"parList",
"List of morph parameters", this),
107 _obsList(
"obsList",
"List of observables", this), _pdfList(
"pdfList",
"List of pdfs", this), _setting(setting),
114 for (
int i = 0; (mref =
dynamic_cast<RooAbsReal *
>(mrefItr->
Next())); ++i) {
117 <<
" is not of type RooAbsReal" << endl;
118 throw string(
"RooMomentMorphND::ctor() ERROR mref is not of type RooAbsReal");
122 <<
" is not a constant, taking a snapshot of its value" << endl;
124 mrefpoints[i] = mref->
getVal();
131 for (
int i = 0; i < mrefpoints.
GetNrows(); ++i) {
133 if (mrefpoints[i] == grid.
array()[j]) {
158 :
RooAbsPdf(other,
name), _cacheMgr(other._cacheMgr, this), _curNormSet(0),
159 _parList(
"parList", this, other._parList), _obsList(
"obsList", this, other._obsList),
160 _referenceGrid(other._referenceGrid), _pdfList(
"pdfList", this, other._pdfList), _M(0), _MSqr(0),
161 _setting(other._setting), _useHorizMorph(other._useHorizMorph)
195 <<
" is not of type RooAbsReal" << endl;
196 throw string(
"RooMomentMorphND::initializeParameters() ERROR parameter is not of type RooAbsReal");
213 <<
" is not of type RooAbsReal" << endl;
214 throw string(
"RooMomentMorphND::initializeObservables() ERROR variable is not of type RooAbsReal");
227 typename vector<T>::const_iterator begin;
228 typename vector<T>::const_iterator end;
229 typename vector<T>::const_iterator me;
235 vector<Digits<T>> vd;
237 for (
typename vector<vector<T>>::const_iterator it = in.begin(); it != in.end(); ++it) {
238 Digits<T>
d = {(*it).begin(), (*it).end(), (*it).begin()};
244 for (
typename vector<Digits<T>>::const_iterator it = vd.begin(); it != vd.end(); ++it) {
245 result.push_back(*(it->me));
247 out.push_back(result);
249 for (
typename vector<Digits<T>>::iterator it = vd.begin();;) {
251 if (it->me == it->end) {
252 if (it + 1 == vd.end()) {
293 <<
": " << nPar <<
" !=" << nDim << endl;
299 <<
": " << nPdf <<
" !=" << nRef << endl;
309 vector<vector<double>> dm(nPdf);
310 for (
int k = 0; k < nPdf; ++k) {
312 for (
int idim = 0; idim < nPar; idim++) {
314 dm2.push_back(delta);
319 vector<vector<int>> powers;
320 for (
int idim = 0; idim < nPar; idim++) {
325 powers.push_back(xtmp);
328 vector<vector<int>>
output;
330 int nCombs =
output.size();
332 for (
int k = 0; k < nPdf; ++k) {
334 for (
int i = 0; i < nCombs; i++) {
336 for (
int ix = 0; ix < nPar; ix++) {
356 : _grid(other._grid), _pdfList(other._pdfList), _pdfMap(other._pdfMap), _nref(other._nref)
368 vector<int> thisBoundaries;
369 vector<double> thisBoundaryCoordinates;
370 thisBoundaries.push_back(bin_x);
371 thisBoundaryCoordinates.push_back(_grid[0]->array()[bin_x]);
374 _nref.push_back(thisBoundaryCoordinates);
380 vector<int> thisBoundaries;
381 vector<double> thisBoundaryCoordinates;
382 thisBoundaries.push_back(bin_x);
383 thisBoundaryCoordinates.push_back(_grid[0]->array()[bin_x]);
384 thisBoundaries.push_back(bin_y);
385 thisBoundaryCoordinates.push_back(_grid[1]->array()[bin_y]);
388 _nref.push_back(thisBoundaryCoordinates);
394 vector<int> thisBoundaries;
395 vector<double> thisBoundaryCoordinates;
396 thisBoundaries.push_back(bin_x);
397 thisBoundaryCoordinates.push_back(_grid[0]->array()[bin_x]);
398 thisBoundaries.push_back(bin_y);
399 thisBoundaryCoordinates.push_back(_grid[1]->array()[bin_y]);
400 thisBoundaries.push_back(bin_z);
401 thisBoundaryCoordinates.push_back(_grid[2]->array()[bin_z]);
404 _nref.push_back(thisBoundaryCoordinates);
410 vector<double> thisBoundaryCoordinates;
411 int nBins = bins.size();
412 for (
int i = 0; i < nBins; i++) {
413 thisBoundaryCoordinates.push_back(_grid[i]->array()[bins[i]]);
417 _nref.push_back(thisBoundaryCoordinates);
434 vector<RooAbsReal *> meanrv(nPdf * nObs,
null);
435 vector<RooAbsReal *> sigmarv(nPdf * nObs,
null);
436 vector<RooAbsReal *> myrms(nObs,
null);
437 vector<RooAbsReal *> mypos(nObs,
null);
438 vector<RooAbsReal *> slope(nPdf * nObs,
null);
439 vector<RooAbsReal *> offsetrv(nPdf * nObs,
null);
440 vector<RooAbsReal *> transVar(nPdf * nObs,
null);
441 vector<RooAbsReal *> transPdf(nPdf,
null);
451 for (
int i = 0; i < 3 * nPdf; ++i) {
452 string fracName =
Form(
"frac_%d", i);
453 double initval = 0.0;
459 else if (i < 2 * nPdf)
472 for (
int i = 0; i < nPdf; ++i) {
473 for (
int j = 0; j < nObs; ++j) {
480 sigmarv[
sij(i, j)] = mom;
481 meanrv[
sij(i, j)] = mom->
mean();
483 ownedComps.
add(*sigmarv[
sij(i, j)]);
488 for (
int j = 0; j < nObs; ++j) {
491 for (
int i = 0; i < nPdf; ++i) {
492 meanList.
add(*meanrv[
sij(i, j)]);
493 rmsList.
add(*sigmarv[
sij(i, j)]);
495 string myrmsName =
Form(
"%s_rms_%d",
GetName(), j);
496 string myposName =
Form(
"%s_pos_%d",
GetName(), j);
497 mypos[j] =
new RooAddition(myposName.c_str(), myposName.c_str(), meanList, coefList2);
498 myrms[j] =
new RooAddition(myrmsName.c_str(), myrmsName.c_str(), rmsList, coefList3);
507 for (
int i = 0; i < nPdf; ++i) {
512 string pdfName =
Form(
"pdf_%d", i);
515 for (
int j = 0; j < nObs; ++j) {
517 string slopeName =
Form(
"%s_slope_%d_%d",
GetName(), i, j);
518 string offsetName =
Form(
"%s_offset_%d_%d",
GetName(), i, j);
528 string transVarName =
Form(
"%s_transVar_%d_%d",
GetName(), i, j);
529 transVar[
sij(i, j)] =
new RooLinearVar(transVarName.c_str(), transVarName.c_str(), *var, *slope[
sij(i, j)],
530 *offsetrv[
sij(i, j)]);
536 ownedComps.
add(*transVar[
sij(i, j)]);
540 transPdfList.
add(*transPdf[i]);
541 ownedComps.
add(*transPdf[i]);
545 theSumPdf =
new RooAddPdf(sumpdfName.c_str(), sumpdfName.c_str(), transPdfList, coefList);
547 theSumPdf =
new RooAddPdf(sumpdfName.c_str(), sumpdfName.c_str(),
_pdfList, coefList);
556 string trackerName =
Form(
"%s_frac_tracker",
GetName());
560 cache =
new CacheElem(*theSumPdf, *tracker, fracl);
627template <
typename Iterator>
630 if ((
first == last) || (
first == k) || (last == k)) {
633 Iterator itr1 =
first;
634 Iterator itr2 = last;
643 while (
first != itr1) {
644 if (*--itr1 < *itr2) {
646 while (!(*itr1 < *j)) ++j;
651 rotate(itr1, j, last);
656 rotate(k, itr2, last);
660 rotate(
first, k, last);
676 for (
int idim = 0; idim < nPar; idim++) {
678 dm2.push_back(delta);
681 vector<vector<int>> powers;
682 for (
int idim = 0; idim < nPar; idim++) {
687 powers.push_back(xtmp);
690 vector<vector<int>>
output;
692 int nCombs =
output.size();
694 vector<double> deltavec(nPdf, 1.0);
697 for (
int i = 0; i < nCombs; i++) {
699 for (
int ix = 0; ix < nPar; ix++) {
703 deltavec[nperm] = tmpDm;
707 double sumposfrac = 0.0;
708 for (
int i = 0; i < nPdf; ++i) {
711 for (
int j = 0; j < nPdf; ++j) {
712 ffrac += (*self.
_M)(j, i) * deltavec[j] * fracNonLinear;
725 ((
RooRealVar *)frac(nPdf + i))->setVal(ffrac);
726 ((
RooRealVar *)frac(2 * nPdf + i))->setVal(ffrac);
729 cout <<
"NonLinear fraction " << ffrac << endl;
731 frac(nPdf + i)->Print();
732 frac(2 * nPdf + i)->Print();
737 for (
int i = 0; i < nPdf; ++i) {
751 for (
int i = 0; i < nPdf; ++i) {
754 ((
RooRealVar *)frac(nPdf + i))->setVal(initval);
755 ((
RooRealVar *)frac(2 * nPdf + i))->setVal(initval);
760 for (
int j = 0; j < nPar; j++) {
762 mtmp.push_back(
m->getVal());
768 vector<double> deltavec(depth, 1.0);
773 for (
int ix = 0; ix < nPar; ix++) {
777 for (
int iperm = 1; iperm <= nPar; ++iperm) {
779 double dtmp = mtmp[xtmp[0]] - self.
_squareVec[0][xtmp[0]];
780 for (
int itmp = 1; itmp < iperm; ++itmp) {
781 dtmp *= mtmp[xtmp[itmp]] - self.
_squareVec[0][xtmp[itmp]];
783 deltavec[nperm + 1] = dtmp;
788 Double_t origFrac1(0.), origFrac2(0.);
789 for (
int i = 0; i < depth; ++i) {
791 for (
int j = 0; j < depth; ++j) {
792 ffrac += (*self.
_MSqr)(j, i) * deltavec[j] * fracLinear;
808 cout <<
"Linear fraction " << ffrac << endl;
836 vector<vector<double>> boundaries(nPar);
837 for (
int idim = 0; idim < nPar; idim++) {
841 boundaries[idim].push_back(lo);
842 boundaries[idim].push_back(
hi);
845 vector<vector<double>>
output;
849 for (
int isq = 0; isq < depth; isq++) {
850 for (
int iref = 0; iref < nRef; iref++) {
873 for (
int ix = 0; ix < nPar; ix++) {
877 for (
int k = 0; k < depth; ++k) {
883 for (
int iperm = 1; iperm <= nPar; ++iperm) {
885 double dtmp =
_squareVec[k][xtmp[0]] - squareBase[xtmp[0]];
886 for (
int itmp = 1; itmp < iperm; ++itmp) {
887 dtmp *=
_squareVec[k][xtmp[itmp]] - squareBase[xtmp[itmp]];
889 M(k, nperm + 1) = dtmp;
909 cout <<
"Currently BinIntegrator only knows how to deal with 1-d " << endl;
bool next_combination(const Iterator first, Iterator k, const Iterator last)
void cartesian_product(vector< vector< T > > &out, vector< vector< T > > &in)
float type_of_call hi(const int &, const int &)
TMatrixT< Double_t > TMatrixD
char * Form(const char *fmt,...)
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Bool_t addOwnedComponents(const RooArgSet &comps)
Take ownership of the contents of 'comps'.
void addServerList(RooAbsCollection &serverList, Bool_t valueProp=kTRUE, Bool_t shapeProp=kFALSE)
Register a list of RooAbsArg as servers to us by calling addServer() for each arg in the list.
void setLocalNoDirtyInhibit(Bool_t flag) const
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
RooAbsArg * first() const
TIterator * createIterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
TIterator-style iteration over contained elements.
RooAbsMoment represents the first, second, or third order derivative of any RooAbsReal as calculated ...
const RooArgSet * nset() const
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
RooAbsMoment * sigma(RooRealVar &obs)
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
RooAddition calculates the sum of a set of RooAbsReal terms, or when constructed with two sets,...
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.
Bool_t setRealValue(const char *name, Double_t newVal=0, Bool_t verbose=kFALSE)
Set value of a RooAbsRealLValye stored in set with given name to newVal No error messages are printed...
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...
Class RooBinning is an implements RooAbsBinning in terms of an array of boundary values,...
virtual Int_t numBoundaries() const
virtual Double_t * array() const
Return array of boundary values.
T * getObj(const RooArgSet *nset, Int_t *sterileIndex=0, const TNamed *isetRangeName=0)
Int_t setObj(const RooArgSet *nset, T *obj, const TNamed *isetRangeName=0)
virtual Bool_t setLabel(const char *label, Bool_t printError=kTRUE)
Set value by specifying the name of the desired state If printError is set, a message will be printed...
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.
RooConstVar represent a constant real-valued object.
RooCustomizer is a factory class to produce clones of a prototype composite PDF object with the same ...
void replaceArg(const RooAbsArg &orig, const RooAbsArg &subst)
Replace any occurence of arg 'orig' with arg 'subst'.
RooAbsArg * build(const char *masterCatState, Bool_t verbose=kFALSE)
Build a clone of the prototype executing all registered 'replace' rules and 'split' rules for the mas...
RooLinearVar is the most general form of a derived real-valued object that can be used by RooRealInte...
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
RooChangeTracker * _tracker
virtual RooArgList containedArgs(Action)
void calculateFractions(const RooMomentMorphND &self, Bool_t verbose=kTRUE) const
void addBinning(const RooAbsBinning &binning)
std::vector< std::vector< double > > _nref
std::vector< RooAbsBinning * > _grid
void addPdf(const RooAbsPdf &pdf, int bin_x)
std::vector< int > _nnuis
virtual Double_t getVal(const RooArgSet *set=0) const
std::vector< int > _squareIdx
Grid _referenceGrid
Do not persist.
CacheElem * getCache(const RooArgSet *nset) const
RooObjCacheManager _cacheMgr
Bool_t setBinIntegrator(RooArgSet &allVars)
std::vector< std::vector< double > > _squareVec
void initializeObservables(const RooArgList &obsList)
int sij(const int &i, const int &j) const
void findShape(const std::vector< double > &x) const
Double_t evaluate() const
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
TIterator * _obsItr
Do not persist.
virtual ~RooMomentMorphND()
RooAbsPdf * sumPdf(const RooArgSet *nset)
void initializeParameters(const RooArgList &parList)
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
RooRealVar represents a variable that can be changed from the outside.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Overloaded RooArgSet::add() method inserts 'var' into set and registers 'var' as server to owner with...
Iterator abstract base class.
virtual TObject * Next()=0
TMatrixT< Element > & Invert(Double_t *det=0)
Invert the matrix and calculate its determinant.
virtual const char * GetName() const
Returns name of object.
Element * GetMatrixArray()
std::shared_ptr< std::function< double(double)> > Linear
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
static void output(int code)