#include "TMHistogrammingCErrorVsEC.h"
#include "AliITSRawStreamSPD.h"
#include <TStyle.h>
#include <TPad.h>
#include <TH1F.h>

//_____________________________________________________________________
TMHistogrammingCErrorVsEC::TMHistogrammingCErrorVsEC() :
  TMHistogramming()
{
  fTheHisto = new TH1F("Consistency_Errors_Vs_EC", "Consistency Errors vs Error Code", AliITSRawStreamSPDErrorLog::kNrErrorCodes-1, 0.5, AliITSRawStreamSPDErrorLog::kNrErrorCodes-0.5);
  fTheHisto->SetMinimum(0);
  fTheHisto->SetStats(0);
  fTheHisto->SetFillColor(kRed);
  fTheHisto->GetXaxis()->SetTitle("Error Code");
  fTheHisto->GetYaxis()->SetTitle("Number of Errors");
  fTheHisto->SetTitleOffset(1.2,"X");
  fTheHisto->SetTitleOffset(1.6,"Y");
}
//_____________________________________________________________________
TMHistogrammingCErrorVsEC::~TMHistogrammingCErrorVsEC() {
  delete fTheHisto;
}
//_____________________________________________________________________
void TMHistogrammingCErrorVsEC::EndEvent(AliITSRawStreamSPD *str, UInt_t globalEventNumber) {
  if (fEventAccept) {
    AliITSRawStreamSPDErrorLog *advLogger = str->GetAdvancedErrorLog();
    for (UInt_t err=1; err<AliITSRawStreamSPDErrorLog::kNrErrorCodes; err++) {
      fTheHisto->Fill(err, advLogger->GetNrErrorsAllEq(err));
    }
  }
  TMHistogramming::EndEvent(str, globalEventNumber);
}
//_____________________________________________________________________
void TMHistogrammingCErrorVsEC::Draw(TPad *pad) {
  pad->cd();
  pad->SetLeftMargin(0.15);
  pad->SetRightMargin(0.15);
  pad->SetBorderSize(0);
  pad->SetBorderMode(0);

  fTheHisto->Draw();
}
//_____________________________________________________________________
void TMHistogrammingCErrorVsEC::Reset() {
  fTheHisto->Reset();
  TMHistogramming::Reset();
}
