33using std::cout, std::endl, std::string, std::vector;
39 : _cacheMgr(this, 10, true, true)
47 _cacheMgr(this, 10, true, true),
48 m(
"m",
"m", this, _m),
49 _varList(
"varList",
"List of variables", this),
50 _pdfList(
"pdfList",
"List of pdfs", this),
68 _cacheMgr(this, 10, true, true),
69 m(
"m",
"m", this, _m),
70 _varList(
"varList",
"List of variables", this),
71 _pdfList(
"pdfList",
"List of pdfs", this),
84 for (
auto *mref : mrefList) {
86 coutE(InputArguments) <<
"RooMomentMorphFunc::ctor(" <<
GetName() <<
") ERROR: mref " << mref->GetName()
87 <<
" is not of type RooAbsReal" << endl;
88 throw string(
"RooPolyMorh::ctor() ERROR mref is not of type RooAbsReal");
91 coutW(InputArguments) <<
"RooMomentMorphFunc::ctor(" <<
GetName() <<
") WARNING mref point " << i
92 <<
" is not a constant, taking a snapshot of its value" << endl;
105 _cacheMgr(other._cacheMgr, this),
106 m(
"m", this, other.
m),
107 _varList(
"varList", this, other._varList),
108 _pdfList(
"pdfList", this, other._pdfList),
110 _setting(other._setting),
111 _useHorizMorph(other._useHorizMorph)
135 coutE(InputArguments) <<
"RooMomentMorphFunc::initialize(" <<
GetName() <<
") ERROR: nPdf != nRefPoints" << endl;
145 (*dm)[i] = (*_mref)[i] - (*_mref)[0];
152 M(i, j) = std::pow((*dm)[i], (
double)j);
171 vector<RooAbsReal *> meanrv(nPdf * nVar, null);
172 vector<RooAbsReal *> sigmarv(nPdf * nVar, null);
173 vector<RooAbsReal *> myrms(nVar, null);
174 vector<RooAbsReal *> mypos(nVar, null);
175 vector<RooAbsReal *> slope(nPdf * nVar, null);
176 vector<RooAbsReal *> offs(nPdf * nVar, null);
177 vector<RooAbsReal *> transVar(nPdf * nVar, null);
178 vector<RooAbsReal *> transPdf(nPdf, null);
187 for (
Int_t i = 0; i < 2 * nPdf; ++i) {
188 std::string fracName =
Form(
"frac_%d", i);
202 std::string sumfuncName =
Form(
"%s_sumfunc",
GetName());
207 for (
Int_t i = 0; i < nPdf; ++i) {
208 for (
Int_t j = 0; j < nVar; ++j) {
210 std::string meanName =
Form(
"%s_mean_%d_%d",
GetName(), i, j);
211 std::string sigmaName =
Form(
"%s_sigma_%d_%d",
GetName(), i, j);
219 sigmarv[
ij(i, j)] = mom;
220 meanrv[
ij(i, j)] = mom->
mean();
222 ownedComps.
add(*sigmarv[
ij(i, j)]);
227 for (
Int_t j = 0; j < nVar; ++j) {
230 for (
Int_t i = 0; i < nPdf; ++i) {
231 meanList.
add(*meanrv[
ij(i, j)]);
232 rmsList.
add(*sigmarv[
ij(i, j)]);
234 std::string myrmsName =
Form(
"%s_rms_%d",
GetName(), j);
235 std::string myposName =
Form(
"%s_pos_%d",
GetName(), j);
236 myrms[j] =
new RooAddition(myrmsName.c_str(), myrmsName.c_str(), rmsList, coefList2);
237 mypos[j] =
new RooAddition(myposName.c_str(), myposName.c_str(), meanList, coefList2);
244 for (
Int_t i = 0; i < nPdf; ++i) {
246 std::string pdfName =
Form(
"pdf_%d", i);
249 for (
Int_t j = 0; j < nVar; ++j) {
251 std::string slopeName =
Form(
"%s_slope_%d_%d",
GetName(), i, j);
252 std::string offsetName =
Form(
"%s_offset_%d_%d",
GetName(), i, j);
259 std::string transVarName =
Form(
"%s_transVar_%d_%d",
GetName(), i, j);
264 new RooLinearVar(transVarName.c_str(), transVarName.c_str(), var, *slope[
ij(i, j)], *offs[
ij(i, j)]);
270 ownedComps.
add(*transVar[
ij(i, j)]);
274 transPdfList.
add(*transPdf[i]);
275 ownedComps.
add(*transPdf[i]);
278 theSumFunc =
new RooRealSumFunc(sumfuncName.c_str(), sumfuncName.c_str(), transPdfList, coefList);
289 std::string trackerName =
Form(
"%s_frac_tracker",
GetName());
293 cache =
new CacheElem(*theSumFunc, *tracker, fracl);
360 return static_cast<RooRealVar *
>(_frac.at(i));
366 return static_cast<RooRealVar *
>(_frac.at(i));
374 double dm = self.
m - (*self.
_mref)[0];
377 double sumposfrac = 0.;
378 for (
Int_t i = 0; i < nPdf; ++i) {
380 for (
Int_t j = 0; j < nPdf; ++j) {
381 ffrac += (*self.
_M)(j, i) * (j == 0 ? 1. : std::pow(dm, (
double)j));
386 const_cast<RooRealVar *
>(frac(i))->setVal(ffrac);
388 const_cast<RooRealVar *
>(frac(nPdf + i))->setVal(ffrac);
390 cout << ffrac << endl;
395 int imin = self.
idxmin(self.
m);
396 int imax = self.
idxmax(self.
m);
397 double mfrac = (self.
m - (*self.
_mref)[imin]) / ((*self.
_mref)[imax] - (*self.
_mref)[imin]);
410 for (
Int_t i = 0; i < 2 * nPdf; ++i) const_cast<RooRealVar *>(frac(i))->setVal(0.);
412 const_cast<RooRealVar *
>(frac(imin))->setVal(1. - mfrac);
413 const_cast<RooRealVar *
>(frac(nPdf + imin))->setVal(1. - mfrac);
414 const_cast<RooRealVar *
>(frac(imax))->setVal(mfrac);
415 const_cast<RooRealVar *
>(frac(nPdf + imax))->setVal(mfrac);
416 }
else if (imax == imin) {
417 const_cast<RooRealVar *
>(frac(imin))->setVal(1.);
418 const_cast<RooRealVar *
>(frac(nPdf + imin))->setVal(1.);
422 for (
Int_t i = 0; i < nPdf; ++i) const_cast<RooRealVar *>(frac(i))->setVal(0.);
424 const_cast<RooRealVar *
>(frac(imin))->setVal(1. - mfrac);
425 const_cast<RooRealVar *
>(frac(imax))->setVal(mfrac);
426 }
else if (imax == imin) {
427 const_cast<RooRealVar *
>(frac(imin))->setVal(1.);
431 for (
Int_t i = 0; i < nPdf; ++i) {
432 if (frac(i)->getVal() < 0)
433 const_cast<RooRealVar *
>(frac(i))->setVal(0.);
434 const_cast<RooRealVar *
>(frac(i))->setVal(frac(i)->getVal() / sumposfrac);
445 double mmin = -DBL_MAX;
446 for (
Int_t i = 0; i < nPdf; ++i) {
447 if ((*
_mref)[i] > mmin && (*
_mref)[i] <= mval) {
460 double mmax = DBL_MAX;
461 for (
Int_t i = 0; i < nPdf; ++i) {
462 if ((*
_mref)[i] < mmax && (*
_mref)[i] >= mval) {
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
TMatrixT< Double_t > TMatrixD
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
TVectorT< Double_t > TVectorD
Common abstract base class for objects that represent a value and a "shape" in RooFit.
void setLocalNoDirtyInhibit(bool flag) const
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
void addServer(RooAbsArg &server, bool valueProp=true, bool shapeProp=false, std::size_t refCount=1)
Register another RooAbsArg as a server to us, ie, declare that we depend on it.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
bool addTyped(const RooAbsCollection &list, bool silent=false)
Adds elements of a given RooAbsCollection to the container if they match the specified type.
Abstract interface for all probability density functions.
const RooArgSet * nset() const
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
Abstract base class for objects that represent a real value and implements functionality common to al...
virtual std::list< double > * binBoundaries(RooAbsRealLValue &obs, double xlo, double xhi) const
Retrieve bin boundaries if this distribution is binned in obs.
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
virtual double getValV(const RooArgSet *normalisationSet=nullptr) const
Return value of object.
friend class RooRealSumFunc
virtual bool isBinnedDistribution(const RooArgSet &) const
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
virtual std::list< double > * plotSamplingHint(RooAbsRealLValue &obs, double xlo, double xhi) const
Interface for returning an optional hint for initial sampling points when constructing a curve projec...
RooAbsMoment * sigma(RooRealVar &obs)
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.
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.
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.
Represents 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 RooMomentMorphFunc &self, bool verbose=true) const
RooRealVar * frac(Int_t i)
RooChangeTracker * _tracker
RooArgList containedArgs(Action) override
double getValV(const RooArgSet *set=nullptr) const override
Return value of object.
~RooMomentMorphFunc() override
RooArgSet * _curNormSet
The cache manager.
bool isBinnedDistribution(const RooArgSet &obs) const override
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
RooObjCacheManager _cacheMgr
CacheElem * getCache(const RooArgSet *nset) const
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
RooAbsReal * sumFunc(const RooArgSet *nset)
int idxmin(const double &m) const
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
Retrieve bin boundaries if this distribution is binned in obs.
std::list< double > * plotSamplingHint(RooAbsRealLValue &obs, double xlo, double xhi) const override
Interface for returning an optional hint for initial sampling points when constructing a curve projec...
Int_t ij(const Int_t &i, const Int_t &j) const
int idxmax(const double &m) const
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.
constexpr Double_t PiOver2()