|
| 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