#include "ParticleStatistic.h"
#include "Event.h"
#include "PtStatistic.h"
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

ParticleStatistic::ParticleStatistic() {
}


ParticleStatistic::~ParticleStatistic() {
}


// function to be called at execution start
void ParticleStatistic::beginJob() {
  ptStat.push_back( new PtStatistic( 0 ) );
  ptStat.push_back( new PtStatistic( 1 ) );
  return;
}


// function to be called at execution end
void ParticleStatistic::endJob() {
  int i;
  int n = ptStat.size();
  string type;
  for ( i = 0; i < n; ++i ) {
    PtStatistic* stat = ptStat[i];
    switch ( stat->particleType() ) {
    case 0:
      type = "hadrons";
      break;
    case 1:
      type = "muons";
      break;
    default:
      type = "other particles";
      break;
    }
    cout << "mean/rms pt for "
         << stat->nParticles() << " " << type << " : "
         << stat->ptMean() << " , "
         << stat->ptRMS () << endl;
  }
  return;
}


// function to be called for each event
void ParticleStatistic::process( const Event& ev ) {

  int i;
  int n = ptStat.size();
  string type;
  for ( i = 0; i < n; ++i ) ptStat[i]->add( ev );

  return;

}

