Skip to content

Commit ea6f381

Browse files
committed
[RF] Add RooStudent location-scale student's t-distribution
Fixes #21284 Original idea from Kirill Ivanov
1 parent 550e363 commit ea6f381

File tree

5 files changed

+123
-0
lines changed

5 files changed

+123
-0
lines changed

README/ReleaseNotes/v640/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ As part of this migration, the following build options are deprecated. From ROOT
192192

193193
## RooFit
194194

195+
- A new RooAbsPdf has been added: `RooStudentT`, which describes the location-scale student's t-distribution.
196+
195197
## RDataFrame
196198

197199
- The message shown in ROOT 6.38 to inform users about change of default compression setting used by Snapshot (was 101 before 6.38, became 505 in 6.38) is now removed.

roofit/roofit/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RooFit
7070
RooPyBind.h
7171
RooSpline.h
7272
RooStepFunction.h
73+
RooStudentT.h
7374
RooTFnBinding.h
7475
RooTFnPdfBinding.h
7576
RooTMathReg.h
@@ -134,6 +135,7 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RooFit
134135
src/RooPolynomial.cxx
135136
src/RooSpline.cxx
136137
src/RooStepFunction.cxx
138+
src/RooStudentT.cxx
137139
src/RooTFnBinding.cxx
138140
src/RooTFnPdfBinding.cxx
139141
src/RooTMathReg.cxx

roofit/roofit/inc/LinkDef1.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#pragma link C++ class RooPowerSum+ ;
2525
#pragma link C++ class RooGaussExpTails+ ;
2626
#pragma link C++ class RooGaussian+ ;
27+
#pragma link C++ class RooStudentT+ ;
2728
#pragma link C++ class RooLognormal+ ;
2829
#pragma link C++ class RooGamma+ ;
2930
#pragma link C++ class RooGaussModel+ ;

roofit/roofit/inc/RooStudentT.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#ifndef RooFit_RooFit_RooStudentT_h
2+
#define RooFit_RooFit_RooStudentT_h
3+
4+
#include "RooAbsPdf.h"
5+
#include "RooRealProxy.h"
6+
7+
class RooAbsReal;
8+
9+
class RooStudentT : public RooAbsPdf {
10+
public:
11+
RooStudentT() {};
12+
RooStudentT(const char *name, const char *title, RooAbsReal::Ref x, RooAbsReal::Ref mean, RooAbsReal::Ref sigma,
13+
RooAbsReal::Ref ndf);
14+
RooStudentT(const RooStudentT &other, const char *name = nullptr);
15+
TObject *clone(const char *newname = nullptr) const override { return new RooStudentT(*this, newname); }
16+
17+
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName = nullptr) const override;
18+
double analyticalIntegral(Int_t code, const char *rangeName = nullptr) const override;
19+
20+
/// Get the _x variable.
21+
RooAbsReal const &x() const { return _x.arg(); }
22+
23+
/// Get the _mean parameter.
24+
RooAbsReal const &mean() const { return _mean.arg(); }
25+
26+
/// Get the standard deviation parameter.
27+
RooAbsReal const &sigma() const { return _sigma.arg(); }
28+
29+
/// Get the degrees of freedom parameter.
30+
RooAbsReal const &ndf() const { return _ndf.arg(); }
31+
32+
Int_t getMaxVal(const RooArgSet &vars) const override;
33+
double maxVal(Int_t code) const override;
34+
35+
protected:
36+
double evaluate() const override;
37+
38+
private:
39+
RooRealProxy _x; ///< variable
40+
RooRealProxy _mean; ///< mean
41+
RooRealProxy _sigma; ///< standard deviation
42+
RooRealProxy _ndf; ///< degrees of freedom
43+
44+
ClassDefOverride(RooStudentT, 1) // Location-scale Student's t-distribution PDF
45+
};
46+
47+
#endif

roofit/roofit/src/RooStudentT.cxx

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* \class RooStudentT
3+
* \ingroup Roofit
4+
*
5+
* Location-scale Student's t-distribution
6+
* \see https://en.wikipedia.org/wiki/Student's_t-distribution#Location-scale_t-distribution
7+
*/
8+
9+
#include "RooStudentT.h"
10+
#include "RooHelpers.h"
11+
12+
#include "TMath.h"
13+
14+
RooStudentT::RooStudentT(const char *name, const char *title, RooAbsReal::Ref x, RooAbsReal::Ref mean,
15+
RooAbsReal::Ref sigma, RooAbsReal::Ref ndf)
16+
: RooAbsPdf(name, title),
17+
_x("x", "Observable", this, x),
18+
_mean("mean", "Mean", this, mean),
19+
_sigma("sigma", "Width", this, sigma),
20+
_ndf("ndf", " Degrees of freedom", this, ndf)
21+
{
22+
RooHelpers::checkRangeOfParameters(this, {&static_cast<RooAbsReal &>(sigma)}, 0);
23+
RooHelpers::checkRangeOfParameters(this, {&static_cast<RooAbsReal &>(ndf)}, 1);
24+
}
25+
26+
RooStudentT::RooStudentT(const RooStudentT &other, const char *name)
27+
: RooAbsPdf(other, name),
28+
_x("x", this, other._x),
29+
_mean("mean", this, other._mean),
30+
_sigma("sigma", this, other._sigma),
31+
_ndf("ndf", this, other._ndf)
32+
{
33+
}
34+
35+
double RooStudentT::evaluate() const
36+
{
37+
const double t = (_x - _mean) / _sigma;
38+
return TMath::Student(t, _ndf);
39+
}
40+
41+
Int_t RooStudentT::getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char * /*rangeName*/) const
42+
{
43+
return matchArgs(allVars, analVars, _x) ? 1 : 0;
44+
}
45+
46+
double RooStudentT::analyticalIntegral(Int_t code, const char *rangeName) const
47+
{
48+
R__ASSERT(code == 1);
49+
50+
double tmin = (_x.min(rangeName) - _mean) / _sigma;
51+
double tmax = (_x.max(rangeName) - _mean) / _sigma;
52+
return (TMath::StudentI(tmax, _ndf) - TMath::StudentI(tmin, _ndf)) * _sigma;
53+
}
54+
55+
/// Advertise that we know the maximum of self for given (mean,ndf,sigma).
56+
Int_t RooStudentT::getMaxVal(const RooArgSet &vars) const
57+
{
58+
RooArgSet dummy;
59+
60+
if (matchArgs(vars, dummy, _x)) {
61+
return 1;
62+
}
63+
return 0;
64+
}
65+
66+
double RooStudentT::maxVal(Int_t code) const
67+
{
68+
R__ASSERT(code == 1);
69+
70+
return TMath::Student(0, _ndf);
71+
}

0 commit comments

Comments
 (0)