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