laura is hosted by Hepforge, IPPP Durham
Laura++  v3r0p1
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 
60 {
61  // Check that the given abscissa is within the allowed range
62  if (!this->checkRange(abscissas)) {
63  gSystem->Exit(EXIT_FAILURE);
64  }
65 
66  // Get our abscissa
67  Double_t abscissa = abscissas[0];
68 
69  // Get the up to date parameter values
70  Double_t mean = mean_->value();
71  Double_t sigma = sigma_->value();
72 
73  // Calculate the value of the Gaussian for the given value of the abscissa.
74  Double_t arg = abscissa - mean;
75 
76  Double_t exponent(0.0);
77  if (TMath::Abs(sigma) > 1e-10) {
78  exponent = -0.5*arg*arg/(sigma*sigma);
79  }
80 
81  Double_t value = TMath::Exp(exponent);
82  this->setUnNormPDFVal(value);
83 
84  // if the parameters are floating then we
85  // need to recalculate the normalisation
86  if (!this->cachePDF() && !this->withinNormCalc() && !this->withinGeneration()) {
87  this->calcNorm();
88  }
89 
90 }
91 
93 {
94  // Get the up to date parameter values
95  Double_t mean = mean_->value();
96  Double_t sigma = sigma_->value();
97 
98  // Calculate the normalisation of the gaussian and cache it.
99  Double_t scale = LauConstants::root2*sigma;
100  Double_t norm(0.0);
101 
102  if (TMath::Abs(sigma) > 1e-10) {
103  norm = LauConstants::rootPiBy2*sigma*(TMath::Erf((this->getMaxAbscissa() - mean)/scale) - TMath::Erf((this->getMinAbscissa() - mean)/scale));
104  }
105 
106  this->setNorm(norm);
107 }
108 
109 void LauGaussPdf::calcPDFHeight(const LauKinematics* /*kinematics*/)
110 {
111  if (this->heightUpToDate()) {
112  return;
113  }
114 
115  // Get the up to date parameter values
116  Double_t mean = mean_->value();
117 
118  LauAbscissas maxPoint(1);
119  maxPoint[0] = mean;
120 
121  // Calculate the PDF height for the Gaussian function.
122  if (mean>this->getMaxAbscissa()) {
123  maxPoint[0] = this->getMaxAbscissa();
124  } else if (mean<this->getMinAbscissa()) {
125  maxPoint[0] = this->getMinAbscissa();
126  }
127  this->calcLikelihoodInfo(maxPoint);
128 
129  Double_t height = this->getUnNormLikelihood();
130  this->setMaxHeight(height);
131 }
132 
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:92
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:109
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
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:59
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
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 ~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