14#include "boost/filesystem.hpp"
21using boost::filesystem::path;
32 if (array ==
nullptr) { LOG(fatal) << description <<
" No MCTrack!"; }
38 if (dir ==
"")
return;
48 if (dir ==
"")
return;
49 if (option.find(imageType) != string::npos) {
50 path fullPath = path(dir +
"/" + imageType +
"/" +
string(c->GetTitle()) +
"." + imageType);
51 string fullDir = fullPath.parent_path().string();
52 if (fullDir.length() > 0) {
53 gSystem->mkdir(fullDir.c_str(),
true);
55 c->SaveAs(fullPath.c_str());
59 string FindAndReplace(
const string& name,
const string& oldSubstr,
const string& newSubstr)
61 string newName = name;
62 Int_t startPos = name.find(oldSubstr);
63 newName.replace(startPos, oldSubstr.size(), newSubstr);
67 vector<string>
Split(
const string& name,
char delimiter)
69 vector<string> result;
70 std::size_t begin = 0;
71 std::size_t end = name.find_first_of(delimiter);
72 while (end != string::npos) {
73 string str = name.substr(begin, end - begin);
74 if (str[0] == delimiter) str.erase(0, 1);
75 result.push_back(str);
77 end = name.find_first_of(delimiter, end + 1);
79 result.push_back(name.substr(begin + 1));
84 TH1D*
DivideH1(TH1* h1, TH1* h2,
const string& histName,
double scale,
const string& titleYaxis)
86 int nBins = h1->GetNbinsX();
87 double min = h1->GetXaxis()->GetXmin();
88 double max = h1->GetXaxis()->GetXmax();
89 string hname = string(h1->GetName()) +
"_divide";
90 if (histName !=
"") hname = histName;
92 TH1D* h3 =
new TH1D(histName.c_str(), hname.c_str(), nBins, min, max);
93 h3->GetXaxis()->SetTitle(h1->GetXaxis()->GetTitle());
94 h3->GetYaxis()->SetTitle(titleYaxis.c_str());
98 h3->Divide(h1, h2, 1., 1.,
"B");
103 TH2D*
DivideH2(TH2* h1, TH2* h2,
const string& histName,
double scale,
const string& titleZaxis)
105 int nBinsX = h1->GetNbinsX();
106 double minX = h1->GetXaxis()->GetXmin();
107 double maxX = h1->GetXaxis()->GetXmax();
108 int nBinsY = h1->GetNbinsY();
109 double minY = h1->GetYaxis()->GetXmin();
110 double maxY = h1->GetYaxis()->GetXmax();
111 string hname = string(h1->GetName()) +
"_divide";
112 if (histName !=
"") hname = histName;
114 TH2D* h3 =
new TH2D(hname.c_str(), hname.c_str(), nBinsX, minX, maxX, nBinsY, minY, maxY);
115 h3->GetXaxis()->SetTitle(h1->GetXaxis()->GetTitle());
116 h3->GetYaxis()->SetTitle(h1->GetYaxis()->GetTitle());
117 h3->GetZaxis()->SetTitle(titleZaxis.c_str());
121 h3->Divide(h1, h2, 1., 1.,
"B");
Access to a MC data branch for time-based analysis.
Task class creating and managing CbmMCDataArray objects.
CbmMCDataArray * InitBranch(const char *name)
TH1D * DivideH1(TH1 *h1, TH1 *h2, const string &histName, double scale, const string &titleYaxis)
T * GetOrFatal(const std::string &objName, const std::string &description="")
void SaveCanvasAsImage(TCanvas *c, const string &dir, const string &option)
string FindAndReplace(const string &name, const string &oldSubstr, const string &newSubstr)
vector< string > Split(const string &name, char delimiter)
TH2D * DivideH2(TH2 *h1, TH2 *h2, const string &histName, double scale, const string &titleZaxis)
CbmMCDataArray * InitOrFatalMc(const std::string &objName, const std::string &description)
void SaveCanvasAsImageImpl(const string &imageType, TCanvas *c, const string &dir, const string &option)