From 292e1a2b9b3c51a1450ffb4dd272934d4cb5282a Mon Sep 17 00:00:00 2001 From: dbalazs92 Date: Sun, 29 Oct 2017 12:17:15 +0100 Subject: [PATCH] Version 1.2 - Upload to repo --- BM1D.cc | 81 +++++++++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 40 ++++++++++++++++++++++ include/Progress.hh | 45 +++++++++++++++++++++++++ setup.sh | 12 +++++++ src/Progress.cc | 67 +++++++++++++++++++++++++++++++++++++ 5 files changed, 245 insertions(+) create mode 100644 BM1D.cc create mode 100644 CMakeLists.txt create mode 100644 include/Progress.hh create mode 100755 setup.sh create mode 100644 src/Progress.cc diff --git a/BM1D.cc b/BM1D.cc new file mode 100644 index 0000000..e781074 --- /dev/null +++ b/BM1D.cc @@ -0,0 +1,81 @@ +/// BM1D program. Date: 2017-10-29 Creators: Balázs Demeter, Balázs Ujvári + +#include +#include "Progress.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; + + TApplication App("tapp", &argc, argv); + TCanvas* Canv = new TCanvas("c10","Live display",800,400); + + if(argc==2) + { + OpenRootFile(); + } + else + { + + Progress* Pr1 = new Progress(n); + Progress* Pr2 = new Progress(n); + + 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; + +} diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ad3ae93 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,40 @@ +# $Id: CMakeLists.txt 12345 2017-10-26 10:11:23 Demeter Balázs $ + +#---------------------------------------------------------------------------- +# Setup the project +cmake_minimum_required(VERSION 2.6 FATAL_ERROR) +project(BM1D) + +list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS}) + +#---------------------------------------------------------------------------- +# Find ROOT (required package) +# +find_package(ROOT REQUIRED) + +#---------------------------------------------------------------------------- +# Setup ROOT include directories and compile definitions +# +include(${ROOT_USE_FILE}) + +# Setup include directory for this project +# +include_directories(${PROJECT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIRS}) + +#---------------------------------------------------------------------------- +# Locate sources and headers for this project +# NB: headers are included so they will show up in IDEs +# +file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc) +file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh) + +#---------------------------------------------------------------------------- +# Add the executable +# +add_executable(BM1D BM1D.cc ${sources} ${headers}) +target_link_libraries(BM1D ${ROOT_LIBRARIES} ) + +#---------------------------------------------------------------------------- +# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX +# +install(TARGETS BM1D DESTINATION bin) diff --git a/include/Progress.hh b/include/Progress.hh new file mode 100644 index 0000000..512f0f9 --- /dev/null +++ b/include/Progress.hh @@ -0,0 +1,45 @@ +/// BM1D program. Date: 2017-10-29 Creators: Balázs Demeter, Balázs Ujvári + +#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(); + + void Count(char a); + + std::vector GetX(); + std::vector GetY(); + +private: + + TRandom* random1; + const Int_t n; + std::vector x; + std::vector y; + +}; + +#endif + + diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..ee2b421 --- /dev/null +++ b/setup.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# +# Author: Balázs Demeter (balazsdemeter92@gmail.com) +# Version: 1.0 +# +# Script for build and make Brownian movement in one dimension + +mkdir bm1d_build +cd bm1d_build +cmake ../ +make +echo Setup complete. diff --git a/src/Progress.cc b/src/Progress.cc new file mode 100644 index 0000000..f4f24e4 --- /dev/null +++ b/src/Progress.cc @@ -0,0 +1,67 @@ +/// BM1D program. Date: 2017-10-29 Creators: Balázs Demeter, Balázs Ujvári + +#include "Progress.hh" + +Progress::Progress(Int_t nP) : +n (nP) +{ + random1 = new TRandom(); +} + +Progress::~Progress() +{ + +} + +void Progress::Count(char a) +{ + for (Int_t i=0;iUniform()>=0.5) + { + x.push_back(x[i-1]-0.1); + } + else + { + x.push_back(x[i-1]+0.1); + } + break; + + case 'g': + if(random1->Gaus()>=0.5) + { + x.push_back(x[i-1]-0.1); + } + else + { + x.push_back(x[i-1]+0.1); + } + break; + + default: + std::cout<<"Invalid argument!"< Progress::GetX() +{ + return x; +} + +std::vector Progress::GetY() +{ + return y; +}