MINT2
RootPlotter2D.cpp
Go to the documentation of this file.
1 #include "Mint/RootPlotter2D.h"
2 #include "Mint/GlobalFunctions.h"
3 
5 RootPlotter2D::RootPlotter2D(TH1* histogram, double width, double height) :
6  RootPlotter(histogram, width, height)
7 {
8  WELCOME_LOG << "Hello from the Plotter() constructor!";
9  //_yAxisLabelOffset = 0.0;
10  _yAxisTitleOffset = 1.3;
11  //_xAxisLabelOffset = 0.9;
12  _lMargin = 0.20;
13  _rMargin = 0.18;
14  _tMargin = 0.10;
15  _bMargin = 0.14;
16 }
17 
19 void RootPlotter2D::setHistogramStyle(TH1* histogram, bool setMinMax){
20 
21  histogram->SetTitle("");
22 
23  histogram->GetXaxis()->SetTitleSize(_xAxisTitleSize);
24  histogram->GetYaxis()->SetTitleSize(_yAxisTitleSize);
25 
26  histogram->GetXaxis()->SetLabelSize(_xAxisLabelSize);
27  histogram->GetYaxis()->SetLabelSize(_yAxisLabelSize);
28 
29  histogram->GetXaxis()->SetTickLength(_xAxisTickLength);
30  histogram->GetYaxis()->SetTickLength(_yAxisTickLength);
31 
32  histogram->GetXaxis()->SetLabelOffset(_xAxisLabelOffset);
33  histogram->GetYaxis()->SetLabelOffset(_yAxisLabelOffset);
34 
35  histogram->GetXaxis()->SetTitleOffset(_xAxisTitleOffset);
36  histogram->GetYaxis()->SetTitleOffset(_yAxisTitleOffset);
37 
38  histogram->GetXaxis()->SetTitle(_xAxisName);
39  histogram->GetYaxis()->SetTitle(_yAxisName);
40 
41 
42  if (setMinMax) histogram->SetMaximum(getGlobalMax());
43  if (setMinMax) histogram->SetMinimum(getGlobalMin());
44  if (setMinMax) histogram->GetZaxis()->SetRangeUser(getGlobalMin(), getGlobalMax());
45 
46 }
47 
50 void RootPlotter2D::addVerticalBox(double xmin, double xmax, int fillColour, int fillstyle){
51  double ymin = getHistogram(0)->GetYaxis()->GetBinLowEdge(0);
52  double ymax = getHistogram(0)->GetYaxis()->GetBinUpEdge( getHistogram(0)->GetYaxis()->GetNbins() );
53 
54  TBox* box = new TBox(xmin ,ymin ,xmax, ymax );
55  box->SetLineColor(0);
56  box->SetFillColor(fillColour);
57  box->SetFillStyle(fillstyle);
58  _objToPlot.push_back(box);
59 }
60 
63 
64  if (_forcedMin != -999.999) return _forcedMin;
65  double globalMin = getHistogram(0)->GetBinContent(getHistogram(0)->GetMinimumBin());
66 
67  for (unsigned int h=1; h<_histograms.size(); h++)
68  {
69  double min = getHistogram(h)->GetBinContent(getHistogram(h)->GetMinimumBin());
70  if (min < globalMin) globalMin = min;
71  }
72 
73  if (globalMin > 0) globalMin = globalMin*0.95;
74  else globalMin = globalMin*1.05;
75 
76  return globalMin;
77 }
78 
81 
82  if (_forcedMax != -999.999) return _forcedMax;
83  double globalMax = getHistogram(0)->GetBinContent(getHistogram(0)->GetMaximumBin());
84  for (unsigned int h=1; h<_histograms.size(); h++)
85  {
86  double max = getHistogram(h)->GetBinContent(getHistogram(h)->GetMaximumBin());
87  if (max > globalMax) globalMax = max;
88  }
89 
90  globalMax = globalMax*1.05;
91 
92  return globalMax;
93 
94 }
95 
98 void RootPlotter2D::addVerticalLine(double xpos, int style){
99  double ymin = getHistogram(0)->GetYaxis()->GetBinLowEdge(1);
100  double ymax = getHistogram(0)->GetYaxis()->GetBinUpEdge (getHistogram(0)->GetXaxis()->GetNbins());
101  INFO_LOG << "Adding TLine from (" << xpos << ", " << ymin << ") to (" << xpos << ", " << ymax << ")";
102  TLine* line = new TLine(xpos ,ymin ,xpos, ymax );
103  line->SetLineColor(1);
104  line->SetLineStyle(style);
105  _objToPlot.push_back(line);
106 }
107 
110 void RootPlotter2D::addHorizontalLine(double ypos, int style){
111  double xlow = getHistogram(0)->GetXaxis()->GetBinLowEdge(1);
112  double xhigh = getHistogram(0)->GetXaxis()->GetBinUpEdge (getHistogram(0)->GetXaxis()->GetNbins());
113  TLine* line = new TLine(xlow ,ypos ,xhigh, ypos );
114  line->SetLineColor(1);
115  line->SetLineStyle(style);
116  _objToPlot.push_back(line);
117 }
118 
121 
122 }
double _yAxisTickLength
Definition: Plotter.h:53
double _tMargin
Definition: Plotter.h:43
double _rMargin
Definition: Plotter.h:42
std::vector< TObject * > _histograms
Definition: Plotter.h:38
#define INFO_LOG
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
double _yAxisTitleSize
Definition: Plotter.h:59
virtual double getGlobalMin()
double _xAxisLabelSize
Definition: Plotter.h:55
double _xAxisTitleSize
Definition: Plotter.h:58
double _forcedMin
Definition: Plotter.h:36
void addHorizontalLine(double ypos, int style=1)
double _xAxisTitleOffset
Definition: Plotter.h:46
double _xAxisTickLength
Definition: Plotter.h:52
double _bMargin
Definition: Plotter.h:44
TString _yAxisName
Definition: RootPlotter.h:28
TString _xAxisName
Definition: RootPlotter.h:27
double _lMargin
Definition: Plotter.h:41
double _yAxisTitleOffset
Definition: Plotter.h:47
#define WELCOME_LOG
virtual double getGlobalMax()
void addVerticalBox(double xmin, double xmax, int fillColour, int fillstyle)
void addVerticalLine(double xpos, int style=1)
TH1 * getHistogram(int i)
Definition: RootPlotter.cpp:16
RootPlotter2D(TH1 *histogram, double width=350, double height=300)
virtual void setHistogramStyle(TH1 *histogram, bool setMinMax)
double _yAxisLabelSize
Definition: Plotter.h:56
virtual ~RootPlotter2D()