CbmRoot
Loading...
Searching...
No Matches
CbmLitFieldApproximationQaReport.cxx
Go to the documentation of this file.
1/* Copyright (C) 2011-2020 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer] */
4
11
12#include "CbmDrawHist.h"
13#include "CbmHistManager.h"
14#include "CbmReportElement.h"
15#include "CbmUtils.h"
16#include "TCanvas.h"
17#include "TGraph2D.h"
18#include "TH1.h"
19#include "TH2.h"
20
21#include <TLegend.h>
22
23#include <boost/assign/list_inserter.hpp>
24#include <boost/assign/list_of.hpp>
25
26#include <cassert>
27using boost::assign::list_of;
28using boost::assign::push_back;
30using Cbm::Split;
31using Cbm::ToString;
32using std::string;
33using std::vector;
34
36
38
40{
41 Out() << R()->DocumentBegin() << std::endl;
42 Out() << R()->Title(0, "Magnetic field QA") << std::endl;
45 Out() << R()->DocumentEnd();
46}
47
49{
50 std::stringstream ss;
51 //
52 // int nofSlices = fQa.get("NofSlices", -1.);
53 // assert(nofSlices > 0);
54 // int nofPolynoms = fQa.get("NofPolynoms", -1.);
55 // assert(nofPolynoms > 0);
56 //
57 // const Int_t nerr = 4; // number of errors [absMean, absRMS, relMean, relRMS]
58 // std::vector<string> colNames = list_of("")("Grid")("Grid")("Grid")("Grid");
59 // for (int i = 0; i < nofPolynoms; i++) {
60 // std::string pol = ToString<int>(i);
61 // int degree = fQa.get("slice0.polynomial" + pol + ".degree", -1.);
62 // assert(degree > 0);
63 // std::string colName = "Polynomial" + ToString<int>(degree);
64 // push_back(colNames).repeat(nerr, colName);
65 // }
66 // ss << R()->TableBegin("Summary table", colNames);
67 //
68 // std::vector<string> colErrNames(1, "");
69 // for (int i = 0; i < nofPolynoms + 1; i++) {
70 // push_back(colErrNames)("abs mean")("abs RMS")("rel mean")("rel RMS");
71 // }
72 // ss << R()->TableRow(colErrNames);
73 //
74 // std::string vnames[4] = {"BX", "BY", "BZ", "MOD"};
75 // for (Int_t iSlice = 0; iSlice < nofSlices; iSlice++) {
76 // std::string slice = "slice" + ToString<Int_t>(iSlice);
77 // std::string sliceZ = ToString<float>(fQa.get(slice + ".Z", -1));
78 // int nSpanCols = 1 + (nofPolynoms + 1) * nerr;
79 // ss << R()->TableEmptyRow(nSpanCols, slice + " Z=" + sliceZ + " cm");
80 // std::string prefix = slice + ".grid";
81 // for (Int_t v = 0; v < 4; v++) {
82 // std::vector<std::string> row;
83 // row.push_back(vnames[v]);
84 // row.push_back(ToString<float>(fQa.get(prefix + ".err." + vnames[v] + ".abs.mean", -1.)));
85 // row.push_back(ToString<float>(fQa.get(prefix + ".err." + vnames[v] + ".abs.rms", -1.)));
86 // row.push_back(ToString<float>(fQa.get(prefix + ".err." + vnames[v] + ".rel.mean", -1.)));
87 // row.push_back(ToString<float>(fQa.get(prefix + ".err." + vnames[v] + ".rel.rms", -1.)));
88 //
89 // for (Int_t iPolynom = 0; iPolynom < nofPolynoms; iPolynom++) {
90 // std::string prefix = slice + ".polynomial" + ToString<Int_t>(iPolynom);
91 // row.push_back(ToString<float>(fQa.get(prefix + ".err." + vnames[v] + ".abs.mean", -1.)));
92 // row.push_back(ToString<float>(fQa.get(prefix + ".err." + vnames[v] + ".abs.rms", -1.)));
93 // row.push_back(ToString<float>(fQa.get(prefix + ".err." + vnames[v] + ".rel.mean", -1.)));
94 // row.push_back(ToString<float>(fQa.get(prefix + ".err." + vnames[v] + ".rel.rms", -1.)));
95 // }
96 // ss << R()->TableRow(row);
97 // }
98 // }
99 // ss << R()->TableEnd();
100 //
101 return ss.str();
102}
103
105{
106 // Set draw styles
108
109 // DrawSlices("Bx", "Apr");
110 // DrawSlices("By", "Apr");
111 // DrawSlices("Bz", "Apr");
112 // DrawSlices("Mod", "Apr");
113 DrawApr("RelErr");
114 DrawApr("Err");
115
116 DrawSlices("Bx", "Grid");
117 DrawSlices("By", "Grid");
118 DrawSlices("Bz", "Grid");
119 DrawSlices("Mod", "Grid");
120}
121
122void CbmLitFieldApproximationQaReport::DrawSlices(const string& b, const string& m)
123{
124 vector<TGraph2D*> graphs2D = HM()->G2Vector("hfa_" + b + "_Graph2D_.*");
125 for (UInt_t i = 0; i < graphs2D.size(); i++) {
126 string name = graphs2D[i]->GetName();
127 string canvasName = GetReportName() + "_slice_" + b + "_" + m + "_at_z_" + Split(name, '_')[3];
128 TCanvas* canvas = CreateCanvas(canvasName.c_str(), canvasName.c_str(), 1000, 1000);
129 canvas->Divide(3, 2);
130 TGraph2D* aprGraph = HM()->G2(FindAndReplace(name, "_" + b + "_", "_" + b + m + "_"));
131 TH1* errH1 = HM()->H1(FindAndReplace(name, "_" + b + "_Graph2D_", "_" + b + "Err" + m + "_H1_"));
132 TH2* errH2 = HM()->H2(FindAndReplace(name, "_" + b + "_Graph2D_", "_" + b + "Err" + m + "_H2_"));
133 TH1* relErrH1 = HM()->H1(FindAndReplace(name, "_" + b + "_Graph2D_", "_" + b + "RelErr" + m + "_H1_"));
134 TH2* relErrH2 = HM()->H2(FindAndReplace(name, "_" + b + "_Graph2D_", "_" + b + "RelErr" + m + "_H2_"));
135 canvas->cd(1);
136 DrawGraph2D(graphs2D[i]);
137 canvas->cd(2);
138 DrawH1(errH1);
139 canvas->cd(3);
140 DrawH2(errH2);
141 canvas->cd(4);
142 DrawGraph2D(aprGraph);
143 canvas->cd(5);
144 DrawH1(relErrH1);
145 canvas->cd(6);
146 DrawH2(relErrH2);
147 }
148}
149
151{
152 vector<TGraph2D*> graphs2D = HM()->G2Vector("hfa_Bx_Graph2D_.*");
153 for (UInt_t i = 0; i < graphs2D.size(); i++) {
154 string z = Split(graphs2D[i]->GetName(), '_')[3];
155 string canvasName = GetReportName() + "_" + err + "_degree_z_" + z;
156 TCanvas* canvas = CreateCanvas(canvasName.c_str(), canvasName.c_str(), 1000, 1000);
157 canvas->Divide(3, 2);
158
159 TLegend* l1 = new TLegend(0.1, 0.1, 0.9, 0.9);
160 l1->SetFillColor(kWhite);
161 l1->SetTextSize(0.1);
162 l1->SetLineWidth(1);
163 l1->SetHeader("Polynomial degree");
164
165 Double_t maxBx = std::numeric_limits<Double_t>::min();
166 Double_t maxBy = std::numeric_limits<Double_t>::min();
167 Double_t maxBz = std::numeric_limits<Double_t>::min();
168 Double_t maxMod = std::numeric_limits<Double_t>::min();
169 vector<TH1*> errBx = HM()->H1Vector("hfa_Bx" + err + "Apr_H1_" + z + "_.*");
170 if (errBx.empty()) return;
171 vector<TH1*> errBy(errBx.size());
172 vector<TH1*> errBz(errBx.size());
173 vector<TH1*> errMod(errBx.size());
174 for (UInt_t iP = 0; iP < errBx.size(); iP++) {
175 string name = errBx[iP]->GetName();
176
177 errBy[iP] = HM()->H1(FindAndReplace(name, "_Bx", "_By"));
178 errBz[iP] = HM()->H1(FindAndReplace(name, "_Bx", "_Bz"));
179 errMod[iP] = HM()->H1(FindAndReplace(name, "_Bx", "_Mod"));
180 string draw_opt = (iP == 0) ? "" : "SAME";
181 canvas->cd(2);
182 DrawH1(errBx[iP], kLinear, kLog, draw_opt.c_str(), 1 + iP, CbmDrawingOptions::LineWidth(), 1 + iP,
184 canvas->cd(3);
185 DrawH1(errBy[iP], kLinear, kLog, draw_opt.c_str(), 1 + iP, CbmDrawingOptions::LineWidth(), 1 + iP,
187 canvas->cd(5);
188 DrawH1(errBz[iP], kLinear, kLog, draw_opt.c_str(), 1 + iP, CbmDrawingOptions::LineWidth(), 1 + iP,
190 canvas->cd(6);
191 DrawH1(errMod[iP], kLinear, kLog, draw_opt.c_str(), 1 + iP, CbmDrawingOptions::LineWidth(), 1 + iP,
193
194 string degree = Split(name, '_')[4];
195 l1->AddEntry(errBx[iP], degree.c_str(), "lp");
196
197 maxBx = std::max(maxBx, errBx[iP]->GetMaximum());
198 maxBy = std::max(maxBy, errBy[iP]->GetMaximum());
199 maxBz = std::max(maxBz, errBz[iP]->GetMaximum());
200 maxMod = std::max(maxMod, errMod[iP]->GetMaximum());
201 }
202 errBx[0]->SetMaximum(1.1 * maxBx);
203 errBy[0]->SetMaximum(1.1 * maxBy);
204 errBz[0]->SetMaximum(1.1 * maxBz);
205 errMod[0]->SetMaximum(1.1 * maxMod);
206
207 canvas->cd(1);
208 l1->Draw();
209 }
210}
211
ClassImp(CbmConverterManager)
void SetDefaultDrawStyle()
void DrawH1(TH1 *hist, HistScale logx, HistScale logy, const string &drawOpt, Int_t color, Int_t lineWidth, Int_t lineStyle, Int_t markerSize, Int_t markerStyle)
void DrawH2(TH2 *hist, HistScale logx, HistScale logy, HistScale logz, const string &drawOpt)
void DrawGraph2D(TGraph2D *graph, HistScale logx, HistScale logy, HistScale logz, const string &drawOpt)
Helper functions for drawing 1D and 2D histograms and graphs.
@ kLinear
Definition CbmDrawHist.h:69
@ kLog
Definition CbmDrawHist.h:68
Histogram manager.
Creates field QA report.
Abstract class for basic report elements (headers, tables, images etc.).
static Int_t MarkerSize()
Definition CbmDrawHist.h:49
static Int_t LineWidth()
Definition CbmDrawHist.h:45
TGraph2D * G2(const std::string &name) const
Return pointer to TGraph2D.
std::vector< TGraph2D * > G2Vector(const std::vector< std::string > &names) const
Return vector of pointers to TGraph2D.
std::vector< TH1 * > H1Vector(const std::vector< std::string > &names) const
Return vector of pointers to TH1 histogram.
TH2 * H2(const std::string &name) const
Return pointer to TH2 histogram.
TH1 * H1(const std::string &name) const
Return pointer to TH1 histogram.
std::string PrintSummaryTable()
Return string with summary table for field QA.
void DrawApr(const std::string &err)
Draw comparison for different polynomial orders for each slice.
virtual void Draw()
Inherited from CbmSimulationReport.
virtual void Create()
Inherited from CbmSimulationReport.
void DrawSlices(const std::string &component, const std::string &opt)
Draw canvas with histograms for each approximated slice.
virtual std::string Title(int size, const std::string &title) const =0
Return string with title.
virtual std::string DocumentBegin() const =0
Return string with open tags for document.
virtual std::string DocumentEnd() const =0
Return string with close tags of the document.
std::ostream & Out() const
All text output goes to this stream.
Definition CbmReport.h:66
void SetReportName(const std::string &name)
Definition CbmReport.h:69
void PrintCanvases() const
Print images created from canvases in the report.
const std::string & GetReportName() const
Definition CbmReport.h:74
const CbmReportElement * R() const
Accessor to CbmReportElement object. User has to write the report using available tags from CbmReport...
Definition CbmReport.h:61
TCanvas * CreateCanvas(const char *name, const char *title, Int_t ww, Int_t wh)
Create canvas and put it to vector of TCanvases. Canvases created with this function will be automati...
Definition CbmReport.cxx:94
CbmHistManager * HM() const
Return pointer to Histogram manager.
string FindAndReplace(const string &name, const string &oldSubstr, const string &newSubstr)
Definition CbmUtils.cxx:59
vector< string > Split(const string &name, char delimiter)
Definition CbmUtils.cxx:67
std::string ToString(const T &value)
Definition CbmUtils.h:26