18#include <TCollection.h>
19#include <TDirectory.h>
20#include <TDirectoryFile.h>
21#include <TGenericClassInfo.h>
31#include <TProfile2D.h>
33#include <boost/regex.hpp>
60 const boost::regex e(pattern);
61 map<string, TNamed*>::const_iterator it;
62 for (it =
fMap.begin(); it !=
fMap.end(); it++) {
63 if (boost::regex_match(it->first, e)) {
64 T ObjectPointer =
dynamic_cast<T
>(it->second);
65 if (ObjectPointer !=
nullptr) objects.push_back(ObjectPointer);
69 catch (exception& ex) {
70 LOG(info) <<
"Exception in CbmHistManager::ObjectVector: " << ex.what();
73 sort(objects.begin(), objects.end(), [](
const TNamed* object1,
const TNamed* object2) {
74 return string(object1->GetName()) > string(object2->GetName());
96 for (
const string& name : names) {
97 objects.push_back(
dynamic_cast<T
>(
fMap.find(name)->second));
118 map<string, TNamed*>::iterator it;
119 for (it =
fMap.begin(); it !=
fMap.end(); it++) {
133 assert(file !=
nullptr);
134 LOG(info) <<
"CbmHistManager::ReadFromFile";
135 TDirectory* dir = gDirectory;
136 TIter nextkey(dir->GetListOfKeys());
138 while ((key = (TKey*) nextkey())) {
139 TObject* obj = key->ReadObj();
147 if (obj->IsA()->InheritsFrom(TH1::Class()) || obj->IsA()->InheritsFrom(TGraph::Class())
148 || obj->IsA()->InheritsFrom(TGraph2D::Class()) || obj->IsA()->InheritsFrom(THnBase::Class())) {
149 TNamed*
h = (TNamed*) obj;
151 Add(
string(
h->GetName()),
h);
157 if (obj->IsA()->InheritsFrom(TDirectoryFile::Class())) {
158 TDirectoryFile* fileDir = (TDirectoryFile*) obj;
159 TIter nextkey(fileDir->GetListOfKeys());
161 while ((key2 = (TKey*) nextkey())) {
162 TObject* obj2 = key2->ReadObj();
171 for (
auto& pair :
fMap) {
184 TH1* hist =
H1(histName);
185 Int_t nofBins = hist->GetNbinsX();
186 Int_t minShrinkBin = std::numeric_limits<Int_t>::max();
187 Int_t maxShrinkBin = std::numeric_limits<Int_t>::min();
188 Bool_t isSet =
false;
189 for (Int_t iBin = 1; iBin <= nofBins; iBin++) {
190 Double_t content = hist->GetBinContent(iBin);
192 minShrinkBin = std::min(iBin, minShrinkBin);
193 maxShrinkBin = std::max(iBin, maxShrinkBin);
198 hist->GetXaxis()->SetRange(minShrinkBin, maxShrinkBin);
205 vector<TH1*> effHistos =
H1Vector(pattern);
206 Int_t nofEffHistos = effHistos.size();
207 for (Int_t iHist = 0; iHist < nofEffHistos; iHist++) {
214 TH1* hist =
H2(histName);
215 Int_t nofBinsX = hist->GetNbinsX();
216 Int_t nofBinsY = hist->GetNbinsY();
217 Int_t minShrinkBinX = std::numeric_limits<Int_t>::max();
218 Int_t maxShrinkBinX = std::numeric_limits<Int_t>::min();
219 Int_t minShrinkBinY = std::numeric_limits<Int_t>::max();
220 Int_t maxShrinkBinY = std::numeric_limits<Int_t>::min();
221 Bool_t isSet =
false;
222 for (Int_t iBinX = 1; iBinX <= nofBinsX; iBinX++) {
223 for (Int_t iBinY = 1; iBinY <= nofBinsY; iBinY++) {
224 Double_t content = hist->GetBinContent(iBinX, iBinY);
226 minShrinkBinX = std::min(iBinX, minShrinkBinX);
227 maxShrinkBinX = std::max(iBinX, maxShrinkBinX);
228 minShrinkBinY = std::min(iBinY, minShrinkBinY);
229 maxShrinkBinY = std::max(iBinY, maxShrinkBinY);
235 hist->GetXaxis()->SetRange(minShrinkBinX, maxShrinkBinX);
236 hist->GetYaxis()->SetRange(minShrinkBinY, maxShrinkBinY);
242 vector<TH1*> effHistos =
H1Vector(pattern);
243 Int_t nofEffHistos = effHistos.size();
244 for (Int_t iHist = 0; iHist < nofEffHistos; iHist++) {
253 vector<TH1*> effHistos =
H1Vector(pattern);
254 Int_t nofEffHistos = effHistos.size();
255 for (Int_t iHist = 0; iHist < nofEffHistos; iHist++) {
256 Scale(effHistos[iHist]->GetName(), scale);
262 TH1* hist =
H1(histName);
263 hist->Scale(1. / hist->Integral());
268 vector<TH1*> effHistos =
H1Vector(pattern);
269 Int_t nofEffHistos = effHistos.size();
270 for (Int_t iHist = 0; iHist < nofEffHistos; iHist++) {
277 TH1* hist =
H1(histName);
280 hist->Scale(1. / (Double_t) ngroup);
286 vector<TH1*> effHistos =
H1Vector(pattern);
287 Int_t nofEffHistos = effHistos.size();
288 for (Int_t iHist = 0; iHist < nofEffHistos; iHist++) {
289 Rebin(effHistos[iHist]->GetName(), ngroup);
295 string str =
"CbmHistManager list of histograms:\n";
296 map<string, TNamed*>::const_iterator it;
297 for (it =
fMap.begin(); it !=
fMap.end(); it++) {
298 str += it->first +
"\n";
305 TCanvas* c =
new TCanvas(name.c_str(), title.c_str(), width, height);
312 for (
unsigned int i = 0; i <
fCanvases.size(); i++) {
ClassImp(CbmConverterManager)
void ShrinkEmptyBinsH1ByPattern(const std::string &pattern)
Shrink empty bins in H1.
CbmHistManager()
Constructor.
TCanvas * CreateCanvas(const std::string &name, const std::string &title, Int_t width, Int_t height)
Create and draw TCanvas and store pointer to it.
std::vector< TGraph2D * > G2Vector(const std::vector< std::string > &names) const
Return vector of pointers to TGraph2D.
void AddTNamedObject(TObject *obj)
Add TName object to map. Used in ReadFromFile method.
void ShrinkEmptyBinsH2ByPattern(const std::string &pattern)
Shrink empty bins in H2.
std::vector< TCanvas * > fCanvases
void SaveCanvasToImage(const std::string &outputDir, const std::string &options="png,eps")
Save all stored canvases to images.
std::vector< TH1 * > H1Vector(const std::vector< std::string > &names) const
Return vector of pointers to TH1 histogram.
void Clear(Option_t *="")
Clear memory. Remove all histograms and canvases.
std::vector< TProfile2D * > P2Vector(const std::vector< std::string > &names) const
Return vector of pointers to TProfile2D.
std::map< std::string, TNamed * > fMap
TH2 * H2(const std::string &name) const
Return pointer to TH2 histogram.
std::vector< TProfile * > P1Vector(const std::vector< std::string > &names) const
Return vector of pointers to TProfile.
void Rebin(const std::string &histName, Int_t ngroup)
Rebin histogram.
void ReadFromFile(TFile *file)
Read histograms from file.
void Scale(const std::string &histName, Double_t scale)
Scale histogram.
std::vector< TH2 * > H2Vector(const std::vector< std::string > &names) const
Return vector of pointers to TH2 histogram.
void ScaleByPattern(const std::string &pattern, Double_t scale)
Scale histograms which name matches specified pattern.
void AddTDirectoryObject(TObject *obj)
Add all TName objects to map in directory. Used in ReadFromFile method.
void WriteToFile()
Write all objects to current opened file.
void ShrinkEmptyBinsH2(const std::string &histName)
Shrink empty bins in H2.
std::vector< TGraph * > G1Vector(const std::vector< std::string > &names) const
Return vector of pointers to TGraph.
void RebinByPattern(const std::string &pattern, Int_t ngroup)
Rebin histograms which name matches specified pattern.
void NormalizeToIntegral(const std::string &histName)
Normalize histogram to integral.
void NormalizeToIntegralByPattern(const std::string &pattern)
Normalize histograms to integral which name matches specified pattern.
void Add(const std::string &name, TNamed *object)
Add new named object to manager.
void ShrinkEmptyBinsH1(const std::string &histName)
Shrink empty bins in H1.
virtual ~CbmHistManager()
Destructor.
std::string ToString() const
Return string representation of class.
void WriteCanvasToFile()
Write all canvas to current opened file.
std::vector< T > ObjectVector(const std::string &pattern) const
TH1 * H1(const std::string &name) const
Return pointer to TH1 histogram.
Data class with information on a STS local track.
void SaveCanvasAsImage(TCanvas *c, const string &dir, const string &option)