Skip to content
Merged
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
2 changes: 1 addition & 1 deletion PWGDQ/Core/MixingHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
{
// loop over all variables and create a mixing pool for each category defined by the binning of the variables
int nCategories = 1;
for (auto& var : fVariables) {

Check failure on line 105 in PWGDQ/Core/MixingHandler.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[const-ref-in-for-loop]

Use constant references for non-modified iterators in range-based for loops.
nCategories *= (fVariableLimits[var.second].size() - 1);
}
// add elements in the map for each category (the key is the category and the value is an empty pool)
Expand All @@ -127,14 +127,14 @@

// loop over the variables and find out in which bin the value of the variable for the event is located
std::vector<int> bin;
for (auto [var, pos] : fVariables) {

Check failure on line 130 in PWGDQ/Core/MixingHandler.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[const-ref-in-for-loop]

Use constant references for non-modified iterators in range-based for loops.
// check that the value is within limits, if not return -1 to exclude the event from mixing
size_t binValue = std::distance(fVariableLimits[pos].begin(), std::upper_bound(fVariableLimits[pos].begin(), fVariableLimits[pos].end(), values[var]));
if (binValue == 0 || binValue == fVariableLimits[pos].size()) {
return -1; // all variables must be inside limits
}
bin.push_back(binValue - 1);
}
}

// Hash the bin values to define a unique category
// The hashing is done such that the original bin values can be retrieved from the category
Expand Down
55 changes: 31 additions & 24 deletions PWGDQ/Core/MixingHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,32 @@

#include <Rtypes.h>

#include <vector>
#include <map>
#include <array>
#include <iostream>

Check failure on line 28 in PWGDQ/Core/MixingHandler.h

View workflow job for this annotation

GitHub Actions / O2 linter

[include-iostream]

Do not include iostream. Use O2 logging instead.
#include <map>
#include <vector>

class MixingHandler : public TNamed
{

public:

// Struct to define track properties relevant for mixing and few utility functions
struct MixingTrack {
float pt;
float eta;
float phi;
uint32_t filteringFlags;
// flip a bit to zero (needed when a track was already used in mixing for that bit for the required pool depth)
void FlipBit(int64_t mask) { filteringFlags ^= mask;}
void Print() const {
void FlipBit(int64_t mask) { filteringFlags ^= mask; }
void Print() const
{
std::cout << "pt: " << pt << ", eta: " << eta << ", phi: " << phi << ", filteringFlags: " << filteringFlags << std::endl;

Check failure on line 46 in PWGDQ/Core/MixingHandler.h

View workflow job for this annotation

GitHub Actions / O2 linter

[logging]

Use O2 logging (LOG, LOGF, LOGP).
}
};

// Struct to define events used in mixing and few utility functions.
// An event is defined as two vectors of tracks (typically the legs of a two-body
//decay or the two-particles in a correlation analysis)
// An event is defined as two vectors of tracks (typically the legs of a two-body
// decay or the two-particles in a correlation analysis)
struct MixingEvent {
std::vector<MixingTrack> tracks1;
std::vector<MixingTrack> tracks2;
Expand All @@ -58,20 +58,23 @@
// counters to keep track of how many times the event was used for mixing (for each track cut separately)
std::array<short, 64> counters = {0};
// add a track to the event and update the filtering mask accordingly
void AddTrack1(const MixingTrack& track) {
void AddTrack1(const MixingTrack& track)
{
tracks1.push_back(track);
filteringMask |= track.filteringFlags;
}
void AddTrack2(const MixingTrack& track) {
void AddTrack2(const MixingTrack& track)
{
tracks2.push_back(track);
filteringMask |= track.filteringFlags;
}
// flip bits in the filtering mask
void FlipFilteringMask(int64_t mask) { filteringMask ^= mask; }
// 1) increment the counters for a given track cut bit mask and if the counters reached the pool depth,
// 1) increment the counters for a given track cut bit mask and if the counters reached the pool depth,
// 2) flip the corresponding bit in the tracks filtering flags to exclude them from further mixing
// 3) for each track, if there are no more active bits in the filtering mask, then remove the track from the event
void IncrementCounters(uint32_t mask, short poolDepth) {
void IncrementCounters(uint32_t mask, short poolDepth)
{
for (int i = 0; i < 32; i++) {
if (mask & (1ULL << i)) {
counters[i]++;
Expand All @@ -95,22 +98,23 @@
}
}
}
void Print() const {
void Print() const
{
std::cout << "Event filtering mask: ";

Check failure on line 103 in PWGDQ/Core/MixingHandler.h

View workflow job for this annotation

GitHub Actions / O2 linter

[logging]

Use O2 logging (LOG, LOGF, LOGP).
for (int i = 0; i < 32; i++) {
if (filteringMask & (1ULL << i)) {
std::cout << "1";

Check failure on line 106 in PWGDQ/Core/MixingHandler.h

View workflow job for this annotation

GitHub Actions / O2 linter

[logging]

Use O2 logging (LOG, LOGF, LOGP).
} else {
std::cout << "0";

Check failure on line 108 in PWGDQ/Core/MixingHandler.h

View workflow job for this annotation

GitHub Actions / O2 linter

[logging]

Use O2 logging (LOG, LOGF, LOGP).
}
}
std::cout << std::endl;

Check failure on line 111 in PWGDQ/Core/MixingHandler.h

View workflow job for this annotation

GitHub Actions / O2 linter

[logging]

Use O2 logging (LOG, LOGF, LOGP).
for (int i = 0; i < 32; i++) {
if (filteringMask & (1ULL << i)) {
std::cout << "Counter " << i << ": " << counters[i] << std::endl;

Check failure on line 114 in PWGDQ/Core/MixingHandler.h

View workflow job for this annotation

GitHub Actions / O2 linter

[logging]

Use O2 logging (LOG, LOGF, LOGP).
}
}
std::cout << "Tracks 1: " << std::endl;

Check failure on line 117 in PWGDQ/Core/MixingHandler.h

View workflow job for this annotation

GitHub Actions / O2 linter

[logging]

Use O2 logging (LOG, LOGF, LOGP).
for (const auto& track : tracks1) {
track.Print();
}
Expand All @@ -123,16 +127,18 @@

struct MixingPool {
std::vector<MixingEvent> events;

// check which events in the pool are empty (i.e. no active tracks for mixing) and remove them from the pool
void CleanPool() {
void CleanPool()
{
events.erase(std::remove_if(events.begin(), events.end(),
[](const MixingEvent& event) { return event.tracks1.empty() && event.tracks2.empty(); }),
events.end());
}
// The function that performs the mixing is called outside this class, but the pool provides the events and tracks to be mixed and takes care of updating the events after mixing
// The function that performs the mixing is called outside this class, but the pool provides the events and tracks to be mixed and takes care of updating the events after mixing
// (e.g. incrementing the counters and removing the tracks that reached the pool depth for a given cut)
void UpdatePool(const MixingEvent& event, short poolDepth) {
void UpdatePool(const MixingEvent& event, short poolDepth)
{
for (auto& event : events) {
event.IncrementCounters(event.filteringMask, poolDepth);
}
Expand All @@ -142,14 +148,15 @@
// getter for the events in the pool
const std::vector<MixingEvent>& GetEvents() const { return events; }

void Print() const {
void Print() const
{
std::cout << "Mixing pool with " << events.size() << " events:" << std::endl;
for (const auto& event : events) {
event.Print();
}
}
};

MixingHandler();
MixingHandler(const char* name, const char* title);
virtual ~MixingHandler();
Expand All @@ -159,9 +166,9 @@
void SetPoolDepth(short depth) { fPoolDepth = depth; }

// getters
//int GetNMixingVariables() const { return fVariables.size(); }
//int GetMixingVariable(VarManager::Variables var); // returns the position in the internal varible list of the handler. Useful for checks, mostly
//std::vector<float> GetMixingVariableLimits(VarManager::Variables var);
// int GetNMixingVariables() const { return fVariables.size(); }
// int GetMixingVariable(VarManager::Variables var); // returns the position in the internal varible list of the handler. Useful for checks, mostly
// std::vector<float> GetMixingVariableLimits(VarManager::Variables var);
MixingPool& GetPool(int category) { return fPools[category]; }
short GetPoolDepth() const { return fPoolDepth; }

Expand All @@ -178,10 +185,10 @@

// bin limits for the variables used for mixing, the number of vectors corresponds to the number of variables and the content of each vector corresponds to the bin limits for that variable
std::vector<std::vector<float>> fVariableLimits;
std::map<int, int> fVariables; // key: variable, value: position in the internal variable list of the handler (used to map the variables to the values passed to FindEventCategory)
std::map<int, int> fVariables; // key: variable, value: position in the internal variable list of the handler (used to map the variables to the values passed to FindEventCategory)

short fPoolDepth; // number of events to be kept in each pool
std::map<int, MixingPool> fPools; // key: category, value: pool of events corresponding to that category
short fPoolDepth; // number of events to be kept in each pool
std::map<int, MixingPool> fPools; // key: category, value: pool of events corresponding to that category

ClassDef(MixingHandler, 2);
};
Expand Down
5 changes: 2 additions & 3 deletions PWGDQ/Tasks/tableReader_withAssoc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1630,7 +1630,7 @@ struct AnalysisSameEventPairing {
TString mixVarsJsonString = fConfigMixingVariablesJson.value;
std::unique_ptr<TObjArray> objArray(mixVarsString.Tokenize(","));
if (objArray->GetEntries() > 0 || mixVarsJsonString != "") {
//fMixingHandler = new MixingHandler("mixingHandler", "mixing handler");
// fMixingHandler = new MixingHandler("mixingHandler", "mixing handler");
if (objArray->GetEntries() > 0) {
for (int iVar = 0; iVar < objArray->GetEntries(); ++iVar) {
dqmixing::SetUpMixing(&fMixingHandler, objArray->At(iVar)->GetName());
Expand All @@ -1643,7 +1643,6 @@ struct AnalysisSameEventPairing {
fMixingHandler.SetPoolDepth(fConfigMixingDepth);
fMixingHandler.Init();
}


fCurrentRun = 0;

Expand Down Expand Up @@ -2294,7 +2293,7 @@ struct AnalysisSameEventPairing {
}
// 3) add the current event to the pool
pool.UpdatePool(mixingEvent, fMixingHandler.GetPoolDepth());
//pool.Print();
// pool.Print();
}
} // end loop over events
}
Expand Down
Loading