CbmRoot
Loading...
Searching...
No Matches
CbmSimulationReport.cxx
Go to the documentation of this file.
1/* Copyright (C) 2011-2021 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Semen Lebedev, Andrey Lebedev [committer], Florian Uhlig */
4
10#include "CbmSimulationReport.h"
11
12#include "CbmDrawHist.h" // for DrawH1, kLinear, DrawH2, HistScale
13#include "CbmHistManager.h" // for CbmHistManager
14
15#include <RtypesCore.h> // for UInt_t
16#include <TDirectory.h> // for TDirectory, gDirectory
17#include <TFile.h> // for TFile, gFile
18#include <TH1.h> // for TH1
19#include <TH2.h> // for TH2
20
21#include <cassert> // for assert
22#include <fstream> // for string, ofstream
23#include <string> // for operator+
24#include <vector> // for vector, __vector_base<>::value_type
25
26using std::ofstream;
27using std::string;
28using std::vector;
29
31
33
34void CbmSimulationReport::Create(CbmHistManager* histManager, const string& outputDir)
35{
36 assert(histManager != nullptr);
37 fHM = histManager;
38 SetOutputDir(outputDir);
40}
41
42void CbmSimulationReport::Create(const string& fileName, const string& outputDir)
43{
44 assert(fHM == nullptr);
45 fHM = new CbmHistManager();
46
47 TFile* oldFile = gFile;
48 TDirectory* oldDir = gDirectory;
49
50 TFile* file = new TFile(fileName.c_str());
51 fHM->ReadFromFile(file);
52 SetOutputDir(outputDir);
54 // delete fHM;
55 // delete file;
56
57 // shouldn't the file be closed ????
58 // file->Close();
59 gFile = oldFile;
60 gDirectory = oldDir;
61}
62
63void CbmSimulationReport::DrawH1ByPattern(const string& histNamePattern)
64{
65 vector<TH1*> histos = HM()->H1Vector(histNamePattern);
66 UInt_t nofHistos = histos.size();
67 if (nofHistos < 1) return;
68 for (UInt_t iHist = 0; iHist < nofHistos; iHist++) {
69 TH1* hist = histos[iHist];
70 string canvasName = GetReportName() + hist->GetName();
71 // TCanvas* canvas = CreateCanvas(canvasName.c_str(), canvasName.c_str(), 800, 500);
72 CreateCanvas(canvasName.c_str(), canvasName.c_str(), 800, 500);
73 DrawH1(hist, kLinear, kLinear);
74 }
75}
76
77void CbmSimulationReport::DrawH1ByPattern(const string& histNamePattern,
78 string (*labelFormatter)(const string&, const CbmHistManager*))
79{
80 vector<TH1*> histos = HM()->H1Vector(histNamePattern);
81 UInt_t nofHistos = histos.size();
82 if (nofHistos < 1) return;
83 string canvasName = GetReportName() + histos[0]->GetName();
84 // TCanvas* canvas = CreateCanvas(canvasName.c_str(), canvasName.c_str(), 600, 500);
85 CreateCanvas(canvasName.c_str(), canvasName.c_str(), 600, 500);
86
87 vector<string> labels(nofHistos);
88 for (UInt_t iHist = 0; iHist < nofHistos; iHist++) {
89 string name = histos[iHist]->GetName();
90 labels[iHist] = labelFormatter(name, HM());
91 }
92
93 DrawH1(histos, labels, kLinear, kLinear, true, 0.3, 0.3, 0.85, 0.6, "PE1");
94}
95
96void CbmSimulationReport::DrawH2ByPattern(const string& histNamePattern, HistScale logx, HistScale logy, HistScale logz,
97 const string& drawOpt)
98{
99 vector<TH2*> histos = HM()->H2Vector(histNamePattern);
100 UInt_t nofHistos = histos.size();
101 if (nofHistos < 1) return;
102 for (UInt_t iHist = 0; iHist < nofHistos; iHist++) {
103 TH2* hist = histos[iHist];
104 string canvasName = GetReportName() + hist->GetName();
105 // TCanvas* canvas = CreateCanvas(canvasName.c_str(), canvasName.c_str(), 800, 500);
106 CreateCanvas(canvasName.c_str(), canvasName.c_str(), 800, 500);
107 DrawH2(hist, logx, logy, logz, drawOpt);
108 }
109}
110
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)
void DrawH2(TH2 *hist, HistScale logx, HistScale logy, HistScale logz, const string &drawOpt)
Helper functions for drawing 1D and 2D histograms and graphs.
HistScale
Define linear or logarithmic scale for drawing.
Definition CbmDrawHist.h:67
@ kLinear
Definition CbmDrawHist.h:69
Histogram manager.
Base class for simulation reports.
Histogram manager.
std::vector< TH1 * > H1Vector(const std::vector< std::string > &names) const
Return vector of pointers to TH1 histogram.
std::vector< TH2 * > H2Vector(const std::vector< std::string > &names) const
Return vector of pointers to TH2 histogram.
void SetOutputDir(const std::string &outputDir)
Definition CbmReport.h:71
CbmReport()
Constructor.
Definition CbmReport.cxx:28
const std::string & GetReportName() const
Definition CbmReport.h:74
void CreateReports()
Create all available report types.
Definition CbmReport.cxx:71
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.
CbmSimulationReport()
Constructor.
virtual void Create()=0
Inherited from CbmReport. Pure abstract function which is called from public Create() function.
virtual ~CbmSimulationReport()
Destructor.
void DrawH1ByPattern(const std::string &histNamePattern)
Select by pattern TH1 histograms and draw each histogram on separate canvas.
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.