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

//_____________________________________________________________________
TMHistogrammingCErrorVsEq::TMHistogrammingCErrorVsEq() :
  TMHistogramming()
{
  fTheHisto = new TH1F("Consistency_Errors_Per_Eq", "Consistency Errors Per Eq", 20, -0.5, 19.5);
  fTheHisto->SetMinimum(0);
  fTheHisto->SetStats(0);
  fTheHisto->SetFillColor(kRed);
  fTheHisto->GetXaxis()->SetTitle("Eq ID");
  fTheHisto->GetYaxis()->SetTitle("Number of Errors");
  fTheHisto->SetTitleOffset(1.2,"X");
  fTheHisto->SetTitleOffset(1.6,"Y");
}
//_____________________________________________________________________
TMHistogrammingCErrorVsEq::~TMHistogrammingCErrorVsEq() {
  delete fTheHisto;
}
//_____________________________________________________________________
void TMHistogrammingCErrorVsEq::EndEvent(AliITSRawStreamSPD *str, UInt_t globalEventNumber) {
  if (fEventAccept) {
    AliITSRawStreamSPDErrorLog *advLogger = str->GetAdvancedErrorLog();
    for (UInt_t eq=0; eq<20; eq++) {
      fTheHisto->Fill(eq, advLogger->GetNrErrors(0,eq));
    }
  }
  TMHistogramming::EndEvent(str, globalEventNumber);
}
//_____________________________________________________________________
void TMHistogrammingCErrorVsEq::Draw(TPad *pad) {
  pad->cd();
  pad->SetLeftMargin(0.15);
  pad->SetRightMargin(0.15);
  pad->SetBorderSize(0);
  pad->SetBorderMode(0);

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