13 #ifndef ROOT_v5_TFormula
14 #define ROOT_v5_TFormula
31 const Int_t kMAXFOUND = 500;
32 const Int_t kTFOperMask = 0x7fffff;
33 const UChar_t kTFOperShift = 23;
40 class TFormulaPrimitive;
43 friend class TFormula;
65 class TFormula :
public TNamed {
69 typedef Double_t (TObject::*TFuncG)(
const Double_t*,
const Double_t*)
const;
86 TObjArray fLinearParts;
91 Int_t fNOperOptimized;
92 TString *fExprOptimized;
93 Int_t *fOperOptimized;
94 TOperOffset *fOperOffset;
95 TFormulaPrimitive **fPredefined;
99 virtual Bool_t CheckOperands(Int_t operation, Int_t &err);
100 virtual Bool_t CheckOperands(Int_t leftoperand, Int_t rightoperartion, Int_t &err);
101 virtual Bool_t StringToNumber(Int_t code);
102 void MakePrimitive(
const char *expr, Int_t pos);
103 inline Int_t *GetOper()
const {
return fOper; }
104 inline Short_t GetAction(Int_t code)
const {
return fOper[code] >> kTFOperShift; }
105 inline Int_t GetActionParam(Int_t code)
const {
return fOper[code] & kTFOperMask; }
107 inline void SetAction(Int_t code, Int_t value, Int_t param = 0) {
108 fOper[code] = (value) << kTFOperShift;
109 fOper[code] += param;
111 inline Int_t *GetOperOptimized()
const {
return fOperOptimized; }
112 inline Short_t GetActionOptimized(Int_t code)
const {
return fOperOptimized[code] >> kTFOperShift; }
113 inline Int_t GetActionParamOptimized(Int_t code)
const {
return fOperOptimized[code] & kTFOperMask; }
115 inline void SetActionOptimized(Int_t code, Int_t value, Int_t param = 0) {
116 fOperOptimized[code] = (value) << kTFOperShift;
117 fOperOptimized[code] += param;
120 void ClearFormula(Option_t *option=
"");
121 virtual Bool_t IsString(Int_t oper)
const;
123 virtual void Convert(UInt_t fromVersion);
126 Double_t EvalParFast(
const Double_t *x,
const Double_t *params);
127 Double_t EvalPrimitive(
const Double_t *x,
const Double_t *params);
128 Double_t EvalPrimitive0(
const Double_t *x,
const Double_t *params);
129 Double_t EvalPrimitive1(
const Double_t *x,
const Double_t *params);
130 Double_t EvalPrimitive2(
const Double_t *x,
const Double_t *params);
131 Double_t EvalPrimitive3(
const Double_t *x,
const Double_t *params);
132 Double_t EvalPrimitive4(
const Double_t *x,
const Double_t *params);
137 kAdd = 1, kSubstract = 2,
138 kMultiply = 3, kDivide = 4,
141 kcos = 10, ksin = 11 , ktan = 12,
142 kacos = 13, kasin = 14 , katan = 15,
146 kpow = 20, ksq = 21, ksqrt = 22,
150 kmin = 24, kmax = 25,
152 klog = 30, kexp = 31, klog10 = 32,
156 kabs = 41 , ksign= 42,
162 kEqual = 62, kNotEqual = 63,
163 kLess = 64, kGreater = 65,
164 kLessThan = 66, kGreaterThan = 67,
167 kcosh = 70 , ksinh = 71, ktanh = 72,
168 kacosh = 73 , kasinh = 74, katanh = 75,
170 kStringEqual = 76, kStringNotEqual = 77,
172 kBitAnd = 78, kBitOr = 79,
173 kLeftShift = 80, kRightShift = 81,
175 kJumpIf = 82, kJump = 83,
177 kexpo = 100 , kxexpo = 100, kyexpo = 101, kzexpo = 102, kxyexpo = 105,
178 kgaus = 110 , kxgaus = 110, kygaus = 111, kzgaus = 112, kxygaus = 115,
179 klandau = 120 , kxlandau = 120, kylandau = 121, kzlandau = 122, kxylandau = 125,
180 kpol = 130 , kxpol = 130, kypol = 131, kzpol = 132,
192 kDefinedVariable = 150,
193 kDefinedString = 151,
199 kBoolOptimizeOr = 156,
200 kBoolOptimizeAnd = 157,
212 kNotGlobal = BIT(10),
213 kNormalized = BIT(14),
218 TFormula(
const char *name,
const char *formula);
219 TFormula(
const TFormula &formula);
220 TFormula& operator=(
const TFormula &rhs);
225 virtual void Analyze(
const char *schain, Int_t &err, Int_t offset=0);
226 virtual Bool_t AnalyzeFunction(TString &chaine, Int_t &err, Int_t offset=0);
227 virtual Int_t Compile(
const char *expression=
"");
228 virtual void Copy(TObject &formula)
const;
229 virtual void Clear(Option_t *option=
"");
230 virtual char *DefinedString(Int_t code);
231 virtual Double_t DefinedValue(Int_t code);
232 virtual Int_t DefinedVariable(TString &variable,Int_t &action);
233 virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0)
const;
234 virtual Double_t EvalParOld(
const Double_t *x,
const Double_t *params=0);
235 virtual Double_t EvalPar(
const Double_t *x,
const Double_t *params=0){
return ((*this).*fOptimal)(x,params);};
236 virtual const TObject *GetLinearPart(Int_t i);
237 virtual Int_t GetNdim()
const {
return fNdim;}
238 virtual Int_t GetNpar()
const {
return fNpar;}
239 virtual Int_t GetNumber()
const {
return fNumber;}
240 virtual TString GetExpFormula(Option_t *option=
"")
const;
241 Double_t GetParameter(Int_t ipar)
const;
242 Double_t GetParameter(
const char *name)
const;
243 virtual Double_t *GetParameters()
const {
return fParams;}
244 virtual void GetParameters(Double_t *params){
for(Int_t i=0;i<fNpar;i++) params[i] = fParams[i];}
245 virtual const char *GetParName(Int_t ipar)
const;
246 virtual Int_t GetParNumber(
const char *name)
const;
247 virtual Bool_t IsLinear()
const {
return TestBit(kLinear);}
248 virtual Bool_t IsNormalized()
const {
return TestBit(kNormalized);}
249 virtual void Print(Option_t *option=
"")
const;
250 virtual void ProcessLinear(TString &replaceformula);
251 virtual void SetNumber(Int_t number) {fNumber = number;}
252 virtual void SetParameter(
const char *name, Double_t parvalue);
253 virtual void SetParameter(Int_t ipar, Double_t parvalue);
254 virtual void SetParameters(
const Double_t *params);
255 virtual void SetParameters(Double_t p0,Double_t p1,Double_t p2=0,Double_t p3=0,Double_t p4=0,
256 Double_t p5=0,Double_t p6=0,Double_t p7=0,Double_t p8=0,
257 Double_t p9=0,Double_t p10=0);
258 virtual void SetParName(Int_t ipar,
const char *name);
259 virtual void SetParNames(
const char *name0=
"p0",
const char *name1=
"p1",
const char
260 *name2=
"p2",
const char *name3=
"p3",
const char
261 *name4=
"p4",
const char *name5=
"p5",
const char *name6=
"p6",
const char *name7=
"p7",
const char
262 *name8=
"p8",
const char *name9=
"p9",
const char *name10=
"p10");
263 virtual void Update() {;}
265 static void SetMaxima(Int_t maxop=1000, Int_t maxpar=1000, Int_t maxconst=1000);
266 static void GetMaxima(Int_t& maxop, Int_t& maxpar, Int_t& maxconst);
268 void Streamer(TBuffer &b,
const TClass *onfile_class);
269 void Streamer(TBuffer &b, Int_t version, UInt_t start, UInt_t count,
const TClass *onfile_class = 0);
271 ClassDef(ROOT::v5::TFormula,8)