Project
Loading...
Searching...
No Matches
TrackUtils.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
17#ifndef INCLUDE_RECONSTRUCTIONDATAFORMATS_TRACKUTILS_H_
18#define INCLUDE_RECONSTRUCTIONDATAFORMATS_TRACKUTILS_H_
19
20#include "GPUCommonRtypes.h"
21#include "GPUCommonArray.h"
22
23#ifndef GPUCA_GPUCODE_DEVICE
24#include <cmath>
25#endif
26
27#include "MathUtils/Utils.h"
29
30namespace o2
31{
32namespace track
33{
34// helper function
35template <typename value_T = float>
36GPUd() value_T BetheBlochSolid(value_T bg, value_T rho = 2.33, value_T kp1 = 0.20, value_T kp2 = 3.00, value_T meanI = 173e-9, value_T meanZA = 0.49848);
37
38template <typename value_T = float>
39GPUd() value_T BetheBlochSolidOpt(value_T bg);
40
41template <typename value_T = float>
42GPUd() void g3helx3(value_T qfield, value_T step, gpu::gpustd::array<value_T, 7>& vect);
43
44//____________________________________________________
45template <typename value_T>
46GPUd() void g3helx3(value_T qfield, value_T step, gpu::gpustd::array<value_T, 7>& vect)
47{
48 /******************************************************************
49 * *
50 * GEANT3 tracking routine in a constant field oriented *
51 * along axis 3 *
52 * Tracking is performed with a conventional *
53 * helix step method *
54 * *
55 * Authors R.Brun, M.Hansroul ********* *
56 * Rewritten V.Perevoztchikov *
57 * *
58 * Rewritten in C++ by I.Belikov *
59 * *
60 * qfield (kG) - particle charge times magnetic field *
61 * step (cm) - step length along the helix *
62 * vect[7](cm,GeV/c) - input/output x, y, z, px/p, py/p ,pz/p, p *
63 * *
64 ******************************************************************/
65#ifndef GPUCA_GPUCODE_DEVICE
66 static_assert(std::is_floating_point_v<value_T>);
67#endif
68
69 const int ix = 0, iy = 1, iz = 2, ipx = 3, ipy = 4, ipz = 5, ipp = 6;
70 constexpr value_T kOvSqSix = 0.408248f; // std::sqrt(1./6.);
71
72 value_T cosx = vect[ipx], cosy = vect[ipy], cosz = vect[ipz];
73
74 value_T rho = qfield * constants::math::B2C / vect[ipp];
75 value_T tet = rho * step;
76
77 value_T tsint, sintt, sint, cos1t;
78 if (gpu::CAMath::Abs(tet) > 0.03f) {
79 sint = gpu::CAMath::Sin(tet);
80 sintt = sint / tet;
81 tsint = (tet - sint) / tet;
82 value_T t = gpu::CAMath::Sin(0.5f * tet);
83 cos1t = 2 * t * t / tet;
84 } else {
85 tsint = tet * tet / 6.f;
86 sintt = (1.f - tet * kOvSqSix) * (1.f + tet * kOvSqSix); // 1.- tsint;
87 sint = tet * sintt;
88 cos1t = 0.5f * tet;
89 }
90
91 value_T f1 = step * sintt;
92 value_T f2 = step * cos1t;
93 value_T f3 = step * tsint * cosz;
94 value_T f4 = -tet * cos1t;
95 value_T f5 = sint;
96
97 vect[ix] += f1 * cosx - f2 * cosy;
98 vect[iy] += f1 * cosy + f2 * cosx;
99 vect[iz] += f1 * cosz + f3;
100
101 vect[ipx] += f4 * cosx - f5 * cosy;
102 vect[ipy] += f4 * cosy + f5 * cosx;
103}
104
105//____________________________________________________
106template <typename value_T>
107GPUd() value_T BetheBlochSolid(value_T bg, value_T rho, value_T kp1, value_T kp2, value_T meanI,
108 value_T meanZA)
109{
110 //
111 // This is the parameterization of the Bethe-Bloch formula inspired by Geant.
112 //
113 // bg - beta*gamma
114 // rho - density [g/cm^3]
115 // kp1 - density effect first junction point
116 // kp2 - density effect second junction point
117 // meanI - mean excitation energy [GeV]
118 // meanZA - mean Z/A
119 //
120 // The default values for the kp* parameters are for silicon.
121 // The returned value is in [GeV/(g/cm^2)].
122 //
123#ifndef GPUCA_GPUCODE_DEVICE
124 static_assert(std::is_floating_point_v<value_T>);
125#endif
126
127 constexpr value_T mK = 0.307075e-3; // [GeV*cm^2/g]
128 constexpr value_T me = 0.511e-3; // [GeV/c^2]
129 kp1 *= 2.303f;
130 kp2 *= 2.303f;
131 value_T bg2 = bg * bg, beta2 = bg2 / (1 + bg2);
132 value_T maxT = 2.f * me * bg2; // neglecting the electron mass
133
134 //*** Density effect
135 value_T d2 = 0.;
136 const value_T x = gpu::CAMath::Log(bg);
137 const value_T lhwI = gpu::CAMath::Log(28.816f * 1e-9f * gpu::CAMath::Sqrt(rho * meanZA) / meanI);
138 if (x > kp2) {
139 d2 = lhwI + x - 0.5f;
140 } else if (x > kp1) {
141 double r = (kp2 - x) / (kp2 - kp1);
142 d2 = lhwI + x - 0.5f + (0.5f - lhwI - kp1) * r * r * r;
143 }
144 auto dedx = mK * meanZA / beta2 * (0.5f * gpu::CAMath::Log(2 * me * bg2 * maxT / (meanI * meanI)) - beta2 - d2);
145 return dedx > 0. ? dedx : 0.;
146}
147
148//____________________________________________________
149template <typename value_T>
150GPUd() value_T BetheBlochSolidOpt(value_T bg)
151{
152 //
153 // This is the parameterization of the Bethe-Bloch formula inspired by Geant with hardcoded constants and better optimization
154 //
155 // bg - beta*gamma
156 // rho - density [g/cm^3]
157 // kp1 - density effect first junction point
158 // kp2 - density effect second junction point
159 // meanI - mean excitation energy [GeV]
160 // meanZA - mean Z/A
161 //
162 // The default values for the kp* parameters are for silicon.
163 // The returned value is in [GeV/(g/cm^2)].
164 //
165 // constexpr value_T rho = 2.33;
166 // constexpr value_T meanI = 173e-9;
167 // constexpr value_T me = 0.511e-3; // [GeV/c^2]
168
169 constexpr value_T mK = 0.307075e-3; // [GeV*cm^2/g]
170 constexpr value_T kp1 = 0.20 * 2.303;
171 constexpr value_T kp2 = 3.00 * 2.303;
172 constexpr value_T meanZA = 0.49848;
173 constexpr value_T lhwI = -1.7175226; // gpu::CAMath::Log(28.816 * 1e-9 * gpu::CAMath::Sqrt(rho * meanZA) / meanI);
174 constexpr value_T log2muTomeanI = 8.6839805; // gpu::CAMath::Log( 2. * me / meanI);
175
176 value_T bg2 = bg * bg, beta2 = bg2 / (1. + bg2);
177
178 //*** Density effect
179 value_T d2 = 0.;
180 const value_T x = gpu::CAMath::Log(bg);
181 if (x > kp2) {
182 d2 = lhwI - 0.5f + x;
183 } else if (x > kp1) {
184 value_T r = (kp2 - x) / (kp2 - kp1);
185 d2 = lhwI - 0.5 + x + (0.5 - lhwI - kp1) * r * r * r;
186 }
187 auto dedx = mK * meanZA / beta2 * (log2muTomeanI + x + x - beta2 - d2);
188 return dedx > 0. ? dedx : 0.;
189}
190
191//____________________________________________________
192template <typename value_T>
193GPUdi() value_T BetheBlochSolidDerivative(value_T dedx, value_T bg)
194{
195 //
196 // This is approximate derivative of the BB over betagamm, NO check for the consistency of the provided dedx and bg is done
197 // Charge 1 particle is assumed for the provied dedx. For charge > 1 particles dedx/q^2 should be provided and obtained value must be scaled by q^2
198 // The call should be usually done as
199 // auto dedx = BetheBlochSolidOpt(bg);
200 // // if derivative needed
201 // auto ddedx = BetheBlochSolidDerivative(dedx, bg, bg*bg)
202 //
203 // dedx - precalculate dedx for bg
204 // bg - beta*gamma
205 //
206 constexpr value_T mK = 0.307075e-3; // [GeV*cm^2/g]
207 constexpr value_T meanZA = 0.49848;
208 auto bg2 = bg * bg;
209 auto t1 = 1 + bg2;
210 // auto derH = (mK * meanZA * (t1+bg2) - dedx*bg2)/(bg*t1);
211 auto derH = (mK * meanZA * (t1 + 1. / bg2) - dedx) / (bg * t1);
212 return derH + derH;
213}
214
215} // namespace track
216} // namespace o2
217
218#endif /* INCLUDE_RECONSTRUCTIONDATAFORMATS_TRACKUTILS_H_ */
General auxilliary methods.
useful math constants
GLint GLenum GLint x
Definition glcorearb.h:403
GLenum array
Definition glcorearb.h:4274
GLboolean r
Definition glcorearb.h:1233
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
Definition glcorearb.h:5034
constexpr float B2C
value_T bg
Definition TrackUtils.h:194
value_T cosz
Definition TrackUtils.h:72
value_T f3
Definition TrackUtils.h:93
constexpr value_T me
Definition TrackUtils.h:128
GPUdi() TrackParametrization< value_T >
value_T sint
Definition TrackUtils.h:77
const int iz
Definition TrackUtils.h:69
kp1 *kp2 *value_T bg2
Definition TrackUtils.h:131
value_T f4
Definition TrackUtils.h:94
value_T step
Definition TrackUtils.h:42
value_T cosy
Definition TrackUtils.h:72
value_T f1
Definition TrackUtils.h:91
const value_T x
Definition TrackUtils.h:136
value_T d2
Definition TrackUtils.h:135
value_T gpu::gpustd::array< value_T, 7 > & vect
Definition TrackUtils.h:42
const int ipy
Definition TrackUtils.h:69
value_T f5
Definition TrackUtils.h:95
kp1 *kp2 *value_T beta2
Definition TrackUtils.h:131
constexpr value_T kOvSqSix
Definition TrackUtils.h:70
GPUd() value_T BetheBlochSolid(value_T bg
Definition TrackUtils.h:150
value_T value_T value_T value_T meanI
Definition TrackUtils.h:36
const int iy
Definition TrackUtils.h:69
value_T maxT
Definition TrackUtils.h:132
const int ix
Definition TrackUtils.h:69
constexpr value_T mK
Definition TrackUtils.h:127
value_T rho
Definition TrackUtils.h:36
value_T value_T kp1
Definition TrackUtils.h:36
value_T sintt
Definition TrackUtils.h:77
const int ipx
Definition TrackUtils.h:69
const int ipp
Definition TrackUtils.h:69
value_T cosx
Definition TrackUtils.h:72
value_T value_T value_T value_T value_T meanZA
Definition TrackUtils.h:36
value_T f2
Definition TrackUtils.h:92
value_T tet
Definition TrackUtils.h:75
const int ipz
Definition TrackUtils.h:69
value_T cos1t
Definition TrackUtils.h:77
const value_T lhwI
Definition TrackUtils.h:137
value_T tsint
Definition TrackUtils.h:77
value_T value_T value_T kp2
Definition TrackUtils.h:36
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...