32 #include "StFormulary.hh"
44 void
StFormulary::Pq(const Double_t *p, const Double_t *q, Double_t x[2])
51 Double_t minus_p_halbe = -(*p)/2.;
52 Double_t wurzel = TMath::Sqrt(-(*q) + TMath::Power((*p)/2., 2));
54 for (i = 0; i < 2; i++) {
55 x[i] = minus_p_halbe + TMath::Power(-1., i) * wurzel;
62 Double_t StFormulary::Angle(
const Double_t *x1,
const Double_t *x2, Int_t dim)
66 Double_t value = ScalarProd(x1, x2, dim)/(Abs(x1, dim) * Abs(x2, dim));
69 if (TMath::Abs(value) < 1.) {
70 return TMath::ACos(value);
73 else if (value >= 1. && value < 1.00001) {
78 return TMath::ACos(value);
83 Double_t StFormulary::Dist_squared(
const Double_t *p1,
const Double_t *p2, Int_t dim)
87 Double_t *minus =
new Double_t[dim];
89 Diff(p1, p2, minus, dim);
90 Double_t dist_sq = Square(minus, dim);
97 Double_t StFormulary::CheckASinArg(Double_t asin_arg)
101 if (TMath::Abs(asin_arg) > 1.) {
102 asin_arg = (asin_arg >= 0) ? +1. : -1.;
109 Double_t StFormulary::RelDiff(
const Double_t p1,
const Double_t p2)
113 return (p1 - p2) / (p1 + p2);
117 Double_t StFormulary::Dist(
const Double_t *p1,
const Double_t *p2, Int_t dim)
121 return TMath::Sqrt(Dist_squared(p1, p2, dim));
125 void StFormulary::VectorProd(
const Double_t *a,
const Double_t *b, Double_t *c)
129 c[1] = a[2]*b[3] - a[3]*b[2];
130 c[2] = a[3]*b[1] - a[1]*b[3];
131 c[3] = a[1]*b[2] - a[2]*b[1];
137 Double_t StFormulary::ScalarProd(
const Double_t *a,
const Double_t *b, Int_t dim)
141 Double_t result = 0.;
143 for (Int_t i=0; i<dim; result += a[i] * b[i], i++);
149 Double_t StFormulary::Square(
const Double_t *p, Int_t dim)
153 return ScalarProd(p, p, dim);
157 void StFormulary::Sum(
const Double_t *p1,
const Double_t *p2, Double_t *P, Int_t n)
162 for (Int_t i=0; i<n; P[i] = p1[i] + p2[i], i++);
168 void StFormulary::Diff(
const Double_t *p1,
const Double_t *p2, Double_t *P, Int_t n)
173 for (Int_t i=0; i<n; P[i] = p1[i] - p2[i], i++);
179 Double_t StFormulary::Abs(
const Double_t *p, Int_t dim)
183 return TMath::Sqrt(Square(p, dim));