Skip to content

Commit f900a8c

Browse files
committed
Address Vit's suggestions
1 parent 0c78590 commit f900a8c

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

PWGHF/Tasks/taskMcInjection.cxx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@
2020
#include <Framework/AnalysisDataModel.h>
2121
#include <Framework/AnalysisHelpers.h>
2222
#include <Framework/AnalysisTask.h>
23+
#include <Framework/Configurable.h>
2324
#include <Framework/HistogramRegistry.h>
2425
#include <Framework/HistogramSpec.h>
2526
#include <Framework/InitContext.h>
2627
#include <Framework/runDataProcessing.h>
2728

2829
#include <TH1.h>
30+
#include <TPDGCode.h>
2931

30-
#include <algorithm>
3132
#include <cstdlib>
3233
#include <memory>
34+
#include <unordered_set>
3335
#include <vector>
3436

3537
using namespace o2;
@@ -104,14 +106,14 @@ struct HfTaskMcInjection {
104106
Preslice<aod::McParticles> perMcCollision = aod::mcparticle::mcCollisionId;
105107
PresliceUnsorted<CollisionWLabels> colPerMcCollision = aod::mccollisionlabel::mcCollisionId;
106108

107-
AxisSpec impParBins = {200, 0, 20};
108-
AxisSpec deltaXYbins = {200, -0.05, 0.05};
109-
AxisSpec deltaZbins = {200, -10, 10};
110-
111109
HistogramRegistry registry{"registry", {}};
112110

113111
void init(InitContext&)
114112
{
113+
AxisSpec impParBins = {200, 0, 20};
114+
AxisSpec deltaXYbins = {200, -0.05, 0.05};
115+
AxisSpec deltaZbins = {200, -10, 10};
116+
115117
registry.add("hCharmImpPar", ";Impact parameter (fm);Charm counts", {HistType::kTH1F, {impParBins}});
116118
registry.add("hCollImpPar", ";Impact parameter (fm);Counts", {HistType::kTH1F, {impParBins}});
117119
hCharmPerCollImpPar = registry.add<TH1>("hCharmPerCollImpPar", ";Impact parameter (fm);Charm counts per collision", {HistType::kTH1F, {impParBins}});
@@ -139,18 +141,18 @@ struct HfTaskMcInjection {
139141

140142
bool isCharm(int pdg)
141143
{
142-
if (std::abs(pdg) / 1000 == 4) // o2-linter: disable=pdg/explicit-code magic-number
144+
if (std::abs(pdg) / 1000 == PDG_t::kCharm)
143145
return true;
144-
if (std::abs(pdg) / 100 == 4) // o2-linter: disable=pdg/explicit-code magic-number
146+
if (std::abs(pdg) / 100 == PDG_t::kCharm)
145147
return true;
146148
return false;
147149
}
148150

149151
bool isBeauty(int pdg) // if needed in the future
150152
{
151-
if (std::abs(pdg) / 1000 == 5) // o2-linter: disable=pdg/explicit-code magic-number
153+
if (std::abs(pdg) / 1000 == PDG_t::kBottom)
152154
return true;
153-
if (std::abs(pdg) / 100 == 5) // o2-linter: disable=pdg/explicit-code magic-number
155+
if (std::abs(pdg) / 100 == PDG_t::kBottom)
154156
return true;
155157
return false;
156158
}
@@ -193,7 +195,6 @@ struct HfTaskMcInjection {
193195
// Then we fill the histogram with the distances of the collisions
194196
for (const auto& collision : collSlice) {
195197
const auto collTracks = tracks.sliceBy(tracksPerCollision, collision.globalIndex());
196-
std::vector<int> charmIds{};
197198
int fromSignalEv{0};
198199
if (collision.centFT0C() < centMaxForCollDelta) {
199200
registry.fill(HIST("hDeltaX"), collision.posX() - collision.mcCollision().posX());
@@ -211,13 +212,14 @@ struct HfTaskMcInjection {
211212
registry.fill(HIST("hDeltaZ_NPV_lt2000"), collision.posZ() - collision.mcCollision().posZ());
212213
}
213214
}
215+
std::unordered_set<int> charmIds{};
214216
for (const auto& track : collTracks) {
215217
if (track.has_mcParticle()) {
216218
auto mcPart = track.mcParticle_as<aod::McParticles>();
217219
for (const auto& mother : mcPart.mothers_as<aod::McParticles>()) {
218220
if (isCharm(mother.pdgCode())) { // charm hadron
219-
if (std::find(charmIds.begin(), charmIds.end(), mother.globalIndex()) == charmIds.end()) {
220-
charmIds.push_back(mother.globalIndex());
221+
if (!charmIds.contains(mother.globalIndex())) {
222+
charmIds.emplace(mother.globalIndex());
221223
fromSignalEv += static_cast<int>(!mother.fromBackgroundEvent());
222224
}
223225
break;

0 commit comments

Comments
 (0)