laura is hosted by Hepforge, IPPP Durham
Laura++  3.6.0
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 #include <iostream>
46 #include <vector>
47 using std::cerr;
48 using std::cout;
49 using std::endl;
50 
51 #include "LauConstants.hh"
53 
54 #include "TMath.h"
55 #include "TSystem.h"
56 
58  const std::vector<LauAbsRValue*>& params,
59  const std::vector<Double_t>& limits,
60  NormBin normalisationBin ) :
61  LauAbsPdf( theVarName, params, limits.front(), limits.back() ),
62  normBin_( normalisationBin ),
63  limits_( limits )
64 {
65  // Constructor for the PSF PDF.
66  //
67  // The parameters in params are the bin contents of all but the
68  // normalisation bin, so has N_bins-1 entries.
69  // The last argument specifies the limits of the bins and the range
70  // as a whole, so has N_bins+1 entries.
71 
72  if ( this->nParameters() != this->nBins() - 1 ) {
73  cerr << "ERROR in LauParametricStepFuncPdf constructor: LauParametricStepFuncPdf requires N-1 parameters, where N is the number of bins."
74  << endl;
75  gSystem->Exit( EXIT_FAILURE );
76  }
77 
78  // Cache the normalisation factor
79  this->calcNorm();
80 }
81 
83 {
84  // Destructor
85 }
86 
88 {
89  // Check that the given abscissa is within the allowed range
90  if ( ! this->checkRange( abscissas ) ) {
91  gSystem->Exit( EXIT_FAILURE );
92  }
93 
94  // Get our abscissa
95  Double_t abscissa = abscissas[0];
96 
97  // Get the parameters
98  const std::vector<LauAbsRValue*>& pars = this->getParameters();
99 
100  // Calculate value
101  Double_t value( 0.0 );
102  const UInt_t numBins = this->nBins();
103 
104  if ( this->normBin() == Last ) {
105  // the last bin is our normalisation bin
106  for ( UInt_t i( 1 ); i <= numBins; ++i ) {
107  if ( abscissa < limits_[i] ) {
108  // in bin i-1 (starting with bin 0)
109  if ( i < numBins ) {
110  // not in last bin
111  value = pars[i - 1]->unblindValue();
112  break;
113  } else {
114  // in last bin
115  Double_t sum( 0.0 );
116  Double_t binSize( 0.0 );
117  for ( UInt_t j( 1 ); j < numBins; ++j ) {
118  binSize = limits_[j] - limits_[j - 1];
119  sum += ( pars[j - 1]->unblindValue() * binSize );
120  }
121  binSize = limits_[numBins] - limits_[numBins - 1];
122  value = ( 1.0 - sum ) / binSize;
123  break;
124  }
125  }
126  }
127  } else {
128  // the first bin is our normalisation bin
129  for ( UInt_t i( 1 ); i <= numBins; ++i ) {
130  if ( abscissa < limits_[i] ) {
131  // in bin i-1 (starting with bin 0)
132  if ( i > 1 ) {
133  // not in first bin
134  value = pars[i - 2]->unblindValue();
135  break;
136  } else {
137  // in first bin
138  Double_t sum( 0.0 );
139  Double_t binSize( 0.0 );
140  for ( UInt_t j( 2 ); j <= numBins; ++j ) {
141  binSize = limits_[j] - limits_[j - 1];
142  sum += ( pars[j - 2]->unblindValue() * binSize );
143  }
144  binSize = limits_[1] - limits_[0];
145  value = ( 1.0 - sum ) / binSize;
146  break;
147  }
148  }
149  }
150  }
151 
152  this->setUnNormPDFVal( value );
153 
154  // if the parameters are floating then we
155  // need to recalculate the normalisation
156  if ( ! this->cachePDF() && ! this->withinNormCalc() && ! this->withinGeneration() ) {
157  this->calcNorm();
158  }
159 }
160 
162 {
163  this->setNorm( 1.0 );
164 }
165 
167 {
168  if ( this->heightUpToDate() ) {
169  return;
170  }
171 
172  // Get the parameters
173  const std::vector<LauAbsRValue*>& pars = this->getParameters();
174 
175  // Find the PDF height
176  Double_t height( 0.0 );
177  Double_t value( 0.0 );
178  const UInt_t numBins = this->nBins();
179 
180  if ( this->normBin() == Last ) {
181  // the last bin is our normalisation bin
182 
183  // Check through all the parameterised bins
184  for ( UInt_t i( 0 ); i < numBins - 1; ++i ) {
185  value = pars[i]->unblindValue();
186  if ( height < value ) {
187  height = value;
188  }
189  }
190 
191  // Check the last bin
192  Double_t sum( 0.0 );
193  Double_t binSize( 0.0 );
194  for ( UInt_t j( 1 ); j < numBins; ++j ) {
195  binSize = limits_[j] - limits_[j - 1];
196  sum += ( pars[j - 1]->unblindValue() * binSize );
197  }
198  binSize = limits_[numBins] - limits_[numBins - 1];
199  value = ( 1.0 - sum ) / binSize;
200  if ( height < value ) {
201  height = value;
202  }
203  } else {
204  // the first bin is our normalisation bin
205 
206  // Check through all the parameterised bins
207  for ( UInt_t i( 1 ); i < numBins; ++i ) {
208  value = pars[i - 1]->unblindValue();
209  if ( height < value ) {
210  height = value;
211  }
212  }
213 
214  // Check the first bin
215  Double_t sum( 0.0 );
216  Double_t binSize( 0.0 );
217  for ( UInt_t j( 2 ); j <= numBins; ++j ) {
218  binSize = limits_[j] - limits_[j - 1];
219  sum += ( pars[j - 2]->unblindValue() * binSize );
220  }
221  binSize = limits_[1] - limits_[0];
222  value = ( 1.0 - sum ) / binSize;
223  if ( height < value ) {
224  height = value;
225  }
226  }
227 
228  this->setMaxHeight( height );
229 }
Double_t value() const
The value of the parameter.
std::vector< Double_t > limits_
limits of the bins
virtual Bool_t cachePDF() const
Check if the PDF is to be cached.
Definition: LauAbsPdf.hh:299
std::vector< Double_t > LauAbscissas
The type used for containing multiple abscissa values.
Definition: LauAbsPdf.hh:58
virtual Bool_t withinNormCalc() const
Check whether the calcNorm method is running.
Definition: LauAbsPdf.hh:448
virtual ~LauParametricStepFuncPdf()
Destructor.
virtual UInt_t nParameters() const
Retrieve the number of PDF parameters.
Definition: LauAbsPdf.hh:109
virtual void setNorm(Double_t norm)
Set the normalisation factor.
Definition: LauAbsPdf.hh:348
virtual void calcNorm()
Calculate the normalisation.
File containing declaration of LauParametricStepFuncPdf class.
virtual void setUnNormPDFVal(Double_t unNormPDFVal)
Set the unnormalised likelihood.
Definition: LauAbsPdf.hh:394
Class for defining the abstract interface for PDF classes.
Definition: LauAbsPdf.hh:54
virtual Bool_t withinGeneration() const
Check whether the generate method is running.
Definition: LauAbsPdf.hh:460
File containing LauConstants namespace.
UInt_t nBins() const
Number of bins.
virtual void setMaxHeight(Double_t maxHeight)
Set the maximum height.
Definition: LauAbsPdf.hh:354
virtual void calcPDFHeight(const LauKinematics *kinematics)
Calculate the PDF height.
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:262
Class for calculating 3-body kinematic quantities.
LauParametricStepFuncPdf(const TString &theVarName, const std::vector< LauAbsRValue * > &params, const std::vector< Double_t > &limits, NormBin normalisationBin=Last)
Constructor.
virtual void calcLikelihoodInfo(const LauAbscissas &abscissas)
Calculate the likelihood (and intermediate info) for a given abscissa.
virtual Bool_t heightUpToDate() const
Check if the maximum height of the PDF is up to date.
Definition: LauAbsPdf.hh:287
NormBin normBin() const
Normalisation bin.
virtual Bool_t checkRange(const LauAbscissas &abscissas) const
Check that all abscissas are within their allowed ranges.
Definition: LauAbsPdf.cc:243
NormBin
Define the allowed options for the normalisation bin.