From 73bc9917fe664c34eaeceb3b71f32e7215637811 Mon Sep 17 00:00:00 2001 From: Marvin Hemmer Date: Fri, 22 Dec 2023 22:09:54 +0100 Subject: [PATCH] [EMCAL-889] AODProducerWorkflowSpec: Fix mcCaloCellLabelCursor filling scheme - Previously when filling the mcCaloCellLabelCursor two vectors were used that were initilized with a single 0 value. This resulted in there always being an extra entry. Also later when calling `particleIds.reserve(cellMClabels.size());` and `amplitudeFraction.reserve(cellMClabels.size());` it only reserved the size for the number of labels we expect. However, since we initilized the vectors with 0 values, when we later emplace_back values `cellMClabels.size()` times, we go over the reserved memory which means the vector might need to reallocate different memory. This is now changed so that the vectors are uninitilized. If there should be no valid label to fill the vectors, the MC ParticleID -1 and the amplitude 0 are stored to ensure the MC cell table is of same length as the normal cell table. --- Detectors/AOD/src/AODProducerWorkflowSpec.cxx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Detectors/AOD/src/AODProducerWorkflowSpec.cxx b/Detectors/AOD/src/AODProducerWorkflowSpec.cxx index 661f94c523189..8b1c7962dfd33 100644 --- a/Detectors/AOD/src/AODProducerWorkflowSpec.cxx +++ b/Detectors/AOD/src/AODProducerWorkflowSpec.cxx @@ -1557,8 +1557,8 @@ void AODProducerWorkflowDPL::addToCaloTable(TCaloHandler& caloHandler, TCaloCurs if (mUseMC) { // Common for PHOS and EMCAL // loop over all MC Labels for the current cell - std::vector particleIds = {0}; - std::vector amplitudeFraction = {0.f}; + std::vector particleIds; + std::vector amplitudeFraction; if (!mEMCselectLeading) { particleIds.reserve(cellMClabels.size()); amplitudeFraction.reserve(cellMClabels.size()); @@ -1585,6 +1585,7 @@ void AODProducerWorkflowDPL::addToCaloTable(TCaloHandler& caloHandler, TCaloCurs particleIds.emplace_back(iter->second); } else { particleIds.emplace_back(-1); // should the mc particle not be in mToStore make sure something (e.g. -1) is saved in particleIds so the length of particleIds is the same es amplitudeFraction! + amplitudeFraction.emplace_back(0.f); LOG(warn) << "CaloTable: Could not find track for mclabel (" << mclabel.getSourceID() << "," << mclabel.getEventID() << "," << mclabel.getTrackID() << ") in the AOD MC store"; if (mMCKineReader) { auto mctrack = mMCKineReader->getTrack(mclabel); @@ -1600,6 +1601,10 @@ void AODProducerWorkflowDPL::addToCaloTable(TCaloHandler& caloHandler, TCaloCurs amplitudeFraction.emplace_back(tmpMaxAmplitude); particleIds.emplace_back(tmpindex); } + if (particleIds.size() == 0) { + particleIds.emplace_back(-1); + amplitudeFraction.emplace_back(0.f); + } mcCaloCellLabelCursor(particleIds, amplitudeFraction); }