CbmRoot
CbmLitClusteringQaReport.cxx
Go to the documentation of this file.
1 
8 #include "CbmDrawHist.h"
9 #include "CbmHistManager.h"
10 #include "CbmReportElement.h"
11 #include "CbmUtils.h"
12 #include "TCanvas.h"
13 #include "TF1.h"
14 #include "TH1.h"
15 #include "TProfile.h"
16 #include <boost/assign/list_of.hpp>
17 #include <vector>
18 using boost::assign::list_of;
21 using Cbm::Split;
22 using std::endl;
23 using std::stringstream;
24 using std::vector;
25 
26 string DefaultHitEfficiencyLabelFormatter(const string& histName,
27  const CbmHistManager* hm) {
28  Double_t efficiency =
29  (histName.find("_Eff_") != string::npos)
31  hm->H1(FindAndReplace(histName, "_Eff_", "_Rec_")),
32  hm->H1(FindAndReplace(histName, "_Eff_", "_Acc_")),
33  100.)
35  hm->H1(FindAndReplace(histName, "_CloneProb_", "_Clone_")),
36  hm->H1(FindAndReplace(histName, "_CloneProb_", "_Acc_")),
37  100.);
38  vector<string> split = Split(histName, '_');
39  return split[1] + ":" + split[3] + "("
40  + NumberToString<Double_t>(efficiency, 1) + ")";
41 }
42 
43 string DefaultAccAndRecLabelFormatter(const string& histName,
44  const CbmHistManager* hm) {
45  Int_t nofEvents = hm->H1("hen_EventNo_ClusteringQa")->GetEntries();
46  vector<string> split = Split(histName, '_');
47  return split[3] + " ("
48  + NumberToString<Double_t>(hm->H1(histName)->GetEntries() / nofEvents,
49  1)
50  + ")";
51 }
52 
54  SetReportName("clustering_qa");
55 }
56 
58 
60  Out().precision(3);
61  Out() << R()->DocumentBegin();
62  Out() << R()->Title(0, GetTitle());
63 
64  Out() << "Number of events: "
65  << HM()->H1("hen_EventNo_ClusteringQa")->GetEntries() << endl;
66 
67  Out() << PrintNofObjects();
68 
69  PrintCanvases();
70  Out() << R()->DocumentEnd();
71 }
72 
74  vector<TH1*> histos = HM()->H1Vector("hno_NofObjects_.+_Event");
75  Int_t nofHistos = histos.size();
76  string str =
77  R()->TableBegin("Number of objects per event", list_of("Name")("Value"));
78  for (Int_t iHist = 0; iHist < nofHistos; iHist++) {
79  string cellName = Split(histos[iHist]->GetName(), '_')[2];
80  str += R()->TableRow(
81  list_of(cellName)(NumberToString<Int_t>(histos[iHist]->GetMean())));
82  }
83  str += R()->TableEnd();
84  return str;
85 }
86 
89  CalculateEfficiencyHistos("Acc", "Rec", "Eff");
90  CalculateEfficiencyHistos("Acc", "Clone", "CloneProb");
91 
92  DrawNofObjectsHistograms("Mvd", "Event");
93  DrawNofObjectsHistograms("Sts", "Event");
94  DrawNofObjectsHistograms("Rich", "Event");
95  DrawNofObjectsHistograms("Trd", "Event");
96  DrawNofObjectsHistograms("Much", "Event");
97  DrawNofObjectsHistograms("Tof", "Event");
98 
99  DrawNofObjectsHistograms("Mvd", "Station");
100  DrawNofObjectsHistograms("Sts", "Station");
101  DrawNofObjectsHistograms("Trd", "Station");
102  DrawNofObjectsHistograms("Much", "Station");
103 
104  DrawH1ByPattern("hpa_.*Cluster_NofDigisInCluster_H1");
106  "hpa_.*Cluster_NofDigisInCluster_H2", kLinear, kLinear, kLinear, "colz");
107 
108  DrawH1ByPattern("hpa_.*(Digi|Cluster|Hit)_NofPointsIn(Digi|Cluster|Hit)_H1");
109  DrawH2ByPattern("hpa_.*(Digi|Cluster|Hit)_NofPointsIn(Digi|Cluster|Hit)_H2",
110  kLinear,
111  kLinear,
112  kLinear,
113  "colz");
114 
115  DrawH1ByPattern("hpa_.*Hit_Sigma.*_H1");
116  DrawH2ByPattern("hpa_.*Hit_Sigma.*_H2", kLinear, kLinear, kLinear, "colz");
117 
118  DrawResidualsAndPulls("Trd");
119  DrawResidualsAndPulls("Much");
120 
121 
122  DrawH1ByPattern("hhe_Trd_All_(Acc|Rec|Clone)_Station",
124  DrawH1ByPattern("hhe_Much_All_(Acc|Rec|Clone)_Station",
126 
127  DrawH1ByPattern("hhe_Trd_All_(Eff|CloneProb)_Station",
129  DrawH1ByPattern("hhe_Much_All_(Eff|CloneProb)_Station",
131 }
132 
134  const string& detName,
135  const string& parameter) {
136  if (!HM()->Exists("hno_NofObjects_" + detName + "Points_" + parameter))
137  return;
138  string canvasName =
139  GetReportName() + "_NofObjects_" + detName + "_" + parameter;
140  TCanvas* canvas =
141  CreateCanvas(canvasName.c_str(), canvasName.c_str(), 800, 500);
142  canvas->SetGrid();
143  canvas->cd();
144  vector<string> labels = list_of("Points")("Digis")("Clusters")("Hits");
145  vector<TH1*> histos =
146  list_of(HM()->H1("hno_NofObjects_" + detName + "Points_" + parameter))(
147  HM()->H1("hno_NofObjects_" + detName + "Digis_" + parameter))(
148  HM()->H1("hno_NofObjects_" + detName + "Clusters_" + parameter));
149  if (HM()->Exists("hno_NofObjects_" + detName + "PixelHits_" + parameter))
150  histos.push_back(
151  HM()->H1("hno_NofObjects_" + detName + "PixelHits_" + parameter));
152  else if (HM()->Exists("hno_NofObjects_" + detName + "StrawHits_" + parameter))
153  histos.push_back(
154  HM()->H1("hno_NofObjects_" + detName + "StrawHits_" + parameter));
155  else if (HM()->Exists("hno_NofObjects_" + detName + "Hits_" + parameter))
156  histos.push_back(
157  HM()->H1("hno_NofObjects_" + detName + "Hits_" + parameter));
158  DrawH1(histos, labels, kLinear, kLinear, true, 0.65, 0.75, 0.95, 0.99);
159 }
160 
162  if (!(HM()->Exists("hrp_" + detName + "_ResidualX_H2")
163  && HM()->Exists("hrp_" + detName + "_ResidualY_H2")
164  && HM()->Exists("hrp_" + detName + "_ResidualT_H2")
165  && HM()->Exists("hrp_" + detName + "_PullX_H2")
166  && HM()->Exists("hrp_" + detName + "_PullY_H2")
167  && HM()->Exists("hrp_" + detName + "_PullT_H2")))
168  return;
169  vector<string> par =
170  list_of("ResidualX")("ResidualY")("ResidualT")("PullX")("PullY")("PullT");
171  Int_t nofCanvases = par.size();
172  for (Int_t iCanvas = 0; iCanvas < nofCanvases; iCanvas++) {
173  string histName = "hrp_" + detName + "_" + par[iCanvas] + "_H2";
174  TH2* hist = HM()->H2(histName);
175  string canvasName = GetReportName() + "_" + histName + "_station";
176  TCanvas* canvas =
177  CreateCanvas(canvasName.c_str(), canvasName.c_str(), 1600, 900);
178  Int_t nofBins = 10; //hist->GetXaxis()->GetNbins();
179  Int_t nofColumns = 5;
180  Int_t nofRows = (nofBins / nofColumns) + ((nofBins % 5 == 0) ? 0 : 1);
181  canvas->Divide(nofColumns, nofRows);
182 
183  std::cout << nofBins << " " << nofColumns << " " << nofRows << std::endl;
184  for (Int_t iBin = 1; iBin <= nofBins; iBin++) {
185  stringstream ss;
186  ss << histName << "_" << iBin << "_py";
187  TH1* projY = hist->ProjectionY(ss.str().c_str(), iBin, iBin);
188  projY->SetNameTitle(ss.str().c_str(), ss.str().c_str());
189  projY->SetXTitle(par[iCanvas].c_str());
190  projY->SetYTitle("Yield");
191  canvas->cd(iBin);
192  DrawH1(projY, kLinear, kLinear);
193  projY->Fit("gaus");
194  }
195  }
197  "hrp_" + detName + "_.*_H2", kLinear, kLinear, kLinear, "colz");
198 }
199 
200 Double_t CbmLitClusteringQaReport::CalcEfficiency(const TH1* histRec,
201  const TH1* histAcc,
202  Double_t scale) {
203  if (histAcc->Integral() == 0 || histRec->Integral() == 0) {
204  return 0.;
205  } else {
206  return scale * Double_t(histRec->Integral())
207  / Double_t(histAcc->Integral());
208  }
209 }
210 
212  Int_t nofEvents = HM()->H1("hen_EventNo_ClusteringQa")->GetEntries();
213 
214  HM()->ScaleByPattern("hhe_.+_.+_(Acc|Rec|Clone)_Station", 1. / nofEvents);
215 
216  HM()->ScaleByPattern("hno_NofObjects_.*_Station", 1. / nofEvents);
217  HM()->ShrinkEmptyBinsH1ByPattern("hno_NofObjects_.*_Station");
218 
219  HM()->NormalizeToIntegralByPattern("hpa_.*Cluster_NofDigisInCluster_.*");
220  HM()->ShrinkEmptyBinsH1ByPattern("hpa_.*Cluster_NofDigisInCluster_H1");
221  HM()->ShrinkEmptyBinsH2ByPattern("hpa_.*Cluster_NofDigisInCluster_H2");
222 
224  "hpa_.*(Digi|Cluster|Hit)_NofPointsIn(Digi|Cluster|Hit)_.*");
226  "hpa_.*(Digi|Cluster|Hit)_NofPointsIn(Digi|Cluster|Hit)_H1");
228  "hpa_.*(Digi|Cluster|Hit)_NofPointsIn(Digi|Cluster|Hit)_H2");
229 
230  HM()->NormalizeToIntegralByPattern("hrp_.*_.*_H2");
231  HM()->ShrinkEmptyBinsH2ByPattern("hrp_.*_.*_H2");
232 
233  HM()->NormalizeToIntegralByPattern("hpa_.*Hit_Sigma.*_.*");
234  HM()->ShrinkEmptyBinsH1ByPattern("hpa_.*Hit_Sigma.*_H1");
235  HM()->ShrinkEmptyBinsH2ByPattern("hpa_.*Hit_Sigma.*_H2");
236 }
237 
239  TH1* histo2,
240  TH1* histo3,
241  Double_t scale) {
242  histo1->Sumw2();
243  histo2->Sumw2();
244  histo3->Sumw2();
245  histo3->Divide(histo1, histo2, 1., 1., "B");
246  histo3->Scale(scale);
247 }
248 
250  const string& rec,
251  const string& eff) {
252  vector<TH1*> effHistos = HM()->H1Vector("hhe_.+_" + eff + "_.+");
253  Int_t nofEffHistos = effHistos.size();
254  for (Int_t iHist = 0; iHist < nofEffHistos; iHist++) {
255  TH1* effHist = effHistos[iHist];
256  string effHistName = effHist->GetName();
257  string accHistName =
258  FindAndReplace(effHistName, "_" + eff + "_", "_" + acc + "_");
259  string recHistName =
260  FindAndReplace(effHistName, "_" + eff + "_", "_" + rec + "_");
261  DivideHistos(HM()->H1(recHistName), HM()->H1(accHistName), effHist, 100.);
262  effHist->SetMinimum(0.);
263  effHist->SetMaximum(100.);
264  }
265 }
266 
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
CbmHistManager::Exists
Bool_t Exists(const std::string &name) const
Check existence of histogram in manager.
Definition: CbmHistManager.h:303
split
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
Definition: ThermalParticleSystem.cxx:144
CbmHistManager::ShrinkEmptyBinsH2ByPattern
void ShrinkEmptyBinsH2ByPattern(const std::string &pattern)
Shrink empty bins in H2.
Definition: core/base/CbmHistManager.cxx:209
CbmHistManager::ScaleByPattern
void ScaleByPattern(const std::string &pattern, Double_t scale)
Scale histograms which name matches specified pattern.
Definition: core/base/CbmHistManager.cxx:221
DefaultAccAndRecLabelFormatter
string DefaultAccAndRecLabelFormatter(const string &histName, const CbmHistManager *hm)
Definition: CbmLitClusteringQaReport.cxx:43
CbmReportElement::DocumentBegin
virtual std::string DocumentBegin() const =0
Return string with open tags for document.
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.
CbmHistManager::ShrinkEmptyBinsH1ByPattern
void ShrinkEmptyBinsH1ByPattern(const std::string &pattern)
Shrink empty bins in H1.
Definition: core/base/CbmHistManager.cxx:174
CbmLitClusteringQaReport
Simulation report for clustering QA.
Definition: CbmLitClusteringQaReport.h:21
CbmReportElement::DocumentEnd
virtual std::string DocumentEnd() const =0
Return string with close tags of the document.
CbmHistManager::H2
TH2 * H2(const std::string &name) const
Return pointer to TH2 histogram.
Definition: CbmHistManager.h:190
DefaultHitEfficiencyLabelFormatter
string DefaultHitEfficiencyLabelFormatter(const string &histName, const CbmHistManager *hm)
Definition: CbmLitClusteringQaReport.cxx:26
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
CbmLitClusteringQaReport::~CbmLitClusteringQaReport
virtual ~CbmLitClusteringQaReport()
Destructor.
Definition: CbmLitClusteringQaReport.cxx:57
CbmLitClusteringQaReport::PrintNofObjects
string PrintNofObjects() const
Print number of objects table.
Definition: CbmLitClusteringQaReport.cxx:73
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.
CbmReport::SetReportName
void SetReportName(const std::string &name)
Definition: CbmReport.h:59
CbmHistManager::NormalizeToIntegralByPattern
void NormalizeToIntegralByPattern(const std::string &pattern)
Normalize histograms to integral which name matches specified pattern.
Definition: core/base/CbmHistManager.cxx:234
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
CbmLitClusteringQaReport::DivideHistos
void DivideHistos(TH1 *histo1, TH1 *histo2, TH1 *histo3, Double_t scale)
Definition: CbmLitClusteringQaReport.cxx:238
CbmReportElement::TableEnd
virtual std::string TableEnd() const =0
Return string with table close tag.
kLinear
@ kLinear
Definition: CbmDrawHist.h:79
CbmLitClusteringQaReport::CbmLitClusteringQaReport
CbmLitClusteringQaReport()
Constructor.
Definition: CbmLitClusteringQaReport.cxx:53
CbmLitClusteringQaReport::CalculateEfficiencyHistos
void CalculateEfficiencyHistos(const string &acc, const string &rec, const string &eff)
Definition: CbmLitClusteringQaReport.cxx:249
CbmSimulationReport::H1
TH1 * H1(const std::string &name) const
Return pointer to TH1 histogram.
Definition: CbmSimulationReport.h:73
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
CbmSimulationReport::DrawH1ByPattern
void DrawH1ByPattern(const std::string &histNamePattern)
Select by pattern TH1 histograms and draw each histogram on separate canvas.
CbmUtils.h
CbmLitClusteringQaReport::DrawResidualsAndPulls
void DrawResidualsAndPulls(const string &detName)
Definition: CbmLitClusteringQaReport.cxx:161
CbmSimulationReport::DrawH2ByPattern
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.
Definition: CbmSimulationReport.cxx:81
CbmLitClusteringQaReport::DrawNofObjectsHistograms
void DrawNofObjectsHistograms(const string &detName, const string &parameter)
Definition: CbmLitClusteringQaReport.cxx:133
CbmLitClusteringQaReport.h
Simulation report for clustering QA.
CbmHistManager::H1Vector
std::vector< TH1 * > H1Vector(const std::string &pattern) const
Return vector of pointers to TH1 histogram.
Definition: core/base/CbmHistManager.cxx:79
CbmSimulationReport::HM
CbmHistManager * HM() const
Return pointer to Histogram manager.
Definition: CbmSimulationReport.h:92
CbmLitClusteringQaReport::Draw
virtual void Draw()
Inherited from CbmSimulationReport.
Definition: CbmLitClusteringQaReport.cxx:87
CbmLitClusteringQaReport::CalcEfficiency
static Double_t CalcEfficiency(const TH1 *histRec, const TH1 *histAcc, Double_t scale)
Definition: CbmLitClusteringQaReport.cxx:200
CbmSimulationReport
Base class for simulation reports.
Definition: CbmSimulationReport.h:28
CbmReport::Out
std::ostream & Out() const
All text output goes to this stream.
Definition: CbmReport.h:56
CbmLitClusteringQaReport::Create
virtual void Create()
Inherited from CbmSimulationReport.
Definition: CbmLitClusteringQaReport.cxx:59
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
CbmLitClusteringQaReport::ScaleAndShrinkHistograms
void ScaleAndShrinkHistograms()
Definition: CbmLitClusteringQaReport.cxx:211
Cbm::Split
vector< string > Split(const string &name, char delimiter)
Definition: CbmUtils.cxx:54