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