#include <iostream>
#include <fstream>
#include <string>

#include "PtStatistic.h"
#include "Event.h"

using namespace std;

const Event* read( ifstream& file );
void dump( const Event& ev );

int main( int argc, char* argv[] ) {

  // open input file
  const string name = argv[1];
  ifstream file( name.c_str(), ios::binary );

  // objects to compute pt mean and rms
  PtStatistic h_stat( 0 );
  PtStatistic m_stat( 1 );

  // loop over events
  const Event* ev;
  while ( ( ev = read( file ) ) != 0 ) {
//    dump( *ev );
    h_stat.add( *ev );
    m_stat.add( *ev );
    delete ev;
  }

  // compute results
  h_stat.compute();
  m_stat.compute();

  // print results
  cout << "mean/rms pt for "
       << h_stat.nParticles() << " hadrons: "
       << h_stat.ptMean() << " "
       << h_stat.ptRMS () << endl;
  cout << "mean/rms pt for "
       << m_stat.nParticles() << " muons:   "
       << m_stat.ptMean() << " "
       << m_stat.ptRMS()  << endl;

  return 0;

}

