laura is hosted by Hepforge, IPPP Durham
Laura++  v2r1p1
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauSigmoidPdf.cc
Go to the documentation of this file.
1 
2 // Copyright University of Warwick 2012 - 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 
16 #include <iostream>
17 #include <vector>
18 using std::cout;
19 using std::cerr;
20 using std::endl;
21 using std::vector;
22 
23 #include "TMath.h"
24 #include "TSystem.h"
25 
26 #include "LauConstants.hh"
27 #include "LauSigmoidPdf.hh"
28 
30 
31 
32 LauSigmoidPdf::LauSigmoidPdf(const TString& theVarName, const vector<LauAbsRValue*>& params, Double_t minAbscissa, Double_t maxAbscissa) :
33  LauAbsPdf(theVarName, params, minAbscissa, maxAbscissa),
34  a_(0),
35  b_(0)
36 {
37  // Constructor for the general form of a Sigmoid PDF.
38  //
39  // The parameters in params "a" and "b" define the steepness of the
40  // slope and shift of the distribution (negative parameter "a" flips
41  // the distribution around the y-axis).
42  // The last two arguments specify the range in which the PDF is
43  // defined, and the PDF will be normalised w.r.t. these limits.
44 
45  a_ = this->findParameter("a");
46  b_ = this->findParameter("b");
47 
48  if ((this->nParameters() != 2) || (a_ == 0) || (b_ == 0)) {
49  cerr<<"ERROR in LauSigmoidPdf constructor: LauSigmoidPdf requires 2 parameters: \"a\" and \"b\"."<<endl;
50  gSystem->Exit(EXIT_FAILURE);
51  }
52 
53  // Cache the normalisation factor
54  this->calcNorm();
55 }
56 
58 {
59  // Destructor
60 }
61 
62 LauSigmoidPdf::LauSigmoidPdf(const LauSigmoidPdf& other) : LauAbsPdf(other.varName(), other.getParameters(), other.getMinAbscissa(), other.getMaxAbscissa())
63 {
64  // Copy constructor
65  this->setRandomFun(other.getRandomFun());
66  this->calcNorm();
67 }
68 
70 {
71  // Check that the given abscissa is within the allowed range
72  if (!this->checkRange(abscissas)) {
73  gSystem->Exit(EXIT_FAILURE);
74  }
75 
76  // Get our abscissa
77  Double_t abscissa = abscissas[0];
78 
79  // Get the up to date parameter values
80  Double_t a = a_->value();
81  Double_t b = b_->value();
82 
83  // Calculate the value of the exponent for the given value of the abscissa.
84 
85  Double_t exponent = -a*abscissa + b;
86 
87  Double_t value = 1.0/(1.0+ TMath::Exp(exponent));
88 
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 a = a_->value();
103  Double_t b = b_->value();
104 
105  // Calculate the normalisation of the sigmoid and cache it.
106  Double_t norm(0.0);
107 
108  if (TMath::Abs(a) > 1e-10) {
109  Double_t expb = TMath::Exp(b);
110 
111  norm = TMath::Log( TMath::Exp(a * this->getMaxAbscissa()) + expb ) -
112  TMath::Log( TMath::Exp(a * this->getMinAbscissa()) + expb );
113  norm /= a;
114 
115  }
116 
117  this->setNorm(norm);
118 }
119 
120 
121 void LauSigmoidPdf::calcPDFHeight(const LauKinematics* /*kinematics*/)
122 {
123  if (this->heightUpToDate()) {
124  return;
125  }
126 
127  // Get the up to date parameter values
128  Double_t a = a_->value();
129 
130  LauAbscissas maxPoint(1);
131  maxPoint[0] = 0;
132 
133  // Calculate the PDF height for the Sigmoid function.
134  if (a > 0.0) {
135  maxPoint[0] = this->getMaxAbscissa();
136  } else {
137  maxPoint[0] = this->getMinAbscissa();
138  }
139  this->calcLikelihoodInfo(maxPoint);
140 
141  Double_t height = this->getUnNormLikelihood();
142  this->setMaxHeight(height);
143 }
144 
145 
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
File containing declaration of LauSigmoidPdf class.
virtual void calcPDFHeight(const LauKinematics *kinematics)
Calculate the PDF height.
ClassImp(LauAbsCoeffSet)
Class for defining a generalised sigmoid PDF.
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
LauSigmoidPdf(const TString &theVarName, const std::vector< LauAbsRValue * > &params, Double_t minAbscissa, Double_t maxAbscissa)
Constructor.
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 ~LauSigmoidPdf()
Destructor.
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
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
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