33 : _cacheMgr(this, 10, true, true)
43 _cacheMgr(this, 10, true, true),
44 m(
"m",
"m", this, _m),
45 _varList(
"varList",
"List of variables", this),
46 _pdfList(
"pdfList",
"List of pdfs", this),
67 _cacheMgr(this, 10, true, true),
68 m(
"m",
"m", this, _m),
69 _varList(
"varList",
"List of variables", this),
70 _pdfList(
"pdfList",
"List of pdfs", this),
84 for (
auto *mref : mrefList) {
86 coutE(InputArguments) <<
"RooMomentMorph::ctor(" <<
GetName() <<
") ERROR: mref " << mref->GetName() <<
" is not of type RooAbsReal" << std::endl ;
87 throw std::string(
"RooPolyMorh::ctor() ERROR mref is not of type RooAbsReal") ;
90 coutW(InputArguments) <<
"RooMomentMorph::ctor(" <<
GetName() <<
") WARNING mref point " << i <<
" is not a constant, taking a snapshot of its value" << std::endl ;
104 _cacheMgr(other._cacheMgr, this),
105 m(
"m", this, other.
m),
106 _varList(
"varList", this, other._varList),
107 _pdfList(
"pdfList", this, other._pdfList),
109 _setting(other._setting),
110 _useHorizMorph(other._useHorizMorph)
133 coutE(InputArguments) <<
"RooMomentMorph::initialize(" <<
GetName() <<
") ERROR: nPdf != nRefPoints" << std::endl ;
143 dm[i] = (*_mref)[i]-(*_mref)[0];
145 if (i>0) M(0,i) = 0.;
149 M(i,j) = std::pow(dm[i],(
double)j);
158 std::unique_ptr<RooChangeTracker> && tracker,
160 : _sumPdf(std::move(sumPdf)), _tracker(std::move(tracker)) {
175 std::vector<RooAbsReal*> meanrv(nPdf*nVar,null);
176 std::vector<RooAbsReal*> sigmarv(nPdf*nVar,null);
177 std::vector<RooAbsReal*> myrms(nVar,null);
178 std::vector<RooAbsReal*> mypos(nVar,null);
179 std::vector<RooAbsReal*> slope(nPdf*nVar,null);
180 std::vector<RooAbsReal*> offs(nPdf*nVar,null);
181 std::vector<RooAbsReal*> transVar(nPdf*nVar,null);
182 std::vector<RooAbsReal*> transPdf(nPdf,null);
191 for (
Int_t i=0; i<2*nPdf; ++i) {
192 std::string fracName =
"frac_" + std::to_string(i);
197 if (i<nPdf) coefList.
add(*frac);
198 else coefList2.
add(*frac);
199 ownedComps.
add(*frac);
202 std::unique_ptr<RooAddPdf> theSumPdf;
203 std::string sumpdfName =
Form(
"%s_sumpdf",
GetName());
208 for (
Int_t i=0; i<nPdf; ++i) {
209 for (
Int_t j=0; j<nVar; ++j) {
211 std::string meanName =
Form(
"%s_mean_%d_%d",
GetName(),i,j);
212 std::string sigmaName =
Form(
"%s_sigma_%d_%d",
GetName(),i,j);
221 sigmarv[
ij(i,j)] = mom ;
222 meanrv[
ij(i,j)] = mom->
mean() ;
224 ownedComps.
add(*sigmarv[
ij(i,j)]) ;
229 for (
Int_t j=0; j<nVar; ++j) {
232 for (
Int_t i=0; i<nPdf; ++i) {
233 meanList.
add(*meanrv[
ij(i,j)]);
234 rmsList.
add(*sigmarv[
ij(i,j)]);
236 std::string myrmsName =
Form(
"%s_rms_%d",
GetName(),j);
237 std::string myposName =
Form(
"%s_pos_%d",
GetName(),j);
238 myrms[j] =
new RooAddition(myrmsName.c_str(),myrmsName.c_str(),rmsList,coefList2);
239 mypos[j] =
new RooAddition(myposName.c_str(),myposName.c_str(),meanList,coefList2);
246 for (
Int_t i=0; i<nPdf; ++i) {
249 std::string pdfName =
"pdf_" + std::to_string(i);
252 for (
Int_t j=0; j<nVar; ++j) {
254 std::string slopeName =
Form(
"%s_slope_%d_%d",
GetName(),i,j);
255 std::string offsetName =
Form(
"%s_offset_%d_%d",
GetName(),i,j);
256 slope[
ij(i,j)] =
new RooFormulaVar(slopeName.c_str(),
"@0/@1", {*sigmarv[ij(i,j)],*myrms[j]});
257 offs[
ij(i,j)] =
new RooFormulaVar(offsetName.c_str(),
"@0-(@1*@2)", {*meanrv[ij(i,j)],*mypos[j],*slope[ij(i,j)]});
261 std::string transVarName =
Form(
"%s_transVar_%d_%d",
GetName(),i,j);
264 transVar[
ij(i,j)] =
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 theSumPdf = std::make_unique<RooAddPdf>(sumpdfName.c_str(),sumpdfName.c_str(),transPdfList,coefList);
281 theSumPdf = std::make_unique<RooAddPdf>(sumpdfName.c_str(),sumpdfName.c_str(),
_pdfList,coefList);
283 theSumPdf->fixCoefNormalization(*nset);
288 theSumPdf->addOwnedComponents(ownedComps) ;
291 std::string trackerName =
Form(
"%s_frac_tracker",
GetName()) ;
292 auto tracker = std::make_unique<RooChangeTracker>(trackerName.c_str(),trackerName.c_str(),
m.
arg(),
true) ;
295 auto cache =
new CacheElem(std::move(theSumPdf),std::move(tracker),fracl) ;
298 cache->calculateFractions(*
this,
false);
328 if (cache->
_tracker->hasChanged(
true)) {
341 if (cache->
_tracker->hasChanged(
true)) {
352 return static_cast<RooRealVar*
>(_frac.at(i)) ;
359 return static_cast<RooRealVar*
>(_frac.at(i)) ;
368 double dm = self.
m - (*self.
_mref)[0];
371 double sumposfrac=0.;
372 for (
Int_t i=0; i<nPdf; ++i) {
374 for (
Int_t j=0; j<nPdf; ++j) { ffrac += (*self.
_M)(j,i) * (j==0?1.:std::pow(dm,(
double)j)); }
375 if (ffrac>=0) sumposfrac+=ffrac;
377 const_cast<RooRealVar*
>(frac(i))->setVal(ffrac);
379 const_cast<RooRealVar*
>(frac(nPdf+i))->setVal(ffrac);
380 if (verbose) { std::cout << ffrac << std::endl; }
384 int imin = self.
idxmin(self.
m);
385 int imax = self.
idxmax(self.
m);
386 double mfrac = (self.
m-(*self.
_mref)[imin])/((*self.
_mref)[imax]-(*self.
_mref)[imin]);
398 for (
Int_t i=0; i<2*nPdf; ++i)
401 const_cast<RooRealVar*
>(frac(imin))->setVal(1.-mfrac);
402 const_cast<RooRealVar*
>(frac(nPdf+imin))->setVal(1.-mfrac);
403 const_cast<RooRealVar*
>(frac(imax))->setVal(mfrac);
404 const_cast<RooRealVar*
>(frac(nPdf+imax))->setVal(mfrac);
405 }
else if (imax==imin) {
406 const_cast<RooRealVar*
>(frac(imin))->setVal(1.);
407 const_cast<RooRealVar*
>(frac(nPdf+imin))->setVal(1.);
411 for (
Int_t i=0; i<nPdf; ++i)
414 const_cast<RooRealVar*
>(frac(imin))->setVal(1.-mfrac);
415 const_cast<RooRealVar*
>(frac(imax))->setVal(mfrac);
416 }
else if (imax==imin) {
417 const_cast<RooRealVar*
>(frac(imin))->setVal(1.);
421 for (
Int_t i = 0; i < nPdf; ++i) {
422 if (frac(i)->getVal() < 0)
423 const_cast<RooRealVar *
>(frac(i))->setVal(0.);
424 const_cast<RooRealVar *
>(frac(i))->setVal(frac(i)->getVal() / sumposfrac);
437 double mmin=-DBL_MAX;
438 for (
Int_t i=0; i<nPdf; ++i)
439 if ( (*
_mref)[i]>mmin && (*
_mref)[i]<=mval ) { mmin=(*_mref)[i]; imin=i; }
451 for (
Int_t i=0; i<nPdf; ++i)
452 if ( (*
_mref)[i]<mmax && (*
_mref)[i]>=mval ) { mmax=(*_mref)[i]; imax=i; }
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.
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.
double getValV(const RooArgSet *set=nullptr) const override
Return current value, normalized by integrating over the observables in nset.
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.
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.
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...
RooArgList containedArgs(Action) override
CacheElem(std::unique_ptr< RooAbsPdf > &&sumPdf, std::unique_ptr< RooChangeTracker > &&tracker, const RooArgList &flist)
RooRealVar * frac(Int_t i)
void calculateFractions(const RooMomentMorph &self, bool verbose=true) const
std::unique_ptr< RooAbsPdf > _sumPdf
std::unique_ptr< RooChangeTracker > _tracker
RooObjCacheManager _cacheMgr
! The cache manager
~RooMomentMorph() override
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
RooMomentMorph()
coverity[UNINIT_CTOR]
RooAbsPdf * sumPdf(const RooArgSet *nset)
Int_t ij(const Int_t &i, const Int_t &j) const
RooArgSet * _curNormSet
! Current normalization set
int idxmin(const double &m) const
int idxmax(const double &m) const
double getValV(const RooArgSet *set=nullptr) const override
Special version of getVal() overrides RooAbsReal::getVal() to save value of current normalization set...
CacheElem * getCache(const RooArgSet *nset) const
Variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
const T & arg() const
Return reference to object held in proxy.
const char * GetName() const override
Returns name of object.
constexpr Double_t PiOver2()