laura is hosted by Hepforge, IPPP Durham
Laura++  v3r4
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauFormulaPar.cc
Go to the documentation of this file.
1 
2 /*
3 Copyright 2014 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 #include <iostream>
30 #include <iomanip>
31 #include <vector>
32 #include <cstdlib>
33 
34 #include "TRandom.h"
35 #include "TMessage.h"
36 #include "TSystem.h"
37 
38 #include "LauFormulaPar.hh"
39 #include "LauParameter.hh"
40 #include "LauRandom.hh"
41 
43 
44 
45 LauFormulaPar::LauFormulaPar(const TString& forName, const TString& formula, const std::vector<LauParameter*>& params) :
46  name_(forName),
47  formula_(forName,formula),
48  paramVec_(params),
49  dummy_(0),
50  paramArray_(0),
51  gaussConstraint_(kFALSE),
52  constraintMean_(0.0),
53  constraintWidth_(0.0)
54 {
55  // Check length of vector matches number of parameter in the formula
56  Int_t nPars = paramVec_.size();
57  if (formula_.GetNpar() != nPars){
58  std::cerr<<"ERROR in LauFormulaPar::evaluate : Number of parameters in the formula is : "<<formula_.GetNpar()<< " and the number of LauParameters is : "<<nPars<<std::endl;
59  gSystem->Exit(EXIT_FAILURE);
60  }
61 
62  if (formula_.GetNdim() != 1){
63  std::cerr<<"ERROR in LauFormulaPar::evaluate : Given formula of dimension: "<<formula_.GetNdim()<<" and not 1"<<std::endl;
64  gSystem->Exit(EXIT_FAILURE);
65  }
66 
67  // Dummy array for TFormula
68  dummy_ = new Double_t[1];
69 
70  // Array of input parameters
71  paramArray_ = new Double_t[nPars];
72 }
73 
75 {
76  delete[] dummy_;
77  delete[] paramArray_;
78 }
79 
81  name_(rhs.name_),
82  formula_(rhs.formula_),
83  paramVec_(rhs.paramVec_),
84  dummy_(0),
85  paramArray_(0),
89 {
90  // Check length of vector matches number of parameter in the formula
91  Int_t nPars = paramVec_.size();
92  if (formula_.GetNpar() != nPars){
93  std::cerr<<"ERROR in LauFormulaPar::evaluate : Number of parameters in the formula is : "<<formula_.GetNpar()<< " and the number of LauParameters is : "<<nPars<<std::endl;
94  gSystem->Exit(EXIT_FAILURE);
95  }
96 
97  if (formula_.GetNdim() != 1){
98  std::cerr<<"ERROR in LauFormulaPar::evaluate : Given formula of dimension: "<<formula_.GetNdim()<<" and not 1"<<std::endl;
99  gSystem->Exit(EXIT_FAILURE);
100  }
101 
102  // Dummy array for TFormula
103  dummy_ = new Double_t[1];
104 
105  // Array of input parameters
106  paramArray_ = new Double_t[nPars];
107 }
108 
110 {
111  if ( &rhs != this ) {
112  name_ = rhs.name_;
113  formula_ = rhs.formula_;
114 
115  Int_t nOldPars = paramVec_.size();
116  Int_t nNewPars = rhs.paramVec_.size();
117 
118  paramVec_ = rhs.paramVec_;
119  if ( nOldPars != nNewPars ) {
120  delete [] paramArray_;
121  paramArray_ = new Double_t[nNewPars];
122  }
123 
124  // NB no need to recreate dummy_
125 
129  }
130  return *this;
131 }
132 
133 Double_t LauFormulaPar::value() const
134 {
135  //Assign vector values to array
136  Int_t nPars = paramVec_.size();
137 
138  for(Int_t i=0; i<nPars; ++i){
139  paramArray_[i] = paramVec_[i]->value();
140  }
141 
142  return formula_.EvalPar(dummy_,paramArray_);
143 }
144 
146 {
147  //Assign vector values to array
148  Int_t nPars = paramVec_.size();
149 
150  for(Int_t i=0; i<nPars; ++i){
151  paramArray_[i] = paramVec_[i]->unblindValue();
152  }
153 
154  return formula_.EvalPar(dummy_,paramArray_);
155 }
156 
157 Double_t LauFormulaPar::genValue() const
158 {
159  //Assign vector values to array
160  Int_t nPars = paramVec_.size();
161 
162  for(Int_t i=0; i<nPars; ++i){
163  paramArray_[i] = paramVec_[i]->genValue();
164  }
165 
166  return formula_.EvalPar(dummy_,paramArray_);
167 }
168 
169 Double_t LauFormulaPar::initValue() const
170 {
171  //Assign vector values to array
172  Int_t nPars = paramVec_.size();
173 
174  for(Int_t i=0; i<nPars; ++i){
175  paramArray_[i] = paramVec_[i]->initValue();
176  }
177 
178  return formula_.EvalPar(dummy_,paramArray_);
179 }
180 
181 Bool_t LauFormulaPar::fixed() const
182 {
183  for ( std::vector<LauParameter*>::const_iterator iter = paramVec_.begin(); iter != paramVec_.end(); ++iter ) {
184  if ( !(*iter)->fixed() ) { return kFALSE; }
185  }
186  return kTRUE;
187 }
188 
189 Bool_t LauFormulaPar::blind() const
190 {
191  for ( std::vector<LauParameter*>::const_iterator iter = paramVec_.begin(); iter != paramVec_.end(); ++iter ) {
192  if ( (*iter)->blind() ) { return kTRUE; }
193  }
194  return kFALSE;
195 }
196 
197 void LauFormulaPar::addGaussianConstraint(Double_t newGaussMean, Double_t newGaussWidth)
198 {
199  gaussConstraint_ = kTRUE;
200  constraintMean_ = newGaussMean;
201  constraintWidth_ = newGaussWidth;
202 }
203 
205 {
206  gaussConstraint_ = kFALSE;
207 }
208 
File containing declaration of LauFormulaPar class.
Double_t initValue() const
The initial value of the parameter.
Double_t constraintMean_
Mean value of the Gaussian constraint.
Double_t unblindValue() const
The unblinded value of the parameter.
Bool_t blind() const
The blinding state.
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 genValue() const
The value generated for the parameter.
Double_t * paramArray_
Array.
Class for defining the fit parameter objects.
Definition: LauParameter.hh:49
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:43
Double_t value() const
Return the value of the LauFormalaPar.