BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
BmnDrawHist.h
Go to the documentation of this file.
1
/**
2
* \file BmnDrawHist.h
3
* \brief Helper functions for drawing 1D and 2D histograms and graphs.
4
* \author Andrey Lebedev <andrey.lebedev@gsi.de>
5
* \date 2008
6
**/
7
#ifndef BMNDRAWHIST_H_
8
#define BMNDRAWHIST_H_
9
10
#include "
TGraph.h
"
11
#include "
TGraph2D.h
"
12
#include "
TH1.h
"
13
#include "
TH1D.h
"
14
#include "
TH2.h
"
15
#include "
TLegend.h
"
16
#include "
TPad.h
"
17
18
#include <fstream>
19
#include <string>
20
#include <vector>
21
using
std::string;
22
using
std::vector;
23
24
/**
25
* \class BmnDrawingOptions
26
* \brief Default options for drawing.
27
* \author Andrey Lebedev <andrey.lebedev@gsi.de>
28
* \date 2012
29
*/
30
31
class
BmnDrawingOptions
32
{
33
public
:
34
static
Int_t
Color
(
Int_t
colorIndex)
35
{
36
static
const
Int_t
nofColors = 6;
37
static
Int_t
colors[nofColors] = {
kRed
,
kBlue
+ 1,
kGreen
+ 3,
kMagenta
+ 4,
kYellow
+ 2,
kViolet
};
38
return
(colorIndex < nofColors) ? colors[colorIndex] : colorIndex;
39
}
40
41
static
Int_t
LineWidth
() {
return
2; }
42
43
static
Int_t
LineStyle
(
Int_t
lineStyleIndex) {
return
lineStyleIndex + 1; }
44
45
static
Float_t
MarkerSize
() {
return
0.8; }
46
47
static
Int_t
MarkerStyle
(
Int_t
markerIndex)
48
{
49
static
const
Int_t
nofMarkers = 4;
50
// static Int_t markers[nofMarkers] = {kOpenCircle, kOpenSquare, kOpenTriangleUp, kOpenDiamond,
51
// kFullCircle, kFullSquare, kFullTriangleUp};
52
static
Int_t
markers[nofMarkers] = {
kFullCircle
,
kFullSquare
,
kFullTriangleUp
,
kFullDiamond
};
53
return
(markerIndex < nofMarkers) ? markers[markerIndex] : markerIndex;
54
}
55
56
static
Double_t
TextSize
() {
return
0.06; }
57
};
58
59
/**
60
* \enum HistScale
61
* \brief Define linear or logarithmic scale for drawing.
62
*/
63
enum
HistScale
64
{
65
kLog
= 0,
/**> Linear scale. */
66
kLinear
= 1
/**> Logarithmic scale */
67
};
68
69
/**
70
* \fn SetStyles
71
* \brief Set default styles for histograms.
72
*/
73
void
SetDefaultDrawStyle
();
74
75
/**
76
* \fn DrawH1
77
* \brief Draw 1D histogram.
78
* \param[in] hist Pointer to histogram.
79
* \param[in] logx Specify logarithmic or linear scale for X axis.
80
* \param[in] logy Specify logarithmic or linear scale for Y axis.
81
* \param[in] drawOpt Other drawing options (see ROOT documentation for details).
82
* \param[in] color Color.
83
* \param[in] lineWidth Line width.
84
* \param[in] lineStyle Line style (see ROOT documentation for details).
85
* \param[in] markerSize Marker size.
86
* \param[in] markerStyle Marker style (see ROOT documentation for details).
87
*/
88
void
DrawH1
(
TH1
* hist,
89
HistScale
logx =
kLinear
,
90
HistScale
logy =
kLinear
,
91
const
string
& drawOpt =
""
,
92
Int_t
color =
BmnDrawingOptions::Color
(0),
93
Int_t
lineWidth =
BmnDrawingOptions::LineWidth
(),
94
Int_t
lineStyle =
BmnDrawingOptions::LineStyle
(0),
95
Float_t
markerSize =
BmnDrawingOptions::MarkerSize
(),
96
Int_t
markerStyle =
BmnDrawingOptions::MarkerStyle
(0),
97
Int_t
fillColor = -1);
98
99
/**
100
* \fn DrawH2
101
* \brief Draw 2D histogram.
102
* \param[in] logx Specify logarithmic or linear scale for X axis.
103
* \param[in] logy Specify logarithmic or linear scale for Y axis.
104
* \param[in] logz Specify logarithmic or linear scale for Z axis.
105
* \param[in] drawOpt Other drawing options (see ROOT documentation for details).
106
*/
107
void
DrawH2
(
TH2
* hist,
108
HistScale
logx =
kLinear
,
109
HistScale
logy =
kLinear
,
110
HistScale
logz =
kLinear
,
111
const
string
& drawOpt =
"COLZ"
);
112
113
/**
114
* \fn DrawH1
115
* \brief Draw several TH1 histograms.
116
* \param[in] histos Array of histograms.
117
* \param[in] histLabels Array of histogram labels.
118
* \param[in] logx Specify logarithmic or linear scale for X axis.
119
* \param[in] logy Specify logarithmic or linear scale for Y axis.
120
* \param[in] drawLegend If true than legend will be drawn.
121
* \param[in] x1 X coordinate of legend in current pad.
122
* \param[in] y1 Y coordinate of legend in current pad.
123
* \param[in] x2 X coordinate of legend in current pad.
124
* \param[in] y2 Y coordinate of legend in current pad.
125
* \param[in] drawOpt Draw options for TH1->Draw method.
126
*/
127
void
DrawH1
(
const
vector<TH1*>& histos,
128
const
vector<string>& histLabels,
129
HistScale
logx =
kLinear
,
130
HistScale
logy =
kLinear
,
131
Bool_t
drawLegend =
true
,
132
Double_t
x1 = 0.25,
133
Double_t
y1 = 0.99,
134
Double_t
x2 = 0.55,
135
Double_t
y2 = 0.75,
136
const
string
& drawOpt =
""
,
137
Bool_t
outputMeanValue01 =
kFALSE
);
138
139
/**
140
* \fn DrawGraph
141
* \brief Draw TGraph.
142
* \param[in] graph Pointer to TGraph.
143
* \param[in] logx Specify logarithmic or linear scale for X axis.
144
* \param[in] logy Specify logarithmic or linear scale for Y axis.
145
* \param[in] drawOpt Other drawing options (see ROOT documentation for details).
146
* \param[in] color Color.
147
* \param[in] lineWidth Line width.
148
* \param[in] lineStyle Line style (see ROOT documentation for details).
149
* \param[in] markerSize Marker size.
150
* \param[in] markerStyle Marker style (see ROOT documentation for details).
151
*/
152
void
DrawGraph
(
TGraph
* graph,
153
HistScale
logx =
kLinear
,
154
HistScale
logy =
kLinear
,
155
const
string
& drawOpt =
"AC"
,
156
Int_t
color =
BmnDrawingOptions::Color
(0),
157
Int_t
lineWidth =
BmnDrawingOptions::LineWidth
(),
158
Int_t
lineStyle =
BmnDrawingOptions::LineStyle
(0),
159
Int_t
markerSize =
BmnDrawingOptions::MarkerSize
(),
160
Int_t
markerStyle =
BmnDrawingOptions::MarkerStyle
(0));
161
162
/**
163
* \fn DrawGraph.
164
* \brief Draw upto 3 TGraphs. If graph == NULL than graph will not be drawn.
165
* \param[in] graphs Vector of TGraphs.
166
* \param[in] graphLabels Vector of graph labels.
167
* \param[in] logx Specify logarithmic or linear scale for X axis.
168
* \param[in] logy Specify logarithmic or linear scale for Y axis.
169
* \param[in] drawLegend If true than legend will be drawn.
170
* \param[in] x1 X coordinate of legend in current pad.
171
* \param[in] y1 Y coordinate of legend in current pad.
172
* \param[in] x2 X coordinate of legend in current pad.
173
* \param[in] y2 Y coordinate of legend in current pad.
174
*/
175
void
DrawGraph
(
const
vector<TGraph*>& graphs,
176
const
vector<string>& graphLabels,
177
HistScale
logx =
kLinear
,
178
HistScale
logy =
kLinear
,
179
Bool_t
drawLegend =
true
,
180
Double_t
x1 = 0.25,
181
Double_t
y1 = 0.99,
182
Double_t
x2 = 0.55,
183
Double_t
y2 = 0.75);
184
185
/**
186
* \fn DrawGraph2D
187
* \brief Draw 2D graph.
188
* \param[in] graph Pointer to TGraph2D.
189
* \param[in] logx Specify logarithmic or linear scale for X axis.
190
* \param[in] logy Specify logarithmic or linear scale for Y axis.
191
* \param[in] logz Specify logarithmic or linear scale for Z axis.
192
* \param[in] drawOpt Other drawing options (see ROOT documentation for details).
193
*/
194
void
DrawGraph2D
(
TGraph2D
* graph,
195
HistScale
logx =
kLinear
,
196
HistScale
logy =
kLinear
,
197
HistScale
logz =
kLinear
,
198
const
string
& drawOpt =
"colz"
);
199
200
void
DrawMeanLine
(
TH1
* hist);
201
202
#endif
Bool_t
bool Bool_t
Int_t
int Int_t
Float_t
float Float_t
kFALSE
constexpr Bool_t kFALSE
Double_t
double Double_t
kRed
kRed
kGreen
kGreen
kMagenta
kMagenta
kBlue
kBlue
kYellow
kYellow
kViolet
kViolet
kFullSquare
kFullSquare
kFullTriangleUp
kFullTriangleUp
kFullCircle
kFullCircle
kFullDiamond
kFullDiamond
TGraph2D.h
TGraph.h
TH1D.h
TH1.h
TH2.h
TLegend.h
TPad.h
BmnDrawingOptions
Default options for drawing.
Definition
BmnDrawHist.h:32
BmnDrawingOptions::LineStyle
static Int_t LineStyle(Int_t lineStyleIndex)
Definition
BmnDrawHist.h:43
BmnDrawingOptions::TextSize
static Double_t TextSize()
Definition
BmnDrawHist.h:56
BmnDrawingOptions::Color
static Int_t Color(Int_t colorIndex)
Definition
BmnDrawHist.h:34
BmnDrawingOptions::LineWidth
static Int_t LineWidth()
Definition
BmnDrawHist.h:41
BmnDrawingOptions::MarkerStyle
static Int_t MarkerStyle(Int_t markerIndex)
Definition
BmnDrawHist.h:47
BmnDrawingOptions::MarkerSize
static Float_t MarkerSize()
Definition
BmnDrawHist.h:45
TGraph2D
TGraph
TH1
TH2
DrawGraph2D
void DrawGraph2D(TGraph2D *graph, HistScale logx=kLinear, HistScale logy=kLinear, HistScale logz=kLinear, const string &drawOpt="colz")
Definition
BmnDrawHist.cxx:323
SetDefaultDrawStyle
void SetDefaultDrawStyle()
Definition
BmnDrawHist.cxx:28
DrawH2
void DrawH2(TH2 *hist, HistScale logx=kLinear, HistScale logy=kLinear, HistScale logz=kLinear, const string &drawOpt="COLZ")
Definition
BmnDrawHist.cxx:86
DrawGraph
void DrawGraph(TGraph *graph, HistScale logx=kLinear, HistScale logy=kLinear, const string &drawOpt="AC", Int_t color=BmnDrawingOptions::Color(0), Int_t lineWidth=BmnDrawingOptions::LineWidth(), Int_t lineStyle=BmnDrawingOptions::LineStyle(0), Int_t markerSize=BmnDrawingOptions::MarkerSize(), Int_t markerStyle=BmnDrawingOptions::MarkerStyle(0))
Definition
BmnDrawHist.cxx:249
DrawH1
void DrawH1(TH1 *hist, HistScale logx=kLinear, HistScale logy=kLinear, const string &drawOpt="", Int_t color=BmnDrawingOptions::Color(0), Int_t lineWidth=BmnDrawingOptions::LineWidth(), Int_t lineStyle=BmnDrawingOptions::LineStyle(0), Float_t markerSize=BmnDrawingOptions::MarkerSize(), Int_t markerStyle=BmnDrawingOptions::MarkerStyle(0), Int_t fillColor=-1)
Definition
BmnDrawHist.cxx:44
DrawMeanLine
void DrawMeanLine(TH1 *hist)
Definition
BmnDrawHist.cxx:233
HistScale
HistScale
Define linear or logarithmic scale for drawing.
Definition
BmnDrawHist.h:64
kLinear
@ kLinear
Definition
BmnDrawHist.h:66
kLog
@ kLog
Definition
BmnDrawHist.h:65
install
include
BmnDrawHist.h
Generated on
for BmnRoot by
1.17.0