CbmRoot
CbmLitTofQaReport.cxx
Go to the documentation of this file.
1 
6 #include "CbmLitTofQaReport.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 "TMarker.h"
17 #include "TPad.h"
18 #include <boost/assign/list_of.hpp>
19 #include <iostream>
20 #include <map>
21 
22 using boost::assign::list_of;
24 using Cbm::Split;
25 using std::cout;
26 using std::endl;
27 using std::map;
28 using std::string;
29 using std::vector;
30 
32  SetReportName("tof_qa");
33 }
34 
36 
38  Out().precision(3);
39  Out() << R()->DocumentBegin();
40  Out() << R()->Title(0, GetTitle());
41 
42  PrintCanvases();
43 
44  Out() << R()->DocumentEnd();
45 }
46 
48  HM()->NormalizeToIntegralByPattern("hmp_TofTrack_All_.+");
49 
50  DrawH2ByPattern("hmp_Tof_Reco_.+_m2p", kLinear, kLinear, kLog, "colz");
51  DrawH2ByPattern("hmp_Tof_RecoMCID_.+_m2p", kLinear, kLinear, kLog, "colz");
52  DrawH2ByPattern("hmp_Tof_RecoAccTof_.+_m2p", kLinear, kLinear, kLog, "colz");
54  "hmp_Tof_RecoMCIDAccTof_.+_m2p", kLinear, kLinear, kLog, "colz");
55  DrawH1ByPattern("hmp_Tof_TimeZero_.+");
56  DrawH1ByPattern("hmp_Tof_dTime");
57  DrawH1ByPattern("hmp_Tof_Time_FirstTrack");
58 
59  DrawH1ByPattern("hmp_TofTrack_All_.+");
60 
61  FitHistograms();
62 }
63 
65  vector<string> categories =
66  list_of("Electron")("Muon")("Pion")("Proton")("Kaon");
67  Int_t nofCategories = categories.size();
68  for (Int_t iCat = 0; iCat < nofCategories; iCat++) {
69  string canvasName = "tof_qa_fit_histograms_" + categories[iCat];
70  TCanvas* canvas =
71  CreateCanvas(canvasName.c_str(), canvasName.c_str(), 1200, 1000);
72  canvas->cd(1);
73  string histName = "hmp_Tof_RecoMCID_" + categories[iCat] + "_m2p";
74  TH2* hist = HM()->H2(histName);
75  DrawH2(hist);
76  hist->FitSlicesY();
77  TH1* meanHist =
78  (TH1*) gDirectory->Get(string(histName + "_1").c_str()); // mean
79  TH1* sigmaHist =
80  (TH1*) gDirectory->Get(string(histName + "_2").c_str()); // sigma
81  Int_t nofBins = meanHist->GetNbinsX();
82  TGraph* upGraph = new TGraph(nofBins);
83  upGraph->GetXaxis()->SetRangeUser(meanHist->GetXaxis()->GetXmin(),
84  meanHist->GetXaxis()->GetXmax());
85  TGraph* downGraph = new TGraph(nofBins);
86  downGraph->GetXaxis()->SetRangeUser(meanHist->GetXaxis()->GetXmin(),
87  meanHist->GetXaxis()->GetXmax());
88  TGraph* meanGraph = new TGraph(nofBins);
89  meanGraph->GetXaxis()->SetRangeUser(meanHist->GetXaxis()->GetXmin(),
90  meanHist->GetXaxis()->GetXmax());
91  for (Int_t iBin = 1; iBin <= nofBins; iBin++) {
92  Double_t p = meanHist->GetBinCenter(iBin);
93  Double_t mean = meanHist->GetBinContent(iBin);
94  Double_t sigma = sigmaHist->GetBinContent(iBin);
95  upGraph->SetPoint(iBin - 1, p, mean + sigma);
96  downGraph->SetPoint(iBin - 1, p, mean - sigma);
97  meanGraph->SetPoint(iBin - 1, p, mean);
98  }
99  std::cout << "Upper function for " << categories[iCat] << std::endl;
100  FitFunction(upGraph);
101  std::cout << "Lower function for " << categories[iCat] << std::endl;
102  FitFunction(downGraph);
103  DrawGraph(meanGraph, kLinear, kLinear, "PSAME");
104  }
105 }
106 
107 void CbmLitTofQaReport::FitFunction(TGraph* graph) {
108  //TF1* f1 = new TF1("f1", "[0]*x*x*x*x+[1]*x*x*x+[2]*x*x+[3]*x+[4]", graph->GetXaxis()->GetXmin(), graph->GetXaxis()->GetXmax());
109  TF1* f1 = new TF1("f1", "[0]*x*x*x*x+[1]*x*x*x+[2]*x*x+[3]*x+[4]", 1., 8.);
110  f1->SetLineColor(kRed);
111  DrawGraph(graph, kLinear, kLinear, "PSAME", kRed, 2, 1, 1, 21);
112  graph->Fit(f1, "RQ");
113  Double_t p0 = f1->GetParameter(0);
114  Double_t p1 = f1->GetParameter(1);
115  Double_t p2 = f1->GetParameter(2);
116  Double_t p3 = f1->GetParameter(3);
117  Double_t p4 = f1->GetParameter(4);
118  std::cout << "Function: " << p0 << "*x^4" << string((p1 > 0) ? "+" : "") << p1
119  << "*x^3" << string((p2 > 0) ? "+" : "") << p2 << "*x^2"
120  << string((p3 > 0) ? "+" : "") << p3 << "*x"
121  << string((p4 > 0) ? "+" : "") << p4 << std::endl;
122 }
123 
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
CbmLitTofQaReport::FitFunction
void FitFunction(TGraph *graph)
Definition: CbmLitTofQaReport.cxx:107
CbmLitTofQaReport.h
Create report for TOF QA.
CbmReportElement::DocumentBegin
virtual std::string DocumentBegin() const =0
Return string with open tags for document.
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
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.
CbmLitTofQaReport::Create
virtual void Create()
Inherited from CbmSimulationReport.
Definition: CbmLitTofQaReport.cxx:37
DrawGraph
void DrawGraph(TGraph *graph, 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:151
CbmReport::SetReportName
void SetReportName(const std::string &name)
Definition: CbmReport.h:59
CbmLitTofQaReport::CbmLitTofQaReport
CbmLitTofQaReport()
Constructor.
Definition: CbmLitTofQaReport.cxx:31
CbmHistManager::NormalizeToIntegralByPattern
void NormalizeToIntegralByPattern(const std::string &pattern)
Normalize histograms to integral which name matches specified pattern.
Definition: core/base/CbmHistManager.cxx:234
CbmReport::PrintCanvases
void PrintCanvases() const
Print images created from canvases in the report.
Definition: CbmReport.cxx:109
CbmLitTofQaReport::~CbmLitTofQaReport
virtual ~CbmLitTofQaReport()
Destructor.
Definition: CbmLitTofQaReport.cxx:35
kLinear
@ kLinear
Definition: CbmDrawHist.h:79
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmLitTofQaReport::FitHistograms
void FitHistograms()
Definition: CbmLitTofQaReport.cxx:64
CbmSimulationReport::DrawH1ByPattern
void DrawH1ByPattern(const std::string &histNamePattern)
Select by pattern TH1 histograms and draw each histogram on separate canvas.
CbmUtils.h
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
CbmLitTofQaReport::Draw
virtual void Draw()
Inherited from CbmSimulationReport.
Definition: CbmLitTofQaReport.cxx:47
CbmSimulationReport::HM
CbmHistManager * HM() const
Return pointer to Histogram manager.
Definition: CbmSimulationReport.h:92
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
CbmLitTofQaReport
Create report for TOF QA.
Definition: CbmLitTofQaReport.h:19