Skip to content

Commit 4fe3782

Browse files
authored
[PWGHF] TrackIndexSkimCreator: hoist collision-invariant slices out of the 2/3-prong loops (AliceO2Group#16666)
1 parent 4a07b35 commit 4fe3782

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

PWGHF/TableProducer/trackIndexSkimCreator.cxx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#include <cstdlib>
8484
#include <iterator> // std::distance
8585
#include <numeric>
86+
#include <optional>
8687
#include <string> // std::string
8788
#include <utility> // std::forward
8889
#include <vector> // std::vector
@@ -2400,6 +2401,9 @@ struct HfTrackIndexSkimCreator {
24002401

24012402
// first loop over positive tracks
24022403
const auto groupedTrackIndicesPos1 = positiveFor2And3Prongs->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache);
2404+
const auto groupedTrackIndicesNeg1 = negativeFor2And3Prongs->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache);
2405+
std::optional<decltype(positiveSoftPions->sliceByCached(aod::track::collisionId, 0, cache))> groupedTrackIndicesSoftPionsPos;
2406+
std::optional<decltype(negativeSoftPions->sliceByCached(aod::track::collisionId, 0, cache))> groupedTrackIndicesSoftPionsNeg;
24032407
int lastFilledD0 = -1; // index to be filled in table for D* mesons
24042408
for (auto trackIndexPos1 = groupedTrackIndicesPos1.begin(); trackIndexPos1 != groupedTrackIndicesPos1.end(); ++trackIndexPos1) {
24052409
const auto trackPos1 = trackIndexPos1.template track_as<TTracks>();
@@ -2418,7 +2422,6 @@ struct HfTrackIndexSkimCreator {
24182422
}
24192423

24202424
// first loop over negative tracks
2421-
const auto groupedTrackIndicesNeg1 = negativeFor2And3Prongs->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache);
24222425
for (auto trackIndexNeg1 = groupedTrackIndicesNeg1.begin(); trackIndexNeg1 != groupedTrackIndicesNeg1.end(); ++trackIndexNeg1) {
24232426
const auto trackNeg1 = trackIndexNeg1.template track_as<TTracks>();
24242427

@@ -3198,8 +3201,10 @@ struct HfTrackIndexSkimCreator {
31983201
// if D* enabled and pt of the D0 is larger than the minimum of the D* one within 20% (D* and D0 momenta are very similar, always within 20% according to PYTHIA8)
31993202
// second loop over positive tracks
32003203
if (TESTBIT(whichHypo2Prong[kN2ProngDecays], 0) && (!config.applyKaonPidIn3Prongs || TESTBIT(trackIndexNeg1.isIdentifiedPid(), ChannelKaonPid))) { // only for D0 candidates; moreover if kaon PID enabled, apply to the negative track
3201-
auto groupedTrackIndicesSoftPionsPos = positiveSoftPions->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache);
3202-
for (auto trackIndexPos2 = groupedTrackIndicesSoftPionsPos.begin(); trackIndexPos2 != groupedTrackIndicesSoftPionsPos.end(); ++trackIndexPos2) {
3204+
if (!groupedTrackIndicesSoftPionsPos) {
3205+
groupedTrackIndicesSoftPionsPos.emplace(positiveSoftPions->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache));
3206+
}
3207+
for (auto trackIndexPos2 = groupedTrackIndicesSoftPionsPos->begin(); trackIndexPos2 != groupedTrackIndicesSoftPionsPos->end(); ++trackIndexPos2) {
32033208
if (trackIndexPos2 == trackIndexPos1) {
32043209
continue;
32053210
}
@@ -3235,8 +3240,10 @@ struct HfTrackIndexSkimCreator {
32353240

32363241
// second loop over negative tracks
32373242
if (TESTBIT(whichHypo2Prong[kN2ProngDecays], 1) && (!config.applyKaonPidIn3Prongs || TESTBIT(trackIndexPos1.isIdentifiedPid(), ChannelKaonPid))) { // only for D0bar candidates; moreover if kaon PID enabled, apply to the positive track
3238-
auto groupedTrackIndicesSoftPionsNeg = negativeSoftPions->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache);
3239-
for (auto trackIndexNeg2 = groupedTrackIndicesSoftPionsNeg.begin(); trackIndexNeg2 != groupedTrackIndicesSoftPionsNeg.end(); ++trackIndexNeg2) {
3243+
if (!groupedTrackIndicesSoftPionsNeg) {
3244+
groupedTrackIndicesSoftPionsNeg.emplace(negativeSoftPions->sliceByCached(aod::track::collisionId, collision.globalIndex(), cache));
3245+
}
3246+
for (auto trackIndexNeg2 = groupedTrackIndicesSoftPionsNeg->begin(); trackIndexNeg2 != groupedTrackIndicesSoftPionsNeg->end(); ++trackIndexNeg2) {
32403247
if (trackIndexNeg1 == trackIndexNeg2) {
32413248
continue;
32423249
}

0 commit comments

Comments
 (0)