EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CbmHistManager.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CbmHistManager.h
1 
8 #ifndef CBMHISTMANAGER_H_
9 #define CBMHISTMANAGER_H_
10 
11 #include "TObject.h"
12 #include <iostream>
13 #include <map>
14 #include <string>
15 #include <vector>
16 #include <cassert>
17 
18 class TFile;
19 class TNamed;
20 class TH1;
21 class TH2;
22 class TGraph;
23 class TGraph2D;
24 class TProfile;
25 class TProfile2D;
26 
27 using std::map;
28 using std::make_pair;
29 using std::string;
30 using std::vector;
31 
38 class CbmHistManager : public TObject
39 {
40 public:
41 
46 
50  virtual ~CbmHistManager();
51 
57  void Add(
58  const string& name,
59  TNamed* object) {
60  //fMap.insert(std::make_pair<string, TNamed*>(name, object));
61  }
62 
73  template<class T> void Create1(
74  const string& name,
75  const string& title,
76  Int_t nofBins,
77  Double_t minBin,
78  Double_t maxBin) {
79  T* h = new T(name.c_str(), title.c_str(), nofBins, minBin, maxBin);
80  Add(name, h);
81  }
82 
96  template<class T> void Create2(
97  const string& name,
98  const string& title,
99  Int_t nofBinsX,
100  Double_t minBinX,
101  Double_t maxBinX,
102  Int_t nofBinsY,
103  Double_t minBinY,
104  Double_t maxBinY) {
105  T* h = new T(name.c_str(), title.c_str(), nofBinsX, minBinX, maxBinX, nofBinsY, minBinY, maxBinY);
106  Add(name, h);
107  }
108 
114  TH1* H1(
115  const string& name) const {
116  if (fMap.count(name) == 0) { // Temporarily used for debugging
117  std::cout << "Error: CbmHistManager::H1(name): name=" << name << std::endl;
118  }
119  assert(fMap.count(name) != 0);
120  return (TH1*) fMap.find(name)->second;
121  }
122 
128  vector<TH1*> H1Vector(
129  const string& pattern) const;
130 
136  TH2* H2(
137  const string& name) const {
138  if (fMap.count(name) == 0) { // Temporarily used for debugging
139  std::cout << "Error: CbmHistManager::H2(name): name=" << name << std::endl;
140  }
141  assert(fMap.count(name) != 0);
142  return (TH2*) fMap.find(name)->second;
143  }
144 
150  vector<TH2*> H2Vector(
151  const string& pattern) const;
152 
158  TGraph* G1(
159  const string& name) const {
160  if (fMap.count(name) == 0) { // Temporarily used for debugging
161  std::cout << "Error: CbmHistManager::G1(name): name=" << name << std::endl;
162  }
163  assert(fMap.count(name) != 0);
164  return (TGraph*) fMap.find(name)->second;
165  }
166 
172  vector<TGraph*> G1Vector(
173  const string& pattern) const;
174 
180  TGraph2D* G2(
181  const string& name) const {
182  if (fMap.count(name) == 0) { // Temporarily used for debugging
183  std::cout << "Error: CbmHistManager::G2(name): name=" << name << std::endl;
184  }
185  assert(fMap.count(name) != 0);
186  return (TGraph2D*) fMap.find(name)->second;
187  }
188 
194  vector<TGraph2D*> G2Vector(
195  const string& pattern) const;
196 
202  TProfile* P1(
203  const string& name) const {
204  if (fMap.count(name) == 0) { // Temporarily used for debugging
205  std::cout << "Error: CbmHistManager::P1(name): name=" << name << std::endl;
206  }
207  assert(fMap.count(name) != 0);
208  return (TProfile*) fMap.find(name)->second;
209  }
210 
216  vector<TProfile*> P1Vector(
217  const string& pattern) const;
218 
224  TProfile2D* P2(
225  const string& name) const {
226  if (fMap.count(name) == 0) { // Temporarily used for debugging
227  std::cout << "Error: CbmHistManager::P2(name): name=" << name << std::endl;
228  }
229  assert(fMap.count(name) != 0);
230  return (TProfile2D*) fMap.find(name)->second;
231  }
232 
238  vector<TProfile2D*> P2Vector(
239  const string& pattern) const;
240 
246  Bool_t Exists(
247  const string& name) const {
248  return (fMap.count(name) == 0) ? false : true;
249  }
250 
254  void WriteToFile();
255 
260  void ReadFromFile(
261  TFile* file);
262 
266  void Clear();
267 
272  void ShrinkEmptyBins(
273  const string& histName);
274 
280  const string& pattern);
281 
287  void Scale(
288  const string& histName,
289  Double_t scale);
290 
296  void ScaleByPattern(
297  const string& pattern,
298  Double_t scale);
299 
305  void Rebin(
306  const string& histName,
307  Int_t ngroup);
308 
314  void RebinByPattern(
315  const string& pattern,
316  Int_t ngroup);
317 
322  string ToString() const;
323 
328  friend std::ostream& operator<<(std::ostream& strm, const CbmHistManager& histManager) {
329  strm << histManager.ToString();
330  return strm;
331  }
332 
333 private:
334  template<class T> vector<T> ObjectVector(
335  const string& pattern) const;
336 
337  // Map of histogram (graph) name to its pointer
338  map<string, TNamed*> fMap;
339 
340  ClassDef(CbmHistManager, 1)
341 };
342 
343 #endif /* CBMHISTMANAGER_H_ */