Version 1.2 - Upload to repo

This commit is contained in:
dbalazs92 2017-10-29 12:17:15 +01:00
parent 09f5881738
commit 292e1a2b9b
5 changed files with 245 additions and 0 deletions

81
BM1D.cc Normal file
View File

@ -0,0 +1,81 @@
/// BM1D program. Date: 2017-10-29 Creators: Balázs Demeter, Balázs Ujvári
#include <iostream>
#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<Double_t> x1 = Pr1->GetX();
vector<Double_t> y1 = Pr1->GetY();
vector<Double_t> x2 = Pr2->GetX();
vector<Double_t> 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;
}

40
CMakeLists.txt Normal file
View File

@ -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)

45
include/Progress.hh Normal file
View File

@ -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 <iostream>
#include <string>
#include <fstream>
#include <cmath>
#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<Double_t> GetX();
std::vector<Double_t> GetY();
private:
TRandom* random1;
const Int_t n;
std::vector<Double_t> x;
std::vector<Double_t> y;
};
#endif

12
setup.sh Executable file
View File

@ -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.

67
src/Progress.cc Normal file
View File

@ -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;i<n;i++)
{
if(i==0)
{
x.push_back(0.0);
y.push_back(0.0);
}
y.push_back((Double_t)i);
switch(a)
{
case 'u':
if(random1->Uniform()>=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!"<<std::endl;
break;
}
}
}
std::vector<Double_t> Progress::GetX()
{
return x;
}
std::vector<Double_t> Progress::GetY()
{
return y;
}