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