Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KFParticleDef.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file KFParticleDef.h
1 /*
2  * This file is part of KFParticle package
3  * Copyright (C) 2007-2019 FIAS Frankfurt Institute for Advanced Studies
4  * 2007-2019 Goethe University of Frankfurt
5  * 2007-2019 Ivan Kisel <I.Kisel@compeng.uni-frankfurt.de>
6  * 2007-2019 Maksym Zyzak
7  *
8  * KFParticle is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * KFParticle is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 
23 #ifndef KFParticleDef_H
24 #define KFParticleDef_H
25 
26 #ifdef __ROOT__ //for the STAR experiment
27 #define HomogeneousField
28 #endif
29 
30 #ifdef HLTCA_STANDALONE
31 #include "RootTypesDef.h"
32 #else
33 #include "TObject.h"
34 #endif
35 
36 #define NInputSets 8
37 
38 #include <Vc/Vc>
39 #include <Vc/version.h>
40 #include <Vc/limits>
41 using ::Vc::float_v;
42 using ::Vc::double_v;
43 using ::Vc::float_v;
44 using ::Vc::int_v;
45 using ::Vc::uint_v;
46 using ::Vc::VectorAlignment;
47 using ::Vc::double_m;
48 using ::Vc::float_m;
49 using ::Vc::int_m;
50 using ::Vc::uint_m;
51 using ::Vc::atan2;
52 using ::Vc::asin;
54 using ::Vc::isfinite;
55 
56 #ifdef VC_VERSION_NUMBER
57 #if VC_VERSION_NUMBER < VC_VERSION_CHECK(1,0,0)
58 template <typename To, typename From> To simd_cast(From &&x) { return static_cast<To>(x); }
59 #endif
60 #elif defined(Vc_VERSION_NUMBER)
61 #if Vc_VERSION_NUMBER < Vc_VERSION_CHECK(1,0,0)
62 template <typename To, typename From> To simd_cast(From &&x) { return static_cast<To>(x); }
63 #endif
64 #endif
65 
67 
68 #if defined(HLTCA_STANDALONE)
69 typedef unsigned char UChar_t;
70 typedef UChar_t Byte_t;
71 typedef int Int_t;
72 typedef double Double_t;
73 #else
74 #include "Rtypes.h"
75 #endif
76 
77 #include "KFPSimdAllocator.h"
78 typedef std::vector<float_v, KFPSimdAllocator<float_v> > kfvector_floatv;
79 
80 typedef std::vector<float, KFPSimdAllocator<float> > kfvector_float;
81 typedef std::vector<int, KFPSimdAllocator<int> > kfvector_int;
82 typedef std::vector<unsigned int, KFPSimdAllocator<unsigned int> > kfvector_uint;
83 
84 namespace KFPMath
85 {
86  static inline __attribute__((always_inline)) float_v Sin ( const float_v &phi )
87  {
88  const float_v pi(3.1415926535897932f);
89  const float_v nTurnsF = (phi + pi) / (float_v(2.f)*pi);
90  int_v nTurns = simd_cast<int_v>( nTurnsF );
91  nTurns( (nTurns<=int_v(Vc::Zero)) && simd_cast<int_m>(phi<-pi)) -= 1;
92 
93  const float_v& x = phi - simd_cast<float_v>(nTurns)*(float_v(2.f)*pi);
94 
95  const float_v& B = 4.f/pi;
96  const float_v& C = -B/pi;
97 
98  float_v y = (B + C * Vc::abs(x)) * x;
99 
100  const float_v& P = 0.218f;
101  y = P * (y * Vc::abs(y) - y) + y;
102 
103  return y;
104  }
105  static inline __attribute__((always_inline)) float_v Cos ( const float_v &phi )
106  {
107  return Sin( phi + 1.570796326795f ); //x + pi/2
108  }
109  static inline __attribute__((always_inline)) float_v ATan2( const float_v &y, const float_v &x )
110  {
111  const float_v pi(3.1415926535897932f);
112  const float_v zero(Vc::Zero);
113 
114  const float_m &xZero = (x == zero);
115  const float_m &yZero = (y == zero);
116  const float_m &xNeg = (x < zero);
117  const float_m &yNeg = (y < zero);
118 
119  const float_v &absX = Vc::abs(x);
120  const float_v &absY = Vc::abs(y);
121 
122  float_v a = absY / absX;
123  const float_m &gt_tan_3pi_8 = (a > float_v(2.414213562373095f));
124  const float_m &gt_tan_pi_8 = (a > float_v(0.4142135623730950f)) && (!gt_tan_3pi_8);
125  float_v b(Vc::Zero);
126  b(gt_tan_3pi_8) = pi/2.f;
127  b(gt_tan_pi_8) = pi/4.f;
128  a(gt_tan_3pi_8) = (-1.f / a);
129  a(gt_tan_pi_8) = ((absY - absX) / (absY + absX)) ;
130  const float_v &a2 = a * a;
131  b += (((8.05374449538e-2f * a2
132  - 1.38776856032E-1f) * a2
133  + 1.99777106478E-1f) * a2
134  - 3.33329491539E-1f) * a2 * a
135  + a;
136  b(xNeg ^ yNeg) = -b;
137  b(xNeg && !yNeg) = (b+pi);
138  b(xNeg && yNeg) = (b-pi);
139  b(xZero && yZero) = zero;
140  b(xZero && yNeg) = (-pi/2.f);
141  return b;
142  }
143  template<typename T> static inline __attribute__((always_inline))
144  typename Vc::Vector<T>::Mask Finite(const Vc::Vector<T> &x) { return Vc::isfinite( x ); }
145  template<typename T> static inline __attribute__((always_inline)) T Log ( const T &x ) { return std::log( x ); }
146  template<typename T> static inline __attribute__((always_inline)) T ACos( const T &x ) { return (3.1415926535897f/2.f - asin( x )); }
147 }
148 
149 #endif