CbmRoot
Loading...
Searching...
No Matches
CbmLitFitQaReport.cxx
Go to the documentation of this file.
1/* Copyright (C) 2012-2016 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer], Timur Ablyazimov */
4
10#include "CbmLitFitQaReport.h"
11
12#include "CbmDrawHist.h"
13#include "CbmHistManager.h"
14#include "CbmReportElement.h"
15#include "CbmUtils.h"
16#include "TCanvas.h"
17#include "TDirectory.h"
18#include "TF1.h"
19#include "TH1.h"
20#include "TLatex.h"
21#include "TPad.h"
22#include "TStyle.h"
23
24#include <boost/assign/list_of.hpp>
25
26#include <map>
27
28using boost::assign::list_of;
30using Cbm::Split;
31using std::map;
32using std::string;
33using std::vector;
34
36
38
40{
41 Out().precision(3);
42 Out() << R()->DocumentBegin();
43 Out() << R()->Title(0, GetTitle());
44
45 Out() << R()->TableBegin("Residuals and pulls (standard deviation)",
46 list_of("")("x")("y")("tx")("ty")("q/p")("x")("y")("tx")("ty")("q/p"));
47 Out() << PrintResAndPullRow("STS first", "htf_Sts_FirstParam_(Res|Pull)_.+", "sigma");
48 Out() << PrintResAndPullRow("STS last", "htf_Sts_LastParam_(Res|Pull)_.+", "sigma");
49 Out() << PrintResAndPullRow("TRD first", "htf_Trd_FirstParam_(Res|Pull)_.+", "sigma");
50 Out() << PrintResAndPullRow("TRD last", "htf_Trd_LastParam_(Res|Pull)_.+", "sigma");
51 Out() << PrintResAndPullRow("MUCH first", "htf_Much_FirstParam_(Res|Pull)_.+", "sigma");
52 Out() << PrintResAndPullRow("MUCH last", "htf_Much_LastParam_(Res|Pull)_.+", "sigma");
53 Out() << R()->TableEnd();
54
55 Out() << R()->TableBegin("Residuals and pulls (RMS)",
56 list_of("")("x")("y")("tx")("ty")("q/p")("x")("y")("tx")("ty")("q/p"));
57 Out() << PrintResAndPullRow("STS first", "htf_Sts_FirstParam_(Res|Pull)_.+", "rms");
58 Out() << PrintResAndPullRow("STS last", "htf_Sts_LastParam_(Res|Pull)_.+", "rms");
59 Out() << PrintResAndPullRow("TRD first", "htf_Trd_FirstParam_(Res|Pull)_.+", "rms");
60 Out() << PrintResAndPullRow("TRD last", "htf_Trd_LastParam_(Res|Pull)_.+", "rms");
61 Out() << PrintResAndPullRow("MUCH first", "htf_Much_FirstParam_(Res|Pull)_.+", "rms");
62 Out() << PrintResAndPullRow("MUCH last", "htf_Much_LastParam_(Res|Pull)_.+", "rms");
63 Out() << R()->TableEnd();
64
65 Out() << R()->TableBegin("Residuals and pulls (mean)",
66 list_of("")("x")("y")("tx")("ty")("q/p")("x")("y")("tx")("ty")("q/p"));
67 Out() << PrintResAndPullRow("STS first", "htf_Sts_FirstParam_(Res|Pull)_.+", "mean");
68 Out() << PrintResAndPullRow("STS last", "htf_Sts_LastParam_(Res|Pull)_.+", "mean");
69 Out() << PrintResAndPullRow("TRD first", "htf_Trd_FirstParam_(Res|Pull)_.+", "mean");
70 Out() << PrintResAndPullRow("TRD last", "htf_Trd_LastParam_(Res|Pull)_.+", "mean");
71 Out() << PrintResAndPullRow("MUCH first", "htf_Much_FirstParam_(Res|Pull)_.+", "mean");
72 Out() << PrintResAndPullRow("MUCH last", "htf_Much_LastParam_(Res|Pull)_.+", "mean");
73 Out() << R()->TableEnd();
74
76
77 Out() << R()->DocumentEnd();
78}
79
80string CbmLitFitQaReport::PrintResAndPullRow(const string& rowName, const string& pattern, const string& propertyName)
81{
82 // Maps parameter name to cell index
83 static map<string, Int_t> ctc;
84 ctc["X"] = 0;
85 ctc["Y"] = 1;
86 ctc["Tx"] = 2;
87 ctc["Ty"] = 3;
88 ctc["Qp"] = 4;
89
90 vector<TH2*> histos = HM()->H2Vector(pattern);
91 Int_t nofHistos = histos.size();
92 if (nofHistos == 0) return "";
93 vector<string> parameters(nofHistos);
94 for (UInt_t iHist = 0; iHist < histos.size(); iHist++) {
95 vector<string> split = Split(histos[iHist]->GetName(), '_');
96 TH1D* py = histos[iHist]->ProjectionY();
97
98 Int_t parIndex = (split[3] == "Res") ? (ctc[split[4]]) : (ctc[split[4]] + 5);
99 if (propertyName == "mean") {
100 parameters[parIndex] = NumberToString<Float_t>(py->GetMean(), 2);
101 }
102 else if (propertyName == "rms") {
103 parameters[parIndex] = NumberToString<Float_t>(py->GetRMS(), 2);
104 }
105 else if (propertyName == "sigma") {
106 py->Fit("gaus", "RQ");
107 TF1* fit = py->GetFunction("gaus");
108 parameters[parIndex] = NumberToString<Float_t>((NULL != fit) ? fit->GetParameter(2) : 0., 2);
109 }
110 }
111 return R()->TableRow(list_of(rowName).range(parameters));
112}
113
115{
116 // 1D
117 DrawResidualAndPullHistograms("Sts", false);
118 DrawResidualAndPullHistograms("Trd", false);
119 DrawResidualAndPullHistograms("Much", false);
120
121 // 2D vs momentum
124 DrawResidualAndPullHistograms("Much", true);
125
126 DrawTrackParams("Sts");
127 DrawTrackParams("Trd");
128 DrawTrackParams("Much");
129
132}
133
134void CbmLitFitQaReport::DrawHistSigmaRMS(Double_t sigma, Double_t rms)
135{
136 string txt1 = Cbm::NumberToString<Double_t>(sigma, 2) + " / " + Cbm::NumberToString<Double_t>(rms, 2);
137 TLatex text;
138 text.SetTextAlign(21);
139 text.SetTextSize(0.08);
140 text.DrawTextNDC(0.5, 0.83, txt1.c_str());
141}
142
143void CbmLitFitQaReport::DrawResidualAndPullHistograms(const string& detName, Bool_t draw2D)
144{
145 string parameterNames[] = {"X", "Y", "Tx", "Ty", "Qp"};
146 string catNames[] = {"Res", "Pull", "WrongCov"};
147
148 if (!HM()->Exists("htf_" + detName + "_FirstParam_Res_X")) return;
149
150 // [0] - for the first track parameter, [1] - for the last track parameter
151 for (Int_t i = 0; i < 2; i++) {
152 string trackParamName = (i == 0) ? "FirstParam" : "LastParam";
153
154 string canvasName = "fit_qa_" + detName + "_" + trackParamName;
155 if (draw2D) canvasName += "_2d";
156 TCanvas* canvas = CreateCanvas(canvasName.c_str(), canvasName.c_str(), 1400, 900);
157 canvas->Divide(5, 3);
158
159 // [0] - "Res", [1] - "Pull", [2] - "WrongCov"
160 for (Int_t iCat = 0; iCat < 3; iCat++) {
161 for (Int_t iPar = 0; iPar < 5; iPar++) {
162 string histName = "htf_" + detName + "_" + trackParamName + "_" + catNames[iCat] + "_" + parameterNames[iPar];
163 if (!HM()->Exists(histName)) return;
164 Int_t histId = iCat * 5 + iPar;
165 canvas->cd(histId + 1);
166 TH2* hist2D = HM()->H2(histName);
167
168 if (draw2D) {
169 DrawH2WithProfile(hist2D, false, false, "COLZ", kBlack, 3);
170 }
171 else {
172 TH1* hist = (TH1D*) hist2D->ProjectionY()->Clone();
173 DrawH1(hist, kLinear, kLog);
174
175 if (histId < 10) { // Fit only residual and pull histograms
176 hist->Fit("gaus", "RQ");
177 hist->SetMaximum(hist->GetMaximum() * 1.50);
178 TF1* fit = hist->GetFunction("gaus");
179 Double_t sigma = (NULL != fit) ? fit->GetParameter(2) : 0.;
180 Double_t rms = hist->GetRMS();
181 DrawHistSigmaRMS(sigma, rms);
182 }
183 }
184 }
185 }
186 }
187}
188
189void CbmLitFitQaReport::DrawTrackParams(const string& detName)
190{
191 if (!HM()->Exists("htp_" + detName + "_FirstParam_X")) return;
192 for (Int_t i = 0; i < 2; i++) {
193 string trackParamName = (i == 0) ? "FirstParam" : "LastParam";
194 string canvasName = string("fit_qa_track_params_" + detName + trackParamName);
195 TCanvas* canvas = CreateCanvas(canvasName.c_str(), canvasName.c_str(), 2000, 1000);
196 canvas->Divide(4, 2);
197 string pattern = string("htp_") + detName + "_" + trackParamName + "_.+";
198 vector<TH1*> histos = HM()->H1Vector(pattern);
199 Int_t nofHistos = histos.size();
200 for (Int_t iHist = 0; iHist < nofHistos; iHist++) {
201 canvas->cd(iHist + 1);
202 DrawH1(histos[iHist]);
203 gPad->SetGridx(true);
204 gPad->SetGridy(true);
205 }
206 }
207}
208
210{
211 TCanvas* canvas1 = CreateCanvas("fit_qa_momentum_momres_mom_2D", "fit_qa_momentum_momres_mom_2D", 600, 600);
212 canvas1->cd(1);
213 DrawH2(HM()->H2("htf_MomRes_Mom"));
214 gPad->SetGridx(true);
215 gPad->SetGridy(true);
216
217 TCanvas* canvas2 = CreateCanvas("fit_qa_momentum_projection", "fit_qa_momentum_projection", 600, 600);
218 canvas2->cd(1);
219 TH1* projY = HM()->H2("htf_MomRes_Mom")->ProjectionY("htf_MomRes_Mom_ProjectionY");
220 DrawH1(projY, kLinear, kLinear);
221 projY->SetStats(true);
222 projY->Fit("gaus", "RQ");
223 projY->SetMaximum(projY->GetMaximum() * 1.25);
224 gPad->SetGridx(true);
225 gPad->SetGridy(true);
226
227 TCanvas* canvas3 = CreateCanvas("fit_qa_momentum_momres_mom_sigma", "fit_qa_momentum_momres_mom_sigma", 600, 600);
228 canvas3->cd(1);
229 HM()->H2("htf_MomRes_Mom")->FitSlicesY();
230 TH1* momslice = gDirectory->Get<TH1>("htf_MomRes_Mom_2");
231 momslice->GetXaxis()->SetTitle("P [GeV/c]");
232 momslice->GetYaxis()->SetTitle("dP/P, #sigma [%]");
233 momslice->SetMinimum(0.);
234 momslice->SetMaximum(3.);
235 DrawH1(momslice, kLinear, kLinear);
236 gPad->SetGridx(true);
237 gPad->SetGridy(true);
238
239 TCanvas* canvas4 = CreateCanvas("fit_qa_momentum_momres_mom_rms", "fit_qa_momentum_momres_mom_rms", 600, 600);
240 canvas4->cd(1);
241 TH2* hMomres = HM()->H2("htf_MomRes_Mom");
242 Int_t nBins = hMomres->GetNbinsX();
243 TH1* momResRms = hMomres->ProjectionX();
244 for (Int_t i = 1; i < nBins; i++) {
245 projY = hMomres->ProjectionY("_py", i, i);
246 Double_t rms = projY->GetRMS();
247 momResRms->SetBinContent(i, rms);
248 momResRms->SetBinError(i, momslice->GetBinError(i));
249 }
250 momResRms->GetXaxis()->SetTitle("P [GeV/c]");
251 momResRms->GetYaxis()->SetTitle("dP/P, RMS [%]");
252 momResRms->SetMinimum(0.);
253 momResRms->SetMaximum(3.);
254 DrawH1(momResRms, kLinear, kLinear, "P");
255 gPad->SetGridx(true);
256 gPad->SetGridy(true);
257
258 TCanvas* canvas5 = CreateCanvas("fit_qa_chi_primary", "fit_qa_chi_primary", 600, 600);
259 canvas5->cd(1);
260 TH1* hChiprim = HM()->H1("htf_ChiPrimary");
261 hChiprim->Scale(1. / hChiprim->Integral());
262 DrawH1(hChiprim, kLinear, kLog);
263 gPad->SetGridx(true);
264 gPad->SetGridy(true);
265}
266
268{
269 const char* histNames[] = {"htp_PrimaryVertexResidualPx", "htp_PrimaryVertexResidualPy",
270 "htp_PrimaryVertexResidualPz", "htp_PrimaryVertexPullPx",
271 "htp_PrimaryVertexPullPy", "htp_PrimaryVertexPullPz"};
272 TCanvas* canvas = CreateCanvas("Momentum at primary vertex residuals and pulls",
273 "Momentum at primary vertex residuals and pulls", 900, 600);
274 canvas->Divide(3, 2);
275
276 for (Int_t i = 0; i < 2; ++i) {
277 for (Int_t j = 0; j < 3; ++j) {
278 Int_t histId = i * 3 + j;
279 canvas->cd(histId + 1);
280 TH1* hist = HM()->H1(histNames[histId]);
281 DrawH1(hist, kLinear, kLinear);
282 hist->SetStats(true);
283 hist->Fit("gaus");
284 gStyle->SetOptFit(1);
285 }
286 }
287
288 const char* histNames2[] = {"htp_PrimaryVertexResidualTx", "htp_PrimaryVertexResidualTy",
289 "htp_PrimaryVertexResidualQp", "htp_PrimaryVertexPullTx",
290 "htp_PrimaryVertexPullTy", "htp_PrimaryVertexPullQp"};
291 TCanvas* canvas2 = CreateCanvas("Tangents and Qp at primary vertex residuals and pulls",
292 "Tangents and Qp at primary vertex residuals and pulls", 900, 600);
293 canvas2->Divide(3, 2);
294
295 for (Int_t i = 0; i < 2; ++i) {
296 for (Int_t j = 0; j < 3; ++j) {
297 Int_t histId = i * 3 + j;
298 canvas2->cd(histId + 1);
299 TH1* hist = HM()->H1(histNames2[histId]);
300 DrawH1(hist, kLinear, kLinear);
301 hist->SetStats(true);
302 hist->Fit("gaus");
303 gStyle->SetOptFit(1);
304 }
305 }
306}
307
ClassImp(CbmConverterManager)
void DrawH2WithProfile(TH2 *hist, Bool_t doGaussFit, Bool_t drawOnlyMean, const string &drawOpt2D, Int_t profileColor, Int_t profileLineWidth)
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)
Helper functions for drawing 1D and 2D histograms and graphs.
@ kLinear
Definition CbmDrawHist.h:69
@ kLog
Definition CbmDrawHist.h:68
Histogram manager.
Create report for fit QA.
Abstract class for basic report elements (headers, tables, images etc.).
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.
std::vector< TH2 * > H2Vector(const std::vector< std::string > &names) const
Return vector of pointers to TH2 histogram.
TH1 * H1(const std::string &name) const
Return pointer to TH1 histogram.
Create report for fit QA.
void DrawResidualAndPullHistograms(const string &detName, Bool_t draw2D)
virtual void Create()
Inherited from CbmSimulationReport.
CbmLitFitQaReport()
Constructor.
void DrawTrackParams(const string &detName)
string PrintResAndPullRow(const string &rowName, const string &histName, const string &propertyName)
virtual void Draw()
Inherited from CbmSimulationReport.
void DrawHistSigmaRMS(Double_t sigma, Double_t rms)
Draw sigma and RMS on histogram.
virtual ~CbmLitFitQaReport()
Destructor.
virtual std::string TableRow(const std::vector< std::string > &row) const =0
Return string with table row tags.
virtual std::string Title(int size, const std::string &title) const =0
Return string with title.
virtual std::string TableBegin(const std::string &caption, const std::vector< std::string > &colNames) const =0
Return string with table open tag.
virtual std::string DocumentBegin() const =0
Return string with open tags for document.
virtual std::string TableEnd() const =0
Return string with table close tag.
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 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
Base class for simulation reports.
TH2 * H2(const std::string &name) const
Return pointer to TH2 histogram.
CbmHistManager * HM() const
Return pointer to Histogram manager.
vector< string > Split(const string &name, char delimiter)
Definition CbmUtils.cxx:67
std::string NumberToString(const T &value, int precision=1)
Definition CbmUtils.h:34