#ifndef BEAMCHI2
#define BEAMCHI2
#include <list>

#include "Chi2Func.h"
#include "FitData.h"
#include "FitPar.h"
#include "FitBeam.h"
#include "SkzpCalculator.h"
#include "TTree.h"
#include "TH1.h"
#include "TH1D.h"
#include "MCReweight/SKZPWeightCalculator.h"

class BeamChi2: public Chi2Func {


public:
  // Standard Constructor
  BeamChi2();
      
  // From Chi2Func
  virtual double GetChi2();
  virtual int    GetNDF() {return fNDF;}
  virtual bool   SetProperty(std::string prop);
  virtual bool   Init();
  virtual void Write();
  virtual double GetHistChi2();

  inline void UseNeugen(const bool &use) {fUseNeugen=use;}
  inline void UseSmoothing(const bool &use) {fUseSmoothing=use;}
  inline void SetDataPOT(const double pot) {fDataPOT=pot;}  
  inline void SetMCPOT(const double pot) {fDataPOT=pot;}
  inline void SetVars(const vector<std::string> vars) {fVars=vars;}
  inline void SetSmoothWidth(const double width) {fSmoothWidth=width;}
  inline void SetBeam(std::string beam){
    fBeam=FitBeam::StringToEnum(beam);}
  inline virtual void    SetName(std::string name) {fName=name;}
  inline virtual const std::string& GetName() const {return fName;}
  

protected:
  
private:


  bool FillMC();
  bool ReweightMC();
  bool GetData();

  std::string  fDataInput;    // Name of Root file for data
  std::string  fDataHistName; // Name data hist file in ab
  std::string  fMCInput;      // Name of Root file for mc
  std::string  fMCTreeName;   // Name of mc tree
  std::string  fMCCut;        // MC cut
  FitBeam::FitBeam_t    fBeam;// which beam (is taken from name of alg)
  double       fDataPOT;      // Data POT
  double       fMCPOT;        // MC POT

  // Weight Calculator
  SkzpCalculator *fSkzpCalc;

  // Neugen
  bool    fUseNeugen;

    // Neugen
  bool    fUseSmoothing;
  double  fSmoothWidth;
  double  fSmoothYWidth;

  // Variables for saving MC info
  bool fSaveFitData;
  std::string fFitDataFile;
  std::string fFitDataTree;

  bool fLoadFitData;
  std::string fLoadFitDataFile;

  // List of variables to use 
  // only enu,emu,eshw, or enu_y are possible
  std::vector<std::string>  fVars; 

  // Hold the data
  std::vector<TH1*>  fRWHists;
  std::vector<TH1*>  fMCHists;
  std::vector<TH1*>  fDataHists;


  std::list<FitData>   fMCList;     // stores MC info

  double  fInitChi2; // chi2 from mc without reweighting
  double  fBestChi2; // chi2 from rw
  int     fNDF;      // degrees of freedom
  
  std::string fName; 

};


#endif 
