#include "TMHistogrammingHitsPerEventEq.h"
#include <TStyle.h>
#include <TPad.h>
#include <TH1F.h>

//_____________________________________________________________________
TMHistogrammingHitsPerEventEq::TMHistogrammingHitsPerEventEq(UInt_t eq) :
  TMHistogramming(), fEq(eq)
{ 
  for (UInt_t hs=0; hs<6; hs++) {
    for (UInt_t chip=0; chip<10; chip++) {
      fTotalNumberOfHitsChip[hs][chip] = 0;
    }
  }

  TString histoName = Form("HitsPerEventEq%d",eq);
  TString histoTitle = Form("Hits Per Event (Per Chip)  Eq %d",eq);

  fTheHisto = new TH1F(histoName.Data(), histoTitle.Data(), 60, -0.5, 59.5);
  fTheHisto->SetMinimum(0);
  fTheHisto->SetStats(0);
  fTheHisto->SetFillColor(kBlue);
  fTheHisto->GetXaxis()->SetTitle("hs*10 + chip");
  fTheHisto->GetYaxis()->SetTitle("Hits Per Event");
  fTheHisto->SetTitleOffset(1.2,"X");
  fTheHisto->SetTitleOffset(1.6,"Y");
}
//_____________________________________________________________________
TMHistogrammingHitsPerEventEq::~TMHistogrammingHitsPerEventEq() {
  delete fTheHisto;
}
//_____________________________________________________________________
void TMHistogrammingHitsPerEventEq::ProcessPixel(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) {
  if (fEventAccept) {
    if (eq==fEq) {
      fTotalNumberOfHitsChip[hs][chip]++;
      fTheHisto->SetBinContent(hs*10+chip+1,((Float_t) fTotalNumberOfHitsChip[hs][chip])/(fNrEvents+1));
    }
  }
}
//_____________________________________________________________________
void TMHistogrammingHitsPerEventEq::Draw(TPad *pad) {
  pad->cd();
  pad->SetLeftMargin(0.15);
  pad->SetRightMargin(0.15);
  pad->SetBorderSize(0);
  pad->SetBorderMode(0);

  fTheHisto->Draw();
}
//_____________________________________________________________________
void TMHistogrammingHitsPerEventEq::Reset() {
  fTheHisto->Reset();
  for (UInt_t hs=0; hs<6; hs++) {
    for (UInt_t chip=0; chip<10; chip++) {
      fTotalNumberOfHitsChip[hs][chip] = 0;
    }
  }
  TMHistogramming::Reset();
}


