PandaRoot
BSEmcHistogrammer.h
Go to the documentation of this file.
1 #ifndef BSEMCHISTOGRAMMER_HH
2 #define BSEMCHISTOGRAMMER_HH
3 
4 #include <map>
5 
6 #include "Rtypes.h"
7 #include "RtypesCore.h"
8 #include "TCanvas.h"
9 #include "TFile.h"
10 #include "TH1.h"
11 #include "TH2.h"
12 #include "TH3.h"
13 #include "TString.h"
14 
15 class TBuffer;
16 class TCanvas;
17 class TClass;
18 class TFile;
19 class TMemberInspector;
20 
30  public:
31  struct AxisData {
32  Int_t BinNumber{100};
33  Double_t Begin{-0.5};
34  Double_t End{99.5};
35  TString Title{"#"};
36  Double_t Offset{1};
37 
38  AxisData(Int_t t_binNumber = 100, Double_t t_begin = -0.5, Double_t t_end = 99.5, TString t_title = "#", Double_t t_offset = 1)
39  : BinNumber(t_binNumber), Begin(t_begin), End(t_end), Title(t_title), Offset(t_offset)
40  {
41  }
42  };
43  // using Key = TString;
45  BSEmcHistogrammer(TFile *t_file);
46  virtual ~BSEmcHistogrammer();
47 
48  void SetOutputFile(TFile *t_file) { fFile = t_file; }
49  TFile *GetOutputFile() { return fFile; }
50 
51  TCanvas *CreateCanvas(const TString &t_key, const TString &t_foldername);
52  TH1F *Create1DHist(const TString &t_key, const TString &t_foldername, AxisData t_xdata, AxisData t_ydata = AxisData{});
53  TH2F *Create2DHist(const TString &t_key, const TString &t_foldername, AxisData t_xdata, AxisData t_ydata);
54  TH3F *Create3DHist(const TString &t_key, const TString &t_foldername, AxisData t_xdata, AxisData t_ydata, AxisData t_zdata);
55 
56  void Fill(const TString &t_key, Double_t t_value, Double_t t_weight);
57  void Fill(const TString &t_key, Double_t t_x, Double_t t_y, Double_t t_weight);
58  TH3F *Get3DHist(const TString &t_key) { return dynamic_cast<TH3F *>(GetHist(t_key)); }
59  TH2F *Get2DHist(const TString &t_key) { return dynamic_cast<TH2F *>(GetHist(t_key)); }
60  TH1F *Get1DHist(const TString &t_key) { return dynamic_cast<TH1F *>(GetHist(t_key)); }
61  TH1 *GetHist(const TString &t_key);
62  void AddHist(TH1 *t_hist, const TString &t_key, const TString &t_foldername);
63 
64  void ClearAllHists();
65  Bool_t DoesHistoExist(const TString &t_key) const;
66 
67  void WriteCanvases();
68 
69  private:
70  void CreateFolders(const TString &t_foldername);
71 
72  Bool_t FolderExists(const TString &t_foldername);
73 
74  private:
75  TFile *fFile{nullptr};
76  std::map<TString, TH1 *> fHistoMap{};
77  std::map<TString, TCanvas *> fCanvasMap{};
78  ClassDef(BSEmcHistogrammer, 1);
79 };
80 
81 #endif /*BSEMCHISTOGRAMMER_HH*/
void Fill(const TString &t_key, Double_t t_value, Double_t t_weight)
TH3F * Get3DHist(const TString &t_key)
TCanvas * CreateCanvas(const TString &t_key, const TString &t_foldername)
TH1F * Create1DHist(const TString &t_key, const TString &t_foldername, AxisData t_xdata, AxisData t_ydata=AxisData{})
TH3F * Create3DHist(const TString &t_key, const TString &t_foldername, AxisData t_xdata, AxisData t_ydata, AxisData t_zdata)
TH2F * Get2DHist(const TString &t_key)
TH2F * Create2DHist(const TString &t_key, const TString &t_foldername, AxisData t_xdata, AxisData t_ydata)
Bool_t DoesHistoExist(const TString &t_key) const
Simple wrapper around std::map<TString (histname), TH1*> to help with histogram creation and writting...
void AddHist(TH1 *t_hist, const TString &t_key, const TString &t_foldername)
TH1 * GetHist(const TString &t_key)
void SetOutputFile(TFile *t_file)
AxisData(Int_t t_binNumber=100, Double_t t_begin=-0.5, Double_t t_end=99.5, TString t_title="#", Double_t t_offset=1)
TH1F * Get1DHist(const TString &t_key)
virtual ~BSEmcHistogrammer()