CbmRoot
Loading...
Searching...
No Matches
CbmQaCheckerProfile1DHandler.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
11
14#include "Logger.h"
15#include "TCanvas.h"
16#include "TError.h"
17#include "TFolder.h"
18#include "TGraphAsymmErrors.h"
19#include "TLegend.h"
20#include "TMath.h"
21#include "TMultiGraph.h"
22#include "TObject.h"
23#include "TProfile.h"
24#include "TRatioPlot.h"
25#include "TStyle.h"
26
27#include <limits>
28
30
31// ---------------------------------------------------------------------------------------------------------------------
32//
33Profile1DHandler::Profile1DHandler(int iObject, int iFile, int iDataset) : Hist1DHandler(iObject, iFile, iDataset) {}
34
35// ---------------------------------------------------------------------------------------------------------------------
36//
38{
39 int nVersions = fpObjDB->GetNofVersions();
40 int iDef = fpObjDB->GetDefaultID();
41
42 // ----- Option parsing
43 std::string sOption = opt;
44 for (auto& ch : sOption) {
45 ch = std::tolower(ch);
46 }
47 bool bDrawRatio = sOption.find("r") != std::string::npos;
48 bool bDrawDiff = sOption.find("d") != std::string::npos;
49
50 // Axis titles
51 TString xAxisTitle = static_cast<TProfile*>(fvpObjects[0])->GetXaxis()->GetTitle();
52 TString yAxisTitle = static_cast<TProfile*>(fvpObjects[0])->GetYaxis()->GetTitle();
53
54 // Original histograms
55 {
56 TString sCanvN = fsBaseName + "_cmp_canvas";
57 TString sCanvT = TString("Comparison result for \"") + fsBaseName + "\"";
58 fpCanvasCmp = std::make_shared<TCanvas>(sCanvN, sCanvT, 500, 500);
59 fpCanvasCmp->SetMargin(0.20, 0.05, 0.20, 0.10);
60 fpCanvasCmp->cd();
61 auto* pMultiGraphOrig = new TMultiGraph(fsBaseName.c_str(), fvpObjects[0]->GetTitle());
62 for (int iV = 0; iV < nVersions; ++iV) {
63 auto* pCopy = new TGraphAsymmErrors((TH1*) fvpObjects[iV]);
64 pCopy->SetMarkerStyle(20);
65 pCopy->SetTitle(fpObjDB->GetVersionLabel(iV).c_str());
66 pMultiGraphOrig->Add(pCopy, "P");
67 }
68 pMultiGraphOrig->GetXaxis()->SetTitle(xAxisTitle);
69 pMultiGraphOrig->GetYaxis()->SetTitle(yAxisTitle);
70 pMultiGraphOrig->Draw("A pmc plc");
71 fpCanvasCmp->BuildLegend();
72 }
73
74 auto* pDefault = static_cast<TProfile*>(fvpObjects[iDef])->ProjectionX();
75
76 // Histogram ratios to default
77 if (bDrawRatio) {
78 TString sCanvN = fsBaseName + "_ratio_canvas";
79 TString sCanvT = TString("Comparison result for \"") + fsBaseName + "\" (ratio)";
80 fpCanvasRat = std::make_shared<TCanvas>(sCanvN, sCanvT, 500, 500);
81 fpCanvasRat->SetMargin(0.20, 0.05, 0.20, 0.10);
82 fpCanvasRat->cd();
83 TString titleRatio = Form("Ratio to %s", fpObjDB->GetVersionLabel(iDef).c_str());
84 auto* pMultiGraphRatio = new TMultiGraph((fsBaseName + "_ratio").c_str(), titleRatio);
85 for (int iV = 0; iV < nVersions; ++iV) {
86 if (iV == iDef) {
87 continue;
88 }
89 auto* pRatio = static_cast<TProfile*>(fvpObjects[iV])->ProjectionX();
90 auto currErrorLevel = gErrorIgnoreLevel;
91 gErrorIgnoreLevel = kError;
92 auto* pCopy = new TGraphAsymmErrors(pRatio, pDefault, "pois");
93 gErrorIgnoreLevel = currErrorLevel;
94 pCopy->GetYaxis()->SetTitle("ratio");
95 pCopy->SetTitle(fpObjDB->GetVersionLabel(iV).c_str());
96 pCopy->SetMarkerStyle(20);
97 pMultiGraphRatio->Add(pCopy, "P");
98 if (pRatio) {
99 delete pRatio;
100 pRatio = nullptr;
101 }
102 }
103 pMultiGraphRatio->GetXaxis()->SetTitle(xAxisTitle);
104 pMultiGraphRatio->GetYaxis()->SetTitle("ratio");
105 pMultiGraphRatio->Draw("A pmc plc");
106 fpCanvasRat->BuildLegend();
107 }
108
109 // Histogram ratios to default
110 if (bDrawDiff) {
111 TString sCanvN = fsBaseName + "_diff_canvas";
112 TString sCanvT = TString("Comparison result for \"") + fsBaseName + "\" (ratio)";
113 fpCanvasDiff = std::make_shared<TCanvas>(sCanvN, sCanvT, 500, 500);
114 fpCanvasDiff->SetMargin(0.20, 0.05, 0.20, 0.10);
115 fpCanvasDiff->cd();
116 TString titleDiff = Form("Difference from %s", fpObjDB->GetVersionLabel(iDef).c_str());
117 auto* pMultiGraphDiff = new TMultiGraph((fsBaseName + "_diff").c_str(), titleDiff);
118 for (int iV = 0; iV < nVersions; ++iV) {
119 if (iV == iDef) {
120 continue;
121 }
122 auto* pDiff = static_cast<TProfile*>(fvpObjects[iV])->ProjectionX();
123 pDiff->Add(pDefault, -1.);
124 auto* pCopy = new TGraphAsymmErrors(pDiff);
125 pCopy->GetYaxis()->SetTitle("difference");
126 pCopy->SetTitle(fpObjDB->GetVersionLabel(iV).c_str());
127 pCopy->SetMarkerStyle(20);
128 pMultiGraphDiff->Add(pCopy, "P");
129 if (pDiff) {
130 delete pDiff;
131 pDiff = nullptr;
132 }
133 }
134 pMultiGraphDiff->GetXaxis()->SetTitle(xAxisTitle);
135 pMultiGraphDiff->GetYaxis()->SetTitle("difference");
136 pMultiGraphDiff->Draw("A pmc plc");
137 fpCanvasDiff->BuildLegend();
138 }
139
140 if (pDefault) {
141 delete pDefault;
142 pDefault = nullptr;
143 }
144}
Handler class for 1D-histograms (including TProfile objects) (declaration)
Handler class for 1D-profiles (implementation)
Common definitions for QA-Checker framework.
Profile1DHandler(int iObject, int iFile, int iDataset)
Constructor.
Hist1DHandler(int iObject, int iFile, int iDataset)
Constructor.
std::string fsBaseName
Base names of the object.
std::shared_ptr< TCanvas > fpCanvasCmp
Comparison canvas: plots together.
std::shared_ptr< TCanvas > fpCanvasDiff
Comparison canvas: difference with default.
std::shared_ptr< ObjectDB > fpObjDB
Pointer to object database.
std::shared_ptr< TCanvas > fpCanvasRat
Comparison canvas: ratios to default.
std::vector< TNamed * > fvpObjects
Vector of objects.
Specification of the handler for TProfile class.
void CreateCanvases(Option_t *opt="") override
Creates object comparison canvas.