Logo ROOT  
Reference Guide
RooLognormal.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2 * Project: RooFit *
3 * @(#)root/roofit:$Id$ *
4 * *
5 * RooFit Lognormal PDF *
6 * *
7 * Author: Gregory Schott and Stefan Schmitz *
8 * *
9 *****************************************************************************/
10
11/** \class RooLognormal
12 \ingroup Roofit
13
14RooFit Lognormal PDF. The two parameters are:
15 - `m0`: the median of the distribution
16 - `k = exp(sigma)`: sigma is called the shape parameter in the TMath parameterization
17
18\f[
19 \mathrm{RooLognormal}(x \, | \, m_0, k) = \frac{1}{\sqrt{2\pi \cdot \ln(k) \cdot x}} \cdot \exp\left( \frac{-\ln^2(\frac{x}{m_0})}{2 \ln^2(k)} \right)
20\f]
21
22The parameterization here is physics driven and differs from the ROOT::Math::lognormal_pdf() in `x,m,s,x0` with:
23 - `m = log(m0)`
24 - `s = log(k)`
25 - `x0 = 0`
26**/
27
28#include "RooLognormal.h"
29#include "RooRandom.h"
30#include "RooMath.h"
31#include "RooHelpers.h"
32#include "RooBatchCompute.h"
33
34#include "TClass.h"
35
37
39
40////////////////////////////////////////////////////////////////////////////////
41
42RooLognormal::RooLognormal(const char *name, const char *title,
43 RooAbsReal& _x, RooAbsReal& _m0,
44 RooAbsReal& _k) :
45 RooAbsPdf(name,title),
46 x("x","Observable",this,_x),
47 m0("m0","m0",this,_m0),
48 k("k","k",this,_k)
49{
50 RooHelpers::checkRangeOfParameters(this, {&_x, &_m0, &_k}, 0.);
51
52 auto par = dynamic_cast<const RooAbsRealLValue*>(&_k);
53 if (par && par->getMin()<=1 && par->getMax()>=1 ) {
54 coutE(InputArguments) << "The parameter '" << par->GetName() << "' with range [" << par->getMin("") << ", "
55 << par->getMax() << "] of the " << this->ClassName() << " '" << this->GetName()
56 << "' can reach the unsafe value 1.0 " << ". Advise to limit its range." << std::endl;
57 }
58}
59
60////////////////////////////////////////////////////////////////////////////////
61
62RooLognormal::RooLognormal(const RooLognormal& other, const char* name) :
63 RooAbsPdf(other,name), x("x",this,other.x), m0("m0",this,other.m0),
64 k("k",this,other.k)
65{
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// ln(k)<1 would correspond to sigma < 0 in the parameterization
70/// resulting by transforming a normal random variable in its
71/// standard parameterization to a lognormal random variable
72/// => treat ln(k) as -ln(k) for k<1
73
75{
76 double ln_k = TMath::Abs(TMath::Log(k));
77 double ln_m0 = TMath::Log(m0);
78
79 double ret = ROOT::Math::lognormal_pdf(x,ln_m0,ln_k);
80 return ret ;
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Compute multiple values of Lognormal distribution.
85void RooLognormal::computeBatch(cudaStream_t* stream, double* output, size_t nEvents, RooFit::Detail::DataMap const& dataMap) const
86{
88 dispatch->compute(stream, RooBatchCompute::Lognormal, output, nEvents,
89 {dataMap.at(x), dataMap.at(m0), dataMap.at(k)});
90}
91
92////////////////////////////////////////////////////////////////////////////////
93
94Int_t RooLognormal::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const
95{
96 if (matchArgs(allVars,analVars,x)) return 1 ;
97 return 0 ;
98}
99
100////////////////////////////////////////////////////////////////////////////////
101
102double RooLognormal::analyticalIntegral(Int_t code, const char* rangeName) const
103{
104 R__ASSERT(code==1) ;
105
106 static const double root2 = sqrt(2.) ;
107
108 double ln_k = TMath::Abs(TMath::Log(k));
109 double ret = 0.5*( RooMath::erf( TMath::Log(x.max(rangeName)/m0)/(root2*ln_k) ) - RooMath::erf( TMath::Log(x.min(rangeName)/m0)/(root2*ln_k) ) ) ;
110
111 return ret ;
112}
113
114////////////////////////////////////////////////////////////////////////////////
115
116Int_t RooLognormal::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, bool /*staticInitOK*/) const
117{
118 if (matchArgs(directVars,generateVars,x)) return 1 ;
119 return 0 ;
120}
121
122////////////////////////////////////////////////////////////////////////////////
123
125{
126 R__ASSERT(code==1) ;
127
128 double xgen ;
129 while(1) {
131 if (xgen<=x.max() && xgen>=x.min()) {
132 x = xgen ;
133 break;
134 }
135 }
136
137 return;
138}
#define coutE(a)
Definition: RooMsgService.h:37
#define ClassImp(name)
Definition: Rtypes.h:375
#define R__ASSERT(e)
Definition: TError.h:118
char name[80]
Definition: TGX11.cxx:110
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:64
bool matchArgs(const RooArgSet &allDeps, RooArgSet &numDeps, const RooArgProxy &a) const
Utility function for use in getAnalyticalIntegral().
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:57
virtual void compute(cudaStream_t *, Computer, RestrictArr, size_t, const VarVector &, const ArgVector &={})=0
auto & at(RooAbsArg const *arg, RooAbsArg const *=nullptr)
Definition: DataMap.h:88
RooFit Lognormal PDF.
Definition: RooLognormal.h:19
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const override
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, bool staticInitOK=true) const override
Load generatedVars with the subset of directVars that we can generate events for, and return a code t...
RooRealProxy k
Definition: RooLognormal.h:38
void generateEvent(Int_t code) override
Interface for generation of an event using the algorithm corresponding to the specified code.
void computeBatch(cudaStream_t *, double *output, size_t nEvents, RooFit::Detail::DataMap const &) const override
Compute multiple values of Lognormal distribution.
RooRealProxy x
Definition: RooLognormal.h:36
RooRealProxy m0
Definition: RooLognormal.h:37
double evaluate() const override
ln(k)<1 would correspond to sigma < 0 in the parameterization resulting by transforming a normal rand...
double analyticalIntegral(Int_t code, const char *rangeName=0) const override
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
static std::complex< double > erf(const std::complex< double > z)
complex erf function
Definition: RooMath.cxx:60
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition: RooRandom.cxx:51
double min(const char *rname=0) const
Query lower limit of range. This requires the payload to be RooAbsRealLValue or derived.
double max(const char *rname=0) const
Query upper limit of range. This requires the payload to be RooAbsRealLValue or derived.
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:130
double lognormal_pdf(double x, double m, double s, double x0=0)
Probability density function of the lognormal distribution.
Double_t x[n]
Definition: legend1.C:17
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
Double_t Gaus(Double_t x, Double_t mean, Double_t sigma)
Gauss.
R__EXTERN RooBatchComputeInterface * dispatchCUDA
R__EXTERN RooBatchComputeInterface * dispatchCPU
This dispatch pointer points to an implementation of the compute library, provided one has been loade...
@ InputArguments
Definition: RooGlobalFunc.h:64
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.
Definition: RooHelpers.cxx:119
Double_t Exp(Double_t x)
Returns the base-e exponential function of x, which is e raised to the power x.
Definition: TMath.h:706
Double_t Log(Double_t x)
Returns the natural logarithm of x.
Definition: TMath.h:753
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition: TMathBase.h:123
static void output()