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