From 2e771fae262b2b5e4074db3f2e3b3fef09c200a3 Mon Sep 17 00:00:00 2001 From: Jseo Date: Wed, 18 Nov 2026 15:20:37 +0100 Subject: [PATCH 1/3] Event mixing in classes of the selected pairing --- PWGDQ/Core/VarManager.cxx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PWGDQ/Core/VarManager.cxx b/PWGDQ/Core/VarManager.cxx index 9b952600152..b7e889fa91e 100644 --- a/PWGDQ/Core/VarManager.cxx +++ b/PWGDQ/Core/VarManager.cxx @@ -1722,6 +1722,8 @@ void VarManager::SetDefaultVarNames() fgVariableUnits[kR3EP] = ""; fgVariableNames[kNPairsPerEvent] = "number of pairs per event"; fgVariableUnits[kNPairsPerEvent] = ""; + fgVariableNames[kNSelTracksForPairing] = "number of selected tracks for pairing"; + fgVariableUnits[kNSelTracksForPairing] = ""; fgVariableNames[kPairMass] = "mass"; fgVariableUnits[kPairMass] = "GeV/c2"; fgVariableNames[kPairMassDau] = "mass dilepton"; @@ -2402,6 +2404,7 @@ void VarManager::SetDefaultVarNames() fgVarNamesMap["kTwoR2EP1"] = kTwoR2EP1; fgVarNamesMap["kTwoR2EP2"] = kTwoR2EP2; fgVarNamesMap["kNPairsPerEvent"] = kNPairsPerEvent; + fgVarNamesMap["kNSelTracksForPairing"] = kNSelTracksForPairing; fgVarNamesMap["kInteractionRate"] = kInteractionRate; fgVarNamesMap["kMuPerBc"] = kMuPerBc; fgVarNamesMap["kNEventWiseVariables"] = kNEventWiseVariables; From 6be1aa91a938cc764f26d8188a73de6ce92736dc Mon Sep 17 00:00:00 2001 From: Jseo Date: Wed, 18 Nov 2026 15:28:56 +0100 Subject: [PATCH 2/3] commit --- PWGDQ/Core/VarManager.h | 10 +++ PWGDQ/Tasks/tableReader_withAssoc.h | 116 ++++++++++++++++++++++++---- 2 files changed, 110 insertions(+), 16 deletions(-) diff --git a/PWGDQ/Core/VarManager.h b/PWGDQ/Core/VarManager.h index 6508b02e3b4..fde47fd6cda 100644 --- a/PWGDQ/Core/VarManager.h +++ b/PWGDQ/Core/VarManager.h @@ -525,6 +525,7 @@ class VarManager : public TObject kA2EPME_FT0C, // A2 of VM to FT0C event plane for ME technique kA2EPME_FT0A, // A2 of VM to FT0A event plane for ME technique kNPairsPerEvent, // number of pairs per event in same-event or mixed-event pairing + kNSelTracksForPairing,// number of tracks in the event passing the pairing track filter (barrel); in ME = that of the first event kInteractionRate, kMuPerBc, @@ -4822,6 +4823,15 @@ void VarManager::FillPairMEAcrossTFs(T const& t1, T const& t2, float* values) values[kEta] = v12.Eta(); values[kPhi] = RecoDecay::constrainAngle(v12.Phi()); values[kRap] = -v12.Rapidity(); + values[kPt1] = t1.pt; + values[kEta1] = t1.eta; + values[kPhi1] = t1.phi; + values[kPt2] = t2.pt; + values[kEta2] = t2.eta; + values[kPhi2] = t2.phi; + if (fgUsedVars[kDeltaPhiPair2]) { + values[kDeltaPhiPair2] = RecoDecay::constrainAngle(v1.Phi() - v2.Phi(), -o2::constants::math::PIHalf); + } if (fgUsedVars[kCosThetaStarRandom] || fgUsedVars[kCosThetaStarFT0C]) { ROOT::Math::Boost boostv12{v12.BoostToCM()}; diff --git a/PWGDQ/Tasks/tableReader_withAssoc.h b/PWGDQ/Tasks/tableReader_withAssoc.h index 5e2ee59de27..34399d36d87 100644 --- a/PWGDQ/Tasks/tableReader_withAssoc.h +++ b/PWGDQ/Tasks/tableReader_withAssoc.h @@ -1511,6 +1511,7 @@ struct AnalysisSameEventPairing { o2::framework::Configurable fConfigMixingVariables{"cfgMixingVars", "", "Mixing configs separated by a comma, default no mixing"}; o2::framework::Configurable fConfigMixingVariablesJson{"cfgMixingVarsJSON", "", "Mixing configs in JSON format"}; o2::framework::Configurable fConfigRunMixingAcrossTFs{"cfgRunMixingAcrossTFs", false, "If true, run event mixing using the MixingHandler which accumulates events across multiple TFs"}; + o2::framework::Configurable fConfigMixingNSelEdges{"cfgMixingNSelEdges", "", "Comma separated class edges in the number of selected pairing tracks per event"}; // o2::framework::Configurable fConfigAddEventMixingHistogram{"cfgAddEventMixingHistogram", "", "Comma separated list of histograms"}; o2::framework::Configurable fConfigAddSEPHistogram{"cfgAddSEPHistogram", "", "Comma separated list of histograms"}; o2::framework::Configurable fConfigAddJSONHistograms{"cfgAddJSONHistograms", "", "Histograms in JSON format"}; @@ -1587,6 +1588,7 @@ struct AnalysisSameEventPairing { int fNCutsMuon = 0; int fNPairCuts = 0; int fNPairPerEvent = 0; + std::vector fMixNSelEdges; bool fEnableBarrelMixingHistos = false; bool fEnableBarrelHistos = false; @@ -1606,6 +1608,9 @@ struct AnalysisSameEventPairing { { fEnableBarrelHistos = context.mOptions.get("processAllSkimmed") || context.mOptions.get("processBarrelOnlySkimmed") || context.mOptions.get("processBarrelOnlyWithCollSkimmed") || context.mOptions.get("processBarrelOnlySkimmedNoCov") || context.mOptions.get("processBarrelOnlySkimmedNoCovWithMultExtra") || context.mOptions.get("processBarrelOnlyWithQvectorCentrSkimmedNoCov") || context.mOptions.get("processBarrelOnlyWithQvectorCentrSkimmed") || context.mOptions.get("processBarrelOnlyWithQvectorCentrVtxCovSkimmed") || context.mOptions.get("processBarrelOnlyDiKaons") || context.mOptions.get("processBarrelOnlyDiProtons") || context.mOptions.get("processBarrelOnlySkimmedWithGlobalMult"); fEnableBarrelMixingHistos = context.mOptions.get("processMixingAllSkimmed") || context.mOptions.get("processMixingBarrelSkimmed") || context.mOptions.get("processMixingBarrelSkimmedFlow") || context.mOptions.get("processMixingBarrelWithQvectorCentrSkimmedNoCov") || context.mOptions.get("processMixingBarrelSkimmedGlobalMult"); + if (fEnableBarrelMixingHistos && fConfigRunMixingAcrossTFs) { + LOG(fatal) << "cfgRunMixingAcrossTFs is on together with an in-TF processMixing* function"; + } fEnableBarrelMixingHistos |= fConfigRunMixingAcrossTFs; fEnableMuonHistos = context.mOptions.get("processAllSkimmed") || context.mOptions.get("processMuonOnlySkimmed") || context.mOptions.get("processMuonOnlySkimmedMultExtra") || context.mOptions.get("processMuonOnlySkimmedFlow") || context.mOptions.get("processMuonOnlyVertexingSkimmed"); fEnableMuonMixingHistos = context.mOptions.get("processMixingAllSkimmed") || context.mOptions.get("processMixingMuonSkimmed") || context.mOptions.get("processMixingMuonSkimmedFlow"); @@ -1856,6 +1861,14 @@ struct AnalysisSameEventPairing { } } + fMixNSelEdges.clear(); + if (!fConfigMixingNSelEdges.value.empty()) { + std::unique_ptr edgeArr(TString(fConfigMixingNSelEdges.value).Tokenize(",")); + for (int ie = 0; ie < edgeArr->GetEntries(); ++ie) { + fMixNSelEdges.push_back(static_cast(edgeArr->At(ie))->GetString().Atoi()); + } + LOGF(info, "Event mixing restricted to classes of selected pairing tracks per event: %s", fConfigMixingNSelEdges.value.c_str()); + } if (fConfigRunMixingAcrossTFs) { if (fNCutsBarrel > MixingHandler::NMaxCuts) { LOGF(fatal, "Across-TF mixing supports at most %d barrel track-cut bits, got %d", MixingHandler::NMaxCuts, fNCutsBarrel); @@ -2142,6 +2155,16 @@ struct AnalysisSameEventPairing { if (groupedAssocs.size() == 0) { continue; } + if constexpr (TPairType == VarManager::kDecayToEE || TPairType == VarManager::kDecayToPiPi || TPairType == VarManager::kDecayToKchKch || TPairType == VarManager::kDecayToPrAPr) { + // number of tracks passing the pairing filter + int nSel = 0; + for (auto const& a : groupedAssocs) { + if (a.isBarrelSelected_raw() & a.isBarrelSelectedPrefilter_raw() & fTrackFilterMask) { + nSel++; + } + } + VarManager::fgValues[VarManager::kNSelTracksForPairing] = nSel; + } if (fConfigOptions.useFlowReso) { if (ResoFlowSP == nullptr || ResoFlowEP == nullptr) { @@ -2152,6 +2175,13 @@ struct AnalysisSameEventPairing { int mixingCategory = -1; if (fConfigRunMixingAcrossTFs) { mixingCategory = fMixingHandler.FindEventCategory(dqtablereader_helpers::varValues()); + // mix only events in the same class of cfgMixingNSelEdges + if (mixingCategory >= 0 && !fMixNSelEdges.empty()) { + const int nSel = static_cast(VarManager::fgValues[VarManager::kNSelTracksForPairing]); + const int nSelClassIndex = static_cast(std::upper_bound(fMixNSelEdges.begin(), fMixNSelEdges.end(), nSel) - fMixNSelEdges.begin()) - 1; + const int nNSelClasses = static_cast(fMixNSelEdges.size()) - 1; + mixingCategory = (nSelClassIndex >= 0 && nSelClassIndex < nNSelClasses) ? mixingCategory * nNSelClasses + nSelClassIndex : -1; + } } fNPairPerEvent = 0; @@ -2675,6 +2705,7 @@ struct AnalysisSameEventPairing { } // 2) run the mixing with the events in the pool corresponding to this event auto& pool = fMixingHandler.GetPool(mixingCategory); + int nMEPairs = 0; for (auto const& poolEvent : pool.GetEvents()) { for (auto const& t1 : mixingEvent.tracks1) { // run +- pairing @@ -2685,6 +2716,7 @@ struct AnalysisSameEventPairing { continue; } VarManager::FillPairMEAcrossTFs(t1, t2); + nMEPairs++; for (int icut = 0; icut < ncuts; icut++) { if (mixedTwoTrackFilter & (static_cast(1) << icut)) { if (fConfigQA) { @@ -2715,6 +2747,7 @@ struct AnalysisSameEventPairing { continue; } VarManager::FillPairMEAcrossTFs(t1, t2); + nMEPairs++; for (int icut = 0; icut < ncuts; icut++) { if (mixedTwoTrackFilter & (static_cast(1) << icut)) { if (fConfigQA) { @@ -2733,6 +2766,7 @@ struct AnalysisSameEventPairing { continue; } VarManager::FillPairMEAcrossTFs(t1, t2); + nMEPairs++; for (int icut = 0; icut < ncuts; icut++) { if (mixedTwoTrackFilter & (static_cast(1) << icut)) { if (fConfigQA) { @@ -2762,6 +2796,7 @@ struct AnalysisSameEventPairing { continue; } VarManager::FillPairMEAcrossTFs(t1, t2); + nMEPairs++; for (int icut = 0; icut < ncuts; icut++) { if (mixedTwoTrackFilter & (static_cast(1) << icut)) { if (fConfigQA) { @@ -2772,6 +2807,10 @@ struct AnalysisSameEventPairing { } } } + if (fEnableBarrelMixingHistos && fConfigQA) { + VarManager::fgValues[VarManager::kNPairsPerEvent] = nMEPairs; + fHistMan->FillHistClass("PairingMEQA", dqtablereader_helpers::varValues()); + } // 3) add the current event to the pool pool.UpdatePool(mixingEvent, fMixingHandler.GetPoolDepth(), mixingEvent.filteringMask); // pool.Print(); @@ -2964,27 +3003,72 @@ struct AnalysisSameEventPairing { events.bindExternalIndices(&assocs); int mixingDepth = fConfigMixingDepth.value; fAmbiguousPairs.clear(); + if constexpr (TPairType == VarManager::kDecayToEE || TPairType == VarManager::kDecayToPiPi || TPairType == VarManager::kDecayToKchKch || TPairType == VarManager::kDecayToPrAPr) { + if (!fMixNSelEdges.empty()) { + // mix only events in the same class of cfgMixingNSelEdges + const int nNSelClasses = static_cast(fMixNSelEdges.size()) - 1; + std::map>> nSelPools; + // fill the pools with events + for (auto const& event : events) { + int nSel = 0; + for (auto const& a : assocs.sliceBy(preSlice, event.globalIndex())) { + if (a.isBarrelSelected_raw() & a.isBarrelSelectedPrefilter_raw() & fTrackFilterMask) { + nSel++; + } + } + const int nSelClassIndex = static_cast(std::upper_bound(fMixNSelEdges.begin(), fMixNSelEdges.end(), nSel) - fMixNSelEdges.begin()) - 1; + if (nSelClassIndex >= 0 && nSelClassIndex < nNSelClasses && event.mixingHash() >= 0) { + nSelPools[event.mixingHash() * nNSelClasses + nSelClassIndex].push_back(event); + } + } + // same sliding window as selfCombinations + for (auto const& [key, poolEvents] : nSelPools) { + for (size_t i = 0; i < poolEvents.size(); i++) { + for (size_t j = i + 1; j < poolEvents.size() && j <= i + static_cast(mixingDepth); j++) { + mixTwoEvents(poolEvents[i], poolEvents[j], events, assocs, tracks, preSlice); + } + } + } + return; + } + } for (auto const& [event1, event2] : selfCombinations(hashBin, mixingDepth, -1, events, events)) { - VarManager::ResetValues(0, VarManager::kNVars); - VarManager::FillEvent(event1, dqtablereader_helpers::varValues()); + mixTwoEvents(event1, event2, events, assocs, tracks, preSlice); + } + } - auto assocs1 = assocs.sliceBy(preSlice, event1.globalIndex()); - assocs1.bindExternalIndices(&events); + // mix one pair of events + template + void mixTwoEvents(TEvent const& event1, TEvent const& event2, TEvents& events, TAssocs const& assocs, TTracks const& tracks, o2::framework::Preslice& preSlice) + { + VarManager::ResetValues(0, VarManager::kNVars); + VarManager::FillEvent(event1, dqtablereader_helpers::varValues()); - auto assocs2 = assocs.sliceBy(preSlice, event2.globalIndex()); - assocs2.bindExternalIndices(&events); + auto assocs1 = assocs.sliceBy(preSlice, event1.globalIndex()); + assocs1.bindExternalIndices(&events); - fNPairPerEvent = 0; - VarManager::FillTwoMixEvents(event1, event2, assocs1, assocs2); - if (fConfigOptions.useFlowReso) { - VarManager::FillTwoMixEventsFlowResoFactor(ResoFlowSP, ResoFlowEP); - } - runMixedPairing(assocs1, assocs2, tracks, tracks); - VarManager::fgValues[VarManager::kNPairsPerEvent] = fNPairPerEvent; - if (fEnableBarrelMixingHistos && fConfigQA) { - fHistMan->FillHistClass("PairingMEQA", dqtablereader_helpers::varValues()); + auto assocs2 = assocs.sliceBy(preSlice, event2.globalIndex()); + assocs2.bindExternalIndices(&events); + + fNPairPerEvent = 0; + VarManager::FillTwoMixEvents(event1, event2, assocs1, assocs2); + if constexpr (TPairType == VarManager::kDecayToEE || TPairType == VarManager::kDecayToPiPi || TPairType == VarManager::kDecayToKchKch || TPairType == VarManager::kDecayToPrAPr) { + int nSel1 = 0; // number of tracks of event1 passing the pairing filter + for (auto const& a : assocs1) { + if (a.isBarrelSelected_raw() & a.isBarrelSelectedPrefilter_raw() & fTrackFilterMask) { + nSel1++; + } } - } // end event loop + VarManager::fgValues[VarManager::kNSelTracksForPairing] = nSel1; + } + if (fConfigOptions.useFlowReso) { + VarManager::FillTwoMixEventsFlowResoFactor(ResoFlowSP, ResoFlowEP); + } + runMixedPairing(assocs1, assocs2, tracks, tracks); + VarManager::fgValues[VarManager::kNPairsPerEvent] = fNPairPerEvent; + if (fEnableBarrelMixingHistos && fConfigQA) { + fHistMan->FillHistClass("PairingMEQA", dqtablereader_helpers::varValues()); + } } template From d903174f3db9de972edd29e4a4e921b16a3521e2 Mon Sep 17 00:00:00 2001 From: Jseo Date: Wed, 18 Nov 2026 15:42:26 +0100 Subject: [PATCH 3/3] clang --- PWGDQ/Core/VarManager.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/PWGDQ/Core/VarManager.h b/PWGDQ/Core/VarManager.h index fde47fd6cda..0addb4cbbf5 100644 --- a/PWGDQ/Core/VarManager.h +++ b/PWGDQ/Core/VarManager.h @@ -511,21 +511,21 @@ class VarManager : public TObject kV2ME_EP, kWV2ME_SP, kWV2ME_EP, - kTwoR2SP1, // Scalar product resolution of event1 for ME technique - kTwoR2SP2, // Scalar product resolution of event2 for ME technique - kTwoR2EP1, // Event plane resolution of event2 for ME technique - kTwoR2EP2, // Event plane resolution of event2 for ME technique - kDeltaPhiME_TPC, // Delta phi of VM to TPC event plane for ME technique - kDeltaPhiME_FT0C, // Delta phi of VM to FT0C event plane for ME technique - kDeltaPhiME_FT0A, // Delta phi of VM to FT0A event plane for ME technique - kCos2DeltaPhiME_TPC, // Cos(2*Delta phi) of VM to TPC event plane for ME technique - kCos2DeltaPhiME_FT0C, // Cos(2*Delta phi) of VM to FT0C event plane for ME technique - kCos2DeltaPhiME_FT0A, // Cos(2*Delta phi) of VM to FT0A event plane for ME technique - kA2EPME_TPC, // A2 of VM to TPC event plane for ME technique - kA2EPME_FT0C, // A2 of VM to FT0C event plane for ME technique - kA2EPME_FT0A, // A2 of VM to FT0A event plane for ME technique - kNPairsPerEvent, // number of pairs per event in same-event or mixed-event pairing - kNSelTracksForPairing,// number of tracks in the event passing the pairing track filter (barrel); in ME = that of the first event + kTwoR2SP1, // Scalar product resolution of event1 for ME technique + kTwoR2SP2, // Scalar product resolution of event2 for ME technique + kTwoR2EP1, // Event plane resolution of event2 for ME technique + kTwoR2EP2, // Event plane resolution of event2 for ME technique + kDeltaPhiME_TPC, // Delta phi of VM to TPC event plane for ME technique + kDeltaPhiME_FT0C, // Delta phi of VM to FT0C event plane for ME technique + kDeltaPhiME_FT0A, // Delta phi of VM to FT0A event plane for ME technique + kCos2DeltaPhiME_TPC, // Cos(2*Delta phi) of VM to TPC event plane for ME technique + kCos2DeltaPhiME_FT0C, // Cos(2*Delta phi) of VM to FT0C event plane for ME technique + kCos2DeltaPhiME_FT0A, // Cos(2*Delta phi) of VM to FT0A event plane for ME technique + kA2EPME_TPC, // A2 of VM to TPC event plane for ME technique + kA2EPME_FT0C, // A2 of VM to FT0C event plane for ME technique + kA2EPME_FT0A, // A2 of VM to FT0A event plane for ME technique + kNPairsPerEvent, // number of pairs per event in same-event or mixed-event pairing + kNSelTracksForPairing, // number of tracks in the event passing the pairing track filter (barrel); in ME = that of the first event kInteractionRate, kMuPerBc,