1 #ifndef HistContainer_h
2 #define HistContainer_h
9 #include "TDirectoryFile.h"
14 typedef std::map<std::string, std::unique_ptr<TH1> >
HistMap;
27 HistContainer(
const std::string name, TDirectory* motherDir=
nullptr,
const std::string option=
"");
38 const TH1&
operator[](
const std::string& hist_name)
const;
42 const TH1*
FindHist(
const std::string& hist_name)
const;
51 void SaveAllAs(std::string prefix=
"./", std::string img_format=
"png");
56 TH1*
h(
const std::string& hist_name)
const;
73 return *(
fHs.at(hist_name));
88 auto iter =
fHs.find(hist_name);
89 return ( iter !=
fHs.end() ) ? iter->second.get() :
nullptr;
virtual void FillDerivedHists()
A user implementation of this method can be called when additional histograms need to be built from t...
std::map< std::string, std::unique_ptr< TH1 > > HistMap
HistContainer(const std::string name, TDirectory *motherDir=nullptr, const std::string option="")
Creates an empty histogram container.
A light container to hold and manipulate user histograms.
HistMap fHs
A container of unique pointers to TH1 objects indexed by names.
TH1 * h(const std::string &hist_name) const
Unrestricted access to stored histograms for friends.
const HistMap & GetHists() const
Returns a reference to the internal histogram container for external handling.
const TH1 & operator[](const std::string &hist_name) const
Returns a reference to the histogram with name hist_name, throws a std::out_of_range exception if no ...
const TH1 * FindHist(const std::string &hist_name) const
Returns a raw pointer to the histogram with hist_name name or nullptr such histogram does not exist...
void SaveAllAs(std::string prefix="./", std::string img_format="png")
Saves all histograms from the container as png images in the prefix directory.
void Add(TH1 *hist)
This container assumes the ownership of the histogram and can modify it.