Changeset View
Changeset View
Standalone View
Standalone View
src/LauFormulaPar.cc
Show All 40 Lines | |||||
ClassImp(LauFormulaPar) | ClassImp(LauFormulaPar) | ||||
LauFormulaPar::LauFormulaPar(const TString& forName, const TString& formula, const std::vector<LauParameter*>& params) : | LauFormulaPar::LauFormulaPar(const TString& forName, const TString& formula, const std::vector<LauParameter*>& params) : | ||||
name_(forName), | name_(forName), | ||||
formula_(forName,formula), | formula_(forName,formula), | ||||
paramVec_(params), | paramVec_(params), | ||||
dummy_(0), | paramArray_(nullptr), | ||||
paramArray_(0), | |||||
gaussConstraint_(kFALSE), | gaussConstraint_(kFALSE), | ||||
constraintMean_(0.0), | constraintMean_(0.0), | ||||
constraintWidth_(0.0) | constraintWidth_(0.0) | ||||
{ | { | ||||
// Check length of vector matches number of parameter in the formula | // Check length of vector matches number of parameter in the formula | ||||
Int_t nPars = paramVec_.size(); | Int_t nPars = paramVec_.size(); | ||||
if (formula_.GetNpar() != nPars){ | if (formula_.GetNpar() != nPars){ | ||||
std::cerr<<"ERROR in LauFormulaPar::evaluate : Number of parameters in the formula is : "<<formula_.GetNpar()<< " and the number of LauParameters is : "<<nPars<<std::endl; | std::cerr<<"ERROR in LauFormulaPar::evaluate : Number of parameters in the formula is : "<<formula_.GetNpar()<< " and the number of LauParameters is : "<<nPars<<std::endl; | ||||
gSystem->Exit(EXIT_FAILURE); | gSystem->Exit(EXIT_FAILURE); | ||||
} | } | ||||
if (formula_.GetNdim() != 1){ | if (formula_.GetNdim() != 0){ | ||||
std::cerr<<"ERROR in LauFormulaPar::evaluate : Given formula of dimension: "<<formula_.GetNdim()<<" and not 1"<<std::endl; | std::cerr<<"ERROR in LauFormulaPar::evaluate : Given formula of dimension: "<<formula_.GetNdim()<<" and not 0"<<std::endl; | ||||
gSystem->Exit(EXIT_FAILURE); | gSystem->Exit(EXIT_FAILURE); | ||||
} | } | ||||
// Dummy array for TFormula | |||||
dummy_ = new Double_t[1]; | |||||
// Array of input parameters | // Array of input parameters | ||||
paramArray_ = new Double_t[nPars]; | paramArray_ = new Double_t[nPars]; | ||||
} | } | ||||
LauFormulaPar::~LauFormulaPar() | LauFormulaPar::~LauFormulaPar() | ||||
{ | { | ||||
delete[] dummy_; | |||||
delete[] paramArray_; | delete[] paramArray_; | ||||
} | } | ||||
LauFormulaPar::LauFormulaPar(const LauFormulaPar& rhs) : LauAbsRValue(rhs), | LauFormulaPar::LauFormulaPar(const LauFormulaPar& rhs) : LauAbsRValue(rhs), | ||||
name_(rhs.name_), | name_(rhs.name_), | ||||
formula_(rhs.formula_), | formula_(rhs.formula_), | ||||
paramVec_(rhs.paramVec_), | paramVec_(rhs.paramVec_), | ||||
dummy_(0), | paramArray_(nullptr), | ||||
paramArray_(0), | |||||
gaussConstraint_(rhs.gaussConstraint_), | gaussConstraint_(rhs.gaussConstraint_), | ||||
constraintMean_(rhs.constraintMean_), | constraintMean_(rhs.constraintMean_), | ||||
constraintWidth_(rhs.constraintWidth_) | constraintWidth_(rhs.constraintWidth_) | ||||
{ | { | ||||
// Check length of vector matches number of parameter in the formula | // Check length of vector matches number of parameter in the formula | ||||
Int_t nPars = paramVec_.size(); | Int_t nPars = paramVec_.size(); | ||||
if (formula_.GetNpar() != nPars){ | if (formula_.GetNpar() != nPars){ | ||||
std::cerr<<"ERROR in LauFormulaPar::evaluate : Number of parameters in the formula is : "<<formula_.GetNpar()<< " and the number of LauParameters is : "<<nPars<<std::endl; | std::cerr<<"ERROR in LauFormulaPar::evaluate : Number of parameters in the formula is : "<<formula_.GetNpar()<< " and the number of LauParameters is : "<<nPars<<std::endl; | ||||
gSystem->Exit(EXIT_FAILURE); | gSystem->Exit(EXIT_FAILURE); | ||||
} | } | ||||
if (formula_.GetNdim() != 1){ | if (formula_.GetNdim() != 0){ | ||||
std::cerr<<"ERROR in LauFormulaPar::evaluate : Given formula of dimension: "<<formula_.GetNdim()<<" and not 1"<<std::endl; | std::cerr<<"ERROR in LauFormulaPar::evaluate : Given formula of dimension: "<<formula_.GetNdim()<<" and not 0"<<std::endl; | ||||
gSystem->Exit(EXIT_FAILURE); | gSystem->Exit(EXIT_FAILURE); | ||||
} | } | ||||
// Dummy array for TFormula | |||||
dummy_ = new Double_t[1]; | |||||
// Array of input parameters | // Array of input parameters | ||||
paramArray_ = new Double_t[nPars]; | paramArray_ = new Double_t[nPars]; | ||||
} | } | ||||
LauFormulaPar& LauFormulaPar::operator=(const LauFormulaPar& rhs) | LauFormulaPar& LauFormulaPar::operator=(const LauFormulaPar& rhs) | ||||
{ | { | ||||
if ( &rhs != this ) { | if ( &rhs != this ) { | ||||
name_ = rhs.name_; | name_ = rhs.name_; | ||||
formula_ = rhs.formula_; | formula_ = rhs.formula_; | ||||
Int_t nOldPars = paramVec_.size(); | Int_t nOldPars = paramVec_.size(); | ||||
Int_t nNewPars = rhs.paramVec_.size(); | Int_t nNewPars = rhs.paramVec_.size(); | ||||
paramVec_ = rhs.paramVec_; | paramVec_ = rhs.paramVec_; | ||||
if ( nOldPars != nNewPars ) { | if ( nOldPars != nNewPars ) { | ||||
delete [] paramArray_; | delete [] paramArray_; | ||||
paramArray_ = new Double_t[nNewPars]; | paramArray_ = new Double_t[nNewPars]; | ||||
} | } | ||||
// NB no need to recreate dummy_ | |||||
gaussConstraint_ = rhs.gaussConstraint_; | gaussConstraint_ = rhs.gaussConstraint_; | ||||
constraintMean_ = rhs.constraintMean_; | constraintMean_ = rhs.constraintMean_; | ||||
constraintWidth_ = rhs.constraintWidth_; | constraintWidth_ = rhs.constraintWidth_; | ||||
} | } | ||||
return *this; | return *this; | ||||
} | } | ||||
Double_t LauFormulaPar::value() const | Double_t LauFormulaPar::value() const | ||||
{ | { | ||||
//Assign vector values to array | //Assign vector values to array | ||||
Int_t nPars = paramVec_.size(); | Int_t nPars = paramVec_.size(); | ||||
for(Int_t i=0; i<nPars; ++i){ | for(Int_t i=0; i<nPars; ++i){ | ||||
paramArray_[i] = paramVec_[i]->value(); | paramArray_[i] = paramVec_[i]->value(); | ||||
} | } | ||||
return formula_.EvalPar(dummy_,paramArray_); | return formula_.EvalPar(nullptr,paramArray_); | ||||
} | } | ||||
Double_t LauFormulaPar::unblindValue() const | Double_t LauFormulaPar::unblindValue() const | ||||
{ | { | ||||
//Assign vector values to array | //Assign vector values to array | ||||
Int_t nPars = paramVec_.size(); | Int_t nPars = paramVec_.size(); | ||||
for(Int_t i=0; i<nPars; ++i){ | for(Int_t i=0; i<nPars; ++i){ | ||||
paramArray_[i] = paramVec_[i]->unblindValue(); | paramArray_[i] = paramVec_[i]->unblindValue(); | ||||
} | } | ||||
return formula_.EvalPar(dummy_,paramArray_); | return formula_.EvalPar(nullptr,paramArray_); | ||||
} | } | ||||
Double_t LauFormulaPar::genValue() const | Double_t LauFormulaPar::genValue() const | ||||
{ | { | ||||
//Assign vector values to array | //Assign vector values to array | ||||
Int_t nPars = paramVec_.size(); | Int_t nPars = paramVec_.size(); | ||||
for(Int_t i=0; i<nPars; ++i){ | for(Int_t i=0; i<nPars; ++i){ | ||||
paramArray_[i] = paramVec_[i]->genValue(); | paramArray_[i] = paramVec_[i]->genValue(); | ||||
} | } | ||||
return formula_.EvalPar(dummy_,paramArray_); | return formula_.EvalPar(nullptr,paramArray_); | ||||
} | } | ||||
Double_t LauFormulaPar::initValue() const | Double_t LauFormulaPar::initValue() const | ||||
{ | { | ||||
//Assign vector values to array | //Assign vector values to array | ||||
Int_t nPars = paramVec_.size(); | Int_t nPars = paramVec_.size(); | ||||
for(Int_t i=0; i<nPars; ++i){ | for(Int_t i=0; i<nPars; ++i){ | ||||
paramArray_[i] = paramVec_[i]->initValue(); | paramArray_[i] = paramVec_[i]->initValue(); | ||||
} | } | ||||
return formula_.EvalPar(dummy_,paramArray_); | return formula_.EvalPar(nullptr,paramArray_); | ||||
} | } | ||||
Bool_t LauFormulaPar::fixed() const | Bool_t LauFormulaPar::fixed() const | ||||
{ | { | ||||
for ( std::vector<LauParameter*>::const_iterator iter = paramVec_.begin(); iter != paramVec_.end(); ++iter ) { | for ( std::vector<LauParameter*>::const_iterator iter = paramVec_.begin(); iter != paramVec_.end(); ++iter ) { | ||||
if ( !(*iter)->fixed() ) { return kFALSE; } | if ( !(*iter)->fixed() ) { return kFALSE; } | ||||
} | } | ||||
return kTRUE; | return kTRUE; | ||||
Show All 22 Lines |