29using std::string, std::vector;
34 : _cacheMgr(this, 10, true, true)
42 _cacheMgr(this, 10, true, true),
43 m(
"m",
"m", this, _m),
44 _varList(
"varList",
"List of variables", this),
45 _pdfList(
"pdfList",
"List of pdfs", this),
63 _cacheMgr(this, 10, true, true),
64 m(
"m",
"m", this, _m),
65 _varList(
"varList",
"List of variables", this),
66 _pdfList(
"pdfList",
"List of pdfs", this),
79 for (
auto *mref : mrefList) {
81 coutE(InputArguments) <<
"RooMomentMorphFunc::ctor(" <<
GetName() <<
") ERROR: mref " << mref->GetName()
82 <<
" is not of type RooAbsReal" << std::endl;
83 throw string(
"RooPolyMorh::ctor() ERROR mref is not of type RooAbsReal");
86 coutW(InputArguments) <<
"RooMomentMorphFunc::ctor(" <<
GetName() <<
") WARNING mref point " << i
87 <<
" is not a constant, taking a snapshot of its value" << std::endl;
100 _cacheMgr(other._cacheMgr, this),
101 m(
"m", this, other.
m),
102 _varList(
"varList", this, other._varList),
103 _pdfList(
"pdfList", this, other._pdfList),
105 _setting(other._setting),
106 _useHorizMorph(other._useHorizMorph)
130 coutE(InputArguments) <<
"RooMomentMorphFunc::initialize(" <<
GetName() <<
") ERROR: nPdf != nRefPoints" << std::endl;
140 (*dm)[i] = (*_mref)[i] - (*_mref)[0];
147 M(i, j) = std::pow((*dm)[i], (
double)j);
166 vector<RooAbsReal *> meanrv(nPdf * nVar, null);
167 vector<RooAbsReal *> sigmarv(nPdf * nVar, null);
168 vector<RooAbsReal *> myrms(nVar, null);
169 vector<RooAbsReal *> mypos(nVar, null);
170 vector<RooAbsReal *> slope(nPdf * nVar, null);
171 vector<RooAbsReal *> offs(nPdf * nVar, null);
172 vector<RooAbsReal *> transVar(nPdf * nVar, null);
173 vector<RooAbsReal *> transPdf(nPdf, null);
182 for (
Int_t i = 0; i < 2 * nPdf; ++i) {
183 std::string fracName =
Form(
"frac_%d", i);
191 coefList2.add(*
static_cast<RooRealVar *
>(fracl.at(i)));
193 ownedComps.add(*
static_cast<RooRealVar *
>(fracl.at(i)));
197 std::string sumfuncName =
Form(
"%s_sumfunc",
GetName());
202 for (
Int_t i = 0; i < nPdf; ++i) {
203 for (
Int_t j = 0; j < nVar; ++j) {
205 std::string meanName =
Form(
"%s_mean_%d_%d",
GetName(), i, j);
206 std::string sigmaName =
Form(
"%s_sigma_%d_%d",
GetName(), i, j);
212 mom->mean()->setLocalNoDirtyInhibit(
true);
214 sigmarv[
ij(i, j)] = mom;
215 meanrv[
ij(i, j)] = mom->mean();
217 ownedComps.add(*sigmarv[
ij(i, j)]);
222 for (
Int_t j = 0; j < nVar; ++j) {
225 for (
Int_t i = 0; i < nPdf; ++i) {
226 meanList.add(*meanrv[
ij(i, j)]);
227 rmsList.add(*sigmarv[
ij(i, j)]);
229 std::string myrmsName =
Form(
"%s_rms_%d",
GetName(), j);
230 std::string myposName =
Form(
"%s_pos_%d",
GetName(), j);
231 myrms[j] =
new RooAddition(myrmsName.c_str(), myrmsName.c_str(), rmsList, coefList2);
232 mypos[j] =
new RooAddition(myposName.c_str(), myposName.c_str(), meanList, coefList2);
233 ownedComps.add(
RooArgSet(*myrms[j], *mypos[j]));
239 for (
Int_t i = 0; i < nPdf; ++i) {
241 std::string pdfName =
Form(
"pdf_%d", i);
244 for (
Int_t j = 0; j < nVar; ++j) {
246 std::string slopeName =
Form(
"%s_slope_%d_%d",
GetName(), i, j);
247 std::string offsetName =
Form(
"%s_offset_%d_%d",
GetName(), i, j);
251 ownedComps.add(
RooArgSet(*slope[
ij(i, j)], *offs[
ij(i, j)]));
254 std::string transVarName =
Form(
"%s_transVar_%d_%d",
GetName(), i, j);
259 new RooLinearVar(transVarName.c_str(), transVarName.c_str(), var, *slope[
ij(i, j)], *offs[
ij(i, j)]);
265 ownedComps.add(*transVar[
ij(i, j)]);
266 cust.replaceArg(var, *transVar[
ij(i, j)]);
268 transPdf[i] =
static_cast<RooAbsPdf *
>(cust.build());
269 transPdfList.add(*transPdf[i]);
270 ownedComps.add(*transPdf[i]);
273 theSumFunc =
new RooRealSumFunc(sumfuncName.c_str(), sumfuncName.c_str(), transPdfList, coefList);
281 theSumFunc->addOwnedComponents(ownedComps);
284 std::string trackerName =
Form(
"%s_frac_tracker",
GetName());
288 cache =
new CacheElem(*theSumFunc, *tracker, fracl);
355 return static_cast<RooRealVar *
>(_frac.at(i));
361 return static_cast<RooRealVar *
>(_frac.at(i));
367 Int_t nPdf = self._pdfList.size();
369 double dm = self.m - (*self._mref)[0];
372 double sumposfrac = 0.;
373 for (
Int_t i = 0; i < nPdf; ++i) {
375 for (
Int_t j = 0; j < nPdf; ++j) {
376 ffrac += (*self._M)(j, i) * (j == 0 ? 1. : std::pow(dm, (
double)j));
381 const_cast<RooRealVar *
>(frac(i))->setVal(ffrac);
383 const_cast<RooRealVar *
>(frac(nPdf + i))->setVal(ffrac);
385 std::cout << ffrac << std::endl;
390 int imin = self.idxmin(self.m);
391 int imax = self.idxmax(self.m);
392 double mfrac = (self.m - (*self._mref)[imin]) / ((*self._mref)[imax] - (*self._mref)[imin]);
393 switch (self._setting) {
405 for (
Int_t i = 0; i < 2 * nPdf; ++i) const_cast<RooRealVar *>(frac(i))->setVal(0.);
407 const_cast<RooRealVar *
>(frac(imin))->setVal(1. - mfrac);
408 const_cast<RooRealVar *
>(frac(nPdf + imin))->setVal(1. - mfrac);
409 const_cast<RooRealVar *
>(frac(imax))->setVal(mfrac);
410 const_cast<RooRealVar *
>(frac(nPdf + imax))->setVal(mfrac);
411 }
else if (imax == imin) {
412 const_cast<RooRealVar *
>(frac(imin))->setVal(1.);
413 const_cast<RooRealVar *
>(frac(nPdf + imin))->setVal(1.);
417 for (
Int_t i = 0; i < nPdf; ++i) const_cast<RooRealVar *>(frac(i))->setVal(0.);
419 const_cast<RooRealVar *
>(frac(imin))->setVal(1. - mfrac);
420 const_cast<RooRealVar *
>(frac(imax))->setVal(mfrac);
421 }
else if (imax == imin) {
422 const_cast<RooRealVar *
>(frac(imin))->setVal(1.);
426 for (
Int_t i = 0; i < nPdf; ++i) {
427 if (frac(i)->getVal() < 0)
428 const_cast<RooRealVar *
>(frac(i))->setVal(0.);
429 const_cast<RooRealVar *
>(frac(i))->setVal(frac(i)->getVal() / sumposfrac);
440 double mmin = -DBL_MAX;
441 for (
Int_t i = 0; i < nPdf; ++i) {
442 if ((*
_mref)[i] > mmin && (*
_mref)[i] <= mval) {
455 double mmax = DBL_MAX;
456 for (
Int_t i = 0; i < nPdf; ++i) {
457 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
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 ...
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
! Current normalization set
bool isBinnedDistribution(const RooArgSet &obs) const override
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
RooObjCacheManager _cacheMgr
! The cache manager
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.
const T & arg() const
Return reference to object held in proxy.
const char * GetName() const override
Returns name of object.
constexpr Double_t PiOver2()