12#ifndef CBMHISTMANAGER_H_
13#define CBMHISTMANAGER_H_
18#include <RtypesCore.h>
29#include <TProfile2D.h>
65 void Add(
const std::string& name, TNamed*
object)
68 std::map<std::string, TNamed*>::iterator it =
fMap.find(name);
69 if (it !=
fMap.end()) {
70 LOG(warn) <<
"CbmHistManager::Add Object with name:" << name <<
" was already added. Set new object.";
73 std::pair<std::string, TNamed*> newpair = std::make_pair(name,
object);
88 void Create1(
const std::string& name,
const std::string& title, Int_t nofBins, Double_t minBin, Double_t maxBin)
90 T*
h =
new T(name.c_str(), title.c_str(), nofBins, minBin, maxBin);
103 void Create1(
const std::string& name,
const std::string& title,
const std::vector<Double_t>& binsX)
105 T*
h =
new T(name.c_str(), title.c_str(), binsX.size() - 1, binsX.data());
123 void Create2(
const std::string& name,
const std::string& title, Int_t nofBinsX, Double_t minBinX, Double_t maxBinX,
124 Int_t nofBinsY, Double_t minBinY, Double_t maxBinY)
126 T*
h =
new T(name.c_str(), title.c_str(), nofBinsX, minBinX, maxBinX, nofBinsY, minBinY, maxBinY);
140 void Create2(
const std::string& name,
const std::string& title,
const std::vector<Double_t>& binsX,
141 const std::vector<Double_t>& binsY)
143 T*
h =
new T(name.c_str(), title.c_str(), binsX.size() - 1, binsX.data(), binsY.size() - 1, binsY.data());
164 void Create3(
const std::string& name,
const std::string& title, Int_t nofBinsX, Double_t minBinX, Double_t maxBinX,
165 Int_t nofBinsY, Double_t minBinY, Double_t maxBinY, Int_t nofBinsZ, Double_t minBinZ, Double_t maxBinZ)
167 T*
h =
new T(name.c_str(), title.c_str(), nofBinsX, minBinX, maxBinX, nofBinsY, minBinY, maxBinY, nofBinsZ, minBinZ,
183 template<
class T,
int nDim>
184 void CreateSparse(
const std::string& name,
const std::string& title,
const std::array<Int_t, nDim>& nBins,
185 const std::array<Double_t, nDim>& minVals,
const std::array<Double_t, nDim>& maxVals)
187 static_assert(std::is_base_of<THnSparse, T>::value,
"Class must be derrived from THnSparse");
188 T*
h =
new T(name.c_str(), title.c_str(), nDim, nBins.data(), minVals.data(), maxVals.data());
194 if (
fMap.count(name) == 0) {
195 LOG(error) <<
"CbmHistManager::GetObject(name): name=" << name;
197 assert(
fMap.count(name) != 0);
198 return fMap.find(name)->second;
207 TH1*
H1(
const std::string& name)
const
209 if (
fMap.count(name) == 0) {
210 LOG(error) <<
"CbmHistManager::H1(name): name=" << name;
212 assert(
fMap.count(name) != 0);
213 return dynamic_cast<TH1*
>(
fMap.find(name)->second);
221 TH1*
H1Clone(
const std::string& name)
const {
return static_cast<TH1*
>(
H1(name)->Clone()); }
228 std::vector<TH1*>
H1Vector(
const std::vector<std::string>& names)
const;
236 std::vector<TH1*>
H1Vector(
const std::string& pattern)
const;
243 TH2*
H2(
const std::string& name)
const
245 if (
fMap.count(name) == 0) {
246 LOG(error) <<
"CbmHistManager::H2(name): name=" << name;
248 assert(
fMap.count(name) != 0);
249 return dynamic_cast<TH2*
>(
fMap.find(name)->second);
257 TH2*
H2Clone(
const std::string& name)
const {
return static_cast<TH2*
>(
H2(name)->Clone()); }
264 std::vector<TH2*>
H2Vector(
const std::vector<std::string>& names)
const;
271 std::vector<TH2*>
H2Vector(
const std::string& pattern)
const;
278 TH3*
H3(
const std::string& name)
const
280 if (
fMap.count(name) == 0) {
281 LOG(error) <<
"CbmHistManager::H3(name): name=" << name;
283 assert(
fMap.count(name) != 0);
284 return dynamic_cast<TH3*
>(
fMap.find(name)->second);
292 TH3*
H3Clone(
const std::string& name)
const {
return static_cast<TH3*
>(
H3(name)->Clone()); }
301 if (
fMap.count(name) == 0) {
302 LOG(error) <<
"CbmHistManager::HnSparse(name): name=" << name;
304 assert(
fMap.count(name) != 0);
305 return dynamic_cast<THnSparse*
>(
fMap.find(name)->second);
313 TGraph*
G1(
const std::string& name)
const
315 if (
fMap.count(name) == 0) {
316 LOG(error) <<
"CbmHistManager::G1(name): name=" << name;
318 assert(
fMap.count(name) != 0);
319 return dynamic_cast<TGraph*
>(
fMap.find(name)->second);
327 std::vector<TGraph*>
G1Vector(
const std::vector<std::string>& names)
const;
334 std::vector<TGraph*>
G1Vector(
const std::string& pattern)
const;
341 TGraph2D*
G2(
const std::string& name)
const
343 if (
fMap.count(name) == 0) {
344 LOG(error) <<
"CbmHistManager::G2(name): name=" << name;
346 assert(
fMap.count(name) != 0);
347 return dynamic_cast<TGraph2D*
>(
fMap.find(name)->second);
355 std::vector<TGraph2D*>
G2Vector(
const std::vector<std::string>& names)
const;
362 std::vector<TGraph2D*>
G2Vector(
const std::string& pattern)
const;
369 TProfile*
P1(
const std::string& name)
const
371 if (
fMap.count(name) == 0) {
372 LOG(error) <<
"CbmHistManager::P1(name): name=" << name;
374 assert(
fMap.count(name) != 0);
375 return dynamic_cast<TProfile*
>(
fMap.find(name)->second);
383 std::vector<TProfile*>
P1Vector(
const std::vector<std::string>& names)
const;
390 std::vector<TProfile*>
P1Vector(
const std::string& pattern)
const;
397 TProfile2D*
P2(
const std::string& name)
const
399 if (
fMap.count(name) == 0) {
400 LOG(error) <<
"CbmHistManager::P2(name): name=" << name;
402 assert(
fMap.count(name) != 0);
403 return dynamic_cast<TProfile2D*
>(
fMap.find(name)->second);
411 std::vector<TProfile2D*>
P2Vector(
const std::vector<std::string>& names)
const;
418 std::vector<TProfile2D*>
P2Vector(
const std::string& pattern)
const;
425 Bool_t
Exists(
const std::string& name)
const {
return (
fMap.count(name) == 0) ? false :
true; }
456 void Clear(Option_t* =
"");
487 void Scale(
const std::string& histName, Double_t scale);
513 void Rebin(
const std::string& histName, Int_t ngroup);
546 TCanvas*
CreateCanvas(
const std::string& name,
const std::string& title, Int_t width, Int_t height);
553 void SaveCanvasToImage(
const std::string& outputDir,
const std::string& options =
"png,eps");
560 std::vector<T>
ObjectVector(
const std::vector<std::string>& names)
const;
562 std::map<std::string, TNamed*>
fMap;
TGraph2D * G2(const std::string &name) const
Return pointer to TGraph2D.
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.
TProfile * P1(const std::string &name) const
Return pointer to TProfile.
std::vector< TGraph2D * > G2Vector(const std::vector< std::string > &names) const
Return vector of pointers to TGraph2D.
std::vector< TH2 * > H2Vector(const std::string &pattern) const
Return vector of pointers to TH2 histogram.
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< TProfile2D * > P2Vector(const std::string &pattern) const
Return vector of pointers to TProfile2D.
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< TProfile * > P1Vector(const std::string &pattern) const
Return vector of pointers to TProfile.
std::vector< TH1 * > H1Vector(const std::string &pattern) const
Return vector of pointers to TH1 histogram.
std::vector< TProfile2D * > P2Vector(const std::vector< std::string > &names) const
Return vector of pointers to TProfile2D.
TProfile2D * P2(const std::string &name) const
Return pointer to TProfile2D.
std::map< std::string, TNamed * > fMap
TH2 * H2(const std::string &name) const
Return pointer to TH2 histogram.
void Create1(const std::string &name, const std::string &title, const std::vector< Double_t > &binsX)
Helper function for creation of 1-dimensional histograms and profiles. Template argument is a real ob...
TNamed * GetObject(const std::string &name) const
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 Create2(const std::string &name, const std::string &title, Int_t nofBinsX, Double_t minBinX, Double_t maxBinX, Int_t nofBinsY, Double_t minBinY, Double_t maxBinY)
Helper function for creation of 2-dimensional histograms and profiles. Template argument is a real ob...
TH3 * H3Clone(const std::string &name) const
Return clone of TH3 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.
TGraph * G1(const std::string &name) const
Return pointer to TGraph.
void WriteToFile()
Write all objects to current opened file.
void Create2(const std::string &name, const std::string &title, const std::vector< Double_t > &binsX, const std::vector< Double_t > &binsY)
Helper function for creation of 2-dimensional histograms and profiles. Template argument is a real ob...
TH3 * H3(const std::string &name) const
Return pointer to TH3 histogram.
void ShrinkEmptyBinsH2(const std::string &histName)
Shrink empty bins in H2.
void CreateSparse(const std::string &name, const std::string &title, const std::array< Int_t, nDim > &nBins, const std::array< Double_t, nDim > &minVals, const std::array< Double_t, nDim > &maxVals)
Helper function for creation of THnSparse objects.
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.
Bool_t Exists(const std::string &name) const
Check existence of object in manager.
TH2 * H2Clone(const std::string &name) const
Return clone of TH2 histogram.
void NormalizeToIntegralByPattern(const std::string &pattern)
Normalize histograms to integral which name matches specified pattern.
void Create1(const std::string &name, const std::string &title, Int_t nofBins, Double_t minBin, Double_t maxBin)
Helper function for creation of 1-dimensional histograms and profiles. Template argument is a real ob...
void Add(const std::string &name, TNamed *object)
Add new named object to manager.
void Create3(const std::string &name, const std::string &title, Int_t nofBinsX, Double_t minBinX, Double_t maxBinX, Int_t nofBinsY, Double_t minBinY, Double_t maxBinY, Int_t nofBinsZ, Double_t minBinZ, Double_t maxBinZ)
Helper function for creation of 3-dimensional histograms and profiles. Template argument is a real ob...
void ShrinkEmptyBinsH1(const std::string &histName)
Shrink empty bins in H1.
virtual ~CbmHistManager()
Destructor.
std::vector< TGraph * > G1Vector(const std::string &pattern) const
Return vector of pointers to TGraph.
friend std::ostream & operator<<(std::ostream &strm, const CbmHistManager &histManager)
Operator << for convenient output to std::ostream.
std::string ToString() const
Return string representation of class.
TH1 * H1Clone(const std::string &name) const
Return clone of TH1 histogram.
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.
THnSparse * HnSparse(const std::string &name) const
Return pointer to THnSparse histogram.
std::vector< TGraph2D * > G2Vector(const std::string &pattern) const
Return vector of pointers to TGraph2D.
std::vector< T > ObjectVector(const std::vector< std::string > &names) const
Data class with information on a STS local track.