#ifndef MARS_MMuonCalibPar
#define MARS_MMuonCalibPar

#ifndef MARS_MParContainer
#include "MParContainer.h"
#endif

#ifndef ROOT_TH1
#include <TH1.h>
#endif

class MGeomCam;
class MCerPhotEvt;
class MMuonSearchPar;

class MMuonCalibPar : public MParContainer
{
private:
  Float_t fArcLen;       // An arc length of a muon along the arc [deg.]
  Float_t fArcPhi;       // A opening angle of a muon arc [deg.]
  Float_t fArcWid;       // A width of a muon [deg.] (1 sigma of gaussian fit)
  Float_t fChiArcPhi;    // A chisquare value of the cosine fit for arc phi
  Float_t fChiArcWid;    // A chisquare value of the cosine fit for arc wid
  Float_t fMuonSize;     // A SIZE of muon which is defined as a SIZE around the estimated circle
  Float_t fEstImpact;    // An estimated impact parameter from the photon distribution along the arc image
  Bool_t  fKeepHist;     // A flag to keep histgram
  Float_t fMargin;       // margin to evaluate muons [mm]. The defaut value is 60 mm, corresponding to 0.2 deg. This value can be changed by using the function of SetMargin
  Bool_t  fUseUnmap;     // This is a flag to know the Unmapped pixels are used. Refer to the class of MImgCleanStd
  Float_t fPeakPhi;      // The angle which indicates the peak position in the estimated circle
  Float_t fArcPhiThres;  // The threshold value to define arc phi
  Float_t fArcWidThres;  // The threshold value to define arc width
  Int_t   fArcPhiBinNum; // The bin number for the histogram of arc phi. You may change this value. However, if you change this, YOU ALSO HAVE TO CHANGE THE THRESHOLD VALUE TO GET ARC LENGTH.
  Int_t   fArcWidBinNum; // The bin number for the histogram of arc wid
  Float_t fArcPhiHistStartVal; // The starting value for the histogram of arc phi
  Float_t fArcPhiHistEndVal;   // The end value for the histogram of arc phi
  Float_t fArcWidHistStartVal; // The starting value for the histogram of arc width
  Float_t fArcWidHistEndVal;   // The end value for the histogram of arc width
  Float_t fEnableImpactCalc;   // If true, the impact calculation will be done, which will consume a lot of time.
  Float_t fDisablePreCuts;     // If true, the pre cuts to select muons for the calibration will be disabled.
  Float_t fUseCleanForWid;     // If true, the only signal after image cleaningwill be used for the histogram of arc width

  TH1F fHistPhi;      // Histogram of photon distribution along the arc.
  TH1F fHistWid;      // Histogram of radial photon distribution of the arc.
  
public:
  MMuonCalibPar(const char *name=NULL, const char *title=NULL);
  
  void Reset();
  
  Float_t GetArcLen()    const { return fArcLen; }
  Float_t GetArcPhi()    const { return fArcPhi; }
  Float_t GetArcWid()    const { return fArcWid; }
  Float_t GetChiArcPhi() const { return fChiArcPhi; }
  Float_t GetChiArcWid() const { return fChiArcWid; }
  Float_t GetMargin()    const { return fMargin; }
  Float_t GetMuonSize()  const { return fMuonSize; }
  Float_t GetEstImpact() const { return fEstImpact; }
  Bool_t  IsUseUnmap()   const { return fUseUnmap; }
  Float_t GetPeakPhi()   const { return fPeakPhi; }
  Float_t GetArcPhiThres()  const { return fArcPhiThres; }
  Float_t GetArcWidThres()  const { return fArcWidThres; }
  Float_t GetArcPhiBinNum() const { return fArcPhiBinNum; }
  Float_t GetArcWidBinNum() const { return fArcWidBinNum; }
  TH1F    &GetHistPhi()        { return fHistPhi; }
  TH1F    &GetHistWid()        { return fHistWid; }
  
  void    SetMargin(Float_t margin) { fMargin = margin; }
  void    SetArcPhiThres(Float_t thres) { fArcPhiThres = thres; }
  void    SetArcWidThres(Float_t thres) { fArcWidThres = thres; }
  void    SetArcPhiBinNum(Int_t num) { fArcPhiBinNum = num; }
  void    SetArcWidBinNum(Int_t num) { fArcWidBinNum = num; }
  
  void    KeepHist() { fKeepHist = kTRUE; }
  Bool_t  IsKeepHist() { return fKeepHist; }
  
  void    EnableImpactCalc()   { fEnableImpactCalc = kTRUE; }
  Bool_t  IsEnableImpactCalc() { return fEnableImpactCalc; }
  void    DisablePreCuts()     { fDisablePreCuts = kTRUE; }
  Bool_t  IsDisablePreCuts()   { return fDisablePreCuts; }
  void    UseCleanForWid()     { fUseCleanForWid = kTRUE; }
  Bool_t  IsUseCleanForWid()   { return fUseCleanForWid; }

  void    Print(Option_t *opt=NULL) const;

  void    FillHist(const MGeomCam &geom, const MCerPhotEvt &evt,
		   const MMuonSearchPar &musearch);
  void    CalcPhi(const MGeomCam &geom, const MCerPhotEvt &evt,
		  const MMuonSearchPar &musearch);
  void    CalcImpact(const MGeomCam &geom, const MMuonSearchPar &musearch,
		     Int_t effbinnum, Float_t startfitval, Float_t endfitval);
  Float_t CalcWid(const MGeomCam &geom, const MCerPhotEvt &evt, 
		  const MMuonSearchPar &musearch);
  Int_t   Calc(const MGeomCam &geom, const MCerPhotEvt &evt,
	       const MMuonSearchPar &musearch);
  
  ClassDef(MMuonCalibPar, 3) // Container to hold muon calibration parameters
};
    
#endif
