Skip to content

Commit 3be3066

Browse files
committed
Split otf particle from a3 track utilities
1 parent 8b48eec commit 3be3066

4 files changed

Lines changed: 169 additions & 139 deletions

File tree

ALICE3/Core/Decayer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifndef ALICE3_CORE_DECAYER_H_
2020
#define ALICE3_CORE_DECAYER_H_
2121

22+
#include "ALICE3/Core/OTFParticle.h"
2223
#include "ALICE3/Core/TrackUtilities.h"
2324

2425
#include <CommonConstants/PhysicsConstants.h>

ALICE3/Core/OTFParticle.h

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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+
///
13+
/// \file OTFParticle.h
14+
/// \brief Basic class to hold information regarding a mc particle to be used in fast simulation
15+
/// \author Jesper Karlsson Gumprecht <jesper.gumprecht@cern.ch>
16+
///
17+
18+
#ifndef ALICE3_CORE_OTFPARTICLE_H_
19+
#define ALICE3_CORE_OTFPARTICLE_H_
20+
21+
#include <CommonConstants/MathConstants.h>
22+
23+
#include <array>
24+
#include <cmath>
25+
#include <cstdint>
26+
#include <span>
27+
28+
namespace o2::upgrade
29+
{
30+
31+
class OTFParticle
32+
{
33+
public:
34+
OTFParticle() = default;
35+
36+
template <typename TParticle>
37+
explicit OTFParticle(const TParticle& particle)
38+
{
39+
mPdgCode = particle.pdgCode();
40+
mGlobalIndex = particle.globalIndex();
41+
mCollisionId = particle.mcCollisionId();
42+
mPx = particle.px();
43+
mPy = particle.py();
44+
mPz = particle.pz();
45+
mE = particle.e();
46+
mVx = particle.vx();
47+
mVy = particle.vy();
48+
mVz = particle.vz();
49+
mVt = particle.vt();
50+
mIsFromMcParticles = true;
51+
if (particle.has_mothers()) {
52+
mIndicesMother = {particle.mothersIds().front(), particle.mothersIds().back()};
53+
}
54+
}
55+
56+
// Setters
57+
void setIsAlive(const bool isAlive) { mIsAlive = isAlive; }
58+
void setIsPrimary(const bool isPrimary) { mIsPrimary = isPrimary; }
59+
void setCollisionId(const int collisionId) { mCollisionId = collisionId; }
60+
void setPDG(const int pdg) { mPdgCode = pdg; }
61+
void setIndicesMother(const int start, const int stop) { mIndicesMother = {start, stop}; }
62+
void setIndicesDaughter(const int start, const int stop) { mIndicesDaughter = {start, stop}; }
63+
void setProductionTime(const float vt) { mVt = vt; }
64+
void setVxVyVz(const float vx, const float vy, const float vz)
65+
{
66+
mVx = vx;
67+
mVy = vy;
68+
mVz = vz;
69+
}
70+
void setPxPyPzE(const float px, const float py, const float pz, const float e)
71+
{
72+
mPx = px;
73+
mPy = py;
74+
mPz = pz;
75+
mE = e;
76+
}
77+
78+
// Getters
79+
int pdgCode() const { return mPdgCode; }
80+
int globalIndex() const { return mGlobalIndex; }
81+
int collisionId() const { return mCollisionId; }
82+
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; // todo
94+
}
95+
int statusCode() const
96+
{
97+
static constexpr int StatusCode = 1;
98+
return StatusCode; // todo
99+
}
100+
float vx() const { return mVx; }
101+
float vy() const { return mVy; }
102+
float vz() const { return mVz; }
103+
float vt() const { return mVt; }
104+
float px() const { return mPx; }
105+
float py() const { return mPy; }
106+
float pz() const { return mPz; }
107+
float e() const { return mE; }
108+
float radius() const { return std::hypot(mVx, mVy); }
109+
float r() const { return radius(); }
110+
float pt() const { return std::hypot(mPx, mPy); }
111+
float p() const { return std::hypot(mPx, mPy, mPz); }
112+
float phi() const { return o2::constants::math::PI + std::atan2(-1.0f * py(), -1.0f * px()); }
113+
float eta() const
114+
{
115+
// As https://github.com/AliceO2Group/AliceO2/blob/dev/Framework/Core/include/Framework/AnalysisDataModel.h#L1943
116+
static constexpr float Tolerance = 1e-7f;
117+
if ((p() - mPz) < Tolerance) {
118+
return (mPz < 0.0f) ? -100.0f : 100.0f;
119+
} else {
120+
return 0.5f * std::log((p() + mPz) / (p() - mPz));
121+
}
122+
}
123+
float y() const
124+
{
125+
// As https://github.com/AliceO2Group/AliceO2/blob/dev/Framework/Core/include/Framework/AnalysisDataModel.h#L1922
126+
static constexpr float Tolerance = 1e-7f;
127+
if ((e() - mPz) < Tolerance) {
128+
return (mPz < 0.0f) ? -100.0f : 100.0f;
129+
} else {
130+
return 0.5f * std::log((mE + mPz) / (mE - mPz));
131+
}
132+
}
133+
int getMotherIndexStart() const { return mIndicesMother[0]; }
134+
int getMotherIndexStop() const { return mIndicesMother[1]; }
135+
int getDaughterIndexStart() const { return mIndicesDaughter[0]; }
136+
int getDaughterIndexStop() const { return mIndicesDaughter[1]; }
137+
std::array<int, 2> getMothers() const { return mIndicesMother; }
138+
std::array<int, 2> getDaughters() const { return mIndicesDaughter; }
139+
std::span<const int> getMotherSpan() const { return hasMothers() ? std::span<const int>(mIndicesMother.data(), 2) : std::span<const int>(); }
140+
141+
// Checks
142+
bool hasDaughters() const { return (mIndicesDaughter[0] > 0); }
143+
bool hasMothers() const { return (mIndicesMother[0] > 0); }
144+
bool hasNaN() const
145+
{
146+
return std::isnan(mPx) || std::isnan(mPy) || std::isnan(mPz) || std::isnan(mE) ||
147+
std::isnan(mVx) || std::isnan(mVy) || std::isnan(mVz);
148+
}
149+
bool hasIndex() const
150+
{
151+
return (mGlobalIndex != -1);
152+
}
153+
154+
private:
155+
int mPdgCode{}, mGlobalIndex{-1};
156+
int mCollisionId{};
157+
float mVx{}, mVy{}, mVz{}, mVt{};
158+
float mPx{}, mPy{}, mPz{}, mE{};
159+
bool mIsAlive{}, mIsFromMcParticles{false};
160+
bool mIsPrimary{};
161+
std::array<int, 2> mIndicesMother{-1, -1}, mIndicesDaughter{-1, -1};
162+
};
163+
164+
} // namespace o2::upgrade
165+
#endif // ALICE3_CORE_OTFPARTICLE_H_

ALICE3/Core/TrackUtilities.h

Lines changed: 2 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#ifndef ALICE3_CORE_TRACKUTILITIES_H_
1919
#define ALICE3_CORE_TRACKUTILITIES_H_
2020

21+
#include "ALICE3/Core/OTFParticle.h"
22+
2123
#include <ReconstructionDataFormats/Track.h>
2224

2325
#include <TLorentzVector.h>
@@ -30,145 +32,6 @@
3032
namespace o2::upgrade
3133
{
3234

33-
class OTFParticle
34-
{
35-
public:
36-
OTFParticle() = default;
37-
38-
template <typename TParticle>
39-
explicit OTFParticle(const TParticle& particle)
40-
{
41-
mPdgCode = particle.pdgCode();
42-
mGlobalIndex = particle.globalIndex();
43-
mCollisionId = particle.mcCollisionId();
44-
mPx = particle.px();
45-
mPy = particle.py();
46-
mPz = particle.pz();
47-
mE = particle.e();
48-
mVx = particle.vx();
49-
mVy = particle.vy();
50-
mVz = particle.vz();
51-
mIsFromMcParticles = true;
52-
if (particle.has_mothers()) {
53-
mIndicesMother = {particle.mothersIds().front(), particle.mothersIds().back()};
54-
}
55-
}
56-
57-
// Setters
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)
65-
{
66-
mVx = vx;
67-
mVy = vy;
68-
mVz = vz;
69-
}
70-
void setPxPyPzE(const float px, const float py, const float pz, const float e)
71-
{
72-
mPx = px;
73-
mPy = py;
74-
mPz = pz;
75-
mE = e;
76-
}
77-
78-
// Getters
79-
int pdgCode() const { return mPdgCode; }
80-
int globalIndex() const { return mGlobalIndex; }
81-
int collisionId() const { return mCollisionId; }
82-
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-
}
105-
float vx() const { return mVx; }
106-
float vy() const { return mVy; }
107-
float vz() const { return mVz; }
108-
float px() const { return mPx; }
109-
float py() const { return mPy; }
110-
float pz() const { return mPz; }
111-
float e() const { return mE; }
112-
float radius() const { return std::hypot(mVx, mVy); }
113-
float r() const { return radius(); }
114-
float pt() const { return std::hypot(mPx, mPy); }
115-
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-
}
159-
160-
private:
161-
int mPdgCode{}, mGlobalIndex{-1};
162-
int mCollisionId{};
163-
float mE{};
164-
float mVx{}, mVy{}, mVz{};
165-
float mPx{}, mPy{}, mPz{};
166-
bool mIsAlive{}, mIsFromMcParticles{false};
167-
bool mIsPrimary{};
168-
169-
std::array<int, 2> mIndicesMother{-1, -1}, mIndicesDaughter{-1, -1};
170-
};
171-
17235
/// Function to convert a TLorentzVector into a perfect Track
17336
/// \param charge particle charge (integer)
17437
/// \param particle the particle to convert (TLorentzVector)

ALICE3/TableProducer/OTF/onTheFlyDecayer.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
///
1717

1818
#include "ALICE3/Core/Decayer.h"
19+
#include "ALICE3/Core/OTFParticle.h"
1920
#include "ALICE3/Core/TrackUtilities.h"
2021
#include "ALICE3/DataModel/OTFMCParticle.h"
2122

0 commit comments

Comments
 (0)