From 9193223359196fcb67f82c3d2e8b31d7d4061953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Gy=C3=B6ngy=C3=B6si?= Date: Tue, 31 Oct 2017 13:31:45 +0100 Subject: [PATCH] Plotter v1.0 --- include/Plotter.hh | 13 +++++++---- src/Plotter.cc | 57 ++++++++++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/include/Plotter.hh b/include/Plotter.hh index d21ed09..372c3ea 100644 --- a/include/Plotter.hh +++ b/include/Plotter.hh @@ -17,16 +17,19 @@ #include "TCanvas.h" #include "TGraph.h" #include "TTree.h" +#include "TMultiGraph.h" -class Plotter { +class Plotter +{ public: - Plotter(); - void Plot(Int_t n, std::vector t, std::vector x); + Plotter(bool draw); + void Plot(Int_t numRuns, Int_t nSteps, std::vector t, std::vector x); + private: + bool draw; + TMultiGraph *mg; TGraph* g1; - TFile* fOut; TCanvas* canv; - TTree *BM1DTree; Double_t tl,xl; }; #endif diff --git a/src/Plotter.cc b/src/Plotter.cc index 3c27edd..81441ba 100644 --- a/src/Plotter.cc +++ b/src/Plotter.cc @@ -1,36 +1,39 @@ #include "Plotter.hh" -Plotter::Plotter() +Plotter::Plotter(bool draw) { - fOut = new TFile("result.root", "RECREATE"); - canv = new TCanvas("canc","display",800,400); - BM1DTree = new TTree("BM1DTree","BM1DTree"); - BM1DTree->Branch("t",&tl, "t/D"); - BM1DTree->Branch("x",&xl, "x/D"); - +if(draw) + { + draw = draw; + canv = new TCanvas("canc","display",800,400); + } +//g1 = new TGraph(); +mg = new TMultiGraph(); } -void Plotter::Plot(Int_t n, std::vector t, std::vector x){ - g1 = new TGraph(n,&t[0],&x[0]); - canv->cd(); - g1->Draw(); - g1->SetLineColor(1); - g1->SetLineWidth(1); - g1->SetMarkerColor(1); - g1->SetMarkerStyle(0); - g1->SetTitle("Brownian Movement D=1"); - g1->GetYaxis()->SetTitle("X"); - g1->GetXaxis()->SetTitle("Time"); +void Plotter::Plot(Int_t numRuns, Int_t nSteps, std::vector t, std::vector x) +{ + mg->SetTitle("BM1D"); - // for (unsigned int i = 0; i < t.size(); i++){ - for (unsigned int i = 0; i < n; i++){ - tl = t[i]; - xl = x[i]; - BM1DTree->Fill(); + for(int i= 0; i < numRuns; i++) + { + g1 = new TGraph(nSteps,&t[i*nSteps],&x[i*nSteps]); + + g1->SetLineColor(i+1); + g1->SetTitle("Brownian Movement"); + g1->GetYaxis()->SetTitle("X"); + g1->GetXaxis()->SetTitle("Time"); + g1->SetLineWidth(1); + g1->SetMarkerColor(1); + g1->SetMarkerStyle(1); + + mg -> Add(g1); } - g1->Write(); - BM1DTree->Write(); - fOut->Close(); - + if(draw) + { + g1->Draw(); + mg -> Draw(); + } + }