CMS 3D CMS Logo

Millepede.h

Go to the documentation of this file.
00001 #ifndef LaserAlignment_millepede1_h
00002 #define LaserAlignment_millepede1_h
00003 
00004 /**********************************************************************
00005  * Wrapper to call MILLEPEDE (FORTRAN) routines in C++ programms      *
00006  *                                                                    *
00007  * all comments and descriptions are copied from the MILLEPEDE code
00008  * written by Volker Blobel:
00009  *                                                                    
00010  *                 Millepede - Linear Least Squares
00011  *                 ================================
00012  *     A Least Squares Method for Detector Alignment - Fortran code
00013  *
00014  *     TESTMP      short test program for detector aligment
00015  *                 with GENER (generator) + ZRAND, ZNORM (random gen.)
00016  *
00017  *     The execution of the test program needs a MAIN program:
00018  *                 CALL TESTMP(0)
00019  *                 CALL TESTMP(1)
00020  *                 END
00021  *
00022  *     INITGL      initialization
00023  *     PARGLO       optional: initialize parameters with nonzero values
00024  *     PARSIG       optional: define sigma for single parameter
00025  *     INITUN       optional: unit for iterations
00026  *     CONSTF       optional: constraints
00027  *     EQULOC      equations for local fit
00028  *     ZERLOC
00029  *     FITLOC      local parameter fit (+entry KILLOC)
00030  *     FITGLO      final global parameter fit
00031  *     ERRPAR      parameter errors
00032  *     CORPAR      parameter correlations
00033  *     PRTGLO      print result on file
00034  *
00035  *     Special matrix subprograms (all in Double Precision):
00036  *        SPMINV   matrix inversion + solution
00037  *        SPAVAT   special double matrix product
00038  *        SPAX     product matrix times vector
00039  *
00040  *     PXHIST      histogram printing
00041  *     CHFMT       formatting of real numbers
00042  *     CHINDL      limit of chi**2/nd
00043  *     FITMUT/FITMIN vector input/ouput for parallel processing
00044  */
00045 
00046 extern "C"
00047 {
00048   //___subroutines_____________________________________________________
00049   /*test of millepede
00050    *     IARG = 0   test with constraint
00051    *     IARG = 1   test without constraint */
00052   void testmp_(int*); 
00053   // generates straight line parameters
00054   void gener_(float y[], float *a, float *b, float x[], float sigma[], float *bias,
00055                           float heff[]);
00056 
00057   /* Initialization of package
00058    *     NAGB = number of global parameters
00059    *     DERGB(1) ... DERGB(NAGB) = derivatives w.r.t. global parameters
00060    *     NALC = number of local parameters (maximum)
00061    *     DERLC(1) ... DERLC(NALC) = derivatives w.r.t. local parameters */
00062   void initgl_(int *nagbar, int *nalcar, int *nstd, int *iprlim);
00063 
00064   /* optional: initialize parameters with nonzero values */
00065   void parglo_(float par[]);
00066 
00067   /* optional: define sigma for single parameter */
00068   void parsig_(int *index, float *sigma);
00069 
00070   /* optional: set nonlinear flag for single parameter */
00071   void nonlin_(int *index);
00072 
00073   /* optional: unit for iterations */
00074   void initun_(int *lun, float *cutfac);
00075 
00076   /* optional: constraints */
00077   void constf_(float dercs[], float *rhs);
00078 
00079   /* a single equation with its derivatives
00080    *     DERGB(1) ... DERGB(NAGB) = derivatives w.r.t. global parameters
00081    *     DERLC(1) ... DERLC(NALC) = derivatives w.r.t. local parameters
00082    *     RMEAS       = measured value
00083    *     SIGMA       = standard deviation
00084    *    (WGHT       = weight = 1/SIGMA**2) */
00085   void equloc_(float dergb[], float derlc[], float *rrmeas, 
00086                            float *sigma);
00087 
00088   /* reset derivatives
00089    *     DERGB(1) ... DERGB(NAGB) = derivatives w.r.t. global parameters
00090    *     DERLC(1) ... DERLC(NALC) = derivatives w.r.t. local parameters */
00091   void zerloc_(float dergb[], float derlc[]);
00092 
00093   /* fit after end of local block - faster(?) version */
00094   void fitloc_(void);
00095 
00096   /* final global fit */
00097   void fitglo_(float par[]);
00098 
00099   /* */
00100   void prtglo_(int *lun);
00101 
00102   /* obtain solution of a system of linear equations with symmetric
00103    *     matrix and the inverse.
00104    *
00105    *                    - - -
00106    *        CALL SPMINV(V,B,N,NRANK,...,...)      solve  V * X = B
00107    *                    - -   -----
00108    *
00109    *           V = symmetric N-by-N matrix in symmetric storage mode
00110    *               V(1) = V11, V(2) = V12, V(3) = V22, V(4) = V13, . . .
00111    *               replaced by inverse matrix
00112    *           B = N-vector, replaced by solution vector
00113    *
00114    *     DIAG(N) =  double precision scratch array
00115    *     FLAG(N) =  logical scratch array
00116    *
00117    *     Method of solution is by elimination selecting the  pivot  on  the
00118    *     diagonal each stage. The rank of the matrix is returned in  NRANK.
00119    *     For NRANK ne N, all remaining  rows  and  cols  of  the  resulting
00120    *     matrix V and the corresponding elements of  B  are  set  to  zero. */
00121   void spminv_(double v[], double b[], int *n, int *nrank, 
00122                            double diag[], bool flag[]); 
00123 
00124   /*  multiply symmetric N-by-N matrix from the left with general M-by-N
00125    *     matrix and from the right with the transposed of the same  general
00126    *     matrix  to  form  symmetric  M-by-M   matrix   (used   for   error
00127    *     propagation).
00128    *
00129    *                    - -   - -                                   T
00130    *        CALL SPAVAT(V,A,W,N,M)         W   =   A   *   V   *   A
00131    *                        -             M*M     M*N     N*N     N*M
00132    *
00133    *        where V = symmetric N-by-N matrix
00134    *              A = general N-by-M matrix
00135    *              W = symmetric M-by-M matrix */
00136   void spavat_(double v[], double a[], double w[],
00137                            int *n, int *m);
00138 
00139   /* multiply general M-by-N matrix A and N-vector X
00140    *
00141    *                   - -   - -
00142    *        CALL  SPAX(A,X,Y,M,N)          Y   :=   A   *    X
00143    *                       -               M       M*N       N
00144    *
00145    *        where A = general M-by-N matrix (A11 A12 ... A1N  A21 A22 ...)
00146    *              X = N vector
00147    *              Y = M vector */
00148   void spax_(double a[], double x[], double y[],
00149                          int *n, int *m);
00150 
00151   /* print X histogram */
00152   void pxhist_(int inc[], int *n, float *xa, float *xb);
00153 
00154   /* prepare printout of array of real numbers as character strings
00155    *
00156    *                  - -
00157    *        CALL CHFMT(X,N,XCHAR,ECHAR)
00158    *                      ----- -----
00159    *     where X( )     = array of n real values
00160    *           XCHAR( ) = array of n character*8 variables
00161    *           ECHAR    = character*4 variable
00162    *
00163    *     CHFMT converts an array of  n  real  values  into n character*  8
00164    *     variables (containing the values as text) and  a  common  exponent
00165    *     for printing. unneccessary zeros are suppressed.
00166    *
00167    *
00168    *     example: x(1)=1200.0, x(2)=1700.0 with n=2 are converted to
00169    *               xchar(1)='  1.2   ', xchar(2)='  1.7   ', echar='e 03' */
00170   void chfmt_(float x[], int *n, const char xchar[], 
00171                           const char echar[], int, int);
00172 
00173   /* get matrix information out */
00174   void fitmut_(int *nvec, float vec[]);
00175 
00176   //___functions_______________________________________________________
00177 
00178   /* return random number U(0,1)
00179    *     (simple generator, showing principle) */
00180   float zrand_(void);
00181 
00182   /* return random number U(0,1)
00183    *     (simple generator, showing principle) */
00184   float znorm_(void);
00185 
00186   /* return error for parameter I */
00187   double errpar_(int *i);
00188 
00189   /* return correlation between parameters I and J */
00190   double corpar_(int *i, int *j);
00191 
00192   /* return limit in chi^2/ND for N sigmas (N=1, 2 or 3) */
00193   float chindl_(int *n, int *nd);
00194 
00195   //___common blocks___________________________________________________
00196 
00197   // basic parameters
00198   const int mglobl = 1400;
00199   const int mlocal = 10;
00200   const int nstore = 10000;
00201   const int mcs= 10;
00202   // derived parameters
00203   const int mgl = mglobl + mcs;
00204   const int msymgb = (mglobl * mglobl + mglobl)/2;
00205   const int msym = (mgl * mgl + mgl)/2;
00206   const int msymlc = (mlocal * mlocal + mlocal)/2;
00207   const int mrecta = mglobl * mlocal;
00208   const int mglocs = mglobl * mcs;
00209   const int msymcs = (mcs * mcs + mcs)/2;
00210 
00211   // common block /LSQRED/ (no idea what all these variables are for)
00212 extern struct
00213 {
00214   double cgmat[msym], clmat[msymlc], clcmat[mrecta],
00215         diag[mgl], bgvec[mgl], blvec[mlocal],
00216         corrm[msymgb], corrv[mglobl],psigm[mglobl],
00217         pparm[mglobl],adercs[mglocs],arhs[mcs],
00218         dparm[mglobl],scdiag[mglobl];
00219   double summ;
00220         bool scflag[mglobl];
00221   int   indgb[mglobl],indlc[mlocal];
00222   int loctot,locrej,
00223         nagb,nalc,nsum,nhist,mhist[51],khist[51],lhist[51],
00224         nst,nfl,indst[nstore];
00225   float arest[nstore];
00226   int itert,lunit,ncs,
00227         nlnpa[mglobl],nstdev;
00228   float cfactr;
00229   int icnpr,icnlim,
00230         indnz[mglobl],indbk[mglobl];
00231 }lsqred_; // extern struct
00232 } 
00233 
00234 #endif // millepede1_H

Generated on Tue Jun 9 17:24:04 2009 for CMSSW by  doxygen 1.5.4