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

//_____________________________________________________________________
TMHistogrammingGlobalPixelXY::TMHistogrammingGlobalPixelXY(TLine *tla[240]) :
  TMHistogrammingShowDet()
{ 
  for (UInt_t mod=0; mod<240; mod++) {
    fDetLines[mod] = tla[mod];
  }

  fTheHisto = new TH2F("fGlobalXYHisto","Global Pixel XY",500,-9,9,500,-9,9);
  //  fTheHisto->SetMarkerStyle(8);
  //  fTheHisto->SetMarkerSize(0.4);
  fTheHisto->SetMarkerColor(kBlue);
  fTheHisto->GetXaxis()->SetTitle("X [cm]");
  fTheHisto->GetYaxis()->SetTitle("Y [cm]");
  fTheHisto->SetStats(0);
}
//_____________________________________________________________________
TMHistogrammingGlobalPixelXY::~TMHistogrammingGlobalPixelXY() {
  delete fTheHisto;
}
//_____________________________________________________________________
void TMHistogrammingGlobalPixelXY::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 x = TMControlSPD::Instance()->GetGlobalX();
    Float_t y = TMControlSPD::Instance()->GetGlobalY();
    fTheHisto->Fill(x,y);
  }
}
//_____________________________________________________________________
void TMHistogrammingGlobalPixelXY::Draw(TPad *pad) {
  pad->cd();
  pad->SetLeftMargin(0.15);
  pad->SetRightMargin(0.15);
  pad->SetBorderSize(0);
  pad->SetBorderMode(0);

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