laura is hosted by Hepforge, IPPP Durham
Laura++  3.6.0
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 "LauFormulaPar.hh"
30 
31 #include "LauParameter.hh"
32 #include "LauRandom.hh"
33 
34 #include "TMessage.h"
35 #include "TRandom.h"
36 #include "TSystem.h"
37 
38 #include <cstdlib>
39 #include <iomanip>
40 #include <iostream>
41 #include <vector>
42 
43 LauFormulaPar::LauFormulaPar( const TString& forName,
44  const TString& formula,
45  const std::vector<LauParameter*>& params ) :
46  name_( forName ),
47  formula_( forName, formula ),
48  paramVec_( params ),
49  paramArray_( nullptr ),
50  gaussConstraint_( kFALSE ),
51  constraintTrueMean_( 0.0 ),
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 : "
59  << formula_.GetNpar() << " and the number of LauParameters is : " << nPars
60  << std::endl;
61  gSystem->Exit( EXIT_FAILURE );
62  }
63 
64  if ( formula_.GetNdim() != 0 ) {
65  std::cerr << "ERROR in LauFormulaPar::evaluate : Given formula of dimension: "
66  << formula_.GetNdim() << " and not 0" << std::endl;
67  gSystem->Exit( EXIT_FAILURE );
68  }
69 
70  // Array of input parameters
71  paramArray_ = new Double_t[nPars];
72 }
73 
74 LauFormulaPar::~LauFormulaPar()
75 {
76  delete[] paramArray_;
77 }
78 
80  LauAbsRValue( rhs ),
81  name_( rhs.name_ ),
82  formula_( rhs.formula_ ),
83  paramVec_( rhs.paramVec_ ),
84  paramArray_( nullptr ),
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 : "
94  << formula_.GetNpar() << " and the number of LauParameters is : " << nPars
95  << std::endl;
96  gSystem->Exit( EXIT_FAILURE );
97  }
98 
99  if ( formula_.GetNdim() != 0 ) {
100  std::cerr << "ERROR in LauFormulaPar::evaluate : Given formula of dimension: "
101  << formula_.GetNdim() << " and not 0" << std::endl;
102  gSystem->Exit( EXIT_FAILURE );
103  }
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 
128  }
129  return *this;
130 }
131 
132 Double_t LauFormulaPar::value() const
133 {
134  //Assign vector values to array
135  Int_t nPars = paramVec_.size();
136 
137  for ( Int_t i = 0; i < nPars; ++i ) {
138  paramArray_[i] = paramVec_[i]->value();
139  }
140 
141  return formula_.EvalPar( nullptr, paramArray_ );
142 }
143 
145 {
146  //Assign vector values to array
147  Int_t nPars = paramVec_.size();
148 
149  for ( Int_t i = 0; i < nPars; ++i ) {
150  paramArray_[i] = paramVec_[i]->unblindValue();
151  }
152 
153  return formula_.EvalPar( nullptr, paramArray_ );
154 }
155 
156 Double_t LauFormulaPar::genValue() const
157 {
158  //Assign vector values to array
159  Int_t nPars = paramVec_.size();
160 
161  for ( Int_t i = 0; i < nPars; ++i ) {
162  paramArray_[i] = paramVec_[i]->genValue();
163  }
164 
165  return formula_.EvalPar( nullptr, paramArray_ );
166 }
167 
168 Double_t LauFormulaPar::initValue() const
169 {
170  //Assign vector values to array
171  Int_t nPars = paramVec_.size();
172 
173  for ( Int_t i = 0; i < nPars; ++i ) {
174  paramArray_[i] = paramVec_[i]->initValue();
175  }
176 
177  return formula_.EvalPar( nullptr, paramArray_ );
178 }
179 
180 Bool_t LauFormulaPar::fixed() const
181 {
182  for ( std::vector<LauParameter*>::const_iterator iter = paramVec_.begin();
183  iter != paramVec_.end();
184  ++iter ) {
185  if ( ! ( *iter )->fixed() ) {
186  return kFALSE;
187  }
188  }
189  return kTRUE;
190 }
191 
192 Bool_t LauFormulaPar::blind() const
193 {
194  for ( std::vector<LauParameter*>::const_iterator iter = paramVec_.begin();
195  iter != paramVec_.end();
196  ++iter ) {
197  if ( ( *iter )->blind() ) {
198  return kTRUE;
199  }
200  }
201  return kFALSE;
202 }
203 
204 void LauFormulaPar::addGaussianConstraint( Double_t newGaussMean, Double_t newGaussWidth )
205 {
206  gaussConstraint_ = kTRUE;
207  constraintTrueMean_ = newGaussMean;
208  constraintMean_ = newGaussMean;
209  constraintWidth_ = newGaussWidth;
210 }
211 
213 {
214  gaussConstraint_ = kFALSE;
215 }
216 
218 {
220 }
221 
223 {
224  const Double_t val { this->unblindValue() };
225  const Double_t diff { val - constraintMean_ };
226  const Double_t term { diff * diff };
227 
228  return term / ( 2.0 * constraintWidth_ * constraintWidth_ );
229 }
Double_t constraintWidth_
Width of the Gaussian constraint.
TString name_
The parameter name.
Double_t initValue() const
The initial value of the parameter.
File containing LauRandom namespace.
Class for defining combinations of fit parameter objects.
Double_t genValue() const
The value generated for the parameter.
File containing declaration of LauParameter class.
Bool_t fixed() const
Boolean to say if the LauFormulaPar is fixed.
Double_t value() const
Return the value of the LauFormalaPar.
Double_t unblindValue() const
The unblinded value of the parameter.
LauFormulaPar & operator=(const LauFormulaPar &rhs)
Copy assignment operator.
void addGaussianConstraint(Double_t newGaussMean, Double_t newGaussWidth)
Add a Gaussian constraint (or modify an existing one)
LauFormulaPar(const TString &forName, const TString &formula, const std::vector< LauParameter * > &params)
Constructor.
void removeGaussianConstraint()
Remove the Gaussian constraint.
std::vector< LauParameter * > paramVec_
Vector of LauParameters in the formula.
TRandom * randomFun()
Access the singleton random number generator with a particular seed.
Definition: LauRandom.cc:33
Double_t constraintMean_
Mean value of the Gaussian constraint.
Double_t constraintWidth_
Width of the Gaussian constraint.
Bool_t blind() const
The blinding state.
Pure abstract base class for defining a parameter containing an R value.
Definition: LauAbsRValue.hh:45
void generateConstraintMean()
Generate per-experiment constraint mean.
Double_t constraintPenalty() const
The penalty term from the Gaussian constraint.
Double_t constraintTrueMean_
True mean of the Gaussian constraint.
TFormula formula_
The formula.
TString name_
The parameter name.
Double_t constraintTrueMean_
True mean of the Gaussian constraint.
File containing declaration of LauFormulaPar class.
Double_t * paramArray_
Array to hold parameter values to pass to formula.
Double_t constraintMean_
Mean value of the Gaussian constraint.
Bool_t gaussConstraint_
Choice to use Gaussian constraint.
Bool_t gaussConstraint_
Choice to use Gaussian constraint.