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 
52  HistPlot(const std::string& sname, const std::string& stitle);
53  ~HistPlot();
54 
56  virtual void Clear();
57 
73  HistPlotVar const& GetNewVar(const std::string& name, const std::string& title,
74  double minval, double maxval,
75  const std::string& unit = "");
76 
86  HistPlotCategory const& GetNewCategory(const std::string& name, const std::string& title);
87 
97  void AddPlot(const HistPlotVar& var,
100  bool invert_colors = false);
101 
112  void AddPlot(const HistPlotVar& varX,
113  const HistPlotVar& varY,
116  bool invert_colors = false);
117 
121  void Fill(double weight = 1.);
122 
127  void Fill(const HistPlotCategory& cat, double weight = 1.);
128 
130  void Draw(bool invert_colors = false);
131 
135  void SetPlotLabel(const std::string& label);
136 
140  void SetPlotTitle(const std::string& title);
141 
145  void SetScaleLabel(const std::string& label);
146 
153  void SetScale(double scale = -1);
154 
158  void SetRebin(int rebin = 4);
159 
163  void WriteHist(const std::string& filename);
164 
165  private:
166  std::string m_PlotLabel;
167  std::string m_PlotTitle;
168  std::string m_ScaleLabel;
169  double m_Scale;
170  bool m_SetScale;
171  int m_Rebin;
172 
173  std::vector<TH1D*> m_1DHists;
174  std::vector<TH2D*> m_2DHists;
175  // std::vector<HistPlotVar*> m_Vars;
176  // std::vector<HistPlotCategory*> m_Cats;
177  HistPlotVarList m_Vars;
178  HistPlotCatList m_Cats;
179  std::map<const HistPlotCategory*,std::vector<TH1D*> > m_CatToHist1D;
180  std::map<const HistPlotCategory*,std::vector<TH2D*> > m_CatToHist2D;
181 
182  std::vector<const HistPlotVar*> m_Plot1D_Var;
183  std::vector<HistPlotCatList> m_Plot1D_Cats;
184  std::vector<bool> m_Plot1D_Color;
185  std::vector<std::pair<const HistPlotVar*,
186  const HistPlotVar*> > m_Plot2D_Vars;
187  std::vector<const HistPlotCategory*> m_Plot2D_Cat;
188  std::vector<bool> m_Plot2D_Color;
189 
190  std::map<TH1D*,const HistPlotVar*> m_HistToVar;
191  std::map<TH2D*,std::pair<const HistPlotVar*,
192  const HistPlotVar*> > m_HistToVars;
193 
194  void DrawPlot(const HistPlotVar& var,
195  const HistPlotCatList& cats,
196  bool invert_colors = false);
197  void DrawPlot(const std::pair<const HistPlotVar*,
198  const HistPlotVar*>& vars,
199  const HistPlotCategory& cat,
200  bool invert_colors = false);
201 
202  };
203 
204 }
205 
206 #endif
RestFrames::HistPlot::WriteHist
void WriteHist(const std::string &filename)
Stores all histograms in root file.
Definition: HistPlot.cc:581
RFPlot.hh
RestFrames::HistPlotCategory
Definition: HistPlotCategory.hh:40
RestFrames::HistPlot::SetRebin
void SetRebin(int rebin=4)
Reduces the number of bins by a factor.
Definition: HistPlot.cc:576
RestFrames::RFList
Definition: RFList.hh:43
RestFrames::HistPlot
Definition: HistPlot.hh:44
RestFrames::HistPlot::SetPlotTitle
void SetPlotTitle(const std::string &title)
Sets plot's title.
Definition: HistPlot.cc:572
RestFrames::HistPlot::GetNewVar
HistPlotVar const & GetNewVar(const std::string &name, const std::string &title, double minval, double maxval, const std::string &unit="")
Defines new variable for plotting.
Definition: HistPlot.cc:86
RestFrames::HistPlot::Fill
void Fill(double weight=1.)
Fills an entry for every variable according to each's current value.
Definition: HistPlot.cc:242
RestFrames::HistPlot::SetPlotLabel
void SetPlotLabel(const std::string &label)
Changes the text at the top of the plot.
Definition: HistPlot.cc:568
RestFrames::HistPlot::HistPlot
HistPlot(const std::string &sname, const std::string &stitle)
Standard constructor.
Definition: HistPlot.cc:40
RestFrames::HistPlot::GetNewCategory
HistPlotCategory const & GetNewCategory(const std::string &name, const std::string &title)
Defines new category for plotting.
Definition: HistPlot.cc:95
RestFrames::RFPlot
Abstract base class for all plotting objects.
Definition: RFPlot.hh:41
RestFrames::HistPlotVar
Definition: HistPlotVar.hh:40
RestFrames::HistPlot::AddPlot
void AddPlot(const HistPlotVar &var, RestFrames::RFList< const HistPlotCategory > cats=RestFrames::RFList< const RestFrames::HistPlotCategory >(), bool invert_colors=false)
Defines new 1D plot.
Definition: HistPlot.cc:102
RestFrames::HistPlot::Clear
virtual void Clear()
Clears HistPlot from all connections to other objects.
Definition: HistPlot.cc:63
RestFrames::HistPlot::Draw
void Draw(bool invert_colors=false)
Draws every histogram.
Definition: HistPlot.cc:272
RestFrames::HistPlot::SetScaleLabel
void SetScaleLabel(const std::string &label)
Sets the label of the normalization of plot.
Definition: HistPlot.cc:564
RestFrames::HistPlot::SetScale
void SetScale(double scale=-1)
Sets the normalization of plot.
Definition: HistPlot.cc:553