MINT2
Plotter.cpp
Go to the documentation of this file.
1 #include "Mint/Plotter.h"
2 
3 TString Plotter::s_imageformat = ".eps";
4 TString Plotter::s_imageformat2 = "";
5 TString Plotter::s_legend_position = "RightTop";
7 double Plotter::s_forcedMax = -999.999;
8 double Plotter::s_forcedMin = -999.999;
9 
13 void Plotter::setImageFormat(TString format){
14  s_imageformat = format;
15 }
16 
20 Plotter::Plotter(TString canvasName, double width, double height) :
21  _canvas(0),
22  _legend(0),
23  _forcedMax(s_forcedMax),
24  _forcedMin(s_forcedMin),
25  _lMargin(0.11),
26  _rMargin(0.15),
27  _tMargin(0.11),
28  _bMargin(0.15),
29  _xAxisTitleOffset(1.0),
30  _yAxisTitleOffset(1.0),
31  _xAxisLabelOffset(0.010),
32  _yAxisLabelOffset(0.005),
33  _xAxisTickLength(0.035),
34  _yAxisTickLength(0.015),
35  _xAxisLabelSize(0.06),
36  _yAxisLabelSize(0.06),
37  _xAxisTitleSize(0.06),
38  _yAxisTitleSize(0.06),
39  _histogramOwnership(0),
40  _objectOwnership(1),
41  _usePresetColours(1),
42  _allImageFormats (0)
43 {
44  WELCOME_LOG << "Hello from the Plotter() constructor!";
45  TString canvasNameUnique = canvasName; canvasNameUnique += s_plotterCount;
46  _canvas = new TCanvas(canvasNameUnique, canvasName, width, height);
47  _colours.push_back(1);
48  _colours.push_back(kRed);
49  _colours.push_back(kMagenta);
50  _colours.push_back(kGreen);
51  _colours.push_back(kCyan);
52  _colours.push_back(kYellow);
53  _colours.push_back(kBlue);
55 }
56 
61 Plotter::Plotter(const Plotter& other) :
62  _canvas( new TCanvas( other._canvas )),
63  _legend(other._legend),
64  _forcedMax(other._forcedMax),
65  _forcedMin(other._forcedMin),
66  _objToPlot(other._objToPlot),
67  _histograms(other._histograms),
68  _colours(other._colours),
69  _lMargin(other._lMargin),
70  _rMargin(other._rMargin),
71  _tMargin(other._tMargin),
72  _bMargin(other._bMargin),
73  _xAxisLabelOffset(other._xAxisLabelOffset),
74  _yAxisLabelOffset(other._yAxisLabelOffset),
75  _histogramOwnership(0),
76  _objectOwnership(0),
77  _usePresetColours(1),
78  _allImageFormats (0)
79 {
80 
81 }
82 
85 
86  pad->SetLeftMargin(_lMargin);
87  pad->SetBottomMargin(_bMargin);
88  pad->SetRightMargin(_rMargin);
89  pad->SetTopMargin(_tMargin);
90 
91 }
92 
93 void Plotter::setColor(int i, int color){
94 
95  while (i >= (int)_colours.size()) {
96  _colours.push_back( getColor(i) );
97  }
98  _colours.at(i) = color;
99 
100 }
101 
104 
105  return _objToPlot.size();
106 
107 }
108 
109 int Plotter::getColor(int i){
110 
111  VERBOSE_LOG << "Colour " << i;
112 
113  if (i >= (int)_colours.size()) {
114  int j = i%_colours.size();
115  int k = (int)(i/_colours.size());
116  return _colours.at(j) + 2*k;
117  }
118  return _colours.at(i);
119 }
120 
122 void Plotter::add(TObject* histogram){
123  _histograms.push_back(histogram);
124 }
125 
134 void Plotter::addDot(double xpos, double ypos, double size, int colour, TString shape, double sizeY){
135 
136  if (sizeY == 0.0) sizeY = size;
137 
138  if (shape == "square") {
139  TBox* box = new TBox(xpos-size*0.5,ypos-sizeY*0.5,xpos+size*0.5,ypos+sizeY*0.5);
140  box->SetFillColor(colour);
141  _objToPlot.push_back(box);
142  }
143  if (shape == "circle") {
144  TEllipse* box = new TEllipse(xpos,ypos,size*0.5,sizeY*0.5);
145  box->SetFillColor(colour);
146  _objToPlot.push_back(box);
147  }
148 
149 }
150 
152 void Plotter::logX(bool log){
153  _canvas->SetLogx(log);
154 }
155 
157 void Plotter::logY(bool log){
158  _canvas->SetLogy(log);
159 }
160 
162 void Plotter::logZ(bool log){
163  _canvas->SetLogz(log);
164 }
165 
168 void Plotter::addObject(TObject* obj){
169  _objToPlot.push_back(obj);
170 }
171 
173 
174  _xAxisTitleOffset = hist->GetXaxis()->GetTitleOffset(); //(1.0),
175  _yAxisTitleOffset = hist->GetYaxis()->GetTitleOffset(); //(1.0),
176  _xAxisLabelOffset = hist->GetXaxis()->GetLabelOffset(); //(0.010),
177  _yAxisLabelOffset = hist->GetYaxis()->GetLabelOffset(); //(0.005),
178  _xAxisTickLength = hist->GetXaxis()->GetTickLength(); //(0.035),
179  _yAxisTickLength = hist->GetYaxis()->GetTickLength(); //(0.015),
180  _xAxisLabelSize = hist->GetXaxis()->GetLabelSize(); //(0.06),
181  _yAxisLabelSize = hist->GetYaxis()->GetLabelSize(); //(0.06),
182  _xAxisTitleSize = hist->GetXaxis()->GetTitleSize(); //(0.06),
183  _yAxisTitleSize = hist->GetYaxis()->GetTitleSize(); //(0.06),
184 
185 }
186 
191  if (_objectOwnership == 1){
192  for(unsigned int i = 0; i < _objToPlot.size(); i++) delete _objToPlot.at(i);
193  }
194  if (_histogramOwnership == 1){
195  for(unsigned int i = 0; i < _histograms.size(); i++) delete _histograms.at(i);
196  }
197  delete _canvas;
198  if (_legend != 0) delete _legend;
199 }
200 
double _yAxisTickLength
Definition: Plotter.h:53
static TString s_imageformat
Definition: Plotter.h:71
double _tMargin
Definition: Plotter.h:43
static int s_plotterCount
Definition: Plotter.h:74
double _rMargin
Definition: Plotter.h:42
void addObject(TObject *obj)
Definition: Plotter.cpp:168
virtual void setCanvasDefaults(TPad *pad)
Definition: Plotter.cpp:84
static double s_forcedMin
Definition: Plotter.h:76
std::vector< TObject * > _histograms
Definition: Plotter.h:38
double _yAxisLabelOffset
Definition: Plotter.h:50
double _xAxisLabelOffset
Definition: Plotter.h:49
std::vector< TObject * > _objToPlot
Definition: Plotter.h:37
void setPropertiesFromTH1(TH1 *hist)
Definition: Plotter.cpp:172
double _yAxisTitleSize
Definition: Plotter.h:59
int getNumObjects()
Definition: Plotter.cpp:103
TPad * _canvas
Definition: Plotter.h:33
double _xAxisLabelSize
Definition: Plotter.h:55
double _xAxisTitleSize
Definition: Plotter.h:58
#define VERBOSE_LOG
static TString s_imageformat2
Definition: Plotter.h:72
virtual ~Plotter()
Definition: Plotter.cpp:190
double _xAxisTitleOffset
Definition: Plotter.h:46
std::vector< int > _colours
Definition: Plotter.h:39
TLegend * _legend
Definition: Plotter.h:34
void addDot(double xpos, double ypos, double size, int colour=1, TString shape="circle", double sizeY=0.0)
Definition: Plotter.cpp:134
void setColor(int i, int color)
Definition: Plotter.cpp:93
double _xAxisTickLength
Definition: Plotter.h:52
double _bMargin
Definition: Plotter.h:44
void logZ(bool log=1)
Definition: Plotter.cpp:162
double _lMargin
Definition: Plotter.h:41
double _yAxisTitleOffset
Definition: Plotter.h:47
bool _objectOwnership
Definition: Plotter.h:62
void logY(bool log=1)
Definition: Plotter.cpp:157
#define WELCOME_LOG
void logX(bool log=1)
Definition: Plotter.cpp:152
void add(TObject *histogram)
Definition: Plotter.cpp:122
static double s_forcedMax
Definition: Plotter.h:75
Plotter(TString canvasName, double width, double height)
Definition: Plotter.cpp:20
void setImageFormat(TString format)
Definition: Plotter.cpp:13
double _yAxisLabelSize
Definition: Plotter.h:56
static TString s_legend_position
Definition: Plotter.h:73
int getColor(int i)
Definition: Plotter.cpp:109
bool _histogramOwnership
Definition: Plotter.h:61