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