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

w_YFMVTC.cpp

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

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