laura is hosted by Hepforge, IPPP Durham
Laura++  v2r2p1
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauGaussPdf.cc
Go to the documentation of this file.
1 
2 // Copyright University of Warwick 2006 - 2013.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 // Authors:
7 // Thomas Latham
8 // John Back
9 // Paul Harrison
10 
15 #include <iostream>
16 #include <vector>
17 using std::cout;
18 using std::cerr;
19 using std::endl;
20 using std::vector;
21 
22 #include "TMath.h"
23 #include "TSystem.h"
24 
25 #include "LauConstants.hh"
26 #include "LauGaussPdf.hh"
27 
29 
30 
31 LauGaussPdf::LauGaussPdf(const TString& theVarName, const vector<LauAbsRValue*>& params, Double_t minAbscissa, Double_t maxAbscissa) :
32  LauAbsPdf(theVarName, params, minAbscissa, maxAbscissa),
33  mean_(0),
34  sigma_(0)
35 {
36  // Constructor for the Gaussian PDF.
37  //
38  // The parameters in params are the mean and the sigma (half the width) of the gaussian.
39  // The last two arguments specify the range in which the PDF is defined, and the PDF
40  // will be normalised w.r.t. these limits.
41 
42  mean_ = this->findParameter("mean");
43  sigma_ = this->findParameter("sigma");
44 
45  if ((this->nParameters() != 2) || (mean_ == 0) || (sigma_ == 0)) {
46  cerr<<"ERROR in LauGaussPdf constructor: LauGaussPdf requires 2 parameters: \"mean\" and \"sigma\"."<<endl;
47  gSystem->Exit(EXIT_FAILURE);
48  }
49 
50  // Cache the normalisation factor
51  this->calcNorm();
52 }
53 
55 {
56  // Destructor
57 }
58 
59 LauGaussPdf::LauGaussPdf(const LauGaussPdf& other) : LauAbsPdf(other.varName(), other.getParameters(), other.getMinAbscissa(), other.getMaxAbscissa())
60 {
61  // Copy constructor
62  this->setRandomFun(other.getRandomFun());
63  this->calcNorm();
64 }
65 
67 {
68  // Check that the given abscissa is within the allowed range
69  if (!this->checkRange(abscissas)) {
70  gSystem->Exit(EXIT_FAILURE);
71  }
72 
73  // Get our abscissa
74  Double_t abscissa = abscissas[0];
75 
76  // Get the up to date parameter values
77  Double_t mean = mean_->value();
78  Double_t sigma = sigma_->value();
79 
80  // Calculate the value of the Gaussian for the given value of the abscissa.
81  Double_t arg = abscissa - mean;
82 
83  Double_t exponent(0.0);
84  if (TMath::Abs(sigma) > 1e-10) {
85  exponent = -0.5*arg*arg/(sigma*sigma);
86  }
87 
88  Double_t value = TMath::Exp(exponent);
89  this->setUnNormPDFVal(value);
90 
91  // if the parameters are floating then we
92  // need to recalculate the normalisation
93  if (!this->cachePDF() && !this->withinNormCalc() && !this->withinGeneration()) {
94  this->calcNorm();
95  }
96 
97 }
98 
100 {
101  // Get the up to date parameter values
102  Double_t mean = mean_->value();
103  Double_t sigma = sigma_->value();
104 
105  // Calculate the normalisation of the gaussian and cache it.
106  Double_t scale = LauConstants::root2*sigma;
107  Double_t norm(0.0);
108 
109  if (TMath::Abs(sigma) > 1e-10) {
110  norm = LauConstants::rootPiBy2*sigma*(TMath::Erf((this->getMaxAbscissa() - mean)/scale) - TMath::Erf((this->getMinAbscissa() - mean)/scale));
111  }
112 
113  this->setNorm(norm);
114 }
115 
116 void LauGaussPdf::calcPDFHeight(const LauKinematics* /*kinematics*/)
117 {
118  if (this->heightUpToDate()) {
119  return;
120  }
121 
122  // Get the up to date parameter values
123  Double_t mean = mean_->value();
124 
125  LauAbscissas maxPoint(1);
126  maxPoint[0] = mean;
127 
128  // Calculate the PDF height for the Gaussian function.
129  if (mean>this->getMaxAbscissa()) {
130  maxPoint[0] = this->getMaxAbscissa();
131  } else if (mean<this->getMinAbscissa()) {
132  maxPoint[0] = this->getMinAbscissa();
133  }
134  this->calcLikelihoodInfo(maxPoint);
135 
136  Double_t height = this->getUnNormLikelihood();
137  this->setMaxHeight(height);
138 }
139 
virtual void setUnNormPDFVal(Double_t unNormPDFVal)
Set the unnormalised likelihood.
Definition: LauAbsPdf.hh:369
virtual Double_t getMinAbscissa() const
Retrieve the minimum value of the (primary) abscissa.
Definition: LauAbsPdf.hh:117
Class for defining a Gaussian PDF.
Definition: LauGaussPdf.hh:33
virtual void calcNorm()
Calculate the normalisation.
Definition: LauGaussPdf.cc:99
virtual Bool_t heightUpToDate() const
Check if the maximum height of the PDF is up to date.
Definition: LauAbsPdf.hh:264
ClassImp(LauAbsCoeffSet)
virtual void calcPDFHeight(const LauKinematics *kinematics)
Calculate the PDF height.
Definition: LauGaussPdf.cc:116
virtual Double_t getUnNormLikelihood() const
Retrieve the unnormalised likelihood value.
Definition: LauAbsPdf.hh:196
virtual void setNorm(Double_t norm)
Set the normalisation factor.
Definition: LauAbsPdf.hh:325
virtual Bool_t checkRange(const LauAbscissas &abscissas) const
Check that all abscissas are within their allowed ranges.
Definition: LauAbsPdf.cc:213
virtual Bool_t withinNormCalc() const
Check whether the calcNorm method is running.
Definition: LauAbsPdf.hh:423
virtual TRandom * getRandomFun() const
Retrieve the random function used for MC generation.
Definition: LauAbsPdf.hh:387
const Double_t rootPiBy2
Square root of Pi divided by two.
virtual void calcLikelihoodInfo(const LauAbscissas &abscissas)
Calculate the likelihood (and intermediate info) for a given abscissa.
Definition: LauGaussPdf.cc:66
const Double_t root2
Square root of two.
virtual Double_t getMaxAbscissa() const
Retrieve the maximum value of the (primary) abscissa.
Definition: LauAbsPdf.hh:123
virtual void setMaxHeight(Double_t maxHeight)
Set the maximum height.
Definition: LauAbsPdf.hh:331
LauGaussPdf(const TString &theVarName, const std::vector< LauAbsRValue * > &params, Double_t minAbscissa, Double_t maxAbscissa)
Constructor.
virtual Bool_t withinGeneration() const
Check whether the generate method is running.
Definition: LauAbsPdf.hh:435
File containing declaration of LauGaussPdf class.
virtual Bool_t cachePDF() const
Check if the PDF is to be cached.
Definition: LauAbsPdf.hh:276
File containing LauConstants namespace.
Class for defining the abstract interface for PDF classes.
Definition: LauAbsPdf.hh:41
Class for calculating 3-body kinematic quantities.
Double_t value() const
The value of the parameter.
virtual void setRandomFun(TRandom *randomFun)
Set the random function used for toy MC generation.
Definition: LauAbsPdf.hh:233
virtual ~LauGaussPdf()
Destructor.
Definition: LauGaussPdf.cc:54
Pure abstract base class for defining a parameter containing an R value.
Definition: LauAbsRValue.hh:29
std::vector< Double_t > LauAbscissas
The type used for containing multiple abscissa values.
Definition: LauAbsPdf.hh:45