50 _cacheMgr(this, 10, true, true),
51 _parList(
"parList",
"List of morph parameters", this),
52 _obsList(
"obsList",
"List of observables", this),
53 _referenceGrid(referenceGrid),
54 _pdfList(
"pdfList",
"List of pdfs", this),
76 _cacheMgr(this, 10, true, true),
77 _parList(
"parList",
"List of morph parameters", this),
78 _obsList(
"obsList",
"List of observables", this),
79 _pdfList(
"pdfList",
"List of pdfs", this),
87 for (
int i = 0; i < mrefpoints.
GetNrows(); ++i) {
89 if (mrefpoints[i] == grid.
array()[j]) {
116 _cacheMgr(this, 10, true, true),
117 _parList(
"parList",
"List of morph parameters", this),
118 _obsList(
"obsList",
"List of observables", this),
119 _pdfList(
"pdfList",
"List of pdfs", this),
126 for (
auto *mref : mrefList) {
128 coutE(InputArguments) <<
"RooMomentMorphFuncND::ctor(" <<
GetName() <<
") ERROR: mref " << mref->GetName()
129 <<
" is not of type RooAbsReal" << endl;
130 throw string(
"RooMomentMorphFuncND::ctor() ERROR mref is not of type RooAbsReal");
133 coutW(InputArguments) <<
"RooMomentMorphFuncND::ctor(" <<
GetName() <<
") WARNING mref point " << i
134 <<
" is not a constant, taking a snapshot of its value" << endl;
142 for (i = 0; i < mrefpoints.
GetNrows(); ++i) {
144 if (mrefpoints[i] == grid.
array()[j]) {
170 _cacheMgr(other._cacheMgr, this),
171 _parList(
"parList", this, other._parList),
172 _obsList(
"obsList", this, other._obsList),
173 _referenceGrid(other._referenceGrid),
174 _pdfList(
"pdfList", this, other._pdfList),
175 _setting(other._setting),
176 _useHorizMorph(other._useHorizMorph)
193 for (
auto *par : parList) {
195 coutE(InputArguments) <<
"RooMomentMorphFuncND::ctor(" <<
GetName() <<
") ERROR: parameter " << par->GetName()
196 <<
" is not of type RooAbsReal" << endl;
197 throw string(
"RooMomentMorphFuncND::initializeParameters() ERROR parameter is not of type RooAbsReal");
206 for (
auto *var : obsList) {
208 coutE(InputArguments) <<
"RooMomentMorphFuncND::ctor(" <<
GetName() <<
") ERROR: variable " << var->GetName()
209 <<
" is not of type RooAbsReal" << endl;
210 throw string(
"RooMomentMorphFuncND::initializeObservables() ERROR variable is not of type RooAbsReal");
231 coutE(InputArguments) <<
"RooMomentMorphFuncND::initialize(" <<
GetName() <<
") ERROR: nPar != nDim"
232 <<
": " << nPar <<
" !=" << nDim << endl;
237 coutE(InputArguments) <<
"RooMomentMorphFuncND::initialize(" <<
GetName() <<
") ERROR: nPdf != nRef"
238 <<
": " << nPdf <<
" !=" << nRef << endl;
243 _M = std::make_unique<TMatrixD>(nPdf, nPdf);
244 _MSqr = std::make_unique<TMatrixD>(depth, depth);
248 vector<vector<double>> dm(nPdf);
249 for (
int k = 0; k < nPdf; ++k) {
251 for (
int idim = 0; idim < nPar; idim++) {
253 dm2.push_back(delta);
258 vector<vector<int>> powers;
259 for (
int idim = 0; idim < nPar; idim++) {
265 powers.push_back(xtmp);
268 vector<vector<int>>
output;
270 int nCombs =
output.size();
272 for (
int k = 0; k < nPdf; ++k) {
274 for (
int i = 0; i < nCombs; i++) {
276 for (
int ix = 0; ix < nPar; ix++) {
277 double delta = dm[k][ix];
296 : _pdfList(other._pdfList), _pdfMap(other._pdfMap), _nref(other._nref)
298 for (
unsigned int i = 0; i < other.
_grid.size(); i++) {
314 vector<int> thisBoundaries;
315 vector<double> thisBoundaryCoordinates;
316 thisBoundaries.push_back(bin_x);
317 thisBoundaryCoordinates.push_back(_grid[0]->array()[bin_x]);
320 _nref.push_back(thisBoundaryCoordinates);
326 vector<int> thisBoundaries;
327 vector<double> thisBoundaryCoordinates;
328 thisBoundaries.push_back(bin_x);
329 thisBoundaryCoordinates.push_back(_grid[0]->array()[bin_x]);
330 thisBoundaries.push_back(bin_y);
331 thisBoundaryCoordinates.push_back(_grid[1]->array()[bin_y]);
334 _nref.push_back(thisBoundaryCoordinates);
340 vector<int> thisBoundaries;
341 vector<double> thisBoundaryCoordinates;
342 thisBoundaries.push_back(bin_x);
343 thisBoundaryCoordinates.push_back(_grid[0]->array()[bin_x]);
344 thisBoundaries.push_back(bin_y);
345 thisBoundaryCoordinates.push_back(_grid[1]->array()[bin_y]);
346 thisBoundaries.push_back(bin_z);
347 thisBoundaryCoordinates.push_back(_grid[2]->array()[bin_z]);
350 _nref.push_back(thisBoundaryCoordinates);
356 vector<double> thisBoundaryCoordinates;
357 int nBins = bins.size();
358 thisBoundaryCoordinates.reserve(nBins);
359 for (
int i = 0; i < nBins; i++) {
360 thisBoundaryCoordinates.push_back(_grid[i]->array()[bins[i]]);
364 _nref.push_back(thisBoundaryCoordinates);
379 vector<RooAbsReal *> meanrv(nPdf * nObs, null);
380 vector<RooAbsReal *> sigmarv(nPdf * nObs, null);
381 vector<RooAbsReal *> myrms(nObs, null);
382 vector<RooAbsReal *> mypos(nObs, null);
383 vector<RooAbsReal *> slope(nPdf * nObs, null);
384 vector<RooAbsReal *> offsets(nPdf * nObs, null);
385 vector<RooAbsReal *> transVar(nPdf * nObs, null);
386 vector<RooAbsReal *> transPdf(nPdf, null);
396 for (
int i = 0; i < 3 * nPdf; ++i) {
397 string fracName =
Form(
"frac_%d", i);
404 else if (i < 2 * nPdf)
418 for (
int i = 0; i < nPdf; ++i) {
419 for (
int j = 0; j < nObs; ++j) {
426 sigmarv[
sij(i, j)] = mom;
427 meanrv[
sij(i, j)] = mom->
mean();
429 ownedComps.
add(*sigmarv[
sij(i, j)]);
434 for (
int j = 0; j < nObs; ++j) {
437 for (
int i = 0; i < nPdf; ++i) {
438 meanList.
add(*meanrv[
sij(i, j)]);
439 rmsList.
add(*sigmarv[
sij(i, j)]);
441 string myrmsName =
Form(
"%s_rms_%d",
GetName(), j);
442 string myposName =
Form(
"%s_pos_%d",
GetName(), j);
443 mypos[j] =
new RooAddition(myposName.c_str(), myposName.c_str(), meanList, coefList2);
444 myrms[j] =
new RooAddition(myrmsName.c_str(), myrmsName.c_str(), rmsList, coefList3);
451 for (
auto const *pdf : static_range_cast<Base_t *>(
_pdfList)) {
453 string pdfName =
Form(
"pdf_%d", i);
457 for (
auto *var : static_range_cast<RooRealVar *>(obsList)) {
459 string slopeName =
Form(
"%s_slope_%d_%d",
GetName(), i, j);
460 string offsetName =
Form(
"%s_offset_%d_%d",
GetName(), i, j);
469 string transVarName =
Form(
"%s_transVar_%d_%d",
GetName(), i, j);
470 transVar[
sij(i, j)] =
new RooLinearVar(transVarName.c_str(), transVarName.c_str(), *var, *slope[
sij(i, j)],
471 *offsets[
sij(i, j)]);
477 ownedComps.
add(*transVar[
sij(i, j)]);
482 transPdfList.
add(*transPdf[i]);
483 ownedComps.
add(*transPdf[i]);
491 theSum =
new RooAddPdf(sumName.c_str(), sumName.c_str(), pdfList, coefList);
493 theSum =
new RooRealSumFunc(sumName.c_str(), sumName.c_str(), pdfList, coefList);
502 string trackerName =
Form(
"%s_frac_tracker",
GetName());
506 cache =
new CacheElem(*theSum, *tracker, fracl);
576 double fracLinear(1.);
577 double fracNonLinear(1.);
582 for (
int idim = 0; idim < nPar; idim++) {
584 dm2.push_back(delta);
587 vector<vector<int>> powers;
588 for (
int idim = 0; idim < nPar; idim++) {
594 powers.push_back(xtmp);
597 vector<vector<int>>
output;
599 int nCombs =
output.size();
601 vector<double> deltavec(nPdf, 1.0);
604 for (
int i = 0; i < nCombs; i++) {
606 for (
int ix = 0; ix < nPar; ix++) {
607 double delta = dm2[ix];
610 deltavec[nperm] = tmpDm;
614 double sumposfrac = 0.0;
615 for (
int i = 0; i < nPdf; ++i) {
618 for (
int j = 0; j < nPdf; ++j) {
619 ffrac += (*self.
_M)(j, i) * deltavec[j] * fracNonLinear;
632 ((
RooRealVar *)frac(nPdf + i))->setVal(ffrac);
633 ((
RooRealVar *)frac(2 * nPdf + i))->setVal(ffrac);
636 cout <<
"NonLinear fraction " << ffrac << endl;
638 frac(nPdf + i)->Print();
639 frac(2 * nPdf + i)->Print();
644 for (
int i = 0; i < nPdf; ++i) {
655 for (
int i = 0; i < nPdf; ++i) {
658 ((
RooRealVar *)frac(nPdf + i))->setVal(initval);
659 ((
RooRealVar *)frac(2 * nPdf + i))->setVal(initval);
662 std::vector<double> mtmp;
665 for (
auto *
m : static_range_cast<RooRealVar *>(self.
_parList)) {
666 mtmp.push_back(
m->getVal());
672 vector<double> deltavec(depth, 1.0);
678 for (
int ix = 0; ix < nPar; ix++) {
682 for (
int iperm = 1; iperm <= nPar; ++iperm) {
684 double dtmp = mtmp[xtmp[0]] - self.
_squareVec[0][xtmp[0]];
685 for (
int itmp = 1; itmp < iperm; ++itmp) {
686 dtmp *= mtmp[xtmp[itmp]] - self.
_squareVec[0][xtmp[itmp]];
688 deltavec[nperm + 1] = dtmp;
693 double origFrac1(0.), origFrac2(0.);
694 for (
int i = 0; i < depth; ++i) {
696 for (
int j = 0; j < depth; ++j) {
697 ffrac += (*self.
_MSqr)(j, i) * deltavec[j] * fracLinear;
713 cout <<
"Linear fraction " << ffrac << endl;
741 vector<vector<double>> boundaries(nPar);
742 for (
int idim = 0; idim < nPar; idim++) {
746 boundaries[idim].push_back(lo);
747 boundaries[idim].push_back(
hi);
750 vector<vector<double>>
output;
754 for (
int isq = 0; isq < depth; isq++) {
755 for (
int iref = 0; iref < nRef; iref++) {
779 for (
int ix = 0; ix < nPar; ix++) {
783 for (
int k = 0; k < depth; ++k) {
789 for (
int iperm = 1; iperm <= nPar; ++iperm) {
791 double dtmp =
_squareVec[k][xtmp[0]] - squareBase[xtmp[0]];
792 for (
int itmp = 1; itmp < iperm; ++itmp) {
793 dtmp *=
_squareVec[k][xtmp[itmp]] - squareBase[xtmp[itmp]];
795 M(k, nperm + 1) = dtmp;
815 cout <<
"Currently BinIntegrator only knows how to deal with 1-d " << endl;
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
void setLocalNoDirtyInhibit(bool flag) const
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
void addServerList(RooAbsCollection &serverList, bool valueProp=true, bool shapeProp=false)
Register a list of RooAbsArg as servers to us by calling addServer() for each arg in the list.
RooAbsBinning is the abstract base class for RooRealVar binning definitions.
Abstract container object that can hold multiple RooAbsArg objects.
Int_t getSize() const
Return the number of elements in the collection.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooAbsArg * first() const
bool setRealValue(const char *name, double newVal=0.0, bool verbose=false)
Set value of a RooAbsRealLValue stored in set with given name to newVal No error messages are printed...
RooAbsMoment represents the first, second, or third order derivative of any RooAbsReal as calculated ...
const RooArgSet * nset() const
Abstract base class for objects that represent a real value and implements functionality common to al...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
virtual double getValV(const RooArgSet *normalisationSet=nullptr) const
Return value of object.
friend class RooRealSumFunc
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
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.
Class RooBinning is an implements RooAbsBinning in terms of an array of boundary values,...
double * array() const override
Return array of boundary values.
Int_t numBoundaries() const override
Return the number boundaries.
Int_t setObj(const RooArgSet *nset, T *obj, const TNamed *isetRangeName=nullptr)
Setter function without integration set.
T * getObj(const RooArgSet *nset, Int_t *sterileIndex=nullptr, const TNamed *isetRangeName=nullptr)
Getter function without integration set.
bool setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
Meta object that tracks value changes in a given set of RooAbsArgs by registering itself as value cli...
bool hasChanged(bool clearState)
Returns true if state has changed since last call with clearState=true.
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
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 occurrence of arg 'orig' with arg 'subst'.
RooAbsArg * build(const char *masterCatState, bool verbose=false)
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...
void calculateFractions(const RooMomentMorphFuncND &self, bool verbose=true) const
RooChangeTracker * _tracker
RooArgList containedArgs(Action) override
std::vector< int > _nnuis
void addBinning(const RooAbsBinning &binning)
std::vector< RooAbsBinning * > _grid
std::vector< std::vector< double > > _nref
void addPdf(const RooAbsReal &func, int bin_x)
RooObjCacheManager _cacheMgr
! Transient cache manager
std::unique_ptr< TMatrixD > _MSqr
void findShape(const std::vector< double > &x) const
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
void initializeParameters(const RooArgList &parList)
RooAbsReal * sumFunc(const RooArgSet *nset)
CacheElem * getCache(const RooArgSet *nset) const
std::unique_ptr< TMatrixD > _M
RooArgSet * _curNormSet
! Transient cache manager
void initializeObservables(const RooArgList &obsList)
bool setBinIntegrator(RooArgSet &allVars)
double getValV(const RooArgSet *set=nullptr) const override
Return value of object.
std::vector< std::vector< double > > _squareVec
int sij(const int &i, const int &j) const
~RooMomentMorphFuncND() override
std::vector< int > _squareIdx
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.
TMatrixT< Element > & Invert(Double_t *det=nullptr)
Invert the matrix and calculate its determinant.
const char * GetName() const override
Returns name of object.
Element * GetMatrixArray()
void cartesianProduct(std::vector< std::vector< T > > &out, std::vector< std::vector< T > > &in)
bool nextCombination(const Iterator first, Iterator k, const Iterator last)
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.