Project
Loading...
Searching...
No Matches
GPUQA.cxx
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#define QA_DEBUG 0
16#define QA_TIMING 0
17
18#include "Rtypes.h" // Include ROOT header first, to use ROOT and disable replacements
19
20#include "TH1F.h"
21#include "TH2F.h"
22#include "TH1D.h"
23#include "TGraphAsymmErrors.h"
24#include "TCanvas.h"
25#include "TPad.h"
26#include "TLegend.h"
27#include "TColor.h"
28#include "TPaveText.h"
29#include "TF1.h"
30#include "TFile.h"
31#include "TTree.h"
32#include "TStyle.h"
33#include "TLatex.h"
34#include "TObjArray.h"
35#include <sys/stat.h>
36
37#include "GPUQA.h"
38#include "GPUTPCDef.h"
39#include "GPUTPCTrackingData.h"
40#include "GPUChainTracking.h"
41#include "GPUChainTrackingGetters.inc"
42#include "GPUTPCTrack.h"
43#include "GPUTPCTracker.h"
44#include "GPUTPCGMMergedTrack.h"
45#include "GPUTPCGMPropagator.h"
47#include "GPUTPCMCInfo.h"
48#include "GPUO2DataTypes.h"
49#include "GPUParam.inc"
51#include "GPUTPCConvertImpl.h"
52#include "TPCFastTransform.h"
54#include "GPUROOTDump.h"
57#include "GPUSettings.h"
58#include "GPUDefMacros.h"
59#ifdef GPUCA_O2_LIB
69#include "TPDGCode.h"
70#include "TParticlePDG.h"
71#include "TDatabasePDG.h"
72#endif
73#include "GPUQAHelper.h"
74#include <algorithm>
75#include <cstdio>
76#include <cinttypes>
77#include <fstream>
78
79#include "utils/timer.h"
80
81#include <oneapi/tbb.h>
82
83using namespace o2::gpu;
84
85namespace o2::gpu
86{
88 bool unattached = false;
89 float qpt = 0.f;
90 bool lowPt = false;
91 bool mev200 = false;
94 int32_t id = 0;
95 bool physics = false, protect = false;
96};
97} // namespace o2::gpu
98
99template <bool COUNT, class T>
100inline checkClusterStateResult GPUQA::checkClusterState(uint32_t attach, T* counts) const
101{
103 r.unattached = attach == 0;
105 if (!r.unattached && !(attach & gputpcgmmergertypes::attachProtect)) {
106 r.qpt = fabsf(mTracking->mIOPtrs.mergedTracks[r.id].GetParam().GetQPt());
107 r.lowPt = r.qpt * mTracking->GetParam().qptB5Scaler > mTracking->GetParam().rec.tpc.rejectQPtB5;
108 r.mev200 = r.qpt > 5;
109 r.mergedLooperUnconnected = mTracking->mIOPtrs.mergedTracks[r.id].MergedLooperUnconnected();
110 r.mergedLooperConnected = mTracking->mIOPtrs.mergedTracks[r.id].MergedLooperConnected();
111 }
112 if (r.mev200) {
113 if constexpr (COUNT) {
114 counts->n200MeV++;
115 }
116 }
117 if (r.lowPt) {
118 if constexpr (COUNT) {
119 counts->nLowPt++;
120 }
121 } else if (r.mergedLooperUnconnected) {
122 if constexpr (COUNT) {
123 counts->nMergedLooperUnconnected++;
124 }
125 } else if (r.mergedLooperConnected) {
126 if constexpr (COUNT) {
127 counts->nMergedLooperConnected++;
128 }
129 } else if (attach) {
130 r.protect = !GPUTPCClusterRejection::GetRejectionStatus<COUNT>(attach, r.physics, counts, &r.mev200) && ((attach & gputpcgmmergertypes::attachProtect) || !GPUTPCClusterRejection::IsTrackRejected(mTracking->mIOPtrs.mergedTracks[r.id], mTracking->GetParam()));
131 }
132 return r;
133}
134
135static const GPUSettingsQA& GPUQA_GetConfig(GPUChainTracking* chain)
136{
137 static GPUSettingsQA defaultConfig;
138 if (chain && chain->mConfigQA) {
139 return *chain->mConfigQA;
140 } else {
141 return defaultConfig;
142 }
143}
144
145static const constexpr float LOG_PT_MIN = -1.;
146
147static constexpr float Y_MAX = 40;
148static constexpr float Z_MAX = 100;
149static constexpr float PT_MIN = 0.01; // TODO: Take from Param
150static constexpr float PT_MIN_PRIM = 0.1;
151static constexpr float PT_MIN_CLUST = 0.01;
152static constexpr float PT_MAX = 20;
153static constexpr float ETA_MAX = 1.5;
154static constexpr float ETA_MAX2 = 0.9;
155
156static constexpr bool CLUST_HIST_INT_SUM = false;
157
158static constexpr const int32_t COLORCOUNT = 12;
159
160static const constexpr char* EFF_TYPES[6] = {"Rec", "Clone", "Fake", "All", "RecAndClone", "MC"};
161static const constexpr char* FINDABLE_NAMES[2] = {"All", "Findable"};
162static const constexpr char* PRIM_NAMES[2] = {"Prim", "Sec"};
163static const constexpr char* PARAMETER_NAMES[5] = {"Y", "Z", "#Phi", "#lambda", "Relative #it{p}_{T}"};
164static const constexpr char* PARAMETER_NAMES_NATIVE[5] = {"Y", "Z", "sin(#Phi)", "tan(#lambda)", "q/#it{p}_{T} (curvature)"};
165static const constexpr char* VSPARAMETER_NAMES[6] = {"Y", "Z", "Phi", "Eta", "Pt", "Pt_log"};
166static const constexpr char* EFF_NAMES[3] = {"Efficiency", "Clone Rate", "Fake Rate"};
167static const constexpr char* EFFICIENCY_TITLES[4] = {"Efficiency (Primary Tracks, Findable)", "Efficiency (Secondary Tracks, Findable)", "Efficiency (Primary Tracks)", "Efficiency (Secondary Tracks)"};
168static const constexpr double SCALE[5] = {10., 10., 1000., 1000., 100.};
169static const constexpr double SCALE_NATIVE[5] = {10., 10., 1000., 1000., 1.};
170static const constexpr char* XAXIS_TITLES[5] = {"#it{y}_{mc} (cm)", "#it{z}_{mc} (cm)", "#Phi_{mc} (rad)", "#eta_{mc}", "#it{p}_{Tmc} (GeV/#it{c})"};
171static const constexpr char* AXIS_TITLES[5] = {"#it{y}-#it{y}_{mc} (mm) (Resolution)", "#it{z}-#it{z}_{mc} (mm) (Resolution)", "#phi-#phi_{mc} (mrad) (Resolution)", "#lambda-#lambda_{mc} (mrad) (Resolution)", "(#it{p}_{T} - #it{p}_{Tmc}) / #it{p}_{Tmc} (%) (Resolution)"};
172static const constexpr char* AXIS_TITLES_NATIVE[5] = {"#it{y}-#it{y}_{mc} (mm) (Resolution)", "#it{z}-#it{z}_{mc} (mm) (Resolution)", "sin(#phi)-sin(#phi_{mc}) (Resolution)", "tan(#lambda)-tan(#lambda_{mc}) (Resolution)", "q*(q/#it{p}_{T} - q/#it{p}_{Tmc}) (Resolution)"};
173static const constexpr char* AXIS_TITLES_PULL[5] = {"#it{y}-#it{y}_{mc}/#sigma_{y} (Pull)", "#it{z}-#it{z}_{mc}/#sigma_{z} (Pull)", "sin(#phi)-sin(#phi_{mc})/#sigma_{sin(#phi)} (Pull)", "tan(#lambda)-tan(#lambda_{mc})/#sigma_{tan(#lambda)} (Pull)",
174 "q*(q/#it{p}_{T} - q/#it{p}_{Tmc})/#sigma_{q/#it{p}_{T}} (Pull)"};
175static const constexpr char* CLUSTER_NAMES[GPUQA::N_CLS_HIST] = {"Correctly attached clusters", "Fake attached clusters", "Attached + adjacent clusters", "Fake adjacent clusters", "Clusters of reconstructed tracks", "Used in Physics", "Protected", "All clusters"};
176static const constexpr char* CLUSTER_TITLES[GPUQA::N_CLS_TYPE] = {"Clusters Pt Distribution / Attachment", "Clusters Pt Distribution / Attachment (relative to all clusters)", "Clusters Pt Distribution / Attachment (integrated)"};
177static const constexpr char* CLUSTER_NAMES_SHORT[GPUQA::N_CLS_HIST] = {"Attached", "Fake", "AttachAdjacent", "FakeAdjacent", "FoundTracks", "Physics", "Protected", "All"};
178static const constexpr char* CLUSTER_TYPES[GPUQA::N_CLS_TYPE] = {"", "Ratio", "Integral"};
179static const constexpr char* REJECTED_NAMES[3] = {"All", "Rejected", "Fraction"};
180static const constexpr int32_t COLORS_HEX[COLORCOUNT] = {0xB03030, 0x00A000, 0x0000C0, 0x9400D3, 0x19BBBF, 0xF25900, 0x7F7F7F, 0xFFD700, 0x07F707, 0x07F7F7, 0xF08080, 0x000000};
181
182static const constexpr int32_t CONFIG_DASHED_MARKERS = 0;
183
184static const constexpr float AXES_MIN[5] = {-Y_MAX, -Z_MAX, 0.f, -ETA_MAX, PT_MIN};
185static const constexpr float AXES_MAX[5] = {Y_MAX, Z_MAX, 2.f * M_PI, ETA_MAX, PT_MAX};
186static const constexpr int32_t AXIS_BINS[5] = {51, 51, 144, 31, 50};
187static const constexpr int32_t RES_AXIS_BINS[] = {1017, 113}; // Consecutive bin sizes, histograms are binned down until the maximum entry is 50, each bin size should evenly divide its predecessor.
188static const constexpr float RES_AXES[5] = {1., 1., 0.03, 0.03, 1.0};
189static const constexpr float RES_AXES_NATIVE[5] = {1., 1., 0.1, 0.1, 5.0};
190static const constexpr float PULL_AXIS = 10.f;
191
192std::vector<TColor*> GPUQA::mColors;
193int32_t GPUQA::initColors()
194{
195 mColors.reserve(COLORCOUNT);
196 for (int32_t i = 0; i < COLORCOUNT; i++) {
197 float f1 = (float)((COLORS_HEX[i] >> 16) & 0xFF) / (float)0xFF;
198 float f2 = (float)((COLORS_HEX[i] >> 8) & 0xFF) / (float)0xFF;
199 float f3 = (float)((COLORS_HEX[i] >> 0) & 0xFF) / (float)0xFF;
200 mColors.emplace_back(new TColor(10000 + i, f1, f2, f3));
201 }
202 return 0;
203}
204static constexpr Color_t defaultColorNums[COLORCOUNT] = {kRed, kBlue, kGreen, kMagenta, kOrange, kAzure, kBlack, kYellow, kGray, kTeal, kSpring, kPink};
205
206#define TRACK_EXPECTED_REFERENCE_X_DEFAULT 81
207#ifdef GPUCA_TPC_GEOMETRY_O2
208static inline int32_t GPUQA_O2_ConvertFakeLabel(int32_t label) { return label >= 0x7FFFFFFE ? -1 : label; }
209inline uint32_t GPUQA::GetNMCCollissions() const { return mMCInfosCol.size(); }
210inline uint32_t GPUQA::GetNMCTracks(int32_t iCol) const { return mMCInfosCol[iCol].num; }
211inline uint32_t GPUQA::GetNMCTracks(const mcLabelI_t& label) const { return mMCInfosCol[mMCEventOffset[label.getSourceID()] + label.getEventID()].num; }
212inline uint32_t GPUQA::GetNMCLabels() const { return mClNative->clustersMCTruth ? mClNative->clustersMCTruth->getIndexedSize() : 0; }
213inline const GPUQA::mcInfo_t& GPUQA::GetMCTrack(uint32_t iTrk, uint32_t iCol) { return mMCInfos[mMCInfosCol[iCol].first + iTrk]; }
214inline const GPUQA::mcInfo_t& GPUQA::GetMCTrack(const mcLabel_t& label) { return mMCInfos[mMCInfosCol[mMCEventOffset[label.getSourceID()] + label.getEventID()].first + label.getTrackID()]; }
215inline GPUQA::mcLabels_t GPUQA::GetMCLabel(uint32_t i) { return mClNative->clustersMCTruth->getLabels(i); }
216inline int32_t GPUQA::GetMCLabelNID(const mcLabels_t& label) { return label.size(); }
217inline int32_t GPUQA::GetMCLabelNID(uint32_t i) { return mClNative->clustersMCTruth->getLabels(i).size(); }
218inline GPUQA::mcLabel_t GPUQA::GetMCLabel(uint32_t i, uint32_t j) { return mClNative->clustersMCTruth->getLabels(i)[j]; }
219inline int32_t GPUQA::GetMCLabelID(uint32_t i, uint32_t j) { return GPUQA_O2_ConvertFakeLabel(mClNative->clustersMCTruth->getLabels(i)[j].getTrackID()); }
220inline int32_t GPUQA::GetMCLabelID(const mcLabels_t& label, uint32_t j) { return GPUQA_O2_ConvertFakeLabel(label[j].getTrackID()); }
221inline int32_t GPUQA::GetMCLabelID(const mcLabel_t& label) { return GPUQA_O2_ConvertFakeLabel(label.getTrackID()); }
222inline uint32_t GPUQA::GetMCLabelCol(uint32_t i, uint32_t j) { return mMCEventOffset[mClNative->clustersMCTruth->getLabels(i)[j].getSourceID()] + mClNative->clustersMCTruth->getLabels(i)[j].getEventID(); }
223inline const auto& GPUQA::GetClusterLabels() { return mClNative->clustersMCTruth; }
224inline float GPUQA::GetMCLabelWeight(uint32_t i, uint32_t j) { return 1; }
225inline float GPUQA::GetMCLabelWeight(const mcLabels_t& label, uint32_t j) { return 1; }
226inline float GPUQA::GetMCLabelWeight(const mcLabel_t& label) { return 1; }
227inline bool GPUQA::mcPresent() { return !mConfig.noMC && mTracking && mClNative && mClNative->clustersMCTruth && mMCInfos.size(); }
228uint32_t GPUQA::GetMCLabelCol(const mcLabel_t& label) const { return !label.isValid() ? 0 : (mMCEventOffset[label.getSourceID()] + label.getEventID()); }
229GPUQA::mcLabelI_t GPUQA::GetMCTrackLabel(uint32_t trackId) const { return trackId >= mTrackMCLabels.size() ? MCCompLabel() : mTrackMCLabels[trackId]; }
230bool GPUQA::CompareIgnoreFake(const mcLabelI_t& l1, const mcLabelI_t& l2) { return l1.compare(l2) >= 0; }
231#define TRACK_EXPECTED_REFERENCE_X 78
232#else
233inline GPUQA::mcLabelI_t::mcLabelI_t(const GPUQA::mcLabel_t& l) : track(l.fMCID) {}
234inline bool GPUQA::mcLabelI_t::operator==(const GPUQA::mcLabel_t& l) { return AbsLabelID(track) == l.fMCID; }
235inline uint32_t GPUQA::GetNMCCollissions() const { return 1; }
236inline uint32_t GPUQA::GetNMCTracks(int32_t iCol) const { return mTracking->mIOPtrs.nMCInfosTPC; }
237inline uint32_t GPUQA::GetNMCTracks(const mcLabelI_t& label) const { return mTracking->mIOPtrs.nMCInfosTPC; }
238inline uint32_t GPUQA::GetNMCLabels() const { return mTracking->mIOPtrs.nMCLabelsTPC; }
239inline const GPUQA::mcInfo_t& GPUQA::GetMCTrack(uint32_t iTrk, uint32_t iCol) { return mTracking->mIOPtrs.mcInfosTPC[AbsLabelID(iTrk)]; }
240inline const GPUQA::mcInfo_t& GPUQA::GetMCTrack(const mcLabel_t& label) { return GetMCTrack(label.fMCID, 0); }
241inline const GPUQA::mcInfo_t& GPUQA::GetMCTrack(const mcLabelI_t& label) { return GetMCTrack(label.track, 0); }
242inline const GPUQA::mcLabels_t& GPUQA::GetMCLabel(uint32_t i) { return mTracking->mIOPtrs.mcLabelsTPC[i]; }
243inline const GPUQA::mcLabel_t& GPUQA::GetMCLabel(uint32_t i, uint32_t j) { return mTracking->mIOPtrs.mcLabelsTPC[i].fClusterID[j]; }
244inline int32_t GPUQA::GetMCLabelNID(const mcLabels_t& label) { return 3; }
245inline int32_t GPUQA::GetMCLabelNID(uint32_t i) { return 3; }
246inline int32_t GPUQA::GetMCLabelID(uint32_t i, uint32_t j) { return mTracking->mIOPtrs.mcLabelsTPC[i].fClusterID[j].fMCID; }
247inline int32_t GPUQA::GetMCLabelID(const mcLabels_t& label, uint32_t j) { return label.fClusterID[j].fMCID; }
248inline int32_t GPUQA::GetMCLabelID(const mcLabel_t& label) { return label.fMCID; }
249inline uint32_t GPUQA::GetMCLabelCol(uint32_t i, uint32_t j) { return 0; }
250
251inline const auto& GPUQA::GetClusterLabels() { return mTracking->mIOPtrs.mcLabelsTPC; }
252inline float GPUQA::GetMCLabelWeight(uint32_t i, uint32_t j) { return mTracking->mIOPtrs.mcLabelsTPC[i].fClusterID[j].fWeight; }
253inline float GPUQA::GetMCLabelWeight(const mcLabels_t& label, uint32_t j) { return label.fClusterID[j].fWeight; }
254inline float GPUQA::GetMCLabelWeight(const mcLabel_t& label) { return label.fWeight; }
255inline int32_t GPUQA::FakeLabelID(int32_t id) { return id < 0 ? id : (-2 - id); }
256inline int32_t GPUQA::AbsLabelID(int32_t id) { return id >= 0 ? id : (-id - 2); }
257inline bool GPUQA::mcPresent() { return !mConfig.noMC && mTracking && GetNMCLabels() && GetNMCTracks(0); }
258uint32_t GPUQA::GetMCLabelCol(const mcLabel_t& label) const { return 0; }
259GPUQA::mcLabelI_t GPUQA::GetMCTrackLabel(uint32_t trackId) const { return trackId >= mTrackMCLabels.size() ? mcLabelI_t() : mTrackMCLabels[trackId]; }
260bool GPUQA::CompareIgnoreFake(const mcLabelI_t& l1, const mcLabelI_t& l2) { return AbsLabelID(l1) == AbsLabelID(l2); }
261#define TRACK_EXPECTED_REFERENCE_X TRACK_EXPECTED_REFERENCE_X_DEFAULT
262#endif
263template <class T>
264inline auto& GPUQA::GetMCTrackObj(T& obj, const GPUQA::mcLabelI_t& l)
265{
266 return obj[mMCEventOffset[l.getSourceID()] + l.getEventID()][l.getTrackID()];
267}
268
269template <>
270auto GPUQA::getHistArray<TH1F>()
271{
272 return std::make_pair(mHist1D, &mHist1D_pos);
273}
274template <>
275auto GPUQA::getHistArray<TH2F>()
276{
277 return std::make_pair(mHist2D, &mHist2D_pos);
278}
279template <>
280auto GPUQA::getHistArray<TH1D>()
281{
282 return std::make_pair(mHist1Dd, &mHist1Dd_pos);
283}
284template <>
285auto GPUQA::getHistArray<TGraphAsymmErrors>()
286{
287 return std::make_pair(mHistGraph, &mHistGraph_pos);
288}
289template <class T, typename... Args>
290void GPUQA::createHist(T*& h, const char* name, Args... args)
291{
292 const auto& p = getHistArray<T>();
293 if (mHaveExternalHists) {
294 if (p.first->size() <= p.second->size()) {
295 GPUError("Array sizes mismatch: Histograms %lu <= Positions %lu", p.first->size(), p.second->size());
296 throw std::runtime_error("Incoming histogram array incomplete");
297 }
298 if (strcmp((*p.first)[p.second->size()].GetName(), name)) {
299 GPUError("Histogram name mismatch: in array %s, trying to create %s", (*p.first)[p.second->size()].GetName(), name);
300 throw std::runtime_error("Incoming histogram has incorrect name");
301 }
302 } else {
303 if constexpr (std::is_same_v<T, TGraphAsymmErrors>) {
304 p.first->emplace_back();
305 p.first->back().SetName(name);
306 } else {
307 p.first->emplace_back(name, args...);
308 }
309 }
310 h = &((*p.first)[p.second->size()]);
311 p.second->emplace_back(&h);
312}
313
314namespace o2::gpu::internal
315{
317 std::tuple<std::vector<std::unique_ptr<TCanvas>>, std::vector<std::unique_ptr<TLegend>>, std::vector<std::unique_ptr<TPad>>, std::vector<std::unique_ptr<TLatex>>, std::vector<std::unique_ptr<TH1D>>> v;
318};
319} // namespace o2::gpu::internal
320
321template <class T, typename... Args>
322T* GPUQA::createGarbageCollected(Args... args)
323{
324 auto& v = std::get<std::vector<std::unique_ptr<T>>>(mGarbageCollector->v);
325 v.emplace_back(std::make_unique<T>(args...));
326 return v.back().get();
327}
328void GPUQA::clearGarbagageCollector()
329{
330 std::get<std::vector<std::unique_ptr<TPad>>>(mGarbageCollector->v).clear(); // Make sure to delete TPad first due to ROOT ownership (std::tuple has no defined order in its destructor)
331 std::apply([](auto&&... args) { ((args.clear()), ...); }, mGarbageCollector->v);
332}
333
334GPUQA::GPUQA(GPUChainTracking* chain, const GPUSettingsQA* config, const GPUParam* param) : mTracking(chain), mConfig(config ? *config : GPUQA_GetConfig(chain)), mParam(param ? param : &chain->GetParam()), mGarbageCollector(std::make_unique<internal::GPUQAGarbageCollection>())
335{
336 mMCEventOffset.resize(1, 0);
337}
338
340{
341 if (mQAInitialized && !mHaveExternalHists) {
342 delete mHist1D;
343 delete mHist2D;
344 delete mHist1Dd;
345 delete mHistGraph;
346 }
347 clearGarbagageCollector(); // Needed to guarantee correct order for ROOT ownership
348}
349
350bool GPUQA::clusterRemovable(int32_t attach, bool prot) const
351{
352 const auto& r = checkClusterState<false>(attach);
353 if (prot) {
354 return r.protect || r.physics;
355 }
356 return (!r.unattached && !r.physics && !r.protect);
357}
358
359template <class T>
360void GPUQA::SetAxisSize(T* e)
361{
362 e->GetYaxis()->SetTitleOffset(1.0);
363 e->GetYaxis()->SetTitleSize(0.045);
364 e->GetYaxis()->SetLabelSize(0.045);
365 e->GetXaxis()->SetTitleOffset(1.03);
366 e->GetXaxis()->SetTitleSize(0.045);
367 e->GetXaxis()->SetLabelOffset(-0.005);
368 e->GetXaxis()->SetLabelSize(0.045);
369}
370
371void GPUQA::SetLegend(TLegend* l, bool bigText)
372{
373 l->SetTextFont(72);
374 l->SetTextSize(bigText ? 0.03 : 0.016);
375 l->SetFillColor(0);
376}
377
378double* GPUQA::CreateLogAxis(int32_t nbins, float xmin, float xmax)
379{
380 float logxmin = std::log10(xmin);
381 float logxmax = std::log10(xmax);
382 float binwidth = (logxmax - logxmin) / nbins;
383
384 double* xbins = new double[nbins + 1];
385
386 xbins[0] = xmin;
387 for (int32_t i = 1; i <= nbins; i++) {
388 xbins[i] = std::pow(10, logxmin + i * binwidth);
389 }
390 return xbins;
391}
392
393void GPUQA::ChangePadTitleSize(TPad* p, float size)
394{
395 p->Update();
396 TPaveText* pt = (TPaveText*)(p->GetPrimitive("title"));
397 if (pt == nullptr) {
398 GPUError("Error changing title");
399 } else {
400 pt->SetTextSize(size);
401 p->Modified();
402 }
403}
404
405void GPUQA::DrawHisto(TH1* histo, char* filename, char* options)
406{
407 TCanvas tmp;
408 tmp.cd();
409 histo->Draw(options);
410 tmp.Print(filename);
411}
412
413void GPUQA::doPerfFigure(float x, float y, float size)
414{
415 const char* str_perf_figure_1 = "ALICE Performance";
416 const char* str_perf_figure_2_mc = "MC, Pb#minusPb, #sqrt{s_{NN}} = 5.36 TeV";
417 const char* str_perf_figure_2_data = "Pb#minusPb, #sqrt{s_{NN}} = 5.36 TeV";
418
419 if (mConfig.perfFigure == 0) {
420 return;
421 }
422 TLatex* t = createGarbageCollected<TLatex>(); // TODO: We could perhaps put everything in a legend, to get a white background if there is a grid
423 t->SetNDC(kTRUE);
424 t->SetTextColor(1);
425 t->SetTextSize(size);
426 t->DrawLatex(x, y, str_perf_figure_1);
427 t->SetTextSize(size * 0.8);
428 t->DrawLatex(x, y - 0.01 - size, mConfig.perfFigure > 0 ? str_perf_figure_2_mc : str_perf_figure_2_data);
429}
430
431void GPUQA::SetMCTrackRange(int32_t min, int32_t max)
432{
433 mMCTrackMin = min;
434 mMCTrackMax = max;
435}
436
437int32_t GPUQA::InitQACreateHistograms()
438{
439 char name[2048], fname[1024];
440 if (mQATasks & taskTrackingEff) {
441 // Create Efficiency Histograms
442 for (int32_t i = 0; i < 6; i++) {
443 for (int32_t j = 0; j < 2; j++) {
444 for (int32_t k = 0; k < 2; k++) {
445 for (int32_t l = 0; l < 5; l++) {
446 snprintf(name, 2048, "%s%s%s%sVs%s", "tracks", EFF_TYPES[i], FINDABLE_NAMES[j], PRIM_NAMES[k], VSPARAMETER_NAMES[l]);
447 if (l == 4) {
448 std::unique_ptr<double[]> binsPt{CreateLogAxis(AXIS_BINS[4], k == 0 ? PT_MIN_PRIM : AXES_MIN[4], AXES_MAX[4])};
449 createHist(mEff[i][j][k][l], name, name, AXIS_BINS[l], binsPt.get());
450 } else {
451 createHist(mEff[i][j][k][l], name, name, AXIS_BINS[l], AXES_MIN[l], AXES_MAX[l]);
452 }
453 if (!mHaveExternalHists) {
454 mEff[i][j][k][l]->Sumw2();
455 }
456 strcat(name, "_eff");
457 if (i < 4) {
458 createHist(mEffResult[i][j][k][l], name);
459 }
460 }
461 }
462 }
463 }
464 }
465
466 // Create Resolution Histograms
467 if (mQATasks & taskTrackingRes) {
468 for (int32_t i = 0; i < 5; i++) {
469 for (int32_t j = 0; j < 5; j++) {
470 snprintf(name, 2048, "rms_%s_vs_%s", VSPARAMETER_NAMES[i], VSPARAMETER_NAMES[j]);
471 snprintf(fname, 1024, "mean_%s_vs_%s", VSPARAMETER_NAMES[i], VSPARAMETER_NAMES[j]);
472 if (j == 4) {
473 std::unique_ptr<double[]> binsPt{CreateLogAxis(AXIS_BINS[4], mConfig.resPrimaries == 1 ? PT_MIN_PRIM : AXES_MIN[4], AXES_MAX[4])};
474 createHist(mRes[i][j][0], name, name, AXIS_BINS[j], binsPt.get());
475 createHist(mRes[i][j][1], fname, fname, AXIS_BINS[j], binsPt.get());
476 } else {
477 createHist(mRes[i][j][0], name, name, AXIS_BINS[j], AXES_MIN[j], AXES_MAX[j]);
478 createHist(mRes[i][j][1], fname, fname, AXIS_BINS[j], AXES_MIN[j], AXES_MAX[j]);
479 }
480 snprintf(name, 2048, "res_%s_vs_%s", VSPARAMETER_NAMES[i], VSPARAMETER_NAMES[j]);
481 const float* axis = mConfig.nativeFitResolutions ? RES_AXES_NATIVE : RES_AXES;
482 const int32_t nbins = i == 4 && mConfig.nativeFitResolutions ? (10 * RES_AXIS_BINS[0]) : RES_AXIS_BINS[0];
483 if (j == 4) {
484 std::unique_ptr<double[]> binsPt{CreateLogAxis(AXIS_BINS[4], mConfig.resPrimaries == 1 ? PT_MIN_PRIM : AXES_MIN[4], AXES_MAX[4])};
485 createHist(mRes2[i][j], name, name, nbins, -axis[i], axis[i], AXIS_BINS[j], binsPt.get());
486 } else {
487 createHist(mRes2[i][j], name, name, nbins, -axis[i], axis[i], AXIS_BINS[j], AXES_MIN[j], AXES_MAX[j]);
488 }
489 }
490 }
491 }
492
493 // Create Pull Histograms
494 if (mQATasks & taskTrackingResPull) {
495 for (int32_t i = 0; i < 5; i++) {
496 for (int32_t j = 0; j < 5; j++) {
497 snprintf(name, 2048, "pull_rms_%s_vs_%s", VSPARAMETER_NAMES[i], VSPARAMETER_NAMES[j]);
498 snprintf(fname, 1024, "pull_mean_%s_vs_%s", VSPARAMETER_NAMES[i], VSPARAMETER_NAMES[j]);
499 if (j == 4) {
500 std::unique_ptr<double[]> binsPt{CreateLogAxis(AXIS_BINS[4], AXES_MIN[4], AXES_MAX[4])};
501 createHist(mPull[i][j][0], name, name, AXIS_BINS[j], binsPt.get());
502 createHist(mPull[i][j][1], fname, fname, AXIS_BINS[j], binsPt.get());
503 } else {
504 createHist(mPull[i][j][0], name, name, AXIS_BINS[j], AXES_MIN[j], AXES_MAX[j]);
505 createHist(mPull[i][j][1], fname, fname, AXIS_BINS[j], AXES_MIN[j], AXES_MAX[j]);
506 }
507 snprintf(name, 2048, "pull_%s_vs_%s", VSPARAMETER_NAMES[i], VSPARAMETER_NAMES[j]);
508 if (j == 4) {
509 std::unique_ptr<double[]> binsPt{CreateLogAxis(AXIS_BINS[4], AXES_MIN[4], AXES_MAX[4])};
510 createHist(mPull2[i][j], name, name, RES_AXIS_BINS[0], -PULL_AXIS, PULL_AXIS, AXIS_BINS[j], binsPt.get());
511 } else {
512 createHist(mPull2[i][j], name, name, RES_AXIS_BINS[0], -PULL_AXIS, PULL_AXIS, AXIS_BINS[j], AXES_MIN[j], AXES_MAX[j]);
513 }
514 }
515 }
516 }
517
518 // Create Cluster Histograms
519 if (mQATasks & taskClusterAttach) {
520 for (int32_t i = 0; i < N_CLS_TYPE * N_CLS_HIST - 1; i++) {
521 int32_t ioffset = i >= (2 * N_CLS_HIST - 1) ? (2 * N_CLS_HIST - 1) : i >= N_CLS_HIST ? N_CLS_HIST : 0;
522 int32_t itype = i >= (2 * N_CLS_HIST - 1) ? 2 : i >= N_CLS_HIST ? 1 : 0;
523 snprintf(name, 2048, "clusters%s%s", CLUSTER_NAMES_SHORT[i - ioffset], CLUSTER_TYPES[itype]);
524 std::unique_ptr<double[]> binsPt{CreateLogAxis(AXIS_BINS[4], PT_MIN_CLUST, PT_MAX)};
525 createHist(mClusters[i], name, name, AXIS_BINS[4], binsPt.get());
526 }
527
528 createHist(mPadRow[0], "padrow0", "padrow0", GPUCA_ROW_COUNT, 0, GPUCA_ROW_COUNT - 1, GPUCA_ROW_COUNT, 0, GPUCA_ROW_COUNT - 1);
529 createHist(mPadRow[1], "padrow1", "padrow1", 100.f, -0.2f, 0.2f, GPUCA_ROW_COUNT, 0, GPUCA_ROW_COUNT - 1);
530 createHist(mPadRow[2], "padrow2", "padrow2", 100.f, -0.2f, 0.2f, GPUCA_ROW_COUNT, 0, GPUCA_ROW_COUNT - 1);
531 }
532
533 if (mQATasks & taskTrackStatistics) {
534 // Create Tracks Histograms
535 for (int32_t i = 0; i < 2; i++) {
536 snprintf(name, 2048, i ? "nrows_with_cluster" : "nclusters");
537 createHist(mNCl[i], name, name, 160, 0, 159);
538 }
539 std::unique_ptr<double[]> binsPt{CreateLogAxis(AXIS_BINS[4], PT_MIN_CLUST, PT_MAX)};
540 createHist(mTracks, "tracks_pt", "tracks_pt", AXIS_BINS[4], binsPt.get());
541 const uint32_t maxTime = (mTracking && mTracking->GetParam().continuousMaxTimeBin > 0) ? mTracking->GetParam().continuousMaxTimeBin : TPC_MAX_TIME_BIN_TRIGGERED;
542 createHist(mT0[0], "tracks_t0", "tracks_t0", (maxTime + 1) / 10, 0, maxTime);
543 createHist(mT0[1], "tracks_t0_res", "tracks_t0_res", 1000, -100, 100);
544 createHist(mClXY, "clXY", "clXY", 1000, -250, 250, 1000, -250, 250); // TODO: Pass name only once
545
546 const int padCount = GPUTPCGeometry::NPads(GPUCA_ROW_COUNT - 1);
547 for (int32_t i = 0; i < 3; i++) {
548 snprintf(name, 2048, "clrej_%d", i);
549 createHist(mClRej[i], name, name, 2 * padCount, -padCount / 2 + 0.5f, padCount / 2 - 0.5f, GPUCA_ROW_COUNT, 0, GPUCA_ROW_COUNT - 1);
550 }
551 createHist(mClRejP, "clrejp", "clrejp", GPUCA_ROW_COUNT, 0, GPUCA_ROW_COUNT - 1);
552 }
553
554 if ((mQATasks & taskClusterCounts) && mConfig.clusterRejectionHistograms) {
555 int32_t num = DoClusterCounts(nullptr, 2);
556 mHistClusterCount.resize(num);
557 DoClusterCounts(nullptr, 1);
558 }
559
560 for (uint32_t i = 0; i < mHist1D->size(); i++) {
561 *mHist1D_pos[i] = &(*mHist1D)[i];
562 }
563 for (uint32_t i = 0; i < mHist2D->size(); i++) {
564 *mHist2D_pos[i] = &(*mHist2D)[i];
565 }
566 for (uint32_t i = 0; i < mHist1Dd->size(); i++) {
567 *mHist1Dd_pos[i] = &(*mHist1Dd)[i];
568 }
569 for (uint32_t i = 0; i < mHistGraph->size(); i++) {
570 *mHistGraph_pos[i] = &(*mHistGraph)[i];
571 }
572
573 return 0;
574}
575
576int32_t GPUQA::loadHistograms(std::vector<TH1F>& i1, std::vector<TH2F>& i2, std::vector<TH1D>& i3, std::vector<TGraphAsymmErrors>& i4, int32_t tasks)
577{
578 if (tasks == -1) {
579 tasks = taskDefaultPostprocess;
580 }
581 if (mQAInitialized && (!mHaveExternalHists || tasks != mQATasks)) {
582 throw std::runtime_error("QA not initialized or initialized with different task array");
583 }
584 mHist1D = &i1;
585 mHist2D = &i2;
586 mHist1Dd = &i3;
587 mHistGraph = &i4;
588 mHist1D_pos.clear();
589 mHist2D_pos.clear();
590 mHist1Dd_pos.clear();
591 mHistGraph_pos.clear();
592 mHaveExternalHists = true;
593 if (mConfig.noMC) {
594 tasks &= tasksNoQC;
595 }
596 mQATasks = tasks;
597 if (InitQACreateHistograms()) {
598 return 1;
599 }
600 mQAInitialized = true;
601 return 0;
602}
603
604void GPUQA::DumpO2MCData(const char* filename) const
605{
606 FILE* fp = fopen(filename, "w+b");
607 if (fp == nullptr) {
608 return;
609 }
610 uint32_t n = mMCInfos.size();
611 fwrite(&n, sizeof(n), 1, fp);
612 fwrite(mMCInfos.data(), sizeof(mMCInfos[0]), n, fp);
613 n = mMCInfosCol.size();
614 fwrite(&n, sizeof(n), 1, fp);
615 fwrite(mMCInfosCol.data(), sizeof(mMCInfosCol[0]), n, fp);
616 n = mMCEventOffset.size();
617 fwrite(&n, sizeof(n), 1, fp);
618 fwrite(mMCEventOffset.data(), sizeof(mMCEventOffset[0]), n, fp);
619 fclose(fp);
620}
621
622int32_t GPUQA::ReadO2MCData(const char* filename)
623{
624 FILE* fp = fopen(filename, "rb");
625 if (fp == nullptr) {
626 return 1;
627 }
628 uint32_t n;
629 uint32_t x;
630 if ((x = fread(&n, sizeof(n), 1, fp)) != 1) {
631 fclose(fp);
632 return 1;
633 }
634 mMCInfos.resize(n);
635 if (fread(mMCInfos.data(), sizeof(mMCInfos[0]), n, fp) != n) {
636 fclose(fp);
637 return 1;
638 }
639 if ((x = fread(&n, sizeof(n), 1, fp)) != 1) {
640 fclose(fp);
641 return 1;
642 }
643 mMCInfosCol.resize(n);
644 if (fread(mMCInfosCol.data(), sizeof(mMCInfosCol[0]), n, fp) != n) {
645 fclose(fp);
646 return 1;
647 }
648 if ((x = fread(&n, sizeof(n), 1, fp)) != 1) {
649 fclose(fp);
650 return 1;
651 }
652 mMCEventOffset.resize(n);
653 if (fread(mMCEventOffset.data(), sizeof(mMCEventOffset[0]), n, fp) != n) {
654 fclose(fp);
655 return 1;
656 }
657 if (mTracking && mTracking->GetProcessingSettings().debugLevel >= 2) {
658 printf("Read %ld bytes MC Infos\n", ftell(fp));
659 }
660 fclose(fp);
661 if (mTracking) {
662 CopyO2MCtoIOPtr(&mTracking->mIOPtrs);
663 }
664 return 0;
665}
666
667void GPUQA::CopyO2MCtoIOPtr(GPUTrackingInOutPointers* ptr)
668{
669 ptr->mcInfosTPC = mMCInfos.data();
670 ptr->nMCInfosTPC = mMCInfos.size();
671 ptr->mcInfosTPCCol = mMCInfosCol.data();
672 ptr->nMCInfosTPCCol = mMCInfosCol.size();
673}
674
675void GPUQA::InitO2MCData(GPUTrackingInOutPointers* updateIOPtr)
676{
677#ifdef GPUCA_O2_LIB
678 if (!mO2MCDataLoaded) {
679 HighResTimer timer(mTracking && mTracking->GetProcessingSettings().debugLevel);
680 if (mTracking && mTracking->GetProcessingSettings().debugLevel) {
681 GPUInfo("Start reading O2 Track MC information");
682 }
683 static constexpr float PRIM_MAX_T = 0.01f;
684
685 o2::steer::MCKinematicsReader mcReader("collisioncontext.root");
686 std::vector<int32_t> refId;
687
688 auto dc = o2::steer::DigitizationContext::loadFromFile("collisioncontext.root");
689 const auto& evrec = dc->getEventRecords();
690 const auto& evparts = dc->getEventParts();
691 std::vector<std::vector<float>> evTimeBins(mcReader.getNSources());
692 for (uint32_t i = 0; i < evTimeBins.size(); i++) {
693 evTimeBins[i].resize(mcReader.getNEvents(i), -100.f);
694 }
695 for (uint32_t i = 0; i < evrec.size(); i++) {
696 const auto& ir = evrec[i];
697 for (uint32_t j = 0; j < evparts[i].size(); j++) {
698 const int iSim = evparts[i][j].sourceID;
699 const int iEv = evparts[i][j].entryID;
700 if (iSim == o2::steer::QEDSOURCEID || ir.differenceInBC(o2::raw::HBFUtils::Instance().getFirstIR()) >= 0) {
703 if (evTimeBins[iSim][iEv] >= 0) {
704 throw std::runtime_error("Multiple time bins for same MC collision found");
705 }
706 evTimeBins[iSim][iEv] = timebin;
707 }
708 }
709 }
710
711 uint32_t nSimSources = mcReader.getNSources();
712 mMCEventOffset.resize(nSimSources);
713 uint32_t nSimTotalEvents = 0;
714 uint32_t nSimTotalTracks = 0;
715 for (uint32_t i = 0; i < nSimSources; i++) {
716 mMCEventOffset[i] = nSimTotalEvents;
717 nSimTotalEvents += mcReader.getNEvents(i);
718 }
719
720 mMCInfosCol.resize(nSimTotalEvents);
721 for (int32_t iSim = 0; iSim < mcReader.getNSources(); iSim++) {
722 for (int32_t i = 0; i < mcReader.getNEvents(iSim); i++) {
723 const float timebin = evTimeBins[iSim][i];
724
725 const std::vector<o2::MCTrack>& tracks = mcReader.getTracks(iSim, i);
726 const std::vector<o2::TrackReference>& trackRefs = mcReader.getTrackRefsByEvent(iSim, i);
727
728 refId.resize(tracks.size());
729 std::fill(refId.begin(), refId.end(), -1);
730 for (uint32_t j = 0; j < trackRefs.size(); j++) {
731 if (trackRefs[j].getDetectorId() == o2::detectors::DetID::TPC) {
732 int32_t trkId = trackRefs[j].getTrackID();
733 if (refId[trkId] == -1) {
734 refId[trkId] = j;
735 }
736 }
737 }
738 mMCInfosCol[mMCEventOffset[iSim] + i].first = mMCInfos.size();
739 mMCInfosCol[mMCEventOffset[iSim] + i].num = tracks.size();
740 mMCInfos.resize(mMCInfos.size() + tracks.size());
741 for (uint32_t j = 0; j < tracks.size(); j++) {
742 auto& info = mMCInfos[mMCInfosCol[mMCEventOffset[iSim] + i].first + j];
743 const auto& trk = tracks[j];
744 TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle(trk.GetPdgCode());
745 Int_t pid = -1;
746 if (abs(trk.GetPdgCode()) == kElectron) {
747 pid = 0;
748 }
749 if (abs(trk.GetPdgCode()) == kMuonMinus) {
750 pid = 1;
751 }
752 if (abs(trk.GetPdgCode()) == kPiPlus) {
753 pid = 2;
754 }
755 if (abs(trk.GetPdgCode()) == kKPlus) {
756 pid = 3;
757 }
758 if (abs(trk.GetPdgCode()) == kProton) {
759 pid = 4;
760 }
761
762 info.charge = particle ? particle->Charge() : 0;
763 info.prim = trk.T() < PRIM_MAX_T;
764 info.primDaughters = 0;
765 if (trk.getFirstDaughterTrackId() != -1) {
766 for (int32_t k = trk.getFirstDaughterTrackId(); k <= trk.getLastDaughterTrackId(); k++) {
767 if (tracks[k].T() < PRIM_MAX_T) {
768 info.primDaughters = 1;
769 break;
770 }
771 }
772 }
773 info.pid = pid;
774 info.t0 = timebin;
775 if (refId[j] >= 0) {
776 const auto& trkRef = trackRefs[refId[j]];
777 info.x = trkRef.X();
778 info.y = trkRef.Y();
779 info.z = trkRef.Z();
780 info.pX = trkRef.Px();
781 info.pY = trkRef.Py();
782 info.pZ = trkRef.Pz();
783 info.genRadius = std::sqrt(trk.GetStartVertexCoordinatesX() * trk.GetStartVertexCoordinatesX() + trk.GetStartVertexCoordinatesY() * trk.GetStartVertexCoordinatesY() + trk.GetStartVertexCoordinatesZ() * trk.GetStartVertexCoordinatesZ());
784 } else {
785 info.x = info.y = info.z = info.pX = info.pY = info.pZ = 0;
786 info.genRadius = 0;
787 }
788 }
789 }
790 }
791 if (timer.IsRunning()) {
792 GPUInfo("Finished reading O2 Track MC information (%f seconds)", timer.GetCurrentElapsedTime());
793 }
794 mO2MCDataLoaded = true;
795 }
796 if (updateIOPtr) {
797 CopyO2MCtoIOPtr(updateIOPtr);
798 }
799#endif
800}
801
802int32_t GPUQA::InitQA(int32_t tasks)
803{
804 if (mQAInitialized) {
805 throw std::runtime_error("QA already initialized");
806 }
807 if (tasks == -1) {
808 tasks = taskDefault;
809 }
810
811 mHist1D = new std::vector<TH1F>;
812 mHist2D = new std::vector<TH2F>;
813 mHist1Dd = new std::vector<TH1D>;
814 mHistGraph = new std::vector<TGraphAsymmErrors>;
815 if (mConfig.noMC) {
816 tasks &= tasksNoQC;
817 }
818 mQATasks = tasks;
819
820 if (mTracking->GetProcessingSettings().qcRunFraction != 100.f && mQATasks != taskClusterCounts) {
821 throw std::runtime_error("QA with qcRunFraction only supported for taskClusterCounts");
822 }
823
824 if (mTracking) {
825 mClNative = mTracking->mIOPtrs.clustersNative;
826 }
827
828 if (InitQACreateHistograms()) {
829 return 1;
830 }
831
832 if (mConfig.enableLocalOutput) {
833 mkdir(mConfig.plotsDir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
834 }
835
836#ifdef GPUCA_O2_LIB
837 if (!mConfig.noMC) {
838 InitO2MCData(mTracking ? &mTracking->mIOPtrs : nullptr);
839 }
840#endif
841
842 if (mConfig.matchMCLabels.size()) {
843 uint32_t nFiles = mConfig.matchMCLabels.size();
844 std::vector<std::unique_ptr<TFile>> files;
845 std::vector<std::vector<std::vector<int32_t>>*> labelsBuffer(nFiles);
846 std::vector<std::vector<std::vector<int32_t>>*> effBuffer(nFiles);
847 for (uint32_t i = 0; i < nFiles; i++) {
848 files.emplace_back(std::make_unique<TFile>(mConfig.matchMCLabels[i].c_str()));
849 labelsBuffer[i] = (std::vector<std::vector<int32_t>>*)files[i]->Get("mcLabelBuffer");
850 effBuffer[i] = (std::vector<std::vector<int32_t>>*)files[i]->Get("mcEffBuffer");
851 if (labelsBuffer[i] == nullptr || effBuffer[i] == nullptr) {
852 GPUError("Error opening / reading from labels file %u/%s: %p %p", i, mConfig.matchMCLabels[i].c_str(), (void*)labelsBuffer[i], (void*)effBuffer[i]);
853 exit(1);
854 }
855 }
856
857 mGoodTracks.resize(labelsBuffer[0]->size());
858 mGoodHits.resize(labelsBuffer[0]->size());
859 for (uint32_t iEvent = 0; iEvent < labelsBuffer[0]->size(); iEvent++) {
860 std::vector<bool> labelsOK((*effBuffer[0])[iEvent].size());
861 for (uint32_t k = 0; k < (*effBuffer[0])[iEvent].size(); k++) {
862 labelsOK[k] = false;
863 for (uint32_t l = 0; l < nFiles; l++) {
864 if ((*effBuffer[0])[iEvent][k] != (*effBuffer[l])[iEvent][k]) {
865 labelsOK[k] = true;
866 break;
867 }
868 }
869 }
870 mGoodTracks[iEvent].resize((*labelsBuffer[0])[iEvent].size());
871 for (uint32_t k = 0; k < (*labelsBuffer[0])[iEvent].size(); k++) {
872 if ((*labelsBuffer[0])[iEvent][k] == MC_LABEL_INVALID) {
873 continue;
874 }
875 mGoodTracks[iEvent][k] = labelsOK[abs((*labelsBuffer[0])[iEvent][k])];
876 }
877 }
878 }
879 mQAInitialized = true;
880 return 0;
881}
882
883void GPUQA::RunQA(bool matchOnly, const std::vector<o2::tpc::TrackTPC>* tracksExternal, const std::vector<o2::MCCompLabel>* tracksExtMC, const o2::tpc::ClusterNativeAccess* clNative)
884{
885 if (!mQAInitialized) {
886 throw std::runtime_error("QA not initialized");
887 }
888 if (mTracking && mTracking->GetProcessingSettings().debugLevel >= 2) {
889 GPUInfo("Running QA - Mask %d, Efficiency %d, Resolution %d, Pulls %d, Cluster Attachment %d, Track Statistics %d, Cluster Counts %d", mQATasks, (int32_t)(mQATasks & taskTrackingEff), (int32_t)(mQATasks & taskTrackingRes), (int32_t)(mQATasks & taskTrackingResPull), (int32_t)(mQATasks & taskClusterAttach), (int32_t)(mQATasks & taskTrackStatistics), (int32_t)(mQATasks & taskClusterCounts));
890 }
891 if (!clNative && mTracking) {
892 clNative = mTracking->mIOPtrs.clustersNative;
893 }
894 mClNative = clNative;
895
896#ifdef GPUCA_TPC_GEOMETRY_O2
897 uint32_t nSimEvents = GetNMCCollissions();
898 if (mTrackMCLabelsReverse.size() < nSimEvents) {
899 mTrackMCLabelsReverse.resize(nSimEvents);
900 }
901 if (mRecTracks.size() < nSimEvents) {
902 mRecTracks.resize(nSimEvents);
903 }
904 if (mFakeTracks.size() < nSimEvents) {
905 mFakeTracks.resize(nSimEvents);
906 }
907 if (mMCParam.size() < nSimEvents) {
908 mMCParam.resize(nSimEvents);
909 }
910#endif
911
912 // Initialize Arrays
913 uint32_t nReconstructedTracks = 0;
914 if (tracksExternal) {
915#ifdef GPUCA_O2_LIB
916 nReconstructedTracks = tracksExternal->size();
917#endif
918 } else {
919 nReconstructedTracks = mTracking->mIOPtrs.nMergedTracks;
920 }
921 mTrackMCLabels.resize(nReconstructedTracks);
922 for (uint32_t iCol = 0; iCol < GetNMCCollissions(); iCol++) {
923 mTrackMCLabelsReverse[iCol].resize(GetNMCTracks(iCol));
924 mRecTracks[iCol].resize(GetNMCTracks(iCol));
925 mFakeTracks[iCol].resize(GetNMCTracks(iCol));
926 mMCParam[iCol].resize(GetNMCTracks(iCol));
927 memset(mRecTracks[iCol].data(), 0, mRecTracks[iCol].size() * sizeof(mRecTracks[iCol][0]));
928 memset(mFakeTracks[iCol].data(), 0, mFakeTracks[iCol].size() * sizeof(mFakeTracks[iCol][0]));
929 for (size_t i = 0; i < mTrackMCLabelsReverse[iCol].size(); i++) {
930 mTrackMCLabelsReverse[iCol][i] = -1;
931 }
932 }
933 if (mQATasks & taskClusterAttach && GetNMCLabels()) {
934 mClusterParam.resize(GetNMCLabels());
935 memset(mClusterParam.data(), 0, mClusterParam.size() * sizeof(mClusterParam[0]));
936 }
937 HighResTimer timer(QA_TIMING || (mTracking && mTracking->GetProcessingSettings().debugLevel >= 2));
938
939 mNEvents++;
940 if (mConfig.writeMCLabels) {
941 mcEffBuffer.resize(mNEvents);
942 mcLabelBuffer.resize(mNEvents);
943 mcEffBuffer[mNEvents - 1].resize(GetNMCTracks(0));
944 mcLabelBuffer[mNEvents - 1].resize(nReconstructedTracks);
945 }
946
947 bool mcAvail = mcPresent() || tracksExtMC;
948
949 if (mcAvail) { // Assign Track MC Labels
950 if (tracksExternal) {
951#ifdef GPUCA_O2_LIB
952 for (uint32_t i = 0; i < tracksExternal->size(); i++) {
953 mTrackMCLabels[i] = (*tracksExtMC)[i];
954 }
955#endif
956 } else {
957 tbb::parallel_for(tbb::blocked_range<uint32_t>(0, nReconstructedTracks, (QA_DEBUG == 0) ? 32 : nReconstructedTracks), [&](const tbb::blocked_range<uint32_t>& range) {
958 auto acc = GPUTPCTrkLbl<true, mcLabelI_t>(GetClusterLabels(), 1.f - mConfig.recThreshold);
959 for (auto i = range.begin(); i < range.end(); i++) {
960 acc.reset();
961 int32_t nClusters = 0;
962 const GPUTPCGMMergedTrack& track = mTracking->mIOPtrs.mergedTracks[i];
963 std::vector<mcLabel_t> labels;
964 for (uint32_t k = 0; k < track.NClusters(); k++) {
965 if (mTracking->mIOPtrs.mergedTrackHits[track.FirstClusterRef() + k].state & GPUTPCGMMergedTrackHit::flagReject) {
966 continue;
967 }
968 nClusters++;
969 uint32_t hitId = mTracking->mIOPtrs.mergedTrackHits[track.FirstClusterRef() + k].num;
970 if (hitId >= GetNMCLabels()) {
971 GPUError("Invalid hit id %u > %d (nClusters %d)", hitId, GetNMCLabels(), mTracking->mIOPtrs.clustersNative ? mTracking->mIOPtrs.clustersNative->nClustersTotal : 0);
972 throw std::runtime_error("qa error");
973 }
974 acc.addLabel(hitId);
975 for (int32_t j = 0; j < GetMCLabelNID(hitId); j++) {
976 if (GetMCLabelID(hitId, j) >= (int32_t)GetNMCTracks(GetMCLabelCol(hitId, j))) {
977 GPUError("Invalid label %d > %d (hit %d, label %d, col %d)", GetMCLabelID(hitId, j), GetNMCTracks(GetMCLabelCol(hitId, j)), hitId, j, (int32_t)GetMCLabelCol(hitId, j));
978 throw std::runtime_error("qa error");
979 }
980 if (GetMCLabelID(hitId, j) >= 0) {
981 if (QA_DEBUG >= 3 && track.OK()) {
982 GPUInfo("Track %d Cluster %u Label %d: %d (%f)", i, k, j, GetMCLabelID(hitId, j), GetMCLabelWeight(hitId, j));
983 }
984 }
985 }
986 }
987
988 float maxweight, sumweight;
989 int32_t maxcount;
990 auto maxLabel = acc.computeLabel(&maxweight, &sumweight, &maxcount);
991 mTrackMCLabels[i] = maxLabel;
992 if (QA_DEBUG && track.OK() && GetNMCTracks(maxLabel) > (uint32_t)maxLabel.getTrackID()) {
993 const mcInfo_t& mc = GetMCTrack(maxLabel);
994 GPUInfo("Track %d label %d (fake %d) weight %f clusters %d (fitted %d) (%f%% %f%%) Pt %f", i, maxLabel.getTrackID(), (int32_t)(maxLabel.isFake()), maxweight, nClusters, track.NClustersFitted(), 100.f * maxweight / sumweight, 100.f * (float)maxcount / (float)nClusters,
995 std::sqrt(mc.pX * mc.pX + mc.pY * mc.pY));
996 }
997 }
998 });
999 }
1000 if (timer.IsRunning()) {
1001 GPUInfo("QA Time: Assign Track Labels:\t\t%6.0f us", timer.GetCurrentElapsedTime(true) * 1e6);
1002 }
1003
1004 for (uint32_t i = 0; i < nReconstructedTracks; i++) {
1005 const GPUTPCGMMergedTrack* track = mTracking ? &mTracking->mIOPtrs.mergedTracks[i] : nullptr;
1006 mcLabelI_t label = mTrackMCLabels[i];
1007 if (mQATasks & taskClusterAttach) {
1008 // fill cluster attachment status
1009 if (!track->OK()) {
1010 continue;
1011 }
1012 if (!mTrackMCLabels[i].isValid()) {
1013 for (uint32_t k = 0; k < track->NClusters(); k++) {
1014 if (mTracking->mIOPtrs.mergedTrackHits[track->FirstClusterRef() + k].state & GPUTPCGMMergedTrackHit::flagReject) {
1015 continue;
1016 }
1017 mClusterParam[mTracking->mIOPtrs.mergedTrackHits[track->FirstClusterRef() + k].num].fakeAttached++;
1018 }
1019 continue;
1020 }
1021 if (mMCTrackMin == -1 || (label.getTrackID() >= mMCTrackMin && label.getTrackID() < mMCTrackMax)) {
1022 for (uint32_t k = 0; k < track->NClusters(); k++) {
1023 if (mTracking->mIOPtrs.mergedTrackHits[track->FirstClusterRef() + k].state & GPUTPCGMMergedTrackHit::flagReject) {
1024 continue;
1025 }
1026 int32_t hitId = mTracking->mIOPtrs.mergedTrackHits[track->FirstClusterRef() + k].num;
1027 bool correct = false;
1028 for (int32_t j = 0; j < GetMCLabelNID(hitId); j++) {
1029 if (label == GetMCLabel(hitId, j)) {
1030 correct = true;
1031 break;
1032 }
1033 }
1034 if (correct) {
1035 mClusterParam[hitId].attached++;
1036 } else {
1037 mClusterParam[hitId].fakeAttached++;
1038 }
1039 }
1040 }
1041 }
1042
1043 if (mTrackMCLabels[i].isFake()) {
1044 (GetMCTrackObj(mFakeTracks, label))++;
1045 } else if (tracksExternal || !track->MergedLooper()) {
1046 GetMCTrackObj(mRecTracks, label)++;
1047 if (mMCTrackMin == -1 || (label.getTrackID() >= mMCTrackMin && label.getTrackID() < mMCTrackMax)) {
1048 int32_t& revLabel = GetMCTrackObj(mTrackMCLabelsReverse, label);
1049 if (tracksExternal) {
1050#ifdef GPUCA_O2_LIB
1051 if (revLabel == -1 || fabsf((*tracksExternal)[i].getZ()) < fabsf((*tracksExternal)[revLabel].getZ())) {
1052 revLabel = i;
1053 }
1054#endif
1055 } else {
1056 const auto* trks = mTracking->mIOPtrs.mergedTracks;
1057 bool comp;
1058 if (revLabel == -1) {
1059 comp = true;
1060 } else {
1061 float shift1 = mTracking->GetTPCTransformHelper()->getCorrMap()->convDeltaTimeToDeltaZinTimeFrame(trks[i].CSide() * GPUChainTracking::NSECTORS / 2, trks[i].GetParam().GetTOffset());
1062 float shift2 = mTracking->GetTPCTransformHelper()->getCorrMap()->convDeltaTimeToDeltaZinTimeFrame(trks[revLabel].CSide() * GPUChainTracking::NSECTORS / 2, trks[revLabel].GetParam().GetTOffset());
1063 comp = fabsf(trks[i].GetParam().GetZ() + shift1) < fabsf(trks[revLabel].GetParam().GetZ() + shift2);
1064 }
1065 if (revLabel == -1 || !trks[revLabel].OK() || (trks[i].OK() && comp)) {
1066 revLabel = i;
1067 }
1068 }
1069 }
1070 }
1071 }
1072 if ((mQATasks & taskClusterAttach)) {
1073 std::vector<uint8_t> lowestPadRow(mTracking->mIOPtrs.nMergedTracks);
1074 // fill cluster adjacent status
1075 if (mTracking->mIOPtrs.mergedTrackHitAttachment) {
1076 for (uint32_t i = 0; i < GetNMCLabels(); i++) {
1077 if (mClusterParam[i].attached == 0 && mClusterParam[i].fakeAttached == 0) {
1078 int32_t attach = mTracking->mIOPtrs.mergedTrackHitAttachment[i];
1080 int32_t track = attach & gputpcgmmergertypes::attachTrackMask;
1081 mcLabelI_t trackL = mTrackMCLabels[track];
1082 bool fake = true;
1083 for (int32_t j = 0; j < GetMCLabelNID(i); j++) {
1084 // GPUInfo("Attach %x Track %d / %d:%d", attach, track, j, GetMCLabelID(i, j));
1085 if (trackL == GetMCLabel(i, j)) {
1086 fake = false;
1087 break;
1088 }
1089 }
1090 if (fake) {
1091 mClusterParam[i].fakeAdjacent++;
1092 } else {
1093 mClusterParam[i].adjacent++;
1094 }
1095 }
1096 }
1097 }
1098 }
1099 if (mTracking->mIOPtrs.nMergedTracks && mTracking->mIOPtrs.clustersNative) {
1100 std::fill(lowestPadRow.begin(), lowestPadRow.end(), 255);
1101 for (uint32_t iSector = 0; iSector < GPUCA_NSECTORS; iSector++) {
1102 for (uint32_t iRow = 0; iRow < GPUCA_ROW_COUNT; iRow++) {
1103 for (uint32_t iCl = 0; iCl < mTracking->mIOPtrs.clustersNative->nClusters[iSector][iRow]; iCl++) {
1104 int32_t i = mTracking->mIOPtrs.clustersNative->clusterOffset[iSector][iRow] + iCl;
1105 for (int32_t j = 0; j < GetMCLabelNID(i); j++) {
1106 uint32_t trackId = GetMCTrackObj(mTrackMCLabelsReverse, GetMCLabel(i, j));
1107 if (trackId < lowestPadRow.size() && lowestPadRow[trackId] > iRow) {
1108 lowestPadRow[trackId] = iRow;
1109 }
1110 }
1111 }
1112 }
1113 }
1114 for (uint32_t i = 0; i < mTracking->mIOPtrs.nMergedTracks; i++) {
1115 const auto& trk = mTracking->mIOPtrs.mergedTracks[i];
1116 if (trk.OK() && lowestPadRow[i] != 255 && trk.NClustersFitted() > 70 && CAMath::Abs(trk.GetParam().GetQPt()) < 0.5) {
1117 int32_t lowestRow = CAMath::Min(mTracking->mIOPtrs.mergedTrackHits[trk.FirstClusterRef()].row, mTracking->mIOPtrs.mergedTrackHits[trk.FirstClusterRef() + trk.NClusters() - 1].row);
1118 mPadRow[0]->Fill(lowestPadRow[i], lowestRow, 1.f);
1119 mPadRow[1]->Fill(CAMath::ATan2(trk.GetParam().GetY(), trk.GetParam().GetX()), lowestRow, 1.f);
1120 if (lowestPadRow[i] == 0 && lowestRow != 0) {
1121 mPadRow[2]->Fill(CAMath::ATan2(trk.GetParam().GetY(), trk.GetParam().GetX()), lowestRow, 1.f);
1122 }
1123 }
1124 }
1125 }
1126 }
1127
1128 if (mConfig.matchMCLabels.size()) {
1129 mGoodHits[mNEvents - 1].resize(GetNMCLabels());
1130 std::vector<bool> allowMCLabels(GetNMCTracks(0));
1131 for (uint32_t k = 0; k < GetNMCTracks(0); k++) {
1132 allowMCLabels[k] = false;
1133 }
1134 for (uint32_t i = 0; i < nReconstructedTracks; i++) {
1135 if (!mGoodTracks[mNEvents - 1][i]) {
1136 continue;
1137 }
1138 if (mConfig.matchDisplayMinPt > 0) {
1139 if (!mTrackMCLabels[i].isValid()) {
1140 continue;
1141 }
1142 const mcInfo_t& info = GetMCTrack(mTrackMCLabels[i]);
1143 if (info.pX * info.pX + info.pY * info.pY < mConfig.matchDisplayMinPt * mConfig.matchDisplayMinPt) {
1144 continue;
1145 }
1146 }
1147
1148 const GPUTPCGMMergedTrack& track = mTracking->mIOPtrs.mergedTracks[i];
1149 for (uint32_t j = 0; j < track.NClusters(); j++) {
1150 int32_t hitId = mTracking->mIOPtrs.mergedTrackHits[track.FirstClusterRef() + j].num;
1151 if (GetMCLabelNID(hitId)) {
1152 int32_t mcID = GetMCLabelID(hitId, 0);
1153 if (mcID >= 0) {
1154 allowMCLabels[mcID] = true;
1155 }
1156 }
1157 }
1158 }
1159 for (uint32_t i = 0; i < GetNMCLabels(); i++) {
1160 for (int32_t j = 0; j < GetMCLabelNID(i); j++) {
1161 int32_t mcID = GetMCLabelID(i, j);
1162 if (mcID >= 0 && allowMCLabels[mcID]) {
1163 mGoodHits[mNEvents - 1][i] = true;
1164 }
1165 }
1166 }
1167 }
1168 if (timer.IsRunning()) {
1169 GPUInfo("QA Time: Cluster attach status:\t\t%6.0f us", timer.GetCurrentElapsedTime(true) * 1e6);
1170 }
1171
1172 if (matchOnly) {
1173 return;
1174 }
1175
1176 // Recompute fNWeightCls (might have changed after merging events into timeframes)
1177 for (uint32_t iCol = 0; iCol < GetNMCCollissions(); iCol++) {
1178 for (uint32_t i = 0; i < GetNMCTracks(iCol); i++) {
1179 mMCParam[iCol][i].nWeightCls = 0.;
1180 }
1181 }
1182 for (uint32_t i = 0; i < GetNMCLabels(); i++) {
1183 float weightTotal = 0.f;
1184 for (int32_t j = 0; j < GetMCLabelNID(i); j++) {
1185 if (GetMCLabelID(i, j) >= 0) {
1186 weightTotal += GetMCLabelWeight(i, j);
1187 }
1188 }
1189 for (int32_t j = 0; j < GetMCLabelNID(i); j++) {
1190 if (GetMCLabelID(i, j) >= 0) {
1191 GetMCTrackObj(mMCParam, GetMCLabel(i, j)).nWeightCls += GetMCLabelWeight(i, j) / weightTotal;
1192 }
1193 }
1194 }
1195 if (timer.IsRunning()) {
1196 GPUInfo("QA Time: Compute cluster label weights:\t%6.0f us", timer.GetCurrentElapsedTime(true) * 1e6);
1197 }
1198
1199 // Compute MC Track Parameters for MC Tracks
1200 tbb::parallel_for<uint32_t>(0, GetNMCCollissions(), [&](auto iCol) {
1201 for (uint32_t i = 0; i < GetNMCTracks(iCol); i++) {
1202 const mcInfo_t& info = GetMCTrack(i, iCol);
1203 additionalMCParameters& mc2 = mMCParam[iCol][i];
1204 mc2.pt = std::sqrt(info.pX * info.pX + info.pY * info.pY);
1205 mc2.phi = M_PI + std::atan2(-info.pY, -info.pX);
1206 float p = info.pX * info.pX + info.pY * info.pY + info.pZ * info.pZ;
1207 if (p < 1e-18) {
1208 mc2.theta = mc2.eta = 0.f;
1209 } else {
1210 mc2.theta = info.pZ == 0 ? (M_PI / 2) : (std::acos(info.pZ / std::sqrt(p)));
1211 mc2.eta = -std::log(std::tan(0.5 * mc2.theta));
1212 }
1213 if (mConfig.writeMCLabels) {
1214 std::vector<int32_t>& effBuffer = mcEffBuffer[mNEvents - 1];
1215 effBuffer[i] = mRecTracks[iCol][i] * 1000 + mFakeTracks[iCol][i];
1216 }
1217 } // clang-format off
1218 }, tbb::simple_partitioner()); // clang-format on
1219 if (timer.IsRunning()) {
1220 GPUInfo("QA Time: Compute track mc parameters:\t%6.0f us", timer.GetCurrentElapsedTime(true) * 1e6);
1221 }
1222
1223 // Fill Efficiency Histograms
1224 if (mQATasks & taskTrackingEff) {
1225 for (uint32_t iCol = 0; iCol < GetNMCCollissions(); iCol++) {
1226 for (uint32_t i = 0; i < GetNMCTracks(iCol); i++) {
1227 if ((mMCTrackMin != -1 && (int32_t)i < mMCTrackMin) || (mMCTrackMax != -1 && (int32_t)i >= mMCTrackMax)) {
1228 continue;
1229 }
1230 const mcInfo_t& info = GetMCTrack(i, iCol);
1231 const additionalMCParameters& mc2 = mMCParam[iCol][i];
1232 if (mc2.nWeightCls == 0.f) {
1233 continue;
1234 }
1235 const float& mcpt = mc2.pt;
1236 const float& mcphi = mc2.phi;
1237 const float& mceta = mc2.eta;
1238
1239 if (info.primDaughters) {
1240 continue;
1241 }
1242 if (mc2.nWeightCls < mConfig.minNClEff) {
1243 continue;
1244 }
1245 int32_t findable = mc2.nWeightCls >= mConfig.minNClFindable;
1246 if (info.pid < 0) {
1247 continue;
1248 }
1249 if (info.charge == 0.f) {
1250 continue;
1251 }
1252 if (mConfig.filterCharge && info.charge * mConfig.filterCharge < 0) {
1253 continue;
1254 }
1255 if (mConfig.filterPID >= 0 && info.pid != mConfig.filterPID) {
1256 continue;
1257 }
1258
1259 if (fabsf(mceta) > ETA_MAX || mcpt < PT_MIN || mcpt > PT_MAX) {
1260 continue;
1261 }
1262
1263 float alpha = std::atan2(info.y, info.x);
1264 alpha /= M_PI / 9.f;
1265 alpha = std::floor(alpha);
1266 alpha *= M_PI / 9.f;
1267 alpha += M_PI / 18.f;
1268
1269 float c = std::cos(alpha);
1270 float s = std::sin(alpha);
1271 float localY = -info.x * s + info.y * c;
1272
1273 if (mConfig.dumpToROOT) {
1274 static auto effdump = GPUROOTDump<TNtuple>::getNew("eff", "alpha:x:y:z:mcphi:mceta:mcpt:rec:fake:findable:prim:ncls");
1275 float localX = info.x * c + info.y * s;
1276 effdump.Fill(alpha, localX, localY, info.z, mcphi, mceta, mcpt, mRecTracks[iCol][i], mFakeTracks[iCol][i], findable, info.prim, mc2.nWeightCls);
1277 }
1278
1279 for (int32_t j = 0; j < 6; j++) {
1280 if (j == 3 || j == 4) {
1281 continue;
1282 }
1283 for (int32_t k = 0; k < 2; k++) {
1284 if (k == 0 && findable == 0) {
1285 continue;
1286 }
1287
1288 int32_t val = (j == 0) ? (mRecTracks[iCol][i] ? 1 : 0) : (j == 1) ? (mRecTracks[iCol][i] ? mRecTracks[iCol][i] - 1 : 0) : (j == 2) ? mFakeTracks[iCol][i] : 1;
1289 if (val == 0) {
1290 continue;
1291 }
1292
1293 for (int32_t l = 0; l < 5; l++) {
1294 if (info.prim && mcpt < PT_MIN_PRIM) {
1295 continue;
1296 }
1297 if (l != 3 && fabsf(mceta) > ETA_MAX2) {
1298 continue;
1299 }
1300 if (l < 4 && mcpt < 1.f / mConfig.qpt) {
1301 continue;
1302 }
1303
1304 float pos = l == 0 ? localY : l == 1 ? info.z : l == 2 ? mcphi : l == 3 ? mceta : mcpt;
1305
1306 mEff[j][k][!info.prim][l]->Fill(pos, val);
1307 }
1308 }
1309 }
1310 }
1311 }
1312 if (timer.IsRunning()) {
1313 GPUInfo("QA Time: Fill efficiency histograms:\t%6.0f us", timer.GetCurrentElapsedTime(true) * 1e6);
1314 }
1315 }
1316
1317 // Fill Resolution Histograms
1318 if (mQATasks & (taskTrackingRes | taskTrackingResPull)) {
1319 GPUTPCGMPropagator prop;
1320 prop.SetMaxSinPhi(.999);
1321 prop.SetMaterialTPC();
1322 prop.SetPolynomialField(&mParam->polynomialField);
1323
1324 for (uint32_t i = 0; i < mTrackMCLabels.size(); i++) {
1325 if (mConfig.writeMCLabels) {
1326 std::vector<int32_t>& labelBuffer = mcLabelBuffer[mNEvents - 1];
1327 labelBuffer[i] = mTrackMCLabels[i].getTrackID();
1328 }
1329 if (mTrackMCLabels[i].isFake()) {
1330 continue;
1331 }
1332 const mcInfo_t& mc1 = GetMCTrack(mTrackMCLabels[i]);
1333 const additionalMCParameters& mc2 = GetMCTrackObj(mMCParam, mTrackMCLabels[i]);
1334
1335 if (mc1.primDaughters) {
1336 continue;
1337 }
1338 if (!tracksExternal) {
1339 if (!mTracking->mIOPtrs.mergedTracks[i].OK()) {
1340 continue;
1341 }
1342 if (mTracking->mIOPtrs.mergedTracks[i].MergedLooper()) {
1343 continue;
1344 }
1345 }
1346 if ((mMCTrackMin != -1 && mTrackMCLabels[i].getTrackID() < mMCTrackMin) || (mMCTrackMax != -1 && mTrackMCLabels[i].getTrackID() >= mMCTrackMax)) {
1347 continue;
1348 }
1349 if (fabsf(mc2.eta) > ETA_MAX || mc2.pt < PT_MIN || mc2.pt > PT_MAX) {
1350 continue;
1351 }
1352 if (mc1.charge == 0.f) {
1353 continue;
1354 }
1355 if (mc1.pid < 0) {
1356 continue;
1357 }
1358 if (mc1.t0 == -100.f) {
1359 continue;
1360 }
1361 if (mConfig.filterCharge && mc1.charge * mConfig.filterCharge < 0) {
1362 continue;
1363 }
1364 if (mConfig.filterPID >= 0 && mc1.pid != mConfig.filterPID) {
1365 continue;
1366 }
1367 if (mc2.nWeightCls < mConfig.minNClRes) {
1368 continue;
1369 }
1370 if (mConfig.resPrimaries == 1 && !mc1.prim) {
1371 continue;
1372 } else if (mConfig.resPrimaries == 2 && mc1.prim) {
1373 continue;
1374 }
1375 if (GetMCTrackObj(mTrackMCLabelsReverse, mTrackMCLabels[i]) != (int32_t)i) {
1376 continue;
1377 }
1378
1380 float alpha = 0.f;
1381 int32_t side;
1382 if (tracksExternal) {
1383#ifdef GPUCA_O2_LIB
1384 for (int32_t k = 0; k < 5; k++) {
1385 param.Par()[k] = (*tracksExternal)[i].getParams()[k];
1386 }
1387 for (int32_t k = 0; k < 15; k++) {
1388 param.Cov()[k] = (*tracksExternal)[i].getCov()[k];
1389 }
1390 param.X() = (*tracksExternal)[i].getX();
1391 param.TOffset() = (*tracksExternal)[i].getTime0();
1392 alpha = (*tracksExternal)[i].getAlpha();
1393 side = (*tracksExternal)[i].hasBothSidesClusters() ? 2 : ((*tracksExternal)[i].hasCSideClusters() ? 1 : 0);
1394#endif
1395 } else {
1396 param = mTracking->mIOPtrs.mergedTracks[i].GetParam();
1397 alpha = mTracking->mIOPtrs.mergedTracks[i].GetAlpha();
1398 side = mTracking->mIOPtrs.mergedTracks[i].CCE() ? 2 : (mTracking->mIOPtrs.mergedTracks[i].CSide() ? 1 : 0);
1399 }
1400
1401 float mclocal[4]; // Rotated x,y,Px,Py mc-coordinates - the MC data should be rotated since the track is propagated best along x
1402 float c = std::cos(alpha);
1403 float s = std::sin(alpha);
1404 float x = mc1.x;
1405 float y = mc1.y;
1406 mclocal[0] = x * c + y * s;
1407 mclocal[1] = -x * s + y * c;
1408 float px = mc1.pX;
1409 float py = mc1.pY;
1410 mclocal[2] = px * c + py * s;
1411 mclocal[3] = -px * s + py * c;
1412
1413 if (mclocal[0] < TRACK_EXPECTED_REFERENCE_X - 3) {
1414 continue;
1415 }
1416 if (mclocal[0] > param.GetX() + 20) {
1417 continue;
1418 }
1419 if (param.GetX() > mConfig.maxResX) {
1420 continue;
1421 }
1422
1423 auto getdz = [this, &param, &mc1, &side, tracksExternal]() {
1424 if (tracksExternal) {
1425 return param.GetZ();
1426 }
1427 if (!mParam->continuousMaxTimeBin) {
1428 return param.GetZ() - mc1.z;
1429 }
1430 float shift = side == 2 ? 0 : mTracking->GetTPCTransformHelper()->getCorrMap()->convDeltaTimeToDeltaZinTimeFrame(side * GPUChainTracking::NSECTORS / 2, param.GetTOffset() - mc1.t0);
1431 return param.GetZ() + shift - mc1.z;
1432 };
1433
1434 prop.SetTrack(&param, alpha);
1435 bool inFlyDirection = 0;
1436 if (mConfig.strict) {
1437 const float dx = param.X() - std::max<float>(mclocal[0], TRACK_EXPECTED_REFERENCE_X_DEFAULT); // Limit distance check
1438 const float dy = param.Y() - mclocal[1];
1439 const float dz = getdz();
1440 if (dx * dx + dy * dy + dz * dz > 5.f * 5.f) {
1441 continue;
1442 }
1443 }
1444
1445 if (prop.PropagateToXAlpha(mclocal[0], alpha, inFlyDirection)) {
1446 continue;
1447 }
1448 if (fabsf(param.Y() - mclocal[1]) > (mConfig.strict ? 1.f : 4.f) || fabsf(getdz()) > (mConfig.strict ? 1.f : 4.f)) {
1449 continue;
1450 }
1451 float charge = mc1.charge > 0 ? 1.f : -1.f;
1452
1453 float deltaY = param.GetY() - mclocal[1];
1454 float deltaZ = getdz();
1455 float deltaPhiNative = param.GetSinPhi() - mclocal[3] / mc2.pt;
1456 float deltaPhi = std::asin(param.GetSinPhi()) - std::atan2(mclocal[3], mclocal[2]);
1457 float deltaLambdaNative = param.GetDzDs() - mc1.pZ / mc2.pt;
1458 float deltaLambda = std::atan(param.GetDzDs()) - std::atan2(mc1.pZ, mc2.pt);
1459 float deltaPtNative = (param.GetQPt() - charge / mc2.pt) * charge;
1460 float deltaPt = (fabsf(1.f / param.GetQPt()) - mc2.pt) / mc2.pt;
1461
1462 float paramval[5] = {mclocal[1], mc1.z, mc2.phi, mc2.eta, mc2.pt};
1463 float resval[5] = {deltaY, deltaZ, mConfig.nativeFitResolutions ? deltaPhiNative : deltaPhi, mConfig.nativeFitResolutions ? deltaLambdaNative : deltaLambda, mConfig.nativeFitResolutions ? deltaPtNative : deltaPt};
1464 float pullval[5] = {deltaY / std::sqrt(param.GetErr2Y()), deltaZ / std::sqrt(param.GetErr2Z()), deltaPhiNative / std::sqrt(param.GetErr2SinPhi()), deltaLambdaNative / std::sqrt(param.GetErr2DzDs()), deltaPtNative / std::sqrt(param.GetErr2QPt())};
1465
1466 for (int32_t j = 0; j < 5; j++) {
1467 for (int32_t k = 0; k < 5; k++) {
1468 if (k != 3 && fabsf(mc2.eta) > ETA_MAX2) {
1469 continue;
1470 }
1471 if (k < 4 && mc2.pt < 1.f / mConfig.qpt) {
1472 continue;
1473 }
1474 if (mQATasks & taskTrackingRes) {
1475 mRes2[j][k]->Fill(resval[j], paramval[k]);
1476 }
1477 if (mQATasks & taskTrackingResPull) {
1478 mPull2[j][k]->Fill(pullval[j], paramval[k]);
1479 }
1480 }
1481 }
1482 }
1483 if (timer.IsRunning()) {
1484 GPUInfo("QA Time: Fill resolution histograms:\t%6.0f us", timer.GetCurrentElapsedTime(true) * 1e6);
1485 }
1486 }
1487
1488 if (mQATasks & taskClusterAttach) {
1489 // Fill cluster histograms
1490 for (uint32_t iTrk = 0; iTrk < nReconstructedTracks; iTrk++) {
1491 const GPUTPCGMMergedTrack& track = mTracking->mIOPtrs.mergedTracks[iTrk];
1492 if (!track.OK()) {
1493 continue;
1494 }
1495 if (!mTrackMCLabels[iTrk].isValid()) {
1496 for (uint32_t k = 0; k < track.NClusters(); k++) {
1497 if (mTracking->mIOPtrs.mergedTrackHits[track.FirstClusterRef() + k].state & GPUTPCGMMergedTrackHit::flagReject) {
1498 continue;
1499 }
1500 int32_t hitId = mTracking->mIOPtrs.mergedTrackHits[track.FirstClusterRef() + k].num;
1501 float totalWeight = 0.;
1502 for (int32_t j = 0; j < GetMCLabelNID(hitId); j++) {
1503 if (GetMCLabelID(hitId, j) >= 0 && GetMCTrackObj(mMCParam, GetMCLabel(hitId, j)).pt > 1.f / mTracking->GetParam().rec.maxTrackQPtB5) {
1504 totalWeight += GetMCLabelWeight(hitId, j);
1505 }
1506 }
1507 int32_t attach = mTracking->mIOPtrs.mergedTrackHitAttachment[hitId];
1508 const auto& r = checkClusterState<false>(attach);
1509 if (totalWeight > 0) {
1510 float weight = 1.f / (totalWeight * (mClusterParam[hitId].attached + mClusterParam[hitId].fakeAttached));
1511 for (int32_t j = 0; j < GetMCLabelNID(hitId); j++) {
1512 mcLabelI_t label = GetMCLabel(hitId, j);
1513 if (!label.isFake() && GetMCTrackObj(mMCParam, label).pt > 1.f / mTracking->GetParam().rec.maxTrackQPtB5) {
1514 float pt = GetMCTrackObj(mMCParam, label).pt;
1515 if (pt < PT_MIN_CLUST) {
1516 pt = PT_MIN_CLUST;
1517 }
1518 mClusters[CL_fake]->Fill(pt, GetMCLabelWeight(hitId, j) * weight);
1519 mClusters[CL_att_adj]->Fill(pt, GetMCLabelWeight(hitId, j) * weight);
1520 if (GetMCTrackObj(mRecTracks, label)) {
1521 mClusters[CL_tracks]->Fill(pt, GetMCLabelWeight(hitId, j) * weight);
1522 }
1523 mClusters[CL_all]->Fill(pt, GetMCLabelWeight(hitId, j) * weight);
1524 if (r.protect || r.physics) {
1525 mClusters[CL_prot]->Fill(pt, GetMCLabelWeight(hitId, j) * weight);
1526 }
1527 if (r.physics) {
1528 mClusters[CL_physics]->Fill(pt, GetMCLabelWeight(hitId, j) * weight);
1529 }
1530 }
1531 }
1532 } else {
1533 float weight = 1.f / (mClusterParam[hitId].attached + mClusterParam[hitId].fakeAttached);
1534 mClusters[CL_fake]->Fill(0.f, weight);
1535 mClusters[CL_att_adj]->Fill(0.f, weight);
1536 mClusters[CL_all]->Fill(0.f, weight);
1537 mClusterCounts.nUnaccessible += weight;
1538 if (r.protect || r.physics) {
1539 mClusters[CL_prot]->Fill(0.f, weight);
1540 }
1541 if (r.physics) {
1542 mClusters[CL_physics]->Fill(0.f, weight);
1543 }
1544 }
1545 }
1546 continue;
1547 }
1548 mcLabelI_t label = mTrackMCLabels[iTrk];
1549 if (mMCTrackMin != -1 && (label.getTrackID() < mMCTrackMin || label.getTrackID() >= mMCTrackMax)) {
1550 continue;
1551 }
1552 for (uint32_t k = 0; k < track.NClusters(); k++) {
1553 if (mTracking->mIOPtrs.mergedTrackHits[track.FirstClusterRef() + k].state & GPUTPCGMMergedTrackHit::flagReject) {
1554 continue;
1555 }
1556 int32_t hitId = mTracking->mIOPtrs.mergedTrackHits[track.FirstClusterRef() + k].num;
1557 float pt = GetMCTrackObj(mMCParam, label).pt;
1558 if (pt < PT_MIN_CLUST) {
1559 pt = PT_MIN_CLUST;
1560 }
1561 float weight = 1.f / (mClusterParam[hitId].attached + mClusterParam[hitId].fakeAttached);
1562 bool correct = false;
1563 for (int32_t j = 0; j < GetMCLabelNID(hitId); j++) {
1564 if (label == GetMCLabel(hitId, j)) {
1565 correct = true;
1566 break;
1567 }
1568 }
1569 if (correct) {
1570 mClusters[CL_attached]->Fill(pt, weight);
1571 mClusters[CL_tracks]->Fill(pt, weight);
1572 } else {
1573 mClusters[CL_fake]->Fill(pt, weight);
1574 }
1575 mClusters[CL_att_adj]->Fill(pt, weight);
1576 mClusters[CL_all]->Fill(pt, weight);
1577 int32_t attach = mTracking->mIOPtrs.mergedTrackHitAttachment[hitId];
1578 const auto& r = checkClusterState<false>(attach);
1579 if (r.protect || r.physics) {
1580 mClusters[CL_prot]->Fill(pt, weight);
1581 }
1582 if (r.physics) {
1583 mClusters[CL_physics]->Fill(pt, weight);
1584 }
1585 }
1586 }
1587 for (uint32_t i = 0; i < GetNMCLabels(); i++) {
1588 if ((mMCTrackMin != -1 && GetMCLabelID(i, 0) < mMCTrackMin) || (mMCTrackMax != -1 && GetMCLabelID(i, 0) >= mMCTrackMax)) {
1589 continue;
1590 }
1591 if (mClusterParam[i].attached || mClusterParam[i].fakeAttached) {
1592 continue;
1593 }
1594 int32_t attach = mTracking->mIOPtrs.mergedTrackHitAttachment[i];
1595 const auto& r = checkClusterState<false>(attach);
1596 if (mClusterParam[i].adjacent) {
1597 int32_t label = mTracking->mIOPtrs.mergedTrackHitAttachment[i] & gputpcgmmergertypes::attachTrackMask;
1598 if (!mTrackMCLabels[label].isValid()) {
1599 float totalWeight = 0.;
1600 for (int32_t j = 0; j < GetMCLabelNID(i); j++) {
1601 mcLabelI_t labelT = GetMCLabel(i, j);
1602 if (!labelT.isFake() && GetMCTrackObj(mMCParam, labelT).pt > 1.f / mTracking->GetParam().rec.maxTrackQPtB5) {
1603 totalWeight += GetMCLabelWeight(i, j);
1604 }
1605 }
1606 float weight = 1.f / totalWeight;
1607 if (totalWeight > 0) {
1608 for (int32_t j = 0; j < GetMCLabelNID(i); j++) {
1609 mcLabelI_t labelT = GetMCLabel(i, j);
1610 if (!labelT.isFake() && GetMCTrackObj(mMCParam, labelT).pt > 1.f / mTracking->GetParam().rec.maxTrackQPtB5) {
1611 float pt = GetMCTrackObj(mMCParam, labelT).pt;
1612 if (pt < PT_MIN_CLUST) {
1613 pt = PT_MIN_CLUST;
1614 }
1615 if (GetMCTrackObj(mRecTracks, labelT)) {
1616 mClusters[CL_tracks]->Fill(pt, GetMCLabelWeight(i, j) * weight);
1617 }
1618 mClusters[CL_att_adj]->Fill(pt, GetMCLabelWeight(i, j) * weight);
1619 mClusters[CL_fakeAdj]->Fill(pt, GetMCLabelWeight(i, j) * weight);
1620 mClusters[CL_all]->Fill(pt, GetMCLabelWeight(i, j) * weight);
1621 if (r.protect || r.physics) {
1622 mClusters[CL_prot]->Fill(pt, GetMCLabelWeight(i, j) * weight);
1623 }
1624 if (r.physics) {
1625 mClusters[CL_physics]->Fill(pt, GetMCLabelWeight(i, j) * weight);
1626 }
1627 }
1628 }
1629 } else {
1630 mClusters[CL_att_adj]->Fill(0.f, 1.f);
1631 mClusters[CL_fakeAdj]->Fill(0.f, 1.f);
1632 mClusters[CL_all]->Fill(0.f, 1.f);
1633 mClusterCounts.nUnaccessible++;
1634 if (r.protect || r.physics) {
1635 mClusters[CL_prot]->Fill(0.f, 1.f);
1636 }
1637 if (r.physics) {
1638 mClusters[CL_physics]->Fill(0.f, 1.f);
1639 }
1640 }
1641 } else {
1642 float pt = GetMCTrackObj(mMCParam, mTrackMCLabels[label]).pt;
1643 if (pt < PT_MIN_CLUST) {
1644 pt = PT_MIN_CLUST;
1645 }
1646 mClusters[CL_att_adj]->Fill(pt, 1.f);
1647 mClusters[CL_tracks]->Fill(pt, 1.f);
1648 mClusters[CL_all]->Fill(pt, 1.f);
1649 if (r.protect || r.physics) {
1650 mClusters[CL_prot]->Fill(pt, 1.f);
1651 }
1652 if (r.physics) {
1653 mClusters[CL_physics]->Fill(pt, 1.f);
1654 }
1655 }
1656 } else {
1657 float totalWeight = 0.;
1658 for (int32_t j = 0; j < GetMCLabelNID(i); j++) {
1659 mcLabelI_t labelT = GetMCLabel(i, j);
1660 if (!labelT.isFake() && GetMCTrackObj(mMCParam, labelT).pt > 1.f / mTracking->GetParam().rec.maxTrackQPtB5) {
1661 totalWeight += GetMCLabelWeight(i, j);
1662 }
1663 }
1664 if (totalWeight > 0) {
1665 for (int32_t j = 0; j < GetMCLabelNID(i); j++) {
1666 mcLabelI_t label = GetMCLabel(i, j);
1667 if (!label.isFake() && GetMCTrackObj(mMCParam, label).pt > 1.f / mTracking->GetParam().rec.maxTrackQPtB5) {
1668 float pt = GetMCTrackObj(mMCParam, label).pt;
1669 if (pt < PT_MIN_CLUST) {
1670 pt = PT_MIN_CLUST;
1671 }
1672 float weight = GetMCLabelWeight(i, j) / totalWeight;
1673 if (mClusterParam[i].fakeAdjacent) {
1674 mClusters[CL_fakeAdj]->Fill(pt, weight);
1675 }
1676 if (mClusterParam[i].fakeAdjacent) {
1677 mClusters[CL_att_adj]->Fill(pt, weight);
1678 }
1679 if (GetMCTrackObj(mRecTracks, label)) {
1680 mClusters[CL_tracks]->Fill(pt, weight);
1681 }
1682 mClusters[CL_all]->Fill(pt, weight);
1683 if (r.protect || r.physics) {
1684 mClusters[CL_prot]->Fill(pt, weight);
1685 }
1686 if (r.physics) {
1687 mClusters[CL_physics]->Fill(pt, weight);
1688 }
1689 }
1690 }
1691 } else {
1692 if (mClusterParam[i].fakeAdjacent) {
1693 mClusters[CL_fakeAdj]->Fill(0.f, 1.f);
1694 }
1695 if (mClusterParam[i].fakeAdjacent) {
1696 mClusters[CL_att_adj]->Fill(0.f, 1.f);
1697 }
1698 mClusters[CL_all]->Fill(0.f, 1.f);
1699 mClusterCounts.nUnaccessible++;
1700 if (r.protect || r.physics) {
1701 mClusters[CL_prot]->Fill(0.f, 1.f);
1702 }
1703 if (r.physics) {
1704 mClusters[CL_physics]->Fill(0.f, 1.f);
1705 }
1706 }
1707 }
1708 }
1709
1710 if (timer.IsRunning()) {
1711 GPUInfo("QA Time: Fill cluster histograms:\t%6.0f us", timer.GetCurrentElapsedTime(true) * 1e6);
1712 }
1713 }
1714 } else if (!mConfig.inputHistogramsOnly && !mConfig.noMC && (mQATasks & (taskTrackingEff | taskTrackingRes | taskTrackingResPull | taskClusterAttach))) {
1715 GPUWarning("No MC information available, only running partial TPC QA!");
1716 } // mcAvail
1717
1718 if (mQATasks & taskTrackStatistics) {
1719 // Fill track statistic histograms
1720 std::vector<std::array<float, 3>> clusterAttachCounts;
1721 if (mcAvail) {
1722 clusterAttachCounts.resize(GetNMCLabels(), {0.f, 0.f});
1723 }
1724 for (uint32_t i = 0; i < nReconstructedTracks; i++) {
1725 const GPUTPCGMMergedTrack& track = mTracking->mIOPtrs.mergedTracks[i];
1726 if (!track.OK()) {
1727 continue;
1728 }
1729 mTracks->Fill(1.f / fabsf(track.GetParam().GetQPt()));
1730 mNCl[0]->Fill(track.NClustersFitted());
1731 uint32_t nClCorrected = 0;
1732 const auto& trackClusters = mTracking->mIOPtrs.mergedTrackHits;
1733 uint32_t jNext = 0;
1734 for (uint32_t j = 0; j < track.NClusters(); j = jNext) {
1735 uint32_t rowClCount = !(trackClusters[track.FirstClusterRef() + j].state & GPUTPCGMMergedTrackHit::flagReject);
1736 for (jNext = j + 1; j < track.NClusters(); jNext++) {
1737 if (trackClusters[track.FirstClusterRef() + j].sector != trackClusters[track.FirstClusterRef() + jNext].sector || trackClusters[track.FirstClusterRef() + j].row != trackClusters[track.FirstClusterRef() + jNext].row) {
1738 break;
1739 }
1740 rowClCount += !(trackClusters[track.FirstClusterRef() + jNext].state & GPUTPCGMMergedTrackHit::flagReject);
1741 }
1742 if (!track.MergedLooper() && rowClCount) {
1743 nClCorrected++;
1744 }
1745 if (mcAvail && rowClCount) {
1746 for (uint32_t k = j; k < jNext; k++) {
1747 const auto& cl = trackClusters[track.FirstClusterRef() + k];
1748 if (cl.state & GPUTPCGMMergedTrackHit::flagReject) {
1749 continue;
1750 }
1751 bool labelOk = false, labelOkNonFake = false;
1752 const mcLabelI_t& trkLabel = mTrackMCLabels[i];
1753 if (trkLabel.isValid() && !trkLabel.isNoise()) {
1754 for (int32_t l = 0; l < GetMCLabelNID(cl.num); l++) {
1755 const mcLabelI_t& clLabel = GetMCLabel(cl.num, l);
1756 if (clLabel.isValid() && !clLabel.isNoise() && CompareIgnoreFake(trkLabel, clLabel)) {
1757 labelOk = true;
1758 if (!trkLabel.isFake()) {
1759 labelOkNonFake = true;
1760 }
1761 break;
1762 }
1763 }
1764 }
1765 clusterAttachCounts[cl.num][0] += 1.0f;
1766 clusterAttachCounts[cl.num][1] += (float)labelOk / rowClCount;
1767 clusterAttachCounts[cl.num][2] += (float)labelOkNonFake / rowClCount;
1768 }
1769 }
1770 }
1771 if (nClCorrected) {
1772 mNCl[1]->Fill(nClCorrected);
1773 }
1774 mT0[0]->Fill(track.GetParam().GetTOffset());
1775 if (mTrackMCLabels.size() && !mTrackMCLabels[i].isFake() && !track.MergedLooper() && !track.CCE()) {
1776 const auto& info = GetMCTrack(mTrackMCLabels[i]);
1777 if (info.t0 != -100.f) {
1778 mT0[1]->Fill(track.GetParam().GetTOffset() - info.t0);
1779 }
1780 }
1781 }
1782 if (mClNative && mTracking && mTracking->GetTPCTransformHelper()) {
1783 for (uint32_t i = 0; i < GPUChainTracking::NSECTORS; i++) {
1784 for (uint32_t j = 0; j < GPUCA_ROW_COUNT; j++) {
1785 for (uint32_t k = 0; k < mClNative->nClusters[i][j]; k++) {
1786 const auto& cl = mClNative->clusters[i][j][k];
1787 float x, y, z;
1788 GPUTPCConvertImpl::convert(*mTracking->GetTPCTransformHelper()->getCorrMap(), mTracking->GetParam(), i, j, cl.getPad(), cl.getTime(), x, y, z);
1789 mTracking->GetParam().Sector2Global(i, x, y, z, &x, &y, &z);
1790 mClXY->Fill(x, y);
1791 }
1792 }
1793 }
1794 }
1795 if (mcAvail) {
1796 double clusterAttachNormalizedCount = 0, clusterAttachNormalizedCountNonFake = 0;
1797 for (uint32_t i = 0; i < clusterAttachCounts.size(); i++) {
1798 if (clusterAttachCounts[i][0]) {
1799 clusterAttachNormalizedCount += clusterAttachCounts[i][1] / clusterAttachCounts[i][0];
1800 clusterAttachNormalizedCountNonFake += clusterAttachCounts[i][2] / clusterAttachCounts[i][0];
1801 }
1802 }
1803 mClusterCounts.nCorrectlyAttachedNormalized = clusterAttachNormalizedCount;
1804 mClusterCounts.nCorrectlyAttachedNormalizedNonFake = clusterAttachNormalizedCountNonFake;
1805 clusterAttachCounts.clear();
1806 }
1807
1808 if (timer.IsRunning()) {
1809 GPUInfo("QA Time: Fill track statistics:\t%6.0f us", timer.GetCurrentElapsedTime(true) * 1e6);
1810 }
1811 }
1812
1813 uint32_t nCl = clNative ? clNative->nClustersTotal : mTracking->GetProcessors()->tpcMerger.NMaxClusters();
1814 mClusterCounts.nTotal += nCl;
1815 if (mQATasks & taskClusterCounts) {
1816 for (uint32_t iSector = 0; iSector < GPUCA_NSECTORS; iSector++) {
1817 for (uint32_t iRow = 0; iRow < GPUCA_ROW_COUNT; iRow++) {
1818 for (uint32_t iCl = 0; iCl < mTracking->mIOPtrs.clustersNative->nClusters[iSector][iRow]; iCl++) {
1819 uint32_t i = mTracking->mIOPtrs.clustersNative->clusterOffset[iSector][iRow] + iCl;
1820 int32_t attach = mTracking->mIOPtrs.mergedTrackHitAttachment[i];
1821 const auto& r = checkClusterState<true>(attach, &mClusterCounts);
1822
1823 if (mcAvail) {
1824 float totalWeight = 0, weight400 = 0, weight40 = 0;
1825 for (int32_t j = 0; j < GetMCLabelNID(i); j++) {
1826 const auto& label = GetMCLabel(i, j);
1827 if (GetMCLabelID(label) >= 0) {
1828 totalWeight += GetMCLabelWeight(label);
1829 if (GetMCTrackObj(mMCParam, label).pt >= 0.4) {
1830 weight400 += GetMCLabelWeight(label);
1831 }
1832 if (GetMCTrackObj(mMCParam, label).pt <= 0.04) {
1833 weight40 += GetMCLabelWeight(label);
1834 }
1835 }
1836 }
1837 if (totalWeight > 0 && 10.f * weight400 >= totalWeight) {
1838 if (!r.unattached && !r.protect && !r.physics) {
1839 mClusterCounts.nFakeRemove400++;
1840 int32_t totalFake = weight400 < 0.9f * totalWeight;
1841 if (totalFake) {
1842 mClusterCounts.nFullFakeRemove400++;
1843 }
1844 /*printf("Fake removal (%d): Hit %7d, attached %d lowPt %d looper %d tube200 %d highIncl %d tube %d bad %d recPt %7.2f recLabel %6d", totalFake, i, (int32_t) (mClusterParam[i].attached || mClusterParam[i].fakeAttached),
1845 (int32_t) lowPt, (int32_t) ((attach & gputpcgmmergertypes::attachGoodLeg) == 0), (int32_t) ((attach & gputpcgmmergertypes::attachTube) && mev200),
1846 (int32_t) ((attach & gputpcgmmergertypes::attachHighIncl) != 0), (int32_t) ((attach & gputpcgmmergertypes::attachTube) != 0), (int32_t) ((attach & gputpcgmmergertypes::attachGood) == 0),
1847 fabsf(qpt) > 0 ? 1.f / qpt : 0.f, id);
1848 for (int32_t j = 0;j < GetMCLabelNID(i);j++)
1849 {
1850 //if (GetMCLabelID(i, j) < 0) break;
1851 printf(" - label%d %6d weight %5d", j, GetMCLabelID(i, j), (int32_t) GetMCLabelWeight(i, j));
1852 if (GetMCLabelID(i, j) >= 0) printf(" - pt %7.2f", mMCParam[GetMCLabelID(i, j)].pt);
1853 else printf(" ");
1854 }
1855 printf("\n");*/
1856 }
1857 mClusterCounts.nAbove400++;
1858 }
1859 if (totalWeight > 0 && weight40 >= 0.9 * totalWeight) {
1860 mClusterCounts.nBelow40++;
1861 if (r.protect || r.physics) {
1862 mClusterCounts.nFakeProtect40++;
1863 }
1864 }
1865 }
1866
1867 if (r.physics) {
1868 mClusterCounts.nPhysics++;
1869 }
1870 if (r.protect) {
1871 mClusterCounts.nProt++;
1872 }
1873 if (r.unattached) {
1874 mClusterCounts.nUnattached++;
1875 }
1876 if (mTracking && mTracking->mIOPtrs.clustersNative) {
1877 const auto& cl = mTracking->mIOPtrs.clustersNative->clustersLinear[i];
1878 mClRej[0]->Fill(cl.getPad() - GPUTPCGeometry::NPads(iRow) / 2 + 0.5, iRow, 1.f);
1879 if (!r.unattached && !r.protect) {
1880 mClRej[1]->Fill(cl.getPad() - GPUTPCGeometry::NPads(iRow) / 2 + 0.5, iRow, 1.f);
1881 }
1882 }
1883 }
1884 }
1885 }
1886 }
1887
1888 // Process cluster count statistics
1889 if ((mQATasks & taskClusterCounts) && mConfig.clusterRejectionHistograms) {
1890 DoClusterCounts(nullptr);
1891 mClusterCounts = counts_t();
1892 }
1893
1894 if (timer.IsRunning()) {
1895 GPUInfo("QA Time: Cluster Counts:\t%6.0f us", timer.GetCurrentElapsedTime(true) * 1e6);
1896 }
1897
1898 if (mConfig.dumpToROOT) {
1899 if (!clNative || !mTracking || !mTracking->mIOPtrs.mergedTrackHitAttachment || !mTracking->mIOPtrs.mergedTracks) {
1900 throw std::runtime_error("Cannot dump non o2::tpc::clusterNative clusters, need also hit attachmend and GPU tracks");
1901 }
1902 uint32_t clid = 0;
1903 for (uint32_t i = 0; i < GPUChainTracking::NSECTORS; i++) {
1904 for (uint32_t j = 0; j < GPUCA_ROW_COUNT; j++) {
1905 for (uint32_t k = 0; k < mClNative->nClusters[i][j]; k++) {
1906 const auto& cl = mClNative->clusters[i][j][k];
1907 uint32_t attach = mTracking->mIOPtrs.mergedTrackHitAttachment[clid];
1908 float x = 0, y = 0, z = 0;
1910 uint32_t track = attach & gputpcgmmergertypes::attachTrackMask;
1911 const auto& trk = mTracking->mIOPtrs.mergedTracks[track];
1912 mTracking->GetTPCTransformHelper()->Transform(i, j, cl.getPad(), cl.getTime(), x, y, z, trk.GetParam().GetTOffset());
1913 mTracking->GetParam().Sector2Global(i, x, y, z, &x, &y, &z);
1914 }
1915 uint32_t extState = mTracking->mIOPtrs.mergedTrackHitStates ? mTracking->mIOPtrs.mergedTrackHitStates[clid] : 0;
1916
1917 if (mConfig.dumpToROOT >= 2) {
1920 memset((void*)&trk, 0, sizeof(trk));
1921 memset((void*)&trkHit, 0, sizeof(trkHit));
1923 uint32_t track = attach & gputpcgmmergertypes::attachTrackMask;
1924 trk = mTracking->mIOPtrs.mergedTracks[track];
1925 for (uint32_t l = 0; l < trk.NClusters(); l++) {
1926 const auto& tmp = mTracking->mIOPtrs.mergedTrackHits[trk.FirstClusterRef() + l];
1927 if (tmp.num == clid) {
1928 trkHit = tmp;
1929 break;
1930 }
1931 }
1932 }
1933 static auto cldump = GPUROOTDump<o2::tpc::ClusterNative, GPUTPCGMMergedTrack, GPUTPCGMMergedTrackHit, uint32_t, uint32_t, float, float, float, uint32_t, uint32_t, uint32_t>::getNew("cluster", "track", "trackHit", "attach", "extState", "x", "y", "z", "sector", "row", "nEv", "clusterTree");
1934 cldump.Fill(cl, trk, trkHit, attach, extState, x, y, z, i, j, mNEvents - 1);
1935 } else {
1936 static auto cldump = GPUROOTDump<o2::tpc::ClusterNative, uint32_t, uint32_t, float, float, float, uint32_t, uint32_t, uint32_t>::getNew("cluster", "attach", "extState", "x", "y", "z", "sector", "row", "nEv", "clusterTree");
1937 cldump.Fill(cl, attach, extState, x, y, z, i, j, mNEvents - 1);
1938 }
1939 clid++;
1940 }
1941 }
1942 }
1943
1944 static auto trkdump = GPUROOTDump<uint32_t, GPUTPCGMMergedTrack>::getNew("nEv", "track", "tracksTree");
1945 for (uint32_t i = 0; i < mTracking->mIOPtrs.nMergedTracks; i++) {
1946 if (mTracking->mIOPtrs.mergedTracks[i].OK()) {
1947 trkdump.Fill(mNEvents - 1, mTracking->mIOPtrs.mergedTracks[i]);
1948 }
1949 }
1950
1951 if (mTracking && mTracking->GetProcessingSettings().createO2Output) {
1952 static auto o2trkdump = GPUROOTDump<uint32_t, o2::tpc::TrackTPC>::getNew("nEv", "track", "tracksO2Tree");
1953 for (uint32_t i = 0; i < mTracking->mIOPtrs.nOutputTracksTPCO2; i++) {
1954 o2trkdump.Fill(mNEvents - 1, mTracking->mIOPtrs.outputTracksTPCO2[i]);
1955 }
1956 }
1957 }
1958
1959 if (mConfig.compareTrackStatus) {
1960#ifdef GPUCA_DETERMINISTIC_MODE
1961 if (!mTracking || !mTracking->GetProcessingSettings().deterministicGPUReconstruction)
1962#endif
1963 {
1964 throw std::runtime_error("Need deterministic processing to compare track status");
1965 }
1966 std::vector<uint8_t> status(mTracking->mIOPtrs.nMergedTracks);
1967 for (uint32_t i = 0; i < mTracking->mIOPtrs.nMergedTracks; i++) {
1968 const auto& trk = mTracking->mIOPtrs.mergedTracks[i];
1969 status[i] = trk.OK() && trk.NClusters() && trk.GetParam().GetNDF() > 0 && (mConfig.noMC || (mTrackMCLabels[i].isValid() && !mTrackMCLabels[i].isFake()));
1970 }
1971 if (mConfig.compareTrackStatus == 1) {
1972 std::ofstream("track.status", std::ios::binary).write((char*)status.data(), status.size() * sizeof(status[0]));
1973 } else if (mConfig.compareTrackStatus == 2) {
1974 std::ifstream f("track.status", std::ios::binary | std::ios::ate);
1975 std::vector<uint8_t> comp(f.tellg());
1976 f.seekg(0);
1977 f.read((char*)comp.data(), comp.size());
1978
1979 if (comp.size() != status.size()) {
1980 throw std::runtime_error("Number of tracks candidates in track fit in track.status and in current reconstruction differ");
1981 }
1982 std::vector<uint32_t> missing, missingComp;
1983 for (uint32_t i = 0; i < status.size(); i++) {
1984 if (status[i] && !comp[i]) {
1985 missingComp.emplace_back(i);
1986 }
1987 if (comp[i] && !status[i]) {
1988 missing.emplace_back(i);
1989 }
1990 }
1991 auto printer = [](std::vector<uint32_t> m, const char* name) {
1992 if (m.size()) {
1993 printf("Missing in %s reconstruction: (%zu)\n", name, m.size());
1994 for (uint32_t i = 0; i < m.size(); i++) {
1995 if (i) {
1996 printf(", ");
1997 }
1998 printf("%d", m[i]);
1999 }
2000 printf("\n");
2001 }
2002 };
2003 printer(missing, "current");
2004 printer(missingComp, "comparison");
2005 }
2006 }
2007
2008 mTrackingScratchBuffer.clear();
2009 mTrackingScratchBuffer.shrink_to_fit();
2010}
2011
2012void GPUQA::GetName(char* fname, int32_t k, bool noDash)
2013{
2014 const int32_t nNewInput = mConfig.inputHistogramsOnly ? 0 : 1;
2015 if (k || mConfig.inputHistogramsOnly || mConfig.name.size()) {
2016 if (!(mConfig.inputHistogramsOnly || k)) {
2017 snprintf(fname, 1024, "%s%s", mConfig.name.c_str(), noDash ? "" : " - ");
2018 } else if (mConfig.compareInputNames.size() > (unsigned)(k - nNewInput)) {
2019 snprintf(fname, 1024, "%s%s", mConfig.compareInputNames[k - nNewInput].c_str(), noDash ? "" : " - ");
2020 } else {
2021 strcpy(fname, mConfig.compareInputs[k - nNewInput].c_str());
2022 if (strlen(fname) > 5 && strcmp(fname + strlen(fname) - 5, ".root") == 0) {
2023 fname[strlen(fname) - 5] = 0;
2024 }
2025 if (!noDash) {
2026 strcat(fname, " - ");
2027 }
2028 }
2029 } else {
2030 fname[0] = 0;
2031 }
2032}
2033
2034template <class T>
2035T* GPUQA::GetHist(T*& ee, std::vector<std::unique_ptr<TFile>>& tin, int32_t k, int32_t nNewInput)
2036{
2037 T* e = ee;
2038 if ((mConfig.inputHistogramsOnly || k) && (e = dynamic_cast<T*>(tin[k - nNewInput]->Get(e->GetName()))) == nullptr) {
2039 GPUWarning("Missing histogram in input %s: %s", mConfig.compareInputs[k - nNewInput].c_str(), ee->GetName());
2040 return (nullptr);
2041 }
2042 ee = e;
2043 return (e);
2044}
2045
2046void GPUQA::DrawQAHistogramsCleanup()
2047{
2048 clearGarbagageCollector();
2049}
2050
2051void GPUQA::resetHists()
2052{
2053 if (!mQAInitialized) {
2054 throw std::runtime_error("QA not initialized");
2055 }
2056 if (mHaveExternalHists) {
2057 throw std::runtime_error("Cannot reset external hists");
2058 }
2059 for (auto& h : *mHist1D) {
2060 h.Reset();
2061 }
2062 for (auto& h : *mHist2D) {
2063 h.Reset();
2064 }
2065 for (auto& h : *mHist1Dd) {
2066 h.Reset();
2067 }
2068 for (auto& h : *mHistGraph) {
2069 h = TGraphAsymmErrors();
2070 }
2071 mClusterCounts = counts_t();
2072}
2073
2074int32_t GPUQA::DrawQAHistograms(TObjArray* qcout)
2075{
2076 const auto oldRootIgnoreLevel = gErrorIgnoreLevel;
2077 gErrorIgnoreLevel = kWarning;
2078 if (!mQAInitialized) {
2079 throw std::runtime_error("QA not initialized");
2080 }
2081
2082 if (mTracking && mTracking->GetProcessingSettings().debugLevel >= 2) {
2083 printf("Creating QA Histograms\n");
2084 }
2085
2086 std::vector<Color_t> colorNums(COLORCOUNT);
2087 if (!(qcout || mConfig.writeFileExt == "root" || mConfig.writeFileExt == "C")) {
2088 [[maybe_unused]] static int32_t initColorsInitialized = initColors();
2089 }
2090 for (int32_t i = 0; i < COLORCOUNT; i++) {
2091 colorNums[i] = (qcout || mConfig.writeFileExt == "root" || mConfig.writeFileExt == "C") ? defaultColorNums[i] : mColors[i]->GetNumber();
2092 }
2093
2094 bool mcAvail = mcPresent();
2095 char name[2048], fname[1024];
2096
2097 const int32_t nNewInput = mConfig.inputHistogramsOnly ? 0 : 1;
2098 const int32_t ConfigNumInputs = nNewInput + mConfig.compareInputs.size();
2099
2100 std::vector<std::unique_ptr<TFile>> tin;
2101 for (uint32_t i = 0; i < mConfig.compareInputs.size(); i++) {
2102 tin.emplace_back(std::make_unique<TFile>(mConfig.compareInputs[i].c_str()));
2103 }
2104 std::unique_ptr<TFile> tout = nullptr;
2105 if (mConfig.output.size()) {
2106 tout = std::make_unique<TFile>(mConfig.output.c_str(), "RECREATE");
2107 }
2108
2109 if (mConfig.enableLocalOutput || mConfig.shipToQCAsCanvas) {
2110 float legendSpacingString = 0.025;
2111 for (int32_t i = 0; i < ConfigNumInputs; i++) {
2112 GetName(fname, i);
2113 if (strlen(fname) * 0.006 > legendSpacingString) {
2114 legendSpacingString = strlen(fname) * 0.006;
2115 }
2116 }
2117
2118 // Create Canvas / Pads for Efficiency Histograms
2119 if (mQATasks & taskTrackingEff) {
2120 for (int32_t ii = 0; ii < 6; ii++) {
2121 snprintf(name, 1024, "eff_vs_%s_layout", VSPARAMETER_NAMES[ii]);
2122 mCEff[ii] = createGarbageCollected<TCanvas>(name, name, 0, 0, 700, 700. * 2. / 3.);
2123 mCEff[ii]->cd();
2124 float dy = 1. / 2.;
2125 mPEff[ii][0] = createGarbageCollected<TPad>("p0", "", 0.0, dy * 0, 0.5, dy * 1);
2126 mPEff[ii][0]->Draw();
2127 mPEff[ii][0]->SetRightMargin(0.04);
2128 mPEff[ii][1] = createGarbageCollected<TPad>("p1", "", 0.5, dy * 0, 1.0, dy * 1);
2129 mPEff[ii][1]->Draw();
2130 mPEff[ii][1]->SetRightMargin(0.04);
2131 mPEff[ii][2] = createGarbageCollected<TPad>("p2", "", 0.0, dy * 1, 0.5, dy * 2 - .001);
2132 mPEff[ii][2]->Draw();
2133 mPEff[ii][2]->SetRightMargin(0.04);
2134 mPEff[ii][3] = createGarbageCollected<TPad>("p3", "", 0.5, dy * 1, 1.0, dy * 2 - .001);
2135 mPEff[ii][3]->Draw();
2136 mPEff[ii][3]->SetRightMargin(0.04);
2137 mLEff[ii] = createGarbageCollected<TLegend>(0.92 - legendSpacingString * 1.45, 0.83 - (0.93 - 0.82) / 2. * (float)ConfigNumInputs, 0.98, 0.849);
2138 SetLegend(mLEff[ii]);
2139 }
2140 }
2141
2142 // Create Canvas / Pads for Resolution Histograms
2143 if (mQATasks & taskTrackingRes) {
2144 for (int32_t ii = 0; ii < 7; ii++) {
2145 if (ii == 6) {
2146 snprintf(name, 1024, "res_integral_layout");
2147 } else {
2148 snprintf(name, 1024, "res_vs_%s_layout", VSPARAMETER_NAMES[ii]);
2149 }
2150 mCRes[ii] = createGarbageCollected<TCanvas>(name, name, 0, 0, 700, 700. * 2. / 3.);
2151 mCRes[ii]->cd();
2152 gStyle->SetOptFit(1);
2153
2154 float dy = 1. / 2.;
2155 mPRes[ii][3] = createGarbageCollected<TPad>("p0", "", 0.0, dy * 0, 0.5, dy * 1);
2156 mPRes[ii][3]->Draw();
2157 mPRes[ii][3]->SetRightMargin(0.04);
2158 mPRes[ii][4] = createGarbageCollected<TPad>("p1", "", 0.5, dy * 0, 1.0, dy * 1);
2159 mPRes[ii][4]->Draw();
2160 mPRes[ii][4]->SetRightMargin(0.04);
2161 mPRes[ii][0] = createGarbageCollected<TPad>("p2", "", 0.0, dy * 1, 1. / 3., dy * 2 - .001);
2162 mPRes[ii][0]->Draw();
2163 mPRes[ii][0]->SetRightMargin(0.04);
2164 mPRes[ii][0]->SetLeftMargin(0.15);
2165 mPRes[ii][1] = createGarbageCollected<TPad>("p3", "", 1. / 3., dy * 1, 2. / 3., dy * 2 - .001);
2166 mPRes[ii][1]->Draw();
2167 mPRes[ii][1]->SetRightMargin(0.04);
2168 mPRes[ii][1]->SetLeftMargin(0.135);
2169 mPRes[ii][2] = createGarbageCollected<TPad>("p4", "", 2. / 3., dy * 1, 1.0, dy * 2 - .001);
2170 mPRes[ii][2]->Draw();
2171 mPRes[ii][2]->SetRightMargin(0.06);
2172 mPRes[ii][2]->SetLeftMargin(0.135);
2173 if (ii < 6) {
2174 mLRes[ii] = createGarbageCollected<TLegend>(0.9 - legendSpacingString * 1.45, 0.93 - (0.93 - 0.86) / 2. * (float)ConfigNumInputs, 0.98, 0.949);
2175 SetLegend(mLRes[ii]);
2176 }
2177 }
2178 }
2179
2180 // Create Canvas / Pads for Pull Histograms
2181 if (mQATasks & taskTrackingResPull) {
2182 for (int32_t ii = 0; ii < 7; ii++) {
2183 if (ii == 6) {
2184 snprintf(name, 1024, "pull_integral_layout");
2185 } else {
2186 snprintf(name, 1024, "pull_vs_%s_layout", VSPARAMETER_NAMES[ii]);
2187 }
2188 mCPull[ii] = createGarbageCollected<TCanvas>(name, name, 0, 0, 700, 700. * 2. / 3.);
2189 mCPull[ii]->cd();
2190 gStyle->SetOptFit(1);
2191
2192 float dy = 1. / 2.;
2193 mPPull[ii][3] = createGarbageCollected<TPad>("p0", "", 0.0, dy * 0, 0.5, dy * 1);
2194 mPPull[ii][3]->Draw();
2195 mPPull[ii][3]->SetRightMargin(0.04);
2196 mPPull[ii][4] = createGarbageCollected<TPad>("p1", "", 0.5, dy * 0, 1.0, dy * 1);
2197 mPPull[ii][4]->Draw();
2198 mPPull[ii][4]->SetRightMargin(0.04);
2199 mPPull[ii][0] = createGarbageCollected<TPad>("p2", "", 0.0, dy * 1, 1. / 3., dy * 2 - .001);
2200 mPPull[ii][0]->Draw();
2201 mPPull[ii][0]->SetRightMargin(0.04);
2202 mPPull[ii][0]->SetLeftMargin(0.15);
2203 mPPull[ii][1] = createGarbageCollected<TPad>("p3", "", 1. / 3., dy * 1, 2. / 3., dy * 2 - .001);
2204 mPPull[ii][1]->Draw();
2205 mPPull[ii][1]->SetRightMargin(0.04);
2206 mPPull[ii][1]->SetLeftMargin(0.135);
2207 mPPull[ii][2] = createGarbageCollected<TPad>("p4", "", 2. / 3., dy * 1, 1.0, dy * 2 - .001);
2208 mPPull[ii][2]->Draw();
2209 mPPull[ii][2]->SetRightMargin(0.06);
2210 mPPull[ii][2]->SetLeftMargin(0.135);
2211 if (ii < 6) {
2212 mLPull[ii] = createGarbageCollected<TLegend>(0.9 - legendSpacingString * 1.45, 0.93 - (0.93 - 0.86) / 2. * (float)ConfigNumInputs, 0.98, 0.949);
2213 SetLegend(mLPull[ii]);
2214 }
2215 }
2216 }
2217
2218 // Create Canvas for Cluster Histos
2219 if (mQATasks & taskClusterAttach) {
2220 for (int32_t i = 0; i < 3; i++) {
2221 snprintf(name, 1024, "clusters_%s_layout", CLUSTER_TYPES[i]);
2222 mCClust[i] = createGarbageCollected<TCanvas>(name, name, 0, 0, 700, 700. * 2. / 3.);
2223 mCClust[i]->cd();
2224 mPClust[i] = createGarbageCollected<TPad>("p0", "", 0.0, 0.0, 1.0, 1.0);
2225 mPClust[i]->Draw();
2226 float y1 = i != 1 ? 0.77 : 0.27, y2 = i != 1 ? 0.9 : 0.42;
2227 mLClust[i] = createGarbageCollected<TLegend>(i == 2 ? 0.1 : (0.65 - legendSpacingString * 1.45), y2 - (y2 - y1) * (ConfigNumInputs + (i != 1) / 2.) + 0.005, i == 2 ? (0.3 + legendSpacingString * 1.45) : 0.9, y2);
2228 SetLegend(mLClust[i]);
2229 }
2230 }
2231
2232 // Create Canvas for track statistic histos
2233 if (mQATasks & taskTrackStatistics) {
2234 mCTracks = createGarbageCollected<TCanvas>("ctrackspt", "ctrackspt", 0, 0, 700, 700. * 2. / 3.);
2235 mCTracks->cd();
2236 mPTracks = createGarbageCollected<TPad>("p0", "", 0.0, 0.0, 1.0, 1.0);
2237 mPTracks->Draw();
2238 mLTracks = createGarbageCollected<TLegend>(0.9 - legendSpacingString * 1.5, 0.93 - (0.93 - 0.86) / 2. * (float)ConfigNumInputs, 0.98, 0.949);
2239 SetLegend(mLTracks, true);
2240
2241 for (int32_t i = 0; i < 2; i++) {
2242 snprintf(name, 2048, "ctrackst0%d", i);
2243 mCT0[i] = createGarbageCollected<TCanvas>(name, name, 0, 0, 700, 700. * 2. / 3.);
2244 mCT0[i]->cd();
2245 mPT0[i] = createGarbageCollected<TPad>("p0", "", 0.0, 0.0, 1.0, 1.0);
2246 mPT0[i]->Draw();
2247 mLT0[i] = createGarbageCollected<TLegend>(0.9 - legendSpacingString * 1.45, 0.93 - (0.93 - 0.86) / 2. * (float)ConfigNumInputs, 0.98, 0.949);
2248 SetLegend(mLT0[i]);
2249
2250 snprintf(name, 2048, "cncl%d", i);
2251 mCNCl[i] = createGarbageCollected<TCanvas>(name, name, 0, 0, 700, 700. * 2. / 3.);
2252 mCNCl[i]->cd();
2253 mPNCl[i] = createGarbageCollected<TPad>("p0", "", 0.0, 0.0, 1.0, 1.0);
2254 mPNCl[i]->Draw();
2255 mLNCl[i] = createGarbageCollected<TLegend>(0.9 - legendSpacingString * 1.45, 0.93 - (0.93 - 0.86) / 2. * (float)ConfigNumInputs, 0.98, 0.949); // TODO: Fix sizing of legend, and also fix font size
2256 SetLegend(mLNCl[i], true);
2257 }
2258
2259 mCClXY = createGarbageCollected<TCanvas>("clxy", "clxy", 0, 0, 700, 700. * 2. / 3.);
2260 mCClXY->cd();
2261 mPClXY = createGarbageCollected<TPad>("p0", "", 0.0, 0.0, 1.0, 1.0);
2262 mPClXY->Draw();
2263
2264 for (int32_t i = 0; i < 3; i++) {
2265 snprintf(name, 2048, "cnclrej%d", i);
2266 mCClRej[i] = createGarbageCollected<TCanvas>(name, name, 0, 0, 700, 700. * 2. / 3.);
2267 mCClRej[i]->cd();
2268 mPClRej[i] = createGarbageCollected<TPad>("p0", "", 0.0, 0.0, 1.0, 1.0);
2269 mPClRej[i]->Draw();
2270 }
2271 mCClRejP = createGarbageCollected<TCanvas>("cnclrejp", "cnclrejp", 0, 0, 700, 700. * 2. / 3.);
2272 mCClRejP->cd();
2273 mPClRejP = createGarbageCollected<TPad>("p0", "", 0.0, 0.0, 1.0, 1.0);
2274 mPClRejP->Draw();
2275
2276 for (int32_t i = 0; i < 3; i++) {
2277 snprintf(name, 2048, "cpadrow%d", i);
2278 mCPadRow[i] = createGarbageCollected<TCanvas>(name, name, 0, 0, 700, 700. * 2. / 3.);
2279 mCPadRow[i]->cd();
2280 mPPadRow[i] = createGarbageCollected<TPad>("p0", "", 0.0, 0.0, 1.0, 1.0);
2281 mPPadRow[i]->Draw();
2282 }
2283 }
2284 }
2285
2286 if (mConfig.enableLocalOutput && !mConfig.inputHistogramsOnly && (mQATasks & taskTrackingEff) && mcPresent()) {
2287 GPUInfo("QA Stats: Eff: Tracks Prim %d (Eta %d, Pt %d) %f%% (%f%%) Sec %d (Eta %d, Pt %d) %f%% (%f%%) - Res: Tracks %d (Eta %d, Pt %d)", (int32_t)mEff[3][1][0][0]->GetEntries(), (int32_t)mEff[3][1][0][3]->GetEntries(), (int32_t)mEff[3][1][0][4]->GetEntries(),
2288 mEff[0][0][0][0]->GetSumOfWeights() / std::max(1., mEff[3][0][0][0]->GetSumOfWeights()), mEff[0][1][0][0]->GetSumOfWeights() / std::max(1., mEff[3][1][0][0]->GetSumOfWeights()), (int32_t)mEff[3][1][1][0]->GetEntries(), (int32_t)mEff[3][1][1][3]->GetEntries(),
2289 (int32_t)mEff[3][1][1][4]->GetEntries(), mEff[0][0][1][0]->GetSumOfWeights() / std::max(1., mEff[3][0][1][0]->GetSumOfWeights()), mEff[0][1][1][0]->GetSumOfWeights() / std::max(1., mEff[3][1][1][0]->GetSumOfWeights()), (int32_t)mRes2[0][0]->GetEntries(),
2290 (int32_t)mRes2[0][3]->GetEntries(), (int32_t)mRes2[0][4]->GetEntries());
2291 }
2292
2293 int32_t flagShowVsPtLog = (mConfig.enableLocalOutput || mConfig.shipToQCAsCanvas) ? 1 : 0;
2294
2295 if (mQATasks & taskTrackingEff) {
2296 // Process / Draw Efficiency Histograms
2297 for (int32_t ii = 0; ii < 5 + flagShowVsPtLog; ii++) {
2298 int32_t i = ii == 5 ? 4 : ii;
2299 for (int32_t k = 0; k < ConfigNumInputs; k++) {
2300 for (int32_t j = 0; j < 4; j++) {
2301 if (mConfig.enableLocalOutput || mConfig.shipToQCAsCanvas) {
2302 mPEff[ii][j]->cd();
2303 if (ii == 5) {
2304 mPEff[ii][j]->SetLogx();
2305 }
2306 }
2307 for (int32_t l = 0; l < 3; l++) {
2308 if (k == 0 && mConfig.inputHistogramsOnly == 0 && ii != 5) {
2309 if (l == 0) {
2310 // Divide eff, compute all for fake/clone
2311 auto oldLevel = gErrorIgnoreLevel;
2312 gErrorIgnoreLevel = kError;
2313 mEffResult[0][j / 2][j % 2][i]->Divide(mEff[l][j / 2][j % 2][i], mEff[5][j / 2][j % 2][i], "cl=0.683 b(1,1) mode");
2314 gErrorIgnoreLevel = oldLevel;
2315 mEff[3][j / 2][j % 2][i]->Reset(); // Sum up rec + clone + fake for fake rate
2316 mEff[3][j / 2][j % 2][i]->Add(mEff[0][j / 2][j % 2][i]);
2317 mEff[3][j / 2][j % 2][i]->Add(mEff[1][j / 2][j % 2][i]);
2318 mEff[3][j / 2][j % 2][i]->Add(mEff[2][j / 2][j % 2][i]);
2319 mEff[4][j / 2][j % 2][i]->Reset(); // Sum up rec + clone for clone rate
2320 mEff[4][j / 2][j % 2][i]->Add(mEff[0][j / 2][j % 2][i]);
2321 mEff[4][j / 2][j % 2][i]->Add(mEff[1][j / 2][j % 2][i]);
2322 } else {
2323 // Divide fake/clone
2324 auto oldLevel = gErrorIgnoreLevel;
2325 gErrorIgnoreLevel = kError;
2326 mEffResult[l][j / 2][j % 2][i]->Divide(mEff[l][j / 2][j % 2][i], mEff[l == 1 ? 4 : 3][j / 2][j % 2][i], "cl=0.683 b(1,1) mode");
2327 gErrorIgnoreLevel = oldLevel;
2328 }
2329 }
2330
2331 TGraphAsymmErrors* e = mEffResult[l][j / 2][j % 2][i];
2332
2333 if (!mConfig.inputHistogramsOnly && k == 0) {
2334 if (tout) {
2335 mEff[l][j / 2][j % 2][i]->Write();
2336 e->Write();
2337 if (l == 2) {
2338 mEff[3][j / 2][j % 2][i]->Write(); // Store also all histogram!
2339 mEff[4][j / 2][j % 2][i]->Write(); // Store also all histogram!
2340 }
2341 }
2342 } else if (GetHist(e, tin, k, nNewInput) == nullptr) {
2343 continue;
2344 }
2345 e->SetTitle(EFFICIENCY_TITLES[j]);
2346 e->GetYaxis()->SetTitle("(Efficiency)");
2347 e->GetXaxis()->SetTitle(XAXIS_TITLES[i]);
2348
2349 e->SetLineWidth(1);
2350 e->SetLineStyle(CONFIG_DASHED_MARKERS ? k + 1 : 1);
2351 SetAxisSize(e);
2352 if (qcout && !mConfig.shipToQCAsCanvas) {
2353 qcout->Add(e);
2354 }
2355 if (!mConfig.enableLocalOutput && !mConfig.shipToQCAsCanvas) {
2356 continue;
2357 }
2358 e->SetMarkerColor(kBlack);
2359 e->SetLineColor(colorNums[(k < 3 ? (l * 3 + k) : (k * 3 + l)) % COLORCOUNT]);
2360 e->GetHistogram()->GetYaxis()->SetRangeUser(-0.02, 1.02);
2361 e->Draw(k || l ? "same P" : "AP");
2362 if (j == 0) {
2363 GetName(fname, k);
2364 mLEff[ii]->AddEntry(e, Form("%s%s", fname, EFF_NAMES[l]), "l");
2365 }
2366 }
2367 if (!mConfig.enableLocalOutput && !mConfig.shipToQCAsCanvas) {
2368 continue;
2369 }
2370 mCEff[ii]->cd();
2371 ChangePadTitleSize(mPEff[ii][j], 0.056);
2372 }
2373 }
2374 if (!mConfig.enableLocalOutput && !mConfig.shipToQCAsCanvas) {
2375 continue;
2376 }
2377
2378 mLEff[ii]->Draw();
2379
2380 if (qcout) {
2381 qcout->Add(mCEff[ii]);
2382 }
2383 if (!mConfig.enableLocalOutput) {
2384 continue;
2385 }
2386 doPerfFigure(0.2, 0.295, 0.025);
2387 mCEff[ii]->Print(Form("%s/eff_vs_%s.pdf", mConfig.plotsDir.c_str(), VSPARAMETER_NAMES[ii]));
2388 if (mConfig.writeFileExt != "") {
2389 mCEff[ii]->Print(Form("%s/eff_vs_%s.%s", mConfig.plotsDir.c_str(), VSPARAMETER_NAMES[ii], mConfig.writeFileExt.c_str()));
2390 }
2391 }
2392 }
2393
2394 if (mQATasks & (taskTrackingRes | taskTrackingResPull)) {
2395 // Process / Draw Resolution Histograms
2396 TH1D *resIntegral[5] = {}, *pullIntegral[5] = {};
2397 TCanvas* cfit = nullptr;
2398 std::unique_ptr<TF1> customGaus = std::make_unique<TF1>("G", "[0]*exp(-(x-[1])*(x-[1])/(2.*[2]*[2]))");
2399 for (int32_t p = 0; p < 2; p++) {
2400 if ((p == 0 && (mQATasks & taskTrackingRes) == 0) || (p == 1 && (mQATasks & taskTrackingResPull) == 0)) {
2401 continue;
2402 }
2403 for (int32_t ii = 0; ii < 5 + flagShowVsPtLog; ii++) {
2404 TCanvas* can = p ? mCPull[ii] : mCRes[ii];
2405 TLegend* leg = p ? mLPull[ii] : mLRes[ii];
2406 int32_t i = ii == 5 ? 4 : ii;
2407 for (int32_t j = 0; j < 5; j++) {
2408 TH2F* src = p ? mPull2[j][i] : mRes2[j][i];
2409 TH1F** dst = p ? mPull[j][i] : mRes[j][i];
2410 TH1D*& dstIntegral = p ? pullIntegral[j] : resIntegral[j];
2411 TPad* pad = p ? mPPull[ii][j] : mPRes[ii][j];
2412
2413 if (!mConfig.inputHistogramsOnly && ii != 5) {
2414 if (cfit == nullptr) {
2415 cfit = createGarbageCollected<TCanvas>();
2416 }
2417 cfit->cd();
2418
2419 TAxis* axis = src->GetYaxis();
2420 int32_t nBins = axis->GetNbins();
2421 int32_t integ = 1;
2422 for (int32_t bin = 1; bin <= nBins; bin++) {
2423 int32_t bin0 = std::max(bin - integ, 0);
2424 int32_t bin1 = std::min(bin + integ, nBins);
2425 std::unique_ptr<TH1D> proj{src->ProjectionX("proj", bin0, bin1)};
2426 proj->ClearUnderflowAndOverflow();
2427 if (proj->GetEntries()) {
2428 uint32_t rebin = 1;
2429 while (proj->GetMaximum() < 50 && rebin < sizeof(RES_AXIS_BINS) / sizeof(RES_AXIS_BINS[0])) {
2430 proj->Rebin(RES_AXIS_BINS[rebin - 1] / RES_AXIS_BINS[rebin]);
2431 rebin++;
2432 }
2433
2434 if (proj->GetEntries() < 20 || proj->GetRMS() < 0.00001) {
2435 dst[0]->SetBinContent(bin, proj->GetRMS());
2436 dst[0]->SetBinError(bin, std::sqrt(proj->GetRMS()));
2437 dst[1]->SetBinContent(bin, proj->GetMean());
2438 dst[1]->SetBinError(bin, std::sqrt(proj->GetRMS()));
2439 } else {
2440 proj->GetXaxis()->SetRange(0, 0);
2441 proj->GetXaxis()->SetRangeUser(std::max(proj->GetXaxis()->GetXmin(), proj->GetMean() - 3. * proj->GetRMS()), std::min(proj->GetXaxis()->GetXmax(), proj->GetMean() + 3. * proj->GetRMS()));
2442 bool forceLogLike = proj->GetMaximum() < 20;
2443 for (int32_t k = forceLogLike ? 2 : 0; k < 3; k++) {
2444 proj->Fit("gaus", forceLogLike || k == 2 ? "sQl" : k ? "sQww" : "sQ");
2445 TF1* fitFunc = proj->GetFunction("gaus");
2446
2447 if (k && !forceLogLike) {
2448 customGaus->SetParameters(fitFunc->GetParameter(0), fitFunc->GetParameter(1), fitFunc->GetParameter(2));
2449 proj->Fit(customGaus.get(), "sQ");
2450 fitFunc = customGaus.get();
2451 }
2452
2453 const float sigma = fabs(fitFunc->GetParameter(2));
2454 dst[0]->SetBinContent(bin, sigma);
2455 dst[1]->SetBinContent(bin, fitFunc->GetParameter(1));
2456 dst[0]->SetBinError(bin, fitFunc->GetParError(2));
2457 dst[1]->SetBinError(bin, fitFunc->GetParError(1));
2458
2459 const bool fail1 = sigma <= 0.f;
2460 const bool fail2 = fabs(proj->GetMean() - dst[1]->GetBinContent(bin)) > std::min<float>(p ? PULL_AXIS : mConfig.nativeFitResolutions ? RES_AXES_NATIVE[j] : RES_AXES[j], 3.f * proj->GetRMS());
2461 const bool fail3 = dst[0]->GetBinContent(bin) > 3.f * proj->GetRMS() || dst[0]->GetBinError(bin) > 1 || dst[1]->GetBinError(bin) > 1;
2462 const bool fail4 = fitFunc->GetParameter(0) < proj->GetMaximum() / 5.;
2463 const bool fail = fail1 || fail2 || fail3 || fail4;
2464 // if (p == 0 && ii == 4 && j == 2) DrawHisto(proj, Form("Hist_bin_%d-%d_vs_%d____%d_%d___%f-%f___%f-%f___%d.pdf", p, j, ii, bin, k, dst[0]->GetBinContent(bin), proj->GetRMS(), dst[1]->GetBinContent(bin), proj->GetMean(), (int32_t) fail), "");
2465
2466 if (!fail) {
2467 break;
2468 } else if (k >= 2) {
2469 dst[0]->SetBinContent(bin, proj->GetRMS());
2470 dst[0]->SetBinError(bin, std::sqrt(proj->GetRMS()));
2471 dst[1]->SetBinContent(bin, proj->GetMean());
2472 dst[1]->SetBinError(bin, std::sqrt(proj->GetRMS()));
2473 }
2474 }
2475 }
2476 } else {
2477 dst[0]->SetBinContent(bin, 0.f);
2478 dst[0]->SetBinError(bin, 0.f);
2479 dst[1]->SetBinContent(bin, 0.f);
2480 dst[1]->SetBinError(bin, 0.f);
2481 }
2482 }
2483 if (ii == 0) {
2484 dstIntegral = src->ProjectionX(mConfig.nativeFitResolutions ? PARAMETER_NAMES_NATIVE[j] : PARAMETER_NAMES[j], 0, nBins + 1);
2485 uint32_t rebin = 1;
2486 while (dstIntegral->GetMaximum() < 50 && rebin < sizeof(RES_AXIS_BINS) / sizeof(RES_AXIS_BINS[0])) {
2487 dstIntegral->Rebin(RES_AXIS_BINS[rebin - 1] / RES_AXIS_BINS[rebin]);
2488 rebin++;
2489 }
2490 }
2491 }
2492 if (ii == 0) {
2493 if (mConfig.inputHistogramsOnly) {
2494 dstIntegral = createGarbageCollected<TH1D>();
2495 }
2496 dstIntegral->SetName(Form(p ? "IntPull%s" : "IntRes%s", VSPARAMETER_NAMES[j]));
2497 dstIntegral->SetTitle(Form(p ? "%s Pull" : "%s Resolution", p || mConfig.nativeFitResolutions ? PARAMETER_NAMES_NATIVE[j] : PARAMETER_NAMES[j]));
2498 }
2499 if (mConfig.enableLocalOutput || mConfig.shipToQCAsCanvas) {
2500 pad->cd();
2501 }
2502 int32_t numColor = 0;
2503 float tmpMax = -1000.;
2504 float tmpMin = 1000.;
2505
2506 for (int32_t l = 0; l < 2; l++) {
2507 for (int32_t k = 0; k < ConfigNumInputs; k++) {
2508 TH1F* e = dst[l];
2509 if (GetHist(e, tin, k, nNewInput) == nullptr) {
2510 continue;
2511 }
2512 if (nNewInput && k == 0 && ii != 5) {
2513 if (p == 0) {
2514 e->Scale(mConfig.nativeFitResolutions ? SCALE_NATIVE[j] : SCALE[j]);
2515 }
2516 }
2517 if (ii == 4) {
2518 e->GetXaxis()->SetRangeUser(0.2, PT_MAX);
2519 } else if (LOG_PT_MIN > 0 && ii == 5) {
2520 e->GetXaxis()->SetRangeUser(LOG_PT_MIN, PT_MAX);
2521 } else if (ii == 5) {
2522 e->GetXaxis()->SetRange(1, 0);
2523 }
2524 e->SetMinimum(-1111);
2525 e->SetMaximum(-1111);
2526
2527 if (e->GetMaximum() > tmpMax) {
2528 tmpMax = e->GetMaximum();
2529 }
2530 if (e->GetMinimum() < tmpMin) {
2531 tmpMin = e->GetMinimum();
2532 }
2533 }
2534 }
2535
2536 float tmpSpan;
2537 tmpSpan = tmpMax - tmpMin;
2538 tmpMax += tmpSpan * .02;
2539 tmpMin -= tmpSpan * .02;
2540 if (j == 2 && i < 3) {
2541 tmpMax += tmpSpan * 0.13 * ConfigNumInputs;
2542 }
2543
2544 for (int32_t k = 0; k < ConfigNumInputs; k++) {
2545 for (int32_t l = 0; l < 2; l++) {
2546 TH1F* e = dst[l];
2547 if (!mConfig.inputHistogramsOnly && k == 0) {
2548 e->SetTitle(Form(p ? "%s Pull" : "%s Resolution", p || mConfig.nativeFitResolutions ? PARAMETER_NAMES_NATIVE[j] : PARAMETER_NAMES[j]));
2549 e->SetStats(kFALSE);
2550 if (tout) {
2551 if (l == 0) {
2552 mRes2[j][i]->SetOption("colz");
2553 mRes2[j][i]->Write();
2554 }
2555 e->Write();
2556 }
2557 } else if (GetHist(e, tin, k, nNewInput) == nullptr) {
2558 continue;
2559 }
2560 e->SetMaximum(tmpMax);
2561 e->SetMinimum(tmpMin);
2562 e->SetLineWidth(1);
2563 e->SetLineStyle(CONFIG_DASHED_MARKERS ? k + 1 : 1);
2564 SetAxisSize(e);
2565 e->GetYaxis()->SetTitle(p ? AXIS_TITLES_PULL[j] : mConfig.nativeFitResolutions ? AXIS_TITLES_NATIVE[j] : AXIS_TITLES[j]);
2566 e->GetXaxis()->SetTitle(XAXIS_TITLES[i]);
2567 if (LOG_PT_MIN > 0 && ii == 5) {
2568 e->GetXaxis()->SetRangeUser(LOG_PT_MIN, PT_MAX);
2569 }
2570
2571 if (j == 0) {
2572 e->GetYaxis()->SetTitleOffset(1.5);
2573 } else if (j < 3) {
2574 e->GetYaxis()->SetTitleOffset(1.4);
2575 }
2576 if (qcout && !mConfig.shipToQCAsCanvas) {
2577 qcout->Add(e);
2578 }
2579 if (!mConfig.enableLocalOutput && !mConfig.shipToQCAsCanvas) {
2580 continue;
2581 }
2582
2583 e->SetMarkerColor(kBlack);
2584 e->SetLineColor(colorNums[numColor++ % COLORCOUNT]);
2585 e->Draw(k || l ? "same" : "");
2586 if (j == 0) {
2587 GetName(fname, k);
2588 leg->AddEntry(e, Form("%s%s", fname, l ? "Mean" : (p ? "Pull" : "Resolution")), "l");
2589 }
2590 }
2591 }
2592 if (!mConfig.enableLocalOutput && !mConfig.shipToQCAsCanvas) {
2593 continue;
2594 }
2595
2596 if (ii == 5) {
2597 pad->SetLogx();
2598 }
2599 can->cd();
2600 if (j == 4) {
2601 ChangePadTitleSize(pad, 0.056);
2602 }
2603 }
2604 if (!mConfig.enableLocalOutput && !mConfig.shipToQCAsCanvas) {
2605 continue;
2606 }
2607
2608 leg->Draw();
2609
2610 if (qcout) {
2611 qcout->Add(can);
2612 }
2613 if (!mConfig.enableLocalOutput) {
2614 continue;
2615 }
2616 doPerfFigure(0.2, 0.295, 0.025);
2617 can->Print(Form(p ? "%s/pull_vs_%s.pdf" : "%s/res_vs_%s.pdf", mConfig.plotsDir.c_str(), VSPARAMETER_NAMES[ii]));
2618 if (mConfig.writeFileExt != "") {
2619 can->Print(Form(p ? "%s/pull_vs_%s.%s" : "%s/res_vs_%s.%s", mConfig.plotsDir.c_str(), VSPARAMETER_NAMES[ii], mConfig.writeFileExt.c_str()));
2620 }
2621 }
2622 }
2623
2624 // Process Integral Resolution Histogreams
2625 for (int32_t p = 0; p < 2; p++) {
2626 if ((p == 0 && (mQATasks & taskTrackingRes) == 0) || (p == 1 && (mQATasks & taskTrackingResPull) == 0)) {
2627 continue;
2628 }
2629 TCanvas* can = p ? mCPull[6] : mCRes[6];
2630 for (int32_t i = 0; i < 5; i++) {
2631 TPad* pad = p ? mPPull[6][i] : mPRes[6][i];
2632 TH1D* hist = p ? pullIntegral[i] : resIntegral[i];
2633 int32_t numColor = 0;
2634 if (mConfig.enableLocalOutput || mConfig.shipToQCAsCanvas) {
2635 pad->cd();
2636 }
2637 if (!mConfig.inputHistogramsOnly && mcAvail) {
2638 TH1D* e = hist;
2639 if (e && e->GetEntries()) {
2640 e->Fit("gaus", "sQ");
2641 }
2642 }
2643
2644 float tmpMax = 0;
2645 for (int32_t k = 0; k < ConfigNumInputs; k++) {
2646 TH1D* e = hist;
2647 if (GetHist(e, tin, k, nNewInput) == nullptr) {
2648 continue;
2649 }
2650 e->SetMaximum(-1111);
2651 if (e->GetMaximum() > tmpMax) {
2652 tmpMax = e->GetMaximum();
2653 }
2654 }
2655
2656 for (int32_t k = 0; k < ConfigNumInputs; k++) {
2657 TH1D* e = hist;
2658 if (GetHist(e, tin, k, nNewInput) == nullptr) {
2659 continue;
2660 }
2661 e->SetMaximum(tmpMax * 1.02);
2662 e->SetMinimum(tmpMax * -0.02);
2663 if (tout && !mConfig.inputHistogramsOnly && k == 0) {
2664 e->Write();
2665 }
2666 if (qcout && !mConfig.shipToQCAsCanvas) {
2667 qcout->Add(e);
2668 }
2669 if (!mConfig.enableLocalOutput && !mConfig.shipToQCAsCanvas) {
2670 continue;
2671 }
2672
2673 e->SetLineColor(colorNums[numColor++ % COLORCOUNT]);
2674 e->Draw(k == 0 ? "" : "same");
2675 }
2676 if (!mConfig.enableLocalOutput && !mConfig.shipToQCAsCanvas) {
2677 continue;
2678 }
2679 can->cd();
2680 }
2681 if (qcout) {
2682 qcout->Add(can);
2683 }
2684 if (!mConfig.enableLocalOutput) {
2685 continue;
2686 }
2687
2688 can->Print(Form(p ? "%s/pull_integral.pdf" : "%s/res_integral.pdf", mConfig.plotsDir.c_str()));
2689 if (mConfig.writeFileExt != "") {
2690 can->Print(Form(p ? "%s/pull_integral.%s" : "%s/res_integral.%s", mConfig.plotsDir.c_str(), mConfig.writeFileExt.c_str()));
2691 }
2692 }
2693 }
2694
2695 uint64_t attachClusterCounts[N_CLS_HIST];
2696 if (mQATasks & taskClusterAttach) {
2697 // Process Cluster Attachment Histograms
2698 if (mConfig.inputHistogramsOnly == 0) {
2699 for (int32_t i = N_CLS_HIST; i < N_CLS_TYPE * N_CLS_HIST - 1; i++) {
2700 mClusters[i]->Sumw2(true);
2701 }
2702 double totalVal = 0;
2703 if (!CLUST_HIST_INT_SUM) {
2704 for (int32_t j = 0; j < mClusters[N_CLS_HIST - 1]->GetXaxis()->GetNbins() + 2; j++) {
2705 totalVal += mClusters[N_CLS_HIST - 1]->GetBinContent(j);
2706 }
2707 }
2708 if (totalVal == 0.) {
2709 totalVal = 1.;
2710 }
2711 for (int32_t i = 0; i < N_CLS_HIST; i++) {
2712 double val = 0;
2713 for (int32_t j = 0; j < mClusters[i]->GetXaxis()->GetNbins() + 2; j++) {
2714 val += mClusters[i]->GetBinContent(j);
2715 mClusters[2 * N_CLS_HIST - 1 + i]->SetBinContent(j, val / totalVal);
2716 }
2717 attachClusterCounts[i] = val;
2718 }
2719
2720 if (!CLUST_HIST_INT_SUM) {
2721 for (int32_t i = 0; i < N_CLS_HIST; i++) {
2722 mClusters[2 * N_CLS_HIST - 1 + i]->SetMaximum(1.02);
2723 mClusters[2 * N_CLS_HIST - 1 + i]->SetMinimum(-0.02);
2724 }
2725 }
2726
2727 for (int32_t i = 0; i < N_CLS_HIST - 1; i++) {
2728 auto oldLevel = gErrorIgnoreLevel;
2729 gErrorIgnoreLevel = kError;
2730 mClusters[N_CLS_HIST + i]->Divide(mClusters[i], mClusters[N_CLS_HIST - 1], 1, 1, "B");
2731 gErrorIgnoreLevel = oldLevel;
2732 mClusters[N_CLS_HIST + i]->SetMinimum(-0.02);
2733 mClusters[N_CLS_HIST + i]->SetMaximum(1.02);
2734 }
2735 }
2736
2737 float tmpMax[2] = {0, 0}, tmpMin[2] = {0, 0};
2738 for (int32_t l = 0; l <= CLUST_HIST_INT_SUM; l++) {
2739 for (int32_t k = 0; k < ConfigNumInputs; k++) {
2740 TH1* e = mClusters[l ? (N_CLS_TYPE * N_CLS_HIST - 2) : (N_CLS_HIST - 1)];
2741 if (GetHist(e, tin, k, nNewInput) == nullptr) {
2742 continue;
2743 }
2744 e->SetMinimum(-1111);
2745 e->SetMaximum(-1111);
2746 if (l == 0) {
2747 e->GetXaxis()->SetRange(2, AXIS_BINS[4]);
2748 }
2749 if (e->GetMaximum() > tmpMax[l]) {
2750 tmpMax[l] = e->GetMaximum();
2751 }
2752 if (e->GetMinimum() < tmpMin[l]) {
2753 tmpMin[l] = e->GetMinimum();
2754 }
2755 }
2756 for (int32_t k = 0; k < ConfigNumInputs; k++) {
2757 for (int32_t i = 0; i < N_CLS_HIST; i++) {
2758 TH1* e = mClusters[l ? (2 * N_CLS_HIST - 1 + i) : i];
2759 if (GetHist(e, tin, k, nNewInput) == nullptr) {
2760 continue;
2761 }
2762 e->SetMaximum(tmpMax[l] * 1.02);
2763 e->SetMinimum(tmpMax[l] * -0.02);
2764 }
2765 }
2766 }
2767
2768 for (int32_t i = 0; i < N_CLS_TYPE; i++) {
2769 if (mConfig.enableLocalOutput || mConfig.shipToQCAsCanvas) {
2770 mPClust[i]->cd();
2771 mPClust[i]->SetLogx();
2772 }
2773 int32_t begin = i == 2 ? (2 * N_CLS_HIST - 1) : i == 1 ? N_CLS_HIST : 0;
2774 int32_t end = i == 2 ? (3 * N_CLS_HIST - 1) : i == 1 ? (2 * N_CLS_HIST - 1) : N_CLS_HIST;
2775 int32_t numColor = 0;
2776 for (int32_t k = 0; k < ConfigNumInputs; k++) {
2777 for (int32_t j = end - 1; j >= begin; j--) {
2778 TH1* e = mClusters[j];
2779 if (GetHist(e, tin, k, nNewInput) == nullptr) {
2780 continue;
2781 }
2782
2783 e->SetTitle(CLUSTER_TITLES[i]);
2784 e->GetYaxis()->SetTitle(i == 0 ? "Number of TPC clusters" : i == 1 ? "Fraction of TPC clusters" : CLUST_HIST_INT_SUM ? "Total TPC clusters (integrated)" : "Fraction of TPC clusters (integrated)");
2785 e->GetXaxis()->SetTitle("#it{p}_{Tmc} (GeV/#it{c})");
2786 e->GetXaxis()->SetTitleOffset(1.1);
2787 e->GetXaxis()->SetLabelOffset(-0.005);
2788 if (tout && !mConfig.inputHistogramsOnly && k == 0) {
2789 e->Write();
2790 }
2791 e->SetStats(kFALSE);
2792 e->SetLineWidth(1);
2793 e->SetLineStyle(CONFIG_DASHED_MARKERS ? j + 1 : 1);
2794 if (i == 0) {
2795 e->GetXaxis()->SetRange(2, AXIS_BINS[4]);
2796 }
2797 if (qcout && !mConfig.shipToQCAsCanvas) {
2798 qcout->Add(e);
2799 }
2800 if (!mConfig.enableLocalOutput && !mConfig.shipToQCAsCanvas) {
2801 continue;
2802 }
2803
2804 e->SetMarkerColor(kBlack);
2805 e->SetLineColor(colorNums[numColor++ % COLORCOUNT]);
2806 e->Draw(j == end - 1 && k == 0 ? "" : "same");
2807 GetName(fname, k);
2808 mLClust[i]->AddEntry(e, Form("%s%s", fname, CLUSTER_NAMES[j - begin]), "l");
2809 }
2810 }
2811 if (ConfigNumInputs == 1) {
2812 TH1* e = reinterpret_cast<TH1F*>(mClusters[begin + CL_att_adj]->Clone());
2813 e->Add(mClusters[begin + CL_prot], -1);
2814 if (qcout && !mConfig.shipToQCAsCanvas) {
2815 qcout->Add(e);
2816 }
2817 if (!mConfig.enableLocalOutput && !mConfig.shipToQCAsCanvas) {
2818 continue;
2819 }
2820
2821 e->SetLineColor(colorNums[numColor++ % COLORCOUNT]);
2822 e->Draw("same");
2823 mLClust[i]->AddEntry(e, "Removed (Strategy A)", "l");
2824 }
2825 if (!mConfig.enableLocalOutput && !mConfig.shipToQCAsCanvas) {
2826 continue;
2827 }
2828
2829 mLClust[i]->Draw();
2830
2831 if (qcout) {
2832 qcout->Add(mCClust[i]);
2833 }
2834 if (!mConfig.enableLocalOutput) {
2835 continue;
2836 }
2837 doPerfFigure(i == 0 ? 0.37 : (i == 1 ? 0.34 : 0.6), 0.295, 0.030);
2838 mCClust[i]->cd();
2839 mCClust[i]->Print(Form(i == 2 ? "%s/clusters_integral.pdf" : i == 1 ? "%s/clusters_relative.pdf" : "%s/clusters.pdf", mConfig.plotsDir.c_str()));
2840 if (mConfig.writeFileExt != "") {
2841 mCClust[i]->Print(Form(i == 2 ? "%s/clusters_integral.%s" : i == 1 ? "%s/clusters_relative.%s" : "%s/clusters.%s", mConfig.plotsDir.c_str(), mConfig.writeFileExt.c_str()));
2842 }
2843 }
2844
2845 for (int32_t i = 0; i < 3; i++) {
2846 auto* e = mPadRow[i];
2847 if (tout && !mConfig.inputHistogramsOnly) {
2848 e->Write();
2849 }
2850 mPPadRow[i]->cd();
2851 e->SetOption("colz");
2852 e->SetTitle(i == 2 ? "First Track Pad Row (row_{MC} = 0, row_{trk} > 0)" : "First Track Pad Row");
2853 e->GetXaxis()->SetTitle(i ? "#Phi (sector)" : "First MC Pad Row");
2854 e->GetYaxis()->SetTitle("First Pad Row");
2855 e->Draw();
2856 mCPadRow[i]->cd();
2857 static const constexpr char* PADROW_NAMES[3] = {"MC", "Phi", "Phi1"};
2858 mCPadRow[i]->Print(Form("%s/padRow%s.pdf", mConfig.plotsDir.c_str(), PADROW_NAMES[i]));
2859 if (mConfig.writeFileExt != "") {
2860 mCPadRow[i]->Print(Form("%s/padRow%s.%s", mConfig.plotsDir.c_str(), PADROW_NAMES[i], mConfig.writeFileExt.c_str()));
2861 }
2862 }
2863 }
2864
2865 // Process cluster count statistics
2866 if ((mQATasks & taskClusterCounts) && !mHaveExternalHists && !mConfig.clusterRejectionHistograms && !mConfig.inputHistogramsOnly) {
2867 DoClusterCounts(attachClusterCounts);
2868 }
2869 if ((qcout || tout) && (mQATasks & taskClusterCounts) && mConfig.clusterRejectionHistograms) {
2870 for (uint32_t i = 0; i < mHistClusterCount.size(); i++) {
2871 if (tout) {
2872 mHistClusterCount[i]->Write();
2873 }
2874 if (qcout) {
2875 qcout->Add(mHistClusterCount[i]);
2876 }
2877 }
2878 }
2879
2880 if (mQATasks & taskTrackStatistics) {
2881 // Process track statistic histograms
2882 float tmpMax = 0.;
2883 for (int32_t k = 0; k < ConfigNumInputs; k++) { // TODO: Simplify this drawing, avoid copy&paste
2884 TH1F* e = mTracks;
2885 if (GetHist(e, tin, k, nNewInput) == nullptr) {
2886 continue;
2887 }
2888 e->SetMaximum(-1111);
2889 if (e->GetMaximum() > tmpMax) {
2890 tmpMax = e->GetMaximum();
2891 }
2892 }
2893 mPTracks->cd();
2894 mPTracks->SetLogx();
2895 for (int32_t k = 0; k < ConfigNumInputs; k++) {
2896 TH1F* e = mTracks;
2897 if (GetHist(e, tin, k, nNewInput) == nullptr) {
2898 continue;
2899 }
2900 if (tout && !mConfig.inputHistogramsOnly && k == 0) {
2901 e->Write();
2902 }
2903 e->SetMaximum(tmpMax * 1.02);
2904 e->SetMinimum(tmpMax * -0.02);
2905 e->SetStats(kFALSE);
2906 e->SetLineWidth(1);
2907 e->SetTitle("Number of Tracks vs #it{p}_{T}");
2908 e->GetYaxis()->SetTitle("Number of Tracks");
2909 e->GetXaxis()->SetTitle("#it{p}_{T} (GeV/#it{c})");
2910 if (qcout) {
2911 qcout->Add(e);
2912 }
2913 e->SetMarkerColor(kBlack);
2914 e->SetLineColor(colorNums[k % COLORCOUNT]);
2915 e->Draw(k == 0 ? "" : "same");
2916 GetName(fname, k, mConfig.inputHistogramsOnly);
2917 mLTracks->AddEntry(e, Form(mConfig.inputHistogramsOnly ? "%s" : "%sTrack #it{p}_{T}", fname), "l");
2918 }
2919 mLTracks->Draw();
2920 doPerfFigure(0.63, 0.7, 0.030);
2921 mCTracks->cd();
2922 mCTracks->Print(Form("%s/tracks.pdf", mConfig.plotsDir.c_str()));
2923 if (mConfig.writeFileExt != "") {
2924 mCTracks->Print(Form("%s/tracks.%s", mConfig.plotsDir.c_str(), mConfig.writeFileExt.c_str()));
2925 }
2926
2927 for (int32_t i = 0; i < 2; i++) {
2928 tmpMax = 0.;
2929 for (int32_t k = 0; k < ConfigNumInputs; k++) {
2930 TH1F* e = mT0[i];
2931 if (GetHist(e, tin, k, nNewInput) == nullptr) {
2932 continue;
2933 }
2934 e->SetMaximum(-1111);
2935 if (e->GetMaximum() > tmpMax) {
2936 tmpMax = e->GetMaximum();
2937 }
2938 }
2939 mPT0[i]->cd();
2940 for (int32_t k = 0; k < ConfigNumInputs; k++) {
2941 TH1F* e = mT0[i];
2942 if (GetHist(e, tin, k, nNewInput) == nullptr) {
2943 continue;
2944 }
2945 if (tout && !mConfig.inputHistogramsOnly && k == 0) {
2946 e->Write();
2947 }
2948 e->SetMaximum(tmpMax * 1.02);
2949 e->SetMinimum(tmpMax * -0.02);
2950 e->SetStats(kFALSE);
2951 e->SetLineWidth(1);
2952 e->SetTitle(i ? "Track t_{0} resolution" : "Track t_{0} distribution");
2953 e->GetYaxis()->SetTitle("a.u.");
2954 e->GetXaxis()->SetTitle(i ? "t_{0} - t_{0, mc}" : "t_{0}");
2955 if (qcout) {
2956 qcout->Add(e);
2957 }
2958 e->SetMarkerColor(kBlack);
2959 e->SetLineColor(colorNums[k % COLORCOUNT]);
2960 e->Draw(k == 0 ? "" : "same");
2961 GetName(fname, k, mConfig.inputHistogramsOnly);
2962 mLT0[i]->AddEntry(e, Form(mConfig.inputHistogramsOnly ? "%s (%s)" : "%sTrack t_{0} %s", fname, i ? "" : "resolution"), "l");
2963 }
2964 mLT0[i]->Draw();
2965 doPerfFigure(0.63, 0.7, 0.030);
2966 mCT0[i]->cd();
2967 mCT0[i]->Print(Form("%s/t0%s.pdf", mConfig.plotsDir.c_str(), i ? "_res" : ""));
2968 if (mConfig.writeFileExt != "") {
2969 mCT0[i]->Print(Form("%s/t0%s.%s", mConfig.plotsDir.c_str(), i ? "_res" : "", mConfig.writeFileExt.c_str()));
2970 }
2971
2972 tmpMax = 0.;
2973 for (int32_t k = 0; k < ConfigNumInputs; k++) {
2974 TH1F* e = mNCl[i];
2975 if (GetHist(e, tin, k, nNewInput) == nullptr) {
2976 continue;
2977 }
2978 e->SetMaximum(-1111);
2979 if (e->GetMaximum() > tmpMax) {
2980 tmpMax = e->GetMaximum();
2981 }
2982 }
2983 mPNCl[i]->cd();
2984 for (int32_t k = 0; k < ConfigNumInputs; k++) {
2985 TH1F* e = mNCl[i];
2986 if (GetHist(e, tin, k, nNewInput) == nullptr) {
2987 continue;
2988 }
2989 if (tout && !mConfig.inputHistogramsOnly && k == 0) {
2990 e->Write();
2991 }
2992 e->SetMaximum(tmpMax * 1.02);
2993 e->SetMinimum(tmpMax * -0.02);
2994 e->SetStats(kFALSE);
2995 e->SetLineWidth(1);
2996 e->SetTitle(i ? "Number of Rows with attached Cluster" : "Number of Clusters");
2997 e->GetYaxis()->SetTitle("a.u.");
2998 e->GetXaxis()->SetTitle(i ? "N_{Rows with Clusters}" : "N_{Clusters}");
2999 if (qcout) {
3000 qcout->Add(e);
3001 }
3002 e->SetMarkerColor(kBlack);
3003 e->SetLineColor(colorNums[k % COLORCOUNT]);
3004 e->Draw(k == 0 ? "" : "same");
3005 GetName(fname, k, mConfig.inputHistogramsOnly);
3006 mLNCl[i]->AddEntry(e, Form(mConfig.inputHistogramsOnly ? "%s" : (i ? "%sN_{Clusters}" : "%sN_{Rows with Clusters}"), fname), "l");
3007 }
3008 mLNCl[i]->Draw();
3009 doPerfFigure(0.6, 0.7, 0.030);
3010 mCNCl[i]->cd();
3011 mCNCl[i]->Print(Form("%s/nClusters%s.pdf", mConfig.plotsDir.c_str(), i ? "_corrected" : ""));
3012 if (mConfig.writeFileExt != "") {
3013 mCNCl[i]->Print(Form("%s/nClusters%s.%s", mConfig.plotsDir.c_str(), i ? "_corrected" : "", mConfig.writeFileExt.c_str()));
3014 }
3015 }
3016
3017 mPClXY->cd();
3018 mClXY->SetOption("colz");
3019 mClXY->Draw();
3020 mCClXY->cd();
3021 mCClXY->Print(Form("%s/clustersXY.pdf", mConfig.plotsDir.c_str()));
3022 if (mConfig.writeFileExt != "") {
3023 mCClXY->Print(Form("%s/clustersXY.%s", mConfig.plotsDir.c_str(), mConfig.writeFileExt.c_str()));
3024 }
3025
3026 if (mQATasks & taskClusterCounts) {
3027 mClRej[2]->Divide(mClRej[1], mClRej[0]);
3028
3029 for (int32_t i = 0; i < 3; i++) {
3030 if (tout && !mConfig.inputHistogramsOnly) {
3031 mClRej[i]->Write();
3032 }
3033 mPClRej[i]->cd();
3034 mClRej[i]->SetTitle(REJECTED_NAMES[i]);
3035 mClRej[i]->SetOption("colz");
3036 mClRej[i]->Draw();
3037 mCClRej[i]->cd();
3038 mCClRej[i]->Print(Form("%s/clustersRej%d%s.pdf", mConfig.plotsDir.c_str(), i, REJECTED_NAMES[i]));
3039 if (mConfig.writeFileExt != "") {
3040 mCClRej[i]->Print(Form("%s/clustersRej%d%s.%s", mConfig.plotsDir.c_str(), i, REJECTED_NAMES[i], mConfig.writeFileExt.c_str()));
3041 }
3042 }
3043
3044 mPClRejP->cd();
3045 for (int32_t k = 0; k < ConfigNumInputs; k++) {
3046 auto* tmp = mClRej[0];
3047 if (GetHist(tmp, tin, k, nNewInput) == nullptr) {
3048 continue;
3049 }
3050 TH1D* proj1 = tmp->ProjectionY(Form("clrejptmp1%d", k)); // TODO: Clean up names
3051 proj1->SetDirectory(nullptr);
3052 tmp = mClRej[1];
3053 if (GetHist(tmp, tin, k, nNewInput) == nullptr) {
3054 continue;
3055 }
3056 TH1D* proj2 = tmp->ProjectionY(Form("clrejptmp2%d", k));
3057 proj2->SetDirectory(nullptr);
3058
3059 auto* e = mClRejP;
3060 if (GetHist(e, tin, k, nNewInput) == nullptr) {
3061 continue;
3062 }
3063 e->Divide(proj2, proj1);
3064 if (tout && !mConfig.inputHistogramsOnly && k == 0) {
3065 e->Write();
3066 }
3067 delete proj1;
3068 delete proj2;
3069 e->SetMinimum(-0.02);
3070 e->SetMaximum(0.22);
3071 e->SetTitle("Rejected Clusters");
3072 e->GetXaxis()->SetTitle("Pad Row");
3073 e->GetYaxis()->SetTitle("Rejected Clusters (fraction)");
3074 e->Draw(k == 0 ? "" : "same");
3075 }
3076 mPClRejP->Print(Form("%s/clustersRejProjected.pdf", mConfig.plotsDir.c_str()));
3077 if (mConfig.writeFileExt != "") {
3078 mPClRejP->Print(Form("%s/clustersRejProjected.%s", mConfig.plotsDir.c_str(), mConfig.writeFileExt.c_str()));
3079 }
3080 }
3081 }
3082
3083 if (tout && !mConfig.inputHistogramsOnly && mConfig.writeMCLabels) {
3084 gInterpreter->GenerateDictionary("vector<vector<int32_t>>", "");
3085 tout->WriteObject(&mcEffBuffer, "mcEffBuffer");
3086 tout->WriteObject(&mcLabelBuffer, "mcLabelBuffer");
3087 remove("AutoDict_vector_vector_int__.cxx");
3088 remove("AutoDict_vector_vector_int___cxx_ACLiC_dict_rdict.pcm");
3089 remove("AutoDict_vector_vector_int___cxx.d");
3090 remove("AutoDict_vector_vector_int___cxx.so");
3091 }
3092
3093 if (tout) {
3094 tout->Close();
3095 }
3096 for (uint32_t i = 0; i < mConfig.compareInputs.size(); i++) {
3097 tin[i]->Close();
3098 }
3099 if (!qcout) {
3100 clearGarbagageCollector();
3101 }
3102 GPUInfo("GPU TPC QA histograms have been written to pdf%s%s files", mConfig.writeFileExt == "" ? "" : " and ", mConfig.writeFileExt.c_str());
3103 gErrorIgnoreLevel = oldRootIgnoreLevel;
3104 return (0);
3105}
3106
3107void GPUQA::PrintClusterCount(int32_t mode, int32_t& num, const char* name, uint64_t n, uint64_t normalization)
3108{
3109 if (mode == 2) {
3110 // do nothing, just count num
3111 } else if (mode == 1) {
3112 char name2[128];
3113 snprintf(name2, 128, "clusterCount%d_", num);
3114 char* ptr = name2 + strlen(name2);
3115 for (uint32_t i = 0; i < strlen(name); i++) {
3116 if ((name[i] >= 'a' && name[i] <= 'z') || (name[i] >= 'A' && name[i] <= 'Z') || (name[i] >= '0' && name[i] <= '9')) {
3117 *(ptr++) = name[i];
3118 }
3119 }
3120 *ptr = 0;
3121 createHist(mHistClusterCount[num], name2, name, 1000, 0, mConfig.histMaxNClusters, 1000, 0, 100);
3122 } else if (mode == 0) {
3123 if (normalization && mConfig.enableLocalOutput) {
3124 printf("\t%40s: %'12" PRIu64 " (%6.2f%%)\n", name, n, 100.f * n / normalization);
3125 }
3126 if (mConfig.clusterRejectionHistograms) {
3127 float ratio = 100.f * n / std::max<uint64_t>(normalization, 1);
3128 mHistClusterCount[num]->Fill(normalization, ratio, 1);
3129 }
3130 }
3131 num++;
3132}
3133
3134int32_t GPUQA::DoClusterCounts(uint64_t* attachClusterCounts, int32_t mode)
3135{
3136 int32_t num = 0;
3137 if (mcPresent() && (mQATasks & taskClusterAttach) && attachClusterCounts) {
3138 for (int32_t i = 0; i < N_CLS_HIST; i++) { // TODO: Check that these counts are still printed correctly!
3139 PrintClusterCount(mode, num, CLUSTER_NAMES[i], attachClusterCounts[i], mClusterCounts.nTotal);
3140 }
3141 PrintClusterCount(mode, num, "Unattached", attachClusterCounts[N_CLS_HIST - 1] - attachClusterCounts[CL_att_adj], mClusterCounts.nTotal);
3142 PrintClusterCount(mode, num, "Removed (Strategy A)", attachClusterCounts[CL_att_adj] - attachClusterCounts[CL_prot], mClusterCounts.nTotal); // Attached + Adjacent (also fake) - protected
3143 PrintClusterCount(mode, num, "Unaccessible", mClusterCounts.nUnaccessible, mClusterCounts.nTotal); // No contribution from track >= 10 MeV, unattached or fake-attached/adjacent
3144 } else {
3145 PrintClusterCount(mode, num, "All Clusters", mClusterCounts.nTotal, mClusterCounts.nTotal);
3146 PrintClusterCount(mode, num, "Used in Physics", mClusterCounts.nPhysics, mClusterCounts.nTotal);
3147 PrintClusterCount(mode, num, "Protected", mClusterCounts.nProt, mClusterCounts.nTotal);
3148 PrintClusterCount(mode, num, "Unattached", mClusterCounts.nUnattached, mClusterCounts.nTotal);
3149 PrintClusterCount(mode, num, "Removed (Strategy A)", mClusterCounts.nTotal - mClusterCounts.nUnattached - mClusterCounts.nProt, mClusterCounts.nTotal);
3150 PrintClusterCount(mode, num, "Removed (Strategy B)", mClusterCounts.nTotal - mClusterCounts.nProt, mClusterCounts.nTotal);
3151 }
3152
3153 PrintClusterCount(mode, num, "Merged Loopers (Track Merging)", mClusterCounts.nMergedLooperConnected, mClusterCounts.nTotal);
3154 PrintClusterCount(mode, num, "Merged Loopers (Afterburner)", mClusterCounts.nMergedLooperUnconnected, mClusterCounts.nTotal);
3155 PrintClusterCount(mode, num, "Looping Legs (other)", mClusterCounts.nLoopers, mClusterCounts.nTotal);
3156 PrintClusterCount(mode, num, "High Inclination Angle", mClusterCounts.nHighIncl, mClusterCounts.nTotal);
3157 PrintClusterCount(mode, num, "Rejected", mClusterCounts.nRejected, mClusterCounts.nTotal);
3158 PrintClusterCount(mode, num, "Tube (> 200 MeV)", mClusterCounts.nTube, mClusterCounts.nTotal);
3159 PrintClusterCount(mode, num, "Tube (< 200 MeV)", mClusterCounts.nTube200, mClusterCounts.nTotal);
3160 PrintClusterCount(mode, num, "Low Pt < 50 MeV", mClusterCounts.nLowPt, mClusterCounts.nTotal);
3161 PrintClusterCount(mode, num, "Low Pt < 200 MeV", mClusterCounts.n200MeV, mClusterCounts.nTotal);
3162
3163 if (mcPresent() && (mQATasks & taskClusterAttach)) {
3164 PrintClusterCount(mode, num, "Tracks > 400 MeV", mClusterCounts.nAbove400, mClusterCounts.nTotal);
3165 PrintClusterCount(mode, num, "Fake Removed (> 400 MeV)", mClusterCounts.nFakeRemove400, mClusterCounts.nAbove400);
3166 PrintClusterCount(mode, num, "Full Fake Removed (> 400 MeV)", mClusterCounts.nFullFakeRemove400, mClusterCounts.nAbove400);
3167 PrintClusterCount(mode, num, "Tracks < 40 MeV", mClusterCounts.nBelow40, mClusterCounts.nTotal);
3168 PrintClusterCount(mode, num, "Fake Protect (< 40 MeV)", mClusterCounts.nFakeProtect40, mClusterCounts.nBelow40);
3169 }
3170 if (mcPresent() && (mQATasks & taskTrackStatistics)) {
3171 PrintClusterCount(mode, num, "Correctly Attached all-trk normalized", mClusterCounts.nCorrectlyAttachedNormalized, mClusterCounts.nTotal);
3172 PrintClusterCount(mode, num, "Correctly Attached non-fake normalized", mClusterCounts.nCorrectlyAttachedNormalizedNonFake, mClusterCounts.nTotal);
3173 }
3174 return num;
3175}
3176
3177void* GPUQA::AllocateScratchBuffer(size_t nBytes)
3178{
3179 mTrackingScratchBuffer.resize((nBytes + sizeof(mTrackingScratchBuffer[0]) - 1) / sizeof(mTrackingScratchBuffer[0]));
3180 return mTrackingScratchBuffer.data();
3181}
std::vector< std::string > labels
A const (ready only) version of MCTruthContainer.
Helper class to access correction maps.
int16_t charge
Definition RawEventData.h:5
int32_t i
#define TPC_MAX_TIME_BIN_TRIGGERED
#define TRACK_EXPECTED_REFERENCE_X_DEFAULT
Definition GPUQA.cxx:206
#define TRACK_EXPECTED_REFERENCE_X
Definition GPUQA.cxx:261
#define QA_DEBUG
Definition GPUQA.cxx:15
#define QA_TIMING
Definition GPUQA.cxx:16
int16_t Color_t
Definition GPUQA.h:32
GPUChain * chain
#define GPUCA_NSECTORS
#define GPUCA_ROW_COUNT
Definition of the MCTrack class.
Definition of the Names Generator class.
uint16_t pos
Definition RawData.h:3
uint32_t j
Definition RawData.h:0
uint32_t side
Definition RawData.h:0
uint16_t pid
Definition RawData.h:2
uint32_t c
Definition RawData.h:2
Definition of TPCFastTransform class.
TBranch * ptr
int nClusters
double num
Class for time synchronization of RawReader instances.
static constexpr ID TPC
Definition DetID.h:64
static constexpr int32_t NSECTORS
Definition GPUChain.h:58
int32_t ReadO2MCData(const char *filename)
Definition GPUQA.h:54
bool clusterRemovable(int32_t attach, bool prot) const
Definition GPUQA.h:52
~GPUQA()=default
Definition GPUQA.cxx:339
void * AllocateScratchBuffer(size_t nBytes)
Definition GPUQA.h:55
void SetMCTrackRange(int32_t min, int32_t max)
Definition GPUQA.h:47
mcLabelI_t GetMCTrackLabel(uint32_t trackId) const
Definition GPUQA.h:51
int32_t DrawQAHistograms()
Definition GPUQA.h:46
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
static GPUROOTDump< T, Args... > getNew(const char *name1, Names... names)
Definition GPUROOTDump.h:64
static DigitizationContext * loadFromFile(std::string_view filename="")
GLdouble n
Definition glcorearb.h:1982
GLfloat GLfloat GLfloat alpha
Definition glcorearb.h:279
GLint GLenum GLint x
Definition glcorearb.h:403
const GLfloat * m
Definition glcorearb.h:4066
GLenum mode
Definition glcorearb.h:266
GLenum src
Definition glcorearb.h:1767
GLuint GLfloat GLfloat GLfloat GLfloat y1
Definition glcorearb.h:5034
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLuint end
Definition glcorearb.h:469
const GLdouble * v
Definition glcorearb.h:832
GLuint const GLchar * name
Definition glcorearb.h:781
GLdouble f
Definition glcorearb.h:310
GLuint GLuint GLfloat weight
Definition glcorearb.h:5477
GLenum GLint * range
Definition glcorearb.h:1899
GLint y
Definition glcorearb.h:270
GLenum GLenum dst
Definition glcorearb.h:1767
GLboolean * data
Definition glcorearb.h:298
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
GLuint GLfloat * val
Definition glcorearb.h:1582
GLboolean r
Definition glcorearb.h:1233
GLenum GLfloat param
Definition glcorearb.h:271
GLuint id
Definition glcorearb.h:650
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
float float float y2
Definition MathUtils.h:44
constexpr int LHCBCPERTIMEBIN
Definition Constants.h:38
Enum< T >::Iterator begin(Enum< T >)
Definition Defs.h:173
value_T f3
Definition TrackUtils.h:93
value_T f1
Definition TrackUtils.h:91
value_T f2
Definition TrackUtils.h:92
struct o2::upgrades_utils::@454 tracks
structure to keep trigger-related info
Defining DataPointCompositeObject explicitly as copiable.
std::string filename()
bool isValid(std::string alias)
int64_t differenceInBC(const InteractionRecord &other) const
std::tuple< std::vector< std::unique_ptr< TCanvas > >, std::vector< std::unique_ptr< TLegend > >, std::vector< std::unique_ptr< TPad > >, std::vector< std::unique_ptr< TLatex > >, std::vector< std::unique_ptr< TH1D > > > v
Definition GPUQA.cxx:317
IR getFirstIRofTF(const IR &rec) const
get 1st IR of TF corresponding to the 1st sampled orbit (in MC)
Definition HBFUtils.h:71
IR getFirstIR() const
Definition HBFUtils.h:47
constexpr size_t min
constexpr size_t max
o2::InteractionRecord ir(0, 0)
vec clear()
o2::InteractionRecord ir0(3, 5)