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