laura is hosted by Hepforge, IPPP Durham
Laura++  v2r1
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauFormulaPar.cc
Go to the documentation of this file.
1 
2 // Copyright University of Warwick 2013 - 2014.
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 #include <iostream>
16 #include <iomanip>
17 #include <vector>
18 #include <cstdlib>
19 
20 #include "TRandom.h"
21 #include "TMessage.h"
22 #include "TSystem.h"
23 
24 #include "LauFormulaPar.hh"
25 #include "LauParameter.hh"
26 #include "LauRandom.hh"
27 
29 
30 
31  LauFormulaPar::LauFormulaPar(const TString& forName, const TString& formula, const std::vector<LauParameter*>& params) :
32  name_(forName),
33  formula_(forName,formula),
34  paramVec_(params),
35  dummy_(0),
36  paramArray_(0),
37  gaussConstraint_(kFALSE),
38  constraintMean_(0.0),
39  constraintWidth_(0.0)
40 {
41  // Dummy array for TFormula
42  dummy_ = new Double_t[1];
43 
44  // Array of input parameters
45  Int_t nPars = paramVec_.size();
46 
47  // Check length of vector matches number of parameter in the formula
48  if (formula_.GetNpar() != nPars){
49  std::cerr<<"ERROR in LauFormulaPar::evaluate : Number of parameters in the formula is : "<<formula_.GetNpar()<< " and the number of LauParameters is : "<<nPars<<std::endl;
50  gSystem->Exit(EXIT_FAILURE);
51  }
52 
53  paramArray_ = new Double_t[nPars];
54 
55  if (formula_.GetNdim() != 1){
56  std::cerr<<"ERROR in LauFormulaPar::evaluate : Given formula of dimension: "<<formula_.GetNdim()<<" and not 1"<<std::endl;
57  gSystem->Exit(EXIT_FAILURE);
58  }
59 }
60 
62 {
63  delete[] dummy_;
64  delete[] paramArray_;
65 }
66 
67 Double_t LauFormulaPar::value() const
68 {
69 
70  //Assign vector values to array
71  Int_t nPars = paramVec_.size();
72 
73  for(Int_t i=0; i<nPars; ++i){
74  paramArray_[i] = paramVec_[i]->value();
75  }
76 
77  return formula_.EvalPar(dummy_,paramArray_);
78 }
79 
80 Bool_t LauFormulaPar::fixed() const
81 {
82  for ( std::vector<LauParameter*>::const_iterator iter = paramVec_.begin(); iter != paramVec_.end(); ++iter ) {
83  if ( !(*iter)->fixed() ) { return kFALSE; }
84  }
85  return kTRUE;
86 }
87 
88 void LauFormulaPar::addGaussianConstraint(Double_t newGaussMean, Double_t newGaussWidth)
89 {
90  gaussConstraint_ = kTRUE;
91  constraintMean_ = newGaussMean;
92  constraintWidth_ = newGaussWidth;
93 }
94 
96 {
97  gaussConstraint_ = kFALSE;
98 }
99 
File containing declaration of LauFormulaPar class.
Double_t constraintMean_
Mean value of the Gaussian constraint.
ClassImp(LauAbsCoeffSet)
Class for defining combinations of fit parameter objects.
virtual ~LauFormulaPar()
std::vector< LauParameter * > paramVec_
Vector of LauParameters in the formula.
Bool_t gaussConstraint_
Choice to use Gaussian constraint.
Bool_t fixed() const
Boolean to say if the LauFormulaPar is fixed.
TFormula formula_
The formula.
void addGaussianConstraint(Double_t newGaussMean, Double_t newGaussWidth)
Add a Gaussian constraint (or modify an existing one)
Double_t * dummy_
Array.
File containing declaration of LauParameter class.
Double_t constraintMean_
Mean value of the Gaussian constraint.
Double_t * paramArray_
Array.
Class for defining the fit parameter objects.
Definition: LauParameter.hh:33
File containing LauRandom namespace.
Double_t constraintWidth_
Width of the Gaussian constraint.
Bool_t gaussConstraint_
Choice to use Gaussian constraint.
void removeGaussianConstraint()
Remove the Gaussian constraint.
TString name_
The parameter name.
Double_t constraintWidth_
Width of the Gaussian constraint.
Double_t value() const
Return the value of the LauFormalaPar.