Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions PWGDQ/Core/VarManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
38 changes: 24 additions & 14 deletions PWGDQ/Core/VarManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,20 +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
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,

Expand Down Expand Up @@ -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()};
Expand Down
127 changes: 111 additions & 16 deletions PWGDQ/Tasks/tableReader_withAssoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include <RtypesCore.h>

#include <algorithm>
#include <charconv>
#include <chrono>
#include <cmath>
#include <cstdint>
Expand All @@ -78,6 +79,7 @@
#include <map>
#include <memory>
#include <string>
#include <system_error>
#include <utility>
#include <variant>
#include <vector>
Expand Down Expand Up @@ -1511,6 +1513,7 @@ struct AnalysisSameEventPairing {
o2::framework::Configurable<std::string> fConfigMixingVariables{"cfgMixingVars", "", "Mixing configs separated by a comma, default no mixing"};
o2::framework::Configurable<std::string> fConfigMixingVariablesJson{"cfgMixingVarsJSON", "", "Mixing configs in JSON format"};
o2::framework::Configurable<bool> fConfigRunMixingAcrossTFs{"cfgRunMixingAcrossTFs", false, "If true, run event mixing using the MixingHandler which accumulates events across multiple TFs"};
o2::framework::Configurable<std::string> fConfigMixingNSelEdges{"cfgMixingNSelEdges", "", "Comma separated class edges in the number of selected pairing tracks per event, (e.g. 2,3,4,1000)"};
// o2::framework::Configurable<std::string> fConfigAddEventMixingHistogram{"cfgAddEventMixingHistogram", "", "Comma separated list of histograms"};
o2::framework::Configurable<std::string> fConfigAddSEPHistogram{"cfgAddSEPHistogram", "", "Comma separated list of histograms"};
o2::framework::Configurable<std::string> fConfigAddJSONHistograms{"cfgAddJSONHistograms", "", "Histograms in JSON format"};
Expand Down Expand Up @@ -1587,6 +1590,7 @@ struct AnalysisSameEventPairing {
int fNCutsMuon = 0;
int fNPairCuts = 0;
int fNPairPerEvent = 0;
std::vector<int> fMixNSelEdges;

bool fEnableBarrelMixingHistos = false;
bool fEnableBarrelHistos = false;
Expand All @@ -1606,6 +1610,9 @@ struct AnalysisSameEventPairing {
{
fEnableBarrelHistos = context.mOptions.get<bool>("processAllSkimmed") || context.mOptions.get<bool>("processBarrelOnlySkimmed") || context.mOptions.get<bool>("processBarrelOnlyWithCollSkimmed") || context.mOptions.get<bool>("processBarrelOnlySkimmedNoCov") || context.mOptions.get<bool>("processBarrelOnlySkimmedNoCovWithMultExtra") || context.mOptions.get<bool>("processBarrelOnlyWithQvectorCentrSkimmedNoCov") || context.mOptions.get<bool>("processBarrelOnlyWithQvectorCentrSkimmed") || context.mOptions.get<bool>("processBarrelOnlyWithQvectorCentrVtxCovSkimmed") || context.mOptions.get<bool>("processBarrelOnlyDiKaons") || context.mOptions.get<bool>("processBarrelOnlyDiProtons") || context.mOptions.get<bool>("processBarrelOnlySkimmedWithGlobalMult");
fEnableBarrelMixingHistos = context.mOptions.get<bool>("processMixingAllSkimmed") || context.mOptions.get<bool>("processMixingBarrelSkimmed") || context.mOptions.get<bool>("processMixingBarrelSkimmedFlow") || context.mOptions.get<bool>("processMixingBarrelWithQvectorCentrSkimmedNoCov") || context.mOptions.get<bool>("processMixingBarrelSkimmedGlobalMult");
if (fEnableBarrelMixingHistos && fConfigRunMixingAcrossTFs) {
LOG(fatal) << "cfgRunMixingAcrossTFs is on together with an in-TF processMixing* function";
}
fEnableBarrelMixingHistos |= fConfigRunMixingAcrossTFs;
fEnableMuonHistos = context.mOptions.get<bool>("processAllSkimmed") || context.mOptions.get<bool>("processMuonOnlySkimmed") || context.mOptions.get<bool>("processMuonOnlySkimmedMultExtra") || context.mOptions.get<bool>("processMuonOnlySkimmedFlow") || context.mOptions.get<bool>("processMuonOnlyVertexingSkimmed");
fEnableMuonMixingHistos = context.mOptions.get<bool>("processMixingAllSkimmed") || context.mOptions.get<bool>("processMixingMuonSkimmed") || context.mOptions.get<bool>("processMixingMuonSkimmedFlow");
Expand Down Expand Up @@ -1856,6 +1863,23 @@ struct AnalysisSameEventPairing {
}
}

fMixNSelEdges.clear();
if (!fConfigMixingNSelEdges.value.empty()) {
std::unique_ptr<TObjArray> edgeArr(TString(fConfigMixingNSelEdges.value).Tokenize(","));
for (int ie = 0; ie < edgeArr->GetEntries(); ++ie) {
const std::string edgeStr = dynamic_cast<TObjString*>(edgeArr->At(ie))->GetString().Data();
int edge = 0;
const auto [ptr, ec] = std::from_chars(edgeStr.data(), edgeStr.data() + edgeStr.size(), edge);
if (ec != std::errc() || ptr != edgeStr.data() + edgeStr.size()) {
LOG(fatal) << "Edges must be integers: '" << fConfigMixingNSelEdges.value << "'";
}
fMixNSelEdges.push_back(edge);
}
if (fMixNSelEdges.size() < 2 || !std::is_sorted(fMixNSelEdges.begin(), fMixNSelEdges.end()) || std::adjacent_find(fMixNSelEdges.begin(), fMixNSelEdges.end()) != fMixNSelEdges.end()) {
LOG(fatal) << "cfgMixingNSelEdges needs at least two edges in strictly increasing order: '" << fConfigMixingNSelEdges.value << "'";
}
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);
Expand Down Expand Up @@ -2142,6 +2166,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) {
Expand All @@ -2152,6 +2186,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<int>(VarManager::fgValues[VarManager::kNSelTracksForPairing]);
const int nSelClassIndex = static_cast<int>(std::upper_bound(fMixNSelEdges.begin(), fMixNSelEdges.end(), nSel) - fMixNSelEdges.begin()) - 1;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think std::upper_bound requires a sorted list, if the user enters something that unsorted in fConfigMixingNSelEdges, this might crash without a reasonable failure message.

Could you add a check that fConfigMixingNSelEdges contains at least two edges and that they all edges are sorted in strictly increasing order? I think std::is_sorted provides a check for that
Then add a proper failure message

@JinjooSeo JinjooSeo Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comments! I modified and added the failure messages to indicate that at least two integer edges are in strictly increasing order in init()

const int nNSelClasses = static_cast<int>(fMixNSelEdges.size()) - 1;
mixingCategory = (nSelClassIndex >= 0 && nSelClassIndex < nNSelClasses) ? mixingCategory * nNSelClasses + nSelClassIndex : -1;
}
}

fNPairPerEvent = 0;
Expand Down Expand Up @@ -2675,6 +2716,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
Expand All @@ -2685,6 +2727,7 @@ struct AnalysisSameEventPairing {
continue;
}
VarManager::FillPairMEAcrossTFs(t1, t2);
nMEPairs++;
for (int icut = 0; icut < ncuts; icut++) {
if (mixedTwoTrackFilter & (static_cast<uint32_t>(1) << icut)) {
if (fConfigQA) {
Expand Down Expand Up @@ -2715,6 +2758,7 @@ struct AnalysisSameEventPairing {
continue;
}
VarManager::FillPairMEAcrossTFs(t1, t2);
nMEPairs++;
for (int icut = 0; icut < ncuts; icut++) {
if (mixedTwoTrackFilter & (static_cast<uint32_t>(1) << icut)) {
if (fConfigQA) {
Expand All @@ -2733,6 +2777,7 @@ struct AnalysisSameEventPairing {
continue;
}
VarManager::FillPairMEAcrossTFs(t1, t2);
nMEPairs++;
for (int icut = 0; icut < ncuts; icut++) {
if (mixedTwoTrackFilter & (static_cast<uint32_t>(1) << icut)) {
if (fConfigQA) {
Expand Down Expand Up @@ -2762,6 +2807,7 @@ struct AnalysisSameEventPairing {
continue;
}
VarManager::FillPairMEAcrossTFs(t1, t2);
nMEPairs++;
for (int icut = 0; icut < ncuts; icut++) {
if (mixedTwoTrackFilter & (static_cast<uint32_t>(1) << icut)) {
if (fConfigQA) {
Expand All @@ -2772,6 +2818,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();
Expand Down Expand Up @@ -2964,27 +3014,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<int>(fMixNSelEdges.size()) - 1;
std::map<int, std::vector<decltype(events.begin())>> 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<int>(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<size_t>(mixingDepth); j++) {
mixTwoEvents<TPairType, TEventFillMap>(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<TEventFillMap>(event1, dqtablereader_helpers::varValues());
mixTwoEvents<TPairType, TEventFillMap>(event1, event2, events, assocs, tracks, preSlice);
}
}

auto assocs1 = assocs.sliceBy(preSlice, event1.globalIndex());
assocs1.bindExternalIndices(&events);
// mix one pair of events
template <int TPairType, uint32_t TEventFillMap, typename TEvent, typename TEvents, typename TAssocs, typename TTracks>
void mixTwoEvents(TEvent const& event1, TEvent const& event2, TEvents& events, TAssocs const& assocs, TTracks const& tracks, o2::framework::Preslice<TAssocs>& preSlice)
{
VarManager::ResetValues(0, VarManager::kNVars);
VarManager::FillEvent<TEventFillMap>(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<TEventFillMap>(event1, event2, assocs1, assocs2);
if (fConfigOptions.useFlowReso) {
VarManager::FillTwoMixEventsFlowResoFactor(ResoFlowSP, ResoFlowEP);
}
runMixedPairing<TPairType, TEventFillMap>(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<TEventFillMap>(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<TPairType, TEventFillMap>(assocs1, assocs2, tracks, tracks);
VarManager::fgValues[VarManager::kNPairsPerEvent] = fNPairPerEvent;
if (fEnableBarrelMixingHistos && fConfigQA) {
fHistMan->FillHistClass("PairingMEQA", dqtablereader_helpers::varValues());
}
}

template <bool TTwoProngFitter, int TPairType, uint32_t TEventFillMap, uint32_t TTrackFillMap, uint32_t TMuonFillMap, typename TEvents, typename TTrackAssocs, typename TTracks, typename TMuonAssocs, typename TMuons>
Expand Down
Loading