Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

w_YFMVTR.cpp

Go to the documentation of this file.
00001 #include "w_YFMVTR.h"
00002 #include <iostream.h>
00003 //=======================================================================
00004 // w_YFMVTR methods
00005 // 11/2001 Kay Huettmann
00006 //=======================================================================
00007 
00008 //-----------------------------------------------------------------------
00009 // getResult(..)
00010 // YFMVTR wrapper (YTOP vertex fit)
00011 // Parameters are passed via a common block, since cfortan is limited to 27 parameters
00012 //-----------------------------------------------------------------------
00013 bool w_YFMVTR::getResult(const vector<Helix>& vHelix,
00014                            HepLorentzVector& track4V, HepSymMatrix& covTrack, 
00015                            Hep3Vector& vertex3V, HepSymMatrix& covVertex, 
00016                            HepMatrix& corrVertexTrack,
00017                            float& chi2) const {
00018  
00019    // set dummy vertex constraint 
00020   Vertex theVertexC;
00021   
00022   // initialize output parameters
00023   HepLorentzVector temp4V(0.,0.,0.,0.);
00024   track4V = temp4V;
00025  
00026   HepSymMatrix tempCov4V(4,0);
00027   covTrack = tempCov4V;
00028 
00029   Hep3Vector temp3V(0.,0.,0.);
00030   vertex3V = temp3V;
00031 
00032   HepSymMatrix tempCov3V(3,0);
00033   covVertex = tempCov3V;
00034 
00035   HepMatrix tempCorr(3,3,0);
00036   corrVertexTrack = tempCorr;
00037 
00038   float _chi2 = -1.;
00039   chi2 = _chi2;
00040 
00041 
00042   if (vHelix.size() > 10) 
00043     cerr << "__w_YFMVTR::getResult: Too many tracks (" << vHelix.size() 
00044          << "). Surplus tracks will be ignored in the fit !!" << endl;
00045 
00046   // Count charged and neutral tracks
00047   int n_charged = 0;
00048   int n_neutral = 0;
00049   vector<const Helix>::iterator itH = vHelix.begin();
00050   for ( ; itH < vHelix.end(); itH++ ) {
00051     if (itH->charge() != 0) {
00052       n_charged++;
00053     } else {
00054       n_neutral++;
00055     }
00056   }
00057 
00058   // fill YMFVTR common block
00059   FCB.nvx = 0;
00060   FCB.nhx = 0;
00061   FCB.neu = 0;
00062   FCB.lvapc = 1;
00063   FCB.lpsum = 1;
00064   FCB.lmcalc = 1;
00065   FCB.lvfix = 0;
00066   FCB.vxin[0] = 0.;
00067   FCB.vvxin[0] = 0.;
00068 
00069   // Check whether there is a vertex constraint
00070   if ( _pVertexC ) {
00071     FCB.nvx = 1;
00072     FCB.lvapc = 0;
00073     // vertex coordinates ...
00074     FCB.vxin[0] = _pVertexC->v3V().x();
00075     FCB.vxin[1] = _pVertexC->v3V().y();
00076     FCB.vxin[2] = _pVertexC->v3V().z();
00077     // covariance matrix 
00078     int j = 0;
00079     for (int m = 1; m <= 3; m++) {
00080       for (int n = 1; n <= m; n++) {
00081         FCB.vvxin[j++] = _pVertexC->cov_matrix(m,n) ;
00082       }
00083     } 
00084   }
00085   
00086   int ntrk = 0; // total number of tracks
00087   int nchg = 0;
00088   int nneu = 0;
00089   int indf;
00090   int indv;
00091   
00092   float cmass[10];
00093   float nmass[10];
00094   
00095  
00097   for (itH = vHelix.begin() ; itH < vHelix.end(); itH++ ) {
00098 
00099     if ((itH - vHelix.begin()) > 10) break;   // too many tracks
00100    
00101     ntrk++; 
00102     indf = 5*(ntrk -1);
00103     indv = 15*(ntrk -1);
00104 
00105     //
00106     // ---  charged track  ---  
00107     //
00108     if (itH->charge() != 0) {
00109       nchg++;
00110       FCB.nhx++;  
00111       FCB.ixhx[nchg -1] = ntrk;    // ntrk is a FORTRAN array index, so it has to start at 1
00112       cmass[nchg -1] = itH->mass();
00113     
00114       // track helix parameters
00115       FCB.hxin[indf   ] = itH->IR();
00116       FCB.hxin[indf+ 1] = itH->TL();
00117       FCB.hxin[indf+ 2] = itH->P0();
00118       FCB.hxin[indf+ 3] = itH->D0();
00119       FCB.hxin[indf+ 4] = itH->Z0();
00120 
00121       // track covariance matrix
00122       int j = 0;
00123       for (int m = 1; m <= 5; m++) {
00124         for (int n = 1; n <= m; n++) { 
00125           j++;
00126           FCB.vhxin[indv +j -1] = itH->cov_matrix(m,n);
00127         }
00128       } 
00129      
00130 
00131 
00132     } else {
00133       //
00134       // ---  neutral track  ---
00135       //
00136       nneu++;
00137       FCB.neu++;
00138       FCB.ixnu[nneu -1] = ntrk;
00139       nmass[nneu -1] = itH->mass();
00140     
00141       // track parameters
00142       FCB.hxin[indf   ] = itH->IR();
00143       FCB.hxin[indf+ 1] = itH->TL();
00144       FCB.hxin[indf+ 2] = itH->P0();
00145       FCB.hxin[indf+ 3] = itH->D0();
00146       FCB.hxin[indf+ 4] = itH->Z0();
00147 
00148       // track covariance matrix
00149       int j = 0;
00150       for (int m = 1; m <= 5; m++) {
00151         for (int n = 1; n <= m; n++) { 
00152           j++;
00153           FCB.vtnui[indv +j -1] = itH->cov_matrix(m,n);
00154         }
00155       } 
00156 
00157 
00158 
00159     }
00160   
00161   }
00162 
00163   int j = 0;
00164   int i;
00165   for (i = 0; i < nchg; i++) {
00166     FCB.ampc[j++] = cmass[i];
00167   }
00168   for (i = 0; i < nneu; i++) {
00169     FCB.ampc[j++] = nmass[i];
00170   }
00171   for (i = 0; i < ntrk*5; i++) {
00172     FCB.tnui[i] = FCB.hxin[i];
00173   }
00174 
00175   FCB.npidc = 1;
00176   
00177 
00186   
00187   
00188 
00189   // call the Fortran routine
00190   int ifail = W_YFMVTR();
00191 
00192   if (! ifail) {
00193 
00194     float ptrk[5];
00195     float vptrk[10];
00196    
00197     ptrk[0] = FCB.psum[0];
00198     ptrk[1] = FCB.psum[1];
00199     ptrk[2] = FCB.psum[2];
00200     ptrk[3] = sqrt(FCB.amass*FCB.amass + ptrk[0]*ptrk[0] +
00201                    ptrk[1]*ptrk[1] + ptrk[2]*ptrk[2]);
00202     ptrk[4] = FCB.amass;
00203 
00204 
00205    // calculate chi2/d.o.f.
00206    int ndf = ( _pVertexC ) ?  ntrk*2 : ntrk*2 -3;
00207    _chi2 = FCB.chisq/((float) ndf);
00208 
00209    // protection against crazy values from YTOP fit (taken from QYFIT)
00210    if (_chi2 < 500.) {
00211      if (ptrk[4] > 500. || ptrk[0] > 1000. || ptrk[1] > 1000. ||
00212          ptrk[2] > 1000. ) {
00213        _chi2 = -1.;
00214      }
00215    } else {
00216      _chi2 = -1.;
00217    }
00218  
00219    // calculate correct 4-momentum covariance matrix
00220    if (_chi2 > 0.) {
00221      
00222      float r1 = ptrk[0]/ptrk[3];
00223      float r2 = ptrk[1]/ptrk[3];
00224      float r3 = ptrk[2]/ptrk[3];
00225      float r4 = ptrk[4]/ptrk[3]; 
00226      
00227      for (int i = 0; i <= 6; i++) {
00228        vptrk[i] = FCB.vpsum[i];
00229      }
00230 
00231      vptrk[9] = r1*r1*vptrk[0] + r2*r2*vptrk[2] +
00232        r3*r3*vptrk[5] + r4*r4*FCB.dmass*FCB.dmass +
00233        2.*r1*(r2*vptrk[1] + r3*vptrk[3]) +
00234        2.*r2*r3*vptrk[4] +
00235        2.*r4*(r1*FCB.vmps[0] + r2*FCB.vmps[1] + r3*FCB.vmps[2]);
00236      
00237      vptrk[6] = r1*vptrk[0] + r2*vptrk[1] + r3*vptrk[3]
00238        +  r4*FCB.vmps[0];
00239    
00240      vptrk[7] = r1*vptrk[1] + r2*vptrk[2] + r3*vptrk[4]
00241        + r4*FCB.vmps[1];
00242 
00243      vptrk[8] = r1*vptrk[3] + r2*vptrk[4] + r3*vptrk[5]
00244        + r4*FCB.vmps[2];
00245 
00246      // prepare return values
00247 
00248      //  mother track
00249      track4V.setPx(ptrk[0]);
00250      track4V.setPy(ptrk[1]);
00251      track4V.setPz(ptrk[2]);
00252      track4V.setE(ptrk[3]);
00253 
00254      // vertex
00255       vertex3V.setX(FCB.vxout[0]);
00256       vertex3V.setY(FCB.vxout[1]);
00257       vertex3V.setZ(FCB.vxout[2]);
00258 
00259      // 4-momentum covariance matrix
00260       int j = 0;
00261       int m;
00262       int n;
00263       for (m = 1 ; m <= 4; m++) {
00264         for (n = 1; n <= m; n++) {
00265           covTrack(m,n)= vptrk[j++];
00266         }
00267       }
00268 
00269      // vertex covariance matrix
00270       j = 0;
00271       for (m = 1; m <= 3; m++) { 
00272         for (n = 1; n <= m; n++) {
00273           covVertex(m,n)= FCB.vvxou[j++];
00274         }
00275       }
00276  
00277       // correlation between momentum annd vertex
00278       j = 0;
00279       for (m = 1; m <= 3; m++) {
00280         for (n = 1; n <= 3; n++) {
00281           // NOTE: You must take the transposed of the Fortran array.
00282           corrVertexTrack(n,m)= FCB.vpsvx[j++];
00283         }
00284       }
00285 
00286      // chi2
00287      chi2 = _chi2; 
00288 
00289    }
00290  }
00291 
00292 
00293 
00294  return (ifail != 0);
00295 }
00296 
00297 

Generated at Mon Nov 11 15:56:02 2002 for ALPHA++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001