Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KFParticleTest.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file KFParticleTest.cxx
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 #include "KFParticle.h"
23 #include "KFPTrack.h"
24 #include "KFPVertex.h"
25 #include "KFParticleSIMD.h"
26 #include "KFParticleTest.h"
27 
28 #include <iostream>
29 #include <iomanip>
30 #include <cmath>
31 
32 #ifndef KFParticleStandalone
34 #endif
35 
36 std::ostream& operator<<(std::ostream& os, const KFParticleBase& particle) {
37  static const char *vn[14] = {"x","y","z","px","py","pz","E","S","M","t","p","Q","Chi2","NDF"};
38 
39  for (Int_t i = 0; i < 8; i++) {
40  if (i == 6) continue; // E
41  if (i == 7 && particle.GetParameter(i) <= 0.0) continue; // S
42  if (particle.GetParameter(i) == 0. && particle.GetCovariance(i,i) == 0) continue;
43  if (particle.GetCovariance(i,i) > 0)
44  os << " " << vn[i]<<": "<< std::setw(8) << particle.GetParameter(i)<< " +/- " << std::setw(6) << sqrt(particle.GetCovariance(i,i));
45  else
46  os << " " << vn[i] << ": " << std::setw(8) << particle.GetParameter(i);
47  }
48  float Mtp[3], MtpErr[3];
49  particle.GetMass(Mtp[0], MtpErr[0]); if (MtpErr[0] < 1e-7 || MtpErr[0] > 1e10) MtpErr[0] = -13;
50  particle.GetLifeTime(Mtp[1], MtpErr[1]); if (MtpErr[1] <= 0 || MtpErr[1] > 1e10) MtpErr[1] = -13;
51  particle.GetMomentum(Mtp[2], MtpErr[2]); if (MtpErr[2] <= 0 || MtpErr[2] > 1e10) MtpErr[2] = -13;
52  for (Int_t i = 8; i < 11; i++) {
53  if (i == 9 && Mtp[i-8] <= 0.0) continue; // t
54  if (MtpErr[i-8] > 0 && MtpErr[i-8] < 1e10) os << " " << vn[i] << ": " << std::setw(8) << Mtp[i-8] << " +/-" << std::setw(7) << MtpErr[i-8];
55  else os << " " << vn[i] << ": " << std::setw(8) << Mtp[i-8];
56  }
57  os << " pdg:" << std::setw(5) << particle.GetPDG() << " Q: "<< std::setw(2) << int(particle.GetQ()) << " chi2/NDF: " << std::setw(8) << particle.GetChi2() << "/" << std::setw(2) << particle.GetNDF();
58  return os;
59 }
60 
61 KFParticleTest::KFParticleTest():fMotherSingle(0),fMotherSIMD(0)
62 {
63  fMotherSingle = new KFParticle();
65 }
66 
68 {
69  if(fMotherSingle) delete fMotherSingle;
70  if(fMotherSIMD) delete fMotherSIMD;
71 }
72 
74 {
75  RunTestSingle();
76  RunTestSIMD();
77 }
78 
80 {
81  std::cout.setf(std::ios::fixed);
82  std::cout.setf(std::ios::showpoint);
83  std::cout.precision(3);
84 
85  std::cout << "Try different constructors" << std::endl<< std::endl;
86  std::cout << "1. Construction from Vertex" << std::endl<< std::endl;
87  KFPVertex vert;
88  vert.SetXYZ(0.0, 0.0, 10.0);
89  vert.SetCovarianceMatrix( 0.01,
90  0.00, 0.01,
91  0.00, 0.00, 0.01 );
92  vert.SetNContributors(2);
93  vert.SetChi2(1.01);
94 
95  KFParticle p1(vert);
96  std::cout << "Vertex Particle p1" << std::endl << " " << p1 << std::endl;
97 
99 
100 #ifdef HomogeneousField
101  KFParticle::SetField(4.9797992706298828);
102 #endif
103  float point[3]={0.f};
104  float b[3] = {0.f};
105  p1.GetFieldValue(point,b);
106  std::cout << "Set Field " << std::setw(6) << b[2] << std::endl;
107 
108  std::cout << std::endl << "2. Construction from Track" << std::endl<< std::endl;
109 
110  KFPTrack track;
111  track.SetParameters(-0.061996019110347252, -1.3579236865955473, 27.147283554077148,
112  0.62539337626870062, -0.028552340672283318, -0.18467358509984011);
113  float C[21]= {3.3055800809774214e-05,
114  0.00098316976438185002, 0.04740889543423539,
115  -8.5596097466772512e-05, -0.0037516094381694971, 0.032156504690647125,
116  -2.2812597903705375e-05, -0.0012121012247057524, 3.0646383360925928e-05, 6.1388628418184652e-05,
117  -4.4071909055788304e-06,-0.00048870318030618627, 3.8062554692505919e-05, 1.2177141510445709e-05, 7.6900178535210476e-06,
118  6.6224441962932268e-06, 0.00034363110217286891, -0.00031520420397528146,-1.6277704753223909e-05,-3.4322154557097545e-06, 1.027411488502718e-05};
119  track.SetCovarianceMatrix(C);
120  track.SetNDF(1);
121  track.SetChi2(1.5);
122  track.SetCharge(-1);
123 
124  KFParticle p2(track, -211);
125 
126  std::cout << "Track Particle p2" << std::endl <<" "<< p2 << std::endl;
127 
129 
130  std::cout << std::endl << "3. Now we will create one more particle from track and call the construction from these 2 particles" << std::endl<< std::endl;
131 
132  KFPTrack track2;
133  track2.SetParameters(-0.20371287092090862, 3.0678058943547839, -19.93988037109375,
134  0.37533048135363339, 0.024923235867488316, 0.19031024520542122);
135  float C2[21]=
136  { 0.00022312908970259721,
137  -0.00064291160449645151, 0.089331037457232143,
138  0.00047880877483649206, -0.045478494677353445, 0.11199165135622025,
139  4.6362085390124077e-07, 0.00070978326424729935, -0.00014164977426380486, 1.7553871209443515e-05,
140  -2.2044831998838091e-05,-0.00059994741249631909, 0.00030148707952079015,-4.6574515272730461e-06, 7.2618497455845866e-06,
141  -1.2427988441207971e-06, 0.00030830063771211896, -0.00061853865528922161, 5.4390968700069889e-06,-1.9914477627292868e-06, 8.9837108094398403e-06};
142 
143  track2.SetCovarianceMatrix(C2);
144  track2.SetNDF(2);
145  track2.SetChi2(2.5);
146  track2.SetCharge(+1);
147  KFParticle p3(track2, 211); // PDG = 11
148  std::cout << "Track Particle p3 " << std::endl <<" "<< p3 << std::endl;
149 
150  KFParticle p4(p2, p3);
151  std::cout << "Particle p4(p2,p3)" << std::endl << " " << p4 << std::endl;
152 
154  std::cout << std::endl << "4. Construction with constrained Mass or (and) vertex position values" << std::endl<< std::endl;
155 
161 
162  const KFParticle pVertex = p1;
163  int NDaughters = 2;
164  const KFParticle *vDaughters[2] = {&p2, &p3};
165 
166  Double_t Mass = 0.497614;
167 
168  std::cout << "4.1 Construction with constrained Mass, without vertex hypothesis " << std::endl<< std::endl;
170  KFParticle K0;
171  K0.Construct(vDaughters,NDaughters,0,Mass);
172  std::cout << "Dauthers" << std::endl
173  << " " << *vDaughters[0] << std::endl
174  << " " << *vDaughters[1] << std::endl
175  << "Mass " << Mass << std::endl;
176  std::cout << "Particle K0" << std::endl << K0 << std::endl;
177  K0.SetProductionVertex(pVertex);
178  std::cout << " Add parent Vertex" << std::endl;
179  std::cout << " K0 with vertex " << K0 << std::endl;
180  std::cout << std::endl << "4.2 Construction without constrained Mass, with vertex hypothesis " << std::endl<< std::endl;
182  KFParticle K0_1;
183  K0_1.Construct(vDaughters,NDaughters,&pVertex,-1);
184 
185  std::cout << "Dauthers" << std::endl
186  << " " << *vDaughters[0] << std::endl
187  << " " << *vDaughters[1] << std::endl
188  << "PV " << std::endl << " " << pVertex << std::endl;
189  std::cout << "K0_1" << std::endl <<" " << K0_1 << std::endl;
190  std::cout << std::endl << "4.3 Construction with constrained Mass, with vertex hypothesis " << std::endl<< std::endl;
192  KFParticle K0_2;
193  K0_2.Construct(vDaughters,NDaughters,&pVertex,Mass);
194 
195  std::cout << "Dauthers" << std::endl
196  << " " << *vDaughters[0] << std::endl
197  << " " << *vDaughters[1] << std::endl
198  << "PV " << std::endl << " " << pVertex << std::endl
199  << "Mass " << Mass << std::endl;
200  std::cout << "K0_2" << std::endl << " " << K0_2 << std::endl;
201 
202  std::cout << std::endl << "4.4 Construction K0_3(p2,p3) without constrained Mass, without vertex hypothesis " << std::endl<< std::endl;
204  KFParticle K0_3;
205  K0_3.Construct(vDaughters,NDaughters,0,-1);
206 
207  std::cout << "Dauthers" << std::endl
208  << " " << *vDaughters[0] << std::endl
209  << " " << *vDaughters[1] << std::endl;
210  std::cout << "K0_3" << std::endl << " " << K0_3 << std::endl;
211 }
212 
214 {
215 }
216 
218 {
219 }
220 
222 {
223 }