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