1919#ifndef ALICE3_CORE_TRACKUTILITIES_H_
2020#define ALICE3_CORE_TRACKUTILITIES_H_
2121
22+ #include < vector>
23+
2224#include " ReconstructionDataFormats/Track.h"
2325#include " Framework/O2DatabasePDGPlugin.h"
2426#include " Framework/AnalysisHelpers.h"
2729namespace o2 ::upgrade
2830{
2931
30- // / Function to convert a McParticle into a perfect Track
31- // / \param particle the particle to convert (mcParticle)
32+ // / Function to convert a TLorentzVector into a perfect Track
33+ // / \param charge particle charge (integer)
34+ // / \param particle the particle to convert (TLorentzVector)
35+ // / \param productionVertex where the particle was produced
3236// / \param o2track the address of the resulting TrackParCov
33- template < typename McParticleType>
34- void convertMCParticleToO2Track (McParticleType& particle,
35- o2::track::TrackParCov& o2track ,
36- const o2::framework::Service<o2::framework::O2DatabasePDG>& pdg )
37+ void convertTLorentzVectorToO2Track ( const int charge,
38+ const TLorentzVector particle,
39+ const std::vector< double > productionVertex ,
40+ o2::track::TrackParCov& o2track )
3741{
38- const auto pdgInfo = pdg->GetParticle (particle.pdgCode ());
39- int charge = 0 ;
40- if (pdgInfo != nullptr ) {
41- charge = pdgInfo->Charge () / 3 ;
42- }
4342 std::array<float , 5 > params;
4443 std::array<float , 15 > covm = {0 .};
4544 float s, c, x;
46- o2::math_utils::sincos (particle.phi ( ), s, c);
47- o2::math_utils::rotateZInv (particle. vx ( ), particle. vy ( ), x, params[0 ], s, c);
48- params[1 ] = particle. vz ( );
45+ o2::math_utils::sincos (static_cast < float >( particle.Phi () ), s, c);
46+ o2::math_utils::rotateZInv (static_cast < float >(productionVertex[ 0 ] ), static_cast < float >(productionVertex[ 1 ] ), x, params[0 ], s, c);
47+ params[1 ] = static_cast < float >(productionVertex[ 2 ] );
4948 params[2 ] = 0 .; // since alpha = phi
50- const auto theta = 2 . * std::atan (std::exp (-particle.eta ()));
49+ const auto theta = 2 . * std::atan (std::exp (-particle.PseudoRapidity ()));
5150 params[3 ] = 1 . / std::tan (theta);
52- params[4 ] = charge / particle.pt ();
51+ params[4 ] = charge / particle.Pt ();
5352
5453 // Initialize TrackParCov in-place
55- new (&o2track)(o2::track::TrackParCov)(x, particle.phi (), params, covm);
56- }
57-
58- // / Function to convert a McParticle into a perfect Track
59- // / \param particle the particle to convert (mcParticle)
60- // / \param o2track the address of the resulting TrackParCov
61- template <typename McParticleType>
62- o2::track::TrackParCov convertMCParticleToO2Track (McParticleType& particle,
63- const o2::framework::Service<o2::framework::O2DatabasePDG>& pdg)
64- {
65- o2::track::TrackParCov o2track;
66- return convertMCParticleToO2Track (particle, o2track, pdg);
54+ new (&o2track)(o2::track::TrackParCov)(x, particle.Phi (), params, covm);
6755}
6856
6957// / Function to convert a TLorentzVector into a perfect Track
7058// / \param pdgCode particle pdg
7159// / \param particle the particle to convert (TLorentzVector)
7260// / \param productionVertex where the particle was produced
7361// / \param o2track the address of the resulting TrackParCov
62+ // / \param pdg the pdg service
7463void convertTLorentzVectorToO2Track (int pdgCode,
7564 TLorentzVector particle,
7665 std::vector<double > productionVertex,
@@ -82,19 +71,35 @@ void convertTLorentzVectorToO2Track(int pdgCode,
8271 if (pdgInfo != nullptr ) {
8372 charge = pdgInfo->Charge () / 3 ;
8473 }
85- std::array<float , 5 > params;
86- std::array<float , 15 > covm = {0 .};
87- float s, c, x;
88- o2::math_utils::sincos (static_cast <float >(particle.Phi ()), s, c);
89- o2::math_utils::rotateZInv (static_cast <float >(productionVertex[0 ]), static_cast <float >(productionVertex[1 ]), x, params[0 ], s, c);
90- params[1 ] = static_cast <float >(productionVertex[2 ]);
91- params[2 ] = 0 ;
92- const auto theta = 2 . * std::atan (std::exp (-particle.PseudoRapidity ()));
93- params[3 ] = 1 . / std::tan (theta);
94- params[4 ] = charge / particle.Pt ();
74+ convertTLorentzVectorToO2Track (charge, particle, productionVertex, o2track);
75+ }
9576
96- // Initialize TrackParCov in-place
97- new (&o2track)(o2::track::TrackParCov)(x, particle.Phi (), params, covm);
77+ // / Function to convert a McParticle into a perfect Track
78+ // / \param particle the particle to convert (mcParticle)
79+ // / \param o2track the address of the resulting TrackParCov
80+ // / \param pdg the pdg service
81+ template <typename McParticleType>
82+ void convertMCParticleToO2Track (McParticleType& particle,
83+ o2::track::TrackParCov& o2track,
84+ const o2::framework::Service<o2::framework::O2DatabasePDG>& pdg)
85+ {
86+ static TLorentzVector tlv;
87+ tlv.SetPxPyPzE (particle.px (), particle.py (), particle.pz (), particle.e ());
88+ tlv.SetXYZT (particle.vx (), particle.vy (), particle.vz (), particle.t ());
89+ convertTLorentzVectorToO2Track (particle.pdgCode (), tlv, {particle.vx (), particle.vy (), particle.vz ()}, o2track, pdg);
90+ }
91+
92+ // / Function to convert a McParticle into a perfect Track
93+ // / \param particle the particle to convert (mcParticle)
94+ // / \param o2track the address of the resulting TrackParCov
95+ // / \param pdg the pdg service
96+ template <typename McParticleType>
97+ o2::track::TrackParCov convertMCParticleToO2Track (McParticleType& particle,
98+ const o2::framework::Service<o2::framework::O2DatabasePDG>& pdg)
99+ {
100+ o2::track::TrackParCov o2track;
101+ convertMCParticleToO2Track (particle, o2track, pdg);
102+ return o2track;
98103}
99104
100105} // namespace o2::upgrade
0 commit comments