ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 \file RooLognormal.cxx
13 \class RooLognormal
14 \ingroup Roofit
15 
16 RooFit Lognormal PDF. The two parameters are:
17  - m0: the median of the distribution
18  - k=exp(sigma): sigma is called the shape parameter in the TMath parametrization
19 
20 \f[ Lognormal(x,m_0,k) = \frac{e^{(-ln^2(x/m_0))/(2ln^2(k))}}{\sqrt{2\pi \cdot ln(k)\cdot x}} \f]
21 
22 The parametrization here is physics driven and differs from the ROOT::Math::lognormal_pdf(x,m,s,x0) with:
23  - m = log(m0)
24  - s = log(k)
25  - x0 = 0
26 **/
27 
28 #include "RooFit.h"
29 
30 #include "Riostream.h"
31 #include "Riostream.h"
32 #include <math.h>
33 
34 #include "RooLognormal.h"
35 #include "RooAbsReal.h"
36 #include "RooRealVar.h"
37 #include "RooRandom.h"
38 #include "RooMath.h"
39 #include "TMath.h"
40 
41 #include <Math/SpecFuncMathCore.h>
42 #include <Math/PdfFuncMathCore.h>
43 #include <Math/ProbFuncMathCore.h>
44 
45 #include "TError.h"
46 
47 using namespace std;
48 
50 
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 
54 RooLognormal::RooLognormal(const char *name, const char *title,
55  RooAbsReal& _x, RooAbsReal& _m0,
56  RooAbsReal& _k) :
57  RooAbsPdf(name,title),
58  x("x","Observable",this,_x),
59  m0("m0","m0",this,_m0),
60  k("k","k",this,_k)
61 {
62 }
63 
64 
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 
68 RooLognormal::RooLognormal(const RooLognormal& other, const char* name) :
69  RooAbsPdf(other,name), x("x",this,other.x), m0("m0",this,other.m0),
70  k("k",this,other.k)
71 {
72 }
73 
74 
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 /// ln(k)<1 would correspond to sigma < 0 in the parametrization
78 /// resulting by transforming a normal random variable in its
79 /// standard parametrization to a lognormal random variable
80 /// => treat ln(k) as -ln(k) for k<1
81 
83 {
84  Double_t xv = x;
86  Double_t ln_m0 = TMath::Log(m0);
87  Double_t x0 = 0;
88 
89  Double_t ret = ROOT::Math::lognormal_pdf(xv,ln_m0,ln_k,x0);
90  return ret ;
91 }
92 
93 
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 
97 Int_t RooLognormal::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const
98 {
99  if (matchArgs(allVars,analVars,x)) return 1 ;
100  return 0 ;
101 }
102 
103 
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 
107 Double_t RooLognormal::analyticalIntegral(Int_t code, const char* rangeName) const
108 {
109  R__ASSERT(code==1) ;
110 
111  static const Double_t root2 = sqrt(2.) ;
112 
113  Double_t ln_k = TMath::Abs(TMath::Log(k));
114  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) ) ) ;
115 
116  return ret ;
117 }
118 
119 
120 
121 
122 ////////////////////////////////////////////////////////////////////////////////
123 
124 Int_t RooLognormal::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t /*staticInitOK*/) const
125 {
126  if (matchArgs(directVars,generateVars,x)) return 1 ;
127  return 0 ;
128 }
129 
130 
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 
135 {
136  R__ASSERT(code==1) ;
137 
138  Double_t xgen ;
139  while(1) {
141  if (xgen<=x.max() && xgen>=x.min()) {
142  x = xgen ;
143  break;
144  }
145  }
146 
147  return;
148 }
149 
150 
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
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:54
RooRealProxy x
Definition: RooLognormal.h:36
ClassImp(RooLognormal) RooLognormal
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
RooFit Lognormal PDF.
Definition: RooLognormal.h:19
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