// Author: Egon Pavlica <http://www.ses-ng.si/~pavlica/>
#include "LRandomWalk.h"
#include "nrutil.h"
#include "nr.h"
#include <time.h>
#include <stdlib.h>
#include <iostream>
//________________________________________
// Simulation of random walk
//
// an exaple of simulation is in file
// simple.cc
//
//
// Logs:
//
// $Log: LRandomWalk.cc,v $
// Revision 1.3 2003/06/26 11:24:25 cvs
// modified particle moving with LMiki and faster LDisorder operations
//
// Revision 1.2 2003/06/26 09:27:11 cvs
// added log fields...
//
ClassImp(LRandomWalk)
int Smer(){
//this is random direction selection with only three possible
//values (-1,0,1), which are all equivalently probable
static long seed=-time(NULL);
float rand=ran1(&seed);
if (rand>0.66666) return 1;
if (rand<0.33334) return -1;
return 0;
}
void LRandomWalk::RandomStep(){
//particle do a random step
MoveTo(Smer(),Smer(),Smer());
//if (fverbose) cout<<"Energy: "<<fspace[e->i][e->j][e->k]<<endl;
}
void LRandomWalk::Init(){
//get fe,fspace,fwspace and from LMiki class
if (!fe) fe=GetParticle();
if (!fspace) fspace=GetSpace();
}
void LRandomWalk::Walk(){
//do a random walk of the particle, correcting energies and
//calculating time with uncertainty principle.
float hplank=6e-34;
float oldenergy,newe,delta;
Init();
if (fverbose) std::cout<<"Random Walk simulationn";
while (fspace->IsInside(fe)) {
oldenergy=fe->GetEnergy();
RandomStep();
newe=fspace->GetEnergy(fe->i,fe->j,fe->k);
fe->SetEnergy(newe);
delta=fabs(oldenergy-newe);
if (delta!=0.0)
fe->time+=hplank/delta;
if (fverbose) std::cout<<fe->i<<","<<fe->j<<","<<fe->k<<std::endl;
if (fverbose) std::cout<<"Time: "<<fe->time<<"tEnergy: "<<newe<<std::endl;
}
if (fverbose) std::cout<<"Particle exited the space at "<<fe->i<<","<<fe->j<<","<<fe->k<<std::endl;
}
ROOT page - Class index - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.