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

//_____________________________________________________________________
TMHistogrammingHitsPerEventAll::TMHistogrammingHitsPerEventAll() :
  TMHistogramming(), fTotalNumberOfHits(0)
{ 
  
  TString histoName = Form("HitsPerEventAll");
  TString histoTitle = Form("Hits Per Event (Per Eq)");

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

  fTheHisto->Draw();
}
//_____________________________________________________________________
void TMHistogrammingHitsPerEventAll::Reset() {
  fTheHisto->Reset();
  fTotalNumberOfHits = 0;
  for (UInt_t eq=0; eq<20; eq++) {
    fTotalNumberOfHitsEq[eq] = 0;
  }
  TMHistogramming::Reset();
}


