CXMainWindow.cpp 46.5 KB
Newer Older
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include "CXMainWindow.h"

#include "TStyle.h"
#include "TG3DLine.h"
#include "TApplication.h"
#include "TGraphErrors.h"
#include "TGMenu.h"
#include "TGSplitter.h"
#include "TRootEmbeddedCanvas.h"
#include "TGTab.h"
#include "TGStatusBar.h"
#include "TVirtualPadEditor.h"
#include "TFrame.h"
#include "TGFileBrowser.h"
#include "KeySymbols.h"
#include "TGListView.h"
#include "TClassMenuItem.h"
#include "TROOT.h"
#include "TGFSContainer.h"
#include "TBrowser.h"
#include "TClass.h"

#include "CXGateBox.h"
#include "CXBgdUtility.h"
#include "CXGuiToolbar.h"
#include "CXFileList.h"
#include "CXGuiLSPlayer.h"
#include "CXHist1DPlayer.h"
#include "CXHist2DPlayer.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
30
#include "CXRad2DPlayer.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
31
#include "CXGammaSearch.h"
32
#include "CXRadReader.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
33 34 35 36
#include "CXRadCubePlayer.h"
#include "CXSavedList.h"
#include "CXRadCubeTH1Proj.h"
#include "CXTH1Proj.h"
37
#include "CXArrow.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

using namespace std;

ULong_t CXred;
ULong_t CXblue;
ULong_t CXblack;
ULong_t CXgreen;

CXMainWindow::CXMainWindow(const TGWindow *p, UInt_t w, UInt_t h) : TGMainFrame(p, w, h)
{
    Init();
}

void CXMainWindow::Init()
{
    gClient->GetColorByName("red",  CXred);
    gClient->GetColorByName("blue", CXblue);
    gClient->GetColorByName("black",CXblack);
    gClient->GetColorByName("green",CXgreen);

    TGHorizontalFrame *fHf = new TGHorizontalFrame(this,GetWidth(),GetHeight());
    
    //------- Menu -----------

    //----------------Menu File--------------------
    
    fMenuFile = new TGPopupMenu(gClient->GetRoot());
    fMenuFile->AddEntry("New Canvas", M_New_Canvas, 0 , gClient->GetPicture("newcanvas.xpm"));
    fMenuFile->AddEntry("New Browser", M_New_Browser, 0, gClient->GetPicture("browser.xpm"));
    fMenuFile->AddEntry("Save Canvas as", M_Save_As, 0, gClient->GetPicture("bld_save.png"));
    fMenuFile->AddEntry("Save hist to ascii", M_Save_To_Ascii, 0, gClient->GetPicture("query_new.xpm"));
    fMenuFile->AddSeparator();
    fMenuFile->AddEntry("Exit", M_Exit, 0, gClient->GetPicture("bld_exit.png"));
    fMenuFile->Connect("Activated(Int_t)", "CXMainWindow", this, "HandleMenu(Int_t)");

    //----------------Menu View--------------------

    fMenuView = new TGPopupMenu(gClient->GetRoot());
    fMenuView->Connect("Activated(Int_t)", "CXMainWindow", this, "HandleMenu(Int_t)");

78
    fMenuView->AddEntry("Browse Files", M_FileListUtility,0,gClient->GetPicture("ed_open.png"));
79
    //    fMenuView->CheckEntry(M_FileListUtility);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
80 81
    IsFileListUtilityEnabled = true;

82
    fMenuView->AddEntry("Saved list", M_SavedList,0,gClient->GetPicture("bld_listbox.xpm"));
83
    //    fMenuView->CheckEntry(M_SavedList);
84
    IsSavedListEnabled = true;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
85

86
    fMenuView->AddSeparator();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
87

88
    fMenuView->AddEntry("Show editor", M_Editor,0,gClient->GetPicture("bld_edit.png"));
89
    //    fMenuView->CheckEntry(M_Editor);
90
    IsEditorEnabled = true;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
91

92 93 94 95 96 97
    //---------------- Menu Tools --------------------

    fMenuTools = new TGPopupMenu(gClient->GetRoot());

    fMenuTools->AddLabel("1D Tools...",gClient->GetPicture("h1_t.xpm"));
    fMenuTools->AddSeparator();
98

99
    fMenuTools->AddEntry("LS Player", M_LSPlayerUtility,0,gClient->GetPicture("levelscheme_t.png"));
100
    //    fMenuTools->CheckEntry(M_LSPlayerUtility);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
101 102
    IsLSPlayerToolEnabled = true;

103
    fMenuTools->AddEntry("Hist1D Player", M_Hist1DPlayer,0,gClient->GetPicture("FitTool.xpm"));
104
    //    fMenuTools->CheckEntry(M_Hist1DPlayer);
105 106 107
    IsHist1DPlayerEnabled= true;

    fMenuTools->AddEntry("background utility", M_BkdUtility,0,gClient->GetPicture("h1_t.xpm"));
108
    //    fMenuTools->CheckEntry(M_BkdUtility);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
109 110
    IsBkdUtilityEnabled = true;

111 112 113
    fMenuTools->AddSeparator();
    fMenuTools->AddLabel("2D Tools...",gClient->GetPicture("h2_t.xpm"));
    fMenuTools->AddSeparator();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
114

115
    fMenuTools->AddEntry("Hist2D Player", M_Hist2DPlayer,0,gClient->GetPicture("h2_t.xpm"));
116
    //    fMenuTools->CheckEntry(M_Hist2DPlayer);
117
    IsHist2DPlayerEnabled= true;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
118

119
    fMenuTools->AddEntry("Rad2D Player", M_Rad2DPlayer,0,gClient->GetPicture("rw3.gif"));
120
    //    fMenuTools->CheckEntry(M_Rad2DPlayer);
121
    IsRad2DPlayerEnabled= true;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
122

123 124 125 126 127
    fMenuTools->AddSeparator();
    fMenuTools->AddLabel("3D Tools...",gClient->GetPicture("h3_t.xpm"));
    fMenuTools->AddSeparator();

    fMenuTools->AddEntry("RadCube Player", M_RadCubePlayer,0,gClient->GetPicture("rw3.gif"));
128
    //    fMenuTools->CheckEntry(M_RadCubePlayer);
129
    IsRadCubePlayerEnabled= true;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
130 131

    fMenuTools->AddSeparator();
132 133 134 135
    fMenuTools->AddLabel("Others...");
    fMenuTools->AddSeparator();

    fMenuTools->AddEntry("Gamma search", M_GammaSearch,0,gClient->GetPicture("ed_find.png"));
Jérémie Dudouet's avatar
Jérémie Dudouet committed
136 137 138

    fMenuTools->Connect("Activated(Int_t)", "CXMainWindow", this, "HandleMenu(Int_t)");

Jérémie Dudouet's avatar
Jérémie Dudouet committed
139 140 141
    //---------------- Menu Options --------------------

    fMenuOptions = new TGPopupMenu(gClient->GetRoot());
142 143
    fMenuOptions->AddEntry("Show Stats", M_ShowStats,0,gClient->GetPicture("stats.png"));
    fMenuOptions->AddEntry("Show Title", M_ShowTitle,0,gClient->GetPicture("eve_text.gif"));
Jérémie Dudouet's avatar
Jérémie Dudouet committed
144 145 146 147 148 149

    gStyle->SetOptTitle(0);
    gStyle->SetOptStat(0);

    fMenuOptions->Connect("Activated(Int_t)", "CXMainWindow", this, "HandleMenu(Int_t)");

Jérémie Dudouet's avatar
Jérémie Dudouet committed
150 151 152 153 154
    fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
    this->AddFrame(fMenuBar, new TGLayoutHints(kLHintsExpandX));
    fMenuBar->AddPopup("File", fMenuFile, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
    fMenuBar->AddPopup("View", fMenuView, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
    fMenuBar->AddPopup("Tools", fMenuTools, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
Jérémie Dudouet's avatar
Jérémie Dudouet committed
155
    fMenuBar->AddPopup("Options", fMenuOptions, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
Jérémie Dudouet's avatar
Jérémie Dudouet committed
156 157 158 159 160 161 162 163 164 165 166 167

    TGHorizontal3DLine *fline = new TGHorizontal3DLine(this);
    AddFrame(fline,new TGLayoutHints(kLHintsExpandX));

    //    //////////////////******************** partie gauche ********************////////////////////////////////
    
    fTGCanvas = new TGCanvas(fHf, 10, 10, kFixedWidth);
    fHf->AddFrame(fTGCanvas, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));

    TGVerticalFrame *VFrame = new TGVerticalFrame(fTGCanvas->GetViewPort());
    fTGCanvas->SetContainer(VFrame);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
168
    fTGCanvas->Resize(GetWidth()*0.27, GetHeight());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
169 170 171 172 173 174 175

    fMainTab = new TGTab(VFrame);
    VFrame->AddFrame(fMainTab, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
    fMainTab->Connect("CloseTab(Int_t)", "CXMainWindow", this, "CloseToolsTab(Int_t)");

    TString Name;

Jérémie Dudouet's avatar
Jérémie Dudouet committed
176 177 178 179 180 181 182 183 184
    // ------- Background subtract Tool -----------
    Name = "Saved List";
    fSavedListTab = fMainTab->AddTab(Name);
    fSavedList = new CXSavedList(fSavedListTab,10,10);
    fSavedList->SetMainWindow(this);
    fSavedList->SetName(Name);
    fSavedListTab->AddFrame(fSavedList, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
    ToggleTab(IsSavedListEnabled,M_SavedList,fSavedListTab,Name);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
    // ------- Background subtract Tool -----------
    Name = "Bkgd Player";
    fBkdToolTab = fMainTab->AddTab(Name);
    fBkdSubtract = new CXBgdUtility(fBkdToolTab,10,10);
    fBkdSubtract->SetMainWindow(this);
    fBkdSubtract->SetName(Name);
    fBkdToolTab->AddFrame(fBkdSubtract, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
    ToggleTab(IsBkdUtilityEnabled,M_BkdUtility,fBkdToolTab,Name);

    // ------- Hist1D Player -----------
    Name = "1D Player";
    fHist1DPlayerTab = fMainTab->AddTab(Name);
    fHist1DPlayer = new CXHist1DPlayer(fHist1DPlayerTab,10,10);
    fHist1DPlayer->SetMainWindow(this);
    fHist1DPlayer->SetName(Name);
    fHist1DPlayerTab->AddFrame(fHist1DPlayer, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
    ToggleTab(IsHist1DPlayerEnabled,M_Hist1DPlayer,fHist1DPlayerTab,Name);

    // ------- Hist2D Player -----------
    Name = "2D Player";
    fHist2DPlayerTab = fMainTab->AddTab(Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
206
    fHist2DPlayer = new CXHist2DPlayer(fHist2DPlayerTab,10,10,this);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
207 208 209 210
    fHist2DPlayer->SetName(Name);
    fHist2DPlayerTab->AddFrame(fHist2DPlayer, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
    ToggleTab(IsHist2DPlayerEnabled,M_Hist2DPlayer,fHist2DPlayerTab,Name);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
211 212 213 214 215 216 217 218
    // ------- Rad2D Player -----------
    Name = "Rad2D Player";
    fRad2DPlayerTab = fMainTab->AddTab(Name);
    fRad2DPlayer = new CXRad2DPlayer(fRad2DPlayerTab,10,10,this);
    fRad2DPlayer->SetName(Name);
    fRad2DPlayerTab->AddFrame(fRad2DPlayer, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
    ToggleTab(IsRad2DPlayerEnabled,M_Rad2DPlayer,fRad2DPlayerTab,Name);

219 220 221
    // ------- RadCube Player -----------
    Name = "RadCube Player";
    fRadCubePlayerTab = fMainTab->AddTab(Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
222
    fRadCubePlayer = new CXRadCubePlayer(fRadCubePlayerTab,10,10,this);
223 224 225
    fRadCubePlayer->SetMainWindow(this);
    fRadCubePlayer->SetName(Name);
    fRadCubePlayerTab->AddFrame(fRadCubePlayer, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
Jérémie Dudouet's avatar
Jérémie Dudouet committed
226
    ToggleTab(IsRadCubePlayerEnabled,M_RadCubePlayer,fRadCubePlayerTab,Name);
227

Jérémie Dudouet's avatar
Jérémie Dudouet committed
228 229 230 231 232 233 234 235 236
    // ------- LS Player Tool -----------
    Name = "LS Player";
    fLSPlayerToolTab = fMainTab->AddTab(Name);
    fLSPlayerTool = new CXGuiLSPlayer(fLSPlayerToolTab,10,10);
    fLSPlayerTool->SetMainWindow(this);
    fLSPlayerTool->SetName(Name);
    fLSPlayerToolTab->AddFrame(fLSPlayerTool, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
    ToggleTab(IsLSPlayerToolEnabled,M_LSPlayerUtility,fLSPlayerToolTab,Name);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
237
    //    // ------- Brows File Tool -----------
Jérémie Dudouet's avatar
Jérémie Dudouet committed
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
    Name = "Files";
    fFileListTab = fMainTab->AddTab(Name);
    fFileList = new CXFileList(fFileListTab,GetWidth(), GetHeight());
    fFileList->SetMainWindow(this);
    fFileList->SetName(Name);
    fFileListTab->AddFrame(fFileList, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
    fMainTab->GetTabTab(fFileList->GetName())->ShowClose();
    ToggleTab(IsFileListUtilityEnabled,M_FileListUtility,fFileListTab,fFileList->GetName());

    //    //////////////////******************** partie droite ********************////////////////////////////////
    
    fSplitter = new TGVFileSplitter(fHf,2,2);
    fSplitter->SetFrame(fTGCanvas, kTRUE);
    fHf->AddFrame(fSplitter, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
    fSplitter->Connect("LayoutHeader(TGFrame *)", "CXMainWindow", this, "DoRefresh()");

    fVFRight = new TGVerticalFrame(fHf, 10, 10);
    fHf->AddFrame(fVFRight, new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY));
    
    fListOfCanvases = new TList();
    
    fCanvasTab = new TGTab(fVFRight);
    fCanvasTab->Connect("CloseTab(Int_t)", "CXMainWindow", this, "CloseCanvasTab(Int_t)");
    fCanvasTab->Connect("Selected(Int_t)", "CXMainWindow", this, "DoTab(Int_t)");
    fVFRight->AddFrame(fCanvasTab, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5));

    NewTab();
    DoTab();

    //------- Editor -----------
    fEditorTab = fMainTab->AddTab("Editor");
    fEditorTab->SetEditable();
    fEditor = TVirtualPadEditor::LoadEditor();
    fEditor->SetGlobal(kFALSE);
    fEditorTab->SetEditable(kFALSE);
    ToggleTab(IsEditorEnabled,M_Editor,fEditorTab,"Editor");

    // status bar
    Int_t parts[] = {20 , 20 , 20 , 20 ,20};
    fStatusBar = new TGStatusBar(fVFRight,50,10,kHorizontalFrame);
    fStatusBar->SetParts(parts,5);
    fStatusBar->Draw3DCorner(kFALSE);
    fVFRight->AddFrame(fStatusBar, new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 0, 0, 2, 0));
    
    AddFrame(fHf, new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY));
    
    UpdateContextMenus();

    // What to clean up in destructor
    SetCleanup(kDeepCleanup);
    
    // Set a name to the main frame
    SetWindowName("Cubix Spectra Player");
291 292 293
    SetIconPixmap("Cubix.png");
    SetIconName("Cubix");

Jérémie Dudouet's avatar
Jérémie Dudouet committed
294 295 296 297 298 299 300 301
    MapSubwindows();
    Layout();
    Resize(GetDefaultSize());
    MapWindow();

    gSystem->ProcessEvents();

    ToggleTab(IsFileListUtilityEnabled,M_FileListUtility,fFileListTab,fFileList->GetName());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
302 303 304 305

    fListOfSavedGates = new TList;
    fListOfSavedGates->SetOwner();
    fListOfSavedGates->SetName("ListOfGates");
Jérémie Dudouet's avatar
Jérémie Dudouet committed
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
}

CXMainWindow::~CXMainWindow()
{
    
}

void CXMainWindow::HandleMovement(Int_t EventType, Int_t EventX, Int_t EventY, TObject *selected)
{
    fSelectedPad = fCanvas->GetClickSelectedPad();

    if(gPad && selected != nullptr)
    {
        const char *text0, *text1, *text2, *text4;
        char text3[50];
        text0 = selected->ClassName();
        SetStatusText(text0,0);
        text1 = selected->GetTitle();
        SetStatusText(text1,1);
        text2 = selected->GetName();
        SetStatusText(text2,2);

        if(fCanvas->GetCrosshair() == 1 && (selected->InheritsFrom("TFrame") || selected->InheritsFrom("TH1") || selected->InheritsFrom("CXCanvas") || selected->InheritsFrom("TPad")))
        {
            if (EventType == kButton2){
                fRefX = gPad->AbsPixeltoX(EventX);
                fRefY = gPad->AbsPixeltoY(EventY);
            }
            if (EventType == kButton1){
                fRefX = 0;
                fRefY = 0;
            }
        }

        if (EventType == kKeyPress)
            sprintf(text3, "%c", (char) EventY);
        else
            sprintf(text3, "%.2f,%.2f", gPad->AbsPixeltoX(EventX)- fRefX, gPad->AbsPixeltoY(EventY) - fRefY );
        SetStatusText(text3,3);

        text4 = selected->GetObjectInfo(EventX,EventY);
        SetStatusText(text4,4);
    }

    //    if (EventType == kButton1Down)
    //    {
    //        if(fMainTab->GetCurrentTab() == fMainTab->GetTabTab("Editor")) fMainTab->CloseTab(fMainTab->GetCurrent());
    //    }

    /// Recuperation de la derniere position de la souris

357
    if(EventType == kMouseMotion) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
358 359 360
        fCanvas->AbsPixeltoXY(EventX,EventY,fLastXPosition,fLastYPosition);
    }

361
    if(EventType == kKeyPress) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
362
        if((EKeySym)EventY==kKey_f && !fCTRL) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
363 364 365 366
            if(IsHist1DPlayerEnabled==false)
                ToggleTab(IsHist1DPlayerEnabled,M_Hist1DPlayer,fHist1DPlayerTab,fHist1DPlayer->GetName());
            fMainTab->SetTab(fHist1DPlayer->GetName());

Jérémie Dudouet's avatar
Jérémie Dudouet committed
367
            fHist1DPlayer->NewFit();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
368
        }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
369
        if((EKeySym)EventY==kKey_f && fCTRL) {
370
            fHist1DPlayer->DoFit();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
371 372
        }
        if((EKeySym)EventY==kKey_s && !fCTRL) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
373 374 375 376
            if(IsHist1DPlayerEnabled==false)
                ToggleTab(IsHist1DPlayerEnabled,M_Hist1DPlayer,fHist1DPlayerTab,fHist1DPlayer->GetName());
            fMainTab->SetTab(fHist1DPlayer->GetName());

Jérémie Dudouet's avatar
Jérémie Dudouet committed
377
            fHist1DPlayer->PeakSearchClear();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
378 379
            fHist1DPlayer->PeakSearch();
        }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
380 381 382
        if((EKeySym)EventY==kKey_c && !fCTRL) {
            fHist1DPlayer->ClearFits();
            fHist1DPlayer->PeakSearchClear();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
383
        }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
384
        if((EKeySym)EventY==kKey_n && !fCTRL) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
385 386
            NewTab();
        }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
387
        if((EKeySym)EventY==kKey_S && !fCTRL && selected && (selected->InheritsFrom("TH1") || selected->InheritsFrom("TGraph") || selected->InheritsFrom("TF1") )) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
388 389
            AddToStoredSpectra(selected);
        }
390 391 392
        if((EKeySym)EventY==kKey_r && !fCTRL && selected && (selected->InheritsFrom(CXArrowBox::Class()))) {
            ((CXArrowBox*)selected)->Clean();
        }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
393 394 395
    }

    /// Don't work with the touch pad
Jérémie Dudouet's avatar
Jérémie Dudouet committed
396 397 398 399 400
    //    if(EventType == kMouseMotion && fLastEventType == kButton1Up && EventX==fLastEventX && EventY==fLastEventY ) //equivalent to escape
    //    {
    //        if(fHist1DPlayer->IsCurrentFit())
    //            fHist1DPlayer->EndFit();
    //    }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426

    fLastEventType = EventType;
    fLastEventX = EventX;
    fLastEventY = EventY;
    fLastSelected = selected;

}

void CXMainWindow::SetStatusText(const char *txt, Int_t pi)
{
    // Set text in status bar.
    if(fStatusBar!=0x0) fStatusBar->SetText(txt,pi);
}

void CXMainWindow::CloseToolsTab(Int_t tabnr)
{
    TGTabElement *tab = fMainTab->GetTabTab(tabnr);
    TString Name = tab->GetText()->Data();
    if(Name==fFileList->GetName())
        ToggleTab(IsFileListUtilityEnabled,M_FileListUtility,fFileListTab,Name);
    else if(Name==fLSPlayerTool->GetName())
        ToggleTab(IsLSPlayerToolEnabled,M_LSPlayerUtility,fLSPlayerToolTab,Name);
    else if(Name==fHist1DPlayer->GetName())
        ToggleTab(IsHist1DPlayerEnabled,M_Hist1DPlayer,fHist1DPlayerTab,Name);
    else if(Name==fHist2DPlayer->GetName())
        ToggleTab(IsHist2DPlayerEnabled,M_Hist2DPlayer,fHist2DPlayerTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
427 428
    else if(Name==fRad2DPlayer->GetName())
        ToggleTab(IsRad2DPlayerEnabled,M_Rad2DPlayer,fRad2DPlayerTab,Name);
429 430
    else if(Name==fRadCubePlayer->GetName())
        ToggleTab(IsRadCubePlayerEnabled,M_RadCubePlayer,fRadCubePlayerTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
431 432 433 434
    else if(Name=="Editor")
        ToggleTab(IsEditorEnabled,M_Editor,fEditorTab,Name);
    else if(Name==fBkdSubtract->GetName())
        ToggleTab(IsBkdUtilityEnabled,M_BkdUtility,fBkdToolTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
435 436
    else if(Name==fSavedList->GetName())
        ToggleTab(IsSavedListEnabled,M_SavedList,fSavedListTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
}

void CXMainWindow::CloseTab(TGTab *tab, Int_t tabnr)
{
    for(int i=0 ; i<fCanvas->GetListOfPrimitives()->GetEntries() ; i++)
    {
        TObject *o = fCanvas->GetListOfPrimitives()->At(i);
        if(o->InheritsFrom("TH1"))
            delete o;
    }

    TGFrameElement *el = 0;
    if (tab->GetTabContainer(tabnr))
        el = (TGFrameElement *)tab->GetTabContainer(tabnr)->GetList()->First();
    
    if (el && el->fFrame) {
        el->fFrame->Disconnect("ProcessedConfigure(Event_t*)");
        el->fFrame->SetFrameElement(0);
        if (el->fFrame->InheritsFrom("TGMainFrame")) {
            Bool_t sleep = (el->fFrame->InheritsFrom("TRootCanvas")) ? kTRUE : kFALSE;
            ((TGMainFrame *)el->fFrame)->CloseWindow();
            if (sleep)
                gSystem->Sleep(150);
            gSystem->ProcessEvents();
        }
        else
            delete el->fFrame;
        el->fFrame = 0;
        if (el->fLayout && (el->fLayout != fgDefaultHints) &&
                (el->fLayout->References() > 0)) {
            el->fLayout->RemoveReference();
            if (!el->fLayout->References()) {
                delete el->fLayout;
            }
        }
        tab->GetTabContainer(tabnr)->GetList()->Remove(el);
        delete el;
        tab->RemoveTab(tabnr);
    }
    
    if(tab == fCanvasTab) fListOfCanvases->RemoveAt(tabnr);
}

void CXMainWindow::DoTab(Int_t tabnr)
{
    fCanvas = (CXCanvas*)fListOfCanvases->At(tabnr);
    fSelectedPad = fCanvas->cd();
    if(fCanvas->GetUniqueID() == 666)
        fSelectedPad = fCanvas->cd(1);
    fCanvas->SetSelectedPad((TPad*)fSelectedPad);
    fCanvas->Update();

    //------- Editor -----------
    if(fEditorTab != nullptr)
    {
        delete fEditor;
        fEditorTab->SetEditable();
        fEditor = TVirtualPadEditor::LoadEditor();
        fEditor->SetGlobal(kFALSE);
        fEditorTab->SetEditable(kFALSE);
    }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518

    TString name = fCanvasTab->GetTabTab(tabnr)->GetText()->Data();

    if(name.BeginsWith("RadCube")) {
        if(IsRadCubePlayerEnabled)
            fMainTab->SetTab(fRadCubePlayer->GetName());
        else
            ToggleTab(IsRadCubePlayerEnabled,M_RadCubePlayer,fRadCubePlayerTab,fRadCubePlayer->GetName());
    }
    else if(name.BeginsWith("RadGG")) {
        if(IsRad2DPlayerEnabled)
            fMainTab->SetTab(fRad2DPlayer->GetName());
        else
            ToggleTab(IsRad2DPlayerEnabled,M_Rad2DPlayer,fRad2DPlayerTab,fRad2DPlayer->GetName());
    }
    else if(name.BeginsWith("GxG")) {
        if(IsHist2DPlayerEnabled)
            fMainTab->SetTab(fHist2DPlayer->GetName());
        else
            ToggleTab(IsHist2DPlayerEnabled,M_Hist2DPlayer,fHist2DPlayerTab,fHist2DPlayer->GetName());
    }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
}

void CXMainWindow::NewTab(Int_t px, Int_t py, TString name)
{
    TString TabName = Form("Canvas %d",fCanvasTab->GetNumberOfTabs());
    if(name != "")
        TabName = name;

    while(fCanvasTab->GetTabTab(TabName))
    {
        TObjArray *arr = TabName.Tokenize("_");
        TString last = arr->Last()->GetName();
        delete arr;

        if(last.IsDigit())
        {
            Int_t n = last.Atoi();
            TabName.ReplaceAll(Form("_%d",n),Form("_%d",n+1));
        }
        else
        {
            TabName.Append("_2");
        }
    }
    
    TGCompositeFrame *atab = fCanvasTab->AddTab(TabName);
    fCanvasTab->GetTabTab(TabName)->ShowClose();

    fToolBar = new CXGuiToolbar(atab, 60, 20, kHorizontalFrame);

    atab->AddFrame(fToolBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX));

    fRootCanvas = new TRootEmbeddedCanvas("ec1", atab);
    atab->AddFrame(fRootCanvas, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5));
    Int_t canvasid = fRootCanvas->GetCanvasWindowId();
    fCanvas = new CXCanvas(TabName.Copy().ReplaceAll(" ","_"), 10, 10, canvasid);
    fCanvas->SetMainWindow(this);
    fListOfCanvases->Add(fCanvas);
    fCanvas->ToggleToolBar();
    fRootCanvas->AdoptCanvas(fCanvas);
    fRootCanvas->GetContainer()->Connect("ProcessedEvent(Event_t*)", "CXMainWindow", this, "ProcessedKeyEvent(Event_t*)");

Jérémie Dudouet's avatar
Jérémie Dudouet committed
561 562 563 564
    fCanvas->SetRightMargin(0.01);
    fCanvas->SetBottomMargin(0.09);
    fCanvas->SetLeftMargin(0.083);
    fCanvas->SetTopMargin(0.04);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597

    fCanvas->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)", "CXMainWindow", this, "HandleMovement(Int_t,Int_t,Int_t, TObject*)");

    if(px*py>1)
    {
        fCanvas->SetUniqueID(666);
        fCanvas->cd();
        fCanvas->Divide(px,py,0.001,0.001);
        fCanvas->Update();

        for(int i=0 ;i<px*py ; i++){
            TVirtualPad *pad = fCanvas->GetPad(i+1);
            pad->cd();
            pad->SetLeftMargin(0.05);
            pad->SetRightMargin(fCanvas->GetRightMargin());
            pad->SetBottomMargin(fCanvas->GetBottomMargin());
            pad->SetTopMargin(fCanvas->GetTopMargin());
            pad->DrawFrame(0,0,1,1);
            pad->Update();
            pad->SetBit(TPad::kCannotMove);
            pad->GetFrame()->SetBit(TObject::kCannotPick);
        }

        fCanvas->SetClickSelectedPad((TPad*) fCanvas->GetPad(1));
        fSelectedPad = (TPad*) fCanvas->GetPad(1);
    }
    else
    {
        fCanvas->DrawFrame(0,0,1,1);
        fCanvas->SetClickSelectedPad((TPad*)fCanvas);
        fSelectedPad = (TPad*) fCanvas;
    }

Jérémie Dudouet's avatar
Jérémie Dudouet committed
598 599
    fCanvas->SetNPads(px*py);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
    fCanvas->Update();
    fCanvas->GetFrame()->SetBit(TObject::kCannotPick);

    fCanvasTab->SetTab(fCanvasTab->GetNumberOfTabs()-1);

    fToolBar->SetCanvas(fCanvas);

    fCanvasTab->MapSubwindows();
    fCanvasTab->Layout();
}

void CXMainWindow::HandleMenu(Int_t id)
{
    // Handle menu items.
    switch (id) {
    case M_New_Canvas:
        NewTab();
        break;
    case M_New_Browser:
        new TBrowser;
        break;
    case M_Save_As:
        fCanvas->SaveCanvasAs();
        break;
    case M_Save_To_Ascii:
        SaveToAscii();
        break;
    case M_Exit:
        CloseWindow();
        break;
    case M_Editor:
        ToggleTab(IsEditorEnabled,M_Editor,fEditorTab,"Editor");
        break;
    case M_BkdUtility:
        ToggleTab(IsBkdUtilityEnabled,M_BkdUtility,fBkdToolTab,fBkdSubtract->GetName());
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
636 637 638
    case M_SavedList:
        ToggleTab(IsSavedListEnabled,M_SavedList,fSavedListTab,fSavedList->GetName());
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
639 640 641 642 643 644
    case M_Hist1DPlayer:
        ToggleTab(IsHist1DPlayerEnabled,M_Hist1DPlayer,fHist1DPlayerTab,fHist1DPlayer->GetName());
        break;
    case M_Hist2DPlayer:
        ToggleTab(IsHist2DPlayerEnabled,M_Hist2DPlayer,fHist2DPlayerTab,fHist2DPlayer->GetName());
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
645 646 647
    case M_Rad2DPlayer:
        ToggleTab(IsRad2DPlayerEnabled,M_Rad2DPlayer,fRad2DPlayerTab,fRad2DPlayer->GetName());
        break;
648 649 650
    case M_RadCubePlayer:
        ToggleTab(IsRadCubePlayerEnabled,M_RadCubePlayer,fRadCubePlayerTab,fRadCubePlayer->GetName());
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
651 652 653 654 655 656
    case M_LSPlayerUtility:
        ToggleTab(IsLSPlayerToolEnabled,M_LSPlayerUtility,fLSPlayerToolTab,fLSPlayerTool->GetName());
        break;
    case M_FileListUtility:
        ToggleTab(IsFileListUtilityEnabled,M_FileListUtility,fFileListTab,fFileList->GetName());
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
    case M_ShowStats:
        IsStatsShown = 1-IsStatsShown;
        if(IsStatsShown) {
            fMenuOptions->CheckEntry(M_ShowStats);
            gStyle->SetOptStat(1000011);
        }
        else {
            fMenuOptions->UnCheckEntry(M_ShowStats);
            gStyle->SetOptStat(0);
        }
        RefreshPads();
        break;
    case M_ShowTitle:
        IsTitleShown = 1-IsTitleShown;
        if(IsTitleShown) {
            fMenuOptions->CheckEntry(M_ShowTitle);
            gStyle->SetOptTitle(1);
        }
        else {
            fMenuOptions->UnCheckEntry(M_ShowTitle);
            gStyle->SetOptTitle(0);
        }
        RefreshPads();
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
    case M_GammaSearch:
        if(fGammaSearchWindow == nullptr)
            fGammaSearchWindow = new CXGammaSearch(gClient->GetRoot(),gClient->GetRoot(),1200,450, this);
        else
            fGammaSearchWindow->MapRaised();
        break;

        if(gPad != 0x0)
        {
            gPad->Modified();
            gPad->Update();
        }
        break;
    }
}

void CXMainWindow::ToggleTab(Bool_t &Enable, ETestCommandIdentifiers id, TGCompositeFrame *tab, const char * name)
{
    if(!Enable)
    {
701 702 703 704
        //        if(fMenuView->GetEntry(id))
        //            fMenuView->CheckEntry(id);
        //        if(fMenuTools->GetEntry(id))
        //            fMenuTools->CheckEntry(id);
705

Jérémie Dudouet's avatar
Jérémie Dudouet committed
706 707 708 709 710 711 712
        fMainTab->AddTab(name,tab);

        fMainTab->SetTab(name);
        fMainTab->GetTabTab(name)->ShowClose();

        if(tab != fEditorTab) tab->MapSubwindows();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
        if(fMainTab->GetNumberOfTabs()>3){
            TString Name = fMainTab->GetTabTab(0)->GetText()->GetString();

            if(Name==fFileList->GetName())
                ToggleTab(IsFileListUtilityEnabled,M_FileListUtility,fFileListTab,Name);
            else if(Name==fLSPlayerTool->GetName())
                ToggleTab(IsLSPlayerToolEnabled,M_LSPlayerUtility,fLSPlayerToolTab,Name);
            else if(Name==fHist1DPlayer->GetName())
                ToggleTab(IsHist1DPlayerEnabled,M_Hist1DPlayer,fHist1DPlayerTab,Name);
            else if(Name==fHist2DPlayer->GetName())
                ToggleTab(IsHist2DPlayerEnabled,M_Hist2DPlayer,fHist2DPlayerTab,Name);
            else if(Name==fRad2DPlayer->GetName())
                ToggleTab(IsRad2DPlayerEnabled,M_Rad2DPlayer,fRad2DPlayerTab,Name);
            else if(Name==fRadCubePlayer->GetName())
                ToggleTab(IsRadCubePlayerEnabled,M_RadCubePlayer,fRadCubePlayerTab,Name);
            else if(Name=="Editor")
                ToggleTab(IsEditorEnabled,M_Editor,fEditorTab,Name);
            else if(Name==fBkdSubtract->GetName())
                ToggleTab(IsBkdUtilityEnabled,M_BkdUtility,fBkdToolTab,Name);
            else if(Name==fSavedList->GetName())
                ToggleTab(IsSavedListEnabled,M_SavedList,fSavedListTab,Name);
        }

        fMainTab->SetTab(name);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
738 739 740 741
        Layout();
    }
    else
    {
742 743 744 745
        //        if(fMenuView->GetEntry(id))
        //            fMenuView->UnCheckEntry(id);
        //        if(fMenuTools->GetEntry(id))
        //            fMenuTools->UnCheckEntry(id);
746

Jérémie Dudouet's avatar
Jérémie Dudouet committed
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
        fMainTab->SetTab(name);
        fMainTab->RemoveTab(fMainTab->GetCurrent());
    }

    Enable = !Enable;
}


void CXMainWindow::SaveCanvasAs()
{
    
    const char* SaveAsTypes[] = {
        "PDF",          "*.pdf",
        "PostScript",   "*.ps",
        "Encapsulated PostScript", "*.eps",
        "SVG",          "*.svg",
        "TeX",          "*.tex",
        "GIF",          "*.gif",
        "ROOT macros",  "*.C",
        "ROOT files",   "*.root",
        "XML",          "*.xml",
        "PNG",          "*.png",
        "XPM",          "*.xpm",
        "JPEG",         "*.jpg",
        "TIFF",         "*.tiff",
        "XCF",          "*.xcf",
        "All files",    "*",
        0,              0
    };
    
    TString workdir = gSystem->WorkingDirectory();
    static TString dir(".");
    static Int_t typeidx = 0;
    static Bool_t overwr = kFALSE;
    TGFileInfo fi;
    fi.fFileTypes   = SaveAsTypes;
    fi.fIniDir      = StrDup(dir);
    fi.fFileTypeIdx = typeidx;
    fi.fOverwrite   = overwr;
    new TGFileDialog(gClient->GetDefaultRoot(), gClient->GetDefaultRoot(), kFDSave, &fi);
    gSystem->ChangeDirectory(workdir.Data());
    if (!fi.fFilename) return;
    TString fn = fi.fFilename;
    dir     = fi.fIniDir;
    typeidx = fi.fFileTypeIdx;
    overwr  = fi.fOverwrite;

    if(!fn.EndsWith(fi.fFileTypes[1]))
        fn.Append(fi.fFileTypes[1]);

    fCanvas->SaveAs(fn);
}

void CXMainWindow::DoRefresh()
{
    fMainTab->Resize(10,10);
    Layout();
}

Jérémie Dudouet's avatar
Jérémie Dudouet committed
806 807 808 809 810 811 812 813 814 815 816 817 818 819
void CXMainWindow::RefreshPads()
{   
    TList *pList = fCanvas->GetListOfPrimitives();
    TObjOptLink *lnk = 0;
    if (pList) lnk = (TObjOptLink*)pList->FirstLink();
    TObject *obj;
    while (lnk) {
        obj = lnk->GetObject();
        if (obj->InheritsFrom(TPad::Class())) {
            ((TPad*)obj)->Modified();
        }
        lnk = (TObjOptLink*)lnk->Next();
    }

Jérémie Dudouet's avatar
Jérémie Dudouet committed
820
    fCanvas->Modified();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
821
    fCanvas->Update();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
}

void CXMainWindow::CloseWindow()
{
    if(fGammaSearchWindow)
        fGammaSearchWindow->CloseWindow();

    UnmapWindow();
    DeleteWindow();//  launch a delete but after a short time like a thread.

    cout << " Bye Bye Cubix!" <<endl;

    gApplication->SetReturnFromRun(false);
    gApplication->Terminate(false);
}

Jérémie Dudouet's avatar
Jérémie Dudouet committed
838
TH1 *CXMainWindow::GetHisto(TVirtualPad *pad, bool GetFirst)
Jérémie Dudouet's avatar
Jérémie Dudouet committed
839
{
Jérémie Dudouet's avatar
Jérémie Dudouet committed
840
    TH1 *hist = nullptr;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
841

Jérémie Dudouet's avatar
Jérémie Dudouet committed
842 843 844 845
    if(pad == nullptr && fSelectedPad == nullptr) {
        fCanvas->cd();
        fSelectedPad = fCanvas->cd();
    }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
846 847 848
    if(pad == nullptr)
        pad = fSelectedPad;

Jérémie Dudouet's avatar
Jérémie Dudouet committed
849 850
    TObjOptLink *lnk = nullptr;
    TObject *obj = nullptr;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
851

Jérémie Dudouet's avatar
Jérémie Dudouet committed
852 853 854 855 856 857 858 859
    TList *pList = pad->GetListOfPrimitives();
    if (pList) lnk = (TObjOptLink*)pList->FirstLink();

    while (lnk) {
        obj = lnk->GetObject();
        if (obj->InheritsFrom(TH1::Class())) {
            hist = dynamic_cast<TH1*>(obj);
            if(GetFirst) return hist;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
860
        }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
861
        lnk = (TObjOptLink*)lnk->Next();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
862 863
    }

Jérémie Dudouet's avatar
Jérémie Dudouet committed
864
    return hist;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
865 866 867 868
}

void CXMainWindow::UpdateContextMenus()
{
869
    /// TH1F ///
Jérémie Dudouet's avatar
Jérémie Dudouet committed
870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907
    TClass *cl = gROOT->GetClass("TH1F");
    cl->MakeCustomMenuList();
    TList * ml = cl->GetMenuList();

    TClassMenuItem *n;

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Add to Stored spectra","AddToStoredSpectra",this,"TObject *",0);
    ml->AddFirst(n);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Fit Peaks","PopUpFitPeaks",this,"TObject *",0);
    ml->AddFirst(n);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Find Peaks","PopUpFindPeaks",this,"TObject *",0);
    ml->AddFirst(n);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Show Background","PopUpShowBackground",this,"TObject *",0);
    ml->AddFirst(n);

    for(int i=0 ; i<6 ; i++)
        ml->RemoveAt(ml->GetEntries()-1);
    for(int i=0 ; i<4 ; i++)
        ml->RemoveAt(ml->GetEntries()-3);
    for(int i=0 ; i<2 ; i++)
        ml->RemoveAt(ml->GetEntries()-9);
    ml->RemoveAt(ml->GetEntries()-13);
    for(int i=0 ; i<4 ; i++)
        ml->RemoveAt(ml->GetEntries()-14);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Normalize","HistNorm",this,"TObject*", 0);
    ml->AddAt(n,5);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Scale","HistScale",this,"Float_t,TObject*", 1);
    ml->AddAt(n,5);

908
    /// TH1D///
Jérémie Dudouet's avatar
Jérémie Dudouet committed
909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991
    cl = gROOT->GetClass("TH1D");
    cl->MakeCustomMenuList();
    ml = cl->GetMenuList();

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Add to Stored spectra","AddToStoredSpectra",this,"TObject *",0);
    ml->AddFirst(n);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Fit Peaks","PopUpFitPeaks",this,"TObject *",0);
    ml->AddFirst(n);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Find Peaks","PopUpFindPeaks",this,"TObject *",0);
    ml->AddFirst(n);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Show Background","PopUpShowBackground",this,"TObject *",0);
    ml->AddFirst(n);

    for(int i=0 ; i<6 ; i++)
        ml->RemoveAt(ml->GetEntries()-1);
    for(int i=0 ; i<4 ; i++)
        ml->RemoveAt(ml->GetEntries()-3);
    for(int i=0 ; i<2 ; i++)
        ml->RemoveAt(ml->GetEntries()-9);
    ml->RemoveAt(ml->GetEntries()-13);
    for(int i=0 ; i<4 ; i++)
        ml->RemoveAt(ml->GetEntries()-14);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Normalize","HistNorm",this,"TObject*", 0);
    ml->AddAt(n,5);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Scale","HistScale",this,"Float_t,TObject*", 1);
    ml->AddAt(n,5);


    /// TH1Proj ///
    cl = gROOT->GetClass("CXTH1Proj");
    cl->MakeCustomMenuList();
    ml = cl->GetMenuList();

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Fit Peaks","PopUpFitPeaks",this,"TObject *",0);
    ml->AddFirst(n);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Find Peaks","PopUpFindPeaks",this,"TObject *",0);
    ml->AddFirst(n);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Show Background","PopUpShowBackground",this,"TObject *",0);
    ml->AddFirst(n);

    for(int i=0 ; i<6 ; i++)
        ml->RemoveAt(ml->GetEntries()-1);
    for(int i=0 ; i<4 ; i++)
        ml->RemoveAt(ml->GetEntries()-3);
    for(int i=0 ; i<2 ; i++)
        ml->RemoveAt(ml->GetEntries()-9);
    ml->RemoveAt(ml->GetEntries()-13);
    for(int i=0 ; i<4 ; i++)
        ml->RemoveAt(ml->GetEntries()-14);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Normalize","HistNorm",this,"TObject*", 0);
    ml->AddAt(n,5);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Scale","HistScale",this,"Float_t,TObject*", 1);
    ml->AddAt(n,5);


    /// TH2F ///
    cl = gROOT->GetClass("TH2F");
    cl->MakeCustomMenuList();
    ml = cl->GetMenuList();

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Add to Stored spectra","AddToStoredSpectra",this,"TObject *",0);
    ml->AddFirst(n);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Eval Background","PopUpEval2DBackground",this,"TObject *",0);
    ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Init Radware GxG","PopUpInitRadGG",this,"TObject *",0);
    ml->AddFirst(n);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Init GxG","PopUpInitGG",this,"TObject *",0);
    ml->AddFirst(n);

    for(int i=0 ; i<6 ; i++)
        ml->RemoveAt(ml->GetEntries()-1);
    for(int i=0 ; i<4 ; i++)
        ml->RemoveAt(ml->GetEntries()-3);
    ml->RemoveAt(ml->GetEntries()-9);
    for(int i=0 ; i<7 ; i++)
        ml->RemoveAt(ml->GetEntries()-12);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Rebin","Rebin2D",this,"Int_t, Int_t, TObject*", 2);
    ml->AddAt(n,12);

    //    n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl);ml->AddAt(n,ml->GetEntries()-4);


    /// TH2D ///
    cl = gROOT->GetClass("TH2D");
    cl->MakeCustomMenuList();
    ml = cl->GetMenuList();

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Add to Stored spectra","AddToStoredSpectra",this,"TObject *",0);
    ml->AddFirst(n);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Eval Background","PopUpEval2DBackground",this,"TObject *",0);
    ml->AddFirst(n);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Init Radware GxG","PopUpInitRadGG",this,"TObject *",0);
    ml->AddFirst(n);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                           "Init GxG","PopUpInitGG",this,"TObject *",0);
    ml->AddFirst(n);

    for(int i=0 ; i<6 ; i++)
        ml->RemoveAt(ml->GetEntries()-1);
    for(int i=0 ; i<4 ; i++)
        ml->RemoveAt(ml->GetEntries()-3);
    ml->RemoveAt(ml->GetEntries()-9);
    for(int i=0 ; i<7 ; i++)
        ml->RemoveAt(ml->GetEntries()-12);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Rebin","Rebin2D",this,"Int_t, Int_t, TObject*", 2);
    ml->AddAt(n,12);

    //    n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl);ml->AddAt(n,ml->GetEntries()-4);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057


    /// CXArrow ///
    cl = gROOT->GetClass("CXArrow");
    cl->MakeCustomMenuList();
    ml = cl->GetMenuList();

    for(int i=0 ; i<18 ; i++)
        ml->RemoveAt(ml->GetEntries()-1);

1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072

    /// TGraph ///
    cl = gROOT->GetClass("TGraph");
    cl->MakeCustomMenuList();
    ml = cl->GetMenuList();
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Scale","GraphScale",this,"Float_t,TObject*", 1);
    ml->AddAt(n,3);

    /// TGraphErrors ///
    cl = gROOT->GetClass("TGraphErrors");
    cl->MakeCustomMenuList();
    ml = cl->GetMenuList();
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Scale","GraphScale",this,"Float_t,TObject*", 1);
    ml->AddAt(n,3);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1073
    //    n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl);ml->AddAt(n,ml->GetEntries()-4);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
}

void CXMainWindow::Rebin2D(Int_t RebinX, Int_t RebinY, TObject *c)
{
    TH2 *hist = static_cast<TH2*>(c);
    TString DrawOpt = hist->GetDrawOption();
    if(DrawOpt=="")
        DrawOpt = "col";
    hist = hist->Rebin2D(RebinX,RebinY,hist->GetName());
    hist->Draw(DrawOpt);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1084
    RefreshPads();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
}

void CXMainWindow::PopUpEval2DBackground(TObject *c)
{
    TH2 *hist = static_cast<TH2*>(c);

    if(IsBkdUtilityEnabled==false)
        ToggleTab(IsBkdUtilityEnabled,M_BkdUtility,fBkdToolTab,fBkdSubtract->GetName());

    fMainTab->SetTab(fBkdSubtract->GetName());

    fBkdSubtract->Do2DEvaluation(hist);
}

void CXMainWindow::PopUpInitGG(TObject *c)
{
    TH2 *hist = static_cast<TH2*>(c);

    if(IsHist2DPlayerEnabled==false)
        ToggleTab(IsHist2DPlayerEnabled,M_Hist2DPlayer,fHist2DPlayerTab,fHist2DPlayer->GetName());

    fMainTab->SetTab(fHist2DPlayer->GetName());

    fHist2DPlayer->InitGG(hist);
}
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123

void CXMainWindow::PopUpInitRadGG(TObject *c)
{
    TH2 *hist = static_cast<TH2*>(c);

    if(IsRad2DPlayerEnabled==false)
        ToggleTab(IsRad2DPlayerEnabled,M_Rad2DPlayer,fRad2DPlayerTab,fRad2DPlayer->GetName());

    fMainTab->SetTab(fRad2DPlayer->GetName());

    fRad2DPlayer->Init(hist);
}

void CXMainWindow::InitRadCubePlayer(CXRadReader *radreader)
1124 1125 1126 1127 1128 1129 1130 1131 1132
{
    if(IsRadCubePlayerEnabled==false)
        ToggleTab(IsRadCubePlayerEnabled,M_RadCubePlayer,fRadCubePlayerTab,fRadCubePlayer->GetName());

    fMainTab->SetTab(fRadCubePlayer->GetName());

    fRadCubePlayer->Init(radreader);
}

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144

void CXMainWindow::HistNorm(TObject *c)
{
    TH1 *hist = static_cast<TH1*>(c);

    Float_t x1,x2;
    x1=gPad->GetUxmin();
    x2=gPad->GetUxmax();
    hist->GetXaxis()->UnZoom();
    hist->Scale(1./hist->Integral());
    hist->GetXaxis()->SetRangeUser(x1,x2);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1145
    RefreshPads();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1146 1147 1148 1149 1150 1151 1152 1153
}

void CXMainWindow::HistScale(Float_t scaleFact, TObject *c)
{
    TH1 *hist = static_cast<TH1*>(c);

    hist->Scale(scaleFact);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1154
    RefreshPads();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1155 1156
}

1157 1158 1159 1160 1161 1162 1163 1164
void CXMainWindow::GraphScale(Float_t scaleFact, TObject *c)
{
    TGraph *graph = static_cast<TGraph*>(c);

    for(int i=0 ; i<graph->GetN() ; i++){
        graph->SetPoint(i,graph->GetX()[i],graph->GetY()[i]*scaleFact);
    }

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1165
    RefreshPads();
1166 1167
}

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1168 1169 1170 1171 1172 1173 1174 1175
void CXMainWindow::PopUpShowBackground(TObject *c)
{
    TH1 *hist = static_cast<TH1*>(c);

    if(GetHisto()->GetName() != hist->GetName())
    {
        fCanvas->cd();
        hist->Draw("hist");
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1176
        RefreshPads();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1177 1178 1179 1180 1181 1182 1183 1184
    }
    if(IsBkdUtilityEnabled==false)
        ToggleTab(IsBkdUtilityEnabled,M_BkdUtility,fBkdToolTab,fBkdSubtract->GetName());

    fMainTab->SetTab(fBkdSubtract->GetName());

    fBkdSubtract->DoActivate();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1185
    RefreshPads();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1186 1187 1188 1189
}

void CXMainWindow::AddToStoredSpectra(TObject *c)
{
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1190
    TString Current = fMainTab->GetCurrentTab()->GetText()->GetString();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1191

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1192 1193 1194
    if(!(Current == fHist2DPlayer->GetName()  ||
         Current == fRadCubePlayer->GetName() ||
         Current == fSavedList->GetName())) {
1195

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1196 1197 1198 1199
        if(IsSavedListEnabled==false)
            ToggleTab(IsSavedListEnabled,M_SavedList,fSavedListTab,fSavedList->GetName());
        else
            fMainTab->SetTab(fSavedList->GetName());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1200
    }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210

    TObject *o = c;
    TObject *clone = nullptr;
    if(o->InheritsFrom("CXRadCubeTH1Proj"))
        clone = ((CXRadCubeTH1Proj*)o)->GetTotalProj();
    else
        clone = o->Clone();
    if(o->InheritsFrom(TH1::Class_Name()))
        ((TH1*)clone)->SetDirectory(nullptr);
    fSavedList->AddToStoredList(clone);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220
}

void CXMainWindow::PopUpFindPeaks(TObject *c)
{
    TH1 *hist = static_cast<TH1*>(c);

    if(GetHisto()->GetName() != hist->GetName())
    {
        fCanvas->cd();
        hist->Draw("hist");
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1221
        RefreshPads();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238
    }
    if(IsHist1DPlayerEnabled==false)
        ToggleTab(IsHist1DPlayerEnabled,M_Hist1DPlayer,fHist1DPlayerTab,fHist1DPlayer->GetName());

    fMainTab->SetTab(fHist1DPlayer->GetName());

    fHist1DPlayer->PeakSearch();
}

void CXMainWindow::PopUpFitPeaks(TObject *c)
{
    TH1 *hist = static_cast<TH1*>(c);

    if(GetHisto()->GetName() != hist->GetName())
    {
        fCanvas->cd();
        hist->Draw("hist");
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1239
        RefreshPads();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256
    }
    if(IsHist1DPlayerEnabled==false)
        ToggleTab(IsHist1DPlayerEnabled,M_Hist1DPlayer,fHist1DPlayerTab,fHist1DPlayer->GetName());

    fMainTab->SetTab(fHist1DPlayer->GetName());

    fHist1DPlayer->NewFit();
}


void CXMainWindow::ProcessedKeyEvent(Event_t *event)
{
    char input[10];
    UInt_t keysym;

    gVirtualX->LookupString(event, input, sizeof(input), keysym);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1257
    //    std::cout << "event : " << event->fCode << " " << event->fState <<" ; "<< event->fType  << "; " << keysym << std::endl;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1258 1259 1260 1261 1262 1263 1264

    if(event->fType == kGKeyPress && keysym == kKey_Control)
        fCTRL = true;
    if(event->fType == kKeyRelease && keysym == kKey_Control)
        fCTRL = false;

}
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288

void CXMainWindow::DoDraw(TObject *obj, TString DrawOpt)
{
    if(obj==nullptr) return;

    gPad = GetSelectedPad();
    if(gPad==nullptr)
        gPad = GetCanvas()->cd();
    if(gPad==nullptr)
        return;

    DrawOpt.ReplaceAll(" ","");

    if(obj->InheritsFrom(TCanvas::Class())){
        TCanvas *canvas_in = (TCanvas*)obj;
        CXCanvas *canvas_out = GetCanvas();
        canvas_out->cd();
        canvas_out->Clear();

        Int_t idraw = 0;

        for(int i=0 ; i<canvas_in->GetListOfPrimitives()->GetEntries() ; i++){
            TObject *o = canvas_in->GetListOfPrimitives()->At(i);

1289 1290 1291
            if(o->InheritsFrom(TPad::Class())) {
                o->DrawClone();
            }
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313
            else {
                if(idraw==0) {
                    idraw++;
                    if(o->InheritsFrom(TH2::Class()))
                        o->Draw("col");
                    else if(o->InheritsFrom(TH1::Class()))
                        o->Draw("hist");
                    else if(o->InheritsFrom(TGraph::Class()))
                        o->Draw("APL");
                    else
                        o->Draw();
                }
                else{
                    if(o->InheritsFrom(TH2::Class()))
                        o->Draw("col same");
                    else if(o->InheritsFrom(TH1::Class()))
                        o->Draw("hist same");
                    else if(o->InheritsFrom(TGraph::Class()))
                        o->Draw("PL");
                    else
                        o->Draw("same");
                }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403
            }
        }
    }
    else if(obj->InheritsFrom(TH1::Class())) {

        TH1 *hist = (TH1*)obj;
        hist->SetDirectory(nullptr);
        hist->SetStats(true);

        if(DrawOpt.Contains("norm")) {
            hist->Scale(1./((Float_t)hist->Integral(1,hist->GetNbinsX())));
            DrawOpt.ReplaceAll("norm","");
        }
        if(DrawOpt.Contains("add")){
            TH1 * HistToadd = GetHisto();
            if(HistToadd == nullptr)
                WARN_MESS << "No histogram to be added found in the current pad, ignored" << ENDL;
            else {
                Float_t Fact=1;
                if(DrawOpt.Contains("(") && DrawOpt.Contains(")")){
                    TObjArray *arr = DrawOpt.Copy().Tokenize("(");
                    TString opt = arr->At(1)->GetName();
                    delete arr;
                    arr = opt.Tokenize(")");
                    opt = arr->First()->GetName();
                    delete arr;
                    if(opt.IsFloat())
                        Fact = opt.Atof();
                    else
                        cout<<"could not decrypt the addition factor, 1 is used"<<endl;
                }
                HistToadd->Add(hist,Fact);
            }
        }
        else if(DrawOpt.Contains("div")){

            TH1 * HistToDiv = GetHisto();
            if(HistToDiv == nullptr)
                WARN_MESS << "No histogram to be divided found in the current pad, ignored" << ENDL;
            else {
                Float_t Fact=1;
                if(DrawOpt.Contains("(") && DrawOpt.Contains(")")){
                    TObjArray *arr = DrawOpt.Copy().Tokenize("(");
                    TString opt = arr->At(1)->GetName();
                    delete arr;
                    arr = opt.Tokenize(")");
                    opt = arr->First()->GetName();
                    delete arr;
                    if(opt.IsFloat())
                        Fact = opt.Atof();
                    else
                        cout<<"could not decrypt the addition factor, 1 is used"<<endl;
                }

                HistToDiv->Divide(HistToDiv,hist,1,Fact);
            }
        }
        else if(DrawOpt.Contains("mult")){

            TH1 * HistToMult = GetHisto();
            if(HistToMult == nullptr)
                WARN_MESS << "No histogram to be multiplied found in the current pad, ignored" << ENDL;
            else {
                Float_t Fact=1;
                if(DrawOpt.Contains("(") && DrawOpt.Contains(")")){
                    TObjArray *arr = DrawOpt.Copy().Tokenize("(");
                    TString opt = arr->At(1)->GetName();
                    delete arr;
                    arr = opt.Tokenize(")");
                    opt = arr->First()->GetName();
                    delete arr;
                    if(opt.IsFloat())
                        Fact = opt.Atof();
                    else
                        cout<<"could not decrypt the addition factor, 1 is used"<<endl;
                }
                HistToMult->Multiply(HistToMult,hist,1,Fact);
            }
        }
        else
            hist->Draw(DrawOpt);
    }
    else
        obj->Draw(DrawOpt);

    RefreshPads();
    gPad->GetFrame()->SetBit(TObject::kCannotPick);
}


Jérémie Dudouet's avatar
Jérémie Dudouet committed
1404
ClassImp(CXMainWindow)