10#include "MultiGraph.h"
17#include <TAttMarker.h>
19#include <TGraphErrors.h>
21#include <TMultiGraph.h>
23#include <TVirtualPad.h>
28 MultiGraph::MultiGraph() : fN(0), fGraphErrors(nullptr), fMultiGraph(new TMultiGraph()), fXaxis(nullptr), fYaxis(nullptr) {
29 fMin[0] = fMin[1] = 0;
30 fMax[0] = fMax[1] = 0;
35 TGraphErrors** temp = fGraphErrors;
36 fGraphErrors =
new TGraphErrors*[fN + 1];
37 for (
int i = 0; i < fN; i++) {
38 fGraphErrors[i] = temp[i];
41 fGraphErrors[fN] =
new TGraphErrors();
42 fMultiGraph->Add(fGraphErrors[fN], opt);
56 void MultiGraph::SetPoint(Int_t graph, Int_t point, Double_t x, Double_t y) { fGraphErrors[graph]->SetPoint(point, x, y); }
59 fGraphErrors[graph]->SetPoint(point, x, y);
60 fGraphErrors[graph]->SetPointError(point, ex, ey);
68 if (option.Contains(
"A") == kFALSE) option =
"A" + option;
69 fMultiGraph->Draw(option);
70 if (fXaxis) Hal::Std::CopyAxisProp(fXaxis, fMultiGraph->GetXaxis());
71 if (fYaxis) Hal::Std::CopyAxisProp(fYaxis, fMultiGraph->GetYaxis());
72 if (fMin[0] != fMax[0]) {
73 fMultiGraph->GetXaxis()->SetRangeUser(fMin[0], fMax[0]);
74 fMultiGraph->GetXaxis()->SetLimits(fMin[0], fMax[0]);
76 if (fMin[1] != fMax[1]) fMultiGraph->GetYaxis()->SetRangeUser(fMin[1], fMax[1]);
83 for (
int i = 0; i < fN; i++)
86 fGraphErrors[no]->SetMarkerStyle(marker);
88 std::cout << __FILE__ <<
" " << __LINE__ <<
"Cannot SetMarkerStyle to graph " << no << std::endl;
94 for (
int i = 0; i < fN; i++)
97 fGraphErrors[no]->SetMarkerSize(size);
99 std::cout << __FILE__ <<
" " << __LINE__ <<
"Cannot SetMarkerSize to graph " << no << std::endl;
105 for (
int i = 0; i < fN; i++)
107 }
else if (no < fN) {
108 fGraphErrors[no]->SetMarkerColor(color);
110 std::cout << __FILE__ <<
" " << __LINE__ <<
"Cannot SetMarkerColor to graph " << no << std::endl;
116 for (
int i = 0; i < fN; i++)
118 }
else if (no < fN) {
119 fGraphErrors[no]->SetLineWidth(width);
121 std::cout << __FILE__ <<
" " << __LINE__ <<
"Cannot SetLineWidth to graph " << no << std::endl;
127 for (
int i = 0; i < fN; i++)
129 }
else if (no < fN) {
130 fGraphErrors[no]->SetLineColor(color);
132 std::cout << __FILE__ <<
" " << __LINE__ <<
"Cannot SetLineColor to graph " << no << std::endl;
138 for (
int i = 0; i < fN; i++)
140 }
else if (no < fN) {
141 fGraphErrors[no]->SetLineStyle(style);
158 for (
int i = 0; i < no; i++) {
165 MultiGraph::~MultiGraph() {
168 for (
int i = 0; i < fN; i++) {
169 delete fGraphErrors[i];
172 delete[] fGraphErrors;
173 if (fXaxis)
delete fXaxis;
174 if (fYaxis)
delete fYaxis;
178 if (fXaxis)
return fXaxis;
179 fXaxis =
new TAxis();
184 if (fYaxis)
return fYaxis;
185 fYaxis =
new TAxis();
194 auto axis = h.GetXaxis();
195 for (
int i = 0; i <= axis->GetNbins(); i++) {
196 SetPoint(no, i, axis->GetBinCenter(i), 0, h.GetBinContent(i), h.GetBinError(i));
void MakeGraphs(Int_t no, Option_t *opt="P")
void MakeGraph(Option_t *opt="P")
void SetYRange(Double_t min, Double_t max)
void SetLineColor(Color_t color, Int_t no=-1)
TGraphErrors * GetGraph(Int_t no) const
TMultiGraph * GetMutliGraph() const
void SetLineAttributes(Style_t style, Width_t width, Color_t color, Int_t no=-1)
void SetXRange(Double_t min, Double_t max)
void SetMarkerColor(Color_t color, Int_t no=-1)
void Draw(Option_t *opt="")
void SetMarkerStyle(Style_t marker, Int_t no=-1)
void SetLineStyle(Style_t style, Int_t no=-1)
void SetMarkerSize(Size_t size, Int_t no=-1)
void SetMarkerAttributes(Style_t style, Size_t size, Color_t color, Int_t no=-1)
void SetLineWidth(Width_t width, Int_t no=-1)
void AddHistogram(const TH1 &h, Int_t no=-1)
void SetPoint(Int_t graph, Int_t point, Double_t x, Double_t y)