laura is hosted by Hepforge, IPPP Durham
Laura++  v3r5
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauChebychevPdf.cc
Go to the documentation of this file.
1 
2 /*
3 Copyright 2009 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/RooChebychev. *
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 
48 #include "TMath.h"
49 #include "TSystem.h"
50 
51 #include "LauChebychevPdf.hh"
52 
54 
55 LauChebychevPdf::LauChebychevPdf(const TString& theVarName, const std::vector<LauAbsRValue*>& params, Double_t minAbscissa, Double_t maxAbscissa) :
56  LauAbsPdf(theVarName, params, minAbscissa, maxAbscissa),
57  coeffs_(params.size(),0)
58 {
59  // Constructor for the Chebychev Polynomial PDF.
60  //
61  // The parameters in params are the coefficients of the polynomial
62  // (polynomial can be anything from 0 to 7 orders).
63  // The last two arguments specify the range in which the PDF is defined, and the PDF
64  // will be normalised w.r.t. these limits.
65 
66  if ( (this->nParameters() > 7) ) {
67  std::cerr << "ERROR in LauChebychevPdf constructor: Too many coeffs - can only cope with order <=7 polynomial." << std::endl;
68  gSystem->Exit(EXIT_FAILURE);
69  }
70 
71  for ( UInt_t i(0); i < this->nParameters(); ++i ) {
72  TString name = "c";
73  name += i+1;
74  coeffs_[i] = this->findParameter( name );
75  }
76 
77  // Cache the normalisation factor
78  this->calcNorm();
79 }
80 
82 {
83  // Destructor
84 }
85 
86 //inline static double p0(double ,double a) { return a; }
87 inline static double p1(double t,double a,double b) { return a*t+b; }
88 inline static double p2(double t,double a,double b,double c) { return p1(t,p1(t,a,b),c); }
89 inline static double p3(double t,double a,double b,double c,double d) { return p2(t,p1(t,a,b),c,d); }
90 //inline static double p4(double t,double a,double b,double c,double d,double e) { return p3(t,p1(t,a,b),c,d,e); }
91 
93 {
94  // Check that the given abscissa is within the allowed range
95  if (!this->checkRange(abscissas)) {
96  gSystem->Exit(EXIT_FAILURE);
97  }
98 
99  // Get our abscissa
100  Double_t abscissa = abscissas[0];
101 
102  Double_t xmin = this->getMinAbscissa();
103  Double_t xmax = this->getMaxAbscissa();
104  Double_t x(-1.0+2.0*(abscissa-xmin)/(xmax-xmin));
105  Double_t x2(x*x);
106  Double_t sum(0) ;
107  switch ( coeffs_.size() ) {
108  case 7: sum += coeffs_[6]->unblindValue()*x*p3(x2,64,-112,56,-7); [[fallthrough]];
109  case 6: sum += coeffs_[5]->unblindValue()*p3(x2,32,-48,18,-1); [[fallthrough]];
110  case 5: sum += coeffs_[4]->unblindValue()*x*p2(x2,16,-20,5); [[fallthrough]];
111  case 4: sum += coeffs_[3]->unblindValue()*p2(x2,8,-8,1); [[fallthrough]];
112  case 3: sum += coeffs_[2]->unblindValue()*x*p1(x2,4,-3); [[fallthrough]];
113  case 2: sum += coeffs_[1]->unblindValue()*p1(x2,2,-1); [[fallthrough]];
114  case 1: sum += coeffs_[0]->unblindValue()*x; [[fallthrough]];
115  case 0: sum +=1;
116  }
117 
118  this->setUnNormPDFVal( sum );
119 
120  // if the parameters are floating then we
121  // need to recalculate the normalisation
122  if (!this->cachePDF() && !this->withinNormCalc() && !this->withinGeneration()) {
123  this->calcNorm();
124  }
125 }
126 
128 {
129  Double_t xmin = this->getMinAbscissa();
130  Double_t xmax = this->getMaxAbscissa();
131 
132  Double_t norm(0) ;
133  switch( coeffs_.size() ) {
134  case 7: case 6: norm += coeffs_[5]->unblindValue()*(-1 + 18./3. - 48./5. + 32./7.); [[fallthrough]];
135  case 5: case 4: norm += coeffs_[3]->unblindValue()*( 1 - 8./3. + 8./5.); [[fallthrough]];
136  case 3: case 2: norm += coeffs_[1]->unblindValue()*(-1 + 2./3.); [[fallthrough]];
137  case 1: case 0: norm += 1;
138  }
139  norm *= xmax-xmin;
140 
141  this->setNorm(norm);
142 }
143 
145 {
146  // TODO - this method can hopefully be improved
147  // At present it scans through the range and then increases by a 20% safety factor
148  // Maybe there's a better way?
149 
150  if (this->heightUpToDate()) {
151  return;
152  }
153 
154  // Calculate the PDF height
155  LauAbscissas maxPoint(1);
156 
157  Double_t minAbs = this->getMinAbscissa();
158  Double_t maxAbs = this->getMaxAbscissa();
159  Double_t range = maxAbs - minAbs;
160  Double_t maxHeight(0.0);
161 
162  // Just scan through the range
163  for ( Double_t point = minAbs; point <= maxAbs; point += range/1000.0 ) {
164  maxPoint[0] = point;
165  this->calcLikelihoodInfo(maxPoint);
166  Double_t heightAtPoint = this->getUnNormLikelihood();
167  if ( heightAtPoint > maxHeight ) {
168  maxHeight = heightAtPoint;
169  }
170  }
171 
172 
173  // Mutliply by 120% to be on the safe side
174  maxHeight *= 1.2;
175 
176  this->setMaxHeight(maxHeight);
177 }
Double_t range() const
The range allowed for the parameter.
virtual void setUnNormPDFVal(Double_t unNormPDFVal)
Set the unnormalised likelihood.
Definition: LauAbsPdf.hh:383
static double p1(double t, double a, double b)
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
Class for defining a Chebychev Polynomial (1st kind) PDF.
ClassImp(LauAbsCoeffSet)
virtual void calcPDFHeight(const LauKinematics *kinematics)
Calculate the PDF height.
const TString & name() const
The parameter name.
std::vector< LauAbsRValue * > coeffs_
Coefficients of polynomial.
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 Bool_t withinNormCalc() const
Check whether the calcNorm method is running.
Definition: LauAbsPdf.hh:437
static double p3(double t, double a, double b, double c, double d)
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
static double p2(double t, double a, double b, double c)
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
virtual ~LauChebychevPdf()
Destructor.
Class for defining the abstract interface for PDF classes.
Definition: LauAbsPdf.hh:55
Class for calculating 3-body kinematic quantities.
File containing declaration of LauChebychevPdf class.
virtual void calcLikelihoodInfo(const LauAbscissas &abscissas)
Calculate the likelihood (and intermediate info) for a given abscissa.
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