laura is hosted by Hepforge, IPPP Durham
Laura++  v2r2
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauSimFitMaster.hh
Go to the documentation of this file.
1 
2 // Copyright University of Warwick 2013 - 2013.
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 
21 #ifndef LAU_SIM_FIT_MASTER
22 #define LAU_SIM_FIT_MASTER
23 
24 #include <map>
25 #include <vector>
26 
27 #include "TMatrixD.h"
28 #include "TMessage.h"
29 #include "TStopwatch.h"
30 #include "TString.h"
31 #include "TVectorDfwd.h"
32 
33 #include "LauFitObject.hh"
34 
35 class TMessage;
36 class TMonitor;
37 class TSocket;
38 class LauAbsRValue;
39 class LauParameter;
40 class LauFitNtuple;
41 
42 
43 class LauSimFitMaster : public LauFitObject {
44 
45  public:
47 
51  LauSimFitMaster( UInt_t numSlaves, UInt_t port = 9090 );
52 
54  virtual ~LauSimFitMaster();
55 
57 
64  void runSimFit( const TString& fitNtupleFileName, UInt_t nExpt, UInt_t firstExpt = 0, Bool_t useAsymmErrors = kFALSE, Bool_t twoStageFit = kFALSE );
65 
67 
75  virtual void withinAsymErrorCalc(Bool_t inAsymErrCalc) { withinAsymErrorCalc_ = inAsymErrCalc; }
76 
78 
85  virtual void setParsFromMinuit(Double_t* par, Int_t npar);
86 
88 
92  virtual Double_t getTotNegLogLikelihood();
93 
95 
101  virtual void addConstraint(const TString& formula, const std::vector<TString>& pars, const Double_t mean, const Double_t width);
102 
103  protected:
105  void printParInfo() const;
106 
108  void initialise();
109 
111  void initSockets();
112 
115 
118 
121 
123  void checkParameter( const LauParameter* param, UInt_t index ) const;
124 
126  void addConParameters();
127 
129  Double_t getLogLikelihoodPenalty();
130 
132 
135  Bool_t readData();
136 
138 
141  Bool_t cacheInputData();
142 
144  void fitExpt( Bool_t useAsymmErrors, Bool_t twoStageFit );
145 
147  void checkInitFitParams();
148 
150  Bool_t finalise();
151 
153  Bool_t writeOutResults();
154 
155 
156  private:
157  // Setup a struct to store information on constrained fit parameters
164  TString formula_;
166  std::vector<TString> conPars_;
168  Double_t mean_;
170  Double_t width_;
171  };
172 
174  std::vector<StoreConstraints> storeCon_;
175 
177  const UInt_t nSlaves_;
178 
180  const UInt_t reqPort_;
181 
183  UInt_t nParams_;
184 
186  UInt_t nFreeParams_;
187 
190 
193 
196 
198  Int_t fitStatus_;
199 
201  UInt_t iExpt_;
202 
204  Double_t NLL_;
205 
207  TMatrixD covMatrix_;
208 
210  std::vector<TMatrixD> covMatrices_;
211 
213  TMonitor* socketMonitor_;
214 
216  std::vector<TSocket*> sSlaves_;
217 
219  std::vector<TMessage*> messagesToSlaves_;
220 
222  TMessage* messageFromSlave_;
223 
225  std::map< TString, UInt_t > parIndices_;
226 
228  std::map< UInt_t, TString > parNames_;
229 
231  std::vector<LauParameter*> params_;
232 
234  std::vector<LauAbsRValue*> conVars_;
235 
237  std::vector<Double_t> parValues_;
238 
240  std::vector< std::vector<UInt_t> > slaveIndices_;
241 
243  std::vector<Double_t*> vectorPar_;
244 
246  std::vector<Double_t> vectorRes_;
247 
249  TStopwatch timer_;
250 
252  TStopwatch cumulTimer_;
253 
256 
258 };
259 
260 #endif
261 
TMonitor * socketMonitor_
Parallel setup monitor.
std::vector< std::vector< UInt_t > > slaveIndices_
Lists of indices for each slave.
std::vector< LauAbsRValue * > conVars_
Gaussian constraints.
Bool_t readData()
Instruct the slaves to read the input data for the given experiment.
ClassDef(LauSimFitMaster, 0)
void getParametersFromSlaves()
Determine/update the parameter initial values from all slaves.
TStopwatch timer_
The fit timer.
std::map< UInt_t, TString > parNames_
Reverse map of index in the values vector to parameter names.
void addConParameters()
Add parameters to the list of Gaussian constrained parameters.
LauFitNtuple * fitNtuple_
The fit results ntuple.
Bool_t writeOutResults()
Instruct the slaves to write out the fit results.
std::vector< LauParameter * > params_
Parameters.
void getParametersFromSlavesFirstTime()
Determine the parameter names and initial values from all slaves.
UInt_t nParams_
The number of fit parameters.
Double_t mean_
The mean value of the Gaussian constraint to be applied.
std::vector< TSocket * > sSlaves_
Sockets for each of the slaves.
const UInt_t reqPort_
The requested port.
std::vector< StoreConstraints > storeCon_
Store the constraints for fit parameters until initialisation is complete.
std::vector< Double_t > vectorRes_
Likelihood values returned from the slaves.
std::map< TString, UInt_t > parIndices_
Map of parameter names to index in the values vector.
Bool_t withinAsymErrorCalc_
Flag to indicate if the asymmetric error calculation (e.g. MINOS) is currently running.
void initSockets()
Initialise socket connections for the slaves.
Struct to store constraint information until the fit is run.
std::vector< TString > conPars_
The list of LauParameter names to be used in the LauFormulaPar.
UInt_t numberBadFits_
The number of fit failures.
TMatrixD covMatrix_
The fit covariance matrix.
Double_t getLogLikelihoodPenalty()
Calculate the penalty terms to the log likelihood from Gaussian constraints.
void checkInitFitParams()
Instruct the slaves to update the initial fit parameter values, if required.
virtual void addConstraint(const TString &formula, const std::vector< TString > &pars, const Double_t mean, const Double_t width)
Store constraint information for fit parameters.
std::vector< Double_t * > vectorPar_
Parameter values to send to the slaves.
void updateParametersFromSlaves()
Update and verify the parameter initial values from all slaves.
std::vector< TMatrixD > covMatrices_
The covariance sub-matrices for each slave.
std::vector< TMessage * > messagesToSlaves_
Messages to slaves.
void checkParameter(const LauParameter *param, UInt_t index) const
Check for compatibility between two same-named parameters, which should therefore be identical...
Class for defining the fit parameter objects.
Definition: LauParameter.hh:33
void fitExpt(Bool_t useAsymmErrors, Bool_t twoStageFit)
Perform the fit for the current experiment.
TString formula_
The formula to be used in the LauFormulaPar.
Int_t fitStatus_
The status of the current fit.
The master process for simultaneous/combined fits.
Bool_t finalise()
Return the final parameters to the slaves and instruct them to perform their finalisation.
TStopwatch cumulTimer_
The total fit timer.
virtual void setParsFromMinuit(Double_t *par, Int_t npar)
This function sets the parameter values from Minuit.
std::vector< Double_t > parValues_
Parameter values.
const UInt_t nSlaves_
The number of slaves.
void runSimFit(const TString &fitNtupleFileName, UInt_t nExpt, UInt_t firstExpt=0, Bool_t useAsymmErrors=kFALSE, Bool_t twoStageFit=kFALSE)
Run the fit.
File containing declaration of LauFitObject class.
Double_t width_
The width of the Gaussian constraint to be applied.
UInt_t nFreeParams_
The number of free fit parameters.
Class to store the results from the fit into an ntuple.
Definition: LauFitNtuple.hh:42
virtual void withinAsymErrorCalc(Bool_t inAsymErrCalc)
Mark that the fit is calculating asymmetric errors.
TMessage * messageFromSlave_
Message from slaves to the master.
Bool_t cacheInputData()
Instruct the slaves to perform the caching.
Double_t NLL_
The negative log-likelihood.
void initialise()
Initialise.
virtual Double_t getTotNegLogLikelihood()
Calculate the new value of the negative log likelihood.
UInt_t iExpt_
The experiment number of the current fit.
Pure abstract base class for defining a parameter containing an R value.
Definition: LauAbsRValue.hh:29
virtual ~LauSimFitMaster()
Destructor.
UInt_t numberOKFits_
The number of successful fits.
The abstract interface for the objects that control the calculation of the likelihood.
Definition: LauFitObject.hh:26
LauSimFitMaster(UInt_t numSlaves, UInt_t port=9090)
Constructor.
void printParInfo() const
Print information on the parameters.