23#include "TRestPhysics.h"
58TVector3
MoveToPlane(
const TVector3& pos,
const TVector3& dir,
const TVector3& n,
const TVector3& a) {
60 Double_t t = (n * a - n * pos) / (n * dir);
71Double_t
DistanceToAxis(
const TVector3& axisPoint,
const TVector3& axisVector,
const TVector3& point) {
72 TVector3 a = axisVector.Cross(axisPoint - point);
73 return a.Mag() / axisVector.Mag();
95 const Double_t R3,
const Double_t lMirr) {
96 Double_t e = 2 * R3 * TMath::Tan(alpha);
97 Double_t a = dir.X() * dir.X() + dir.Y() * dir.Y();
98 Double_t b = 2 * (pos.X() * dir.X() + pos.Y() * dir.Y()) + e * dir.Z();
99 Double_t half_b = b / 2;
100 Double_t c = pos.X() * pos.X() + pos.Y() * pos.Y() - R3 * R3 + e * pos.Z();
102 Double_t root1 = (-half_b - TMath::Sqrt(half_b * half_b - a * c)) / a;
103 Double_t root2 = (-half_b + TMath::Sqrt(half_b * half_b - a * c)) / a;
104 if (pos.Z() + root1 * dir.Z() > -lMirr and pos.Z() + root1 * dir.Z() < 0) {
105 return pos + root1 * dir;
106 }
else if (pos.Z() + root2 * dir.Z() > -lMirr and pos.Z() + root2 * dir.Z() < 0) {
107 return pos + root2 * dir;
111 return pos - c / b * dir;
123 const Double_t R3,
const Double_t lMirr,
const Double_t focal) {
124 Double_t beta = 3 * alpha;
125 Double_t e = 2 * R3 * TMath::Tan(beta);
127 Double_t g = 2 * R3 * TMath::Tan(beta) / (focal + R3 / TMath::Tan(2 * alpha));
128 Double_t a = dir.X() * dir.X() + dir.Y() * dir.Y() - g * dir.Z() * dir.Z();
129 Double_t b = 2 * (pos.X() * dir.X() + pos.Y() * dir.Y() - g * dir.Z() * pos.Z()) + e * dir.Z();
130 Double_t half_b = b / 2;
131 Double_t c = pos.X() * pos.X() + pos.Y() * pos.Y() - R3 * R3 + e * pos.Z() - g * pos.Z() * pos.Z();
132 Double_t root1 = (-half_b - TMath::Sqrt(half_b * half_b - a * c)) / a;
133 Double_t root2 = (-half_b + TMath::Sqrt(half_b * half_b - a * c)) / a;
134 if (pos.Z() + root1 * dir.Z() > 0 and pos.Z() + root1 * dir.Z() < lMirr) {
135 return pos + root1 * dir;
136 }
else if (pos.Z() + root2 * dir.Z() > 0 and pos.Z() + root2 * dir.Z() < lMirr) {
137 return pos + root2 * dir;
151 TVectorD coneAxis(3, cAxis);
154 M.Rank1Update(coneAxis, coneAxis);
156 double cT2 = cosTheta * cosTheta;
157 TMatrixD gamma(3, 3);
174Double_t
GetVectorsAngle(
const TVector3& v1,
const TVector3& v2) {
return TMath::ACos(v1.Dot(v2)); }
186TVector3
GetConeNormal(
const TVector3& pos,
const Double_t alpha,
const Double_t R) {
189 r = TMath::Sqrt(pos.X() * pos.X() + pos.Y() * pos.Y());
193 Double_t cosA = TMath::Cos(alpha);
194 Double_t sinA = TMath::Sin(alpha);
196 return -TVector3(cosA * pos.X() / r, cosA * pos.Y() / r, sinA);
206 TVector3 normalVec = pos;
208 1 / (R3 * TMath::Tan(alpha) / TMath::Sqrt(R3 * R3 + R3 * 2 * TMath::Tan(alpha) * (-pos.Z())));
209 Double_t n = TMath::Sqrt(pos.X() * pos.X() + pos.Y() * pos.Y()) - m * pos.Z();
210 normalVec.SetZ(pos.Z() - (-n / m));
211 return normalVec.Unit();
221 const Double_t focal) {
222 TVector3 normalVec = pos;
223 Double_t beta = 3 * alpha;
225 Double_t m = 1 / (R3 * TMath::Tan(beta) * (1 - 2 * pos.Z() / (focal + R3 / TMath::Tan(2 * alpha))) /
226 TMath::Sqrt(R3 * R3 - R3 * 2 * TMath::Tan(beta) * pos.Z() *
227 (1.0 - pos.Z() / (focal + R3 / TMath::Tan(2 * alpha)))));
228 Double_t n = TMath::Sqrt(pos.X() * pos.X() + pos.Y() * pos.Y()) - m * pos.Z();
229 normalVec.SetZ(pos.Z() - (-n / m));
230 return normalVec.Unit();
246 const TVector3& v,
const Double_t cosTheta) {
265 const TVector3& axis,
const TVector3& v) {
269 TMatrixD Ut(1, 3, u);
272 TVector3 deltaV = pos - v;
273 deltaV.GetXYZ(delta);
274 TMatrixD D(3, 1, delta);
275 TMatrixD Dt(1, 3, delta);
277 TMatrixD C2 = Ut * M * U;
278 Double_t c2 = C2[0][0];
280 TMatrixD C1 = Ut * M * D;
281 Double_t c1 = C1[0][0];
283 TMatrixD C0 = Dt * M * D;
284 Double_t c0 = C0[0][0];
286 Double_t root = c1 * c1 - c0 * c2;
287 if (root < 0)
return 0;
289 Double_t t1 = (-c1 + TMath::Sqrt(root)) / c2;
290 Double_t t2 = (-c1 - TMath::Sqrt(root)) / c2;
295 Double_t h2 = t2 * dir.Dot(axis) + axis.Dot(deltaV);
307TVector3
MoveByDistance(
const TVector3& pos,
const TVector3& dir, Double_t d) {
return pos + d * dir.Unit(); }
313TVector3
MoveByDistanceFast(
const TVector3& pos,
const TVector3& dir, Double_t d) {
return pos + d * dir; }
318Double_t
GetDistance(
const TVector3& v1,
const TVector3& v2) {
return (v2 - v1).Mag(); }
323Double_t
GetDistance2(
const TVector3& v1,
const TVector3& v2) {
return (v2 - v1).Mag2(); }
This namespace serves to define physics constants and other basic physical operations.
TVector3 GetHyperbolicVectorIntersection(const TVector3 &pos, const TVector3 &dir, const Double_t alpha, const Double_t R3, const Double_t lMirr, const Double_t focal)
TVector3 MoveByDistance(const TVector3 &pos, const TVector3 &dir, Double_t d)
This method transports a position pos by a distance d in the direction defined by dir.
TVector3 GetParabolicNormal(const TVector3 &pos, const Double_t alpha, const Double_t R3)
This method returns the normal vector on a parabolic surface pointing towards the inside of the parab...
Double_t GetDistance(const TVector3 &v1, const TVector3 &v2)
This method returns the cartesian distance between vector v2 and v1.
TVector3 GetConeNormal(const TVector3 &pos, const Double_t alpha, const Double_t R=0)
This method will return a vector that is normal to the cone surface. The position pos should be at th...
Double_t GetConeVectorIntersection(const TVector3 &pos, const TVector3 &dir, const TVector3 &d, const TVector3 &v, const Double_t cosTheta)
This method will find the intersection of the trajectory defined by the vector starting at pos and mo...
TVector3 GetPlaneVectorIntersection(const TVector3 &pos, const TVector3 &dir, TVector3 const &n, TVector3 const &a)
This method will find the intersection of the trajectory defined by the vector starting at pos and mo...
TVector3 GetHyperbolicNormal(const TVector3 &pos, const Double_t alpha, const Double_t R3, const Double_t focal)
This method returns the normal vector on a hyperbolic surface pointing towards the inside of the hype...
Double_t DistanceToAxis(const TVector3 &axisPoint, const TVector3 &axisVector, const TVector3 &point)
This method will return the distance from point to the straight defined by axisPoint and axisVector.
TVector3 GetParabolicVectorIntersection(const TVector3 &pos, const TVector3 &dir, const Double_t alpha, const Double_t R3, const Double_t lMirr)
TMatrixD GetConeMatrix(const TVector3 &d, const Double_t cosTheta)
It returns the cone matrix M = d^T x d - cosTheta^2 x I, extracted from the document by "David Eberly...
TVector3 MoveToPlane(const TVector3 &pos, const TVector3 &dir, const TVector3 &n, const TVector3 &a)
This method will translate the vector with direction dir starting at position pos to the plane define...
Double_t GetDistance2(const TVector3 &v1, const TVector3 &v2)
This method returns the squared cartesian distance between vector v2 and v1.
TVector3 MoveByDistanceFast(const TVector3 &pos, const TVector3 &dir, Double_t d)
This method transports a position pos by a distance d in the direction defined by dir....
TVector3 GetVectorReflection(const TVector3 &dir, const TVector3 &n)
This method will return the reflected vector respect to a plane defined by its normal vector n....
Double_t GetVectorsAngle(const TVector3 &v1, const TVector3 &v2)
This method will return the angle in radians between 2 vectors.