Skip to content

Commit ffc9dea

Browse files
authored
[PWGCF] Fix slow event mixing (#15942)
1 parent 6b2b283 commit ffc9dea

3 files changed

Lines changed: 106 additions & 59 deletions

File tree

PWGCF/Femto/Core/pairHistManager.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ enum PairHist {
100100

101101
// mixing qa
102102
kSeNpart1VsNpart2, // number of unique particles 1 vs unique number of particles 2 in each same event
103-
kMeMixingWindow, // mixing window size
103+
kMeMixingWindowRaw, // mixing window size
104+
kMeMixingWindowEffective, // mixing window size, counting event pairs with particle pairs
104105
kMeNpart1VsNpart2, // number of unique particles 1 vs number of unique particles 2 in each mixed event
105106
kMeVtz1VsMult1VsCent1VsVtz2VsMult2VsCent2, // correlation of event properties in each mixing bin
106107

@@ -233,7 +234,8 @@ constexpr std::array<histmanager::HistInfo<PairHist>, kPairHistogramLast>
233234
{kTrueMultVsMult, o2::framework::HistType::kTH2F, "hTrueMultVsMult", "Multiplicity_{True} vs Multiplicity; Multiplicity_{True} ; Multiplicity"},
234235
{kTrueCentVsCent, o2::framework::HistType::kTH2F, "hTrueCentVsCent", "Centrality_{True} vs Centrality; Centrality_{True} (%); Centrality (%)"},
235236
{kSeNpart1VsNpart2, o2::framework::HistType::kTH2F, "hSeNpart1VsNpart2", "# unique particle 1 vs # unique particle 2 in each same event; # partilce 1; # particle 2"},
236-
{kMeMixingWindow, o2::framework::HistType::kTH1F, "hMeMixingWindow", "Mixing Window; Mixing Windown ; Entries"},
237+
{kMeMixingWindowRaw, o2::framework::HistType::kTH1F, "hMeMixingWindowRaw", "Raw Mixing Window; Raw Mixing Window ; Entries"},
238+
{kMeMixingWindowEffective, o2::framework::HistType::kTH1F, "hMeMixingWindowEffective", "Effective Mixing Window; Effective Mixing Windown ; Entries"},
237239
{kMeNpart1VsNpart2, o2::framework::HistType::kTH2F, "hMeNpart1VsNpart2", "# unique particle 1 vs # unique partilce 2 in each mixing bin; # partilce 1; # particle 2"},
238240
{kMeVtz1VsMult1VsCent1VsVtz2VsMult2VsCent2, o2::framework::HistType::kTHnSparseF, "hVtz1VsMult1VsCent1VsVtz2VsMult2VsCent2", "Mixing bins; V_{z,1} (cm); multiplicity_{1}; centrality_{1} (%); V_{z,2} (cm); multiplicity_{2}; centrality_{2} (%)"},
239241
}};
@@ -276,7 +278,8 @@ constexpr std::array<histmanager::HistInfo<PairHist>, kPairHistogramLast>
276278
{kKstarVsMtVsMinvVsPt1VsPt2VsMultVsCent, {confAnalysis.kstar, confAnalysis.mt, confAnalysis.massInv, confAnalysis.pt1, confAnalysis.pt2, confAnalysis.multiplicity, confAnalysis.centrality}}, \
277279
{kDalitz, {confAnalysis.kstar, confAnalysis.dalitzMtot, confAnalysis.dalitzM12, confAnalysis.dalitzM13}}, \
278280
{kSeNpart1VsNpart2, {confMixing.particleBinning, confMixing.particleBinning}}, \
279-
{kMeMixingWindow, {confMixing.particleBinning}}, \
281+
{kMeMixingWindowRaw, {confMixing.particleBinning}}, \
282+
{kMeMixingWindowEffective, {confMixing.particleBinning}}, \
280283
{kMeNpart1VsNpart2, {confMixing.particleBinning, confMixing.particleBinning}}, \
281284
{kMeVtz1VsMult1VsCent1VsVtz2VsMult2VsCent2, {confMixing.vtxBins, confMixing.multBins, confMixing.centBins, confMixing.vtxBins, confMixing.multBins, confMixing.centBins}},
282285

@@ -599,7 +602,9 @@ class PairHistManager
599602
void resetTrackedParticlesPerEvent()
600603
{
601604
mParticles1PerEvent.clear();
605+
mParticles1PerEvent.reserve(100);
602606
mParticles2PerEvent.clear();
607+
mParticles2PerEvent.reserve(100);
603608
}
604609

605610
void fillMixingQaSe()
@@ -616,10 +621,11 @@ class PairHistManager
616621
}
617622
}
618623

619-
void fillMixingQaMePerMixingBin(int windowSize)
624+
void fillMixingQaMePerMixingBin(int windowSizeRaw, int windowSizeEffective)
620625
{
621-
if (mEventMixingQa) {
622-
mHistogramRegistry->fill(HIST(prefix) + HIST(MixingQaDir) + HIST(getHistName(kMeMixingWindow, HistTable)), windowSize);
626+
if (mPairCorrelationQa) {
627+
mHistogramRegistry->fill(HIST(prefix) + HIST(MixingQaDir) + HIST(getHistName(kMeMixingWindowRaw, HistTable)), windowSizeRaw);
628+
mHistogramRegistry->fill(HIST(prefix) + HIST(MixingQaDir) + HIST(getHistName(kMeMixingWindowEffective, HistTable)), windowSizeEffective);
623629
}
624630
}
625631

@@ -732,7 +738,8 @@ class PairHistManager
732738
{
733739
std::string mcDir = std::string(prefix) + std::string(MixingQaDir);
734740
if (mPairCorrelationQa) {
735-
mHistogramRegistry->add(mcDir + getHistNameV2(kMeMixingWindow, HistTable), getHistDesc(kMeMixingWindow, HistTable), getHistType(kMeMixingWindow, HistTable), {Specs.at(kMeMixingWindow)});
741+
mHistogramRegistry->add(mcDir + getHistNameV2(kMeMixingWindowRaw, HistTable), getHistDesc(kMeMixingWindowRaw, HistTable), getHistType(kMeMixingWindowRaw, HistTable), {Specs.at(kMeMixingWindowRaw)});
742+
mHistogramRegistry->add(mcDir + getHistNameV2(kMeMixingWindowEffective, HistTable), getHistDesc(kMeMixingWindowEffective, HistTable), getHistType(kMeMixingWindowEffective, HistTable), {Specs.at(kMeMixingWindowEffective)});
736743
mHistogramRegistry->add(mcDir + getHistNameV2(kMeNpart1VsNpart2, HistTable), getHistDesc(kMeNpart1VsNpart2, HistTable), getHistType(kMeNpart1VsNpart2, HistTable), {Specs.at(kMeNpart1VsNpart2)});
737744
}
738745
if (mEventMixingQa) {

PWGCF/Femto/Core/pairProcessHelpers.h

Lines changed: 90 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ void processSameEvent(T1 const& SliceParticle1,
281281
PairHistManager.fillMixingQaSe();
282282
}
283283

284-
// process mixed event
284+
// mixed event in data
285285
template <modes::Mode mode,
286286
typename T1,
287287
typename T2,
@@ -304,54 +304,79 @@ void processMixedEvent(T1 const& Collisions,
304304
T9& CprManager,
305305
T10& PcManager)
306306
{
307-
bool firstBin = true;
308-
int windowSize = 0;
309-
PairHistManager.resetTrackedParticlesPerEvent();
310-
auto pairGenerator = o2::soa::selfCombinations(policy, depth, -1, Collisions, Collisions);
311-
for (auto pairIterator = pairGenerator.begin(); pairIterator != pairGenerator.end(); pairIterator++) {
312-
auto const& [collision1, collision2] = *pairIterator;
313-
if (pairIterator.isNewWindow()) { // is true for the first bin, so we skip
314-
if (!firstBin) {
315-
// we fill histograms after we finish processing one mixing bin
316-
// the very first bin is considered a new window, so we skp it
317-
PairHistManager.fillMixingQaMePerMixingBin(windowSize);
307+
int64_t lastCollisionIndex = -1;
308+
int windowSizeRaw = 0;
309+
int windowSizeEffective = 0;
310+
311+
for (auto const& [collision1, collision2] : o2::soa::selfCombinations(policy, depth, -1, Collisions, Collisions)) {
312+
313+
// --- new window ---
314+
if (collision1.globalIndex() != lastCollisionIndex) {
315+
if (lastCollisionIndex != -1) {
316+
PairHistManager.fillMixingQaMePerMixingBin(windowSizeRaw, windowSizeEffective);
318317
}
319-
windowSize = pairIterator.currentWindowNeighbours();
320-
firstBin = false;
318+
windowSizeRaw = 0;
319+
windowSizeEffective = 0;
320+
lastCollisionIndex = collision1.globalIndex();
321321
}
322+
323+
++windowSizeRaw;
324+
322325
if (collision1.magField() != collision2.magField()) {
323-
LOG(warn) << "Tried to mixng to events with different magntic field. This should not happen...";
326+
LOG(warn) << "Tried mixing events with different magnetic field.";
324327
continue;
325328
}
329+
326330
CprManager.setMagField(collision1.magField());
331+
327332
auto sliceParticle1 = Partition1->sliceByCached(o2::aod::femtobase::stored::fColId, collision1.globalIndex(), cache);
333+
328334
auto sliceParticle2 = Partition2->sliceByCached(o2::aod::femtobase::stored::fColId, collision2.globalIndex(), cache);
329335

330336
PairHistManager.resetTrackedParticlesPerEvent();
337+
338+
if (sliceParticle1.size() == 0 || sliceParticle2.size() == 0) {
339+
PairHistManager.fillMixingQaMePerEvent();
340+
continue;
341+
}
342+
343+
bool hasValidPair = false;
331344
PairHistManager.fillMixingQaMe(collision1, collision2);
332345
for (auto const& [p1, p2] : o2::soa::combinations(o2::soa::CombinationsFullIndexPolicy(sliceParticle1, sliceParticle2))) {
333-
// pair cleaning
346+
334347
if (!PcManager.isCleanPair(p1, p2, TrackTable)) {
335348
continue;
336349
}
337-
// Close pair rejection
350+
338351
CprManager.setPair(p1, p2, TrackTable);
339352
if (CprManager.isClosePair()) {
340353
continue;
341354
}
355+
342356
PairHistManager.setPair(p1, p2, TrackTable, collision1, collision2);
343357
CprManager.fill(PairHistManager.getKstar());
358+
344359
if (PairHistManager.checkPairCuts()) {
345-
PairHistManager.template fill<mode>();
360+
hasValidPair = true;
346361
PairHistManager.trackParticlesPerEvent(p1, p2);
362+
PairHistManager.template fill<mode>();
347363
}
348364
}
365+
366+
if (hasValidPair) {
367+
++windowSizeEffective;
368+
}
369+
349370
PairHistManager.fillMixingQaMePerEvent();
350371
}
351-
PairHistManager.fillMixingQaMePerMixingBin(windowSize); // fill last window
372+
373+
// --- final window ---
374+
if (windowSizeRaw > 0) {
375+
PairHistManager.fillMixingQaMePerMixingBin(windowSizeRaw, windowSizeEffective);
376+
}
352377
}
353378

354-
// process mixed event with mc information
379+
// process mixed event in mc
355380
template <modes::Mode mode,
356381
typename T1,
357382
typename T2,
@@ -386,64 +411,80 @@ void processMixedEvent(T1 const& Collisions,
386411
T15& CprManager,
387412
T16& PcManager)
388413
{
389-
bool firstBin = true;
390-
int windowSize = 0;
391-
PairHistManager.resetTrackedParticlesPerEvent();
392-
auto pairGenerator = o2::soa::selfCombinations(policy, depth, -1, Collisions, Collisions);
393-
for (auto pairIterator = pairGenerator.begin(); pairIterator != pairGenerator.end(); ++pairIterator) {
394-
auto const& [collision1, collision2] = *pairIterator;
395-
// handle mixing windows (same as data)
396-
if (pairIterator.isNewWindow()) {
397-
if (!firstBin) {
398-
PairHistManager.fillMixingQaMePerMixingBin(windowSize);
414+
int64_t lastCollisionIndex = -1;
415+
int windowSizeRaw = 0;
416+
int windowSizeEffective = 0;
417+
418+
for (auto const& [collision1, collision2] : o2::soa::selfCombinations(policy, depth, -1, Collisions, Collisions)) {
419+
if (collision1.globalIndex() != lastCollisionIndex) {
420+
if (lastCollisionIndex != -1) {
421+
PairHistManager.fillMixingQaMePerMixingBin(windowSizeRaw, windowSizeEffective);
399422
}
400-
windowSize = pairIterator.currentWindowNeighbours();
401-
firstBin = false;
423+
windowSizeRaw = 0;
424+
windowSizeEffective = 0;
425+
lastCollisionIndex = collision1.globalIndex();
402426
}
427+
428+
++windowSizeRaw;
429+
403430
if (collision1.magField() != collision2.magField()) {
404-
LOG(warn) << "Tried to mixng to events with different magntic field. This should not happen...";
431+
LOG(warn) << "Tried mixing events with different magnetic field.";
405432
continue;
406433
}
434+
407435
CprManager.setMagField(collision1.magField());
408436

409-
auto sliceParticle1 = Partition1->sliceByCached(
410-
o2::aod::femtobase::stored::fColId,
411-
collision1.globalIndex(),
412-
cache);
413-
auto sliceParticle2 = Partition2->sliceByCached(
414-
o2::aod::femtobase::stored::fColId,
415-
collision2.globalIndex(),
416-
cache);
437+
auto sliceParticle1 = Partition1->sliceByCached(o2::aod::femtobase::stored::fColId, collision1.globalIndex(), cache);
438+
439+
auto sliceParticle2 = Partition2->sliceByCached(o2::aod::femtobase::stored::fColId, collision2.globalIndex(), cache);
417440

418441
PairHistManager.resetTrackedParticlesPerEvent();
442+
443+
if (sliceParticle1.size() == 0 || sliceParticle2.size() == 0) {
444+
PairHistManager.fillMixingQaMePerEvent();
445+
continue;
446+
}
447+
448+
bool hasValidPair = false;
419449
PairHistManager.fillMixingQaMe(collision1, collision2);
420-
for (auto const& [p1, p2] :
421-
o2::soa::combinations(o2::soa::CombinationsFullIndexPolicy(sliceParticle1, sliceParticle2))) {
422-
// particle cleaning (MC-specific)
450+
451+
for (auto const& [p1, p2] : o2::soa::combinations(o2::soa::CombinationsFullIndexPolicy(sliceParticle1, sliceParticle2))) {
452+
423453
if (!ParticleCleaner1.isClean(p1, mcParticles, mcMothers, mcPartonicMothers) ||
424454
!ParticleCleaner2.isClean(p2, mcParticles, mcMothers, mcPartonicMothers)) {
425455
continue;
426456
}
427-
// pair cleaning
457+
428458
if (!PcManager.isCleanPair(p1, p2, TrackTable)) {
429459
continue;
430460
}
431-
// close pair rejection
461+
432462
CprManager.setPair(p1, p2, TrackTable);
433463
if (CprManager.isClosePair()) {
434464
continue;
435465
}
466+
436467
PairHistManager.setPairMc(p1, p2, TrackTable, mcParticles, collision1, collision2, mcCollisions);
468+
437469
CprManager.fill(PairHistManager.getKstar());
470+
438471
if (PairHistManager.checkPairCuts()) {
439-
PairHistManager.template fill<mode>();
472+
hasValidPair = true;
440473
PairHistManager.trackParticlesPerEvent(p1, p2);
474+
PairHistManager.template fill<mode>();
441475
}
442476
}
477+
478+
if (hasValidPair) {
479+
++windowSizeEffective;
480+
}
481+
443482
PairHistManager.fillMixingQaMePerEvent();
444483
}
445-
// final window
446-
PairHistManager.fillMixingQaMePerMixingBin(windowSize);
484+
485+
if (windowSizeRaw > 0) {
486+
PairHistManager.fillMixingQaMePerMixingBin(windowSizeRaw, windowSizeEffective);
487+
}
447488
}
448489

449490
} // namespace pairprocesshelpers

PWGCF/Femto/Macros/cutculatorGui.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import tkinter as tk
2020
from tkinter import ttk, filedialog, messagebox
2121
import argparse
22-
import sys
2322

2423
try:
2524
import ROOT
@@ -128,11 +127,11 @@ def _build_ui(self):
128127
top = tk.Frame(self, bg=BG, pady=10, padx=18)
129128
top.pack(fill="x")
130129

131-
tk.Label(top, text="CutCulator", font=FONT_TITLE, bg=BG, fg=ACCENT).pack(side="left")
130+
tk.Label(top, text="CutCulator", font=FONT_TITLE, bg=BG, fg=ACCENT).pack(side="left")
132131

133132
btn_frame = tk.Frame(top, bg=BG)
134133
btn_frame.pack(side="right")
135-
self._btn_open = self._make_button(btn_frame, "📂 Open ROOT file", self._open_file_dialog, ACCENT)
134+
self._btn_open = self._make_button(btn_frame, "Open ROOT file", self._open_file_dialog, ACCENT)
136135
self._btn_open.pack(side="left", padx=4)
137136

138137
# ── file + histogram selector bar ──

0 commit comments

Comments
 (0)