-
Notifications
You must be signed in to change notification settings - Fork 4
/
mnpfit.F
73 lines (73 loc) · 1.66 KB
/
mnpfit.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
*
* $Id: mnpfit.F,v 1.1.1.1 2000/06/08 11:19:20 andras Exp $
*
* $Log: mnpfit.F,v $
* Revision 1.1.1.1 2000/06/08 11:19:20 andras
* import of MINUIT from CERNlib 2000
*
* Revision 1.1.1.1 1996/03/07 14:31:31 mclareni
* Minuit
*
*
#include "minuit/pilot.h"
SUBROUTINE MNPFIT(PARX2P,PARY2P,NPAR2P,COEF2P,SDEV2P)
#include "minuit/d506dp.inc"
C
C to fit a parabola to npar2p points
C
C npar2p no. of points
C parx2p(i) x value of point i
C pary2p(i) y value of point i
C
C coef2p(1...3) coefficients of the fitted parabola
C y=coef2p(1) + coef2p(2)*x + coef2p(3)*x**2
C sdev2p= variance
C method : chi**2 = min equation solved explicitly
DIMENSION PARX2P(NPAR2P),PARY2P(NPAR2P),COEF2P(NPAR2P)
DIMENSION CZ(3)
C
DO 3 I=1,3
3 CZ(I)=0.
SDEV2P=0.
IF(NPAR2P.LT.3) GO TO 10
F=NPAR2P
C--- center x values for reasons of machine precision
XM=0.
DO 2 I=1,NPAR2P
2 XM=XM+PARX2P(I)
XM=XM/F
X2=0.
X3=0.
X4=0.
Y=0.
Y2=0.
XY=0.
X2Y=0.
DO 1 I=1,NPAR2P
S=PARX2P(I)-XM
T=PARY2P(I)
S2=S*S
X2=X2+S2
X3=X3+S*S2
X4=X4+S2*S2
Y=Y+T
Y2=Y2+T*T
XY=XY+S*T
X2Y=X2Y+S2*T
1 CONTINUE
A=(F*X4-X2**2)*X2-F*X3**2
IF(A.EQ.0.) GOTO 10
CZ(3)=(X2*(F*X2Y-X2*Y)-F*X3*XY)/A
CZ(2)=(XY-X3*CZ(3))/X2
CZ(1)=(Y-X2*CZ(3))/F
IF(NPAR2P.EQ.3) GOTO 6
SDEV2P=Y2-(CZ(1)*Y+CZ(2)*XY+CZ(3)*X2Y)
IF(SDEV2P.LT.0.) SDEV2P=0.
SDEV2P=SDEV2P/(F-3.)
6 CZ(1)=CZ(1)+XM*(XM*CZ(3)-CZ(2))
CZ(2)=CZ(2)-2.*XM*CZ(3)
10 CONTINUE
DO 11 I=1,3
11 COEF2P(I)=CZ(I)
RETURN
END