Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pyeig4.f
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file pyeig4.f
1 
2 C*********************************************************************
3 
4 C...PYEIG4
5 C...Finds eigenvalues and eigenvectors to a 4 * 4 matrix.
6 C...Specific application: mixing in neutralino sector.
7 
8  SUBROUTINE pyeig4(A,W,Z)
9 
10 C...Double precision and integer declarations.
11  IMPLICIT DOUBLE PRECISION(a-h, o-z)
12  IMPLICIT INTEGER(i-n)
13  INTEGER pyk,pychge,pycomp
14 
15 C...Arrays: in call and local.
16  dimension a(4,4),w(4),z(4,4),x(4),d(4,4),e(4)
17 
18 C...Coefficients of fourth-degree equation from matrix.
19 C...x**4 + b3 * x**3 + b2 * x**2 + b1 * x + b0 = 0.
20  b3=-(a(1,1)+a(2,2)+a(3,3)+a(4,4))
21  b2=0d0
22  DO 110 i=1,3
23  DO 100 j=i+1,4
24  b2=b2+a(i,i)*a(j,j)-a(i,j)*a(j,i)
25  100 CONTINUE
26  110 CONTINUE
27  b1=0d0
28  b0=0d0
29  DO 120 i=1,4
30  i1=mod(i,4)+1
31  i2=mod(i+1,4)+1
32  i3=mod(i+2,4)+1
33  b1=b1+a(i,i)*(-a(i1,i1)*a(i2,i2)+a(i1,i2)*a(i2,i1)+
34  & a(i1,i3)*a(i3,i1)+a(i2,i3)*a(i3,i2))-
35  & a(i,i1)*a(i1,i2)*a(i2,i)-a(i,i2)*a(i2,i1)*a(i1,i)
36  b0=b0+(-1d0)**(i+1)*a(1,i)*(
37  & a(2,i1)*(a(3,i2)*a(4,i3)-a(3,i3)*a(4,i2))+
38  & a(2,i2)*(a(3,i3)*a(4,i1)-a(3,i1)*a(4,i3))+
39  & a(2,i3)*(a(3,i1)*a(4,i2)-a(3,i2)*a(4,i1)))
40  120 CONTINUE
41 
42 C...Coefficients of third-degree equation needed for
43 C...separation into two second-degree equations.
44 C...u**3 + c2 * u**2 + c1 * u + c0 = 0.
45  c2=-b2
46  c1=b1*b3-4d0*b0
47  c0=-b1**2-b0*b3**2+4d0*b0*b2
48  cq=c1/3d0-c2**2/9d0
49  cr=c1*c2/6d0-c0/2d0-c2**3/27d0
50  cqr=cq**3+cr**2
51 
52 C...Cases with one or three real roots.
53  IF(cqr.GE.0d0) THEN
54  s1=(cr+sqrt(cqr))**(1d0/3d0)
55  s2=(cr-sqrt(cqr))**(1d0/3d0)
56  u=s1+s2-c2/3d0
57  ELSE
58  sabs=sqrt(-cq)
59  the=acos(cr/sabs**3)/3d0
60  sre=sabs*cos(the)
61  u=2d0*sre-c2/3d0
62  ENDIF
63 
64 C...Find and solve two second-degree equations.
65  p1=b3/2d0-sqrt(b3**2/4d0+u-b2)
66  p2=b3/2d0+sqrt(b3**2/4d0+u-b2)
67  q1=u/2d0+sqrt(u**2/4d0-b0)
68  q2=u/2d0-sqrt(u**2/4d0-b0)
69  IF(abs(p1*q1+p2*q2-b1).LT.abs(p1*q2+p2*q1-b1)) THEN
70  qsav=q1
71  q1=q2
72  q2=qsav
73  ENDIF
74  x(1)=-p1/2d0+sqrt(p1**2/4d0-q1)
75  x(2)=-p1/2d0-sqrt(p1**2/4d0-q1)
76  x(3)=-p2/2d0+sqrt(p2**2/4d0-q2)
77  x(4)=-p2/2d0-sqrt(p2**2/4d0-q2)
78 
79 C...Order eigenvalues in asceding mass.
80  w(1)=x(1)
81  DO 150 i1=2,4
82  DO 130 i2=i1-1,1,-1
83  IF(abs(x(i1)).GE.abs(w(i2))) goto 140
84  w(i2+1)=w(i2)
85  130 CONTINUE
86  140 w(i2+1)=x(i1)
87  150 CONTINUE
88 
89 C...Find equation system for eigenvectors.
90  DO 250 i=1,4
91  DO 170 j1=1,4
92  d(j1,j1)=a(j1,j1)-w(i)
93  DO 160 j2=j1+1,4
94  d(j1,j2)=a(j1,j2)
95  d(j2,j1)=a(j2,j1)
96  160 CONTINUE
97  170 CONTINUE
98 
99 C...Find largest element in matrix.
100  damax=0d0
101  DO 190 j1=1,4
102  DO 180 j2=1,4
103  IF(abs(d(j1,j2)).LE.damax) goto 180
104  ja=j1
105  jb=j2
106  damax=abs(d(j1,j2))
107  180 CONTINUE
108  190 CONTINUE
109 
110 C...Subtract others by multiple of row selected above.
111  damax=0d0
112  DO 210 j3=ja+1,ja+3
113  j1=j3-4*((j3-1)/4)
114  rl=d(j1,jb)/d(ja,jb)
115  DO 200 j2=1,4
116  d(j1,j2)=d(j1,j2)-rl*d(ja,j2)
117  IF(abs(d(j1,j2)).LE.damax) goto 200
118  jc=j1
119  jd=j2
120  damax=abs(d(j1,j2))
121  200 CONTINUE
122  210 CONTINUE
123 
124 C...Do one more subtraction of a row.
125  damax=0d0
126  DO 230 j3=jc+1,jc+3
127  j1=j3-4*((j3-1)/4)
128  IF(j1.EQ.ja) goto 230
129  rl=d(j1,jd)/d(jc,jd)
130  DO 220 j2=1,4
131  IF(j2.EQ.jb) goto 220
132  d(j1,j2)=d(j1,j2)-rl*d(jc,j2)
133  IF(abs(d(j1,j2)).LE.damax) goto 220
134  je=j1
135  damax=abs(d(j1,j2))
136  220 CONTINUE
137  230 CONTINUE
138 
139 C...Construct unnormalized eigenvector.
140  jf1=jd+1-4*(jd/4)
141  jf2=jd+2-4*((jd+1)/4)
142  IF(jf1.EQ.jb) jf1=jd+3-4*((jd+2)/4)
143  IF(jf2.EQ.jb) jf2=jd+3-4*((jd+2)/4)
144  e(jf1)=-d(je,jf2)
145  e(jf2)=d(je,jf1)
146  e(jd)=-(d(jc,jf1)*e(jf1)+d(jc,jf2)*e(jf2))/d(jc,jd)
147  e(jb)=-(d(ja,jf1)*e(jf1)+d(ja,jf2)*e(jf2)+d(ja,jd)*e(jd))/
148  & d(ja,jb)
149 
150 C...Normalize and fill in final array.
151  ea=sqrt(e(1)**2+e(2)**2+e(3)**2+e(4)**2)
152  sgn=(-1d0)**int(pyr(0)+0.5d0)
153  DO 240 j=1,4
154  z(i,j)=sgn*e(j)/ea
155  240 CONTINUE
156  250 CONTINUE
157 
158  RETURN
159  END