#include "RooFit.h"
#include "Riostream.h"
#include "RooFormulaVar.h"
#include "RooFormulaVar.h"
#include "RooStreamParser.h"
#include "RooNLLVar.h"
#include "RooChi2Var.h"
#include "RooMsgService.h"
ClassImp(RooFormulaVar)
RooFormulaVar::RooFormulaVar(const char *name, const char *title, const char* inFormula, const RooArgList& dependents) :
RooAbsReal(name,title),
_actualVars("actualVars","Variables used by formula expression",this),
_formula(0), _formExpr(inFormula)
{
_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::getVal(const RooArgSet* set) const
{
_nset = (RooArgSet*) set ;
return RooAbsReal::getVal(set) ;
}
Double_t RooFormulaVar::evaluate() const
{
return formula().eval(_nset) ;
}
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::printMultiline(ostream& os, Int_t contents, Bool_t verbose, TString indent) const
{
RooAbsReal::printMultiline(os,contents,verbose,indent);
if(verbose) {
indent.Append(" ");
os << indent;
formula().printMultiline(os,contents,verbose,indent);
}
}
Bool_t RooFormulaVar::readFromStream(istream& , Bool_t , Bool_t )
{
coutE(InputArguments) << "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) {
coutI(Minimization) << "RooFormulaVar::defaultErrorLevel(" << GetName()
<< ") Formula contains a RooNLLVar, using its error level" << endl ;
return nllArg->defaultErrorLevel() ;
} else if (chi2Arg && !nllArg) {
coutI(Minimization) << "RooFormulaVar::defaultErrorLevel(" << GetName()
<< ") Formula contains a RooChi2Var, using its error level" << endl ;
return chi2Arg->defaultErrorLevel() ;
} else if (!nllArg && !chi2Arg) {
coutI(Minimization) << "RooFormulaVar::defaultErrorLevel(" << GetName() << ") WARNING: "
<< "Formula contains neither RooNLLVar nor RooChi2Var server, using default level of 1.0" << endl ;
} else {
coutI(Minimization) << "RooFormulaVar::defaultErrorLevel(" << GetName() << ") WARNING: "
<< "Formula contains BOTH RooNLLVar and RooChi2Var server, using default level of 1.0" << endl ;
}
return 1.0 ;
}
Last change: Wed Jun 25 08:32:54 2008
Last generated: 2008-06-25 08:32
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.