laura is hosted by Hepforge, IPPP Durham
Laura++  v2r1p1
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauParametricStepFuncPdf.cc
Go to the documentation of this file.
1 
2 // Copyright University of Warwick 2008 - 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 /*****************************************************************************
16  * Class based on RooFit/RooParametricStepFunction. *
17  * Original copyright given below. *
18  *****************************************************************************
19  * Authors: *
20  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
21  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
22  * *
23  * Copyright (c) 2000-2005, Regents of the University of California *
24  * and Stanford University. All rights reserved. *
25  * *
26  * Redistribution and use in source and binary forms, *
27  * with or without modification, are permitted according to the terms *
28  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
29  *****************************************************************************/
30 
31 
32 #include <iostream>
33 #include <vector>
34 using std::cout;
35 using std::cerr;
36 using std::endl;
37 using std::vector;
38 
39 #include "TMath.h"
40 #include "TSystem.h"
41 
42 #include "LauConstants.hh"
44 
46 
47 
48 LauParametricStepFuncPdf::LauParametricStepFuncPdf(const TString& theVarName, const vector<LauAbsRValue*>& params, const vector<Double_t>& limits, NormBin normalisationBin) :
49  LauAbsPdf(theVarName, params, limits.front(), limits.back()),
50  normBin_(normalisationBin),
51  limits_(limits)
52 {
53  // Constructor for the PSF PDF.
54  //
55  // The parameters in params are the bin contents of all but the
56  // normalisation bin, so has N_bins-1 entries.
57  // The last argument specifies the limits of the bins and the range
58  // as a whole, so has N_bins+1 entries.
59 
60  if (this->nParameters() != this->nBins()-1) {
61  cerr<<"ERROR in LauParametricStepFuncPdf constructor: LauParametricStepFuncPdf requires N-1 parameters, where N is the number of bins."<<endl;
62  gSystem->Exit(EXIT_FAILURE);
63  }
64 
65  // Cache the normalisation factor
66  this->calcNorm();
67 }
68 
70 {
71  // Destructor
72 }
73 
74 LauParametricStepFuncPdf::LauParametricStepFuncPdf(const LauParametricStepFuncPdf& other) : LauAbsPdf(other.varName(), other.getParameters(), other.getMinAbscissa(), other.getMaxAbscissa())
75 {
76  // Copy constructor
77  normBin_ = other.normBin_;
78  limits_ = other.limits_;
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 parameters
94  const vector<LauAbsRValue*>& pars = this->getParameters();
95 
96  // Calculate value
97  Double_t value(0.0);
98  const UInt_t numBins = this->nBins();
99 
100  if ( this->normBin() == Last ) {
101  // the last bin is our normalisation bin
102  for ( UInt_t i(1); i<=numBins; ++i ) {
103  if ( abscissa < limits_[i] ) {
104  // in bin i-1 (starting with bin 0)
105  if ( i < numBins ) {
106  // not in last bin
107  value = pars[i-1]->value();
108  break;
109  } else {
110  // in last bin
111  Double_t sum(0.0);
112  Double_t binSize(0.0);
113  for ( UInt_t j(1); j<numBins; ++j ) {
114  binSize = limits_[j] - limits_[j-1];
115  sum += ( pars[j-1]->value() * binSize );
116  }
117  binSize = limits_[numBins] - limits_[numBins-1];
118  value = ( 1.0 - sum ) / binSize;
119  break;
120  }
121  }
122  }
123  } else {
124  // the first bin is our normalisation bin
125  for ( UInt_t i(1); i<=numBins; ++i ) {
126  if ( abscissa < limits_[i] ) {
127  // in bin i-1 (starting with bin 0)
128  if ( i > 1 ) {
129  // not in first bin
130  value = pars[i-2]->value();
131  break;
132  } else {
133  // in first bin
134  Double_t sum(0.0);
135  Double_t binSize(0.0);
136  for ( UInt_t j(2); j<=numBins; ++j ) {
137  binSize = limits_[j] - limits_[j-1];
138  sum += ( pars[j-2]->value() * binSize );
139  }
140  binSize = limits_[1] - limits_[0];
141  value = ( 1.0 - sum ) / binSize;
142  break;
143  }
144  }
145  }
146  }
147 
148  this->setUnNormPDFVal(value);
149 
150  // if the parameters are floating then we
151  // need to recalculate the normalisation
152  if (!this->cachePDF() && !this->withinNormCalc() && !this->withinGeneration()) {
153  this->calcNorm();
154  }
155 }
156 
158 {
159  this->setNorm(1.0);
160 }
161 
163 {
164  if (this->heightUpToDate()) {
165  return;
166  }
167 
168  // Get the parameters
169  const vector<LauAbsRValue*>& pars = this->getParameters();
170 
171  // Find the PDF height
172  Double_t height(0.0);
173  Double_t value(0.0);
174  const UInt_t numBins = this->nBins();
175 
176  if ( this->normBin() == Last ) {
177  // the last bin is our normalisation bin
178 
179  // Check through all the parameterised bins
180  for ( UInt_t i(0); i<numBins-1; ++i ) {
181  value = pars[i]->value();
182  if ( height < value ) {
183  height = value;
184  }
185  }
186 
187  // Check the last bin
188  Double_t sum(0.0);
189  Double_t binSize(0.0);
190  for ( UInt_t j(1); j<numBins; ++j ) {
191  binSize = limits_[j] - limits_[j-1];
192  sum += ( pars[j-1]->value() * binSize );
193  }
194  binSize = limits_[numBins] - limits_[numBins-1];
195  value = ( 1.0 - sum ) / binSize;
196  if ( height < value ) {
197  height = value;
198  }
199  } else {
200  // the first bin is our normalisation bin
201 
202  // Check through all the parameterised bins
203  for ( UInt_t i(1); i<numBins; ++i ) {
204  value = pars[i-1]->value();
205  if ( height < value ) {
206  height = value;
207  }
208  }
209 
210  // Check the first bin
211  Double_t sum(0.0);
212  Double_t binSize(0.0);
213  for ( UInt_t j(2); j<=numBins; ++j ) {
214  binSize = limits_[j] - limits_[j-1];
215  sum += ( pars[j-2]->value() * binSize );
216  }
217  binSize = limits_[1] - limits_[0];
218  value = ( 1.0 - sum ) / binSize;
219  if ( height < value ) {
220  height = value;
221  }
222  }
223 
224  this->setMaxHeight(height);
225 }
226 
virtual void setUnNormPDFVal(Double_t unNormPDFVal)
Set the unnormalised likelihood.
Definition: LauAbsPdf.hh:369
virtual Bool_t heightUpToDate() const
Check if the maximum height of the PDF is up to date.
Definition: LauAbsPdf.hh:264
ClassImp(LauAbsCoeffSet)
NormBin normBin_
normalisation bin
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 ~LauParametricStepFuncPdf()
Destructor.
virtual Bool_t withinNormCalc() const
Check whether the calcNorm method is running.
Definition: LauAbsPdf.hh:423
virtual TRandom * getRandomFun() const
Retrieve the random function used for MC generation.
Definition: LauAbsPdf.hh:387
LauParametricStepFuncPdf(const TString &theVarName, const std::vector< LauAbsRValue * > &params, const std::vector< Double_t > &limits, NormBin normalisationBin=Last)
Constructor.
NormBin normBin() const
Normalisation bin.
Class for defining a Parametric Step Function PDF.
UInt_t nBins() const
Number of bins.
virtual void setMaxHeight(Double_t maxHeight)
Set the maximum height.
Definition: LauAbsPdf.hh:331
virtual void calcLikelihoodInfo(const LauAbscissas &abscissas)
Calculate the likelihood (and intermediate info) for a given abscissa.
File containing declaration of LauParametricStepFuncPdf class.
virtual const std::vector< LauAbsRValue * > & getParameters() const
Retrieve the parameters of the PDF, e.g. so that they can be loaded into a fit.
Definition: LauAbsPdf.hh:239
virtual Bool_t withinGeneration() const
Check whether the generate method is running.
Definition: LauAbsPdf.hh:435
virtual void calcNorm()
Calculate the normalisation.
virtual Bool_t cachePDF() const
Check if the PDF is to be cached.
Definition: LauAbsPdf.hh:270
std::vector< Double_t > limits_
limits of the bins
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.
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