Skip to content

Commit 954f657

Browse files
authored
[PWGHF] Fix reserve in derived-data creators (#16801)
1 parent db7fc58 commit 954f657

10 files changed

Lines changed: 180 additions & 152 deletions

PWGHF/TableProducer/derivedDataCreatorB0ToDPi.cxx

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct HfDerivedDataCreatorB0ToDPi {
9494

9595
SliceCache cache;
9696
static constexpr double Mass{o2::constants::physics::MassB0};
97+
static constexpr int NHypothesesCand{1}; // Number of possible selection hypotheses per candidate.
9798

9899
using CollisionsWCentMult = soa::Join<aod::Collisions, aod::CentFV0As, aod::CentFT0Ms, aod::CentFT0As, aod::CentFT0Cs, aod::PVMultZeqs>;
99100
using CollisionsWMcCentMult = soa::Join<aod::Collisions, aod::McCollisionLabels, aod::CentFV0As, aod::CentFT0Ms, aod::CentFT0As, aod::CentFT0Cs, aod::PVMultZeqs>;
@@ -139,6 +140,7 @@ struct HfDerivedDataCreatorB0ToDPi {
139140
void fillTablesCandidate(const T& candidate, const U& prongCharm, const V& prongBachelor, int candFlag, double invMass,
140141
double ct, double y, int8_t flagMc, int8_t origin, float mlScore, const std::vector<float>& mlScoresCharm)
141142
{
143+
LOGF(debug, "Filling candidate at derived index %d", rowsCommon.rowCandidateBase.lastIndex() + 1);
142144
rowsCommon.fillTablesCandidate(candidate, invMass, y);
143145
if (fillCandidatePar) {
144146
rowCandidatePar(
@@ -249,38 +251,39 @@ struct HfDerivedDataCreatorB0ToDPi {
249251
rowsCommon.matchedCollisions.clear();
250252
}
251253
}
252-
auto sizeTableColl = collisions.size();
253-
rowsCommon.reserveTablesColl(sizeTableColl);
254+
// const auto sizeTableColl = collisions.size();
255+
// rowsCommon.reserveTablesColl(sizeTableColl);
256+
const auto sizeTableCand = candidates.size() * NHypothesesCand;
257+
rowsCommon.reserveTablesCandidates(sizeTableCand);
258+
reserveTable(rowCandidatePar, fillCandidatePar, sizeTableCand);
259+
reserveTable(rowCandidateParDplus, fillCandidateParDplus, sizeTableCand);
260+
reserveTable(rowCandidateParE, fillCandidateParE, sizeTableCand);
261+
reserveTable(rowCandidateSel, fillCandidateSel, sizeTableCand);
262+
reserveTable(rowCandidateMl, fillCandidateMl, sizeTableCand);
263+
reserveTable(rowCandidateMlDplus, fillCandidateMlDplus, sizeTableCand);
264+
reserveTable(rowCandidateId, fillCandidateId, sizeTableCand);
265+
if constexpr (IsMc) {
266+
reserveTable(rowCandidateMc, fillCandidateMc, sizeTableCand);
267+
}
254268
for (const auto& collision : collisions) {
255-
auto thisCollId = collision.globalIndex();
256-
auto candidatesThisColl = candidates->sliceByCached(aod::hf_cand::collisionId, thisCollId, cache); // FIXME
257-
auto sizeTableCand = candidatesThisColl.size();
258-
LOGF(debug, "Rec. collision %d has %d candidates", thisCollId, sizeTableCand);
269+
const auto thisCollId = collision.globalIndex();
270+
const auto candidatesThisColl = candidates->sliceByCached(aod::hf_cand::collisionId, thisCollId, cache); // FIXME
271+
const auto sizeTableCandThisColl = candidatesThisColl.size();
272+
LOGF(debug, "Rec. collision %d has %d candidates", thisCollId, sizeTableCandThisColl);
259273
// Skip collisions without HF candidates (and without HF particles in matched MC collisions if saving indices of reconstructed collisions matched to MC collisions)
260274
bool mcCollisionHasMcParticles{false};
261275
if constexpr (IsMc) {
262276
mcCollisionHasMcParticles = confDerData.fillMcRCollId && collision.has_mcCollision() && rowsCommon.hasMcParticles[collision.mcCollisionId()];
263277
LOGF(debug, "Rec. collision %d has MC collision %d with MC particles? %s", thisCollId, collision.mcCollisionId(), mcCollisionHasMcParticles ? "yes" : "no");
264278
}
265-
if (sizeTableCand == 0 && (!confDerData.fillMcRCollId || !mcCollisionHasMcParticles)) {
279+
if (sizeTableCandThisColl == 0 && (!confDerData.fillMcRCollId || !mcCollisionHasMcParticles)) {
266280
LOGF(debug, "Skipping rec. collision %d", thisCollId);
267281
continue;
268282
}
269283
LOGF(debug, "Filling rec. collision %d at derived index %d", thisCollId, rowsCommon.rowCollBase.lastIndex() + 1);
270284
rowsCommon.fillTablesCollision<IsMc>(collision);
271285

272286
// Fill candidate properties
273-
rowsCommon.reserveTablesCandidates(sizeTableCand);
274-
reserveTable(rowCandidatePar, fillCandidatePar, sizeTableCand);
275-
reserveTable(rowCandidateParDplus, fillCandidateParDplus, sizeTableCand);
276-
reserveTable(rowCandidateParE, fillCandidateParE, sizeTableCand);
277-
reserveTable(rowCandidateSel, fillCandidateSel, sizeTableCand);
278-
reserveTable(rowCandidateMl, fillCandidateMl, sizeTableCand);
279-
reserveTable(rowCandidateMlDplus, fillCandidateMlDplus, sizeTableCand);
280-
reserveTable(rowCandidateId, fillCandidateId, sizeTableCand);
281-
if constexpr (IsMc) {
282-
reserveTable(rowCandidateMc, fillCandidateMc, sizeTableCand);
283-
}
284287
int8_t flagMcRec = 0, origin = 0;
285288
for (const auto& candidate : candidatesThisColl) {
286289
if constexpr (IsMl) {

PWGHF/TableProducer/derivedDataCreatorBplusToD0Pi.cxx

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ struct HfDerivedDataCreatorBplusToD0Pi {
9797

9898
SliceCache cache;
9999
static constexpr double Mass{o2::constants::physics::MassBPlus};
100+
static constexpr int NHypothesesCand{1}; // Number of possible selection hypotheses per candidate.
100101

101102
using CollisionsWCentMult = soa::Join<aod::Collisions, aod::CentFV0As, aod::CentFT0Ms, aod::CentFT0As, aod::CentFT0Cs, aod::PVMultZeqs>;
102103
using CollisionsWMcCentMult = soa::Join<aod::Collisions, aod::McCollisionLabels, aod::CentFV0As, aod::CentFT0Ms, aod::CentFT0As, aod::CentFT0Cs, aod::PVMultZeqs>;
@@ -142,6 +143,7 @@ struct HfDerivedDataCreatorBplusToD0Pi {
142143
void fillTablesCandidate(const T& candidate, const U& prongCharm, const V& prongBachelor, int candFlag, double invMass,
143144
double ct, double y, int8_t flagMc, int8_t origin, float mlScore, const std::vector<float>& mlScoresCharm)
144145
{
146+
LOGF(debug, "Filling candidate at derived index %d", rowsCommon.rowCandidateBase.lastIndex() + 1);
145147
rowsCommon.fillTablesCandidate(candidate, invMass, y);
146148
if (fillCandidatePar) {
147149
rowCandidatePar(
@@ -284,39 +286,40 @@ struct HfDerivedDataCreatorBplusToD0Pi {
284286
rowsCommon.matchedCollisions.clear();
285287
}
286288
}
287-
auto sizeTableColl = collisions.size();
288-
rowsCommon.reserveTablesColl(sizeTableColl);
289+
// const auto sizeTableColl = collisions.size();
290+
// rowsCommon.reserveTablesColl(sizeTableColl);
291+
const auto sizeTableCand = candidates.size() * NHypothesesCand;
292+
rowsCommon.reserveTablesCandidates(sizeTableCand);
293+
reserveTable(rowCandidatePar, fillCandidatePar, sizeTableCand);
294+
reserveTable(rowCandidateParD0, fillCandidateParD0, sizeTableCand);
295+
reserveTable(rowCandidateParE, fillCandidateParE, sizeTableCand);
296+
reserveTable(rowCandidateParD0E, fillCandidateParD0E, sizeTableCand);
297+
reserveTable(rowCandidateSel, fillCandidateSel, sizeTableCand);
298+
reserveTable(rowCandidateMl, fillCandidateMl, sizeTableCand);
299+
reserveTable(rowCandidateMlD0, fillCandidateMlD0, sizeTableCand);
300+
reserveTable(rowCandidateId, fillCandidateId, sizeTableCand);
301+
if constexpr (IsMc) {
302+
reserveTable(rowCandidateMc, fillCandidateMc, sizeTableCand);
303+
}
289304
for (const auto& collision : collisions) {
290-
auto thisCollId = collision.globalIndex();
291-
auto candidatesThisColl = candidates->sliceByCached(aod::hf_cand::collisionId, thisCollId, cache); // FIXME
292-
auto sizeTableCand = candidatesThisColl.size();
293-
LOGF(debug, "Rec. collision %d has %d candidates", thisCollId, sizeTableCand);
305+
const auto thisCollId = collision.globalIndex();
306+
const auto candidatesThisColl = candidates->sliceByCached(aod::hf_cand::collisionId, thisCollId, cache); // FIXME
307+
const auto sizeTableCandThisColl = candidatesThisColl.size();
308+
LOGF(debug, "Rec. collision %d has %d candidates", thisCollId, sizeTableCandThisColl);
294309
// Skip collisions without HF candidates (and without HF particles in matched MC collisions if saving indices of reconstructed collisions matched to MC collisions)
295310
bool mcCollisionHasMcParticles{false};
296311
if constexpr (IsMc) {
297312
mcCollisionHasMcParticles = confDerData.fillMcRCollId && collision.has_mcCollision() && rowsCommon.hasMcParticles[collision.mcCollisionId()];
298313
LOGF(debug, "Rec. collision %d has MC collision %d with MC particles? %s", thisCollId, collision.mcCollisionId(), mcCollisionHasMcParticles ? "yes" : "no");
299314
}
300-
if (sizeTableCand == 0 && (!confDerData.fillMcRCollId || !mcCollisionHasMcParticles)) {
315+
if (sizeTableCandThisColl == 0 && (!confDerData.fillMcRCollId || !mcCollisionHasMcParticles)) {
301316
LOGF(debug, "Skipping rec. collision %d", thisCollId);
302317
continue;
303318
}
304319
LOGF(debug, "Filling rec. collision %d at derived index %d", thisCollId, rowsCommon.rowCollBase.lastIndex() + 1);
305320
rowsCommon.fillTablesCollision<IsMc>(collision);
306321

307322
// Fill candidate properties
308-
rowsCommon.reserveTablesCandidates(sizeTableCand);
309-
reserveTable(rowCandidatePar, fillCandidatePar, sizeTableCand);
310-
reserveTable(rowCandidateParD0, fillCandidateParD0, sizeTableCand);
311-
reserveTable(rowCandidateParE, fillCandidateParE, sizeTableCand);
312-
reserveTable(rowCandidateParD0E, fillCandidateParD0E, sizeTableCand);
313-
reserveTable(rowCandidateSel, fillCandidateSel, sizeTableCand);
314-
reserveTable(rowCandidateMl, fillCandidateMl, sizeTableCand);
315-
reserveTable(rowCandidateMlD0, fillCandidateMlD0, sizeTableCand);
316-
reserveTable(rowCandidateId, fillCandidateId, sizeTableCand);
317-
if constexpr (IsMc) {
318-
reserveTable(rowCandidateMc, fillCandidateMc, sizeTableCand);
319-
}
320323
int8_t flagMcRec = 0, origin = 0;
321324
for (const auto& candidate : candidatesThisColl) {
322325
if constexpr (IsMl) {

PWGHF/TableProducer/derivedDataCreatorD0ToKPi.cxx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ struct HfDerivedDataCreatorD0ToKPi {
8989

9090
SliceCache cache;
9191
static constexpr double Mass{o2::constants::physics::MassD0};
92+
static constexpr int NHypothesesCand{2}; // Number of possible selection hypotheses per candidate.
9293

9394
using CollisionsWCentMult = soa::Join<aod::Collisions, aod::CentFV0As, aod::CentFT0Ms, aod::CentFT0As, aod::CentFT0Cs, aod::PVMultZeqs>;
9495
using CollisionsWMcCentMult = soa::Join<aod::Collisions, aod::McCollisionLabels, aod::CentFV0As, aod::CentFT0Ms, aod::CentFT0As, aod::CentFT0Cs, aod::PVMultZeqs>;
@@ -150,6 +151,7 @@ struct HfDerivedDataCreatorD0ToKPi {
150151
void fillTablesCandidate(const T& candidate, int candFlag, double invMass, double cosThetaStar, double topoChi2,
151152
double ct, double y, int8_t flagMc, int8_t origin, const std::vector<float>& mlScores)
152153
{
154+
LOGF(debug, "Filling candidate at derived index %d", rowsCommon.rowCandidateBase.lastIndex() + 1);
153155
rowsCommon.fillTablesCandidate(candidate, invMass, y);
154156
if (fillCandidatePar) {
155157
std::array<std::array<std::array<float, 3>, 2>, 2> sigmas{}; // PID nSigma [Expected][Hypothesis][TPC/TOF/TPC+TOF]
@@ -248,36 +250,37 @@ struct HfDerivedDataCreatorD0ToKPi {
248250
rowsCommon.matchedCollisions.clear();
249251
}
250252
}
251-
auto sizeTableColl = collisions.size();
252-
rowsCommon.reserveTablesColl(sizeTableColl);
253+
// const auto sizeTableColl = collisions.size();
254+
// rowsCommon.reserveTablesColl(sizeTableColl);
255+
const auto sizeTableCand = candidates.size() * NHypothesesCand;
256+
rowsCommon.reserveTablesCandidates(sizeTableCand);
257+
reserveTable(rowCandidatePar, fillCandidatePar, sizeTableCand);
258+
reserveTable(rowCandidateParE, fillCandidateParE, sizeTableCand);
259+
reserveTable(rowCandidateSel, fillCandidateSel, sizeTableCand);
260+
reserveTable(rowCandidateMl, fillCandidateMl, sizeTableCand);
261+
reserveTable(rowCandidateId, fillCandidateId, sizeTableCand);
262+
if constexpr (IsMc) {
263+
reserveTable(rowCandidateMc, fillCandidateMc, sizeTableCand);
264+
}
253265
for (const auto& collision : collisions) {
254-
auto thisCollId = collision.globalIndex();
255-
auto candidatesThisColl = candidates->sliceByCached(aod::hf_cand::collisionId, thisCollId, cache); // FIXME
256-
auto sizeTableCand = candidatesThisColl.size();
257-
LOGF(debug, "Rec. collision %d has %d candidates", thisCollId, sizeTableCand);
266+
const auto thisCollId = collision.globalIndex();
267+
const auto candidatesThisColl = candidates->sliceByCached(aod::hf_cand::collisionId, thisCollId, cache); // FIXME
268+
const auto sizeTableCandThisColl = candidatesThisColl.size();
269+
LOGF(debug, "Rec. collision %d has %d candidates", thisCollId, sizeTableCandThisColl);
258270
// Skip collisions without HF candidates (and without HF particles in matched MC collisions if saving indices of reconstructed collisions matched to MC collisions)
259271
bool mcCollisionHasMcParticles{false};
260272
if constexpr (IsMc) {
261273
mcCollisionHasMcParticles = confDerData.fillMcRCollId && collision.has_mcCollision() && rowsCommon.hasMcParticles[collision.mcCollisionId()];
262274
LOGF(debug, "Rec. collision %d has MC collision %d with MC particles? %s", thisCollId, collision.mcCollisionId(), mcCollisionHasMcParticles ? "yes" : "no");
263275
}
264-
if (sizeTableCand == 0 && (!confDerData.fillMcRCollId || !mcCollisionHasMcParticles)) {
276+
if (sizeTableCandThisColl == 0 && (!confDerData.fillMcRCollId || !mcCollisionHasMcParticles)) {
265277
LOGF(debug, "Skipping rec. collision %d", thisCollId);
266278
continue;
267279
}
268280
LOGF(debug, "Filling rec. collision %d at derived index %d", thisCollId, rowsCommon.rowCollBase.lastIndex() + 1);
269281
rowsCommon.fillTablesCollision<IsMc>(collision);
270282

271283
// Fill candidate properties
272-
rowsCommon.reserveTablesCandidates(sizeTableCand);
273-
reserveTable(rowCandidatePar, fillCandidatePar, sizeTableCand);
274-
reserveTable(rowCandidateParE, fillCandidateParE, sizeTableCand);
275-
reserveTable(rowCandidateSel, fillCandidateSel, sizeTableCand);
276-
reserveTable(rowCandidateMl, fillCandidateMl, sizeTableCand);
277-
reserveTable(rowCandidateId, fillCandidateId, sizeTableCand);
278-
if constexpr (IsMc) {
279-
reserveTable(rowCandidateMc, fillCandidateMc, sizeTableCand);
280-
}
281284
int8_t flagMcRec = 0, origin = 0;
282285
for (const auto& candidate : candidatesThisColl) {
283286
if constexpr (IsMc) {

PWGHF/TableProducer/derivedDataCreatorDplusToPiKPi.cxx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ struct HfDerivedDataCreatorDplusToPiKPi {
9090

9191
SliceCache cache;
9292
static constexpr double Mass{o2::constants::physics::MassDPlus};
93+
static constexpr int NHypothesesCand{1}; // Number of possible selection hypotheses per candidate.
9394

9495
using CollisionsWCentMult = soa::Join<aod::Collisions, aod::CentFV0As, aod::CentFT0Ms, aod::CentFT0As, aod::CentFT0Cs, aod::PVMultZeqs>;
9596
using CollisionsWMcCentMult = soa::Join<aod::Collisions, aod::McCollisionLabels, aod::CentFV0As, aod::CentFT0Ms, aod::CentFT0As, aod::CentFT0Cs, aod::PVMultZeqs>;
@@ -134,6 +135,7 @@ struct HfDerivedDataCreatorDplusToPiKPi {
134135
void fillTablesCandidate(const T& candidate, int candFlag, double invMass,
135136
double ct, double y, int8_t flagMc, int8_t origin, int8_t swapping, int8_t flagDecayChan, const std::vector<float>& mlScores)
136137
{
138+
LOGF(debug, "Filling candidate at derived index %d", rowsCommon.rowCandidateBase.lastIndex() + 1);
137139
rowsCommon.fillTablesCandidate(candidate, invMass, y);
138140
if (fillCandidatePar) {
139141
rowCandidatePar(
@@ -246,36 +248,37 @@ struct HfDerivedDataCreatorDplusToPiKPi {
246248
rowsCommon.matchedCollisions.clear();
247249
}
248250
}
249-
auto sizeTableColl = collisions.size();
250-
rowsCommon.reserveTablesColl(sizeTableColl);
251+
// const auto sizeTableColl = collisions.size();
252+
// rowsCommon.reserveTablesColl(sizeTableColl);
253+
const auto sizeTableCand = candidates.size() * NHypothesesCand;
254+
rowsCommon.reserveTablesCandidates(sizeTableCand);
255+
reserveTable(rowCandidatePar, fillCandidatePar, sizeTableCand);
256+
reserveTable(rowCandidateParE, fillCandidateParE, sizeTableCand);
257+
reserveTable(rowCandidateSel, fillCandidateSel, sizeTableCand);
258+
reserveTable(rowCandidateMl, fillCandidateMl, sizeTableCand);
259+
reserveTable(rowCandidateId, fillCandidateId, sizeTableCand);
260+
if constexpr (IsMc) {
261+
reserveTable(rowCandidateMc, fillCandidateMc, sizeTableCand);
262+
}
251263
for (const auto& collision : collisions) {
252-
auto thisCollId = collision.globalIndex();
253-
auto candidatesThisColl = candidates->sliceByCached(aod::hf_cand::collisionId, thisCollId, cache); // FIXME
254-
auto sizeTableCand = candidatesThisColl.size();
255-
LOGF(debug, "Rec. collision %d has %d candidates", thisCollId, sizeTableCand);
264+
const auto thisCollId = collision.globalIndex();
265+
const auto candidatesThisColl = candidates->sliceByCached(aod::hf_cand::collisionId, thisCollId, cache); // FIXME
266+
const auto sizeTableCandThisColl = candidatesThisColl.size();
267+
LOGF(debug, "Rec. collision %d has %d candidates", thisCollId, sizeTableCandThisColl);
256268
// Skip collisions without HF candidates (and without HF particles in matched MC collisions if saving indices of reconstructed collisions matched to MC collisions)
257269
bool mcCollisionHasMcParticles{false};
258270
if constexpr (IsMc) {
259271
mcCollisionHasMcParticles = confDerData.fillMcRCollId && collision.has_mcCollision() && rowsCommon.hasMcParticles[collision.mcCollisionId()];
260272
LOGF(debug, "Rec. collision %d has MC collision %d with MC particles? %s", thisCollId, collision.mcCollisionId(), mcCollisionHasMcParticles ? "yes" : "no");
261273
}
262-
if (sizeTableCand == 0 && (!confDerData.fillMcRCollId || !mcCollisionHasMcParticles)) {
274+
if (sizeTableCandThisColl == 0 && (!confDerData.fillMcRCollId || !mcCollisionHasMcParticles)) {
263275
LOGF(debug, "Skipping rec. collision %d", thisCollId);
264276
continue;
265277
}
266278
LOGF(debug, "Filling rec. collision %d at derived index %d", thisCollId, rowsCommon.rowCollBase.lastIndex() + 1);
267279
rowsCommon.fillTablesCollision<IsMc>(collision);
268280

269281
// Fill candidate properties
270-
rowsCommon.reserveTablesCandidates(sizeTableCand);
271-
reserveTable(rowCandidatePar, fillCandidatePar, sizeTableCand);
272-
reserveTable(rowCandidateParE, fillCandidateParE, sizeTableCand);
273-
reserveTable(rowCandidateSel, fillCandidateSel, sizeTableCand);
274-
reserveTable(rowCandidateMl, fillCandidateMl, sizeTableCand);
275-
reserveTable(rowCandidateId, fillCandidateId, sizeTableCand);
276-
if constexpr (IsMc) {
277-
reserveTable(rowCandidateMc, fillCandidateMc, sizeTableCand);
278-
}
279282
int8_t flagMcRec = 0, origin = 0, swapping = 0, flagDecayChanRec = 0;
280283
for (const auto& candidate : candidatesThisColl) {
281284
if constexpr (IsMl) {

0 commit comments

Comments
 (0)