Skip to content

Commit 151669d

Browse files
committed
Add protection for V0/casc. MC matching in HF PID task.
1 parent 8d79be4 commit 151669d

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

PWGHF/Tasks/taskPidStudies.cxx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,18 @@ struct HfTaskPidStudies {
305305
}
306306

307307
template <typename T1>
308-
int isMatched(const T1& cand)
308+
int isMatched(const T1& cand, int mcCoresSize)
309309
{
310310
if constexpr (std::is_same<T1, V0sMcRec::iterator>::value) {
311311
if (!cand.has_v0MCCore()) {
312312
return Particle::NotMatched;
313313
}
314314
auto v0MC = cand.template v0MCCore_as<aod::V0MCCores>();
315+
int v0MCId = cand.template v0MCCoreId();
316+
if (v0MCId >= mcCoresSize) {
317+
// LOG(warn) << "v0MCId (" << v0MCId << ") >= MCCores size (" << mcCoresSize << "). Some issue in the data model?";
318+
return Particle::NotMatched;
319+
}
315320
if (v0MC.pdgCode() == kK0Short && v0MC.pdgCodeNegative() == -kPiPlus && v0MC.pdgCodePositive() == kPiPlus) {
316321
return Particle::K0s;
317322
}
@@ -509,7 +514,7 @@ struct HfTaskPidStudies {
509514

510515
void processV0Mc(CollisionsMc const& /*mcCollisions*/,
511516
V0sMcRec const& v0s,
512-
aod::V0MCCores const&,
517+
aod::V0MCCores const& v0MCCores,
513518
aod::McParticles const& /*particlesMc*/,
514519
PidTracks const& /*tracks*/,
515520
aod::BCsWithTimestamps const&)
@@ -522,7 +527,8 @@ struct HfTaskPidStudies {
522527
continue;
523528
}
524529
if (isSelectedV0AsK0s(v0) || isSelectedV0AsLambda(v0)) {
525-
int const matched = isMatched(v0);
530+
int const v0MCCoresSize = v0MCCores.size();
531+
int const matched = isMatched(v0, v0MCCoresSize);
526532
if (matched != Particle::NotMatched) {
527533
fillTree<true, CollisionsMc>(v0, matched);
528534
}
@@ -552,7 +558,7 @@ struct HfTaskPidStudies {
552558

553559
void processCascMc(CollisionsMc const& /*mcCollisions*/,
554560
CascsMcRec const& cascades,
555-
aod::CascMCCores const&,
561+
aod::CascMCCores const& cascMCCores,
556562
aod::McParticles const& /*particlesMc*/,
557563
PidTracks const&,
558564
aod::BCsWithTimestamps const&)
@@ -565,7 +571,8 @@ struct HfTaskPidStudies {
565571
continue;
566572
}
567573
if (isSelectedCascAsOmega<CollisionsMc>(casc)) {
568-
int const matched = isMatched(casc);
574+
int const cascMCCoresSize = cascMCCores.size();
575+
int const matched = isMatched(casc, cascMCCoresSize);
569576
if (matched != Particle::NotMatched) {
570577
fillTree<false, CollisionsMc>(casc, matched);
571578
}

0 commit comments

Comments
 (0)