#include <iostream>
#include <fstream>

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

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

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

  // open input file
  const char* name = argv[1];
  std::ifstream file( name, std::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
  std::cout << "mean/rms pt for "
            << h_stat.nParticles() << " hadrons: "
            << h_stat.ptMean() << " "
            << h_stat.ptRMS () << std::endl;
  std::cout << "mean/rms pt for "
            << m_stat.nParticles() << " muons:   "
            << m_stat.ptMean() << " "
            << m_stat.ptRMS() << std::endl;

  return 0;

}

