ROOTPWA
Vec.cc
Go to the documentation of this file.
1 #include "Vec.h"
2 
3 
4 using namespace std;
5 
6 
7 void threeVec::_init(double x, double y, double z) {
8  this->_x = x;
9  this->_y = y;
10  this->_z = z;
11 }
12 
13 
15  this->_init(0.0, 0.0, 0.0);
16 }
17 
18 
19 threeVec::threeVec(double x, double y, double z) {
20  this->_init(x, y, z);
21 }
22 
23 
25  this->_init(V._x, V._y, V._z);
26 }
27 
28 
30  ;
31 }
32 
33 
35  return threeVec(this->_x + V._x,
36  this->_y + V._y,
37  this->_z + V._z);
38 }
39 
40 
42  return threeVec(this->_x - V._x,
43  this->_y - V._y,
44  this->_z - V._z);
45 }
46 
47 
49  return threeVec( -this->_x, -this->_y, -this->_z);
50 }
51 
52 
53 double threeVec::operator*(const threeVec& V) const {
54  return (this->_x*V._x + this->_y*V._y + this->_z*V._z);
55 }
56 
57 
59  return threeVec(this->_y*V._z - this->_z*V._y,
60  this->_z*V._x - this->_x*V._z,
61  this->_x*V._y - this->_y*V._x);
62 }
63 
64 
65 threeVec operator*(double a, const threeVec& V) {
66  return threeVec(a*V._x, a*V._y, a*V._z);
67 }
68 
69 
70 threeVec operator*(const threeVec& V, double a) {
71  return ( a*V );
72 }
73 
74 
76  this->_x = V._x;
77  this->_y = V._y;
78  this->_z = V._z;
79  return *this;
80 }
81 
82 
84  this->_x += V._x;
85  this->_y += V._y;
86  this->_z += V._z;
87  return *this;
88 }
89 
90 
92  this->_x -= V._x;
93  this->_y -= V._y;
94  this->_z -= V._z;
95  return *this;
96 }
97 
98 
100  this->_x *= a;
101  this->_y *= a;
102  this->_z *= a;
103  return *this;
104 }
105 
106 
107 const threeVec& threeVec::print(ostream& os) const {
108  os << this->_x << "\t" << this->_y << "\t" << this->_z << endl;
109  return *this;
110 }
111 
112 
113 threeVec& threeVec::scan(istream& is) {
114  is >> this->_x;
115  is >> this->_y;
116  is >> this->_z;
117  return *this;
118 }
119 
120 
121 ostream& operator<<(ostream& os, const threeVec& V) {
122  V.print(os);
123  return os;
124 }
125 
126 
127 istream& operator>>(istream& is, threeVec& V) {
128  V.scan(is);
129  return is;
130 }
131 
132 
133 threeVec threeVec::write(ostream& os) const {
134  os.write((char*) &(this->_x), sizeof(this->_x) );
135  os.write((char*) &(this->_y), sizeof(this->_y) );
136  os.write((char*) &(this->_z), sizeof(this->_z) );
137  os.flush();
138  return *this;
139 }
140 
141 
142 threeVec threeVec::read(istream& is) {
143  is.read((char*) &(this->_x), sizeof(this->_x) );
144  is.read((char*) &(this->_y), sizeof(this->_y) );
145  is.read((char*) &(this->_z), sizeof(this->_z) );
146  return *this;
147 }
148 
149 
150 double&
151 threeVec::operator [] (const int index)
152 {
153  assert(index >=0 && index <=2);
154  switch(index) {
155  case 0:
156  return _x;
157  break;
158  case 1:
159  return _y;
160  break;
161  case 2:
162  return _z;
163  break;
164  default:
165  cerr << "threeVec: error: index " << index << " out of bounds";
166  cerr << endl;
167  break;
168  }
169  return _x;
170 }
171 
172 
173 const double&
174 threeVec::operator [] (const int index) const
175 {
176  assert(index >=0 && index <=2);
177  switch(index) {
178  case 0:
179  return _x;
180  break;
181  case 1:
182  return _y;
183  break;
184  case 2:
185  return _z;
186  break;
187  default:
188  cerr << "threeVec: error: index " << index << " out of bounds";
189  cerr << endl;
190  break;
191  }
192  return _x;
193 }
194 
195 
196 threeVec threeVec::set(double x,double y,double z) {
197  this->_x = x;
198  this->_y = y;
199  this->_z = z;
200  return *this;
201 }
202 
203 
204 int threeVec::operator==(const threeVec& V) const {
205  return (this->_x==V._x
206  && this->_y==V._y
207  && this->_z==V._z);
208 }
209 
210 
211 int threeVec::operator!=(const threeVec& V) const {
212  return ( !(*this==V) );
213 }
214 
215 
216 int threeVec::operator<(const threeVec& V) const {
217  return ( this->lenSq() < V.lenSq() );
218 }
219 
220 
221 int threeVec::operator>(const threeVec& V) const {
222  return ( this->lenSq() > V.lenSq() );
223 }
224 
225 
226 int threeVec::operator>=(const threeVec& V) const {
227  return ( this->lenSq() >= V.lenSq() );
228 }
229 
230 
231 int threeVec::operator<=(const threeVec& V) const {
232  return ( this->lenSq() <= V.lenSq() );
233 }
234 
235 
236 double threeVec::x() const {
237  return this->_x;
238 }
239 
240 
241 double threeVec::y() const {
242  return this->_y;
243 }
244 
245 
246 double threeVec::z() const {
247  return this->_z;
248 }
249 
250 
251 double threeVec::r() const {
252  return pow( this->lenSq(),0.5 );
253 }
254 
255 
256 double threeVec::theta() const {
257  return acos( this->cosTheta() );
258 }
259 
260 
261 double threeVec::cosTheta() const {
262  return ( this->_z/this->r() );
263 }
264 
265 
266 double threeVec::phi() const {
267  return atan2( this->_y, this->_x );
268 }
269 
270 
271 double threeVec::len() const {
272  return pow(this->lenSq(),0.5);
273 }
274 
275 
276 double threeVec::lenSq() const {
277  return (this->_x*this->_x
278  + this->_y*this->_y
279  + this->_z*this->_z);
280 }
281 
282 
283 double threeVec::operator~() const {
284  return pow(this->lenSq(),0.5);
285 }
286 
287 
288 threeVec& threeVec::x(double x) {
289  this->_x = x;
290  return *this;
291 }
292 
293 
294 threeVec& threeVec::y(double y) {
295  this->_y = y;
296  return *this;
297 }
298 
299 
300 threeVec& threeVec::z(double z) {
301  this->_z = z;
302  return *this;
303 }
304 
305 
306 threeVec& threeVec::cartesian(double x,double y,double z) {
307  this->_init(x, y, z);
308  return *this;
309 }
310 
311 
312 threeVec& threeVec::polar(double r,double theta,double phi) {
313  this->_x = r*sin(theta)*cos(phi);
314  this->_y = r*sin(theta)*sin(phi);
315  this->_z = r*cos(theta);
316  return *this;
317 }
318 
319 
320 void fourVec::_init(double t, threeVec V) {
321  this->_t = t;
322  this->_V = V;
323 }
324 
325 
327  this->_init(0.0,threeVec(0.0, 0.0, 0.0));
328 }
329 
330 
332  this->_init(t,V);
333 }
334 
335 
337  this->_init(v._t,v._V);
338 }
339 
340 
342  ;
343 }
344 
345 
347  return fourVec( this->_t + v._t,
348  this->_V + v._V );
349 }
350 
351 
353  return fourVec( this->_t - v._t,
354  this->_V - v._V );
355 }
356 
357 
359  return fourVec( -this->_t, -this->_V );
360 }
361 
362 
363 double fourVec::operator*(const fourVec& v) const {
364  return ( this->_t*v._t - this->_V*v._V );
365 }
366 
367 
369  return (this->_V/v._V );
370 }
371 
372 
373 fourVec operator*(double a, const fourVec& v) {
374  return fourVec(a*v._t, a*v._V);
375 }
376 
377 
378 fourVec operator*(const fourVec& v, double a) {
379  return fourVec(a*v._t, a*v._V);
380 }
381 
382 
384  this->_t = v._t;
385  this->_V = v._V;
386  return *this;
387 }
388 
389 
391  this->_t += v._t;
392  this->_V += v._V;
393  return *this;
394 }
395 
396 
398  this->_t -= v._t;
399  this->_V -= v._V;
400  return *this;
401 }
402 
403 
405  this->_t *= a;
406  this->_V *= a;
407  return *this;
408 }
409 
410 
411 const fourVec& fourVec::print(ostream& os) const {
412  os << this->_t << "\t";
413  this->_V.print(os);
414  return *this;
415 }
416 
417 
418 fourVec& fourVec::scan(istream& is) {
419  is >> this->_t;
420  this->_V.scan(is);
421  return *this;
422 }
423 
424 
425 ostream& operator<<(ostream& os, const fourVec& v) {
426  v.print(os);
427  return os;
428 }
429 
430 
431 istream& operator>>(istream& is, fourVec& v) {
432  v.scan(is);
433  return is;
434 }
435 
436 
437 fourVec fourVec::write(ostream& os) const {
438  os.write((char*) &(this->_t), sizeof(this->_t) );
439  this->_V.write(os);
440  os.flush();
441  return *this;
442 }
443 
444 
445 fourVec fourVec::read(istream& is) {
446  is.read((char*) &(this->_t), sizeof(this->_t) );
447  this->_V.read(is);
448  return *this;
449 }
450 
451 
452 double&
453 fourVec::operator [] (const int index)
454 {
455  assert(index >=0 && index <=3);
456  switch(index) {
457  case 0:
458  return _t;
459  break;
460  case 1:
461  case 2:
462  case 3:
463  return _V[index-1];
464  break;
465  default:
466  cerr << "fourVec: warning: index " << index << " out of bounds";
467  cerr << endl;
468  break;
469  }
470  return _t;
471 }
472 
473 
474 const double&
475 fourVec::operator [] (const int index) const
476 {
477  assert(index >=0 && index <=3);
478  switch(index) {
479  case 0:
480  return _t;
481  break;
482  case 1:
483  case 2:
484  case 3:
485  return _V[index-1];
486  break;
487  default:
488  cerr << "fourVec: warning: index " << index << " out of bounds";
489  cerr << endl;
490  break;
491  }
492  return _t;
493 }
494 
495 
496 fourVec fourVec::set(double t,double x,double y,double z) {
497  this->set(t,threeVec(x,y,z));
498  return *this;
499 }
500 
501 
503  this->_t = t;
504  this->_V = V;
505  return *this;
506 }
507 
508 
509 int fourVec::operator==(const fourVec& v) const {
510  return (this->_t==v._t && (this->_V == v._V) );
511 }
512 
513 
514 int fourVec::operator!=(const fourVec& v) const {
515  return ( !(*this==v) );
516 }
517 
518 
519 int fourVec::operator<(const fourVec& v) const {
520  return ( this->lenSq() < v.lenSq() );
521 }
522 
523 
524 int fourVec::operator>(const fourVec& v) const {
525  return ( this->lenSq() > v.lenSq() );
526 }
527 
528 
529 int fourVec::operator>=(const fourVec& v) const {
530  return ( this->lenSq() >= v.lenSq() );
531 }
532 
533 
534 int fourVec::operator<=(const fourVec& v) const {
535  return ( this->lenSq() <= v.lenSq() );
536 }
537 
538 
540  return this->_V;
541 }
542 
543 
544 double fourVec::t() const {
545  return this->_t;
546 }
547 
548 
549 double fourVec::x() const {
550  return this->_V.x();
551 }
552 
553 
554 double fourVec::y() const {
555  return this->_V.y();
556 }
557 
558 
559 double fourVec::z() const {
560  return this->_V.z();
561 }
562 
563 
564 double fourVec::r() const {
565  return pow( this->_V.lenSq(),0.5 );
566 }
567 
568 
569 double fourVec::theta() const {
570  return acos( this->_V.cosTheta() );
571 }
572 
573 
574 double fourVec::cosTheta() const {
575  return ( this->_V.cosTheta() );
576 }
577 
578 
579 double fourVec::phi() const {
580  return ( this->_V.phi() );
581 }
582 
583 
584 double fourVec::len() const {
585  return pow(this->lenSq(),0.5);
586 }
587 
588 
589 double fourVec::lenSq() const {
590  return ( this->_t*this->_t - this->_V.lenSq() );
591 }
592 
593 
594 double fourVec::operator~() const {
595  return pow(this->lenSq(),0.5);
596 }
597 
598 
600  this->_V = V;
601  return *this;
602 }
603 
604 
605 fourVec& fourVec::x(double x) {
606  this->_V.x(x);
607  return *this;
608 }
609 
610 
611 fourVec& fourVec::y(double y) {
612  this->_V.y(y);
613  return *this;
614 }
615 
616 
617 fourVec& fourVec::z(double z) {
618  this->_V.z(z);
619  return *this;
620 }
621 
622 
623 fourVec& fourVec::t(double t) {
624  this->_t = t;
625  return *this;
626 }
627 
628 
629 fourVec& fourVec::cartesian(double x,double y,double z) {
630  this->_V.cartesian(x, y, z);
631  return *this;
632 }
633 
634 
635 fourVec& fourVec::polar(double r,double theta,double phi) {
636  this->_V.polar(r, theta, phi);
637  return *this;
638 }
639 
640 
642  this->_t = pow( this->_V.lenSq()+m*m, 0.5 );
643  return *this;
644 }