Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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.
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_t RooLognormal::analyticalIntegral(Int_t code, const char* rangeName) const
103{
104 R__ASSERT(code==1) ;
105
106 static const Double_t root2 = sqrt(2.) ;
107
109 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) ) ) ;
110
111 return ret ;
112}
113
114////////////////////////////////////////////////////////////////////////////////
115
116Int_t RooLognormal::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t /*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_t xgen ;
129 while(1) {
131 if (xgen<=x.max() && xgen>=x.min()) {
132 x = xgen ;
133 break;
134 }
135 }
136
137 return;
138}
#define oocoutE(o, a)
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:64
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 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.
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.
void computeBatch(cudaStream_t *, double *output, size_t nEvents, RooFit::Detail::DataMap const &) const
Compute multiple values of Lognormal distribution.
RooRealProxy k
double 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
RooRealProxy m0
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:60
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition RooRandom.cxx:53
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
R__EXTERN RooBatchComputeInterface * dispatchCUDA
R__EXTERN RooBatchComputeInterface * dispatchCPU
This dispatch pointer points to an implementation of the compute library, provided one has been loade...
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 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
static void output(int code)
Definition gifencode.c:226