Logo ROOT  
Reference Guide
RooPolyVar.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$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 RooPolyVar.cxx
19\class RooPolyVar
20\ingroup Roofitcore
21
22Class RooPolyVar is a RooAbsReal implementing a polynomial in terms
23of a list of RooAbsReal coefficients
24\f[f(x) = \sum_{i} a_{i} \cdot x^i \f]
25Class RooPolyvar implements analytical integrals of all polynomials
26it can define.
27**/
28
29#include <cmath>
30
31#include "RooPolyVar.h"
32#include "RooArgList.h"
33#include "RooMsgService.h"
34//#include "Riostream.h"
35
36#include "TError.h"
37
38using namespace std;
39
41;
42
43
44////////////////////////////////////////////////////////////////////////////////
45/// Default constructor
46
47RooPolyVar::RooPolyVar() : _lowestOrder(0)
48{ }
49
50
51////////////////////////////////////////////////////////////////////////////////
52/// Construct polynomial in x with coefficients in coefList. If
53/// lowestOrder is not zero, then the first element in coefList is
54/// interpreted as as the 'lowestOrder' coefficients and all
55/// subsequent coeffient elements are shifted by a similar amount.
56RooPolyVar::RooPolyVar(const char* name, const char* title,
57 RooAbsReal& x, const RooArgList& coefList, Int_t lowestOrder) :
58 RooAbsReal(name, title),
59 _x("x", "Dependent", this, x),
60 _coefList("coefList","List of coefficients",this),
61 _lowestOrder(lowestOrder)
62{
63 // Check lowest order
64 if (_lowestOrder<0) {
65 coutE(InputArguments) << "RooPolyVar::ctor(" << GetName()
66 << ") WARNING: lowestOrder must be >=0, setting value to 0" << endl ;
67 _lowestOrder=0 ;
68 }
69
70 RooFIter coefIter = coefList.fwdIterator() ;
71 RooAbsArg* coef ;
72 while((coef = (RooAbsArg*)coefIter.next())) {
73 if (!dynamic_cast<RooAbsReal*>(coef)) {
74 coutE(InputArguments) << "RooPolyVar::ctor(" << GetName() << ") ERROR: coefficient " << coef->GetName()
75 << " is not of type RooAbsReal" << endl ;
76 R__ASSERT(0) ;
77 }
78 _coefList.add(*coef) ;
79 }
80}
81
82
83////////////////////////////////////////////////////////////////////////////////
84/// Constructor of flat polynomial function
85
86RooPolyVar::RooPolyVar(const char* name, const char* title,
87 RooAbsReal& x) :
88 RooAbsReal(name, title),
89 _x("x", "Dependent", this, x),
90 _coefList("coefList","List of coefficients",this),
91 _lowestOrder(1)
92{ }
93
94
95
96////////////////////////////////////////////////////////////////////////////////
97/// Copy constructor
98
99RooPolyVar::RooPolyVar(const RooPolyVar& other, const char* name) :
100 RooAbsReal(other, name),
101 _x("x", this, other._x),
102 _coefList("coefList",this,other._coefList),
103 _lowestOrder(other._lowestOrder)
104{ }
105
106
107
108
109////////////////////////////////////////////////////////////////////////////////
110/// Destructor
111
113{ }
114
115
116
117
118////////////////////////////////////////////////////////////////////////////////
119/// Calculate and return value of polynomial
120
122{
123 const unsigned sz = _coefList.getSize();
124 const int lowestOrder = _lowestOrder;
125 if (!sz) return lowestOrder ? 1. : 0.;
126 _wksp.clear();
127 _wksp.reserve(sz);
128 {
129 const RooArgSet* nset = _coefList.nset();
130 for (const auto arg : _coefList) {
131 const auto c = static_cast<RooAbsReal*>(arg);
132 _wksp.push_back(c->getVal(nset));
133 }
134 }
135 const Double_t x = _x;
136 Double_t retVal = _wksp[sz - 1];
137 for (unsigned i = sz - 1; i--; ) retVal = _wksp[i] + x * retVal;
138 return retVal * std::pow(x, lowestOrder);
139}
140
141
142
143////////////////////////////////////////////////////////////////////////////////
144/// Advertise that we can internally integrate over x
145
146Int_t RooPolyVar::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const
147{
148 if (matchArgs(allVars, analVars, _x)) return 1;
149 return 0;
150}
151
152
153
154////////////////////////////////////////////////////////////////////////////////
155/// Calculate and return analytical integral over x
156
157Double_t RooPolyVar::analyticalIntegral(Int_t code, const char* rangeName) const
158{
159 R__ASSERT(code==1) ;
160
161 const Double_t xmin = _x.min(rangeName), xmax = _x.max(rangeName);
162 const int lowestOrder = _lowestOrder;
163 const unsigned sz = _coefList.getSize();
164 if (!sz) return xmax - xmin;
165 _wksp.clear();
166 _wksp.reserve(sz);
167 {
168 const RooArgSet* nset = _coefList.nset();
170 unsigned i = 1 + lowestOrder;
171 RooAbsReal* c;
172 while ((c = (RooAbsReal*) it.next())) {
173 _wksp.push_back(c->getVal(nset) / Double_t(i));
174 ++i;
175 }
176 }
177 Double_t min = _wksp[sz - 1], max = _wksp[sz - 1];
178 for (unsigned i = sz - 1; i--; )
179 min = _wksp[i] + xmin * min, max = _wksp[i] + xmax * max;
180 return max * std::pow(xmax, 1 + lowestOrder) - min * std::pow(xmin, 1 + lowestOrder);
181}
#define c(i)
Definition: RSha256.hxx:101
#define coutE(a)
Definition: RooMsgService.h:34
int Int_t
Definition: RtypesCore.h:41
double Double_t
Definition: RtypesCore.h:55
#define ClassImp(name)
Definition: Rtypes.h:365
#define R__ASSERT(e)
Definition: TError.h:96
char name[80]
Definition: TGX11.cxx:109
float xmin
Definition: THbookFile.cxx:93
float xmax
Definition: THbookFile.cxx:93
double pow(double, double)
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:71
RooFIter fwdIterator() const R__SUGGEST_ALTERNATIVE("begin()
One-time forward iterator.
Int_t getSize() const
const RooArgSet * nset() const
Definition: RooAbsProxy.h:46
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:59
Bool_t 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:21
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
A one-time forward iterator working on RooLinkedList or RooAbsCollection.
RooAbsArg * next()
Return next element or nullptr if at end.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
Class RooPolyVar is a RooAbsReal implementing a polynomial in terms of a list of RooAbsReal coefficie...
Definition: RooPolyVar.h:28
RooPolyVar()
Default constructor.
Definition: RooPolyVar.cxx:47
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const
Advertise that we can internally integrate over x.
Definition: RooPolyVar.cxx:146
Int_t _lowestOrder
Definition: RooPolyVar.h:47
virtual ~RooPolyVar()
Destructor.
Definition: RooPolyVar.cxx:112
RooListProxy _coefList
Definition: RooPolyVar.h:46
RooRealProxy _x
Definition: RooPolyVar.h:45
Double_t analyticalIntegral(Int_t code, const char *rangeName=0) const
Calculate and return analytical integral over x.
Definition: RooPolyVar.cxx:157
Double_t evaluate() const
do not persist
Definition: RooPolyVar.cxx:121
std::vector< Double_t > _wksp
Definition: RooPolyVar.h:49
Double_t min(const char *rname=0) const
Query lower limit of range. This requires the payload to be RooAbsRealLValue or derived.
Double_t max(const char *rname=0) const
Query upper limit of range. This requires the payload to be RooAbsRealLValue or derived.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Double_t x[n]
Definition: legend1.C:17
@ InputArguments
Definition: RooGlobalFunc.h:68