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{
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
93////////////////////////////////////////////////////////////////////////////////
94/// Compute multiple values of Chebychev.
96{
97 std::vector<double> extraArgs;
98 extraArgs.reserve(_coefList.size() + 2);
99 for (auto *coef : _coefList) {
100 extraArgs.push_back(static_cast<const RooAbsReal *>(coef)->getVal());
101 }
102 extraArgs.push_back(_x.min(_refRangeName ? _refRangeName->GetName() : nullptr));
103 extraArgs.push_back(_x.max(_refRangeName ? _refRangeName->GetName() : nullptr));
104 RooBatchCompute::compute(ctx.config(this), RooBatchCompute::Chebychev, ctx.output(), {ctx.at(_x)}, extraArgs);
105}
106
107////////////////////////////////////////////////////////////////////////////////
108
109
110Int_t RooChebychev::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /* rangeName */) const
111{
112 return matchArgs(allVars, analVars, _x) ? 1 : 0;
113}
114
115////////////////////////////////////////////////////////////////////////////////
116
117double RooChebychev::analyticalIntegral(Int_t code, const char *rangeName) const
118{
119 assert(1 == code);
120 (void)code;
121
122 double xmax = _x.max(_refRangeName ? _refRangeName->GetName() : nullptr);
123 double xmin = _x.min(_refRangeName ? _refRangeName->GetName() : nullptr);
124 unsigned int sz = _coefList.size();
125
126 std::vector<double> coeffs;
127 for (auto it : _coefList)
128 coeffs.push_back(static_cast<const RooAbsReal &>(*it).getVal());
129
130 return RooFit::Detail::MathFuncs::chebychevIntegral(coeffs.data(), sz, xmin, xmax, _x.min(rangeName),
131 _x.max(rangeName));
132}
#define ClassImp(name)
Definition Rtypes.h:382
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:24
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.
RooArgList const & coefList() const
RooRealProxy _x
void selectNormalizationRange(const char *rangeName=nullptr, bool force=false) override
Interface function to force use of a given normalization range to interpret function value.
TNamed * _refRangeName
RooListProxy _coefList
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
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:518
double chebychev(double *coeffs, unsigned int nCoeffs, double x_in, double xMin, double xMax)
Definition MathFuncs.h:139