9 double xTCL::vmaxa(
const double *a,
int na)
12 for (
int i=0;i<na;i++){
if (r < TMath::Abs(a[i])) r = TMath::Abs(a[i]);}
16 double xTCL::vmaxa(
const TVectorD &a)
18 return vmaxa(a.GetMatrixArray(),a.GetNrows());
21 int xTCL::lvmaxa(
const double *a,
int na)
25 for (
int i=0;i<na;i++){
if (r < TMath::Abs(a[i])) {r = TMath::Abs(a[i]);l=i;}}
29 int xTCL::lvmina(
const double *a,
int na)
31 double r=TMath::Abs(a[0]);
33 for (
int i=1;i<na;i++){
if (r > TMath::Abs(a[i])) {r = TMath::Abs(a[i]);l=i;}}
37 void xTCL::vfill(
double *a,
double f,
int na)
39 for (
int i=0;i<na;i++) {a[i]=f;}
69 static void eigen2(
double G[3],
double lam[2],
double eig[2])
71 double spur = G[0]+G[2];
73 double dis = (G[0]-G[2])*(G[0]-G[2])+4*G[1]*G[1];
76 lam[0] = 0.5*(spur+dis);
77 lam[1] = 0.5*(spur-dis);
80 double g[3]={G[0]-G[2]-dis,2*G[1],G[2]-G[0]-dis};
82 for (
int i=1;i<3;i++) {
if (fabs(g[i])>fabs(g[kase])) kase = i;}
84 case 0: eig[0] = g[1]/g[0]; eig[1]=-1;
break;
85 case 1: eig[1] = g[0]/g[1]; eig[0]=-1;
break;
86 case 2: eig[1] = g[1]/g[2]; eig[0]=-1;
break;
88 double nor = sqrt(eig[0]*eig[0]+eig[1]*eig[1]);
90 int j=(fabs(eig[0])>fabs(eig[1]))? 0:1;
91 if(eig[j]<0) nor = -nor;
92 eig[0]/=nor;eig[1]/=nor;}
99 double xTCL::simpson(
const double *F,
double A,
double B,
int NP)
102 assert(N2>0 && !(N2&1));
106 for (
int N = 1;N<=N2-3;N+=2) {S1+=F[N];S2+=F[N+1];}
108 double H=(F[0]+F[N2]+S1+S1)*(B-A)/(3*N2);
112 double **xTCL::makeMatrixD(
int m,
int n)
114 int szp = (m*
sizeof(
double*)+
sizeof(
double))/
sizeof(
double);
116 double *d =
new double[szp+szd];
117 memset(d,0,(szp+szd)*
sizeof(
double));
118 double **p = (
double**)d;
120 for (
int i=0;i<m;i++) { p[i]=d; d+=n;};
124 void xTCL::mxmlrt(
const TMatrixD &A,
const TMatrixD &B,TMatrixD &X)
126 int nRowA = A.GetNrows();
127 int nColA = A.GetNcols();
128 int nRowB = B.GetNrows();
129 int nColB = B.GetNcols();
if(nColB){}
130 assert(nColA ==nRowB);
131 X.ResizeTo(nRowA,nRowA);
132 TCL::mxmlrt(A.GetMatrixArray(),B.GetMatrixArray()
133 ,X.GetMatrixArray(),nRowA,nColA);
137 void xTCL::mxmlrtS(
const double *A,
const double *B,
double *X,
int nra,
int nca)
139 TCL::vzero(X,nra*nra);
140 for (
int i=0,ii=0;i<nra;i++,ii+=nca) {
141 for (
int j=0,jj=0;j<nca;j++,jj+=nca) {
142 if(!A[ii+j])
continue;
143 for (
int k=0,kk=0;k<=i;k++,kk+=nca) {
144 double &Xik =X[i*nra+k];
145 for (
int l=0;l<nca;l++) {
146 if(!A[kk+l])
continue;
147 Xik +=A[ii+j]*A[kk+l]*B[jj+l];
149 for (
int i=0;i<nra;i++){
150 for (
int k=0;k<i ;k++){X[k*nra+i] = X[i*nra+k];}}
153 void xTCL::mxmlrtS(
const TMatrixD &A,
const TMatrixD &B,TMatrixD &X)
155 int nRowA = A.GetNrows();
156 int nColA = A.GetNcols();
157 int nRowB = B.GetNrows();
158 int nColB = B.GetNcols();
if(nColB){}
159 assert(nColA ==nRowB);
160 X.ResizeTo(nRowA,nRowA);
161 xTCL::mxmlrtS(A.GetMatrixArray(),B.GetMatrixArray()
162 ,X.GetMatrixArray(),nRowA,nColA);
166 TMatrixD xTCL::T(
const TMatrixD &mx)
172 double xTCL::vasum(
const double *a,
int na)
175 for (
int i=0;i<na;i++) { sum += TMath::Abs(a[i]);}
179 double xTCL::vasum(
const TVectorD &a)
181 return vasum(a.GetMatrixArray(),a.GetNrows());
184 int xTCL::SqProgSimple( TVectorD &x
185 ,
const TVectorD &g,
const TMatrixD &G
187 ,
const TVectorD &Max,
int iAktp)
189 static const double kSMALL = 1e-9;
190 static int nCall=0; nCall++;
191 enum {kINIT=0,kADDCONS,kFREECONS};
193 int nPars = g.GetNrows();
194 TVectorD xx(x),gg(g),add(nPars);
196 int nCons=0,addCons = -1,freCons=-1,freSide=0,addSide=0,con=0;
201 freCons=-1; freSide=0;
202 if (nCons && kase==kFREECONS ) {
203 double tryGra=kSMALL; freCons=-1;
204 for (
int ix=0;ix<nPars;ix++) {
205 if(!Side[ix])
continue;
206 double gra = gg[ix]*Side[ix];
207 if (gra< tryGra)
continue;
208 if (gra>=maxGra)
continue;
209 freCons=ix; tryGra=gra;
213 freSide = Side[freCons];
219 if(kase==kFREECONS && freCons<0) {
break;}
225 for (
int ix=0;ix<nPars;ix++) {
226 if (Side[ix]==0)
continue;
227 for (
int jx=0;jx<nPars;jx++) {S[ix][jx]=0; S[jx][ix]=0;}
228 S[ix][ix]=1; B[ix]=0;
232 double det=12345; S.Invert(&det);
236 double along = B*add;
237 if (along>0) add*=(-1.);
242 double bSb = (B*(S*B));
243 double tau = -bb/(TMath::Abs(bSb)+3e-33);
247 if(kase==kFREECONS && freSide) {
248 if (add[freCons]*freSide > -kSMALL) {
249 Side[freCons]=freSide; nCons++;
continue;}
254 addCons = -1; addSide = 0;
256 for (
int ix=0;ix<nPars;ix++) {
257 if (Side[ix]) {add[ix]=0; con = 100*con+ix+1;
continue;}
258 double xi = xx[ix]+fak*add[ix];
259 if (xi < Min[ix]){fak = (Min[ix]-xx[ix])/add[ix]; addCons=ix;addSide=-1;}
260 if (xi > Max[ix]){fak = (Max[ix]-xx[ix])/add[ix]; addCons=ix;addSide= 1;}
261 assert(fak<=1. && fak>=0.);
267 kase = kFREECONS;
if (!addSide)
continue;
269 xx[addCons] = (addSide<0)? Min[addCons]:Max[addCons];
271 Side[addCons] = addSide ;nCons++;
278 void xTCL::toEuler(
const double TT[3][3],
double PhiThePsi[6])
291 double cThe = TT[2][2];
if (cThe>1) cThe=1;
if (cThe<-1) cThe=-1;
292 double sThe = (TT[0][2]*TT[0][2]+TT[1][2]*TT[1][2])
293 + (TT[2][0]*TT[2][0]+TT[2][1]*TT[2][1]);
294 sThe = sqrt(0.5*sThe);
296 double N = 0.5*(cThe*cThe+sThe*sThe+1);
299 double sPsi = 0,cPsi=1;
301 sPsi = TT[0][2]/sThe; cPsi = TT[1][2]/sThe;
302 N = 0.5*(cPsi*cPsi+sPsi*sPsi+1);
305 double cPhi = cPsi*TT[0][0]-sPsi*TT[1][0];
306 double sPhi = cPsi*TT[0][1]-sPsi*TT[1][1];
308 PhiThePsi[0] = cPhi ; PhiThePsi[1] = sPhi;
309 PhiThePsi[2] = cThe ; PhiThePsi[3] = sThe;
310 PhiThePsi[4] = cPsi ; PhiThePsi[5] = sPsi;
313 double test = fabs(TT[0][0] -( cPsi*cPhi - sPsi*cThe*sPhi))
314 + fabs(TT[1][0] -(-sPsi*cPhi - cPsi*cThe*sPhi))
315 + fabs(TT[2][0] -( sThe*sPhi))
316 + fabs(TT[0][1] -( cPsi*sPhi + sPsi*cThe*cPhi))
317 + fabs(TT[1][1] -(-sPsi*sPhi + cPsi*cThe*cPhi))
318 + fabs(TT[2][1] -(-sThe*cPhi))
319 + fabs(TT[0][2] -( sPsi*sThe))
320 + fabs(TT[1][2] -( cPsi*sThe))
321 + fabs(TT[2][2] -( cThe));
322 printf(
"EPS=%g\n",test);