CbmRoot
CbmSimulationReport.cxx
Go to the documentation of this file.
1 
6 #include "CbmSimulationReport.h"
7 
8 #include "CbmDrawHist.h" // for DrawH1, kLinear, DrawH2, HistScale
9 #include "CbmHistManager.h" // for CbmHistManager
10 
11 #include <RtypesCore.h> // for UInt_t
12 #include <TFile.h> // for TFile
13 #include <TH1.h> // for TH1
14 #include <TH2.h> // for TH2
15 
16 #include <assert.h> // for assert
17 #include <fstream> // for string, ofstream
18 #include <string> // for operator+
19 #include <vector> // for vector, __vector_base<>::value_type
20 
21 using std::ofstream;
22 using std::string;
23 using std::vector;
24 
26 
28 
30  const string& outputDir) {
31  assert(histManager != nullptr);
32  fHM = histManager;
33  SetOutputDir(outputDir);
34  CreateReports();
35 }
36 
37 void CbmSimulationReport::Create(const string& fileName,
38  const string& outputDir) {
39  assert(fHM == nullptr);
40  fHM = new CbmHistManager();
41  TFile* file = new TFile(fileName.c_str());
42  fHM->ReadFromFile(file);
43  SetOutputDir(outputDir);
44  CreateReports();
45  // delete fHM;
46  // delete file;
47 }
48 
49 void CbmSimulationReport::DrawH1ByPattern(const string& histNamePattern) {
50  vector<TH1*> histos = HM()->H1Vector(histNamePattern);
51  UInt_t nofHistos = histos.size();
52  if (nofHistos < 1) return;
53  for (UInt_t iHist = 0; iHist < nofHistos; iHist++) {
54  TH1* hist = histos[iHist];
55  string canvasName = GetReportName() + hist->GetName();
56  // TCanvas* canvas = CreateCanvas(canvasName.c_str(), canvasName.c_str(), 800, 500);
57  CreateCanvas(canvasName.c_str(), canvasName.c_str(), 800, 500);
58  DrawH1(hist, kLinear, kLinear);
59  }
60 }
61 
63  const string& histNamePattern,
64  string (*labelFormatter)(const string&, const CbmHistManager*)) {
65  vector<TH1*> histos = HM()->H1Vector(histNamePattern);
66  UInt_t nofHistos = histos.size();
67  if (nofHistos < 1) return;
68  string canvasName = GetReportName() + histos[0]->GetName();
69  // TCanvas* canvas = CreateCanvas(canvasName.c_str(), canvasName.c_str(), 600, 500);
70  CreateCanvas(canvasName.c_str(), canvasName.c_str(), 600, 500);
71 
72  vector<string> labels(nofHistos);
73  for (UInt_t iHist = 0; iHist < nofHistos; iHist++) {
74  string name = histos[iHist]->GetName();
75  labels[iHist] = labelFormatter(name, HM());
76  }
77 
78  DrawH1(histos, labels, kLinear, kLinear, true, 0.3, 0.3, 0.85, 0.6, "PE1");
79 }
80 
81 void CbmSimulationReport::DrawH2ByPattern(const string& histNamePattern,
82  HistScale logx,
83  HistScale logy,
84  HistScale logz,
85  const string& drawOpt) {
86  vector<TH2*> histos = HM()->H2Vector(histNamePattern);
87  UInt_t nofHistos = histos.size();
88  if (nofHistos < 1) return;
89  for (UInt_t iHist = 0; iHist < nofHistos; iHist++) {
90  TH2* hist = histos[iHist];
91  string canvasName = GetReportName() + hist->GetName();
92  // TCanvas* canvas = CreateCanvas(canvasName.c_str(), canvasName.c_str(), 800, 500);
93  CreateCanvas(canvasName.c_str(), canvasName.c_str(), 800, 500);
94  DrawH2(hist, logx, logy, logz, drawOpt);
95  }
96 }
97 
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
CbmSimulationReport::fHM
CbmHistManager * fHM
Definition: CbmSimulationReport.h:123
CbmHistManager::ReadFromFile
void ReadFromFile(TFile *file)
Read histograms from file.
Definition: core/base/CbmHistManager.cxx:110
HistScale
HistScale
Define linear or logarithmic scale for drawing.
Definition: CbmDrawHist.h:77
CbmSimulationReport::Create
virtual void Create()=0
Inherited from CbmReport. Pure abstract function which is called from public Create() function.
CbmReport::GetReportName
const std::string & GetReportName() const
Definition: CbmReport.h:64
CbmSimulationReport::~CbmSimulationReport
virtual ~CbmSimulationReport()
Destructor.
Definition: CbmSimulationReport.cxx:27
CbmDrawHist.h
Helper functions for drawing 1D and 2D histograms and graphs.
CbmHistManager.h
Histogram manager.
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
CbmHistManager
Histogram manager.
Definition: CbmHistManager.h:41
kLinear
@ kLinear
Definition: CbmDrawHist.h:79
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmSimulationReport::DrawH1ByPattern
void DrawH1ByPattern(const std::string &histNamePattern)
Select by pattern TH1 histograms and draw each histogram on separate canvas.
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
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
CbmSimulationReport.h
Base class for simulation reports.
CbmHistManager::H2Vector
std::vector< TH2 * > H2Vector(const std::string &pattern) const
Return vector of pointers to TH2 histogram.
Definition: core/base/CbmHistManager.cxx:83
CbmSimulationReport
Base class for simulation reports.
Definition: CbmSimulationReport.h:28
DrawH2
void DrawH2(TH2 *hist, HistScale logx, HistScale logy, HistScale logz, const string &drawOpt)
Definition: CbmDrawHist.cxx:84
CbmReport
Base class for reports.
Definition: CbmReport.h:35
CbmReport::CreateReports
void CreateReports()
Create all available report types.
Definition: CbmReport.cxx:60
CbmSimulationReport::CbmSimulationReport
CbmSimulationReport()
Constructor.
Definition: CbmSimulationReport.cxx:25
CbmReport::SetOutputDir
void SetOutputDir(const std::string &outputDir)
Definition: CbmReport.h:61