40 : _cacheMgr(this, 10, true, true), _setting(
RooMomentMorphND::Linear), _useHorizMorph(true)
49 _parList(
"parList",
"List of morph parameters", this), _obsList(
"obsList",
"List of observables", this),
50 _referenceGrid(referenceGrid), _pdfList(
"pdfList",
"List of pdfs", this), _setting(setting), _useHorizMorph(true)
70 _parList(
"parList",
"List of morph parameters", this), _obsList(
"obsList",
"List of observables", this),
71 _pdfList(
"pdfList",
"List of pdfs", this), _setting(setting), _useHorizMorph(true)
77 for (
int i = 0; i < mrefpoints.
GetNrows(); ++i) {
79 if (mrefpoints[i] == grid.
array()[j]) {
106 _parList(
"parList",
"List of morph parameters", this), _obsList(
"obsList",
"List of observables", this),
107 _pdfList(
"pdfList",
"List of pdfs", this), _setting(setting), _useHorizMorph(true)
112 for (
auto *mref : mrefList) {
114 coutE(InputArguments) <<
"RooMomentMorphND::ctor(" <<
GetName() <<
") ERROR: mref " << mref->GetName()
115 <<
" is not of type RooAbsReal" << endl;
116 throw string(
"RooMomentMorphND::ctor() ERROR mref is not of type RooAbsReal");
119 coutW(InputArguments) <<
"RooMomentMorphND::ctor(" <<
GetName() <<
") WARNING mref point " << i
120 <<
" is not a constant, taking a snapshot of its value" << endl;
129 for (i = 0; i < mrefpoints.
GetNrows(); ++i) {
131 if (mrefpoints[i] == grid.
array()[j]) {
157 _obsList(
"obsList", this, other._obsList), _referenceGrid(other._referenceGrid),
158 _pdfList(
"pdfList", this, other._pdfList), _setting(other._setting), _useHorizMorph(other._useHorizMorph)
175 for (
auto *par : parList) {
177 coutE(InputArguments) <<
"RooMomentMorphND::ctor(" <<
GetName() <<
") ERROR: parameter " << par->GetName()
178 <<
" is not of type RooAbsReal" << endl;
179 throw string(
"RooMomentMorphND::initializeParameters() ERROR parameter is not of type RooAbsReal");
188 for (
auto *var : obsList) {
190 coutE(InputArguments) <<
"RooMomentMorphND::ctor(" <<
GetName() <<
") ERROR: variable " << var->GetName()
191 <<
" is not of type RooAbsReal" << endl;
192 throw string(
"RooMomentMorphND::initializeObservables() ERROR variable is not of type RooAbsReal");
213 coutE(InputArguments) <<
"RooMomentMorphND::initialize(" <<
GetName() <<
") ERROR: nPar != nDim"
214 <<
": " << nPar <<
" !=" << nDim << endl;
219 coutE(InputArguments) <<
"RooMomentMorphND::initialize(" <<
GetName() <<
") ERROR: nPdf != nRef"
220 <<
": " << nPdf <<
" !=" << nRef << endl;
225 _M = std::make_unique<TMatrixD>(nPdf, nPdf);
226 _MSqr = std::make_unique<TMatrixD>(depth, depth);
230 vector<vector<double>> dm(nPdf);
231 for (
int k = 0; k < nPdf; ++k) {
233 for (
int idim = 0; idim < nPar; idim++) {
235 dm2.push_back(delta);
240 vector<vector<int>> powers;
241 for (
int idim = 0; idim < nPar; idim++) {
246 powers.push_back(xtmp);
249 vector<vector<int>>
output;
251 int nCombs =
output.size();
253 for (
int k = 0; k < nPdf; ++k) {
255 for (
int i = 0; i < nCombs; i++) {
257 for (
int ix = 0; ix < nPar; ix++) {
258 double delta = dm[k][ix];
277 : _pdfList(other._pdfList), _pdfMap(other._pdfMap), _nref(other._nref)
279 for (
unsigned int i = 0; i < other.
_grid.size(); i++) {
295 vector<int> thisBoundaries;
296 vector<double> thisBoundaryCoordinates;
297 thisBoundaries.push_back(bin_x);
298 thisBoundaryCoordinates.push_back(_grid[0]->array()[bin_x]);
301 _nref.push_back(thisBoundaryCoordinates);
307 vector<int> thisBoundaries;
308 vector<double> thisBoundaryCoordinates;
309 thisBoundaries.push_back(bin_x);
310 thisBoundaryCoordinates.push_back(_grid[0]->array()[bin_x]);
311 thisBoundaries.push_back(bin_y);
312 thisBoundaryCoordinates.push_back(_grid[1]->array()[bin_y]);
315 _nref.push_back(thisBoundaryCoordinates);
321 vector<int> thisBoundaries;
322 vector<double> thisBoundaryCoordinates;
323 thisBoundaries.push_back(bin_x);
324 thisBoundaryCoordinates.push_back(_grid[0]->array()[bin_x]);
325 thisBoundaries.push_back(bin_y);
326 thisBoundaryCoordinates.push_back(_grid[1]->array()[bin_y]);
327 thisBoundaries.push_back(bin_z);
328 thisBoundaryCoordinates.push_back(_grid[2]->array()[bin_z]);
331 _nref.push_back(thisBoundaryCoordinates);
337 vector<double> thisBoundaryCoordinates;
338 int nBins = bins.size();
339 for (
int i = 0; i < nBins; i++) {
340 thisBoundaryCoordinates.push_back(_grid[i]->array()[bins[i]]);
344 _nref.push_back(thisBoundaryCoordinates);
359 vector<RooAbsReal *> meanrv(nPdf * nObs, null);
360 vector<RooAbsReal *> sigmarv(nPdf * nObs, null);
361 vector<RooAbsReal *> myrms(nObs, null);
362 vector<RooAbsReal *> mypos(nObs, null);
363 vector<RooAbsReal *> slope(nPdf * nObs, null);
364 vector<RooAbsReal *> offsets(nPdf * nObs, null);
365 vector<RooAbsReal *> transVar(nPdf * nObs, null);
366 vector<RooAbsReal *> transPdf(nPdf, null);
376 for (
int i = 0; i < 3 * nPdf; ++i) {
377 string fracName =
Form(
"frac_%d", i);
383 else if (i < 2 * nPdf)
390 Sum_t *theSum =
nullptr;
396 for (
int i = 0; i < nPdf; ++i) {
397 for (
int j = 0; j < nObs; ++j) {
404 sigmarv[
sij(i, j)] = mom;
405 meanrv[
sij(i, j)] = mom->
mean();
407 ownedComps.
add(*sigmarv[
sij(i, j)]);
412 for (
int j = 0; j < nObs; ++j) {
415 for (
int i = 0; i < nPdf; ++i) {
416 meanList.
add(*meanrv[
sij(i, j)]);
417 rmsList.
add(*sigmarv[
sij(i, j)]);
419 string myrmsName =
Form(
"%s_rms_%d",
GetName(), j);
420 string myposName =
Form(
"%s_pos_%d",
GetName(), j);
421 mypos[j] =
new RooAddition(myposName.c_str(), myposName.c_str(), meanList, coefList2);
422 myrms[j] =
new RooAddition(myrmsName.c_str(), myrmsName.c_str(), rmsList, coefList3);
430 for (
auto const *pdf : static_range_cast<Base_t *>(
_pdfList)) {
432 string pdfName =
Form(
"pdf_%d", i);
436 for (
auto *var : static_range_cast<RooRealVar *>(obsList)) {
438 string slopeName =
Form(
"%s_slope_%d_%d",
GetName(), i, j);
439 string offsetName =
Form(
"%s_offset_%d_%d",
GetName(), i, j);
448 string transVarName =
Form(
"%s_transVar_%d_%d",
GetName(), i, j);
449 transVar[
sij(i, j)] =
new RooLinearVar(transVarName.c_str(), transVarName.c_str(), *var, *slope[
sij(i, j)],
450 *offsets[
sij(i, j)]);
456 ownedComps.
add(*transVar[
sij(i, j)]);
461 transPdfList.
add(*transPdf[i]);
462 ownedComps.
add(*transPdf[i]);
467 theSum =
new Sum_t(sumName.c_str(), sumName.c_str(), transPdfList, coefList);
469 theSum =
new Sum_t(sumName.c_str(), sumName.c_str(),
_pdfList, coefList);
478 string trackerName =
Form(
"%s_frac_tracker",
GetName());
482 cache =
new CacheElem(*theSum, *tracker, fracl);
553 double fracLinear(1.);
554 double fracNonLinear(1.);
559 for (
int idim = 0; idim < nPar; idim++) {
561 dm2.push_back(delta);
564 vector<vector<int>> powers;
565 for (
int idim = 0; idim < nPar; idim++) {
570 powers.push_back(xtmp);
573 vector<vector<int>>
output;
575 int nCombs =
output.size();
577 vector<double> deltavec(nPdf, 1.0);
580 for (
int i = 0; i < nCombs; i++) {
582 for (
int ix = 0; ix < nPar; ix++) {
583 double delta = dm2[ix];
586 deltavec[nperm] = tmpDm;
590 double sumposfrac = 0.0;
591 for (
int i = 0; i < nPdf; ++i) {
594 for (
int j = 0; j < nPdf; ++j) {
595 ffrac += (*self.
_M)(j, i) * deltavec[j] * fracNonLinear;
608 ((
RooRealVar *)frac(nPdf + i))->setVal(ffrac);
609 ((
RooRealVar *)frac(2 * nPdf + i))->setVal(ffrac);
612 cout <<
"NonLinear fraction " << ffrac << endl;
614 frac(nPdf + i)->Print();
615 frac(2 * nPdf + i)->Print();
620 for (
int i = 0; i < nPdf; ++i) {
631 for (
int i = 0; i < nPdf; ++i) {
634 ((
RooRealVar *)frac(nPdf + i))->setVal(initval);
635 ((
RooRealVar *)frac(2 * nPdf + i))->setVal(initval);
638 std::vector<double> mtmp;
641 for (
auto *
m : static_range_cast<RooRealVar *>(self.
_parList)) {
642 mtmp.push_back(
m->getVal());
648 vector<double> deltavec(depth, 1.0);
653 for (
int ix = 0; ix < nPar; ix++) {
657 for (
int iperm = 1; iperm <= nPar; ++iperm) {
659 double dtmp = mtmp[xtmp[0]] - self.
_squareVec[0][xtmp[0]];
660 for (
int itmp = 1; itmp < iperm; ++itmp) {
661 dtmp *= mtmp[xtmp[itmp]] - self.
_squareVec[0][xtmp[itmp]];
663 deltavec[nperm + 1] = dtmp;
668 double origFrac1(0.), origFrac2(0.);
669 for (
int i = 0; i < depth; ++i) {
671 for (
int j = 0; j < depth; ++j) {
672 ffrac += (*self.
_MSqr)(j, i) * deltavec[j] * fracLinear;
688 cout <<
"Linear fraction " << ffrac << endl;
716 vector<vector<double>> boundaries(nPar);
717 for (
int idim = 0; idim < nPar; idim++) {
721 boundaries[idim].push_back(lo);
722 boundaries[idim].push_back(
hi);
725 vector<vector<double>>
output;
729 for (
int isq = 0; isq < depth; isq++) {
730 for (
int iref = 0; iref < nRef; iref++) {
753 for (
int ix = 0; ix < nPar; ix++) {
757 for (
int k = 0; k < depth; ++k) {
763 for (
int iperm = 1; iperm <= nPar; ++iperm) {
765 double dtmp =
_squareVec[k][xtmp[0]] - squareBase[xtmp[0]];
766 for (
int itmp = 1; itmp < iperm; ++itmp) {
767 dtmp *=
_squareVec[k][xtmp[itmp]] - squareBase[xtmp[itmp]];
769 M(k, nperm + 1) = dtmp;
789 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.
RooAbsCollection is an 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 RooAbsRealLValye 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
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooNumIntConfig * specialIntegratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
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.
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.
RooChangeTracker is a meta object that tracks value changes in a given set of RooAbsArgs by registeri...
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 occurence 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...
RooChangeTracker * _tracker
void calculateFractions(const RooMomentMorphND &self, bool verbose=true) const
RooArgList containedArgs(Action) override
void addBinning(const RooAbsBinning &binning)
std::vector< RooAbsBinning * > _grid
std::vector< int > _nnuis
void addPdf(const RooAbsPdf &pdf, int bin_x)
std::vector< std::vector< double > > _nref
std::vector< int > _squareIdx
CacheElem * getCache(const RooArgSet *nset) const
bool setBinIntegrator(RooArgSet &allVars)
RooObjCacheManager _cacheMgr
! Transient cache manager
RooArgSet * _curNormSet
! Transient cache manager
std::unique_ptr< TMatrixD > _M
std::vector< std::vector< double > > _squareVec
void initializeObservables(const RooArgList &obsList)
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
int sij(const int &i, const int &j) const
virtual double getVal(const RooArgSet *set=nullptr) const
void findShape(const std::vector< double > &x) const
RooAbsPdf * sumPdf(const RooArgSet *nset)
void initializeParameters(const RooArgList &parList)
~RooMomentMorphND() override
std::unique_ptr< TMatrixD > _MSqr
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.