laura is hosted by Hepforge, IPPP Durham
Laura++  3.6.0
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 
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 "LauSigmoidPdf.hh"
37 
38 #include "TMath.h"
39 #include "TSystem.h"
40 
41 LauSigmoidPdf::LauSigmoidPdf( const TString& theVarName,
42  const std::vector<LauAbsRValue*>& params,
43  Double_t minAbscissa,
44  Double_t maxAbscissa ) :
45  LauAbsPdf( theVarName, params, minAbscissa, maxAbscissa ),
46  a_( 0 ),
47  b_( 0 )
48 {
49  // Constructor for the general form of a Sigmoid PDF.
50  //
51  // The parameters in params "a" and "b" define the steepness of the
52  // slope and shift of the distribution (negative parameter "a" flips
53  // the distribution around the y-axis).
54  // The last two arguments specify the range in which the PDF is
55  // defined, and the PDF will be normalised w.r.t. these limits.
56 
57  a_ = this->findParameter( "a" );
58  b_ = this->findParameter( "b" );
59 
60  if ( ( this->nParameters() != 2 ) || ( a_ == 0 ) || ( b_ == 0 ) ) {
61  cerr << "ERROR in LauSigmoidPdf constructor: LauSigmoidPdf requires 2 parameters: \"a\" and \"b\"."
62  << endl;
63  gSystem->Exit( EXIT_FAILURE );
64  }
65 
66  // Cache the normalisation factor
67  this->calcNorm();
68 }
69 
71 {
72  // Destructor
73 }
74 
76  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 
113 {
114  // Get the up to date parameter values
115  Double_t a = a_->unblindValue();
116  Double_t b = b_->unblindValue();
117 
118  // Calculate the normalisation of the sigmoid and cache it.
119  Double_t norm( 0.0 );
120 
121  if ( TMath::Abs( a ) > 1e-10 ) {
122  Double_t expb = TMath::Exp( b );
123 
124  norm = TMath::Log( TMath::Exp( a * this->getMaxAbscissa() ) + expb ) -
125  TMath::Log( TMath::Exp( a * this->getMinAbscissa() ) + expb );
126  norm /= a;
127  }
128 
129  this->setNorm( norm );
130 }
131 
132 void LauSigmoidPdf::calcPDFHeight( const LauKinematics* /*kinematics*/ )
133 {
134  if ( this->heightUpToDate() ) {
135  return;
136  }
137 
138  // Get the up to date parameter values
139  Double_t a = a_->unblindValue();
140 
141  LauAbscissas maxPoint( 1 );
142  maxPoint[0] = 0;
143 
144  // Calculate the PDF height for the Sigmoid function.
145  if ( a > 0.0 ) {
146  maxPoint[0] = this->getMaxAbscissa();
147  } else {
148  maxPoint[0] = this->getMinAbscissa();
149  }
150  this->calcLikelihoodInfo( maxPoint );
151 
152  Double_t height = this->getUnNormLikelihood();
153  this->setMaxHeight( height );
154 }
virtual Double_t getMaxAbscissa() const
Retrieve the maximum value of the (primary) abscissa.
Definition: LauAbsPdf.hh:141
virtual void calcLikelihoodInfo(const LauAbscissas &abscissas)
Calculate the likelihood (and intermediate info) for a given abscissa.
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
Class for defining a generalised sigmoid PDF.
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 LauAbsRValue * findParameter(const TString &parName)
Retrieve the specified parameter.
Definition: LauAbsPdf.cc:431
virtual void calcNorm()
Calculate the normalisation.
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 TRandom * getRandomFun() const
Retrieve the random function used for MC generation.
Definition: LauAbsPdf.hh:412
virtual void setUnNormPDFVal(Double_t unNormPDFVal)
Set the unnormalised likelihood.
Definition: LauAbsPdf.hh:394
virtual ~LauSigmoidPdf()
Destructor.
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.
LauAbsRValue * b_
Parameter b.
virtual void calcPDFHeight(const LauKinematics *kinematics)
Calculate the PDF height.
LauAbsRValue * a_
Parameter a.
virtual void setMaxHeight(Double_t maxHeight)
Set the maximum height.
Definition: LauAbsPdf.hh:354
Class for calculating 3-body kinematic quantities.
LauSigmoidPdf(const TString &theVarName, const std::vector< LauAbsRValue * > &params, Double_t minAbscissa, Double_t maxAbscissa)
Constructor.
File containing declaration of LauSigmoidPdf 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 void setRandomFun(TRandom *randomFun)
Set the random function used for toy MC generation.
Definition: LauAbsPdf.hh:256
virtual Bool_t checkRange(const LauAbscissas &abscissas) const
Check that all abscissas are within their allowed ranges.
Definition: LauAbsPdf.cc:243