CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/QCDAnalysis/ChargedHadronSpectra/src/PlotUtils.cc

Go to the documentation of this file.
00001 #include "QCDAnalysis/ChargedHadronSpectra/interface/PlotUtils.h"
00002 
00003 using namespace std;
00004 
00005 /*****************************************************************************/
00006 void PlotUtils::printHelix
00007   (const GlobalPoint& p1, const GlobalPoint& p2,
00008    const GlobalVector& v2, ofstream& outFile, int charge)
00009 {
00010   GlobalVector dp = p2 - p1;
00011   GlobalVector n2(-v2.y(),v2.x(),0.);
00012   n2 = n2.unit();
00013 
00014   double r = -0.5 * (dp.x()*dp.x() + dp.y()*dp.y()) /
00015                     (dp.x()*n2.x() + dp.y()*n2.y());
00016   GlobalPoint c = p2 + r * n2;
00017 
00018   double dphi = sqrt(2 * 0.1 / fabs(r)); // allowed deflection: 0.1 cm
00019 
00020   double phi = acos(( (p1-c).x()*(p2-c).x() +
00021                       (p1-c).y()*(p2-c).y() )/(r*r));
00022 
00023   if(dp.x()*v2.x() + dp.y()*v2.y() < 0) phi = 2*M_PI - phi;
00024 
00025   int nstep = (int)(phi/dphi) + 1;
00026 
00027   if(nstep > 1)
00028   {
00029     dphi = phi / nstep;
00030     double dz = (p2 - p1).z() / nstep;
00031 
00032 
00033     GlobalPoint P0 = p1;
00034     GlobalPoint P1;
00035 
00036     charge = ((p1 - c).x() * (p2 - c).y() - (p1 - c).y() * (p2 - c).x() > 0 ?
00037               -1 : 1);
00038     if(dp.x()*v2.x() + dp.y()*v2.y() < 0) charge = -charge;
00039 
00040     outFile << ", Line[{{"<<P0.x()<<","<<P0.y()<<",("<<P0.z()<<"-zs)*mz}" ;
00041 
00042     for(int i = 0; i < nstep; i++)
00043     {
00044       double a = -charge * (i+1)*dphi;
00045       double z = p1.z() + (i+1)*dz;
00046 
00047       double x = c.x() + cos(a)*(p1 - c).x() - sin(a)*(p1 - c).y();
00048       double y = c.y() + sin(a)*(p1 - c).x() + cos(a)*(p1 - c).y();
00049 
00050       P1 = GlobalPoint(x,y,z);
00051 
00052       outFile << ", {"<<P1.x()<<","<<P1.y()<<",("<<P1.z()<<"-zs)*mz}";
00053       P0 = P1;
00054     }
00055     outFile << "}]" << std::endl;
00056   }
00057   else
00058   {
00059     GlobalPoint P0 = p1;
00060     GlobalPoint P1 = p2;
00061 
00062     outFile << ", Line[{{"<<P0.x()<<","<<P0.y()<<",("<<P0.z()<<"-zs)*mz}"
00063                   << ", {"<<P1.x()<<","<<P1.y()<<",("<<P1.z()<<"-zs)*mz}}]" << std::endl;
00064   }
00065 }