CMS 3D CMS Logo

ConversionFastHelix.cc

Go to the documentation of this file.
00001 #include "RecoEgamma/EgammaPhotonAlgos/interface/ConversionFastHelix.h"
00002 #include "RecoTracker/TkSeedGenerator/interface/FastLine.h"
00003 #include "TrackingTools/TrajectoryParametrization/interface/GlobalTrajectoryParameters.h"
00004 #include "TrackingTools/TrajectoryParametrization/interface/CurvilinearTrajectoryError.h"
00005 #include "TrackingTools/TrajectoryParametrization/interface/CartesianTrajectoryError.h"
00006 #include "MagneticField/Engine/interface/MagneticField.h"
00007 
00008 
00009 #include <cfloat>
00010 
00011 ConversionFastHelix::ConversionFastHelix(const GlobalPoint& outerHit,
00012                      const GlobalPoint& middleHit,
00013                                          const GlobalPoint& aVertex,
00014                                          const MagneticField* field ) : 
00015   theOuterHit(outerHit),
00016   theMiddleHit(middleHit),
00017   theVertex(aVertex),
00018   theCircle(outerHit,
00019             middleHit,
00020             aVertex),
00021   mField(field) {
00022   
00023   validStateAtVertex=false;
00024 
00025 
00026   makeHelix();
00027  
00028   
00029 }
00030 
00031 
00032 void ConversionFastHelix::makeHelix()  {
00033 
00034 
00035   if(   theCircle.isValid()) {
00036      theHelix_=helixStateAtVertex();
00037   } else {
00038      theHelix_= straightLineStateAtVertex();
00039   }
00040   
00041 
00042 }
00043 
00044 
00045 FreeTrajectoryState ConversionFastHelix::stateAtVertex()  {
00046 
00047   return theHelix_;
00048 
00049 }
00050 
00051 
00052 FreeTrajectoryState ConversionFastHelix::helixStateAtVertex()  {
00053   
00054   
00055   
00056   GlobalPoint pMid(theMiddleHit);
00057   GlobalPoint v(theVertex);
00058   FTS atVertex;
00059   
00060   double dydx = 0.;
00061   double pt = 0., px = 0., py = 0.;
00062   
00063   //remember (radius rho in cm):
00064   //rho = 
00065   //100. * pt * 
00066   //(10./(3.*MagneticField::inTesla(GlobalPoint(0., 0., 0.)).z()));
00067   
00068   double rho = theCircle.rho();
00069   pt = 0.01 * rho * (0.3*mField->inTesla(GlobalPoint(0,0,0)).z());
00070   
00071   // (py/px)|x=v.x() = (dy/dx)|x=v.x()
00072   //remember:
00073   //y(x) = +-sqrt(rho^2 - (x-x0)^2) + y0 
00074   //y(x) =  sqrt(rho^2 - (x-x0)^2) + y0  if y(x) >= y0 
00075   //y(x) = -sqrt(rho^2 - (x-x0)^2) + y0  if y(x) < y0
00076   //=> (dy/dx) = -(x-x0)/sqrt(Q)  if y(x) >= y0
00077   //   (dy/dx) =  (x-x0)/sqrt(Q)  if y(x) < y0
00078   //with Q = rho^2 - (x-x0)^2
00079   
00080   
00081   double arg=rho*rho - ( (v.x()-theCircle.x0())*(v.x()-theCircle.x0()) );
00082   
00083   if ( arg >= 0 ) { 
00084     
00085     
00086     //  double root = sqrt(  rho*rho - ( (v.x()-theCircle.x0())*(v.x()-theCircle.x0()) )  );
00087     double root = sqrt(  arg );
00088     
00089     if((v.y() - theCircle.y0()) > 0.)
00090       dydx = -(v.x() - theCircle.x0()) / root;
00091     else
00092       dydx = (v.x() - theCircle.x0()) / root;
00093     
00094     px = pt/sqrt(1. + dydx*dydx);
00095     py = px*dydx;
00096     // check sign with scalar product
00097     if(px*(pMid.x() - v.x()) + py*(pMid.y() - v.y()) < 0.) {
00098       px *= -1.;
00099       py *= -1.;
00100     } 
00101     
00102     //std::cout << " ConversionFastHelix:helixStateAtVertex  rho " << rho  << " pt " << pt  << " v " <<  v << " theCircle.x0() " <<theCircle.x0() << " theCircle.y0() "  <<  theCircle.y0() << " v.x()-theCircle.x0() "  << v.x()-theCircle.x0() << " rho^2 " << rho*rho << "  v.x()-theCircle.x0()^2 " <<   (v.x()-theCircle.x0())*(v.x()-theCircle.x0()) <<  " root " << root << " arg " << arg <<  " dydx " << dydx << std::endl;
00103     //calculate z0, pz
00104     //(z, R*phi) linear relation in a helix
00105     //with R, phi defined as radius and angle w.r.t. centre of circle
00106     //in transverse plane
00107     //pz = pT*(dz/d(R*phi)))
00108     
00109     FastLine flfit(theOuterHit, theMiddleHit, theCircle.rho());
00110    
00111     
00112     
00113     double z_0 = 0; 
00114     
00115     //std::cout << " ConversionFastHelix:helixStateAtVertex  flfit.n2() " <<  flfit.n2() << " flfit.c() " << flfit.c() << " flfit.n2() " << flfit.n2() << std::endl;
00116     if ( flfit.n2() !=0 && !isnan( flfit.c()) && !isnan(flfit.n2())   ) {
00117       //  std::cout << " Accepted " << std::endl;
00118       z_0 = -flfit.c()/flfit.n2();
00119       double dzdrphi = -flfit.n1()/flfit.n2();
00120       double pz = pt*dzdrphi;
00121       
00122       //get sign of particle
00123       
00124       GlobalVector magvtx=mField->inTesla(v);
00125       TrackCharge q = 
00126         ((theCircle.x0()*py - theCircle.y0()*px) / 
00127          (magvtx.z()) < 0.) ? 
00128         -1 : 1;
00129       
00130 
00131       AlgebraicSymMatrix55 C = AlgebraicMatrixID();
00132       //MP
00133       
00134       atVertex = FTS(GlobalTrajectoryParameters(GlobalPoint(v.x(), v.y(), z_0),
00135                                                 GlobalVector(px, py, pz),
00136                                                 q,
00137                                                 mField),
00138                      CurvilinearTrajectoryError(C));
00139       
00140       //std::cout << " ConversionFastHelix:helixStateAtVertex globalPoint " << GlobalPoint(v.x(), v.y(), z_0) << " GlobalVector " << GlobalVector(px, py, pz)  << " q " << q << " MField " << mField->inTesla(v) << std::endl;
00141       //std::cout << " ConversionFastHelix:helixStateAtVertex atVertex.transverseCurvature() " << atVertex.transverseCurvature() << std::endl;
00142       if( atVertex.transverseCurvature() !=0 ) {
00143         
00144         validStateAtVertex=true;    
00145         
00146         //std::cout << " ConversionFastHelix:helixStateAtVertex validHelixStateAtVertex status " << validStateAtVertex << std::endl;
00147         return atVertex;
00148       }else
00149         return atVertex;
00150     } else {
00151       //std::cout << " ConversionFastHelix:helixStateAtVertex not accepted  validHelixStateAtVertex status  " << validStateAtVertex << std::endl;
00152       return atVertex;
00153     }
00154     
00155     
00156     
00157   } else {
00158     
00159     //std::cout << " ConversionFastHelix:helixStateAtVertex not accepted because arg <0 validHelixStateAtVertex status  " << validStateAtVertex << std::endl;
00160     return atVertex;
00161   }
00162   
00163 
00164 
00165   
00166   
00167 }
00168 
00169 FreeTrajectoryState ConversionFastHelix::straightLineStateAtVertex() {
00170 
00171 
00172   //calculate FTS assuming straight line...
00173 
00174   GlobalPoint pMid(theMiddleHit);
00175   GlobalPoint v(theVertex);
00176 
00177   double dydx = 0.;
00178   double pt = 0., px = 0., py = 0.;
00179   
00180   if(fabs(theCircle.n1()) > 0. || fabs(theCircle.n2()) > 0.)
00181     pt = 1.e+4;// 10 TeV //else no pt
00182   if(fabs(theCircle.n2()) > 0.) {
00183     dydx = -theCircle.n1()/theCircle.n2(); //else px = 0 
00184   }
00185   px = pt/sqrt(1. + dydx*dydx);
00186   py = px*dydx;
00187   // check sign with scalar product
00188   if (px*(pMid.x() - v.x()) + py*(pMid.y() - v.y()) < 0.) {
00189     px *= -1.;
00190     py *= -1.;
00191   } 
00192 
00193   //calculate z_0 and pz at vertex using weighted mean
00194   //z = z(r) = z0 + (dz/dr)*r
00195   //tan(theta) = dr/dz = (dz/dr)^-1
00196   //theta = atan(1./dzdr)
00197   //p = pt/sin(theta)
00198   //pz = p*cos(theta) = pt/tan(theta) 
00199 
00200   FastLine flfit(theOuterHit, theMiddleHit);
00201   FTS atVertex;
00202 
00203   double z_0 = 0;
00204   if (flfit.n2() !=0  && !isnan( flfit.c()) && !isnan(flfit.n2())   ) {
00205     z_0 = -flfit.c()/flfit.n2();
00206 
00207     double dzdr = -flfit.n1()/flfit.n2();
00208     double pz = pt*dzdr; 
00209     
00210     TrackCharge q = 1;
00211  
00212     AlgebraicSymMatrix66 C = AlgebraicMatrixID();
00213     //MP
00214     FTS atVertex = FTS(GlobalTrajectoryParameters(GlobalPoint(v.x(), v.y(), z_0),
00215                                                   GlobalVector(px, py, pz),
00216                                                   q,
00217                                                   mField),
00218                        CartesianTrajectoryError(C));
00219 
00220     validStateAtVertex=true;        
00221 
00222     //    std::cout << " ConversionFastHelix:strighLIneStateAtVertex validStraightLineStateAtVertex status " <<validStateAtVertex  << std::endl;
00223     return atVertex;
00224     
00225   } else {
00226     
00227       return atVertex;
00228   
00229   }
00230 
00231 }

Generated on Tue Jun 9 17:43:26 2009 for CMSSW by  doxygen 1.5.4