laura is hosted by Hepforge, IPPP Durham
Laura++  v2r2p1
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 
29 
30 
31  LauLinearPdf::LauLinearPdf(const TString& theVarName, const vector<LauAbsRValue*>& params, Double_t minAbscissa, Double_t maxAbscissa) :
32  LauAbsPdf(theVarName, params, minAbscissa, maxAbscissa),
33  slope_(0),posflag_(kTRUE)
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  // Cache the normalisation factor.
49  this->calcNorm();
50 }
51 
53 {
54  // Destructor
55 }
56 
57 LauLinearPdf::LauLinearPdf(const LauLinearPdf& 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 straight line for the given value of the abscissa.
78  Double_t constVal = 1.0/(this->getMaxAbscissa() - this->getMinAbscissa());
79  constVal -= slope * (this->getMaxAbscissa() + this->getMinAbscissa()) * 0.5;
80 
81  Double_t value = slope*abscissa + constVal;
82 
83  // Make sure the PDF doesn't go negative
84  if ( value < 0.0 ) {
85  if ( posflag_ ) {
86  std::cerr << "WARNING in LauLinearPdf::calcLikelihoodInfo : The PDF is negative, setting to zero" << std::endl;
87  }
88  value = 0.0;
89  posflag_= kFALSE;
90  }
91 
92  this->setUnNormPDFVal(value);
93 }
94 
96 {
97  // Nothing to calculate here since the PDF is already normalised to 1
98  this->setNorm(1.0);
99 }
100 
101 void LauLinearPdf::calcPDFHeight( const LauKinematics* /*kinematics*/ )
102 {
103  if (this->heightUpToDate()) {
104  return;
105  }
106 
107  // Get the up to date parameter values
108  Double_t slope = slope_->value();
109 
110  // Calculate the PDF height for the straight line
111  LauAbscissas maxPoint(1);
112  if (slope>0.0) {
113  maxPoint[0] = this->getMaxAbscissa();
114  } else {
115  maxPoint[0] = this->getMinAbscissa();
116  }
117  this->calcLikelihoodInfo(maxPoint);
118 
119  Double_t height = this->getUnNormLikelihood();
120 
121  this->setMaxHeight(height);
122 }
Bool_t posflag_
Definition: LauLinearPdf.hh:72
virtual void setUnNormPDFVal(Double_t unNormPDFVal)
Set the unnormalised likelihood.
Definition: LauAbsPdf.hh:369
virtual ~LauLinearPdf()
Destructor.
Definition: LauLinearPdf.cc:52
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)
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 void calcNorm()
Calculate the normalisation.
Definition: LauLinearPdf.cc:95
virtual TRandom * getRandomFun() const
Retrieve the random function used for MC generation.
Definition: LauAbsPdf.hh:387
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:123
virtual void setMaxHeight(Double_t maxHeight)
Set the maximum height.
Definition: LauAbsPdf.hh:331
File containing declaration of LauLinearPdf class.
virtual void calcPDFHeight(const LauKinematics *kinematics)
Calculate the PDF height.
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.
LauLinearPdf(const TString &theVarName, const std::vector< LauAbsRValue * > &params, Double_t minAbscissa, Double_t maxAbscissa)
Constructor.
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
virtual void calcLikelihoodInfo(const LauAbscissas &abscissas)
Calculate the likelihood (and intermediate info) for a given abscissa.
Definition: LauLinearPdf.cc:64