CMS 3D CMS Logo

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