Skip to content

Commit b643287

Browse files
wiechuladavidrohr
authored andcommitted
TPC: Cluster filter for PbPb 2023
1 parent 0bd7fb7 commit b643287

File tree

7 files changed

+83
-16
lines changed

7 files changed

+83
-16
lines changed

GPU/GPUTracking/Debug/GPUTPCClusterFilter.cxx

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,62 @@
1212
/// \file GPUTPCClusterFilter.cxx
1313
/// \author David Rohr
1414

15+
#include "GPUCommonLogger.h"
1516
#include "GPUTPCClusterFilter.h"
1617
#include "DataFormatsTPC/ClusterNative.h"
1718

1819
using namespace o2::gpu;
1920

20-
GPUTPCClusterFilter::GPUTPCClusterFilter(const o2::tpc::ClusterNativeAccess& clusters)
21+
GPUTPCClusterFilter::GPUTPCClusterFilter(const o2::tpc::ClusterNativeAccess& clusters, uint8_t filterType)
22+
: mFilterType(filterType)
2123
{
22-
// Could initialize private variables based on the clusters here
24+
if (filterType == 1) {
25+
// Custom filter settings go here
26+
27+
} else if (filterType == 2) {
28+
// PbPb23 filter
29+
mClusterStats = std::make_unique<std::vector<int>[]>(MaxStacks);
30+
static bool called = false;
31+
if (!called) {
32+
LOGP(info, "GPUTPCClusterFilter called for PbPb 2023 settings");
33+
called = true;
34+
}
35+
36+
for (uint32_t iSector = 0; iSector < GPUCA_NSECTORS; iSector++) {
37+
for (uint32_t iRow = 0; iRow < GPUCA_ROW_COUNT; iRow++) {
38+
const uint32_t globalStack = getGlobalStack(iSector, iRow);
39+
mClusterStats[globalStack].resize(MaxTimeBin);
40+
41+
for (uint32_t k = 0; k < clusters.nClusters[iSector][iRow]; k++) {
42+
const o2::tpc::ClusterNative& cl = clusters.clusters[iSector][iRow][k];
43+
const int clTime = static_cast<int>(cl.getTime());
44+
const float clQmax = cl.getQmax();
45+
46+
if (clQmax < 12) {
47+
if (clTime >= static_cast<int>(mClusterStats[globalStack].size())) {
48+
mClusterStats[globalStack].resize(mClusterStats[globalStack].size() + 445);
49+
}
50+
++mClusterStats[globalStack][clTime];
51+
}
52+
}
53+
}
54+
}
55+
}
2356
}
2457

2558
bool GPUTPCClusterFilter::filter(uint32_t sector, uint32_t row, o2::tpc::ClusterNative& cl)
2659
{
2760
// Return true to keep the cluster, false to drop it.
2861
// May change cluster properties by modifying the cl reference.
2962
// Note that this function might be called multiple times for the same cluster, in which case the final modified cl reference goes into the output clusters.
63+
if (mFilterType == 2) {
64+
const uint32_t globalStack = getGlobalStack(sector, row);
65+
const int clTime = static_cast<int>(cl.getTime());
66+
const float clQmax = cl.getQmax();
67+
if ((mClusterStats[globalStack][clTime] > 40 && clQmax < 12) || (mClusterStats[globalStack][clTime] > 200)) {
68+
return false;
69+
}
70+
}
71+
3072
return true;
3173
}

GPU/GPUTracking/Debug/GPUTPCClusterFilter.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
#ifndef GPUTPCCLUSTERFILTER_H
1616
#define GPUTPCCLUSTERFILTER_H
1717

18+
#include <memory>
1819
#include <cstdint>
20+
#include <vector>
21+
#include "GPUDefConstantsAndSettings.h"
1922

2023
namespace o2::tpc
2124
{
@@ -28,8 +31,29 @@ namespace o2::gpu
2831
class GPUTPCClusterFilter
2932
{
3033
public:
31-
GPUTPCClusterFilter(const o2::tpc::ClusterNativeAccess& clusters);
34+
GPUTPCClusterFilter(const o2::tpc::ClusterNativeAccess& clusters, uint8_t filterType);
3235
bool filter(uint32_t sector, uint32_t row, o2::tpc::ClusterNative& cl);
36+
37+
private:
38+
static constexpr uint32_t MaxTimeBin = 14256;
39+
static constexpr uint32_t MaxStacks = GPUCA_NSECTORS * 4;
40+
uint8_t mFilterType = 0; //< 0: off, 1: custom, 2: PbPb23
41+
42+
std::unique_ptr<std::vector<int>[]> mClusterStats; //< Number of clusters per stack and time bin
43+
44+
uint32_t getGlobalStack(uint32_t sector, uint32_t row) const
45+
{
46+
int stack = 3;
47+
if (row < 63) {
48+
stack = 0;
49+
} else if (row < 97) {
50+
stack = 1;
51+
} else if (row < 127) {
52+
stack = 2;
53+
}
54+
55+
return sector * 4 + stack;
56+
};
3357
};
3458
} // namespace o2::gpu
3559

GPU/GPUTracking/Definitions/GPUSettingsList.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ AddOption(tpcDownscaledEdx, uint8_t, 0, "", 0, "If != 0, downscale dEdx processi
291291
AddOption(tpcMaxAttachedClustersPerSectorRow, uint32_t, 51000, "", 0, "Maximum number of TPC attached clusters which can be decoded per SectorRow")
292292
AddOption(tpcUseOldCPUDecoding, bool, false, "", 0, "Enable old CPU-based TPC decoding")
293293
AddOption(tpcApplyCFCutsAtDecoding, bool, false, "", 0, "Apply cluster cuts from clusterization during decoding of compressed clusters")
294-
AddOption(tpcApplyDebugClusterFilter, bool, false, "", 0, "Apply custom cluster filter of GPUTPCClusterFilter class")
294+
AddOption(tpcApplyClusterFilterOnCPU, uint8_t, 0, "", 0, "Apply custom cluster filter of GPUTPCClusterFilter class, 0: off, 1: debug, 2: PbPb23")
295295
AddOption(RTCcacheFolder, std::string, "./rtccache/", "", 0, "Folder in which the cache file is stored")
296296
AddOption(RTCprependCommand, std::string, "", "", 0, "Prepend RTC compilation commands by this string")
297297
AddOption(RTCoverrideArchitecture, std::string, "", "", 0, "Override arhcitecture part of RTC compilation command line")

GPU/GPUTracking/Global/GPUChainTracking.cxx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,16 +294,12 @@ bool GPUChainTracking::ValidateSettings()
294294
return false;
295295
}
296296
}
297-
if ((GetRecoSteps() & GPUDataTypes::RecoStep::TPCDecompression) && GetProcessingSettings().tpcApplyCFCutsAtDecoding && !GetProcessingSettings().tpcUseOldCPUDecoding) {
298-
GPUError("tpcApplyCFCutsAtDecoding currently requires tpcUseOldCPUDecoding");
299-
return false;
300-
}
301297
if ((GetRecoStepsGPU() & GPUDataTypes::RecoStep::TPCCompression) && !(GetRecoStepsGPU() & GPUDataTypes::RecoStep::TPCCompression) && (GetProcessingSettings().tpcCompressionGatherMode == 1 || GetProcessingSettings().tpcCompressionGatherMode == 3)) {
302298
GPUError("Invalid tpcCompressionGatherMode for compression on CPU");
303299
return false;
304300
}
305-
if (GetProcessingSettings().tpcApplyDebugClusterFilter == 1 && (GetRecoStepsGPU() & GPUDataTypes::RecoStep::TPCClusterFinding || GetProcessingSettings().delayedOutput || GetProcessingSettings().runMC)) {
306-
GPUError("tpcApplyDebugClusterFilter cannot be used with GPU clusterization or with delayedOutput for GPU or with MC labels");
301+
if (GetProcessingSettings().tpcApplyClusterFilterOnCPU > 0 && (GetRecoStepsGPU() & GPUDataTypes::RecoStep::TPCClusterFinding || GetProcessingSettings().delayedOutput || GetProcessingSettings().runMC)) {
302+
GPUError("tpcApplyClusterFilterOnCPU cannot be used with GPU clusterization or with delayedOutput for GPU or with MC labels");
307303
return false;
308304
}
309305
if (GetRecoSteps() & RecoStep::TRDTracking) {
@@ -815,7 +811,7 @@ int32_t GPUChainTracking::RunChainFinalize()
815811

816812
PrintDebugOutput();
817813

818-
//PrintMemoryRelations();
814+
// PrintMemoryRelations();
819815

820816
if (GetProcessingSettings().eventDisplay) {
821817
if (!mDisplayRunning) {

GPU/GPUTracking/Global/GPUChainTrackingClusterizer.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ int32_t GPUChainTracking::RunTPCClusterizer(bool synchronizeOutput)
635635
if (mWaitForFinalInputs) {
636636
GPUFatal("Cannot use waitForFinalInput callback without delayed output");
637637
}
638-
if (!GetProcessingSettings().tpcApplyDebugClusterFilter) {
638+
if (!GetProcessingSettings().tpcApplyClusterFilterOnCPU) {
639639
AllocateRegisteredMemory(mInputsHost->mResourceClusterNativeOutput, mSubOutputControls[GPUTrackingOutputs::getIndex(&GPUTrackingOutputs::clustersNative)]);
640640
tmpNativeClusters = mInputsHost->mPclusterNativeOutput;
641641
} else {
@@ -1021,7 +1021,7 @@ int32_t GPUChainTracking::RunTPCClusterizer(bool synchronizeOutput)
10211021
tmpNativeAccess->clustersMCTruth = mcLabelsConstView;
10221022
tmpNativeAccess->setOffsetPtrs();
10231023
mIOPtrs.clustersNative = tmpNativeAccess;
1024-
if (GetProcessingSettings().tpcApplyDebugClusterFilter) {
1024+
if (GetProcessingSettings().tpcApplyClusterFilterOnCPU) {
10251025
auto allocator = [this, &tmpNativeClusters](size_t size) {
10261026
this->mInputsHost->mNClusterNative = size;
10271027
this->AllocateRegisteredMemory(this->mInputsHost->mResourceClusterNativeOutput, this->mSubOutputControls[GPUTrackingOutputs::getIndex(&GPUTrackingOutputs::clustersNative)]);

GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ int32_t GPUChainTracking::RunTPCCompression()
201201

202202
int32_t GPUChainTracking::RunTPCDecompression()
203203
{
204+
const bool runFiltering = GetProcessingSettings().tpcApplyCFCutsAtDecoding || (GetProcessingSettings().tpcApplyClusterFilterOnCPU > 0) || (param().tpcCutTimeBin > 0);
205+
if (runFiltering && !GetProcessingSettings().tpcUseOldCPUDecoding) {
206+
GPUFatal("tpcApplyCFCutsAtDecoding, tpcApplyClusterFilterOnCPU and tpcCutTimeBin currently require tpcUseOldCPUDecoding");
207+
}
208+
204209
if (GetProcessingSettings().tpcUseOldCPUDecoding) {
205210
const auto& threadContext = GetThreadContext();
206211
TPCClusterDecompressor decomp;
@@ -214,7 +219,6 @@ int32_t GPUChainTracking::RunTPCDecompression()
214219
return ((tmpBuffer = std::make_unique<ClusterNative[]>(size))).get();
215220
};
216221
auto& decompressTimer = getTimer<TPCClusterDecompressor>("TPCDecompression", 0);
217-
bool runFiltering = GetProcessingSettings().tpcApplyCFCutsAtDecoding;
218222
auto allocatorUse = runFiltering ? std::function<ClusterNative*(size_t)>{allocatorTmp} : std::function<ClusterNative*(size_t)>{allocatorFinal};
219223
decompressTimer.Start();
220224
if (decomp.decompress(mIOPtrs.tpcCompressedClusters, *mClusterNativeAccess, allocatorUse, param(), GetProcessingSettings().deterministicGPUReconstruction)) {

GPU/GPUTracking/Global/GPUChainTrackingDebugAndProfiling.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ void GPUChainTracking::SanityCheck()
295295

296296
void GPUChainTracking::RunTPCClusterFilter(o2::tpc::ClusterNativeAccess* clusters, std::function<o2::tpc::ClusterNative*(size_t)> allocator, bool applyClusterCuts)
297297
{
298-
GPUTPCClusterFilter clusterFilter(*clusters);
298+
const uint8_t filterType = GetProcessingSettings().tpcApplyClusterFilterOnCPU;
299+
GPUTPCClusterFilter clusterFilter(*clusters, filterType);
299300
o2::tpc::ClusterNative* outputBuffer = nullptr;
300301
for (int32_t iPhase = 0; iPhase < 2; iPhase++) {
301302
uint32_t countTotal = 0;
@@ -312,7 +313,7 @@ void GPUChainTracking::RunTPCClusterFilter(o2::tpc::ClusterNativeAccess* cluster
312313
if (param().tpcCutTimeBin > 0) {
313314
keep = keep && cl.getTime() < param().tpcCutTimeBin;
314315
}
315-
keep = keep && (!GetProcessingSettings().tpcApplyDebugClusterFilter || clusterFilter.filter(iSector, iRow, cl));
316+
keep = keep && (!filterType || clusterFilter.filter(iSector, iRow, cl));
316317
if (iPhase && keep) {
317318
outputBuffer[countTotal] = cl;
318319
}

0 commit comments

Comments
 (0)