|
musrfit 1.10.0
|
Visitor class for evaluating the AST. More...


Public Member Functions | |
| EvalVisitor (const std::vector< Int_t > &map, const std::vector< Double_t > ¶m, const PMetaData &metaData) | |
| Double_t | operator() (const musrfit::ast::leer &) const |
| Evaluates a leer (empty) AST node. | |
| Double_t | operator() (double val) const |
| Evaluates a numeric literal. | |
| Double_t | operator() (const musrfit::ast::constant &c) const |
| Evaluates a constant (PI, GAMMA_MU, B, EN, T#). | |
| Double_t | operator() (const musrfit::ast::parameter &p) const |
| Evaluates a parameter reference (PAR#). | |
| Double_t | operator() (const musrfit::ast::map_ref &m) const |
| Evaluates a map reference (MAP#) for indirect parameter lookup. | |
| Double_t | operator() (const musrfit::ast::function_call &f) const |
| Evaluates a function call (COS, SIN, EXP, SQRT, etc.). | |
| Double_t | operator() (const musrfit::ast::power_call &p) const |
| Evaluates a power operation POW(base, exponent). | |
| Double_t | operator() (const musrfit::ast::expression &expr) const |
| Evaluates a complete expression with binary operators. | |
Private Attributes | |
| const std::vector< Int_t > & | fMap |
| const std::vector< Double_t > & | fParam |
| const PMetaData & | fMetaData |
Visitor class for evaluating the AST.
This visitor traverses the AST and computes the numeric value of the expression. It uses the visitor pattern with boost::static_visitor to handle different AST node types.
Definition at line 179 of file PFunction.h.
|
inline |
Definition at line 182 of file PFunction.h.
| Double_t PFunction::EvalVisitor::operator() | ( | const musrfit::ast::constant & | c | ) | const |
Evaluates a constant (PI, GAMMA_MU, B, EN, T#).
Converts symbolic constants to their numeric values, including full support for experimental metadata (magnetic field, energy, temperature).
| c | The constant AST node with type, sign, and optional index |
Definition at line 451 of file PFunction.cpp.
References fMetaData, and GAMMA_BAR_MUON.
| Double_t PFunction::EvalVisitor::operator() | ( | const musrfit::ast::expression & | e | ) | const |
Evaluates a complete expression with binary operators.
Evaluates the first operand, then applies each operation in sequence from left to right. The AST structure encodes operator precedence, so this left-to-right evaluation produces correct results.
Handles division by zero by checking if divisor magnitude is greater than 1e-20; otherwise returns 0.0 for that sub-expression.
| e | The expression AST node with first operand and operation list |
Definition at line 649 of file PFunction.cpp.
| Double_t PFunction::EvalVisitor::operator() | ( | const musrfit::ast::function_call & | f | ) | const |
Evaluates a function call (COS, SIN, EXP, SQRT, etc.).
Recursively evaluates the argument expression, then applies the specified mathematical function. Supports trigonometric, hyperbolic, inverse, exponential, and logarithmic functions.
| f | The function call AST node with function ID and argument expression |
Definition at line 552 of file PFunction.cpp.
| Double_t PFunction::EvalVisitor::operator() | ( | const musrfit::ast::leer & | ) | const |
Evaluates a leer (empty) AST node.
Definition at line 426 of file PFunction.cpp.
| Double_t PFunction::EvalVisitor::operator() | ( | const musrfit::ast::map_ref & | m | ) | const |
Evaluates a map reference (MAP#) for indirect parameter lookup.
Performs a two-level lookup: first looks up the map index in fMap, then uses that value to index into fParam. This allows for flexible parameter remapping. Validates both lookups and applies sign.
| m | The map reference AST node containing map number and sign |
Definition at line 522 of file PFunction.cpp.
| Double_t PFunction::EvalVisitor::operator() | ( | const musrfit::ast::parameter & | p | ) | const |
Evaluates a parameter reference (PAR#).
Looks up the parameter value from the fParam vector using the parameter number (1-based indexing in syntax, 0-based in vector). Validates bounds and applies sign.
| p | The parameter AST node containing number and sign |
Definition at line 499 of file PFunction.cpp.
References fParam.
| Double_t PFunction::EvalVisitor::operator() | ( | const musrfit::ast::power_call & | p | ) | const |
Evaluates a power operation POW(base, exponent).
Recursively evaluates both the base and exponent expressions, then computes base^exponent using std::pow. Uses absolute value of base to avoid complex number issues with negative bases.
| p | The power call AST node with base and exponent expressions |
Definition at line 603 of file PFunction.cpp.
| Double_t PFunction::EvalVisitor::operator() | ( | double | val | ) | const |
Evaluates a numeric literal.
| val | The literal value from the AST |
Definition at line 437 of file PFunction.cpp.
|
private |
Definition at line 197 of file PFunction.h.
Referenced by EvalVisitor(), and operator()().
|
private |
Definition at line 199 of file PFunction.h.
Referenced by EvalVisitor(), and operator()().
|
private |
Definition at line 198 of file PFunction.h.
Referenced by EvalVisitor(), operator()(), and operator()().