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#ifndef GPUCA_RUN2
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#ifndef GPUCA_RUN2
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#ifndef GPUCA_RUN2 // Run 3 implementation
180 mcLabels_t GetMCLabel(uint32_t i);
181 mcLabel_t GetMCLabel(uint32_t i, uint32_t j);
182#else // Run 2 implementation
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 bool isNoise() const { return false; }
191 void invalidate() { track = MC_LABEL_INVALID; }
192 void setFakeFlag(bool v = true) { track = v ? FakeLabelID(track) : AbsLabelID(track); }
193 void setNoise() { track = MC_LABEL_INVALID; }
194 bool operator==(const mcLabel_t& l);
195 bool operator!=(const mcLabel_t& l) { return !(*this == l); }
196 mcLabelI_t() = default;
197 mcLabelI_t(const mcLabel_t& l);
198 int32_t track = MC_LABEL_INVALID;
199 };
200 const mcLabels_t& GetMCLabel(uint32_t i);
201 const mcLabel_t& GetMCLabel(uint32_t i, uint32_t j);
202 const mcInfo_t& GetMCTrack(const mcLabelI_t& label);
203 static int32_t FakeLabelID(const int32_t id);
204 static int32_t AbsLabelID(const int32_t id);
205#endif
206 template <class T>
207 auto& GetMCTrackObj(T& obj, const mcLabelI_t& l);
208
209 uint32_t GetNMCCollissions() const;
210 uint32_t GetNMCTracks(int32_t iCol) const;
211 uint32_t GetNMCTracks(const mcLabelI_t& label) const;
212 uint32_t GetNMCLabels() const;
213 const mcInfo_t& GetMCTrack(uint32_t iTrk, uint32_t iCol);
214 const mcInfo_t& GetMCTrack(const mcLabel_t& label);
215 int32_t GetMCLabelNID(const mcLabels_t& label);
216 int32_t GetMCLabelNID(uint32_t i);
217 int32_t GetMCLabelID(uint32_t i, uint32_t j);
218 uint32_t GetMCLabelCol(uint32_t i, uint32_t j);
219 static int32_t GetMCLabelID(const mcLabels_t& label, uint32_t j);
220 static int32_t GetMCLabelID(const mcLabel_t& label);
221 float GetMCLabelWeight(uint32_t i, uint32_t j);
222 float GetMCLabelWeight(const mcLabels_t& label, uint32_t j);
223 float GetMCLabelWeight(const mcLabel_t& label);
224 static bool CompareIgnoreFake(const mcLabelI_t& l1, const mcLabelI_t& l2);
225 const auto& GetClusterLabels();
226 bool mcPresent();
227
228 template <bool COUNT = false, class T = void>
229 checkClusterStateResult checkClusterState(uint32_t attach, T* counts = nullptr) const;
230
231 GPUChainTracking* mTracking;
232 const GPUSettingsQA& mConfig;
233 const GPUParam* mParam;
234
235 //-------------------------
236
237 std::vector<mcLabelI_t> mTrackMCLabels;
238#ifndef GPUCA_RUN2
239 std::vector<std::vector<int32_t>> mTrackMCLabelsReverse;
240 std::vector<std::vector<int32_t>> mRecTracks;
241 std::vector<std::vector<int32_t>> mFakeTracks;
242 std::vector<std::vector<additionalMCParameters>> mMCParam;
243#else
244 std::vector<int32_t> mTrackMCLabelsReverse[1];
245 std::vector<int32_t> mRecTracks[1];
246 std::vector<int32_t> mFakeTracks[1];
247 std::vector<additionalMCParameters> mMCParam[1];
248#endif
249 std::vector<mcInfo_t> mMCInfos;
250 std::vector<GPUTPCMCInfoCol> mMCInfosCol;
251 std::vector<uint32_t> mMCNEvents;
252 std::vector<uint32_t> mMCEventOffset;
253
254 std::vector<additionalClusterParameters> mClusterParam;
255 int32_t mNTotalFakes = 0;
256
257 TH1F* mEff[6][2][2][5]; // eff,clone,fake,all,all-fake - findable - secondaries - y,z,phi,eta,pt - work,result
258 TGraphAsymmErrors* mEffResult[4][2][2][5];
259 TCanvas* mCEff[6];
260 TPad* mPEff[6][4];
261 TLegend* mLEff[6];
262
263 TH1F* mRes[5][5][2]; // y,z,phi,lambda,pt,ptlog res - param - res,mean
264 TH2F* mRes2[5][5];
265 TCanvas* mCRes[7];
266 TPad* mPRes[7][5];
267 TLegend* mLRes[6];
268
269 TH1F* mPull[5][5][2]; // y,z,phi,lambda,pt,ptlog res - param - res,mean
270 TH2F* mPull2[5][5];
271 TCanvas* mCPull[7];
272 TPad* mPPull[7][5];
273 TLegend* mLPull[6];
274
275 enum CL_types { CL_attached = 0,
276 CL_fake = 1,
277 CL_att_adj = 2,
278 CL_fakeAdj = 3,
279 CL_tracks = 4,
280 CL_physics = 5,
281 CL_prot = 6,
282 CL_all = 7 };
283 TH1D* mClusters[N_CLS_TYPE * N_CLS_HIST - 1]; // attached, fakeAttached, attach+adjacent, fakeAdjacent, physics, protected, tracks, all / count, rel, integral
284 TCanvas* mCClust[N_CLS_TYPE];
285 TPad* mPClust[N_CLS_TYPE];
286 TLegend* mLClust[N_CLS_TYPE];
287
288 struct counts_t {
289 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;
290 int64_t nMergedLooperConnected = 0, nMergedLooperUnconnected = 0, nCorrectlyAttachedNormalized = 0, nCorrectlyAttachedNormalizedNonFake = 0;
291 double nUnaccessible = 0;
292 } mClusterCounts;
293
294 TH1F* mTrackPt;
295 TCanvas* mCTrackPt;
296 TPad* mPTrackPt;
297 TLegend* mLTrackPt;
298
299 TH1F* mNCl[2];
300 TCanvas* mCNCl[2];
301 TPad* mPNCl[2];
302 TLegend* mLNCl[2];
303
304 TH1F* mT0[2];
305 TCanvas* mCT0[2];
306 TPad* mPT0[2];
307 TLegend* mLT0[2];
308
309 TH2F* mClXY;
310 TCanvas* mCClXY;
311 TPad* mPClXY;
312
313 TH2F* mClRej[3];
314 TH1D* mClRejP;
315 TCanvas* mCClRej[3];
316 TCanvas* mCClRejP;
317 TPad* mPClRej[3];
318 TPad* mPClRejP;
319
320 TH2F* mPadRow[4];
321 TCanvas* mCPadRow[4];
322 TPad* mPPadRow[4];
323
324 std::vector<TH2F*> mHistClusterCount;
325
326 std::vector<TH1F>* mHist1D = nullptr;
327 std::vector<TH2F>* mHist2D = nullptr;
328 std::vector<TH1D>* mHist1Dd = nullptr;
329 std::vector<TGraphAsymmErrors>* mHistGraph = nullptr;
330 bool mHaveExternalHists = false;
331 std::vector<TH1F**> mHist1D_pos{};
332 std::vector<TH2F**> mHist2D_pos{};
333 std::vector<TH1D**> mHist1Dd_pos{};
334 std::vector<TGraphAsymmErrors**> mHistGraph_pos{};
335 template <class T>
336 auto getHistArray();
337 template <class T, typename... Args>
338 void createHist(T*& h, const char* name, Args... args);
339
340 std::unique_ptr<internal::GPUQAGarbageCollection> mGarbageCollector;
341 template <class T, typename... Args>
342 T* createGarbageCollected(Args... args);
343 void clearGarbagageCollector();
344
345 int32_t mNEvents = 0;
346 bool mQAInitialized = false;
347 bool mO2MCDataLoaded = false;
348 int32_t mQATasks = 0;
349 std::vector<std::vector<int32_t>> mcEffBuffer;
350 std::vector<std::vector<int32_t>> mcLabelBuffer;
351 std::vector<std::vector<bool>> mGoodTracks;
352 std::vector<std::vector<bool>> mGoodHits;
353
354 std::vector<uint64_t> mTrackingScratchBuffer;
355
356 static std::vector<TColor*> mColors;
357 static int32_t initColors();
358
359 int32_t mMCTrackMin = -1, mMCTrackMax = -1;
360
361 const o2::tpc::ClusterNativeAccess* mClNative = nullptr;
362 FILE* mTextDump = nullptr;
363};
364
365inline bool GPUQA::SuppressTrack(int32_t iTrack) const { return (mConfig.matchMCLabels.size() && !mGoodTracks[mNEvents][iTrack]); }
366inline bool GPUQA::SuppressHit(int32_t iHit) const { return (mConfig.matchMCLabels.size() && !mGoodHits[mNEvents - 1][iHit]); }
367inline int32_t GPUQA::HitAttachStatus(int32_t iHit) const { return (mClusterParam.size() && mClusterParam[iHit].fakeAttached ? (mClusterParam[iHit].attached ? 1 : 2) : 0); }
368
369} // namespace o2::gpu
370
371#endif
372#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:338
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