laura is hosted by Hepforge, IPPP Durham
Laura++  v3r4
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauSigmoidPdf.cc
Go to the documentation of this file.
1 
2 /*
3 Copyright 2012 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 
30 #include <iostream>
31 #include <vector>
32 using std::cout;
33 using std::cerr;
34 using std::endl;
35 using std::vector;
36 
37 #include "TMath.h"
38 #include "TSystem.h"
39 
40 #include "LauConstants.hh"
41 #include "LauSigmoidPdf.hh"
42 
44 
45 
46 LauSigmoidPdf::LauSigmoidPdf(const TString& theVarName, const vector<LauAbsRValue*>& params, Double_t minAbscissa, Double_t maxAbscissa) :
47  LauAbsPdf(theVarName, params, minAbscissa, maxAbscissa),
48  a_(0),
49  b_(0)
50 {
51  // Constructor for the general form of a Sigmoid PDF.
52  //
53  // The parameters in params "a" and "b" define the steepness of the
54  // slope and shift of the distribution (negative parameter "a" flips
55  // the distribution around the y-axis).
56  // The last two arguments specify the range in which the PDF is
57  // defined, and the PDF will be normalised w.r.t. these limits.
58 
59  a_ = this->findParameter("a");
60  b_ = this->findParameter("b");
61 
62  if ((this->nParameters() != 2) || (a_ == 0) || (b_ == 0)) {
63  cerr<<"ERROR in LauSigmoidPdf constructor: LauSigmoidPdf requires 2 parameters: \"a\" and \"b\"."<<endl;
64  gSystem->Exit(EXIT_FAILURE);
65  }
66 
67  // Cache the normalisation factor
68  this->calcNorm();
69 }
70 
72 {
73  // Destructor
74 }
75 
76 LauSigmoidPdf::LauSigmoidPdf(const LauSigmoidPdf& other) : LauAbsPdf(other.varName(), other.getParameters(), other.getMinAbscissa(), other.getMaxAbscissa())
77 {
78  // Copy constructor
79  this->setRandomFun(other.getRandomFun());
80  this->calcNorm();
81 }
82 
84 {
85  // Check that the given abscissa is within the allowed range
86  if (!this->checkRange(abscissas)) {
87  gSystem->Exit(EXIT_FAILURE);
88  }
89 
90  // Get our abscissa
91  Double_t abscissa = abscissas[0];
92 
93  // Get the up to date parameter values
94  Double_t a = a_->unblindValue();
95  Double_t b = b_->unblindValue();
96 
97  // Calculate the value of the exponent for the given value of the abscissa.
98 
99  Double_t exponent = -a*abscissa + b;
100 
101  Double_t value = 1.0/(1.0+ TMath::Exp(exponent));
102 
103  this->setUnNormPDFVal(value);
104 
105  // if the parameters are floating then we
106  // need to recalculate the normalisation
107  if (!this->cachePDF() && !this->withinNormCalc() && !this->withinGeneration()) {
108  this->calcNorm();
109  }
110 
111 }
112 
114 {
115  // Get the up to date parameter values
116  Double_t a = a_->unblindValue();
117  Double_t b = b_->unblindValue();
118 
119  // Calculate the normalisation of the sigmoid and cache it.
120  Double_t norm(0.0);
121 
122  if (TMath::Abs(a) > 1e-10) {
123  Double_t expb = TMath::Exp(b);
124 
125  norm = TMath::Log( TMath::Exp(a * this->getMaxAbscissa()) + expb ) -
126  TMath::Log( TMath::Exp(a * this->getMinAbscissa()) + expb );
127  norm /= a;
128 
129  }
130 
131  this->setNorm(norm);
132 }
133 
134 
135 void LauSigmoidPdf::calcPDFHeight(const LauKinematics* /*kinematics*/)
136 {
137  if (this->heightUpToDate()) {
138  return;
139  }
140 
141  // Get the up to date parameter values
142  Double_t a = a_->unblindValue();
143 
144  LauAbscissas maxPoint(1);
145  maxPoint[0] = 0;
146 
147  // Calculate the PDF height for the Sigmoid function.
148  if (a > 0.0) {
149  maxPoint[0] = this->getMaxAbscissa();
150  } else {
151  maxPoint[0] = this->getMinAbscissa();
152  }
153  this->calcLikelihoodInfo(maxPoint);
154 
155  Double_t height = this->getUnNormLikelihood();
156  this->setMaxHeight(height);
157 }
158 
159 
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
virtual Bool_t heightUpToDate() const
Check if the maximum height of the PDF is up to date.
Definition: LauAbsPdf.hh:278
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: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
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:437
virtual TRandom * getRandomFun() const
Retrieve the random function used for MC generation.
Definition: LauAbsPdf.hh:401
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: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
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 void setRandomFun(TRandom *randomFun)
Set the random function used for toy MC generation.
Definition: LauAbsPdf.hh:247
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