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;
89struct checkClusterStateResult;
90namespace internal
91{
92struct GPUQAGarbageCollection;
93} // namespace internal
94
95class GPUQA
96{
97 public:
98 GPUQA();
99 GPUQA(GPUChainTracking* chain, const GPUSettingsQA* config = nullptr, const GPUParam* param = nullptr);
100 ~GPUQA();
101
102#ifdef GPUCA_TPC_GEOMETRY_O2
103 using mcLabels_t = gsl::span<const o2::MCCompLabel>;
104 using mcLabel_t = o2::MCCompLabel;
105 using mcLabelI_t = mcLabel_t;
106#else
107 using mcLabels_t = AliHLTTPCClusterMCLabel;
108 using mcLabel_t = AliHLTTPCClusterMCWeight;
109
110 private:
111 struct mcLabelI_t;
112
113 public:
114#endif
115
116 void UpdateParam(const GPUParam* param) { mParam = param; }
117 int32_t InitQA(int32_t tasks = -1);
118 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);
119 int32_t DrawQAHistograms(TObjArray* qcout = nullptr);
120 void DrawQAHistogramsCleanup(); // Needed after call to DrawQAHistograms with qcout != nullptr when GPUSettingsQA.shipToQCAsCanvas = true to clean up the Canvases etc.
121 void SetMCTrackRange(int32_t min, int32_t max);
122 bool SuppressTrack(int32_t iTrack) const;
123 bool SuppressHit(int32_t iHit) const;
124 int32_t HitAttachStatus(int32_t iHit) const;
125 mcLabelI_t GetMCTrackLabel(uint32_t trackId) const;
126 uint32_t GetMCLabelCol(const mcLabel_t& label) const;
127 bool clusterRemovable(int32_t attach, bool prot) const;
128 void InitO2MCData(GPUTrackingInOutPointers* updateIOPtr = nullptr);
129 void DumpO2MCData(const char* filename) const;
130 int32_t ReadO2MCData(const char* filename);
131 static bool QAAvailable() { return true; }
132 bool IsInitialized() { return mQAInitialized; }
133 void UpdateChain(GPUChainTracking* chain) { mTracking = chain; }
134
135 const std::vector<TH1F>& getHistograms1D() const { return *mHist1D; }
136 const std::vector<TH2F>& getHistograms2D() const { return *mHist2D; }
137 const std::vector<TH1D>& getHistograms1Dd() const { return *mHist1Dd; }
138 const std::vector<TGraphAsymmErrors>& getGraphs() const { return *mHistGraph; }
139 void resetHists();
140 int32_t loadHistograms(std::vector<TH1F>& i1, std::vector<TH2F>& i2, std::vector<TH1D>& i3, std::vector<TGraphAsymmErrors>& i4, int32_t tasks = -1);
141 void* AllocateScratchBuffer(size_t nBytes);
142
143 static constexpr int32_t N_CLS_HIST = 8;
144 static constexpr int32_t N_CLS_TYPE = 3;
145
146 static constexpr int32_t MC_LABEL_INVALID = -1e9;
147
148 enum QA_TASKS {
149 taskTrackingEff = 1,
150 taskTrackingRes = 2,
151 taskTrackingResPull = 4,
152 taskClusterAttach = 8,
153 taskTrackStatistics = 16,
154 taskClusterCounts = 32,
155 taskDefault = 63,
156 taskDefaultPostprocess = 31,
157 tasksNoQC = 56
158 };
159
160 private:
161 struct additionalMCParameters {
162 float pt, phi, theta, eta, nWeightCls;
163 };
164
165 struct additionalClusterParameters {
166 int32_t attached, fakeAttached, adjacent, fakeAdjacent;
167 float pt;
168 };
169
170 int32_t InitQACreateHistograms();
171 int32_t DoClusterCounts(uint64_t* attachClusterCounts, int32_t mode = 0);
172 void PrintClusterCount(int32_t mode, int32_t& num, const char* name, uint64_t n, uint64_t normalization);
173 void CopyO2MCtoIOPtr(GPUTrackingInOutPointers* ptr);
174 template <class T>
175 void SetAxisSize(T* e);
176 void SetLegend(TLegend* l, bool bigText = false);
177 double* CreateLogAxis(int32_t nbins, float xmin, float xmax);
178 void ChangePadTitleSize(TPad* p, float size);
179 void DrawHisto(TH1* histo, char* filename, char* options);
180 void doPerfFigure(float x, float y, float size);
181 void GetName(char* fname, int32_t k, bool noDash = false);
182 template <class T>
183 T* GetHist(T*& ee, std::vector<std::unique_ptr<TFile>>& tin, int32_t k, int32_t nNewInput);
184
185 using mcInfo_t = GPUTPCMCInfo;
186#ifdef GPUCA_TPC_GEOMETRY_O2
187 mcLabels_t GetMCLabel(uint32_t i);
188 mcLabel_t GetMCLabel(uint32_t i, uint32_t j);
189#else
190 struct mcLabelI_t {
191 int32_t getTrackID() const { return AbsLabelID(track); }
192 int32_t getEventID() const { return 0; }
193 int32_t getSourceID() const { return 0; }
194 int64_t getTrackEventSourceID() const { return getTrackID(); }
195 bool isFake() const { return track < 0; }
196 bool isValid() const { return track != MC_LABEL_INVALID; }
197 void invalidate() { track = MC_LABEL_INVALID; }
198 void setFakeFlag(bool v = true) { track = v ? FakeLabelID(track) : AbsLabelID(track); }
199 void setNoise() { track = MC_LABEL_INVALID; }
200 bool operator==(const mcLabel_t& l);
201 bool operator!=(const mcLabel_t& l) { return !(*this == l); }
202 mcLabelI_t() = default;
203 mcLabelI_t(const mcLabel_t& l);
204 int32_t track = MC_LABEL_INVALID;
205 };
206 const mcLabels_t& GetMCLabel(uint32_t i);
207 const mcLabel_t& GetMCLabel(uint32_t i, uint32_t j);
208 const mcInfo_t& GetMCTrack(const mcLabelI_t& label);
209 static int32_t FakeLabelID(const int32_t id);
210 static int32_t AbsLabelID(const int32_t id);
211#endif
212 template <class T>
213 auto& GetMCTrackObj(T& obj, const mcLabelI_t& l);
214
215 uint32_t GetNMCCollissions() const;
216 uint32_t GetNMCTracks(int32_t iCol) const;
217 uint32_t GetNMCTracks(const mcLabelI_t& label) const;
218 uint32_t GetNMCLabels() const;
219 const mcInfo_t& GetMCTrack(uint32_t iTrk, uint32_t iCol);
220 const mcInfo_t& GetMCTrack(const mcLabel_t& label);
221 int32_t GetMCLabelNID(const mcLabels_t& label);
222 int32_t GetMCLabelNID(uint32_t i);
223 int32_t GetMCLabelID(uint32_t i, uint32_t j);
224 uint32_t GetMCLabelCol(uint32_t i, uint32_t j);
225 static int32_t GetMCLabelID(const mcLabels_t& label, uint32_t j);
226 static int32_t GetMCLabelID(const mcLabel_t& label);
227 float GetMCLabelWeight(uint32_t i, uint32_t j);
228 float GetMCLabelWeight(const mcLabels_t& label, uint32_t j);
229 float GetMCLabelWeight(const mcLabel_t& label);
230 static bool CompareIgnoreFake(const mcLabelI_t& l1, const mcLabelI_t& l2);
231 const auto& GetClusterLabels();
232 bool mcPresent();
233
234 template <bool COUNT = false, class T = void>
235 checkClusterStateResult checkClusterState(uint32_t attach, T* counts = nullptr) const;
236
237 GPUChainTracking* mTracking;
238 const GPUSettingsQA& mConfig;
239 const GPUParam* mParam;
240
241 //-------------------------
242
243 std::vector<mcLabelI_t> mTrackMCLabels;
244#ifdef GPUCA_TPC_GEOMETRY_O2
245 std::vector<std::vector<int32_t>> mTrackMCLabelsReverse;
246 std::vector<std::vector<int32_t>> mRecTracks;
247 std::vector<std::vector<int32_t>> mFakeTracks;
248 std::vector<std::vector<additionalMCParameters>> mMCParam;
249#else
250 std::vector<int32_t> mTrackMCLabelsReverse[1];
251 std::vector<int32_t> mRecTracks[1];
252 std::vector<int32_t> mFakeTracks[1];
253 std::vector<additionalMCParameters> mMCParam[1];
254#endif
255 std::vector<mcInfo_t> mMCInfos;
256 std::vector<GPUTPCMCInfoCol> mMCInfosCol;
257 std::vector<uint32_t> mMCNEvents;
258 std::vector<uint32_t> mMCEventOffset;
259
260 std::vector<additionalClusterParameters> mClusterParam;
261 int32_t mNTotalFakes = 0;
262
263 TH1F* mEff[6][2][2][5]; // eff,clone,fake,all,all-fake - findable - secondaries - y,z,phi,eta,pt - work,result
264 TGraphAsymmErrors* mEffResult[4][2][2][5];
265 TCanvas* mCEff[6];
266 TPad* mPEff[6][4];
267 TLegend* mLEff[6];
268
269 TH1F* mRes[5][5][2]; // y,z,phi,lambda,pt,ptlog res - param - res,mean
270 TH2F* mRes2[5][5];
271 TCanvas* mCRes[7];
272 TPad* mPRes[7][5];
273 TLegend* mLRes[6];
274
275 TH1F* mPull[5][5][2]; // y,z,phi,lambda,pt,ptlog res - param - res,mean
276 TH2F* mPull2[5][5];
277 TCanvas* mCPull[7];
278 TPad* mPPull[7][5];
279 TLegend* mLPull[6];
280
281 enum CL_types { CL_attached = 0,
282 CL_fake = 1,
283 CL_att_adj = 2,
284 CL_fakeAdj = 3,
285 CL_tracks = 4,
286 CL_physics = 5,
287 CL_prot = 6,
288 CL_all = 7 };
289 TH1D* mClusters[N_CLS_TYPE * N_CLS_HIST - 1]; // attached, fakeAttached, attach+adjacent, fakeAdjacent, physics, protected, tracks, all / count, rel, integral
290 TCanvas* mCClust[N_CLS_TYPE];
291 TPad* mPClust[N_CLS_TYPE];
292 TLegend* mLClust[N_CLS_TYPE];
293
294 struct counts_t {
295 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;
296 int64_t nMergedLooperConnected = 0, nMergedLooperUnconnected = 0, nCorrectlyAttachedNormalized = 0, nCorrectlyAttachedNormalizedNonFake = 0;
297 double nUnaccessible = 0;
298 } mClusterCounts;
299
300 TH1F* mTracks;
301 TCanvas* mCTracks;
302 TPad* mPTracks;
303 TLegend* mLTracks;
304
305 TH1F* mNCl[2];
306 TCanvas* mCNCl[2];
307 TPad* mPNCl[2];
308 TLegend* mLNCl[2];
309
310 TH1F* mT0[2];
311 TCanvas* mCT0[2];
312 TPad* mPT0[2];
313 TLegend* mLT0[2];
314
315 TH2F* mClXY;
316 TCanvas* mCClXY;
317 TPad* mPClXY;
318
319 TH2F* mClRej[3];
320 TH1D* mClRejP;
321 TCanvas* mCClRej[3];
322 TCanvas* mCClRejP;
323 TPad* mPClRej[3];
324 TPad* mPClRejP;
325
326 TH2F* mPadRow[2];
327 TCanvas* mCPadRow[2];
328 TPad* mPPadRow[2];
329
330 std::vector<TH2F*> mHistClusterCount;
331
332 std::vector<TH1F>* mHist1D = nullptr;
333 std::vector<TH2F>* mHist2D = nullptr;
334 std::vector<TH1D>* mHist1Dd = nullptr;
335 std::vector<TGraphAsymmErrors>* mHistGraph = nullptr;
336 bool mHaveExternalHists = false;
337 std::vector<TH1F**> mHist1D_pos{};
338 std::vector<TH2F**> mHist2D_pos{};
339 std::vector<TH1D**> mHist1Dd_pos{};
340 std::vector<TGraphAsymmErrors**> mHistGraph_pos{};
341 template <class T>
342 auto getHistArray();
343 template <class T, typename... Args>
344 void createHist(T*& h, const char* name, Args... args);
345
346 std::unique_ptr<internal::GPUQAGarbageCollection> mGarbageCollector;
347 template <class T, typename... Args>
348 T* createGarbageCollected(Args... args);
349 void clearGarbagageCollector();
350
351 int32_t mNEvents = 0;
352 bool mQAInitialized = false;
353 bool mO2MCDataLoaded = false;
354 int32_t mQATasks = 0;
355 std::vector<std::vector<int32_t>> mcEffBuffer;
356 std::vector<std::vector<int32_t>> mcLabelBuffer;
357 std::vector<std::vector<bool>> mGoodTracks;
358 std::vector<std::vector<bool>> mGoodHits;
359
360 std::vector<uint64_t> mTrackingScratchBuffer;
361
362 static std::vector<TColor*> mColors;
363 static int32_t initColors();
364
365 int32_t mMCTrackMin = -1, mMCTrackMax = -1;
366
367 const o2::tpc::ClusterNativeAccess* mClNative = nullptr;
368};
369
370inline bool GPUQA::SuppressTrack(int32_t iTrack) const { return (mConfig.matchMCLabels.size() && !mGoodTracks[mNEvents][iTrack]); }
371inline bool GPUQA::SuppressHit(int32_t iHit) const { return (mConfig.matchMCLabels.size() && !mGoodHits[mNEvents - 1][iHit]); }
372inline int32_t GPUQA::HitAttachStatus(int32_t iHit) const { return (mClusterParam.size() && mClusterParam[iHit].fakeAttached ? (mClusterParam[iHit].attached ? 1 : 2) : 0); }
373
374} // namespace o2::gpu
375
376#endif
377#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:338
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
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()
bool isValid(std::string alias)
constexpr size_t min
constexpr size_t max