#include "TMHistogrammingGlobalPixelZDist.h"
#include "TMControlSPD.h"
#include "AliITSRawStreamSPD.h"
#include <TStyle.h>
#include <TPad.h>
#include <TH1F.h>
#include <TMath.h>

//_____________________________________________________________________
TMHistogrammingGlobalPixelZDist::TMHistogrammingGlobalPixelZDist() :
  TMHistogramming()
{ 

  fTotal = new TH1F("GlobalPixelZDistTotal","Global Z Distribution (red=outer, blue=inner layer)",150,-15,15);
  fTotal->SetLineColor(kBlack);
  fTotal->GetXaxis()->SetTitle("Z [cm]");
  fTotal->SetStats(0);

  fInner = new TH1F("GlobalPixelZDistInner","Global Z Distribution (red=outer, blue=inner layer)",150,-15,15);
  fInner->SetLineColor(kBlue);
  fInner->GetXaxis()->SetTitle("Z [cm]");
  fInner->SetStats(0);

  fOuter = new TH1F("GlobalPixelZDistOuter","Global Z Distribution (red=outer, blue=inner layer)",150,-15,15);
  fOuter->SetLineColor(kRed);
  fOuter->GetXaxis()->SetTitle("Z [cm]");
  fOuter->SetStats(0);
}
//_____________________________________________________________________
TMHistogrammingGlobalPixelZDist::~TMHistogrammingGlobalPixelZDist() {
  delete fInner;
  delete fOuter;
}
//_____________________________________________________________________
void TMHistogrammingGlobalPixelZDist::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();
    fTotal->Fill(z);
    if (hs<2) fInner->Fill(z);
    else      fOuter->Fill(z);
  }
}
//_____________________________________________________________________
void TMHistogrammingGlobalPixelZDist::Draw(TPad *pad) {
  pad->cd();
  pad->SetLeftMargin(0.15);
  pad->SetRightMargin(0.15);
  pad->SetBorderSize(0);
  pad->SetBorderMode(0);

  fTotal->Draw();
  fInner->Draw("same");
  fOuter->Draw("same");
}
//_____________________________________________________________________
void TMHistogrammingGlobalPixelZDist::Reset() {
  fTotal->Reset();
  fInner->Reset();
  fOuter->Reset();
  TMHistogramming::Reset();
}


