#include "StHbtMaker/Cut/nikEventCut.h"
#include <TMath.h>
#include <sstream>

#ifdef __ROOT__
ClassImp(nikEventCut)
#endif

//_________________
nikEventCut::nikEventCut() {
  mRefMult[0] = -1;
  mRefMult[1] = +1000000;
  
  mImpPar[0] = 0.;
  mImpPar[1] = 666.;

  mNEventsPassed = 0;
  mNEventsFailed = 0;
}

//_________________
nikEventCut::nikEventCut(const nikEventCut& c) : StHbtEventCut(c) {

  mRefMult[0] = c.mRefMult[0];
  mRefMult[1] = c.mRefMult[1];

  mImpPar[0] = c.mImpPar[0];
  mImpPar[1] = c.mImpPar[1];

  mNEventsPassed = 0;
  mNEventsFailed = 0;
}

//____________
nikEventCut::~nikEventCut() {

#ifdef STHBTDEBUG
  std::cout << "Event cut destructor" << std::endl;
#endif

#ifdef STHBTDEBUG
  std::cout << "Event cut is killed" << std::endl;
#endif
}

//_________________
bool nikEventCut::Pass(const StHbtEvent* event) {
#ifdef STHBTDEBUG
  std::cout << "nikEventCut::Pass" << std::endl;
#endif

  int   mult = event->RefMult();
  //float 
  
#ifdef STHBTDEBUG
  std::cout << "RefMult: " << mult << std::endl;
#endif

  bool mGoodRefMult = mult >= mRefMult[0] && mult <= mRefMult[1];
  //bool mGoodImpPar  = 
  bool mGoodEvent   = mGoodRefMult;
  
  mGoodEvent ? mNEventsPassed++ : mNEventsFailed++;
  
  return mGoodEvent;
}


//_________________
string nikEventCut::Report() {

  stringstream rep_stream;
  rep_stream << mRefMult[0] << " <= Multiplicity <= " << mRefMult[1] 
	     << std::endl;

  return rep_stream.str();
}


//_________________
nikEventCut* nikEventCut::Clone() { 
  nikEventCut *c = new nikEventCut(*this);
  return c;
}


//_________________
void nikEventCut::SetEventMult(int lo, int hi) {
  mRefMult[0] = lo;
  mRefMult[1] = hi;
}


//_________________
void nikEventCut::SetImpactPar(float lo, float hi) {
  mImpPar[0] = lo;
  mImpPar[1] = hi;
}


//_________________
int nikEventCut::NEventsPassed() {
  return mNEventsPassed;
}


//_________________
int nikEventCut::NEventsFailed() {
  return mNEventsFailed;
}
