Belle II Software light-2406-ragdoll
VectorUtil.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/* ROOT headers. */
12#include <Math/Vector3D.h>
13#include <TVector3.h>
14
15namespace Belle2 {
24 static constexpr auto XYZToTVector = [](const ROOT::Math::XYZVector& a)
25 {
26 return TVector3(a.X(), a.Y(), a.Z());
27 };
28
29 namespace VectorUtil {
30
38 inline void setMagThetaPhi(ROOT::Math::XYZVector& vector,
39 double mag, double theta, double phi)
40 {
41 const double amag = std::abs(mag);
42 const double sinTheta = std::sin(theta);
43 const double x = amag * sinTheta * std::cos(phi);
44 const double y = amag * sinTheta * std::sin(phi);
45 const double z = amag * std::cos(theta);
46 vector.SetXYZ(x, y, z);
47 }
48
54 inline void setMag(ROOT::Math::XYZVector& vector, double mag)
55 {
56 setMagThetaPhi(vector, mag, vector.Theta(), vector.Phi());
57 }
58
64 inline void setTheta(ROOT::Math::XYZVector& vector, double theta)
65 {
66 setMagThetaPhi(vector, vector.R(), theta, vector.Phi());
67 }
68
74 inline void setPhi(ROOT::Math::XYZVector& vector, double phi)
75 {
76 setMagThetaPhi(vector, vector.R(), vector.Theta(), phi);
77 }
78
86 inline void setPtThetaPhi(ROOT::Math::XYZVector& vector,
87 double pt, double theta, double phi)
88 {
89 const double aPt = std::abs(pt);
90 const double x = aPt * std::cos(phi);
91 const double y = aPt * std::sin(phi);
92 const double tanTheta = std::tan(theta);
93 const double z = tanTheta ? aPt / tanTheta : 0;
94 vector.SetXYZ(x, y, z);
95 }
96
97 }
98
100}
static constexpr auto XYZToTVector
Helper function to convert XYZVector to TVector3.
Definition: VectorUtil.h:24
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24