laura is hosted by Hepforge, IPPP Durham
Laura++  v3r2
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 
75 {
76  // Check that the given abscissa is within the allowed range
77  if (!this->checkRange(abscissas)) {
78  gSystem->Exit(EXIT_FAILURE);
79  }
80 
81  // Get our abscissa
82  Double_t abscissa = abscissas[0];
83 
84  // Get the parameters
85  const vector<LauAbsRValue*>& pars = this->getParameters();
86 
87  // Calculate value
88  Double_t value(0.0);
89  const UInt_t numBins = this->nBins();
90 
91  if ( this->normBin() == Last ) {
92  // the last bin is our normalisation bin
93  for ( UInt_t i(1); i<=numBins; ++i ) {
94  if ( abscissa < limits_[i] ) {
95  // in bin i-1 (starting with bin 0)
96  if ( i < numBins ) {
97  // not in last bin
98  value = pars[i-1]->unblindValue();
99  break;
100  } else {
101  // in last bin
102  Double_t sum(0.0);
103  Double_t binSize(0.0);
104  for ( UInt_t j(1); j<numBins; ++j ) {
105  binSize = limits_[j] - limits_[j-1];
106  sum += ( pars[j-1]->unblindValue() * binSize );
107  }
108  binSize = limits_[numBins] - limits_[numBins-1];
109  value = ( 1.0 - sum ) / binSize;
110  break;
111  }
112  }
113  }
114  } else {
115  // the first bin is our normalisation bin
116  for ( UInt_t i(1); i<=numBins; ++i ) {
117  if ( abscissa < limits_[i] ) {
118  // in bin i-1 (starting with bin 0)
119  if ( i > 1 ) {
120  // not in first bin
121  value = pars[i-2]->unblindValue();
122  break;
123  } else {
124  // in first bin
125  Double_t sum(0.0);
126  Double_t binSize(0.0);
127  for ( UInt_t j(2); j<=numBins; ++j ) {
128  binSize = limits_[j] - limits_[j-1];
129  sum += ( pars[j-2]->unblindValue() * binSize );
130  }
131  binSize = limits_[1] - limits_[0];
132  value = ( 1.0 - sum ) / binSize;
133  break;
134  }
135  }
136  }
137  }
138 
139  this->setUnNormPDFVal(value);
140 
141  // if the parameters are floating then we
142  // need to recalculate the normalisation
143  if (!this->cachePDF() && !this->withinNormCalc() && !this->withinGeneration()) {
144  this->calcNorm();
145  }
146 }
147 
149 {
150  this->setNorm(1.0);
151 }
152 
154 {
155  if (this->heightUpToDate()) {
156  return;
157  }
158 
159  // Get the parameters
160  const vector<LauAbsRValue*>& pars = this->getParameters();
161 
162  // Find the PDF height
163  Double_t height(0.0);
164  Double_t value(0.0);
165  const UInt_t numBins = this->nBins();
166 
167  if ( this->normBin() == Last ) {
168  // the last bin is our normalisation bin
169 
170  // Check through all the parameterised bins
171  for ( UInt_t i(0); i<numBins-1; ++i ) {
172  value = pars[i]->unblindValue();
173  if ( height < value ) {
174  height = value;
175  }
176  }
177 
178  // Check the last bin
179  Double_t sum(0.0);
180  Double_t binSize(0.0);
181  for ( UInt_t j(1); j<numBins; ++j ) {
182  binSize = limits_[j] - limits_[j-1];
183  sum += ( pars[j-1]->unblindValue() * binSize );
184  }
185  binSize = limits_[numBins] - limits_[numBins-1];
186  value = ( 1.0 - sum ) / binSize;
187  if ( height < value ) {
188  height = value;
189  }
190  } else {
191  // the first bin is our normalisation bin
192 
193  // Check through all the parameterised bins
194  for ( UInt_t i(1); i<numBins; ++i ) {
195  value = pars[i-1]->unblindValue();
196  if ( height < value ) {
197  height = value;
198  }
199  }
200 
201  // Check the first bin
202  Double_t sum(0.0);
203  Double_t binSize(0.0);
204  for ( UInt_t j(2); j<=numBins; ++j ) {
205  binSize = limits_[j] - limits_[j-1];
206  sum += ( pars[j-2]->unblindValue() * binSize );
207  }
208  binSize = limits_[1] - limits_[0];
209  value = ( 1.0 - sum ) / binSize;
210  if ( height < value ) {
211  height = value;
212  }
213  }
214 
215  this->setMaxHeight(height);
216 }
217 
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)
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
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:276
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.
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