diff --git a/BM1D.cc b/BM1D.cc index 2eae252..4f98d29 100644 --- a/BM1D.cc +++ b/BM1D.cc @@ -1,81 +1,20 @@ -/// BM1D program. Date: 2017-10-29 Creators: Balázs Demeter, Balázs Ujvári, Dávid Baranyai - #include -#include "Progress.hh" +#include "BM1DProcess.hh" +#include "Plotter.hh" #include "TApplication.h" -#include "TGraph.h" using namespace std; -void OpenRootFile() -{ - TFile *fIn = TFile::Open("Plot1.root", "READ"); - fIn->ls(); - TGraph *Ga; - TGraph *Gb; - fIn->GetObject("1", Ga); - fIn->GetObject("2", Gb); - Ga->Draw(); - Gb->Draw("same"); - delete fIn; -} - - int main(int argc, char* argv[]) { - Int_t n = 1000, p0 = 1, start = 0; - - TApplication App("tapp", &argc, argv); - TCanvas* Canv = new TCanvas("c10","Live display",800,400); - - if(argc==2) - { - OpenRootFile(); - } - else - { - - Progress* Pr1 = new Progress(n,p0,start); - Progress* Pr2 = new Progress(n,p0,start); - - Pr1->Count('u'); - Pr2->Count('g'); - - vector x1 = Pr1->GetX(); - vector y1 = Pr1->GetY(); - vector x2 = Pr2->GetX(); - vector y2 = Pr2->GetY(); - - TGraph* G1 = new TGraph(n,&x1[0],&y1[0]); - TGraph* G2 = new TGraph(n,&x2[0],&y2[0]); - - TFile* fOut = new TFile("Plot1.root", "RECREATE"); - - G1->SetLineColor(1); - G1->SetLineWidth(1); - G1->SetMarkerColor(1); - G1->SetMarkerStyle(0); - G1->SetTitle("Brownian Movement D=1"); - G1->GetXaxis()->SetTitle("X"); - G1->GetYaxis()->SetTitle("Time"); - G2->SetLineColor(2); - G2->SetLineWidth(1); - G2->SetMarkerColor(2); - G2->SetMarkerStyle(0); - G2->SetTitle("Brownian Movement D=1"); - G2->GetXaxis()->SetTitle("X"); - G2->GetYaxis()->SetTitle("Time"); - - G1->Draw(); - G2->Draw("same"); - G1->Write("1"); - G2->Write("2"); - - fOut->Close(); - - } - - App.Run(); - return 0; + TApplication App("tapp", &argc, argv); + Int_t n = 1000; + BM1DProcess *myBM1DProcess = new BM1DProcess(n); + myBM1DProcess->Init(); + myBM1DProcess->Run(); + Plotter* myPlotter = new Plotter(); + myPlotter->Plot(n, myBM1DProcess->GetT(), myBM1DProcess->GetX()); + App.Run(); + return 0; } diff --git a/README.md b/README.md index 9296e62..d91fdaa 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,8 @@ If there's command line argument, then program opens the created root file. Name ## Updates +* 2017/10/30 - 'v1.4' - New Structure + * 2017/10/29 - 'v1.3.1' - Release Candidate * 2017/10/29 - 'v1.3' - Minor fixes in Progress diff --git a/include/BM1DProcess.hh b/include/BM1DProcess.hh new file mode 100644 index 0000000..ba91c09 --- /dev/null +++ b/include/BM1DProcess.hh @@ -0,0 +1,35 @@ +#ifndef BM1DProcess_h +#define BM1DProcess_h 1 + +#include +#include +#include +#include + +#include "TRandom.h" + +class BM1DProcess { +public: + BM1DProcess(Int_t n); //n is the number of steps + ~BM1DProcess(); + + void SetP0(Double_t p0_new){p0 = p0_new;} + void SetP1(Double_t p1_new){p1 = p1_new;} + + void Init(); + void Run(); + + std::vector GetT(){return t;} + std::vector GetX(){return x;} + + private: + Int_t nSteps; + Double_t p0,p1,p2,p3,p4; + TRandom* randomGenerator; + Double_t rand1; + std::vector t; + std::vector x; +}; + +#endif + diff --git a/include/BM1DProcess.hh~ b/include/BM1DProcess.hh~ new file mode 100644 index 0000000..e69de29 diff --git a/include/Plotter.hh b/include/Plotter.hh new file mode 100644 index 0000000..d21ed09 --- /dev/null +++ b/include/Plotter.hh @@ -0,0 +1,32 @@ +#ifndef Plotter_h +#define Plotter_h 1 + +#include +#include +#include +#include + +#include "TROOT.h" +#include "TF1.h" +#include "TH1.h" +#include "TH2.h" +#include "TH3.h" +#include "TNtuple.h" +#include "TFile.h" +#include "TMath.h" +#include "TCanvas.h" +#include "TGraph.h" +#include "TTree.h" + +class Plotter { +public: + Plotter(); + void Plot(Int_t n, std::vector t, std::vector x); +private: + TGraph* g1; + TFile* fOut; + TCanvas* canv; + TTree *BM1DTree; + Double_t tl,xl; +}; +#endif diff --git a/include/Plotter.hh~ b/include/Plotter.hh~ new file mode 100644 index 0000000..e69de29 diff --git a/include/Progress.hh b/include/Progress.hh deleted file mode 100644 index 2762ef5..0000000 --- a/include/Progress.hh +++ /dev/null @@ -1,58 +0,0 @@ -/// BM1D program. Date: 2017-10-29 Creators: Balázs Demeter, Balázs Ujvári, Dávid Baranyai - -#ifndef Progress_h -#define Progress_h 1 - -#include -#include -#include -#include - -#include "TROOT.h" -#include "TF1.h" -#include "TH1.h" -#include "TH2.h" -#include "TH3.h" -#include "TNtuple.h" -#include "TFile.h" -#include "TRandom.h" -#include "TMath.h" -#include "TCanvas.h" - -class Progress { - -public: - - Progress(Int_t n); - Progress(Int_t n, Double_t p0_Set); - Progress(Int_t n, Double_t p0_Set, Double_t startposition); - ~Progress(); - - void Count(char a); - - Double_t GetP0(); - Int_t GetSteps(); - Double_t GetNext(char a); - Double_t GetPrevious(); - - void SetP0(double p0_new); - - std::vector GetX(); - std::vector GetY(); - -private: - - TRandom* random1; - const Int_t n; - std::vector x; - std::vector y; - - Double_t p0; - Double_t preVstate; - Int_t steps; - -}; - -#endif - - diff --git a/result.root b/result.root new file mode 100644 index 0000000..25bbb83 Binary files /dev/null and b/result.root differ diff --git a/setup.sh b/setup.sh old mode 100755 new mode 100644 index ee2b421..7587dd5 --- a/setup.sh +++ b/setup.sh @@ -1,10 +1,6 @@ #!/bin/bash -# -# Author: Balázs Demeter (balazsdemeter92@gmail.com) -# Version: 1.0 -# -# Script for build and make Brownian movement in one dimension +rm -rf bm1d_build mkdir bm1d_build cd bm1d_build cmake ../ diff --git a/src/BM1DProcess.cc b/src/BM1DProcess.cc new file mode 100644 index 0000000..364a117 --- /dev/null +++ b/src/BM1DProcess.cc @@ -0,0 +1,40 @@ +#include "BM1DProcess.hh" + +BM1DProcess::BM1DProcess(Int_t nP) : + nSteps (nP), p0(0.5), p1(0.3) +{ + randomGenerator = new TRandom(); +} + +BM1DProcess::~BM1DProcess() +{ + ; +} + +void BM1DProcess::Init(){ + t.push_back(0.0); //let's start at t=0, x=0, you can change it if you vant, please use Set methods + x.push_back(0.0); +} + +void BM1DProcess::Run(){ + for (Int_t i = 1;i < nSteps;i++) + { + rand1 = randomGenerator->Uniform(); + if(rand1 < p0) { //step in time, but no step in x + t.push_back(t[i-1] + 1); + x.push_back(x[i-1]); + } + else {//step left or right + if(rand1 < p0 + p1) + { + t.push_back(t[i-1]+1); + x.push_back(x[i-1]+1); //one step right + } + else + { + t.push_back(t[i-1]+1); + x.push_back(x[i-1]-1); //one step left + } + } + } +} diff --git a/src/BM1DProcess.cc~ b/src/BM1DProcess.cc~ new file mode 100644 index 0000000..792d600 --- /dev/null +++ b/src/BM1DProcess.cc~ @@ -0,0 +1 @@ +# diff --git a/src/Plotter.cc b/src/Plotter.cc new file mode 100644 index 0000000..b947b4e --- /dev/null +++ b/src/Plotter.cc @@ -0,0 +1,35 @@ +#include "Plotter.hh" + +Plotter::Plotter() +{ + ; +} +void Plotter::Plot(Int_t n, std::vector t, std::vector x){ + fOut = new TFile("result.root", "RECREATE"); + g1 = new TGraph(n,&t[0],&x[0]); + canv = new TCanvas("canc","display",800,400); + TTree *BM1DTree = new TTree("BM1DTree","BM1DTree"); + + 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"); + + BM1DTree->Branch("tl",&tl, "tl/D"); + BM1DTree->Branch("xl",&xl, "xl/D"); + for (unsigned int i = 0; i < t.size(); i++){ + tl = t[i]; + xl = x[i]; + BM1DTree->Fill(); + } + + g1->Write(); + BM1DTree->Write(); + fOut->Close(); + +} + diff --git a/src/Plotter.cc~ b/src/Plotter.cc~ new file mode 100644 index 0000000..e69de29 diff --git a/src/Progress.cc b/src/Progress.cc deleted file mode 100644 index 9f6fa55..0000000 --- a/src/Progress.cc +++ /dev/null @@ -1,92 +0,0 @@ -/// BM1D program. Date: 2017-10-29 Creators: Balázs Demeter, Balázs Ujvári, Dávid Baranyai - -#include "Progress.hh" - -Progress::Progress(Int_t nP) : -n (nP), p0(1), preVstate(0), steps(0) -{ - random1 = new TRandom(); -} - -Progress::Progress(Int_t nP, Double_t p0_Set) : -n (nP), p0(p0_Set), preVstate(0), steps(0) -{ - random1 = new TRandom(); -} - -Progress::Progress(Int_t nP, Double_t p0_Set, Double_t startposition) : -n (nP), p0(p0_Set), preVstate(startposition), steps(0) -{ - random1 = new TRandom(); -} - -Progress::~Progress() -{ - -} - -void Progress::Count(char a) -{ - for (Int_t i=0;iUniform(-p0,p0); - break; - - case 'g': - preVstate+=random1->Gaus(-p0,p0); - break; - - default: - std::cout<<"Invalid argument!"< Progress::GetX() -{ - return x; -} - -std::vector Progress::GetY() -{ - return y; -}