Belle II Software  release-05-02-19
B2Vector3.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Jakob Lettenbichler *
7  * Eugenio Paoloni *
8  * Martin Ritter *
9  * *
10  * This software is provided "as is" without any warranty. *
11  **************************************************************************/
12 
13 #pragma once
14 
15 
16 #include <framework/logging/Logger.h>
17 
18 #include <TVector3.h>
19 #include <string>
20 #include <iostream> // std::cout, std::fixed
21 #include <iomanip> // std::setprecision
22 #include <typeinfo>
23 #include <cmath>
24 
25 
26 namespace Belle2 {
44  template<typename DataType>
45  class B2Vector3 {
46  protected:
48  static_assert(std::is_floating_point<DataType>::value, "B2Vector3 only works with floating point types");
50  DataType m_coordinates[3];
51  public:
53  typedef DataType value_type;
54 
56  B2Vector3(void) : m_coordinates {static_cast<DataType>(0), static_cast<DataType>(0), static_cast<DataType>(0)} {};
58  B2Vector3(const DataType xVal, const DataType yVal, const DataType zVal): m_coordinates {xVal, yVal, zVal} {};
60  explicit B2Vector3(const DataType(& coords)[3]): m_coordinates {coords[0], coords[1], coords[2]} {};
62  explicit B2Vector3(const DataType(* coords)[3]): m_coordinates {(*coords)[0], (*coords)[1], (*coords)[2]} {};
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  // cppcheck-suppress noExplicitConstructor
68  B2Vector3(const TVector3* tVec3): m_coordinates {static_cast<DataType>(tVec3->X()), static_cast<DataType>(tVec3->Y()), static_cast<DataType>(tVec3->Z())} {};
70  explicit B2Vector3(const B2Vector3<DataType>& b2Vec3): m_coordinates {b2Vec3.X(), b2Vec3.Y(), b2Vec3.Z()} {};
72  explicit B2Vector3(const B2Vector3<DataType>* b2Vec3): m_coordinates {b2Vec3->X(), b2Vec3->Y(), b2Vec3->Z()} {};
74  // cppcheck-suppress noExplicitConstructor
75  template <typename OtherType> B2Vector3(const B2Vector3<OtherType>& b2Vec3):
76  m_coordinates {static_cast<DataType>(b2Vec3.X()), static_cast<DataType>(b2Vec3.Y()), static_cast<DataType>(b2Vec3.Z())} {};
78  template <typename OtherType> explicit B2Vector3(const B2Vector3<OtherType>* b2Vec3):
79  m_coordinates {static_cast<DataType>(b2Vec3->X()), static_cast<DataType>(b2Vec3->Y()), static_cast<DataType>(b2Vec3->Z())} {};
80 
82  DataType operator()(unsigned i) const { return m_coordinates[i]; }
84  DataType operator[](unsigned i) const { return m_coordinates[i]; }
86  DataType& operator()(unsigned i) { return m_coordinates[i]; }
88  DataType& operator[](unsigned i) { return m_coordinates[i]; }
89 
93  B2Vector3<DataType>& operator = (const TVector3& b);
94 
96  operator TVector3() const { return GetTVector3(); }
97 
99  bool operator == (const B2Vector3<DataType>& b) const { return X() == b.X() && Y() == b.Y() && Z() == b.Z(); }
101  bool operator == (const TVector3& b) const { return X() == b.X() && Y() == b.Y() && Z() == b.Z(); }
103  bool operator != (const B2Vector3<DataType>& b) const { return !(*this == b); }
105  bool operator != (const TVector3& b) const { return !(*this == b); }
106 
112  B2Vector3<DataType>& operator *= (DataType a);
114  B2Vector3<DataType> operator - () const { return B2Vector3<DataType>(-X(), -Y(), -Z()); }
117  {
118  return B2Vector3<DataType>(X() + b.X(), Y() + b.Y(), Z() + b.Z());
119  }
121  B2Vector3<DataType> operator - (const B2Vector3<DataType>& b) const
122  {
123  return B2Vector3<DataType>(X() - b.X(), Y() - b.Y(), Z() - b.Z());
124  }
127  {
128  return B2Vector3<DataType>(a * X(), a * Y(), a * Z());
129  }
132  {
133  return B2Vector3<DataType>(X() / a, Y() / a, Z() / a);
134  }
136  DataType operator * (const B2Vector3<DataType>& b) const { return Dot(b); }
137 
138 
140  DataType Phi() const { return X() == 0 && Y() == 0 ? 0 : atan2(Y(), X()); }
142  DataType Theta() const { return X() == 0 && Y() == 0 && Z() == 0 ? 0 : atan2(Perp(), Z()); }
144  DataType CosTheta() const { const double pTot = Mag(); return pTot == 0 ? 1 : Z() / pTot; }
146  DataType Mag2() const { return X() * X() + Y() * Y() + Z() * Z(); }
148  DataType Mag() const { return std::hypot((double)Perp(), (double)Z()); }
149 
151  void SetPhi(DataType phi)
152  {
153  const double perp = Perp();
154  SetX(perp * cos((double)phi));
155  SetY(perp * sin((double)phi));
156  }
157 
159  void SetTheta(DataType theta)
160  {
161  const double ma = Mag();
162  const double ph = Phi();
163  const double ctheta = std::cos((double) theta);
164  const double stheta = std::sin((double) theta);
165  SetX(ma * stheta * std::cos(ph));
166  SetY(ma * stheta * std::cos(ph));
167  SetZ(ma * ctheta);
168  }
169 
171  void SetMag(DataType mag)
172  {
173  double factor = Mag();
174  if (factor == 0) {
175  B2WARNING(name() << "::SetMag: zero vector can't be stretched");
176  } else {
177  factor = mag / factor;
178  SetX(X()*factor);
179  SetY(Y()*factor);
180  SetZ(Z()*factor);
181  }
182  }
183 
185  DataType Perp2() const { return X() * X() + Y() * Y(); }
187  DataType Pt() const { return Perp(); }
189  DataType Perp() const { return std::hypot((double)X(), (double)Y()); }
190 
192  void SetPerp(DataType r)
193  {
194  const double p = Perp();
195  if (p != 0.0) {
196  m_coordinates[0] *= r / p;
197  m_coordinates[1] *= r / p;
198  }
199  }
200 
202  DataType Perp2(const B2Vector3<DataType>& axis) const
203  {
204  const double tot = axis.Mag2();
205  const double ss = Dot(axis);
206  double per = Mag2();
207  if (tot > 0.0) per -= ss * ss / tot;
208  if (per < 0) per = 0;
209  return per;
210  }
211 
213  DataType Pt(const B2Vector3<DataType>& axis) const { return Perp(axis); }
215  DataType Perp(const B2Vector3<DataType>& axis) const { return std::sqrt(Perp2(axis)); }
217  DataType DeltaPhi(const B2Vector3<DataType>& v) const { return Mpi_pi(Phi() - v.Phi()); }
218 
219 
221  static DataType Mpi_pi(DataType angle)
222  {
223  if (std::isnan(angle)) {
224  B2ERROR(name() << "::Mpi_pi: function called with NaN");
225  return angle;
226  }
227  angle = std::remainder(angle, 2 * M_PI);
228  //for compatibility with ROOT we flip the sign for exactly pi
229  if (angle == M_PI) angle = -M_PI;
230  return angle;
231  }
232 
234  DataType DeltaR(const B2Vector3<DataType>& v) const
235  {
236  const double deta = Eta() - v.Eta();
237  const double dphi = DeltaPhi(v);
238  return std::hypot(deta, dphi);
239  }
240 
242  DataType DrEtaPhi(const B2Vector3<DataType>& v) const
243  {
244  return DeltaR(v);
245  }
246 
248  void SetMagThetaPhi(DataType mag, DataType theta, DataType phi)
249  {
250  const double amag = std::abs(mag);
251  const double sinTheta = std::sin((double)theta);
252  m_coordinates[0] = amag * sinTheta * std::cos((double)phi);
253  m_coordinates[1] = amag * sinTheta * std::sin((double)phi);
254  m_coordinates[2] = amag * std::cos((double)theta);
255  }
256 
259  {
260  const double tot = Mag2();
261  B2Vector3<DataType> p(X(), Y(), Z());
262  return tot > 0.0 ? p *= (1.0 / std::sqrt(tot)) : p;
263  }
264 
267  {
268  const double xVal = std::abs((double)X());
269  const double yVal = std::abs((double)Y());
270  const double zVal = std::abs((double)Z());
271  if (xVal < yVal) {
272  return xVal < zVal ? B2Vector3<DataType>(0, Z(), -Y()) : B2Vector3<DataType>(Y(), -X(), 0);
273  } else {
274  return yVal < zVal ? B2Vector3<DataType>(-Z(), 0, X()) : B2Vector3<DataType>(Y(), -X(), 0);
275  }
276  }
277 
279  DataType Dot(const B2Vector3<DataType>& p) const
280  {
281  return X() * p.X() + Y() * p.Y() + Z() * p.Z();
282  }
283 
285  B2Vector3<DataType> Cross(const B2Vector3<DataType>& p) const
286  {
287  return B2Vector3<DataType>(Y() * p.Z() - p.Y() * Z(), Z() * p.X() - p.Z() * X(), X() * p.Y() - p.X() * Y());
288  }
289 
291  DataType Angle(const B2Vector3<DataType>& q) const
292  {
293  const double ptot2 = Mag2() * q.Mag2();
294  if (ptot2 <= 0) {
295  return 0.0;
296  } else {
297  double arg = Dot(q) / std::sqrt(ptot2);
298  if (arg > 1.0) arg = 1.0;
299  if (arg < -1.0) arg = -1.0;
300  return std::acos(arg);
301  }
302  }
303 
308  DataType PseudoRapidity() const
309  {
310  const double cosTheta = CosTheta();
311  if (std::abs(cosTheta) < 1) return -0.5 * std::log((1.0 - cosTheta) / (1.0 + cosTheta));
312  if (Z() == 0) return 0;
313  //B2WARNING(name() << "::PseudoRapidity: transverse momentum = 0! return +/- 10e10");
314  if (Z() > 0) return 10e10;
315  else return -10e10;
316  }
317 
318 
320  DataType Eta() const { return PseudoRapidity(); }
321 
322 
324  void RotateX(DataType angle)
325  {
326  //rotate vector around X
327  const double s = std::sin((double)angle);
328  const double c = std::cos((double)angle);
329  const double yOld = Y();
330  m_coordinates[1] = c * yOld - s * Z();
331  m_coordinates[2] = s * yOld + c * Z();
332  }
333 
334 
336  void RotateY(DataType angle)
337  {
338  //rotate vector around Y
339  const double s = std::sin((double)angle);
340  const double c = std::cos((double)angle);
341  const double zOld = Z();
342  m_coordinates[0] = s * zOld + c * X();
343  m_coordinates[2] = c * zOld - s * X();
344  }
345 
346 
348  void RotateZ(DataType angle)
349  {
350  //rotate vector around Z
351  const double s = std::sin((double)angle);
352  const double c = std::cos((double)angle);
353  const double xOld = X();
354  m_coordinates[0] = c * xOld - s * Y();
355  m_coordinates[1] = s * xOld + c * Y();
356  }
357 
359  void RotateUz(const B2Vector3<DataType>& NewUzVector)
360  {
361  // NewUzVector must be normalized !
362 
363  const double u1 = NewUzVector.X();
364  const double u2 = NewUzVector.Y();
365  const double u3 = NewUzVector.Z();
366  double up = u1 * u1 + u2 * u2;
367 
368  if (up) {
369  up = std::sqrt(up);
370  DataType px = X(), py = Y(), pz = Z();
371  m_coordinates[0] = (u1 * u3 * px - u2 * py + u1 * up * pz) / up;
372  m_coordinates[1] = (u2 * u3 * px + u1 * py + u2 * up * pz) / up;
373  m_coordinates[2] = (u3 * u3 * px - px + u3 * up * pz) / up;
374  } else if (u3 < 0.) {
375  m_coordinates[0] = -m_coordinates[0];
376  m_coordinates[2] = -m_coordinates[2];
377  }
378  }
379 
388  void Rotate(DataType alpha, const B2Vector3<DataType>& v)
389  {
390  B2Vector3<DataType> n = v.Unit();
391  *this = (n * (n.Dot(*this)) + cos(alpha) * ((n.Cross(*this)).Cross(n)) + sin(alpha) * (n.Cross(*this)));
392  }
393 
395  void Abs()
396  {
397  m_coordinates[0] = std::abs(m_coordinates[0]);
398  m_coordinates[1] = std::abs(m_coordinates[1]);
399  m_coordinates[2] = std::abs(m_coordinates[2]);
400  }
401 
403  void Sqrt()
404  {
405  Abs();
406  m_coordinates[0] = std::sqrt(m_coordinates[0]);
407  m_coordinates[1] = std::sqrt(m_coordinates[1]);
408  m_coordinates[2] = std::sqrt(m_coordinates[2]);
409  }
410 
412  DataType at(unsigned i) const;
414  DataType x() const { return m_coordinates[0]; }
416  DataType y() const { return m_coordinates[1]; }
418  DataType z() const { return m_coordinates[2]; }
420  DataType X() const { return x(); }
422  DataType Y() const { return y(); }
424  DataType Z() const { return z(); }
426  DataType Px() const { return x(); }
428  DataType Py() const { return y(); }
430  DataType Pz() const { return z(); }
431 
433  void GetXYZ(Double_t* carray) const;
435  void GetXYZ(Float_t* carray) const;
437  void GetXYZ(TVector3* tVec) const;
439  TVector3 GetTVector3() const;
440 
442  void SetX(DataType x) { m_coordinates[0] = x; }
444  void SetY(DataType y) { m_coordinates[1] = y; }
446  void SetZ(DataType z) { m_coordinates[2] = z; }
447 
449  void SetXYZ(DataType x, DataType y, DataType z)
450  {
451  SetX(x); SetY(y); SetZ(z);
452  }
454  void SetXYZ(const TVector3& tVec);
456  void SetXYZ(const TVector3* tVec);
457 
459  static std::string name();
460 
462  std::string PrintString(unsigned precision = 4) const
463  {
464  return name() + " " + PrintStringXYZ(precision) + " " + PrintStringCyl(precision);
465  }
466 
468  std::string PrintStringXYZ(unsigned precision = 4) const
469  {
470  std::ostringstream output;
471  output << "(x,y,z)=("
472  << std::fixed << std::setprecision(precision)
473  << X() << "," << Y() << "," << Z() << ")";
474  return output.str();
475  }
476 
478  std::string PrintStringCyl(unsigned precision = 4) const
479  {
480  std::ostringstream output;
481  output << "(rho, theta, phi)=("
482  << std::fixed << std::setprecision(precision)
483  << Mag() << "," << Theta() * 180. / M_PI << "," << Phi() * 180. / M_PI << ")";
484  return output.str();
485  }
486 
488  void Print()
489  {
490  //print vector parameters
491  Print(PrintString().c_str());
492  }
493 
494  };
495 
497  typedef B2Vector3<double> B2Vector3D;
498 
501 
503  template <typename DataType>
504  Bool_t operator == (const TVector3& a, const B2Vector3<DataType>& b)
505  {
506  return (a.X() == b.X() && a.Y() == b.Y() && a.Z() == b.Z());
507  }
508 
510  template < typename DataType>
511  Bool_t operator != (const TVector3& a, const B2Vector3<DataType>& b)
512  {
513  return !(a == b);
514  }
515 
517  template < typename DataType>
518  B2Vector3<DataType> operator * (DataType a, const B2Vector3<DataType>& p)
519  {
520  return B2Vector3<DataType>(a * p.X(), a * p.Y(), a * p.Z());
521  }
522 
524  template < typename DataType>
525  B2Vector3<DataType> operator + (const TVector3& a, const B2Vector3<DataType>& b)
526  {
527  return B2Vector3<DataType>(a.X() + b.X(), a.Y() + b.Y(), a.Z() + b.Z());
528  }
529 
531  template < typename DataType>
532  B2Vector3<DataType> operator - (const TVector3& a, const B2Vector3<DataType>& b)
533  {
534  return B2Vector3<DataType>(a.X() - b.X(), a.Y() - b.Y(), a.Z() - b.Z());
535  }
536 
538  template < typename DataType>
539  B2Vector3<DataType> operator + (const B2Vector3<DataType>& a, const TVector3& b)
540  {
541  return B2Vector3<DataType>(a.X() + b.X(), a.Y() + b.Y(), a.Z() + b.Z());
542  }
543 
545  template < typename DataType>
546  B2Vector3<DataType> operator - (const B2Vector3<DataType>& a, const TVector3& b)
547  {
548  return B2Vector3<DataType>(a.X() - b.X(), a.Y() - b.Y(), a.Z() - b.Z());
549  }
550 
551 
553  template< typename DataType >
554  B2Vector3<DataType>& B2Vector3<DataType>::operator = (const B2Vector3<DataType>& b)
555  {
556  m_coordinates[0] = b.X();
557  m_coordinates[1] = b.Y();
558  m_coordinates[2] = b.Z();
559  return *this;
560  }
561 
563  template< typename DataType >
565  {
566  m_coordinates[0] = b.X();
567  m_coordinates[1] = b.Y();
568  m_coordinates[2] = b.Z();
569  return *this;
570  }
571 
573  template< typename DataType >
575  {
576  m_coordinates[0] += b.X();
577  m_coordinates[1] += b.Y();
578  m_coordinates[2] += b.Z();
579  return *this;
580  }
581 
582 
584  template< typename DataType >
586  {
587  m_coordinates[0] -= b.X();
588  m_coordinates[1] -= b.Y();
589  m_coordinates[2] -= b.Z();
590  return *this;
591  }
592 
594  template< typename DataType >
596  {
597  m_coordinates[0] *= a;
598  m_coordinates[1] *= a;
599  m_coordinates[2] *= a;
600  return *this;
601  }
602 
604  template< typename DataType >
605  void B2Vector3<DataType>::SetXYZ(const TVector3& tVec)
606  {
607  m_coordinates[0] = static_cast<Double_t>(tVec.X());
608  m_coordinates[1] = static_cast<Double_t>(tVec.Y());
609  m_coordinates[2] = static_cast<Double_t>(tVec.Z());
610  }
611 
613  template< typename DataType >
614  void B2Vector3<DataType>::SetXYZ(const TVector3* tVec)
615  {
616  m_coordinates[0] = static_cast<Double_t>(tVec->X());
617  m_coordinates[1] = static_cast<Double_t>(tVec->Y());
618  m_coordinates[2] = static_cast<Double_t>(tVec->Z());
619  }
620 
621  template< typename DataType >
622  void B2Vector3<DataType>::GetXYZ(double* carray) const
623  {
624  carray[0] = X();
625  carray[1] = Y();
626  carray[2] = Z();
627  }
628 
630  template< typename DataType >
631  void B2Vector3<DataType>::GetXYZ(TVector3* tVec) const
632  {
633  tVec->SetXYZ(static_cast<Double_t>(X()),
634  static_cast<Double_t>(Y()),
635  static_cast<Double_t>(Z()));
636  }
637 
638 
640  template< typename DataType >
642  {
643  return
644  TVector3(
645  static_cast<Double_t>(X()),
646  static_cast<Double_t>(Y()),
647  static_cast<Double_t>(Z())
648  );
649  }
650 
651 
653  template < typename DataType>
654  DataType B2Vector3<DataType>::at(unsigned i) const
655  {
656  switch (i) {
657  case 0:
659  case 1:
661  case 2:
663  }
664  B2FATAL(this->name() << "::access operator: given index (i=" << i << ") is out of bounds!");
665  return 0.;
666  }
667 
669  template < typename DataType>
670  std::string B2Vector3<DataType>::name()
671  {
672  return std::string("B2Vector3<") + typeid(DataType).name() + std::string(">");
673  }
674 
676 } // end namespace Belle2
Belle2::B2Vector3::PrintStringCyl
std::string PrintStringCyl(unsigned precision=4) const
create a string containing vector in spherical coordinates
Definition: B2Vector3.h:488
Belle2::B2Vector3::value_type
DataType value_type
storage type of the vector
Definition: B2Vector3.h:63
Belle2::B2Vector3::operator[]
DataType operator[](unsigned i) const
member access without boundary check
Definition: B2Vector3.h:94
Belle2::B2Vector3::operator/
B2Vector3< DataType > operator/(DataType a) const
Scaling of 3-vectors with a real number.
Definition: B2Vector3.h:141
Belle2::B2Vector3::operator-=
B2Vector3< DataType > & operator-=(const B2Vector3< DataType > &b)
subtraction
Definition: B2Vector3.h:595
Belle2::B2Vector3::Py
DataType Py() const
access variable Y (= .at(1) without boundary check)
Definition: B2Vector3.h:438
Belle2::B2Vector3::Unit
B2Vector3< DataType > Unit() const
Unit vector parallel to this.
Definition: B2Vector3.h:268
Belle2::B2Vector3::Perp
DataType Perp() const
The transverse component (R in cylindrical coordinate system).
Definition: B2Vector3.h:199
Belle2::B2Vector3::name
static std::string name()
Returns the name of the B2Vector.
Definition: B2Vector3.h:680
Belle2::B2Vector3::B2Vector3
B2Vector3(const DataType xVal, const DataType yVal, const DataType zVal)
Constructor expecting 3 coordinates.
Definition: B2Vector3.h:68
Belle2::B2Vector3::SetMag
void SetMag(DataType mag)
Set magnitude keeping theta and phi constant.
Definition: B2Vector3.h:181
Belle2::B2Vector3::operator!=
bool operator!=(const B2Vector3< DataType > &b) const
Comparison != with a B2Vector3.
Definition: B2Vector3.h:113
Belle2::B2Vector3::Rotate
void Rotate(DataType alpha, const B2Vector3< DataType > &v)
Rotation around an arbitrary axis v with angle alpha.
Definition: B2Vector3.h:398
Belle2::B2Vector3::SetPhi
void SetPhi(DataType phi)
Set phi keeping mag and theta constant.
Definition: B2Vector3.h:161
Belle2::B2Vector3::operator=
B2Vector3< DataType > & operator=(const B2Vector3< DataType > &b)
Assignment via B2Vector3.
Definition: B2Vector3.h:564
Belle2::operator==
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:50
Belle2::B2Vector3::Eta
DataType Eta() const
Returns the pseudo-rapidity.
Definition: B2Vector3.h:330
Belle2::B2Vector3::PrintStringXYZ
std::string PrintStringXYZ(unsigned precision=4) const
create a string containing vector in cartesian coordinates
Definition: B2Vector3.h:478
Belle2::operator!=
bool operator!=(const DecayNode &node1, const DecayNode &node2)
Not equal: See operator==.
Definition: DecayNode.cc:67
Belle2::B2Vector3::x
DataType x() const
access variable X (= .at(0) without boundary check)
Definition: B2Vector3.h:424
Belle2::B2Vector3::DeltaPhi
DataType DeltaPhi(const B2Vector3< DataType > &v) const
returns phi in the interval [-PI,PI)
Definition: B2Vector3.h:227
Belle2::B2Vector3::Angle
DataType Angle(const B2Vector3< DataType > &q) const
The angle w.r.t.
Definition: B2Vector3.h:301
Belle2::B2Vector3::operator+
B2Vector3< DataType > operator+(const B2Vector3< DataType > &b) const
Addition of 3-vectors.
Definition: B2Vector3.h:126
Belle2::B2Vector3::B2Vector3
B2Vector3(const TVector3 *tVec3)
Constructor expecting a pointer to a TVector3.
Definition: B2Vector3.h:78
Belle2::B2Vector3::PrintString
std::string PrintString(unsigned precision=4) const
create a string containing vector in cartesian and spherical coordinates
Definition: B2Vector3.h:472
Belle2::B2Vector3::operator+=
B2Vector3< DataType > & operator+=(const B2Vector3< DataType > &b)
addition
Definition: B2Vector3.h:584
Belle2::B2Vector3::operator*=
B2Vector3< DataType > & operator*=(DataType a)
scaling with real numbers
Definition: B2Vector3.h:605
Belle2::B2Vector3::Orthogonal
B2Vector3< DataType > Orthogonal() const
Vector orthogonal to this one.
Definition: B2Vector3.h:276
Belle2::B2Vector3::Pz
DataType Pz() const
access variable Z (= .at(2) without boundary check)
Definition: B2Vector3.h:440
Belle2::B2Vector3::Cross
B2Vector3< DataType > Cross(const B2Vector3< DataType > &p) const
Cross product.
Definition: B2Vector3.h:295
Belle2::B2Vector3::GetXYZ
void GetXYZ(Double_t *carray) const
directly copies coordinates to an array of double
Belle2::B2Vector3::DeltaR
DataType DeltaR(const B2Vector3< DataType > &v) const
return deltaR with respect to input-vector
Definition: B2Vector3.h:244
Belle2::B2Vector3::Z
DataType Z() const
access variable Z (= .at(2) without boundary check)
Definition: B2Vector3.h:434
Belle2::operator*
B2Vector3< DataType > operator*(DataType a, const B2Vector3< DataType > &p)
non-memberfunction Scaling of 3-vectors with a real number
Definition: B2Vector3.h:528
Belle2::B2Vector3::SetY
void SetY(DataType y)
set Y/2nd-coordinate
Definition: B2Vector3.h:454
Belle2::B2Vector3::RotateUz
void RotateUz(const B2Vector3< DataType > &NewUzVector)
Rotates reference frame from Uz to newUz (unit vector).
Definition: B2Vector3.h:369
Belle2::B2Vector3
A fast and root compatible alternative to TVector3.
Definition: B2Vector3.h:55
Belle2::B2Vector3::operator()
DataType operator()(unsigned i) const
member access without boundary check
Definition: B2Vector3.h:92
Belle2::B2Vector3::operator*
B2Vector3< DataType > operator*(DataType a) const
Scaling of 3-vectors with a real number.
Definition: B2Vector3.h:136
Belle2::B2Vector3::Dot
DataType Dot(const B2Vector3< DataType > &p) const
Scalar product.
Definition: B2Vector3.h:289
Belle2::B2Vector3::Print
void Print()
just for backward compatibility, should not be used with new code
Definition: B2Vector3.h:498
Belle2::B2Vector3::Phi
DataType Phi() const
The azimuth angle.
Definition: B2Vector3.h:150
Belle2::B2Vector3::SetTheta
void SetTheta(DataType theta)
Set theta keeping mag and phi constant.
Definition: B2Vector3.h:169
Belle2::B2Vector3D
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition: B2Vector3.h:507
Belle2::B2Vector3::B2Vector3
B2Vector3(const DataType(*coords)[3])
Constructor using a pointer.
Definition: B2Vector3.h:72
Belle2::B2Vector3::PseudoRapidity
DataType PseudoRapidity() const
Returns the pseudo-rapidity, i.e.
Definition: B2Vector3.h:318
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::B2Vector3::B2Vector3
B2Vector3(void)
empty Constructor sets everything to 0
Definition: B2Vector3.h:66
Belle2::operator-
B2Vector3< DataType > operator-(const TVector3 &a, const B2Vector3< DataType > &b)
non-memberfunction for substracting a TVector3 from a B2Vector3
Definition: B2Vector3.h:542
Belle2::operator+
B2Vector3< DataType > operator+(const TVector3 &a, const B2Vector3< DataType > &b)
non-memberfunction for adding a TVector3 to a B2Vector3
Definition: B2Vector3.h:535
Belle2::B2Vector3::Sqrt
void Sqrt()
calculates the square root of the absolute values of the coordinates element-wise
Definition: B2Vector3.h:413
Belle2::B2Vector3::SetPerp
void SetPerp(DataType r)
Set the transverse component keeping phi and z constant.
Definition: B2Vector3.h:202
Belle2::B2Vector3::GetTVector3
TVector3 GetTVector3() const
returns a TVector3 containing the same coordinates
Definition: B2Vector3.h:651
Belle2::B2Vector3::RotateX
void RotateX(DataType angle)
Rotates the B2Vector3 around the x-axis.
Definition: B2Vector3.h:334
Belle2::B2Vector3::y
DataType y() const
access variable Y (= .at(1) without boundary check)
Definition: B2Vector3.h:426
Belle2::B2Vector3::SetMagThetaPhi
void SetMagThetaPhi(DataType mag, DataType theta, DataType phi)
setter with mag, theta, phi
Definition: B2Vector3.h:258
Belle2::B2Vector3::operator-
B2Vector3< DataType > operator-() const
unary minus
Definition: B2Vector3.h:124
Belle2::B2Vector3::Mpi_pi
static DataType Mpi_pi(DataType angle)
returns given angle in the interval [-PI,PI)
Definition: B2Vector3.h:231
Belle2::B2Vector3::Px
DataType Px() const
access variable X (= .at(0) without boundary check)
Definition: B2Vector3.h:436
Belle2::B2Vector3::CosTheta
DataType CosTheta() const
Cosine of the polar angle.
Definition: B2Vector3.h:154
Belle2::B2Vector3::Perp2
DataType Perp2() const
The transverse component squared (R^2 in cylindrical coordinate system).
Definition: B2Vector3.h:195
Belle2::B2Vector3::z
DataType z() const
access variable Z (= .at(2) without boundary check)
Definition: B2Vector3.h:428
Belle2::B2Vector3::Mag2
DataType Mag2() const
The magnitude squared (rho^2 in spherical coordinate system).
Definition: B2Vector3.h:156
Belle2::B2Vector3::B2Vector3
B2Vector3(const DataType(&coords)[3])
Constructor using a reference.
Definition: B2Vector3.h:70
Belle2::B2Vector3::DrEtaPhi
DataType DrEtaPhi(const B2Vector3< DataType > &v) const
return DrEtaPhi with respect to input-vector
Definition: B2Vector3.h:252
Belle2::B2Vector3::RotateZ
void RotateZ(DataType angle)
Rotates the B2Vector3 around the z-axis.
Definition: B2Vector3.h:358
Belle2::B2Vector3::RotateY
void RotateY(DataType angle)
Rotates the B2Vector3 around the y-axis.
Definition: B2Vector3.h:346
Belle2::B2Vector3::at
DataType at(unsigned i) const
safe member access (with boundary check!)
Definition: B2Vector3.h:664
Belle2::B2Vector3::B2Vector3
B2Vector3(const TVector3 &tVec3)
Constructor expecting a TVector3.
Definition: B2Vector3.h:75
Belle2::B2Vector3::X
DataType X() const
access variable X (= .at(0) without boundary check)
Definition: B2Vector3.h:430
Belle2::B2Vector3F
B2Vector3< float > B2Vector3F
typedef for common usage with float
Definition: B2Vector3.h:510
Belle2::B2Vector3::operator==
bool operator==(const B2Vector3< DataType > &b) const
Comparison for equality with a B2Vector3.
Definition: B2Vector3.h:109
Belle2::B2Vector3::SetXYZ
void SetXYZ(DataType x, DataType y, DataType z)
set all coordinates using data type
Definition: B2Vector3.h:459
Belle2::B2Vector3::Pt
DataType Pt() const
The transverse component (R in cylindrical coordinate system).
Definition: B2Vector3.h:197
Belle2::B2Vector3::Theta
DataType Theta() const
The polar angle.
Definition: B2Vector3.h:152
Belle2::B2Vector3::Abs
void Abs()
calculates the absolute value of the coordinates element-wise
Definition: B2Vector3.h:405
Belle2::B2Vector3::Mag
DataType Mag() const
The magnitude (rho in spherical coordinate system).
Definition: B2Vector3.h:158
Belle2::B2Vector3::m_coordinates
DataType m_coordinates[3]
Make sure that we only have floating point vectors.
Definition: B2Vector3.h:58
Belle2::B2Vector3::SetZ
void SetZ(DataType z)
set Z/3rd-coordinate
Definition: B2Vector3.h:456
Belle2::B2Vector3::Y
DataType Y() const
access variable Y (= .at(1) without boundary check)
Definition: B2Vector3.h:432
Belle2::B2Vector3::SetX
void SetX(DataType x)
set X/1st-coordinate
Definition: B2Vector3.h:452