BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtPolInt.cc
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2//
3// Environment:
4// This software is part of models developed at BES collaboration
5// based on the EvtGen framework. If you use all or part
6// of it, please give an appropriate acknowledgement.
7//
8// Copyright Information: See EvtGen/BesCopyright
9// Copyright (A) 2006 Ping Rong-Gang, Pang Cai-Ying@IHEP
10//
11// Module: EvtEvtPloInt.cc
12//
13// Description: Routine to deal with polynomial interpolation
14//
15// Modification history:
16//
17// Ping R.-G. December, 2010 Module created
18//
19//------------------------------------------------------------------------
20
22
24 double y,dy;
25 int i,m,ns=0;
26 double den,dif,dift,ho,hp,w;
27
28 int n=vx.size();
29 vector <double> c(n),d(n);
30 dif = fabs(xx-vx[0]);
31 for (i=0;i<n;i++){
32 if ((dift = fabs(xx-vx[i]))<dif){
33 ns=i;
34 dif = dift;
35 }
36 c[i] = vy[i];
37 d[i] = vy[i];
38 }
39 y = vy[ns--];
40 for (m=1;m<n;m++){
41 for (i=0;i<n-m;i++){
42 ho = vx[i] -xx;
43 hp = vx[i+m] -xx;
44 w = c[i+1] - d[i];
45 if(( den = ho-hp) == 0.0) std::cout<<"Error in routine polint"<<std::endl;
46 den = w/den;
47 d[i] = hp*den;
48 c[i] = ho*den;
49 }
50 y += (dy=(2*(ns+1)< (n-m) ? c[ns+1]: d[ns--]));
51 }
52 value = y;
53 error = dy;
54 // std::cout<<"value= "<<value<<std::endl;
55 if(value <0) value = 0;
56 return;
57}
58
60{
61 double y,dy;
62 const double TINY=1.0e-25;
63 int m,i,ns=0;
64 double w,t,hh,h,dd;
65
66 int n=vx.size();
67 vector <double> c(n),d(n);
68 hh=fabs(xx-vx[0]);
69 for (i=0;i<n;i++) {
70 h=fabs(xx-vx[i]);
71 if (h == 0.0) {
72 y=vy[i];
73 dy=0.0;
74 return;
75 } else if (h < hh) {
76 ns=i;
77 hh=h;
78 }
79 c[i]=vy[i];
80 d[i]=vy[i]+TINY;
81 }
82 y=vy[ns--];
83 for (m=1;m<n;m++) {
84 for (i=0;i<n-m;i++) {
85 w=c[i+1]-d[i];
86 h=vx[i+m]-xx;
87 t=(vx[i]-xx)*d[i]/h;
88 dd=t-c[i+1];
89 if (dd == 0.0) std::cout<<"Error in routine ratint"<<std::endl;
90 dd=w/dd;
91 d[i]=c[i+1]*dd;
92 c[i]=t*dd;
93 }
94 y += (dy=(2*(ns+1) < (n-m) ? c[ns+1] : d[ns--]));
95 }
96 value = y;
97 error = dy;
98 if(value <0) value = 0;
99 return;
100}
101
102vector <double> EvtPolInt::spline()
103{
104 vector <double> y2;
105 y2.clear();
106 for(int i=0;i<size;i++){y2.push_back(0.0);}
107 double yp1=0;
108 double ypn=0;
109 int i,k;
110 double p,qn,sig,un;
111
112 int n=size;
113 vector<double> u; //(n-1);
114 if (yp1 > 0.99e30){
115 u[0]=0.0;
116 y2.push_back(0.0);}
117 else {
118 y2.push_back(-0.5);
119 u[0]=(3.0/(vx[1]-vx[0]))*((vy[1]-vy[0])/(vx[1]-vx[0])-yp1);
120 }
121 for (i=1;i<n-1;i++) {
122 sig=(vx[i]-vx[i-1])/(vx[i+1]-vx[i-1]);
123 p=sig*y2[i-1]+2.0;
124 double yy2=(sig-1.0)/p;
125 y2.push_back(yy2);
126 u[i]=(vy[i+1]-vy[i])/(vx[i+1]-vx[i]) - (vy[i]-vy[i-1])/(vx[i]-vx[i-1]);
127 u[i]=(6.0*u[i]/(vx[i+1]-vx[i-1])-sig*u[i-1])/p;
128 }
129 if (ypn > 0.99e30)
130 qn=un=0.0;
131 else {
132 qn=0.5;
133 un=(3.0/(vx[n-1]-vx[n-2]))*(ypn-(vy[n-1]-vy[n-2])/(vx[n-1]-vx[n-2]));
134 }
135 y2[n-1]=(un-qn*u[n-2])/(qn*y2[n-2]+1.0);
136 for (k=n-2;k>=0;k--)
137 y2[k]=y2[k]*y2[k+1]+u[k];
138 return y2;
139 }
140
142 vector <double> y2a = spline();
143 double y;
144 int k;
145 double h,b,a;
146
147 int n=vx.size();
148 int klo=0;
149 int khi=n-1;
150 while (khi-klo > 1) {
151 k=(khi+klo) >> 1;
152 if (vx[k] > xx) khi=k;
153 else klo=k;
154 }
155 h=vx[khi]-vx[klo];
156 if (h == 0.0) std::cout<<"Bad xa input to routine splint"<<std::endl;
157 a=(vx[khi]-xx)/h;
158 b=(xx-vx[klo])/h;
159 y=a*vy[klo]+b*vy[khi]+((a*a*a-a)*y2a[klo]
160 +(b*b*b-b)*y2a[khi])*(h*h)/6.0;
161 value = y;
162 return;
163}
164
166 polynomial();
167 // ratint();
168 // splint();
169return value;
170}
171
173 polynomial();
174 //ratint();
175return error;
176}
const Int_t n
double w
#define TINY
Definition TRunge.cxx:1095
TTree * t
Definition binning.cxx:23
double getvalue()
Definition EvtPolInt.cc:165
double geterror()
Definition EvtPolInt.cc:172
vector< double > spline()
Definition EvtPolInt.cc:102
void ratint()
Definition EvtPolInt.cc:59
void splint()
Definition EvtPolInt.cc:141
void polynomial()
Definition EvtPolInt.cc:23
double y[1000]
const double b
Definition slope.cxx:9
#define ns(x)
Definition xmltok.c:1504