Skip to content

Commit a687c9b

Browse files
authored
[ALICE3] Refactor otf decayer and fix indices for cascade decays (#16262)
1 parent 509e1a7 commit a687c9b

2 files changed

Lines changed: 152 additions & 422 deletions

File tree

ALICE3/Core/TrackUtilities.h

Lines changed: 93 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,52 @@
2222

2323
#include <TLorentzVector.h>
2424

25+
#include <array>
2526
#include <cmath>
27+
#include <span>
2628
#include <vector>
2729

2830
namespace o2::upgrade
2931
{
3032

31-
/// Struct to store mc info for the otf decayer
32-
struct OTFParticle {
33+
class OTFParticle
34+
{
35+
public:
3336
OTFParticle() = default;
3437

3538
template <typename TParticle>
3639
explicit OTFParticle(const TParticle& particle)
3740
{
3841
mPdgCode = particle.pdgCode();
42+
mGlobalIndex = particle.globalIndex();
43+
mCollisionId = particle.mcCollisionId();
3944
mPx = particle.px();
4045
mPy = particle.py();
4146
mPz = particle.pz();
4247
mE = particle.e();
4348
mVx = particle.vx();
4449
mVy = particle.vy();
4550
mVz = particle.vz();
51+
mIsFromMcParticles = true;
52+
if (particle.has_mothers()) {
53+
mIndicesMother = {particle.mothersIds().front(), particle.mothersIds().back()};
54+
}
4655
}
4756

4857
// Setters
49-
void setIsAlive(bool isAlive) { mIsAlive = isAlive; }
50-
void setPDG(int pdg) { mPdgCode = pdg; }
51-
void setVxVyVz(float vx, float vy, float vz)
58+
void setIsAlive(const bool isAlive) { mIsAlive = isAlive; }
59+
void setIsPrimary(const bool isPrimary) { mIsPrimary = isPrimary; }
60+
void setCollisionId(const int collisionId) { mCollisionId = collisionId; }
61+
void setPDG(const int pdg) { mPdgCode = pdg; }
62+
void setIndicesMother(const int start, const int stop) { mIndicesMother = {start, stop}; }
63+
void setIndicesDaughter(const int start, const int stop) { mIndicesDaughter = {start, stop}; }
64+
void setVxVyVz(const float vx, const float vy, const float vz)
5265
{
5366
mVx = vx;
5467
mVy = vy;
5568
mVz = vz;
5669
}
57-
void setPxPyPzE(float px, float py, float pz, float e)
70+
void setPxPyPzE(const float px, const float py, const float pz, const float e)
5871
{
5972
mPx = px;
6073
mPy = py;
@@ -64,7 +77,31 @@ struct OTFParticle {
6477

6578
// Getters
6679
int pdgCode() const { return mPdgCode; }
80+
int globalIndex() const { return mGlobalIndex; }
81+
int collisionId() const { return mCollisionId; }
6782
bool isAlive() const { return mIsAlive; }
83+
bool isPrimary() const { return mIsPrimary; }
84+
bool isFromMcParticles() const { return mIsFromMcParticles; }
85+
float weight() const
86+
{
87+
static constexpr float Weight = 1.f;
88+
return Weight;
89+
}
90+
uint8_t flags() const
91+
{
92+
static constexpr uint8_t Flags = 1;
93+
return Flags;
94+
}
95+
float vt() const
96+
{
97+
static constexpr float Vt = 1.f;
98+
return Vt;
99+
}
100+
int statusCode() const
101+
{
102+
static constexpr int StatusCode = 1;
103+
return StatusCode;
104+
}
68105
float vx() const { return mVx; }
69106
float vy() const { return mVy; }
70107
float vz() const { return mVz; }
@@ -73,15 +110,63 @@ struct OTFParticle {
73110
float pz() const { return mPz; }
74111
float e() const { return mE; }
75112
float radius() const { return std::hypot(mVx, mVy); }
113+
float r() const { return radius(); }
76114
float pt() const { return std::hypot(mPx, mPy); }
77115
float p() const { return std::hypot(mPx, mPy, mPz); }
116+
float phi() const { return o2::constants::math::PI + std::atan2(-1.0f * py(), -1.0f * px()); }
117+
float eta() const
118+
{
119+
// As https://github.com/AliceO2Group/AliceO2/blob/dev/Framework/Core/include/Framework/AnalysisDataModel.h#L1943
120+
static constexpr float Tolerance = 1e-7f;
121+
if ((p() - mPz) < Tolerance) {
122+
return (mPz < 0.0f) ? -100.0f : 100.0f;
123+
} else {
124+
return 0.5f * std::log((p() + mPz) / (p() - mPz));
125+
}
126+
}
127+
128+
float y() const
129+
{
130+
// As https://github.com/AliceO2Group/AliceO2/blob/dev/Framework/Core/include/Framework/AnalysisDataModel.h#L1922
131+
static constexpr float Tolerance = 1e-7f;
132+
if ((e() - mPz) < Tolerance) {
133+
return (mPz < 0.0f) ? -100.0f : 100.0f;
134+
} else {
135+
return 0.5f * std::log((mE + mPz) / (mE - mPz));
136+
}
137+
}
138+
139+
bool hasDaughters() const { return (mIndicesDaughter[0] > 0); }
140+
bool hasMothers() const { return (mIndicesMother[0] > 0); }
141+
int getMotherIndexStart() const { return mIndicesMother[0]; }
142+
int getMotherIndexStop() const { return mIndicesMother[1]; }
143+
int getDaughterIndexStart() const { return mIndicesDaughter[0]; }
144+
int getDaughterIndexStop() const { return mIndicesDaughter[1]; }
145+
std::array<int, 2> getMothers() const { return mIndicesMother; }
146+
std::array<int, 2> getDaughters() const { return mIndicesDaughter; }
147+
std::span<const int> getMotherSpan() const { return hasMothers() ? std::span<const int>(mIndicesMother.data(), 2) : std::span<const int>(); }
148+
149+
bool hasNaN() const
150+
{
151+
return std::isnan(mPx) || std::isnan(mPy) || std::isnan(mPz) || std::isnan(mE) ||
152+
std::isnan(mVx) || std::isnan(mVy) || std::isnan(mVz);
153+
}
154+
155+
bool hasIndex() const
156+
{
157+
return (mGlobalIndex != -1);
158+
}
78159

79160
private:
80-
int mPdgCode{};
161+
int mPdgCode{}, mGlobalIndex{-1};
162+
int mCollisionId{};
81163
float mE{};
82164
float mVx{}, mVy{}, mVz{};
83165
float mPx{}, mPy{}, mPz{};
84-
bool mIsAlive{};
166+
bool mIsAlive{}, mIsFromMcParticles{false};
167+
bool mIsPrimary{};
168+
169+
std::array<int, 2> mIndicesMother{-1, -1}, mIndicesDaughter{-1, -1};
85170
};
86171

87172
/// Function to convert a TLorentzVector into a perfect Track

0 commit comments

Comments
 (0)