36 : _cacheMgr(this,10,true,true), _curNormSet(nullptr), _mref(nullptr), _M(nullptr), _useHorizMorph(true)
50 _cacheMgr(this,10,true,true),
52 _varList(
"varList",
"List of variables",this),
53 _pdfList(
"pdfList",
"List of pdfs",this),
58 for (
auto *var : varList) {
60 coutE(InputArguments) <<
"RooMomentMorph::ctor(" <<
GetName() <<
") ERROR: variable " << var->
GetName() <<
" is not of type RooAbsReal" << std::endl ;
61 throw std::string(
"RooPolyMorh::ctor() ERROR variable is not of type RooAbsReal") ;
68 for (
auto const *pdf : pdfList) {
69 if (!
dynamic_cast<RooAbsPdf const*
>(pdf)) {
70 coutE(InputArguments) <<
"RooMomentMorph::ctor(" <<
GetName() <<
") ERROR: pdf " << pdf->GetName() <<
" is not of type RooAbsPdf" << std::endl ;
71 throw std::string(
"RooPolyMorh::ctor() ERROR pdf is not of type RooAbsPdf") ;
92 _cacheMgr(this,10,true,true),
94 _varList(
"varList",
"List of variables",this),
95 _pdfList(
"pdfList",
"List of pdfs",this),
100 for (
auto *var : varList) {
102 coutE(InputArguments) <<
"RooMomentMorph::ctor(" <<
GetName() <<
") ERROR: variable " << var->
GetName() <<
" is not of type RooAbsReal" << std::endl ;
103 throw std::string(
"RooPolyMorh::ctor() ERROR variable is not of type RooAbsReal") ;
109 for (
auto const *pdf : pdfList) {
110 if (!
dynamic_cast<RooAbsPdf const*
>(pdf)) {
111 coutE(InputArguments) <<
"RooMomentMorph::ctor(" <<
GetName() <<
") ERROR: pdf " << pdf->GetName() <<
" is not of type RooAbsPdf" << std::endl ;
112 throw std::string(
"RooPolyMorh::ctor() ERROR pdf is not of type RooAbsPdf") ;
120 for (
auto *mref : mrefList) {
122 coutE(InputArguments) <<
"RooMomentMorph::ctor(" <<
GetName() <<
") ERROR: mref " << mref->GetName() <<
" is not of type RooAbsReal" << std::endl ;
123 throw std::string(
"RooPolyMorh::ctor() ERROR mref is not of type RooAbsReal") ;
126 coutW(InputArguments) <<
"RooMomentMorph::ctor(" <<
GetName() <<
") WARNING mref point " << i <<
" is not a constant, taking a snapshot of its value" << std::endl ;
140 _cacheMgr(other._cacheMgr,this),
141 _curNormSet(nullptr),
143 _varList(
"varList",this,other._varList),
144 _pdfList(
"pdfList",this,other._pdfList),
145 _setting(other._setting),
146 _useHorizMorph(other._useHorizMorph)
170 coutE(InputArguments) <<
"RooMomentMorph::initialize(" <<
GetName() <<
") ERROR: nPdf != nRefPoints" << std::endl ;
180 dm[i] = (*_mref)[i]-(*_mref)[0];
182 if (i>0) M(0,i) = 0.;
195 std::unique_ptr<RooChangeTracker> && tracker,
197 : _sumPdf(std::move(sumPdf)), _tracker(std::move(tracker)) {
212 std::vector<RooAbsReal*> meanrv(nPdf*nVar,null);
213 std::vector<RooAbsReal*> sigmarv(nPdf*nVar,null);
214 std::vector<RooAbsReal*> myrms(nVar,null);
215 std::vector<RooAbsReal*> mypos(nVar,null);
216 std::vector<RooAbsReal*> slope(nPdf*nVar,null);
217 std::vector<RooAbsReal*> offs(nPdf*nVar,null);
218 std::vector<RooAbsReal*> transVar(nPdf*nVar,null);
219 std::vector<RooAbsReal*> transPdf(nPdf,null);
228 for (
Int_t i=0; i<2*nPdf; ++i) {
229 std::string fracName =
"frac_" + std::to_string(i);
234 if (i<nPdf) coefList.
add(*frac);
235 else coefList2.
add(*frac);
236 ownedComps.
add(*frac);
239 std::unique_ptr<RooAddPdf> theSumPdf;
240 std::string sumpdfName =
Form(
"%s_sumpdf",
GetName());
245 for (
Int_t i=0; i<nPdf; ++i) {
246 for (
Int_t j=0; j<nVar; ++j) {
248 std::string meanName =
Form(
"%s_mean_%d_%d",
GetName(),i,j);
249 std::string sigmaName =
Form(
"%s_sigma_%d_%d",
GetName(),i,j);
258 sigmarv[
ij(i,j)] = mom ;
259 meanrv[
ij(i,j)] = mom->
mean() ;
261 ownedComps.
add(*sigmarv[
ij(i,j)]) ;
266 for (
Int_t j=0; j<nVar; ++j) {
269 for (
Int_t i=0; i<nPdf; ++i) {
270 meanList.
add(*meanrv[
ij(i,j)]);
271 rmsList.
add(*sigmarv[
ij(i,j)]);
273 std::string myrmsName =
Form(
"%s_rms_%d",
GetName(),j);
274 std::string myposName =
Form(
"%s_pos_%d",
GetName(),j);
275 myrms[j] =
new RooAddition(myrmsName.c_str(),myrmsName.c_str(),rmsList,coefList2);
276 mypos[j] =
new RooAddition(myposName.c_str(),myposName.c_str(),meanList,coefList2);
283 for (
Int_t i=0; i<nPdf; ++i) {
286 std::string pdfName =
"pdf_" + std::to_string(i);
289 for (
Int_t j=0; j<nVar; ++j) {
291 std::string slopeName =
Form(
"%s_slope_%d_%d",
GetName(),i,j);
292 std::string offsetName =
Form(
"%s_offset_%d_%d",
GetName(),i,j);
293 slope[
ij(i,j)] =
new RooFormulaVar(slopeName.c_str(),
"@0/@1", {*sigmarv[ij(i,j)],*myrms[j]});
294 offs[
ij(i,j)] =
new RooFormulaVar(offsetName.c_str(),
"@0-(@1*@2)", {*meanrv[ij(i,j)],*mypos[j],*slope[ij(i,j)]});
298 std::string transVarName =
Form(
"%s_transVar_%d_%d",
GetName(),i,j);
301 transVar[
ij(i,j)] =
new RooLinearVar(transVarName.c_str(),transVarName.c_str(),*var,*slope[
ij(i,j)],*offs[
ij(i,j)]);
307 ownedComps.
add(*transVar[
ij(i,j)]) ;
311 transPdfList.
add(*transPdf[i]);
312 ownedComps.
add(*transPdf[i]) ;
315 theSumPdf = std::make_unique<RooAddPdf>(sumpdfName.c_str(),sumpdfName.c_str(),transPdfList,coefList);
318 theSumPdf = std::make_unique<RooAddPdf>(sumpdfName.c_str(),sumpdfName.c_str(),
_pdfList,coefList);
324 theSumPdf->addOwnedComponents(ownedComps) ;
327 std::string trackerName =
Form(
"%s_frac_tracker",
GetName()) ;
328 auto tracker = std::make_unique<RooChangeTracker>(trackerName.c_str(),trackerName.c_str(),
m.
arg(),
true) ;
331 auto cache =
new CacheElem(std::move(theSumPdf),std::move(tracker),fracl) ;
334 cache->calculateFractions(*
this,
false);
364 if (cache->
_tracker->hasChanged(
true)) {
377 if (cache->
_tracker->hasChanged(
true)) {
388 return static_cast<RooRealVar*
>(_frac.at(i)) ;
395 return static_cast<RooRealVar*
>(_frac.at(i)) ;
404 double dm = self.
m - (*self.
_mref)[0];
407 double sumposfrac=0.;
408 for (
Int_t i=0; i<nPdf; ++i) {
410 for (
Int_t j=0; j<nPdf; ++j) { ffrac += (*self.
_M)(j,i) * (j==0?1.:
TMath::Power(dm,(
double)j)); }
411 if (ffrac>=0) sumposfrac+=ffrac;
416 if (verbose) { std::cout << ffrac << std::endl; }
420 int imin = self.
idxmin(self.
m);
421 int imax = self.
idxmax(self.
m);
422 double mfrac = (self.
m-(*self.
_mref)[imin])/((*self.
_mref)[imax]-(*self.
_mref)[imin]);
434 for (
Int_t i=0; i<2*nPdf; ++i)
438 ((
RooRealVar*)frac(nPdf+imin))->setVal(1.-mfrac);
440 ((
RooRealVar*)frac(nPdf+imax))->setVal(mfrac);
441 }
else if (imax==imin) {
447 for (
Int_t i=0; i<nPdf; ++i)
452 }
else if (imax==imin) {
457 for (
Int_t i=0; i<nPdf; ++i) {
472 double mmin=-DBL_MAX;
473 for (
Int_t i=0; i<nPdf; ++i)
474 if ( (*
_mref)[i]>mmin && (*
_mref)[i]<=mval ) { mmin=(*_mref)[i]; imin=i; }
486 for (
Int_t i=0; i<nPdf; ++i)
487 if ( (*
_mref)[i]<mmax && (*
_mref)[i]>=mval ) { mmax=(*_mref)[i]; imax=i; }
TMatrixT< Double_t > TMatrixD
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
TVectorT< Double_t > TVectorD
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
RooAbsMoment represents the first, second, or third order derivative of any RooAbsReal as calculated ...
Abstract interface for all probability density functions.
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.
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.
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 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 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
virtual double getVal(const RooArgSet *set=nullptr) const
Special version of getVal() overrides RooAbsReal::getVal() to save value of current normalization set...
~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
CacheElem * getCache(const RooArgSet *nset) const
RooRealVar represents a variable that can be changed from the outside.
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.
virtual const char * GetName() const
Returns name of object.
constexpr Double_t PiOver2()
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.