ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 /**
18 \file RooPolynomial.cxx
19 \class RooPolynomial
20 \ingroup Roofit
21 
22 RooPolynomial implements a polynomial p.d.f of the form
23 \f[ f(x) = \sum_{i} a_{i} * x^i \f]
24 By default coefficient a_0 is chosen to be 1, as polynomial
25 probability density functions have one degree of freedome
26 less than polynomial functions due to the normalization condition
27 **/
28 
29 #include <cmath>
30 #include <cassert>
31 
32 #include "RooPolynomial.h"
33 #include "RooAbsReal.h"
34 #include "RooArgList.h"
35 #include "RooMsgService.h"
36 
37 #include "TError.h"
38 
39 using namespace std;
40 
42 ;
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// coverity[UNINIT_CTOR]
46 
48 {
49 }
50 
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// Constructor
54 
55 RooPolynomial::RooPolynomial(const char* name, const char* title,
56  RooAbsReal& x, const RooArgList& coefList, Int_t lowestOrder) :
57  RooAbsPdf(name, title),
58  _x("x", "Dependent", this, x),
59  _coefList("coefList","List of coefficients",this),
60  _lowestOrder(lowestOrder)
61 {
62  // Check lowest order
63  if (_lowestOrder<0) {
64  coutE(InputArguments) << "RooPolynomial::ctor(" << GetName()
65  << ") WARNING: lowestOrder must be >=0, setting value to 0" << endl ;
66  _lowestOrder=0 ;
67  }
68 
69  RooFIter coefIter = coefList.fwdIterator() ;
70  RooAbsArg* coef ;
71  while((coef = (RooAbsArg*)coefIter.next())) {
72  if (!dynamic_cast<RooAbsReal*>(coef)) {
73  coutE(InputArguments) << "RooPolynomial::ctor(" << GetName() << ") ERROR: coefficient " << coef->GetName()
74  << " is not of type RooAbsReal" << endl ;
75  R__ASSERT(0) ;
76  }
77  _coefList.add(*coef) ;
78  }
79 }
80 
81 
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 
85 RooPolynomial::RooPolynomial(const char* name, const char* title,
86  RooAbsReal& x) :
87  RooAbsPdf(name, title),
88  _x("x", "Dependent", this, x),
89  _coefList("coefList","List of coefficients",this),
90  _lowestOrder(1)
91 { }
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// Copy constructor
95 
96 RooPolynomial::RooPolynomial(const RooPolynomial& other, const char* name) :
97  RooAbsPdf(other, name),
98  _x("x", this, other._x),
99  _coefList("coefList",this,other._coefList),
100  _lowestOrder(other._lowestOrder)
101 { }
102 
103 
104 
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Destructor
108 
110 { }
111 
112 
113 
114 
115 ////////////////////////////////////////////////////////////////////////////////
116 
118 {
119  // Calculate and return value of polynomial
120 
121  const unsigned sz = _coefList.getSize();
122  const int lowestOrder = _lowestOrder;
123  if (!sz) return lowestOrder ? 1. : 0.;
124  _wksp.clear();
125  _wksp.reserve(sz);
126  {
127  const RooArgSet* nset = _coefList.nset();
129  RooAbsReal* c;
130  while ((c = (RooAbsReal*) it.next())) _wksp.push_back(c->getVal(nset));
131  }
132  const Double_t x = _x;
133  Double_t retVal = _wksp[sz - 1];
134  for (unsigned i = sz - 1; i--; ) retVal = _wksp[i] + x * retVal;
135  return retVal * std::pow(x, lowestOrder) + (lowestOrder ? 1.0 : 0.0);
136 }
137 
138 
139 
140 ////////////////////////////////////////////////////////////////////////////////
141 
142 Int_t RooPolynomial::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const
143 {
144  if (matchArgs(allVars, analVars, _x)) return 1;
145  return 0;
146 }
147 
148 
149 
150 ////////////////////////////////////////////////////////////////////////////////
151 
152 Double_t RooPolynomial::analyticalIntegral(Int_t code, const char* rangeName) const
153 {
154  R__ASSERT(code==1) ;
155 
156  const Double_t xmin = _x.min(rangeName), xmax = _x.max(rangeName);
157  const int lowestOrder = _lowestOrder;
158  const unsigned sz = _coefList.getSize();
159  if (!sz) return xmax - xmin;
160  _wksp.clear();
161  _wksp.reserve(sz);
162  {
163  const RooArgSet* nset = _coefList.nset();
165  unsigned i = 1 + lowestOrder;
166  RooAbsReal* c;
167  while ((c = (RooAbsReal*) it.next())) {
168  _wksp.push_back(c->getVal(nset) / Double_t(i));
169  ++i;
170  }
171  }
172  Double_t min = _wksp[sz - 1], max = _wksp[sz - 1];
173  for (unsigned i = sz - 1; i--; )
174  min = _wksp[i] + xmin * min, max = _wksp[i] + xmax * max;
175  return max * std::pow(xmax, 1 + lowestOrder) - min * std::pow(xmin, 1 + lowestOrder) +
176  (lowestOrder ? (xmax - xmin) : 0.);
177 }
const RooArgSet * nset() const
Definition: RooAbsProxy.h:47
#define coutE(a)
Definition: RooMsgService.h:35
Double_t analyticalIntegral(Int_t code, const char *rangeName=0) const
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral. ...
RooListProxy _coefList
Definition: RooPolynomial.h:46
float xmin
Definition: THbookFile.cxx:93
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
Definition: vector.h:433
RooRealProxy _x
Definition: RooPolynomial.h:45
return c
RooFIter fwdIterator() const
virtual ~RooPolynomial()
Destructor.
#define R__ASSERT(e)
Definition: TError.h:98
RooPolynomial()
coverity[UNINIT_CTOR]
int Int_t
Definition: RtypesCore.h:41
Double_t x[n]
Definition: legend1.C:17
double pow(double, double)
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
ClassImp(RooPolynomial)
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported...
std::vector< Double_t > _wksp
Definition: RooPolynomial.h:49
Double_t evaluate() const
do not persist
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
float xmax
Definition: THbookFile.cxx:93
RooAbsArg * next()
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
#define name(a, b)
Definition: linkTestLib0.cpp:5
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
Double_t min(const char *rname=0) const
Definition: RooRealProxy.h:56
Int_t _lowestOrder
Definition: RooPolynomial.h:47
RooPolynomial implements a polynomial p.d.f of the form By default coefficient a_0 is chosen to be 1...
Definition: RooPolynomial.h:28
Bool_t matchArgs(const RooArgSet &allDeps, RooArgSet &numDeps, const RooArgProxy &a) const
Utility function for use in getAnalyticalIntegral().
Int_t getSize() const
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
Double_t max(const char *rname=0) const
Definition: RooRealProxy.h:57