/*************************************/
/***                               ***/
/***          StFlow               ***/
/***  VERSION: 1.0                 ***/
/***   AUTHOR: Nikita Ermakov      ***/
/***     DATE:                     ***/
/***   E-MAIL: coffe92@gmail.com   ***/
/***                               ***/
/*************************************/

#ifndef STFLOW_HH
#define STFLOW_HH

#include "StMaker.h"
#include "StThreeVector.hh"
#include "StThreeVectorF.hh"
#include "StPhysicalHelixD.hh"
#include "StRefMultCorr/StRefMultCorr.h"

#include "StMuDSTMaker/COMMON/StMuDstMaker.h"
#include "StMuDSTMaker/COMMON/StMuDst.h"
#include "StMuDSTMaker/COMMON/StMuEvent.h"
#include "StMuDSTMaker/COMMON/StMuTrack.h"
#include "StMuDSTMaker/COMMON/StMuPrimaryVertex.h"
#include "StMuDSTMaker/COMMON/StMuBTofPidTraits.h"
#include "StMuDSTMaker/COMMON/StMuBTofHit.h"

#include <TString.h>
#include <TFile.h>
#include <TLorentzVector.h>
#include <TProfile.h>
#include <TTree.h>
#include <TH1.h>
#include <TH2.h>

#include <vector>
#include <iostream>

#ifndef St_NO_NAMESPACES
using namespace std;
#endif

class StMuDst;
class StMuDstMaker;
class StMuEvent;
class StMuTrack;


const float PION_MASS   = 0.139569; // GeV/c^2
const float PROTON_MASS = 0.938272; // GeV/c^2
const float KAON_MASS   = 0.4936;   // GeV/c^2

//_________________
class StFlow : public StMaker 
{
public:
  StFlow(StMuDstMaker *muMaker, const Char_t *oFileName);
  ~StFlow();
  //
  // Chain methods
  //
  void  Clear(Option_t *option = "");
  Int_t Init();
  Int_t Make();
  Int_t Finish();

  void CleanVariables();
  void SetMuDstMaker(StMuDstMaker *maker);
  //
  // Setup event
  //
  void SetTriggerId(unsigned int id);
  void SetVtxZCut(float lo, float hi);
  void SetVtxRCut(float lo, float hi);
  void SetVtxShift(float xShift, float yShift);
  void SetVtxVpdVzDiffCut(float lo, float hi);
  //
  // Setup track
  //
  void SetP(float lo, float hi);
  void SetPt(float lo, float hi);
  void SetTrackNHits(int lo, int hi);
  void SetTrackNHitsFit(int lo, int hi);
  void SetTrackEta(float lo, float hi);
  void SetTrackFlag(short lo, short hi);
  void SetTrackDCA(float lo, float hi);
  //
  // Cut methods
  //
  Bool_t AcceptTrigger(StMuEvent *muEvent);
  Bool_t AcceptPrimVtx(StThreeVectorF vtxPos, Float_t vpdVz);
  Bool_t AcceptTrack(StMuTrack *trk, UShort_t vtxInd);
  Bool_t IsTofTrack(StMuTrack *trk);

 private:
  const char *mFileName;
  TFile      *mOutFile;
  
  vector<UInt_t> mTriggerIdCollection;
  //
  // Global counters
  //
  bool  mEventIsGood;
  int   mNEventsIn;
  int   mNEventsPassed;

  bool  mIsGoodTrack;
  //
  // Event cuts
  //
  float mPrimVtxZ[2];
  float mPrimVtxR[2];
  float mPrimVtxVpdVzDiff[2];
  float mPrimVtxXShift;
  float mPrimVtxYShift;
  
  // Single-particle cuts
  //
  float          mTrackP[2];
  float          mTrackPt[2];
  float          mTrackDca[2];
  float          mTrackDcaGlobal[2];
  unsigned short mTrackNHits[2];
  unsigned short mTrackNHitsFit[2];
  float          mTrackEta[2];
  short          mTrackFlag[2];
  //
  // Pointers to classes
  //
  StMuPrimaryVertex *mPrimVertex;
  StMuTrack         *mPrimTrack;
  StMuTrack         *mGlobTrack;
  StMuDstMaker      *mMuDstMaker;
  StMuEvent         *mMuEvent;
  StMuDst           *mMuDst;
  StRefMultCorr     *mRefMultCorrUtil;

  //
  // Histograms
  //
  TProfile *hdV2vsCent;
  TH2F     *hV2vsCent;
  //
  // Trigger
  //
  unsigned int mCurrentTrigger;

  ClassDef(StFlow, 1)
};

#endif
