1 #include "TPolynomial.h"
4 void TPolynomial::MakePolySeries(Double_t x, Int_t type, Int_t Np, Double_t *P) {
7 for (Int_t i = 1; i < Np; i++) {
11 case 3: P[n+1] = -x + 1;
break;
12 case 4: P[n+1] = 2*x;
break;
16 default: P[n+1] = x;
break;
21 case 1: P[n+1] = 2*x*P[n] - P[n-1];
break;
22 case 2: P[n+1] =((2.*n+1)*x*P[n] - n*P[n-1])/(n+1);
break;
23 case 3: P[n+1] = (2*n+1-x)*P[n]-n*n*P[n-1];
break;
24 case 4: P[n+1] = 2*x*P[n]-2*n*P[n-1];
break;
26 default: P[n+1] = P[n]*x;
break;
32 Double_t TPolynomial::CalcPoly(Double_t *x, Double_t *par) {
34 Int_t key = TMath::Nint(par[0]);
35 Int_t R = key/(100*100);
45 case 1: X = 2*x[0];
break;
46 case 2: X = TMath::Log(x[0]);
break;
47 case 3: X = TMath::Exp(x[0]);
break;
48 case 4: X = 2*x[0] - 1;
break;
49 case 6: scale = x[0]*(1-TMath::Abs(x[0])); i1 = 0; i2--;
50 case 5: X = 2*TMath::Power(x[0],2) - 1;
break;
51 case 8: scale = 2*x[0]*(1-TMath::Abs(2*x[0])); i1 = 0; i2--;
52 case 7: X = 8*TMath::Power(x[0],2) - 1;
break;
53 default: X = x[0];
break;
56 Double_t *P =
new Double_t[np];
57 TPolynomial::MakePolySeries(X,T,np,P);
59 Double_t val = par[ip]*P[0]; ip++;
60 for (Int_t i = i1; ip < n; i++, ip++) {
61 val += scale*par[ip]*P[i];
67 TF1 *TPolynomial::MakePoly(TString Name, Int_t Npar, Int_t R, Double_t xmin, Double_t xmax) {
79 if (Name.BeginsWith(
"Pol",TString::kIgnoreCase)) T = 0;
80 if (Name.BeginsWith(
"Tch",TString::kIgnoreCase)) T = 1;
81 if (Name.BeginsWith(
"Leg",TString::kIgnoreCase)) T = 2;
82 if (Name.BeginsWith(
"Lag",TString::kIgnoreCase)) T = 3;
83 if (Name.BeginsWith(
"Her",TString::kIgnoreCase)) T = 4;
84 Int_t key = Npar + 1 + 100*(100*R + T);
85 TF1 *f =
new TF1(Form(
"%s_%i_%i",Name.Data(),R,Npar),TPolynomial::CalcPoly,xmin,xmax,Npar+1);
86 f->FixParameter(0,key);
87 for (Int_t i = 1; i <= Npar; i++) f->SetParameter(i,0);
91 TF1 *TPolynomial::MakePol(
const Int_t N,
const Char_t *X, TString type, Int_t i0) {
93 if (! type.CompareTo(
"PL",TString::kIgnoreCase)) {
94 Func = Form(
"[%i]",N); cout << Func << endl;
95 for (
int n = N-1+i0; n>=i0; n--) {
97 if (n < N-1) temp = Form(
"%s*(%s)+[%i]",X,Func.Data(),n);
98 else temp = Form(
"%s*%s+[%i]",X,Func.Data(),n);
99 Func = temp; cout << Func << endl;
103 TString T0(
"1"); Func = Form(
"[0]");
108 if (! type.CompareTo(
"TCheb",TString::kIgnoreCase)) xx = Form(
"%s",X);
109 else xx = Form(
"(2*%s-1)",X);
111 Func += Form(
"+[1]*%s",T1.Data()); cout << Func << endl;
112 for (
int n = 2; n<=N; n++) {
113 T2 = Form(
"(2*%s*%s-%s)",xx.Data(),T1.Data(),T0.Data());
115 cout << T0 <<
"\t" << T1 <<
"\t" << T2 << endl;
116 Func += Form(
"+[%i]*%s",n,T2.Data()); cout << Func << endl;
123 if (Func !=
"") {fun =
new TF1(Form(
"%s%i",type.Data(),N),Func.Data()); cout <<
"Make " << fun->GetName() << endl;}
127 void TPolynomial::GetFunc(TF1 *func) {
129 TString Func(func->GetTitle());
130 Int_t Npar = func->GetNpar();
131 for (Int_t p = 0; p < Npar; p++) {
133 par += func->GetParameter(p);
134 Func.ReplaceAll(Form(
"[%i]",p),par.Data());
136 cout << Func << endl;