musrfit  1.9.2
PFunction.h
Go to the documentation of this file.
1 /***************************************************************************
2 
3  PFunction.h
4 
5  Author: Andreas Suter
6  e-mail: andreas.suter@psi.ch
7 
8 ***************************************************************************/
9 
10 /***************************************************************************
11  * Copyright (C) 2007-2023 by Andreas Suter *
12  * andreas.suter@psi.ch *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  * This program is distributed in the hope that it will be useful, *
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22  * GNU General Public License for more details. *
23  * *
24  * You should have received a copy of the GNU General Public License *
25  * along with this program; if not, write to the *
26  * Free Software Foundation, Inc., *
27  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
28  ***************************************************************************/
29 
30 #ifndef _PFUNCTION_H_
31 #define _PFUNCTION_H_
32 
33 #include <vector>
34 
35 #include <boost/version.hpp>
36 
37 #if BOOST_VERSION >= 103800
38 # include <boost/spirit/include/classic_ast.hpp>
39  using namespace BOOST_SPIRIT_CLASSIC_NS;
40 #else
41 # include <boost/spirit/tree/ast.hpp>
42  using namespace boost::spirit;
43 #endif
44 
45 #include <TString.h>
46 
47 #include "PMusr.h"
48 #include "PFunctionGrammar.h"
49 
50 //----------------------------------------------------------------------------
51 #define OP_ADD 0
52 #define OP_SUB 1
53 #define OP_MUL 2
54 #define OP_DIV 3
55 
56 #define FUN_COS 0
57 #define FUN_SIN 1
58 #define FUN_TAN 2
59 #define FUN_COSH 3
60 #define FUN_SINH 4
61 #define FUN_TANH 5
62 #define FUN_ACOS 6
63 #define FUN_ASIN 7
64 #define FUN_ATAN 8
65 #define FUN_ACOSH 9
66 #define FUN_ASINH 10
67 #define FUN_ATANH 11
68 #define FUN_LOG 12
69 #define FUN_LN 13
70 #define FUN_EXP 14
71 #define FUN_SQRT 15
72 #define FUN_POW 16
73 
74 //----------------------------------------------------------------------------
78 typedef struct func_tree_node {
79  Int_t fID;
80  Int_t fOperatorTag;
81  Int_t fFunctionTag;
82  Int_t fIvalue;
83  Bool_t fSign;
84  Double_t fDvalue;
85  std::vector<func_tree_node> children;
87 
88 //----------------------------------------------------------------------------
92 class PFunction {
93  public:
94  PFunction(tree_parse_info<> info);
95  virtual ~PFunction();
96 
97  virtual Bool_t IsValid() { return fValid; }
98  virtual Int_t GetFuncNo() { return fFuncNo; }
99  virtual Bool_t CheckMapAndParamRange(UInt_t mapSize, UInt_t paramSize);
100  virtual Double_t Eval(std::vector<Double_t> param, PMetaData metaData);
101  virtual void SetMap(std::vector<Int_t> map) { fMap = map; }
102 
103  virtual TString* GetFuncString() { return &fFuncString; }
104 
105  protected:
106  virtual void InitNode(PFuncTreeNode &node);
107  virtual Bool_t SetFuncNo();
108 
109  virtual Bool_t FindAndCheckMapAndParamRange(PFuncTreeNode &node, UInt_t mapSize, UInt_t paramSize);
110  virtual Bool_t GenerateFuncEvalTree();
111  virtual void FillFuncEvalTree(iter_t const& i, PFuncTreeNode &node);
112  virtual Double_t EvalNode(PFuncTreeNode &node);
113  virtual void CleanupFuncEvalTree();
114  virtual void CleanupNode(PFuncTreeNode &node);
115 
116  private:
117  tree_parse_info<> fInfo;
118  std::vector<Double_t> fParam;
119  std::vector<Int_t> fMap;
121 
122  Bool_t fValid;
123  Int_t fFuncNo;
124 
125  virtual void EvalTreeForString(tree_parse_info<> info);
126  virtual void EvalTreeForStringExpression(iter_t const& i);
127  TString fFuncString;
128 
130 };
131 
132 #endif // _PFUNCTION_H_
Bool_t fValid
flag showing if the function is valid
Definition: PFunction.h:122
virtual void SetMap(std::vector< Int_t > map)
Definition: PFunction.h:101
Int_t fOperatorTag
tag for &#39;+&#39;, &#39;-&#39;, &#39;*&#39;, &#39;/&#39;
Definition: PFunction.h:80
PFuncTreeNode fFunc
Definition: PFunction.h:120
virtual Int_t GetFuncNo()
Definition: PFunction.h:98
Double_t fDvalue
for numbers
Definition: PFunction.h:84
parse_tree_match_t::tree_iterator iter_t
std::vector< Double_t > fParam
parameter vector (from the msr-file Fit Parameter block)
Definition: PFunction.h:118
Int_t fFuncNo
function number, i.e. FUNx with x the function number
Definition: PFunction.h:123
std::vector< Int_t > fMap
map vector
Definition: PFunction.h:119
virtual Bool_t IsValid()
Definition: PFunction.h:97
Bool_t fSign
for sign, true means &#39;-&#39;, false &#39;+&#39;
Definition: PFunction.h:83
Int_t fFunctionTag
tag got "cos", "sin", ...
Definition: PFunction.h:81
PMetaData fMetaData
keeps meta data from data files (field, energy, temperature, ...)
Definition: PFunction.h:129
Int_t fID
tag showing what tree element this is
Definition: PFunction.h:79
Int_t fIvalue
for parameter numbers and maps
Definition: PFunction.h:82
std::vector< func_tree_node > children
holding sub-tree
Definition: PFunction.h:85
virtual TString * GetFuncString()
Definition: PFunction.h:103
struct func_tree_node PFuncTreeNode
TString fFuncString
clear text representation of the function
Definition: PFunction.h:127
tree_parse_info fInfo
AST parse tree holding a single parsed msr-function in an ascii representation.
Definition: PFunction.h:117