laura is hosted by Hepforge, IPPP Durham
Laura++  v3r3
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  // Check length of vector matches number of parameter in the formula
42  Int_t nPars = paramVec_.size();
43  if (formula_.GetNpar() != nPars){
44  std::cerr<<"ERROR in LauFormulaPar::evaluate : Number of parameters in the formula is : "<<formula_.GetNpar()<< " and the number of LauParameters is : "<<nPars<<std::endl;
45  gSystem->Exit(EXIT_FAILURE);
46  }
47 
48  if (formula_.GetNdim() != 1){
49  std::cerr<<"ERROR in LauFormulaPar::evaluate : Given formula of dimension: "<<formula_.GetNdim()<<" and not 1"<<std::endl;
50  gSystem->Exit(EXIT_FAILURE);
51  }
52 
53  // Dummy array for TFormula
54  dummy_ = new Double_t[1];
55 
56  // Array of input parameters
57  paramArray_ = new Double_t[nPars];
58 }
59 
61 {
62  delete[] dummy_;
63  delete[] paramArray_;
64 }
65 
67  name_(rhs.name_),
68  formula_(rhs.formula_),
69  paramVec_(rhs.paramVec_),
70  dummy_(0),
71  paramArray_(0),
75 {
76  // Check length of vector matches number of parameter in the formula
77  Int_t nPars = paramVec_.size();
78  if (formula_.GetNpar() != nPars){
79  std::cerr<<"ERROR in LauFormulaPar::evaluate : Number of parameters in the formula is : "<<formula_.GetNpar()<< " and the number of LauParameters is : "<<nPars<<std::endl;
80  gSystem->Exit(EXIT_FAILURE);
81  }
82 
83  if (formula_.GetNdim() != 1){
84  std::cerr<<"ERROR in LauFormulaPar::evaluate : Given formula of dimension: "<<formula_.GetNdim()<<" and not 1"<<std::endl;
85  gSystem->Exit(EXIT_FAILURE);
86  }
87 
88  // Dummy array for TFormula
89  dummy_ = new Double_t[1];
90 
91  // Array of input parameters
92  paramArray_ = new Double_t[nPars];
93 }
94 
96 {
97  if ( &rhs != this ) {
98  name_ = rhs.name_;
99  formula_ = rhs.formula_;
100 
101  Int_t nOldPars = paramVec_.size();
102  Int_t nNewPars = rhs.paramVec_.size();
103 
104  paramVec_ = rhs.paramVec_;
105  if ( nOldPars != nNewPars ) {
106  delete [] paramArray_;
107  paramArray_ = new Double_t[nNewPars];
108  }
109 
110  // NB no need to recreate dummy_
111 
115  }
116  return *this;
117 }
118 
119 Double_t LauFormulaPar::value() const
120 {
121  //Assign vector values to array
122  Int_t nPars = paramVec_.size();
123 
124  for(Int_t i=0; i<nPars; ++i){
125  paramArray_[i] = paramVec_[i]->value();
126  }
127 
128  return formula_.EvalPar(dummy_,paramArray_);
129 }
130 
132 {
133  //Assign vector values to array
134  Int_t nPars = paramVec_.size();
135 
136  for(Int_t i=0; i<nPars; ++i){
137  paramArray_[i] = paramVec_[i]->unblindValue();
138  }
139 
140  return formula_.EvalPar(dummy_,paramArray_);
141 }
142 
143 Bool_t LauFormulaPar::fixed() const
144 {
145  for ( std::vector<LauParameter*>::const_iterator iter = paramVec_.begin(); iter != paramVec_.end(); ++iter ) {
146  if ( !(*iter)->fixed() ) { return kFALSE; }
147  }
148  return kTRUE;
149 }
150 
151 void LauFormulaPar::addGaussianConstraint(Double_t newGaussMean, Double_t newGaussWidth)
152 {
153  gaussConstraint_ = kTRUE;
154  constraintMean_ = newGaussMean;
155  constraintWidth_ = newGaussWidth;
156 }
157 
159 {
160  gaussConstraint_ = kFALSE;
161 }
162 
File containing declaration of LauFormulaPar class.
Double_t constraintMean_
Mean value of the Gaussian constraint.
Double_t unblindValue() const
The unblinded value of the parameter.
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.
LauFormulaPar(const TString &forName, const TString &formula, const std::vector< LauParameter * > &params)
Constructor.
Bool_t fixed() const
Boolean to say if the LauFormulaPar is fixed.
TString name_
The parameter name.
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:35
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.
LauFormulaPar & operator=(const LauFormulaPar &rhs)
Copy assignment operator.
Double_t constraintWidth_
Width of the Gaussian constraint.
Pure abstract base class for defining a parameter containing an R value.
Definition: LauAbsRValue.hh:29
Double_t value() const
Return the value of the LauFormalaPar.