travex
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
tvx::HistContainer Class Reference

A light container to hold and manipulate user histograms. More...

#include <HistContainer.h>

Inheritance diagram for tvx::HistContainer:

Public Member Functions

 HistContainer (const std::string name, TDirectory *motherDir=nullptr, const std::string option="")
 Creates an empty histogram container. More...
 
void Add (TH1 *hist)
 This container assumes the ownership of the histogram and can modify it. More...
 
const HistMapGetHists () const
 Returns a reference to the internal histogram container for external handling. More...
 
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 such histogram exists. More...
 
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. More...
 
virtual void FillDerivedHists ()
 A user implementation of this method can be called when additional histograms need to be built from the already available ones. More...
 
void SaveAllAs (std::string prefix="./", std::string img_format="png")
 Saves all histograms from the container as png images in the prefix directory. More...
 

Protected Member Functions

TH1 * h (const std::string &hist_name) const
 Unrestricted access to stored histograms for friends. More...
 

Private Attributes

HistMap fHs
 A container of unique pointers to TH1 objects indexed by names. More...
 

Detailed Description

A light container to hold and manipulate user histograms.

This class may be used by itself or serve as a base class when additional functionality is needed to fill user histograms. When saved in a ROOT file the histograms are placed in a subdirectory named name in motherDir.

Definition at line 23 of file HistContainer.h.

Constructor & Destructor Documentation

HistContainer::HistContainer ( const std::string  name,
TDirectory *  motherDir = nullptr,
const std::string  option = "" 
)

Creates an empty histogram container.

Follow up by filling it with TH1* objects using HistContainer::Add(TH1* hist).

Definition at line 17 of file HistContainer.cxx.

Member Function Documentation

void HistContainer::Add ( TH1 *  hist)

This container assumes the ownership of the histogram and can modify it.

Adds the user provided histogram to the internal container.

Basic checks are performed to validate the pointer.

Definition at line 29 of file HistContainer.cxx.

void tvx::HistContainer::FillDerivedHists ( )
inlinevirtual

A user implementation of this method can be called when additional histograms need to be built from the already available ones.

Usage cases include a ratio of two histograms or a fit to the histogram data points

Definition at line 83 of file HistContainer.h.

const TH1 * tvx::HistContainer::FindHist ( const std::string &  hist_name) const
inline

Returns a raw pointer to the histogram with hist_name name or nullptr such histogram does not exist.

Definition at line 77 of file HistContainer.h.

const HistMap & tvx::HistContainer::GetHists ( ) const
inline

Returns a reference to the internal histogram container for external handling.

Definition at line 65 of file HistContainer.h.

TH1 * tvx::HistContainer::h ( const std::string &  hist_name) const
inlineprotected

Unrestricted access to stored histograms for friends.

Definition at line 86 of file HistContainer.h.

const TH1 & tvx::HistContainer::operator[] ( const std::string &  hist_name) const
inline

Returns a reference to the histogram with name hist_name, throws a std::out_of_range exception if no such histogram exists.

Definition at line 71 of file HistContainer.h.

void HistContainer::SaveAllAs ( std::string  prefix = "./",
std::string  img_format = "png" 
)

Saves all histograms from the container as png images in the prefix directory.

Some additional options, such as XX, XY, and XZ specifying logarithmic X, Y, and Z axes correspondingly, are recognized if set with TH1::SetOption().

For the list of supported image formats see ROOT's TPad::SaveAs(...)

Definition at line 53 of file HistContainer.cxx.

Member Data Documentation

HistMap tvx::HistContainer::fHs
private

A container of unique pointers to TH1 objects indexed by names.

Definition at line 61 of file HistContainer.h.


The documentation for this class was generated from the following files: