CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GflashTrajectory.cc
Go to the documentation of this file.
1 // Most methods of this class are excerpted from CDF Helix and Trajectory class
2 
4 
6  :
7  _cotTheta(0.0),_curvature(0.0),_z0(0.0),_d0(0.0),_phi0(0.0),
8  _isStale(1),
9  _sinPhi0(2),_cosPhi0(2),_sinTheta(2),_cosTheta(2),
10  _s(-999.999),
11  _aa(2),_ss(2),_cc(2)
12 {
13  //detault constructor
14 }
15 
16 //GflashTrajectory::GflashTrajectory(const HepGeom::Vector3D<double> & MomentumGev, const HepGeom::Point3D<double> & PositionCm,
17 // double q, double BFieldTesla)
18 void GflashTrajectory::initializeTrajectory(const HepGeom::Vector3D<double> & MomentumGev, const HepGeom::Point3D<double> & PositionCm,
19  double q, double BFieldTesla)
20  {
21  double CotTheta = 0.0 ;
22  double W = 0;
23  double Z0 = 0;
24  double D0 = 0;
25  double Phi0 =0;
26 
27  if (BFieldTesla != 0.0 && q != 0.0) {
28  double CurvatureConstant=0.0029979;
29  double Helicity = -1.0 * fabs(BFieldTesla) * fabs(q) / (BFieldTesla*q);
30  double Radius = fabs(MomentumGev.perp()/(CurvatureConstant*BFieldTesla*q));
31 
32  if(Radius==0.0) W = HUGE_VAL; else W = Helicity/Radius;
33  double phi1 = MomentumGev.phi();
34  double x = PositionCm.x(), y = PositionCm.y(), z = PositionCm.z();
35  double sinPhi1 = sin(phi1), cosPhi1 = cos(phi1);
36  double gamma = atan((x*cosPhi1 + y*sinPhi1)/(x*sinPhi1-y*cosPhi1 -1/W));
37  Phi0 = phi1+gamma;
38  if(Phi0 > M_PI) Phi0 = Phi0 - 2.0*M_PI;
39  if(Phi0 < -M_PI) Phi0 = Phi0 + 2.0*M_PI;
40  D0 = ((1/W + y*cosPhi1 - x*sinPhi1) /cos(gamma) - 1/W);
41  CotTheta = MomentumGev.z()/MomentumGev.perp();
42  Z0 = z + gamma*CotTheta/W;
43  }
44  else {
45  CLHEP::Hep3Vector direction = MomentumGev.unit();
46  CLHEP::Hep3Vector projectedDirection = CLHEP::Hep3Vector(direction.x(),direction.y(),0.0).unit();
47  double s = projectedDirection.dot(PositionCm);
48  double sprime = s/sin(direction.theta());
49  Z0 = (PositionCm - sprime*direction).z();
50  Phi0 = MomentumGev.phi();
51  CotTheta = MomentumGev.z()/MomentumGev.perp();
52  W = 0.0;
53  D0 = (PositionCm.y()*cos(Phi0) - PositionCm.x()*sin(Phi0));
54  }
55 
56  _cotTheta=CotTheta;
57  _curvature=W/2;
58  _z0=Z0;
59  _d0=D0;
60  _phi0=Phi0;
61 
62  _isStale=1;
63  _s=-999.999;
64  _aa =-999.999;
65  _ss =-999.999;
66  _cc =-999.999;
67  _sinPhi0 = 1.0;
68  _cosPhi0 = 1.0;
69  _sinTheta = 1.0;
70  _cosTheta = 1.0;
71 }
72 
74 {
75 }
76 
77 void GflashTrajectory::setCotTheta(double cotTheta) {
78  _cotTheta=cotTheta;
79  _isStale=true;
80 }
81 
84  _isStale=true;
85 }
86 
87 void GflashTrajectory::setZ0(double z0) {
88  _z0 = z0;
89  _isStale=true;
90 }
91 
92 void GflashTrajectory::setD0(double d0){
93  _d0=d0;
94  _isStale=true;
95 }
96 
97 void GflashTrajectory::setPhi0(double phi0){
98  _phi0=phi0;
99  _isStale=true;
100 }
101 
103  _refreshCache();
104  return _sinPhi0;
105 }
107  _refreshCache();
108  return _cosPhi0;
109 }
111  _refreshCache();
112  return _sinTheta;
113 }
115  _refreshCache();
116  return _cosTheta;
117 }
118 
119 HepGeom::Point3D<double> GflashTrajectory::getPosition(double s) const
120 {
122  if (s==0.0 || _curvature==0.0) {
123  return HepGeom::Point3D<double> (-_d0*_sinPhi0+s*_cosPhi0*_sinTheta,
125  _z0+s*_cosTheta);
126  } else {
127  return HepGeom::Point3D<double> ((_cosPhi0*_ss-_sinPhi0*(2.0*_curvature*_d0+1.0-_cc))
128  /(2.0*_curvature),
129  (_sinPhi0*_ss+_cosPhi0*(2.0*_curvature*_d0+1.0-_cc))
130  /(2.0*_curvature),
131  _s*_cosTheta + _z0);
132  }
133 }
134 
135 HepGeom::Vector3D<double> GflashTrajectory::getDirection(double s) const
136 {
138  if (s==0.0) {
139  return HepGeom::Vector3D<double> (_cosPhi0*_sinTheta,_sinPhi0*_sinTheta,_cosTheta);
140  }
141  double xtan = _sinTheta*(_cosPhi0*_cc -_sinPhi0*_ss);
142  double ytan = _sinTheta*(_cosPhi0*_ss +_sinPhi0*_cc);
143  double ztan = _cosTheta;
144  return HepGeom::Vector3D<double> (xtan,ytan,ztan);
145 }
146 
147 
149 
151 
152  double cP0sT = _cosPhi0*_sinTheta, sP0sT = _sinPhi0*_sinTheta;
153  if ( s && _curvature) {
154  point.getPosition().set((_cosPhi0*_ss-
155  _sinPhi0*(2.0*_curvature*_d0+1.0-_cc))
156  /(2.0*_curvature),
157  (_sinPhi0*_ss+
158  _cosPhi0*(2.0*_curvature*_d0+1.0-_cc))
159  /(2.0*_curvature),
160  s*_cosTheta + _z0);
161 
162  point.getMomentum().set(cP0sT*_cc-sP0sT*_ss,
163  cP0sT*_ss+sP0sT*_cc,
164  _cosTheta);
165  point.setPathLength(s);
166  }
167  else {
168  point.getPosition().set(-_d0*_sinPhi0+s*cP0sT,
169  _d0*_cosPhi0+s*sP0sT,
170  _z0+s*_cosTheta);
171 
172  point.getMomentum().set(cP0sT,sP0sT,_cosTheta);
173 
174  point.setPathLength(s);
175  }
176 
177 }
178 
180 {
181  return (getSinTheta()?(getL2DAtR(rho)/getSinTheta()):0.0);
182 }
183 
184 double GflashTrajectory::getPathLengthAtZ(double z) const {
185  return (getCosTheta()?(z-getZ0())/getCosTheta():0.0);
186 }
187 
188 double GflashTrajectory::getZAtR(double rho) const {
189  return _z0 + getCotTheta()*getL2DAtR(rho);
190 }
191 
192 double GflashTrajectory::getL2DAtR(double rho) const {
193 
194  double L2D;
195 
196  double c = getCurvature();
197  double d = getD0();
198 
199  if (c!=0.0) {
200  double rad = (rho*rho-d*d)/(1.0+2.0*c*d);
201  double rprime;
202  if (rad<0.0) {
203  rprime = 0.0;
204  }
205  else {
206  rprime = sqrt( rad );
207  }
208  if (c*rprime > 1.0 || c*rprime < -1.0) {
209  L2D = c*rprime > 0. ? M_PI/c : -M_PI/c;
210  }
211  else
212  L2D = asin(c*rprime)/c;
213  } else {
214  double rad = rho*rho-d*d;
215  double rprime;
216  if (rad<0.0) rprime = 0.0;
217  else rprime = sqrt( rad );
218 
219  L2D = rprime;
220  }
221  return L2D;
222 }
223 
224 // Update _sinTheta,_cosTheta,_sinPhi0, and _cosPhi0
226  if (_isStale) {
227  _isStale=false;
228  double theta;
229  if ( _cotTheta==0.0 ) {
230  theta = M_PI/2.0;
231  }
232  else {
233  theta=atan(1.0/_cotTheta);
234  if (theta<0.0) theta+=M_PI;
235  }
236  if (theta==0.0) {
237  _sinTheta=0.0;
238  _cosTheta=1.0;
239  }
240  else {
241  _cosTheta=cos(theta);
243  }
244  if (_phi0==0.0) {
245  _sinPhi0=0.0;
246  _cosPhi0=1.0;
247  }
248  else {
249  _cosPhi0 = cos(_phi0);
250  _sinPhi0 = sin(_phi0);
251  // _sinPhi0 = sqrt(1.0-_cosPhi0*_cosPhi0);
252  // if (_phi0>M_PI) _sinPhi0 = -_sinPhi0;
253  }
254  }
255 }
256 // Update _s, _aa, _ss, and _cc if the arclength has changed.
258  _refreshCache();
259  if (_s!=s){
260  _s=s;
262  if (_aa==0.0) {
263  _ss=0.0;
264  _cc=1.0;
265  }
266  else {
267  _ss=sin(_aa);
268  _cc=cos(_aa);
269  }
270  }
271 }
double getL2DAtR(double r) const
static const double Z0
double getPathLengthAtZ(double z) const
void _refreshCache() const
double getCosPhi0() const
void setPathLength(double pathLength)
Divides< arg, void > D0
Definition: Factorize.h:143
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
void setCurvature(double curvature)
double getSinPhi0() const
float float float z
void setPhi0(double phi0)
tuple d
Definition: ztail.py:151
HepGeom::Point3D< double > getPosition(double s=0.0) const
double getCotTheta() const
T curvature(T InversePt, const edm::EventSetup &iSetup)
T sqrt(T t)
Definition: SSEVec.h:18
void setZ0(double z0)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
void setD0(double d0)
double getSinTheta() const
#define M_PI
double getCosTheta() const
void getGflashTrajectoryPoint(GflashTrajectoryPoint &point, double s) const
double getZ0() const
double getZAtR(double r) const
void _cacheSinesAndCosines(double s) const
HepGeom::Vector3D< double > getDirection(double s=0.0) const
Gflash3Vector & getPosition()
double getCurvature() const
Gflash3Vector & getMomentum()
double getD0() const
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
void setCotTheta(double cotTheta)
double getPathLengthAtRhoEquals(double rho) const
void initializeTrajectory(const HepGeom::Vector3D< double > &, const HepGeom::Point3D< double > &, double q, double Field)