Skip to content

Commit dd375b1

Browse files
authored
[PWGLF] Initialize variables, remove unused includes and use Particle constructor (#16405)
1 parent 442c6fc commit dd375b1

1 file changed

Lines changed: 71 additions & 72 deletions

File tree

PWGLF/TableProducer/Nuspex/coalescenceTreeProducer.cxx

Lines changed: 71 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -73,33 +73,75 @@ struct CoalescenceTreeProducer {
7373

7474
OutputObj<TTree> treeBoundState{"treeBoundState"};
7575

76-
int64_t eventID; // Event ID
77-
int64_t idB1, idB2, idB3; // MC particle IDs of the constituent baryons
76+
int64_t eventID = 0; // Event ID
77+
int64_t idB1 = 0, idB2 = 0, idB3 = 0; // MC particle IDs
7878

79-
int pdgB1, pdgB2, pdgB3;
80-
int chargeB1, chargeB2, chargeB3;
79+
int pdgB1 = 0, pdgB2 = 0, pdgB3 = 0;
80+
int chargeB1 = 0, chargeB2 = 0, chargeB3 = 0;
8181

82-
// Space-time coordinates and momentum components of the constituent baryons in the lab frame
83-
float xB1, yB1, zB1, tB1, pxB1, pyB1, pzB1;
84-
float xB2, yB2, zB2, tB2, pxB2, pyB2, pzB2;
85-
float xB3, yB3, zB3, tB3, pxB3, pyB3, pzB3;
86-
87-
static constexpr double MassP = o2::constants::physics::MassProton;
88-
static constexpr double MassN = o2::constants::physics::MassNeutron;
89-
static constexpr double MassL = o2::constants::physics::MassLambda0;
82+
// Space-time coordinates and momentum components
83+
float xB1 = 0.f, yB1 = 0.f, zB1 = 0.f, tB1 = 0.f, pxB1 = 0.f, pyB1 = 0.f, pzB1 = 0.f;
84+
float xB2 = 0.f, yB2 = 0.f, zB2 = 0.f, tB2 = 0.f, pxB2 = 0.f, pyB2 = 0.f, pzB2 = 0.f;
85+
float xB3 = 0.f, yB3 = 0.f, zB3 = 0.f, tB3 = 0.f, pxB3 = 0.f, pyB3 = 0.f, pzB3 = 0.f;
9086

9187
struct Particle {
92-
int64_t id;
93-
int pdg;
94-
int charge;
95-
float x;
96-
float y;
97-
float z;
98-
float t;
99-
float px;
100-
float py;
101-
float pz;
102-
float mass;
88+
int64_t id = 0;
89+
int pdg = 0;
90+
int charge = 0;
91+
92+
float x = 0.f;
93+
float y = 0.f;
94+
float z = 0.f;
95+
float t = 0.f;
96+
97+
float px = 0.f;
98+
float py = 0.f;
99+
float pz = 0.f;
100+
101+
float mass = 0.f;
102+
103+
Particle() = default;
104+
105+
template <typename T>
106+
explicit Particle(T const& p)
107+
: id(p.globalIndex()),
108+
pdg(p.pdgCode()),
109+
charge(chargeFromPdg(pdg)),
110+
x(p.vx()),
111+
y(p.vy()),
112+
z(p.vz()),
113+
t(p.vt()),
114+
px(p.px()),
115+
py(p.py()),
116+
pz(p.pz()),
117+
mass(static_cast<float>(massFromPdg(pdg)))
118+
{
119+
}
120+
121+
static int chargeFromPdg(int pdg)
122+
{
123+
if (pdg == PDG_t::kProton) {
124+
return 1;
125+
}
126+
if (pdg == PDG_t::kProtonBar) {
127+
return -1;
128+
}
129+
return 0;
130+
}
131+
132+
static double massFromPdg(int pdg)
133+
{
134+
switch (std::abs(pdg)) {
135+
case PDG_t::kProton:
136+
return o2::constants::physics::MassProton;
137+
case PDG_t::kNeutron:
138+
return o2::constants::physics::MassNeutron;
139+
case PDG_t::kLambda0:
140+
return o2::constants::physics::MassLambda0;
141+
default:
142+
return -1.;
143+
}
144+
}
103145
};
104146

105147
void init(InitContext&)
@@ -154,49 +196,6 @@ struct CoalescenceTreeProducer {
154196
}
155197
}
156198

157-
int chargeFromPdg(int pdg) const
158-
{
159-
int charge(0);
160-
if (pdg == PDG_t::kProton) {
161-
charge = 1;
162-
}
163-
if (pdg == PDG_t::kProtonBar) {
164-
charge = -1;
165-
}
166-
return charge;
167-
}
168-
169-
double massFromPdg(int pdg) const
170-
{
171-
switch (std::abs(pdg)) {
172-
case PDG_t::kProton:
173-
return MassP;
174-
case PDG_t::kNeutron:
175-
return MassN;
176-
case PDG_t::kLambda0:
177-
return MassL;
178-
default:
179-
return -1.;
180-
}
181-
}
182-
183-
template <typename T>
184-
Particle makeParticle(T const& p)
185-
{
186-
const int pdg = p.pdgCode();
187-
return {p.globalIndex(),
188-
pdg,
189-
chargeFromPdg(pdg),
190-
p.vx(),
191-
p.vy(),
192-
p.vz(),
193-
p.vt(),
194-
p.px(),
195-
p.py(),
196-
p.pz(),
197-
static_cast<float>(massFromPdg(pdg))};
198-
}
199-
200199
ROOT::Math::PxPyPzMVector makeFourVector(Particle const& p)
201200
{
202201
return ROOT::Math::PxPyPzMVector{p.px, p.py, p.pz, p.mass};
@@ -496,17 +495,17 @@ struct CoalescenceTreeProducer {
496495
const int pdg = particle.pdgCode();
497496

498497
if (pdg == PDG_t::kProton) {
499-
protons.push_back(makeParticle(particle));
498+
protons.emplace_back(particle);
500499
} else if (pdg == PDG_t::kProtonBar) {
501-
antiProtons.push_back(makeParticle(particle));
500+
antiProtons.emplace_back(particle);
502501
} else if (pdg == PDG_t::kNeutron) {
503-
neutrons.push_back(makeParticle(particle));
502+
neutrons.emplace_back(particle);
504503
} else if (pdg == PDG_t::kNeutronBar) {
505-
antiNeutrons.push_back(makeParticle(particle));
504+
antiNeutrons.emplace_back(particle);
506505
} else if (pdg == PDG_t::kLambda0) {
507-
lambdas.push_back(makeParticle(particle));
506+
lambdas.emplace_back(particle);
508507
} else if (pdg == PDG_t::kLambda0Bar) {
509-
antiLambdas.push_back(makeParticle(particle));
508+
antiLambdas.emplace_back(particle);
510509
}
511510
}
512511
}

0 commit comments

Comments
 (0)