CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoEgamma/EgammaPhotonAlgos/src/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 && !std::isnan( flfit.c()) && !std::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   FTS atVertex;
00172 
00173   //calculate FTS assuming straight line...
00174 
00175   GlobalPoint pMid(theMiddleHit);
00176   GlobalPoint v(theVertex);
00177 
00178   double dydx = 0.;
00179   double pt = 0., px = 0., py = 0.;
00180   
00181   if(fabs(theCircle.n1()) > 0. || fabs(theCircle.n2()) > 0.)
00182     pt = 1.e+4;// 10 TeV //else no pt
00183   if(fabs(theCircle.n2()) > 0.) {
00184     dydx = -theCircle.n1()/theCircle.n2(); //else px = 0 
00185   }
00186 
00187   if ( pt==0 && dydx==0. ) {
00188     validStateAtVertex=false;
00189     return atVertex; 
00190   }
00191   px = pt/sqrt(1. + dydx*dydx);
00192   py = px*dydx;
00193 
00194   // check sign with scalar product
00195   if (px*(pMid.x() - v.x()) + py*(pMid.y() - v.y()) < 0.) {
00196     px *= -1.;
00197     py *= -1.;
00198   } 
00199 
00200   //calculate z_0 and pz at vertex using weighted mean
00201   //z = z(r) = z0 + (dz/dr)*r
00202   //tan(theta) = dr/dz = (dz/dr)^-1
00203   //theta = atan(1./dzdr)
00204   //p = pt/sin(theta)
00205   //pz = p*cos(theta) = pt/tan(theta) 
00206 
00207 
00208   FastLine flfit(theOuterHit, theMiddleHit);
00209 
00210   double z_0 = 0;
00211   if (flfit.n2() !=0  && !std::isnan( flfit.c()) && !std::isnan(flfit.n2())   ) {
00212     z_0 = -flfit.c()/flfit.n2();
00213 
00214     double dzdr = -flfit.n1()/flfit.n2();
00215     double pz = pt*dzdr; 
00216     
00217     TrackCharge q = 1;
00218  
00219     AlgebraicSymMatrix66 C = AlgebraicMatrixID();
00220     //MP
00221     atVertex = FTS(GlobalTrajectoryParameters(GlobalPoint(v.x(), v.y(), z_0),
00222                                                   GlobalVector(px, py, pz),
00223                                                   q,
00224                                                   mField),
00225                        CartesianTrajectoryError(C));
00226 
00227     //    std::cout << "  ConversionFastHelix::straightLineStateAtVertex curvature " << atVertex.transverseCurvature() << "   signedInverseMomentum " << atVertex.signedInverseMomentum() << std::endl;
00228     if ( atVertex.transverseCurvature() == -0 ) {
00229       return atVertex;
00230     } else {
00231       validStateAtVertex=true;        
00232       return atVertex;
00233     }
00234   
00235   } else {
00236 
00237 
00238     return atVertex;
00239   
00240   }
00241 
00242 }