LauSimFitMaster.cc
Go to the documentation of this file.
68 for ( std::vector<TSocket*>::iterator iter = sSlaves_.begin(); iter != sSlaves_.end(); ++iter ) {
76 for (std::vector<LauAbsRValue*>::iterator iter = conVars_.begin(); iter != conVars_.end(); ++iter){
85 for ( std::vector<LauParameter*>::iterator iter = params_.begin(); iter != params_.end(); ++iter ) {
90 for ( std::vector<Double_t*>::iterator iter = vectorPar_.begin(); iter != vectorPar_.end(); ++iter ) {
97 for ( std::vector<TMessage*>::iterator iter = messagesToSlaves_.begin(); iter != messagesToSlaves_.end(); ++iter ) {
108 std::cerr << "ERROR in LauSimFitMaster::initSockets : Sockets already initialised." << std::endl;
112 //initialise socket connection, then accept a connection and return a full-duplex communication socket.
118 std::cout << "INFO in LauSimFitMaster::initSockets : Waiting for connection with " << nSlaves_ << " workers on port " << actual_port << std::endl;
145 * OLD VERSION THAT JUST GETS THE NAMES - COULD HAVE A SERIES OF EXCHANGES TO GET THE NAMES, INIT VALUES, RANGES, ETC. INSTEAD OF PASSING PARAMETERS
146 * THIS INCREASES THE GENERALITY OF THE CODE, I.E. THERE IS NO NEED FOR THE SLAVES TO KNOW ANY LAURA++ CLASS BUT THIS ONE, BUT MAKES IT RATHER MORE DENSE
147 * FOR THE MOMENT I WILL STICK WITH THE METHOD OF PASSING LAUPARAMETER OBJECTS AROUND AND CONSIDER GOING BACK TO THIS GENERAL METHOD ONCE EVERYTHING IS WORKING
161 // Wait to receive the response and check that it has come from the slave we just requested from
164 std::cerr << "ERROR in LauSimFitMaster::getParametersFromSlavesFirstTime : Received message from a different slave than expected!" << std::endl;
170 TObjArray * objarray = dynamic_cast<TObjArray*>( messageFromSlave_->ReadObject( messageFromSlave_->GetClass() ) );
172 std::cerr << "ERROR in LauSimFitMaster::getParametersFromSlavesFirstTime : Error reading parameter names from slave" << std::endl;
180 std::cerr << "ERROR in LauSimFitMaster::getParametersFromSlavesFirstTime : Error reading parameter names from slave" << std::endl;
209 std::cerr << "ERROR in LauSimFitMaster::getParametersFromSlaves : Sockets not initialised." << std::endl;
236 // Wait to receive the response and check that it has come from the slave we just requested from
239 std::cerr << "ERROR in LauSimFitMaster::updateParametersFromSlaves : Received message from a different slave than expected!" << std::endl;
245 TObjArray * objarray = dynamic_cast<TObjArray*>( messageFromSlave_->ReadObject( messageFromSlave_->GetClass() ) );
247 std::cerr << "ERROR in LauSimFitMaster::updateParametersFromSlaves : Error reading parameter names from slave" << std::endl;
256 std::cerr << "ERROR in LauSimFitMaster::updateParametersFromSlaves : Unexpected number of parameters received from slave" << std::endl;
263 std::cerr << "ERROR in LauSimFitMaster::updateParametersFromSlaves : Error reading parameter from slave" << std::endl;
272 std::cerr << "ERROR in LauSimFitMaster::updateParametersFromSlaves : Unexpected parameter name received from slave" << std::endl;
278 std::cerr << "ERROR in LauSimFitMaster::updateParametersFromSlaves : Unexpected parameter received from slave" << std::endl;
310 // Wait to receive the response and check that it has come from the slave we just requested from
313 std::cerr << "ERROR in LauSimFitMaster::getParametersFromSlavesFirstTime : Received message from a different slave than expected!" << std::endl;
319 TObjArray * objarray = dynamic_cast<TObjArray*>( messageFromSlave_->ReadObject( messageFromSlave_->GetClass() ) );
321 std::cerr << "ERROR in LauSimFitMaster::getParametersFromSlavesFirstTime : Error reading parameters from slave" << std::endl;
332 std::cerr << "ERROR in LauSimFitMaster::getParametersFromSlavesFirstTime : Error reading parameter from slave" << std::endl;
367 std::cout << "INFO in LauSimFitMaster::printParInfo : Slave " << iSlave << " has the following parameters:\n";
368 for ( std::vector<UInt_t>::const_iterator iter = indices.begin(); iter != indices.end(); ++iter ) {
373 std::cerr << "ERROR in LauSimFitMaster::printParInfo : Discrepancy in parameter name and value records, this is very strange!!" << std::endl;
382 std::cout << "INFO in LauSimFitMaster::printParInfo : " << "There are " << nParams_ << " parameters in total" << std::endl;
391 std::cerr << "ERROR in LauSimFitMaster::checkParameter : Parameter name is different!! This shouldn't happen!!" << std::endl;
394 std::cerr << "WARNING in LauSimFitMaster::checkParameter : Initial value for parameter " << parName << " is different, will use the value first set: " << storedPar->initValue() << std::endl;
397 std::cerr << "WARNING in LauSimFitMaster::checkParameter : Minimum allowed value for parameter " << parName << " is different, will use the value first set: " << storedPar->minValue() << std::endl;
400 std::cerr << "WARNING in LauSimFitMaster::checkParameter : Maximum allowed value for parameter " << parName << " is different, will use the value first set: " << storedPar->maxValue() << std::endl;
403 std::cerr << "WARNING in LauSimFitMaster::checkParameter : Fixed/floating property of parameter " << parName << " is different, will use the value first set: " << (storedPar->fixed() ? "fixed" : "floating") << std::endl;
406 std::cerr << "WARNING in LauSimFitMaster::checkParameter : First stage property of parameter " << parName << " is different, will use the value first set: " << (storedPar->firstStage() ? "true" : "false") << std::endl;
409 std::cerr << "WARNING in LauSimFitMaster::checkParameter : Second stage property of parameter " << parName << " is different, will use the value first set: " << (storedPar->secondStage() ? "true" : "false") << std::endl;
418 void LauSimFitMaster::runSimFit( const TString& fitNtupleFileName, UInt_t nExpt, UInt_t firstExpt, Bool_t useAsymmErrors, Bool_t twoStageFit )
425 std::cout << "INFO in LauSimFitMaster::runSimFit : First experiment = " << firstExpt << std::endl;
426 std::cout << "INFO in LauSimFitMaster::runSimFit : Number of experiments = " << nExpt << std::endl;
448 std::cerr << "ERROR in LauSimFitMaster::runSimFit : One or more slaves reported problems with reading data for experiment " << iExpt_ << ", skipping..." << std::endl;
480 std::cout << "INFO in LauSimFitMaster::runSimFit : Number of OK Fits = " << numberOKFits_ << std::endl;
481 std::cout << "INFO in LauSimFitMaster::runSimFit : Number of Failed Fits = " << numberBadFits_ << std::endl;
484 std::cout << "INFO in LauSimFitMaster::runSimFit : Fit efficiency = " << fitEff*100.0 << "%." << std::endl;
524 std::cerr << "ERROR in LauSimFitMaster::readData : Slave " << iSlave << " reports no events found for experiment " << iExpt_ << std::endl;
527 std::cerr << "INFO in LauSimFitMaster::readData : Slave " << iSlave << " reports " << nEvents << " events found for experiment " << iExpt_ << std::endl;
539 std::cerr << "ERROR in LauSimFitMaster::cacheInputData : Sockets not initialised." << std::endl;
569 std::cerr << "ERROR in LauSimFitMaster::cacheInputData : Slave " << iSlave << " reports an error performing caching" << std::endl;
589 // Instruct the salves to update initial fit parameters if required (e.g. if using random numbers).
612 std::cerr << "ERROR in LauSimFitMaster:fitExpt : Not running second stage fit since first stage failed." << std::endl;
646 std::cerr << "ERROR in LauSimFitMaster::setParsFromMinuit : Unexpected number of free parameters: " << npar << ".\n";
669 std::cerr << "ERROR in LauSimFitMaster::getTotNegLogLikelihood : Sockets not initialised." << std::endl;
717 for ( std::vector<LauAbsRValue*>::const_iterator iter = conVars_.begin(); iter != conVars_.end(); ++iter ) {
729 void LauSimFitMaster::addConstraint(const TString& formula, const std::vector<TString>& pars, const Double_t mean, const Double_t width)
744 for ( std::vector<LauParameter*>::const_iterator iter = params_.begin(); iter != params_.end(); ++iter ) {
747 std::cout << "INFO in LauSimFitMaster::addConParameters : Added Gaussian constraint to parameter "<< (*iter)->name() << std::endl;
752 for ( std::vector<StoreConstraints>::iterator iter = storeCon_.begin(); iter != storeCon_.end(); ++iter ) {
755 for ( std::vector<TString>::iterator iternames = names.begin(); iternames != names.end(); ++iternames ) {
756 for ( std::vector<LauParameter*>::const_iterator iterfit = params_.begin(); iterfit != params_.end(); ++iterfit ) {
765 std::cerr << "WARNING in LauSimFitMaster::addConParameters: Could not find parameters to constrain in the formula... skipping" << std::endl;
773 std::cout << "INFO in LauSimFitMaster::addConParameters : Added Gaussian constraint to formula\n";
775 for ( std::vector<LauParameter*>::iterator iterparam = params.begin(); iterparam != params.end(); ++iterparam ) {
838 // TODO - at present we lose the information on the correlations between the parameters that are unique to each slave
839 // - so should we store the full correlation matrix in an ntuple? along with all the parameters?
878 TObjArray * objarray = dynamic_cast<TObjArray*>( messageFromSlave_->ReadObject( messageFromSlave_->GetClass() ) );
880 std::cerr << "ERROR in LauSimFitMaster::finalise : Error reading finalised parameters from slave" << std::endl;
888 std::cerr << "ERROR in LauSimFitMaster::finalise : Unexpected number of finalised parameters received from slave" << std::endl;
894 std::cerr << "ERROR in LauSimFitMaster::finalise : Error reading parameter from slave" << std::endl;
903 std::cerr << "ERROR in LauSimFitMaster::finalise : Unexpected parameter name received from slave" << std::endl;
910 std::cerr << "ERROR in LauSimFitMaster::finalise : Unexpected parameter received from slave" << std::endl;
924 std::cerr << "ERROR in LauSimFitMaster::finalise : Slave " << iSlave << " reports an error performing finalisation" << std::endl;
933 for ( std::vector<LauParameter*>::iterator iter = params_.begin(); iter != params_.end(); ++iter ) {
950 std::cerr << "ERROR in LauSimFitMaster::writeOutResults : Sockets not initialised." << std::endl;
980 std::cerr << "ERROR in LauSimFitMaster::writeOutResults : Slave " << iSlave << " reports an error performing finalisation" << std::endl;
std::vector< std::vector< UInt_t > > slaveIndices_ Lists of indices for each slave. Definition: LauSimFitMaster.hh:240 Bool_t readData() Instruct the slaves to read the input data for the given experiment. Definition: LauSimFitMaster.cc:490 File containing declaration of LauFormulaPar class. void getParametersFromSlaves() Determine/update the parameter initial values from all slaves. Definition: LauSimFitMaster.cc:206 Bool_t fixed() const Check whether the parameter is fixed or floated. Definition: LauParameter.hh:194 virtual void updateParameters()=0 Update the values and errors of the parameters based on the fit minimum. std::map< UInt_t, TString > parNames_ Reverse map of index in the values vector to parameter names. Definition: LauSimFitMaster.hh:228 void addConParameters() Add parameters to the list of Gaussian constrained parameters. Definition: LauSimFitMaster.cc:739 File containing declaration of LauParamFixed class. Double_t maxValue() const The maximum value allowed for the parameter. Definition: LauParameter.hh:182 Bool_t writeOutResults() Instruct the slaves to write out the fit results. Definition: LauSimFitMaster.cc:947 ClassImp(LauAbsCoeffSet) Class for defining combinations of fit parameter objects. Definition: LauFormulaPar.hh:35 virtual Bool_t twoStageFit() const =0 Determine whether the two-stage fit is enabled. File containing declaration of LauAbsFitter class. Double_t minValue() const The minimum value allowed for the parameter. Definition: LauParameter.hh:176 void getParametersFromSlavesFirstTime() Determine the parameter names and initial values from all slaves. Definition: LauSimFitMaster.cc:293 Double_t mean_ The mean value of the Gaussian constraint to be applied. Definition: LauSimFitMaster.hh:168 std::vector< StoreConstraints > storeCon_ Store the constraints for fit parameters until initialisation is complete. Definition: LauSimFitMaster.hh:174 std::vector< Double_t > vectorRes_ Likelihood values returned from the slaves. Definition: LauSimFitMaster.hh:246 std::map< TString, UInt_t > parIndices_ Map of parameter names to index in the values vector. Definition: LauSimFitMaster.hh:225 void addGaussianConstraint(Double_t newGaussMean, Double_t newGaussWidth) Add a Gaussian constraint (or modify an existing one) Definition: LauFormulaPar.cc:88 virtual void initialise(LauFitObject *fitObj, const std::vector< LauParameter * > ¶meters)=0 Initialise the fitter, setting the information on the parameters. virtual std::pair< Int_t, Double_t > minimise()=0 Perform the minimisation of the fit function. Bool_t withinAsymErrorCalc_ Flag to indicate if the asymmetric error calculation (e.g. MINOS) is currently running. Definition: LauSimFitMaster.hh:189 File containing LauFitter class. Struct to store constraint information until the fit is run. Definition: LauSimFitMaster.hh:162 std::vector< TString > conPars_ The list of LauParameter names to be used in the LauFormulaPar. Definition: LauSimFitMaster.hh:166 Bool_t firstStage() const Check whether the parameter should be floated only in the first stage of a two stage fit... Definition: LauParameter.hh:200 Double_t getLogLikelihoodPenalty() Calculate the penalty terms to the log likelihood from Gaussian constraints. Definition: LauSimFitMaster.cc:713 void checkInitFitParams() Instruct the slaves to update the initial fit parameter values, if required. Definition: LauSimFitMaster.cc:579 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. Definition: LauSimFitMaster.cc:729 File containing declaration of LauParameter class. Predicate to allow counting of the number of fixed parameters. Definition: LauParamFixed.hh:24 std::vector< Double_t * > vectorPar_ Parameter values to send to the slaves. Definition: LauSimFitMaster.hh:243 Bool_t secondStage() const Check whether the parameter should be floated only in the second stage of a two stage fit... Definition: LauParameter.hh:206 void updateParametersFromSlaves() Update and verify the parameter initial values from all slaves. Definition: LauSimFitMaster.cc:223 virtual void fixFirstStageParameters()=0 Fix parameters marked as "first stage". std::vector< TMatrixD > covMatrices_ The covariance sub-matrices for each slave. Definition: LauSimFitMaster.hh:210 virtual UInt_t nParameters() const =0 Get the total number of fit parameters. virtual void releaseSecondStageParameters()=0 Release parameters marked as "second stage". void storeCorrMatrix(UInt_t iExpt, Double_t NLL, Int_t fitStatus, const TMatrixD &covMatrix) Store the correlation matrix and other fit information. Definition: LauFitNtuple.cc:64 void checkParameter(const LauParameter *param, UInt_t index) const Check for compatibility between two same-named parameters, which should therefore be identical... Definition: LauSimFitMaster.cc:385 void fitExpt(Bool_t useAsymmErrors, Bool_t twoStageFit) Perform the fit for the current experiment. Definition: LauSimFitMaster.cc:585 static LauAbsFitter * fitter() Method that provides access to the singleton fitter. Definition: LauFitter.cc:34 Bool_t finalise() Return the final parameters to the slaves and instruct them to perform their finalisation. Definition: LauSimFitMaster.cc:782 virtual UInt_t nFreeParameters() const =0 Get the number of floating fit parameters. virtual void setParsFromMinuit(Double_t *par, Int_t npar) This function sets the parameter values from Minuit. Definition: LauSimFitMaster.cc:637 File containing declaration of LauSimFitMaster class. void storeParsAndErrors(const std::vector< LauParameter * > &fitVars, const std::vector< LauParameter > &extraVars) Store parameters and their errors. Definition: LauFitNtuple.cc:134 void runSimFit(const TString &fitNtupleFileName, UInt_t nExpt, UInt_t firstExpt=0, Bool_t useAsymmErrors=kFALSE, Bool_t twoStageFit=kFALSE) Run the fit. Definition: LauSimFitMaster.cc:418 Double_t width_ The width of the Gaussian constraint to be applied. Definition: LauSimFitMaster.hh:170 virtual Bool_t useAsymmFitErrors() const =0 Determine whether calculation of asymmetric errors is enabled. Bool_t cacheInputData() Instruct the slaves to perform the caching. Definition: LauSimFitMaster.cc:536 virtual Double_t getTotNegLogLikelihood() Calculate the new value of the negative log likelihood. Definition: LauSimFitMaster.cc:666 virtual void releaseFirstStageParameters()=0 Release parameters marked as "first stage". File containing declaration of LauFitNtuple class. virtual const TMatrixD & covarianceMatrix() const =0 Retrieve the fit covariance matrix. Generated by 1.8.5 |