CbmRoot
Loading...
Searching...
No Matches
CbmLitTrackingQaStudyReport.cxx
Go to the documentation of this file.
1/* Copyright (C) 2011-2014 UGiessen/JINR-LIT, Giessen/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Semen Lebedev [committer], Andrey Lebedev */
4
11
12#include "CbmDrawHist.h"
13#include "CbmHistManager.h"
14#include "CbmReportElement.h"
15#include "CbmUtils.h"
16#include "TCanvas.h"
17#include "TH1.h"
18#include "TLine.h"
19
20#include <boost/assign/list_of.hpp>
21
22#include <vector>
23using boost::assign::list_of;
26using Cbm::Split;
27using std::vector;
28
29string DefaultRowNameFormatter(const string& name) { return name; }
30
31string EventNoRowNameFormatter(const string& name) { return Split(name, '_')[1]; }
32
33string NofObjectsRowNameFormatter(const string& name) { return Split(name, '_')[2]; }
34
35string TrackHitsRowNameFormatter(const string& name)
36{
37 vector<string> split = Split(name, '_');
38 return split[1] + ":" + split[3];
39}
40
41string NofGhostsRowNameFormatter(const string& name) { return Split(name, '_')[2]; }
42
43string EventNoCellFormatter(const TH1* hist, Int_t /* nofEvents */)
44{
45 return NumberToString<Double_t>(hist->GetEntries());
46}
47
48string NofObjectsCellFormatter(const TH1* hist, Int_t /* nofEvents */)
49{
50 return NumberToString<Double_t>(hist->GetMean());
51}
52
53string TrackHitsCellFormatter(const TH1* hist, Int_t /* nofEvents */)
54{
55 return NumberToString<Double_t>(hist->GetMean());
56}
57
58string NofGhostsCellFormatter(const TH1* hist, Int_t nofEvents)
59{
60 return NumberToString<Double_t>(hist->GetEntries() / nofEvents);
61}
62
63
65{
66 SetReportName("tracking_qa_study");
67 SetReportTitle("Tracking QA study report");
68}
69
71
73{
74 Out().precision(3);
75 Out() << R()->DocumentBegin();
76 Out() << R()->Title(0, GetTitle());
77
78 Out() << PrintTable("Number of events", "hen_EventNo_TrackingQa", EventNoRowNameFormatter, EventNoCellFormatter);
79 Out() << PrintTable("Number of objects per event", "hno_NofObjects_.+", NofObjectsRowNameFormatter,
81 Out() << PrintTable("Number of all, true and fake hits in tracks and rings", "hth_.+_TrackHits_.*",
83 Out() << PrintTable("Number of ghosts", "hng_NofGhosts_.+", NofGhostsRowNameFormatter, NofGhostsCellFormatter);
84 Out() << PrintEfficiencyTable("Tracking efficiency with RICH", "hte_.*Rich.*_Eff_p");
85 Out() << PrintEfficiencyTable("Tracking efficiency w/o RICH", "hte_((?!Rich).)*_Eff_p");
87 Out() << R()->DocumentEnd();
88}
89
90string CbmLitTrackingQaStudyReport::PrintTable(const string& tableName, const string& pattern,
91 string (*rowNameFormatter)(const string&),
92 string (*cellFormatter)(const TH1*, Int_t)) const
93{
94 Int_t nofStudies = HM().size();
95 vector<vector<TH1*>> histos(nofStudies);
96 for (Int_t i = 0; i < nofStudies; i++) {
97 histos[i] = HM(i)->H1Vector(pattern);
98 }
99 string str = R()->TableBegin(tableName, list_of(string("")).range(GetStudyNames()));
100 for (UInt_t iHist = 0; iHist < histos[0].size(); iHist++) {
101 string cellName = rowNameFormatter(histos[0][iHist]->GetName());
102 vector<string> cells(nofStudies);
103 for (Int_t i = 0; i < nofStudies; i++) {
104 Int_t nofEvents = HM(i)->H1("hen_EventNo_TrackingQa")->GetEntries();
105 cells[i] = cellFormatter(histos[i][iHist], nofEvents);
106 }
107 str += R()->TableRow(list_of(cellName).range(cells));
108 }
109 str += R()->TableEnd();
110 return str;
111}
112
113string CbmLitTrackingQaStudyReport::PrintEfficiencyTable(const string& tableName, const string& pattern) const
114{
115 Int_t nofStudies = HM().size();
116 vector<vector<TH1*>> histos(nofStudies); // = fHM->H1Vector(effRegex);
117 for (Int_t i = 0; i < nofStudies; i++) {
118 histos[i] = HM(i)->H1Vector(pattern);
119 }
120 string str = R()->TableBegin(tableName, list_of(string("")).range(GetStudyNames()));
121
122 for (UInt_t iHist = 0; iHist != histos[0].size(); iHist++) {
123 vector<string> split = Split(histos[0][iHist]->GetName(), '_');
124 string cellName = split[1] + "(" + split[2] + "):" + split[3];
125 vector<string> cells(nofStudies);
126 for (Int_t i = 0; i < nofStudies; i++) {
127 Int_t nofEvents = HM(i)->H1("hen_EventNo_TrackingQa")->GetEntries();
128 string effName = histos[0][iHist]->GetName();
129 string accName = FindAndReplace(effName, "_Eff_", "_Acc_");
130 string recName = FindAndReplace(effName, "_Eff_", "_Rec_");
131 Double_t acc = HM(i)->H1(accName)->GetEntries() / nofEvents;
132 Double_t rec = HM(i)->H1(recName)->GetEntries() / nofEvents;
133 Double_t eff = (acc != 0.) ? 100. * rec / acc : 0.;
134 string accStr = NumberToString<Double_t>(acc);
135 string recStr = NumberToString<Double_t>(rec);
136 string effStr = NumberToString<Double_t>(eff);
137 cells[i] = effStr + "(" + recStr + "/" + accStr + ")";
138 }
139 str += R()->TableRow(list_of(cellName).range(cells));
140 }
141 str += R()->TableEnd();
142 return str;
143}
144
151
153{
154 string histNamePattern = "hte_.+_.+_(All|Electron|Muon)_Eff_(p|Angle)";
155 vector<TH1*> histos = HM()[0]->H1Vector(histNamePattern);
156 for (UInt_t i = 0; i < histos.size(); i++) {
157 string histName = histos[i]->GetName();
158 DrawEfficiency("tracking_qa_study_" + histName, histName);
159 }
160
161 histNamePattern = "hte_.+_.+_(All|Electron|Muon)_Acc_(p|Angle)";
162 histos = HM()[0]->H1Vector(histNamePattern);
163 for (UInt_t i = 0; i < histos.size(); i++) {
164 string histName = histos[i]->GetName();
165 DrawAccAndRec("tracking_qa_study_" + histName, histName);
166 }
167
168 histNamePattern = "hte_.+_.+_(All|Electron|Muon)_Rec_(p|Angle)";
169 histos = HM()[0]->H1Vector(histNamePattern);
170 for (UInt_t i = 0; i < histos.size(); i++) {
171 string histName = histos[i]->GetName();
172 DrawAccAndRec("tracking_qa_study_" + histName, histName);
173 }
174}
175
176void CbmLitTrackingQaStudyReport::DrawEfficiency(const string& canvasName, const string& histName)
177{
178 TCanvas* canvas = CreateCanvas(canvasName.c_str(), canvasName.c_str(), 600, 500);
179 canvas->SetGrid();
180 canvas->cd();
181
182 Int_t nofStudies = HM().size();
183 vector<string> labels(nofStudies);
184 vector<TH1*> histos(nofStudies);
185 vector<Double_t> efficiencies(nofStudies);
186 for (Int_t iStudy = 0; iStudy < nofStudies; iStudy++) {
187 CbmHistManager* hm = HM()[iStudy];
188 histos[iStudy] = hm->H1(histName);
189 efficiencies[iStudy] = CalcEfficiency(hm->H1(FindAndReplace(histName, "_Eff_", "_Rec_")),
190 hm->H1(FindAndReplace(histName, "_Eff_", "_Acc_")), 100.);
191 labels[iStudy] = GetStudyName(iStudy) + "(" + NumberToString<Double_t>(efficiencies[iStudy], 1) + ")";
192 }
193
194 DrawH1(histos, labels, kLinear, kLinear, true, 0.3, 0.3, 0.85, 0.6, "PE1");
195 DrawMeanEfficiencyLines(histos, efficiencies);
196}
197
198void CbmLitTrackingQaStudyReport::DrawAccAndRec(const string& canvasName, const string& histName)
199{
200 TCanvas* canvas = CreateCanvas(canvasName.c_str(), canvasName.c_str(), 600, 500);
201 canvas->SetGrid();
202 canvas->cd();
203
204 Int_t nofStudies = HM().size();
205 vector<string> labels(nofStudies);
206 vector<TH1*> histos(nofStudies);
207 for (Int_t iStudy = 0; iStudy < nofStudies; iStudy++) {
208 CbmHistManager* hm = HM()[iStudy];
209 Int_t nofEvents = hm->H1("hen_EventNo_TrackingQa")->GetEntries();
210 histos[iStudy] = hm->H1(histName);
211 histos[iStudy]->Scale(1. / nofEvents);
212 Double_t nofObjects = histos[iStudy]->GetEntries() / nofEvents;
213 labels[iStudy] = GetStudyName(iStudy) + "(" + NumberToString<Double_t>(nofObjects, 1) + ")";
214 }
215
216 DrawH1(histos, labels, kLinear, kLinear, true, 0.65, 0.75, 0.95, 0.99);
217}
218
219void CbmLitTrackingQaStudyReport::DivideHistos(TH1* histo1, TH1* histo2, TH1* histo3, Double_t scale)
220{
221 histo1->Sumw2();
222 histo2->Sumw2();
223 histo3->Sumw2();
224 histo3->Divide(histo1, histo2, 1., 1., "B");
225 histo3->Scale(scale);
226}
227
229 const vector<Double_t>& efficiencies)
230{
231 assert(histos.size() != 0 && efficiencies.size() == histos.size());
232
233 Double_t minX = histos[0]->GetXaxis()->GetXmin();
234 Double_t maxX = histos[0]->GetXaxis()->GetXmax();
235 Int_t nofHistos = histos.size();
236 for (Int_t iHist = 0; iHist < nofHistos; iHist++) {
237 TLine* line = new TLine(minX, efficiencies[iHist], maxX, efficiencies[iHist]);
238 line->SetLineWidth(1);
239 line->SetLineColor(histos[iHist]->GetLineColor());
240 line->Draw();
241 }
242}
243
244Double_t CbmLitTrackingQaStudyReport::CalcEfficiency(const TH1* histRec, const TH1* histAcc, Double_t scale) const
245{
246 if (histAcc->Integral() == 0 || histRec->Integral() == 0) {
247 return 0.;
248 }
249 else {
250 return scale * Double_t(histRec->Integral()) / Double_t(histAcc->Integral());
251 }
252}
253
255{
256 Int_t nofStudies = HM().size();
257 for (Int_t iStudy = 0; iStudy < nofStudies; iStudy++) {
258 vector<TH1*> effHistos = HM()[iStudy]->H1Vector("hte_.+_Eff_.+");
259 Int_t nofEffHistos = effHistos.size();
260 for (Int_t iHist = 0; iHist < nofEffHistos; iHist++) {
261 TH1* effHist = effHistos[iHist];
262 string effHistName = effHist->GetName();
263 string accHistName = FindAndReplace(effHistName, "_Eff_", "_Acc_");
264 string recHistName = FindAndReplace(effHistName, "_Eff_", "_Rec_");
265 DivideHistos(HM()[iStudy]->H1(recHistName), HM()[iStudy]->H1(accHistName), effHist, 100.);
266 effHist->SetMinimum(0.);
267 effHist->SetMaximum(100.);
268 }
269 }
270}
271
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)
Helper functions for drawing 1D and 2D histograms and graphs.
@ kLinear
Definition CbmDrawHist.h:69
Histogram manager.
string TrackHitsRowNameFormatter(const string &name)
string TrackHitsCellFormatter(const TH1 *hist, Int_t)
string NofObjectsCellFormatter(const TH1 *hist, Int_t)
string NofObjectsRowNameFormatter(const string &name)
string NofGhostsCellFormatter(const TH1 *hist, Int_t nofEvents)
string DefaultRowNameFormatter(const string &name)
string EventNoRowNameFormatter(const string &name)
string NofGhostsRowNameFormatter(const string &name)
string EventNoCellFormatter(const TH1 *hist, Int_t)
Creates study report for tracking QA.
Abstract class for basic report elements (headers, tables, images etc.).
Histogram manager.
TH1 * H1(const std::string &name) const
Return pointer to TH1 histogram.
Creates study report for tracking QA.
void CalculateEfficiencyHistos()
Calculate efficiency histograms.
void DrawMeanEfficiencyLines(const std::vector< TH1 * > &histos, const std::vector< Double_t > &efficiencies)
Draw mean efficiency lines on histogram.
void DrawAccAndRec(const string &canvasName, const string &histName)
Draw accepted and reconstructed tracks histograms.
void DrawEfficiency(const string &canvasName, const string &histName)
Draw efficiency histogram.
string PrintTable(const string &tableName, const string &pattern, string(*rowNameFormatter)(const string &), string(*cellFormatter)(const TH1 *, Int_t)) const
Return formated string with table of numbers.
string PrintEfficiencyTable(const string &tableName, const string &pattern) const
Return formated string with table of efficiency numbers.
void Draw()
Inherited from CbmLitStudyReport.
Double_t CalcEfficiency(const TH1 *histRec, const TH1 *histAcc, Double_t scale=1.) const
Calculate efficiency for two histograms.
void Create()
Inherited from CbmLitStudyReport.
void DrawEfficiencyHistos()
Main function for drawing efficiency histograms.
void DivideHistos(TH1 *histo1, TH1 *histo2, TH1 *histo3, Double_t scale)
Divide two histograms.
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.
void SetReportTitle(const std::string &title)
Definition CbmReport.h:70
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 study reports.
const std::vector< std::string > & GetStudyNames() const
const std::vector< CbmHistManager * > & HM() const
const std::string & GetStudyName(Int_t index) const
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 NumberToString(const T &value, int precision=1)
Definition CbmUtils.h:34