ROOT logo
#include <TG3DLine.h>
#include <TGButton.h>
#include <TGMenu.h>
#include <TGPicture.h>
#include <TGSplitter.h>
#include <TGToolBar.h>
#include <TGMsgBox.h>

#include <TGrid.h>
#include <TSystem.h>
#include <TInterpreter.h>
#include <TROOT.h>

#include <TEveManager.h>
#include <TEveSelection.h>

#include <AliEveEventManager.h>
#include <AliEveMultiView.h>
#include <AliEveMacro.h>
#include <AliEveMacroExecutor.h>
#include <AliEveTrackFitter.h>
#include <AliEveTrackCounter.h>

#include "../alice-macros/geom_gentle.C"
#include "../alice-macros/geom_gentle_trd.C"
#include "../alice-macros/geom_gentle_muon.C"


#include "AliEveMainWindow.h"
#include "AliEveUtil.h"
#include "AliEveFileDialog.h"

AliEveMainWindow::AliEveMainWindow(const char* title, UInt_t width, UInt_t height)
    : TGMainFrame(gClient->GetRoot(), width, height),
      fMenuBar(0),
      fMenuFile(0),
      fMenuEdit(0),
      fMenuView(0),
      fMenuViewToolbars(0),
      fMenuViewSidebars(0),
      fMenuGo(0),
      fMenuTools(0),
      fMenuHelp(0),
      fToolBar(0),
      fPicturePool(0),
//      fEve(0),
      fFileDialog(0)
{
	static const TEveException kEH("AliEveMainWindow");
	Info(kEH.Data(),"Constructor called");
	
    AliEveUtil::Init();
    fPicturePool = AliEveUtil::GetPicturePool();
   
//    fEve = TEveManager::Create(kFALSE, "VVV");
    gEve->GetDefaultViewer()->SetElementName("3D View");
    gEve->GetSelection()->SetPickToSelect(TEveSelection::kPS_PableCompound);
    gEve->GetHighlight()->SetPickToSelect(TEveSelection::kPS_PableCompound);

    TString evedir(Form("%s/EVE", gSystem->Getenv("ALICE_ROOT")));
    gEve->RegisterGeometryAlias("Default", Form("%s/alice-data/default_geo.root", evedir.Data()));
    
    setupMenus();
    setupToolbars();

    TGHorizontalFrame* hf = new TGHorizontalFrame(this,200,200);
    
    // 3D View Frame
    TGFrame* towerViewFrame = gEve->GetDefaultViewer()->GetGUIFrame();
    towerViewFrame->MapWindow();
    towerViewFrame->ReparentWindow(hf);
    
    hf->AddFrame(towerViewFrame, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY , 3, 3, 3, 3));
    
    AddFrame(hf, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY , 3, 3, 3, 3));

    SetWindowName(title);
    Resize(width,height);
    MapSubwindows();
    MapWindow();
    Layout();

    gEve->Redraw3D(kTRUE);
    gSystem->ProcessEvents();
}

AliEveMainWindow::~AliEveMainWindow()
{
//    if(fEve) delete fEve;
}

void AliEveMainWindow::onMenuFileItem(UInt_t id)
{
    switch(id){
    case MENU_FILE_OPEN:
    {
        if(!fFileDialog) fFileDialog = new AliEveFileDialog( gClient->GetRoot(), this, kAliEveFDLocal);

        fFileDialog->setMode(kAliEveFDLocal);
        fFileDialog->MapWindow();
        
        if(fFileDialog->accepted()) {
         AliEveEventManager::SetESDFileName(fFileDialog->GetPathESD());
         AliEveEventManager::SetESDfriendFileName(fFileDialog->GetPathESDfriend());
         AliEveEventManager::SetAODFileName(fFileDialog->GetPathAOD());
         AliEveEventManager::AddAODfriend(fFileDialog->GetPathAODfriend());
         AliEveEventManager::SetRawFileName(fFileDialog->GetPathRaw());
         AliEveEventManager::SetCdbUri(fFileDialog->GetCDBStoragePath());
         loadFiles();        
        }
        break;
    }
    case MENU_FILE_OPEN_URL:
    {
        if(!fFileDialog) fFileDialog = new AliEveFileDialog( gClient->GetRoot(), this, kAliEveFDRemote);

        fFileDialog->setMode(kAliEveFDRemote);
        fFileDialog->MapWindow();
        if(fFileDialog->accepted()) {
         AliEveEventManager::SetFilesPath(fFileDialog->GetUrl());
         AliEveEventManager::SetCdbUri(fFileDialog->GetCDBStoragePath());
         
         

    // Open event
    if (fFileDialog->GetUrl().BeginsWith("alien:"))
    {
        if (gGrid != 0)
        {
            Info("AliEveMainWindow::openFile", "TGrid already initializied. Skiping checks and initialization.");
        }
        else
        {
            Info("AliEveMainWindow::openFile", "AliEn requested - connecting.");
            if (gSystem->Getenv("GSHELL_ROOT") == 0)
            {
                Error("AliEveMainWindow::openFile", "AliEn environment not initialized. Aborting.");
                new TGMsgBox(gClient->GetRoot(), this, "AliEve", "AliEn environment not initialized. Aborting.", kMBIconStop);
                return;
            }
            if (TGrid::Connect("alien") == 0)
            {
                Error("AliEveMainWindow::openFile", "TGrid::Connect() failed. Aborting.");
                new TGMsgBox(gClient->GetRoot(), this, "AliEve", "TGrid::Connect() failed. Aborting.", kMBIconStop);
                return;
            }
        }
    }
         
         loadFiles();        
        }

        break;
    }
    default:
    {
        break;
    }
    }
}

void AliEveMainWindow::onMenuEditItem(UInt_t /*id*/)
{

}

void AliEveMainWindow::onMenuViewItem(UInt_t /*id*/)
{

}

void AliEveMainWindow::onMenuGoItem(UInt_t id)
{
    switch(id){
    case MENU_GO_NEXT_EVENT:
    {
        AliEveEventManager::GetMaster()->NextEvent();
        break;
    }
    case MENU_GO_PREV_EVENT:
    {
        AliEveEventManager::GetMaster()->PrevEvent();
        break;
    }
    default:
    {
        break;
    }
    }

    TEveElement* top = gEve->GetCurrentEvent();

    AliEveMultiView *mv = AliEveMultiView::Instance();

    mv->ImportEventRPhi(top);
    mv->ImportEventRhoZ(top);

    gEve->Redraw3D(kTRUE);
}

void AliEveMainWindow::setupMenus()
{

    fMenuBar = new TGMenuBar(this);

    // File Menu
    fMenuFile = new TGPopupMenu(gClient->GetRoot());
    fMenuFile->AddEntry("&Open...", MENU_FILE_OPEN, 0, fPicturePool->GetPicture("menu/document-open.png"));
    fMenuFile->AddEntry("&Open URL...", MENU_FILE_OPEN_URL, 0, fPicturePool->GetPicture("menu/document-open-remote.png"));
    fMenuFile->AddSeparator();
    fMenuFile->AddEntry("&Connect To Server...", MENU_FILE_OPEN_CONNECTION, 0, fPicturePool->GetPicture("menu/network-connect.png"));
    fMenuFile->AddSeparator();
    fMenuFile->AddEntry("Export View(s)...", MENU_FILE_EXPORT_VIEWS, 0, fPicturePool->GetPicture("menu/document-export.png"));
    fMenuFile->AddSeparator();
    fMenuFile->AddEntry("E&xit", MENU_FILE_EXIT, 0, fPicturePool->GetPicture("menu/application-exit.png"));
    // --

    // Edit Menu
    fMenuEdit = new TGPopupMenu(gClient->GetRoot());
    fMenuEdit->AddEntry("&Undo",   MENU_EDIT_UNDO, 0, fPicturePool->GetPicture("menu/edit-undo.png"));
    fMenuEdit->AddEntry("&Redo",   MENU_EDIT_REDO, 0, fPicturePool->GetPicture("menu/edit-redo.png"));
    fMenuEdit->AddSeparator();
    fMenuEdit->AddEntry("&Cut",   MENU_EDIT_CUT, 0, fPicturePool->GetPicture("menu/edit-cut.png"));
    fMenuEdit->AddEntry("C&opy",  MENU_EDIT_COPY, 0, fPicturePool->GetPicture("menu/edit-copy.png"));
    fMenuEdit->AddEntry("&Paste", MENU_EDIT_PASTE, 0, fPicturePool->GetPicture("menu/edit-paste.png"));
    fMenuEdit->AddEntry("&Delete",MENU_EDIT_DELETE, 0, fPicturePool->GetPicture("menu/edit-delete.png"));
    fMenuEdit->AddSeparator();
    fMenuEdit->AddEntry("P&references", MENU_EDIT_PROP, 0, fPicturePool->GetPicture("menu/document-properties.png"));
    // --

    // View Menu
    fMenuView = new TGPopupMenu(gClient->GetRoot());

    fMenuViewToolbars = new TGPopupMenu(gClient->GetRoot());
    fMenuViewToolbars->AddEntry("&Main Toolbar", MENU_VIEW_TOOLBAR_MAIN);
    fMenuViewToolbars->AddEntry("&Navigation Toolbar", MENU_VIEW_TOOLBAR_NAV);
    fMenuView->AddPopup("Toolbars", fMenuViewToolbars);

    fMenuViewSidebars = new TGPopupMenu(gClient->GetRoot());
    fMenuViewSidebars->AddEntry("Hi&story", MENU_VIEW_TOOLBAR_HIST);
    fMenuViewSidebars->AddEntry("&Properties", MENU_VIEW_TOOLBAR_NAV);
    fMenuView->AddPopup("Sidebars", fMenuViewSidebars);

    fMenuView->AddSeparator();
    fMenuView->AddEntry("&Reload", MENU_VIEW_RELOAD, 0, fPicturePool->GetPicture("menu/view-refresh.png"));
    fMenuView->AddSeparator();
    fMenuView->AddEntry("Zoom &In", MENU_VIEW_ZOOM_IN, 0, fPicturePool->GetPicture("menu/zoom-in.png"));
    fMenuView->AddEntry("Zoom &Out",MENU_VIEW_ZOOM_OUT, 0, fPicturePool->GetPicture("menu/zoom-out.png"));
    fMenuView->AddEntry("Zoom &Reset",MENU_VIEW_ZOOM_RESET, 0, fPicturePool->GetPicture("menu/zoom-original.png"));
    // --

    // Go Menu
    fMenuGo = new TGPopupMenu(gClient->GetRoot());
    fMenuGo->AddEntry("&Next Event",   MENU_GO_NEXT_EVENT, 0, fPicturePool->GetPicture("navigation/media-seek-forward.png"));
    fMenuGo->AddEntry("P&revious Event",   MENU_GO_PREV_EVENT, 0, fPicturePool->GetPicture("navigation/media-seek-backward.png"));
    fMenuGo->AddSeparator();
    fMenuGo->AddEntry("&First Event", MENU_GO_FIRST_EVENT,0, fPicturePool->GetPicture("navigation/media-skip-backward.png"));
    fMenuGo->AddEntry("&Last Event",  MENU_GO_LAST_EVENT, 0, fPicturePool->GetPicture("navigation/media-skip-forward.png"));
    fMenuGo->AddSeparator();
    fMenuGo->AddEntry("&Play", MENU_GO_PLAY, 0, fPicturePool->GetPicture("navigation/media-playback-start.png"));
    // --

    // Tools Menu
    fMenuTools = new TGPopupMenu(gClient->GetRoot());
    fMenuTools->AddEntry("&QA Histograms", MENU_TOOLS_QA);
    fMenuTools->AddEntry("&Macros", MENU_TOOLS_MACROS);
    // --

    // Help Menu
    fMenuHelp = new TGPopupMenu(gClient->GetRoot());
    fMenuHelp->AddEntry("&Contents", MENU_HELP_CONTENTS, 0, fPicturePool->GetPicture("menu/help-contents.png"));
    fMenuHelp->AddEntry("&About", MENU_HELP_ABOUT, 0, fPicturePool->GetPicture("menu/help-about.png"));
    // --

    // Add popupmenus to MenuBar
    fMenuBar->AddPopup("&File", fMenuFile, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
    fMenuBar->AddPopup("&Edit", fMenuEdit, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
    fMenuBar->AddPopup("&View", fMenuView, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
    fMenuBar->AddPopup("&Go", fMenuGo, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
    fMenuBar->AddPopup("&Tools", fMenuTools, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
    fMenuBar->AddPopup("&Help", fMenuHelp, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));

    // MenuBar to the window
    AddFrame(fMenuBar,  new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX));

    // Menu signals
    fMenuFile->Connect("Activated(Int_t)", "AliEveMainWindow", this, "onMenuFileItem(Int_t)");
    fMenuEdit->Connect("Activated(Int_t)", "AliEveMainWindow", this, "onMenuEditItem(Int_t)");
    fMenuView->Connect("Activated(Int_t)", "AliEveMainWindow", this, "onMenuViewItem(Int_t)");
    fMenuGo->Connect("Activated(Int_t)", "AliEveMainWindow", this, "onMenuGoItem(Int_t)");
}

void AliEveMainWindow::setupToolbars()
{
    TGMenuEntry* tmpMenuEntry;

    fToolBar = new TGToolBar(this);

    tmpMenuEntry = fMenuFile->GetEntry("Open...");
    fToolBar->AddButton(this, new TGPictureButton(fToolBar, tmpMenuEntry->GetPic(), tmpMenuEntry->GetEntryId() ));
    tmpMenuEntry = fMenuFile->GetEntry("Open URL...");
    fToolBar->AddButton(this, new TGPictureButton(fToolBar, tmpMenuEntry->GetPic(), tmpMenuEntry->GetEntryId() ));
    tmpMenuEntry = fMenuFile->GetEntry("Connect To Server...");
    fToolBar->AddButton(this, new TGPictureButton(fToolBar, tmpMenuEntry->GetPic(), tmpMenuEntry->GetEntryId() ));
    tmpMenuEntry = fMenuFile->GetEntry("Export View(s)...");
    fToolBar->AddButton(this, new TGPictureButton(fToolBar, tmpMenuEntry->GetPic(), tmpMenuEntry->GetEntryId() ));

    fToolBar->AddFrame(new TGVertical3DLine(fToolBar),  new TGLayoutHints(kLHintsExpandY));

    tmpMenuEntry = fMenuView->GetEntry("Reload");
    fToolBar->AddButton(this, new TGPictureButton(fToolBar, tmpMenuEntry->GetPic(), tmpMenuEntry->GetEntryId() ));
    tmpMenuEntry = fMenuView->GetEntry("Zoom In");
    fToolBar->AddButton(this, new TGPictureButton(fToolBar, tmpMenuEntry->GetPic(), tmpMenuEntry->GetEntryId() ));
    tmpMenuEntry = fMenuView->GetEntry("Zoom Out");
    fToolBar->AddButton(this, new TGPictureButton(fToolBar, tmpMenuEntry->GetPic(), tmpMenuEntry->GetEntryId() ));
    tmpMenuEntry = fMenuView->GetEntry("Zoom Reset");
    fToolBar->AddButton(this, new TGPictureButton(fToolBar, tmpMenuEntry->GetPic(), tmpMenuEntry->GetEntryId() ));




    AddFrame(new TGHorizontal3DLine(this), new TGLayoutHints(kLHintsExpandX));
    AddFrame(fToolBar, new TGLayoutHints(kLHintsNormal));
    AddFrame(new TGHorizontal3DLine(this), new TGLayoutHints(kLHintsExpandX));


    //fToolBar->Connect("Clicked(Int_t)", "RCMainWindow", this, "openFile()");
}

void AliEveMainWindow::loadFiles()
{
    TString name("Event"); // CINT has trouble with direct "Event".
    new AliEveEventManager(name, 0);
    gEve->AddEvent(AliEveEventManager::GetMaster());

    TEveUtil::AssertMacro("VizDB_scan.C");

    AliEveMacroExecutor *exec    = AliEveEventManager::GetMaster()->GetExecutor();
    //==============================================================================
    // Geometry, scenes, projections and viewers
    //==============================================================================

    AliEveMultiView *mv = new AliEveMultiView;

    mv->SetDepth(-10);

    TEveUtil::LoadMacro("geom_gentle.C");
    mv->InitGeomGentle(geom_gentle(), geom_gentle_rphi(), geom_gentle_rhoz(), 0);


    TEveUtil::LoadMacro("geom_gentle_trd.C");
    mv->InitGeomGentleTrd(geom_gentle_trd());

    TEveUtil::LoadMacro("geom_gentle_muon.C");
    mv->InitGeomGentleMuon(geom_gentle_muon(kFALSE), kTRUE, kTRUE, kFALSE);

    mv->SetDepth(0);

    //==============================================================================
    // Registration of per-event macros
    //==============================================================================

    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "SIM Track",   "kine_tracks.C", "kine_tracks", "", kFALSE));

    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "SIM Hits ITS", "its_hits.C",    "its_hits",    "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "SIM Hits TPC", "tpc_hits.C",    "tpc_hits",    "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "SIM Hits T0",  "t0_hits.C",     "t0_hits",     "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "SIM Hits FMD", "fmd_hits.C",    "fmd_hits",    "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "SIM Hits ACORDE", "acorde_hits.C",    "acorde_hits",    "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "SIM Hits EMCAL", "emcal_hits.C",    "emcal_hits",    "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "SIM Hits TOF",  "tof_hits.C",     "tof_hits",     "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "SIM Hits TRD", "trd_hits.C",    "trd_hits",    "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "SIM Hits VZERO", "vzero_hits.C",    "vzero_hits",    "", kFALSE));

    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "DIG ITS",     "its_digits.C",  "its_digits",  "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "DIG TPC",     "tpc_digits.C",  "tpc_digits",  "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "DIG TOF",     "tof_digits.C",  "tof_digits",  "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "DIG HMPID",   "hmpid_digits.C","hmpid_digits","", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "DIG FMD",     "fmd_digits.C",  "fmd_digits",  "", kFALSE));

    exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW ITS",     "its_raw.C",     "its_raw",     "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW TPC",     "tpc_raw.C",     "tpc_raw",     "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW TOF",     "tof_raw.C",     "tof_raw",     "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW HMPID",   "hmpid_raw.C",   "hmpid_raw",   "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW T0",      "t0_raw.C",      "t0_raw",      "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW FMD",     "fmd_raw.C",     "fmd_raw",     "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW VZERO",   "vzero_raw.C",   "vzero_raw",   "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW ACORDE",  "acorde_raw.C",  "acorde_raw",  "", kFALSE));

    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX",             "primary_vertex.C", "primary_vertex",             "",                kTRUE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse",     "primary_vertex.C", "primary_vertex_ellipse",     "",                kTRUE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box",         "primary_vertex.C", "primary_vertex_box",         "kFALSE, 3, 3, 3", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX SPD",         "primary_vertex.C", "primary_vertex_spd",         "",                kTRUE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse SPD", "primary_vertex.C", "primary_vertex_ellipse_spd", "",                kTRUE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box SPD",     "primary_vertex.C", "primary_vertex_box_spd",     "kFALSE, 3, 3, 3", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX TPC",         "primary_vertex.C", "primary_vertex_tpc",         "",                kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Ellipse TPC", "primary_vertex.C", "primary_vertex_ellipse_tpc", "",                kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC PVTX Box TPC",     "primary_vertex.C", "primary_vertex_box_tpc",     "kFALSE, 3, 3, 3", kFALSE));

    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC V0",   "esd_V0_points.C",       "esd_V0_points_onfly"));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC V0",   "esd_V0_points.C",       "esd_V0_points_offline"));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC V0",   "esd_V0.C",              "esd_V0"));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC CSCD", "esd_cascade_points.C",  "esd_cascade_points"));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC CSCD", "esd_cascade.C",         "esd_cascade"));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC KINK", "esd_kink_points.C",     "esd_kink_points"));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC KINK", "esd_kink.C",            "esd_kink"));

    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Tracks",              "esd_tracks.C", "esd_tracks",              "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Tracks ITS standalone",          "esd_tracks.C", "esd_tracks_ITS_standalone",              "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Tracks ITS",          "esd_tracks.C", "esd_tracks_ITS",              "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Tracks TPC",           "esd_tracks.C", "esd_tracks_TPC",              "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Tracks MI",           "esd_tracks.C", "esd_tracks_MI",           "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Tracks by category",  "esd_tracks.C", "esd_tracks_by_category",  "", kTRUE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Tracks by anal cuts", "esd_tracks.C", "esd_tracks_by_anal_cuts", "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Tracks Lego", "lego.C", "lego", "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Tracks Beams Info", "beams_info.C", "beams_info", "", kFALSE));

    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Tracklets SPD", "esd_spd_tracklets.C", "esd_spd_tracklets", "", kTRUE));

    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC ZDC",      "esd_zdc.C", "esd_zdc", "", kFALSE));

    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clusters",     "clusters.C",     "clusters", "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clusters ITS", "its_clusters.C", "its_clusters"));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clusters TPC", "tpc_clusters.C", "tpc_clusters"));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clusters TRD", "trd_clusters.C", "trd_clusters"));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clusters TOF", "tof_clusters.C", "tof_clusters"));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clusters HMPID", "hmpid_clusters.C", "hmpid_clusters"));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clusters PHOS", "phos_clusters.C", "phos_clusters"));

    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clusters TPC", "vplot_tpc.C",    "vplot_tpc", "", kFALSE));

    exec->AddMacro(new AliEveMacro(AliEveMacro::kAOD, "ANA HF",   "aod_HF.C",   "aod_HF",   "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kAOD, "ANA Jets", "jetplane.C", "jetplane", "", kFALSE));

    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "DUMP VZERO",   "vzero_dump.C",   "vzero_dump",   "", kFALSE));


    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "SIM TrackRef MUON", "muon_trackRefs.C", "muon_trackRefs", "kTRUE", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRawReader, "RAW MUON", "muon_raw.C", "muon_raw", "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "DIG MUON", "muon_digits.C", "muon_digits", "", kFALSE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kRunLoader, "REC Clusters MUON", "muon_clusters.C", "muon_clusters", "", kTRUE));
    exec->AddMacro(new AliEveMacro(AliEveMacro::kESD, "REC Tracks MUON", "esd_muon_tracks.C", "esd_muon_tracks", "kTRUE,kFALSE", kTRUE));


    //==============================================================================
    // AliEve objects - global tools
    //==============================================================================

    AliEveTrackFitter* fitter = new AliEveTrackFitter();
    gEve->AddToListTree(fitter, 1);
    gEve->AddElement(fitter, gEve->GetEventScene());

    AliEveTrackCounter* g_trkcnt = new AliEveTrackCounter("Primary Counter");
    gEve->AddToListTree(g_trkcnt, kFALSE);

    // A refresh to show proper window.
    //gEve->GetViewers()->SwitchColorSet();
    gEve->Redraw3D(kTRUE);
    gSystem->ProcessEvents();

    // Register command to call on each event.
    // AliEveEventManager::GetMaster()->AddNewEventCommand("on_new_event();");
    AliEveEventManager::GetMaster()->GotoEvent(0);

    gEve->Redraw3D(kTRUE);
}

 AliEveMainWindow.cxx:1
 AliEveMainWindow.cxx:2
 AliEveMainWindow.cxx:3
 AliEveMainWindow.cxx:4
 AliEveMainWindow.cxx:5
 AliEveMainWindow.cxx:6
 AliEveMainWindow.cxx:7
 AliEveMainWindow.cxx:8
 AliEveMainWindow.cxx:9
 AliEveMainWindow.cxx:10
 AliEveMainWindow.cxx:11
 AliEveMainWindow.cxx:12
 AliEveMainWindow.cxx:13
 AliEveMainWindow.cxx:14
 AliEveMainWindow.cxx:15
 AliEveMainWindow.cxx:16
 AliEveMainWindow.cxx:17
 AliEveMainWindow.cxx:18
 AliEveMainWindow.cxx:19
 AliEveMainWindow.cxx:20
 AliEveMainWindow.cxx:21
 AliEveMainWindow.cxx:22
 AliEveMainWindow.cxx:23
 AliEveMainWindow.cxx:24
 AliEveMainWindow.cxx:25
 AliEveMainWindow.cxx:26
 AliEveMainWindow.cxx:27
 AliEveMainWindow.cxx:28
 AliEveMainWindow.cxx:29
 AliEveMainWindow.cxx:30
 AliEveMainWindow.cxx:31
 AliEveMainWindow.cxx:32
 AliEveMainWindow.cxx:33
 AliEveMainWindow.cxx:34
 AliEveMainWindow.cxx:35
 AliEveMainWindow.cxx:36
 AliEveMainWindow.cxx:37
 AliEveMainWindow.cxx:38
 AliEveMainWindow.cxx:39
 AliEveMainWindow.cxx:40
 AliEveMainWindow.cxx:41
 AliEveMainWindow.cxx:42
 AliEveMainWindow.cxx:43
 AliEveMainWindow.cxx:44
 AliEveMainWindow.cxx:45
 AliEveMainWindow.cxx:46
 AliEveMainWindow.cxx:47
 AliEveMainWindow.cxx:48
 AliEveMainWindow.cxx:49
 AliEveMainWindow.cxx:50
 AliEveMainWindow.cxx:51
 AliEveMainWindow.cxx:52
 AliEveMainWindow.cxx:53
 AliEveMainWindow.cxx:54
 AliEveMainWindow.cxx:55
 AliEveMainWindow.cxx:56
 AliEveMainWindow.cxx:57
 AliEveMainWindow.cxx:58
 AliEveMainWindow.cxx:59
 AliEveMainWindow.cxx:60
 AliEveMainWindow.cxx:61
 AliEveMainWindow.cxx:62
 AliEveMainWindow.cxx:63
 AliEveMainWindow.cxx:64
 AliEveMainWindow.cxx:65
 AliEveMainWindow.cxx:66
 AliEveMainWindow.cxx:67
 AliEveMainWindow.cxx:68
 AliEveMainWindow.cxx:69
 AliEveMainWindow.cxx:70
 AliEveMainWindow.cxx:71
 AliEveMainWindow.cxx:72
 AliEveMainWindow.cxx:73
 AliEveMainWindow.cxx:74
 AliEveMainWindow.cxx:75
 AliEveMainWindow.cxx:76
 AliEveMainWindow.cxx:77
 AliEveMainWindow.cxx:78
 AliEveMainWindow.cxx:79
 AliEveMainWindow.cxx:80
 AliEveMainWindow.cxx:81
 AliEveMainWindow.cxx:82
 AliEveMainWindow.cxx:83
 AliEveMainWindow.cxx:84
 AliEveMainWindow.cxx:85
 AliEveMainWindow.cxx:86
 AliEveMainWindow.cxx:87
 AliEveMainWindow.cxx:88
 AliEveMainWindow.cxx:89
 AliEveMainWindow.cxx:90
 AliEveMainWindow.cxx:91
 AliEveMainWindow.cxx:92
 AliEveMainWindow.cxx:93
 AliEveMainWindow.cxx:94
 AliEveMainWindow.cxx:95
 AliEveMainWindow.cxx:96
 AliEveMainWindow.cxx:97
 AliEveMainWindow.cxx:98
 AliEveMainWindow.cxx:99
 AliEveMainWindow.cxx:100
 AliEveMainWindow.cxx:101
 AliEveMainWindow.cxx:102
 AliEveMainWindow.cxx:103
 AliEveMainWindow.cxx:104
 AliEveMainWindow.cxx:105
 AliEveMainWindow.cxx:106
 AliEveMainWindow.cxx:107
 AliEveMainWindow.cxx:108
 AliEveMainWindow.cxx:109
 AliEveMainWindow.cxx:110
 AliEveMainWindow.cxx:111
 AliEveMainWindow.cxx:112
 AliEveMainWindow.cxx:113
 AliEveMainWindow.cxx:114
 AliEveMainWindow.cxx:115
 AliEveMainWindow.cxx:116
 AliEveMainWindow.cxx:117
 AliEveMainWindow.cxx:118
 AliEveMainWindow.cxx:119
 AliEveMainWindow.cxx:120
 AliEveMainWindow.cxx:121
 AliEveMainWindow.cxx:122
 AliEveMainWindow.cxx:123
 AliEveMainWindow.cxx:124
 AliEveMainWindow.cxx:125
 AliEveMainWindow.cxx:126
 AliEveMainWindow.cxx:127
 AliEveMainWindow.cxx:128
 AliEveMainWindow.cxx:129
 AliEveMainWindow.cxx:130
 AliEveMainWindow.cxx:131
 AliEveMainWindow.cxx:132
 AliEveMainWindow.cxx:133
 AliEveMainWindow.cxx:134
 AliEveMainWindow.cxx:135
 AliEveMainWindow.cxx:136
 AliEveMainWindow.cxx:137
 AliEveMainWindow.cxx:138
 AliEveMainWindow.cxx:139
 AliEveMainWindow.cxx:140
 AliEveMainWindow.cxx:141
 AliEveMainWindow.cxx:142
 AliEveMainWindow.cxx:143
 AliEveMainWindow.cxx:144
 AliEveMainWindow.cxx:145
 AliEveMainWindow.cxx:146
 AliEveMainWindow.cxx:147
 AliEveMainWindow.cxx:148
 AliEveMainWindow.cxx:149
 AliEveMainWindow.cxx:150
 AliEveMainWindow.cxx:151
 AliEveMainWindow.cxx:152
 AliEveMainWindow.cxx:153
 AliEveMainWindow.cxx:154
 AliEveMainWindow.cxx:155
 AliEveMainWindow.cxx:156
 AliEveMainWindow.cxx:157
 AliEveMainWindow.cxx:158
 AliEveMainWindow.cxx:159
 AliEveMainWindow.cxx:160
 AliEveMainWindow.cxx:161
 AliEveMainWindow.cxx:162
 AliEveMainWindow.cxx:163
 AliEveMainWindow.cxx:164
 AliEveMainWindow.cxx:165
 AliEveMainWindow.cxx:166
 AliEveMainWindow.cxx:167
 AliEveMainWindow.cxx:168
 AliEveMainWindow.cxx:169
 AliEveMainWindow.cxx:170
 AliEveMainWindow.cxx:171
 AliEveMainWindow.cxx:172
 AliEveMainWindow.cxx:173
 AliEveMainWindow.cxx:174
 AliEveMainWindow.cxx:175
 AliEveMainWindow.cxx:176
 AliEveMainWindow.cxx:177
 AliEveMainWindow.cxx:178
 AliEveMainWindow.cxx:179
 AliEveMainWindow.cxx:180
 AliEveMainWindow.cxx:181
 AliEveMainWindow.cxx:182
 AliEveMainWindow.cxx:183
 AliEveMainWindow.cxx:184
 AliEveMainWindow.cxx:185
 AliEveMainWindow.cxx:186
 AliEveMainWindow.cxx:187
 AliEveMainWindow.cxx:188
 AliEveMainWindow.cxx:189
 AliEveMainWindow.cxx:190
 AliEveMainWindow.cxx:191
 AliEveMainWindow.cxx:192
 AliEveMainWindow.cxx:193
 AliEveMainWindow.cxx:194
 AliEveMainWindow.cxx:195
 AliEveMainWindow.cxx:196
 AliEveMainWindow.cxx:197
 AliEveMainWindow.cxx:198
 AliEveMainWindow.cxx:199
 AliEveMainWindow.cxx:200
 AliEveMainWindow.cxx:201
 AliEveMainWindow.cxx:202
 AliEveMainWindow.cxx:203
 AliEveMainWindow.cxx:204
 AliEveMainWindow.cxx:205
 AliEveMainWindow.cxx:206
 AliEveMainWindow.cxx:207
 AliEveMainWindow.cxx:208
 AliEveMainWindow.cxx:209
 AliEveMainWindow.cxx:210
 AliEveMainWindow.cxx:211
 AliEveMainWindow.cxx:212
 AliEveMainWindow.cxx:213
 AliEveMainWindow.cxx:214
 AliEveMainWindow.cxx:215
 AliEveMainWindow.cxx:216
 AliEveMainWindow.cxx:217
 AliEveMainWindow.cxx:218
 AliEveMainWindow.cxx:219
 AliEveMainWindow.cxx:220
 AliEveMainWindow.cxx:221
 AliEveMainWindow.cxx:222
 AliEveMainWindow.cxx:223
 AliEveMainWindow.cxx:224
 AliEveMainWindow.cxx:225
 AliEveMainWindow.cxx:226
 AliEveMainWindow.cxx:227
 AliEveMainWindow.cxx:228
 AliEveMainWindow.cxx:229
 AliEveMainWindow.cxx:230
 AliEveMainWindow.cxx:231
 AliEveMainWindow.cxx:232
 AliEveMainWindow.cxx:233
 AliEveMainWindow.cxx:234
 AliEveMainWindow.cxx:235
 AliEveMainWindow.cxx:236
 AliEveMainWindow.cxx:237
 AliEveMainWindow.cxx:238
 AliEveMainWindow.cxx:239
 AliEveMainWindow.cxx:240
 AliEveMainWindow.cxx:241
 AliEveMainWindow.cxx:242
 AliEveMainWindow.cxx:243
 AliEveMainWindow.cxx:244
 AliEveMainWindow.cxx:245
 AliEveMainWindow.cxx:246
 AliEveMainWindow.cxx:247
 AliEveMainWindow.cxx:248
 AliEveMainWindow.cxx:249
 AliEveMainWindow.cxx:250
 AliEveMainWindow.cxx:251
 AliEveMainWindow.cxx:252
 AliEveMainWindow.cxx:253
 AliEveMainWindow.cxx:254
 AliEveMainWindow.cxx:255
 AliEveMainWindow.cxx:256
 AliEveMainWindow.cxx:257
 AliEveMainWindow.cxx:258
 AliEveMainWindow.cxx:259
 AliEveMainWindow.cxx:260
 AliEveMainWindow.cxx:261
 AliEveMainWindow.cxx:262
 AliEveMainWindow.cxx:263
 AliEveMainWindow.cxx:264
 AliEveMainWindow.cxx:265
 AliEveMainWindow.cxx:266
 AliEveMainWindow.cxx:267
 AliEveMainWindow.cxx:268
 AliEveMainWindow.cxx:269
 AliEveMainWindow.cxx:270
 AliEveMainWindow.cxx:271
 AliEveMainWindow.cxx:272
 AliEveMainWindow.cxx:273
 AliEveMainWindow.cxx:274
 AliEveMainWindow.cxx:275
 AliEveMainWindow.cxx:276
 AliEveMainWindow.cxx:277
 AliEveMainWindow.cxx:278
 AliEveMainWindow.cxx:279
 AliEveMainWindow.cxx:280
 AliEveMainWindow.cxx:281
 AliEveMainWindow.cxx:282
 AliEveMainWindow.cxx:283
 AliEveMainWindow.cxx:284
 AliEveMainWindow.cxx:285
 AliEveMainWindow.cxx:286
 AliEveMainWindow.cxx:287
 AliEveMainWindow.cxx:288
 AliEveMainWindow.cxx:289
 AliEveMainWindow.cxx:290
 AliEveMainWindow.cxx:291
 AliEveMainWindow.cxx:292
 AliEveMainWindow.cxx:293
 AliEveMainWindow.cxx:294
 AliEveMainWindow.cxx:295
 AliEveMainWindow.cxx:296
 AliEveMainWindow.cxx:297
 AliEveMainWindow.cxx:298
 AliEveMainWindow.cxx:299
 AliEveMainWindow.cxx:300
 AliEveMainWindow.cxx:301
 AliEveMainWindow.cxx:302
 AliEveMainWindow.cxx:303
 AliEveMainWindow.cxx:304
 AliEveMainWindow.cxx:305
 AliEveMainWindow.cxx:306
 AliEveMainWindow.cxx:307
 AliEveMainWindow.cxx:308
 AliEveMainWindow.cxx:309
 AliEveMainWindow.cxx:310
 AliEveMainWindow.cxx:311
 AliEveMainWindow.cxx:312
 AliEveMainWindow.cxx:313
 AliEveMainWindow.cxx:314
 AliEveMainWindow.cxx:315
 AliEveMainWindow.cxx:316
 AliEveMainWindow.cxx:317
 AliEveMainWindow.cxx:318
 AliEveMainWindow.cxx:319
 AliEveMainWindow.cxx:320
 AliEveMainWindow.cxx:321
 AliEveMainWindow.cxx:322
 AliEveMainWindow.cxx:323
 AliEveMainWindow.cxx:324
 AliEveMainWindow.cxx:325
 AliEveMainWindow.cxx:326
 AliEveMainWindow.cxx:327
 AliEveMainWindow.cxx:328
 AliEveMainWindow.cxx:329
 AliEveMainWindow.cxx:330
 AliEveMainWindow.cxx:331
 AliEveMainWindow.cxx:332
 AliEveMainWindow.cxx:333
 AliEveMainWindow.cxx:334
 AliEveMainWindow.cxx:335
 AliEveMainWindow.cxx:336
 AliEveMainWindow.cxx:337
 AliEveMainWindow.cxx:338
 AliEveMainWindow.cxx:339
 AliEveMainWindow.cxx:340
 AliEveMainWindow.cxx:341
 AliEveMainWindow.cxx:342
 AliEveMainWindow.cxx:343
 AliEveMainWindow.cxx:344
 AliEveMainWindow.cxx:345
 AliEveMainWindow.cxx:346
 AliEveMainWindow.cxx:347
 AliEveMainWindow.cxx:348
 AliEveMainWindow.cxx:349
 AliEveMainWindow.cxx:350
 AliEveMainWindow.cxx:351
 AliEveMainWindow.cxx:352
 AliEveMainWindow.cxx:353
 AliEveMainWindow.cxx:354
 AliEveMainWindow.cxx:355
 AliEveMainWindow.cxx:356
 AliEveMainWindow.cxx:357
 AliEveMainWindow.cxx:358
 AliEveMainWindow.cxx:359
 AliEveMainWindow.cxx:360
 AliEveMainWindow.cxx:361
 AliEveMainWindow.cxx:362
 AliEveMainWindow.cxx:363
 AliEveMainWindow.cxx:364
 AliEveMainWindow.cxx:365
 AliEveMainWindow.cxx:366
 AliEveMainWindow.cxx:367
 AliEveMainWindow.cxx:368
 AliEveMainWindow.cxx:369
 AliEveMainWindow.cxx:370
 AliEveMainWindow.cxx:371
 AliEveMainWindow.cxx:372
 AliEveMainWindow.cxx:373
 AliEveMainWindow.cxx:374
 AliEveMainWindow.cxx:375
 AliEveMainWindow.cxx:376
 AliEveMainWindow.cxx:377
 AliEveMainWindow.cxx:378
 AliEveMainWindow.cxx:379
 AliEveMainWindow.cxx:380
 AliEveMainWindow.cxx:381
 AliEveMainWindow.cxx:382
 AliEveMainWindow.cxx:383
 AliEveMainWindow.cxx:384
 AliEveMainWindow.cxx:385
 AliEveMainWindow.cxx:386
 AliEveMainWindow.cxx:387
 AliEveMainWindow.cxx:388
 AliEveMainWindow.cxx:389
 AliEveMainWindow.cxx:390
 AliEveMainWindow.cxx:391
 AliEveMainWindow.cxx:392
 AliEveMainWindow.cxx:393
 AliEveMainWindow.cxx:394
 AliEveMainWindow.cxx:395
 AliEveMainWindow.cxx:396
 AliEveMainWindow.cxx:397
 AliEveMainWindow.cxx:398
 AliEveMainWindow.cxx:399
 AliEveMainWindow.cxx:400
 AliEveMainWindow.cxx:401
 AliEveMainWindow.cxx:402
 AliEveMainWindow.cxx:403
 AliEveMainWindow.cxx:404
 AliEveMainWindow.cxx:405
 AliEveMainWindow.cxx:406
 AliEveMainWindow.cxx:407
 AliEveMainWindow.cxx:408
 AliEveMainWindow.cxx:409
 AliEveMainWindow.cxx:410
 AliEveMainWindow.cxx:411
 AliEveMainWindow.cxx:412
 AliEveMainWindow.cxx:413
 AliEveMainWindow.cxx:414
 AliEveMainWindow.cxx:415
 AliEveMainWindow.cxx:416
 AliEveMainWindow.cxx:417
 AliEveMainWindow.cxx:418
 AliEveMainWindow.cxx:419
 AliEveMainWindow.cxx:420
 AliEveMainWindow.cxx:421
 AliEveMainWindow.cxx:422
 AliEveMainWindow.cxx:423
 AliEveMainWindow.cxx:424
 AliEveMainWindow.cxx:425
 AliEveMainWindow.cxx:426
 AliEveMainWindow.cxx:427
 AliEveMainWindow.cxx:428
 AliEveMainWindow.cxx:429
 AliEveMainWindow.cxx:430
 AliEveMainWindow.cxx:431
 AliEveMainWindow.cxx:432
 AliEveMainWindow.cxx:433
 AliEveMainWindow.cxx:434
 AliEveMainWindow.cxx:435
 AliEveMainWindow.cxx:436
 AliEveMainWindow.cxx:437
 AliEveMainWindow.cxx:438
 AliEveMainWindow.cxx:439
 AliEveMainWindow.cxx:440
 AliEveMainWindow.cxx:441
 AliEveMainWindow.cxx:442
 AliEveMainWindow.cxx:443
 AliEveMainWindow.cxx:444
 AliEveMainWindow.cxx:445
 AliEveMainWindow.cxx:446
 AliEveMainWindow.cxx:447
 AliEveMainWindow.cxx:448
 AliEveMainWindow.cxx:449
 AliEveMainWindow.cxx:450
 AliEveMainWindow.cxx:451
 AliEveMainWindow.cxx:452
 AliEveMainWindow.cxx:453
 AliEveMainWindow.cxx:454
 AliEveMainWindow.cxx:455
 AliEveMainWindow.cxx:456
 AliEveMainWindow.cxx:457
 AliEveMainWindow.cxx:458
 AliEveMainWindow.cxx:459
 AliEveMainWindow.cxx:460
 AliEveMainWindow.cxx:461
 AliEveMainWindow.cxx:462
 AliEveMainWindow.cxx:463
 AliEveMainWindow.cxx:464
 AliEveMainWindow.cxx:465
 AliEveMainWindow.cxx:466
 AliEveMainWindow.cxx:467