Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooChiSquarePdf.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitModels *
4 * @(#)root/roofit:$Id$
5 * Authors: *
6 * Kyle Cranmer
7 * *
8 *****************************************************************************/
9
10/** \class RooChiSquarePdf
11 \ingroup Roofit
12
13The PDF of the Chi Square distribution for n degrees of freedom.
14Oddly, this is hard to find in ROOT (except via relation to GammaDist).
15Here we also implement the analytic integral.
16**/
17
18#include "RooChiSquarePdf.h"
19#include "RooRealVar.h"
20#include "RooBatchCompute.h"
21#include "RooHelpers.h"
22
23#include "TMath.h"
24
25#include <array>
26#include <cmath>
27
28
29////////////////////////////////////////////////////////////////////////////////
30
34
35////////////////////////////////////////////////////////////////////////////////
36
37RooChiSquarePdf::RooChiSquarePdf(const char* name, const char* title,
38 RooAbsReal& x, RooAbsReal& ndof):
39 RooAbsPdf(name, title),
40 _x("x", "Dependent", this, x),
41 _ndof("ndof","ndof", this, ndof)
42{
43 RooHelpers::checkRangeOfParameters(this, {&x, &ndof}, 0.);
44}
45
46////////////////////////////////////////////////////////////////////////////////
47
50 _x("x", this, other._x),
51 _ndof("ndof",this,other._ndof)
52{
53}
54
55////////////////////////////////////////////////////////////////////////////////
56
58{
59 if (_x <= 0)
60 return 0;
61
62 return pow(_x, (_ndof / 2.) - 1.) * std::exp(-_x / 2.) / TMath::Gamma(_ndof / 2.) / std::pow(2., _ndof / 2.);
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// Compute multiple values of ChiSquare distribution.
68{
69 std::array<double, 1> extraArgs{_ndof};
71}
72
73////////////////////////////////////////////////////////////////////////////////
74/// No analytical calculation available (yet) of integrals over subranges
75
77{
78 if (rangeName && strlen(rangeName)) {
79 return 0 ;
80 }
81
82 if (matchArgs(allVars, analVars, _x)) return 1;
83 return 0;
84}
85
86////////////////////////////////////////////////////////////////////////////////
87
89{
90 assert(1 == code); (void)code;
91 double xmin = _x.min(rangeName); double xmax = _x.max(rangeName);
92
93 // TMath::Prob needs ndof to be an integer, or it returns 0.
94 // return TMath::Prob(xmin, _ndof) - TMath::Prob(xmax,_ndof);
95
96 // cumulative is known based on lower incomplete gamma function, or regularized gamma function
97 // Wikipedia defines lower incomplete gamma function without the normalization 1/Gamma(ndof),
98 // but it is included in the ROOT implementation.
99 double pmin = TMath::Gamma(_ndof/2,xmin/2);
100 double pmax = TMath::Gamma(_ndof/2,xmax/2);
101
102 // only use this if range is appropriate
103 return pmax-pmin;
104}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:110
float xmin
float xmax
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:32
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
bool matchArgs(const RooArgSet &allDeps, RooArgSet &analDeps, const RooArgProxy &a, const Proxies &... proxies) const
Definition RooAbsReal.h:428
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
The PDF of the Chi Square distribution for n degrees of freedom.
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=nullptr) const override
No analytical calculation available (yet) of integrals over subranges.
double analyticalIntegral(Int_t code, const char *rangeName=nullptr) const override
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
RooRealProxy _ndof
RooRealProxy _x
void doEval(RooFit::EvalContext &) const override
Compute multiple values of ChiSquare distribution.
std::span< double > output()
RooBatchCompute::Config config(RooAbsArg const *arg) const
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.
Double_t x[n]
Definition legend1.C:17
void compute(Config cfg, Computer comp, std::span< double > output, VarSpan vars, ArgSpan extraArgs={})
void checkRangeOfParameters(const RooAbsReal *callingClass, std::initializer_list< const RooAbsReal * > pars, double min=-std::numeric_limits< double >::max(), double max=std::numeric_limits< double >::max(), bool limitsInAllowedRange=false, std::string const &extraMessage="")
Check if the parameters have a range, and warn if the range extends below / above the set limits.
Double_t Gamma(Double_t z)
Computation of gamma(z) for all z.
Definition TMath.cxx:353