CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
fourvec.cc
Go to the documentation of this file.
1 //
2 //
3 // File: src/fourvec.cc
4 // Purpose: Define 3- and 4-vector types for the hitfit package, and
5 // supply a few additional operations.
6 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
7 //
8 // CMSSW File : src/fourvec.cc
9 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
10 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
11 //
12 
36 #include <cmath>
37 
38 using std::fabs;
39 using std::sqrt;
40 using std::sin;
41 using std::cos;
42 using std::atan;
43 using std::exp;
44 using std::log;
45 using std::tan;
46 using std::atan2;
47 
48 
49 namespace { // unnamed namespace
50 
51 
52 double cal_th (double theta, double z)
53 //
54 // Purpose: Helper for deteta. Find `calorimeter theta' given
55 // physics theta and z-vertex. Copied from run 1 code.
56 //
57 // Inputs:
58 // theta - Physics theta.
59 // z - Z-vertex.
60 //
61 // Returns:
62 // Calorimeter theta.
63 //
64 {
65  const double R_CC = 91.6;
66  const double Z_EC = 178.9;
67  const double BIGG = 1e8;
68 
69  double tanth;
70  if (fabs (cos (theta)) < 1/BIGG)
71  tanth = BIGG * sin (theta);
72  else
73  tanth = tan (theta);
74 
75  double z_cc = R_CC / tanth + z;
76 
77  if (fabs (z_cc) < Z_EC)
78  theta = atan2 (R_CC, z_cc);
79 
80  else {
81  double zz = Z_EC;
82  if (tanth < 0) zz = - zz;
83  double r_ec = (zz-z) * tanth;
84  theta = atan2 (r_ec, zz);
85  }
86 
87  if (theta < 0) theta += 2 * M_PI;
88  return theta;
89 }
90 
91 
92 } // unnamed namespace
93 
94 
95 namespace hitfit {
96 
97 
98 void adjust_p_for_mass (Fourvec& v, double mass)
99 //
100 // Purpose: Adjust the 3-vector part of V (leaving the energy unchanged)
101 // so that it has mass MASS. (Provided that is possible.)
102 //
103 // Inputs:
104 // v - The 4-vector to scale.
105 // mass - The desired mass of the 4-vector.
106 //
107 // Outputs:
108 // v - The scaled 4-vector.
109 //
110 {
111  CLHEP::Hep3Vector vect = v.vect();
112  double old_p2 = vect.mag2();
113  if (old_p2 == 0)
114  return;
115  double new_p2 = v.e()*v.e() - mass*mass;
116  if (new_p2 < 0)
117  new_p2 = 0;
118  vect *= sqrt (new_p2 / old_p2);
119  v.setVect (vect);
120 }
121 
122 
123 void adjust_e_for_mass (Fourvec& v, double mass)
124 //
125 // Purpose: Adjust the energy component of V (leaving the 3-vector part
126 // unchanged) so that it has mass MASS.
127 //
128 // Inputs:
129 // v - The 4-vector to scale.
130 // mass - The desired mass of the 4-vector.
131 //
132 // Outputs:
133 // v - The scaled 4-vector.
134 //
135 {
136  v.setE (sqrt (v.vect().mag2() + mass*mass));
137 }
138 
139 
140 void rottheta (Fourvec& v, double theta)
141 //
142 // Purpose: Rotate V through polar angle THETA.
143 //
144 // Inputs:
145 // v - The 4-vector to rotate.
146 // theta - The rotation angle.
147 //
148 // Outputs:
149 // v - The rotated 4-vector.
150 //
151 {
152  double s = sin (theta), c = cos (theta);
153  double old_pt = v.perp();
154  double new_pt = old_pt*c - v.z()*s;
155  v.setZ (old_pt*s + v.z()*c);
156 
157  v.setX (v.x() * new_pt / old_pt);
158  v.setY (v.y() * new_pt / old_pt);
159 }
160 
161 
162 void roteta (Fourvec& v, double eta)
163 //
164 // Purpose: Rotate a Fourvec through a polar angle such that
165 // its pseudorapidity changes by ETA.
166 //
167 // Inputs:
168 // v - The 4-vector to rotate.
169 // eta - The rotation angle.
170 //
171 // Outputs:
172 // v - The rotated 4-vector.
173 //
174 {
175  double theta1 = v.theta ();
176  double eta1 = theta_to_eta (theta1);
177  double eta2 = eta1 + eta;
178  double theta2 = eta_to_theta (eta2);
179 
180  rottheta (v, theta1 - theta2);
181 }
182 
183 
184 double eta_to_theta (double eta)
185 //
186 // Purpose: Convert psuedorapidity to polar angle.
187 //
188 // Inputs:
189 // eta - Pseudorapidity.
190 //
191 // Returns:
192 // Polar angle.
193 //
194 {
195  return 2 * atan (exp (-eta));
196 }
197 
198 
199 double theta_to_eta (double theta)
200 //
201 // Purpose: Convert polar angle to psuedorapidity.
202 //
203 // Inputs:
204 // theta - Polar angle.
205 //
206 // Returns:
207 // Pseudorapidity.
208 //
209 {
210  return - log (tan (theta / 2));
211 }
212 
213 
214 double deteta (const Fourvec& v, double zvert)
215 //
216 // Purpose: Get the detector eta (D0-specific).
217 //
218 // Inputs:
219 // v - Vector on which to operate.
220 // zvert - Z-vertex.
221 //
222 // Returns:
223 // Detector eta of V.
224 //
225 {
226  return theta_to_eta (cal_th (v.theta(), zvert));
227 }
228 
229 
230 double phidiff (double phi)
231 //
232 // Purpose: Handle wraparound for a difference in azimuthal angles.
233 //
234 // Inputs:
235 // phi - Azimuthal angle.
236 //
237 // Returns:
238 // PHI normalized to the range -pi .. pi.
239 //
240 {
241  while (phi < -M_PI)
242  phi += 2 * M_PI;
243  while (phi > M_PI)
244  phi -= 2*M_PI;
245  return phi;
246 }
247 
248 
249 double delta_r (const Fourvec& a, const Fourvec& b)
250 //
251 // Purpose: Find the distance in R between two four-vectors.
252 //
253 // Inputs:
254 // a - First four-vector.
255 // b - Second four-vector.
256 //
257 // Returns:
258 // the distance in R between A and B.
259 //
260 {
261  double deta = a.pseudoRapidity() - b.pseudoRapidity();
262  double dphi = phidiff (a.phi() - b.phi());
263  return sqrt (deta*deta + dphi*dphi);
264 }
265 
266 
267 } // namespace hitfit
Define three-vector and four-vector classes for the HitFit package, and supply a few additional opera...
void adjust_e_for_mass(Fourvec &v, double mass)
Adjust the energy component of four-vector v (leaving the three-vector part unchanged) so that the fo...
Definition: fourvec.cc:123
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
double phidiff(double phi)
Normalized difference in azimuthal angles to a range between .
Definition: fourvec.cc:230
double theta_to_eta(double theta)
Convert polar angle to pseudorapidity.
Definition: fourvec.cc:199
void roteta(Fourvec &v, double eta)
Rotate four-vector v through a polar angle such that the four-vector pseudorapidity changes by a desi...
Definition: fourvec.cc:162
T eta() const
float float float z
T sqrt(T t)
Definition: SSEVec.h:48
double eta_to_theta(double eta)
Convert pseudorapidity to polar angle.
Definition: fourvec.cc:184
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
double delta_r(const Fourvec &a, const Fourvec &b)
Find the distance between two four-vectors in the two-dimensional space .
Definition: fourvec.cc:249
CLHEP::HepLorentzVector Fourvec
Typedef for a HepLorentzVector.
Definition: fourvec.h:57
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
double deteta(const Fourvec &v, double zvert)
NOT USED ANYMORE: Get the detector (D0-specific), requires z-vertex.
Definition: fourvec.cc:214
#define M_PI
void adjust_p_for_mass(Fourvec &v, double mass)
Adjust the three-vector part of v, leaving the energy unchanged,.
Definition: fourvec.cc:98
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
void rottheta(Fourvec &v, double theta)
Rotate four-vector v through a polar angle.
Definition: fourvec.cc:140
Definition: DDAxes.h:10