Changeset View
Changeset View
Standalone View
Standalone View
inc/LauSimFitTask.hh
- This file was moved from inc/LauSimFitSlave.hh.
Show All 16 Lines | |||||
/* | /* | ||||
Laura++ package authors: | Laura++ package authors: | ||||
John Back | John Back | ||||
Paul Harrison | Paul Harrison | ||||
Thomas Latham | Thomas Latham | ||||
*/ | */ | ||||
/*! \file LauSimFitSlave.hh | /*! \file LauSimFitTask.hh | ||||
\brief File containing declaration of LauSimFitSlave class. | \brief File containing declaration of LauSimFitTask class. | ||||
*/ | */ | ||||
/*! \class LauSimFitSlave | /*! \class LauSimFitTask | ||||
\brief The base class for any slave process for simultaneous/combined fits | \brief The base class for any task 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 base class from which slaves should inherit. | This class acts as the base class from which tasks should inherit. | ||||
This allows any fitting framework to plug in to the JFit method. | This allows any fitting framework to plug in to the JFit method. | ||||
*/ | */ | ||||
#ifndef LAU_SIM_FIT_SLAVE | #ifndef LAU_SIM_FIT_TASK | ||||
#define LAU_SIM_FIT_SLAVE | #define LAU_SIM_FIT_TASK | ||||
#include "TMatrixDfwd.h" | #include "TMatrixDfwd.h" | ||||
#include "LauFitObject.hh" | #include "LauFitObject.hh" | ||||
class TMessage; | class TMessage; | ||||
class TSocket; | class TSocket; | ||||
class TString; | class TString; | ||||
class LauFitNtuple; | class LauFitNtuple; | ||||
class LauSimFitSlave : public LauFitObject { | class LauSimFitTask : public LauFitObject { | ||||
public: | public: | ||||
//! Constructor | //! Constructor | ||||
LauSimFitSlave(); | LauSimFitTask(); | ||||
//! Destructor | //! Destructor | ||||
virtual ~LauSimFitSlave(); | virtual ~LauSimFitTask(); | ||||
//! Obtain the number of slaves | //! Obtain the number of tasks | ||||
UInt_t nSlaves() const {return nSlaves_;} | UInt_t nTasks() const {return nTasks_;} | ||||
//! Obtain the ID number of this slave | //! Obtain the ID number of this task | ||||
UInt_t slaveId() const {return slaveId_;} | UInt_t taskId() const {return taskId_;} | ||||
//! Start the slave process for simultaneous fitting | //! Start the task process for simultaneous fitting | ||||
/*! | /*! | ||||
\param [in] dataFileName the name of the input data file | \param [in] dataFileName the name of the input data file | ||||
\param [in] dataTreeName the name of the tree containing the data | \param [in] dataTreeName the name of the tree containing the data | ||||
\param [in] histFileName the file name for the output histograms | \param [in] histFileName the file name for the output histograms | ||||
\param [in] tableFileName the file name for the latex output file | \param [in] tableFileName the file name for the latex output file | ||||
\param [in] addressMaster the hostname of the machine running the master process | \param [in] addressCoordinator the hostname of the machine running the coordinator process | ||||
\param [in] portMaster the port number on which the master process is listening | \param [in] portCoordinator the port number on which the coordinator process is listening | ||||
*/ | */ | ||||
virtual void runSlave(const TString& dataFileName, const TString& dataTreeName, | virtual void runTask(const TString& dataFileName, const TString& dataTreeName, | ||||
const TString& histFileName, const TString& tableFileName = "", | const TString& histFileName, const TString& tableFileName = "", | ||||
const TString& addressMaster = "localhost", const UInt_t portMaster = 9090); | const TString& addressCoordinator = "localhost", const UInt_t portCoordinator = 9090); | ||||
//! Initialise the fit model | //! Initialise the fit model | ||||
/*! | /*! | ||||
Each class that inherits from this one must implement | Each class that inherits from this one must implement | ||||
this to do what is appropriate | this to do what is appropriate | ||||
*/ | */ | ||||
virtual void initialise() = 0; | virtual void initialise() = 0; | ||||
Show All 9 Lines | class LauSimFitTask : public LauFitObject { | ||||
protected: | protected: | ||||
//! Const access to the fit ntuple | //! Const access to the fit ntuple | ||||
const LauFitNtuple* fitNtuple() const {return fitNtuple_;} | const LauFitNtuple* fitNtuple() const {return fitNtuple_;} | ||||
//! Access to the fit ntuple | //! Access to the fit ntuple | ||||
LauFitNtuple* fitNtuple() {return fitNtuple_;} | LauFitNtuple* fitNtuple() {return fitNtuple_;} | ||||
//! Establish the connection to the master process | //! Establish the connection to the coordinator process | ||||
/*! | /*! | ||||
\param [in] addressMaster the hostname of the machine running the master process | \param [in] addressCoordinator the hostname of the machine running the coordinator process | ||||
\param [in] portMaster the port number on which the master process is listening | \param [in] portCoordinator the port number on which the coordinator process is listening | ||||
*/ | */ | ||||
void connectToMaster( const TString& addressMaster, const UInt_t portMaster ); | void connectToCoordinator( const TString& addressCoordinator, const UInt_t portCoordinator ); | ||||
//! Listen for requests from the master and act accordingly | //! Listen for requests from the coordinator and act accordingly | ||||
void processMasterRequests(); | void processCoordinatorRequests(); | ||||
//! Setup saving of fit results to ntuple/LaTeX table etc. | //! Setup saving of fit results to ntuple/LaTeX table etc. | ||||
/*! | /*! | ||||
Provide here a default implementation that produces an ntuple only. | Provide here a default implementation that produces an ntuple only. | ||||
Derived classes can override as they wish. | Derived classes can override as they wish. | ||||
\param [in] histFileName the file name for the output histograms | \param [in] histFileName the file name for the output histograms | ||||
\param [in] tableFileName the file name for the latex output file | \param [in] tableFileName the file name for the latex output file | ||||
*/ | */ | ||||
virtual void setupResultsOutputs( const TString& histFileName, const TString& tableFileName ); | virtual void setupResultsOutputs( const TString& histFileName, const TString& tableFileName ); | ||||
//! Package the initial fit parameters for transmission to the master | //! Package the initial fit parameters for transmission to the coordinator | ||||
/*! | /*! | ||||
\param [out] array the array to be filled with the LauParameter objects | \param [out] array the array to be filled with the LauParameter objects | ||||
*/ | */ | ||||
virtual void prepareInitialParArray( TObjArray& array ) = 0; | virtual void prepareInitialParArray( TObjArray& array ) = 0; | ||||
//! Perform all finalisation actions | //! Perform all finalisation actions | ||||
/*! | /*! | ||||
- Receive the results of the fit from the master | - Receive the results of the fit from the coordinator | ||||
- Perform any finalisation routines | - Perform any finalisation routines | ||||
- Package the finalised fit parameters for transmission back to the master | - Package the finalised fit parameters for transmission back to the coordinator | ||||
\param [in] fitStat the status of the fit, e.g. status code, EDM, NLL | \param [in] fitStat the status of the fit, e.g. status code, EDM, NLL | ||||
\param [in] parsFromMaster the parameters at the fit minimum | \param [in] parsFromCoordinator the parameters at the fit minimum | ||||
\param [in] covMat the fit covariance matrix | \param [in] covMat the fit covariance matrix | ||||
\param [out] parsToMaster the array to be filled with the finalised LauParameter objects | \param [out] parsToCoordinator the array to be filled with the finalised LauParameter objects | ||||
*/ | */ | ||||
virtual void finaliseExperiment( const LauAbsFitter::FitStatus& fitStat, const TObjArray* parsFromMaster, const TMatrixD* covMat, TObjArray& parsToMaster ) = 0; | virtual void finaliseExperiment( const LauAbsFitter::FitStatus& fitStat, const TObjArray* parsFromCoordinator, const TMatrixD* covMat, TObjArray& parsToCoordinator ) = 0; | ||||
//! Open the input file and verify that all required variables are present | //! Open the input file and verify that all required variables are present | ||||
/*! | /*! | ||||
\param [in] dataFileName the name of the input file | \param [in] dataFileName the name of the input file | ||||
\param [in] dataTreeName the name of the input tree | \param [in] dataTreeName the name of the input tree | ||||
*/ | */ | ||||
virtual Bool_t verifyFitData(const TString& dataFileName, const TString& dataTreeName) = 0; | virtual Bool_t verifyFitData(const TString& dataFileName, const TString& dataTreeName) = 0; | ||||
//! Read in the data for the current experiment | //! Read in the data for the current experiment | ||||
/*! | /*! | ||||
\return the number of events read in | \return the number of events read in | ||||
*/ | */ | ||||
virtual UInt_t readExperimentData() = 0; | virtual UInt_t readExperimentData() = 0; | ||||
//! Cache the input data values to calculate the likelihood during the fit | //! Cache the input data values to calculate the likelihood during the fit | ||||
virtual void cacheInputFitVars() = 0; | virtual void cacheInputFitVars() = 0; | ||||
//! Write out any fit results | //! Write out any fit results | ||||
virtual void writeOutAllFitResults(); | virtual void writeOutAllFitResults(); | ||||
private: | private: | ||||
//! Copy constructor (not implemented) | //! Copy constructor (not implemented) | ||||
LauSimFitSlave(const LauSimFitSlave& rhs); | LauSimFitTask(const LauSimFitTask& rhs); | ||||
//! Copy assignment operator (not implemented) | //! Copy assignment operator (not implemented) | ||||
LauSimFitSlave& operator=(const LauSimFitSlave& rhs); | LauSimFitTask& operator=(const LauSimFitTask& rhs); | ||||
//! A socket to enable parallel setup | //! A socket to enable parallel setup | ||||
TSocket* sMaster_; | TSocket* socketCoordinator_; | ||||
//! Message from master to the slaves | //! Message from coordinator to the tasks | ||||
TMessage* messageFromMaster_; | TMessage* messageFromCoordinator_; | ||||
//! Slave id number | //! Task id number | ||||
UInt_t slaveId_; | UInt_t taskId_; | ||||
//! The total number of slaves | //! The total number of tasks | ||||
UInt_t nSlaves_; | UInt_t nTasks_; | ||||
//! Parameter values array (for reading from the master) | //! Parameter values array (for reading from the coordinator) | ||||
Double_t* parValues_; | Double_t* parValues_; | ||||
//! The fit ntuple | //! The fit ntuple | ||||
LauFitNtuple* fitNtuple_; | LauFitNtuple* fitNtuple_; | ||||
ClassDef(LauSimFitSlave,0); | ClassDef(LauSimFitTask,0); | ||||
}; | }; | ||||
#endif | #endif | ||||