BmnRoot
Loading...
Searching...
No Matches
BmnHistManager.h
Go to the documentation of this file.
1
8#ifndef BMNHISTMANAGER_H_
9#define BMNHISTMANAGER_H_
10
11#include "TObject.h"
12#include <iostream>
13#include <map>
14#include "TString.h"
15#include <vector>
16#include <cassert>
17#include <utility>
18#include <functional>
19
20class TFile;
21class TNamed;
22class TH1;
23class TH2;
24class TGraph;
25class TGraph2D;
26class TProfile;
27class TProfile2D;
28
29using std::map;
30using std::make_pair;
31using std::string;
32using std::vector;
33
40class BmnHistManager : public TObject
41{
42public:
43
48
52 virtual ~BmnHistManager();
53
59 void Add(const TString& name, TNamed* object) {
60 std::pair<TString, TNamed*> newpair = std::make_pair(name, object);
61 fMap.insert(newpair);
62 }
63
74 template<class T> void Create1(
75 const TString& name,
76 const TString& title,
77 Int_t nofBins,
78 Double_t minBin,
79 Double_t maxBin) {
80 T* h = new T(name.Data(), title.Data(), nofBins, minBin, maxBin);
81 Add(name, h);
82 }
83
97 template<class T> void Create2(
98 const TString& name,
99 const TString& title,
100 Int_t nofBinsX,
101 Double_t minBinX,
102 Double_t maxBinX,
103 Int_t nofBinsY,
104 Double_t minBinY,
105 Double_t maxBinY) {
106 T* h = new T(name.Data(), title.Data(), nofBinsX, minBinX, maxBinX, nofBinsY, minBinY, maxBinY);
107 Add(name, h);
108 }
109
115 TH1* H1(const TString& name) const {
116 if (fMap.count(name) == 0) { // Temporarily used for debugging
117 std::cout << "Error: BmnHistManager::H1(name): name=" << name << std::endl;
118 }
119 assert(fMap.count(name) != 0);
120 return (TH1*) fMap.find(name)->second;
121 }
122
128 TH2* H2(const TString& name) const {
129 if (fMap.count(name) == 0) { // Temporarily used for debugging
130 std::cout << "Error: BmnHistManager::H2(name): name=" << name << std::endl;
131 }
132 assert(fMap.count(name) != 0);
133 return (TH2*) fMap.find(name)->second;
134 }
135
141 Bool_t Exists(const TString& name) const {
142 return (fMap.count(name) == 0) ? false : true;
143 }
144
149
154
155
161 TFile* file);
162
166 void Clear();
167
172 void ShrinkEmptyBinsH1(const TString& histName);
173
174
179 void ShrinkEmptyBinsH2(const TString& histName);
180
186 void Scale(const TString& histName, Double_t scale);
187
192 void NormalizeToIntegral(const TString& histName);
193
199 void Rebin(const TString& histName, Int_t ngroup);
200
205 TString ToString() const;
206
211 friend std::ostream& operator<<(std::ostream& strm, const BmnHistManager& histManager) {
212 strm << histManager.ToString();
213 return strm;
214 }
215
216private:
217
218 // Map of histogram (graph) name to its pointer
219 map<TString, TNamed*> fMap;
220
221 ClassDef(BmnHistManager, 1)
222};
223
224#endif /* BmnHISTMANAGER_H_ */
Histogram manager.
friend std::ostream & operator<<(std::ostream &strm, const BmnHistManager &histManager)
Operator << for convenient output to std::ostream.
void Add(const TString &name, TNamed *object)
Add new named object to manager.
void ResetHists()
Reset all histograms.
void ShrinkEmptyBinsH2(const TString &histName)
Shrink empty bins in H2.
virtual ~BmnHistManager()
Destructor.
BmnHistManager()
Constructor.
void Rebin(const TString &histName, Int_t ngroup)
Rebin histogram.
void Scale(const TString &histName, Double_t scale)
Scale histogram.
Bool_t Exists(const TString &name) const
Check existence of histogram in manager.
TH2 * H2(const TString &name) const
Return pointer to TH2 histogram.
void WriteToFile()
Write all histograms to current opened file.
void Create2(const TString &name, const TString &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...
void Clear()
Clear memory. Remove all histograms.
TString ToString() const
Return string representation of class.
void NormalizeToIntegral(const TString &histName)
Normalize histogram to integral.
void Create1(const TString &name, const TString &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...
TH1 * H1(const TString &name) const
Return pointer to TH1 histogram.
void ReadFromFile(TFile *file)
Read histograms from file.
void ShrinkEmptyBinsH1(const TString &histName)
Shrink empty bins in H1.