Belle II Software development
Utility.cc
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#include "arich/modules/arichReconstruction/Utility.h"
10#include <Math/Vector3D.h>
11#include <Math/Rotation3D.h>
12#include <cmath>
13
14
15namespace Belle2 {
20 namespace arich {
21 //****************************************************************************
22 // originated from the Numerical recipes error function
23 double Erf(double x)
24 {
25 const double Z1 = 1;
26 const double HF = Z1 / 2;
27 const double C1 = 0.56418958;
28
29 const double P10 = +3.6767877;
30 const double Q10 = +3.2584593;
31 const double P11 = -9.7970465E-2;
32
33 static const double P2[5] = { 7.3738883, 6.8650185, 3.0317993, 0.56316962, 4.3187787e-5 };
34 static const double Q2[5] = { 7.3739609, 15.184908, 12.79553, 5.3542168, 1. };
35
36 const double P30 = -1.2436854E-1;
37 const double Q30 = +4.4091706E-1;
38 const double P31 = -9.6821036E-2;
39
40 double V = fabs(x);
41 double H = 0;
42 double Y;
43
44 if (V < HF) {
45 Y = V * V;
46 H = x * (P10 + P11 * Y) / (Q10 + Y);
47 } else {
48 if (V < 4) {
49 double AP = P2[4];
50 double AQ = Q2[4];
51 for (int c1 = 3; c1 >= 0; c1--) {
52 AP = P2[c1] + V * AP;
53 AQ = Q2[c1] + V * AQ;
54 }
55 H = 1 - exp(-V * V) * AP / AQ;
56 } else {
57 Y = 1. / V * V;
58 H = 1 - exp(-V * V) * (C1 + Y * (P30 + P31 * Y) / (Q30 + Y)) / V;
59 }
60 if (x < 0)
61 H = - H;
62 }
63 return H;
64 }
65
66
67 //*******************************************************************************
68
69 ROOT::Math::XYZVector Refraction(const ROOT::Math::XYZVector s, const double n)
70 {
71 double x = s.X() / n;
72 double y = s.Y() / n;
73
74 if (x * x + y * y > 1) return ROOT::Math::XYZVector();
75 if (s.Z() < 0) return ROOT::Math::XYZVector(x, y, -sqrt(1 - x * x - y * y));
76 else return ROOT::Math::XYZVector(x, y, sqrt(1 - x * x - y * y));
77 }
78 //---------------------------------------------------------------
79
80
81 int Refraction(ROOT::Math::XYZVector s, ROOT::Math::XYZVector norm, double n, ROOT::Math::XYZVector
82 &newdir)
83 {
84 double sp = s.Dot(norm);
85 double sign = (sp > 0) * 2 - 1;
86 ROOT::Math::XYZVector vsth = (s - sp * norm) * (1 / n);
87 double cth = sqrt(1 - vsth.Mag2());
88 newdir = vsth + cth * norm * sign;
89 return 1;
90 }
91
92 //---------------------------------------------------------------
93 ROOT::Math::XYZVector setThetaPhi(double theta, double fi)
94 {
95 ROOT::Math::XYZVector r;
96 r.SetXYZ(cos(fi) * sin(theta),
97 sin(fi) * sin(theta),
98 cos(theta));
99 return r;
100
101 }
102 //---------------------------------------------------------------
103
104 ROOT::Math::Rotation3D TransformToFixed(ROOT::Math::XYZVector r)
105 {
106 // Description: Calculates the base vectors of the track system
107 // Output:
108 ROOT::Math::XYZVector fX, fY, fZ;// base vectors
109
110 double ss = 1 - r.Y() * r.Y();
111 if (ss > 0) {
112 ss = sqrt(ss);
113 fZ = r;
114 fX = ROOT::Math::XYZVector(fZ.Z() / ss, 0, -fZ.X() / ss);
115 fY = fZ.Cross(fX);
116 } else {
117 fZ = ROOT::Math::XYZVector(0, 1, 0);
118 fX = ROOT::Math::XYZVector(0, 0, 1);
119 fY = ROOT::Math::XYZVector(1, 0, 0);
120 }
121 ROOT::Math::Rotation3D transform;
122 transform.SetComponents(fX, fY, fZ);
123 transform.Invert();
124 return transform;
125 }
126
127 ROOT::Math::Rotation3D TransformFromFixed(ROOT::Math::XYZVector r)
128 {
129 // Description: Calculates the base vectors of the track system
130 // Output:
131 ROOT::Math::XYZVector fX, fY, fZ;// base vectors
132
133 double ss = 1 - r.Y() * r.Y();
134 if (ss > 0) {
135 ss = sqrt(ss);
136 fZ = r;
137 fX = ROOT::Math::XYZVector(fZ.Z() / ss, 0, -fZ.X() / ss);
138 fY = fZ.Cross(fX);
139 } else {
140 fZ = ROOT::Math::XYZVector(0, 1, 0);
141 fX = ROOT::Math::XYZVector(0, 0, 1);
142 fY = ROOT::Math::XYZVector(1, 0, 0);
143 }
144 ROOT::Math::Rotation3D transform;
145 transform.SetComponents(fX, fY, fZ);
146 return transform;
147 }
148
149
150 double ExpectedCherenkovAngle(double p, double mass, double refind)
151 {
152 // Description:
153 // calculates Cerenkov angle of a particle of mass MASS and momentum P
154 //
155 // Input Parameters:
156 // p momentum of the particle
157 // mass of the particle
158 //
159 // return expected cherenkov angle
160
161 if (mass <= 0 || p < 0) return 0;
162 double a = p / mass;
163 double b = a / sqrt(1 + a * a) * refind;
164 if (b > 1) return acos(1 / b);
165 return 0;
166 }
167
168 double SquareInt(double aaa, double fi, double mean, double sigma)
169 {
170
171 double aa = aaa / sqrt(2); // 2
172 fi += M_PI / 4;
173 fi = fi / (2 * M_PI);
174 fi = 8 * (fi - floor(fi));
175
176 if (fi < 0) fi += 16;
177 if (fi > 8) fi = 16 - fi;
178 if (fi > 4) fi = 8 - fi;
179 if (fi > 2) fi = 4 - fi;
180 if (fi > 1) fi = 2 - fi;
181 fi = fi * M_PI / 4;
182
183 double sf = aa * sin(fi);
184 double cf = aa * cos(fi);
185
186 double a[4], b[4];
187 //double n0 = 2*cf;
188 double n0 = 2 * aa * aa / (cf + sf); // A.Petelin 21.12.2006
189
190 const double sq2pi = 1 / sqrt(2.*M_PI);
191 double sqrt2sigma = 1 / (M_SQRT2 * sigma);
192
193
194 a[0] = (mean + sf) * sqrt2sigma;
195 a[1] = (mean - sf) * sqrt2sigma;
196 a[2] = (mean + cf) * sqrt2sigma;
197 a[3] = (mean - cf) * sqrt2sigma;
198
199 for (int i = 0; i < 4; i++) b[i] = exp(-a[i] * a[i]);
200 for (int i = 0; i < 4; i++) a[i] = Erf(a[i]);
201
202 double gint = 0;
203 const double dsf = 0.001;
204 if (fabs(sf) > dsf) gint += 0.5 * n0 * (a[0] - a[1]);
205
206 double dy = (cf - sf);
207 double dx = (cf + sf);
208
209 if (fabs(dx) > dsf && fabs(dy) > dsf) {
210
211 double k = dy / dx + dx / dy;
212 // double n = k * cf - sf;
213 double n = k * cf; // A.Petelin 21.12.2006
214 // +sf -sf +cf -cf
215 gint +=
216 sq2pi * k * sigma * (-b[0] - b[1] + b[2] + b[3]) +
217 0.5 * k * mean * (-a[0] - a[1] + a[2] + a[3]) +
218 0.5 * n * (-a[0] + a[1] + a[2] - a[3]);
219
220 }
221
222 return gint / (aa);
223 }
224 }
226}
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.