Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KFPTrackVector.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file KFPTrackVector.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 #ifndef KFPTrackVector_H
23 #define KFPTrackVector_H
24 
25 #include "KFPTrack.h"
26 #include "KFParticleDef.h"
27 
50 {
52  public:
53  KFPTrackVector():fId(), fPDG(), fQ(), fPVIndex(), fNPixelHits(), fNE(0), fNMu(0), fNPi(0), fNK(0), fNP(0), fND(0), fNT(0), fNHe3(0), fNHe4(0) { }
55 
57  int Size() const { return fP[0].size(); }
58  int DataSize() const {
60  const int& size = fP[0].size();
61 
62  const int dataSize = size * 32
63 #ifdef NonhomogeneousField
64  + size * 10
65 #endif
66  + 9;
67  return dataSize;
68  }
69 
70  void Resize(const int n);
71  void Set(KFPTrackVector& v, int vSize, int offset);
72  void SetTracks(const KFPTrackVector& track, const kfvector_uint& trackIndex, const int nIndexes);
73  void GetTrack(KFPTrack& track, const int n);
74 
75  const kfvector_float& X() const { return fP[0]; }
76  const kfvector_float& Y() const { return fP[1]; }
77  const kfvector_float& Z() const { return fP[2]; }
78  const kfvector_float& Px() const { return fP[3]; }
79  const kfvector_float& Py() const { return fP[4]; }
80  const kfvector_float& Pz() const { return fP[5]; }
81 
82  const kfvector_float& Parameter(const int i) const { return fP[i]; }
83  const kfvector_float& Covariance(const int i) const { return fC[i]; }
84 #ifdef NonhomogeneousField
85  const kfvector_float& FieldCoefficient(const int i) const { return fField[i]; }
86 #endif
87 
88  const kfvector_int& Id() const { return fId; }
89  const kfvector_int& PDG() const { return fPDG; }
90  const kfvector_int& Q() const { return fQ; }
91  const kfvector_int& PVIndex() const { return fPVIndex; }
92  const kfvector_int& NPixelHits() const { return fNPixelHits; }
93 
94  float Pt(const int n) const { return sqrt(fP[3][n]*fP[3][n]+fP[4][n]*fP[4][n]); }
95  float P(const int n) const { return sqrt(fP[3][n]*fP[3][n]+fP[4][n]*fP[4][n]+fP[5][n]*fP[5][n]); }
96 
97  //modifiers
98  void SetParameter (float value, int iP, int iTr) { fP[iP][iTr] = value; }
99  void SetCovariance(float value, int iC, int iTr) { fC[iC][iTr] = value; }
100 
101  void SetParameter (const float_v& value, int iP, int iTr);
102  void SetCovariance(const float_v& value, int iC, int iTr);
103 
104 #ifdef NonhomogeneousField
105  void SetFieldCoefficient(float value, int iP, int iTr) { fField[iP][iTr] = value; }
106 #endif
107  void SetId (int value, int iTr) { fId[iTr] = value; }
108  void SetPDG (int value, int iTr) { fPDG[iTr] = value; }
109  void SetQ (int value, int iTr) { fQ[iTr] = value; }
110  void SetPVIndex (int value, int iTr) { fPVIndex[iTr] = value; }
111  void SetNPixelHits (int value, int iTr) { fNPixelHits[iTr] = value; }
112  void SetLastElectron(int n) { fNE = n; }
113  void SetLastMuon (int n) { fNMu = n; }
114  void SetLastPion (int n) { fNPi = n; }
115  void SetLastKaon (int n) { fNK = n; }
116  void SetLastProton (int n) { fNP = n; }
117  void SetLastDeuteron(int n) { fND = n; }
118  void SetLastTritium (int n) { fNT = n; }
119  void SetLastHe3 (int n) { fNHe3 = n; }
120  void SetLastHe4 (int n) { fNHe4 = n; }
121 
123  {
125  fNE = 0; fNMu = 0; fNPi = 0; fNK = 0; fNP = 0; fND = 0; fNT = 0; fNHe3 = 0; fNHe4 = 0;
126  for(int i=0; i<Size(); i++)
127  {
128  switch (abs(fPDG[i]))
129  {
130  case 11: fNE++; break;
131  case 13: fNMu++; break;
132  case 19: fNMu++; break;
133  case 211: fNPi++; break;
134  case 1: fNPi++; break;
135  case 3: fNPi++; break;
136  case 321: fNK++; break;
137  case 2212: fNP++; break;
138  case 1000010020: fND++; break;
139  case 1000010030: fNT++; break;
140  case 1000020030: fNHe3++; break;
141  case 1000020040: fNHe4++; break;
142  }
143  }
144 
145  fNMu += fNE; fNPi += fNMu; fNK += fNPi; fNP += fNK;
146  fND += fNP; fNT += fND; fNHe3 += fNT; fNHe4 += fNHe3;
147  }
148 
149  int FirstElectron() { return 0; }
150  const int& LastElectron() const { return fNE; }
151  int NElectrons() { return fNE; }
152  int FirstMuon() { return int(fNE/float_vLen)*float_vLen; }
153  const int& LastMuon() const { return fNMu; }
154  int NMuons() { return fNMu - fNE; }
155  int FirstPion() { return int(fNMu/float_vLen)*float_vLen; }
156  const int& LastPion() const { return fNPi; }
157  int NPions() { return fNPi - fNMu; }
158  int FirstKaon() { return int(fNPi/float_vLen)*float_vLen; }
159  const int& LastKaon() const { return fNK; }
160  int NKaons() { return fNK - fNPi; }
161  int FirstProton() { return int(fNK/float_vLen)*float_vLen; }
162  const int& LastProton() const { return fNP; }
163  int NProtons() { return fNP - fNK; }
164  int FirstDeuteron() { return int(fNP/float_vLen)*float_vLen; }
165  const int& LastDeuteron() const { return fND; }
166  int NDeuterons() { return fND - fNP; }
167  int FirstTritium() { return int(fND/float_vLen)*float_vLen; }
168  const int& LastTritium() const { return fNT; }
169  int NTritiums() { return fNT - fND; }
170  int FirstHe3() { return int(fNT/float_vLen)*float_vLen; }
171  const int& LastHe3() const { return fNHe3; }
172  int NHe3s() { return fNHe3 - fNT; }
173  int FirstHe4() { return int(fNHe3/float_vLen)*float_vLen; }
174  const int& LastHe4() const { return fNHe4; }
175  int NHe4s() { return fNHe4 - fNHe3; }
176 
177  void AddElectron() {fNE++;}
178  void AddMuon() {fNMu++;}
179  void AddPion() {fNPi++;}
180  void AddKaon() {fNK++;}
181  void AddProton() {fNP++;}
182  void AddDeuteron() {fND++;}
183  void AddTririum() {fNT++;}
184  void AddHe3() {fNHe3++;}
185  void AddHe4() {fNHe4++;}
186 
187  void RotateXY( float_v alpha, int firstElement );
188 
189  void PrintTrack(int n);
190  void Print();
191 
193  {
195  const int localSize = track.Size();
196 
197  for(int i=0; i<6; i++)
198  {
199  fP[i].resize(localSize);
200  for(int n=0; n<localSize; n++)
201  fP[i][n] = track.fP[i][n];
202  }
203 
204  for(int i=0; i<21; i++)
205  {
206  fC[i].resize(localSize);
207  for(int n=0; n<localSize; n++)
208  fC[i][n] = track.fC[i][n];
209  }
210 
211 #ifdef NonhomogeneousField
212  for(int i=0; i<10; i++)
213  {
214  fField[i].resize(localSize);
215  for(int n=0; n<localSize; n++)
216  fField[i][n] = track.fField[i][n];
217  }
218 #endif
219 
220  fId.resize(localSize);
221  for(int n=0; n<localSize; n++)
222  fId[n] = track.fId[n];
223 
224  fPDG.resize(localSize);
225  for(int n=0; n<localSize; n++)
226  fPDG[n] = track.fPDG[n];
227 
228  fQ.resize(localSize);
229  for(int n=0; n<localSize; n++)
230  fQ[n] = track.fQ[n];
231 
232  fPVIndex.resize(localSize);
233  for(int n=0; n<localSize; n++)
234  fPVIndex[n] = track.fPVIndex[n];
235 
236  fNPixelHits.resize(localSize);
237  for(int n=0; n<localSize; n++)
238  fNPixelHits[n] = track.fNPixelHits[n];
239 
240  fNE = track.fNE;
241  fNMu = track.fNMu;
242  fNPi = track.fNPi;
243  fNK = track.fNK;
244  fNP = track.fNP;
245  fND = track.fND;
246  fNT = track.fNT;
247  fNHe3 = track.fNHe3;
248  fNHe4 = track.fNHe4;
249 
250  return *this;
251  }
252 
253  void SetDataToVector(int* data, int& offset)
254  {
263  for(int iP=0; iP<6; iP++)
264  {
265  memcpy( &(data[offset]), &(fP[iP][0]), Size()*sizeof(float));
266  offset += Size();
267  }
268 
269  for(int iC=0; iC<21; iC++)
270  {
271  memcpy( &(data[offset]), &(fC[iC][0]), Size()*sizeof(float));
272  offset += Size();
273  }
274 
275  memcpy( &(data[offset]), &(fId[0]), Size()*sizeof(float));
276  offset += Size();
277 
278  memcpy( &(data[offset]), &(fPDG[0]), Size()*sizeof(float));
279  offset += Size();
280 
281  memcpy( &(data[offset]), &(fQ[0]), Size()*sizeof(float));
282  offset += Size();
283 
284  memcpy( &(data[offset]), &(fPVIndex[0]), Size()*sizeof(float));
285  offset += Size();
286 
287  memcpy( &(data[offset]), &(fNPixelHits[0]), Size()*sizeof(float));
288  offset += Size();
289 
290 #ifdef NonhomogeneousField
291  for(int iF=0; iF<10; iF++)
292  {
293  memcpy( &(data[offset]), &(fField[iF][0]), Size()*sizeof(float));
294  offset += Size();
295  }
296 #endif
297 
298  data[offset] = fNE; offset++;
299  data[offset] = fNMu; offset++;
300  data[offset] = fNPi; offset++;
301  data[offset] = fNK; offset++;
302  data[offset] = fNP; offset++;
303  data[offset] = fND; offset++;
304  data[offset] = fNT; offset++;
305  data[offset] = fNHe3; offset++;
306  data[offset] = fNHe4; offset++;
307  }
308 
309  void ReadDataFromVector(int* data, int& offset)
310  {
319  for(int iP=0; iP<6; iP++)
320  {
321  memcpy( &(fP[iP][0]), &(data[offset]), Size()*sizeof(float));
322  offset += Size();
323  }
324 
325  for(int iC=0; iC<21; iC++)
326  {
327  memcpy( &(fC[iC][0]), &(data[offset]), Size()*sizeof(float));
328  offset += Size();
329  }
330 
331  memcpy( &(fId[0]), &(data[offset]), Size()*sizeof(float));
332  offset += Size();
333 
334  memcpy( &(fPDG[0]), &(data[offset]), Size()*sizeof(float));
335  offset += Size();
336 
337  memcpy( &(fQ[0]), &(data[offset]), Size()*sizeof(float));
338  offset += Size();
339 
340  memcpy( &(fPVIndex[0]), &(data[offset]), Size()*sizeof(float));
341  offset += Size();
342 
343  memcpy( &(fNPixelHits[0]), &(data[offset]), Size()*sizeof(float));
344  offset += Size();
345 
346 #ifdef NonhomogeneousField
347  for(int iF=0; iF<10; iF++)
348  {
349  memcpy( &(fField[iF][0]), &(data[offset]), Size()*sizeof(float));
350  offset += Size();
351  }
352 #endif
353 
354  fNE = data[offset]; offset++;
355  fNMu = data[offset]; offset++;
356  fNPi = data[offset]; offset++;
357  fNK = data[offset]; offset++;
358  fNP = data[offset]; offset++;
359  fND = data[offset]; offset++;
360  fNT = data[offset]; offset++;
361  fNHe3 = data[offset]; offset++;
362  fNHe4 = data[offset]; offset++;
363  }
364 
365  void *operator new(size_t size) { return _mm_malloc(size, sizeof(float_v)); }
366  void *operator new[](size_t size) { return _mm_malloc(size, sizeof(float_v)); }
367  void *operator new(size_t size, void *ptr) { return ::operator new(size, ptr);}
368  void *operator new[](size_t size, void *ptr) { return ::operator new(size, ptr);}
369  void operator delete(void *ptr, size_t) { _mm_free(ptr); }
370  void operator delete[](void *ptr, size_t) { _mm_free(ptr); }
371 
372  private:
375 
381 
391 #ifdef NonhomogeneousField
392  kfvector_float fField[10];
393 #endif
394 
395  int fNE;
396  int fNMu;
397  int fNPi;
398  int fNK;
399  int fNP;
400  int fND;
401  int fNT;
402  int fNHe3;
403  int fNHe4;
404 } __attribute__((aligned(sizeof(float_v))));
406 #endif