@@ -1004,6 +1004,14 @@ struct Derivedupcanalysis {
10041004 histos.add (" eventQA/mc/hSelGeneratorsId" , " hSelGeneratorsId" , kTH1D , {axisGeneratorIds});
10051005 }
10061006
1007+ if (doprocessV0sMC || doprocessCascadesMC || doprocessGenerated) {
1008+ histos.add (" generalQA/mc/hInvalidMCReferences" , " Out-of-range MC references; Reference type; Entries" , kTH1D , {{7 , -0.5 , 6.5 }});
1009+ const std::array<const char *, 7 > referenceLabels{" Vertex collision" , " V0 core" , " V0 collision" , " Cascade core" , " Cascade collision" , " Generated V0 collision" , " Generated cascade collision" };
1010+ for (std::size_t i = 0 ; i < referenceLabels.size (); ++i) {
1011+ histos.get <TH1 >(HIST (" generalQA/mc/hInvalidMCReferences" ))->GetXaxis ()->SetBinLabel (i + 1 , referenceLabels[i]);
1012+ }
1013+ }
1014+
10071015 if (doprocessV0sMC || doprocessCascadesMC) {
10081016 // Event QA
10091017 histos.add (" eventQA/mc/hFakeEvents" , " hFakeEvents" , {kTH1D , {{1 , -0 .5f , 0 .5f }}});
@@ -2229,12 +2237,25 @@ struct Derivedupcanalysis {
22292237 }
22302238 }
22312239
2240+ bool hasValidMCReference (int64_t index, int64_t tableSize, int referenceType)
2241+ {
2242+ if (index < 0 ) {
2243+ return false ;
2244+ }
2245+ // has_*() only checks the sign; older derived files can contain stale positive indices.
2246+ if (index >= tableSize) {
2247+ histos.fill (HIST (" generalQA/mc/hInvalidMCReferences" ), referenceType);
2248+ return false ;
2249+ }
2250+ return true ;
2251+ }
2252+
22322253 void processV0sMC (StraCollisonsFullMC const & collisions,
22332254 V0CandidatesMC const & fullV0s,
22342255 DauTracks const &,
22352256 aod::MotherMCParts const &,
2236- StraMCCollisionsFull const &,
2237- V0MCCoresFull const &,
2257+ StraMCCollisionsFull const & mcCollisions ,
2258+ V0MCCoresFull const & v0MCCores ,
22382259 NeutronsMC const & neutrons)
22392260 {
22402261 v0sGrouped.clear ();
@@ -2244,7 +2265,7 @@ struct Derivedupcanalysis {
22442265 }
22452266
22462267 for (const auto & collision : collisions) {
2247- if (!collision.has_straMCCollision ( )) {
2268+ if (!hasValidMCReference ( collision.straMCCollisionId (), mcCollisions. size (), 0 )) {
22482269 histos.fill (HIST (" eventQA/mc/hFakeEvents" ), 0 ); // no assoc. MC collisions
22492270 continue ;
22502271 }
@@ -2300,9 +2321,9 @@ struct Derivedupcanalysis {
23002321 std::bitset<kSelNum > selMap = computeBitmapV0 (v0, collision);
23012322
23022323 if (doMCAssociation) {
2303- if (v0.has_v0MCCore ( )) {
2324+ if (hasValidMCReference ( v0.v0MCCoreId (), v0MCCores. size (), 1 )) {
23042325 const auto & v0MC = v0.v0MCCore_as <V0MCCoresFull>();
2305- if (v0MC.has_straMCCollision () ) {
2326+ if (hasValidMCReference ( v0MC.straMCCollisionId (), mcCollisions. size (), 2 ) && v0MC. pdgCode () != - 1 ) {
23062327 const auto & candidateCollision = v0MC.straMCCollision_as <StraMCCollisionsFull>();
23072328 if (std::find (generatorIds->begin (), generatorIds->end (), candidateCollision.generatorsID ()) != generatorIds->end ()) {
23082329 histos.fill (HIST (" generalQA/mc/h3dV0CollisionAssociation" ), candidateCollision.generatorsID (), mcCollision.generatorsID (), v0MC.straMCCollisionId () == mcCollision.globalIndex ());
@@ -2368,8 +2389,8 @@ struct Derivedupcanalysis {
23682389 CascadeCandidatesMC const & fullCascades,
23692390 DauTracks const &,
23702391 aod::MotherMCParts const &,
2371- StraMCCollisionsFull const &,
2372- CascMCCoresFull const &,
2392+ StraMCCollisionsFull const & mcCollisions ,
2393+ CascMCCoresFull const & cascMCCores ,
23732394 NeutronsMC const & neutrons)
23742395 {
23752396 cascadesGrouped.clear ();
@@ -2379,7 +2400,7 @@ struct Derivedupcanalysis {
23792400 }
23802401
23812402 for (const auto & collision : collisions) {
2382- if (!collision.has_straMCCollision ( )) {
2403+ if (!hasValidMCReference ( collision.straMCCollisionId (), mcCollisions. size (), 0 )) {
23832404 histos.fill (HIST (" eventQA/mc/hFakeEvents" ), 0 ); // no assoc. MC collisions
23842405 continue ;
23852406 }
@@ -2432,9 +2453,9 @@ struct Derivedupcanalysis {
24322453 std::bitset<kSelNum > selMap = computeBitmapCascade (casc, collision);
24332454
24342455 if (doMCAssociation) {
2435- if (casc.has_cascMCCore ( )) {
2456+ if (hasValidMCReference ( casc.cascMCCoreId (), cascMCCores. size (), 3 )) {
24362457 const auto & cascMC = casc.cascMCCore_as <CascMCCoresFull>();
2437- if (cascMC.has_straMCCollision () ) {
2458+ if (hasValidMCReference ( cascMC.straMCCollisionId (), mcCollisions. size (), 4 ) && cascMC. pdgCode () != - 1 ) {
24382459 const auto & candidateCollision = cascMC.straMCCollision_as <StraMCCollisionsFull>();
24392460 if (std::find (generatorIds->begin (), generatorIds->end (), candidateCollision.generatorsID ()) != generatorIds->end ()) {
24402461 histos.fill (HIST (" generalQA/mc/h3dCascadeCollisionAssociation" ), candidateCollision.generatorsID (), mcCollision.generatorsID (), cascMC.straMCCollisionId () == mcCollision.globalIndex ());
@@ -2464,7 +2485,7 @@ struct Derivedupcanalysis {
24642485 // V0 start
24652486 for (auto const & v0MC : V0MCCores) {
24662487 // Consider only primaries
2467- if (!v0MC.has_straMCCollision () || !v0MC.isPhysicalPrimary ( ))
2488+ if (!v0MC.isPhysicalPrimary () || !hasValidMCReference ( v0MC.straMCCollisionId (), mcCollisions. size (), 5 ))
24682489 continue ;
24692490
24702491 // Kinematics (|y| < rapidityCut)
@@ -2531,7 +2552,7 @@ struct Derivedupcanalysis {
25312552 // Cascade start
25322553 for (auto const & cascMC : CascMCCores) {
25332554 // Consider only primaries
2534- if (!cascMC.has_straMCCollision () || !cascMC.isPhysicalPrimary ( ))
2555+ if (!cascMC.isPhysicalPrimary () || !hasValidMCReference ( cascMC.straMCCollisionId (), mcCollisions. size (), 6 ))
25352556 continue ;
25362557 // Kinematics (|y| < rapidityCut)
25372558 float pTmc = cascMC.ptMC ();
0 commit comments