#include "track.hh"

#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;


// extrapolate a state to a new x position (=detector plane)
state extrapolate(state st, float x)
{
  state result;
  
  result.x = x;
  result.y = st.y + tan(M_PI / 180. * st.theta) * (x-st.x);
  result.theta = st.theta;

  return result;
}


// scatter particle with probablity 50% by +/- 2 deg
void scatter(state *st)
{
    if (random() > pow(2., 31.)/2. ) {
      st->theta += unirandom(-2., 2.);
    }
}


// function to calculate a uniformly distributed random number 
// between min and max
double unirandom(float min, float max)
{
  return min + (max-min)*random() / (pow(2., 31.)-1.);
}