Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooChebychev.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitModels *
4 * @(#)root/roofit:$Id$
5 * Authors: *
6 * GR, Gerhard Raven, UC San Diego, Gerhard.Raven@slac.stanford.edu
7 * *
8 * Copyright (c) 2000-2005, Regents of the University of California *
9 * and Stanford University. All rights reserved. *
10 * *
11 * Redistribution and use in source and binary forms, *
12 * with or without modification, are permitted according to the terms *
13 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
14 *****************************************************************************/
15
16/** \class RooChebychev
17 \ingroup Roofit
18
19Chebychev polynomial p.d.f. of the first kind.
20
21The coefficient that goes with \f$ T_0(x)=1 \f$ (i.e. the constant polynomial) is
22implicitly assumed to be 1, and the list of coefficients supplied by callers
23starts with the coefficient that goes with \f$ T_1(x)=x \f$ (i.e. the linear term).
24**/
25
26#include "RooChebychev.h"
27#include "RooRealVar.h"
28#include "RooArgList.h"
29#include "RooNameReg.h"
30#include "RooBatchCompute.h"
31
33
34#include <cmath>
35
37
38////////////////////////////////////////////////////////////////////////////////
39
41
42////////////////////////////////////////////////////////////////////////////////
43/// Constructor
44
45RooChebychev::RooChebychev(const char* name, const char* title,
46 RooAbsReal& x, const RooArgList& coefList):
47 RooAbsPdf(name, title),
48 _x("x", "Dependent", this, x),
49 _coefList("coefficients","List of coefficients",this)
50{
51 _coefList.addTyped<RooAbsReal>(coefList);
52}
53
54////////////////////////////////////////////////////////////////////////////////
55
56RooChebychev::RooChebychev(const RooChebychev& other, const char* name) :
57 RooAbsPdf(other, name),
58 _x("x", this, other._x),
59 _coefList("coefList",this,other._coefList),
60 _refRangeName(other._refRangeName)
61{
62}
63
64////////////////////////////////////////////////////////////////////////////////
65
66void RooChebychev::selectNormalizationRange(const char* rangeName, bool force)
67{
68 if (rangeName && (force || !_refRangeName)) {
69 _refRangeName = const_cast<TNamed*>(RooNameReg::instance().constPtr(rangeName));
70 }
71 if (!rangeName) {
72 _refRangeName = nullptr ;
73 }
74}
75
76////////////////////////////////////////////////////////////////////////////////
77
79{
80 // first bring the range of the variable _x to the normalised range [-1, 1]
81 // calculate sum_k c_k T_k(x) where x is given in the normalised range,
82 // c_0 = 1, and the higher coefficients are given in _coefList
83 double xmax = _x.max(_refRangeName ? _refRangeName->GetName() : nullptr);
84 double xmin = _x.min(_refRangeName ? _refRangeName->GetName() : nullptr);
85
86 std::vector<double> coeffs;
87 for (auto it : _coefList) {
88 coeffs.push_back(static_cast<const RooAbsReal &>(*it).getVal());
89 }
91}
92
94{
95 // first bring the range of the variable _x to the normalised range [-1, 1]
96 // calculate sum_k c_k T_k(x) where x is given in the normalised range,
97 // c_0 = 1, and the higher coefficients are given in _coefList
98 double xmax = _x.max(_refRangeName ? _refRangeName->GetName() : nullptr);
99 double xmin = _x.min(_refRangeName ? _refRangeName->GetName() : nullptr);
100
101 ctx.addResult(this,
102 ctx.buildCall("RooFit::Detail::MathFuncs::chebychev", _coefList, _coefList.size(), _x, xmin, xmax));
103}
104
105////////////////////////////////////////////////////////////////////////////////
106/// Compute multiple values of Chebychev.
108{
109 std::vector<double> extraArgs;
110 extraArgs.reserve(_coefList.size() + 2);
111 for (auto *coef : _coefList) {
112 extraArgs.push_back(static_cast<const RooAbsReal *>(coef)->getVal());
113 }
114 extraArgs.push_back(_x.min(_refRangeName ? _refRangeName->GetName() : nullptr));
115 extraArgs.push_back(_x.max(_refRangeName ? _refRangeName->GetName() : nullptr));
116 RooBatchCompute::compute(ctx.config(this), RooBatchCompute::Chebychev, ctx.output(), {ctx.at(_x)}, extraArgs);
117}
118
119////////////////////////////////////////////////////////////////////////////////
120
121
122Int_t RooChebychev::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /* rangeName */) const
123{
124 if (matchArgs(allVars, analVars, _x)) return 1;
125 return 0;
126}
127
128////////////////////////////////////////////////////////////////////////////////
129
130double RooChebychev::analyticalIntegral(Int_t code, const char* rangeName) const
131{
132 assert(1 == code); (void)code;
133
134 double xmax = _x.max(_refRangeName ? _refRangeName->GetName() : nullptr);
135 double xmaxFull = _x.max(rangeName);
136 double xmin = _x.min(_refRangeName ? _refRangeName->GetName() : nullptr);
137 double xminFull = _x.min(rangeName);
138 unsigned int sz = _coefList.size();
139
140 std::vector<double> coeffs;
141 for (auto it : _coefList)
142 coeffs.push_back(static_cast<const RooAbsReal &>(*it).getVal());
143
144 return RooFit::Detail::MathFuncs::chebychevIntegral(coeffs.data(), sz, xmin, xmax, xminFull, xmaxFull);
145}
146
147std::string RooChebychev::buildCallToAnalyticIntegral(Int_t /* code */, const char *rangeName,
149{
150 double xmax = _x.max(_refRangeName ? _refRangeName->GetName() : nullptr);
151 double xmaxFull = _x.max(rangeName);
152 double xmin = _x.min(_refRangeName ? _refRangeName->GetName() : nullptr);
153 double xminFull = _x.min(rangeName);
154 unsigned int sz = _coefList.size();
155
156 return ctx.buildCall("RooFit::Detail::MathFuncs::chebychevIntegral", _coefList, sz, xmin, xmax, xminFull, xmaxFull);
157}
#define ClassImp(name)
Definition Rtypes.h:377
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
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:103
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
Chebychev polynomial p.d.f.
void doEval(RooFit::EvalContext &) const override
Compute multiple values of Chebychev.
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=nullptr) const override
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
double analyticalIntegral(Int_t code, const char *rangeName=nullptr) const override
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
RooRealProxy _x
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.
void selectNormalizationRange(const char *rangeName=nullptr, bool force=false) override
Interface function to force use of a given normalization range to interpret function value.
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 ...
TNamed * _refRangeName
RooListProxy _coefList
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
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.
std::span< double > output()
RooBatchCompute::Config config(RooAbsArg const *arg) const
const TNamed * constPtr(const char *stringPtr)
Return a unique TNamed pointer for given C++ string.
static RooNameReg & instance()
Return reference to singleton instance.
double max(const char *rname=nullptr) const
Query upper limit of range. This requires the payload to be RooAbsRealLValue or derived.
double min(const char *rname=nullptr) const
Query lower limit of range. This requires the payload to be RooAbsRealLValue or derived.
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Double_t x[n]
Definition legend1.C:17
void compute(Config cfg, Computer comp, std::span< double > output, VarSpan vars, ArgSpan extraArgs={})
double chebychevIntegral(double const *coeffs, unsigned int nCoeffs, double xMin, double xMax, double xMinFull, double xMaxFull)
Definition MathFuncs.h:513
double chebychev(double *coeffs, unsigned int nCoeffs, double x_in, double xMin, double xMax)
Definition MathFuncs.h:139