Changeset View
Changeset View
Standalone View
Standalone View
inc/LauSimFitCoordinator.hh
- This file was moved from inc/LauSimFitMaster.hh.
Show All 16 Lines | |||||
/* | /* | ||||
Laura++ package authors: | Laura++ package authors: | ||||
John Back | John Back | ||||
Paul Harrison | Paul Harrison | ||||
Thomas Latham | Thomas Latham | ||||
*/ | */ | ||||
/*! \file LauSimFitMaster.hh | /*! \file LauSimFitCoordinator.hh | ||||
\brief File containing declaration of LauSimFitMaster class. | \brief File containing declaration of LauSimFitCoordinator class. | ||||
*/ | */ | ||||
/*! \class LauSimFitMaster | /*! \class LauSimFitCoordinator | ||||
\brief The master process for simultaneous/combined fits | \brief The coordinator process for simultaneous/combined fits | ||||
Implementation of the JFit method described in arXiv:1409.5080 [physics.data-an]. | Implementation of the JFit method described in arXiv:1409.5080 [physics.data-an]. | ||||
This class acts as the interface between the slave processes and the minimiser. | This class acts as the interface between the task processes and the minimiser. | ||||
*/ | */ | ||||
#ifndef LAU_SIM_FIT_MASTER | #ifndef LAU_SIM_FIT_COORDINATOR | ||||
#define LAU_SIM_FIT_MASTER | #define LAU_SIM_FIT_COORDINATOR | ||||
#include <map> | #include <map> | ||||
#include <vector> | #include <vector> | ||||
#include "TMatrixD.h" | #include "TMatrixD.h" | ||||
#include "TStopwatch.h" | #include "TStopwatch.h" | ||||
#include "TString.h" | #include "TString.h" | ||||
#include "LauFitObject.hh" | #include "LauFitObject.hh" | ||||
class TMessage; | class TMessage; | ||||
class TMonitor; | class TMonitor; | ||||
class TSocket; | class TSocket; | ||||
class LauAbsRValue; | class LauAbsRValue; | ||||
class LauParameter; | class LauParameter; | ||||
class LauFitNtuple; | class LauFitNtuple; | ||||
class LauSimFitMaster : public LauFitObject { | class LauSimFitCoordinator : public LauFitObject { | ||||
public: | public: | ||||
//! Constructor | //! Constructor | ||||
/*! | /*! | ||||
\param [in] numSlaves the number of slaves processes to expect connections from | \param [in] numTasks the number of tasks processes to expect connections from | ||||
\param [in] port the port on which to listen for connections from the slaves | \param [in] port the port on which to listen for connections from the tasks | ||||
*/ | */ | ||||
LauSimFitMaster( UInt_t numSlaves, UInt_t port = 9090 ); | LauSimFitCoordinator( UInt_t numTasks, UInt_t port = 9090 ); | ||||
//! Destructor | //! Destructor | ||||
virtual ~LauSimFitMaster(); | virtual ~LauSimFitCoordinator(); | ||||
//! Run the fit | //! Run the fit | ||||
/*! | /*! | ||||
\param [in] fitNtupleFileName the file to which the ntuple containing the fit results should be written | \param [in] fitNtupleFileName the file to which the ntuple containing the fit results should be written | ||||
\param [in] nExp the number of experiments to be fitted | \param [in] nExp the number of experiments to be fitted | ||||
\param [in] firstExp the ID of the first experiment to be fitted | \param [in] firstExp the ID of the first experiment to be fitted | ||||
\param [in] useAsymmErrors should asymmetric errors be calculated or not | \param [in] useAsymmErrors should asymmetric errors be calculated or not | ||||
\param [in] doTwoStageFit should the fit be performed in two stages or not | \param [in] doTwoStageFit should the fit be performed in two stages or not | ||||
Show All 33 Lines | class LauSimFitCoordinator : public LauFitObject { | ||||
protected: | protected: | ||||
//! Print information on the parameters | //! Print information on the parameters | ||||
void printParInfo() const; | void printParInfo() const; | ||||
//! Initialise | //! Initialise | ||||
void initialise(); | void initialise(); | ||||
//! Initialise socket connections for the slaves | //! Initialise socket connections for the tasks | ||||
void initSockets(); | void initSockets(); | ||||
//! Determine/update the parameter initial values from all slaves | //! Determine/update the parameter initial values from all tasks | ||||
void getParametersFromSlaves(); | void getParametersFromTasks(); | ||||
//! Determine the parameter names and initial values from all slaves | //! Determine the parameter names and initial values from all tasks | ||||
void getParametersFromSlavesFirstTime(); | void getParametersFromTasksFirstTime(); | ||||
//! Update and verify the parameter initial values from all slaves | //! Update and verify the parameter initial values from all tasks | ||||
void updateParametersFromSlaves(); | void updateParametersFromTasks(); | ||||
//! Check for compatibility between two same-named parameters, which should therefore be identical | //! Check for compatibility between two same-named parameters, which should therefore be identical | ||||
void checkParameter( const LauParameter* param, UInt_t index ) const; | void checkParameter( const LauParameter* param, UInt_t index ) const; | ||||
//! Add parameters to the list of Gaussian constrained parameters | //! Add parameters to the list of Gaussian constrained parameters | ||||
void addConParameters(); | void addConParameters(); | ||||
//! Calculate the penalty terms to the log likelihood from Gaussian constraints | //! Calculate the penalty terms to the log likelihood from Gaussian constraints | ||||
Double_t getLogLikelihoodPenalty(); | Double_t getLogLikelihoodPenalty(); | ||||
//! Instruct the slaves to read the input data for the given experiment | //! Instruct the tasks to read the input data for the given experiment | ||||
/*! | /*! | ||||
\return success/failure of the reading operations | \return success/failure of the reading operations | ||||
*/ | */ | ||||
Bool_t readData(); | Bool_t readData(); | ||||
//! Instruct the slaves to perform the caching | //! Instruct the tasks to perform the caching | ||||
/*! | /*! | ||||
\return success/failure of the caching operations | \return success/failure of the caching operations | ||||
*/ | */ | ||||
Bool_t cacheInputData(); | Bool_t cacheInputData(); | ||||
//! Perform the fit for the current experiment | //! Perform the fit for the current experiment | ||||
void fitExpt(); | void fitExpt(); | ||||
//! Instruct the slaves to update the initial fit parameter values, if required | //! Instruct the tasks to update the initial fit parameter values, if required | ||||
void checkInitFitParams(); | void checkInitFitParams(); | ||||
//! Return the final parameters to the slaves and instruct them to perform their finalisation | //! Return the final parameters to the tasks and instruct them to perform their finalisation | ||||
Bool_t finalise(); | Bool_t finalise(); | ||||
//! Instruct the slaves to write out the fit results | //! Instruct the tasks to write out the fit results | ||||
Bool_t writeOutResults(); | Bool_t writeOutResults(); | ||||
private: | private: | ||||
//! Copy constructor (not implemented) | //! Copy constructor (not implemented) | ||||
LauSimFitMaster(const LauSimFitMaster& rhs); | LauSimFitCoordinator(const LauSimFitCoordinator& rhs); | ||||
//! Copy assignment operator (not implemented) | //! Copy assignment operator (not implemented) | ||||
LauSimFitMaster& operator=(const LauSimFitMaster& rhs); | LauSimFitCoordinator& operator=(const LauSimFitCoordinator& rhs); | ||||
//! Store the constraints for fit parameters until initialisation is complete | //! Store the constraints for fit parameters until initialisation is complete | ||||
std::vector<StoreConstraints> storeCon_; | std::vector<StoreConstraints> storeCon_; | ||||
//! The number of slaves | //! The number of tasks | ||||
const UInt_t nSlaves_; | const UInt_t nTasks_; | ||||
//! The requested port | //! The requested port | ||||
const UInt_t reqPort_; | const UInt_t reqPort_; | ||||
//! The covariance sub-matrices for each slave | //! The covariance sub-matrices for each task | ||||
std::vector<TMatrixD> covMatrices_; | std::vector<TMatrixD> covMatrices_; | ||||
//! Parallel setup monitor | //! Parallel setup monitor | ||||
TMonitor* socketMonitor_; | TMonitor* socketMonitor_; | ||||
//! Sockets for each of the slaves | //! Sockets for each of the tasks | ||||
std::vector<TSocket*> sSlaves_; | std::vector<TSocket*> socketTasks_; | ||||
//! Messages to slaves | //! Messages to tasks | ||||
std::vector<TMessage*> messagesToSlaves_; | std::vector<TMessage*> messagesToTasks_; | ||||
//! Message from slaves to the master | //! Message from tasks to the coordinator | ||||
TMessage* messageFromSlave_; | TMessage* messageFromTask_; | ||||
//! Map of parameter names to index in the values vector | //! Map of parameter names to index in the values vector | ||||
std::map< TString, UInt_t > parIndices_; | std::map< TString, UInt_t > parIndices_; | ||||
//! Reverse map of index in the values vector to parameter names | //! Reverse map of index in the values vector to parameter names | ||||
std::map< UInt_t, TString > parNames_; | std::map< UInt_t, TString > parNames_; | ||||
//! Parameters | //! Parameters | ||||
std::vector<LauParameter*> params_; | std::vector<LauParameter*> params_; | ||||
//! Gaussian constraints | //! Gaussian constraints | ||||
std::vector<LauAbsRValue*> conVars_; | std::vector<LauAbsRValue*> conVars_; | ||||
//! Parameter values | //! Parameter values | ||||
std::vector<Double_t> parValues_; | std::vector<Double_t> parValues_; | ||||
//! Lists of indices for each slave | //! Lists of indices for each task | ||||
std::vector< std::vector<UInt_t> > slaveIndices_; | std::vector< std::vector<UInt_t> > taskIndices_; | ||||
//! Lists of indices of free parameters for each slave | //! Lists of indices of free parameters for each task | ||||
std::vector< std::vector<UInt_t> > slaveFreeIndices_; | std::vector< std::vector<UInt_t> > taskFreeIndices_; | ||||
//! Parameter values to send to the slaves | //! Parameter values to send to the tasks | ||||
std::vector<Double_t*> vectorPar_; | std::vector<Double_t*> vectorPar_; | ||||
//! Likelihood values returned from the slaves | //! Likelihood values returned from the tasks | ||||
std::vector<Double_t> vectorRes_; | std::vector<Double_t> vectorRes_; | ||||
//! The fit timer | //! The fit timer | ||||
TStopwatch timer_; | TStopwatch timer_; | ||||
//! The total fit timer | //! The total fit timer | ||||
TStopwatch cumulTimer_; | TStopwatch cumulTimer_; | ||||
//! The fit results ntuple | //! The fit results ntuple | ||||
LauFitNtuple* fitNtuple_; | LauFitNtuple* fitNtuple_; | ||||
ClassDef(LauSimFitMaster,0); | ClassDef(LauSimFitCoordinator,0); | ||||
}; | }; | ||||
#endif | #endif | ||||