7#include "boost/filesystem.hpp"
20using boost::filesystem::path;
31 if (array ==
nullptr) { LOG(fatal) << description <<
" No MCTrack!"; }
37 if (dir ==
"")
return;
47 if (dir ==
"")
return;
48 if (option.find(imageType) != string::npos) {
49 path fullPath = path(dir +
"/" + imageType +
"/" +
string(c->GetTitle()) +
"." + imageType);
50 string fullDir = fullPath.parent_path().string();
51 if (fullDir.length() > 0) {
52 gSystem->mkdir(fullDir.c_str(),
true);
54 c->SaveAs(fullPath.c_str());
58 string FindAndReplace(
const string& name,
const string& oldSubstr,
const string& newSubstr)
60 string newName = name;
61 Int_t startPos = name.find(oldSubstr);
62 newName.replace(startPos, oldSubstr.size(), newSubstr);
69 std::size_t begin = 0;
70 std::size_t end = name.find_first_of(delimiter);
71 while (end != string::npos) {
72 string str = name.substr(begin, end - begin);
73 if (str[0] == delimiter) str.erase(0, 1);
74 result.push_back(str);
76 end = name.find_first_of(delimiter, end + 1);
78 result.push_back(name.substr(begin + 1));
83 TH1D*
DivideH1(TH1* h1, TH1* h2,
const string& histName,
double scale,
const string& titleYaxis)
85 int nBins = h1->GetNbinsX();
86 double min = h1->GetXaxis()->GetXmin();
87 double max = h1->GetXaxis()->GetXmax();
88 string hname = string(h1->GetName()) +
"_divide";
89 if (histName !=
"") hname = histName;
91 TH1D* h3 =
new TH1D(histName.c_str(), hname.c_str(), nBins,
min,
max);
92 h3->GetXaxis()->SetTitle(h1->GetXaxis()->GetTitle());
93 h3->GetYaxis()->SetTitle(titleYaxis.c_str());
97 h3->Divide(h1, h2, 1., 1.,
"B");
102 TH2D*
DivideH2(TH2* h1, TH2* h2,
const string& histName,
double scale,
const string& titleZaxis)
104 int nBinsX = h1->GetNbinsX();
105 double minX = h1->GetXaxis()->GetXmin();
106 double maxX = h1->GetXaxis()->GetXmax();
107 int nBinsY = h1->GetNbinsY();
108 double minY = h1->GetYaxis()->GetXmin();
109 double maxY = h1->GetYaxis()->GetXmax();
110 string hname = string(h1->GetName()) +
"_divide";
111 if (histName !=
"") hname = histName;
113 TH2D* h3 =
new TH2D(hname.c_str(), hname.c_str(), nBinsX, minX, maxX, nBinsY, minY, maxY);
114 h3->GetXaxis()->SetTitle(h1->GetXaxis()->GetTitle());
115 h3->GetYaxis()->SetTitle(h1->GetYaxis()->GetTitle());
116 h3->GetZaxis()->SetTitle(titleZaxis.c_str());
120 h3->Divide(h1, h2, 1., 1.,
"B");
friend fscal max(fscal x, fscal y)
friend fscal min(fscal x, fscal y)
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)