Run for uniform,gauss,layer

This commit is contained in:
Korcsmaros Berta 2017-10-31 12:29:46 +01:00
parent fb42b93a5f
commit a3ac1c6d3d
2 changed files with 105 additions and 35 deletions

View File

@ -10,22 +10,19 @@
class BM1DProcess {
public:
BM1DProcess(Int_t n); //n is the number of steps
BM1DProcess();
~BM1DProcess();
void SetP0(Double_t p0_new){p0 = p0_new;}
void SetP1(Double_t p1_new){p1 = p1_new;}
void Init();
void Run();
void Run(int nSteps, int nRuns, double p0, double p1);
void Run(int nSteps, int nRuns, double p0, double mu, double sigma);
void Run(int nSteps, int nRuns, double p0, double x1, double x2, double mu1, double sigma1, double mu2, double sigma2);
std::vector<Double_t> GetT(){return t;}
std::vector<Double_t> GetX(){return x;}
private:
Int_t nSteps;
Double_t p0,p1,p2,p3,p4;
TRandom* randomGenerator;
TRandom* randomGeneratorGauss;
Double_t rand1;
std::vector<Double_t> t;
std::vector<Double_t> x;

View File

@ -1,40 +1,113 @@
#include "BM1DProcess.hh"
BM1DProcess::BM1DProcess(Int_t nP) :
nSteps (nP), p0(0.5), p1(0.3)
BM1DProcess::BM1DProcess()
{
randomGenerator = new TRandom();
randomGeneratorGauss = new TRandom();
}
BM1DProcess::~BM1DProcess()
{
;
delete randomGenerator;
delete randomGeneratorGauss;
}
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(int nRuns, int nSteps, double p0, double p1)
{
for(int i = 0; i < nRuns; i++) //multiple runs
{
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);
for(int ii = 0; ii < nSteps ; ii++)
{
rand1 = randomGenerator->Uniform();
if(rand1 < p0) //step in time, but no step in x
{
t.push_back(t.back() + 1);
x.push_back(x.back());
}
else //step left or right
{
if(rand1 < p0 + p1)
{
t.push_back(t.back()+1);
x.push_back(x.back()+1); //one step right
}
else
{
t.push_back(t.back() + 1);
x.push_back(x.back() - 1); //one step left
}
}
}
}
}
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
}
}
}
void BM1DProcess::Run(int nRuns, int nSteps, double p0, double mu, double sigma)
{
for(int i = 0; i < nRuns; i++) //multiple runs
{
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);
for(int ii = 0; ii < nSteps ; ii++)
{
rand1 = randomGenerator->Uniform();
if(rand1 < p0) //step in time, but no step in x
{
t.push_back(t.back() + 1);
x.push_back(x.back());
}
else //step left or right
{
double randGauss = randomGeneratorGauss -> Gaus(mu,sigma);
t.push_back(t.back() + 1);
x.push_back(x.back() + randGauss); //one step right
}
}
}
}
void BM1DProcess::Run(int nRuns, int nSteps, double p0, double x1, double x2, double mu1, double sigma1, double mu2, double sigma2)
{
for(int i = 0; i < nRuns; i++) //multiple runs
{
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);
double randGauss;
for(int ii = 0; ii < nSteps ; ii++)
{
rand1 = randomGenerator->Uniform();
if(rand1 < p0) //step in time, but no step in x
{
t.push_back(t.back() + 1);
x.push_back(x.back());
}
else //step left or right
{
if(x.back() < x2 && x.back() > x1)
{
randGauss = randomGeneratorGauss -> Gaus(mu1,sigma1);
}
else
{
randGauss = randomGeneratorGauss -> Gaus(mu2,sigma2);
}
t.push_back(t.back() + 1);
x.push_back(x.back() + randGauss); //one step right
}
}
}
}