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 oocoutE(this, InputArguments) << "The parameter '" << par->GetName() << "' with range [" << par->getMin("") << ", "
55 << par->getMax() << "] of the " << this->IsA()->GetName() << " '" << 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{
77 Double_t ln_m0 = TMath::Log(m0);
78
79 Double_t ret = ROOT::Math::lognormal_pdf(x,ln_m0,ln_k);
80 return ret ;
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Compute multiple values of Lognormal distribution.
86 return RooBatchCompute::dispatch->computeLognormal(this, evalData, x->getValues(evalData, normSet), m0->getValues(evalData, normSet), k->getValues(evalData, normSet));
87}
88
89////////////////////////////////////////////////////////////////////////////////
90
91Int_t RooLognormal::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const
92{
93 if (matchArgs(allVars,analVars,x)) return 1 ;
94 return 0 ;
95}
96
97////////////////////////////////////////////////////////////////////////////////
98
99Double_t RooLognormal::analyticalIntegral(Int_t code, const char* rangeName) const
100{
101 R__ASSERT(code==1) ;
102
103 static const Double_t root2 = sqrt(2.) ;
104
106 Double_t 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) ) ) ;
107
108 return ret ;
109}
110
111////////////////////////////////////////////////////////////////////////////////
112
113Int_t RooLognormal::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t /*staticInitOK*/) const
114{
115 if (matchArgs(directVars,generateVars,x)) return 1 ;
116 return 0 ;
117}
118
119////////////////////////////////////////////////////////////////////////////////
120
122{
123 R__ASSERT(code==1) ;
124
125 Double_t xgen ;
126 while(1) {
128 if (xgen<=x.max() && xgen>=x.min()) {
129 x = xgen ;
130 break;
131 }
132 }
133
134 return;
135}
#define oocoutE(o, a)
Definition: RooMsgService.h:48
int Int_t
Definition: RtypesCore.h:45
bool Bool_t
Definition: RtypesCore.h:63
double Double_t
Definition: RtypesCore.h:59
#define ClassImp(name)
Definition: Rtypes.h:364
#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:61
virtual RooSpan< const double > getValues(RooBatchCompute::RunContext &evalData, const RooArgSet *normSet=nullptr) const
by this change, please consult the release notes for ROOT 6.24 for guidance on how to make this trans...
Definition: RooAbsReal.cxx:311
Bool_t 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:35
virtual RooSpan< double > computeLognormal(const RooAbsReal *, RunContext &, RooSpan< const double > x, RooSpan< const double > m0, RooSpan< const double > k)=0
RooFit Lognormal PDF.
Definition: RooLognormal.h:19
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, Bool_t staticInitOK=kTRUE) const
Load generatedVars with the subset of directVars that we can generate events for, and return a code t...
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
RooRealProxy k
Definition: RooLognormal.h:38
Double_t evaluate() const
ln(k)<1 would correspond to sigma < 0 in the parameterization resulting by transforming a normal rand...
void generateEvent(Int_t code)
Interface for generation of an event using the algorithm corresponding to the specified code.
RooRealProxy x
Definition: RooLognormal.h:36
RooRealProxy m0
Definition: RooLognormal.h:37
RooSpan< double > evaluateSpan(RooBatchCompute::RunContext &evalData, const RooArgSet *normSet) const
Compute multiple values of Lognormal distribution.
Double_t analyticalIntegral(Int_t code, const char *rangeName=0) const
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:580
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition: RooRandom.cxx:53
A simple container to hold a batch of data values.
Definition: RooSpan.h:34
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.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
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 * dispatch
This dispatch pointer points to an implementation of the compute library, provided one has been loade...
@ InputArguments
Definition: RooGlobalFunc.h:61
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:118
Double_t Exp(Double_t x)
Definition: TMath.h:677
Double_t Log(Double_t x)
Definition: TMath.h:710
Short_t Abs(Short_t d)
Definition: TMathBase.h:120
This struct enables passing computation data around between elements of a computation graph.
Definition: RunContext.h:31