#include "RooFit.h"
#include "RooFormulaVar.h"
#include "RooFormulaVar.h"
#include "RooStreamParser.h"
#include "RooNLLVar.h"
#include "RooChi2Var.h"
ClassImp(RooFormulaVar)
RooFormulaVar::RooFormulaVar(const char *name, const char *title, const char* formula, const RooArgList& dependents) :
RooAbsReal(name,title),
_actualVars("actualVars","Variables used by formula expression",this),
_formula(0), _formExpr(formula)
{
_actualVars.add(dependents) ;
if (_actualVars.getSize()==0) _value = traceEval(0) ;
}
RooFormulaVar::RooFormulaVar(const char *name, const char *title, const RooArgList& dependents) :
RooAbsReal(name,title),
_actualVars("actualVars","Variables used by formula expression",this),
_formula(0), _formExpr(title)
{
_actualVars.add(dependents) ;
if (_actualVars.getSize()==0) _value = traceEval(0) ;
}
RooFormulaVar::RooFormulaVar(const RooFormulaVar& other, const char* name) :
RooAbsReal(other, name),
_actualVars("actualVars",this,other._actualVars),
_formula(0), _formExpr(other._formExpr)
{
}
RooFormulaVar::~RooFormulaVar()
{
if (_formula) delete _formula ;
}
RooFormula& RooFormulaVar::formula() const
{
if (!_formula) {
_formula = new RooFormula(GetName(),_formExpr,_actualVars) ;
}
return *_formula ;
}
Double_t RooFormulaVar::evaluate() const
{
return formula().eval(0) ;
}
Bool_t RooFormulaVar::isValidReal(Double_t , Bool_t ) const {
return kTRUE ;
}
Bool_t RooFormulaVar::redirectServersHook(const RooAbsCollection& newServerList, Bool_t mustReplaceAll, Bool_t nameChange, Bool_t )
{
return _formula ? _formula->changeDependents(newServerList,mustReplaceAll,nameChange) : kFALSE ;
}
void RooFormulaVar::printToStream(ostream& os, PrintOption opt, TString indent) const
{
RooAbsReal::printToStream(os,opt,indent);
if(opt >= Verbose) {
indent.Append(" ");
os << indent;
formula().printToStream(os,opt,indent);
}
}
Bool_t RooFormulaVar::readFromStream(istream& , Bool_t , Bool_t )
{
cout << "RooFormulaVar::readFromStream(" << GetName() << "): can't read" << endl ;
return kTRUE ;
}
void RooFormulaVar::writeToStream(ostream& os, Bool_t compact) const
{
if (compact) {
cout << getVal() << endl ;
} else {
os << GetTitle() ;
}
}
Double_t RooFormulaVar::defaultErrorLevel() const
{
RooAbsReal* nllArg(0) ;
RooAbsReal* chi2Arg(0) ;
TIterator* iter = _actualVars.createIterator() ;
RooAbsArg* arg ;
while((arg=(RooAbsArg*)iter->Next())) {
if (dynamic_cast<RooNLLVar*>(arg)) {
nllArg = (RooAbsReal*)arg ;
}
if (dynamic_cast<RooChi2Var*>(arg)) {
chi2Arg = (RooAbsReal*)arg ;
}
}
delete iter ;
if (nllArg && !chi2Arg) {
cout << "RooFormulaVar::defaultErrorLevel(" << GetName()
<< ") Formula contains a RooNLLVar, using its error level" << endl ;
return nllArg->defaultErrorLevel() ;
} else if (chi2Arg && !nllArg) {
cout << "RooFormulaVar::defaultErrorLevel(" << GetName()
<< ") Formula contains a RooChi2Var, using its error level" << endl ;
return chi2Arg->defaultErrorLevel() ;
} else if (!nllArg && !chi2Arg) {
cout << "RooFormulaVar::defaultErrorLevel(" << GetName() << ") WARNING: "
<< "Formula contains neither RooNLLVar nor RooChi2Var server, using default level of 1.0" << endl ;
} else {
cout << "RooFormulaVar::defaultErrorLevel(" << GetName() << ") WARNING: "
<< "Formula contains BOTH RooNLLVar and RooChi2Var server, using default level of 1.0" << endl ;
}
return 1.0 ;
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.