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