RootParFormula.h
Go to the documentation of this file.
1 // RootParFormula.h
2 //
3 // David Adams
4 // July 2021
5 //
6 // Implementation of ParFormula base on TFormula.
7 
8 #ifndef RootParFormula_H
9 #define RootParFormula_H
10 
12 #include "TFormula.h"
13 
14 class RootParFormula : public ParFormula {
15 
16 public:
17 
18  // Ctor from a string formula.
19  RootParFormula(Name snam, Name sform);
20 
21  // Name.
22  Name name() const override { return m_nam; }
23 
24  // Formula.
25  Name formulaString() const override { return m_sform; }
26 
27  // Variable dimension.
28  Index nvar() const override { return m_ptf == nullptr ? 0 : m_ptf->GetNdim(); }
29 
30  // Parameter counts.
31  Index npar() const override { return m_parNames.size(); }
32  Names pars() const override { return m_parNames; }
33  Names setPars() const override;
34  Names unsetPars() const override;
35  Names resetPars() const override;
36 
37  // Return if a parameter appears in the equation.
38  bool isPar(Name parnam) const override;
39 
40  // Return if ready for evaluation.
41  bool ready() const override;
42 
43  // Default return.
44  Value defaultEval() const override { return m_defval; }
45 
46  // Evaluate.
47  double eval(const Values& vars) const override {
48  return ready() && nvar() <= vars.size() ? m_ptf->EvalPar(&vars[0], &m_parValues[0]) : m_defval;
49  }
50  double eval(Value var) const override {
51  return ready() && nvar() <= 1 ? m_ptf->Eval(var) : m_defval;
52  }
53  double eval() const override {
54  return ready() && nvar() == 0 ? m_ptf->Eval(0.0) : m_defval;
55  }
56 
57  // Set a parameter value.
58  int setParValue(Name parnam, Value parval) override;
59 
60  // Set default return.
61  int setDefaultEval(Value val) override { m_defval = val; return 0; }
62 
63  // Unset paramter values.
64  int unsetParValues() override;
65 
66 private:
67 
69  TFormula* m_ptf;
73  std::vector<Index> m_setCounts;
75 
76 };
77 
78 #endif
79 
std::string Name
Definition: ParFormula.h:23
Name name() const override
std::vector< Index > m_setCounts
unsigned int Index
Definition: ParFormula.h:22
double eval() const override
int setParValue(Name parnam, Value parval) override
Names setPars() const override
Index nvar() const override
Index npar() const override
double eval(const Values &vars) const override
Value defaultEval() const override
RootParFormula(Name snam, Name sform)
double Value
Definition: ParFormula.h:20
TFormula * m_ptf
Name formulaString() const override
Names pars() const override
std::vector< Name > Names
Definition: ParFormula.h:24
int unsetParValues() override
Names unsetPars() const override
bool ready() const override
int var
Definition: 018_def.c:9
Names resetPars() const override
bool isPar(Name parnam) const override
std::vector< Value > Values
Definition: ParFormula.h:21
double eval(Value var) const override
int setDefaultEval(Value val) override