18 #pragma optimize("",off)
60 TObjArray * TFormulaPrimitive::fgListOfFunction = 0;
61 #ifdef R__COMPLETE_MEM_TERMINATION
63 class TFormulaPrimitiveCleanup {
66 TFormulaPrimitiveCleanup(
TObjArray **functions) : fListOfFunctions(functions) {}
67 ~TFormulaPrimitiveCleanup() {
68 delete *fListOfFunctions;
78 TFormulaPrimitive::TFormulaPrimitive() :
TNamed(),
80 fType(0),fNArguments(0),fNParameters(0),fIsStatic(
kTRUE)
88 TFormulaPrimitive::TFormulaPrimitive(
const char *
name,
const char *formula,
89 GenFunc0 fpointer) :
TNamed(name,formula),
91 fType(0),fNArguments(0),fNParameters(0),fIsStatic(
kTRUE)
99 TFormulaPrimitive::TFormulaPrimitive(
const char *name,
const char *formula,
100 GenFunc10 fpointer) :
TNamed(name,formula),
102 fType(10),fNArguments(1),fNParameters(0),fIsStatic(
kTRUE)
110 TFormulaPrimitive::TFormulaPrimitive(
const char *name,
const char *formula,
111 GenFunc110 fpointer) :
TNamed(name,formula),
113 fType(110),fNArguments(2),fNParameters(0),fIsStatic(
kTRUE)
121 TFormulaPrimitive::TFormulaPrimitive(
const char *name,
const char *formula,
122 GenFunc1110 fpointer) :
TNamed(name,formula),
124 fType(1110),fNArguments(3),fNParameters(0),fIsStatic(
kTRUE)
132 TFormulaPrimitive::TFormulaPrimitive(
const char *name,
const char *formula,
133 GenFuncG fpointer,
Int_t npar) :
TNamed(name,formula),
135 fType(-1),fNArguments(2),fNParameters(npar),fIsStatic(
kTRUE)
143 TFormulaPrimitive::TFormulaPrimitive(
const char *name,
const char *formula,
144 TFuncG fpointer) :
TNamed(name,formula),
146 fType(0),fNArguments(0),fNParameters(0),fIsStatic(
kFALSE)
154 TFormulaPrimitive::TFormulaPrimitive(
const char *name,
const char *formula,
155 TFunc0 fpointer) :
TNamed(name,formula),
157 fType(0),fNArguments(0),fNParameters(0),fIsStatic(
kFALSE)
165 TFormulaPrimitive::TFormulaPrimitive(
const char *name,
const char *formula,
166 TFunc10 fpointer) :
TNamed(name,formula),
168 fType(-10),fNArguments(1),fNParameters(0),fIsStatic(
kFALSE)
176 TFormulaPrimitive::TFormulaPrimitive(
const char *name,
const char *formula,
177 TFunc110 fpointer) :
TNamed(name,formula),
179 fType(-110),fNArguments(2),fNParameters(0),fIsStatic(
kFALSE)
187 TFormulaPrimitive::TFormulaPrimitive(
const char *name,
const char *formula,
188 TFunc1110 fpointer) :
TNamed(name,formula),
189 fTFunc1110(fpointer),
190 fType(-1110),fNArguments(3),fNParameters(0),fIsStatic(
kFALSE)
199 Int_t TFormulaPrimitive::AddFormula(TFormulaPrimitive * formula)
202 if (fgListOfFunction == 0) BuildBasicFormulas();
203 if (FindFormula(formula->GetName(),formula->fNArguments)){
207 fgListOfFunction->AddLast(formula);
217 if (fIsStatic ==
kFALSE)
return 0;
219 if (
fType==0)
return fFunc0();
221 return fFunc10(x[0]);
224 return fFunc110(x[0],x[1]);
227 return fFunc1110(x[0],x[1],x[2]);
238 if (fIsStatic ==
kTRUE)
return 0;
239 if (
fType== 0)
return (*o.*fTFunc0)();
240 if (
fType==-10)
return (*o.*fTFunc10)(*x);
241 if (
fType==-110)
return (*o.*fTFunc110)(x[0],x[1]);
242 if (
fType==-1110)
return (*o.*fTFunc1110)(x[0],x[1],x[2]);
252 return fFuncG(x,param);
256 #define RTFastFun__POLY(var) \
258 Double_t res= param[var-1]+param[var]*x[0]; \
259 for (Int_t j=var-1 ;j>0;j--) res = param[j-1]+x[0]*res; \
319 TFormulaPrimitive* TFormulaPrimitive::FindFormula(
const char* name)
322 if (!fgListOfFunction) {
323 BuildBasicFormulas();
325 Int_t nobjects = fgListOfFunction->GetEntries();
326 for (
Int_t i = 0; i < nobjects; ++i) {
327 TFormulaPrimitive *formula = (TFormulaPrimitive*)fgListOfFunction->At(i);
328 if (formula && 0==strcmp(name, formula->GetName()))
return formula;
337 TFormulaPrimitive* TFormulaPrimitive::FindFormula(
const char* name,
UInt_t nargs)
340 if (!fgListOfFunction) {
341 BuildBasicFormulas();
343 Int_t nobjects = fgListOfFunction->GetEntries();
344 for (
Int_t i = 0; i < nobjects; ++i) {
345 TFormulaPrimitive *prim = (TFormulaPrimitive*)fgListOfFunction->At(i);
347 bool match = ( ((
UInt_t)prim->fNArguments) == nargs );
348 if (match && 0==strcmp(name, prim->GetName()))
return prim;
358 TFormulaPrimitive* TFormulaPrimitive::FindFormula(
const char* name,
const char *args)
366 for(
UInt_t c = 0;
c < strlen(args); ++
c ) {
368 case '(': ++nest;
break;
369 case ')': --nest;
break;
370 case '<': ++nest;
break;
371 case '>': --nest;
break;
372 case ',': nargs += (nest==0);
break;
376 return FindFormula(name,nargs);
378 return FindFormula(name);
390 for (
Int_t j=npar ;j>=0;j--) {
391 res += temp*param[j];
403 if (sigma == 0)
return 1.e30;
414 if (sigma == 0)
return 0;
416 return TMath::Exp(-0.5*arg*arg)/(2.50662827463100024*sigma);
423 Int_t TFormulaPrimitive::BuildBasicFormulas()
426 if (fgListOfFunction==0) {
428 fgListOfFunction->SetOwner(
kTRUE);
430 #ifdef R__COMPLETE_MEM_TERMINATION
431 static TFormulaPrimitiveCleanup gCleanup(&fgListOfFunction);
437 AddFormula(
new TFormulaPrimitive(
"XandY",
"XandY",TFastFun::XandY));
438 AddFormula(
new TFormulaPrimitive(
"XorY",
"XorY",TFastFun::XorY));
439 AddFormula(
new TFormulaPrimitive(
"XNot",
"XNot",TFastFun::XNot));
440 AddFormula(
new TFormulaPrimitive(
"XlY",
"XlY",TFastFun::XlY));
441 AddFormula(
new TFormulaPrimitive(
"XleY",
"XleY",TFastFun::XleY));
442 AddFormula(
new TFormulaPrimitive(
"XgY",
"XgY",TFastFun::XgY));
443 AddFormula(
new TFormulaPrimitive(
"XgeY",
"XgeY",TFastFun::XgeY));
444 AddFormula(
new TFormulaPrimitive(
"XeY",
"XeY",TFastFun::XeY));
445 AddFormula(
new TFormulaPrimitive(
"XneY",
"XneY",TFastFun::XneY));
447 AddFormula(
new TFormulaPrimitive(
"PlusXY",
"PlusXY",TFastFun::PlusXY));
448 AddFormula(
new TFormulaPrimitive(
"MinusXY",
"MinusXY",TFastFun::MinusXY));
449 AddFormula(
new TFormulaPrimitive(
"MultXY",
"MultXY",TFastFun::MultXY));
450 AddFormula(
new TFormulaPrimitive(
"DivXY",
"DivXY",TFastFun::DivXY));
451 AddFormula(
new TFormulaPrimitive(
"XpYpZ",
"XpYpZ",TFastFun::XpYpZ));
452 AddFormula(
new TFormulaPrimitive(
"XxYxZ",
"XxYxZ",TFastFun::XxYxZ));
453 AddFormula(
new TFormulaPrimitive(
"XxYpZ",
"XxYpZ",TFastFun::XxYpZ));
454 AddFormula(
new TFormulaPrimitive(
"XpYxZ",
"XpYxZ",TFastFun::XpYxZ));
458 AddFormula(
new TFormulaPrimitive(
"Gausn",
"Gausn",TFastFun::Gausn));
460 AddFormula(
new TFormulaPrimitive(
"Landaun",
"Landaun",TFastFun::Landaun));
466 AddFormula(
new TFormulaPrimitive(
"Pol0",
"Pol0",(GenFuncG)TFastFun::FPol0,1));
467 AddFormula(
new TFormulaPrimitive(
"Pol1",
"Pol1",(GenFuncG)TFastFun::FPol1,2));
468 AddFormula(
new TFormulaPrimitive(
"Pol2",
"Pol2",(GenFuncG)TFastFun::FPol2,3));
469 AddFormula(
new TFormulaPrimitive(
"Pol3",
"Pol3",(GenFuncG)TFastFun::FPol3,4));
470 AddFormula(
new TFormulaPrimitive(
"Pol4",
"Pol4",(GenFuncG)TFastFun::FPol4,5));
471 AddFormula(
new TFormulaPrimitive(
"Pol5",
"Pol5",(GenFuncG)TFastFun::FPol5,6));
472 AddFormula(
new TFormulaPrimitive(
"Pol6",
"Pol6",(GenFuncG)TFastFun::FPol6,7));
473 AddFormula(
new TFormulaPrimitive(
"Pol7",
"Pol7",(GenFuncG)TFastFun::FPol7,8));
474 AddFormula(
new TFormulaPrimitive(
"Pol8",
"Pol8",(GenFuncG)TFastFun::FPol8,9));
475 AddFormula(
new TFormulaPrimitive(
"Pol9",
"Pol9",(GenFuncG)TFastFun::FPol9,10));
476 AddFormula(
new TFormulaPrimitive(
"Pol10",
"Pol10",(GenFuncG)TFastFun::FPol10,11));
479 AddFormula(
new TFormulaPrimitive(
"Pow2",
"Pow2",TFastFun::Pow2));
480 AddFormula(
new TFormulaPrimitive(
"Pow3",
"Pow3",TFastFun::Pow3));
481 AddFormula(
new TFormulaPrimitive(
"Pow4",
"Pow4",TFastFun::Pow4));
482 AddFormula(
new TFormulaPrimitive(
"Pow5",
"Pow5",TFastFun::Pow5));
485 AddFormula(
new TFormulaPrimitive(
"TMath::Cos",
"TMath::Cos",
cos));
486 AddFormula(
new TFormulaPrimitive(
"cos",
"cos",
cos));
487 AddFormula(
new TFormulaPrimitive(
"TMath::Sin",
"TMath::Sin",
sin));
488 AddFormula(
new TFormulaPrimitive(
"sin",
"sin",
sin));
489 AddFormula(
new TFormulaPrimitive(
"TMath::Tan",
"TMath::Tan",
tan));
490 AddFormula(
new TFormulaPrimitive(
"tan",
"tan",
tan));
491 AddFormula(
new TFormulaPrimitive(
"TMath::ACos",
"TMath::ACos",
acos));
492 AddFormula(
new TFormulaPrimitive(
"acos",
"acos",
acos));
493 AddFormula(
new TFormulaPrimitive(
"TMath::ASin",
"TMath::ASin",
asin));
494 AddFormula(
new TFormulaPrimitive(
"asin",
"asin",
asin));
495 AddFormula(
new TFormulaPrimitive(
"TMath::ATan",
"TMath::ATan",
atan));
496 AddFormula(
new TFormulaPrimitive(
"atan",
"atan",
atan));
497 AddFormula(
new TFormulaPrimitive(
"TMath::ATan2",
"TMath::ATan2",
atan2));
498 AddFormula(
new TFormulaPrimitive(
"atan2",
"atan2",
atan2));
500 AddFormula(
new TFormulaPrimitive(
"pow",
"pow",
TMath::Power));
501 AddFormula(
new TFormulaPrimitive(
"sq",
"sq",TFastFun::Pow2));
504 AddFormula(
new TFormulaPrimitive(
"min",
"min",(GenFunc110)
TMath::Min));
505 AddFormula(
new TFormulaPrimitive(
"max",
"max",(GenFunc110)
TMath::Max));
507 AddFormula(
new TFormulaPrimitive(
"log",
"log",
TMath::Log));
508 AddFormula(
new TFormulaPrimitive(
"exp",
"exp",
TMath::Exp));
509 AddFormula(
new TFormulaPrimitive(
"log10",
"log10",
TMath::Log10));
515 AddFormula(
new TFormulaPrimitive(
"TMath::CosH",
"TMath::Cosh",
cosh));
516 AddFormula(
new TFormulaPrimitive(
"cosh",
"cosh",
cosh));
517 AddFormula(
new TFormulaPrimitive(
"TMath::SinH",
"TMath::SinH",
sinh));
518 AddFormula(
new TFormulaPrimitive(
"sinh",
"sinh",
sinh));
519 AddFormula(
new TFormulaPrimitive(
"TMath::TanH",
"TMath::Tanh",
tanh));
520 AddFormula(
new TFormulaPrimitive(
"tanh",
"tanh",
tanh));
521 AddFormula(
new TFormulaPrimitive(
"TMath::ACosH",
"TMath::ACosh",
TMath::ACosH));
522 AddFormula(
new TFormulaPrimitive(
"acosh",
"acosH",
TMath::ACosH));
523 AddFormula(
new TFormulaPrimitive(
"TMath::ASinH",
"TMath::ASinh",
TMath::ASinH));
524 AddFormula(
new TFormulaPrimitive(
"acosh",
"acosH",
TMath::ASinH));
525 AddFormula(
new TFormulaPrimitive(
"TMath::ATanH",
"TMath::ATanh",
TMath::ATanH));
526 AddFormula(
new TFormulaPrimitive(
"atanh",
"atanh",
TMath::ATanH));
528 AddFormula(
new TFormulaPrimitive(
"TMath::Abs",
"TMath::Abs",
TMath::Abs));
529 AddFormula(
new TFormulaPrimitive(
"TMath::BreitWigner",
"TMath::BreitWigner",
TMath::BreitWigner));
Double_t Landau(Double_t x, Double_t mpv=0, Double_t sigma=1, Bool_t norm=kFALSE)
The LANDAU function.
Double_t BreitWigner(Double_t x, Double_t mean=0, Double_t gamma=1)
Calculate a Breit Wigner function with mean and gamma.
Namespace for new ROOT classes and functions.
This class implements a mutex interface.
Short_t Min(Short_t a, Short_t b)
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
The TNamed class is the base class for all named ROOT classes.
UChar_t mod R__LOCKGUARD2(gSrvAuthenticateMutex)
Double_t Log10(Double_t x)
Double_t Gaus(Double_t x, Double_t mean=0, Double_t sigma=1, Bool_t norm=kFALSE)
Calculate a gaussian function with mean and sigma.
double atan2(double, double)
Mother of all ROOT objects.
Short_t Max(Short_t a, Short_t b)
Double_t Sqrt(Double_t x)
void TMath_GenerInterface()