StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tofPathLength.cc
1  /***************************************************************************
2  *
3  * $Id: tofPathLength.cc,v 1.8 2009/02/11 18:02:27 dongx Exp $
4  *
5  * Author: Frank Geurts
6  ***************************************************************************
7  *
8  * Description: Calculate helix path length between to points.
9  * requires begin and end point StThreeVectors and helix curvature
10  *
11  ***************************************************************************
12  *
13  * $Log: tofPathLength.cc,v $
14  * Revision 1.8 2009/02/11 18:02:27 dongx
15  * fix the mis-overwriting in the last release
16  *
17  * Revision 1.6 2005/07/06 19:20:01 fisyak
18  * StThreeVectorD == StThreeVector<double>
19  *
20  * Revision 1.5 2004/03/17 01:49:56 dongx
21  * add tofPathLength(StThreeVectorD*, StThreeVectorF*, double)
22  *
23  * Revision 1.4 2003/09/02 17:59:10 perev
24  * gcc 3.2 updates + WarnOff
25  *
26  * Revision 1.3 2003/08/06 23:42:56 geurts
27  * function definitions in seperate header file
28  *
29  * Revision 1.2 2003/07/11 05:08:49 geurts
30  * added extra overloaded function.
31  *
32  * Revision 1.1 2003/04/15 01:45:16 geurts
33  * Introduction of standalone function for TOF path length calculation
34  *
35  **************************************************/
36 #include "StThreeVectorD.hh"
37 #include "StThreeVectorF.hh"
38 #include "tofPathLength.hh"
39 
40 // ----------------------------------------------------------------------------------------------
41 #if 0
42 double tofPathLength(const StThreeVectorD* beginPoint, const StThreeVectorD* endPoint, const double curvature){
43  // used in StTofGeometry::tofHelixToArray
44  double x,y,z;
45  x = (double)beginPoint->x();
46  y = (double)beginPoint->y();
47  z = (double)beginPoint->z();
48  StThreeVector<double> bp (x,y,z);
49  x = (double)endPoint->x();
50  y = (double)endPoint->y();
51  z = (double)endPoint->z();
52  StThreeVector<double> ep(x,y,z);
53  return tofPathLength(&bp,&ep,curvature);
54 }
55 #endif
56 
57 double tofPathLength(const StThreeVectorD* beginPoint, const StThreeVectorF* endPoint, const double curvature){
58  double x,y,z;
59  x = (double)beginPoint->x();
60  y = (double)beginPoint->y();
61  z = (double)beginPoint->z();
62  StThreeVector<double> bp (x,y,z);
63  x = (double)endPoint->x();
64  y = (double)endPoint->y();
65  z = (double)endPoint->z();
66  StThreeVector<double> ep(x,y,z);
67  return tofPathLength(&bp,&ep,curvature);
68 }
69 
70 
71 double tofPathLength(const StThreeVectorF* beginPoint, const StThreeVectorD* endPoint, const double curvature){
72  double x,y,z;
73  x = (double)beginPoint->x();
74  y = (double)beginPoint->y();
75  z = (double)beginPoint->z();
76  StThreeVector<double> bp (x,y,z);
77  x = (double)endPoint->x();
78  y = (double)endPoint->y();
79  z = (double)endPoint->z();
80  StThreeVector<double> ep(x,y,z);
81  return tofPathLength(&bp,&ep,curvature);
82 }
83 
84 double tofPathLength(const StThreeVectorF* beginPoint, const StThreeVectorF* endPoint, const double curvature){
85  double x,y,z;
86  x = (double)beginPoint->x();
87  y = (double)beginPoint->y();
88  z = (double)beginPoint->z();
89  StThreeVector<double> bp (x,y,z);
90  x = (double)endPoint->x();
91  y = (double)endPoint->y();
92  z = (double)endPoint->z();
93  StThreeVector<double> ep(x,y,z);
94  return tofPathLength(&bp,&ep,curvature);
95 }
96 
97 // ----------------------------------------------------------------------------------------------
98 double tofPathLength(const StThreeVector<double>* beginPoint, const StThreeVector<double>* endPoint, const double curvature){
99 
100  double xdif = endPoint->x() - beginPoint->x();
101  double ydif = endPoint->y() - beginPoint->y();
102 
103  double C = ::sqrt(xdif*xdif + ydif*ydif);
104  double s_perp = C;
105  if (curvature){
106  double R = 1/curvature;
107  s_perp = 2*R * asin(C/(2*R));
108  }
109 
110  double s_z = fabs(endPoint->z() - beginPoint->z());
111  double value = ::sqrt(s_perp*s_perp + s_z*s_z);
112 
113  return(value);
114 }
115