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

//_____________________________________________________________________
TMHistogrammingCErrorVsECperEq::TMHistogrammingCErrorVsECperEq(UInt_t eq) :
  TMHistogramming(), fEq(eq)
{
  TString title = Form("Consistency Errors vs Error Code (Eq %d)",fEq);
  fTheHisto = new TH1F(title.Data(), title.Data(), 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");
}
//_____________________________________________________________________
TMHistogrammingCErrorVsECperEq::~TMHistogrammingCErrorVsECperEq() {
  delete fTheHisto;
}
//_____________________________________________________________________
void TMHistogrammingCErrorVsECperEq::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->GetNrErrors(err,fEq));
    }
  }
  TMHistogramming::EndEvent(str, globalEventNumber);
}
//_____________________________________________________________________
void TMHistogrammingCErrorVsECperEq::Draw(TPad *pad) {
  pad->cd();
  pad->SetLeftMargin(0.15);
  pad->SetRightMargin(0.15);
  pad->SetBorderSize(0);
  pad->SetBorderMode(0);

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