CbmRoot
Loading...
Searching...
No Matches
CbmLitClusteringQaReport.cxx
Go to the documentation of this file.
1/* Copyright (C) 2011-2017 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer] */
4
12
13#include "CbmDrawHist.h"
14#include "CbmHistManager.h"
15#include "CbmReportElement.h"
16#include "CbmUtils.h"
17#include "TCanvas.h"
18#include "TF1.h"
19#include "TH1.h"
20#include "TProfile.h"
21
22#include <boost/assign/list_of.hpp>
23
24#include <vector>
25using boost::assign::list_of;
28using Cbm::Split;
29using std::endl;
30using std::stringstream;
31using std::vector;
32
33string DefaultHitEfficiencyLabelFormatter(const string& histName, const CbmHistManager* hm)
34{
35 Double_t efficiency =
36 (histName.find("_Eff_") != string::npos)
37 ? CbmLitClusteringQaReport::CalcEfficiency(hm->H1(FindAndReplace(histName, "_Eff_", "_Rec_")),
38 hm->H1(FindAndReplace(histName, "_Eff_", "_Acc_")), 100.)
39 : CbmLitClusteringQaReport::CalcEfficiency(hm->H1(FindAndReplace(histName, "_CloneProb_", "_Clone_")),
40 hm->H1(FindAndReplace(histName, "_CloneProb_", "_Acc_")), 100.);
41 vector<string> split = Split(histName, '_');
42 return split[1] + ":" + split[3] + "(" + NumberToString<Double_t>(efficiency, 1) + ")";
43}
44
45string DefaultAccAndRecLabelFormatter(const string& histName, const CbmHistManager* hm)
46{
47 Int_t nofEvents = hm->H1("hen_EventNo_ClusteringQa")->GetEntries();
48 vector<string> split = Split(histName, '_');
49 return split[3] + " (" + NumberToString<Double_t>(hm->H1(histName)->GetEntries() / nofEvents, 1) + ")";
50}
51
53
55
57{
58 Out().precision(3);
59 Out() << R()->DocumentBegin();
60 Out() << R()->Title(0, GetTitle());
61
62 Out() << "Number of events: " << HM()->H1("hen_EventNo_ClusteringQa")->GetEntries() << endl;
63
64 Out() << PrintNofObjects();
65
67 Out() << R()->DocumentEnd();
68}
69
71{
72 vector<TH1*> histos = HM()->H1Vector("hno_NofObjects_.+_Event");
73 Int_t nofHistos = histos.size();
74 string str = R()->TableBegin("Number of objects per event", list_of("Name")("Value"));
75 for (Int_t iHist = 0; iHist < nofHistos; iHist++) {
76 string cellName = Split(histos[iHist]->GetName(), '_')[2];
77 str += R()->TableRow(list_of(cellName)(NumberToString<Int_t>(histos[iHist]->GetMean())));
78 }
79 str += R()->TableEnd();
80 return str;
81}
82
84{
86 CalculateEfficiencyHistos("Acc", "Rec", "Eff");
87 CalculateEfficiencyHistos("Acc", "Clone", "CloneProb");
88
89 DrawNofObjectsHistograms("Mvd", "Event");
90 DrawNofObjectsHistograms("Sts", "Event");
91 DrawNofObjectsHistograms("Rich", "Event");
92 DrawNofObjectsHistograms("Trd", "Event");
93 DrawNofObjectsHistograms("Much", "Event");
94 DrawNofObjectsHistograms("Tof", "Event");
95
96 DrawNofObjectsHistograms("Mvd", "Station");
97 DrawNofObjectsHistograms("Sts", "Station");
98 DrawNofObjectsHistograms("Trd", "Station");
99 DrawNofObjectsHistograms("Much", "Station");
100
101 DrawH1ByPattern("hpa_.*Cluster_NofDigisInCluster_H1");
102 DrawH2ByPattern("hpa_.*Cluster_NofDigisInCluster_H2", kLinear, kLinear, kLinear, "colz");
103
104 DrawH1ByPattern("hpa_.*(Digi|Cluster|Hit)_NofPointsIn(Digi|Cluster|Hit)_H1");
105 DrawH2ByPattern("hpa_.*(Digi|Cluster|Hit)_NofPointsIn(Digi|Cluster|Hit)_H2", kLinear, kLinear, kLinear, "colz");
106
107 DrawH1ByPattern("hpa_.*Hit_Sigma.*_H1");
108 DrawH2ByPattern("hpa_.*Hit_Sigma.*_H2", kLinear, kLinear, kLinear, "colz");
109
111 DrawResidualsAndPulls("Much");
112
113
114 DrawH1ByPattern("hhe_Trd_All_(Acc|Rec|Clone)_Station", DefaultAccAndRecLabelFormatter);
115 DrawH1ByPattern("hhe_Much_All_(Acc|Rec|Clone)_Station", DefaultAccAndRecLabelFormatter);
116
117 DrawH1ByPattern("hhe_Trd_All_(Eff|CloneProb)_Station", DefaultHitEfficiencyLabelFormatter);
118 DrawH1ByPattern("hhe_Much_All_(Eff|CloneProb)_Station", DefaultHitEfficiencyLabelFormatter);
119}
120
121void CbmLitClusteringQaReport::DrawNofObjectsHistograms(const string& detName, const string& parameter)
122{
123 if (!HM()->Exists("hno_NofObjects_" + detName + "Points_" + parameter)) return;
124 string canvasName = GetReportName() + "_NofObjects_" + detName + "_" + parameter;
125 TCanvas* canvas = CreateCanvas(canvasName.c_str(), canvasName.c_str(), 800, 500);
126 canvas->SetGrid();
127 canvas->cd();
128 vector<string> labels = list_of("Points")("Digis")("Clusters")("Hits");
129 vector<TH1*> histos = list_of(HM()->H1("hno_NofObjects_" + detName + "Points_" + parameter))(
130 HM()->H1("hno_NofObjects_" + detName + "Digis_" + parameter))(
131 HM()->H1("hno_NofObjects_" + detName + "Clusters_" + parameter));
132 if (HM()->Exists("hno_NofObjects_" + detName + "PixelHits_" + parameter))
133 histos.push_back(HM()->H1("hno_NofObjects_" + detName + "PixelHits_" + parameter));
134 else if (HM()->Exists("hno_NofObjects_" + detName + "StrawHits_" + parameter))
135 histos.push_back(HM()->H1("hno_NofObjects_" + detName + "StrawHits_" + parameter));
136 else if (HM()->Exists("hno_NofObjects_" + detName + "Hits_" + parameter))
137 histos.push_back(HM()->H1("hno_NofObjects_" + detName + "Hits_" + parameter));
138 DrawH1(histos, labels, kLinear, kLinear, true, 0.65, 0.75, 0.95, 0.99);
139}
140
142{
143 if (!(HM()->Exists("hrp_" + detName + "_ResidualX_H2") && HM()->Exists("hrp_" + detName + "_ResidualY_H2")
144 && HM()->Exists("hrp_" + detName + "_ResidualT_H2") && HM()->Exists("hrp_" + detName + "_PullX_H2")
145 && HM()->Exists("hrp_" + detName + "_PullY_H2") && HM()->Exists("hrp_" + detName + "_PullT_H2")))
146 return;
147 vector<string> par = list_of("ResidualX")("ResidualY")("ResidualT")("PullX")("PullY")("PullT");
148 Int_t nofCanvases = par.size();
149 for (Int_t iCanvas = 0; iCanvas < nofCanvases; iCanvas++) {
150 string histName = "hrp_" + detName + "_" + par[iCanvas] + "_H2";
151 TH2* hist = HM()->H2(histName);
152 string canvasName = GetReportName() + "_" + histName + "_station";
153 TCanvas* canvas = CreateCanvas(canvasName.c_str(), canvasName.c_str(), 1600, 900);
154 Int_t nofBins = 10; //hist->GetXaxis()->GetNbins();
155 Int_t nofColumns = 5;
156 Int_t nofRows = (nofBins / nofColumns) + ((nofBins % 5 == 0) ? 0 : 1);
157 canvas->Divide(nofColumns, nofRows);
158
159 std::cout << nofBins << " " << nofColumns << " " << nofRows << std::endl;
160 for (Int_t iBin = 1; iBin <= nofBins; iBin++) {
161 stringstream ss;
162 ss << histName << "_" << iBin << "_py";
163 TH1* projY = hist->ProjectionY(ss.str().c_str(), iBin, iBin);
164 projY->SetNameTitle(ss.str().c_str(), ss.str().c_str());
165 projY->SetXTitle(par[iCanvas].c_str());
166 projY->SetYTitle("Yield");
167 canvas->cd(iBin);
168 DrawH1(projY, kLinear, kLinear);
169 projY->Fit("gaus");
170 }
171 }
172 DrawH2ByPattern("hrp_" + detName + "_.*_H2", kLinear, kLinear, kLinear, "colz");
173}
174
175Double_t CbmLitClusteringQaReport::CalcEfficiency(const TH1* histRec, const TH1* histAcc, Double_t scale)
176{
177 if (histAcc->Integral() == 0 || histRec->Integral() == 0) {
178 return 0.;
179 }
180 else {
181 return scale * Double_t(histRec->Integral()) / Double_t(histAcc->Integral());
182 }
183}
184
186{
187 Int_t nofEvents = HM()->H1("hen_EventNo_ClusteringQa")->GetEntries();
188
189 HM()->ScaleByPattern("hhe_.+_.+_(Acc|Rec|Clone)_Station", 1. / nofEvents);
190
191 HM()->ScaleByPattern("hno_NofObjects_.*_Station", 1. / nofEvents);
192 HM()->ShrinkEmptyBinsH1ByPattern("hno_NofObjects_.*_Station");
193
194 HM()->NormalizeToIntegralByPattern("hpa_.*Cluster_NofDigisInCluster_.*");
195 HM()->ShrinkEmptyBinsH1ByPattern("hpa_.*Cluster_NofDigisInCluster_H1");
196 HM()->ShrinkEmptyBinsH2ByPattern("hpa_.*Cluster_NofDigisInCluster_H2");
197
198 HM()->NormalizeToIntegralByPattern("hpa_.*(Digi|Cluster|Hit)_NofPointsIn(Digi|Cluster|Hit)_.*");
199 HM()->ShrinkEmptyBinsH1ByPattern("hpa_.*(Digi|Cluster|Hit)_NofPointsIn(Digi|Cluster|Hit)_H1");
200 HM()->ShrinkEmptyBinsH2ByPattern("hpa_.*(Digi|Cluster|Hit)_NofPointsIn(Digi|Cluster|Hit)_H2");
201
202 HM()->NormalizeToIntegralByPattern("hrp_.*_.*_H2");
203 HM()->ShrinkEmptyBinsH2ByPattern("hrp_.*_.*_H2");
204
205 HM()->NormalizeToIntegralByPattern("hpa_.*Hit_Sigma.*_.*");
206 HM()->ShrinkEmptyBinsH1ByPattern("hpa_.*Hit_Sigma.*_H1");
207 HM()->ShrinkEmptyBinsH2ByPattern("hpa_.*Hit_Sigma.*_H2");
208}
209
210void CbmLitClusteringQaReport::DivideHistos(TH1* histo1, TH1* histo2, TH1* histo3, Double_t scale)
211{
212 histo1->Sumw2();
213 histo2->Sumw2();
214 histo3->Sumw2();
215 histo3->Divide(histo1, histo2, 1., 1., "B");
216 histo3->Scale(scale);
217}
218
219void CbmLitClusteringQaReport::CalculateEfficiencyHistos(const string& acc, const string& rec, const string& eff)
220{
221 vector<TH1*> effHistos = HM()->H1Vector("hhe_.+_" + eff + "_.+");
222 Int_t nofEffHistos = effHistos.size();
223 for (Int_t iHist = 0; iHist < nofEffHistos; iHist++) {
224 TH1* effHist = effHistos[iHist];
225 string effHistName = effHist->GetName();
226 string accHistName = FindAndReplace(effHistName, "_" + eff + "_", "_" + acc + "_");
227 string recHistName = FindAndReplace(effHistName, "_" + eff + "_", "_" + rec + "_");
228 DivideHistos(HM()->H1(recHistName), HM()->H1(accHistName), effHist, 100.);
229 effHist->SetMinimum(0.);
230 effHist->SetMaximum(100.);
231 }
232}
233
ClassImp(CbmConverterManager)
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 DefaultAccAndRecLabelFormatter(const string &histName, const CbmHistManager *hm)
string DefaultHitEfficiencyLabelFormatter(const string &histName, const CbmHistManager *hm)
Simulation report for clustering QA.
Abstract class for basic report elements (headers, tables, images etc.).
Histogram manager.
void ShrinkEmptyBinsH1ByPattern(const std::string &pattern)
Shrink empty bins in H1.
void ShrinkEmptyBinsH2ByPattern(const std::string &pattern)
Shrink empty bins in H2.
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.
void ScaleByPattern(const std::string &pattern, Double_t scale)
Scale histograms which name matches specified pattern.
void NormalizeToIntegralByPattern(const std::string &pattern)
Normalize histograms to integral which name matches specified pattern.
TH1 * H1(const std::string &name) const
Return pointer to TH1 histogram.
Simulation report for clustering QA.
void DivideHistos(TH1 *histo1, TH1 *histo2, TH1 *histo3, Double_t scale)
virtual void Create()
Inherited from CbmSimulationReport.
void CalculateEfficiencyHistos(const string &acc, const string &rec, const string &eff)
virtual ~CbmLitClusteringQaReport()
Destructor.
virtual void Draw()
Inherited from CbmSimulationReport.
void DrawResidualsAndPulls(const string &detName)
string PrintNofObjects() const
Print number of objects table.
static Double_t CalcEfficiency(const TH1 *histRec, const TH1 *histAcc, Double_t scale)
void DrawNofObjectsHistograms(const string &detName, const string &parameter)
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 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
Base class for simulation reports.
void DrawH1ByPattern(const std::string &histNamePattern)
Select by pattern TH1 histograms and draw each histogram on separate canvas.
TH1 * H1(const std::string &name) const
Return pointer to TH1 histogram.
CbmHistManager * HM() const
Return pointer to Histogram manager.
void DrawH2ByPattern(const std::string &histNamePattern, HistScale logx=kLinear, HistScale logy=kLinear, HistScale logz=kLinear, const std::string &drawOpt="")
Select by pattern TH2 histograms and draw each histogram on separate canvas.
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