#include "TMHistogrammingGlobalPixelZY.h"
#include "TMControlSPD.h"
#include "AliITSRawStreamSPD.h"
#include <TStyle.h>
#include <TPad.h>
#include <TH2F.h>
#include <TLine.h>

//_____________________________________________________________________
TMHistogrammingGlobalPixelZY::TMHistogrammingGlobalPixelZY(TLine *tla[960]) :
  TMHistogrammingShowDet()
{

  for (UInt_t mod=0; mod<960; mod++) {
    fDetLines[mod] = tla[mod];
  }

  fTheHisto = new TH2F("fGlobalZYHisto","Global Pixel ZY",500,-15,15,500,-9,9);
  //  fTheHisto->SetMarkerStyle(8);
  //  fTheHisto->SetMarkerSize(0.4);
  fTheHisto->SetMarkerColor(kBlue);
  fTheHisto->GetXaxis()->SetTitle("Z [cm]");
  fTheHisto->GetYaxis()->SetTitle("Y [cm]");
  fTheHisto->SetStats(0);
}
//_____________________________________________________________________
TMHistogrammingGlobalPixelZY::~TMHistogrammingGlobalPixelZY() {
  delete fTheHisto;
}
//_____________________________________________________________________
void TMHistogrammingGlobalPixelZY::ProcessPixel(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) {
  if (fEventAccept) {
    UInt_t mod, colM, rowM;
    AliITSRawStreamSPD::OnlineToOffline(eq,hs,chip,col,row,mod,colM,rowM);
    TMControlSPD::Instance()->TransformClusterToGlobal(mod,colM,rowM);  
    Float_t z = TMControlSPD::Instance()->GetGlobalZ();
    Float_t y = TMControlSPD::Instance()->GetGlobalY();
    fTheHisto->Fill(z,y);
  }
}
//_____________________________________________________________________
void TMHistogrammingGlobalPixelZY::Draw(TPad *pad) {
  pad->cd();
  pad->SetLeftMargin(0.15);
  pad->SetRightMargin(0.15);
  pad->SetBorderSize(0);
  pad->SetBorderMode(0);

  fTheHisto->Draw();

}
//_____________________________________________________________________
void TMHistogrammingGlobalPixelZY::Reset() {
  fTheHisto->Reset();
  TMHistogramming::Reset();
}
//_____________________________________________________________________
void TMHistogrammingGlobalPixelZY::DrawDetector(TPad *pad) {
  pad->cd();
  for (UInt_t mod=0; mod<960; mod++) {
    fDetLines[mod]->Draw();
  }
}
//_____________________________________________________________________
void TMHistogrammingGlobalPixelZY::HideDetector(TPad *pad) {
  pad->Clear();
  Draw(pad);
}

