#include "StHbtMaker/Infrastructure/StHbtPair.hh"
#include "StHbtMaker/Cut/fxtPairCutMonitor.h"
#include <cstdio>
#include <string>
#include "StLorentzVector.hh"

#ifdef __ROOT__ 
ClassImp(fxtPairCutMonitor)
#endif

//_________________
fxtPairCutMonitor::fxtPairCutMonitor(const char* name){ // default constructor
  string s("fxtPairCutMonitor");
  string n(name);
  mKt = new StHbt1FHisto( (s+n+"mKt").c_str(),"Kt;k_{T} (GeV/c)",
			  150,0.,1.5);
  mPt1Pt2Qinv = new StHbt3FHisto( (s+n+"mPt1Pt2Qinv").c_str(),
				  "p_{T1} vs p_{T2} vs q_{inv};p_{T1} (GeV/c);p_{T2} (GeV/c);q_{inv} (GeV/c)",
				  32,0.,1.6,32,0.,1.6,400,0.,0.8);
			     
  mFMRvsQinv = new StHbt2FHisto( (s+n+"mFMRvsQinv").c_str(),
				 "FMR vs q_{inv};q_{Inv} (GeV/c);FMR",
				 200, 0., 0.8,
				 100, 0., 1.); 
  mSLvsQinv = new StHbt2FHisto( (s+n+"mSLvsQinv").c_str(),
				"SL vs q_{inv};q_{inv} (GeV/c);SL",
				200, 0., 0.8,
				32,-0.6, 1.); 
  mAveSepVsQinv = new StHbt2FHisto( (s+n+"mAveSepVsQinv").c_str(),
				    "AveSep vs q_{inv};q_{inv} (GeV/c); AveSep (cm)",
				    200, 0., 0.8, 100, 0., 50.);
  mRValueVsQinv = new StHbt2FHisto( (s+n+"mRValueVsQinv").c_str(),
				    "R=#sqrt{#\Delta#eta+#Delta#phi} vs q_{inv};q_{inv} (GeV/c);R",
				    200, 0., 0.8, 200, 0., 2.);

  mPartMass = 0.493677; //Kaon mass by default
}

//_________________
fxtPairCutMonitor::fxtPairCutMonitor( const  fxtPairCutMonitor& cutMoni)  {
  mKt = new StHbt1FHisto(*(cutMoni.mKt));
  mPt1Pt2Qinv = new StHbt3FHisto(*(cutMoni.mPt1Pt2Qinv));
  mFMRvsQinv =new StHbt2FHisto(*(cutMoni.mFMRvsQinv));
  mSLvsQinv =new StHbt2FHisto(*(cutMoni.mSLvsQinv));
  mAveSepVsQinv = new StHbt2FHisto(*(cutMoni.mAveSepVsQinv));
  mRValueVsQinv = new StHbt2FHisto(*(cutMoni.mRValueVsQinv));
  mPartMass = cutMoni.mPartMass;
}

//_________________
fxtPairCutMonitor::~fxtPairCutMonitor(){
  delete mKt;
  delete mPt1Pt2Qinv;
  delete mFMRvsQinv;
  delete mSLvsQinv;
  delete mAveSepVsQinv;
  delete mRValueVsQinv;
}

//_________________
void  fxtPairCutMonitor::Fill(const StHbtPair* pair){
  //Float_t mT = sqrt(pair->kT()*pair->kT() + (mPartMass*mPartMass));
  mKt->Fill( pair->kT(), 1.);
  mPt1Pt2Qinv->Fill(  pair->track1()->Track()->Pt(),
		      pair->track2()->Track()->Pt(),
		      pair->qInv() );
  mFMRvsQinv->Fill( pair->qInv(), pair->getFracOfMergedRow(), 1.);
  mSLvsQinv->Fill( pair->qInv(), pair->quality(), 1.);
  mAveSepVsQinv->Fill(pair->qInv(), pair->NominalTpcAverageSeparation(), 1.);
  mRValueVsQinv->Fill(pair->qInv(), pair->rValue(), 1.);
}


