Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KFParticleBaseSIMD.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file KFParticleBaseSIMD.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 KFParticleBaseSIMD_H
24 #define KFParticleBaseSIMD_H
25 
26 #ifdef HLTCA_STANDALONE
27 #include "RootTypesDef.h"
28 #endif
29 
30 #include <vector>
31 #include "KFParticleDef.h"
32 
46 
47  public:
48 
49  //*
50  //* ABSTRACT METHODS HAVE TO BE DEFINED IN USER CLASS
51  //*
52 #if __GNUC__ && ( defined(ENVIRONMENT32) || GCC_VERSION < 40300 )
53 
54 #else
55 
56  void *operator new(size_t size) { return _mm_malloc(size, sizeof(float_v)); }
57  void *operator new[](size_t size) { return _mm_malloc(size, sizeof(float_v)); }
58  void *operator new(size_t size, void *ptr) { return ::operator new(size, ptr);}
59  void *operator new[](size_t size, void *ptr) { return ::operator new(size, ptr);}
60  void operator delete(void *ptr, size_t) { _mm_free(ptr); }
61  void operator delete[](void *ptr, size_t) { _mm_free(ptr); }
62 
63 #endif
64 
66  virtual void GetFieldValue(const float_v xyz[], float_v B[]) const = 0;
67 
68  //* Virtual methods needed for particle transportation
69  //* One can use particular implementations for collider (only Bz component)
70  //* geometry and for fixed-target (CBM-like) geometry which are provided below
71  //* in TRANSPORT section
72 
73  //* Get dS to xyz[] space point
74 
76  virtual float_v GetDStoPoint( const float_v xyz[3], float_v dsdr[6] ) const = 0;
77 
78  float_v GetDStoPointLine( const float_v xyz[3], float_v dsdr[6] ) const;
79  float_v GetDStoPointBz( float_v Bz, const float_v xyz[3], float_v dsdr[6], const float_v* param = 0 ) const;
80  float_v GetDStoPointBy( float_v By, const float_v xyz[3], float_v dsdr[6] ) const;
81  float_v GetDStoPointCBM( const float_v xyz[3], float_v dsdr[6] ) const;
82 
84  virtual void GetDStoParticle( const KFParticleBaseSIMD &p, float_v dS[2], float_v dsdr[4][6] ) const = 0;
86  virtual void GetDStoParticleFast( const KFParticleBaseSIMD &p, float_v dS[2] ) const = 0;
87 
88  void GetDStoParticleLine( const KFParticleBaseSIMD &p, float_v dS[2], float_v dsdr[4][6] ) const ;
89  void GetDStoParticleLine( const KFParticleBaseSIMD &p, float_v dS[2] ) const ;
90  void GetDStoParticleBz( float_v Bz, const KFParticleBaseSIMD &p, float_v dS[2], float_v dsdr[4][6], const float_v* param1 =0, const float_v* param2 =0 ) const ;
91  void GetDStoParticleBz( float_v Bz, const KFParticleBaseSIMD &p, float_v dS[2], const float_v* param1 =0, const float_v* param2 =0 ) const ;
92  void GetDStoParticleBy( float_v B, const KFParticleBaseSIMD &p, float_v dS[2], float_v dsdr[4][6] ) const ;
93  void GetDStoParticleBy( float_v B, const KFParticleBaseSIMD &p, float_v dS[2] ) const ;
94  void GetDStoParticleB( float_v B[3], const KFParticleBaseSIMD &p, float_v dS[2], float_v dsdr[4][6] ) const;
95  void GetDStoParticleB( float_v B[3], const KFParticleBaseSIMD &p, float_v dS[2] ) const;
96  void GetDStoParticleCBM( const KFParticleBaseSIMD &p, float_v dS[2], float_v dsdr[4][6] ) const ;
97  void GetDStoParticleCBM( const KFParticleBaseSIMD &p, float_v dS[2] ) const ;
98 
100  virtual void Transport( float_v dS, const float_v dsdr[6], float_v P[], float_v C[], float_v* dsdr1=0, float_v* F=0, float_v* F1=0 ) const = 0;
102  virtual void TransportFast( float_v dS, float_v P[] ) const = 0;
103 
104 
105 
106  //*
107  //* INITIALIZATION
108  //*
109 
110  //* Constructor
111 
113 
114  //* Destructor
115 
116  virtual ~KFParticleBaseSIMD() { ; }
117 
118  void Initialize( const float_v Param[], const float_v Cov[], int_v Charge, float_v Mass );
119  void Initialize();
120 
122  void SetMassHypo(float_v m) { fMassHypo = m;}
123  const float_v& GetMassHypo() const { return fMassHypo; }
124  const float_v& GetSumDaughterMass() const {return SumDaughterMass;}
125 
126  //*
127  //* ACCESSORS
128  //*
129 
130  //* Simple accessors
131 
132  float_v GetX () const { return fP[0]; }
133  float_v GetY () const { return fP[1]; }
134  float_v GetZ () const { return fP[2]; }
135  float_v GetPx () const { return fP[3]; }
136  float_v GetPy () const { return fP[4]; }
137  float_v GetPz () const { return fP[5]; }
138  float_v GetE () const { return fP[6]; }
139  float_v GetS () const { return fP[7]; }
140  int_v GetQ () const { return fQ; }
141  float_v GetChi2 () const { return fChi2; }
142  int_v GetNDF () const { return fNDF; }
143 
144  const float_v& X () const { return fP[0]; }
145  const float_v& Y () const { return fP[1]; }
146  const float_v& Z () const { return fP[2]; }
147  const float_v& Px () const { return fP[3]; }
148  const float_v& Py () const { return fP[4]; }
149  const float_v& Pz () const { return fP[5]; }
150  const float_v& E () const { return fP[6]; }
151  const float_v& S () const { return fP[7]; }
152  const int_v& Q () const { return fQ; }
153  const float_v& Chi2 () const { return fChi2; }
154  const int_v& NDF () const { return fNDF; }
155 
156  float_v GetParameter ( Int_t i ) const { return fP[i]; }
157  float_v GetCovariance( Int_t i ) const { return fC[i]; }
158  float_v GetCovariance( Int_t i, Int_t j ) const { return fC[IJ(i,j)]; }
159 
160  //* Accessors with calculations( &value, &estimated sigma )
161  //* error flag returned (0 means no error during calculations)
162 
163  float_m GetMomentum ( float_v &p, float_v &error ) const ;
164  float_m GetPt ( float_v &pt, float_v &error ) const ;
165  float_m GetEta ( float_v &eta, float_v &error ) const ;
166  float_m GetPhi ( float_v &phi, float_v &error ) const ;
167  float_m GetMass ( float_v &m, float_v &error ) const ;
168  float_m GetDecayLength ( float_v &l, float_v &error ) const ;
169  float_m GetDecayLengthXY ( float_v &l, float_v &error ) const ;
170  float_m GetLifeTime ( float_v &ctau, float_v &error ) const ;
171  float_m GetR ( float_v &r, float_v &error ) const ;
172 
173  //*
174  //* MODIFIERS
175  //*
176 
177  float_v & X () { return fP[0]; }
178  float_v & Y () { return fP[1]; }
179  float_v & Z () { return fP[2]; }
180  float_v & Px () { return fP[3]; }
181  float_v & Py () { return fP[4]; }
182  float_v & Pz () { return fP[5]; }
183  float_v & E () { return fP[6]; }
184  float_v & S () { return fP[7]; }
185  int_v & Q () { return fQ; }
186  float_v & Chi2 () { return fChi2; }
187  int_v & NDF () { return fNDF; }
188 
189  float_v & Parameter ( Int_t i ) { return fP[i]; }
190  float_v & Covariance( Int_t i ) { return fC[i]; }
191  float_v & Covariance( Int_t i, Int_t j ) { return fC[IJ(i,j)]; }
192 
193 
194  //*
195  //* CONSTRUCTION OF THE PARTICLE BY ITS DAUGHTERS AND MOTHER
196  //* USING THE KALMAN FILTER METHOD
197  //*
198 
199 
200  //* Simple way to add daughter ex. D0+= Pion;
201 
202  void operator +=( const KFParticleBaseSIMD &Daughter );
203 
204  //* Add daughter track to the particle
205 
206  void AddDaughter( const KFParticleBaseSIMD &Daughter );
207  void SubtractDaughter( const KFParticleBaseSIMD &Daughter );
208 
209  void AddDaughterWithEnergyFit( const KFParticleBaseSIMD &Daughter );
210  void AddDaughterWithEnergyFitMC( const KFParticleBaseSIMD &Daughter );
211  //with mass constrained
212 
213  //* Set production vertex
214 
215  void SetProductionVertex( const KFParticleBaseSIMD &Vtx );
216 
217  //* Set mass constraint
218 
219  void SetNonlinearMassConstraint( float_v Mass );
220  void SetMassConstraint( float_v Mass, float_v SigmaMass = float_v(0.f) );
221 
222  //* Set no decay length for resonances
223 
224  void SetNoDecayLength();
225 
226 
227  //* Everything in one go
228 
229  void Construct( const KFParticleBaseSIMD *vDaughters[], Int_t nDaughters, const KFParticleBaseSIMD *ProdVtx=0, Float_t Mass=-1 );
230 
231 
232  //*
233  //* TRANSPORT
234  //*
235  //* ( main transportation parameter is S = SignedPath/Momentum )
236  //* ( parameters of decay & production vertices are stored locally )
237  //*
238 
239 
240  //* Transport the particle to its decay vertex
241 
242  void TransportToDecayVertex();
243 
244  //* Transport the particle to its production vertex
245 
247 
248  //* Transport the particle on dS parameter (SignedPath/Momentum)
249 
250  void TransportToDS( float_v dS, const float_v* dsdr );
251  void TransportToDSLine( float_v dS, const float_v* dsdr );
252  //* Particular extrapolators one can use
253  void TransportBz( float_v Bz, float_v dS, const float_v* dsdr, float_v P[], float_v C[], float_v* dsdr1=0, float_v* F=0, float_v* F1=0 ) const;
254  void TransportBz( float_v Bz, float_v dS, float_v P[] ) const;
255  void TransportCBM( float_v dS, const float_v* dsdr, float_v P[], float_v C[], float_v* dsdr1=0, float_v* F=0, float_v* F1=0 ) const;
256  void TransportCBM( float_v dS, float_v P[] ) const;
257 
258  //*
259  //* OTHER UTILITIES
260  //*
261 
262  //* Calculate distance from another object [cm]
263 
264  float_v GetDistanceFromVertex( const float_v vtx[] ) const;
265  float_v GetDistanceFromVertex( const KFParticleBaseSIMD &Vtx ) const;
266  float_v GetDistanceFromParticle( const KFParticleBaseSIMD &p ) const;
267 
268  //* Calculate CAMath::Sqrt(Chi2/ndf) deviation from vertex
269  //* v = [xyz], Cv=[Cxx,Cxy,Cyy,Cxz,Cyz,Czz]-covariance matrix
270 
271  float_v GetDeviationFromVertex( const float_v v[],
272  const float_v Cv[]=0 ) const;
273  float_v GetDeviationFromVertex( const KFParticleBaseSIMD &Vtx ) const;
274  float_v GetDeviationFromParticle( const KFParticleBaseSIMD &p ) const;
275 
276  //* Subtract the particle from the vertex
277 
278  void SubtractFromVertex( KFParticleBaseSIMD &Vtx ) const;
279  void SubtractFromParticle( KFParticleBaseSIMD &Vtx ) const;
280 
281  static void GetArmenterosPodolanski(KFParticleBaseSIMD& positive, KFParticleBaseSIMD& negative, float_v QtAlfa[2] );
282  void RotateXY(float_v angle, float_v Vtx[3]);
283 
284  int_v Id() const { return fId; }
285  int NDaughters() const { return fDaughterIds.size(); }
286  std::vector<int_v> & DaughterIds() { return fDaughterIds; }
287  int_v GetDaughterId(int iD) const { return fDaughterIds[iD]; }
288 
289  void SetId( int_v id ){ fId = id; }
290  void SetNDaughters( int n ) { fDaughterIds.reserve(n); }
291  void AddDaughterId( int_v id ){ fDaughterIds.push_back(id); }
292  void CleanDaughtersId() { fDaughterIds.clear(); }
293 
294  void SetPDG ( int pdg ) { fPDG = pdg; }
295  void SetPDG ( int_v& pdg ) { fPDG = pdg; }
296  const int_v& GetPDG () const { return fPDG; }
297  const int_v& PDG () const { return fPDG; }
298 
299  void GetDistanceToVertexLine( const KFParticleBaseSIMD &Vertex, float_v &l, float_v &dl, float_m *isParticleFromVertex = 0 ) const;
300 
301  static void MultQSQt( const float_v Q[], const float_v S[], float_v SOut[], const int kN );
302 
303  protected:
305  static Int_t IJ( Int_t i, Int_t j ){
306  return ( j<=i ) ? i*(i+1)/2+j :j*(j+1)/2+i;
307  }
309  float_v & Cij( Int_t i, Int_t j ){ return fC[IJ(i,j)]; }
310 
311  void TransportLine( float_v S, const float_v* dsdr, float_v P[], float_v C[], float_v* dsdr1=0, float_v* F=0, float_v* F1=0 ) const ;
312  void TransportLine( float_v S, float_v P[] ) const ;
313 
314  static void InvertCholetsky3(float_v a[6]);
315 
316  void GetMeasurement( const KFParticleBaseSIMD& daughter, float_v m[], float_v V[], float_v D[3][3] ) ;
317 
318  //* Mass constraint function. is needed for the nonlinear mass constraint and a fit with mass constraint
319  void SetMassConstraint( float_v *mP, float_v *mC, float_v mJ[7][7], float_v mass, float_m mask );
320 
321  float_v fP[8];
322  float_v fC[36];
323  int_v fQ;
324  int_v fNDF;
325  float_v fChi2;
326  float_v fSFromDecay;
327  float_v SumDaughterMass;
328  float_v fMassHypo;
329  int_v fId;
331  int_v fPDG;
332 
341  std::vector<int_v> fDaughterIds; // id of particles it created from. if size == 1 then this is id of track.
342 
343 } __attribute__((aligned(sizeof(float_v))));
344 
345 #endif