laura is hosted by Hepforge, IPPP Durham
Laura++  v3r4
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauGaussPdf.cc
Go to the documentation of this file.
1 
2 /*
3 Copyright 2006 University of Warwick
4 
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 */
17 
18 /*
19 Laura++ package authors:
20 John Back
21 Paul Harrison
22 Thomas Latham
23 */
24 
29 #include <iostream>
30 #include <vector>
31 using std::cout;
32 using std::cerr;
33 using std::endl;
34 using std::vector;
35 
36 #include "TMath.h"
37 #include "TSystem.h"
38 
39 #include "LauConstants.hh"
40 #include "LauGaussPdf.hh"
41 
43 
44 
45 LauGaussPdf::LauGaussPdf(const TString& theVarName, const vector<LauAbsRValue*>& params, Double_t minAbscissa, Double_t maxAbscissa) :
46  LauAbsPdf(theVarName, params, minAbscissa, maxAbscissa),
47  mean_(0),
48  sigma_(0)
49 {
50  // Constructor for the Gaussian PDF.
51  //
52  // The parameters in params are the mean and the sigma (half the width) of the gaussian.
53  // The last two arguments specify the range in which the PDF is defined, and the PDF
54  // will be normalised w.r.t. these limits.
55 
56  mean_ = this->findParameter("mean");
57  sigma_ = this->findParameter("sigma");
58 
59  if ((this->nParameters() != 2) || (mean_ == 0) || (sigma_ == 0)) {
60  cerr<<"ERROR in LauGaussPdf constructor: LauGaussPdf requires 2 parameters: \"mean\" and \"sigma\"."<<endl;
61  gSystem->Exit(EXIT_FAILURE);
62  }
63 
64  // Cache the normalisation factor
65  this->calcNorm();
66 }
67 
69 {
70  // Destructor
71 }
72 
74 {
75  // Check that the given abscissa is within the allowed range
76  if (!this->checkRange(abscissas)) {
77  gSystem->Exit(EXIT_FAILURE);
78  }
79 
80  // Get our abscissa
81  Double_t abscissa = abscissas[0];
82 
83  // Get the up to date parameter values
84  Double_t mean = mean_->unblindValue();
85  Double_t sigma = sigma_->unblindValue();
86 
87  // Calculate the value of the Gaussian for the given value of the abscissa.
88  Double_t arg = abscissa - mean;
89 
90  Double_t exponent(0.0);
91  if (TMath::Abs(sigma) > 1e-10) {
92  exponent = -0.5*arg*arg/(sigma*sigma);
93  }
94 
95  Double_t value = TMath::Exp(exponent);
96  this->setUnNormPDFVal(value);
97 
98  // if the parameters are floating then we
99  // need to recalculate the normalisation
100  if (!this->cachePDF() && !this->withinNormCalc() && !this->withinGeneration()) {
101  this->calcNorm();
102  }
103 
104 }
105 
107 {
108  // Get the up to date parameter values
109  Double_t mean = mean_->unblindValue();
110  Double_t sigma = sigma_->unblindValue();
111 
112  // Calculate the normalisation of the gaussian and cache it.
113  Double_t scale = LauConstants::root2*sigma;
114  Double_t norm(0.0);
115 
116  if (TMath::Abs(sigma) > 1e-10) {
117  norm = LauConstants::rootPiBy2*sigma*(TMath::Erf((this->getMaxAbscissa() - mean)/scale) - TMath::Erf((this->getMinAbscissa() - mean)/scale));
118  }
119 
120  this->setNorm(norm);
121 }
122 
123 void LauGaussPdf::calcPDFHeight(const LauKinematics* /*kinematics*/)
124 {
125  if (this->heightUpToDate()) {
126  return;
127  }
128 
129  // Get the up to date parameter values
130  Double_t mean = mean_->unblindValue();
131 
132  LauAbscissas maxPoint(1);
133  maxPoint[0] = mean;
134 
135  // Calculate the PDF height for the Gaussian function.
136  if (mean>this->getMaxAbscissa()) {
137  maxPoint[0] = this->getMaxAbscissa();
138  } else if (mean<this->getMinAbscissa()) {
139  maxPoint[0] = this->getMinAbscissa();
140  }
141  this->calcLikelihoodInfo(maxPoint);
142 
143  Double_t height = this->getUnNormLikelihood();
144  this->setMaxHeight(height);
145 }
146 
virtual void setUnNormPDFVal(Double_t unNormPDFVal)
Set the unnormalised likelihood.
Definition: LauAbsPdf.hh:383
virtual Double_t getMinAbscissa() const
Retrieve the minimum value of the (primary) abscissa.
Definition: LauAbsPdf.hh:131
Class for defining a Gaussian PDF.
Definition: LauGaussPdf.hh:47
virtual void calcNorm()
Calculate the normalisation.
Definition: LauGaussPdf.cc:106
virtual Bool_t heightUpToDate() const
Check if the maximum height of the PDF is up to date.
Definition: LauAbsPdf.hh:278
ClassImp(LauAbsCoeffSet)
virtual void calcPDFHeight(const LauKinematics *kinematics)
Calculate the PDF height.
Definition: LauGaussPdf.cc:123
virtual Double_t getUnNormLikelihood() const
Retrieve the unnormalised likelihood value.
Definition: LauAbsPdf.hh:210
virtual void setNorm(Double_t norm)
Set the normalisation factor.
Definition: LauAbsPdf.hh:339
virtual Bool_t checkRange(const LauAbscissas &abscissas) const
Check that all abscissas are within their allowed ranges.
Definition: LauAbsPdf.cc:227
virtual Bool_t withinNormCalc() const
Check whether the calcNorm method is running.
Definition: LauAbsPdf.hh:437
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:73
const Double_t root2
Square root of two.
virtual Double_t getMaxAbscissa() const
Retrieve the maximum value of the (primary) abscissa.
Definition: LauAbsPdf.hh:137
virtual void setMaxHeight(Double_t maxHeight)
Set the maximum height.
Definition: LauAbsPdf.hh:345
virtual Bool_t withinGeneration() const
Check whether the generate method is running.
Definition: LauAbsPdf.hh:449
File containing declaration of LauGaussPdf class.
virtual Bool_t cachePDF() const
Check if the PDF is to be cached.
Definition: LauAbsPdf.hh:290
File containing LauConstants namespace.
Class for defining the abstract interface for PDF classes.
Definition: LauAbsPdf.hh:55
Class for calculating 3-body kinematic quantities.
Double_t value() const
The value of the parameter.
virtual ~LauGaussPdf()
Destructor.
Definition: LauGaussPdf.cc:68
Pure abstract base class for defining a parameter containing an R value.
Definition: LauAbsRValue.hh:43
std::vector< Double_t > LauAbscissas
The type used for containing multiple abscissa values.
Definition: LauAbsPdf.hh:59