Skip to content

Commit 336d938

Browse files
committed
Do not use raw pointers and LorentzVector
1 parent a2c567d commit 336d938

1 file changed

Lines changed: 49 additions & 70 deletions

File tree

PWGUD/Tasks/ptSpectraInclusiveUpc.cxx

Lines changed: 49 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <CommonConstants/MathConstants.h>
2424
#include <CommonConstants/PhysicsConstants.h>
25+
#include "Common/Core/RecoDecay.h"
2526
#include <Framework/ASoA.h>
2627
#include <Framework/AnalysisDataModel.h>
2728
#include <Framework/AnalysisHelpers.h>
@@ -32,21 +33,23 @@
3233
#include <Framework/InitContext.h>
3334
#include <Framework/OutputObjHeader.h>
3435
#include <Framework/runDataProcessing.h>
36+
#include <Framework/O2DatabasePDGPlugin.h>
3537

36-
#include <Math/GenVector/LorentzVector.h>
37-
#include <Math/GenVector/PxPyPzM4D.h>
3838
#include <TMCProcess.h>
3939
#include <TPDGCode.h>
4040

4141
#include <cmath>
4242
#include <cstdlib>
43+
#include <array>
4344

4445
using namespace o2;
4546
using namespace o2::framework;
4647
using namespace o2::framework::expressions;
4748

4849
struct PtSpectraInclusiveUpc {
4950

51+
Service<o2::framework::O2DatabasePDG> pdg;
52+
5053
HistogramRegistry histos{"histos", {}, OutputObjHandlingPolicy::AnalysisObject};
5154

5255
Configurable<int> nBinsPt{"nBinsPt", 100, "N bins in pT histos"};
@@ -60,7 +63,6 @@ struct PtSpectraInclusiveUpc {
6063
using CC = CCs::iterator;
6164
using TCs = soa::Join<aod::UDTracks, aod::UDTracksPID, aod::UDTracksExtra, aod::UDTracksFlags, aod::UDTracksDCA, aod::UDMcTrackLabels>;
6265
using TC = TCs::iterator;
63-
using LorentzVectorM = ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double>>;
6466

6567
const double etaMax = 0.9;
6668
const double yMax = 0.9;
@@ -71,6 +73,7 @@ struct PtSpectraInclusiveUpc {
7173

7274
void init(InitContext const&)
7375
{
76+
7477
// axes
7578
const AxisSpec axisPt{nBinsPt, 0, 5, "#it{p}_{T} GeV/#it{c}"};
7679
const AxisSpec axisEventCounter{2, 0.5, 2.5, "Event type"};
@@ -113,35 +116,37 @@ struct PtSpectraInclusiveUpc {
113116
void processSim(aod::UDMcCollision const&, aod::UDMcParticles const& mcParticles)
114117
{
115118

119+
std::array<float, 3> trackMomentum;
120+
116121
for (const auto& mcParticle : mcParticles) {
117122
if (!mcParticle.isPhysicalPrimary())
118123
continue;
119124

120-
LorentzVectorM pMC(mcParticle.px(), mcParticle.py(), mcParticle.pz(), o2::constants::physics::MassPionCharged);
125+
trackMomentum[0] = mcParticle.px();
126+
trackMomentum[1] = mcParticle.py();
127+
trackMomentum[2] = mcParticle.pz();
121128

122129
if (applyKineCutsInGen) {
123-
if (std::fabs(pMC.Eta()) > etaMax)
130+
if (std::fabs(RecoDecay::eta(trackMomentum)) > etaMax)
124131
continue;
125132

126-
if (std::fabs(pMC.Rapidity()) > yMax)
133+
if (std::fabs(RecoDecay::y(trackMomentum, pdg->Mass(mcParticle.pdgCode()))) > yMax)
127134
continue;
128135

129-
if (pMC.Pt() < ptMin)
136+
if (RecoDecay::pt(trackMomentum) < ptMin)
130137
continue;
131138
}
132139

133140
if (std::abs(mcParticle.pdgCode()) == PDG_t::kPiPlus) {
134-
histos.fill(HIST("ptGeneratedPion"), pMC.Pt());
141+
histos.fill(HIST("ptGeneratedPion"), RecoDecay::pt(trackMomentum));
135142
}
136143

137144
if (std::abs(mcParticle.pdgCode()) == PDG_t::kKPlus) {
138-
pMC.SetM(o2::constants::physics::MassKaonCharged);
139-
histos.fill(HIST("ptGeneratedKaon"), pMC.Pt());
145+
histos.fill(HIST("ptGeneratedKaon"), RecoDecay::pt(trackMomentum));
140146
}
141147

142148
if (std::abs(mcParticle.pdgCode()) == PDG_t::kProton) {
143-
pMC.SetM(o2::constants::physics::MassProton);
144-
histos.fill(HIST("ptGeneratedProton"), pMC.Pt());
149+
histos.fill(HIST("ptGeneratedProton"), RecoDecay::pt(trackMomentum));
145150
}
146151

147152
histos.fill(HIST("myEventCounter"), 1); // gen event
@@ -157,9 +162,7 @@ struct PtSpectraInclusiveUpc {
157162
auto nSigmaKa = -999.;
158163
auto nSigmaPr = -999.;
159164

160-
LorentzVectorM* pion = new LorentzVectorM();
161-
LorentzVectorM* kaon = new LorentzVectorM();
162-
LorentzVectorM* proton = new LorentzVectorM();
165+
std::array<float, 3> trackMomentum;
163166

164167
for (const auto& track : tracks) {
165168
if (!track.isPVContributor()) {
@@ -183,20 +186,9 @@ struct PtSpectraInclusiveUpc {
183186
continue;
184187
}
185188

186-
pion->SetPx(track.px());
187-
pion->SetPy(track.py());
188-
pion->SetPz(track.pz());
189-
pion->SetM(o2::constants::physics::MassPionCharged);
190-
191-
kaon->SetPx(track.px());
192-
kaon->SetPy(track.py());
193-
kaon->SetPz(track.pz());
194-
kaon->SetM(o2::constants::physics::MassKaonCharged);
195-
196-
proton->SetPx(track.px());
197-
proton->SetPy(track.py());
198-
proton->SetPz(track.pz());
199-
proton->SetM(o2::constants::physics::MassProton);
189+
trackMomentum[0] = track.px();
190+
trackMomentum[1] = track.py();
191+
trackMomentum[2] = track.pz();
200192

201193
if (!track.has_udMcParticle()) {
202194
continue;
@@ -212,37 +204,37 @@ struct PtSpectraInclusiveUpc {
212204
nSigmaPr = track.tpcNSigmaPr();
213205

214206
if (std::abs(nSigmaPi) < sigmaMax) {
215-
if (std::abs(pion->Rapidity()) > yMax) {
207+
if (std::abs(RecoDecay::y(trackMomentum, o2::constants::physics::MassPionCharged)) > yMax) {
216208
continue;
217209
}
218210

219211
if (mcParticle.isPhysicalPrimary()) {
220-
histos.fill(HIST("ptReconstructedTPCPion"), pion->Pt());
212+
histos.fill(HIST("ptReconstructedTPCPion"), track.pt());
221213
histos.fill(HIST("DCAxy_primary_pions"), track.dcaXY());
222214
} else {
223215
histos.fill(HIST("DCAxy_secondary_pions"), track.dcaXY());
224216
}
225217
}
226218
if (std::abs(nSigmaKa) < sigmaMax) {
227-
if (std::abs(kaon->Rapidity()) > yMax) {
219+
if (std::abs(RecoDecay::y(trackMomentum, o2::constants::physics::MassKaonCharged)) > yMax) {
228220
continue;
229221
}
230222

231223
if (mcParticle.isPhysicalPrimary()) {
232-
histos.fill(HIST("ptReconstructedTPCKaon"), kaon->Pt());
224+
histos.fill(HIST("ptReconstructedTPCKaon"), track.pt());
233225
histos.fill(HIST("DCAxy_primary_kaons"), track.dcaXY());
234226
} else {
235227
histos.fill(HIST("DCAxy_secondary_kaons"), track.dcaXY());
236228
}
237229
}
238230

239231
if (std::abs(nSigmaPr) < sigmaMax) {
240-
if (std::abs(proton->Rapidity()) > yMax) {
232+
if (std::abs(RecoDecay::y(trackMomentum, o2::constants::physics::MassProton)) > yMax) {
241233
continue;
242234
}
243235

244236
if (mcParticle.isPhysicalPrimary()) {
245-
histos.fill(HIST("ptReconstructedTPCProton"), proton->Pt());
237+
histos.fill(HIST("ptReconstructedTPCProton"), track.pt());
246238
histos.fill(HIST("DCAxy_primary_protons"), track.dcaXY());
247239
} else {
248240
if (mcParticle.getProcess() == kPDecay) {
@@ -261,12 +253,12 @@ struct PtSpectraInclusiveUpc {
261253
nSigmaPr = track.tofNSigmaPr();
262254

263255
if (std::abs(nSigmaPi) < sigmaMax) {
264-
if (std::abs(pion->Rapidity()) > yMax) {
256+
if (std::abs(RecoDecay::y(trackMomentum, o2::constants::physics::MassPionCharged)) > yMax) {
265257
continue;
266258
}
267259

268260
if (mcParticle.isPhysicalPrimary()) {
269-
histos.fill(HIST("ptReconstructedTOFPion"), pion->Pt());
261+
histos.fill(HIST("ptReconstructedTOFPion"), track.pt());
270262
if (!hasTpc)
271263
histos.fill(HIST("DCAxy_primary_pions"), track.dcaXY());
272264
} else {
@@ -275,12 +267,12 @@ struct PtSpectraInclusiveUpc {
275267
}
276268
}
277269
if (std::abs(nSigmaKa) < sigmaMax) {
278-
if (std::abs(kaon->Rapidity()) > yMax) {
270+
if (std::abs(RecoDecay::y(trackMomentum, o2::constants::physics::MassKaonCharged)) > yMax) {
279271
continue;
280272
}
281273

282274
if (mcParticle.isPhysicalPrimary()) {
283-
histos.fill(HIST("ptReconstructedTOFKaon"), kaon->Pt());
275+
histos.fill(HIST("ptReconstructedTOFKaon"), track.pt());
284276
if (!hasTpc)
285277
histos.fill(HIST("DCAxy_primary_kaons"), track.dcaXY());
286278
} else {
@@ -290,12 +282,12 @@ struct PtSpectraInclusiveUpc {
290282
}
291283

292284
if (std::abs(nSigmaPr) < sigmaMax) {
293-
if (std::abs(proton->Rapidity()) > yMax) {
285+
if (std::abs(RecoDecay::y(trackMomentum, o2::constants::physics::MassProton)) > yMax) {
294286
continue;
295287
}
296288

297289
if (mcParticle.isPhysicalPrimary()) {
298-
histos.fill(HIST("ptReconstructedTOFProton"), proton->Pt());
290+
histos.fill(HIST("ptReconstructedTOFProton"), track.pt());
299291
if (!hasTpc)
300292
histos.fill(HIST("DCAxy_primary_protons"), track.dcaXY());
301293
} else {
@@ -321,9 +313,7 @@ struct PtSpectraInclusiveUpc {
321313
auto nSigmaKa = -999.;
322314
auto nSigmaPr = -999.;
323315

324-
LorentzVectorM* pion = new LorentzVectorM();
325-
LorentzVectorM* kaon = new LorentzVectorM();
326-
LorentzVectorM* proton = new LorentzVectorM();
316+
std::array<float, 3> trackMomentum;
327317

328318
for (const auto& track : tracks) {
329319
if (!track.isPVContributor()) {
@@ -347,20 +337,9 @@ struct PtSpectraInclusiveUpc {
347337
continue;
348338
}
349339

350-
pion->SetPx(track.px());
351-
pion->SetPy(track.py());
352-
pion->SetPz(track.pz());
353-
pion->SetM(o2::constants::physics::MassPionCharged);
354-
355-
kaon->SetPx(track.px());
356-
kaon->SetPy(track.py());
357-
kaon->SetPz(track.pz());
358-
kaon->SetM(o2::constants::physics::MassKaonCharged);
359-
360-
proton->SetPx(track.px());
361-
proton->SetPy(track.py());
362-
proton->SetPz(track.pz());
363-
proton->SetM(o2::constants::physics::MassProton);
340+
trackMomentum[0] = track.px();
341+
trackMomentum[1] = track.py();
342+
trackMomentum[2] = track.pz();
364343

365344
bool hasTpc = false;
366345
// TPC tracks
@@ -371,26 +350,26 @@ struct PtSpectraInclusiveUpc {
371350
nSigmaPr = track.tpcNSigmaPr();
372351

373352
if (std::abs(nSigmaPi) < sigmaMax) {
374-
if (std::abs(pion->Rapidity()) > yMax) {
353+
if (std::abs(RecoDecay::y(trackMomentum, o2::constants::physics::MassPionCharged)) > yMax) {
375354
continue;
376355
}
377-
histos.fill(HIST("ptDataTPCPion"), pion->Pt());
356+
histos.fill(HIST("ptDataTPCPion"), track.pt());
378357
histos.fill(HIST("DCAxy_data_pions"), track.dcaXY());
379358
}
380359

381360
if (std::abs(nSigmaKa) < sigmaMax) {
382-
if (std::abs(kaon->Rapidity()) > yMax) {
361+
if (std::abs(RecoDecay::y(trackMomentum, o2::constants::physics::MassKaonCharged)) > yMax) {
383362
continue;
384363
}
385-
histos.fill(HIST("ptDataTPCKaon"), kaon->Pt());
364+
histos.fill(HIST("ptDataTPCKaon"), track.pt());
386365
histos.fill(HIST("DCAxy_data_kaons"), track.dcaXY());
387366
}
388367

389368
if (std::abs(nSigmaPr) < sigmaMax) {
390-
if (std::abs(proton->Rapidity()) > yMax) {
369+
if (std::abs(RecoDecay::y(trackMomentum, o2::constants::physics::MassProton)) > yMax) {
391370
continue;
392371
}
393-
histos.fill(HIST("ptDataTPCProton"), proton->Pt());
372+
histos.fill(HIST("ptDataTPCProton"), track.pt());
394373
histos.fill(HIST("DCAxy_data_protons"), track.dcaXY());
395374
}
396375
}
@@ -402,27 +381,27 @@ struct PtSpectraInclusiveUpc {
402381
nSigmaPr = track.tofNSigmaPr();
403382

404383
if (std::abs(nSigmaPi) < sigmaMax) {
405-
if (std::abs(pion->Rapidity()) > yMax) {
384+
if (std::abs(RecoDecay::y(trackMomentum, o2::constants::physics::MassPionCharged)) > yMax) {
406385
continue;
407386
}
408-
histos.fill(HIST("ptDataTOFPion"), pion->Pt());
387+
histos.fill(HIST("ptDataTOFPion"), track.pt());
409388
if (!hasTpc)
410389
histos.fill(HIST("DCAxy_data_pions"), track.dcaXY());
411390
}
412391
if (std::abs(nSigmaKa) < sigmaMax) {
413-
if (std::abs(kaon->Rapidity()) > yMax) {
392+
if (std::abs(RecoDecay::y(trackMomentum, o2::constants::physics::MassKaonCharged)) > yMax) {
414393
continue;
415394
}
416-
histos.fill(HIST("ptDataTOFKaon"), kaon->Pt());
395+
histos.fill(HIST("ptDataTOFKaon"), track.pt());
417396
if (!hasTpc)
418397
histos.fill(HIST("DCAxy_data_kaons"), track.dcaXY());
419398
}
420399

421400
if (std::abs(nSigmaPr) < sigmaMax) {
422-
if (std::abs(proton->Rapidity()) > yMax) {
401+
if (std::abs(RecoDecay::y(trackMomentum, o2::constants::physics::MassProton)) > yMax) {
423402
continue;
424403
}
425-
histos.fill(HIST("ptDataTOFProton"), proton->Pt());
404+
histos.fill(HIST("ptDataTOFProton"), track.pt());
426405
if (!hasTpc)
427406
histos.fill(HIST("DCAxy_data_protons"), track.dcaXY());
428407
}

0 commit comments

Comments
 (0)