#include "EventDiscriminator.h"
#include "DiscAnalysis.h"
#include <iostream>
#include <math.h>

#include "TH1F.h"
#include "TFile.h"

#include <string>

using namespace std;

DiscAnalysis::DiscAnalysis() {
}


DiscAnalysis::~DiscAnalysis() {
}


void DiscAnalysis::init( const std::string& name ) {
  disc = new EventDiscriminator;
  disc->read( name );
  h_disc = new TH1F( "h_disc", "h_disc", 20, 0.0, 1.0 );
}


void DiscAnalysis::analyze( const Event& ev ) {
  h_disc->Fill( disc->get( ev ) );
  return;
}


void DiscAnalysis::save( const std::string& name ) {
  TDirectory* currentDir = gDirectory;
  TFile* file = new TFile( name.c_str(), "CREATE" );
  h_disc->Write();
  file->Close();
  delete file;
  currentDir->cd();
  return;
}

