Skip to content

Commit 2e10a1f

Browse files
mhemmer-cernnoferini
authored andcommitted
[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.
1 parent 5cc77ff commit 2e10a1f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Detectors/AOD/src/AODProducerWorkflowSpec.cxx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,8 +1557,8 @@ void AODProducerWorkflowDPL::addToCaloTable(TCaloHandler& caloHandler, TCaloCurs
15571557
if (mUseMC) {
15581558
// Common for PHOS and EMCAL
15591559
// loop over all MC Labels for the current cell
1560-
std::vector<int32_t> particleIds = {0};
1561-
std::vector<float> amplitudeFraction = {0.f};
1560+
std::vector<int32_t> particleIds;
1561+
std::vector<float> amplitudeFraction;
15621562
if (!mEMCselectLeading) {
15631563
particleIds.reserve(cellMClabels.size());
15641564
amplitudeFraction.reserve(cellMClabels.size());
@@ -1585,6 +1585,7 @@ void AODProducerWorkflowDPL::addToCaloTable(TCaloHandler& caloHandler, TCaloCurs
15851585
particleIds.emplace_back(iter->second);
15861586
} else {
15871587
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!
1588+
amplitudeFraction.emplace_back(0.f);
15881589
LOG(warn) << "CaloTable: Could not find track for mclabel (" << mclabel.getSourceID() << "," << mclabel.getEventID() << "," << mclabel.getTrackID() << ") in the AOD MC store";
15891590
if (mMCKineReader) {
15901591
auto mctrack = mMCKineReader->getTrack(mclabel);
@@ -1600,6 +1601,10 @@ void AODProducerWorkflowDPL::addToCaloTable(TCaloHandler& caloHandler, TCaloCurs
16001601
amplitudeFraction.emplace_back(tmpMaxAmplitude);
16011602
particleIds.emplace_back(tmpindex);
16021603
}
1604+
if (particleIds.size() == 0) {
1605+
particleIds.emplace_back(-1);
1606+
amplitudeFraction.emplace_back(0.f);
1607+
}
16031608
mcCaloCellLabelCursor(particleIds,
16041609
amplitudeFraction);
16051610
}

0 commit comments

Comments
 (0)