laura is hosted by Hepforge, IPPP Durham
Laura++  3.6.0
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauFitObject.hh
Go to the documentation of this file.
1 
2 /*
3 Copyright 2013 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 #ifndef LAU_FIT_OBJECT
30 #define LAU_FIT_OBJECT
31 
32 #include "LauAbsFitter.hh"
33 #include "LauFormulaPar.hh"
34 
35 #include "TMatrixD.h"
36 #include "TObject.h"
37 #include "TString.h"
38 #include "TVectorD.h"
39 
40 #include <set>
41 #include <vector>
42 
47 class LauFitObject : public TObject {
48 
49  public:
51  virtual ~LauFitObject() = default;
52 
54 
57  void useAsymmFitErrors( Bool_t useAsymmErrors ) { useAsymmFitErrors_ = useAsymmErrors; }
58 
60  Bool_t useAsymmFitErrors() const { return useAsymmFitErrors_; }
61 
63 
73  void twoStageFit( Bool_t doTwoStageFit ) { twoStageFit_ = doTwoStageFit; }
74 
76  Bool_t twoStageFit() const { return twoStageFit_; }
77 
79 
85  virtual void withinAsymErrorCalc( const Bool_t inAsymErrCalc )
86  {
87  withinAsymErrorCalc_ = inAsymErrCalc;
88  }
89 
91 
94  Bool_t withinAsymErrorCalc() const { return withinAsymErrorCalc_; }
95 
97 
106  void setNExpts( UInt_t nExperiments, UInt_t firstExperiment, Bool_t toyExpts );
107 
109  UInt_t eventsPerExpt() const { return evtsPerExpt_; }
110 
112  UInt_t nExpt() const { return nExpt_; }
113 
115  UInt_t firstExpt() const { return firstExpt_; }
116 
118  UInt_t iExpt() const { return iExpt_; }
119 
121  Bool_t toyExpts() const { return toyExpts_; }
122 
124 
131  virtual void setParsFromMinuit( Double_t* par, Int_t npar ) = 0;
132 
134 
138  virtual Double_t getTotNegLogLikelihood() = 0;
139 
141 
149  void addConstraint( const TString& formula,
150  const std::vector<TString>& pars,
151  const Double_t mean,
152  const Double_t width );
153 
155 
161  void addFormulaConstraint( const TString& formula,
162  const std::vector<TString>& pars,
163  const Double_t mean,
164  const Double_t width );
165 
167 
172  void addMultiDimConstraint( const std::vector<TString>& pars,
173  const TVectorD& means,
174  const TMatrixD& covMat );
175 
176  protected:
178  LauFitObject();
179 
184  enum class ConstraintType {
185  Formula,
186  MultDim
187  };
188 
189  // Setup a struct to store information on constrained fit parameters
196  TString formula_;
198  std::vector<TString> conPars_;
200  Double_t mean_;
202  Double_t width_;
204  std::unique_ptr<LauFormulaPar> formulaPar_;
205  };
206 
207  // Setup a class to store information on n-dimensional constrained fit parameters
213  public:
215  MultiDimConstraint() = default;
216 
218  MultiDimConstraint( const std::vector<TString>& parNames,
219  const TVectorD& means,
220  const TMatrixD& covMat );
221 
223  Double_t constraintPenalty() const;
224 
227 
229  std::vector<TString> conPars_;
231  TVectorD trueMeans_;
233  TVectorD means_;
235  TMatrixD invCovMat_;
237  TMatrixD sqrtCovMat_;
239  std::vector<LauParameter*> conLauPars_;
240  };
241 
243 
250  Bool_t checkRepetition( const std::vector<TString>& names, const ConstraintType conType );
251 
253 
262  void generateConstraintMeans( std::vector<LauAbsRValue*>& conVars );
263 
265  const std::vector<FormulaConstraint>& formulaConstraints() const { return formulaConstraints_; }
266 
268  std::vector<FormulaConstraint>& formulaConstraints() { return formulaConstraints_; }
269 
271  const std::vector<MultiDimConstraint>& multiDimConstraints() const
272  {
273  return multiDimConstraints_;
274  }
275 
277  std::vector<MultiDimConstraint>& multiDimConstraints() { return multiDimConstraints_; }
278 
280  const std::set<TString>& formulaConstrainedPars() const { return formulaConstrainedPars_; }
281 
283  std::set<TString>& formulaConstrainedPars() { return formulaConstrainedPars_; }
284 
286  const std::set<TString>& multiDimConstrainedPars() const { return multiDimConstrainedPars_; }
287 
289  std::set<TString>& multiDimConstrainedPars() { return multiDimConstrainedPars_; }
290 
292  void resetFitCounters();
293 
295 
298  void setCurrentExperiment( const UInt_t curExpt ) { iExpt_ = curExpt; }
299 
301 
305  void startNewFit( const UInt_t nPars, const UInt_t nFreePars );
306 
308  void eventsPerExpt( UInt_t nEvents ) { evtsPerExpt_ = nEvents; }
309 
311  Double_t worstLogLike() const { return worstLogLike_; }
312 
314 
317  void worstLogLike( const Double_t newWorstLogLike ) { worstLogLike_ = newWorstLogLike; }
318 
320 
324  void storeFitStatus( const LauAbsFitter::FitStatus& status, const TMatrixD& covMatrix );
325 
327  UInt_t nTotParams() const { return nParams_; }
328 
330  UInt_t nFreeParams() const { return nFreeParams_; }
331 
333  const LauAbsFitter::FitStatus& fitStatus() const { return fitStatus_; }
334 
336  Double_t nll() const { return fitStatus_.NLL; }
337 
339  Double_t edm() const { return fitStatus_.EDM; }
340 
342  Int_t statusCode() const { return fitStatus_.status; }
343 
345  const TMatrixD& covarianceMatrix() const { return covMatrix_; }
346 
348  UInt_t numberOKFits() const { return numberOKFits_; }
349 
351  UInt_t numberBadFits() const { return numberBadFits_; }
352 
353  private:
355  LauFitObject( const LauFitObject& rhs );
356 
359 
361  std::vector<FormulaConstraint> formulaConstraints_;
362 
364  std::vector<MultiDimConstraint> multiDimConstraints_;
365 
367  std::set<TString> formulaConstrainedPars_;
368 
370  std::set<TString> multiDimConstrainedPars_;
371 
373  Bool_t twoStageFit_;
374 
377 
379  UInt_t nParams_;
380 
382  UInt_t nFreeParams_;
383 
386 
388 
389  Bool_t toyExpts_;
390 
392  UInt_t firstExpt_;
393 
395  UInt_t nExpt_;
396 
398  UInt_t iExpt_;
399 
401  UInt_t evtsPerExpt_;
402 
405 
407  Double_t worstLogLike_;
408 
410  TMatrixD covMatrix_;
411 
414 
417 
418  ClassDef( LauFitObject, 0 )
419 };
420 
421 #endif
virtual Double_t getTotNegLogLikelihood()=0
Calculate the new value of the negative log likelihood.
TMatrixD sqrtCovMat_
The Cholesky Decomposition of the covariance matrix of the parameters.
TString formula_
The formula to be used in the LauFormulaPar.
Double_t worstLogLike_
The worst log likelihood value found so far.
UInt_t numberOKFits() const
Access the number of successful fits.
std::set< TString > & formulaConstrainedPars()
Access to the parameter names used in formula constraints.
std::vector< MultiDimConstraint > multiDimConstraints_
Store the ND constraints for fit parameters until initialisation is complete.
Struct to store fit status information.
Definition: LauAbsFitter.hh:54
UInt_t numberBadFits_
The number of fit failures.
std::vector< FormulaConstraint > formulaConstraints_
Store the constraints for fit parameters until initialisation is complete.
UInt_t nFreeParams_
The number of free fit parameters.
@ Formula
Formula-based constraint on a combination of parameters.
std::set< TString > formulaConstrainedPars_
Store the names of all parameters used in all formula constraints.
File containing declaration of LauAbsFitter class.
TVectorD trueMeans_
The true mean values of the constraint.
UInt_t firstExpt() const
Obtain the number of the first experiment.
std::set< TString > multiDimConstrainedPars_
Store the names of all parameters used in all multi-dimensional constraints.
std::vector< FormulaConstraint > & formulaConstraints()
Access to the formula constraints store.
Bool_t useAsymmFitErrors_
Option to use asymmetric errors.
void addMultiDimConstraint(const std::vector< TString > &pars, const TVectorD &means, const TMatrixD &covMat)
Store n-dimensional constraint information for fit parameters.
Bool_t toyExpts() const
Obtain whether this is toy.
UInt_t nParams_
The number of fit parameters.
ConstraintType
Enumeration of the different types of constraint.
void twoStageFit(Bool_t doTwoStageFit)
Turn on or off the two stage fit.
Definition: LauFitObject.hh:73
TMatrixD invCovMat_
The inverse covariance matrix of the parameters.
Bool_t useAsymmFitErrors() const
Report whether or not calculation of asymmetric errors is enabled.
Definition: LauFitObject.hh:60
Class to store n-dimensional constraint information.
Struct to store formula-based constraint information.
std::vector< MultiDimConstraint > & multiDimConstraints()
Access to the ND constraints store.
virtual void setParsFromMinuit(Double_t *par, Int_t npar)=0
This function sets the parameter values from Minuit.
Double_t width_
The width of the Gaussian constraint to be applied.
void storeFitStatus(const LauAbsFitter::FitStatus &status, const TMatrixD &covMatrix)
Store fit status information.
Definition: LauFitObject.cc:93
UInt_t numberBadFits() const
Access the number of failed fits.
const std::set< TString > & multiDimConstrainedPars() const
Const access to the parameter names used in ND constraints.
void resetFitCounters()
Reset the good/bad fit counters.
Definition: LauFitObject.cc:76
Bool_t withinAsymErrorCalc_
Flag to indicate if the asymmetric error calculation (e.g. MINOS) is currently running.
Double_t constraintPenalty() const
Get the penalty term.
Double_t mean_
The mean value of the Gaussian constraint to be applied.
const std::vector< MultiDimConstraint > & multiDimConstraints() const
Const access to the ND constraints store.
LauFitObject(const LauFitObject &rhs)
Copy constructor (not implemented)
const LauAbsFitter::FitStatus & fitStatus() const
Access the fit status information.
void generateConstraintMeans(std::vector< LauAbsRValue * > &conVars)
Generate per-experiment mean for each Gaussian constraint.
std::set< TString > & multiDimConstrainedPars()
Access to the parameter names used in ND constraints.
void useAsymmFitErrors(Bool_t useAsymmErrors)
Turn on or off the computation of asymmetric errors (e.g. MINOS routine in Minuit)
Definition: LauFitObject.hh:57
const std::vector< FormulaConstraint > & formulaConstraints() const
Const access to the formula constraints store.
Bool_t withinAsymErrorCalc() const
Query whether the fit is calculating the asymmetric errors.
Definition: LauFitObject.hh:94
UInt_t iExpt() const
Obtain the number of the current experiment.
MultiDimConstraint()=default
Default constructor.
Int_t statusCode() const
Access the fit status code.
@ MultDim
Multi-dimensional constraint on several parameters.
virtual ~LauFitObject()=default
Destructor.
std::unique_ptr< LauFormulaPar > formulaPar_
The LauFormulaPar pointer.
std::vector< LauParameter * > conLauPars_
The LauParameters used in the constraints.
std::vector< TString > conPars_
The list of LauParameter names to be used in the LauFormulaPar.
Double_t NLL
The negative log-likelihood.
Definition: LauAbsFitter.hh:58
Double_t edm() const
Access the current EDM value.
const std::set< TString > & formulaConstrainedPars() const
Const access to the parameter names used in formula constraints.
void startNewFit(const UInt_t nPars, const UInt_t nFreePars)
Indicate the start of a new fit.
Definition: LauFitObject.cc:83
TVectorD means_
The per-experiment mean values of the constraint.
void generateConstraintMeans()
Generate per-experiment constraint means.
void addConstraint(const TString &formula, const std::vector< TString > &pars, const Double_t mean, const Double_t width)
Store constraint information for fit parameters.
UInt_t evtsPerExpt_
The number of events in the current experiment.
UInt_t nExpt_
The number of experiments to consider.
Bool_t checkRepetition(const std::vector< TString > &names, const ConstraintType conType)
Check if parameters names for constraints have already been used elsewhere.
virtual void withinAsymErrorCalc(const Bool_t inAsymErrCalc)
Mark that the fit is calculating asymmetric errors.
Definition: LauFitObject.hh:85
The abstract interface for the objects that control the calculation of the likelihood.
Definition: LauFitObject.hh:47
const TMatrixD & covarianceMatrix() const
Access the fit covariance matrix.
LauFitObject()
Constructor.
Definition: LauFitObject.cc:41
std::vector< TString > conPars_
The list of LauParameter names to be used in the constraint.
Double_t EDM
The estimated distance to the minimum.
Definition: LauAbsFitter.hh:60
TMatrixD covMatrix_
The fit covariance matrix.
UInt_t nExpt() const
Obtain the number of experiments.
Bool_t twoStageFit_
Option to perform a two stage fit.
UInt_t eventsPerExpt() const
Obtain the total number of events in the current experiment.
LauFitObject & operator=(const LauFitObject &rhs)
Copy assignment operator (not implemented)
Double_t nll() const
Access the current NLL value.
UInt_t nTotParams() const
Access the total number of fit parameters.
Bool_t twoStageFit() const
Report whether the two-stage fit is enabled.
Definition: LauFitObject.hh:76
Int_t status
The status code of the fit.
Definition: LauAbsFitter.hh:56
Bool_t toyExpts_
Flag to indicate whether this is toy.
File containing declaration of LauFormulaPar class.
LauAbsFitter::FitStatus fitStatus_
The status of the current fit.
UInt_t iExpt_
The current experiment number.
UInt_t firstExpt_
The number of the first experiment to consider.
void addFormulaConstraint(const TString &formula, const std::vector< TString > &pars, const Double_t mean, const Double_t width)
Store constraint information for fit parameters.
void setCurrentExperiment(const UInt_t curExpt)
Set the ID of the current experiment.
UInt_t numberOKFits_
The number of successful fits.
void eventsPerExpt(UInt_t nEvents)
Set the number of events in the current experiment.
Double_t worstLogLike() const
Access the worst log likelihood found so far.
UInt_t nFreeParams() const
Access the total number of fit parameters.
void worstLogLike(const Double_t newWorstLogLike)
Set a new value for the worst log likelihood.
void setNExpts(UInt_t nExperiments, UInt_t firstExperiment, Bool_t toyExpts)
Set the number of experiments, the first experiment, and whether this is toy.
Definition: LauFitObject.cc:61