#include "EventSim.h"

#include "Event.h"

#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <math.h>

using namespace std;

// simulate data with random seed
EventSim::EventSim( unsigned int n, unsigned int s ):
 evId( 0 ),
 nMax( n ) {
  srandom( s );
}


EventSim::~EventSim() {
}


// get an event
const Event* EventSim::get() {
  if ( evId < nMax ) return generate();
  return 0;
}


// generate an event
const Event* EventSim::generate() {

  // create a new event
  Event* ev = new Event( ++evId );

  // simulate 3 particles
  int n = 3;

  // simulate and store data for particles
  int j;
  float pt;
  float eta;
  float phi;
  int charge;
  int muonId;
  for ( j = 0; j < n; ++j ) {
    pt     =   ( random() * 100.0      / RAND_MAX ) + 1.0;
    eta    =   ( random() * 5.0        / RAND_MAX ) - 2.5;
    phi    =   ( random() * 2.0 * M_PI / RAND_MAX ) - M_PI;
    charge = ( ( random() * 1.0        / RAND_MAX ) > 0.5 ? +1 : -1 );
    muonId = ( ( random() * 1.0        / RAND_MAX ) > 0.8 ? +1 :  0 );
    ev->add( pt, eta, phi, charge, muonId );
  }

  return ev;

}

