Skip to content

Commit 6756192

Browse files
authored
[ALICE3] Move common track handling to header (#11276)
1 parent 8c4ba1d commit 6756192

File tree

5 files changed

+123
-119
lines changed

5 files changed

+123
-119
lines changed

ALICE3/Core/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,19 @@
1212
o2physics_add_library(ALICE3Core
1313
SOURCES TOFResoALICE3.cxx
1414
DelphesO2TrackSmearer.cxx
15-
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore)
15+
PUBLIC_LINK_LIBRARIES O2::Framework
16+
O2Physics::AnalysisCore)
1617

1718
o2physics_target_root_dictionary(ALICE3Core
1819
HEADERS TOFResoALICE3.h
20+
TrackUtilities.h
1921
DelphesO2TrackSmearer.h
2022
LINKDEF ALICE3CoreLinkDef.h)
2123

2224
o2physics_add_library(FastTracker
2325
SOURCES FastTracker.cxx
24-
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore)
26+
PUBLIC_LINK_LIBRARIES O2::Framework
27+
O2Physics::AnalysisCore)
2528

2629
o2physics_target_root_dictionary(FastTracker
2730
HEADERS FastTracker.h

ALICE3/Core/TrackUtilities.h

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
///
12+
/// \file TrackUtilities.h
13+
///
14+
/// \brief Set of utilities for the ALICE3 track handling
15+
///
16+
/// \since May 21, 2025
17+
///
18+
19+
#ifndef ALICE3_CORE_TRACKUTILITIES_H_
20+
#define ALICE3_CORE_TRACKUTILITIES_H_
21+
22+
#include <vector>
23+
24+
#include "ReconstructionDataFormats/Track.h"
25+
#include "Framework/O2DatabasePDGPlugin.h"
26+
#include "Framework/AnalysisHelpers.h"
27+
#include "TLorentzVector.h"
28+
29+
namespace o2::upgrade
30+
{
31+
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
36+
/// \param o2track the address of the resulting TrackParCov
37+
void convertTLorentzVectorToO2Track(const int charge,
38+
const TLorentzVector particle,
39+
const std::vector<double> productionVertex,
40+
o2::track::TrackParCov& o2track)
41+
{
42+
std::array<float, 5> params;
43+
std::array<float, 15> covm = {0.};
44+
float s, c, x;
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]);
48+
params[2] = 0.; // since alpha = phi
49+
const auto theta = 2. * std::atan(std::exp(-particle.PseudoRapidity()));
50+
params[3] = 1. / std::tan(theta);
51+
params[4] = charge / particle.Pt();
52+
53+
// Initialize TrackParCov in-place
54+
new (&o2track)(o2::track::TrackParCov)(x, particle.Phi(), params, covm);
55+
}
56+
57+
/// Function to convert a TLorentzVector into a perfect Track
58+
/// \param pdgCode particle pdg
59+
/// \param particle the particle to convert (TLorentzVector)
60+
/// \param productionVertex where the particle was produced
61+
/// \param o2track the address of the resulting TrackParCov
62+
/// \param pdg the pdg service
63+
void convertTLorentzVectorToO2Track(int pdgCode,
64+
TLorentzVector particle,
65+
std::vector<double> productionVertex,
66+
o2::track::TrackParCov& o2track,
67+
const o2::framework::Service<o2::framework::O2DatabasePDG>& pdg)
68+
{
69+
const auto pdgInfo = pdg->GetParticle(pdgCode);
70+
int charge = 0;
71+
if (pdgInfo != nullptr) {
72+
charge = pdgInfo->Charge() / 3;
73+
}
74+
convertTLorentzVectorToO2Track(charge, particle, productionVertex, o2track);
75+
}
76+
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.vt());
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;
103+
}
104+
105+
} // namespace o2::upgrade
106+
107+
#endif // ALICE3_CORE_TRACKUTILITIES_H_

ALICE3/TableProducer/OTF/onTheFlyRichPid.cxx

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "Framework/ASoAHelpers.h"
4848
#include "Common/DataModel/TrackSelectionTables.h"
4949
#include "Common/Core/trackUtilities.h"
50+
#include "ALICE3/Core/TrackUtilities.h"
5051
#include "ReconstructionDataFormats/DCA.h"
5152
#include "DetectorsBase/Propagator.h"
5253
#include "DetectorsBase/GeometryManager.h"
@@ -446,34 +447,6 @@ struct OnTheFlyRichPid {
446447
updateProjectiveParameters();
447448
}
448449

449-
/// Function to convert a McParticle into a perfect Track
450-
/// \param particle the particle to convert (mcParticle)
451-
/// \param o2track the address of the resulting TrackParCov
452-
template <typename McParticleType>
453-
o2::track::TrackParCov convertMCParticleToO2Track(McParticleType& particle)
454-
{
455-
// FIXME: this is a fundamentally important piece of code.
456-
// It could be placed in a utility file instead of here.
457-
auto pdgInfo = pdg->GetParticle(particle.pdgCode());
458-
int charge = 0;
459-
if (pdgInfo != nullptr) {
460-
charge = pdgInfo->Charge() / 3;
461-
}
462-
std::array<float, 5> params;
463-
std::array<float, 15> covm = {0.};
464-
float s, c, x;
465-
o2::math_utils::sincos(particle.phi(), s, c);
466-
o2::math_utils::rotateZInv(particle.vx(), particle.vy(), x, params[0], s, c);
467-
params[1] = particle.vz();
468-
params[2] = 0.; // since alpha = phi
469-
auto theta = 2. * std::atan(std::exp(-particle.eta()));
470-
params[3] = 1. / std::tan(theta);
471-
params[4] = charge / particle.pt();
472-
473-
// Return TrackParCov
474-
return o2::track::TrackParCov(x, particle.phi(), params, covm);
475-
}
476-
477450
/// check if particle reaches radiator
478451
/// \param track the input track
479452
/// \param radius the radius of the layer you're calculating the length to
@@ -778,7 +751,7 @@ struct OnTheFlyRichPid {
778751
continue;
779752

780753
auto mcParticle = track.mcParticle();
781-
o2::track::TrackParCov o2track = convertMCParticleToO2Track(mcParticle);
754+
o2::track::TrackParCov o2track = o2::upgrade::convertMCParticleToO2Track(mcParticle, pdg);
782755

783756
// float xPv = error_value;
784757
if (o2track.propagateToDCA(mcPvVtx, dBz)) {

ALICE3/TableProducer/OTF/onTheFlyTofPid.cxx

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "Framework/ASoAHelpers.h"
4141
#include "Common/DataModel/TrackSelectionTables.h"
4242
#include "Common/Core/trackUtilities.h"
43+
#include "ALICE3/Core/TrackUtilities.h"
4344
#include "ReconstructionDataFormats/DCA.h"
4445
#include "DetectorsBase/Propagator.h"
4546
#include "DetectorsBase/GeometryManager.h"
@@ -252,34 +253,6 @@ struct OnTheFlyTofPid {
252253
}
253254
}
254255

255-
/// Function to convert a McParticle into a perfect Track
256-
/// \param particle the particle to convert (mcParticle)
257-
/// \param o2track the address of the resulting TrackParCov
258-
template <typename McParticleType>
259-
o2::track::TrackParCov convertMCParticleToO2Track(McParticleType& particle)
260-
{
261-
// FIXME: this is a fundamentally important piece of code.
262-
// It could be placed in a utility file instead of here.
263-
auto pdgInfo = pdg->GetParticle(particle.pdgCode());
264-
int charge = 0;
265-
if (pdgInfo != nullptr) {
266-
charge = pdgInfo->Charge() / 3;
267-
}
268-
std::array<float, 5> params;
269-
std::array<float, 15> covm = {0.};
270-
float s, c, x;
271-
o2::math_utils::sincos(particle.phi(), s, c);
272-
o2::math_utils::rotateZInv(particle.vx(), particle.vy(), x, params[0], s, c);
273-
params[1] = particle.vz();
274-
params[2] = 0.; // since alpha = phi
275-
auto theta = 2. * std::atan(std::exp(-particle.eta()));
276-
params[3] = 1. / std::tan(theta);
277-
params[4] = charge / particle.pt();
278-
279-
// Return TrackParCov
280-
return o2::track::TrackParCov(x, particle.phi(), params, covm);
281-
}
282-
283256
/// function to calculate track length of this track up to a certain radius
284257
/// \param track the input track
285258
/// \param radius the radius of the layer you're calculating the length to
@@ -519,7 +492,7 @@ struct OnTheFlyTofPid {
519492
LOG(debug) << "Track without mcParticle found!";
520493
}
521494
const auto& mcParticle = track.mcParticle();
522-
o2::track::TrackParCov o2track = convertMCParticleToO2Track(mcParticle);
495+
o2::track::TrackParCov o2track = o2::upgrade::convertMCParticleToO2Track(mcParticle, pdg);
523496

524497
float xPv = -100.f;
525498
static constexpr float kTrkXThreshold = -99.f; // Threshold to consider a good propagation of the track

ALICE3/TableProducer/OTF/onTheFlyTracker.cxx

Lines changed: 7 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include "ALICE3/Core/DelphesO2TrackSmearer.h"
6262
#include "ALICE3/Core/FastTracker.h"
6363
#include "ALICE3/Core/DetLayer.h"
64+
#include "ALICE3/Core/TrackUtilities.h"
6465
#include "ALICE3/DataModel/collisionAlice3.h"
6566
#include "ALICE3/DataModel/tracksAlice3.h"
6667
#include "ALICE3/DataModel/OTFStrangeness.h"
@@ -275,7 +276,7 @@ struct OnTheFlyTracker {
275276
mapPdgLut.insert(std::make_pair(1000010030, lutTrChar));
276277
mapPdgLut.insert(std::make_pair(1000020030, lutHe3Char));
277278
}
278-
for (auto e : mapPdgLut) {
279+
for (const auto& e : mapPdgLut) {
279280
if (!mSmearer.loadTable(e.first, e.second)) {
280281
LOG(fatal) << "Having issue with loading the LUT " << e.first << " " << e.second;
281282
}
@@ -493,59 +494,6 @@ struct OnTheFlyTracker {
493494
decayDaughters.push_back(*laDecay.GetDecay(1));
494495
}
495496

496-
/// Function to convert a TLorentzVector into a perfect Track
497-
/// \param pdgCode particle pdg
498-
/// \param particle the particle to convert (TLorentzVector)
499-
/// \param productionVertex where the particle was produced
500-
/// \param o2track the address of the resulting TrackParCov
501-
void convertTLorentzVectorToO2Track(int pdgCode, TLorentzVector particle, std::vector<double> productionVertex, o2::track::TrackParCov& o2track)
502-
{
503-
auto pdgInfo = pdgDB->GetParticle(pdgCode);
504-
int charge = 0;
505-
if (pdgInfo != nullptr) {
506-
charge = pdgInfo->Charge() / 3;
507-
}
508-
std::array<float, 5> params;
509-
std::array<float, 15> covm = {0.};
510-
float s, c, x;
511-
o2::math_utils::sincos(static_cast<float>(particle.Phi()), s, c);
512-
o2::math_utils::rotateZInv(static_cast<float>(productionVertex[0]), static_cast<float>(productionVertex[1]), x, params[0], s, c);
513-
params[1] = static_cast<float>(productionVertex[2]);
514-
params[2] = 0;
515-
auto theta = 2. * std::atan(std::exp(-particle.PseudoRapidity()));
516-
params[3] = 1. / std::tan(theta);
517-
params[4] = charge / particle.Pt();
518-
519-
// Initialize TrackParCov in-place
520-
new (&o2track)(o2::track::TrackParCov)(x, particle.Phi(), params, covm);
521-
}
522-
523-
/// Function to convert a McParticle into a perfect Track
524-
/// \param particle the particle to convert (mcParticle)
525-
/// \param o2track the address of the resulting TrackParCov
526-
template <typename McParticleType>
527-
void convertMCParticleToO2Track(McParticleType& particle, o2::track::TrackParCov& o2track)
528-
{
529-
auto pdgInfo = pdgDB->GetParticle(particle.pdgCode());
530-
int charge = 0;
531-
if (pdgInfo != nullptr) {
532-
charge = pdgInfo->Charge() / 3;
533-
}
534-
std::array<float, 5> params;
535-
std::array<float, 15> covm = {0.};
536-
float s, c, x;
537-
o2::math_utils::sincos(particle.phi(), s, c);
538-
o2::math_utils::rotateZInv(particle.vx(), particle.vy(), x, params[0], s, c);
539-
params[1] = particle.vz();
540-
params[2] = 0.; // since alpha = phi
541-
auto theta = 2. * std::atan(std::exp(-particle.eta()));
542-
params[3] = 1. / std::tan(theta);
543-
params[4] = charge / particle.pt();
544-
545-
// Initialize TrackParCov in-place
546-
new (&o2track)(o2::track::TrackParCov)(x, particle.phi(), params, covm);
547-
}
548-
549497
float dNdEta = 0.f; // Charged particle multiplicity to use in the efficiency evaluation
550498
void process(aod::McCollision const& mcCollision, aod::McParticles const& mcParticles)
551499
{
@@ -605,7 +553,7 @@ struct OnTheFlyTracker {
605553
if (cascadeDecaySettings.decayXi) {
606554
if (mcParticle.pdgCode() == 3312) {
607555
o2::track::TrackParCov xiTrackParCov;
608-
convertMCParticleToO2Track(mcParticle, xiTrackParCov);
556+
o2::upgrade::convertMCParticleToO2Track(mcParticle, xiTrackParCov, pdgDB);
609557
decayParticle(mcParticle, xiTrackParCov, decayProducts, xiDecayVertex, laDecayVertex);
610558
xiDecayRadius2D = sqrt(xiDecayVertex[0] * xiDecayVertex[0] + xiDecayVertex[1] * xiDecayVertex[1]);
611559
laDecayRadius2D = sqrt(laDecayVertex[0] * laDecayVertex[0] + laDecayVertex[1] * laDecayVertex[1]);
@@ -653,7 +601,7 @@ struct OnTheFlyTracker {
653601
}
654602

655603
o2::track::TrackParCov trackParCov;
656-
convertMCParticleToO2Track(mcParticle, trackParCov);
604+
o2::upgrade::convertMCParticleToO2Track(mcParticle, trackParCov, pdgDB);
657605

658606
bool isDecayDaughter = false;
659607
if (mcParticle.getProcess() == 4)
@@ -674,9 +622,9 @@ struct OnTheFlyTracker {
674622
continue;
675623
}
676624

677-
convertTLorentzVectorToO2Track(-211, decayProducts[0], xiDecayVertex, xiDaughterTrackParCovsPerfect[0]);
678-
convertTLorentzVectorToO2Track(-211, decayProducts[1], laDecayVertex, xiDaughterTrackParCovsPerfect[1]);
679-
convertTLorentzVectorToO2Track(2212, decayProducts[2], laDecayVertex, xiDaughterTrackParCovsPerfect[2]);
625+
o2::upgrade::convertTLorentzVectorToO2Track(-211, decayProducts[0], xiDecayVertex, xiDaughterTrackParCovsPerfect[0], pdgDB);
626+
o2::upgrade::convertTLorentzVectorToO2Track(-211, decayProducts[1], laDecayVertex, xiDaughterTrackParCovsPerfect[1], pdgDB);
627+
o2::upgrade::convertTLorentzVectorToO2Track(2212, decayProducts[2], laDecayVertex, xiDaughterTrackParCovsPerfect[2], pdgDB);
680628

681629
for (int i = 0; i < 3; i++) {
682630
isReco[i] = false;

0 commit comments

Comments
 (0)