LOGO

RestFrames  v1.0.1
RestFrames HEP Event Analysis Software Library
HistPlot.hh
Go to the documentation of this file.
1 // RestFrames: particle physics event analysis library
3 // --------------------------------------------------------------------
4 // Copyright (c) 2014-2016, Christopher Rogan
14 // This file is part of RestFrames.
15 //
16 // RestFrames is free software; you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation; either version 2 of the License, or
19 // (at your option) any later version.
20 //
21 // RestFrames is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with RestFrames. If not, see <http://www.gnu.org/licenses/>.
29 
30 #ifndef HistPlot_HH
31 #define HistPlot_HH
32 
33 #include <utility>
34 #include <TH1D.h>
35 #include <TH2D.h>
36 
37 #include "RestFrames/RFPlot.hh"
38 
39 namespace RestFrames {
40 
41  class HistPlotVar;
42  class HistPlotCategory;
43 
44  class HistPlot : public RFPlot {
45 
46  public:
47  HistPlot(const std::string& sname, const std::string& stitle);
48  ~HistPlot();
49 
50  virtual void Clear();
51 
52  HistPlotVar const& GetNewVar(const std::string& name, const std::string& title,
53  double minval, double maxval,
54  const std::string& unit = "");
55 
56  HistPlotCategory const& GetNewCategory(const std::string& name, const std::string& title);
57 
58  void AddPlot(const HistPlotVar& var,
61  bool invert_colors = false);
62  void AddPlot(const HistPlotVar& varX,
63  const HistPlotVar& varY,
66  bool invert_colors = false);
67 
68  void Fill(double weight = 1.);
69  void Fill(const HistPlotCategory& cat, double weight = 1.);
70 
71  void Draw(bool invert_colors = false);
72 
73  void SetPlotLabel(const std::string& label);
74 
75  void SetPlotTitle(const std::string& title);
76 
77  void SetScaleLabel(const std::string& label);
78 
79  void SetScale(double scale = -1);
80 
81  void SetRebin(int rebin = 4);
82 
83  void WriteHist(const std::string& filename);
84 
85  private:
86  std::string m_PlotLabel;
87  std::string m_PlotTitle;
88  std::string m_ScaleLabel;
89  double m_Scale;
90  bool m_SetScale;
91  int m_Rebin;
92 
93  std::vector<TH1D*> m_1DHists;
94  std::vector<TH2D*> m_2DHists;
95  // std::vector<HistPlotVar*> m_Vars;
96  // std::vector<HistPlotCategory*> m_Cats;
97  HistPlotVarList m_Vars;
98  HistPlotCatList m_Cats;
99  std::map<const HistPlotCategory*,std::vector<TH1D*> > m_CatToHist1D;
100  std::map<const HistPlotCategory*,std::vector<TH2D*> > m_CatToHist2D;
101 
102  std::vector<const HistPlotVar*> m_Plot1D_Var;
103  std::vector<HistPlotCatList> m_Plot1D_Cats;
104  std::vector<bool> m_Plot1D_Color;
105  std::vector<std::pair<const HistPlotVar*,
106  const HistPlotVar*> > m_Plot2D_Vars;
107  std::vector<const HistPlotCategory*> m_Plot2D_Cat;
108  std::vector<bool> m_Plot2D_Color;
109 
110  std::map<TH1D*,const HistPlotVar*> m_HistToVar;
111  std::map<TH2D*,std::pair<const HistPlotVar*,
112  const HistPlotVar*> > m_HistToVars;
113 
114  void DrawPlot(const HistPlotVar& var,
115  const HistPlotCatList& cats,
116  bool invert_colors = false);
117  void DrawPlot(const std::pair<const HistPlotVar*,
118  const HistPlotVar*>& vars,
119  const HistPlotCategory& cat,
120  bool invert_colors = false);
121 
122  };
123 
124 }
125 
126 #endif
virtual void Clear()
Clears RFBase of all connections to other objects.
Definition: HistPlot.cc:63