Skip to content

Commit 32c219e

Browse files
committed
[PWGLF] Initialize variables, remove unused includes and use Particle constructor
1 parent 685cf1f commit 32c219e

1 file changed

Lines changed: 71 additions & 80 deletions

File tree

PWGLF/TableProducer/Nuspex/coalescenceTreeProducer.cxx

Lines changed: 71 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@
2828
///
2929
/// \author Alberto Calivà <alberto.caliva@cern.ch>
3030

31-
#include "Framework/AnalysisTask.h"
32-
#include "Framework/Configurable.h"
33-
#include "Framework/HistogramRegistry.h"
34-
#include "Framework/InitContext.h"
35-
#include "Framework/Logger.h"
36-
#include "Framework/OutputObjHeader.h"
37-
#include "Framework/runDataProcessing.h"
38-
3931
#include <Math/Boost.h>
4032
#include <Math/Vector3D.h>
4133
#include <Math/Vector4D.h>
@@ -73,33 +65,75 @@ struct CoalescenceTreeProducer {
7365

7466
OutputObj<TTree> treeBoundState{"treeBoundState"};
7567

76-
int64_t eventID; // Event ID
77-
int64_t idB1, idB2, idB3; // MC particle IDs of the constituent baryons
78-
79-
int pdgB1, pdgB2, pdgB3;
80-
int chargeB1, chargeB2, chargeB3;
68+
int64_t eventID = 0; // Event ID
69+
int64_t idB1 = 0, idB2 = 0, idB3 = 0; // MC particle IDs
8170

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;
71+
int pdgB1 = 0, pdgB2 = 0, pdgB3 = 0;
72+
int chargeB1 = 0, chargeB2 = 0, chargeB3 = 0;
8673

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;
74+
// Space-time coordinates and momentum components
75+
float xB1 = 0.f, yB1 = 0.f, zB1 = 0.f, tB1 = 0.f, pxB1 = 0.f, pyB1 = 0.f, pzB1 = 0.f;
76+
float xB2 = 0.f, yB2 = 0.f, zB2 = 0.f, tB2 = 0.f, pxB2 = 0.f, pyB2 = 0.f, pzB2 = 0.f;
77+
float xB3 = 0.f, yB3 = 0.f, zB3 = 0.f, tB3 = 0.f, pxB3 = 0.f, pyB3 = 0.f, pzB3 = 0.f;
9078

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

105139
void init(InitContext&)
@@ -154,49 +188,6 @@ struct CoalescenceTreeProducer {
154188
}
155189
}
156190

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-
200191
ROOT::Math::PxPyPzMVector makeFourVector(Particle const& p)
201192
{
202193
return ROOT::Math::PxPyPzMVector{p.px, p.py, p.pz, p.mass};
@@ -496,17 +487,17 @@ struct CoalescenceTreeProducer {
496487
const int pdg = particle.pdgCode();
497488

498489
if (pdg == PDG_t::kProton) {
499-
protons.push_back(makeParticle(particle));
490+
protons.emplace_back(particle);
500491
} else if (pdg == PDG_t::kProtonBar) {
501-
antiProtons.push_back(makeParticle(particle));
492+
antiProtons.emplace_back(particle);
502493
} else if (pdg == PDG_t::kNeutron) {
503-
neutrons.push_back(makeParticle(particle));
494+
neutrons.emplace_back(particle);
504495
} else if (pdg == PDG_t::kNeutronBar) {
505-
antiNeutrons.push_back(makeParticle(particle));
496+
antiNeutrons.emplace_back(particle);
506497
} else if (pdg == PDG_t::kLambda0) {
507-
lambdas.push_back(makeParticle(particle));
498+
lambdas.emplace_back(particle);
508499
} else if (pdg == PDG_t::kLambda0Bar) {
509-
antiLambdas.push_back(makeParticle(particle));
500+
antiLambdas.emplace_back(particle);
510501
}
511502
}
512503
}

0 commit comments

Comments
 (0)