Project
Loading...
Searching...
No Matches
GPUExtractPbPbCollision.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15static void GPUExtractPbPbCollision(GPUParam& param, GPUTrackingInOutPointers& ioPtrs)
16{
17 std::vector<uint32_t> counts(param.continuousMaxTimeBin + 1);
18 std::vector<uint32_t> sums(param.continuousMaxTimeBin + 1);
19 std::vector<uint32_t> countsTracks(param.continuousMaxTimeBin + 1);
20 std::vector<uint32_t> sumsTracks(param.continuousMaxTimeBin + 1);
21 std::vector<bool> mask(param.continuousMaxTimeBin + 1);
22 const int32_t driftlength = 520;
23 const bool checkAfterGlow = true;
24 const int32_t afterGlowLength = checkAfterGlow ? 8000 : 0;
25 for (uint32_t i = 0; i < ioPtrs.clustersNative->nClustersTotal; i++) {
26 int32_t time = ioPtrs.clustersNative->clustersLinear[i].getTime();
27 if (time < 0 || time > param.continuousMaxTimeBin) {
28 fprintf(stderr, "Invalid time %d > %d\n", time, param.continuousMaxTimeBin);
29 throw std::runtime_error("Invalid Time");
30 }
31 counts[time]++;
32 }
33 for (uint32_t i = 0; i < ioPtrs.nMergedTracks; i++) {
34 if (ioPtrs.mergedTracks[i].NClusters() < 40) {
35 continue;
36 }
37 int32_t time = ioPtrs.mergedTracks[i].GetParam().GetTZOffset();
38 if (time < 0 || time > param.continuousMaxTimeBin) {
39 continue;
40 }
41 countsTracks[time]++;
42 }
43 int32_t first = 0, last = 0;
44 for (int32_t i = driftlength; i < param.continuousMaxTimeBin; i++) {
45 if (counts[i]) {
46 first = i;
47 break;
48 }
49 }
50 for (int32_t i = param.continuousMaxTimeBin + 1 - driftlength; i > 0; i--) {
51 if (counts[i - 1]) {
52 last = i;
53 break;
54 }
55 }
56 uint32_t count = 0;
57 uint32_t countTracks = 0;
58 uint32_t min = 1e9;
59 uint64_t avg = 0;
60 for (int32_t i = first; i < last; i++) {
61 count += counts[i];
62 countTracks += countsTracks[i];
63 if (i - first >= driftlength) {
64 sums[i - driftlength] = count;
65 sumsTracks[i - driftlength] = countTracks;
66 if (count < min) {
67 min = count;
68 }
69 avg += count;
70 count -= counts[i - driftlength];
71 countTracks -= countsTracks[i - driftlength];
72 }
73 }
74 avg /= (last - first - driftlength);
75 printf("BASELINE Min %d Avg %d\n", min, (int32_t)avg);
76 /*for (int32_t i = first; i < last - driftlength; i++) {
77 printf("STAT %d: %u %u (trks %u)\n", i, sums[i], counts[i], sumsTracks[i]);
78 }*/
79 bool found = false;
80 do {
81 found = false;
82 uint32_t max = 0, maxpos = 0;
83 for (int32_t i = first; i < last - driftlength - afterGlowLength; i++) {
84 if (sums[i] > 10 * min && sums[i] > avg && sumsTracks[i] > 3) {
85 bool noColInAfterGlow = true;
86 if (checkAfterGlow) {
87 for (int32_t ii = i + driftlength; ii < i + driftlength + afterGlowLength; ii++) {
88 if (sums[ii] > 10 * min && sums[ii] > avg && sumsTracks[ii] > 3) {
89 noColInAfterGlow = false;
90 }
91 }
92 }
93 if (noColInAfterGlow && sums[i] > max) {
94 max = sums[i];
95 maxpos = i;
96 found = true;
97 }
98 }
99 }
100 if (found) {
101 uint32_t glow = 0;
102 uint32_t glowcount = 0;
103 if (checkAfterGlow) {
104 int32_t glowstart = maxpos + driftlength;
105 int32_t glowend = std::min<int32_t>(last, maxpos + driftlength + afterGlowLength);
106 for (int32_t i = glowstart; i < glowend; i++) {
107 glowcount++;
108 glow += counts[i];
109 }
110 // printf("AFTERGLOW RANGE %d %d\n", glowstart, glowend);
111 }
112 printf("MAX %d: %u (Tracks %u) Glow %d (%d)\n", maxpos, max, sumsTracks[maxpos], glow, glowcount);
113 for (int32_t i = std::max<int32_t>(first, maxpos - driftlength); i < std::min<int32_t>(last, maxpos + driftlength + afterGlowLength); i++) {
114 sums[i] = 0;
115 mask[i] = true;
116 }
117 }
118 } while (found && !checkAfterGlow);
119 uint32_t noise = 0;
120 uint32_t noisecount = 0;
121 for (int32_t i = first; i < last; i++) {
122 if (!mask[i]) {
123 noise += counts[i];
124 noisecount++;
125 }
126 }
127 printf("AVERAGE NOISE: %d\n", noise / noisecount);
128}
int16_t time
Definition RawEventData.h:4
int32_t i
GLint GLsizei count
Definition glcorearb.h:399
GLenum GLfloat param
Definition glcorearb.h:271
GLint GLuint mask
Definition glcorearb.h:291
constexpr size_t min
constexpr size_t max