#ifndef MARS_MHFalseSource
#define MARS_MHFalseSource

#ifndef MARS_MH
#include "MH.h"
#endif

#ifndef ROOT_TH3
#include <TH3.h>
#endif

class TH2D;

class MParList;
class MTime;
class MPointingPos;
class MObservatory;

class MHFalseSource : public MH
{
private:
    MTime         *fTime;        //! container to take the event time from
    MPointingPos  *fPointPos;    //! container to take pointing position from
    MObservatory  *fObservatory; //! conteiner to take observatory location from

    Float_t fMm2Deg;             // conversion factor for display in degrees

    Float_t fAlphaCut;           // Alpha cut
    Float_t fBgMean;             // Background mean

    Float_t fMinDist;            // Min dist
    Float_t fMaxDist;            // Max dist

    Float_t fMinLD;              // Minimum distance in percent of dist
    Float_t fMaxLD;              // Maximum distance in percent of dist

    TH3D    fHist;               // Alpha vs. x and y

    Double_t fRa;
    Double_t fDec;

    Int_t DistancetoPrimitive(Int_t px, Int_t py);
    void Modified();

    void ProjectAll(TH2D *h);
    void ProjectOff(TH2D *h, TH2D *all);
    void ProjectOn(TH2D *h, TH2D *all);

    TObject *GetCatalog();

    void MakeSymmetric(TH1 *h);

public:
    MHFalseSource(const char *name=NULL, const char *title=NULL);

    Bool_t SetupFill(const MParList *pList);
    Bool_t Fill(const MParContainer *par, const Stat_t w=1);

    TH1 *GetHistByName(const TString name) { return &fHist; }

    void FitSignificance(Float_t sigint=15, Float_t sigmax=70, Float_t bgmin=40, Float_t bgmax=70, Byte_t polynom=1); //*MENU*
    void FitSignificanceStd() { FitSignificance(); } //*MENU*

    void SetMinDist(Float_t dist) { fMinDist = dist; } // Absolute minimum distance
    void SetMaxDist(Float_t dist) { fMaxDist = dist; } // Absolute maximum distance
    void SetMinLD(Float_t ratio)  { fMinLD = ratio; }  // Minimum ratio between length/dist
    void SetMaxLD(Float_t ratio)  { fMaxLD = ratio; }  // Maximum ratio between length/dist

    void SetAlphaCut(Float_t alpha); //*MENU*
    void SetAlphaPlus5()  { SetAlphaCut(fAlphaCut+5); } //*MENU*
    void SetAlphaMinus5() { SetAlphaCut(fAlphaCut-5); } //*MENU*

    void SetBgMean(Float_t alpha); //*MENU*
    void SetBgMeanPlus5()  { SetBgMean(fBgMean+5); } //*MENU*
    void SetBgMeanMinus5() { SetBgMean(fBgMean-5); } //*MENU*

    void Paint(Option_t *opt="");
    void Draw(Option_t *option="");

    static Double_t Significance(Double_t s, Double_t b);
    static Double_t SignificanceLiMa(Double_t s, Double_t b, Double_t alpha=1);

    ClassDef(MHFalseSource, 1) //3D-histogram in alpha, x and y
};

#endif
