Changeset View
Changeset View
Standalone View
Standalone View
src/LauRooFitTask.cc
- This file was moved from src/LauRooFitSlave.cc.
Show All 16 Lines | |||||
/* | /* | ||||
Laura++ package authors: | Laura++ package authors: | ||||
John Back | John Back | ||||
Paul Harrison | Paul Harrison | ||||
Thomas Latham | Thomas Latham | ||||
*/ | */ | ||||
/*! \file LauRooFitSlave.cc | /*! \file LauRooFitTask.cc | ||||
\brief File containing implementation of LauRooFitSlave class. | \brief File containing implementation of LauRooFitTask class. | ||||
*/ | */ | ||||
#include <iostream> | #include <iostream> | ||||
#include <vector> | #include <vector> | ||||
#include "RooFormulaVar.h" | |||||
#include "RooRealVar.h" | #include "RooRealVar.h" | ||||
#include "RooDataSet.h" | #include "RooDataSet.h" | ||||
#include "TFile.h" | #include "TFile.h" | ||||
#include "TString.h" | #include "TString.h" | ||||
#include "TSystem.h" | #include "TSystem.h" | ||||
#include "TTree.h" | #include "TTree.h" | ||||
#include "LauFitNtuple.hh" | #include "LauFitNtuple.hh" | ||||
#include "LauParameter.hh" | #include "LauParameter.hh" | ||||
#include "LauSimFitSlave.hh" | #include "LauSimFitTask.hh" | ||||
#include "LauRooFitSlave.hh" | #include "LauRooFitTask.hh" | ||||
ClassImp(LauRooFitSlave) | ClassImp(LauRooFitTask) | ||||
LauRooFitSlave::LauRooFitSlave( RooAbsPdf& model, const Bool_t extended, const RooArgSet& vars, const TString& weightVarName ) : | LauRooFitTask::LauRooFitTask( RooAbsPdf& model, const Bool_t extended, const RooArgSet& vars, const TString& weightVarName ) : | ||||
LauSimFitSlave(), | LauSimFitTask(), | ||||
model_(model), | model_(model), | ||||
dataVars_(vars), | dataVars_(vars), | ||||
weightVarName_(weightVarName), | weightVarName_(weightVarName), | ||||
dataFile_(0), | dataFile_(0), | ||||
dataTree_(0), | dataTree_(0), | ||||
exptData_(0), | exptData_(0), | ||||
extended_(extended), | extended_(extended), | ||||
iExptCat_("iExpt","Expt Number"), | iExptSet_(), | ||||
nllVar_(0) | nllVar_(0) | ||||
{ | { | ||||
} | } | ||||
LauRooFitSlave::~LauRooFitSlave() | LauRooFitTask::~LauRooFitTask() | ||||
{ | { | ||||
delete nllVar_; nllVar_ = 0; | delete nllVar_; nllVar_ = 0; | ||||
this->cleanData(); | this->cleanData(); | ||||
} | } | ||||
void LauRooFitSlave::cleanData() | void LauRooFitTask::cleanData() | ||||
{ | { | ||||
if ( dataFile_ != 0 ) { | if ( dataFile_ != 0 ) { | ||||
dataFile_->Close(); | dataFile_->Close(); | ||||
delete dataFile_; | delete dataFile_; | ||||
dataTree_ = 0; | dataTree_ = 0; | ||||
dataFile_ = 0; | dataFile_ = 0; | ||||
} | } | ||||
delete exptData_; | delete exptData_; | ||||
exptData_ = 0; | exptData_ = 0; | ||||
} | } | ||||
void LauRooFitSlave::initialise() | void LauRooFitTask::initialise() | ||||
{ | { | ||||
if ( weightVarName_ != "" ) { | if ( weightVarName_ != "" ) { | ||||
Bool_t weightVarFound = kFALSE; | Bool_t weightVarFound = kFALSE; | ||||
RooFIter argset_iter = dataVars_.fwdIterator(); | RooFIter argset_iter = dataVars_.fwdIterator(); | ||||
RooAbsArg* param(0); | RooAbsArg* param(0); | ||||
while ( (param = argset_iter.next()) ) { | while ( (param = argset_iter.next()) ) { | ||||
TString name = param->GetName(); | TString name = param->GetName(); | ||||
if ( name == weightVarName_ ) { | if ( name == weightVarName_ ) { | ||||
weightVarFound = kTRUE; | weightVarFound = kTRUE; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if ( ! weightVarFound ) { | if ( ! weightVarFound ) { | ||||
std::cerr << "ERROR in LauRooFitSlave::initialise : The set of data variables does not contain the weighting variable \"" << weightVarName_ << std::endl; | std::cerr << "ERROR in LauRooFitTask::initialise : The set of data variables does not contain the weighting variable \"" << weightVarName_ << std::endl; | ||||
std::cerr << " : Weighting will be disabled." << std::endl; | std::cerr << " : Weighting will be disabled." << std::endl; | ||||
weightVarName_ = ""; | weightVarName_ = ""; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
Bool_t LauRooFitSlave::verifyFitData(const TString& dataFileName, const TString& dataTreeName) | Bool_t LauRooFitTask::verifyFitData(const TString& dataFileName, const TString& dataTreeName) | ||||
{ | { | ||||
// Clean-up from any previous runs | // Clean-up from any previous runs | ||||
if ( dataFile_ != 0 ) { | if ( dataFile_ != 0 ) { | ||||
this->cleanData(); | this->cleanData(); | ||||
} | } | ||||
// Open the data file | // Open the data file | ||||
dataFile_ = TFile::Open( dataFileName ); | dataFile_ = TFile::Open( dataFileName ); | ||||
if ( ! dataFile_ ) { | if ( ! dataFile_ ) { | ||||
std::cerr << "ERROR in LauRooFitSlave::verifyFitData : Problem opening data file \"" << dataFileName << "\"" << std::endl; | std::cerr << "ERROR in LauRooFitTask::verifyFitData : Problem opening data file \"" << dataFileName << "\"" << std::endl; | ||||
return kFALSE; | return kFALSE; | ||||
} | } | ||||
// Retrieve the tree | // Retrieve the tree | ||||
dataTree_ = dynamic_cast<TTree*>( dataFile_->Get( dataTreeName ) ); | dataTree_ = dynamic_cast<TTree*>( dataFile_->Get( dataTreeName ) ); | ||||
if ( ! dataTree_ ) { | if ( ! dataTree_ ) { | ||||
std::cerr << "ERROR in LauRooFitSlave::verifyFitData : Problem retrieving tree \"" << dataTreeName << "\" from data file \"" << dataFileName << "\"" << std::endl; | std::cerr << "ERROR in LauRooFitTask::verifyFitData : Problem retrieving tree \"" << dataTreeName << "\" from data file \"" << dataFileName << "\"" << std::endl; | ||||
dataFile_->Close(); | dataFile_->Close(); | ||||
delete dataFile_; | delete dataFile_; | ||||
dataFile_ = 0; | dataFile_ = 0; | ||||
return kFALSE; | return kFALSE; | ||||
} | } | ||||
// Check that the tree contains branches for all the fit variables | // Check that the tree contains branches for all the fit variables | ||||
RooFIter argset_iter = dataVars_.fwdIterator(); | RooFIter argset_iter = dataVars_.fwdIterator(); | ||||
RooAbsArg* param(0); | RooAbsArg* param(0); | ||||
Bool_t allOK(kTRUE); | Bool_t allOK(kTRUE); | ||||
while ( (param = argset_iter.next()) ) { | while ( (param = argset_iter.next()) ) { | ||||
TString name = param->GetName(); | TString name = param->GetName(); | ||||
TBranch* branch = dataTree_->GetBranch( name ); | TBranch* branch = dataTree_->GetBranch( name ); | ||||
if ( branch == 0 ) { | if ( branch == 0 ) { | ||||
std::cerr << "ERROR in LauRooFitSlave::verifyFitData : The data tree does not contain a branch for fit variable \"" << name << std::endl; | std::cerr << "ERROR in LauRooFitTask::verifyFitData : The data tree does not contain a branch for fit variable \"" << name << std::endl; | ||||
allOK = kFALSE; | allOK = kFALSE; | ||||
} | } | ||||
} | } | ||||
if ( ! allOK ) { | if ( ! allOK ) { | ||||
return kFALSE; | return kFALSE; | ||||
} | } | ||||
// Check whether the tree has the branch iExpt | // Check whether the tree has the branch iExpt | ||||
TBranch* branch = dataTree_->GetBranch("iExpt"); | TBranch* branch = dataTree_->GetBranch("iExpt"); | ||||
if ( branch == 0 ) { | if ( branch == 0 ) { | ||||
std::cout << "WARNING in LauRooFitSlave::verifyFitData : Cannot find branch \"iExpt\" in the tree, will treat all data as being from a single experiment" << std::endl; | std::cout << "WARNING in LauRooFitTask::verifyFitData : Cannot find branch \"iExpt\" in the tree, will treat all data as being from a single experiment" << std::endl; | ||||
} else { | } else { | ||||
// Define the valid values for the iExpt RooCategory | // Define the valid values for iExpt | ||||
iExptCat_.clearTypes(); | iExptSet_.clear(); | ||||
const UInt_t firstExp = dataTree_->GetMinimum("iExpt"); | const UInt_t firstExp = dataTree_->GetMinimum("iExpt"); | ||||
const UInt_t lastExp = dataTree_->GetMaximum("iExpt"); | const UInt_t lastExp = dataTree_->GetMaximum("iExpt"); | ||||
for ( UInt_t iExp = firstExp; iExp <= lastExp; ++iExp ) { | for ( UInt_t iExp = firstExp; iExp <= lastExp; ++iExp ) { | ||||
iExptCat_.defineType( TString::Format("expt%d",iExp), iExp ); | iExptSet_.insert( iExp ); | ||||
} | } | ||||
} | } | ||||
return kTRUE; | return kTRUE; | ||||
} | } | ||||
void LauRooFitSlave::prepareInitialParArray( TObjArray& array ) | void LauRooFitTask::prepareInitialParArray( TObjArray& array ) | ||||
{ | { | ||||
// Check that the NLL variable has been initialised | // Check that the NLL variable has been initialised | ||||
if ( ! nllVar_ ) { | if ( ! nllVar_ ) { | ||||
std::cerr << "ERROR in LauRooFitSlave::prepareInitialParArray : NLL var not initialised" << std::endl; | std::cerr << "ERROR in LauRooFitTask::prepareInitialParArray : NLL var not initialised" << std::endl; | ||||
return; | return; | ||||
} | } | ||||
// If we already prepared the entries in the fitPars_ vector then we only need to add the contents to the array | // If we already prepared the entries in the fitPars_ vector then we only need to add the contents to the array | ||||
if ( ! fitPars_.empty() ) { | if ( ! fitPars_.empty() ) { | ||||
for ( std::vector<LauParameter*>::iterator iter = fitPars_.begin(); iter != fitPars_.end(); ++iter ) { | for ( std::vector<LauParameter*>::iterator iter = fitPars_.begin(); iter != fitPars_.end(); ++iter ) { | ||||
array.Add(*iter); | array.Add(*iter); | ||||
} | } | ||||
Show All 18 Lines | if ( ! param->isConstant() ) { | ||||
// Do the conversion and add it to the array | // Do the conversion and add it to the array | ||||
LauParameter* lpar = this->convertToLauParameter( rrvar ); | LauParameter* lpar = this->convertToLauParameter( rrvar ); | ||||
fitVars_.push_back( rrvar ); | fitVars_.push_back( rrvar ); | ||||
fitPars_.push_back( lpar ); | fitPars_.push_back( lpar ); | ||||
array.Add( lpar ); | array.Add( lpar ); | ||||
} else { | } else { | ||||
RooFormulaVar* rfvar = dynamic_cast<RooFormulaVar*>( param ); | RooFormulaVar* rfvar = dynamic_cast<RooFormulaVar*>( param ); | ||||
if ( rfvar == 0 ) { | if ( rfvar == 0 ) { | ||||
std::cerr << "ERROR in LauRooFitSlave::prepareInitialParArray : The parameter is neither a RooRealVar nor a RooFormulaVar, don't know what to do" << std::endl; | std::cerr << "ERROR in LauRooFitTask::prepareInitialParArray : The parameter is neither a RooRealVar nor a RooFormulaVar, don't know what to do" << std::endl; | ||||
continue; | continue; | ||||
} | } | ||||
std::vector< std::pair<RooRealVar*,LauParameter*> > lpars = this->convertToLauParameters( rfvar ); | std::vector< std::pair<RooRealVar*,LauParameter*> > lpars = this->convertToLauParameters( rfvar ); | ||||
for ( std::vector< std::pair<RooRealVar*,LauParameter*> >::iterator iter = lpars.begin(); iter != lpars.end(); ++iter ) { | for ( std::vector< std::pair<RooRealVar*,LauParameter*> >::iterator iter = lpars.begin(); iter != lpars.end(); ++iter ) { | ||||
RooRealVar* rrv = iter->first; | RooRealVar* rrv = iter->first; | ||||
LauParameter* lpar = iter->second; | LauParameter* lpar = iter->second; | ||||
if ( ! rrv->isConstant() ) { | if ( ! rrv->isConstant() ) { | ||||
continue; | continue; | ||||
Show All 9 Lines | if ( ! param->isConstant() ) { | ||||
} | } | ||||
} | } | ||||
} | } | ||||
delete varSet; | delete varSet; | ||||
this->startNewFit( nFreePars, nFreePars ); | this->startNewFit( nFreePars, nFreePars ); | ||||
} | } | ||||
LauParameter* LauRooFitSlave::convertToLauParameter( const RooRealVar* rooParameter ) const | LauParameter* LauRooFitTask::convertToLauParameter( const RooRealVar* rooParameter ) const | ||||
{ | { | ||||
return new LauParameter( rooParameter->GetName(), rooParameter->getVal(), rooParameter->getMin(), rooParameter->getMax(), rooParameter->isConstant() ); | return new LauParameter( rooParameter->GetName(), rooParameter->getVal(), rooParameter->getMin(), rooParameter->getMax(), rooParameter->isConstant() ); | ||||
} | } | ||||
std::vector< std::pair<RooRealVar*,LauParameter*> > LauRooFitSlave::convertToLauParameters( const RooFormulaVar* rooFormula ) const | std::vector< std::pair<RooRealVar*,LauParameter*> > LauRooFitTask::convertToLauParameters( const RooFormulaVar* rooFormula ) const | ||||
{ | { | ||||
// Create the empty vector | // Create the empty vector | ||||
std::vector< std::pair<RooRealVar*,LauParameter*> > lauParameters; | std::vector< std::pair<RooRealVar*,LauParameter*> > lauParameters; | ||||
Int_t parIndex(0); | Int_t parIndex(0); | ||||
RooAbsArg* rabsarg(0); | RooAbsArg* rabsarg(0); | ||||
RooRealVar* rrvar(0); | RooRealVar* rrvar(0); | ||||
RooFormulaVar* rfvar(0); | RooFormulaVar* rfvar(0); | ||||
Show All 15 Lines | if ( rfvar ) { | ||||
std::vector< std::pair<RooRealVar*,LauParameter*> > lpars = this->convertToLauParameters( rfvar ); | std::vector< std::pair<RooRealVar*,LauParameter*> > lpars = this->convertToLauParameters( rfvar ); | ||||
for ( std::vector< std::pair<RooRealVar*,LauParameter*> >::iterator iter = lpars.begin(); iter != lpars.end(); ++iter ) { | for ( std::vector< std::pair<RooRealVar*,LauParameter*> >::iterator iter = lpars.begin(); iter != lpars.end(); ++iter ) { | ||||
lauParameters.push_back( *iter ); | lauParameters.push_back( *iter ); | ||||
} | } | ||||
continue; | continue; | ||||
} | } | ||||
// If neither of those worked we don't know what to do, so print an error message and continue | // If neither of those worked we don't know what to do, so print an error message and continue | ||||
std::cerr << "ERROR in LauRooFitSlave::convertToLauParameters : One of the parameters is not a RooRealVar nor a RooFormulaVar, it is a: " << rabsarg->ClassName() << std::endl; | std::cerr << "ERROR in LauRooFitTask::convertToLauParameters : One of the parameters is not a RooRealVar nor a RooFormulaVar, it is a: " << rabsarg->ClassName() << std::endl; | ||||
std::cerr << " : Do not know how to process that - it will be skipped." << std::endl; | std::cerr << " : Do not know how to process that - it will be skipped." << std::endl; | ||||
} | } | ||||
return lauParameters; | return lauParameters; | ||||
} | } | ||||
Double_t LauRooFitSlave::getTotNegLogLikelihood() | Double_t LauRooFitTask::getTotNegLogLikelihood() | ||||
{ | { | ||||
Double_t nLL = (nllVar_ != 0) ? nllVar_->getVal() : 0.0; | Double_t nLL = (nllVar_ != 0) ? nllVar_->getVal() : 0.0; | ||||
return nLL; | return nLL; | ||||
} | } | ||||
void LauRooFitSlave::setParsFromMinuit(Double_t* par, Int_t npar) | void LauRooFitTask::setParsFromMinuit(Double_t* par, Int_t npar) | ||||
{ | { | ||||
// This function sets the internal parameters based on the values | // This function sets the internal parameters based on the values | ||||
// that Minuit is using when trying to minimise the total likelihood function. | // that Minuit is using when trying to minimise the total likelihood function. | ||||
// MINOS reports different numbers of free parameters depending on the | // MINOS reports different numbers of free parameters depending on the | ||||
// situation, so disable this check | // situation, so disable this check | ||||
const UInt_t nFreePars = this->nFreeParams(); | const UInt_t nFreePars = this->nFreeParams(); | ||||
if ( ! this->withinAsymErrorCalc() ) { | if ( ! this->withinAsymErrorCalc() ) { | ||||
if (static_cast<UInt_t>(npar) != nFreePars) { | if (static_cast<UInt_t>(npar) != nFreePars) { | ||||
std::cerr << "ERROR in LauRooFitSlave::setParsFromMinuit : Unexpected number of free parameters: " << npar << ".\n"; | std::cerr << "ERROR in LauRooFitTask::setParsFromMinuit : Unexpected number of free parameters: " << npar << ".\n"; | ||||
std::cerr << " Expected: " << nFreePars << ".\n" << std::endl; | std::cerr << " Expected: " << nFreePars << ".\n" << std::endl; | ||||
gSystem->Exit(EXIT_FAILURE); | gSystem->Exit(EXIT_FAILURE); | ||||
} | } | ||||
} | } | ||||
// Despite npar being the number of free parameters | // Despite npar being the number of free parameters | ||||
// the par array actually contains all the parameters, | // the par array actually contains all the parameters, | ||||
// free and floating... | // free and floating... | ||||
// Update all the floating ones with their new values | // Update all the floating ones with their new values | ||||
for (UInt_t i(0); i<nFreePars; ++i) { | for (UInt_t i(0); i<nFreePars; ++i) { | ||||
if (!fitPars_[i]->fixed()) { | if (!fitPars_[i]->fixed()) { | ||||
// Set both the RooRealVars and the LauParameters | // Set both the RooRealVars and the LauParameters | ||||
fitPars_[i]->value(par[i]); | fitPars_[i]->value(par[i]); | ||||
fitVars_[i]->setVal(par[i]); | fitVars_[i]->setVal(par[i]); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
UInt_t LauRooFitSlave::readExperimentData() | UInt_t LauRooFitTask::readExperimentData() | ||||
{ | { | ||||
// check that we're being asked to read a valid index | // check that we're being asked to read a valid index | ||||
const UInt_t exptIndex = this->iExpt(); | const UInt_t exptIndex = this->iExpt(); | ||||
if ( iExptCat_.numTypes() == 0 && exptIndex != 0 ) { | if ( iExptSet_.empty() && exptIndex != 0 ) { | ||||
std::cerr << "ERROR in LauRooFitSlave::readExperimentData : Invalid experiment number " << exptIndex << ", data contains only one experiment" << std::endl; | std::cerr << "ERROR in LauRooFitTask::readExperimentData : Invalid experiment number " << exptIndex << ", data contains only one experiment" << std::endl; | ||||
return 0; | return 0; | ||||
} else if ( ! iExptCat_.isValidIndex( exptIndex ) ) { | } else if ( iExptSet_.find( exptIndex ) == iExptSet_.end() ) { | ||||
std::cerr << "ERROR in LauRooFitSlave::readExperimentData : Invalid experiment number " << exptIndex << std::endl; | std::cerr << "ERROR in LauRooFitTask::readExperimentData : Invalid experiment number " << exptIndex << std::endl; | ||||
return 0; | return 0; | ||||
} | } | ||||
// cleanup the data from any previous experiment | // cleanup the data from any previous experiment | ||||
delete exptData_; | delete exptData_; | ||||
// retrieve the data and find out how many events have been read | // retrieve the data and find out how many events have been read | ||||
if ( iExptCat_.numTypes() == 0 ) { | if ( iExptSet_.empty() ) { | ||||
exptData_ = new RooDataSet( TString::Format("expt%dData",exptIndex), "", dataTree_, dataVars_, "", (weightVarName_ != "") ? weightVarName_.Data() : 0 ); | exptData_ = new RooDataSet( TString::Format("expt%dData",exptIndex), "", dataTree_, dataVars_, "", (weightVarName_ != "") ? weightVarName_.Data() : 0 ); | ||||
} else { | } else { | ||||
const TString selectionString = TString::Format("iExpt==%d",exptIndex); | const TString selectionString = TString::Format("iExpt==%d",exptIndex); | ||||
TTree* exptTree = dataTree_->CopyTree(selectionString); | TTree* exptTree = dataTree_->CopyTree(selectionString); | ||||
exptData_ = new RooDataSet( TString::Format("expt%dData",exptIndex), "", exptTree, dataVars_, "", (weightVarName_ != "") ? weightVarName_.Data() : 0 ); | exptData_ = new RooDataSet( TString::Format("expt%dData",exptIndex), "", exptTree, dataVars_, "", (weightVarName_ != "") ? weightVarName_.Data() : 0 ); | ||||
delete exptTree; | delete exptTree; | ||||
} | } | ||||
const UInt_t nEvent = exptData_->numEntries(); | const UInt_t nEvent = exptData_->numEntries(); | ||||
this->eventsPerExpt( nEvent ); | this->eventsPerExpt( nEvent ); | ||||
return nEvent; | return nEvent; | ||||
} | } | ||||
void LauRooFitSlave::cacheInputFitVars() | void LauRooFitTask::cacheInputFitVars() | ||||
{ | { | ||||
// cleanup the old NLL info | // cleanup the old NLL info | ||||
delete nllVar_; | delete nllVar_; | ||||
// construct the new NLL variable for this dataset | // construct the new NLL variable for this dataset | ||||
nllVar_ = new RooNLLVar("nllVar", "", model_, *exptData_, extended_); | nllVar_ = new RooNLLVar("nllVar", "", model_, *exptData_, extended_); | ||||
} | } | ||||
void LauRooFitSlave::finaliseExperiment( const LauAbsFitter::FitStatus& fitStat, const TObjArray* parsFromMaster, const TMatrixD* covMat, TObjArray& parsToMaster ) | void LauRooFitTask::finaliseExperiment( const LauAbsFitter::FitStatus& fitStat, const TObjArray* parsFromCoordinator, const TMatrixD* covMat, TObjArray& parsToCoordinator ) | ||||
{ | { | ||||
// Copy the fit status information | // Copy the fit status information | ||||
this->storeFitStatus( fitStat, *covMat ); | this->storeFitStatus( fitStat, *covMat ); | ||||
// Now process the parameters | // Now process the parameters | ||||
const UInt_t nFreePars = this->nFreeParams(); | const UInt_t nFreePars = this->nFreeParams(); | ||||
UInt_t nPars = parsFromMaster->GetEntries(); | UInt_t nPars = parsFromCoordinator->GetEntries(); | ||||
if ( nPars != nFreePars ) { | if ( nPars != nFreePars ) { | ||||
std::cerr << "ERROR in LauRooFitSlave::finaliseExperiment : Unexpected number of parameters received from master" << std::endl; | std::cerr << "ERROR in LauRooFitTask::finaliseExperiment : Unexpected number of parameters received from coordinator" << std::endl; | ||||
std::cerr << " : Received " << nPars << " when expecting " << nFreePars << std::endl; | std::cerr << " : Received " << nPars << " when expecting " << nFreePars << std::endl; | ||||
gSystem->Exit( EXIT_FAILURE ); | gSystem->Exit( EXIT_FAILURE ); | ||||
} | } | ||||
for ( UInt_t iPar(0); iPar < nPars; ++iPar ) { | for ( UInt_t iPar(0); iPar < nPars; ++iPar ) { | ||||
LauParameter* parameter = dynamic_cast<LauParameter*>( (*parsFromMaster)[iPar] ); | LauParameter* parameter = dynamic_cast<LauParameter*>( (*parsFromCoordinator)[iPar] ); | ||||
if ( ! parameter ) { | if ( ! parameter ) { | ||||
std::cerr << "ERROR in LauRooFitSlave::finaliseExperiment : Error reading parameter from master" << std::endl; | std::cerr << "ERROR in LauRooFitTask::finaliseExperiment : Error reading parameter from coordinator" << std::endl; | ||||
gSystem->Exit( EXIT_FAILURE ); | gSystem->Exit( EXIT_FAILURE ); | ||||
} | } | ||||
if ( parameter->name() != fitPars_[iPar]->name() ) { | if ( parameter->name() != fitPars_[iPar]->name() ) { | ||||
std::cerr << "ERROR in LauRooFitSlave::finaliseExperiment : Error reading parameter from master" << std::endl; | std::cerr << "ERROR in LauRooFitTask::finaliseExperiment : Error reading parameter from coordinator" << std::endl; | ||||
gSystem->Exit( EXIT_FAILURE ); | gSystem->Exit( EXIT_FAILURE ); | ||||
} | } | ||||
*(fitPars_[iPar]) = *parameter; | *(fitPars_[iPar]) = *parameter; | ||||
RooRealVar* rrv = fitVars_[iPar]; | RooRealVar* rrv = fitVars_[iPar]; | ||||
rrv->setVal( parameter->value() ); | rrv->setVal( parameter->value() ); | ||||
rrv->setError( parameter->error() ); | rrv->setError( parameter->error() ); | ||||
rrv->setAsymError( parameter->negError(), parameter->posError() ); | rrv->setAsymError( parameter->negError(), parameter->posError() ); | ||||
} | } | ||||
// Update the pulls and add each finalised fit parameter to the list to | // Update the pulls and add each finalised fit parameter to the list to | ||||
// send back to the master | // send back to the coordinator | ||||
for ( std::vector<LauParameter*>::iterator iter = fitPars_.begin(); iter != fitPars_.end(); ++iter ) { | for ( std::vector<LauParameter*>::iterator iter = fitPars_.begin(); iter != fitPars_.end(); ++iter ) { | ||||
(*iter)->updatePull(); | (*iter)->updatePull(); | ||||
parsToMaster.Add( *iter ); | parsToCoordinator.Add( *iter ); | ||||
} | } | ||||
// Write the results into the ntuple | // Write the results into the ntuple | ||||
std::vector<LauParameter> extraVars; | std::vector<LauParameter> extraVars; | ||||
LauFitNtuple* ntuple = this->fitNtuple(); | LauFitNtuple* ntuple = this->fitNtuple(); | ||||
ntuple->storeParsAndErrors(fitPars_, extraVars); | ntuple->storeParsAndErrors(fitPars_, extraVars); | ||||
// find out the correlation matrix for the parameters | // find out the correlation matrix for the parameters | ||||
ntuple->storeCorrMatrix(this->iExpt(), this->fitStatus(), this->covarianceMatrix()); | ntuple->storeCorrMatrix(this->iExpt(), this->fitStatus(), this->covarianceMatrix()); | ||||
// Fill the data into ntuple | // Fill the data into ntuple | ||||
ntuple->updateFitNtuple(); | ntuple->updateFitNtuple(); | ||||
} | } | ||||