laura is hosted by Hepforge, IPPP Durham
Laura++  v2r1p1
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauExponentialPdf.cc
Go to the documentation of this file.
1 
2 // Copyright University of Warwick 2011 - 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 "LauExponentialPdf.hh"
27 
29 
30 
31 LauExponentialPdf::LauExponentialPdf(const TString& theVarName, const vector<LauAbsRValue*>& params, Double_t minAbscissa, Double_t maxAbscissa) :
32  LauAbsPdf(theVarName, params, minAbscissa, maxAbscissa),
33  slope_(0)
34 {
35  // Constructor for the Exponential PDF.
36  //
37  // The parameter in param is the slope of the exponential ie exp(slope*x).
38  // The last two arguments specify the range in which the PDF is defined, and the PDF
39  // will be normalised w.r.t. these limits.
40 
41  slope_ = this->findParameter("slope");
42 
43  if ((this->nParameters() != 1) || (slope_ == 0)) {
44  cerr<<"ERROR in LauExponentialPdf constructor: LauExponentialPdf requires 1 parameter: \"slope\"."<<endl;
45  gSystem->Exit(EXIT_FAILURE);
46  }
47 
48  // Cache the normalisation factor
49  this->calcNorm();
50 }
51 
53 {
54  // Destructor
55 }
56 
57 LauExponentialPdf::LauExponentialPdf(const LauExponentialPdf& other) : LauAbsPdf(other.varName(), other.getParameters(), other.getMinAbscissa(), other.getMaxAbscissa())
58 {
59  // Copy constructor
60  this->setRandomFun(other.getRandomFun());
61  this->calcNorm();
62 }
63 
65 {
66  // Check that the given abscissa is within the allowed range
67  if (!this->checkRange(abscissas)) {
68  gSystem->Exit(EXIT_FAILURE);
69  }
70 
71  // Get our abscissa
72  Double_t abscissa = abscissas[0];
73 
74  // Get the up to date parameter values
75  Double_t slope = slope_->value();
76 
77  // Calculate the value of the Exponential for the given value of the abscissa.
78 
79  Double_t exponent(0.0);
80  if(slope != 0){
81  exponent = slope*abscissa;
82  }
83 
84  Double_t value = TMath::Exp(exponent);
85  this->setUnNormPDFVal(value);
86 
87  // if the parameters are floating then we
88  // need to recalculate the normalisation
89  if (!this->cachePDF() && !this->withinNormCalc() && !this->withinGeneration()) {
90  this->calcNorm();
91  }
92 
93 }
94 
96 {
97  // Get the up to date parameter values
98  Double_t slope = slope_->value();
99 
100  // Calculate the normalisation of the exponential and cache it.
101  Double_t norm(0.0);
102 
103  if(slope != 0){
104  norm = (1/slope)*(TMath::Exp(slope*this->getMaxAbscissa()) - TMath::Exp(slope*this->getMinAbscissa())) ;
105  }
106 
107  this->setNorm(norm);
108 }
109 
111 {
112  if (this->heightUpToDate()) {
113  return;
114  }
115 
116  // Get the up to date parameter values
117  Double_t slope = slope_->value();
118 
119  LauAbscissas maxPoint(1);
120  maxPoint[0] = 0;
121 
122  // Calculate the PDF height for the Exponential function.
123  if (slope > 0) {
124  maxPoint[0] = this->getMaxAbscissa();
125  } else if (slope < 0) {
126  maxPoint[0] = this->getMinAbscissa();
127  }
128  this->calcLikelihoodInfo(maxPoint);
129 
130  Double_t height = this->getUnNormLikelihood();
131  this->setMaxHeight(height);
132 }
133 
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
virtual Bool_t heightUpToDate() const
Check if the maximum height of the PDF is up to date.
Definition: LauAbsPdf.hh:264
ClassImp(LauAbsCoeffSet)
LauExponentialPdf(const TString &theVarName, const std::vector< LauAbsRValue * > &params, Double_t minAbscissa, Double_t maxAbscissa)
Constructor.
File containing declaration of LauExponentialPdf class.
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
virtual void calcLikelihoodInfo(const LauAbscissas &abscissas)
Calculate the likelihood (and intermediate info) for a given abscissa.
virtual void calcNorm()
Calculate the normalisation.
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
virtual Bool_t cachePDF() const
Check if the PDF is to be cached.
Definition: LauAbsPdf.hh:270
Class for defining an Exponential PDF.
File containing LauConstants namespace.
virtual ~LauExponentialPdf()
Destructor.
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 calcPDFHeight(const LauKinematics *kinematics)
Calculate the PDF height.
virtual void setRandomFun(TRandom *randomFun)
Set the random function used for toy MC generation.
Definition: LauAbsPdf.hh:233
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