PandaRoot
BSEmcHistogrammer.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 #ifndef BSEMCHISTOGRAMMER_HH
14 #define BSEMCHISTOGRAMMER_HH
15 
16 #include <map>
17 
18 #include "Rtypes.h"
19 #include "RtypesCore.h"
20 #include "TCanvas.h"
21 #include "TFile.h"
22 #include "TH1.h"
23 #include "TH2.h"
24 #include "TH3.h"
25 #include "TString.h"
26 
27 class TBuffer;
28 class TCanvas;
29 class TClass;
30 class TFile;
31 class TMemberInspector;
32 
42  public:
43  struct AxisData {
44  Int_t BinNumber{100};
45  Double_t Begin{-0.5};
46  Double_t End{99.5};
47  TString Title{"#"};
48  Double_t Offset{1};
49 
50  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)
51  : BinNumber(t_binNumber), Begin(t_begin), End(t_end), Title(t_title), Offset(t_offset)
52  {
53  }
54  };
55  // using Key = TString;
57  BSEmcHistogrammer(TFile *t_file);
58  virtual ~BSEmcHistogrammer();
59 
60  void SetOutputFile(TFile *t_file) { fFile = t_file; }
61  TFile *GetOutputFile() { return fFile; }
62 
63  TCanvas *CreateCanvas(const TString &t_key, const TString &t_foldername);
64  TH1F *Create1DHist(const TString &t_key, const TString &t_foldername, AxisData t_xdata, AxisData t_ydata = AxisData{});
65  TH2F *Create2DHist(const TString &t_key, const TString &t_foldername, AxisData t_xdata, AxisData t_ydata);
66  TH3F *Create3DHist(const TString &t_key, const TString &t_foldername, AxisData t_xdata, AxisData t_ydata, AxisData t_zdata);
67 
68  void Fill(const TString &t_key, Double_t t_value, Double_t t_weight);
69  void Fill(const TString &t_key, Double_t t_x, Double_t t_y, Double_t t_weight);
70  TH3F *Get3DHist(const TString &t_key) { return dynamic_cast<TH3F *>(GetHist(t_key)); }
71  TH2F *Get2DHist(const TString &t_key) { return dynamic_cast<TH2F *>(GetHist(t_key)); }
72  TH1F *Get1DHist(const TString &t_key) { return dynamic_cast<TH1F *>(GetHist(t_key)); }
73  TH1 *GetHist(const TString &t_key);
74  void AddHist(TH1 *t_hist, const TString &t_key, const TString &t_foldername);
75 
76  void ClearAllHists();
77  Bool_t DoesHistoExist(const TString &t_key) const;
78 
79  void WriteCanvases();
80 
81  private:
82  void CreateFolders(const TString &t_foldername);
83 
84  Bool_t FolderExists(const TString &t_foldername);
85 
86  private:
87  TFile *fFile{nullptr};
88  std::map<TString, TH1 *> fHistoMap{};
89  std::map<TString, TCanvas *> fCanvasMap{};
90  ClassDef(BSEmcHistogrammer, 1);
91 };
92 
93 #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()