49 m(
"m",
"m", this, _m),
50 _varList(
"varList",
"List of variables", this),
51 _pdfList(
"pdfList",
"List of pdfs", this),
73 m(
"m",
"m", this, _m),
74 _varList(
"varList",
"List of variables", this),
75 _pdfList(
"pdfList",
"List of pdfs", this),
89 for (
auto *mref : mrefList) {
91 coutE(InputArguments) <<
"RooMomentMorph::ctor(" <<
GetName() <<
") ERROR: mref " << mref->GetName() <<
" is not of type RooAbsReal" << std::endl ;
92 throw std::string(
"RooPolyMorh::ctor() ERROR mref is not of type RooAbsReal") ;
95 coutW(InputArguments) <<
"RooMomentMorph::ctor(" <<
GetName() <<
") WARNING mref point " << i <<
" is not a constant, taking a snapshot of its value" << std::endl ;
110 m(
"m", this, other.
m),
137 if (nPdf!=
_mref->GetNrows()) {
138 coutE(InputArguments) <<
"RooMomentMorph::initialize(" <<
GetName() <<
") ERROR: nPdf != nRefPoints" << std::endl ;
148 dm[i] = (*_mref)[i]-(*_mref)[0];
150 if (i>0) M(0,i) = 0.;
154 M(i,j) = std::pow(dm[i],(
double)j);
163 std::unique_ptr<RooChangeTracker> && tracker,
180 std::vector<RooAbsReal*> meanrv(nPdf*nVar,null);
181 std::vector<RooAbsReal*> sigmarv(nPdf*nVar,null);
182 std::vector<RooAbsReal*> myrms(nVar,null);
183 std::vector<RooAbsReal*> mypos(nVar,null);
184 std::vector<RooAbsReal*> slope(nPdf*nVar,null);
185 std::vector<RooAbsReal*> offs(nPdf*nVar,null);
186 std::vector<RooAbsReal*> transVar(nPdf*nVar,null);
187 std::vector<RooAbsReal*> transPdf(nPdf,null);
196 for (
Int_t i=0; i<2*nPdf; ++i) {
197 std::string fracName =
"frac_" + std::to_string(i);
202 if (i<nPdf) coefList.
add(*frac);
203 else coefList2.
add(*frac);
204 ownedComps.
add(*frac);
207 std::unique_ptr<RooAddPdf> theSumPdf;
208 std::string sumpdfName =
Form(
"%s_sumpdf",
GetName());
213 for (
Int_t i=0; i<nPdf; ++i) {
214 for (
Int_t j=0; j<nVar; ++j) {
216 std::string meanName =
Form(
"%s_mean_%d_%d",
GetName(),i,j);
217 std::string sigmaName =
Form(
"%s_sigma_%d_%d",
GetName(),i,j);
226 sigmarv[
ij(i,j)] = mom ;
227 meanrv[
ij(i,j)] = mom->
mean() ;
229 ownedComps.
add(*sigmarv[
ij(i,j)]) ;
234 for (
Int_t j=0; j<nVar; ++j) {
237 for (
Int_t i=0; i<nPdf; ++i) {
238 meanList.
add(*meanrv[
ij(i,j)]);
239 rmsList.
add(*sigmarv[
ij(i,j)]);
241 std::string myrmsName =
Form(
"%s_rms_%d",
GetName(),j);
242 std::string myposName =
Form(
"%s_pos_%d",
GetName(),j);
243 myrms[j] =
new RooAddition(myrmsName.c_str(),myrmsName.c_str(),rmsList,coefList2);
244 mypos[j] =
new RooAddition(myposName.c_str(),myposName.c_str(),meanList,coefList2);
251 for (
Int_t i=0; i<nPdf; ++i) {
254 std::string pdfName =
"pdf_" + std::to_string(i);
257 for (
Int_t j=0; j<nVar; ++j) {
259 std::string slopeName =
Form(
"%s_slope_%d_%d",
GetName(),i,j);
260 std::string offsetName =
Form(
"%s_offset_%d_%d",
GetName(),i,j);
261 slope[
ij(i,j)] =
new RooFormulaVar(slopeName.c_str(),
"@0/@1", {*sigmarv[ij(i,j)],*myrms[j]});
262 offs[
ij(i,j)] =
new RooFormulaVar(offsetName.c_str(),
"@0-(@1*@2)", {*meanrv[ij(i,j)],*mypos[j],*slope[ij(i,j)]});
266 std::string transVarName =
Form(
"%s_transVar_%d_%d",
GetName(),i,j);
269 transVar[
ij(i,j)] =
new RooLinearVar(transVarName.c_str(),transVarName.c_str(),*var,*slope[
ij(i,j)],*offs[
ij(i,j)]);
273 transVar[
ij(i,j)]->addServer(
const_cast<RooAbsReal&
>(
m.arg()));
275 ownedComps.
add(*transVar[
ij(i,j)]) ;
279 transPdfList.
add(*transPdf[i]);
280 ownedComps.
add(*transPdf[i]) ;
283 theSumPdf = std::make_unique<RooAddPdf>(sumpdfName.c_str(),sumpdfName.c_str(),transPdfList,coefList);
286 theSumPdf = std::make_unique<RooAddPdf>(sumpdfName.c_str(),sumpdfName.c_str(),
_pdfList,coefList);
288 theSumPdf->fixCoefNormalization(*nset);
292 theSumPdf->addServer(
const_cast<RooAbsReal&
>(
m.arg()));
293 theSumPdf->addOwnedComponents(ownedComps) ;
296 std::string trackerName =
Form(
"%s_frac_tracker",
GetName()) ;
297 auto tracker = std::make_unique<RooChangeTracker>(trackerName.c_str(),trackerName.c_str(),
m.arg(),
true) ;
300 auto cache =
new CacheElem(std::move(theSumPdf),std::move(tracker),fracl) ;
301 _cacheMgr.setObj(
nullptr,
nullptr,cache,
nullptr);
303 cache->calculateFractions(*
this,
false);
333 if (cache->
_tracker->hasChanged(
true)) {
346 if (cache->
_tracker->hasChanged(
true)) {
373 double dm = self.
m - (*self.
_mref)[0];
376 double sumposfrac=0.;
377 for (
Int_t i=0; i<nPdf; ++i) {
379 for (
Int_t j=0; j<nPdf; ++j) { ffrac += (*self.
_M)(j,i) * (j==0?1.:std::pow(dm,(
double)j)); }
380 if (ffrac>=0) sumposfrac+=ffrac;
385 if (verbose) { std::cout << ffrac << std::endl; }
389 int imin = self.
idxmin(self.
m);
390 int imax = self.
idxmax(self.
m);
391 double mfrac = (self.
m-(*self.
_mref)[imin])/((*self.
_mref)[imax]-(*self.
_mref)[imin]);
403 for (
Int_t i=0; i<2*nPdf; ++i)
410 }
else if (imax==imin) {
416 for (
Int_t i=0; i<nPdf; ++i)
421 }
else if (imax==imin) {
426 for (
Int_t i = 0; i < nPdf; ++i) {
442 double mmin=-DBL_MAX;
443 for (
Int_t i=0; i<nPdf; ++i)
444 if ( (*
_mref)[i]>mmin && (*
_mref)[i]<=mval ) { mmin=(*_mref)[i]; imin=i; }
456 for (
Int_t i=0; i<nPdf; ++i)
457 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
int Int_t
Signed integer 4 bytes (int).
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
double getValV(const RooArgSet *set=nullptr) const override
Return current value, normalized by integrating over the observables in nset.
RooAbsPdf()
Default constructor.
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.
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 char * GetName() const override
Returns name of object.
constexpr Double_t PiOver2()