Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
38
39#include "TError.h"
40#include <vector>
41
42
43////////////////////////////////////////////////////////////////////////////////
44/// Create a polynomial in the variable `x`.
45/// \param[in] name Name of the PDF
46/// \param[in] title Title for plotting the PDF
47/// \param[in] x The variable of the polynomial
48/// \param[in] coefList The coefficients \f$ a_i \f$
49/// \param[in] lowestOrder [optional] Truncate the sum such that it skips the lower orders:
50/// \f[
51/// 1. + \sum_{i=0}^{\mathrm{coefList.size()}} a_{i} * x^{(i + \mathrm{lowestOrder})}
52/// \f]
53///
54/// This means that
55/// \code{.cpp}
56/// RooPolynomial pol("pol", "pol", x, RooArgList(a, b), lowestOrder = 2)
57/// \endcode
58/// computes
59/// \f[
60/// \mathrm{pol}(x) = 1 * x^0 + (0 * x^{\ldots}) + a * x^2 + b * x^3.
61/// \f]
62
63RooPolynomial::RooPolynomial(const char *name, const char *title, RooAbsReal &x, const RooArgList &coefList,
64 Int_t lowestOrder)
65 : RooAbsPdf(name, title),
66 _x("x", "Dependent", this, x),
67 _coefList("coefList", "List of coefficients", this),
68 _lowestOrder(lowestOrder)
69{
70 // Check lowest order
71 if (_lowestOrder < 0) {
72 coutE(InputArguments) << "RooPolynomial::ctor(" << GetName()
73 << ") WARNING: lowestOrder must be >=0, setting value to 0" << std::endl;
74 _lowestOrder = 0;
75 }
76
78}
79
80////////////////////////////////////////////////////////////////////////////////
81
82RooPolynomial::RooPolynomial(const char *name, const char *title, RooAbsReal &x)
83 : RooAbsPdf(name, title),
84 _x("x", "Dependent", this, x),
85 _coefList("coefList", "List of coefficients", this)
86{
87}
88
89////////////////////////////////////////////////////////////////////////////////
90/// Copy constructor
91
94 _x("x", this, other._x),
95 _coefList("coefList", this, other._coefList),
96 _lowestOrder(other._lowestOrder)
97{
98}
99
100////////////////////////////////////////////////////////////////////////////////
101
103{
104 const unsigned sz = _coefList.size();
105 if (!sz)
106 return _lowestOrder ? 1. : 0.;
107
109
110 return RooFit::Detail::MathFuncs::polynomial<true>(_wksp.data(), sz, _lowestOrder, _x);
111}
112
113/// Compute multiple values of Polynomial.
115{
116 return RooPolyVar::doEvalImpl(this, ctx, _x.arg(), _coefList, _lowestOrder);
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// Advertise to RooFit that this function can be analytically integrated.
121Int_t RooPolynomial::getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char * /*rangeName*/) const
122{
123 return matchArgs(allVars, analVars, _x);
124}
125
126////////////////////////////////////////////////////////////////////////////////
127/// Do the analytical integral according to the code that was returned by getAnalyticalIntegral().
128double RooPolynomial::analyticalIntegral(Int_t code, const char *rangeName) const
129{
130 R__ASSERT(code == 1);
131
132 const double xmin = _x.min(rangeName);
133 const double xmax = _x.max(rangeName);
134 const unsigned sz = _coefList.size();
135 if (!sz)
136 return _lowestOrder ? xmax - xmin : 0.0;
137
139
140 return RooFit::Detail::MathFuncs::polynomialIntegral<true>(_wksp.data(), sz, _lowestOrder, xmin, xmax);
141}
#define coutE(a)
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
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:24
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
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:49
Double_t x[n]
Definition legend1.C:17