/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Reconstruction/KalFitAlg/KalFitAlg-00-07-55-p03/src/KalFitDoca.cxx

Go to the documentation of this file.
00001 
00002 
00003 
00004 #include "KalFitAlg/helix/Helix.h"
00005 #include "KalFitAlg/KalFitHitMdc.h"
00006 #include "KalFitAlg/KalFitWire.h"
00007 //#include "KalFitAlg/KalFitTrack.h"
00008 
00009 
00010 using namespace  KalmanFit;
00011 // this approach function is used to calculate poca beteween from the helix and 
00012 // the wire , well it also can deal with the wire sag.  
00013 // this function transpalted from belle trasan packages.
00014 
00015 double 
00016 Helix::approach(KalFitHitMdc& hit, bool doSagCorrection) const {
00017     //...Cal. dPhi to rotate...
00018     //const TMDCWire & w = * link.wire();
00019     HepPoint3D positionOnWire, positionOnTrack;
00020     HepPoint3D pv = pivot();
00021     //std::cout<<"the track pivot in approach is "<<pv<<std::endl;
00022     HepVector Va = a();
00023     //std::cout<<"the track parameters is "<<Va<<std::endl;
00024     HepSymMatrix Ma = Ea(); 
00025     //std::cout<<"the error matrix is "<<Ma<<std::endl;
00026 
00027     Helix _helix(pv, Va ,Ma);
00028     //_helix.pivot(IP);
00029     const KalFitWire& w = hit.wire();
00030     Hep3Vector Wire = w.fwd() - w.bck(); 
00031     //xyPosition(), returns middle position of a wire. z componet is 0.
00032     //w.xyPosition(wp);
00033     double wp[3]; 
00034     wp[0] = 0.5*(w.fwd() + w.bck()).x();   
00035     wp[1] = 0.5*(w.fwd() + w.bck()).y();
00036     wp[2] = 0.;
00037     double wb[3]; 
00038     //w.backwardPosition(wb);
00039     wb[0] = w.bck().x();
00040     wb[1] = w.bck().y();
00041     wb[2] = w.bck().z();
00042     double v[3];
00043     v[0] = Wire.unit().x();
00044     v[1] = Wire.unit().y();
00045     v[2] = Wire.unit().z();
00046     //std::cout<<"Wire.unit() is "<<Wire.unit()<<std::endl; 
00047     
00048     //...Sag correction...
00049     /* if (doSagCorrection) {
00050         HepVector3D dir = w.direction();
00051         HepPoint3D xw(wp[0], wp[1], wp[2]);
00052         HepPoint3D wireBackwardPosition(wb[0], wb[1], wb[2]);
00053         w.wirePosition(link.positionOnTrack().z(),
00054                        xw,
00055                        wireBackwardPosition,
00056                        dir);
00057         v[0] = dir.x();
00058         v[1] = dir.y();
00059         v[2] = dir.z();
00060         wp[0] = xw.x();
00061         wp[1] = xw.y();
00062         wp[2] = xw.z();
00063         wb[0] = wireBackwardPosition.x();
00064         wb[1] = wireBackwardPosition.y();
00065         wb[2] = wireBackwardPosition.z();
00066      }
00067     */
00068     //...Cal. dPhi to rotate...
00069     const HepPoint3D & xc = _helix.center();
00070 
00071     //std::cout<<" helix center: "<<xc<<std::endl;
00072     
00073     double xt[3]; _helix.x(0., xt);
00074     double x0 = - xc.x();
00075     double y0 = - xc.y();
00076     double x1 = wp[0] + x0;
00077     double y1 = wp[1] + y0;
00078     x0 += xt[0];
00079     y0 += xt[1];
00080     double dPhi = atan2(x0 * y1 - y0 * x1, x0 * x1 + y0 * y1);
00081     
00082     //std::cout<<"dPhi is "<<dPhi<<std::endl;
00083 
00084     //...Setup...
00085     double kappa = _helix.kappa();
00086     double phi0 = _helix.phi0();
00087 
00088     //...Axial case...
00089   /*  if (!w.stereo()) {
00090         positionOnTrack = _helix.x(dPhi);
00091         HepPoint3D x(wp[0], wp[1], wp[2]);
00092         x.setZ(positionOnTrack.z());
00093          positionOnWire = x;
00094      //link.dPhi(dPhi);
00095      std::cout<<" in axial wire : positionOnTrack is "<<positionOnTrack
00096               <<" positionOnWire is "<<positionOnWire<<std::endl;
00097          return (positionOnTrack - positionOnWire).mag();
00098     }
00099    */
00100     double firstdfdphi = 0.;
00101     static bool first = true;
00102     if (first) {
00103 //      extern BelleTupleManager * BASF_Histogram;
00104 //      BelleTupleManager * m = BASF_Histogram;
00105 //      h_nTrial = m->histogram("TTrack::approach nTrial", 100, 0., 100.);
00106     }
00107 //#endif
00108 
00109     //...Stereo case...
00110     double rho = Helix::ConstantAlpha / kappa;
00111     double tanLambda = _helix.tanl();
00112     static HepPoint3D x;
00113     double t_x[3];
00114     double t_dXdPhi[3];
00115     const double convergence = 1.0e-5;
00116     double l;
00117     unsigned nTrial = 0;
00118     while (nTrial < 100) {
00119 
00120 //      x = link.positionOnTrack(_helix->x(dPhi));
00121         positionOnTrack = _helix.x(dPhi);
00122         x = _helix.x(dPhi);
00123         t_x[0] = x[0];
00124         t_x[1] = x[1];
00125         t_x[2] = x[2];
00126 
00127         l = v[0] * t_x[0] + v[1] * t_x[1] + v[2] * t_x[2]
00128             - v[0] * wb[0] - v[1] * wb[1] - v[2] * wb[2];
00129 
00130         double rcosPhi = rho * cos(phi0 + dPhi);
00131         double rsinPhi = rho * sin(phi0 + dPhi);
00132         t_dXdPhi[0] =   rsinPhi;
00133         t_dXdPhi[1] = - rcosPhi;
00134         t_dXdPhi[2] = - rho * tanLambda;
00135 
00136         //...f = d(Distance) / d phi...
00137         double t_d2Xd2Phi[2];
00138         t_d2Xd2Phi[0] = rcosPhi;
00139         t_d2Xd2Phi[1] = rsinPhi;
00140 
00141         //...iw new...
00142         double n[3];
00143         n[0] = t_x[0] - wb[0];
00144         n[1] = t_x[1] - wb[1];
00145         n[2] = t_x[2] - wb[2];
00146         
00147         double a[3];
00148         a[0] = n[0] - l * v[0];
00149         a[1] = n[1] - l * v[1];
00150         a[2] = n[2] - l * v[2];
00151         double dfdphi = a[0] * t_dXdPhi[0]
00152             + a[1] * t_dXdPhi[1]
00153             + a[2] * t_dXdPhi[2];
00154 
00155 //#ifdef TRKRECO_DEBUG
00156         if (nTrial == 0) {
00157 //          break;
00158             firstdfdphi = dfdphi;
00159         }
00160 
00161         //...Check bad case...
00162         if (nTrial > 3) {
00163             std::cout<<" bad case, calculate approach ntrial = "<<nTrial<< std::endl;
00164         }
00165 //#endif
00166 
00167         //...Is it converged?...
00168         if (fabs(dfdphi) < convergence)
00169             break;
00170 
00171         double dv = v[0] * t_dXdPhi[0]
00172             + v[1] * t_dXdPhi[1]
00173             + v[2] * t_dXdPhi[2];
00174         double t0 = t_dXdPhi[0] * t_dXdPhi[0]
00175             + t_dXdPhi[1] * t_dXdPhi[1]
00176             + t_dXdPhi[2] * t_dXdPhi[2];
00177         double d2fd2phi = t0 - dv * dv
00178             + a[0] * t_d2Xd2Phi[0]
00179             + a[1] * t_d2Xd2Phi[1];
00180 //          + a[2] * t_d2Xd2Phi[2];
00181 
00182         dPhi -= dfdphi / d2fd2phi;
00183 
00184 //      cout << "nTrial=" << nTrial << endl;
00185 //      cout << "iw f,df,dphi=" << dfdphi << "," << d2fd2phi << "," << dPhi << endl;
00186 
00187         ++nTrial;
00188     }
00189     //...Cal. positions...
00190     positionOnWire[0] = wb[0] + l * v[0];
00191     positionOnWire[1] = wb[1] + l * v[1];
00192     positionOnWire[2] = wb[2] + l * v[2];
00193    
00194     //std::cout<<" positionOnTrack is "<<positionOnTrack
00195     //         <<" positionOnWire is "<<positionOnWire<<std::endl;
00196     return (positionOnTrack - positionOnWire).mag();
00197 
00198     //link.dPhi(dPhi);
00199 
00200     // #ifdef TRKRECO_DEBUG
00201     // h_nTrial->accumulate((float) nTrial + .5);
00202     // #endif
00203     // return nTrial;
00204 }
00205 
00206 
00207 double
00208 Helix::approach(HepPoint3D pfwd, HepPoint3D pbwd,  bool doSagCorrection) const 
00209 {
00210 // ...Cal. dPhi to rotate...
00211 // const TMDCWire & w = * link.wire();
00212     HepPoint3D positionOnWire, positionOnTrack;
00213     HepPoint3D pv = pivot();
00214     HepVector Va = a();
00215     HepSymMatrix Ma = Ea(); 
00216 
00217     Helix _helix(pv, Va ,Ma);
00218     Hep3Vector Wire;
00219     Wire[0] = (pfwd - pbwd).x();
00220     Wire[1] = (pfwd - pbwd).y();
00221     Wire[2] = (pfwd - pbwd).z(); 
00222 // xyPosition(), returns middle position of a wire. z componet is 0.
00223 // w.xyPosition(wp);
00224     double wp[3]; 
00225     wp[0] = 0.5*(pfwd + pbwd).x();   
00226     wp[1] = 0.5*(pfwd + pbwd).y();
00227     wp[2] = 0.;
00228     double wb[3]; 
00229 // w.backwardPosition(wb);
00230     wb[0] = pbwd.x();
00231     wb[1] = pbwd.y();
00232     wb[2] = pbwd.z();
00233     double v[3];
00234     v[0] = Wire.unit().x();
00235     v[1] = Wire.unit().y();
00236     v[2] = Wire.unit().z();
00237 // std::cout<<"Wire.unit() is "<<Wire.unit()<<std::endl; 
00238 
00239 // ...Sag correction...
00240     /* if (doSagCorrection) {
00241         HepVector3D dir = w.direction();
00242         HepPoint3D xw(wp[0], wp[1], wp[2]);
00243         HepPoint3D wireBackwardPosition(wb[0], wb[1], wb[2]);
00244         w.wirePosition(link.positionOnTrack().z(),
00245                        xw,
00246                        wireBackwardPosition,
00247                        dir);
00248         v[0] = dir.x();
00249         v[1] = dir.y();
00250         v[2] = dir.z();
00251         wp[0] = xw.x();
00252         wp[1] = xw.y();
00253         wp[2] = xw.z();
00254         wb[0] = wireBackwardPosition.x();
00255         wb[1] = wireBackwardPosition.y();
00256         wb[2] = wireBackwardPosition.z();
00257      }
00258     */
00259     // ...Cal. dPhi to rotate...
00260     const HepPoint3D & xc = _helix.center();
00261     double xt[3];
00262      _helix.x(0., xt);
00263     double x0 = - xc.x();
00264     double y0 = - xc.y();
00265     double x1 = wp[0] + x0;
00266     double y1 = wp[1] + y0;
00267     x0 += xt[0];
00268     y0 += xt[1];
00269     //std::cout<<" x0 is: "<<x0<<" y0 is: "<<y0<<std::endl;
00270     //std::cout<<" x1 is: "<<x1<<" y1 is: "<<y1<<std::endl;
00271     //std::cout<<" xt[0] is: "<<xt[0]<<" xt[1] is: "<<xt[1]<<std::endl;
00272 
00273     double dPhi = atan2(x0 * y1 - y0 * x1, x0 * x1 + y0 * y1);
00274     //std::cout<<" x0 * y1 - y0 * x1 is: "<<(x0 * y1 - y0 * x1)<<std::endl;
00275     //std::cout<<" x0 * x1 + y0 * y1 is: "<<(x0 * x1 + y0 * y1)<<std::endl;
00276     //std::cout<<" before loop dPhi is "<<dPhi<<std::endl;
00277     //...Setup...
00278     double kappa = _helix.kappa();
00279     double phi0 = _helix.phi0();
00280 
00281     //...Axial case...
00282   /*  if (!w.stereo()) {
00283         positionOnTrack = _helix.x(dPhi);
00284         HepPoint3D x(wp[0], wp[1], wp[2]);
00285         x.setZ(positionOnTrack.z());
00286          positionOnWire = x;
00287      //link.dPhi(dPhi);
00288      std::cout<<" in axial wire : positionOnTrack is "<<positionOnTrack
00289               <<" positionOnWire is "<<positionOnWire<<std::endl;
00290          return (positionOnTrack - positionOnWire).mag();
00291     }
00292    */
00293     double firstdfdphi = 0.;
00294     static bool first = true;
00295     if (first) {
00296 //      extern BelleTupleManager * BASF_Histogram;
00297 //      BelleTupleManager * m = BASF_Histogram;
00298 //      h_nTrial = m->histogram("TTrack::approach nTrial", 100, 0., 100.);
00299     }
00300 //#endif
00301 
00302     //...Stereo case...
00303     double rho = Helix::ConstantAlpha / kappa;
00304     double tanLambda = _helix.tanl();
00305     static HepPoint3D x;
00306     double t_x[3];
00307     double t_dXdPhi[3];
00308     const double convergence = 1.0e-5;
00309     double l;
00310     unsigned nTrial = 0;
00311     while (nTrial < 100) {
00312 
00313 // x = link.positionOnTrack(_helix->x(dPhi));
00314         positionOnTrack = _helix.x(dPhi);
00315         x = _helix.x(dPhi);
00316         t_x[0] = x[0];
00317         t_x[1] = x[1];
00318         t_x[2] = x[2];
00319 
00320         l = v[0] * t_x[0] + v[1] * t_x[1] + v[2] * t_x[2]
00321             - v[0] * wb[0] - v[1] * wb[1] - v[2] * wb[2];
00322 
00323         double rcosPhi = rho * cos(phi0 + dPhi);
00324         double rsinPhi = rho * sin(phi0 + dPhi);
00325         t_dXdPhi[0] =   rsinPhi;
00326         t_dXdPhi[1] = - rcosPhi;
00327         t_dXdPhi[2] = - rho * tanLambda;
00328 
00329         //...f = d(Distance) / d phi...
00330         double t_d2Xd2Phi[2];
00331         t_d2Xd2Phi[0] = rcosPhi;
00332         t_d2Xd2Phi[1] = rsinPhi;
00333 
00334         //...iw new...
00335         double n[3];
00336         n[0] = t_x[0] - wb[0];
00337         n[1] = t_x[1] - wb[1];
00338         n[2] = t_x[2] - wb[2];
00339         
00340         double a[3];
00341         a[0] = n[0] - l * v[0];
00342         a[1] = n[1] - l * v[1];
00343         a[2] = n[2] - l * v[2];
00344         double dfdphi = a[0] * t_dXdPhi[0]
00345             + a[1] * t_dXdPhi[1]
00346             + a[2] * t_dXdPhi[2];
00347 
00348         if (nTrial == 0) {
00349 //          break;
00350             firstdfdphi = dfdphi;
00351         }
00352 
00353         //...Check bad case...
00354         if (nTrial > 3) {
00355 //          std::cout<<" BAD CASE!!, calculate approach ntrial = "<<nTrial<< endl;
00356         }
00357         //...Is it converged?...
00358         if (fabs(dfdphi) < convergence)
00359             break;
00360 
00361         double dv = v[0] * t_dXdPhi[0]
00362             + v[1] * t_dXdPhi[1]
00363             + v[2] * t_dXdPhi[2];
00364         double t0 = t_dXdPhi[0] * t_dXdPhi[0]
00365             + t_dXdPhi[1] * t_dXdPhi[1]
00366             + t_dXdPhi[2] * t_dXdPhi[2];
00367         double d2fd2phi = t0 - dv * dv
00368             + a[0] * t_d2Xd2Phi[0]
00369             + a[1] * t_d2Xd2Phi[1];
00370         //  + a[2] * t_d2Xd2Phi[2];
00371 
00372         dPhi -= dfdphi / d2fd2phi;
00373         ++nTrial;
00374     }
00375     //std::cout<<" dPhi is: "<<dPhi<<std::endl;
00376     //...Cal. positions...
00377     positionOnWire[0] = wb[0] + l * v[0];
00378     positionOnWire[1] = wb[1] + l * v[1];
00379     positionOnWire[2] = wb[2] + l * v[2];
00380 
00381     //std::cout<<"wb[0] is: "<<wb[0]<<" l is: "<<l<<" v[0] is: "<<v[0]<<std::endl;
00382     //std::cout<<"wb[1] is: "<<wb[1]<<" v[1] is: "<<v[1]<<std::endl;
00383     //std::cout<<"wb[2] is: "<<wb[2]<<" v[2] is: "<<v[2]<<std::endl;
00384 
00385     //std::cout<<" positionOnTrack is "<<positionOnTrack
00386     //         <<" positionOnWire is "<<positionOnWire<<std::endl;
00387 
00388     return (positionOnTrack - positionOnWire).mag();
00389     // link.dPhi(dPhi);
00390     // return nTrial;
00391 }

Generated on Tue Nov 29 23:13:24 2016 for BOSS_7.0.2 by  doxygen 1.4.7