laura is hosted by Hepforge, IPPP Durham
Laura++  v3r5
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauBifurcatedGaussPdf.cc
Go to the documentation of this file.
1 
2 /*
3 Copyright 2006 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 
32 #include "TMath.h"
33 #include "TSystem.h"
34 
35 #include "LauBifurcatedGaussPdf.hh"
36 #include "LauConstants.hh"
37 
39 
40 
41 LauBifurcatedGaussPdf::LauBifurcatedGaussPdf(const TString& theVarName, const std::vector<LauAbsRValue*>& params, Double_t minAbscissa, Double_t maxAbscissa) :
42  LauAbsPdf(theVarName, params, minAbscissa, maxAbscissa),
43  mean_(0),
44  sigmaL_(0),
45  sigmaR_(0)
46 {
47  // Constructor for the bifurcated Gaussian PDF.
48  // The bifurcated Gaussian combines the left half of a
49  // Gaussian with resolution sigmaL with the right half
50  // of a Gaussian with resolution sigmaR, both having
51  // a common mean (or more correctly, peak position).
52 
53  // NB the parameters in params are the mean, sigmaL and sigmaR
54  // The last two arguments specify the range in which the PDF is defined, and the PDF
55  // will be normalised w.r.t. these limits.
56 
57  mean_ = this->findParameter("mean");
58  sigmaL_ = this->findParameter("sigmaL");
59  sigmaR_ = this->findParameter("sigmaR");
60 
61  if ((this->nParameters() != 3) || (mean_ == 0) || (sigmaL_ == 0) || (sigmaR_ == 0) ) {
62  std::cerr << "ERROR in LauBifurcatedGaussPdf constructor: LauBifurcatedGaussPdf requires 3 parameters: \"mean\", \"sigmaL\" and \"sigmaR\"." << std::endl;
63  gSystem->Exit(EXIT_FAILURE);
64  }
65 
66  // Cache the normalisation factor
67  this->calcNorm();
68 }
69 
71 {
72  // Destructor
73 }
74 
76 {
77 
78  // Check that the given abscissa is within the allowed range
79  if (!this->checkRange(abscissas)) {
80  gSystem->Exit(EXIT_FAILURE);
81  }
82 
83  // Get our abscissa
84  Double_t abscissa = abscissas[0];
85 
86  // Get the up to date parameter values
87  Double_t mean = mean_->unblindValue();
88  Double_t sigmaL = sigmaL_->unblindValue();
89  Double_t sigmaR = sigmaR_->unblindValue();
90 
91  // Evaluate the Birfucated Gaussian PDF value
92  Double_t arg = abscissa - mean;
93  Double_t coef(0.0);
94  Double_t value(0.0);
95 
96  if (arg < 0.0){
97  if (TMath::Abs(sigmaL) > 1e-30) {
98  coef = -0.5/(sigmaL*sigmaL);
99  }
100  } else {
101  if (TMath::Abs(sigmaR) > 1e-30) {
102  coef = -0.5/(sigmaR*sigmaR);
103  }
104  }
105  value = TMath::Exp(coef*arg*arg);
106 
107  // Calculate the norm
108  Double_t xscaleL = LauConstants::root2*sigmaL;
109  Double_t xscaleR = LauConstants::root2*sigmaR;
110 
111  Double_t integral(0.0);
112  Double_t norm(0.0);
113  Double_t result(0.0);
114 
115 
116  if(this->getMaxAbscissa() < mean){
117  integral = sigmaL * ( TMath::Erf((this->getMaxAbscissa() - mean)/xscaleL) - TMath::Erf((this->getMinAbscissa() - mean)/xscaleL));
118  }else if (this->getMinAbscissa() > mean){
119  integral = sigmaR * (TMath::Erf((this->getMaxAbscissa() - mean)/xscaleR) - TMath::Erf((this->getMinAbscissa() - mean)/xscaleR));
120  }else{
121  integral = sigmaR*TMath::Erf((this->getMaxAbscissa() -mean)/xscaleR) - sigmaL*TMath::Erf((this->getMinAbscissa() - mean)/xscaleL);
122  }
123 
124  norm = LauConstants::rootPiBy2*integral;
125 
126  // the result
127  result = value/norm;
128  this->setUnNormPDFVal(result);
129 
130 }
131 
133 {
134  // Nothing to do here, since it already normalized
135  this->setNorm(1.0);
136 }
137 
138 
140 {
141  if (this->heightUpToDate()) {
142  return;
143  }
144 
145  // Get the up to date parameter values
146  Double_t mean = mean_->unblindValue();
147 
148  LauAbscissas maxPoint(1);
149  maxPoint[0] = mean;
150 
151  // Calculate the PDF height for the Bifurcated Gaussian function.
152  if (mean>this->getMaxAbscissa()) {
153  maxPoint[0] = this->getMaxAbscissa();
154  } else if (mean<this->getMinAbscissa()) {
155  maxPoint[0] = this->getMinAbscissa();
156  }
157  this->calcLikelihoodInfo(maxPoint);
158 
159  Double_t height = this->getUnNormLikelihood();
160  this->setMaxHeight(height);
161 }
162 
163 
164 
165 
LauAbsRValue * sigmaL_
Sigma of left Gaussian.
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
ClassImp(LauAbsCoeffSet)
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
virtual void calcPDFHeight(const LauKinematics *kinematics)
Calculate the PDF height.
virtual ~LauBifurcatedGaussPdf()
Destructor.
virtual Double_t unblindValue() const =0
The unblinded value of the parameter.
const Double_t rootPiBy2
Square root of Pi divided by two.
File containing declaration of LauBifurcatedGaussPdf class.
const Double_t root2
Square root of two.
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
Class for defining a bifurcated Gaussian PDF.
LauAbsRValue * sigmaR_
Sigma of right Gaussian.
virtual void calcLikelihoodInfo(const LauAbscissas &abscissas)
Calculate the likelihood (and intermediate info) for a given abscissa.
LauAbsRValue * mean_
Gaussian mean.
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 calcNorm()
Calculate the normalisation.
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