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 <fstream> // for string, ofstream
22#include <string> // for operator+
23#include <vector> // for vector, __vector_base<>::value_type
24
25#include <assert.h> // for assert
26
27using std::ofstream;
28using std::string;
29using std::vector;
30
32
34
35void CbmSimulationReport::Create(CbmHistManager* histManager, const string& outputDir)
36{
37 assert(histManager != nullptr);
38 fHM = histManager;
39 SetOutputDir(outputDir);
41}
42
43void CbmSimulationReport::Create(const string& fileName, const string& outputDir)
44{
45 assert(fHM == nullptr);
46 fHM = new CbmHistManager();
47
48 TFile* oldFile = gFile;
49 TDirectory* oldDir = gDirectory;
50
51 TFile* file = new TFile(fileName.c_str());
52 fHM->ReadFromFile(file);
53 SetOutputDir(outputDir);
55 // delete fHM;
56 // delete file;
57
58 // shouldn't the file be closed ????
59 // file->Close();
60 gFile = oldFile;
61 gDirectory = oldDir;
62}
63
64void CbmSimulationReport::DrawH1ByPattern(const string& histNamePattern)
65{
66 vector<TH1*> histos = HM()->H1Vector(histNamePattern);
67 UInt_t nofHistos = histos.size();
68 if (nofHistos < 1) return;
69 for (UInt_t iHist = 0; iHist < nofHistos; iHist++) {
70 TH1* hist = histos[iHist];
71 string canvasName = GetReportName() + hist->GetName();
72 // TCanvas* canvas = CreateCanvas(canvasName.c_str(), canvasName.c_str(), 800, 500);
73 CreateCanvas(canvasName.c_str(), canvasName.c_str(), 800, 500);
74 DrawH1(hist, kLinear, kLinear);
75 }
76}
77
78void CbmSimulationReport::DrawH1ByPattern(const string& histNamePattern,
79 string (*labelFormatter)(const string&, const CbmHistManager*))
80{
81 vector<TH1*> histos = HM()->H1Vector(histNamePattern);
82 UInt_t nofHistos = histos.size();
83 if (nofHistos < 1) return;
84 string canvasName = GetReportName() + histos[0]->GetName();
85 // TCanvas* canvas = CreateCanvas(canvasName.c_str(), canvasName.c_str(), 600, 500);
86 CreateCanvas(canvasName.c_str(), canvasName.c_str(), 600, 500);
87
88 vector<string> labels(nofHistos);
89 for (UInt_t iHist = 0; iHist < nofHistos; iHist++) {
90 string name = histos[iHist]->GetName();
91 labels[iHist] = labelFormatter(name, HM());
92 }
93
94 DrawH1(histos, labels, kLinear, kLinear, true, 0.3, 0.3, 0.85, 0.6, "PE1");
95}
96
97void CbmSimulationReport::DrawH2ByPattern(const string& histNamePattern, HistScale logx, HistScale logy, HistScale logz,
98 const string& drawOpt)
99{
100 vector<TH2*> histos = HM()->H2Vector(histNamePattern);
101 UInt_t nofHistos = histos.size();
102 if (nofHistos < 1) return;
103 for (UInt_t iHist = 0; iHist < nofHistos; iHist++) {
104 TH2* hist = histos[iHist];
105 string canvasName = GetReportName() + hist->GetName();
106 // TCanvas* canvas = CreateCanvas(canvasName.c_str(), canvasName.c_str(), 800, 500);
107 CreateCanvas(canvasName.c_str(), canvasName.c_str(), 800, 500);
108 DrawH2(hist, logx, logy, logz, drawOpt);
109 }
110}
111
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.
void ReadFromFile(TFile *file)
Read histograms from file.
std::vector< TH2 * > H2Vector(const std::vector< std::string > &names) const
Return vector of pointers to TH2 histogram.
Base class for reports.
Definition CbmReport.h:45
void SetOutputDir(const std::string &outputDir)
Definition CbmReport.h:71
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.