MINT2
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Plotter Class Referenceabstract

#include <Plotter.h>

Inheritance diagram for Plotter:
RootPlotter RootPlotter1D RootPlotter2D

Public Member Functions

int getColor (int i)
 
void setColor (int i, int color)
 
void usePresetColours (bool val=true)
 
void allImageFormats (bool val=true)
 
void setHistogramOwnership (bool i=1)
 
void setObjectOwnership (bool i=1)
 
 Plotter (TString canvasName, double width, double height)
 
 Plotter (const Plotter &other)
 
virtual void plot (TString plotDirectory, TString plotOptions="", TPad *pad=0, double scaleFactor=1.0)=0
 Draw the histograms and objects onto the canvas. More...
 
void add (TObject *histogram)
 
void addDot (double xpos, double ypos, double size, int colour=1, TString shape="circle", double sizeY=0.0)
 
void logX (bool log=1)
 
void logY (bool log=1)
 
void logZ (bool log=1)
 
void addObject (TObject *obj)
 
int getNumObjects ()
 
void setImageFormat (TString format)
 
TPad * getCanvas ()
 
void scaleTextSize (double scale)
 
void scaleAxisTitleSize (double scale)
 
void scaleAxisTitleOffset (double scale)
 
void setXAxisLabelSize (double val)
 
void setYAxisLabelSize (double val)
 
void setXAxisTitleSize (double val)
 
void setYAxisTitleSize (double val)
 
void setXAxisLabelOffset (double val)
 
void setYAxisLabelOffset (double val)
 
void setXAxisTitleOffset (double val)
 
void setYAxisTitleOffset (double val)
 
void setXAxisTickLength (double val)
 
void setYAxisTickLength (double val)
 
void setPropertiesFromTH1 (TH1 *hist)
 
void setMin (double min)
 
void setMax (double max)
 
void setBMargin (double val)
 
void setLMargin (double val)
 
void setRMargin (double val)
 
void setTMargin (double val)
 
virtual ~Plotter ()
 

Static Public Attributes

static TString s_imageformat = ".eps"
 
static TString s_imageformat2 = ""
 
static TString s_legend_position = "RightTop"
 
static int s_plotterCount = 0
 
static double s_forcedMax = -999.999
 
static double s_forcedMin = -999.999
 

Protected Member Functions

virtual void setCanvasDefaults (TPad *pad)
 

Protected Attributes

TPad * _canvas
 
TLegend * _legend
 
double _forcedMax
 
double _forcedMin
 
std::vector< TObject * > _objToPlot
 
std::vector< TObject * > _histograms
 
std::vector< int > _colours
 
double _lMargin
 
double _rMargin
 
double _tMargin
 
double _bMargin
 
double _xAxisTitleOffset
 
double _yAxisTitleOffset
 
double _xAxisLabelOffset
 
double _yAxisLabelOffset
 
double _xAxisTickLength
 
double _yAxisTickLength
 
double _xAxisLabelSize
 
double _yAxisLabelSize
 
double _xAxisTitleSize
 
double _yAxisTitleSize
 
bool _histogramOwnership
 
bool _objectOwnership
 
bool _usePresetColours
 
bool _allImageFormats
 

Detailed Description

HyperPlot, Author: Sam Harnew, sam.h.nosp@m.arne.nosp@m.w@gma.nosp@m.il.c.nosp@m.om , Date: Dec 2015

Base class for all RootHistogram plotters - these just make plotting root histograms a little easier.

Definition at line 26 of file Plotter.h.

Constructor & Destructor Documentation

◆ Plotter() [1/2]

Plotter::Plotter ( TString  canvasName,
double  width,
double  height 
)

Contruct a plotter with some name, width and height

Definition at line 20 of file Plotter.cpp.

20  :
21  _canvas(0),
22  _legend(0),
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),
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 }
double _yAxisTickLength
Definition: Plotter.h:53
double _tMargin
Definition: Plotter.h:43
static int s_plotterCount
Definition: Plotter.h:74
double _rMargin
Definition: Plotter.h:42
static double s_forcedMin
Definition: Plotter.h:76
double _forcedMax
Definition: Plotter.h:35
double _yAxisLabelOffset
Definition: Plotter.h:50
double _xAxisLabelOffset
Definition: Plotter.h:49
double _yAxisTitleSize
Definition: Plotter.h:59
TPad * _canvas
Definition: Plotter.h:33
double _xAxisLabelSize
Definition: Plotter.h:55
double _xAxisTitleSize
Definition: Plotter.h:58
double _forcedMin
Definition: Plotter.h:36
double _xAxisTitleOffset
Definition: Plotter.h:46
std::vector< int > _colours
Definition: Plotter.h:39
TLegend * _legend
Definition: Plotter.h:34
double _xAxisTickLength
Definition: Plotter.h:52
double _bMargin
Definition: Plotter.h:44
bool _usePresetColours
Definition: Plotter.h:64
double _lMargin
Definition: Plotter.h:41
double _yAxisTitleOffset
Definition: Plotter.h:47
bool _allImageFormats
Definition: Plotter.h:65
bool _objectOwnership
Definition: Plotter.h:62
#define WELCOME_LOG
static double s_forcedMax
Definition: Plotter.h:75
double _yAxisLabelSize
Definition: Plotter.h:56
bool _histogramOwnership
Definition: Plotter.h:61

◆ Plotter() [2/2]

Plotter::Plotter ( const Plotter other)

Copy another plotter - this will hold the same pointers, so make sure that the new plotter doesn't own any of them

Definition at line 61 of file Plotter.cpp.

61  :
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),
79 {
80 
81 }
double _tMargin
Definition: Plotter.h:43
double _rMargin
Definition: Plotter.h:42
std::vector< TObject * > _histograms
Definition: Plotter.h:38
double _forcedMax
Definition: Plotter.h:35
double _yAxisLabelOffset
Definition: Plotter.h:50
double _xAxisLabelOffset
Definition: Plotter.h:49
std::vector< TObject * > _objToPlot
Definition: Plotter.h:37
TPad * _canvas
Definition: Plotter.h:33
double _forcedMin
Definition: Plotter.h:36
std::vector< int > _colours
Definition: Plotter.h:39
TLegend * _legend
Definition: Plotter.h:34
double _bMargin
Definition: Plotter.h:44
bool _usePresetColours
Definition: Plotter.h:64
double _lMargin
Definition: Plotter.h:41
bool _allImageFormats
Definition: Plotter.h:65
bool _objectOwnership
Definition: Plotter.h:62
bool _histogramOwnership
Definition: Plotter.h:61

◆ ~Plotter()

Plotter::~Plotter ( )
virtual

Definition at line 190 of file Plotter.cpp.

190  {
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 }
std::vector< TObject * > _histograms
Definition: Plotter.h:38
std::vector< TObject * > _objToPlot
Definition: Plotter.h:37
TPad * _canvas
Definition: Plotter.h:33
TLegend * _legend
Definition: Plotter.h:34
bool _objectOwnership
Definition: Plotter.h:62
bool _histogramOwnership
Definition: Plotter.h:61

Member Function Documentation

◆ add()

void Plotter::add ( TObject *  histogram)

add a histogram to the plotter

Definition at line 122 of file Plotter.cpp.

122  {
123  _histograms.push_back(histogram);
124 }
std::vector< TObject * > _histograms
Definition: Plotter.h:38

◆ addDot()

void Plotter::addDot ( double  xpos,
double  ypos,
double  size,
int  colour = 1,
TString  shape = "circle",
double  sizeY = 0.0 
)

add a dot to some point in the canvas

The TString 'shape' can be

  • square (draws a TBox at that (x,y) coord )
  • circle (draws a TEllipse at that (x,y) coord )

Definition at line 134 of file Plotter.cpp.

134  {
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 }
std::vector< TObject * > _objToPlot
Definition: Plotter.h:37

◆ addObject()

void Plotter::addObject ( TObject *  obj)

Add an object to the Plotter (e.g. TMarker, TBox...). By default, the plotter takes ownership of the object

Definition at line 168 of file Plotter.cpp.

168  {
169  _objToPlot.push_back(obj);
170 }
std::vector< TObject * > _objToPlot
Definition: Plotter.h:37

◆ allImageFormats()

void Plotter::allImageFormats ( bool  val = true)
inline

If switched on, the plotter will save the canvas to .pdf .png .eps and .C formats (as required by CDS)

Definition at line 83 of file Plotter.h.

◆ getCanvas()

TPad* Plotter::getCanvas ( )
inline

Get the canvas

Definition at line 111 of file Plotter.h.

◆ getColor()

int Plotter::getColor ( int  i)

Get histogram colour i (these are preset)

Definition at line 109 of file Plotter.cpp.

109  {
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 }
#define VERBOSE_LOG
std::vector< int > _colours
Definition: Plotter.h:39

◆ getNumObjects()

int Plotter::getNumObjects ( )

how many objects have been added to the plotter

Definition at line 103 of file Plotter.cpp.

103  {
104 
105  return _objToPlot.size();
106 
107 }
std::vector< TObject * > _objToPlot
Definition: Plotter.h:37

◆ logX()

void Plotter::logX ( bool  log = 1)

use a log scale for the x-axis

Definition at line 152 of file Plotter.cpp.

152  {
153  _canvas->SetLogx(log);
154 }
TPad * _canvas
Definition: Plotter.h:33

◆ logY()

void Plotter::logY ( bool  log = 1)

use a log scale for the y-axis

Definition at line 157 of file Plotter.cpp.

157  {
158  _canvas->SetLogy(log);
159 }
TPad * _canvas
Definition: Plotter.h:33

◆ logZ()

void Plotter::logZ ( bool  log = 1)

use a log scale for the z-axis

Definition at line 162 of file Plotter.cpp.

162  {
163  _canvas->SetLogz(log);
164 }
TPad * _canvas
Definition: Plotter.h:33

◆ plot()

virtual void Plotter::plot ( TString  plotDirectory,
TString  plotOptions = "",
TPad *  pad = 0,
double  scaleFactor = 1.0 
)
pure virtual

Draw the histograms and objects onto the canvas.

Implemented in RootPlotter.

◆ scaleAxisTitleOffset()

void Plotter::scaleAxisTitleOffset ( double  scale)
inline

Scale the title offsets on the axis by a constant factor

Definition at line 128 of file Plotter.h.

◆ scaleAxisTitleSize()

void Plotter::scaleAxisTitleSize ( double  scale)
inline

Scale the titles on the axis by a constant factor

Definition at line 122 of file Plotter.h.

◆ scaleTextSize()

void Plotter::scaleTextSize ( double  scale)
inline

Scale the labels and titles on the axis by a constant factor

Definition at line 114 of file Plotter.h.

◆ setBMargin()

void Plotter::setBMargin ( double  val)
inline

set the left margin size (as a fracition of the pad width)

Definition at line 158 of file Plotter.h.

◆ setCanvasDefaults()

void Plotter::setCanvasDefaults ( TPad *  pad)
protectedvirtual

Set defaults on the TCanvas

Definition at line 84 of file Plotter.cpp.

84  {
85 
86  pad->SetLeftMargin(_lMargin);
87  pad->SetBottomMargin(_bMargin);
88  pad->SetRightMargin(_rMargin);
89  pad->SetTopMargin(_tMargin);
90 
91 }
double _tMargin
Definition: Plotter.h:43
double _rMargin
Definition: Plotter.h:42
double _bMargin
Definition: Plotter.h:44
double _lMargin
Definition: Plotter.h:41

◆ setColor()

void Plotter::setColor ( int  i,
int  color 
)

Set histogram colour i

Definition at line 93 of file Plotter.cpp.

93  {
94 
95  while (i >= (int)_colours.size()) {
96  _colours.push_back( getColor(i) );
97  }
98  _colours.at(i) = color;
99 
100 }
std::vector< int > _colours
Definition: Plotter.h:39
int getColor(int i)
Definition: Plotter.cpp:109

◆ setHistogramOwnership()

void Plotter::setHistogramOwnership ( bool  i = 1)
inline

Should I take ownership of the histograms (default is no)

Definition at line 86 of file Plotter.h.

◆ setImageFormat()

void Plotter::setImageFormat ( TString  format)

Set the image format for all plots to be made

Definition at line 13 of file Plotter.cpp.

13  {
14  s_imageformat = format;
15 }
static TString s_imageformat
Definition: Plotter.h:71

◆ setLMargin()

void Plotter::setLMargin ( double  val)
inline

set the right margin size (as a fracition of the pad width)

Definition at line 159 of file Plotter.h.

◆ setMax()

void Plotter::setMax ( double  max)
inline

Set the forced maximum (histograms will be forced to draw with this max)

Definition at line 155 of file Plotter.h.

◆ setMin()

void Plotter::setMin ( double  min)
inline

Set the forced minimum (histograms will be forced to draw with this min)

Definition at line 153 of file Plotter.h.

◆ setObjectOwnership()

void Plotter::setObjectOwnership ( bool  i = 1)
inline

Should I take ownership of the objects (default is yes)

Definition at line 88 of file Plotter.h.

◆ setPropertiesFromTH1()

void Plotter::setPropertiesFromTH1 ( TH1 *  hist)

set _xAxisTitleOffset, _yAxisTitleOffset, _xAxisLabelOffset, _yAxisLabelOffset, _xAxisTickLength , _yAxisTickLength , _xAxisLabelSize , _yAxisLabelSize , _xAxisTitleSize , _yAxisTitleSize from the histogram given.

Destructor - delete all the histograms and objects that I own.

Definition at line 172 of file Plotter.cpp.

◆ setRMargin()

void Plotter::setRMargin ( double  val)
inline

set the top margin size (as a fracition of the pad width)

Definition at line 160 of file Plotter.h.

◆ setTMargin()

void Plotter::setTMargin ( double  val)
inline

set the bottom margin size (as a fracition of the pad width)

Definition at line 161 of file Plotter.h.

◆ setXAxisLabelOffset()

void Plotter::setXAxisLabelOffset ( double  val)
inline

set the x-axis label offset

Definition at line 138 of file Plotter.h.

◆ setXAxisLabelSize()

void Plotter::setXAxisLabelSize ( double  val)
inline

set the x-axis label size

Definition at line 134 of file Plotter.h.

◆ setXAxisTickLength()

void Plotter::setXAxisTickLength ( double  val)
inline

set the x-axis tick length

Definition at line 142 of file Plotter.h.

◆ setXAxisTitleOffset()

void Plotter::setXAxisTitleOffset ( double  val)
inline

set the x-axis title offset

Definition at line 140 of file Plotter.h.

◆ setXAxisTitleSize()

void Plotter::setXAxisTitleSize ( double  val)
inline

set the x-axis title size

Definition at line 136 of file Plotter.h.

◆ setYAxisLabelOffset()

void Plotter::setYAxisLabelOffset ( double  val)
inline

set the y-axis label offset

Definition at line 139 of file Plotter.h.

◆ setYAxisLabelSize()

void Plotter::setYAxisLabelSize ( double  val)
inline

set the y-axis label size

Definition at line 135 of file Plotter.h.

◆ setYAxisTickLength()

void Plotter::setYAxisTickLength ( double  val)
inline

set the y-axis tick length

Definition at line 143 of file Plotter.h.

◆ setYAxisTitleOffset()

void Plotter::setYAxisTitleOffset ( double  val)
inline

set the y-axis title offset

Definition at line 141 of file Plotter.h.

◆ setYAxisTitleSize()

void Plotter::setYAxisTitleSize ( double  val)
inline

set the y-axis title size

Definition at line 137 of file Plotter.h.

◆ usePresetColours()

void Plotter::usePresetColours ( bool  val = true)
inline

Should I use the preset colours?

Definition at line 82 of file Plotter.h.

Member Data Documentation

◆ _allImageFormats

bool Plotter::_allImageFormats
protected

If true, I will save the canvas in all formats when plot() is called

Definition at line 65 of file Plotter.h.

◆ _bMargin

double Plotter::_bMargin
protected

bottom margin size (as a fracition of the pad width)

Definition at line 44 of file Plotter.h.

◆ _canvas

TPad* Plotter::_canvas
protected

The canvas which add histograms and TObjects are plotted on

Definition at line 33 of file Plotter.h.

◆ _colours

std::vector<int> Plotter::_colours
protected

Vector of colours to draw the histograms

Definition at line 39 of file Plotter.h.

◆ _forcedMax

double Plotter::_forcedMax
protected

Force a maximum for plotting histograms

Definition at line 35 of file Plotter.h.

◆ _forcedMin

double Plotter::_forcedMin
protected

Force a minimum for plotting histogram

Definition at line 36 of file Plotter.h.

◆ _histogramOwnership

bool Plotter::_histogramOwnership
protected

do I own the Histogram pointers given to me?

Definition at line 61 of file Plotter.h.

◆ _histograms

std::vector<TObject*> Plotter::_histograms
protected

Vector of Histogramss to plot (e.g TH1D or TH2D)

Definition at line 38 of file Plotter.h.

◆ _legend

TLegend* Plotter::_legend
protected

The legend (not really implemented yet)

Definition at line 34 of file Plotter.h.

◆ _lMargin

double Plotter::_lMargin
protected

left margin size (as a fracition of the pad width)

Definition at line 41 of file Plotter.h.

◆ _objectOwnership

bool Plotter::_objectOwnership
protected

do I own the Objects pointers given to me?

Definition at line 62 of file Plotter.h.

◆ _objToPlot

std::vector<TObject*> Plotter::_objToPlot
protected

Vector of TObjects to plot (e.g TLine or TMarker)

Definition at line 37 of file Plotter.h.

◆ _rMargin

double Plotter::_rMargin
protected

right margin size (as a fracition of the pad width)

Definition at line 42 of file Plotter.h.

◆ _tMargin

double Plotter::_tMargin
protected

top margin size (as a fracition of the pad width)

Definition at line 43 of file Plotter.h.

◆ _usePresetColours

bool Plotter::_usePresetColours
protected

Do I use my colour scheme for histograms (true) or the original colours given (false)

Definition at line 64 of file Plotter.h.

◆ _xAxisLabelOffset

double Plotter::_xAxisLabelOffset
protected

x-axis label offset

Definition at line 49 of file Plotter.h.

◆ _xAxisLabelSize

double Plotter::_xAxisLabelSize
protected

x-axis label size

Definition at line 55 of file Plotter.h.

◆ _xAxisTickLength

double Plotter::_xAxisTickLength
protected

x-axis tick length

Definition at line 52 of file Plotter.h.

◆ _xAxisTitleOffset

double Plotter::_xAxisTitleOffset
protected

x-axis title offset

Definition at line 46 of file Plotter.h.

◆ _xAxisTitleSize

double Plotter::_xAxisTitleSize
protected

x-axis title size

Definition at line 58 of file Plotter.h.

◆ _yAxisLabelOffset

double Plotter::_yAxisLabelOffset
protected

y-axis label offset

Definition at line 50 of file Plotter.h.

◆ _yAxisLabelSize

double Plotter::_yAxisLabelSize
protected

y-axis label size

Definition at line 56 of file Plotter.h.

◆ _yAxisTickLength

double Plotter::_yAxisTickLength
protected

y-axis tick length

Definition at line 53 of file Plotter.h.

◆ _yAxisTitleOffset

double Plotter::_yAxisTitleOffset
protected

y-axis title offset

Definition at line 47 of file Plotter.h.

◆ _yAxisTitleSize

double Plotter::_yAxisTitleSize
protected

y-axis title size

Definition at line 59 of file Plotter.h.

◆ s_forcedMax

double Plotter::s_forcedMax = -999.999
static

Force a maximum histogram value for all plotters

Definition at line 75 of file Plotter.h.

◆ s_forcedMin

double Plotter::s_forcedMin = -999.999
static

Force a minimum histogram value for all plotters

Definition at line 76 of file Plotter.h.

◆ s_imageformat

TString Plotter::s_imageformat = ".eps"
static

Primary image format

Definition at line 71 of file Plotter.h.

◆ s_imageformat2

TString Plotter::s_imageformat2 = ""
static

Secondary image format

Definition at line 72 of file Plotter.h.

◆ s_legend_position

TString Plotter::s_legend_position = "RightTop"
static

Legend positon

Definition at line 73 of file Plotter.h.

◆ s_plotterCount

int Plotter::s_plotterCount = 0
static

Plotter count (good for making unique names)

Definition at line 74 of file Plotter.h.


The documentation for this class was generated from the following files: