#include "StHbtMaker/Infrastructure/StHbtEvent.hh"
#include "StHbtMaker/Infrastructure/StHbtTypes.hh"
#include "StHbtMaker/Cut/fxtEventCutMonitor.h"
#include <cstdio>
#include <cmath>

#ifdef __ROOT__ 
ClassImp(fxtEventCutMonitor)
#endif

//_________________
fxtEventCutMonitor::fxtEventCutMonitor(){
  mVertexYvsVertexX = new StHbt2FHisto("VertexYvsVertexX",
				       "VertexYvsVertexX;x (cm);y (cm)", 
				       300, -6.,6., 300, -6.,6.);
  mVertexZ = new StHbt1FHisto("VertexZ", "VertexZ; z (cm)",
			      320, -80., 80.);
  mRefMult = new StHbt1FHisto("RefMult", "RefMult;RefMult",
			      600, -0.5, 599.5);
  mVpdVzDiff = new StHbt1FHisto("VpdVzDiff", "mVpdVzDiff",
				40, -20., 20.);
}

//_________________
fxtEventCutMonitor::fxtEventCutMonitor(const char* title1, const char* title2){
  char tit1[100];

  sprintf(tit1,"%s%s_VertexYvsVertexX",title1,title2);
  mVertexYvsVertexX = new StHbt2FHisto(tit1, "VertexYvsVertexX;x (cm);y (cm)", 
				       300, -6.,6., 300, -6.,6.);

  sprintf(tit1,"%s%s_VertexZ",title1,title2);
  mVertexZ = new StHbt1FHisto(tit1, "VertexZ;z (cm)", 
			      320, -80., 80.);

  sprintf(tit1,"%s%s_RefMult",title1,title2);
  mRefMult = new StHbt1FHisto(tit1, "RefMult;RefMult", 600, 0., 600.);

  sprintf(tit1,"%s%s_VpdVzDiff",title1,title2);
  mVpdVzDiff = new StHbt1FHisto(tit1, "VpdVzDiff", 40, -20., 20.);
}

//_________________
fxtEventCutMonitor::~fxtEventCutMonitor(){
//  delete mScaler;
  delete mVertexYvsVertexX;
  delete mVertexZ;
  delete mRefMult;
  delete mVpdVzDiff;
}

//_________________
void fxtEventCutMonitor::Fill(const StHbtEvent* event){

  mVertexYvsVertexX->Fill( event->PrimVertPos().x(), event->PrimVertPos().y(), 1.);
  mVertexZ->Fill( event->PrimVertPos().z(), 1.);
  mRefMult->Fill( event->UncorrectedNumberOfPrimaries(), 1.);
  mVpdVzDiff->Fill( (event->PrimVertPos().z() - event->VpdVz()), 1.);
}

//_________________
void fxtEventCutMonitor::Finish(){
  std::cout << " entries in histogram mVertexYvsVertexX : "
	    << mVertexYvsVertexX->Integral() << std::endl;
  std::cout << " entries in histogram mVertexZ : "
	    << mVertexZ->Integral() << std::endl;
  std::cout << " entries in histogram mRefMult : "
	    << mRefMult->Integral() << std::endl;
  std::cout << " entries in histogram mVpdVzDiff : "
	    << mVpdVzDiff->Integral() << std::endl;
}

//_________________
StHbtString fxtEventCutMonitor::Report(){
  string Stemp;
  char Ctemp[100];
  sprintf(Ctemp," fxtEventCutMonitor");
  Stemp=Ctemp;
  StHbtString returnThis = Stemp;
  return returnThis;
}


