musrfit 1.10.0
PFunction::EvalVisitor Class Reference

Visitor class for evaluating the AST. More...

Inheritance diagram for PFunction::EvalVisitor:
Collaboration diagram for PFunction::EvalVisitor:

Public Member Functions

 EvalVisitor (const std::vector< Int_t > &map, const std::vector< Double_t > &param, 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 PMetaDatafMetaData
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ EvalVisitor()

PFunction::EvalVisitor::EvalVisitor ( const std::vector< Int_t > & map,
const std::vector< Double_t > & param,
const PMetaData & metaData )
inline

Definition at line 182 of file PFunction.h.

References fMap, fMetaData, and fParam.

Member Function Documentation

◆ operator()() [1/8]

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).

Parameters
cThe constant AST node with type, sign, and optional index
Returns
The constant's numeric value (with sign applied if negative)

Definition at line 451 of file PFunction.cpp.

References fMetaData, and GAMMA_BAR_MUON.

◆ operator()() [2/8]

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.

Parameters
eThe expression AST node with first operand and operation list
Returns
The computed result of the expression

Definition at line 649 of file PFunction.cpp.

◆ operator()() [3/8]

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.

Parameters
fThe function call AST node with function ID and argument expression
Returns
The result of applying the mathematical function to the argument

Definition at line 552 of file PFunction.cpp.

◆ operator()() [4/8]

Double_t PFunction::EvalVisitor::operator() ( const musrfit::ast::leer & ) const

Evaluates a leer (empty) AST node.

Returns
Always returns 0.0

Definition at line 426 of file PFunction.cpp.

◆ operator()() [5/8]

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.

Parameters
mThe map reference AST node containing map number and sign
Returns
The indirectly referenced parameter value (with sign), or 0.0 if invalid

Definition at line 522 of file PFunction.cpp.

References fMap, and fParam.

◆ operator()() [6/8]

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.

Parameters
pThe parameter AST node containing number and sign
Returns
The parameter value (with sign applied), or 0.0 if out of bounds

Definition at line 499 of file PFunction.cpp.

References fParam.

◆ operator()() [7/8]

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.

Parameters
pThe power call AST node with base and exponent expressions
Returns
The result of raising the base to the exponent power

Definition at line 603 of file PFunction.cpp.

◆ operator()() [8/8]

Double_t PFunction::EvalVisitor::operator() ( double val) const

Evaluates a numeric literal.

Parameters
valThe literal value from the AST
Returns
The literal value unchanged

Definition at line 437 of file PFunction.cpp.

Member Data Documentation

◆ fMap

const std::vector<Int_t>& PFunction::EvalVisitor::fMap
private

Definition at line 197 of file PFunction.h.

Referenced by EvalVisitor(), and operator()().

◆ fMetaData

const PMetaData& PFunction::EvalVisitor::fMetaData
private

Definition at line 199 of file PFunction.h.

Referenced by EvalVisitor(), and operator()().

◆ fParam

const std::vector<Double_t>& PFunction::EvalVisitor::fParam
private

Definition at line 198 of file PFunction.h.

Referenced by EvalVisitor(), operator()(), and operator()().


The documentation for this class was generated from the following files: