ROOT  6.06/09
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 //////////////////////////////////////////////////////////////////////////////
12 //
13 // BEGIN_HTML
14 // RooFit 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 parametrization
17 //
18 // Lognormal(x,m0,k) = 1/(sqrt(2*pi)*ln(k)*x)*exp(-ln^2(x/m0)/(2*ln^2(k)))
19 //
20 // The parametrization here is physics driven and differs from the ROOT::Math::lognormal_pdf(x,m,s,x0) with:
21 // - m = log(m0)
22 // - s = log(k)
23 // - x0 = 0
24 // END_HTML
25 
26 
27 #include "RooFit.h"
28 
29 #include "Riostream.h"
30 #include "Riostream.h"
31 #include <math.h>
32 
33 #include "RooLognormal.h"
34 #include "RooAbsReal.h"
35 #include "RooRealVar.h"
36 #include "RooRandom.h"
37 #include "RooMath.h"
38 #include "TMath.h"
39 
40 #include <Math/SpecFuncMathCore.h>
41 #include <Math/PdfFuncMathCore.h>
42 #include <Math/ProbFuncMathCore.h>
43 
44 #include "TError.h"
45 
46 using namespace std;
47 
49 
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 
53 RooLognormal::RooLognormal(const char *name, const char *title,
54  RooAbsReal& _x, RooAbsReal& _m0,
55  RooAbsReal& _k) :
56  RooAbsPdf(name,title),
57  x("x","Observable",this,_x),
58  m0("m0","m0",this,_m0),
59  k("k","k",this,_k)
60 {
61 }
62 
63 
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 
67 RooLognormal::RooLognormal(const RooLognormal& other, const char* name) :
68  RooAbsPdf(other,name), x("x",this,other.x), m0("m0",this,other.m0),
69  k("k",this,other.k)
70 {
71 }
72 
73 
74 
75 ////////////////////////////////////////////////////////////////////////////////
76 /// ln(k)<1 would correspond to sigma < 0 in the parametrization
77 /// resulting by transforming a normal random variable in its
78 /// standard parametrization to a lognormal random variable
79 /// => treat ln(k) as -ln(k) for k<1
80 
82 {
83  Double_t xv = x;
85  Double_t ln_m0 = TMath::Log(m0);
86  Double_t x0 = 0;
87 
88  Double_t ret = ROOT::Math::lognormal_pdf(xv,ln_m0,ln_k,x0);
89  return ret ;
90 }
91 
92 
93 
94 ////////////////////////////////////////////////////////////////////////////////
95 
96 Int_t RooLognormal::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const
97 {
98  if (matchArgs(allVars,analVars,x)) return 1 ;
99  return 0 ;
100 }
101 
102 
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 
106 Double_t RooLognormal::analyticalIntegral(Int_t code, const char* rangeName) const
107 {
108  R__ASSERT(code==1) ;
109 
110  static const Double_t root2 = sqrt(2.) ;
111 
112  Double_t ln_k = TMath::Abs(TMath::Log(k));
113  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) ) ) ;
114 
115  return ret ;
116 }
117 
118 
119 
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 
123 Int_t RooLognormal::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t /*staticInitOK*/) const
124 {
125  if (matchArgs(directVars,generateVars,x)) return 1 ;
126  return 0 ;
127 }
128 
129 
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 
134 {
135  R__ASSERT(code==1) ;
136 
137  Double_t xgen ;
138  while(1) {
140  if (xgen<=x.max() && xgen>=x.min()) {
141  x = xgen ;
142  break;
143  }
144  }
145 
146  return;
147 }
148 
149 
double lognormal_pdf(double x, double m, double s, double x0=0)
Probability density function of the lognormal distribution.
Double_t Log(Double_t x)
Definition: TMath.h:526
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported...
void generateEvent(Int_t code)
Interface for generation of anan event using the algorithm corresponding to the specified code...
#define R__ASSERT(e)
Definition: TError.h:98
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
RooRealProxy k
Definition: RooLognormal.h:38
STL namespace.
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
double sqrt(double)
Double_t x[n]
Definition: legend1.C:17
Double_t analyticalIntegral(Int_t code, const char *rangeName=0) const
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral. ...
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition: RooRandom.cxx:53
RooRealProxy x
Definition: RooLognormal.h:36
ClassImp(RooLognormal) RooLognormal
Double_t Gaus(Double_t x, Double_t mean=0, Double_t sigma=1, Bool_t norm=kFALSE)
Calculate a gaussian function with mean and sigma.
Definition: TMath.cxx:453
Double_t evaluate() const
ln(k)<1 would correspond to sigma < 0 in the parametrization resulting by transforming a normal rando...
RooRealProxy m0
Definition: RooLognormal.h:37
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...
Double_t Exp(Double_t x)
Definition: TMath.h:495
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
#define name(a, b)
Definition: linkTestLib0.cpp:5
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
Double_t min(const char *rname=0) const
Definition: RooRealProxy.h:56
static std::complex< double > erf(const std::complex< double > z)
complex erf function
Definition: RooMath.cxx:584
Bool_t matchArgs(const RooArgSet &allDeps, RooArgSet &numDeps, const RooArgProxy &a) const
Utility function for use in getAnalyticalIntegral().
Double_t max(const char *rname=0) const
Definition: RooRealProxy.h:57