Jpp  master_rocky
the software that should make you happy
JStyle.hh
Go to the documentation of this file.
1 #ifndef __JROOT__JSTYLE__
2 #define __JROOT__JSTYLE__
3 
4 #include "TStyle.h"
5 #include "TCanvas.h"
6 
7 #include "Jeep/JProperties.hh"
8 
9 
10 /**
11  * \author mdejong
12  */
13 
14 namespace JROOT {}
15 namespace JPP { using namespace JROOT; }
16 
17 namespace JROOT {
18 
19  /**
20  * Wrapper class around ROOT TStyle.
21  */
22  class JStyle :
23  public TStyle
24  {
25  public:
26  struct JParameters {
27  /**
28  * Default constructor.
29  */
31  fontSize (1.0),
32  topMargin (0.1),
33  bottomMargin(0.15),
34  leftMargin (0.15),
35  rightMargin (0.10),
36  titleOffset (1.00),
37  tickLength (1.00)
38  {}
39 
40 
41  /**
42  * Get properties of this class.
43  */
45  {
46  return JParametersHelper(*this);
47  }
48 
49 
50  /**
51  * Get properties of this class.
52  */
54  {
55  return JParametersHelper(*this);
56  }
57 
58  Double_t fontSize;
59  Double_t topMargin;
60  Double_t bottomMargin;
61  Double_t leftMargin;
62  Double_t rightMargin;
63  Double_t titleOffset;
64  Double_t tickLength;
65 
66  private:
67  /**
68  * Auxiliary class for I/O of parameters.
69  */
71  public JProperties
72  {
73  public:
74  /**
75  * Constructor.
76  *
77  * \param object parameters
78  */
79  template<class JParameters_t>
80  JParametersHelper(JParameters_t& object)
81  {
82  insert(gmake_property(object.fontSize));
83  insert(gmake_property(object.topMargin));
84  insert(gmake_property(object.bottomMargin));
85  insert(gmake_property(object.leftMargin));
86  insert(gmake_property(object.rightMargin));
87  insert(gmake_property(object.titleOffset));
88  insert(gmake_property(object.tickLength));
89  }
90  };
91  };
92 
93 
94  /**
95  * Constructor.
96  *
97  * \param title title
98  * \param x number of pixels in X
99  * \param y number of pixels in Y
100  * \param parameters parameters
101  */
102  JStyle(const char* title,
103  const UInt_t x,
104  const UInt_t y,
105  const JParameters& parameters = JParameters()) :
106  TStyle(title, NULL)
107  {
108  const Double_t font_size = (Double_t) y * 0.7e-4 * parameters.fontSize;
109  const Double_t title_offset = 1.5 * parameters.titleOffset;
110  const Double_t tick_length = 3.0e-5 * parameters.tickLength;
111 
112  SetPadTopMargin (parameters.topMargin);
113  SetPadBottomMargin(parameters.bottomMargin);
114  SetPadLeftMargin (parameters.leftMargin);
115  SetPadRightMargin (parameters.rightMargin);
116 
117  SetCanvasColor(0);
118  SetCanvasBorderMode(0);
119  SetCanvasBorderSize(0);
120 
121  SetPadColor(0);
122  SetPadBorderMode(0);
123  SetPadBorderSize(0);
124 
125  for (const auto option : { "X", "Y", "Z"}) {
126  SetTickLength (tick_length * (x < y ? x : y), option);
127  SetLabelSize (font_size, option);
128  SetTitleOffset(title_offset, option);
129  SetTitleSize (font_size, option);
130  }
131 
132  SetTitleX(0.05);
133  SetTitleY(0.99);
134 
135  SetStatColor(0);
136  SetStatBorderSize(1);
137  SetStatFontSize(font_size);
138  SetOptStat(111111);
139  SetOptFit(1111);
140 
141  SetPaintTextFormat("3.0f");
142  SetPalette(1);
143 
144  SetTitleFillColor(0);
145  SetTitleAlign(23);
146  SetTitleX(0.5);
147  SetTitleBorderSize(0);
148  }
149 
150 
151  /**
152  * Scale font sizes.
153  *
154  * \param factor scale factor
155  */
156  void setFontSize(const Double_t factor)
157  {
158  for (const auto option : { "X", "Y", "Z"}) {
159  SetLabelSize(GetLabelSize(option) * factor, option);
160  SetTitleSize(GetTitleSize(option) * factor, option);
161  }
162  }
163  };
164 }
165 
166 #endif
Utility class to parse parameter values.
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
Utility class to parse parameter values.
Definition: JProperties.hh:501
Auxiliary class for I/O of parameters.
Definition: JStyle.hh:72
JParametersHelper(JParameters_t &object)
Constructor.
Definition: JStyle.hh:80
Wrapper class around ROOT TStyle.
Definition: JStyle.hh:24
void setFontSize(const Double_t factor)
Scale font sizes.
Definition: JStyle.hh:156
JStyle(const char *title, const UInt_t x, const UInt_t y, const JParameters &parameters=JParameters())
Constructor.
Definition: JStyle.hh:102
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.
JProperties getProperties()
Get properties of this class.
Definition: JStyle.hh:44
JParameters()
Default constructor.
Definition: JStyle.hh:30
JProperties getProperties() const
Get properties of this class.
Definition: JStyle.hh:53