laura is hosted by Hepforge, IPPP Durham
Laura++  3.6.0
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::cerr;
32 using std::cout;
33 using std::endl;
34 
35 #include "LauConstants.hh"
36 #include "LauGaussPdf.hh"
37 
38 #include "TMath.h"
39 #include "TSystem.h"
40 
41 LauGaussPdf::LauGaussPdf( const TString& theVarName,
42  const std::vector<LauAbsRValue*>& params,
43  Double_t minAbscissa,
44  Double_t maxAbscissa ) :
45  LauAbsPdf( theVarName, params, minAbscissa, maxAbscissa ),
46  mean_( 0 ),
47  sigma_( 0 )
48 {
49  // Constructor for the Gaussian PDF.
50  //
51  // The parameters in params are the mean and the sigma (half the width) of the gaussian.
52  // The last two arguments specify the range in which the PDF is defined, and the PDF
53  // will be normalised w.r.t. these limits.
54 
55  mean_ = this->findParameter( "mean" );
56  sigma_ = this->findParameter( "sigma" );
57 
58  if ( ( this->nParameters() != 2 ) || ( mean_ == 0 ) || ( sigma_ == 0 ) ) {
59  cerr << "ERROR in LauGaussPdf constructor: LauGaussPdf requires 2 parameters: \"mean\" and \"sigma\"."
60  << 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 
106 {
107  // Get the up to date parameter values
108  Double_t mean = mean_->unblindValue();
109  Double_t sigma = sigma_->unblindValue();
110 
111  // Calculate the normalisation of the gaussian and cache it.
112  Double_t scale = LauConstants::root2 * sigma;
113  Double_t norm( 0.0 );
114 
115  if ( TMath::Abs( sigma ) > 1e-10 ) {
116  norm = LauConstants::rootPiBy2 * sigma *
117  ( TMath::Erf( ( this->getMaxAbscissa() - mean ) / scale ) -
118  TMath::Erf( ( this->getMinAbscissa() - mean ) / scale ) );
119  }
120 
121  this->setNorm( norm );
122 }
123 
124 void LauGaussPdf::calcPDFHeight( const LauKinematics* /*kinematics*/ )
125 {
126  if ( this->heightUpToDate() ) {
127  return;
128  }
129 
130  // Get the up to date parameter values
131  Double_t mean = mean_->unblindValue();
132 
133  LauAbscissas maxPoint( 1 );
134  maxPoint[0] = mean;
135 
136  // Calculate the PDF height for the Gaussian function.
137  if ( mean > this->getMaxAbscissa() ) {
138  maxPoint[0] = this->getMaxAbscissa();
139  } else if ( mean < this->getMinAbscissa() ) {
140  maxPoint[0] = this->getMinAbscissa();
141  }
142  this->calcLikelihoodInfo( maxPoint );
143 
144  Double_t height = this->getUnNormLikelihood();
145  this->setMaxHeight( height );
146 }
virtual void calcPDFHeight(const LauKinematics *kinematics)
Calculate the PDF height.
Definition: LauGaussPdf.cc:124
LauAbsRValue * mean_
Gaussian mean.
Definition: LauGaussPdf.hh:91
LauAbsRValue * sigma_
Gaussian sigma.
Definition: LauGaussPdf.hh:93
virtual Double_t getMaxAbscissa() const
Retrieve the maximum value of the (primary) abscissa.
Definition: LauAbsPdf.hh:141
Double_t value() const
The value of the parameter.
virtual Double_t getMinAbscissa() const
Retrieve the minimum value of the (primary) abscissa.
Definition: LauAbsPdf.hh:135
virtual ~LauGaussPdf()
Destructor.
Definition: LauGaussPdf.cc:68
virtual Bool_t cachePDF() const
Check if the PDF is to be cached.
Definition: LauAbsPdf.hh:299
std::vector< Double_t > LauAbscissas
The type used for containing multiple abscissa values.
Definition: LauAbsPdf.hh:58
virtual void calcNorm()
Calculate the normalisation.
Definition: LauGaussPdf.cc:105
virtual void calcLikelihoodInfo(const LauAbscissas &abscissas)
Calculate the likelihood (and intermediate info) for a given abscissa.
Definition: LauGaussPdf.cc:73
virtual LauAbsRValue * findParameter(const TString &parName)
Retrieve the specified parameter.
Definition: LauAbsPdf.cc:431
const Double_t root2
Square root of two.
virtual Bool_t withinNormCalc() const
Check whether the calcNorm method is running.
Definition: LauAbsPdf.hh:448
virtual UInt_t nParameters() const
Retrieve the number of PDF parameters.
Definition: LauAbsPdf.hh:109
virtual void setNorm(Double_t norm)
Set the normalisation factor.
Definition: LauAbsPdf.hh:348
virtual Double_t unblindValue() const =0
The unblinded value of the parameter.
virtual void setUnNormPDFVal(Double_t unNormPDFVal)
Set the unnormalised likelihood.
Definition: LauAbsPdf.hh:394
Class for defining the abstract interface for PDF classes.
Definition: LauAbsPdf.hh:54
virtual Bool_t withinGeneration() const
Check whether the generate method is running.
Definition: LauAbsPdf.hh:460
File containing LauConstants namespace.
virtual void setMaxHeight(Double_t maxHeight)
Set the maximum height.
Definition: LauAbsPdf.hh:354
LauGaussPdf(const TString &theVarName, const std::vector< LauAbsRValue * > &params, Double_t minAbscissa, Double_t maxAbscissa)
Constructor.
Definition: LauGaussPdf.cc:41
Class for calculating 3-body kinematic quantities.
const Double_t rootPiBy2
Square root of Pi divided by two.
File containing declaration of LauGaussPdf class.
virtual Double_t getUnNormLikelihood() const
Retrieve the unnormalised likelihood value.
Definition: LauAbsPdf.hh:218
virtual Bool_t heightUpToDate() const
Check if the maximum height of the PDF is up to date.
Definition: LauAbsPdf.hh:287
virtual Bool_t checkRange(const LauAbscissas &abscissas) const
Check that all abscissas are within their allowed ranges.
Definition: LauAbsPdf.cc:243