Skip to content

Commit 1a73198

Browse files
authored
[PWGDQ] Event mixing in classes of the selected pairing in tableReader (#18804)
1 parent 26f87ea commit 1a73198

3 files changed

Lines changed: 138 additions & 30 deletions

File tree

‎PWGDQ/Core/VarManager.cxx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,8 @@ void VarManager::SetDefaultVarNames()
17221722
fgVariableUnits[kR3EP] = "";
17231723
fgVariableNames[kNPairsPerEvent] = "number of pairs per event";
17241724
fgVariableUnits[kNPairsPerEvent] = "";
1725+
fgVariableNames[kNSelTracksForPairing] = "number of selected tracks for pairing";
1726+
fgVariableUnits[kNSelTracksForPairing] = "";
17251727
fgVariableNames[kPairMass] = "mass";
17261728
fgVariableUnits[kPairMass] = "GeV/c2";
17271729
fgVariableNames[kPairMassDau] = "mass dilepton";
@@ -2402,6 +2404,7 @@ void VarManager::SetDefaultVarNames()
24022404
fgVarNamesMap["kTwoR2EP1"] = kTwoR2EP1;
24032405
fgVarNamesMap["kTwoR2EP2"] = kTwoR2EP2;
24042406
fgVarNamesMap["kNPairsPerEvent"] = kNPairsPerEvent;
2407+
fgVarNamesMap["kNSelTracksForPairing"] = kNSelTracksForPairing;
24052408
fgVarNamesMap["kInteractionRate"] = kInteractionRate;
24062409
fgVarNamesMap["kMuPerBc"] = kMuPerBc;
24072410
fgVarNamesMap["kNEventWiseVariables"] = kNEventWiseVariables;

‎PWGDQ/Core/VarManager.h‎

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -511,20 +511,21 @@ class VarManager : public TObject
511511
kV2ME_EP,
512512
kWV2ME_SP,
513513
kWV2ME_EP,
514-
kTwoR2SP1, // Scalar product resolution of event1 for ME technique
515-
kTwoR2SP2, // Scalar product resolution of event2 for ME technique
516-
kTwoR2EP1, // Event plane resolution of event2 for ME technique
517-
kTwoR2EP2, // Event plane resolution of event2 for ME technique
518-
kDeltaPhiME_TPC, // Delta phi of VM to TPC event plane for ME technique
519-
kDeltaPhiME_FT0C, // Delta phi of VM to FT0C event plane for ME technique
520-
kDeltaPhiME_FT0A, // Delta phi of VM to FT0A event plane for ME technique
521-
kCos2DeltaPhiME_TPC, // Cos(2*Delta phi) of VM to TPC event plane for ME technique
522-
kCos2DeltaPhiME_FT0C, // Cos(2*Delta phi) of VM to FT0C event plane for ME technique
523-
kCos2DeltaPhiME_FT0A, // Cos(2*Delta phi) of VM to FT0A event plane for ME technique
524-
kA2EPME_TPC, // A2 of VM to TPC event plane for ME technique
525-
kA2EPME_FT0C, // A2 of VM to FT0C event plane for ME technique
526-
kA2EPME_FT0A, // A2 of VM to FT0A event plane for ME technique
527-
kNPairsPerEvent, // number of pairs per event in same-event or mixed-event pairing
514+
kTwoR2SP1, // Scalar product resolution of event1 for ME technique
515+
kTwoR2SP2, // Scalar product resolution of event2 for ME technique
516+
kTwoR2EP1, // Event plane resolution of event2 for ME technique
517+
kTwoR2EP2, // Event plane resolution of event2 for ME technique
518+
kDeltaPhiME_TPC, // Delta phi of VM to TPC event plane for ME technique
519+
kDeltaPhiME_FT0C, // Delta phi of VM to FT0C event plane for ME technique
520+
kDeltaPhiME_FT0A, // Delta phi of VM to FT0A event plane for ME technique
521+
kCos2DeltaPhiME_TPC, // Cos(2*Delta phi) of VM to TPC event plane for ME technique
522+
kCos2DeltaPhiME_FT0C, // Cos(2*Delta phi) of VM to FT0C event plane for ME technique
523+
kCos2DeltaPhiME_FT0A, // Cos(2*Delta phi) of VM to FT0A event plane for ME technique
524+
kA2EPME_TPC, // A2 of VM to TPC event plane for ME technique
525+
kA2EPME_FT0C, // A2 of VM to FT0C event plane for ME technique
526+
kA2EPME_FT0A, // A2 of VM to FT0A event plane for ME technique
527+
kNPairsPerEvent, // number of pairs per event in same-event or mixed-event pairing
528+
kNSelTracksForPairing, // number of tracks in the event passing the pairing track filter (barrel); in ME = that of the first event
528529
kInteractionRate,
529530
kMuPerBc,
530531

@@ -4822,6 +4823,15 @@ void VarManager::FillPairMEAcrossTFs(T const& t1, T const& t2, float* values)
48224823
values[kEta] = v12.Eta();
48234824
values[kPhi] = RecoDecay::constrainAngle(v12.Phi());
48244825
values[kRap] = -v12.Rapidity();
4826+
values[kPt1] = t1.pt;
4827+
values[kEta1] = t1.eta;
4828+
values[kPhi1] = t1.phi;
4829+
values[kPt2] = t2.pt;
4830+
values[kEta2] = t2.eta;
4831+
values[kPhi2] = t2.phi;
4832+
if (fgUsedVars[kDeltaPhiPair2]) {
4833+
values[kDeltaPhiPair2] = RecoDecay::constrainAngle(v1.Phi() - v2.Phi(), -o2::constants::math::PIHalf);
4834+
}
48254835

48264836
if (fgUsedVars[kCosThetaStarRandom] || fgUsedVars[kCosThetaStarFT0C]) {
48274837
ROOT::Math::Boost boostv12{v12.BoostToCM()};

‎PWGDQ/Tasks/tableReader_withAssoc.h‎

Lines changed: 111 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#include <RtypesCore.h>
6969

7070
#include <algorithm>
71+
#include <charconv>
7172
#include <chrono>
7273
#include <cmath>
7374
#include <cstdint>
@@ -78,6 +79,7 @@
7879
#include <map>
7980
#include <memory>
8081
#include <string>
82+
#include <system_error>
8183
#include <utility>
8284
#include <variant>
8385
#include <vector>
@@ -1511,6 +1513,7 @@ struct AnalysisSameEventPairing {
15111513
o2::framework::Configurable<std::string> fConfigMixingVariables{"cfgMixingVars", "", "Mixing configs separated by a comma, default no mixing"};
15121514
o2::framework::Configurable<std::string> fConfigMixingVariablesJson{"cfgMixingVarsJSON", "", "Mixing configs in JSON format"};
15131515
o2::framework::Configurable<bool> fConfigRunMixingAcrossTFs{"cfgRunMixingAcrossTFs", false, "If true, run event mixing using the MixingHandler which accumulates events across multiple TFs"};
1516+
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)"};
15141517
// o2::framework::Configurable<std::string> fConfigAddEventMixingHistogram{"cfgAddEventMixingHistogram", "", "Comma separated list of histograms"};
15151518
o2::framework::Configurable<std::string> fConfigAddSEPHistogram{"cfgAddSEPHistogram", "", "Comma separated list of histograms"};
15161519
o2::framework::Configurable<std::string> fConfigAddJSONHistograms{"cfgAddJSONHistograms", "", "Histograms in JSON format"};
@@ -1587,6 +1590,7 @@ struct AnalysisSameEventPairing {
15871590
int fNCutsMuon = 0;
15881591
int fNPairCuts = 0;
15891592
int fNPairPerEvent = 0;
1593+
std::vector<int> fMixNSelEdges;
15901594

15911595
bool fEnableBarrelMixingHistos = false;
15921596
bool fEnableBarrelHistos = false;
@@ -1606,6 +1610,9 @@ struct AnalysisSameEventPairing {
16061610
{
16071611
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");
16081612
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");
1613+
if (fEnableBarrelMixingHistos && fConfigRunMixingAcrossTFs) {
1614+
LOG(fatal) << "cfgRunMixingAcrossTFs is on together with an in-TF processMixing* function";
1615+
}
16091616
fEnableBarrelMixingHistos |= fConfigRunMixingAcrossTFs;
16101617
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");
16111618
fEnableMuonMixingHistos = context.mOptions.get<bool>("processMixingAllSkimmed") || context.mOptions.get<bool>("processMixingMuonSkimmed") || context.mOptions.get<bool>("processMixingMuonSkimmedFlow");
@@ -1856,6 +1863,23 @@ struct AnalysisSameEventPairing {
18561863
}
18571864
}
18581865

1866+
fMixNSelEdges.clear();
1867+
if (!fConfigMixingNSelEdges.value.empty()) {
1868+
std::unique_ptr<TObjArray> edgeArr(TString(fConfigMixingNSelEdges.value).Tokenize(","));
1869+
for (int ie = 0; ie < edgeArr->GetEntries(); ++ie) {
1870+
const std::string edgeStr = dynamic_cast<TObjString*>(edgeArr->At(ie))->GetString().Data();
1871+
int edge = 0;
1872+
const auto [ptr, ec] = std::from_chars(edgeStr.data(), edgeStr.data() + edgeStr.size(), edge);
1873+
if (ec != std::errc() || ptr != edgeStr.data() + edgeStr.size()) {
1874+
LOG(fatal) << "Edges must be integers: '" << fConfigMixingNSelEdges.value << "'";
1875+
}
1876+
fMixNSelEdges.push_back(edge);
1877+
}
1878+
if (fMixNSelEdges.size() < 2 || !std::is_sorted(fMixNSelEdges.begin(), fMixNSelEdges.end()) || std::adjacent_find(fMixNSelEdges.begin(), fMixNSelEdges.end()) != fMixNSelEdges.end()) {
1879+
LOG(fatal) << "cfgMixingNSelEdges needs at least two edges in strictly increasing order: '" << fConfigMixingNSelEdges.value << "'";
1880+
}
1881+
LOGF(info, "Event mixing restricted to classes of selected pairing tracks per event: %s", fConfigMixingNSelEdges.value.c_str());
1882+
}
18591883
if (fConfigRunMixingAcrossTFs) {
18601884
if (fNCutsBarrel > MixingHandler::NMaxCuts) {
18611885
LOGF(fatal, "Across-TF mixing supports at most %d barrel track-cut bits, got %d", MixingHandler::NMaxCuts, fNCutsBarrel);
@@ -2142,6 +2166,16 @@ struct AnalysisSameEventPairing {
21422166
if (groupedAssocs.size() == 0) {
21432167
continue;
21442168
}
2169+
if constexpr (TPairType == VarManager::kDecayToEE || TPairType == VarManager::kDecayToPiPi || TPairType == VarManager::kDecayToKchKch || TPairType == VarManager::kDecayToPrAPr) {
2170+
// number of tracks passing the pairing filter
2171+
int nSel = 0;
2172+
for (auto const& a : groupedAssocs) {
2173+
if (a.isBarrelSelected_raw() & a.isBarrelSelectedPrefilter_raw() & fTrackFilterMask) {
2174+
nSel++;
2175+
}
2176+
}
2177+
VarManager::fgValues[VarManager::kNSelTracksForPairing] = nSel;
2178+
}
21452179

21462180
if (fConfigOptions.useFlowReso) {
21472181
if (ResoFlowSP == nullptr || ResoFlowEP == nullptr) {
@@ -2152,6 +2186,13 @@ struct AnalysisSameEventPairing {
21522186
int mixingCategory = -1;
21532187
if (fConfigRunMixingAcrossTFs) {
21542188
mixingCategory = fMixingHandler.FindEventCategory(dqtablereader_helpers::varValues());
2189+
// mix only events in the same class of cfgMixingNSelEdges
2190+
if (mixingCategory >= 0 && !fMixNSelEdges.empty()) {
2191+
const int nSel = static_cast<int>(VarManager::fgValues[VarManager::kNSelTracksForPairing]);
2192+
const int nSelClassIndex = static_cast<int>(std::upper_bound(fMixNSelEdges.begin(), fMixNSelEdges.end(), nSel) - fMixNSelEdges.begin()) - 1;
2193+
const int nNSelClasses = static_cast<int>(fMixNSelEdges.size()) - 1;
2194+
mixingCategory = (nSelClassIndex >= 0 && nSelClassIndex < nNSelClasses) ? mixingCategory * nNSelClasses + nSelClassIndex : -1;
2195+
}
21552196
}
21562197

21572198
fNPairPerEvent = 0;
@@ -2675,6 +2716,7 @@ struct AnalysisSameEventPairing {
26752716
}
26762717
// 2) run the mixing with the events in the pool corresponding to this event
26772718
auto& pool = fMixingHandler.GetPool(mixingCategory);
2719+
int nMEPairs = 0;
26782720
for (auto const& poolEvent : pool.GetEvents()) {
26792721
for (auto const& t1 : mixingEvent.tracks1) {
26802722
// run +- pairing
@@ -2685,6 +2727,7 @@ struct AnalysisSameEventPairing {
26852727
continue;
26862728
}
26872729
VarManager::FillPairMEAcrossTFs(t1, t2);
2730+
nMEPairs++;
26882731
for (int icut = 0; icut < ncuts; icut++) {
26892732
if (mixedTwoTrackFilter & (static_cast<uint32_t>(1) << icut)) {
26902733
if (fConfigQA) {
@@ -2715,6 +2758,7 @@ struct AnalysisSameEventPairing {
27152758
continue;
27162759
}
27172760
VarManager::FillPairMEAcrossTFs(t1, t2);
2761+
nMEPairs++;
27182762
for (int icut = 0; icut < ncuts; icut++) {
27192763
if (mixedTwoTrackFilter & (static_cast<uint32_t>(1) << icut)) {
27202764
if (fConfigQA) {
@@ -2733,6 +2777,7 @@ struct AnalysisSameEventPairing {
27332777
continue;
27342778
}
27352779
VarManager::FillPairMEAcrossTFs(t1, t2);
2780+
nMEPairs++;
27362781
for (int icut = 0; icut < ncuts; icut++) {
27372782
if (mixedTwoTrackFilter & (static_cast<uint32_t>(1) << icut)) {
27382783
if (fConfigQA) {
@@ -2762,6 +2807,7 @@ struct AnalysisSameEventPairing {
27622807
continue;
27632808
}
27642809
VarManager::FillPairMEAcrossTFs(t1, t2);
2810+
nMEPairs++;
27652811
for (int icut = 0; icut < ncuts; icut++) {
27662812
if (mixedTwoTrackFilter & (static_cast<uint32_t>(1) << icut)) {
27672813
if (fConfigQA) {
@@ -2772,6 +2818,10 @@ struct AnalysisSameEventPairing {
27722818
}
27732819
}
27742820
}
2821+
if (fEnableBarrelMixingHistos && fConfigQA) {
2822+
VarManager::fgValues[VarManager::kNPairsPerEvent] = nMEPairs;
2823+
fHistMan->FillHistClass("PairingMEQA", dqtablereader_helpers::varValues());
2824+
}
27752825
// 3) add the current event to the pool
27762826
pool.UpdatePool(mixingEvent, fMixingHandler.GetPoolDepth(), mixingEvent.filteringMask);
27772827
// pool.Print();
@@ -2964,27 +3014,72 @@ struct AnalysisSameEventPairing {
29643014
events.bindExternalIndices(&assocs);
29653015
int mixingDepth = fConfigMixingDepth.value;
29663016
fAmbiguousPairs.clear();
3017+
if constexpr (TPairType == VarManager::kDecayToEE || TPairType == VarManager::kDecayToPiPi || TPairType == VarManager::kDecayToKchKch || TPairType == VarManager::kDecayToPrAPr) {
3018+
if (!fMixNSelEdges.empty()) {
3019+
// mix only events in the same class of cfgMixingNSelEdges
3020+
const int nNSelClasses = static_cast<int>(fMixNSelEdges.size()) - 1;
3021+
std::map<int, std::vector<decltype(events.begin())>> nSelPools;
3022+
// fill the pools with events
3023+
for (auto const& event : events) {
3024+
int nSel = 0;
3025+
for (auto const& a : assocs.sliceBy(preSlice, event.globalIndex())) {
3026+
if (a.isBarrelSelected_raw() & a.isBarrelSelectedPrefilter_raw() & fTrackFilterMask) {
3027+
nSel++;
3028+
}
3029+
}
3030+
const int nSelClassIndex = static_cast<int>(std::upper_bound(fMixNSelEdges.begin(), fMixNSelEdges.end(), nSel) - fMixNSelEdges.begin()) - 1;
3031+
if (nSelClassIndex >= 0 && nSelClassIndex < nNSelClasses && event.mixingHash() >= 0) {
3032+
nSelPools[event.mixingHash() * nNSelClasses + nSelClassIndex].push_back(event);
3033+
}
3034+
}
3035+
// same sliding window as selfCombinations
3036+
for (auto const& [key, poolEvents] : nSelPools) {
3037+
for (size_t i = 0; i < poolEvents.size(); i++) {
3038+
for (size_t j = i + 1; j < poolEvents.size() && j <= i + static_cast<size_t>(mixingDepth); j++) {
3039+
mixTwoEvents<TPairType, TEventFillMap>(poolEvents[i], poolEvents[j], events, assocs, tracks, preSlice);
3040+
}
3041+
}
3042+
}
3043+
return;
3044+
}
3045+
}
29673046
for (auto const& [event1, event2] : selfCombinations(hashBin, mixingDepth, -1, events, events)) {
2968-
VarManager::ResetValues(0, VarManager::kNVars);
2969-
VarManager::FillEvent<TEventFillMap>(event1, dqtablereader_helpers::varValues());
3047+
mixTwoEvents<TPairType, TEventFillMap>(event1, event2, events, assocs, tracks, preSlice);
3048+
}
3049+
}
29703050

2971-
auto assocs1 = assocs.sliceBy(preSlice, event1.globalIndex());
2972-
assocs1.bindExternalIndices(&events);
3051+
// mix one pair of events
3052+
template <int TPairType, uint32_t TEventFillMap, typename TEvent, typename TEvents, typename TAssocs, typename TTracks>
3053+
void mixTwoEvents(TEvent const& event1, TEvent const& event2, TEvents& events, TAssocs const& assocs, TTracks const& tracks, o2::framework::Preslice<TAssocs>& preSlice)
3054+
{
3055+
VarManager::ResetValues(0, VarManager::kNVars);
3056+
VarManager::FillEvent<TEventFillMap>(event1, dqtablereader_helpers::varValues());
29733057

2974-
auto assocs2 = assocs.sliceBy(preSlice, event2.globalIndex());
2975-
assocs2.bindExternalIndices(&events);
3058+
auto assocs1 = assocs.sliceBy(preSlice, event1.globalIndex());
3059+
assocs1.bindExternalIndices(&events);
29763060

2977-
fNPairPerEvent = 0;
2978-
VarManager::FillTwoMixEvents<TEventFillMap>(event1, event2, assocs1, assocs2);
2979-
if (fConfigOptions.useFlowReso) {
2980-
VarManager::FillTwoMixEventsFlowResoFactor(ResoFlowSP, ResoFlowEP);
2981-
}
2982-
runMixedPairing<TPairType, TEventFillMap>(assocs1, assocs2, tracks, tracks);
2983-
VarManager::fgValues[VarManager::kNPairsPerEvent] = fNPairPerEvent;
2984-
if (fEnableBarrelMixingHistos && fConfigQA) {
2985-
fHistMan->FillHistClass("PairingMEQA", dqtablereader_helpers::varValues());
3061+
auto assocs2 = assocs.sliceBy(preSlice, event2.globalIndex());
3062+
assocs2.bindExternalIndices(&events);
3063+
3064+
fNPairPerEvent = 0;
3065+
VarManager::FillTwoMixEvents<TEventFillMap>(event1, event2, assocs1, assocs2);
3066+
if constexpr (TPairType == VarManager::kDecayToEE || TPairType == VarManager::kDecayToPiPi || TPairType == VarManager::kDecayToKchKch || TPairType == VarManager::kDecayToPrAPr) {
3067+
int nSel1 = 0; // number of tracks of event1 passing the pairing filter
3068+
for (auto const& a : assocs1) {
3069+
if (a.isBarrelSelected_raw() & a.isBarrelSelectedPrefilter_raw() & fTrackFilterMask) {
3070+
nSel1++;
3071+
}
29863072
}
2987-
} // end event loop
3073+
VarManager::fgValues[VarManager::kNSelTracksForPairing] = nSel1;
3074+
}
3075+
if (fConfigOptions.useFlowReso) {
3076+
VarManager::FillTwoMixEventsFlowResoFactor(ResoFlowSP, ResoFlowEP);
3077+
}
3078+
runMixedPairing<TPairType, TEventFillMap>(assocs1, assocs2, tracks, tracks);
3079+
VarManager::fgValues[VarManager::kNPairsPerEvent] = fNPairPerEvent;
3080+
if (fEnableBarrelMixingHistos && fConfigQA) {
3081+
fHistMan->FillHistClass("PairingMEQA", dqtablereader_helpers::varValues());
3082+
}
29883083
}
29893084

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

0 commit comments

Comments
 (0)