11 #include "FairLogger.h"
14 #include "TDirectory.h"
23 #include "TProfile2D.h"
26 #include <boost/regex.hpp>
42 public std::binary_function<const TNamed*, const TNamed*, Bool_t> {
44 Bool_t
operator()(
const TNamed* object1,
const TNamed* object2)
const {
45 return string(object1->GetName()) > string(object2->GetName());
58 const boost::regex e(pattern);
59 map<string, TNamed*>::const_iterator it;
60 for (it =
fMap.begin(); it !=
fMap.end(); it++) {
61 if (boost::regex_match(it->first, e)) {
62 T ObjectPointer =
dynamic_cast<T
>(it->second);
63 if (ObjectPointer !=
nullptr) objects.push_back(ObjectPointer);
66 }
catch (exception& ex) {
67 LOG(info) <<
"Exception in CbmHistManager::ObjectVector: " << ex.what();
75 return ObjectVector<TH1*>(pattern);
79 return ObjectVector<TH2*>(pattern);
83 return ObjectVector<TGraph*>(pattern);
87 return ObjectVector<TGraph2D*>(pattern);
91 return ObjectVector<TProfile*>(pattern);
95 return ObjectVector<TProfile2D*>(pattern);
99 map<string, TNamed*>::iterator it;
100 for (it =
fMap.begin(); it !=
fMap.end(); it++) {
105 void CbmHistManager::WriteToFileNew(
const string& str) {
106 std::string histoName =
"";
107 map<string, TNamed*>::iterator it;
108 TDirectory* oldir = gDirectory;
109 TFile* fHist =
new TFile(str.c_str(),
"RECREATE");
112 TDirectory* cdHistosUpAndDown = fHist->mkdir(
"HistosUpAndDown");
113 cdHistosUpAndDown->cd();
114 for (it =
fMap.begin(); it !=
fMap.end(); it++) {
115 if (it->first.find(
"Up") != std::string::npos
116 || it->first.find(
"Down") != std::string::npos) {
117 if (!((it->first.find(
"Pi") != std::string::npos)
118 || (it->first.find(
"Plus") != std::string::npos)
119 || (it->first.find(
"Minus") != std::string::npos))) {
121 std::cout <<
"Histogram: " << it->first << std::endl;
126 TDirectory* cdHistosQa = fHist->mkdir(
"HistosQa");
128 for (it =
fMap.begin(); it !=
fMap.end(); it++) {
129 if (!(it->first.find(
"Up") != std::string::npos
130 || it->first.find(
"Down") != std::string::npos)) {
131 if (it->first.find(
"Pi") == std::string::npos) { it->second->Write(); }
137 gDirectory->cd(oldir->GetPath());
142 assert(file != NULL);
143 LOG(info) <<
"CbmHistManager::ReadFromFile";
144 TDirectory* dir = gDirectory;
145 TIter nextkey(dir->GetListOfKeys());
148 while ((key = (TKey*) nextkey())) {
149 TObject* obj = key->ReadObj();
150 if (obj->IsA()->InheritsFrom(TH1::Class())
151 || obj->IsA()->InheritsFrom(TGraph::Class())
152 || obj->IsA()->InheritsFrom(TGraph2D::Class())) {
153 TNamed*
h = (TNamed*) obj;
154 TNamed* h1 = (TNamed*) file->Get(
h->GetName());
155 Add(
string(
h->GetName()), h1);
162 map<string, TNamed*>::iterator it;
163 for (it =
fMap.begin(); it !=
fMap.end(); it++) {
170 TH1* hist =
H1(histName);
171 Int_t nofBins = hist->GetNbinsX();
174 Bool_t isSet =
false;
175 for (Int_t iBin = 1; iBin <= nofBins; iBin++) {
176 Double_t content = hist->GetBinContent(iBin);
178 minShrinkBin =
std::min(iBin, minShrinkBin);
179 maxShrinkBin =
std::max(iBin, maxShrinkBin);
184 hist->GetXaxis()->SetRange(minShrinkBin, maxShrinkBin);
190 vector<TH1*> effHistos =
H1Vector(pattern);
191 Int_t nofEffHistos = effHistos.size();
192 for (Int_t iHist = 0; iHist < nofEffHistos; iHist++) {
198 TH1* hist =
H2(histName);
199 Int_t nofBinsX = hist->GetNbinsX();
200 Int_t nofBinsY = hist->GetNbinsY();
205 Bool_t isSet =
false;
206 for (Int_t iBinX = 1; iBinX <= nofBinsX; iBinX++) {
207 for (Int_t iBinY = 1; iBinY <= nofBinsY; iBinY++) {
208 Double_t content = hist->GetBinContent(iBinX, iBinY);
210 minShrinkBinX =
std::min(iBinX, minShrinkBinX);
211 maxShrinkBinX =
std::max(iBinX, maxShrinkBinX);
212 minShrinkBinY =
std::min(iBinY, minShrinkBinY);
213 maxShrinkBinY =
std::max(iBinY, maxShrinkBinY);
219 hist->GetXaxis()->SetRange(minShrinkBinX, maxShrinkBinX);
220 hist->GetYaxis()->SetRange(minShrinkBinY, maxShrinkBinY);
225 vector<TH1*> effHistos =
H1Vector(pattern);
226 Int_t nofEffHistos = effHistos.size();
227 for (Int_t iHist = 0; iHist < nofEffHistos; iHist++) {
233 H1(histName)->Scale(scale);
237 vector<TH1*> effHistos =
H1Vector(pattern);
238 Int_t nofEffHistos = effHistos.size();
239 for (Int_t iHist = 0; iHist < nofEffHistos; iHist++) {
240 Scale(effHistos[iHist]->GetName(), scale);
245 TH1* hist =
H1(histName);
246 hist->Scale(1. / hist->Integral());
250 vector<TH1*> effHistos =
H1Vector(pattern);
251 Int_t nofEffHistos = effHistos.size();
252 for (Int_t iHist = 0; iHist < nofEffHistos; iHist++) {
258 TH1* hist =
H1(histName);
261 hist->Scale(1. / (Double_t) ngroup);
266 vector<TH1*> effHistos =
H1Vector(pattern);
267 Int_t nofEffHistos = effHistos.size();
268 for (Int_t iHist = 0; iHist < nofEffHistos; iHist++) {
269 Rebin(effHistos[iHist]->GetName(), ngroup);
274 string str =
"CbmHistManager list of histograms:\n";
275 map<string, TNamed*>::const_iterator it;
276 for (it =
fMap.begin(); it !=
fMap.end(); it++) {
277 str += it->first +
"\n";
283 const std::string& title,
286 TCanvas* c =
new TCanvas(name.c_str(), title.c_str(), width, height);
292 const std::string& options) {