SynAPSE  0.6.0
Synergistic Analysis of Phase Space Evolution
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Drawer.hh
1 #ifndef DRAWER_HH
2 #define DRAWER_HH
3 
4 // C++ includes
5 #include <iostream>
6 #include <string>
7 #include <map>
8 
9 // ROOT includes
10 #include "TH1F.h"
11 #include "TH2F.h"
12 #include "THStack.h"
13 #include "TList.h"
14 #include "TGraphErrors.h"
15 #include "TMultiGraph.h"
16 #include "TF1.h"
17 #include "TGaxis.h"
18 #include "TLine.h"
19 #include "TBox.h"
20 #include "TPaveStats.h"
21 #include "TLegend.h"
22 #include "TCanvas.h"
23 
24 // Additional includes
25 #include "Pitch.hh"
26 #include "Globals.hh"
27 #include "ProgressBar.hh"
28 #include "InfoBox.hh"
29 #include "ScatterGraph.hh"
30 
32 namespace Beam {
33 
35 struct DrawOpt {
36  const char* title = "";
37  int line_style = 1;
38  int line_color = 1;
39  int line_width = 2;
40  int fill_style = 0;
41  int fill_color = 0;
42  int fill_alpha = 1;
43  int marker_style = 0;
44  int marker_color = 1;
45  int marker_size = 1;
46  const char* hist_opt = "";
47  const char* graph_opt = "";
48  const char* hist_leg = "";
49  const char* graph_leg = "";
50 };
51 
53 struct VarSet {
54  std::string label;
55  std::string unit;
56  double llim;
57  double ulim;
58  size_t nbins = 100;
59 };
60 
67 class Drawer {
68  public:
70  Drawer();
71 
73  Drawer(const Drawer& dra);
74 
76  Drawer& operator=(const Drawer& dra);
77 
79  ~Drawer();
80 
86  void SetVariableSettings(const std::string& var,
87  const VarSet& varset) { _varsets[var] = varset; }
88 
95  void SetVariableLimits(const std::string& var,
96  double llim,
97  double ulim);
98 
106  TH1F* New1DHistogram(const std::string& name,
107  const std::string& var) const;
108 
117  TH2F* New2DHistogram(const std::string& name,
118  const std::string& varx,
119  const std::string& vary) const;
120 
129  ScatterGraph* NewAmplitudeScatter(const std::string& name,
130  const std::string& varx,
131  const std::string& vary) const;
132 
139  THStack* NewStack(std::map<std::string, TH1F*> hists) const;
140 
149  std::map<std::string, TPaveStats*> NewStackStats(std::map<std::string, TH1F*> hists,
150  const std::string draw_opt="EMR",
151  double* hoffset=NULL) const;
152 
160  TLegend* NewStackLegend(std::map<std::string, TH1F*> hists,
161  const double hoffset = 0) const;
162 
170  THStack* DrawStack(std::map<std::string, TH1F*> hists,
171  const std::string& name) const;
172 
179  void SaveStack(std::map<std::string, TH1F*> hists,
180  const std::string& name,
181  bool ratio=false) const;
182 
189  TMultiGraph* NewMultiGraph(std::map<std::string, TGraphErrors*> graphs) const;
190 
198  TLegend* NewMultiGraphLegend(std::map<std::string, TGraphErrors*> graphs,
199  const std::string corner="tr") const;
200 
210  TGaxis* NewMultiGraphEmittanceAxis(TF1* func,
211  const double& miny,
212  const double& maxy,
213  const double& maxx) const;
214 
223  TMultiGraph* DrawMultiGraph(std::map<std::string, TGraphErrors*> graphs,
224  const std::string& name,
225  TF1* func = NULL);
226 
233  void SaveMultiGraph(std::map<std::string, TGraphErrors*> graphs,
234  const std::string& name,
235  TF1* func = NULL);
236 
244  TH1F* ProjectionMeanX(TH2F* hist,
245  bool fit = false) const;
246 
251  void SetInfoBox(InfoBox* info) { _info = info; }
252 
254  InfoBox* GetInfoBox() const { return _info; }
255 
256  private:
257 
259  void Initialize();
260 
266  void SetStyle(TH1* obj,
267  const std::string& type) const;
268 
274  void SetStyle(TGraph* obj,
275  const std::string& type) const;
276 
282  void DrawMICEModules(const double& miny,
283  const double& maxy) const;
284 
291  std::string FindBestCorner(std::map<std::string, TGraphErrors*> graphs) const;
292 
298  void SaveGIF(const std::string& name,
299  const std::vector<TCanvas*>& canv) const;
300 
301  std::vector<std::string> _types;
302  std::vector<std::string> _vars;
303  std::map<std::string, DrawOpt> _options;
304  std::map<std::string, VarSet> _varsets;
306 };
307 } // namespace Beam
308 
309 #endif
int marker_size
Marker size.
Definition: Drawer.hh:45
void SaveStack(std::map< std::string, TH1F * > hists, const std::string &name, bool ratio=false) const
Saves superimposed data types histograms.
Definition: Drawer.cc:188
TMultiGraph * NewMultiGraph(std::map< std::string, TGraphErrors * > graphs) const
Initializes a multigraph of graphs of different data types.
Definition: Drawer.cc:254
~Drawer()
Destructor.
Definition: Drawer.cc:36
std::map< std::string, TPaveStats * > NewStackStats(std::map< std::string, TH1F * > hists, const std::string draw_opt="EMR", double *hoffset=NULL) const
Intializes stat boxes for a stack of histogram of different data types.
Definition: Drawer.cc:130
void SaveGIF(const std::string &name, const std::vector< TCanvas * > &canv) const
Saves the canvases, in order, to a single GIF.
Definition: Drawer.cc:536
TLegend * NewStackLegend(std::map< std::string, TH1F * > hists, const double hoffset=0) const
Intializes a legend for a stack of histogram of different data types.
Definition: Drawer.cc:116
int fill_style
Fill pattern (TAttFill code)
Definition: Drawer.hh:40
double ulim
Upper limit of the corresponding axis.
Definition: Drawer.hh:57
THStack * DrawStack(std::map< std::string, TH1F * > hists, const std::string &name) const
Draws superimposed data types histograms.
Definition: Drawer.cc:165
ScatterGraph * NewAmplitudeScatter(const std::string &name, const std::string &varx, const std::string &vary) const
Returns a scatter plot with an amplitude color scale.
Definition: Drawer.cc:80
void SetInfoBox(InfoBox *info)
Sets the info box.
Definition: Drawer.hh:251
void SetVariableSettings(const std::string &var, const VarSet &varset)
Sets custom settings for the specified variable.
Definition: Drawer.hh:86
Structure that stores the drawing options of each data type.
Definition: Drawer.hh:35
TLegend * NewMultiGraphLegend(std::map< std::string, TGraphErrors * > graphs, const std::string corner="tr") const
Intializes a legend for a multigraph of different data types.
Definition: Drawer.cc:273
void SetVariableLimits(const std::string &var, double llim, double ulim)
Sets the limits of the specified variable.
Definition: Drawer.cc:42
int fill_color
Fill color (TColor code)
Definition: Drawer.hh:41
void DrawMICEModules(const double &miny, const double &maxy) const
Draws the MICE beam line elements onto an evolution graph.
Definition: Drawer.cc:481
std::map< std::string, DrawOpt > _options
Drawing options for each data type.
Definition: Drawer.hh:303
double llim
Lower limit of the corresponding axis.
Definition: Drawer.hh:56
const char * title
Long name of the data type.
Definition: Drawer.hh:36
std::string FindBestCorner(std::map< std::string, TGraphErrors * > graphs) const
Finds the corner that leasts overlaps the graph.
Definition: Drawer.cc:503
Drawer()
Default constructor, intializes the default drawing options.
Definition: Drawer.cc:5
TH2F * New2DHistogram(const std::string &name, const std::string &varx, const std::string &vary) const
Defines an appropriate TH1F to draw two of the phase space component.
Definition: Drawer.cc:66
void SetStyle(TH1 *obj, const std::string &type) const
Sets the histogram style according to the predefined options.
Definition: Drawer.cc:445
std::string label
Label of the variable to be drawn.
Definition: Drawer.hh:54
Drawer & operator=(const Drawer &dra)
Equality operator.
Definition: Drawer.cc:21
size_t nbins
Number of bins.
Definition: Drawer.hh:58
int marker_color
Marker color (TColor code)
Definition: Drawer.hh:44
int line_color
Line color (TColor code)
Definition: Drawer.hh:38
int marker_style
Marker shape (TAttMarker code)
Definition: Drawer.hh:43
THStack * NewStack(std::map< std::string, TH1F * > hists) const
Initializes a stack of histograms of different data types.
Definition: Drawer.cc:97
int fill_alpha
Fill opacity (From 0=transparent to 1=opaque)
Definition: Drawer.hh:42
void SaveMultiGraph(std::map< std::string, TGraphErrors * > graphs, const std::string &name, TF1 *func=NULL)
Saves superimposed data types histograms.
Definition: Drawer.cc:337
TH1F * ProjectionMeanX(TH2F *hist, bool fit=false) const
Produces a TH1F of the mean Y as a function of X from a TH2F.
Definition: Drawer.cc:353
std::map< std::string, VarSet > _varsets
Drawing options for each data type.
Definition: Drawer.hh:304
int line_style
Line style (plain, dashed, dotted, etc.)
Definition: Drawer.hh:37
const char * hist_opt
ROOT histogram drawing option.
Definition: Drawer.hh:46
Stores the default drawing options and methods to produce ROOT plots.
Definition: Drawer.hh:67
std::string unit
Unit in which the variable is expressed.
Definition: Drawer.hh:55
const char * graph_opt
ROOT graph drawing option.
Definition: Drawer.hh:47
const char * hist_leg
ROOT histogram legend drawing option.
Definition: Drawer.hh:48
Defines functions that allow to plot a ROOT scatter graph with a color scale.
Definition: ScatterGraph.hh:31
int line_width
Line width.
Definition: Drawer.hh:39
TGaxis * NewMultiGraphEmittanceAxis(TF1 *func, const double &miny, const double &maxy, const double &maxx) const
Intializes an emittance axis for fractional quantities.
Definition: Drawer.cc:289
TMultiGraph * DrawMultiGraph(std::map< std::string, TGraphErrors * > graphs, const std::string &name, TF1 *func=NULL)
Draws superimposed data types histograms.
Definition: Drawer.cc:303
InfoBox * _info
MAUS info box to be drawn.
Definition: Drawer.hh:305
std::vector< std::string > _vars
Phase space variables.
Definition: Drawer.hh:302
Structure that stores the drawing options for each variable.
Definition: Drawer.hh:53
TH1F * New1DHistogram(const std::string &name, const std::string &var) const
Returns an appropriate TH1F to draw one of the phase space component.
Definition: Drawer.cc:56
Stores the MICE run information to be printed as TPaveText.
Definition: InfoBox.hh:18
std::vector< std::string > _types
Data types.
Definition: Drawer.hh:301
void Initialize()
Initializes the default drawing options.
Definition: Drawer.cc:393
InfoBox * GetInfoBox() const
Returns a pointer to the info box.
Definition: Drawer.hh:254
const char * graph_leg
ROOT graph legend drawing option.
Definition: Drawer.hh:49