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

//_____________________________________________________________________
TMHistogrammingFastorProblemEq::TMHistogrammingFastorProblemEq(UInt_t eq) :
  TMHistogramming(), fEq(eq)
{
  ResetHitChip();

  TString name = Form("FastorProblemEq%d",fEq);
  TString title = Form("Events with Chip Hits w/o FastOR Eq %d (Per Chip)",fEq);

  fTheHisto = new TH1F(name, title, 60, -0.5, 59.5);
  fTheHisto->SetMinimum(0);
  fTheHisto->SetStats(0);
  fTheHisto->SetFillColor(kBlue);
  fTheHisto->GetXaxis()->SetTitle("hs*10 + chip");
  fTheHisto->GetYaxis()->SetTitle("Number of Events");
  fTheHisto->SetTitleOffset(1.2,"X");
  fTheHisto->SetTitleOffset(1.6,"Y");
}
//_____________________________________________________________________
TMHistogrammingFastorProblemEq::~TMHistogrammingFastorProblemEq() {
  delete fTheHisto;
}
//_____________________________________________________________________
void TMHistogrammingFastorProblemEq::ResetHitChip() {
  for (UInt_t hs=0; hs<6; hs++) {
    for (UInt_t chip=0; chip<10; chip++) {
      fHitChip[hs][chip] = kFALSE;
    }
  }
}
//_____________________________________________________________________
void TMHistogrammingFastorProblemEq::ProcessPixel(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) {
  if (fEventAccept) {
    if (eq==fEq) {
      fHitChip[hs][chip]=kTRUE;
    }
  }
}
//_____________________________________________________________________
void TMHistogrammingFastorProblemEq::EndEvent(AliITSRawStreamSPD *str, UInt_t globalEventNumber) {
  if (fEventAccept) {
    for (UInt_t hs=0; hs<6; hs++) {
      for (UInt_t chip=0; chip<10; chip++) {
	if (fHitChip[hs][chip]) {
	  if (!str->GetFastOrSignal(fEq,hs,chip)) {
	    fTheHisto->Fill(hs*10+chip);
	  }
	}
      }
    }

    ResetHitChip();
  }

  TMHistogramming::EndEvent(str, globalEventNumber);
}
//_____________________________________________________________________
void TMHistogrammingFastorProblemEq::Draw(TPad *pad) {
  pad->cd();
  pad->SetLeftMargin(0.15);
  pad->SetRightMargin(0.15);
  pad->SetBorderSize(0);
  pad->SetBorderMode(0);

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

  TMHistogramming::Reset();
}


