Belle II Software development
B2Vector3.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11
12#include <framework/logging/Logger.h>
13
14#include <TVector3.h>
15#include <Math/Vector3D.h>
16#include <string>
17#include <iostream> // std::cout, std::fixed
18#include <iomanip> // std::setprecision
19#include <typeinfo>
20#include <cmath>
21
22
23namespace Belle2 {
28
40
41 template<typename DataType>
42 class B2Vector3 {
43 protected:
45 static_assert(std::is_floating_point<DataType>::value, "B2Vector3 only works with floating point types");
47 DataType m_coordinates[3] {};
48 public:
50 typedef DataType value_type;
51
53 B2Vector3(void) : m_coordinates {static_cast<DataType>(0), static_cast<DataType>(0), static_cast<DataType>(0)} {};
55 B2Vector3(const DataType xVal, const DataType yVal, const DataType zVal): m_coordinates {xVal, yVal, zVal} {};
57 explicit B2Vector3(const DataType(& coords)[3]): m_coordinates {coords[0], coords[1], coords[2]} {};
59 explicit B2Vector3(const DataType(* coords)[3]): m_coordinates {(*coords)[0], (*coords)[1], (*coords)[2]} {};
61 // cppcheck-suppress noExplicitConstructor
62 B2Vector3(const TVector3& tVec3): m_coordinates {static_cast<DataType>(tVec3.X()), static_cast<DataType>(tVec3.Y()), static_cast<DataType>(tVec3.Z())} {};
64 // cppcheck-suppress noExplicitConstructor
65 B2Vector3(const TVector3* tVec3): m_coordinates {static_cast<DataType>(tVec3->X()), static_cast<DataType>(tVec3->Y()), static_cast<DataType>(tVec3->Z())} {};
67 explicit B2Vector3(const B2Vector3<DataType>& b2Vec3): m_coordinates {b2Vec3.X(), b2Vec3.Y(), b2Vec3.Z()} {};
69 explicit B2Vector3(const B2Vector3<DataType>* b2Vec3): m_coordinates {b2Vec3->X(), b2Vec3->Y(), b2Vec3->Z()} {};
71 // the implicit conversion between B2Vector3 of different types is intended;
72 // the second id keeps cppcheck quiet in translation units where this template is not instantiated
73 // cppcheck-suppress[noExplicitConstructor,unmatchedSuppression]
74 template <typename OtherType> B2Vector3(const B2Vector3<OtherType>& b2Vec3):
75 m_coordinates {static_cast<DataType>(b2Vec3.X()), static_cast<DataType>(b2Vec3.Y()), static_cast<DataType>(b2Vec3.Z())} {};
76
77 template <typename OtherType> explicit B2Vector3(const B2Vector3<OtherType>* b2Vec3):
78 m_coordinates {static_cast<DataType>(b2Vec3->X()), static_cast<DataType>(b2Vec3->Y()), static_cast<DataType>(b2Vec3->Z())} {};
79
80 // cppcheck-suppress noExplicitConstructor
81 B2Vector3(const ROOT::Math::XYZVector& xyzVec): m_coordinates {static_cast<DataType>(xyzVec.X()), static_cast<DataType>(xyzVec.Y()), static_cast<DataType>(xyzVec.Z())} {};
83 // cppcheck-suppress noExplicitConstructor
84 B2Vector3(const ROOT::Math::XYZVector* xyzVec): m_coordinates {static_cast<DataType>(xyzVec->X()), static_cast<DataType>(xyzVec->Y()), static_cast<DataType>(xyzVec->Z())} {};
85
87 DataType operator()(unsigned i) const { return m_coordinates[i]; }
89 DataType operator[](unsigned i) const { return m_coordinates[i]; }
91 DataType& operator()(unsigned i) { return m_coordinates[i]; }
93 DataType& operator[](unsigned i) { return m_coordinates[i]; }
94
98 B2Vector3<DataType>& operator = (const TVector3& b);
100 B2Vector3<DataType>& operator = (const ROOT::Math::XYZVector& b);
101
103 operator TVector3() const { return GetTVector3(); }
105 operator ROOT::Math::XYZVector() const { return GetXYZVector(); }
106
108 bool operator == (const B2Vector3<DataType>& b) const { return X() == b.X() && Y() == b.Y() && Z() == b.Z(); }
110 bool operator == (const TVector3& b) const { return X() == b.X() && Y() == b.Y() && Z() == b.Z(); }
112 bool operator == (const ROOT::Math::XYZVector& b) const { return X() == b.X() && Y() == b.Y() && Z() == b.Z(); }
114 bool operator != (const B2Vector3<DataType>& b) const { return !(*this == b); }
116 bool operator != (const TVector3& b) const { return !(*this == b); }
118 bool operator != (const ROOT::Math::XYZVector& b) const { return !(*this == b); }
119
127 B2Vector3<DataType> operator - () const { return B2Vector3<DataType>(-X(), -Y(), -Z()); }
130 {
131 return B2Vector3<DataType>(X() + b.X(), Y() + b.Y(), Z() + b.Z());
132 }
133
135 {
136 return B2Vector3<DataType>(X() - b.X(), Y() - b.Y(), Z() - b.Z());
137 }
138
140 {
141 return B2Vector3<DataType>(a * X(), a * Y(), a * Z());
142 }
143
145 {
146 return B2Vector3<DataType>(X() / a, Y() / a, Z() / a);
147 }
148
149 DataType operator * (const B2Vector3<DataType>& b) const { return Dot(b); }
150
151
153 DataType Phi() const { return X() == 0 && Y() == 0 ? 0 : atan2(Y(), X()); }
155 DataType Theta() const { return X() == 0 && Y() == 0 && Z() == 0 ? 0 : atan2(Perp(), Z()); }
157 DataType CosTheta() const { const double pTot = Mag(); return pTot == 0 ? 1 : Z() / pTot; }
159 DataType Mag2() const { return X() * X() + Y() * Y() + Z() * Z(); }
161 DataType Mag() const { return std::hypot((double)Perp(), (double)Z()); }
162
164 void SetPhi(DataType phi)
165 {
166 const double perp = Perp();
167 SetX(perp * cos((double)phi));
168 SetY(perp * sin((double)phi));
169 }
170
172 void SetTheta(DataType theta)
173 {
174 const double ma = Mag();
175 const double ph = Phi();
176 const double ctheta = std::cos((double) theta);
177 const double stheta = std::sin((double) theta);
178 SetX(ma * stheta * std::cos(ph));
179 SetY(ma * stheta * std::cos(ph));
180 SetZ(ma * ctheta);
181 }
182
184 void SetMag(DataType mag)
185 {
186 double factor = Mag();
187 if (factor == 0) {
188 B2WARNING(name() << "::SetMag: zero vector can't be stretched");
189 } else {
190 factor = mag / factor;
191 SetX(X()*factor);
192 SetY(Y()*factor);
193 SetZ(Z()*factor);
194 }
195 }
196
198 DataType Perp2() const { return X() * X() + Y() * Y(); }
200 DataType Pt() const { return Perp(); }
202 DataType Perp() const { return std::hypot((double)X(), (double)Y()); }
203
205 void SetPerp(DataType r)
206 {
207 const double p = Perp();
208 if (p != 0.0) {
209 m_coordinates[0] *= r / p;
210 m_coordinates[1] *= r / p;
211 }
212 }
213
215 DataType Perp2(const B2Vector3<DataType>& axis) const
216 {
217 const double tot = axis.Mag2();
218 const double ss = Dot(axis);
219 double per = Mag2();
220 if (tot > 0.0) per -= ss * ss / tot;
221 if (per < 0) per = 0;
222 return per;
223 }
224
226 DataType Pt(const B2Vector3<DataType>& axis) const { return Perp(axis); }
228 DataType Perp(const B2Vector3<DataType>& axis) const { return std::sqrt(Perp2(axis)); }
230 DataType DeltaPhi(const B2Vector3<DataType>& v) const { return Mpi_pi(Phi() - v.Phi()); }
231
232
234 static DataType Mpi_pi(DataType angle)
235 {
236 if (std::isnan(angle)) {
237 B2ERROR(name() << "::Mpi_pi: function called with NaN");
238 return angle;
239 }
240 angle = std::remainder(angle, 2 * M_PI);
241 //for compatibility with ROOT we flip the sign for exactly pi
242 if (angle == M_PI) angle = -M_PI;
243 return angle;
244 }
245
247 DataType DeltaR(const B2Vector3<DataType>& v) const
248 {
249 const double deta = Eta() - v.Eta();
250 const double dphi = DeltaPhi(v);
251 return std::hypot(deta, dphi);
252 }
253
255 DataType DrEtaPhi(const B2Vector3<DataType>& v) const
256 {
257 return DeltaR(v);
258 }
259
261 void SetMagThetaPhi(DataType mag, DataType theta, DataType phi)
262 {
263 const double amag = std::abs(mag);
264 const double sinTheta = std::sin((double)theta);
265 m_coordinates[0] = amag * sinTheta * std::cos((double)phi);
266 m_coordinates[1] = amag * sinTheta * std::sin((double)phi);
267 m_coordinates[2] = amag * std::cos((double)theta);
268 }
269
272 {
273 const double tot = Mag2();
274 B2Vector3<DataType> p(X(), Y(), Z());
275 return tot > 0.0 ? p *= (1.0 / std::sqrt(tot)) : p;
276 }
277
280 {
281 const double xVal = std::abs((double)X());
282 const double yVal = std::abs((double)Y());
283 const double zVal = std::abs((double)Z());
284 if (xVal < yVal) {
285 return xVal < zVal ? B2Vector3<DataType>(0, Z(), -Y()) : B2Vector3<DataType>(Y(), -X(), 0);
286 } else {
287 return yVal < zVal ? B2Vector3<DataType>(-Z(), 0, X()) : B2Vector3<DataType>(Y(), -X(), 0);
288 }
289 }
290
292 DataType Dot(const B2Vector3<DataType>& p) const
293 {
294 return X() * p.X() + Y() * p.Y() + Z() * p.Z();
295 }
296
299 {
300 return B2Vector3<DataType>(Y() * p.Z() - p.Y() * Z(), Z() * p.X() - p.Z() * X(), X() * p.Y() - p.X() * Y());
301 }
302
304 DataType Angle(const B2Vector3<DataType>& q) const
305 {
306 const double ptot2 = static_cast<double>(Mag2()) * q.Mag2();
307 if (ptot2 <= 0) {
308 return 0.0;
309 } else {
310 double arg = Dot(q) / std::sqrt(ptot2);
311 if (arg > 1.0) arg = 1.0;
312 if (arg < -1.0) arg = -1.0;
313 return std::acos(arg);
314 }
315 }
316
321 DataType PseudoRapidity() const
322 {
323 const double cosTheta = CosTheta();
324 if (std::abs(cosTheta) < 1) return -0.5 * std::log((1.0 - cosTheta) / (1.0 + cosTheta));
325 if (Z() == 0) return 0;
326 //B2WARNING(name() << "::PseudoRapidity: transverse momentum = 0! return +/- 10e10");
327 if (Z() > 0) return 10e10;
328 else return -10e10;
329 }
330
331
333 DataType Eta() const { return PseudoRapidity(); }
334
335
337 void RotateX(DataType angle)
338 {
339 //rotate vector around X
340 const double s = std::sin((double)angle);
341 const double c = std::cos((double)angle);
342 const double yOld = Y();
343 m_coordinates[1] = c * yOld - s * Z();
344 m_coordinates[2] = s * yOld + c * Z();
345 }
346
347
349 void RotateY(DataType angle)
350 {
351 //rotate vector around Y
352 const double s = std::sin((double)angle);
353 const double c = std::cos((double)angle);
354 const double zOld = Z();
355 m_coordinates[0] = s * zOld + c * X();
356 m_coordinates[2] = c * zOld - s * X();
357 }
358
359
361 void RotateZ(DataType angle)
362 {
363 //rotate vector around Z
364 const double s = std::sin((double)angle);
365 const double c = std::cos((double)angle);
366 const double xOld = X();
367 m_coordinates[0] = c * xOld - s * Y();
368 m_coordinates[1] = s * xOld + c * Y();
369 }
370
372 void RotateUz(const B2Vector3<DataType>& NewUzVector)
373 {
374 // NewUzVector must be normalized !
375
376 const double u1 = NewUzVector.X();
377 const double u2 = NewUzVector.Y();
378 const double u3 = NewUzVector.Z();
379 double up = u1 * u1 + u2 * u2;
380
381 if (up) {
382 up = std::sqrt(up);
383 DataType px = X(), py = Y(), pz = Z();
384 m_coordinates[0] = (u1 * u3 * px - u2 * py + u1 * up * pz) / up;
385 m_coordinates[1] = (u2 * u3 * px + u1 * py + u2 * up * pz) / up;
386 m_coordinates[2] = (u3 * u3 * px - px + u3 * up * pz) / up;
387 } else if (u3 < 0.) {
390 }
391 }
392
401 void Rotate(DataType alpha, const B2Vector3<DataType>& v)
402 {
403 B2Vector3<DataType> n = v.Unit();
404 *this = (n * (n.Dot(*this)) + cos(alpha) * ((n.Cross(*this)).Cross(n)) + sin(alpha) * (n.Cross(*this)));
405 }
406
408 void Abs()
409 {
410 m_coordinates[0] = std::abs(m_coordinates[0]);
411 m_coordinates[1] = std::abs(m_coordinates[1]);
412 m_coordinates[2] = std::abs(m_coordinates[2]);
413 }
414
416 void Sqrt()
417 {
418 Abs();
419 m_coordinates[0] = std::sqrt(m_coordinates[0]);
420 m_coordinates[1] = std::sqrt(m_coordinates[1]);
421 m_coordinates[2] = std::sqrt(m_coordinates[2]);
422 }
423
425 DataType at(unsigned i) const;
427 DataType x() const { return m_coordinates[0]; }
429 DataType y() const { return m_coordinates[1]; }
431 DataType z() const { return m_coordinates[2]; }
433 // X() forwards to the non-static member x(), so it cannot be static: this is a cppcheck false positive
434 // cppcheck-suppress[functionStatic,unmatchedSuppression]
435 DataType X() const { return x(); }
437 DataType Y() const { return y(); }
439 DataType Z() const { return z(); }
441 // Px() forwards to the non-static member x(), so it cannot be static: this is a cppcheck false positive
442 // cppcheck-suppress[functionStatic,unmatchedSuppression]
443 DataType Px() const { return x(); }
445 DataType Py() const { return y(); }
447 DataType Pz() const { return z(); }
448
450 void GetXYZ(Double_t* carray) const;
452 void GetXYZ(Float_t* carray) const;
454 void GetXYZ(TVector3* tVec) const;
456 void GetXYZ(ROOT::Math::XYZVector* xyzVec) const;
458 TVector3 GetTVector3() const;
460 ROOT::Math::XYZVector GetXYZVector() const;
461
463 void SetX(DataType x) { m_coordinates[0] = x; }
465 void SetY(DataType y) { m_coordinates[1] = y; }
467 void SetZ(DataType z) { m_coordinates[2] = z; }
468
470 void SetXYZ(DataType x, DataType y, DataType z)
471 {
472 SetX(x); SetY(y); SetZ(z);
473 }
474
475 void SetXYZ(const TVector3& tVec);
477 void SetXYZ(const TVector3* tVec);
479 void SetXYZ(const ROOT::Math::XYZVector& xyzVec);
481 void SetXYZ(const ROOT::Math::XYZVector* xyzVec);
482
484 static std::string name();
485
487 std::string PrintString(unsigned precision = 4) const
488 {
489 return name() + " " + PrintStringXYZ(precision) + " " + PrintStringCyl(precision);
490 }
491
493 std::string PrintStringXYZ(unsigned precision = 4) const
494 {
495 std::ostringstream output;
496 output << "(x,y,z)=("
497 << std::fixed << std::setprecision(precision)
498 << X() << "," << Y() << "," << Z() << ")";
499 return output.str();
500 }
501
503 std::string PrintStringCyl(unsigned precision = 4) const
504 {
505 std::ostringstream output;
506 output << "(rho, theta, phi)=("
507 << std::fixed << std::setprecision(precision)
508 << Mag() << "," << Theta() * 180. / M_PI << "," << Phi() * 180. / M_PI << ")";
509 return output.str();
510 }
511
513 void Print()
514 {
515 //print vector parameters
516 Print(PrintString().c_str());
517 }
518
519 };
520
523
526
528 template <typename DataType>
529 Bool_t operator == (const TVector3& a, const B2Vector3<DataType>& b)
530 {
531 return (a.X() == b.X() && a.Y() == b.Y() && a.Z() == b.Z());
532 }
533
535 template < typename DataType>
536 Bool_t operator != (const TVector3& a, const B2Vector3<DataType>& b)
537 {
538 return !(a == b);
539 }
540
542 template < typename DataType>
544 {
545 return B2Vector3<DataType>(a * p.X(), a * p.Y(), a * p.Z());
546 }
547
549 template < typename DataType>
551 {
552 return B2Vector3<DataType>(a.X() + b.X(), a.Y() + b.Y(), a.Z() + b.Z());
553 }
554
556 template < typename DataType>
558 {
559 return B2Vector3<DataType>(a.X() - b.X(), a.Y() - b.Y(), a.Z() - b.Z());
560 }
561
563 template < typename DataType>
565 {
566 return B2Vector3<DataType>(a.X() + b.X(), a.Y() + b.Y(), a.Z() + b.Z());
567 }
568
570 template < typename DataType>
572 {
573 return B2Vector3<DataType>(a.X() - b.X(), a.Y() - b.Y(), a.Z() - b.Z());
574 }
575
577 template < typename DataType>
578 B2Vector3<DataType> operator + (const ROOT::Math::XYZVector& a, const B2Vector3<DataType>& b)
579 {
580 return B2Vector3<DataType>(a.X() + b.X(), a.Y() + b.Y(), a.Z() + b.Z());
581 }
582
584 template < typename DataType>
585 B2Vector3<DataType> operator - (const ROOT::Math::XYZVector& a, const B2Vector3<DataType>& b)
586 {
587 return B2Vector3<DataType>(a.X() - b.X(), a.Y() - b.Y(), a.Z() - b.Z());
588 }
589
591 template < typename DataType>
592 B2Vector3<DataType> operator + (const B2Vector3<DataType>& a, const ROOT::Math::XYZVector& b)
593 {
594 return B2Vector3<DataType>(a.X() + b.X(), a.Y() + b.Y(), a.Z() + b.Z());
595 }
596
598 template < typename DataType>
599 B2Vector3<DataType> operator - (const B2Vector3<DataType>& a, const ROOT::Math::XYZVector& b)
600 {
601 return B2Vector3<DataType>(a.X() - b.X(), a.Y() - b.Y(), a.Z() - b.Z());
602 }
603
604
606 template< typename DataType >
608 {
609 m_coordinates[0] = b.X();
610 m_coordinates[1] = b.Y();
611 m_coordinates[2] = b.Z();
612 return *this;
613 }
614
616 template< typename DataType >
618 {
619 m_coordinates[0] = b.X();
620 m_coordinates[1] = b.Y();
621 m_coordinates[2] = b.Z();
622 return *this;
623 }
624
626 template< typename DataType >
628 {
629 m_coordinates[0] = b.X();
630 m_coordinates[1] = b.Y();
631 m_coordinates[2] = b.Z();
632 return *this;
633 }
634
636 template< typename DataType >
638 {
639 m_coordinates[0] += b.X();
640 m_coordinates[1] += b.Y();
641 m_coordinates[2] += b.Z();
642 return *this;
643 }
644
645
647 template< typename DataType >
649 {
650 m_coordinates[0] -= b.X();
651 m_coordinates[1] -= b.Y();
652 m_coordinates[2] -= b.Z();
653 return *this;
654 }
655
657 template< typename DataType >
659 {
660 m_coordinates[0] *= a;
661 m_coordinates[1] *= a;
662 m_coordinates[2] *= a;
663 return *this;
664 }
665
667 template< typename DataType >
668 void B2Vector3<DataType>::SetXYZ(const TVector3& tVec)
669 {
670 m_coordinates[0] = static_cast<Double_t>(tVec.X());
671 m_coordinates[1] = static_cast<Double_t>(tVec.Y());
672 m_coordinates[2] = static_cast<Double_t>(tVec.Z());
673 }
674
676 template< typename DataType >
677 void B2Vector3<DataType>::SetXYZ(const TVector3* tVec)
678 {
679 m_coordinates[0] = static_cast<Double_t>(tVec->X());
680 m_coordinates[1] = static_cast<Double_t>(tVec->Y());
681 m_coordinates[2] = static_cast<Double_t>(tVec->Z());
682 }
683
685 template< typename DataType >
686 void B2Vector3<DataType>::SetXYZ(const ROOT::Math::XYZVector& xyzVec)
687 {
688 m_coordinates[0] = static_cast<Double_t>(xyzVec.X());
689 m_coordinates[1] = static_cast<Double_t>(xyzVec.Y());
690 m_coordinates[2] = static_cast<Double_t>(xyzVec.Z());
691 }
692
694 template< typename DataType >
695 void B2Vector3<DataType>::SetXYZ(const ROOT::Math::XYZVector* xyzVec)
696 {
697 m_coordinates[0] = static_cast<Double_t>(xyzVec->X());
698 m_coordinates[1] = static_cast<Double_t>(xyzVec->Y());
699 m_coordinates[2] = static_cast<Double_t>(xyzVec->Z());
700 }
701
702 template< typename DataType >
703 void B2Vector3<DataType>::GetXYZ(Double_t* carray) const
704 {
705 carray[0] = X();
706 carray[1] = Y();
707 carray[2] = Z();
708 }
709
710 template< typename DataType >
711 void B2Vector3<DataType>::GetXYZ(Float_t* carray) const
712 {
713 carray[0] = X();
714 carray[1] = Y();
715 carray[2] = Z();
716 }
717
719 template< typename DataType >
720 void B2Vector3<DataType>::GetXYZ(TVector3* tVec) const
721 {
722 tVec->SetXYZ(static_cast<Double_t>(X()),
723 static_cast<Double_t>(Y()),
724 static_cast<Double_t>(Z()));
725 }
726
728 template< typename DataType >
729 void B2Vector3<DataType>::GetXYZ(ROOT::Math::XYZVector* xyzVec) const
730 {
731 xyzVec->SetXYZ(static_cast<Double_t>(X()),
732 static_cast<Double_t>(Y()),
733 static_cast<Double_t>(Z()));
734 }
735
736
738 template< typename DataType >
740 {
741 return
742 TVector3(
743 static_cast<Double_t>(X()),
744 static_cast<Double_t>(Y()),
745 static_cast<Double_t>(Z())
746 );
747 }
748
749
751 template< typename DataType >
752 ROOT::Math::XYZVector B2Vector3<DataType>::GetXYZVector() const
753 {
754 return
755 ROOT::Math::XYZVector(
756 static_cast<Double_t>(X()),
757 static_cast<Double_t>(Y()),
758 static_cast<Double_t>(Z())
759 );
760 }
761
762
764 template < typename DataType>
765 DataType B2Vector3<DataType>::at(unsigned i) const
766 {
767 switch (i) {
768 case 0:
769 case 1:
770 case 2:
771 return m_coordinates[i];
772 }
773 B2FATAL(this->name() << "::access operator: given index (i=" << i << ") is out of bounds!");
774 return 0.;
775 }
776
778 template < typename DataType>
780 {
781 return std::string("B2Vector3<") + typeid(DataType).name() + std::string(">");
782 }
783
785} // end namespace Belle2
A fast and root compatible alternative to TVector3.
Definition B2Vector3.h:42
DataType Phi() const
The azimuth angle.
Definition B2Vector3.h:153
void SetMag(DataType mag)
Set magnitude keeping theta and phi constant.
Definition B2Vector3.h:184
B2Vector3< DataType > operator-() const
unary minus
Definition B2Vector3.h:127
DataType Pz() const
access variable Z (= .at(2) without boundary check)
Definition B2Vector3.h:447
B2Vector3(const B2Vector3< DataType > &b2Vec3)
Constructor expecting a B2Vector3 of same type.
Definition B2Vector3.h:67
DataType operator()(unsigned i) const
member access without boundary check
Definition B2Vector3.h:87
DataType Perp2() const
The transverse component squared (R^2 in cylindrical coordinate system).
Definition B2Vector3.h:198
void SetPerp(DataType r)
Set the transverse component keeping phi and z constant.
Definition B2Vector3.h:205
DataType y() const
access variable Y (= .at(1) without boundary check)
Definition B2Vector3.h:429
void SetX(DataType x)
set X/1st-coordinate
Definition B2Vector3.h:463
DataType Theta() const
The polar angle.
Definition B2Vector3.h:155
DataType CosTheta() const
Cosine of the polar angle.
Definition B2Vector3.h:157
B2Vector3< DataType > Cross(const B2Vector3< DataType > &p) const
Cross product.
Definition B2Vector3.h:298
DataType z() const
access variable Z (= .at(2) without boundary check)
Definition B2Vector3.h:431
B2Vector3(const B2Vector3< DataType > *b2Vec3)
Constructor expecting a pointer to a B2Vector3.
Definition B2Vector3.h:69
void SetMagThetaPhi(DataType mag, DataType theta, DataType phi)
setter with mag, theta, phi
Definition B2Vector3.h:261
std::string PrintStringXYZ(unsigned precision=4) const
create a string containing vector in cartesian coordinates
Definition B2Vector3.h:493
B2Vector3< DataType > Orthogonal() const
Vector orthogonal to this one.
Definition B2Vector3.h:279
DataType Eta() const
Returns the pseudo-rapidity.
Definition B2Vector3.h:333
B2Vector3< DataType > operator*(DataType a) const
Scaling of 3-vectors with a real number.
Definition B2Vector3.h:139
DataType DeltaPhi(const B2Vector3< DataType > &v) const
returns phi in the interval [-PI,PI)
Definition B2Vector3.h:230
void RotateY(DataType angle)
Rotates the B2Vector3 around the y-axis.
Definition B2Vector3.h:349
DataType operator[](unsigned i) const
member access without boundary check
Definition B2Vector3.h:89
std::string PrintString(unsigned precision=4) const
create a string containing vector in cartesian and spherical coordinates
Definition B2Vector3.h:487
DataType Mag() const
The magnitude (rho in spherical coordinate system).
Definition B2Vector3.h:161
DataType value_type
storage type of the vector
Definition B2Vector3.h:50
B2Vector3(const ROOT::Math::XYZVector &xyzVec)
Constructor expecting a XYZVector.
Definition B2Vector3.h:81
bool operator==(const B2Vector3< DataType > &b) const
Comparison for equality with a B2Vector3.
Definition B2Vector3.h:108
DataType x() const
access variable X (= .at(0) without boundary check)
Definition B2Vector3.h:427
B2Vector3(const DataType(*coords)[3])
Constructor using a pointer.
Definition B2Vector3.h:59
DataType DeltaR(const B2Vector3< DataType > &v) const
return deltaR with respect to input-vector
Definition B2Vector3.h:247
DataType Perp(const B2Vector3< DataType > &axis) const
The transverse component w.r.t.
Definition B2Vector3.h:228
DataType & operator()(unsigned i)
member access without boundary check
Definition B2Vector3.h:91
void RotateX(DataType angle)
Rotates the B2Vector3 around the x-axis.
Definition B2Vector3.h:337
void Abs()
calculates the absolute value of the coordinates element-wise
Definition B2Vector3.h:408
B2Vector3(const DataType(&coords)[3])
Constructor using a reference.
Definition B2Vector3.h:57
B2Vector3(const ROOT::Math::XYZVector *xyzVec)
Constructor expecting a pointer to a XYZVector.
Definition B2Vector3.h:84
DataType Pt(const B2Vector3< DataType > &axis) const
The transverse component w.r.t.
Definition B2Vector3.h:226
DataType Mag2() const
The magnitude squared (rho^2 in spherical coordinate system).
Definition B2Vector3.h:159
void SetTheta(DataType theta)
Set theta keeping mag and phi constant.
Definition B2Vector3.h:172
B2Vector3< DataType > operator+(const B2Vector3< DataType > &b) const
Addition of 3-vectors.
Definition B2Vector3.h:129
B2Vector3(const TVector3 &tVec3)
Constructor expecting a TVector3.
Definition B2Vector3.h:62
void RotateZ(DataType angle)
Rotates the B2Vector3 around the z-axis.
Definition B2Vector3.h:361
void Print()
just for backward compatibility, should not be used with new code
Definition B2Vector3.h:513
void Sqrt()
calculates the square root of the absolute values of the coordinates element-wise
Definition B2Vector3.h:416
void SetZ(DataType z)
set Z/3rd-coordinate
Definition B2Vector3.h:467
DataType Dot(const B2Vector3< DataType > &p) const
Scalar product.
Definition B2Vector3.h:292
void SetY(DataType y)
set Y/2nd-coordinate
Definition B2Vector3.h:465
B2Vector3(const B2Vector3< OtherType > *b2Vec3)
Constructor expecting a pointer to a B2Vector3 of different type.
Definition B2Vector3.h:77
DataType PseudoRapidity() const
Returns the pseudo-rapidity, i.e.
Definition B2Vector3.h:321
DataType DrEtaPhi(const B2Vector3< DataType > &v) const
return DrEtaPhi with respect to input-vector
Definition B2Vector3.h:255
bool operator!=(const B2Vector3< DataType > &b) const
Comparison != with a B2Vector3.
Definition B2Vector3.h:114
DataType Perp() const
The transverse component (R in cylindrical coordinate system).
Definition B2Vector3.h:202
B2Vector3(void)
empty Constructor sets everything to 0
Definition B2Vector3.h:53
DataType Perp2(const B2Vector3< DataType > &axis) const
The transverse component w.r.t.
Definition B2Vector3.h:215
B2Vector3(const B2Vector3< OtherType > &b2Vec3)
Constructor expecting a B2Vector3 of different type.
Definition B2Vector3.h:74
void RotateUz(const B2Vector3< DataType > &NewUzVector)
Rotates reference frame from Uz to newUz (unit vector).
Definition B2Vector3.h:372
DataType Py() const
access variable Y (= .at(1) without boundary check)
Definition B2Vector3.h:445
static DataType Mpi_pi(DataType angle)
returns given angle in the interval [-PI,PI)
Definition B2Vector3.h:234
B2Vector3< DataType > Unit() const
Unit vector parallel to this.
Definition B2Vector3.h:271
DataType Pt() const
The transverse component (R in cylindrical coordinate system).
Definition B2Vector3.h:200
B2Vector3(const TVector3 *tVec3)
Constructor expecting a pointer to a TVector3.
Definition B2Vector3.h:65
DataType Px() const
access variable X (= .at(0) without boundary check)
Definition B2Vector3.h:443
void SetXYZ(DataType x, DataType y, DataType z)
set all coordinates using data type
Definition B2Vector3.h:470
DataType Angle(const B2Vector3< DataType > &q) const
The angle w.r.t.
Definition B2Vector3.h:304
DataType & operator[](unsigned i)
member access without boundary check
Definition B2Vector3.h:93
std::string PrintStringCyl(unsigned precision=4) const
create a string containing vector in spherical coordinates
Definition B2Vector3.h:503
B2Vector3< DataType > operator/(DataType a) const
Scaling of 3-vectors with a real number.
Definition B2Vector3.h:144
void Rotate(DataType alpha, const B2Vector3< DataType > &v)
Rotation around an arbitrary axis v with angle alpha.
Definition B2Vector3.h:401
void SetPhi(DataType phi)
Set phi keeping mag and theta constant.
Definition B2Vector3.h:164
B2Vector3(const DataType xVal, const DataType yVal, const DataType zVal)
Constructor expecting 3 coordinates.
Definition B2Vector3.h:55
bool operator==(const DecayNode &node1, const DecayNode &node2)
Compare two Decay Nodes: They are equal if All daughter decay nodes are equal or one of the daughter ...
Definition DecayNode.cc:47
bool operator!=(const DecayNode &node1, const DecayNode &node2)
Not equal: See operator==.
Definition DecayNode.cc:64
void SetXYZ(const ROOT::Math::XYZVector *xyzVec)
set all coordinates using a pointer to XYZVector
Definition B2Vector3.h:695
void GetXYZ(ROOT::Math::XYZVector *xyzVec) const
directly copies coordinates to a XYZVector
Definition B2Vector3.h:729
void SetXYZ(const TVector3 &tVec)
set all coordinates using a reference to TVector3
Definition B2Vector3.h:668
B2Vector3< DataType > & operator-=(const B2Vector3< DataType > &b)
subtraction
Definition B2Vector3.h:648
void GetXYZ(Float_t *carray) const
directly copies coordinates to an array of float
Definition B2Vector3.h:711
TVector3 GetTVector3() const
returns a TVector3 containing the same coordinates
Definition B2Vector3.h:739
B2Vector3< float > B2Vector3F
typedef for common usage with float
Definition B2Vector3.h:525
void GetXYZ(TVector3 *tVec) const
directly copies coordinates to a TVector3
Definition B2Vector3.h:720
void SetXYZ(const TVector3 *tVec)
set all coordinates using a pointer to TVector3
Definition B2Vector3.h:677
ROOT::Math::XYZVector GetXYZVector() const
returns a XYZVector containing the same coordinates
Definition B2Vector3.h:752
B2Vector3< DataType > & operator+=(const B2Vector3< DataType > &b)
addition
Definition B2Vector3.h:637
B2Vector3< DataType > operator*(DataType a, const B2Vector3< DataType > &p)
non-memberfunction Scaling of 3-vectors with a real number
Definition B2Vector3.h:543
B2Vector3< DataType > operator-(const TVector3 &a, const B2Vector3< DataType > &b)
non-memberfunction for subtracting a TVector3 from a B2Vector3
Definition B2Vector3.h:557
B2Vector3< DataType > & operator*=(DataType a)
scaling with real numbers
Definition B2Vector3.h:658
void GetXYZ(Double_t *carray) const
directly copies coordinates to an array of double
Definition B2Vector3.h:703
B2Vector3< DataType > operator+(const TVector3 &a, const B2Vector3< DataType > &b)
non-memberfunction for adding a TVector3 to a B2Vector3
Definition B2Vector3.h:550
void SetXYZ(const ROOT::Math::XYZVector &xyzVec)
set all coordinates using a reference to XYZVector
Definition B2Vector3.h:686
B2Vector3< DataType > & operator=(const B2Vector3< DataType > &b)
Assignment via B2Vector3.
Definition B2Vector3.h:607
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition B2Vector3.h:522
DataType at(unsigned i) const
safe member access (with boundary check!)
Definition B2Vector3.h:765
static std::string name()
Returns the name of the B2Vector.
Definition B2Vector3.h:779
Abstract base class for different kinds of events.