laura is hosted by Hepforge, IPPP Durham
Laura++  v2r0
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauLinearPdf.cc
Go to the documentation of this file.
1 
2 // Copyright University of Warwick 2006 - 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 "LauLinearPdf.hh"
27 
28 ClassImp(LauLinearPdf)
29 
30 
31 LauLinearPdf::LauLinearPdf(const TString& theVarName, const vector<LauParameter*>& params, Double_t minAbscissa, Double_t maxAbscissa) :
32  LauAbsPdf(theVarName, params, minAbscissa, maxAbscissa),
33  slope_(0)
34 {
35  // Constructor for the linear PDF.
36  //
37  // The parameters in params are the slope and y-intercept of the line.
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<<"Warning. LauLinearPdf requires 1 parameter: \"slope\"."<<endl;
45  gSystem->Exit(EXIT_FAILURE);
46  }
47 
48  // See whether the parameters we've been given characterize a positive definite PDF
49  // If not, change them.
50  this->checkPositiveness();
51 
52  // Cache the normalisation factor.
53  this->calcNorm();
54 }
55 
57 {
58  // Destructor
59 }
60 
61 LauLinearPdf::LauLinearPdf(const LauLinearPdf& other) : LauAbsPdf(other.varName(), other.getParameters(), other.getMinAbscissa(), other.getMaxAbscissa())
62 {
63  // Copy constructor
64  this->setRandomFun(other.getRandomFun());
65  this->calcNorm();
66 }
67 
69 {
70  // Check that the given abscissa is within the allowed range
71  if (!this->checkRange(abscissas)) {
72  gSystem->Exit(EXIT_FAILURE);
73  }
74 
75  // Get our abscissa
76  Double_t abscissa = abscissas[0];
77 
78  // Get the up to date parameter values
79  Double_t slope = slope_->value();
80 
81  // Calculate the value of the straight line for the given value of the abscissa.
82  Double_t constVal = 1.0/(this->getMaxAbscissa() - this->getMinAbscissa());
83  constVal -= slope * (this->getMaxAbscissa() + this->getMinAbscissa()) * 0.5;
84 
85  Double_t value = slope*abscissa + constVal;
86  this->setUnNormPDFVal(value);
87 }
88 
90 {
91  // Nothing to calculate here since the PDF is already normalised to 1
92  this->setNorm(1.0);
93 }
94 
95 void LauLinearPdf::calcPDFHeight( const LauKinematics* /*kinematics*/ )
96 {
97  if (this->heightUpToDate()) {
98  return;
99  }
100 
101  // Get the up to date parameter values
102  Double_t slope = slope_->value();
103 
104  // Calculate the PDF height for the straight line
105  LauAbscissas maxPoint(1);
106  if (slope>0.0) {
107  maxPoint[0] = this->getMaxAbscissa();
108  } else {
109  maxPoint[0] = this->getMinAbscissa();
110  }
111  this->calcLikelihoodInfo(maxPoint);
112 
113  Double_t height = this->getUnNormLikelihood();
114  this->setMaxHeight(height);
115 }
116 
118 {
119  // Get the up to date parameter values
120  Double_t slope = slope_->value();
121 
122  //Check that the slope is such that the PDF won't take negative values.
123  LauAbscissas minPoint(1);
124  if (slope>0.0) {
125  minPoint[0] = this->getMinAbscissa();
126  } else {
127  minPoint[0] = this->getMaxAbscissa();
128  }
129  this->calcLikelihoodInfo(minPoint);
130 
131  Double_t minimum = this->getUnNormLikelihood();
132  if (minimum < 0.0) {
133  Double_t oldslope = slope;
134  slope = 2.0/((this->getMaxAbscissa() - this->getMinAbscissa())*(this->getMaxAbscissa() - this->getMinAbscissa()));
135  if (oldslope < 0.0)
136  slope *= -1.0;
137 
138  if (slope < this->getParMin("slope"))
139  this->setParMin("slope", slope-1e-6);
140  if (slope > this->getParMax("slope"))
141  this->setParMax("slope", slope+1e-6);
142  this->setParValue("slope",slope);
143 
144  cerr<<"ERROR in LauLinearPdf::checkPositiveness : Given value of slope = "<<oldslope<<
145  " makes the PDF go negative. Resetting to slope = "<<slope<<endl;
146  }
147 }
virtual void setParMax(const TString &parName, Double_t maxValue)
Change the maximum value of the specified parameter.
Definition: LauAbsPdf.cc:481
virtual void setUnNormPDFVal(Double_t unNormPDFVal)
Set the unnormalised likelihood.
Definition: LauAbsPdf.hh:454
virtual ~LauLinearPdf()
Destructor.
Definition: LauLinearPdf.cc:56
virtual Double_t getMinAbscissa() const
Retrieve the minimum value of the (primary) abscissa.
Definition: LauAbsPdf.hh:158
virtual void checkPositiveness()
Check that PDF is positive.
virtual Bool_t heightUpToDate() const
Check if the maximum height of the PDF is up to date.
Definition: LauAbsPdf.hh:349
virtual Double_t getUnNormLikelihood() const
Retrieve the unnormalised likelihood value.
Definition: LauAbsPdf.hh:278
virtual void setNorm(Double_t norm)
Set the normalisation factor.
Definition: LauAbsPdf.hh:410
virtual Bool_t checkRange(const LauAbscissas &abscissas) const
Check that all abscissas are within their allowed ranges.
Definition: LauAbsPdf.cc:213
virtual Double_t getParMin(const TString &parName) const
Retrieve the minimum value of the specified parameter.
Definition: LauAbsPdf.cc:415
virtual void calcNorm()
Calculate the normalisation.
Definition: LauLinearPdf.cc:89
virtual void setParMin(const TString &parName, Double_t minValue)
Change the minimum value of the specified parameter.
Definition: LauAbsPdf.cc:473
virtual TRandom * getRandomFun() const
Retrieve the random function used for MC generation.
Definition: LauAbsPdf.hh:472
virtual void setParValue(const TString &parName, Double_t value)
Change the value of the specified parameter.
Definition: LauAbsPdf.cc:465
Class for defining a straight line PDF.
Definition: LauLinearPdf.hh:30
virtual Double_t getMaxAbscissa() const
Retrieve the maximum value of the (primary) abscissa.
Definition: LauAbsPdf.hh:164
virtual void setMaxHeight(Double_t maxHeight)
Set the maximum height.
Definition: LauAbsPdf.hh:416
Class for defining the fit parameter objects.
Definition: LauParameter.hh:32
File containing declaration of LauLinearPdf class.
virtual void calcPDFHeight(const LauKinematics *kinematics)
Calculate the PDF height.
Definition: LauLinearPdf.cc:95
virtual Double_t getParMax(const TString &parName) const
Retrieve the maximum value of the specified parameter.
Definition: LauAbsPdf.cc:425
File containing LauConstants namespace.
Class for defining the abstract interface for PDF classes.
Definition: LauAbsPdf.hh:40
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:315
std::vector< Double_t > LauAbscissas
The type used for containing multiple abscissa values.
Definition: LauAbsPdf.hh:44
virtual void calcLikelihoodInfo(const LauAbscissas &abscissas)
Calculate the likelihood (and intermediate info) for a given abscissa.
Definition: LauLinearPdf.cc:68
LauLinearPdf(const TString &theVarName, const std::vector< LauParameter * > &params, Double_t minAbscissa, Double_t maxAbscissa)
Constructor.