Subversion Repositories f9daq

Rev

Rev 172 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #include "../include/sipmscan.h"
  2. #include "../include/workstation.h"
  3. #include "../include/substructure.h"
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. // Main window constructor (+layout) ---------------------------------
  9.  
  10. TGAppMainFrame::TGAppMainFrame(const TGWindow *p, int w, int h)
  11. {
  12.    TGCompositeFrame *fT1;
  13.    idtotal = 0;
  14.  
  15.    char *cTemp;
  16.  
  17.    // CAMAC and Scope objects
  18.    gDaq = new daq();
  19.    gScopeDaq = new daqscope();
  20.  
  21.    // Define main window and menubar
  22.    fMain = new TGMainFrame(p, w, h, kVerticalFrame);
  23.    
  24.    // Initialize the menu
  25.    fMenuBar = new TGMenuBar(fMain, 200, 30);
  26.    InitMenu();
  27.    fMain->AddFrame(fMenuBar, new TGLayoutHints(kLHintsExpandX | kLHintsTop));
  28.  
  29.    // Prepare the tabbed structure
  30.    fTab = new TGTab(fMain, 500, 500);
  31.  
  32.    // Read the layout we wish to use
  33.    int frmWidth[measwin+analysiswin], frmHeight[measwin+analysiswin];
  34.    LayoutRead(measwin+analysiswin, frmWidth, frmHeight);
  35.  
  36.    // Structure the measurement layout window
  37.    int *vert, *hor, *wPane, *hPane;
  38.  
  39.    vert = new int[2]; hor = new int;
  40.    *hor = 1;
  41.    vert[0] = 1; vert[1] = 0;
  42.  
  43.    const char *measFrmTit[] = {"Settings pane", "Display", "Main measurement window"};
  44.    wPane = new int[measwin]; hPane = new int[measwin];
  45.    for(int i = 0; i < measwin; i++)
  46.    {
  47.       wPane[i] = frmWidth[i];
  48.       hPane[i] = frmHeight[i];
  49.    }
  50.  
  51.    fT1 = fTab->AddTab("Measurement");
  52.    TGSplitter(fT1, "horizontal", hor, vert, measFrmTit, measLayout, wPane, hPane);
  53.    fT1->AddFrame(fLayout[idtotal], new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
  54.    idtotal++;
  55.    delete[] vert; delete hor; delete[] wPane; delete[] hPane;
  56.  
  57.    // Structure the analysis layout window
  58.    vert = new int[2]; hor = new int;
  59.    *hor = 1;
  60.    vert[0] = 1; vert[1] = 1;
  61.  
  62.    const char *analysisFrmTit[] = {"Histogram file selection", "Analysis", "Histogram", "Histogram controls"};
  63.    wPane = new int[analysiswin]; hPane = new int[analysiswin];
  64.    for(int i = 0; i < analysiswin; i++)
  65.    {
  66.       wPane[i] = frmWidth[i+measwin];
  67.       hPane[i] = frmHeight[i+measwin];
  68.    }
  69.  
  70.    fT1 = fTab->AddTab("Analysis");
  71.    TGSplitter(fT1, "horizontal", hor, vert, analysisFrmTit, analysisLayout, wPane, hPane);
  72.    fT1->AddFrame(fLayout[idtotal], new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
  73.    idtotal++;
  74.    delete[] vert; delete hor; delete[] wPane; delete[] hPane;
  75.  
  76.    // Structure the monitoring layout window (Fieldpoint) //TODO
  77.    fT1 = fTab->AddTab("Monitoring");
  78.    fTab->SetEnabled(2,kFALSE); //TODO
  79.  
  80.    // Structure the help layout window
  81.    fT1 = fTab->AddTab("Help");
  82.    TGTextView *helpdesc;
  83.    const TGFont *tfont = gClient->GetFont(HELPFONT);
  84.    FontStruct_t helpFont = tfont->GetFontStruct();
  85.    helpdesc = new TGTextView(fT1,100,100);
  86.    helpdesc->SetFont(helpFont);
  87.    helpdesc->SetForegroundColor(0x000000);
  88.    fT1->AddFrame(helpdesc, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
  89.    
  90.    cTemp = new char[1024];
  91.    sprintf(cTemp, "%s/doc/README", rootdir);
  92.    if(helpdesc->LoadFile(cTemp))
  93.    {
  94.       if(DBGSIG) printf("TGAppMainFrame(): Help file correctly loaded.\n");
  95.    }
  96.    else
  97.       printf("Error! Help file not loaded.\n");
  98.    delete[] cTemp;
  99.    helpdesc->AddLine("");
  100.  
  101.    fMain->AddFrame(fTab, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
  102.  
  103.    // Set the inner layout of each frame
  104.    AppLayout();
  105.  
  106.    fMain->SetWindowName(WINDOW_NAME);
  107.    fMain->MapSubwindows();
  108.    fMain->MapWindow();
  109.    fMain->Layout();
  110.  
  111.    // Prepare initial settings
  112.    EnableScan(0);       //.
  113.    EnableScan(1);       // Grey out scan
  114.    EnableScan(2);       // options by default
  115.    EnableScan(3);       //.
  116.    EnableLiveUpdate();  //. Disable the live histogram update at beginning
  117.    VoltOut(1);          //. Get the output voltage save in file
  118.    HistogramOptions(1); //. Enable clean plots by default
  119.    plotType->widgetTB[0]->SetDown(kTRUE);                       //.
  120.    fMenuHisttype->CheckEntry(M_ANALYSIS_HISTTYPE_1DADC);        // Set the ADC histogram
  121.    fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DTDC);      // to show by default
  122.    fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_2D);         //.
  123.    acqStarted = false;  //. At program start, the acquisition is stopped
  124.    ToolTipSet();        //. Turn on tooltips
  125.    PositionSet(1);      //. Get starting table position
  126.    RotationSet(1);      //. Get starting rotation
  127.  
  128.    if(DBGSIG > 1)
  129.    {
  130.       printf("TGAppMainFrame(): At end of constructor\n");
  131.       gObjectTable->Print();
  132.    }
  133. }
  134.  
  135. TGAppMainFrame::~TGAppMainFrame()
  136. {
  137.    fMain->Cleanup();
  138.    delete fMain;
  139. }
  140.  
  141. // -------------------------------------------------------------------
  142.  
  143. // Event handler for menubar actions ---------------------------------
  144.  
  145. void TGAppMainFrame::HandleMenu(Int_t id)
  146. {
  147. //   int ret = 0;
  148.    char cmd[256];
  149.  
  150.    switch(id)
  151.    {
  152.       case M_FILE_SET_LAYOUT:
  153.          LayoutSet();
  154.          break;
  155.  
  156.       case M_FILE_SAVE_LAYOUT:
  157.          LayoutSave();
  158.          break;
  159.  
  160.       case M_FILE_SAVE_MSETTINGS:
  161.          // Here, we save the set values in the measurement layout (automatically done when we safely exit the application and after each start of measurement).
  162.          break;
  163.  
  164.       case M_FILE_SAVE_ASETTINGS:
  165.          // Here, we save the set values in the analysis layout (automatically done when we safely exit the application and after each start of analysis).
  166.          break;
  167.  
  168.       case M_FILE_CHECK_WIDTH:
  169.          printf("\nSettings window: %dx%d\n", measLayout[0]->GetWidth(), measLayout[0]->GetHeight());
  170.          printf("Histogram window: %dx%d\n", measLayout[1]->GetWidth(), measLayout[1]->GetHeight());
  171.          printf("Main measurement window: %dx%d\n", measLayout[2]->GetWidth(), measLayout[2]->GetHeight());
  172.          printf("Histogram file window: %dx%d\n", analysisLayout[0]->GetWidth(), analysisLayout[0]->GetHeight());
  173.          printf("Analysis window: %dx%d\n", analysisLayout[1]->GetWidth(), analysisLayout[1]->GetHeight());
  174.          printf("Histogram window: %dx%d\n", analysisLayout[2]->GetWidth(), analysisLayout[2]->GetHeight());
  175.          printf("Histogram controls window: %dx%d\n", analysisLayout[3]->GetWidth(), analysisLayout[3]->GetHeight());
  176.  
  177.          printf("Main window: %dx%d\n", fMain->GetWidth(), fMain->GetHeight());
  178.          printf("Menu bar: %dx%d\n", fMenuBar->GetWidth(), fMenuBar->GetHeight());
  179.          printf("Tab window: %dx%d\n", fTab->GetWidth(), fTab->GetHeight());
  180.          break;
  181.  
  182.       case M_FILE_EXIT:
  183.          CloseWindow();
  184.          break;
  185.  
  186.       case M_ANALYSIS_HISTTYPE_1DADC:
  187.          ChangeHisttype(0);
  188.          break;
  189.  
  190.       case M_ANALYSIS_HISTTYPE_1DTDC:
  191.          ChangeHisttype(1);
  192.          break;
  193.  
  194.       case M_ANALYSIS_HISTTYPE_2D:
  195.          ChangeHisttype(2);
  196.          break;
  197.  
  198.       case M_ANALYSIS_INTEG:
  199.          fTab->SetTab(1);
  200.          analTab->SetTab(0);
  201.          for(int i = 0; i < 3; i++)
  202.          {
  203.             if(intSpect->widgetChBox[i]->IsDown())
  204.                intSpect->widgetChBox[i]->SetState(kButtonUp);
  205.          }
  206.          break;
  207.  
  208.       case M_ANALYSIS_INTEGX:
  209.          fTab->SetTab(1);
  210.          analTab->SetTab(0);
  211.          for(int i = 0; i < 3; i++)
  212.          {
  213.             if(i == 0)
  214.                intSpect->widgetChBox[i]->SetState(kButtonDown);
  215.             else
  216.             {
  217.                if(intSpect->widgetChBox[i]->IsDown())
  218.                   intSpect->widgetChBox[i]->SetState(kButtonUp);
  219.             }
  220.          }
  221.          break;
  222.  
  223.       case M_ANALYSIS_INTEGY:
  224.          fTab->SetTab(1);
  225.          analTab->SetTab(0);
  226.          for(int i = 0; i < 3; i++)
  227.          {
  228.             if(i == 1)
  229.                intSpect->widgetChBox[i]->SetState(kButtonDown);
  230.             else
  231.             {
  232.                if(intSpect->widgetChBox[i]->IsDown())
  233.                   intSpect->widgetChBox[i]->SetState(kButtonUp);
  234.             }
  235.          }
  236.          break;
  237.  
  238.       case M_ANALYSIS_PHOTMU:
  239.          fTab->SetTab(1);
  240.          analTab->SetTab(1);
  241.          for(int i = 0; i < 3; i++)
  242.          {
  243.             if(i == 2)
  244.                intSpect->widgetChBox[i]->SetState(kButtonDown);
  245.             else
  246.             {
  247.                if(intSpect->widgetChBox[i]->IsDown())
  248.                   intSpect->widgetChBox[i]->SetState(kButtonUp);
  249.             }
  250.          }
  251.          break;
  252.  
  253.       case M_ANALYSIS_BREAKDOWN:
  254.          fTab->SetTab(1);
  255.          analTab->SetTab(2);
  256.          break;
  257.  
  258.       case M_ANALYSIS_SURFSCAN:
  259.          fTab->SetTab(1);
  260.          analTab->SetTab(3);
  261.          break;
  262.  
  263.       case M_ANALYSIS_TIMING:
  264.          fTab->SetTab(1);
  265.          analTab->SetTab(4);
  266.          break;
  267.  
  268.       case M_HELP_WEBHELP:
  269.          printf("TGAppMainFrame::HandleMenu(): Opening %s/doc/documentation.html in a web browser.\n", rootdir);
  270.          sprintf(cmd, "xdg-open %s/doc/documentation.html &", rootdir);
  271.          system(cmd);
  272.          break;
  273.  
  274.       case M_HELP_ABOUT:
  275.          About();
  276.          break;
  277.  
  278.       default:
  279. //         fMainFrame->SetCurrent(id);
  280.          break;
  281.    }
  282. }
  283.  
  284. // -------------------------------------------------------------------
  285.  
  286. // Initialize the main window menu -----------------------------------
  287.  
  288. void TGAppMainFrame::InitMenu()
  289. {
  290.    fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
  291.  
  292.    // Popup menu in menubar for File controls
  293.    fMenuFile = new TGPopupMenu(gClient->GetRoot());
  294.    fMenuFile->AddEntry(new TGHotString("Set &user layout"), M_FILE_SET_LAYOUT);
  295.    fMenuFile->AddEntry(new TGHotString("Save &current layout"), M_FILE_SAVE_LAYOUT);
  296.    fMenuFile->AddSeparator();
  297.    fMenuFile->AddEntry(new TGHotString("Save current &measurement settings"), M_FILE_SAVE_MSETTINGS);
  298.    fMenuFile->AddEntry(new TGHotString("Save current &analysis settings"), M_FILE_SAVE_ASETTINGS);
  299.    fMenuFile->AddEntry(new TGHotString("&Check frame width (Testing)"), M_FILE_CHECK_WIDTH);
  300.    fMenuFile->AddSeparator();
  301.    fMenuFile->AddEntry(new TGHotString("E&xit"), M_FILE_EXIT);
  302.  
  303.    // Popup menu in menubar for Analysis controls
  304.    fMenuHisttype = new TGPopupMenu(gClient->GetRoot()); // adds a cascade menu that will be incorporated into analysis controls
  305.    fMenuHisttype->AddEntry(new TGHotString("1D &ADC histogram"), M_ANALYSIS_HISTTYPE_1DADC);
  306.    fMenuHisttype->AddEntry(new TGHotString("1D &TDC histogram"), M_ANALYSIS_HISTTYPE_1DTDC);
  307.    fMenuHisttype->AddEntry(new TGHotString("&2D ADC vs. TDC histogram"), M_ANALYSIS_HISTTYPE_2D);
  308.  
  309.    fMenuAnalysis = new TGPopupMenu(gClient->GetRoot()); // adds a new popup menu to the menubar
  310.    fMenuAnalysis->AddPopup(new TGHotString("&Histogram type"), fMenuHisttype);
  311.    fMenuAnalysis->AddEntry(new TGHotString("&Integrate spectrum"), M_ANALYSIS_INTEG);
  312.    fMenuAnalysis->AddEntry(new TGHotString("Integrate spectrum (&X direction)"), M_ANALYSIS_INTEGX);
  313.    fMenuAnalysis->AddEntry(new TGHotString("Integrate spectrum (&Y direction)"), M_ANALYSIS_INTEGY);
  314.    fMenuAnalysis->AddEntry(new TGHotString("&Relative PDE"), M_ANALYSIS_PHOTMU);
  315.    fMenuAnalysis->AddEntry(new TGHotString("&Breakdown voltage"), M_ANALYSIS_BREAKDOWN);
  316.    fMenuAnalysis->AddEntry(new TGHotString("Surface 2&D scan"), M_ANALYSIS_SURFSCAN);
  317.    fMenuAnalysis->AddEntry(new TGHotString("&Timing analysis"), M_ANALYSIS_TIMING);
  318.  
  319.    // Popup menu in menubar for File controls
  320.    fMenuHelp = new TGPopupMenu(gClient->GetRoot());
  321.    fMenuHelp->AddEntry(new TGHotString("Open &help in web browser"), M_HELP_WEBHELP);
  322.    fMenuHelp->AddEntry(new TGHotString("&About"), M_HELP_ABOUT);
  323.  
  324.    // Connect all menu items with actions
  325.    fMenuFile->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)");
  326.    fMenuAnalysis->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)");
  327.    fMenuHelp->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)");
  328.  
  329.    // Draw the created popup menus on the menubar
  330.    fMenuBar->AddPopup(new TGHotString("&File"), fMenuFile, fMenuBarItemLayout);
  331.    fMenuBar->AddPopup(new TGHotString("&Analysis"),fMenuAnalysis,fMenuBarItemLayout);
  332.    fMenuBar->AddPopup(new TGHotString("&Help"), fMenuHelp, fMenuBarItemLayout);
  333. }
  334.  
  335. // -------------------------------------------------------------------
  336.  
  337. // Setting the application subwindow layout --------------------------
  338.  
  339. void TGAppMainFrame::AppLayout()
  340. {
  341.    double numform[6], numform2[6];
  342.    int *checksel;
  343.    char selected[256];
  344.    int subgroup[2];
  345.    TGCompositeFrame *fH1, *fV1, *fH2, *fT1;
  346.    TGGroupFrame *fG1;
  347.  
  348.    TGLayoutHints *f0centerX = new TGLayoutHints(kLHintsCenterX,2,2,2,2);
  349.    TGLayoutHints *f0leftX = new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2);
  350.    TGLayoutHints *f0leftXnoleft = new TGLayoutHints(kLHintsLeft | kLHintsTop,0,2,2,2);
  351.    TGLayoutHints *f0leftXpad = new TGLayoutHints(kLHintsLeft | kLHintsTop,12,12,2,2);
  352.    TGLayoutHints *f0rightX = new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2);
  353.    TGLayoutHints *f0rightXpad = new TGLayoutHints(kLHintsRight | kLHintsTop,12,12,2,2);
  354.    TGLayoutHints *f0centerY = new TGLayoutHints(kLHintsCenterY,2,2,2,2);
  355.    TGLayoutHints *f0center2d = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,2,2,2,2);
  356.    TGLayoutHints *f1expandX = new TGLayoutHints(kLHintsExpandX,2,2,2,2);
  357.    TGLayoutHints *f1expand2d = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,2,2,2,2);
  358.    TGLayoutHints *f1expandXpad = new TGLayoutHints(kLHintsExpandX,12,12,2,2);
  359.  
  360. // Settings pane ---------------------------------------------------------------------------
  361.    subgroup[0] = (measLayout[0]->GetWidth())-4;
  362.  
  363.    // Check buttons to toggle voltage, surface and Z axis scans
  364.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *scansOn -> 4 check buttons (voltage, surface, Z axis, incidence angle scans)\n");
  365.    scansOn = new TSubStructure();
  366.    checksel = new int[4];
  367.    checksel[0] = 0; checksel[1] = 0; checksel[2] = 0; checksel[3] = 0;
  368.    const char *selnames[] = {"Voltage scan ON/OFF", "Surface scan ON/OFF", "Z-axis scan ON/OFF","Rotation scan ON/OFF","0","0","0","0","0","0","0","0","0","0","0","0"};
  369.    if(scansOn->TGCheckList(measLayout[0], subgroup[0], 30, 4, selnames, checksel, "vertical", "center"))
  370.       measLayout[0]->AddFrame(scansOn->outsidebox, f1expandXpad);
  371.    delete[] checksel;
  372.  
  373.    // Hard limit for maximum voltage we can set
  374.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *vHardlimit -> Number entry for voltage limit\n");
  375.    vHardlimit = new TSubStructure();
  376.    for(int i = 0; i < 6; i++) numform[i] = 0;
  377.    numform[0] = 6; numform[1] = 2;
  378.    if(vHardlimit->TGLabelNEntry(measLayout[0], subgroup[0], 30, "Voltage limit:", 70.00, numform, "center"))
  379.       measLayout[0]->AddFrame(vHardlimit->outsidebox, f1expandXpad);
  380.  
  381.    // Number of used channels
  382.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *NCH -> Number entry for number of channels to capture\n");
  383.    NCH = new TSubStructure();
  384.    for(int i = 0; i < 6; i++) numform[i] = 0;
  385.    numform[0] = 3; numform[2] = 2; numform[3] = 2; numform[4] = 1; numform[5] = 8;
  386.    if(NCH->TGLabelNEntry(measLayout[0], subgroup[0], 30, "Nr. of channels:", 1, numform, "center"))
  387.       measLayout[0]->AddFrame(NCH->outsidebox, f1expandXpad);
  388.  
  389.    // Select the units to use for table positioning (micrometer, table position units)
  390.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *posUnits -> Dropdown menu for selecting the units for table positioning\n");
  391.    posUnits = new TSubStructure();
  392.    selnames[0] = "table units"; selnames[1] = "micrometers";
  393.    sprintf(selected, "table units");
  394.    if(posUnits->TGLabelDrop(measLayout[0], 2*subgroup[0]/3, 30, "Position units:", 2, selnames, selected))
  395.       measLayout[0]->AddFrame(posUnits->outsidebox, f1expandXpad);
  396.  
  397.    // Select the units to use for rotation platform (degrees, table rotation units)
  398.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *rotUnits -> Dropdown menu for selecting the units for rotation\n");
  399.    rotUnits = new TSubStructure();
  400.    selnames[0] = "table units"; selnames[1] = "degrees";
  401.    sprintf(selected, "degrees");
  402.    if(rotUnits->TGLabelDrop(measLayout[0], 2*subgroup[0]/3, 30, "Rotation units:", 2, selnames, selected))
  403.       measLayout[0]->AddFrame(rotUnits->outsidebox, f1expandXpad);
  404.  
  405.    // Button and textbox to enter the oscilloscope IP address
  406.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *oscConnect -> Text Entry (oscilloscope IP address)\n");
  407.    oscConnect = new TSubStructure();
  408.    if(oscConnect->TGLabelTEntryButton(measLayout[0], subgroup[0], 30, "Scope IP:", "178.172.43.157", "Connect", "twoline"))
  409.       measLayout[0]->AddFrame(oscConnect->outsidebox, f1expandXpad);
  410.  
  411.    // Laser settings (freq., tune, ND filter)
  412.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *laserInfo -> Text Entry (Laser setting information)\n");
  413.    laserInfo = new TSubStructure();
  414.    if(laserInfo->TGLabelTEntry(measLayout[0], subgroup[0], 30, "Laser settings:", "kHz, tune, ND", "twoline"))
  415.       measLayout[0]->AddFrame(laserInfo->outsidebox, f1expandXpad);
  416.  
  417.    // Chamber temperature (will only be manually set until we can get it directly from the chamber)
  418.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *chtemp -> Number entry for chamber temperature\n");
  419.    chtemp = new TSubStructure();
  420.    for(int i = 0; i < 6; i++) numform[i] = 0;
  421.    numform[0] = 5; numform[1] = 1; numform[3] = 2; numform[4] = -70.; numform[5] = 140.;
  422.    if(chtemp->TGLabelNEntry(measLayout[0], subgroup[0], 30, "Chamber temp.:", 25.0, numform, "center"))
  423.       measLayout[0]->AddFrame(chtemp->outsidebox, f1expandXpad);
  424.  
  425.    // Check button to toggle live update of histogram (in display canvas)
  426.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *liveDisp -> 1 check button (live histogram update)\n");
  427.    liveDisp = new TSubStructure();
  428.    checksel = new int;
  429.    *checksel = 0;
  430.    selnames[0] = "Live histogram ON/OFF";
  431.    if(liveDisp->TGCheckList(measLayout[0], subgroup[0], 30, 1, selnames, checksel, "vertical", "center"))
  432.       measLayout[0]->AddFrame(liveDisp->outsidebox, f1expandXpad);
  433.    delete checksel;
  434.  
  435.    // Actions for Settings pane //TODO
  436.    scansOn->widgetChBox[0]->Connect("Clicked()", "TGAppMainFrame", this, "EnableScan(=0)");
  437.    scansOn->widgetChBox[1]->Connect("Clicked()", "TGAppMainFrame", this, "EnableScan(=1)");
  438.    scansOn->widgetChBox[2]->Connect("Clicked()", "TGAppMainFrame", this, "EnableScan(=2)");
  439.    scansOn->widgetChBox[3]->Connect("Clicked()", "TGAppMainFrame", this, "EnableScan(=3)");
  440.    vHardlimit->widgetNE[0]->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "VoltageLimit()");
  441.    (vHardlimit->widgetNE[0]->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "VoltageLimit()");
  442.    posUnits->widgetCB->Connect("Selected(Int_t)", "TGAppMainFrame", this, "ChangeUnits(Int_t)");
  443.    rotUnits->widgetCB->Connect("Selected(Int_t)", "TGAppMainFrame", this, "ChangeUnitsRot(Int_t)");
  444.    liveDisp->widgetChBox[0]->Connect("Clicked()", "TGAppMainFrame", this, "EnableLiveUpdate()");
  445. // Settings pane ---------------------------------------------------------------------------
  446.  
  447. // Main window -----------------------------------------------------------------------------
  448.    TGTab *setTab;
  449.  
  450.    // Voltage, position and incidence angle tab
  451.    subgroup[0] = 2*(measLayout[2]->GetWidth())/7-14;
  452.    subgroup[1] = (measLayout[2]->GetHeight())/2-4;
  453.    setTab = new TGTab(measLayout[2], subgroup[0], subgroup[1]);
  454.  
  455.    fT1 = setTab->AddTab("Voltage, position and incidence angle");
  456.    fH1 = new TGCompositeFrame(fT1, measLayout[2]->GetWidth(), subgroup[1], kFixedHeight | kHorizontalFrame);
  457.  
  458.    // Left pane (Bias voltage controls)
  459.    fV1 = new TGCompositeFrame(fH1, subgroup[0], subgroup[1], kFixedWidth | kFixedHeight | kVerticalFrame);
  460.    fG1 = new TGGroupFrame(fV1, "Bias voltage controls");
  461.  
  462.    // Output voltage supply channel
  463.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *vOutCh -> Dropdown menu for bias voltage channel\n");
  464.    vOutCh = new TSubStructure();
  465.    selnames[0] = "U0"; selnames[1] = "U1"; selnames[2] = "U2"; selnames[3] = "U3"; selnames[4] = "U4"; selnames[5] = "U5"; selnames[6] = "U6"; selnames[7] = "U7"; selnames[8] = "U100"; selnames[9] = "U101"; selnames[10] = "U102"; selnames[11] = "U103"; selnames[12] = "U104"; selnames[13] = "U105"; selnames[14] = "U106"; selnames[15] = "U107";
  466.    sprintf(selected, "U0");
  467.    if(vOutCh->TGLabelDrop(fG1, 2*subgroup[0]/3, 30, "Output channel:", 16, selnames, selected))
  468.       fG1->AddFrame(vOutCh->outsidebox, f1expandXpad);
  469.  
  470.    // Output voltage setting
  471.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *vOutOpt -> 2 check buttons (negative polarity, ON/OFF toggle switch)\n");
  472.    vOutOpt = new TSubStructure();
  473.    checksel = new int[2];
  474.    checksel[0] = 0; checksel[1] = 0;
  475.    selnames[1] = "Output ON/OFF"; selnames[0] = "Negative polarity";
  476.    if(vOutOpt->TGCheckList(fG1, 3*subgroup[0]/4, 30, 2, selnames, checksel, "vertical", "center"))
  477.       fG1->AddFrame(vOutOpt->outsidebox, f1expandXpad);
  478.    delete[] checksel;
  479.  
  480.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *vOut -> Number entry for bias voltage\n");
  481.    vOut = new TSubStructure();
  482.    for(int i = 0; i < 6; i++) numform[i] = 0;
  483.    numform[0] = 7; numform[1] = 2; numform[3] = 2; numform[4] = 0.; numform[5] = vHardlimit->widgetNE[0]->GetNumber();
  484.    if(vOut->TGLabelNEntry(fG1, 3*subgroup[0]/4, 30, "Output voltage:", 0.00, numform, "center"))
  485.       fG1->AddFrame(vOut->outsidebox, f1expandXpad);
  486.    
  487.    // Set, get and reset voltage buttons
  488.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *vOutButtons -> 3 buttons (set bias voltage, read current bias voltage, reset voltage output when it gets interlocked)\n");
  489.    vOutButtons = new TSubStructure();
  490.    selnames[0] = "Set"; selnames[1] = "Get"; selnames[2] = "Reset";
  491.    if(vOutButtons->TGMultiButton(fG1, 3*subgroup[0]/4, 30, 3, selnames, "center"))
  492.       fG1->AddFrame(vOutButtons->outsidebox, f1expandXpad);
  493.  
  494.    // Voltage scan controls
  495.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *vOutStart -> Number entry for starting bias voltage\n");
  496.    vOutStart = new TSubStructure();
  497.    for(int i = 0; i < 6; i++) numform[i] = 0;
  498.    numform[0] = 7; numform[1] = 2;
  499.    if(vOutStart->TGLabelNEntry(fG1, 3*subgroup[0]/4, 30, "V (min):", 0.00, numform, "center"))
  500.       fG1->AddFrame(vOutStart->outsidebox, f1expandXpad);
  501.  
  502.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *vOutStop -> Number entry for starting bias voltage\n");
  503.    vOutStop = new TSubStructure();
  504.    for(int i = 0; i < 6; i++) numform[i] = 0;
  505.    numform[0] = 7; numform[1] = 2;
  506.    if(vOutStop->TGLabelNEntry(fG1, 3*subgroup[0]/4, 30, "V (max):", 0.00, numform, "center"))
  507.       fG1->AddFrame(vOutStop->outsidebox, f1expandXpad);
  508.  
  509.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *vOutStep -> Number entry for starting bias voltage\n");
  510.    vOutStep = new TSubStructure();
  511.    for(int i = 0; i < 6; i++) numform[i] = 0;
  512.    numform[0] = 7; numform[1] = 2;
  513.    if(vOutStep->TGLabelNEntry(fG1, 3*subgroup[0]/4, 30, "V (step):", 0.00, numform, "center"))
  514.       fG1->AddFrame(vOutStep->outsidebox, f1expandXpad);
  515.  
  516.    fV1->AddFrame(fG1, f1expand2d);
  517.    // Left pane (Bias voltage controls)
  518.    fH1->AddFrame(fV1, f0leftX);
  519.  
  520.    // Center pane (Table position controls)
  521.    subgroup[0] = 3*(measLayout[2]->GetWidth())/7-13;
  522.    fV1 = new TGCompositeFrame(fH1, subgroup[0], subgroup[1], kFixedWidth | kFixedHeight | kVerticalFrame);
  523.    fG1 = new TGGroupFrame(fV1, "Table position controls");
  524.  
  525.    // X, Y and Z positions
  526.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *xPos, *yPos, *zPos, *zPosMin, *zPosMax, *zPosStep -> Settings for position and Z axis scan\n");
  527.    fH2 = new TGCompositeFrame(fG1, 3*subgroup[0]/4, 30, kFixedWidth | kHorizontalFrame);
  528.    xPos = new TSubStructure();
  529.    for(int i = 0; i < 6; i++) numform[i] = 0;
  530.    numform[0] = 9; numform[3] = 2; numform[4] = -100; numform[5] = 215000;
  531.    if(xPos->TGLabelNEntry(fH2, 8*subgroup[0]/16, 30, "X:", 0, numform, "center"))
  532.       fH2->AddFrame(xPos->outsidebox, f0centerX);
  533.  
  534.    zPosMin = new TSubStructure();
  535.    numform[5] = 375000;
  536.    if(zPosMin->TGLabelNEntry(fH2, 8*subgroup[0]/16, 30, "Z (min):", 0, numform, "center"))
  537.       fH2->AddFrame(zPosMin->outsidebox, f0centerX);
  538.    fG1->AddFrame(fH2, f1expandXpad);
  539.  
  540.    fH2 = new TGCompositeFrame(fG1, 3*subgroup[0]/4, 30, kFixedWidth | kHorizontalFrame);
  541.    yPos = new TSubStructure();
  542.    numform[5] = 215000;
  543.    if(yPos->TGLabelNEntry(fH2, 8*subgroup[0]/16, 30, "Y:", 0, numform, "center"))
  544.       fH2->AddFrame(yPos->outsidebox, f0centerX);
  545.  
  546.    zPosMax = new TSubStructure();
  547.    numform[5] = 375000;
  548.    if(zPosMax->TGLabelNEntry(fH2, 8*subgroup[0]/16, 30, "Z (max):", 0, numform, "center"))
  549.       fH2->AddFrame(zPosMax->outsidebox, f0centerX);
  550.    fG1->AddFrame(fH2, f1expandXpad);
  551.    
  552.    fH2 = new TGCompositeFrame(fG1, 3*subgroup[0]/4, 30, kFixedWidth | kHorizontalFrame);
  553.    zPos = new TSubStructure();
  554.    numform[5] = 375000;
  555.    if(zPos->TGLabelNEntry(fH2, 8*subgroup[0]/16, 30, "Z:", 0, numform, "center"))
  556.       fH2->AddFrame(zPos->outsidebox, f0centerX);
  557.  
  558.    zPosStep = new TSubStructure();
  559.    for(int i = 0; i < 6; i++) numform[i] = 0;
  560.    numform[0] = 9;
  561.    if(zPosStep->TGLabelNEntry(fH2, 8*subgroup[0]/16, 30, "Z (step):", 0, numform, "center"))
  562.       fH2->AddFrame(zPosStep->outsidebox, f0centerX);
  563.    fG1->AddFrame(fH2, f1expandXpad);
  564.    
  565.    // Set, get, home and reset position buttons
  566.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *posButtons -> 4 buttons (set position, read current position, home the motor and reset all three controllers)\n");
  567.    posButtons = new TSubStructure();
  568.    selnames[0] = "Set"; selnames[1] = "Get"; selnames[2] = "Home"; selnames[3] = "Reset";
  569.    if(posButtons->TGMultiButton(fG1, 3*subgroup[0]/4, 30, 4, selnames, "center"))
  570.       fG1->AddFrame(posButtons->outsidebox, f1expandXpad);
  571.  
  572.    // Position scan controls
  573.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *xPosMin, *xPosMax, *xPosStep, *yPosMin, *yPosMax, *yPosStep -> Settings for X and Y axis scans\n");
  574.    fH2 = new TGCompositeFrame(fG1, 3*subgroup[0]/4, 30, kFixedWidth | kHorizontalFrame);
  575.    xPosMin = new TSubStructure();
  576.    for(int i = 0; i < 6; i++) numform[i] = 0;
  577.    numform[0] = 9; numform[3] = 2; numform[4] = -100; numform[5] = 215000;
  578.    if(xPosMin->TGLabelNEntry(fH2, 8*subgroup[0]/16, 30, "X (min):", 0, numform, "center"))
  579.       fH2->AddFrame(xPosMin->outsidebox, f0centerX);
  580.  
  581.    yPosMin = new TSubStructure();
  582.    if(yPosMin->TGLabelNEntry(fH2, 8*subgroup[0]/16, 30, "Y (min):", 0, numform, "center"))
  583.       fH2->AddFrame(yPosMin->outsidebox, f0centerX);
  584.    fG1->AddFrame(fH2, f1expandXpad);
  585.  
  586.    fH2 = new TGCompositeFrame(fG1, 3*subgroup[0]/4, 30, kFixedWidth | kHorizontalFrame);
  587.    xPosMax = new TSubStructure();
  588.    if(xPosMax->TGLabelNEntry(fH2, 8*subgroup[0]/16, 30, "X (max):", 0, numform, "center"))
  589.       fH2->AddFrame(xPosMax->outsidebox, f0centerX);
  590.  
  591.    yPosMax = new TSubStructure();
  592.    if(yPosMax->TGLabelNEntry(fH2, 8*subgroup[0]/16, 30, "Y (max):", 0, numform, "center"))
  593.       fH2->AddFrame(yPosMax->outsidebox, f0centerX);
  594.    fG1->AddFrame(fH2, f1expandXpad);
  595.  
  596.    fH2 = new TGCompositeFrame(fG1, 3*subgroup[0]/4, 30, kFixedWidth | kHorizontalFrame);
  597.    xPosStep = new TSubStructure();
  598.    for(int i = 0; i < 6; i++) numform[i] = 0;
  599.    numform[0] = 9;
  600.    if(xPosStep->TGLabelNEntry(fH2, 8*subgroup[0]/16, 30, "X (step):", 0, numform, "center"))
  601.       fH2->AddFrame(xPosStep->outsidebox, f0centerX);
  602.  
  603.    yPosStep = new TSubStructure();
  604.    if(yPosStep->TGLabelNEntry(fH2, 8*subgroup[0]/16, 30, "Y (step):", 0, numform, "center"))
  605.       fH2->AddFrame(yPosStep->outsidebox, f0centerX);
  606.    fG1->AddFrame(fH2, f1expandXpad);
  607.  
  608.    fV1->AddFrame(fG1, f1expand2d);
  609.    // Center pane (Table position controls)
  610.    fH1->AddFrame(fV1, f0leftX);
  611.  
  612.    // Right pane (Incidence angle controls)
  613.    subgroup[0] = 2*(measLayout[2]->GetWidth())/7-14;
  614.    fV1 = new TGCompositeFrame(fH1, subgroup[0], subgroup[1], kFixedWidth | kFixedHeight | kVerticalFrame);
  615.    fG1 = new TGGroupFrame(fV1, "Incidence angle controls");
  616.  
  617.    // Rotation positions
  618.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *rotPos -> Setting for rotation position\n");
  619.    rotPos = new TSubStructure();
  620.    for(int i = 0; i < 6; i++) numform[i] = 0;
  621.    numform[0] = 7; numform[1] = 2; numform[3] = 2; numform[4] = -180.; numform[5] = 180.;
  622.    if(rotPos->TGLabelNEntry(fG1, 3*subgroup[0]/4, 30, "Incidence angle:", 0., numform, "center"))
  623.       fG1->AddFrame(rotPos->outsidebox, f1expandXpad);
  624.    
  625.    // Set, get, home and reset rotation buttons
  626.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *rotButtons -> 4 buttons (set rotation, read current rotation, home the motor and reset controller)\n");
  627.    rotButtons = new TSubStructure();
  628.    selnames[0] = "Set"; selnames[1] = "Get"; selnames[2] = "Home"; selnames[3] = "Reset";
  629.    if(rotButtons->TGMultiButton(fG1, 3*subgroup[0]/4, 30, 4, selnames, "center"))
  630.       fG1->AddFrame(rotButtons->outsidebox, f1expandXpad);
  631.  
  632.    // Rotation scan controls
  633.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *rotPosMin -> Number entry for starting angle\n");
  634.    rotPosMin = new TSubStructure();
  635.    if(rotPosMin->TGLabelNEntry(fG1, 3*subgroup[0]/4, 30, "Angle (min):", 0.0, numform, "center"))
  636.       fG1->AddFrame(rotPosMin->outsidebox, f1expandXpad);
  637.  
  638.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *rotPosMax -> Number entry for finishing angle\n");
  639.    rotPosMax = new TSubStructure();
  640.    if(rotPosMax->TGLabelNEntry(fG1, 3*subgroup[0]/4, 30, "Angle (max):", 0.0, numform, "center"))
  641.       fG1->AddFrame(rotPosMax->outsidebox, f1expandXpad);
  642.  
  643.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *rotPosStep -> Number entry for angle step\n");
  644.    rotPosStep = new TSubStructure();
  645.    for(int i = 0; i < 6; i++) numform[i] = 0;
  646.    numform[0] = 7; numform[1] = 1;
  647.    if(rotPosStep->TGLabelNEntry(fG1, 3*subgroup[0]/4, 30, "Angle (step):", 0.0, numform, "center"))
  648.       fG1->AddFrame(rotPosStep->outsidebox, f1expandXpad);
  649.  
  650.    fV1->AddFrame(fG1, f1expand2d);
  651.    // Right pane (Incidence angle controls)
  652.    fH1->AddFrame(fV1, f0leftX);
  653.    
  654.    fT1->AddFrame(fH1, f1expand2d);
  655.  
  656.    // Waveform tab
  657.    //TODO
  658.    measLayout[2]->AddFrame(setTab, f0leftX);
  659.  
  660.    // Bottom pane (File controls)
  661.    subgroup[0] = measLayout[2]->GetWidth()-19;
  662.    subgroup[1] = (measLayout[2]->GetHeight())/4-4;
  663.    fH1 = new TGCompositeFrame(measLayout[2], subgroup[0], subgroup[1], kFixedWidth | kFixedHeight | kHorizontalFrame);
  664.    fG1 = new TGGroupFrame(fH1, "Event/Data file controls");
  665.  
  666.    // Number of events
  667.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *evtNum -> Number entry for set number of events to acquire\n");
  668.    evtNum = new TSubStructure();
  669.    for(int i = 0; i < 6; i++) numform[i] = 0;
  670.    numform[0] = 8; numform[2] = 1;
  671.    if(evtNum->TGLabelNEntry(fG1, 3*subgroup[0]/4, 30, "Number of events:", 10000, numform, "left"))
  672.       fG1->AddFrame(evtNum->outsidebox, f0leftXpad);
  673.  
  674.    // Time stamp display
  675.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *timeStamp -> Text entry for timestamp\n");
  676.    timeStamp = new TSubStructure();
  677.    if(timeStamp->TGLabelTEntry(fG1, 3*subgroup[0]/4, 30, "Time stamp:", "", "oneline"))
  678.    {
  679.       timeStamp->widgetTE->SetState(kFALSE);
  680.       fG1->AddFrame(timeStamp->outsidebox, f1expandXpad);
  681.    }
  682.  
  683.    // Save to file
  684.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *fileName -> Text entry for timestamp\n");
  685.    fileName = new TSubStructure();
  686.    char *cTemp;
  687.    cTemp = new char[256];
  688.    sprintf(cTemp, "%s/results/test%s", rootdir, histext);
  689.    if(fileName->TGLabelTEntryButton(fG1, 3*subgroup[0]/4, 30, "Save to file:", cTemp, "...", "oneline"))
  690.    {
  691.       fileName->widgetTE->SetState(kFALSE);
  692.       fG1->AddFrame(fileName->outsidebox, f1expandXpad);
  693.    }
  694.  
  695.    fH1->AddFrame(fG1, new TGLayoutHints(kLHintsExpandX,8,2,2,2));
  696.    // Bottom pane (File controls)
  697.    measLayout[2]->AddFrame(fH1, f0leftX);
  698.  
  699.    // Start acquisition and progress bar
  700.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *measProgress -> Button to start acquiring data and horizontal progress bar\n");
  701.    measProgress = new TSubStructure();
  702.    if(measProgress->TGButtonProgressTEntry(measLayout[2], 3*subgroup[0]/4, 30, "Start acquisition", "Estimated end time: "))
  703.    {
  704.       measProgress->widgetTE->SetState(kFALSE);
  705.       measLayout[2]->AddFrame(measProgress->outsidebox, f1expandXpad);
  706.    }
  707.  
  708.    // Actions for Main window //TODO
  709.    vOutOpt->widgetChBox[0]->Connect("Clicked()", "TGAppMainFrame", this, "NegativePolarity()");
  710.    vOutButtons->widgetTB[0]->Connect("Clicked()", "TGAppMainFrame", this, "VoltOut(=0)");
  711.    vOutButtons->widgetTB[1]->Connect("Clicked()", "TGAppMainFrame", this, "VoltOut(=1)");
  712.    vOutButtons->widgetTB[2]->Connect("Clicked()", "TGAppMainFrame", this, "VoltOut(=2)");
  713.    posButtons->widgetTB[0]->Connect("Clicked()", "TGAppMainFrame", this, "PositionSet(=0)");
  714.    posButtons->widgetTB[1]->Connect("Clicked()", "TGAppMainFrame", this, "PositionSet(=1)");
  715.    posButtons->widgetTB[2]->Connect("Clicked()", "TGAppMainFrame", this, "PositionSet(=2)");
  716.    posButtons->widgetTB[3]->Connect("Clicked()", "TGAppMainFrame", this, "PositionSet(=3)");
  717.    rotButtons->widgetTB[0]->Connect("Clicked()", "TGAppMainFrame", this, "RotationSet(=0)");
  718.    rotButtons->widgetTB[1]->Connect("Clicked()", "TGAppMainFrame", this, "RotationSet(=1)");
  719.    rotButtons->widgetTB[2]->Connect("Clicked()", "TGAppMainFrame", this, "RotationSet(=2)");
  720.    rotButtons->widgetTB[3]->Connect("Clicked()", "TGAppMainFrame", this, "RotationSet(=3)");
  721.    fileName->widgetTB[0]->Connect("Clicked()", "TGAppMainFrame", this, "SaveFile()");
  722.    measProgress->widgetTB[0]->Connect("Clicked()", "TGAppMainFrame", this, "StartAcq()");
  723.    // TODO - Save file
  724.  
  725. // Main window -----------------------------------------------------------------------------
  726.  
  727. // Display pane ----------------------------------------------------------------------------
  728.    measCanvas = new TRootEmbeddedCanvas("measCanvas",measLayout[1],300,300);
  729.    measLayout[1]->AddFrame(measCanvas, f1expand2d);
  730. // Display pane ----------------------------------------------------------------------------
  731.  
  732. // Histogram file selection pane -----------------------------------------------------------
  733.    subgroup[0] = (analysisLayout[0]->GetWidth())-4;
  734.  
  735.    // Open browser for file selection
  736.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *selectDir -> Button to open histogram files\n");
  737.    selectDir = new TSubStructure();
  738.    if(selectDir->TGLabelButton(analysisLayout[0], 3*subgroup[0]/4, 30, "File selection:", "...", "left"))
  739.       analysisLayout[0]->AddFrame(selectDir->outsidebox, f0leftXpad);
  740.  
  741.    // List view of the opened files
  742.    if(DBGSIG > 1) printf("AppLayout(): Creating TGListBox *fileList -> List box for opened histograms\n");
  743.    fileList = new TGListBox(analysisLayout[0],1);
  744.    fileList->GetVScrollbar();
  745.    fileList->Resize(300, (3*analysisLayout[0]->GetHeight()/7)-10 );
  746.    analysisLayout[0]->AddFrame(fileList, f1expandXpad);
  747.  
  748.    fH1 = new TGCompositeFrame(analysisLayout[0], subgroup[0], 30, kHorizontalFrame);
  749.    // Multiple file selection toggle
  750.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *multiSelect -> 2 check buttons (enable multiple select, select everything)\n");
  751.    multiSelect = new TSubStructure();
  752.    checksel = new int[2];
  753.    checksel[0] = 0; checksel[1] = 0;
  754.    selnames[0] = "Multiple file select"; selnames[1] = "Select all listed files";
  755.    if(multiSelect->TGCheckList(fH1, subgroup[0]/2, 30, 2, selnames, checksel, "horizontal", "left"))
  756.       fH1->AddFrame(multiSelect->outsidebox, f0leftX);
  757.    delete[] checksel;
  758.    
  759.    // Previous/next controls, clear list and edit header
  760.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *fileListCtrl -> Multiple buttons for controlling and displaying the histograms in list box\n");
  761.    fileListCtrl = new TSubStructure();
  762.    selnames[0] = "<<"; selnames[1] = ">>"; selnames[2] = "Edit header"; selnames[3] = "Clear list";
  763.    if(fileListCtrl->TGMultiButton(fH1, subgroup[0]/3, 30, 4, selnames, "right"))
  764.       fH1->AddFrame(fileListCtrl->outsidebox, f0rightX);
  765.  
  766.    analysisLayout[0]->AddFrame(fH1, f1expandXpad);
  767.  
  768.    // Header information of opened file
  769.    fG1 = new TGGroupFrame(analysisLayout[0], "Opened file header information");
  770.  
  771.    fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30);
  772.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *dispTime -> Display text Entry for opened histogram (time stamp)\n");
  773.    dispTime = new TSubStructure();
  774.    if(dispTime->TGLabelTEntry(fH1, 3*subgroup[0]/4-24, 30, "Time:", "", "oneline"))
  775.       fH1->AddFrame(dispTime->outsidebox, f0leftXnoleft);
  776.    dispTime->widgetTE->SetState(kFALSE);
  777.  
  778.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *dispBias -> Number entry for opened histogram (bias voltage)\n");
  779.    dispBias = new TSubStructure();
  780.    for(int i = 0; i < 6; i++) numform[i] = 0;
  781.    numform[0] = 7; numform[1] = 2;
  782.    if(dispBias->TGLabelNEntry(fH1, subgroup[0]/4-24, 30, "Bias voltage:", 0.00, numform, "center"))
  783.       fH1->AddFrame(dispBias->outsidebox, f0leftX);
  784.    dispBias->widgetNE[0]->SetState(kFALSE);
  785.    fG1->AddFrame(fH1, f0leftXpad);
  786.  
  787.    fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30);
  788.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *dispPos -> Display text Entry for opened histogram (table position)\n");
  789.    dispPos = new TSubStructure();
  790.    if(dispPos->TGLabelTEntry(fH1, subgroup[0]/2-12, 30, "Position:", "", "oneline"))
  791.       fH1->AddFrame(dispPos->outsidebox, f0leftXnoleft);
  792.    dispPos->widgetTE->SetState(kFALSE);
  793.  
  794.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *dispTemp -> Number entry for opened histogram (temperature)\n");
  795.    dispTemp = new TSubStructure();
  796.    for(int i = 0; i < 6; i++) numform[i] = 0;
  797.    numform[0] = 6; numform[1] = 1;
  798.    if(dispTemp->TGLabelNEntry(fH1, subgroup[0]/4-18, 30, "Temperature:", 0.0, numform, "center"))
  799.       fH1->AddFrame(dispTemp->outsidebox, f0leftX);
  800.    dispTemp->widgetNE[0]->SetState(kFALSE);
  801.  
  802.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *dispAngle -> Number entry for opened histogram (incidence angle)\n");
  803.    dispAngle = new TSubStructure();
  804.    for(int i = 0; i < 6; i++) numform[i] = 0;
  805.    numform[0] = 7; numform[1] = 2;
  806.    if(dispAngle->TGLabelNEntry(fH1, subgroup[0]/4-18, 30, "Angle:", 0.00, numform, "center"))
  807.       fH1->AddFrame(dispAngle->outsidebox, f0leftX);
  808.    dispAngle->widgetNE[0]->SetState(kFALSE);
  809.    fG1->AddFrame(fH1, f0leftXpad);
  810.  
  811.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *dispLaser -> Display text Entry for opened histogram (laser and additional info)\n");
  812.    dispLaser = new TSubStructure();
  813.    if(dispLaser->TGLabelTEntry(fG1, 3*subgroup[0]/4, 30, "Laser settings:", "", "oneline"))
  814.       fG1->AddFrame(dispLaser->outsidebox, f1expandXpad);
  815.    dispLaser->widgetTE->SetState(kFALSE);
  816.  
  817.    analysisLayout[0]->AddFrame(fG1, f1expandX);
  818.  
  819.    // Actions for histogram file selection pane
  820.    selectDir->widgetTB[0]->Connect("Clicked()", "TGAppMainFrame", this, "SelectDirectory()");
  821.    multiSelect->widgetChBox[0]->Connect("Clicked()", "TGAppMainFrame", this, "ListMultiSelect(=0)");
  822.    multiSelect->widgetChBox[1]->Connect("Clicked()", "TGAppMainFrame", this, "ListMultiSelect(=1)");
  823.    fileList->Connect("DoubleClicked(Int_t)", "TGAppMainFrame", this, "FileListNavigation(Int_t)");
  824.    fileListCtrl->widgetTB[0]->Connect("Clicked()", "TGAppMainFrame", this, "FileListNavigation(=-2)");
  825.    fileListCtrl->widgetTB[1]->Connect("Clicked()", "TGAppMainFrame", this, "FileListNavigation(=-3)");
  826.    fileListCtrl->widgetTB[2]->Connect("Clicked()", "TGAppMainFrame", this, "HeaderEdit()");
  827.    fileListCtrl->widgetTB[3]->Connect("Clicked()", "TGAppMainFrame", this, "ClearHistogramList()");
  828.  
  829. // Histogram file selection pane -----------------------------------------------------------
  830.  
  831. // Analysis pane ---------------------------------------------------------------------------
  832.    fH1 = new TGCompositeFrame(analysisLayout[1], analysisLayout[1]->GetWidth(), 30, kHorizontalFrame);
  833.  
  834.    subgroup[0] = (analysisLayout[1]->GetWidth())/2-4;
  835.    subgroup[1] = (analysisLayout[1]->GetHeight())-4;
  836.  
  837.    analTab = new TGTab(fH1, subgroup[0], subgroup[1]);
  838.  
  839.    // Analysis tabs
  840.    // Integrate spectrum tab
  841.    fT1 = analTab->AddTab("Integ. spectrum");
  842.    fV1 = new TGCompositeFrame(fT1, subgroup[0], subgroup[1], kVerticalFrame | kFixedWidth | kFixedHeight);
  843.  
  844.    // Check buttons to toggle direction of integration and normalization
  845.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *intSpect -> 3 check buttons (direction of integration, normalization)\n");
  846.    intSpect = new TSubStructure();
  847.    checksel = new int[3];
  848.    checksel[0] = 0; checksel[1] = 0; checksel[2] = 1;
  849.    selnames[0] = "X direction (for edge scans)";
  850.    selnames[1] = "Y direction (for edge scans)";
  851.    selnames[2] = "Normalize to number of events";
  852.    if(intSpect->TGCheckList(fV1, subgroup[0], 30, 3, selnames, checksel, "vertical", "center"))
  853.       fV1->AddFrame(intSpect->outsidebox, f1expandXpad);
  854.    delete[] checksel;
  855.  
  856.    // Values for 2D plot pixel resolution
  857.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *resol2d -> Pixel resolution for 2D plots\n");
  858.    resol2d = new TSubStructure();
  859.    for(int i = 0; i < 6; i++) { numform[i] = 0; numform2[i] = 0; }
  860.    numform[0] = 5; numform2[0] = 5; numform[2] = 2; numform2[2] = 2;
  861.    if(resol2d->TGLabelDoubleNEntry(fV1, subgroup[0], 30, "2D plot pixel resolution (X, Y):", 40, numform, 40, numform2, "center"))
  862.       fV1->AddFrame(resol2d->outsidebox, f1expandX);
  863.  
  864.    // Start integrating or set its defaults
  865.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *intSpectButtons -> 2 buttons for integrating spectra\n");
  866.    intSpectButtons = new TSubStructure();
  867.    selnames[0] = "Start"; selnames[1] = "Start and edit"; selnames[2] = "Default values";
  868.    if(intSpectButtons->TGMultiButton(fV1, subgroup[0], 30, 3, selnames, "center"))
  869.       fV1->AddFrame(intSpectButtons->outsidebox, f1expandX);
  870.  
  871.    fT1->AddFrame(fV1, f1expandX);
  872.  
  873.    // Relative photon detection efficiency tab (PDE)
  874.    fT1 = analTab->AddTab("Relative PDE");
  875.    fV1 = new TGCompositeFrame(fT1, subgroup[0], subgroup[1], kVerticalFrame | kFixedWidth | kFixedHeight);
  876.  
  877.    // Check button to toggle normalization
  878.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *relPde -> 2 check buttons (relative pde, normalization)\n");
  879.    relPde = new TSubStructure();
  880.    checksel = new int;
  881.    *checksel = 1;
  882.    selnames[0] = "Normalize to number of events";
  883.    if(relPde->TGCheckList(fV1, subgroup[0], 30, 1, selnames, checksel, "vertical", "center"))
  884.       fV1->AddFrame(relPde->outsidebox, f1expandXpad);
  885.    delete[] checksel;
  886.  
  887.    // Calculate relative PDE using the middle of the pedestal peak
  888.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *midPeak -> Calculate the relative PDE, by setting the middle of the pedestal peak.\n");
  889.    midPeak = new TSubStructure();
  890.    checksel = new int;
  891.    *checksel = 0;
  892.    selnames[0] = "Pedestal entries end at middle of ped. peak";
  893.    if(midPeak->TGCheckList(fV1, subgroup[0], 30, 1, selnames, checksel, "vertical", "center"))
  894.       fV1->AddFrame(midPeak->outsidebox, f1expandX);
  895.    delete checksel;
  896.  
  897.    // Select the dark run
  898.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *darkRun -> Button to open histogram files of a dark run\n");
  899.    darkRun = new TSubStructure();
  900.    if(darkRun->TGLabelTEntryButton(fV1, 3*subgroup[0]/4, 30, "Select dark run histogram:", "", "...", "oneline"))
  901.    {
  902.       darkRun->widgetTE->SetState(kFALSE);
  903.       fV1->AddFrame(darkRun->outsidebox, f1expandXpad);
  904.    }
  905.  
  906.    // Select the offset of 0 angle
  907.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *zeroAngle -> Set the offset for 0 angle\n");
  908.    zeroAngle = new TSubStructure();
  909.    for(int i = 0; i < 6; i++) numform[i] = 0;
  910.    numform[0] = 6; numform[1] = 2;
  911.    if(zeroAngle->TGLabelNEntry(fV1, 3*subgroup[0]/4, 30, "Offset to zero angle:", 0., numform, "center"))
  912.       fV1->AddFrame(zeroAngle->outsidebox, f0centerX);
  913.  
  914.    // Start calculating the PDE or set its defaults
  915.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *relPdeButtons -> 2 buttons for calculating the relative PDE\n");
  916.    relPdeButtons = new TSubStructure();
  917.    selnames[0] = "Start"; selnames[1] = "Start and edit"; selnames[2] = "Default values";
  918.    if(relPdeButtons->TGMultiButton(fV1, subgroup[0], 30, 3, selnames, "center"))
  919.       fV1->AddFrame(relPdeButtons->outsidebox, f1expandX);
  920.  
  921.    fT1->AddFrame(fV1, f1expandX);
  922.  
  923.    // Breaktown voltage tab
  924.    fT1 = analTab->AddTab("Breakdown voltage");
  925.    fV1 = new TGCompositeFrame(fT1, subgroup[0], subgroup[1], kVerticalFrame | kFixedWidth | kFixedHeight);
  926.  
  927.    // Select the minumum number of peaks for fitting to be initiated
  928.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *minPeak -> Minimum number of peaks to fit for peak fitting\n");
  929.    minPeak = new TSubStructure();
  930.    for(int i = 0; i < 6; i++) numform[i] = 0;
  931.    numform[0] = 4; numform[2] = 1; numform[3] = 2; numform[4] = 1; numform[5] = 20;
  932.    if(minPeak->TGLabelNEntry(fV1, subgroup[0], 30, "Min. nr. of peaks:", 2, numform, "center"))
  933.       fV1->AddFrame(minPeak->outsidebox, f0centerX);
  934.  
  935.    // Select which separation to use
  936.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *peakSepCalc -> Make the separation between the selected peaks\n");
  937.    peakSepCalc = new TSubStructure();
  938.    for(int i = 0; i < 6; i++) numform[i] = 0;
  939.    numform[0] = 4; numform[2] = 1; numform[3] = 2; numform[4] = 1; numform[5] = 3;
  940.    if(peakSepCalc->TGLabelNEntry(fV1, subgroup[0], 30, "Calculate peak separation between N pe and N+1 pe peaks:", 1, numform, "center"))
  941.       fV1->AddFrame(peakSepCalc->outsidebox, f0centerX);
  942.  
  943.    // Start calculating the breakdown voltage or set its defaults
  944.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *brDownButtons -> 2 buttons for calculating the breakdown voltage\n");
  945.    brDownButtons = new TSubStructure();
  946.    selnames[0] = "Start"; selnames[1] = "Start and edit"; selnames[2] = "Default values";
  947.    if(brDownButtons->TGMultiButton(fV1, subgroup[0], 30, 3, selnames, "center"))
  948.       fV1->AddFrame(brDownButtons->outsidebox, f1expandX);
  949.  
  950.    fT1->AddFrame(fV1, f1expandX);
  951.  
  952.    // Surface scan tab
  953.    fT1 = analTab->AddTab("Surface scan");
  954.    fV1 = new TGCompositeFrame(fT1, subgroup[0], subgroup[1], kVerticalFrame | kFixedWidth | kFixedHeight);
  955.  
  956.    // Check button to toggle normalization
  957.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *surfScanOpt -> 2 check buttons (normalization, zero bottom-left corner)\n");
  958.    surfScanOpt = new TSubStructure();
  959.    checksel = new int[2];
  960.    checksel[0] = 1; checksel[1] = 0;
  961.    selnames[0] = "Normalize to number of events"; selnames[1] = "Zero the bottom left corner";
  962.    if(surfScanOpt->TGCheckList(fV1, subgroup[0], 30, 2, selnames, checksel, "vertical", "center"))
  963.       fV1->AddFrame(surfScanOpt->outsidebox, f1expandXpad);
  964.    delete[] checksel;
  965.  
  966.    // Values for 2D plot pixel resolution
  967.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *resolSurf -> Pixel resolution for surface plots\n");
  968.    resolSurf = new TSubStructure();
  969.    for(int i = 0; i < 6; i++) { numform[i] = 0; numform2[i] = 0; }
  970.    numform[0] = 5; numform2[0] = 5; numform[2] = 2; numform2[2] = 2;
  971.    if(resolSurf->TGLabelDoubleNEntry(fV1, subgroup[0], 30, "Surface plot pixel resolution (X, Y):", 40, numform, 40, numform2, "center"))
  972.       fV1->AddFrame(resolSurf->outsidebox, f1expandX);
  973.  
  974.    // Start calculating the breakdown voltage or set its defaults
  975.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *surfButtons -> 2 buttons for calculating the surface scan\n");
  976.    surfButtons = new TSubStructure();
  977.    selnames[0] = "Start"; selnames[1] = "Start and edit"; selnames[2] = "Default values";
  978.    if(surfButtons->TGMultiButton(fV1, subgroup[0], 30, 3, selnames, "center"))
  979.       fV1->AddFrame(surfButtons->outsidebox, f1expandX);
  980.  
  981.    fT1->AddFrame(fV1, f1expandX);
  982.  
  983.    // Timing tab
  984.    fT1 = analTab->AddTab("Timing");
  985.    fV1 = new TGCompositeFrame(fT1, subgroup[0], subgroup[1], kVerticalFrame | kFixedWidth | kFixedHeight);
  986.  
  987.    fT1->AddFrame(fV1, f1expandX);
  988.  
  989.    // Analysis tabs
  990.    fH1->AddFrame(analTab, /*f1expandX*/f0leftX);
  991.  
  992.    // Peak fitting settings
  993.    fV1 = new TGCompositeFrame(fH1, subgroup[0], 30, kVerticalFrame);
  994.  
  995.    fH2 = new TGCompositeFrame(fV1, subgroup[0], 30, kHorizontalFrame);
  996.    // Select the sigma for peak fitting
  997.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *fitSigma -> Sigma for peak fitting\n");
  998.    fitSigma = new TSubStructure();
  999.    for(int i = 0; i < 6; i++) numform[i] = 0;
  1000.    numform[0] = 6; numform[1] = 3; numform[2] = 2;
  1001.    if(fitSigma->TGLabelNEntry(fH2, subgroup[0]/2, 30, "Peak sigma:", 1.2, numform, "center"))
  1002.       fH2->AddFrame(fitSigma->outsidebox, f0centerX);
  1003.    // Select the signal to noise treshold for peak fitting
  1004.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *fitTresh -> S/N ratio for peak fitting\n");
  1005.    fitTresh = new TSubStructure();
  1006.    for(int i = 0; i < 6; i++) numform[i] = 0;
  1007.    numform[0] = 6; numform[1] = 3; numform[2] = 2;
  1008.    if(fitTresh->TGLabelNEntry(fH2, subgroup[0]/2, 30, "S/N ratio:", 0.005, numform, "center"))
  1009.       fH2->AddFrame(fitTresh->outsidebox, f0centerX);
  1010.    fV1->AddFrame(fH2, f1expandXpad);
  1011.  
  1012.    // Select the background interpolation for peak fitting
  1013.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *fitInter -> Background interpolation for peak fitting\n");
  1014.    fitInter = new TSubStructure();
  1015.    for(int i = 0; i < 6; i++) numform[i] = 0;
  1016.    numform[0] = 5; numform[2] = 1;
  1017.    if(fitInter->TGLabelNEntry(fV1, subgroup[0], 30, "Back. interpolation:", 7, numform, "center"))
  1018.       fV1->AddFrame(fitInter->outsidebox, f0centerX);
  1019.  
  1020.    // Select the ADC offset
  1021.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *adcOffset -> Select the offset for all ADC spectra\n");
  1022.    adcOffset = new TSubStructure();
  1023.    for(int i = 0; i < 6; i++) numform[i] = 0;
  1024.    numform[0] = 6; numform[1] = 2;
  1025.    if(adcOffset->TGLabelNEntry(fV1, subgroup[0], 30, "ADC spectrum offset:", 0.00, numform, "center"))
  1026.       fV1->AddFrame(adcOffset->outsidebox, f0centerX);
  1027.  
  1028.    // Select the acceptable error for peak fitting
  1029.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *accError -> Acceptable peak fitting error for peak fitting\n");
  1030.    accError = new TSubStructure();
  1031.    for(int i = 0; i < 6; i++) numform[i] = 0;
  1032.    numform[0] = 6; numform[1] = 2; numform[2] = 1;
  1033.    if(accError->TGLabelNEntry(fV1, subgroup[0], 30, "Max. peak fit error:", 0.15, numform, "center"))
  1034.       fV1->AddFrame(accError->outsidebox, f0centerX);
  1035.  
  1036.    // Select the pedestal lower limit for peak fitting
  1037.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *pedesLow -> Lower ADC limit of pedestal peak for peak fitting\n");
  1038.    pedesLow = new TSubStructure();
  1039.    for(int i = 0; i < 6; i++) numform[i] = 0;
  1040.    numform[0] = 6; numform[1] = 1; numform[2] = 2;
  1041.    if(pedesLow->TGLabelNEntry(fV1, subgroup[0], 30, "Pedestal low limit:", 0.0, numform, "center"))
  1042.       fV1->AddFrame(pedesLow->outsidebox, f0centerX);
  1043.  
  1044.    // Check buttons to toggle subtracting the background and exporting the fitted spectra
  1045.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *fitChecks -> 2 check buttons (substracting background, exporting fitted spectra)\n");
  1046.    fitChecks = new TSubStructure();
  1047.    checksel = new int[2];
  1048.    checksel[0] = 1; checksel[1] = 0;
  1049.    selnames[0] = "Backround subtraction ON/OFF";
  1050.    selnames[1] = "Export fitted spectra ON/OFF";
  1051.    if(fitChecks->TGCheckList(fV1, subgroup[0], 30, 2, selnames, checksel, "vertical", "center"))
  1052.       fV1->AddFrame(fitChecks->outsidebox, f1expandXpad);
  1053.    delete[] checksel;
  1054.  
  1055.    // Analysis progress bar
  1056.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *analysisProgress -> Horizontal progress bar for analysis\n");
  1057.    analysisProgress = new TSubStructure();
  1058.    if(analysisProgress->TGLabelProgress(fV1, subgroup[0], 30, "Current analysis:"))
  1059.       fV1->AddFrame(analysisProgress->outsidebox, f1expandXpad);
  1060.  
  1061.    fH1->AddFrame(fV1, f1expandX);
  1062.  
  1063.    analysisLayout[1]->AddFrame(fH1, f1expandXpad);
  1064.  
  1065.    // Actions for analysis pane
  1066.    intSpectButtons->widgetTB[0]->Connect("Clicked()", "TGAppMainFrame", this, "AnalysisHandle(=0)");
  1067.    intSpectButtons->widgetTB[1]->Connect("Clicked()", "TGAppMainFrame", this, "AnalysisHandle(=1)");
  1068.    intSpectButtons->widgetTB[2]->Connect("Clicked()", "TGAppMainFrame", this, "AnalysisDefaults()");
  1069.  
  1070.    relPdeButtons->widgetTB[0]->Connect("Clicked()", "TGAppMainFrame", this, "AnalysisHandle(=0)");
  1071.    relPdeButtons->widgetTB[1]->Connect("Clicked()", "TGAppMainFrame", this, "AnalysisHandle(=1)");
  1072.    relPdeButtons->widgetTB[2]->Connect("Clicked()", "TGAppMainFrame", this, "AnalysisDefaults()");
  1073.    darkRun->widgetTB[0]->Connect("Clicked()", "TGAppMainFrame", this, "SelectDarkHist()");
  1074.  
  1075.    brDownButtons->widgetTB[0]->Connect("Clicked()", "TGAppMainFrame", this, "AnalysisHandle(=0)");
  1076.    brDownButtons->widgetTB[1]->Connect("Clicked()", "TGAppMainFrame", this, "AnalysisHandle(=1)");
  1077.    brDownButtons->widgetTB[2]->Connect("Clicked()", "TGAppMainFrame", this, "AnalysisDefaults()");
  1078.  
  1079.    surfButtons->widgetTB[0]->Connect("Clicked()", "TGAppMainFrame", this, "AnalysisHandle(=0)");
  1080.    surfButtons->widgetTB[1]->Connect("Clicked()", "TGAppMainFrame", this, "AnalysisHandle(=1)");
  1081.    surfButtons->widgetTB[2]->Connect("Clicked()", "TGAppMainFrame", this, "AnalysisDefaults()");
  1082. // Analysis pane ---------------------------------------------------------------------------
  1083.  
  1084. // Histogram pane --------------------------------------------------------------------------
  1085.    analysisCanvas = new TRootEmbeddedCanvas("analysisCanvas",analysisLayout[2],300,300);
  1086.    analysisLayout[2]->AddFrame(analysisCanvas, f1expand2d);
  1087.    analysisCanvas->GetCanvas()->SetGrid();
  1088. // Histogram pane --------------------------------------------------------------------------
  1089.  
  1090. // Histogram controls pane -----------------------------------------------------------------
  1091.    subgroup[0] = (analysisLayout[3]->GetWidth())-4;
  1092.  
  1093.    // Control for histogram X range
  1094.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *adcRange -> Range for ADC histogram\n");
  1095.    adcRange = new TSubStructure();
  1096.    for(int i = 0; i < 6; i++) { numform[i] = 0; numform2[i] = 0; }
  1097.    numform[0] = 6; numform2[0] = 6;
  1098.    if(adcRange->TGLabelDoubleNEntry(analysisLayout[3], subgroup[0], 30, "ADC range (min, max):", 0, numform, 0, numform2, "center"))
  1099.       analysisLayout[3]->AddFrame(adcRange->outsidebox, f1expandXpad);
  1100.  
  1101.    // TDC window for getting data
  1102.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *tdcRange -> Range for TDC histogram\n");
  1103.    tdcRange = new TSubStructure();
  1104.    for(int i = 0; i < 6; i++) { numform[i] = 0; numform2[i] = 0; }
  1105.    numform[0] = 8; numform[1] = 2; numform2[0] = 8; numform2[1] = 2;
  1106.    if(tdcRange->TGLabelDoubleNEntry(analysisLayout[3], subgroup[0], 30, "TDC range (min, max):", -0.5, numform, 221.8, numform2, "center"))
  1107.       analysisLayout[3]->AddFrame(tdcRange->outsidebox, f1expandXpad);
  1108.  
  1109.    // Y axis range settings
  1110.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *yRange -> Y axis range\n");
  1111.    yRange = new TSubStructure();
  1112.    for(int i = 0; i < 6; i++) { numform[i] = 0; numform2[i] = 0; }
  1113.    numform[0] = 8; numform[1] = 1; numform2[0] = 8; numform2[1] = 1;
  1114.    if(yRange->TGLabelDoubleNEntry(analysisLayout[3], subgroup[0], 30, "Y range (min, max):", 0, numform, 0, numform2, "center"))
  1115.       analysisLayout[3]->AddFrame(yRange->outsidebox, f1expandXpad);
  1116.  
  1117.    fH1 = new TGHorizontalFrame(analysisLayout[3], subgroup[0], 30);
  1118.    // Select the channel to display
  1119.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *selectCh -> Channel to display\n");
  1120.    selectCh = new TSubStructure();
  1121.    for(int i = 0; i < 6; i++) numform[i] = 0;
  1122.    numform[0] = 3; numform[2] = 2; numform[3] = 2; numform[4] = 0; numform[5] = 7; // TODO - ko odprem file, nastavi zgornjo limito
  1123.    if(selectCh->TGLabelNEntry(fH1, subgroup[0]/2-24, 30, "Display channel:", 0, numform, "center"))
  1124.       fH1->AddFrame(selectCh->outsidebox, f0leftX);
  1125.    selChannel = -1;
  1126.  
  1127.    // Change plot type
  1128.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *plotType -> 3 buttons for selecting the plot type (ADC, TDC, ADC/TDC)\n");
  1129.    plotType = new TSubStructure();
  1130.    selnames[0] = "ADC"; selnames[1] = "TDC"; selnames[2] = "ADC/TDC";
  1131.    if(plotType->TGMultiButton(fH1, subgroup[0]/2-24, 30, 3, selnames, "center"))
  1132.       fH1->AddFrame(plotType->outsidebox, f1expandX);
  1133.    analysisLayout[3]->AddFrame(fH1, f1expandXpad);
  1134.  
  1135.    // Check button to toggle logarithmic scale
  1136.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *histOpt -> 2 check buttons (histogram logarithmic scale, clean plots)\n");
  1137.    histOpt = new TSubStructure();
  1138.    checksel = new int[2];
  1139.    checksel[0] = 0; checksel[1] = 1;
  1140.    selnames[0] = "Logarithmic scale ON/OFF";
  1141.    selnames[1] = "Clean plots ON/OFF";
  1142.    if(histOpt->TGCheckList(analysisLayout[3], subgroup[0], 30, 2, selnames, checksel, "vertical", "center"))
  1143.       analysisLayout[3]->AddFrame(histOpt->outsidebox, f1expandXpad);
  1144.    delete[] checksel;
  1145.  
  1146.    // Export the selected files
  1147.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *exportHist -> Button to export current histogram\n");
  1148.    exportHist = new TSubStructure();
  1149.    if(exportHist->TGLabelButton(analysisLayout[3], subgroup[0], 30, "Export selected histograms:", "Export", "center"))
  1150.       analysisLayout[3]->AddFrame(exportHist->outsidebox, f1expandXpad);
  1151.  
  1152.    // Edit the selected histograms
  1153.    if(DBGSIG > 1) printf("AppLayout(): Creating TSubStructure *editSelHist -> Button to additionally edit the selected histograms (make a canvas clone in a new tab)\n");
  1154.    editSelHist = new TSubStructure();
  1155.    if(editSelHist->TGLabelButton(analysisLayout[3], subgroup[0], 30, "Edit selected histograms:", "Edit", "center"))
  1156.       analysisLayout[3]->AddFrame(editSelHist->outsidebox, f1expandXpad);
  1157.  
  1158.    // Actions for histogram controls pane //TODO
  1159.    for(int i = 0; i < 2; i++)
  1160.    {
  1161.       adcRange->widgetNE[i]->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "UpdateHistogram(=0)");
  1162. //      (adcRange->widgetNE[i]->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "UpdateHistogram(=0)");
  1163.       tdcRange->widgetNE[i]->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "UpdateHistogram(=0)");
  1164. //      (tdcRange->widgetNE[i]->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "UpdateHistogram(=0)");
  1165.       yRange->widgetNE[i]->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "UpdateHistogram(=0)");
  1166. //      (yRange->widgetNE[i]->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "UpdateHistogram(=0)");
  1167.    }
  1168.    plotType->widgetTB[0]->Connect("Clicked()", "TGAppMainFrame", this, "ChangeHisttype(=0)");
  1169.    plotType->widgetTB[1]->Connect("Clicked()", "TGAppMainFrame", this, "ChangeHisttype(=1)");
  1170.    plotType->widgetTB[2]->Connect("Clicked()", "TGAppMainFrame", this, "ChangeHisttype(=2)");
  1171.    selectCh->widgetNE[0]->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "UpdateHistogram(=2)");
  1172.    selectCh->widgetNE[0]->Connect("ValueChanged(Long_t)", "TGAppMainFrame", this, "UpdateHistogram(=2)");
  1173.    (selectCh->widgetNE[0]->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "UpdateHistogram(=2)");
  1174.    histOpt->widgetChBox[0]->Connect("Clicked()", "TGAppMainFrame", this, "HistogramOptions(=0)");
  1175.    histOpt->widgetChBox[1]->Connect("Clicked()", "TGAppMainFrame", this, "HistogramOptions(=1)");
  1176.    exportHist->widgetTB[0]->Connect("Clicked()", "TGAppMainFrame", this, "UpdateHistogram(=1)");
  1177.  
  1178. // Histogram controls pane -----------------------------------------------------------------
  1179. }
  1180.  
  1181. // -------------------------------------------------------------------
  1182.  
  1183. // Closing main window and checking about information ----------------
  1184.  
  1185. void TGAppMainFrame::CloseWindow()
  1186. {
  1187.    gApplication->Terminate(0);
  1188. }
  1189.  
  1190. Bool_t TGAppMainFrame::About()
  1191. {
  1192.    int ret = 0;
  1193.  
  1194.    new TGMsgBox(gClient->GetRoot(), fMain, fMain->GetWindowName(), "Software for SiPM characterization with\nCAMAC, scope, bias voltage and table position support\n\nCreated by Gasper Kukec Mezek (gasper.kukec@ung.si),\nUpdated on July 17th 2015", kMBIconQuestion, kMBClose, &ret);
  1195.  
  1196.    return kFALSE;
  1197. }
  1198.  
  1199. // -------------------------------------------------------------------
  1200.  
  1201. // Subwindow constructor (+layout) and close subwindow ---------------
  1202. /*
  1203. TGMdiSubwindow::TGMdiSubwindow(TGMdiMainFrame *main, int w, int h)
  1204. {
  1205.    // Create a new subwindow
  1206.    fMdiFrame = new TGMdiFrame(main, w, h);
  1207.    fMdiFrame->Connect("CloseWindow()", "TGMdiSubwindow", this, "CloseWindow(=0)");
  1208.    fMdiFrame->DontCallClose();
  1209. }
  1210.  
  1211. Bool_t TGMdiSubwindow::CloseWindow(int layoutchange)
  1212. {
  1213.    int ret = 0;
  1214.  
  1215.    if(layoutchange == 0)
  1216.       new TGMsgBox(gClient->GetRoot(), fMdiFrame, fMdiFrame->GetWindowName(), "Really want to close the window?", kMBIconExclamation, kMBYes | kMBNo, &ret);
  1217.    else if(layoutchange == 1)
  1218.       ret = kMBYes;
  1219.    if(ret == kMBYes)
  1220.    {
  1221.       if(strcmp("Information window", fMdiFrame->GetWindowName()) == 0)
  1222.          id = -1;
  1223.       return fMdiFrame->CloseWindow();
  1224.    }
  1225.  
  1226.    return kFALSE;
  1227. }*/
  1228.  
  1229. // -------------------------------------------------------------------
  1230.  
  1231. // Main function -----------------------------------------------------
  1232. void root_app()
  1233. {
  1234.    if(DBGSIG > 1)
  1235.    {
  1236.       printf("root_app(): Starting objects\n");
  1237.       gObjectTable->Print();
  1238.    }
  1239.  
  1240.    int winWidth = 1240;
  1241.    int winHeight = 800;
  1242.    layoutMainWindow(&winWidth, &winHeight);
  1243.  
  1244.    new TGAppMainFrame(gClient->GetRoot(), winWidth, winHeight);
  1245. }
  1246.  
  1247. int main(int argc, char **argv)
  1248. {
  1249.    if(DBGSIG > 1)
  1250.    {
  1251.       printf("main(): Starting objects\n");
  1252.       gObjectTable->Print();
  1253.    }
  1254.  
  1255.    TApplication theApp("MdiTest", &argc, argv);
  1256.    root_app();
  1257.    theApp.Run();
  1258.  
  1259.    return 0;
  1260. }
  1261.  
  1262. // -------------------------------------------------------------------
  1263.