diff --git a/include/BM1DProcess.hh b/include/BM1DProcess.hh index ba91c09..6b52b96 100644 --- a/include/BM1DProcess.hh +++ b/include/BM1DProcess.hh @@ -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 GetT(){return t;} std::vector GetX(){return x;} private: - Int_t nSteps; - Double_t p0,p1,p2,p3,p4; TRandom* randomGenerator; + TRandom* randomGeneratorGauss; Double_t rand1; std::vector t; std::vector x; diff --git a/src/BM1DProcess.cc b/src/BM1DProcess.cc index 364a117..7a907c4 100644 --- a/src/BM1DProcess.cc +++ b/src/BM1DProcess.cc @@ -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 + } + } + } +} \ No newline at end of file