#include "TMHistogrammingClusterWidthPhi.h"
#include "HenrikClusterFinderSPD.h"
#include <TPad.h>
#include <TH1F.h>

//_____________________________________________________________________
TMHistogrammingClusterWidthPhi::TMHistogrammingClusterWidthPhi() :
  TMHistogramming()
{

  fHistTotal = new TH1F("ClusterWidthPhi","Cluster Width Phi (black=all, red=outer, blue=inner layer)",
			256,0.5,256+0.5);
  fHistTotal->SetXTitle("Cluster Width Phi [N Pixels]");
  fHistTotal->SetStats(0);
  fHistTotal->SetLineColor(kBlack);
  fHistTotal->SetBit(TH1::kCanRebin);

  fHistInner = new TH1F("ClusterWidthPhiInn","Cluster Width Phi (black=all, red=outer, blue=inner layer)",
		       256,0.5,256+0.5);
  fHistInner->SetXTitle("Cluster Width Phi [N Pixels]");
  fHistInner->SetStats(0);
  fHistInner->SetLineColor(kBlue);
  fHistInner->SetBit(TH1::kCanRebin);

  fHistOuter = new TH1F("ClusterWidthPhiOut","Cluster Width Phi (black=all, red=outer, blue=inner layer)",
		       256,0.5,256+0.5);
  fHistOuter->SetXTitle("Cluster Width Phi [N Pixels]");
  fHistOuter->SetStats(0);
  fHistOuter->SetLineColor(kRed);
  fHistOuter->SetBit(TH1::kCanRebin);
}
//_____________________________________________________________________
TMHistogrammingClusterWidthPhi::~TMHistogrammingClusterWidthPhi() {
  delete fHistTotal;
  delete fHistInner;
  delete fHistOuter;
}
//_____________________________________________________________________
void TMHistogrammingClusterWidthPhi::ProcessClusters(HenrikClusterFinderSPD* clFinder) {
  if (fEventAccept) {
    for (UInt_t mod=0; mod<240; mod++) {
      for (UInt_t cl = 0; cl<clFinder->GetClusterCount(mod); cl++) {
	UInt_t width = clFinder->GetClusterWidthPhi(mod,cl);
	fHistTotal->Fill(width);
	if (mod<80) {
	  fHistInner->Fill(width);
	}
	else {
	  fHistOuter->Fill(width);
	}
      }
    }
  }
}
//_____________________________________________________________________
void TMHistogrammingClusterWidthPhi::Draw(TPad *pad) {
  pad->cd();
  pad->SetLeftMargin(0.15);
  pad->SetRightMargin(0.15);
  pad->SetBorderSize(0);
  pad->SetBorderMode(0);

  fHistTotal->Draw();
  fHistInner->Draw("same");
  fHistOuter->Draw("same");
}
//_____________________________________________________________________
void TMHistogrammingClusterWidthPhi::Reset() {
  
  fHistTotal->Reset();
  fHistInner->Reset();
  fHistOuter->Reset();

  TMHistogramming::Reset();
}
