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