39 : _cacheMgr(this,10,true,true)
49 _cacheMgr(this, 10, true, true),
50 m(
"m",
"m", this, _m),
51 _varList(
"varList",
"List of variables", this),
52 _pdfList(
"pdfList",
"List of pdfs", this),
73 _cacheMgr(this, 10, true, true),
74 m(
"m",
"m", this, _m),
75 _varList(
"varList",
"List of variables", this),
76 _pdfList(
"pdfList",
"List of pdfs", this),
90 for (
auto *mref : mrefList) {
92 coutE(InputArguments) <<
"RooMomentMorph::ctor(" <<
GetName() <<
") ERROR: mref " << mref->GetName() <<
" is not of type RooAbsReal" << std::endl ;
93 throw std::string(
"RooPolyMorh::ctor() ERROR mref is not of type RooAbsReal") ;
96 coutW(InputArguments) <<
"RooMomentMorph::ctor(" <<
GetName() <<
") WARNING mref point " << i <<
" is not a constant, taking a snapshot of its value" << std::endl ;
110 _cacheMgr(other._cacheMgr, this),
111 m(
"m", this, other.
m),
112 _varList(
"varList", this, other._varList),
113 _pdfList(
"pdfList", this, other._pdfList),
115 _setting(other._setting),
116 _useHorizMorph(other._useHorizMorph)
139 coutE(InputArguments) <<
"RooMomentMorph::initialize(" <<
GetName() <<
") ERROR: nPdf != nRefPoints" << std::endl ;
149 dm[i] = (*_mref)[i]-(*_mref)[0];
151 if (i>0) M(0,i) = 0.;
155 M(i,j) = std::pow(dm[i],(
double)j);
164 std::unique_ptr<RooChangeTracker> && tracker,
166 : _sumPdf(std::move(sumPdf)), _tracker(std::move(tracker)) {
181 std::vector<RooAbsReal*> meanrv(nPdf*nVar,null);
182 std::vector<RooAbsReal*> sigmarv(nPdf*nVar,null);
183 std::vector<RooAbsReal*> myrms(nVar,null);
184 std::vector<RooAbsReal*> mypos(nVar,null);
185 std::vector<RooAbsReal*> slope(nPdf*nVar,null);
186 std::vector<RooAbsReal*> offs(nPdf*nVar,null);
187 std::vector<RooAbsReal*> transVar(nPdf*nVar,null);
188 std::vector<RooAbsReal*> transPdf(nPdf,null);
197 for (
Int_t i=0; i<2*nPdf; ++i) {
198 std::string fracName =
"frac_" + std::to_string(i);
203 if (i<nPdf) coefList.
add(*frac);
204 else coefList2.
add(*frac);
205 ownedComps.
add(*frac);
208 std::unique_ptr<RooAddPdf> theSumPdf;
209 std::string sumpdfName =
Form(
"%s_sumpdf",
GetName());
214 for (
Int_t i=0; i<nPdf; ++i) {
215 for (
Int_t j=0; j<nVar; ++j) {
217 std::string meanName =
Form(
"%s_mean_%d_%d",
GetName(),i,j);
218 std::string sigmaName =
Form(
"%s_sigma_%d_%d",
GetName(),i,j);
227 sigmarv[
ij(i,j)] = mom ;
228 meanrv[
ij(i,j)] = mom->
mean() ;
230 ownedComps.
add(*sigmarv[
ij(i,j)]) ;
235 for (
Int_t j=0; j<nVar; ++j) {
238 for (
Int_t i=0; i<nPdf; ++i) {
239 meanList.
add(*meanrv[
ij(i,j)]);
240 rmsList.
add(*sigmarv[
ij(i,j)]);
242 std::string myrmsName =
Form(
"%s_rms_%d",
GetName(),j);
243 std::string myposName =
Form(
"%s_pos_%d",
GetName(),j);
244 myrms[j] =
new RooAddition(myrmsName.c_str(),myrmsName.c_str(),rmsList,coefList2);
245 mypos[j] =
new RooAddition(myposName.c_str(),myposName.c_str(),meanList,coefList2);
252 for (
Int_t i=0; i<nPdf; ++i) {
255 std::string pdfName =
"pdf_" + std::to_string(i);
258 for (
Int_t j=0; j<nVar; ++j) {
260 std::string slopeName =
Form(
"%s_slope_%d_%d",
GetName(),i,j);
261 std::string offsetName =
Form(
"%s_offset_%d_%d",
GetName(),i,j);
262 slope[
ij(i,j)] =
new RooFormulaVar(slopeName.c_str(),
"@0/@1", {*sigmarv[ij(i,j)],*myrms[j]});
263 offs[
ij(i,j)] =
new RooFormulaVar(offsetName.c_str(),
"@0-(@1*@2)", {*meanrv[ij(i,j)],*mypos[j],*slope[ij(i,j)]});
267 std::string transVarName =
Form(
"%s_transVar_%d_%d",
GetName(),i,j);
270 transVar[
ij(i,j)] =
new RooLinearVar(transVarName.c_str(),transVarName.c_str(),*var,*slope[
ij(i,j)],*offs[
ij(i,j)]);
276 ownedComps.
add(*transVar[
ij(i,j)]) ;
280 transPdfList.
add(*transPdf[i]);
281 ownedComps.
add(*transPdf[i]) ;
284 theSumPdf = std::make_unique<RooAddPdf>(sumpdfName.c_str(),sumpdfName.c_str(),transPdfList,coefList);
287 theSumPdf = std::make_unique<RooAddPdf>(sumpdfName.c_str(),sumpdfName.c_str(),
_pdfList,coefList);
289 theSumPdf->fixCoefNormalization(*nset);
294 theSumPdf->addOwnedComponents(ownedComps) ;
297 std::string trackerName =
Form(
"%s_frac_tracker",
GetName()) ;
298 auto tracker = std::make_unique<RooChangeTracker>(trackerName.c_str(),trackerName.c_str(),
m.
arg(),
true) ;
301 auto cache =
new CacheElem(std::move(theSumPdf),std::move(tracker),fracl) ;
304 cache->calculateFractions(*
this,
false);
334 if (cache->
_tracker->hasChanged(
true)) {
347 if (cache->
_tracker->hasChanged(
true)) {
358 return static_cast<RooRealVar*
>(_frac.at(i)) ;
365 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) { ffrac += (*self.
_M)(j,i) * (j==0?1.:std::pow(dm,(
double)j)); }
381 if (ffrac>=0) sumposfrac+=ffrac;
383 const_cast<RooRealVar*
>(frac(i))->setVal(ffrac);
385 const_cast<RooRealVar*
>(frac(nPdf+i))->setVal(ffrac);
386 if (verbose) { 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]);
404 for (
Int_t i=0; i<2*nPdf; ++i)
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)
420 const_cast<RooRealVar*
>(frac(imin))->setVal(1.-mfrac);
421 const_cast<RooRealVar*
>(frac(imax))->setVal(mfrac);
422 }
else if (imax==imin) {
423 const_cast<RooRealVar*
>(frac(imin))->setVal(1.);
427 for (
Int_t i = 0; i < nPdf; ++i) {
428 if (frac(i)->getVal() < 0)
429 const_cast<RooRealVar *
>(frac(i))->setVal(0.);
430 const_cast<RooRealVar *
>(frac(i))->setVal(frac(i)->getVal() / sumposfrac);
443 double mmin=-DBL_MAX;
444 for (
Int_t i=0; i<nPdf; ++i)
445 if ( (*
_mref)[i]>mmin && (*
_mref)[i]<=mval ) { mmin=(*_mref)[i]; imin=i; }
457 for (
Int_t i=0; i<nPdf; ++i)
458 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
~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
The cache manager.
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.
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()