#ifndef MARS_MCamDisplay
#define MARS_MCamDisplay

#ifndef MARS_MAGIC
#include "MAGIC.h"
#endif
#ifndef ROOT_Gtypes
#include <Gtypes.h>
#endif
#ifndef ROOT_TClonesArray
#include <TClonesArray.h>
#endif

class TBox;
class TText;
class TArrow;

class MGeomCam;
class MHexagon;
class MRflEvtData;
class MCerPhotEvt;
class MCerPhotPix;
class MImgCleanStd;
class MPedestalPix;
class MPedestalCam;

class MCamDisplay : public TObject
{
private:
    MGeomCam      *fGeomCam;     // pointer to camera geometry

    Bool_t         fAutoScale;   // indicating the autoscale function

    UInt_t         fNumPixels;   // number of pixels in the present geometry
    Float_t        fRange;       // the range in millimeters of the present geometry

    Int_t          fColors[50];

    TArrow        *fArrowX;      // Coordinate System
    TArrow        *fArrowY;      // Coordinate System

    TText         *fLegRadius;   // Coordinate System
    TText         *fLegDegree;   // Coordinate System

    TClonesArray  *fPixels;      // array of all hexagons
    TClonesArray  *fLegend;      // array of all color bars
    TClonesArray  *fLegText;     // array of all texts
    TClonesArray  *fPhotons;     // array of reflector photons
 
    UInt_t         fW;           // Width of canvas
    UInt_t         fH;           // Height of canvas

    TBox  *GetBox(Int_t i)  { return (TBox*) fLegend->At(i); }
    TText *GetText(Int_t i) { return (TText*)fLegText->At(i); }

    MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); }

    void  SetPixColor(const MCerPhotPix &pix, const UInt_t i, Float_t min, Float_t max);
    void  SetPixColorRatio(const MCerPhotPix &pix, Float_t min, Float_t max);
    void  SetPixColorLevel(const MCerPhotPix &pix, Float_t lvl1, Float_t lvl2);
    void  SetPixColorError(const MCerPhotPix &pix, const UInt_t i, Float_t min, Float_t max);
    void  SetPixColorPedestal(const MPedestalPix &pix, const UInt_t i, Float_t min, Float_t max);
    Int_t GetColor(Float_t val, Float_t min, Float_t max);

    void UpdateLegend(Float_t min, Float_t max);
    void SetRange();
    void SetPalette();

public:
    MCamDisplay();
    MCamDisplay(MGeomCam *geom);
    ~MCamDisplay();

    void SetAutoScale(Bool_t input=kTRUE) { fAutoScale = input; }
    void FillPhotNum(const MCerPhotEvt &event);
    void FillRatio(const MCerPhotEvt &event);
    void FillLevels(const MCerPhotEvt &event, Float_t lvl1, Float_t lvl2);
    void FillErrorPhot(const MCerPhotEvt &event);
    void FillLevels(const MCerPhotEvt &event, const MImgCleanStd &clean);
    void FillPedestals(const MPedestalCam &event);
    void FillRflEvent(const MRflEvtData &event);
    void ShowRflEvent(const MRflEvtData *event=NULL, EMarkerStyle m=kFullDotMedium);

    void DrawPixelNumbers();

    void  Paint(Option_t *option="");
    void  Reset();
    void  Draw(Option_t *option="");
    void  SavePrimitive(ofstream &out, Option_t *);
    Int_t DistancetoPrimitive(Int_t px, Int_t py);
    char *GetObjectInfo(Int_t px, Int_t py) const;
    //virtual void  ExecuteEvent(Int_t event, Int_t px, Int_t py);

    void SetPalette(Int_t ncolors, Int_t *colors);

    void SetPrettyPalette(); // *MENU*
    void SetDeepBlueSeaPalette(); // *MENU*
    void SetInvDeepBlueSeaPalette(); // *MENU*

    void SetPix(const Int_t pixnum, const Int_t color, Float_t min, Float_t max);      // New function added by M.Lopez in 31-01-03

    ClassDef(MCamDisplay, 0) // Displays the magic camera
};

#endif
