Project
Loading...
Searching...
No Matches
GPUQA.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
15#ifndef GPUQA_H
16#define GPUQA_H
17
18#include "GPUSettings.h"
20class TH1F;
21class TH2F;
22class TCanvas;
23class TPad;
24class TLegend;
25class TPad;
26class TH1;
27class TFile;
28class TH1D;
29class TObjArray;
30class TColor;
31class TGraphAsymmErrors;
32typedef int16_t Color_t;
33
34#if !defined(GPUCA_BUILD_QA) || defined(GPUCA_GPUCODE)
35
36namespace o2::gpu
37{
38class GPUQA
39{
40 public:
41 GPUQA(void* chain) {}
42 ~GPUQA() = default;
43 typedef int32_t mcLabelI_t;
44 int32_t InitQA(int32_t tasks = 0) { return 1; }
45 void RunQA(bool matchOnly = false) {}
46 int32_t DrawQAHistograms() { return 1; }
47 void SetMCTrackRange(int32_t min, int32_t max) {}
48 bool SuppressTrack(int32_t iTrack) const { return false; }
49 bool SuppressHit(int32_t iHit) const { return false; }
50 int32_t HitAttachStatus(int32_t iHit) const { return false; }
51 mcLabelI_t GetMCTrackLabel(uint32_t trackId) const { return -1; }
52 bool clusterRemovable(int32_t attach, bool prot) const { return false; }
53 void DumpO2MCData(const char* filename) const {}
54 int32_t ReadO2MCData(const char* filename) { return 1; }
55 void* AllocateScratchBuffer(size_t nBytes) { return nullptr; }
56 static bool QAAvailable() { return false; }
57 static bool IsInitialized() { return false; }
59};
60} // namespace o2::gpu
61
62#else
63
64#include "GPUTPCDef.h"
65#include <cmath>
66#include <vector>
67#include <memory>
68#ifdef GPUCA_TPC_GEOMETRY_O2
69#include <gsl/span>
70#endif
71
72namespace o2
73{
74class MCCompLabel;
75namespace tpc
76{
77class TrackTPC;
78struct ClusterNativeAccess;
79} // namespace tpc
80} // namespace o2
81
83
84namespace o2::gpu
85{
86class GPUChainTracking;
87struct GPUParam;
88struct GPUTPCMCInfo;
89namespace internal
90{
91struct GPUQAGarbageCollection;
92} // namespace internal
93
94class GPUQA
95{
96 public:
97 GPUQA();
98 GPUQA(GPUChainTracking* chain, const GPUSettingsQA* config = nullptr, const GPUParam* param = nullptr);
99 ~GPUQA();
100
101#ifdef GPUCA_TPC_GEOMETRY_O2
102 using mcLabels_t = gsl::span<const o2::MCCompLabel>;
103 using mcLabel_t = o2::MCCompLabel;
104 using mcLabelI_t = mcLabel_t;
105#else
106 using mcLabels_t = AliHLTTPCClusterMCLabel;
107 using mcLabel_t = AliHLTTPCClusterMCWeight;
108
109 private:
110 struct mcLabelI_t;
111
112 public:
113#endif
114
115 void UpdateParam(const GPUParam* param) { mParam = param; }
116 int32_t InitQA(int32_t tasks = -1);
117 void RunQA(bool matchOnly = false, const std::vector<o2::tpc::TrackTPC>* tracksExternal = nullptr, const std::vector<o2::MCCompLabel>* tracksExtMC = nullptr, const o2::tpc::ClusterNativeAccess* clNative = nullptr);
118 int32_t DrawQAHistograms(TObjArray* qcout = nullptr);
119 void DrawQAHistogramsCleanup(); // Needed after call to DrawQAHistograms with qcout != nullptr when GPUSettingsQA.shipToQCAsCanvas = true to clean up the Canvases etc.
120 void SetMCTrackRange(int32_t min, int32_t max);
121 bool SuppressTrack(int32_t iTrack) const;
122 bool SuppressHit(int32_t iHit) const;
123 int32_t HitAttachStatus(int32_t iHit) const;
124 mcLabelI_t GetMCTrackLabel(uint32_t trackId) const;
125 uint32_t GetMCLabelCol(const mcLabel_t& label) const;
126 bool clusterRemovable(int32_t attach, bool prot) const;
127 void InitO2MCData(GPUTrackingInOutPointers* updateIOPtr = nullptr);
128 void DumpO2MCData(const char* filename) const;
129 int32_t ReadO2MCData(const char* filename);
130 static bool QAAvailable() { return true; }
131 bool IsInitialized() { return mQAInitialized; }
132 void UpdateChain(GPUChainTracking* chain) { mTracking = chain; }
133
134 const std::vector<TH1F>& getHistograms1D() const { return *mHist1D; }
135 const std::vector<TH2F>& getHistograms2D() const { return *mHist2D; }
136 const std::vector<TH1D>& getHistograms1Dd() const { return *mHist1Dd; }
137 const std::vector<TGraphAsymmErrors>& getGraphs() const { return *mHistGraph; }
138 void resetHists();
139 int32_t loadHistograms(std::vector<TH1F>& i1, std::vector<TH2F>& i2, std::vector<TH1D>& i3, std::vector<TGraphAsymmErrors>& i4, int32_t tasks = -1);
140 void* AllocateScratchBuffer(size_t nBytes);
141
142 static constexpr int32_t N_CLS_HIST = 8;
143 static constexpr int32_t N_CLS_TYPE = 3;
144
145 static constexpr int32_t MC_LABEL_INVALID = -1e9;
146
147 enum QA_TASKS {
148 taskTrackingEff = 1,
149 taskTrackingRes = 2,
150 taskTrackingResPull = 4,
151 taskClusterAttach = 8,
152 taskTrackStatistics = 16,
153 taskClusterCounts = 32,
154 taskDefault = 63,
155 taskDefaultPostprocess = 31,
156 tasksNoQC = 56
157 };
158
159 private:
160 struct additionalMCParameters {
161 float pt, phi, theta, eta, nWeightCls;
162 };
163
164 struct additionalClusterParameters {
165 int32_t attached, fakeAttached, adjacent, fakeAdjacent;
166 float pt;
167 };
168
169 int32_t InitQACreateHistograms();
170 int32_t DoClusterCounts(uint64_t* attachClusterCounts, int32_t mode = 0);
171 void PrintClusterCount(int32_t mode, int32_t& num, const char* name, uint64_t n, uint64_t normalization);
172 void CopyO2MCtoIOPtr(GPUTrackingInOutPointers* ptr);
173 template <class T>
174 void SetAxisSize(T* e);
175 void SetLegend(TLegend* l);
176 double* CreateLogAxis(int32_t nbins, float xmin, float xmax);
177 void ChangePadTitleSize(TPad* p, float size);
178 void DrawHisto(TH1* histo, char* filename, char* options);
179 void doPerfFigure(float x, float y, float size);
180 void GetName(char* fname, int32_t k);
181 template <class T>
182 T* GetHist(T*& ee, std::vector<std::unique_ptr<TFile>>& tin, int32_t k, int32_t nNewInput);
183
184 using mcInfo_t = GPUTPCMCInfo;
185#ifdef GPUCA_TPC_GEOMETRY_O2
186 mcLabels_t GetMCLabel(uint32_t i);
187 mcLabel_t GetMCLabel(uint32_t i, uint32_t j);
188#else
189 struct mcLabelI_t {
190 int32_t getTrackID() const { return AbsLabelID(track); }
191 int32_t getEventID() const { return 0; }
192 int32_t getSourceID() const { return 0; }
193 int64_t getTrackEventSourceID() const { return getTrackID(); }
194 bool isFake() const { return track < 0; }
195 bool isValid() const { return track != MC_LABEL_INVALID; }
196 void invalidate() { track = MC_LABEL_INVALID; }
197 void setFakeFlag(bool v = true) { track = v ? FakeLabelID(track) : AbsLabelID(track); }
198 void setNoise() { track = MC_LABEL_INVALID; }
199 bool operator==(const mcLabel_t& l);
200 bool operator!=(const mcLabel_t& l) { return !(*this == l); }
201 mcLabelI_t() = default;
202 mcLabelI_t(const mcLabel_t& l);
203 int32_t track = MC_LABEL_INVALID;
204 };
205 const mcLabels_t& GetMCLabel(uint32_t i);
206 const mcLabel_t& GetMCLabel(uint32_t i, uint32_t j);
207 const mcInfo_t& GetMCTrack(const mcLabelI_t& label);
208 static int32_t FakeLabelID(const int32_t id);
209 static int32_t AbsLabelID(const int32_t id);
210#endif
211 template <class T>
212 auto& GetMCTrackObj(T& obj, const mcLabelI_t& l);
213
214 uint32_t GetNMCCollissions() const;
215 uint32_t GetNMCTracks(int32_t iCol) const;
216 uint32_t GetNMCTracks(const mcLabelI_t& label) const;
217 uint32_t GetNMCLabels() const;
218 const mcInfo_t& GetMCTrack(uint32_t iTrk, uint32_t iCol);
219 const mcInfo_t& GetMCTrack(const mcLabel_t& label);
220 int32_t GetMCLabelNID(const mcLabels_t& label);
221 int32_t GetMCLabelNID(uint32_t i);
222 int32_t GetMCLabelID(uint32_t i, uint32_t j);
223 uint32_t GetMCLabelCol(uint32_t i, uint32_t j);
224 static int32_t GetMCLabelID(const mcLabels_t& label, uint32_t j);
225 static int32_t GetMCLabelID(const mcLabel_t& label);
226 float GetMCLabelWeight(uint32_t i, uint32_t j);
227 float GetMCLabelWeight(const mcLabels_t& label, uint32_t j);
228 float GetMCLabelWeight(const mcLabel_t& label);
229 const auto& GetClusterLabels();
230 bool mcPresent();
231
232 GPUChainTracking* mTracking;
233 const GPUSettingsQA& mConfig;
234 const GPUParam* mParam;
235
236 const char* str_perf_figure_1 = "ALICE Performance 2018/03/20";
237 // const char* str_perf_figure_2 = "2015, MC pp, #sqrt{s} = 5.02 TeV";
238 const char* str_perf_figure_2 = "2015, MC Pb-Pb, #sqrt{s_{NN}} = 5.02 TeV";
239 //-------------------------
240
241 std::vector<mcLabelI_t> mTrackMCLabels;
242#ifdef GPUCA_TPC_GEOMETRY_O2
243 std::vector<std::vector<int32_t>> mTrackMCLabelsReverse;
244 std::vector<std::vector<int32_t>> mRecTracks;
245 std::vector<std::vector<int32_t>> mFakeTracks;
246 std::vector<std::vector<additionalMCParameters>> mMCParam;
247#else
248 std::vector<int32_t> mTrackMCLabelsReverse[1];
249 std::vector<int32_t> mRecTracks[1];
250 std::vector<int32_t> mFakeTracks[1];
251 std::vector<additionalMCParameters> mMCParam[1];
252#endif
253 std::vector<mcInfo_t> mMCInfos;
254 std::vector<GPUTPCMCInfoCol> mMCInfosCol;
255 std::vector<uint32_t> mMCNEvents;
256 std::vector<uint32_t> mMCEventOffset;
257
258 std::vector<additionalClusterParameters> mClusterParam;
259 int32_t mNTotalFakes = 0;
260
261 TH1F* mEff[4][2][2][5]; // eff,clone,fake,all - findable - secondaries - y,z,phi,eta,pt - work,result
262 TGraphAsymmErrors* mEffResult[4][2][2][5];
263 TCanvas* mCEff[6];
264 TPad* mPEff[6][4];
265 TLegend* mLEff[6];
266
267 TH1F* mRes[5][5][2]; // y,z,phi,lambda,pt,ptlog res - param - res,mean
268 TH2F* mRes2[5][5];
269 TCanvas* mCRes[7];
270 TPad* mPRes[7][5];
271 TLegend* mLRes[6];
272
273 TH1F* mPull[5][5][2]; // y,z,phi,lambda,pt,ptlog res - param - res,mean
274 TH2F* mPull2[5][5];
275 TCanvas* mCPull[7];
276 TPad* mPPull[7][5];
277 TLegend* mLPull[6];
278
279 enum CL_types { CL_attached = 0,
280 CL_fake = 1,
281 CL_att_adj = 2,
282 CL_fakeAdj = 3,
283 CL_tracks = 4,
284 CL_physics = 5,
285 CL_prot = 6,
286 CL_all = 7 };
287 TH1D* mClusters[N_CLS_TYPE * N_CLS_HIST - 1]; // attached, fakeAttached, attach+adjacent, fakeAdjacent, physics, protected, tracks, all / count, rel, integral
288 TCanvas* mCClust[N_CLS_TYPE];
289 TPad* mPClust[N_CLS_TYPE];
290 TLegend* mLClust[N_CLS_TYPE];
291
292 struct counts_t {
293 int64_t nRejected = 0, nTube = 0, nTube200 = 0, nLoopers = 0, nLowPt = 0, n200MeV = 0, nPhysics = 0, nProt = 0, nUnattached = 0, nTotal = 0, nHighIncl = 0, nAbove400 = 0, nFakeRemove400 = 0, nFullFakeRemove400 = 0, nBelow40 = 0, nFakeProtect40 = 0, nMergedLooper = 0;
294 double nUnaccessible = 0;
295 } mClusterCounts;
296
297 TH1F* mTracks;
298 TCanvas* mCTracks;
299 TPad* mPTracks;
300 TLegend* mLTracks;
301
302 TH1F* mNCl;
303 TCanvas* mCNCl;
304 TPad* mPNCl;
305 TLegend* mLNCl;
306
307 TH2F* mClXY;
308 TCanvas* mCClXY;
309 TPad* mPClXY;
310
311 std::vector<TH2F*> mHistClusterCount;
312
313 std::vector<TH1F>* mHist1D = nullptr;
314 std::vector<TH2F>* mHist2D = nullptr;
315 std::vector<TH1D>* mHist1Dd = nullptr;
316 std::vector<TGraphAsymmErrors>* mHistGraph = nullptr;
317 bool mHaveExternalHists = false;
318 std::vector<TH1F**> mHist1D_pos{};
319 std::vector<TH2F**> mHist2D_pos{};
320 std::vector<TH1D**> mHist1Dd_pos{};
321 std::vector<TGraphAsymmErrors**> mHistGraph_pos{};
322 template <class T>
323 auto getHistArray();
324 template <class T, typename... Args>
325 void createHist(T*& h, const char* name, Args... args);
326
327 std::unique_ptr<internal::GPUQAGarbageCollection> mGarbageCollector;
328 template <class T, typename... Args>
329 T* createGarbageCollected(Args... args);
330 void clearGarbagageCollector();
331
332 int32_t mNEvents = 0;
333 bool mQAInitialized = false;
334 bool mO2MCDataLoaded = false;
335 int32_t mQATasks = 0;
336 std::vector<std::vector<int32_t>> mcEffBuffer;
337 std::vector<std::vector<int32_t>> mcLabelBuffer;
338 std::vector<std::vector<bool>> mGoodTracks;
339 std::vector<std::vector<bool>> mGoodHits;
340
341 std::vector<uint64_t> mTrackingScratchBuffer;
342
343 static std::vector<TColor*> mColors;
344 static int32_t initColors();
345
346 int32_t mMCTrackMin = -1, mMCTrackMax = -1;
347
348 const o2::tpc::ClusterNativeAccess* mClNative = nullptr;
349};
350
351inline bool GPUQA::SuppressTrack(int32_t iTrack) const { return (mConfig.matchMCLabels.size() && !mGoodTracks[mNEvents][iTrack]); }
352inline bool GPUQA::SuppressHit(int32_t iHit) const { return (mConfig.matchMCLabels.size() && !mGoodHits[mNEvents - 1][iHit]); }
353inline int32_t GPUQA::HitAttachStatus(int32_t iHit) const { return (mClusterParam.size() && mClusterParam[iHit].fakeAttached ? (mClusterParam[iHit].attached ? 1 : 2) : 0); }
354
355} // namespace o2::gpu
356
357#endif
358#endif
int32_t i
int16_t Color_t
Definition GPUQA.h:32
GPUChain * chain
uint32_t j
Definition RawData.h:0
TBranch * ptr
double num
Class for time synchronization of RawReader instances.
int32_t ReadO2MCData(const char *filename)
Definition GPUQA.h:54
bool clusterRemovable(int32_t attach, bool prot) const
Definition GPUQA.h:52
int32_t HitAttachStatus(int32_t iHit) const
Definition GPUQA.h:50
~GPUQA()=default
Definition GPUQA.cxx:343
void * AllocateScratchBuffer(size_t nBytes)
Definition GPUQA.h:55
static bool QAAvailable()
Definition GPUQA.h:56
void SetMCTrackRange(int32_t min, int32_t max)
Definition GPUQA.h:47
bool SuppressTrack(int32_t iTrack) const
Definition GPUQA.h:48
mcLabelI_t GetMCTrackLabel(uint32_t trackId) const
Definition GPUQA.h:51
int32_t DrawQAHistograms()
Definition GPUQA.h:46
void UpdateChain(GPUChainTracking *chain)
Definition GPUQA.h:58
static bool IsInitialized()
Definition GPUQA.h:57
bool SuppressHit(int32_t iHit) const
Definition GPUQA.h:49
int32_t InitQA(int32_t tasks=0)
Definition GPUQA.h:44
void DumpO2MCData(const char *filename) const
Definition GPUQA.h:53
int32_t mcLabelI_t
Definition GPUQA.h:43
void RunQA(bool matchOnly=false)
Definition GPUQA.h:45
GPUQA(void *chain)
Definition GPUQA.h:41
GLdouble n
Definition glcorearb.h:1982
GLint GLenum GLint x
Definition glcorearb.h:403
GLenum mode
Definition glcorearb.h:266
GLsizeiptr size
Definition glcorearb.h:659
const GLdouble * v
Definition glcorearb.h:832
GLuint const GLchar * name
Definition glcorearb.h:781
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
GLenum GLfloat param
Definition glcorearb.h:271
bool isValid(std::string_view dcsAlias)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
bool operator!=(const observer_ptr< W1 > &p1, const observer_ptr< W2 > &p2)
bool operator==(const observer_ptr< W1 > &p1, const observer_ptr< W2 > &p2)
std::string filename()
constexpr size_t min
constexpr size_t max