Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:18

0001 /*
0002  * This file is part of KFParticle package
0003  * Copyright (C) 2007-2019 FIAS Frankfurt Institute for Advanced Studies
0004  *               2007-2019 Goethe University of Frankfurt
0005  *               2007-2019 Ivan Kisel <I.Kisel@compeng.uni-frankfurt.de>
0006  *               2007-2019 Maksym Zyzak
0007  *
0008  * KFParticle is free software: you can redistribute it and/or modify
0009  * it under the terms of the GNU General Public License as published by
0010  * the Free Software Foundation, either version 3 of the License, or
0011  * (at your option) any later version.
0012  *
0013  * KFParticle is distributed in the hope that it will be useful,
0014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0016  * GNU General Public License for more details.
0017  *
0018  * You should have received a copy of the GNU General Public License
0019  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
0020  */
0021 
0022 #include "KFParticle.h"
0023 #include "KFPTrack.h"
0024 #include "KFPVertex.h"
0025 #include "KFParticleSIMD.h"
0026 #include "KFParticleTest.h"
0027 
0028 #include <iostream>
0029 #include <iomanip>
0030 #include <cmath>
0031 
0032 #ifndef KFParticleStandalone
0033 ClassImp(KFParticleTest)
0034 #endif
0035 
0036 std::ostream&  operator<<(std::ostream& os, const KFParticleBase& particle) {
0037   static const char *vn[14] = {"x","y","z","px","py","pz","E","S","M","t","p","Q","Chi2","NDF"};
0038 
0039   for (Int_t i = 0; i < 8; i++) {
0040     if (i == 6) continue;                                    // E
0041     if (i == 7 && particle.GetParameter(i) <= 0.0) continue; // S
0042     if (particle.GetParameter(i) == 0. && particle.GetCovariance(i,i) == 0) continue;
0043     if (particle.GetCovariance(i,i) > 0) 
0044       os << " " << vn[i]<<": "<< std::setw(8) << particle.GetParameter(i)<< " +/- " << std::setw(6) << sqrt(particle.GetCovariance(i,i));
0045     else 
0046       os << " " << vn[i] << ": " << std::setw(8) << particle.GetParameter(i);
0047   }
0048   float Mtp[3], MtpErr[3];
0049   particle.GetMass(Mtp[0], MtpErr[0]);     if (MtpErr[0] < 1e-7 || MtpErr[0] > 1e10) MtpErr[0] = -13;
0050   particle.GetLifeTime(Mtp[1], MtpErr[1]); if (MtpErr[1] <=   0 || MtpErr[1] > 1e10) MtpErr[1] = -13;
0051   particle.GetMomentum(Mtp[2], MtpErr[2]); if (MtpErr[2] <=   0 || MtpErr[2] > 1e10) MtpErr[2] = -13;
0052   for (Int_t i = 8; i < 11; i++) {
0053     if (i == 9 && Mtp[i-8] <= 0.0) continue; // t
0054     if (MtpErr[i-8] > 0 && MtpErr[i-8] < 1e10) os << " " << vn[i] << ": " << std::setw(8) << Mtp[i-8] << " +/-" << std::setw(7) << MtpErr[i-8];
0055     else                                       os << " " << vn[i] << ": " << std::setw(8) << Mtp[i-8];
0056   }
0057   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();
0058   return os;
0059 }
0060 
0061 KFParticleTest::KFParticleTest():fMotherSingle(0),fMotherSIMD(0)
0062 {
0063   fMotherSingle = new KFParticle();
0064   fMotherSIMD = new KFParticleSIMD();
0065 }
0066 
0067 KFParticleTest::~KFParticleTest()
0068 {
0069   if(fMotherSingle) delete fMotherSingle;
0070   if(fMotherSIMD) delete fMotherSIMD;
0071 }
0072 
0073 void KFParticleTest::RunTest() 
0074 {
0075   RunTestSingle();
0076   RunTestSIMD();
0077 }
0078 
0079 void KFParticleTest::RunTestSingle()
0080 {
0081   std::cout.setf(std::ios::fixed);
0082   std::cout.setf(std::ios::showpoint);
0083   std::cout.precision(3);
0084     
0085   std::cout << "Try different constructors" << std::endl<< std::endl;
0086   std::cout << "1. Construction from Vertex" << std::endl<< std::endl;
0087   KFPVertex vert;
0088   vert.SetXYZ(0.0, 0.0, 10.0);
0089   vert.SetCovarianceMatrix( 0.01,
0090                             0.00,  0.01,
0091                             0.00,  0.00, 0.01 );
0092   vert.SetNContributors(2);
0093   vert.SetChi2(1.01);
0094   
0095   KFParticle p1(vert);
0096   std::cout << "Vertex Particle p1" << std::endl << "  " << p1 << std::endl;
0097 
0098   ///  *****************************************************************************************
0099   
0100 #ifdef HomogeneousField  
0101   KFParticle::SetField(4.9797992706298828);
0102 #endif
0103   float point[3]={0.f};
0104   float b[3] = {0.f};
0105   p1.GetFieldValue(point,b);
0106   std::cout << "Set Field " <<  std::setw(6) << b[2] << std::endl;
0107   
0108   std::cout << std::endl << "2. Construction from Track" << std::endl<< std::endl;
0109   
0110   KFPTrack track;
0111   track.SetParameters(-0.061996019110347252, -1.3579236865955473,   27.147283554077148, 
0112                    0.62539337626870062,  -0.028552340672283318, -0.18467358509984011);
0113   float C[21]= {3.3055800809774214e-05, 
0114            0.00098316976438185002,    0.04740889543423539, 
0115           -8.5596097466772512e-05, -0.0037516094381694971,    0.032156504690647125, 
0116           -2.2812597903705375e-05, -0.0012121012247057524,  3.0646383360925928e-05, 6.1388628418184652e-05, 
0117           -4.4071909055788304e-06,-0.00048870318030618627,  3.8062554692505919e-05, 1.2177141510445709e-05, 7.6900178535210476e-06, 
0118            6.6224441962932268e-06, 0.00034363110217286891, -0.00031520420397528146,-1.6277704753223909e-05,-3.4322154557097545e-06, 1.027411488502718e-05};
0119   track.SetCovarianceMatrix(C);
0120   track.SetNDF(1);
0121   track.SetChi2(1.5);
0122   track.SetCharge(-1);
0123   
0124   KFParticle p2(track, -211);
0125   
0126   std::cout << "Track Particle p2" << std::endl <<"  "<< p2 << std::endl;
0127   
0128   ///  *****************************************************************************************
0129   
0130   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;
0131   
0132   KFPTrack track2;
0133   track2.SetParameters(-0.20371287092090862,   3.0678058943547839,  -19.93988037109375, 
0134                 0.37533048135363339, 0.024923235867488316, 0.19031024520542122);
0135   float C2[21]=
0136     { 0.00022312908970259721, 
0137      -0.00064291160449645151,   0.089331037457232143, 
0138       0.00047880877483649206,  -0.045478494677353445,     0.11199165135622025, 
0139       4.6362085390124077e-07, 0.00070978326424729935, -0.00014164977426380486, 1.7553871209443515e-05, 
0140      -2.2044831998838091e-05,-0.00059994741249631909,  0.00030148707952079015,-4.6574515272730461e-06, 7.2618497455845866e-06, 
0141      -1.2427988441207971e-06, 0.00030830063771211896, -0.00061853865528922161, 5.4390968700069889e-06,-1.9914477627292868e-06, 8.9837108094398403e-06};
0142 
0143   track2.SetCovarianceMatrix(C2);
0144   track2.SetNDF(2);
0145   track2.SetChi2(2.5);
0146   track2.SetCharge(+1);
0147   KFParticle p3(track2, 211); // PDG = 11
0148   std::cout << "Track Particle p3 " << std::endl <<"  "<< p3 << std::endl;
0149   
0150   KFParticle p4(p2, p3);
0151   std::cout << "Particle p4(p2,p3)" << std::endl << "  " << p4 << std::endl;
0152 
0153   ///  *****************************************************************************************
0154   std::cout << std::endl << "4. Construction with constrained Mass or (and) vertex position values" << std::endl<< std::endl;
0155 
0156 /// This is the example of the KFParticleBase::Construct function usage.
0157 /// parameter 1 - array of the daughter particles
0158 /// parameter 2 - number of the daughter particles
0159 /// parameter 3 - vertex (it should be the object of the KFParticle class)
0160 /// parameter 4 - the value we force the particle mass to be equial to.
0161 
0162   const KFParticle pVertex = p1;
0163   int NDaughters = 2;
0164   const KFParticle *vDaughters[2] = {&p2, &p3};
0165   
0166   Double_t Mass = 0.497614;
0167   
0168   std::cout << "4.1 Construction with constrained Mass, without vertex hypothesis " << std::endl<< std::endl;
0169 /// we assume Mass to be the mass of the constructed particle
0170   KFParticle K0;
0171   K0.Construct(vDaughters,NDaughters,0,Mass);
0172   std::cout << "Dauthers" << std::endl
0173         << "  " << *vDaughters[0] << std::endl
0174         << "  " << *vDaughters[1] << std::endl
0175         << "Mass    " << Mass << std::endl;
0176   std::cout << "Particle K0" << std::endl << K0 << std::endl;
0177   K0.SetProductionVertex(pVertex);
0178   std::cout << " Add parent Vertex" << std::endl;
0179   std::cout << " K0 with vertex  " << K0 << std::endl;
0180   std::cout << std::endl << "4.2 Construction without constrained Mass, with vertex hypothesis " << std::endl<< std::endl;
0181 /// we assume p1 to be the vertex of the constructed particle
0182   KFParticle K0_1;
0183   K0_1.Construct(vDaughters,NDaughters,&pVertex,-1);
0184 
0185   std::cout << "Dauthers" << std::endl
0186         << "  " << *vDaughters[0] << std::endl
0187         << "  " << *vDaughters[1] << std::endl
0188         << "PV " << std::endl << "  " << pVertex        << std::endl;
0189   std::cout << "K0_1" << std::endl <<"  " << K0_1 << std::endl;
0190   std::cout << std::endl << "4.3 Construction with constrained Mass, with vertex hypothesis " << std::endl<< std::endl;
0191 ///we assume p1 to be the vertex of the constructed particle, Mass to be the mass of the constructed particle
0192   KFParticle K0_2;
0193   K0_2.Construct(vDaughters,NDaughters,&pVertex,Mass);
0194 
0195   std::cout << "Dauthers" << std::endl
0196         << "  " << *vDaughters[0] << std::endl
0197         << "  " << *vDaughters[1] << std::endl
0198         << "PV " << std::endl << "  " << pVertex        << std::endl
0199         << "Mass    " << Mass << std::endl;
0200   std::cout << "K0_2" << std::endl <<  "  " << K0_2 << std::endl;
0201 
0202   std::cout << std::endl << "4.4 Construction K0_3(p2,p3) without constrained Mass, without vertex hypothesis " << std::endl<< std::endl;
0203 ///we assume p1 to be the vertex of the constructed particle, Mass to be the mass of the constructed particle
0204   KFParticle K0_3;
0205   K0_3.Construct(vDaughters,NDaughters,0,-1);
0206 
0207   std::cout << "Dauthers" << std::endl
0208        << "  " << *vDaughters[0] << std::endl
0209        << "  " << *vDaughters[1] << std::endl;
0210   std::cout << "K0_3" << std::endl << "  " <<  K0_3 << std::endl;
0211 }
0212 
0213 void KFParticleTest::RunTestSIMD()
0214 {
0215 }
0216 
0217 void KFParticleTest::CompareSingleAndSIMDResults()
0218 {
0219 }
0220 
0221 void KFParticleTest::PrintTutorial()
0222 {
0223 }