Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooPolynomial.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitModels *
4 * @(#)root/roofit:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17/** \class RooPolynomial
18 \ingroup Roofit
19
20RooPolynomial implements a polynomial p.d.f of the form
21\f[ f(x) = \mathcal{N} \cdot \sum_{i} a_{i} * x^i \f]
22By default, the coefficient \f$ a_0 \f$ is chosen to be 1, as polynomial
23probability density functions have one degree of freedom
24less than polynomial functions due to the normalisation condition. \f$ \mathcal{N} \f$
25is a normalisation constant that is automatically calculated when the polynomial is used
26in computations.
27
28The sum can be truncated at the low end. See the main constructor
29RooPolynomial::RooPolynomial(const char*, const char*, RooAbsReal&, const RooArgList&, Int_t)
30**/
31
32#include "RooPolynomial.h"
33#include "RooArgList.h"
34#include "RooMsgService.h"
35#include "RooPolyVar.h"
36
39
40#include "TError.h"
41#include <vector>
42
44
45////////////////////////////////////////////////////////////////////////////////
46/// Create a polynomial in the variable `x`.
47/// \param[in] name Name of the PDF
48/// \param[in] title Title for plotting the PDF
49/// \param[in] x The variable of the polynomial
50/// \param[in] coefList The coefficients \f$ a_i \f$
51/// \param[in] lowestOrder [optional] Truncate the sum such that it skips the lower orders:
52/// \f[
53/// 1. + \sum_{i=0}^{\mathrm{coefList.size()}} a_{i} * x^{(i + \mathrm{lowestOrder})}
54/// \f]
55///
56/// This means that
57/// \code{.cpp}
58/// RooPolynomial pol("pol", "pol", x, RooArgList(a, b), lowestOrder = 2)
59/// \endcode
60/// computes
61/// \f[
62/// \mathrm{pol}(x) = 1 * x^0 + (0 * x^{\ldots}) + a * x^2 + b * x^3.
63/// \f]
64
65RooPolynomial::RooPolynomial(const char *name, const char *title, RooAbsReal &x, const RooArgList &coefList,
66 Int_t lowestOrder)
67 : RooAbsPdf(name, title),
68 _x("x", "Dependent", this, x),
69 _coefList("coefList", "List of coefficients", this),
70 _lowestOrder(lowestOrder)
71{
72 // Check lowest order
73 if (_lowestOrder < 0) {
74 coutE(InputArguments) << "RooPolynomial::ctor(" << GetName()
75 << ") WARNING: lowestOrder must be >=0, setting value to 0" << std::endl;
76 _lowestOrder = 0;
77 }
78
80}
81
82////////////////////////////////////////////////////////////////////////////////
83
84RooPolynomial::RooPolynomial(const char *name, const char *title, RooAbsReal &x)
85 : RooAbsPdf(name, title),
86 _x("x", "Dependent", this, x),
87 _coefList("coefList", "List of coefficients", this)
88{
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// Copy constructor
93
95 : RooAbsPdf(other, name),
96 _x("x", this, other._x),
97 _coefList("coefList", this, other._coefList),
98 _lowestOrder(other._lowestOrder)
99{
100}
101
102////////////////////////////////////////////////////////////////////////////////
103
105{
106 const unsigned sz = _coefList.size();
107 if (!sz)
108 return _lowestOrder ? 1. : 0.;
109
111
112 return RooFit::Detail::EvaluateFuncs::polynomialEvaluate<true>(_wksp.data(), sz, _lowestOrder, _x);
113}
114
116{
117 const unsigned sz = _coefList.size();
118 if (!sz) {
119 ctx.addResult(this, std::to_string((_lowestOrder ? 1. : 0.)));
120 return;
121 }
122
123 ctx.addResult(
124 this, ctx.buildCall("RooFit::Detail::EvaluateFuncs::polynomialEvaluate<true>", _coefList, sz, _lowestOrder, _x));
125}
126
127/// Compute multiple values of Polynomial.
129{
130 return RooPolyVar::doEvalImpl(this, ctx, _x.arg(), _coefList, _lowestOrder);
131}
132
133////////////////////////////////////////////////////////////////////////////////
134/// Advertise to RooFit that this function can be analytically integrated.
135Int_t RooPolynomial::getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char * /*rangeName*/) const
136{
137 return matchArgs(allVars, analVars, _x);
138}
139
140////////////////////////////////////////////////////////////////////////////////
141/// Do the analytical integral according to the code that was returned by getAnalyticalIntegral().
142double RooPolynomial::analyticalIntegral(Int_t code, const char *rangeName) const
143{
144 R__ASSERT(code == 1);
145
146 const double xmin = _x.min(rangeName);
147 const double xmax = _x.max(rangeName);
148 const unsigned sz = _coefList.size();
149 if (!sz)
150 return _lowestOrder ? xmax - xmin : 0.0;
151
153
154 return RooFit::Detail::AnalyticalIntegrals::polynomialIntegral<true>(_wksp.data(), sz, _lowestOrder, xmin, xmax);
155}
156
157std::string RooPolynomial::buildCallToAnalyticIntegral(Int_t /* code */, const char *rangeName,
159{
160 const double xmin = _x.min(rangeName);
161 const double xmax = _x.max(rangeName);
162 const unsigned sz = _coefList.size();
163 if (!sz)
164 return std::to_string(_lowestOrder ? xmax - xmin : 0.0);
165
166 return ctx.buildCall("RooFit::Detail::AnalyticalIntegrals::polynomialIntegral<true>", _coefList, sz, _lowestOrder,
167 xmin, xmax);
168}
#define coutE(a)
#define ClassImp(name)
Definition Rtypes.h:377
#define R__ASSERT(e)
Definition TError.h:118
char name[80]
Definition TGX11.cxx:110
float xmin
float xmax
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.
Definition RooAbsPdf.h:40
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
bool matchArgs(const RooArgSet &allDeps, RooArgSet &numDeps, const RooArgProxy &a) const
Utility function for use in getAnalyticalIntegral().
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
A class to maintain the context for squashing of RooFit models into code.
std::string buildCall(std::string const &funcname, Args_t const &...args)
Build the code to call the function with name funcname, passing some arguments.
void addResult(RooAbsArg const *key, std::string const &value)
A function to save an expression that includes/depends on the result of the input node.
static void fillCoeffValues(std::vector< double > &wksp, RooListProxy const &coefList)
static void doEvalImpl(RooAbsArg const *caller, RooFit::EvalContext &, RooAbsReal const &x, RooArgList const &coefs, int lowestOrder)
RooPolynomial implements a polynomial p.d.f of the form.
double evaluate() const override
do not persist
RooRealProxy _x
void translate(RooFit::Detail::CodeSquashContext &ctx) const override
This function defines a translation for each RooAbsReal based object that can be used to express the ...
std::string buildCallToAnalyticIntegral(Int_t code, const char *rangeName, RooFit::Detail::CodeSquashContext &ctx) const override
This function defines the analytical integral translation for the class.
std::vector< double > _wksp
RooListProxy _coefList
double analyticalIntegral(Int_t code, const char *rangeName=nullptr) const override
Do the analytical integral according to the code that was returned by getAnalyticalIntegral().
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=nullptr) const override
Advertise to RooFit that this function can be analytically integrated.
void doEval(RooFit::EvalContext &) const override
Compute multiple values of Polynomial.
RooArgList const & coefList() const
Get the coefficient list.
double max(const char *rname=nullptr) const
Query upper limit of range. This requires the payload to be RooAbsRealLValue or derived.
const T & arg() const
Return reference to object held in proxy.
double min(const char *rname=nullptr) const
Query lower limit of range. This requires the payload to be RooAbsRealLValue or derived.
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Double_t x[n]
Definition legend1.C:17