CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DQM/SiStripCommissioningSources/plugins/tracking/SiStripFineDelayTOF.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripCommissioningSources/plugins/tracking/SiStripFineDelayTOF.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include <DataFormats/TrackReco/interface/Track.h>
00004 #include <iostream>
00005 #include "TVector3.h"
00006 #include "TMath.h"
00007 
00008 //#define TIF_COSMIC_SETUP
00009 
00010 double SiStripFineDelayTOF::timeOfFlight(bool cosmics, bool field, double* trackParameters, double* hit, double* phit, bool onDisk)
00011 {
00012 
00013   // case 1: cosmics with no field.
00014   if(cosmics && !field) {
00015    return timeOfFlightCosmic(hit,phit);
00016   }
00017   // case 2: cosmics with field.
00018   else if(cosmics && field) {
00019    return timeOfFlightCosmicB(trackParameters,hit,phit,onDisk);
00020   }
00021   // case 3: beam with no field.
00022   else if(!cosmics && !field) {
00023    return timeOfFlightBeam(hit,phit);
00024   }
00025   // case 4: beam with field.
00026   else {
00027    return timeOfFlightBeamB(trackParameters,hit,phit,onDisk);
00028   }
00029 }
00030 
00031 double SiStripFineDelayTOF::timeOfFlightCosmic(double* hit, double* phit)
00032 {
00033   // constants
00034   const double c = 30; // cm/ns
00035 #ifndef TIF_COSMIC_SETUP
00036   const double Rmu = 385; // cm
00037   const double zmu = 560; // cm
00038   // estimate the time for crossing the barrel
00039   TVector3 r0(hit[0],hit[1],hit[2]);
00040   TVector3 pr(phit[0],phit[1],phit[2]);
00041   TVector2 r0_xy = r0.XYvector();
00042   TVector2 pr_xy = pr.Unit().XYvector();
00043   double t_barrel = ((r0_xy*pr_xy)+sqrt( (r0_xy*pr_xy)*(r0_xy*pr_xy) - r0_xy.Mod2() + Rmu*Rmu  ))/c*pr.Mag()/pr.Perp();
00044   // estimate the time for crossing endcaps
00045   double t_endcap = fabs(((phit[2]/fabs(phit[2])*zmu)+hit[2])/c*pr.Mag()/pr.Pz());
00046   // take the minimum
00047   return t_barrel<t_endcap ? t_barrel : t_endcap;
00048 #else
00049   const double y_trigger = 100; //cm
00050   double p = sqrt(phit[0]*phit[0]+phit[1]*phit[1]+phit[2]*phit[2]);
00051 //  LogDebug("TOF") << "momentum:" << phit[0] << " " << phit[1] << " " << phit[2];
00052 //  LogDebug("TOF") << "p/py=" << p/phit[1] << "  Y0,Y,dY = " << y_trigger << " " << hit[1] << " " << (y_trigger-hit[1]); 
00053 //  LogDebug("TOF") << "d, t=d/c : " << ((y_trigger-hit[1])*(p/phit[1])) << " " << ((y_trigger-hit[1])*(p/phit[1])/c); 
00054   return fabs((y_trigger-hit[1])*(p/phit[1])/c);
00055 #endif
00056 }
00057 
00058 double SiStripFineDelayTOF::timeOfFlightCosmicB(double* trackParameters, double* hit, double* phit, bool onDisk)
00059 {
00060   // constants
00061   const double Rmu = 385; // cm
00062   const double zmu = 560; // cm
00063   const double c = 30; // cm/ns
00064   // track parameters
00065   double& kappa = trackParameters[0];
00066   double& theta = trackParameters[1];
00067   double& phi_0 = trackParameters[2];
00068   double& d_0   = trackParameters[3];
00069   double& z_0   = trackParameters[4];
00070   double invkappa = 1/kappa;
00071   // computes the value of the track parameter that correspond to the hit, relative to phi_0
00072   //double phi = kappa*tan(theta)*(hit[2]-z_0);
00073   double phi = getPhi(trackParameters,hit,onDisk) - phi_0;
00074   // computes the value of the track parameter that correspond to the muon system, relative to phi_0
00075   // phi_mu = phi_mu0 - phi_0
00076   double phi_mu_b = (kappa>0 ? -1 : 1 ) * acos((Rmu*Rmu-d_0*d_0-2*invkappa*invkappa+2*invkappa*d_0)/(2*invkappa*d_0-2*invkappa*invkappa));
00077   double phi_mu_e = kappa*tan(theta)*((phit[2]<0 ? 1 : -1)*zmu-z_0);
00078   // estimate the time for crossing the barrel
00079   double t_barrel = fabs(invkappa/(c*sin(theta))*(phi-phi_mu_b));
00080   // estimate the time for crossing endcaps
00081   double t_endcap = fabs(invkappa/(c*sin(theta))*(phi-phi_mu_e));
00082   // take the minimum
00083   return t_barrel<t_endcap ? t_barrel : t_endcap;
00084 }
00085 
00086 double SiStripFineDelayTOF::timeOfFlightBeam(double* hit, double*)
00087 {
00088   // constants
00089   const double c = 30; // cm/ns
00090   TVector3 r0(hit[0],hit[1],hit[2]);
00091   return r0.Mag()/c;
00092 }
00093 
00094 double SiStripFineDelayTOF::timeOfFlightBeamB(double* trackParameters, double* hit, double* phit, bool onDisk)
00095 {
00096   // constants
00097   const double c = 30; // cm/ns
00098   // track parameters
00099   double& theta = trackParameters[1];
00100   // returns the time of flight from the origin
00101   return onDisk? fabs(hit[2]/(c*cos(theta))) : fabs(sqrt(hit[0]*hit[0]+hit[1]*hit[1])/(c*sin(theta)));
00102 }
00103 
00104 double SiStripFineDelayTOF::x(double* trackParameters, double phi)
00105 {
00106   return trackParameters[3]*sin(trackParameters[2]) + (1/trackParameters[0])*(sin(phi)-sin(trackParameters[2]));
00107 }
00108 
00109 double SiStripFineDelayTOF::y(double* trackParameters, double phi)
00110 {
00111   return -trackParameters[3]*cos(trackParameters[2]) - (1/trackParameters[0])*(cos(phi)-cos(trackParameters[2]));
00112 }
00113 
00114 double SiStripFineDelayTOF::z(double* trackParameters, double phi)
00115 {
00116   return trackParameters[4] + (phi-trackParameters[2])/(trackParameters[0]*tan(trackParameters[1]));
00117 }
00118   
00119 double SiStripFineDelayTOF::getPhi(double* trackParameters, double* hit, bool onDisk)
00120 {
00121  if(onDisk) //use z coordinate to find phi
00122    return trackParameters[2] + trackParameters[0]*tan(trackParameters[1])*(hit[2]-trackParameters[4]);
00123  else // use x,y coordinate to find phi
00124  {
00125    double phi =0;
00126    if(trackParameters[2]>-2.35 && trackParameters[2]<-0.78) {
00127      // first use y
00128      phi = acos(-trackParameters[0]*(hit[1]-(trackParameters[3]-1/trackParameters[0])*(-cos(trackParameters[2]))));
00129      // use x to resolve the ambiguity
00130      if(fabs(x(trackParameters,phi)-hit[0])>fabs(x(trackParameters,-phi)-hit[0])) phi *= -1.;
00131    } else {
00132      // first use x
00133      phi = asin(trackParameters[0]*(hit[0]-(trackParameters[3]-1/trackParameters[0])*sin(trackParameters[2])));
00134      // use y to resolve the ambiguity
00135      if((fabs(y(trackParameters,phi)-hit[1])>fabs(y(trackParameters,TMath::Pi()-phi)-hit[1]))) 
00136        phi = phi>0 ? TMath::Pi()-phi: -TMath::Pi()-phi;
00137    }
00138    return phi;
00139  }
00140  return 0.;
00141 }
00142 
00143 void SiStripFineDelayTOF::trackParameters(const reco::Track& tk,double* trackParameters)
00144 {
00145       math::XYZPoint position = tk.outerPosition();
00146       math::XYZVector momentum = tk.outerMomentum();
00147       LogDebug("trackParameters") << "outer position: " << position.x() << " " << position.y() << " " << position.z();
00148       LogDebug("trackParameters") << "outer momentum: " << momentum.x() << " " << momentum.y() << " " << momentum.z();
00149       math::XYZVector fieldDirection(0,0,1);
00150       // computes the center of curvature
00151       math::XYZVector radius = momentum.Cross(fieldDirection).Unit();
00152       position -= radius / trackParameters[0];
00153       LogDebug("trackParameters") << "center of curvature: " << position.x() << " " << position.y() << " " << position.z();
00154       // the transverse IP
00155       trackParameters[3] = position.rho() - fabs(1/trackParameters[0]);
00156       if(trackParameters[0]>0) trackParameters[3] *= -1.;
00157       // phi_0
00158       double phi_out = trackParameters[2];
00159       double phi_0 = position.phi() - TMath::Pi()/2;
00160       if(trackParameters[0]<0) phi_0 -= TMath::Pi();
00161       if(phi_0<-2*TMath::Pi()) phi_0 += 2*TMath::Pi();
00162       if(phi_0>2*TMath::Pi()) phi_0 -= 2*TMath::Pi();
00163       if(phi_0 > 0) phi_0 -= 2*TMath::Pi();
00164       LogDebug("trackParameters") << "phi_0: " << phi_0;
00165       trackParameters[2] = phi_0;
00166       // z_0
00167       trackParameters[4] = tk.outerPosition().z() - (phi_out-phi_0)/TMath::Tan(trackParameters[1])/trackParameters[0];
00168       LogDebug("trackParameters") << "z_0: " << tk.outerPosition().z() << " " << trackParameters[4] << " " << tk.innerPosition().z();  
00169 }
00170