]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCCalibViewerGUI.cxx
made const array arguments of GetPredictedChi2 methods
[u/mrichter/AliRoot.git] / TPC / AliTPCCalibViewerGUI.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16
17 ///////////////////////////////////////////////////////////////////////////////
18 //                                                                           //
19 //  GUI for the AliTPCCalibViewer                                            //
20 //  used for the calibration monitor                                         //
21 //  All functionalities of the AliTPCCalibViewer are here available
22 //  
23 //  Example usage:                                                           //
24 /*
25   aliroot
26   AliTPCCalibViewerGUI::ShowGUI("CalibTree.root")
27   
28 */
29 //                         //
30 //                                                                           //
31 ///////////////////////////////////////////////////////////////////////////////
32
33
34 #include "AliTPCCalibViewerGUI.h"
35 #include "AliTPCCalPad.h"
36 #include <iostream>
37
38 #include <TCanvas.h>
39 #include <TPad.h>
40 #include <TVirtualPad.h>
41
42 #include <TROOT.h>
43 #include <TMath.h>
44 #include <TObjArray.h>
45 #include <TObjString.h>
46 #include <TVector.h>
47 #include <string.h>
48 #include <TH1.h>
49 #include "TStyle.h"
50 #include "TGFileDialog.h"
51 #include "TGInputDialog.h"
52 #include "AliTPCCalibViewer.h"
53 #include "AliTPCPreprocessorOnline.h"
54
55 // #include "TGListBox.h"
56 // #include "TGNumberEntry"
57 // #include "TGSplitter"
58 // #include "TGTab"
59 // #include "TGLabel"
60 // #include "TGButtonGroup"
61 // #include "TGComboBox"
62 // #include "TRootEmbeddedCanvas"
63 // #include "TGButton"
64 // #include "TGRadioButton"
65 // #include "GTCheckButton"
66 // #include "TGTextEntry"
67
68
69
70
71 ClassImp(AliTPCCalibViewerGUI)
72
73 AliTPCCalibViewerGUI::AliTPCCalibViewerGUI(const TGWindow *p, UInt_t w, UInt_t h, char* fileName)
74   : TGCompositeFrame(p, w, h),
75     fViewer(0),
76     fPreprocessor(0),
77     fContTopBottom(0),
78     fContLCR(0),
79     fContLeft(0),
80     ftabLeft(0),
81     ftabLeft0(0),
82     ftabLeft1(0),
83     ftabRight(0),
84     fTabRight0(0),
85     fTabRight1(0),
86     fContRight(0),
87     fContCenter(0),
88     fContPlotOpt(0),
89     fContDrawOpt(0),
90     fContDrawOptSub1D2D(0),
91     fContNormalized(0),
92     fContCustom(0),
93     fContCuts(0),
94     fContSector(0),
95     fContAddCuts(0),
96     fContFit(0),
97     fContAddFit(0),
98     fContScaling(0),
99     fContSetMax(0),
100     fContSetMin(0),
101     fContAddDrawOpt(0),
102     fListVariables(0),
103     fBtnDraw(0),
104     fBtnFit(0),
105     fBtnAddFitFunction(0),
106     fBtnGetMinMax(0),
107     fCanvMain(0),
108     fRadioRaw(0),
109     fRadioNormalized(0),
110     fRadioPredefined(0),
111     fRadioCustom(0),
112     fRadio1D(0),
113     fRadio2D(0),
114     fRadioTPC(0),
115     fRadioSideA(0),
116     fRadioSideC(0),
117     fRadioROC(0),
118     fRadioSector(0),
119     fComboAddDrawOpt(0),
120     fChkAuto(0),
121     fChkAutoAppend(0),
122     fComboMethod(0),
123     fListNormalization(0),
124     fComboCustom(0),
125     fLblCustomDraw(0),
126     fChkAddDrawOpt(0),
127     fNmbSector(0),
128     fLblSector(0),
129     fChkCutZero(0),
130     fChkAddCuts(0),
131     fLblAddCuts(0),
132     fComboAddCuts(0), 
133     fComboCustomFit(0),
134     fChkSetMax(0),
135     fChkSetMin(0),
136     fChkGetMinMaxAuto(0),
137     fTxtSetMax(0),
138     fTxtSetMin(0) ,
139     fContDrawOpt1D(0), 
140     fcontDrawOpt1DSubLR(0),
141     fContDrawOpt1DSubNSC(0), 
142     fRadioNorm(0),
143     fRadioSigma(0),
144     fTxtSigmas(0),
145     fContCumuLR(0),
146     fContCumLeft(0),
147     fContCumRight(0),
148     fLblSigmaMax(0),
149     fTxtSigmaMax(0),
150     fRadioCumulative(0),
151     fCheckCumulativePM(0),
152     fRadioIntegrate(0),
153     fContDrawOpt1DSubMML(0),
154     fChkMean(0),
155     fChkMedian(0),
156     fChkLTM(0),
157     fContStatOpt(0),
158     fChkStatName(0),
159     fChkStatEntries(0),
160     fContStatMean(0),
161     fChkStatMean(0),
162     fChkStatMeanPM(0),
163     fContStatRMS(0),
164     fChkStatRMS(0),
165     fChkStatRMSPM(0),
166     fChkStatUnderflow(0),
167     fChkStatOverflow(0),
168     fChkStatIntegral(0),
169     fContStatSkew(0),
170     fChkStatSkewness(0),
171     fChkStatSkewnessPM(0),
172     fContStatKurt(0),
173     fChkStatKurtosis(0),
174     fChkStatKurtosisPM(0),
175     fBtnUnchekAll(0),
176     fContLabeling(0),
177     fChkLabelTitle(0),
178     fTxtLabelTitle(0),
179     fChkLabelXaxis(0),
180     fTxtLabelXaxis(0),
181     fChkLabelYaxis(0),
182     fTxtLabelYaxis(0),
183     fChkLabelGetAuto(0),
184     fContSave(0),
185     fBtnSave(0),
186     fContAddSaveOpt(0),
187     fChkAddSaveOpt(0),
188     fComboAddSaveOpt(0),
189     fContExport(0),
190     fContAddExport(0),
191     fComboExportName(0),
192     fBtnExport(0),
193     fBtnAddNorm(0), 
194     fContTree(0),
195     fBtnDumpToFile(0),
196     fBtnLoadTree(0),
197     fChkAddAsReference(0),
198     fTxtRefName(0), 
199     fInitialized(0)
200 {
201    //
202    // AliTPCCalibViewerGUI constructor; fileName specifies the ROOT tree used for drawing 
203    //
204
205    // draw the GUI:
206    fPreprocessor = new AliTPCPreprocessorOnline();
207    DrawGUI(p, w, h);
208    // initialize the AliTPCCalibViewer:
209    if (fileName) Initialize(fileName);
210    // set default button states:
211    SetInitialValues();
212    // do first drawing: 
213    if (fileName) DoDraw();
214 }
215
216
217 void AliTPCCalibViewerGUI::DrawGUI(const TGWindow */*p*/, UInt_t w, UInt_t h) {
218    // 
219    // draw the GUI
220    // 
221    // ======================================================================   
222    // ************************* Display everything *************************
223    // ======================================================================
224    
225    SetCleanup(kDeepCleanup);
226
227    // *****************************************************************************
228    // ************************* content of this MainFrame *************************
229    // *****************************************************************************
230    // top level container with horizontal layout
231    fContTopBottom = new TGCompositeFrame(this, w, h, kVerticalFrame | kFixedWidth | kFixedHeight);
232    AddFrame(fContTopBottom, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
233    
234    fContLCR = new TGCompositeFrame(fContTopBottom, w, h, kHorizontalFrame | kFixedWidth | kFixedHeight);
235    fContTopBottom->AddFrame(fContLCR, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
236    
237    // ***********************************************************************
238    // ************************* content of fContLCR *************************
239    // ***********************************************************************
240    // left container
241    fContLeft = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
242    fContLCR->AddFrame(fContLeft, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 5, 3, 3, 3));
243    
244    // left vertical splitter
245    TGVSplitter *splitLeft = new TGVSplitter(fContLCR);
246    splitLeft->SetFrame(fContLeft, kTRUE);
247    fContLCR->AddFrame(splitLeft, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
248
249    // right container
250    fContRight = new TGCompositeFrame(fContLCR, 150, 200, kVerticalFrame | kFixedWidth | kFitHeight);
251    fContLCR->AddFrame(fContRight, new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandY, 3, 5, 3, 3));
252    
253    // center container
254    fContCenter = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
255    fContLCR->AddFrame(fContCenter, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
256
257    // right vertical splitter
258    TGVSplitter *splitRight = new TGVSplitter(fContLCR);
259    splitRight->SetFrame(fContRight, kFALSE);
260    fContLCR->AddFrame(splitRight, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
261    
262    
263    // ========================================================================
264    // ************************* content of fContLeft *************************
265    // ========================================================================
266    // --- draw button and tabLeft ---
267    // draw button
268    fBtnDraw = new TGTextButton(fContLeft, "&Draw");
269    fContLeft->AddFrame(fBtnDraw, new TGLayoutHints(kLHintsExpandX, 10, 10, 0, 0));
270    //fBtnDraw->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "DoTest(=\"fBtnDraw clicked\")");
271    fBtnDraw->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "DoDraw()");
272    fBtnDraw->SetToolTipText("Press here to draw according to selections.");
273    
274    // tabs on the left side:
275    ftabLeft = new TGTab(fContLeft);
276    fContLeft->AddFrame(ftabLeft, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 8, 0));
277    ftabLeft0 = ftabLeft->AddTab("General");
278    ftabLeft1 = ftabLeft->AddTab("More plot options");
279
280    
281       // **************************** content of tabLeft0 *******************************
282       
283       // draw options container *** fcontDrawOpt ***  " Plot options "
284       fContDrawOpt = new TGGroupFrame(ftabLeft0, "Plot options", kVerticalFrame | kFitWidth | kFitHeight);
285       ftabLeft0->AddFrame(fContDrawOpt, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
286       fContDrawOptSub1D2D = new TGCompositeFrame(fContDrawOpt, 200, 23, kHorizontalFrame | kFitWidth | kFixedHeight);
287       fContDrawOpt->AddFrame(fContDrawOptSub1D2D, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
288       
289          // ------------------------- content of fContDrawOpt -------------------------
290          // -- radio1D, radio2D, chkAuto
291          // 1D radio button
292          fRadio1D = new TGRadioButton(fContDrawOptSub1D2D, "1D", 30);
293          fContDrawOptSub1D2D->AddFrame(fRadio1D, new TGLayoutHints(kLHintsNormal, 0, 2, 0, 0));
294          fRadio1D->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsGeneral()");
295          fRadio1D->SetToolTipText("1D drawing \nSelect this if you want to have the full control for the custom draw.");
296          
297          // 2D radio button
298          fRadio2D = new TGRadioButton(fContDrawOptSub1D2D, "2D", 31);
299          fContDrawOptSub1D2D->AddFrame(fRadio2D, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
300          fRadio2D->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsGeneral()");
301          fRadio2D->SetToolTipText("2D drawing");
302          
303          // additional draw options container
304          fContAddDrawOpt = new TGCompositeFrame(fContDrawOpt, 200, 200, kVerticalFrame | kFitWidth | kFitHeight);
305          fContDrawOpt->AddFrame(fContAddDrawOpt, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
306
307             //  content of --- fContAddDrawOpt ---
308             // addition draw options label
309             fChkAddDrawOpt = new TGCheckButton(fContAddDrawOpt, "Draw options:");
310             //fChkAddDrawOpt->SetTextJustify(kTextLeft);
311             fContAddDrawOpt->AddFrame(fChkAddDrawOpt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
312             fChkAddDrawOpt->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "DoNewSelection()");
313             fChkAddDrawOpt->SetToolTipText("Enter additional draw options like 'prof' or 'colz' here.\nBe careful with the option 'same' for 2D drawings as it will crash (ROOT feature).");
314             
315             // additional draw options combo box
316             fComboAddDrawOpt = new TGComboBox(fContAddDrawOpt);
317             fComboAddDrawOpt->Resize(0, fBtnDraw->GetDefaultHeight());
318             fComboAddDrawOpt->EnableTextInput(kTRUE);
319             fContAddDrawOpt->AddFrame(fComboAddDrawOpt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
320             fComboAddDrawOpt->Connect("ReturnPressed()", "AliTPCCalibViewerGUI", this, "HandleButtonsGeneral(=14)");
321             fComboAddDrawOpt->Connect("Selected(Int_t)", "AliTPCCalibViewerGUI", this, "DoNewSelection()");
322                   
323          // automatic redraw check button
324          fChkAuto = new TGCheckButton(fContDrawOpt, "Auto redraw");
325          fContDrawOpt->AddFrame(fChkAuto, new TGLayoutHints(kLHintsNormal, 0, 2, 0, 0));
326          fChkAuto->SetToolTipText("Decide if you want an automatic redraw on each new selection.\nNot recommended on a slow machine, during remote connection or if your draw option is 'same'.");
327          
328          // automatic append ending check button
329          fChkAutoAppend = new TGCheckButton(fContDrawOpt, "Auto add appending");
330          fContDrawOpt->AddFrame(fChkAutoAppend, new TGLayoutHints(kLHintsNormal, 0, 2, 0, 0));
331          fChkAutoAppend->SetToolTipText("Tries to repair your custom draw string or custom cut string, if you forgot '~' or '.fElements' \nThis function may be buggy!");
332                
333       
334       // *** predefined radio button ***  " Predefined "
335       fRadioPredefined = new TGRadioButton(ftabLeft0, "Predefined: ", 13);
336       ftabLeft0->AddFrame(fRadioPredefined, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
337       fRadioPredefined->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsGeneral()");
338       fRadioPredefined->SetToolTipText("Draw predefined variables according to selection.");
339       
340       // list of variables
341       fListVariables = new TGListBox(ftabLeft0);
342       ftabLeft0->AddFrame(fListVariables, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY, 10, 0, 0, 0));
343       fListVariables->Connect("Selected(Int_t)", "AliTPCCalibViewerGUI", this, "DoNewSelection()");
344    
345       
346       // normalization options container *** fContPlotOpt ***
347       //fContPlotOpt = new TGCompositeFrame(fContLeft, 200, 200, kVerticalFrame | kFitWidth | kFitHeight);
348       fContPlotOpt = new TGGroupFrame(ftabLeft0, "Normalization options", kVerticalFrame | kFitWidth | kFitHeight);
349       ftabLeft0->AddFrame(fContPlotOpt, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10, 0, 0, 0));
350
351          // ------------------------- content of fContPlotOpt -------------------------
352          // raw radio button
353          fRadioRaw = new TGRadioButton(fContPlotOpt, "Raw", 10);
354          fContPlotOpt->AddFrame(fRadioRaw, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
355          fRadioRaw->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsGeneral()");
356          fRadioRaw->SetToolTipText("Plot without normalization");
357       
358          // normalized radio button
359          fRadioNormalized = new TGRadioButton(fContPlotOpt, "Normalized", 11);
360          fContPlotOpt->AddFrame(fRadioNormalized, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
361          fRadioNormalized->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsGeneral()");
362          fRadioNormalized->SetToolTipText("Normalize data");
363       
364          // normalized options container *** fContNormalized ***
365          fContNormalized = new TGCompositeFrame(fContPlotOpt, 200, 200, kVerticalFrame | kFitWidth | kFitHeight);
366          fContPlotOpt->AddFrame(fContNormalized, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 15, 0, 0, 0));
367       
368             // --- content of fContNormalized ---
369             // --- combo box to select 'subtract' or 'divide', list of normalization variables
370             // method drop down combo box
371             fComboMethod = new TGComboBox(fContNormalized);
372             fComboMethod->Resize(0, fBtnDraw->GetDefaultHeight());
373             fContNormalized->AddFrame(fComboMethod, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
374             fComboMethod->Connect("Selected(Int_t)", "AliTPCCalibViewerGUI", this, "DoNewSelection()");
375          
376             // list of normalization variables
377             fListNormalization = new TGListBox(fContNormalized);
378             fContNormalized->AddFrame(fListNormalization, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
379             fListNormalization->Connect("Selected(Int_t)", "AliTPCCalibViewerGUI", this, "DoNewSelection()");
380
381       // custom radio button
382       fRadioCustom = new TGRadioButton(ftabLeft0, "Custom: ", 12);
383       ftabLeft0->AddFrame(fRadioCustom, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
384       fRadioCustom->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsGeneral()");
385       fRadioCustom->SetToolTipText("Draw data according to user specific text entry in the 'Custom Draw' line. Remember '~' (= '.fElements')!");
386       // custom options container is located further down
387       
388       // **************************** content of tabLeft1 *******************************
389       
390       // draw options container *** fcontDrawOpt1D ***  " Plot options "
391       fContDrawOpt1D = new TGGroupFrame(ftabLeft1, "1D Plot options", kVerticalFrame | kFitWidth | kFitHeight);
392       ftabLeft1->AddFrame(fContDrawOpt1D, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
393       
394       fcontDrawOpt1DSubLR = new TGCompositeFrame(fContDrawOpt1D, 1, 1, kVerticalFrame | kFitWidth | kFitHeight);
395       fContDrawOpt1D->AddFrame(fcontDrawOpt1DSubLR, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
396       
397          // ***** content of fContDrawOpt1DSubLR *****
398          fContDrawOpt1DSubNSC = new TGCompositeFrame(fcontDrawOpt1DSubLR, 200, 23, kVerticalFrame | kFitWidth | kFitHeight);
399          fcontDrawOpt1DSubLR->AddFrame(fContDrawOpt1DSubNSC, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
400          
401             // --------------------------- content of fContDrawOpt1DSubNSC -----------------
402             fRadioNorm = new TGRadioButton(fContDrawOpt1DSubNSC, "Normal", 110);
403             fContDrawOpt1DSubNSC->AddFrame(fRadioNorm, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
404             fRadioNorm->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtons1D()");
405             fRadioNorm->SetToolTipText("Produce a normal 1D plot, a histogram of the selected data.");
406                
407             fRadioSigma = new TGRadioButton(fContDrawOpt1DSubNSC, "Sigma", 111);
408             fContDrawOpt1DSubNSC->AddFrame(fRadioSigma, new TGLayoutHints(kLHintsNormal, 0, 0, 5, 0));
409             fRadioSigma->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtons1D()");
410             fRadioSigma->SetToolTipText("Draw a normal histogram, but also lines that indicate the mean/median/LTM \nand sigmas of the selected data.");
411
412             fTxtSigmas = new TGTextEntry(fContDrawOpt1DSubNSC, "2; 4; 6", 111);
413             fContDrawOpt1DSubNSC->AddFrame(fTxtSigmas, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 10, 15, 0, 0));
414             fTxtSigmas->Connect("ReturnPressed()", "AliTPCCalibViewerGUI", this, "HandleButtons1D(=111)");
415             fTxtSigmas->SetToolTipText("Enter sigma intervals you would like to be indicated by lines. \nExample: '2; 4; 6'");
416                
417             fContCumuLR = new TGCompositeFrame(fContDrawOpt1DSubNSC, 200, 23, kHorizontalFrame | kFitWidth | kFitHeight);
418             fContDrawOpt1DSubNSC->AddFrame(fContCumuLR, new TGLayoutHints(kLHintsExpandX, 0, 0, 5, 0));
419             
420                fContCumLeft = new TGCompositeFrame(fContCumuLR, 200, 23, kVerticalFrame | kFitWidth | kFitHeight);
421                fContCumuLR->AddFrame(fContCumLeft, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
422                            
423                   fRadioCumulative = new TGRadioButton(fContCumLeft, "Cumulative", 112);
424                   fContCumLeft->AddFrame(fRadioCumulative, new TGLayoutHints(kLHintsNormal, 0, 10, 0, 0));
425                   fRadioCumulative->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtons1D()");
426                   fRadioCumulative->SetToolTipText("Draw the cumulative (SigmaCut) of the given selection. \nThe data distribution is integrated, starting from the mean/median/LTM.");
427                   
428                   fCheckCumulativePM = new TGCheckButton(fContCumLeft, "Plus/Minus");
429                   fContCumLeft->AddFrame(fCheckCumulativePM, new TGLayoutHints(kLHintsNormal, 10, 15, 0, 0));
430                   fCheckCumulativePM->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtons1D()");
431                   fCheckCumulativePM->SetToolTipText("Decide whether you want the cumulative integration for each direction (+/-) \nor only for the absolute distance to the mean/median/LTM value.");
432                   
433                   fRadioIntegrate = new TGRadioButton(fContCumLeft, "Integrate", 113);
434                   fContCumLeft->AddFrame(fRadioIntegrate, new TGLayoutHints(kLHintsNormal, 0, 0, 5, 0));
435                   fRadioIntegrate->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtons1D()");
436                   fRadioIntegrate->SetToolTipText("Draw the integral of the given selection.");
437                   
438                fContCumRight = new TGCompositeFrame(fContCumuLR, 200, 23, kVerticalFrame | kFitWidth | kFitHeight);
439                fContCumuLR->AddFrame(fContCumRight, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
440                
441                   fLblSigmaMax = new TGLabel(fContCumRight, "SigmaMax:");
442                   fLblSigmaMax->SetTextJustify(kTextLeft);
443                   fContCumRight->AddFrame(fLblSigmaMax, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 5, 0, 0, 0));
444
445                   fTxtSigmaMax = new TGTextEntry(fContCumRight, "5", 112);
446                   fContCumRight->AddFrame(fTxtSigmaMax, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 10, 15, 0, 0));
447                   fTxtSigmaMax->Connect("ReturnPressed()", "AliTPCCalibViewerGUI", this, "HandleButtons1D(=112)");
448                   fTxtSigmaMax->SetToolTipText("Enter up to which multiple of sigma you want to integrate.");
449              
450             
451          fContDrawOpt1DSubMML = new TGCompositeFrame(fcontDrawOpt1DSubLR, 200, 23, kHorizontalFrame | kFitWidth | kFitHeight);
452          fcontDrawOpt1DSubLR->AddFrame(fContDrawOpt1DSubMML, new TGLayoutHints(kLHintsExpandX, 0, 0, 5, 0));
453          
454             // -------------- content of fcontDrawOpt1DSubLR
455             fChkMean = new TGCheckButton(fContDrawOpt1DSubMML, "Mean");
456             fContDrawOpt1DSubMML->AddFrame(fChkMean, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
457             fChkMean->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtons1D()");
458             fChkMean->SetToolTipText("Activate Mean for Sigma/Cumulative/Integrate");
459
460             fChkMedian = new TGCheckButton(fContDrawOpt1DSubMML, "Median");
461             fContDrawOpt1DSubMML->AddFrame(fChkMedian, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
462             fChkMedian->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtons1D()");
463             fChkMedian->SetToolTipText("Activate Median for Sigma/Cumulative/Integrate");
464
465             fChkLTM = new TGCheckButton(fContDrawOpt1DSubMML, "LTM");
466             fContDrawOpt1DSubMML->AddFrame(fChkLTM, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
467             fChkLTM->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtons1D()");
468             fChkLTM->SetToolTipText("Activate LTM for Sigma/Cumulative/Integrate");
469             
470       
471       // statistic options container *** fcontStatOpt1D ***  " Statistic options "      
472       fContStatOpt = new TGGroupFrame(ftabLeft1, "Statistic options", kVerticalFrame | kFitWidth | kFitHeight);
473       ftabLeft1->AddFrame(fContStatOpt, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
474       
475          fChkStatName = new TGCheckButton(fContStatOpt, "Name");
476          fContStatOpt->AddFrame(fChkStatName, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
477          fChkStatName->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsStat()");
478          fChkStatName->SetToolTipText("Display the name in the statistics legend.");
479       
480          fChkStatEntries = new TGCheckButton(fContStatOpt, "Entries");
481          fContStatOpt->AddFrame(fChkStatEntries, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
482          fChkStatEntries->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsStat()");
483          fChkStatEntries->SetToolTipText("Display the number of entries in the statistics legend.");
484       
485          fContStatMean = new TGCompositeFrame(fContStatOpt, 1, 1, kHorizontalFrame | kFitWidth | kFitHeight);
486          fContStatOpt->AddFrame(fContStatMean, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
487       
488             fChkStatMean = new TGCheckButton(fContStatMean, "Mean");
489             fContStatMean->AddFrame(fChkStatMean, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
490             fChkStatMean->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsStat()");
491             fChkStatMean->SetToolTipText("Display the mean value of the data in the statistics legend.");
492             
493             fChkStatMeanPM = new TGCheckButton(fContStatMean, "+- Error");
494             fContStatMean->AddFrame(fChkStatMeanPM, new TGLayoutHints(kLHintsNormal, 10, 0, 0, 0));
495             fChkStatMeanPM->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsStat()");
496             fChkStatMeanPM->SetToolTipText("Display the mean value's error in the statistics legend.");
497
498          fContStatRMS = new TGCompositeFrame(fContStatOpt, 1, 1, kHorizontalFrame | kFitWidth | kFitHeight);
499          fContStatOpt->AddFrame(fContStatRMS, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
500       
501             fChkStatRMS = new TGCheckButton(fContStatRMS, "RMS");
502             fContStatRMS->AddFrame(fChkStatRMS, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
503             fChkStatRMS->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsStat()");
504             fChkStatRMS->SetToolTipText("Display the RMS value of the data in the statistics legend.");
505             
506             fChkStatRMSPM = new TGCheckButton(fContStatRMS, "+- Error");
507             fContStatRMS->AddFrame(fChkStatRMSPM, new TGLayoutHints(kLHintsNormal, 10, 0, 0, 0));
508             fChkStatRMSPM->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsStat()");
509             fChkStatRMSPM->SetToolTipText("Display the RMS value's error in the statistics legend.");
510
511          fChkStatUnderflow = new TGCheckButton(fContStatOpt, "Underflow");
512          fContStatOpt->AddFrame(fChkStatUnderflow, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
513          fChkStatUnderflow->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsStat()");
514          fChkStatUnderflow->SetToolTipText("Display the number of entries in the underflow bin.");
515       
516          fChkStatOverflow = new TGCheckButton(fContStatOpt, "Overflow");
517          fContStatOpt->AddFrame(fChkStatOverflow, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
518          fChkStatOverflow->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsStat()");
519          fChkStatOverflow->SetToolTipText("Display the number of entries in the overflow bin.");
520       
521          fChkStatIntegral = new TGCheckButton(fContStatOpt, "Integral");
522          fContStatOpt->AddFrame(fChkStatIntegral, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
523          fChkStatIntegral->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsStat()");
524          fChkStatIntegral->SetToolTipText("Display the integral of the data in the statistics legend.");
525       
526          fContStatSkew = new TGCompositeFrame(fContStatOpt, 1, 1, kHorizontalFrame | kFitWidth | kFitHeight);
527          fContStatOpt->AddFrame(fContStatSkew, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
528       
529             fChkStatSkewness = new TGCheckButton(fContStatSkew, "Skewness");
530             fContStatSkew->AddFrame(fChkStatSkewness, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
531             fChkStatSkewness->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsStat()");
532             fChkStatSkewness->SetToolTipText("Display the skewness of the data in the statistics legend. \nBe careful! Sometimes the skewness causes a floating point exception that hangs the GUI!");
533             
534             fChkStatSkewnessPM = new TGCheckButton(fContStatSkew, "+- Error");
535             fContStatSkew->AddFrame(fChkStatSkewnessPM, new TGLayoutHints(kLHintsNormal, 10, 0, 0, 0));
536             fChkStatSkewnessPM->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsStat()");
537             fChkStatSkewnessPM->SetToolTipText("Display the skewness' error in the statistics legend.");
538
539          fContStatKurt = new TGCompositeFrame(fContStatOpt, 1, 1, kHorizontalFrame | kFitWidth | kFitHeight);
540          fContStatOpt->AddFrame(fContStatKurt, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
541       
542             fChkStatKurtosis = new TGCheckButton(fContStatKurt, "Kurtosis");
543             fContStatKurt->AddFrame(fChkStatKurtosis, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
544             fChkStatKurtosis->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsStat()");
545             fChkStatKurtosis->SetToolTipText("Display the kurtosis of the data in the statistics legend.");
546             
547             fChkStatKurtosisPM = new TGCheckButton(fContStatKurt, "+- Error");
548             fContStatKurt->AddFrame(fChkStatKurtosisPM, new TGLayoutHints(kLHintsNormal, 10, 0, 0, 0));
549             fChkStatKurtosisPM->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsStat()");
550             fChkStatKurtosisPM->SetToolTipText("Display the kurtosis' error in the statistics legend.");
551        
552       fBtnUnchekAll = new TGTextButton(fContStatOpt, "&Uncheck all");
553       fContStatOpt->AddFrame(fBtnUnchekAll, new TGLayoutHints(kLHintsExpandX, 10, 10, 0, 0));
554       //fBtnDraw->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "DoTest(=\"fBtnDraw clicked\")");
555       fBtnUnchekAll->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "UnchekAllStat()");
556       fBtnUnchekAll->SetToolTipText("Disable all statistics legend entries, \nno statistics legend.");
557
558       
559       // custom options container
560       // --- fComboCustom --- the custom draw line on the very low
561       fContCustom = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
562       fContTopBottom->AddFrame(fContCustom, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
563    
564          // ------------------------- content of fContCustom -------------------------
565          fLblCustomDraw = new TGLabel(fContCustom, "Custom draw: ");
566          fLblCustomDraw->SetTextJustify(kTextLeft);
567          fContCustom->AddFrame(fLblCustomDraw, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
568          // text field for custom draw command
569          fComboCustom = new TGComboBox(fContCustom);
570          fComboCustom->Resize(0, fBtnDraw->GetDefaultHeight());
571          fComboCustom->EnableTextInput(kTRUE);
572          fContCustom->AddFrame(fComboCustom, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
573          fComboCustom->Connect("ReturnPressed()", "AliTPCCalibViewerGUI", this, "HandleButtonsGeneral(=42)");
574          fComboCustom->Connect("Selected(Int_t)", "AliTPCCalibViewerGUI", this, "DoNewSelection()");
575       
576    
577       // additional cuts container
578       fContAddCuts = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
579       fContTopBottom->AddFrame(fContAddCuts, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
580       
581          // ------------------------- content of fContAddCuts -------------------------
582          fLblAddCuts = new TGLabel(fContAddCuts, "Custom cuts:  ");
583          fLblAddCuts->SetTextJustify(kTextLeft);
584          fContAddCuts->AddFrame(fLblAddCuts, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
585          // combo text field for additional cuts
586          fComboAddCuts = new TGComboBox(fContAddCuts);
587          fComboAddCuts->Resize(0, fBtnDraw->GetDefaultHeight());
588          fComboAddCuts->EnableTextInput(kTRUE);
589          fContAddCuts->AddFrame(fComboAddCuts, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
590          fComboAddCuts->Connect("ReturnPressed()", "AliTPCCalibViewerGUI", this, "HandleButtonsCuts(=31)");
591          fComboAddCuts->Connect("Selected(Int_t)", "AliTPCCalibViewerGUI", this, "DoNewSelection()");
592          
593    // ==========================================================================
594    // ************************* content of fContCenter *************************
595    // ========================================================================
596    // main drawing canvas
597    fCanvMain = new TRootEmbeddedCanvas("Main_Canvas", fContCenter, 200, 200, kFitWidth | kFitHeight);
598    fContCenter->AddFrame(fCanvMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
599    fCanvMain->GetCanvas()->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)", "AliTPCCalibViewerGUI", this, "MouseMove(Int_t, Int_t, Int_t, TObject*)");
600    fCanvMain->GetCanvas()->Connect("RangeAxisChanged()", "AliTPCCalibViewerGUI", this, "GetMinMax()");
601    fCanvMain->GetCanvas()->SetToolTipText("The Main_Canvas, here your plots are displayed.");
602    
603    
604    // =========================================================================   
605    // ************************* content of fContRight *************************
606    // ========================================================================
607    
608    // tabs on the right side:
609    ftabRight = new TGTab(fContRight);
610    fContRight->AddFrame(ftabRight, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 8, 0));
611    fTabRight0 = ftabRight->AddTab("Basic");
612    fTabRight1 = ftabRight->AddTab("Advanced");
613
614    
615       // **************************** content of tabLeft0 *******************************
616       // cut options container
617       fContCuts = new TGGroupFrame(fTabRight0, "Cuts", kVerticalFrame | kFitWidth | kFitHeight);
618       fTabRight0->AddFrame(fContCuts, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
619    
620       
621          // ************************* content of fContCuts *************************
622          // TPC radio button
623          fRadioTPC = new TGRadioButton(fContCuts, "Whole TPC", 20);
624          fContCuts->AddFrame(fRadioTPC, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
625          fRadioTPC->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsCuts()");
626          fRadioTPC->SetToolTipText("No cuts, use the whole TPC. \nIn 2D mode, A side and C side are superimposed!");
627       
628          // side A radio button
629          fRadioSideA = new TGRadioButton(fContCuts, "Side A", 21);
630          fContCuts->AddFrame(fRadioSideA, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
631          fRadioSideA->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsCuts()");
632          fRadioSideA->SetToolTipText("Use only side A.");
633       
634          // side C radio button
635          fRadioSideC = new TGRadioButton(fContCuts, "Side C", 22);
636          fContCuts->AddFrame(fRadioSideC, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
637          fRadioSideC->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsCuts()");
638          fRadioSideC->SetToolTipText("Use only side C.");
639       
640          // roc radio button
641          fRadioROC = new TGRadioButton(fContCuts, "ROC", 23);
642          fContCuts->AddFrame(fRadioROC, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
643          fRadioROC->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsCuts()");
644          fRadioROC->SetToolTipText("Use only one ROC (readout chamber).");
645
646          // sector radio button
647          fRadioSector = new TGRadioButton(fContCuts, "Sector", 24);
648          fContCuts->AddFrame(fRadioSector, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
649          fRadioSector->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsCuts()");
650          fRadioSector->SetToolTipText("Use only one Sector (0-17 A-Side, 18-35 C-Side).");
651       
652          // sector options container
653          fContSector = new TGCompositeFrame(fContCuts, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
654          fContCuts->AddFrame(fContSector, new TGLayoutHints(kLHintsExpandX, 5, 0, 0, 0));
655          
656             // ------------------------- content of fContSector -------------------------
657             // sector number entry
658             fNmbSector = new TGNumberEntry(fContSector, 0, 1, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, 71);
659             fContSector->AddFrame(fNmbSector, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
660             fNmbSector->Connect("ValueSet(Long_t)", "AliTPCCalibViewerGUI", this, "ChangeSector()");
661             
662             // sector number label
663             fLblSector = new TGLabel(fContSector, "IROC, A");
664             fLblSector->SetTextJustify(kTextLeft);
665             fContSector->AddFrame(fLblSector, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 5, 0, 0, 0));
666          
667          // cut zeros check button
668          fChkCutZero = new TGCheckButton(fContCuts, "Cut zeros");
669          fContCuts->AddFrame(fChkCutZero, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
670          fChkCutZero->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "DoNewSelection()");
671          fChkCutZero->SetToolTipText("Use only values that are not zero. \nWhen doing a custom draw this cut is composed of the draw string\nup to the first ':' or '>>' and the condition that this should not be zero.");
672       
673          // additional cuts check button
674          fChkAddCuts = new TGCheckButton(fContCuts, "Custom cuts");
675          fContCuts->AddFrame(fChkAddCuts, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
676          fChkAddCuts->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "DoNewSelection()");
677          fChkAddCuts->SetToolTipText("Activate the custom cuts on the bottom. Remember '~' (= '.fElements')!");
678          // fContAddCuts' content is locaed further op
679       
680       
681       // Scaling options container
682       fContScaling = new TGGroupFrame(fTabRight0, "Scaling", kVerticalFrame | kFitWidth | kFitHeight);
683       fTabRight0->AddFrame(fContScaling, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
684    
685          // ************************* content of fContScaling *************************
686          // SetMaximum container
687          fContSetMax = new TGCompositeFrame(fContScaling, 200, 200, kVerticalFrame | kFitWidth | kFitHeight);
688          fContScaling->AddFrame(fContSetMax, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
689          
690             // ------------------------- content of fContSetMax -------------------------
691             // SetMaximum - checkbox
692             fChkSetMax = new TGCheckButton(fContSetMax, "Set fixed max.");
693             fContSetMax->AddFrame(fChkSetMax, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
694             fChkSetMax->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsNoRedraw()");
695             fChkSetMax->SetToolTipText("Set the maximum fixed to the value specified here.");
696             
697             // text field for maximum value
698             fTxtSetMax = new TGTextEntry(fContSetMax, "", 41);
699             fContSetMax->AddFrame(fTxtSetMax, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
700             fTxtSetMax->Connect("ReturnPressed()", "AliTPCCalibViewerGUI", this, "HandleButtonsNoRedraw()");
701             fTxtSetMax->SetToolTipText("maximum value for the drawing");
702       
703          // SetMinimum container
704          fContSetMin = new TGCompositeFrame(fContScaling, 200, 200, kVerticalFrame | kFitWidth | kFitHeight);
705          fContScaling->AddFrame(fContSetMin, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
706          
707             // ------------------------- content of fContSetMin -------------------------
708             // SetMinimum - checkbox
709             fChkSetMin = new TGCheckButton(fContSetMin, "Set fixed min.");
710             fContSetMin->AddFrame(fChkSetMin, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
711             fChkSetMin->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsNoRedraw()");
712             fChkSetMin->SetToolTipText("Set the minimum fixed to the value specified here.");
713             
714             // text field for minimum value
715             fTxtSetMin = new TGTextEntry(fContSetMin, "", 40);
716             fContSetMin->AddFrame(fTxtSetMin, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
717             fTxtSetMin->Connect("ReturnPressed()", "AliTPCCalibViewerGUI", this, "HandleButtonsNoRedraw()");
718             fTxtSetMin->SetToolTipText("minimum value for the drawing");
719          
720          // get Min & Max from Plot - button
721          fBtnGetMinMax = new TGTextButton(fContScaling, "&Get scale from plot");
722          fContScaling->AddFrame(fBtnGetMinMax, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
723          fBtnGetMinMax->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "GetMinMax()");
724          fBtnGetMinMax->SetToolTipText("Get min and max from plot, e.g. after rescaling by dragging the palette. \nObsolete! The button's function will change to 'Unzoom all'.");
725          
726          // GetMinMaxAuto - checkbox
727          fChkGetMinMaxAuto = new TGCheckButton(fContScaling, "Get Min + Max auto.");
728          fContScaling->AddFrame(fChkGetMinMaxAuto, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
729          fChkGetMinMaxAuto->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsNoRedraw()");
730          fChkGetMinMaxAuto->SetToolTipText("Get minimum and maximum automatically from each new plot. \nDeactivate this, if you want to 'save' your specified minimum and maximum.");
731          
732       // labeling container *** fContLabeling ***  " Labeling "      
733          fContLabeling = new TGGroupFrame(fTabRight0, "Labeling", kVerticalFrame | kFitWidth | kFitHeight);
734          fTabRight0->AddFrame(fContLabeling, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
735          
736             fChkLabelTitle = new TGCheckButton(fContLabeling, "Set title:");
737             fContLabeling->AddFrame(fChkLabelTitle, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
738             fChkLabelTitle->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsNoRedraw()");
739             fChkLabelTitle->SetToolTipText("Set the plot title.");
740                
741             fTxtLabelTitle = new TGTextEntry(fContLabeling, "Title", 500);
742             fContLabeling->AddFrame(fTxtLabelTitle, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
743             fTxtLabelTitle->Connect("ReturnPressed()", "AliTPCCalibViewerGUI", this, "HandleButtonsNoRedraw(=50)");
744             fTxtLabelTitle->SetToolTipText("plot title");
745    
746             fChkLabelXaxis = new TGCheckButton(fContLabeling, "Set X-axis label:");
747             fContLabeling->AddFrame(fChkLabelXaxis, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
748             fChkLabelXaxis->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsNoRedraw()");
749             fChkLabelXaxis->SetToolTipText("Set the X-axis label.");
750                
751             fTxtLabelXaxis = new TGTextEntry(fContLabeling, "XaxisLabel", 500);
752             fContLabeling->AddFrame(fTxtLabelXaxis, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
753             fTxtLabelXaxis->Connect("ReturnPressed()", "AliTPCCalibViewerGUI", this, "HandleButtonsNoRedraw(=51)");
754             fTxtLabelXaxis->SetToolTipText("X-axis label");
755    
756             fChkLabelYaxis = new TGCheckButton(fContLabeling, "Set Y-axis label:");
757             fContLabeling->AddFrame(fChkLabelYaxis, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
758             fChkLabelYaxis->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsNoRedraw()");
759             fChkLabelYaxis->SetToolTipText("Set the Y-axis label.");
760                
761             fTxtLabelYaxis = new TGTextEntry(fContLabeling, "YaxisLabel", 500);
762             fContLabeling->AddFrame(fTxtLabelYaxis, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
763             fTxtLabelYaxis->Connect("ReturnPressed()", "AliTPCCalibViewerGUI", this, "HandleButtonsNoRedraw(=52)");
764             fTxtLabelYaxis->SetToolTipText("Y-axis label");
765    
766             fChkLabelGetAuto = new TGCheckButton(fContLabeling, "Get labels auto.");
767             fContLabeling->AddFrame(fChkLabelGetAuto, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
768             fChkLabelGetAuto->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "HandleButtonsNoRedraw()");
769             fChkLabelGetAuto->SetToolTipText("Get labels automatically from each new plot \nDeactivate this, if you want to 'save' your specified labels.");
770
771       
772       // **************************** content of ftabRight1 *******************************
773       // Save container
774       fContSave = new TGGroupFrame(fTabRight1, "Save", kVerticalFrame | kFitWidth | kFitHeight);
775       fTabRight1->AddFrame(fContSave, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
776          // save button
777          fBtnSave = new TGTextButton(fContSave, "&Save picture");
778          fContSave->AddFrame(fBtnSave, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
779          fBtnSave->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "SavePicture()");
780          fBtnSave->SetToolTipText("Open a 'Save as...' dialog to save the current plot as picture or macro.");
781
782          // additional save options container
783          fContAddSaveOpt = new TGCompositeFrame(fContSave, 200, 200, kVerticalFrame | kFitWidth | kFitHeight);
784          fContSave->AddFrame(fContAddSaveOpt, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
785    
786             //  content of --- fContAddSaveOpt ---
787             // addition save options label
788             fChkAddSaveOpt = new TGCheckButton(fContAddSaveOpt, "Save options:");
789             fContAddSaveOpt->AddFrame(fChkAddSaveOpt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
790             fChkAddSaveOpt->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "DoNewSelection()");
791             fChkAddSaveOpt->SetToolTipText("Additional save options (see documentation for TPad::Print()).");
792             
793             // additional save options combo box
794             fComboAddSaveOpt = new TGComboBox(fContAddSaveOpt);
795             fContAddSaveOpt->AddFrame(fComboAddSaveOpt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
796             fComboAddSaveOpt->Resize(0, fBtnDraw->GetDefaultHeight());
797             fComboAddSaveOpt->EnableTextInput(kTRUE);
798             fComboAddSaveOpt->Connect("ReturnPressed()", "AliTPCCalibViewerGUI", this, "SavePicture()");
799             // fComboAddSaveOpt->Connect("Selected(Int_t)", "AliTPCCalibViewerGUI", this, "SavePicture()");
800      
801       // calPad export container
802       fContExport = new TGGroupFrame(fTabRight1, "Export AliTPCCalPad", kVerticalFrame | kFitWidth | kFitHeight);
803       fTabRight1->AddFrame(fContExport, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
804    
805          // ------------------------- content of fContExport -------------------------
806          // container for export name
807          fContAddExport = new TGCompositeFrame(fContExport, 200, 200, kVerticalFrame | kFitWidth | kFitHeight);
808          fContExport->AddFrame(fContAddExport, new TGLayoutHints(kLHintsExpandX, -5, -5, 0, 0));
809          
810          fComboExportName = new TGComboBox(fContAddExport);
811          fComboExportName->Resize(0, fBtnDraw->GetDefaultHeight());
812          fContAddExport->AddFrame(fComboExportName, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
813          fComboExportName->AddEntry("calPad",  0);  // first default value
814          fComboExportName->Select(0);               // select default value before connecting
815          fComboExportName->EnableTextInput(kTRUE);
816          fComboExportName->Connect("ReturnPressed()", "AliTPCCalibViewerGUI", this, "DoExport()");
817          fComboExportName->Connect("Selected(Int_t)", "AliTPCCalibViewerGUI", this, "DoExport()");
818   
819          // export button
820          fBtnExport = new TGTextButton(fContExport, "&Export to CINT");
821          fContExport->AddFrame(fBtnExport, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
822          fBtnExport->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "DoExport()");
823          fBtnExport->SetToolTipText("Export the current 2D view as AliTPCCalPad to the CINT command line interpreter, use the specified name. \nThis works only in 2D mode.");
824       
825          // add to normalisation button
826          fBtnAddNorm = new TGTextButton(fContExport, "&Add to normalization");
827          fContExport->AddFrame(fBtnAddNorm, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
828          fBtnAddNorm->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "DoExportNorm()");
829          fBtnAddNorm->SetToolTipText("Use the current 2D view as normalization variable, use the specified name. \nNot yet working!");
830
831       // Tree container
832       fContTree = new TGGroupFrame(fTabRight1, "Tree", kVerticalFrame | kFitWidth | kFitHeight);
833       fTabRight1->AddFrame(fContTree, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
834
835          // dump tree to file button
836          fBtnDumpToFile = new TGTextButton(fContTree, "&Dump to File");
837          fContTree->AddFrame(fBtnDumpToFile, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
838          fBtnDumpToFile->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "DoDumpToFile()");
839          fBtnDumpToFile->SetToolTipText("Write the exported CalPads to a new CalibTree");
840
841          // dump tree to file button
842          fBtnLoadTree = new TGTextButton(fContTree, "&Load Tree");
843          fContTree->AddFrame(fBtnLoadTree, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
844          fBtnLoadTree->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "DoLoadTree()");
845          fBtnLoadTree->SetToolTipText("Load and initialize a new calibration tree. ");
846
847          fChkAddAsReference = new TGCheckButton(fContTree, "as reference:");
848          fContTree->AddFrame(fChkAddAsReference, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
849          fChkAddAsReference->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "DoLoadTree()");
850          fChkAddAsReference->SetToolTipText("To add a new tree as reference tree.");
851             
852          fTxtRefName = new TGTextEntry(fContTree, "R", 500);
853          fContTree->AddFrame(fTxtRefName, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 15, 0, 0, 0));
854          // fTxtRefName->Connect("ReturnPressed()", "AliTPCCalibViewerGUI", this, "HandleButtonsNoRedraw(=50)");
855          fTxtRefName->SetToolTipText("Reference Name");
856         
857             
858       // Fit options container
859       fContFit = new TGGroupFrame(fTabRight1, "Custom fit", kVerticalFrame | kFitWidth | kFitHeight);
860       fTabRight1->AddFrame(fContFit, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
861    
862          // ------------------------- content of fContFit -------------------------
863          // container for additional fits
864          fContAddFit = new TGCompositeFrame(fContFit, 200, 200, kVerticalFrame | kFitWidth | kFitHeight);
865          fContFit->AddFrame(fContAddFit, new TGLayoutHints(kLHintsExpandX, -5, -5, 0, 0));
866       
867             // --- content of fContAddFit ---
868             // text field for custom fit
869             fComboCustomFit = new TGComboBox(fContAddFit);
870             fComboCustomFit->Resize(0, fBtnDraw->GetDefaultHeight());
871             fComboCustomFit->EnableTextInput(kTRUE);
872             fContAddFit->AddFrame(fComboCustomFit, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
873             fComboCustomFit->Connect("ReturnPressed()", "AliTPCCalibViewerGUI", this, "DoFit()");
874             fComboCustomFit->Connect("Selected(Int_t)", "AliTPCCalibViewerGUI", this, "DoFit()");
875          
876          // fit button
877          fBtnFit = new TGTextButton(fContAddFit, "&Fit");
878          fContAddFit->AddFrame(fBtnFit, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
879          fBtnFit->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "DoFit()");
880          fBtnFit->SetToolTipText("Fit a whole TPC side, e.g. with gx~ ++ gy~, the result is printed to the console \nNot yet final status.");
881       
882          // add fit function button
883          //fBtnAddFitFunction = new TGTextButton(fContAddFit, "&Add fit function to normalization");
884          //fContAddFit->AddFrame(fBtnAddFitFunction, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
885          //fBtnAddFitFunction->Connect("Clicked()", "AliTPCCalibViewerGUI", this, "AddFitFunction()");
886
887    SetWindowName("AliTPCCalibViewer GUI");
888    MapSubwindows();
889    Resize(GetDefaultSize());
890    MapWindow();
891 }
892
893
894 void AliTPCCalibViewerGUI::SetInitialValues() {
895    // 
896    // Set the default button states
897    // 
898    fChkAuto->SetState(kButtonUp);
899    fRadioPredefined->SetState(kButtonDown);
900    fRadioRaw->SetState(kButtonDown);
901    fRadioTPC->SetState(kButtonDown);
902    fRadio1D->SetState(kButtonDown);
903    fChkAddCuts->SetState(kButtonUp);
904    fChkGetMinMaxAuto->SetState(kButtonDown);
905    fChkSetMin->SetState(kButtonUp);
906    fChkSetMax->SetState(kButtonUp);
907    fRadioNorm->SetState(kButtonDown);
908    fRadioSigma->SetState(kButtonUp);
909    fRadioCumulative->SetState(kButtonUp);
910    fChkMean->SetState(kButtonDown);
911    fCheckCumulativePM->SetState(kButtonUp);
912    
913    fChkLabelGetAuto->SetState(kButtonDown);
914
915    // TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO 
916    // TODO Set the checkboxes state as it is really     TODO 
917    // TODO in gStyle                                    TODO 
918    // TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO 
919 //          k = 1;  kurtosis printed
920 //          k = 2;  kurtosis and kurtosis error printed
921 //          s = 1;  skewness printed
922 //          s = 2;  skewness and skewness error printed
923 //          i = 1;  integral of bins printed
924 //          o = 1;  number of overflows printed
925 //          u = 1;  number of underflows printed
926 //          r = 1;  rms printed
927 //          r = 2;  rms and rms error printed
928 //          m = 1;  mean value printed
929 //          m = 2;  mean and mean error values printed
930 //          e = 1;  number of entries printed
931 //          n = 1;  name of histogram is printed    
932 //          (default = 000001111)
933          
934    Int_t statOpt = gStyle->GetOptStat();
935    if (statOpt == 1) statOpt = 1111;
936    if (statOpt / 200000000 >= 1) {
937       fChkStatKurtosis->SetState(kButtonDown);
938       fChkStatKurtosisPM->SetState(kButtonDown);
939       statOpt -= 200000000;
940    }
941    if (statOpt / 100000000 >= 1) {
942       fChkStatKurtosis->SetState(kButtonDown);
943       statOpt -= 100000000;
944    }
945    if (statOpt / 20000000 >= 1) {
946       fChkStatSkewness->SetState(kButtonDown);
947       fChkStatSkewnessPM->SetState(kButtonDown);
948       statOpt -= 20000000;
949    }
950    if (statOpt / 10000000 >= 1) {
951       fChkStatSkewness->SetState(kButtonDown);
952       statOpt -= 10000000;
953    }
954    if (statOpt / 1000000 >= 1) {
955       fChkStatIntegral->SetState(kButtonDown);
956       statOpt -= 1000000;
957    }
958    if (statOpt / 100000 >= 1) {
959       fChkStatOverflow->SetState(kButtonDown);
960       statOpt -= 100000;
961    }
962    if (statOpt / 10000 >= 1) {
963       fChkStatUnderflow->SetState(kButtonDown);
964       statOpt -= 10000;
965    }
966    if (statOpt / 2000 >= 1) {
967       fChkStatRMS->SetState(kButtonDown);
968       fChkStatRMSPM->SetState(kButtonDown);
969       statOpt -= 2000;
970    }
971    if (statOpt / 1000 >= 1) {
972       fChkStatRMS->SetState(kButtonDown);
973       statOpt -= 1000;
974    }
975    if (statOpt / 200 >= 1) {
976       fChkStatMean->SetState(kButtonDown);
977       fChkStatMeanPM->SetState(kButtonDown);
978       statOpt -= 200;
979    }
980    if (statOpt / 100 >= 1) {
981       fChkStatMean->SetState(kButtonDown);
982       statOpt -= 100;
983    }
984    if (statOpt / 10 >= 1) {
985       fChkStatEntries->SetState(kButtonDown);
986       statOpt -= 10;
987    }
988    if (statOpt / 1 >= 1) {
989       fChkStatName->SetState(kButtonDown);
990       statOpt -= 1;
991    }
992    
993   /* 
994    fChkStatName->SetState(kButtonDown);
995    fChkStatEntries->SetState(kButtonDown);
996    fChkStatMean->SetState(kButtonDown);
997    fChkStatRMS->SetState(kButtonDown);
998    */
999 //    fChkStatMeanPM->SetState(kButtonUp);
1000 //    fChkStatRMSPM->SetState(kButtonUp);
1001 //    fChkStatUnderflow->SetState(kButtonUp);
1002 //    fChkStatOverflow->SetState(kButtonUp);
1003 //    fChkStatIntegral->SetState(kButtonUp);
1004 //    fChkStatSkewness->SetState(kButtonUp);
1005 //    fChkStatSkewnessPM->SetState(kButtonUp);
1006 //    fChkStatKurtosis->SetState(kButtonDown);
1007 //    fChkStatKurtosisPM->SetState(kButtonDown);
1008    
1009    // fill fComboAddDrawOpt with some additional drawing options
1010    fComboAddDrawOpt->AddEntry("same",      0);
1011    fComboAddDrawOpt->AddEntry("profbox",   1);
1012    fComboAddDrawOpt->AddEntry("profcolz",  2);
1013    fComboAddDrawOpt->AddEntry("profcont0", 3);
1014    fComboAddDrawOpt->AddEntry("proflego",  4);
1015    fComboAddDrawOpt->AddEntry("proflego2", 5);
1016    fComboAddDrawOpt->AddEntry("profsurf",  6);
1017    fComboAddDrawOpt->AddEntry("profsurf1", 7);
1018    fComboAddDrawOpt->AddEntry("profsurf2", 8);
1019    fComboAddDrawOpt->AddEntry("box",    9);
1020    fComboAddDrawOpt->AddEntry("colz",  10);
1021    fComboAddDrawOpt->AddEntry("cont0", 11);
1022    fComboAddDrawOpt->AddEntry("lego",  12);
1023    fComboAddDrawOpt->AddEntry("lego2", 13);
1024    fComboAddDrawOpt->AddEntry("surf",  14);
1025    fComboAddDrawOpt->AddEntry("surf1", 15);
1026    fComboAddDrawOpt->AddEntry("surf2", 16);
1027
1028    // fill fComboAddSaveOpt with some additional drawing options
1029    fComboAddSaveOpt->AddEntry("Portrait",  0);
1030    fComboAddSaveOpt->AddEntry("Landscape", 1);
1031    fComboAddSaveOpt->AddEntry("Preview",   2);
1032    fComboAddSaveOpt->AddEntry("+50",       3);
1033
1034    // fill fComboMethod
1035    fComboMethod->AddEntry("subtract",  0);
1036    fComboMethod->AddEntry("divide by", 1);
1037    
1038    // fill fComboExportName
1039 //    fComboExportName->AddEntry("calPad",  0);
1040    // fComboExportName->AddEntry("calPad2", 1);
1041    fBtnExport->SetEnabled(kFALSE);
1042    fBtnAddNorm->SetEnabled(kFALSE);
1043
1044    // select initial variables
1045    fListVariables->Select(0);
1046    fListNormalization->Select(0);
1047    fComboMethod->Select(0);
1048 //    fComboExportName->Select(0);
1049 //    fComboExportName->EnableTextInput(kTRUE);
1050
1051    //fCanvMain->GetCanvas()->ToggleEventStatus(); // klappt nicht
1052    //fCanvMain->GetCanvas()->GetCanvasImp()->ShowStatusBar(kTRUE); // klappt auch nicht
1053    fListVariables->IntegralHeight(kFALSE);         // naja
1054    fListNormalization->IntegralHeight(kFALSE);     // naja
1055    fChkAuto->SetState(kButtonDown);
1056   
1057    // Make first drawing:
1058    // DoDraw();
1059 }
1060
1061
1062 AliTPCCalibViewerGUI::AliTPCCalibViewerGUI(const AliTPCCalibViewerGUI &c)
1063    : TGCompositeFrame(c.fParent, c.fWidth, c.fHeight),
1064     fViewer(0),
1065     fPreprocessor(0),
1066     fContTopBottom(0),
1067     fContLCR(0),
1068     fContLeft(0),
1069     ftabLeft(0),
1070     ftabLeft0(0),
1071     ftabLeft1(0),
1072     ftabRight(0),
1073     fTabRight0(0),
1074     fTabRight1(0),
1075     fContRight(0),
1076     fContCenter(0),
1077     fContPlotOpt(0),
1078     fContDrawOpt(0),
1079     fContDrawOptSub1D2D(0),
1080     fContNormalized(0),
1081     fContCustom(0),
1082     fContCuts(0),
1083     fContSector(0),
1084     fContAddCuts(0),
1085     fContFit(0),
1086     fContAddFit(0),
1087     fContScaling(0),
1088     fContSetMax(0),
1089     fContSetMin(0),
1090     fContAddDrawOpt(0),
1091     fListVariables(0),
1092     fBtnDraw(0),
1093     fBtnFit(0),
1094     fBtnAddFitFunction(0),
1095     fBtnGetMinMax(0),
1096     fCanvMain(0),
1097     fRadioRaw(0),
1098     fRadioNormalized(0),
1099     fRadioPredefined(0),
1100     fRadioCustom(0),
1101     fRadio1D(0),
1102     fRadio2D(0),
1103     fRadioTPC(0),
1104     fRadioSideA(0),
1105     fRadioSideC(0),
1106     fRadioROC(0),
1107     fRadioSector(0),
1108     fComboAddDrawOpt(0),
1109     fChkAuto(0),
1110     fChkAutoAppend(0),
1111     fComboMethod(0),
1112     fListNormalization(0),
1113     fComboCustom(0),
1114     fLblCustomDraw(0),
1115     fChkAddDrawOpt(0),
1116     fNmbSector(0),
1117     fLblSector(0),
1118     fChkCutZero(0),
1119     fChkAddCuts(0),
1120     fLblAddCuts(0),
1121     fComboAddCuts(0), 
1122     fComboCustomFit(0),
1123     fChkSetMax(0),
1124     fChkSetMin(0),
1125     fChkGetMinMaxAuto(0),
1126     fTxtSetMax(0),
1127     fTxtSetMin(0), 
1128     fContDrawOpt1D(0),
1129     fcontDrawOpt1DSubLR(0),
1130     fContDrawOpt1DSubNSC(0), 
1131     fRadioNorm(0),
1132     fRadioSigma(0),
1133     fTxtSigmas(0),
1134     fContCumuLR(0),
1135     fContCumLeft(0),
1136     fContCumRight(0),
1137     fLblSigmaMax(0),
1138     fTxtSigmaMax(0),
1139     fRadioCumulative(0),
1140     fCheckCumulativePM(0),
1141     fRadioIntegrate(0),
1142     fContDrawOpt1DSubMML(0),
1143     fChkMean(0),
1144     fChkMedian(0),
1145     fChkLTM(0), 
1146     fContStatOpt(0),
1147     fChkStatName(0),
1148     fChkStatEntries(0),
1149     fContStatMean(0),
1150     fChkStatMean(0),
1151     fChkStatMeanPM(0),
1152     fContStatRMS(0),
1153     fChkStatRMS(0),
1154     fChkStatRMSPM(0),
1155     fChkStatUnderflow(0),
1156     fChkStatOverflow(0),
1157     fChkStatIntegral(0),
1158     fContStatSkew(0),
1159     fChkStatSkewness(0),
1160     fChkStatSkewnessPM(0),
1161     fContStatKurt(0),
1162     fChkStatKurtosis(0),
1163     fChkStatKurtosisPM(0),
1164     fBtnUnchekAll(0),
1165     fContLabeling(0),
1166     fChkLabelTitle(0),
1167     fTxtLabelTitle(0),
1168     fChkLabelXaxis(0),
1169     fTxtLabelXaxis(0),
1170     fChkLabelYaxis(0),
1171     fTxtLabelYaxis(0),
1172     fChkLabelGetAuto(0),
1173     fContSave(0),
1174     fBtnSave(0),
1175     fContAddSaveOpt(0),
1176     fChkAddSaveOpt(0),
1177     fComboAddSaveOpt(0),
1178     fContExport(0),
1179     fContAddExport(0),
1180     fComboExportName(0),
1181     fBtnExport(0),
1182     fBtnAddNorm(0), 
1183     fContTree(0),
1184     fBtnDumpToFile(0),
1185     fBtnLoadTree(0),
1186     fChkAddAsReference(0),
1187     fTxtRefName(0),
1188     fInitialized(0)
1189 {
1190   //
1191   // dummy AliTPCCalibViewerGUI copy constructor
1192   //
1193 }
1194
1195
1196 AliTPCCalibViewerGUI & AliTPCCalibViewerGUI::operator =(const AliTPCCalibViewerGUI & /*param*/) {
1197    //
1198    // dummy assignment operator
1199    //
1200    return (*this);
1201 }
1202
1203
1204 AliTPCCalibViewerGUI::~AliTPCCalibViewerGUI() {
1205    // 
1206    // Destructor
1207    // 
1208    if (fCanvMain && fCanvMain->GetCanvas()) {
1209       for (Int_t i = 0; i < fCanvMain->GetCanvas()->GetListOfPrimitives()->GetEntries(); i++) {
1210          if (strcmp(fCanvMain->GetCanvas()->GetListOfPrimitives()->At(i)->ClassName(), "TFrame") != 0)
1211             fCanvMain->GetCanvas()->GetListOfPrimitives()->At(i)->Delete();
1212       }
1213    }
1214    Cleanup();
1215    if (fViewer) fViewer->Delete();
1216    delete fPreprocessor;
1217 }
1218
1219
1220 /*
1221 void AliTPCCalibViewerGUI::CloseWindow() {
1222    DeleteWindow();
1223 }
1224 */
1225
1226
1227 void AliTPCCalibViewerGUI::Initialize(const char* fileName, const char* treeName) {
1228    // 
1229    // initialize the GUI with a calibrationTree from fileName
1230    // 
1231    
1232    // create AliTPCCalibViewer object, which will be used for generating all drawings
1233    if (fViewer) delete fViewer;
1234    fViewer = new AliTPCCalibViewer(fileName, treeName);
1235    Initialize(fViewer);   
1236 }
1237
1238
1239 void AliTPCCalibViewerGUI::Initialize(AliTPCCalibViewer *viewer) {
1240    //
1241    // initializes the GUI with default settings and opens tree for drawing
1242    //
1243    
1244    fViewer = viewer;
1245    TString selectedVariable("");
1246    TString selectedNormalization("");
1247    Int_t variableId = -1;
1248    Int_t normalizationId = -1;
1249    if (fInitialized) {
1250       // remember the selected entry
1251       if (fListVariables->GetSelectedEntry()) selectedVariable = fListVariables->GetSelectedEntry()->GetTitle();
1252       if (fListNormalization->GetSelectedEntry()) selectedNormalization = fListNormalization->GetSelectedEntry()->GetTitle();
1253    }
1254    
1255    // fill fListVariables, list of drawable variables:
1256    TObjArray* arr = fViewer->GetListOfVariables();
1257    if (!arr) return;
1258    TIterator* iter = arr->MakeIterator();
1259    iter->Reset();
1260    TObjString* currentStr = 0;
1261    Int_t id = 0;
1262    fListVariables->RemoveAll();
1263    while ((currentStr = (TObjString*)(iter->Next()))) {
1264       fListVariables->AddEntry(currentStr->GetString().Data(), id);
1265       if (fInitialized && currentStr->GetString() == selectedVariable) variableId = id;
1266       id++;
1267    }
1268
1269    // fill fListNorm, list of normalization variables:
1270    TObjArray *arrNorm = fViewer->GetListOfNormalizationVariables();
1271    TIterator *iterNorm = arrNorm->MakeIterator();
1272    iterNorm->Reset();
1273    currentStr = 0;
1274    id = 0;
1275    fListNormalization->RemoveAll();
1276    while ((currentStr = (TObjString*)(iterNorm->Next()))) {
1277       fListNormalization->AddEntry(currentStr->GetString().Data(), id);
1278       if (fInitialized && currentStr->GetString() == selectedNormalization) normalizationId = id;
1279       id++;
1280    }
1281    currentStr = 0;
1282    iter->Reset();
1283    //Add draw variables to the list of normalisation
1284    while ((currentStr = (TObjString*)(iter->Next()))) {
1285       if (currentStr->GetString().BeginsWith("Map")) continue; //don't add mapping information
1286       fListNormalization->AddEntry(currentStr->GetString().Data(), id);
1287       if (fInitialized && currentStr->GetString() == selectedNormalization) normalizationId = id;
1288       id++;
1289    }
1290
1291    delete iterNorm;
1292    arrNorm->Delete();
1293    delete arrNorm;
1294
1295    delete iter;
1296    arr->Delete();
1297    delete arr;
1298    
1299    // trick do display the entries corectly after reinitialization
1300    // otherwise all the entries would appear as one kryptic entry
1301    // resizing the listbox somehow fixes the problem...
1302    if (fInitialized) fListVariables->Resize(fListVariables->GetWidth()-1, fListVariables->GetHeight());
1303    if (fInitialized) fListVariables->Resize(fListVariables->GetWidth()+1, fListVariables->GetHeight());
1304    if (fInitialized) fListNormalization->Resize(fListNormalization->GetWidth()-1, fListNormalization->GetHeight());
1305    if (fInitialized) fListNormalization->Resize(fListNormalization->GetWidth()+1, fListNormalization->GetHeight());
1306    
1307    // select the last selected variable and normalization
1308    if (fInitialized && variableId != -1)     fListVariables->Select(variableId);
1309    if (fInitialized && normalizationId != -1)fListVariables->Select(normalizationId);
1310    
1311    if (fInitialized) Info("Initialize", "AliTPCCalibViewerGUI new initialized.");
1312    fInitialized = kTRUE;
1313
1314 }
1315
1316 void AliTPCCalibViewerGUI::Reset(){
1317   //
1318   // reset variables, delete calib viewer
1319   //
1320   if (fViewer) delete fViewer;
1321   fListVariables->RemoveAll();
1322   fListNormalization->RemoveAll();
1323   fInitialized = kFALSE;
1324 }
1325
1326 void AliTPCCalibViewerGUI::HandleButtonsGeneral(Int_t id) {
1327    //
1328    // handles mutual radio button exclusions
1329    // for general Tab
1330    //
1331    if (id == -1) {
1332       TGButton *btn = (TGButton *) gTQSender;
1333       id = btn->WidgetId();
1334    }
1335
1336    switch (id) {
1337       case 10:             // fRadioRaw
1338          fRadioNormalized->SetState(kButtonUp);
1339          fRadioPredefined->SetState(kButtonDown);
1340          fRadioCustom->SetState(kButtonUp);
1341          // fComboMethod->UnmapWindow();
1342          // fListNormalization->UnmapWindow();
1343          break;
1344       case 11:             // fRadioNormalized
1345          fRadioRaw->SetState(kButtonUp);
1346          fRadioPredefined->SetState(kButtonDown);
1347          fRadioCustom->SetState(kButtonUp);
1348          break;
1349       case 12:             // fRadioCustom
1350          fRadioPredefined->SetState(kButtonUp);
1351          // fComboCustom->SetEnabled(kFALSE);
1352          // fRadioNormalized->SetState(kButtonUp);
1353          break;
1354       case 14:             // select Draw options fComboAddDrawOpt
1355          fChkAddDrawOpt->SetState(kButtonDown);
1356          break;
1357       case 13:             // fRadioPredefined
1358          fRadioCustom->SetState(kButtonUp);
1359          // fComboCustom->SetEnabled(kTRUE);
1360          //f RadioNormalized->SetState(kButtonUp);
1361          break;
1362       //--------
1363       case 30:             // fRadio1D
1364          fRadio2D->SetState(kButtonUp);
1365          fBtnExport->SetEnabled(kFALSE);
1366          fBtnAddNorm->SetEnabled(kFALSE);
1367          break;
1368       case 31:             // fRadio2D
1369          fRadio1D->SetState(kButtonUp);
1370          fBtnExport->SetEnabled(kTRUE);
1371          fBtnAddNorm->SetEnabled(kTRUE);
1372          break;
1373       case 42:             // fComboCustom
1374          fRadioCustom->SetState(kButtonDown);
1375          fRadioPredefined->SetState(kButtonUp);
1376          break;
1377    }
1378    DoNewSelection();
1379 }
1380
1381
1382 void AliTPCCalibViewerGUI::HandleButtons1D(Int_t id) {
1383    //
1384    // handles mutual radio button exclusions
1385    // 1D-Tab buttons
1386    //
1387    
1388    if (id == -1) {
1389       TGButton *btn = (TGButton *) gTQSender;
1390       id = btn->WidgetId();
1391    }
1392    switch (id) {
1393       case 110:            // 1D draw normal
1394          fRadioNorm->SetState(kButtonDown);
1395          fRadioSigma->SetState(kButtonUp);
1396          fRadioCumulative->SetState(kButtonUp);
1397          fRadioIntegrate->SetState(kButtonUp);
1398          break;
1399       case 111:            // 1D draw sigma
1400          fRadioNorm->SetState(kButtonUp);
1401          fRadioSigma->SetState(kButtonDown);
1402          fRadioCumulative->SetState(kButtonUp);
1403          fRadioIntegrate->SetState(kButtonUp);
1404          break;
1405       case 112:            // 1D draw cumulative
1406          fRadioNorm->SetState(kButtonUp);
1407          fRadioSigma->SetState(kButtonUp);
1408          fRadioCumulative->SetState(kButtonDown);
1409          fRadioIntegrate->SetState(kButtonUp);
1410          break;
1411       case 113:            // 1D draw integral
1412          fRadioNorm->SetState(kButtonUp);
1413          fRadioSigma->SetState(kButtonUp);
1414          fRadioCumulative->SetState(kButtonUp);
1415          fRadioIntegrate->SetState(kButtonDown);
1416          break;
1417    }
1418    DoNewSelection();
1419 }
1420
1421
1422 void AliTPCCalibViewerGUI::HandleButtonsStat(Int_t id) {
1423    // 
1424    // handles statistic check boxes 
1425    // checks each checkbox if checked
1426    // if the checkbox is checked, appends 'n' for name, 'e' for entries, ...
1427    // to a TString, passes this TString to gStyle->SetOptStat(...)
1428    // 
1429    if (id == -1) {
1430       TGButton *btn = (TGButton *) gTQSender;
1431       id = btn->WidgetId();
1432    }
1433    TString statOpt("");
1434    if (fChkStatName->GetState() == kButtonDown) statOpt.Append("n");
1435    if (fChkStatEntries->GetState() == kButtonDown) statOpt.Append("e");
1436    if (fChkStatMean->GetState() == kButtonDown && fChkStatMeanPM->GetState() == kButtonUp) statOpt.Append("m");
1437    if (fChkStatMeanPM->GetState() == kButtonDown) statOpt.Append("M");
1438    if (fChkStatRMS->GetState() == kButtonDown && fChkStatRMSPM->GetState() == kButtonUp) statOpt.Append("r");
1439    if (fChkStatRMSPM->GetState() == kButtonDown) statOpt.Append("R");
1440    if (fChkStatUnderflow->GetState() == kButtonDown) statOpt.Append("u");
1441    if (fChkStatOverflow->GetState() == kButtonDown) statOpt.Append("o");
1442    if (fChkStatIntegral->GetState() == kButtonDown) statOpt.Append("i");
1443    if (fChkStatSkewness->GetState() == kButtonDown && fChkStatSkewnessPM->GetState() == kButtonUp) statOpt.Append("s");
1444    if (fChkStatSkewnessPM->GetState() == kButtonDown) statOpt.Append("S");
1445    if (fChkStatKurtosis->GetState() == kButtonDown && fChkStatKurtosisPM->GetState() == kButtonUp) statOpt.Append("k");
1446    if (fChkStatKurtosisPM->GetState() == kButtonDown) statOpt.Append("K");
1447    
1448    gStyle->SetOptStat(statOpt);
1449    DoNewSelection();
1450 }
1451
1452
1453 void AliTPCCalibViewerGUI::HandleButtonsCuts(Int_t id) {
1454    //
1455    // handles mutual radio button exclusions
1456    // right side buttons
1457    //
1458     if (id == -1) {
1459       TGButton *btn = (TGButton *) gTQSender;
1460       id = btn->WidgetId();
1461    }
1462
1463    switch (id) {
1464       case 20:             // fRadioTPC
1465          fRadioSideA->SetState(kButtonUp);
1466          fRadioSideC->SetState(kButtonUp);
1467          fRadioROC->SetState(kButtonUp);
1468          fRadioSector->SetState(kButtonUp);
1469          break;
1470       case 21:             // fRadioSideA
1471          fRadioTPC->SetState(kButtonUp);
1472          fRadioSideC->SetState(kButtonUp);
1473          fRadioROC->SetState(kButtonUp);
1474          fRadioSector->SetState(kButtonUp);
1475          break;
1476       case 22:             // fRadioSideC
1477          fRadioTPC->SetState(kButtonUp);
1478          fRadioSideA->SetState(kButtonUp);
1479          fRadioROC->SetState(kButtonUp);
1480          fRadioSector->SetState(kButtonUp);
1481          break;
1482       case 23:             // fRadioROC
1483          fRadioTPC->SetState(kButtonUp);
1484          fRadioSideA->SetState(kButtonUp);
1485          fRadioSideC->SetState(kButtonUp);
1486          fRadioSector->SetState(kButtonUp);
1487          break;
1488       case 24:             // fRadioSector
1489          fRadioTPC->SetState(kButtonUp);
1490          fRadioSideA->SetState(kButtonUp);
1491          fRadioSideC->SetState(kButtonUp);
1492          fRadioROC->SetState(kButtonUp);
1493          break;
1494       case 31:            // fComboAddCuts
1495          fChkAddCuts->SetState(kButtonDown);
1496          break;
1497    }
1498    DoNewSelection();
1499 }
1500
1501
1502 void AliTPCCalibViewerGUI::HandleButtonsNoRedraw(Int_t id) {
1503    //
1504    // handles label & scaling checkboxes 
1505    // without redrawing (not necessary, faster like this)
1506    //
1507     if (id == -1) {
1508       TGButton *btn = (TGButton *) gTQSender;
1509       id = btn->WidgetId();
1510    }
1511
1512    switch (id) {
1513       case 40:             // fTxtSetMin
1514          fChkSetMin->SetState(kButtonDown);
1515          break;
1516       case 41:             // fTxtSetMax
1517          fChkSetMax->SetState(kButtonDown);
1518          break;
1519       case 50:             // fTxtLabelTitle
1520          fChkLabelTitle->SetState(kButtonDown);
1521          break;
1522       case 51:             // fTxtLabelXaxis
1523          fChkLabelXaxis->SetState(kButtonDown);
1524          break;
1525       case 52:             // fTxtLabelXaxis
1526          fChkLabelYaxis->SetState(kButtonDown);
1527          break;
1528    }
1529    SetMinMaxLabel();
1530 }
1531
1532 void AliTPCCalibViewerGUI::ReplacePlaceHolders(TString &str)
1533 {
1534     //
1535     // replace the defined placeholders in the custom draw string and cut string
1536     //
1537     TString drawPlaceHolder("#draw#");
1538     TString normPlaceHolder("#norm#");
1539
1540     //current draw variable
1541     TString desiredData("");
1542     if (fListVariables->GetSelectedEntry()){
1543       desiredData += ((TGTextLBEntry*)(fListVariables->GetSelectedEntry()))->GetTitle();
1544       str.ReplaceAll(drawPlaceHolder,desiredData);
1545     }
1546 //    desiredData += fViewer->GetAbbreviation();
1547
1548     //current normalisation
1549     TString normalizationData("");
1550     if (fListNormalization->GetSelectedEntry()){
1551       normalizationData += ((TGTextLBEntry*)(fListNormalization->GetSelectedEntry()))->GetTitle();
1552       if (! (TString(((TGTextLBEntry*)(fListNormalization->GetSelectedEntry()))->GetTitle())).BeginsWith("Fit"))
1553         if ( normalizationData.BeginsWith("_") ) normalizationData = desiredData+normalizationData;
1554       if ( fListVariables->FindEntry(normalizationData.Data()) )
1555         normalizationData+="~";
1556       str.ReplaceAll(normPlaceHolder,normalizationData);
1557     }
1558 }
1559
1560 void AliTPCCalibViewerGUI::DoNewSelection() {
1561    //
1562    // decides whether to redraw if user makes another selection
1563    //
1564    if (fChkAuto->GetState() == kButtonDown) DoDraw();
1565 }
1566
1567
1568 TString* AliTPCCalibViewerGUI::GetDrawString() {
1569    // 
1570    // create the draw string out of selection
1571    // 
1572    
1573    // specify data to plot
1574    TString desiredData("");
1575    if (!fListVariables->GetSelectedEntry()) return 0;
1576    desiredData += ((TGTextLBEntry*)(fListVariables->GetSelectedEntry()))->GetTitle();
1577    desiredData += fViewer->GetAbbreviation();
1578
1579    // specify normalization
1580    if (fRadioPredefined->GetState() == kButtonDown && fRadioNormalized->GetState() == kButtonDown) {
1581       TString op("");
1582       switch (fComboMethod->GetSelected()) {
1583          case 0:        // subtraction
1584             op += "-";
1585             break;
1586          case 1:        // division
1587             op += "/";
1588             break;
1589       }
1590       TString normalizationData("");
1591       if (!fListNormalization->GetSelectedEntry()) return 0;
1592       normalizationData += ((TGTextLBEntry*)(fListNormalization->GetSelectedEntry()))->GetTitle();
1593       
1594       if ( normalizationData.BeginsWith("Fit")) {
1595          // create fit formula, evaluate it an replace normalizationData-String
1596          // ********** create cut string **********
1597          TString cutStr("");
1598          if (fRadioTPC->GetState() == kButtonDown)
1599             cutStr += ""; // whole TPC is used for fitting
1600          if (fRadioSideA->GetState() == kButtonDown)
1601             cutStr += "(sector/18)%2==0"; // side A
1602          if (fRadioSideC->GetState() == kButtonDown)
1603             cutStr+= "(sector/18)%2==1"; // side C
1604          if (fRadioROC->GetState() == kButtonDown) {
1605             Int_t sector = (Int_t)(fNmbSector->GetNumber());
1606             cutStr += "sector==";
1607             cutStr += sector; 
1608          }
1609          if (fRadioSector->GetState() == kButtonDown) {
1610             Int_t sector = ((Int_t)(fNmbSector->GetNumber()))%36;
1611             cutStr += "sector%36==";
1612             cutStr += sector; 
1613          }
1614          if (fChkAddCuts->GetState() == kButtonDown && strcmp(fComboAddCuts->GetTextEntry()->GetText(), "") != 0){
1615             if (fRadioTPC->GetState() != kButtonDown) cutStr += " && ";
1616             cutStr += fComboAddCuts->GetTextEntry()->GetText();  
1617          }
1618          Double_t chi2 = 0;
1619          TVectorD fitParam(0);
1620          TMatrixD covMatrix(0,0);
1621          TString formulaStr("");
1622          if (normalizationData.CompareTo("FitLinLocal") == 0)
1623             formulaStr = "lx~ ++ ly~";
1624          if (normalizationData.CompareTo("FitLinGlobal") == 0) 
1625             formulaStr = "gx~ ++ gy~";
1626          if (normalizationData.CompareTo("FitParLocal") == 0)
1627             formulaStr = "lx~ ++ ly~ ++ lx~^2 ++ ly~^2 ++ lx~*ly~";
1628          if (normalizationData.CompareTo("FitParGlobal") == 0)
1629             formulaStr = "gx~ ++ gy~ ++ gx~^2 ++ gy~^2 ++ gx~*gy~";
1630          formulaStr.ReplaceAll("~", fViewer->GetAbbreviation());
1631          normalizationData = *fViewer->Fit(desiredData.Data(), formulaStr.Data(), cutStr.Data(), chi2, fitParam, covMatrix);
1632       }  // if ( normalizationData.BeginsWith("Fit")
1633
1634       desiredData += op;
1635       if (! (TString(((TGTextLBEntry*)(fListNormalization->GetSelectedEntry()))->GetTitle())).BeginsWith("Fit"))
1636          if ( normalizationData.BeginsWith("_") ) desiredData += ((TGTextLBEntry*)(fListVariables->GetSelectedEntry()))->GetTitle();
1637       if ( fListVariables->FindEntry(normalizationData.Data()) )
1638           normalizationData+="~";
1639       desiredData += normalizationData;
1640    }
1641    else if (fRadioCustom->GetState() == kButtonDown) {
1642       desiredData = fComboCustom->GetTextEntry()->GetText();
1643       if (desiredData == "") return 0;
1644       ReplacePlaceHolders(desiredData);
1645    }
1646    
1647    // try to add forgotten '~'
1648    if (fChkAutoAppend->GetState() == kButtonDown) 
1649       desiredData = TString(fViewer->AddAbbreviations((char*)desiredData.Data()));
1650    return new TString(desiredData.Data());
1651 }   
1652
1653   
1654 TString* AliTPCCalibViewerGUI::GetSectorString() {
1655    // 
1656    // create the sector string out of selection
1657    // 
1658
1659    TString sectorStr("");
1660    if (fRadioTPC->GetState() == kButtonDown)
1661       sectorStr += "ALL";
1662    if (fRadioSideA->GetState() == kButtonDown)
1663       sectorStr += "A"; //cuts += "(sector/18)%2==0";
1664    if (fRadioSideC->GetState() == kButtonDown)
1665       sectorStr+= "C"; //cuts += "(sector/18)%2==1";
1666    if (fRadioROC->GetState() == kButtonDown) {
1667       Int_t sector = (Int_t)(fNmbSector->GetNumber());
1668       sectorStr += sector; //cuts += "sector==";
1669    }
1670    if (fRadioSector->GetState() == kButtonDown) {
1671       Int_t sector = ((Int_t)(fNmbSector->GetNumber()))%36;
1672       sectorStr += "S";
1673       sectorStr += sector; //cuts += "sector%36==";
1674    }
1675    return new TString(sectorStr.Data());
1676 }   
1677   
1678  
1679  TString* AliTPCCalibViewerGUI::GetCutString() {
1680    // 
1681    // create the cut string out of selection
1682    // 
1683   
1684    TString cutsStr("");
1685    if (fChkCutZero->GetState() == kButtonDown) {
1686       TString cutZerosStr(GetDrawString()->Data());
1687       if (cutZerosStr.Contains(">>")) {
1688          cutZerosStr.Remove(cutZerosStr.First(">>"));
1689       }
1690       if (cutZerosStr.Contains(":")) {
1691          cutZerosStr.Remove(cutZerosStr.First(":"));
1692       }
1693       cutsStr += cutZerosStr.Data();
1694       cutsStr += "!=0";
1695       if (fChkAddCuts->GetState() == kButtonDown) cutsStr += " && ";
1696    }
1697    if (fChkAddCuts->GetState() == kButtonDown){
1698        cutsStr += fComboAddCuts->GetTextEntry()->GetText();
1699        ReplacePlaceHolders(cutsStr);
1700    }
1701
1702    
1703    // try to add forgotten '~'
1704    if (fChkAutoAppend->GetState() == kButtonDown) 
1705       cutsStr = TString(fViewer->AddAbbreviations((char*)cutsStr.Data()));
1706    return new TString(cutsStr.Data());
1707 }
1708
1709
1710 void AliTPCCalibViewerGUI::DoDraw() {
1711    //
1712    // main method for drawing according to user selection
1713    //
1714    
1715    // specify data to plot:
1716   if (!GetDrawString()) return;
1717    TString desiredData(GetDrawString()->Data());
1718    // specify sector:
1719    TString sectorStr(GetSectorString()->Data());
1720    // specify cuts:
1721    TString cutsStr(GetCutString()->Data());
1722
1723    TString addDrawOpt("");
1724    if (fChkAddDrawOpt->GetState() == kButtonDown)
1725       addDrawOpt += fComboAddDrawOpt->GetTextEntry()->GetText();
1726    
1727    // remove last picture
1728    if (!addDrawOpt.Contains("same"))
1729       for (Int_t i = 0; i < fCanvMain->GetCanvas()->GetListOfPrimitives()->GetEntries(); i++) {
1730          if (strcmp(fCanvMain->GetCanvas()->GetListOfPrimitives()->At(i)->ClassName(), "TFrame") != 0)
1731             fCanvMain->GetCanvas()->GetListOfPrimitives()->At(i)->Delete();
1732       }
1733    //fCanvMain->GetCanvas()->Clear();
1734    fCanvMain->GetCanvas()->cd();
1735    Int_t entries = -1;
1736    // draw finally
1737    if (fRadio1D->GetState() == kButtonDown){
1738       // 1D-Drawing
1739       TString strSigmaMax(fTxtSigmaMax->GetText());  // get sigmaMax from text enty
1740       Double_t sigmaMax = (strSigmaMax.IsFloat()) ? strSigmaMax.Atof() : 5; // convert to double, if not convertable, set to 5
1741       Bool_t plotMean   = fChkMean->GetState() == kButtonDown;
1742       Bool_t plotMedian = fChkMedian->GetState() == kButtonDown;
1743       Bool_t plotLTM    = fChkLTM->GetState() == kButtonDown;
1744       if (fRadioNorm->GetState() == kButtonDown)  // normal 1D drawing
1745          entries = fViewer->EasyDraw1D(desiredData.Data(), sectorStr.Data(), cutsStr.Data(), addDrawOpt.Data());
1746       if (fRadioSigma->GetState() == kButtonDown) // sigma 1D drawing
1747          entries = fViewer->DrawHisto1D(desiredData.Data(), sectorStr.Data(), cutsStr.Data(), // 
1748             fTxtSigmas->GetText(), plotMean, plotMedian, plotLTM);
1749       if (fRadioCumulative->GetState() == kButtonDown)  // cumulative 1D drawing
1750          entries = fViewer->SigmaCut(desiredData.Data(), sectorStr.Data(), cutsStr.Data(), //
1751             sigmaMax, plotMean, plotMedian, plotLTM, // 
1752             fCheckCumulativePM->GetState() == kButtonDown, fTxtSigmas->GetText(), /* Float_t sigmaStep =*/ -1);
1753       if (fRadioIntegrate->GetState() == kButtonDown)  // integral 1D drawing  
1754          entries = fViewer->Integrate(desiredData.Data(), sectorStr.Data(), cutsStr.Data(), //
1755             sigmaMax, plotMean, plotMedian, plotLTM, // 
1756             fTxtSigmas->GetText(), /* Float_t sigmaStep =*/ -1);            
1757    }
1758    else if (fRadio2D->GetState() == kButtonDown) {
1759       // 2D-Drawing
1760       entries = fViewer->EasyDraw(desiredData.Data(), sectorStr.Data(), cutsStr.Data(), addDrawOpt.Data());
1761    }
1762    if (entries == -1) return; // nothing was drawn, there is no histogram to get min and max
1763    
1764    SetMinMaxLabel();
1765    fCanvMain->GetCanvas()->Update();
1766 }
1767
1768
1769 void AliTPCCalibViewerGUI::DoFit() {
1770    //
1771    // main method for fitting
1772    //
1773    
1774    Double_t chi2 = 0;
1775    TVectorD fitParam(0);
1776    TMatrixD covMatrix(0,0);
1777    TString cutStr("");
1778    TString formulaStr("");
1779
1780    // specify data to plot:
1781    TString drawStr(GetDrawString()->Data());
1782    
1783    // ********** create cut string **********
1784    if (fRadioTPC->GetState() == kButtonDown)
1785       cutStr += ""; // whole TPC is used for fitting
1786    if (fRadioSideA->GetState() == kButtonDown)
1787       cutStr += "(sector/18)%2==0"; // side A
1788    if (fRadioSideC->GetState() == kButtonDown)
1789       cutStr+= "(sector/18)%2==1"; // side C
1790    if (fRadioROC->GetState() == kButtonDown) {
1791       Int_t sector = (Int_t)(fNmbSector->GetNumber());
1792       cutStr += "sector==";
1793       cutStr += sector; 
1794    }
1795    if (fRadioSector->GetState() == kButtonDown) {
1796       Int_t sector = (Int_t)(fNmbSector->GetNumber())%36;
1797       cutStr += "sector%36==";
1798       cutStr += sector; 
1799    }
1800    if (fChkAddCuts->GetState() == kButtonDown && strcmp(fComboAddCuts->GetTextEntry()->GetText(), "") != 0){
1801       if (fRadioTPC->GetState() != kButtonDown) cutStr += " && ";
1802       cutStr += fComboAddCuts->GetTextEntry()->GetText();  
1803    }
1804    // try to add forgotten '~'
1805    if (fChkAutoAppend->GetState() == kButtonDown) 
1806       cutStr = TString(fViewer->AddAbbreviations((char*)cutStr.Data()));
1807    
1808    // ********** get formula string **********
1809    formulaStr += fComboCustomFit->GetTextEntry()->GetText();
1810    if (fChkAutoAppend->GetState() == kButtonDown) 
1811       formulaStr = TString(fViewer->AddAbbreviations((char*)formulaStr.Data()));
1812
1813    // ********** call AliTPCCalibViewer's fit-function
1814   ReplacePlaceHolders(drawStr);
1815   ReplacePlaceHolders(cutStr);
1816   TString *returnStr = fViewer->Fit(drawStr.Data(), formulaStr.Data(), cutStr.Data(), chi2, fitParam, covMatrix);
1817    
1818    std::cout << std::endl;
1819    std::cout << "Your fit formula reads as follows:" << std::endl;
1820    std::cout << returnStr->Data() << std::endl;
1821    std::cout << "chi2 = " << chi2 << std::endl;
1822
1823   delete returnStr;
1824 }
1825
1826
1827 void AliTPCCalibViewerGUI::DoExport() {
1828    //
1829    // function to export a CalPad to Cint
1830    //
1831    if ( fRadio2D->GetState() != kButtonDown){
1832       Error("ExportCalPad", "Export of AliTPCCalPad to CINT works only in 2D mode.");
1833       return;
1834    }
1835    // specify data to plot:
1836    TString desiredData(GetDrawString()->Data());
1837    // specify cuts:
1838    TString cutsStr(GetCutString()->Data());
1839    // get name for the calPad   
1840    const char* calPadName = fComboExportName->GetTextEntry()->GetText();
1841    // create calPad according to drawCommand and cuts
1842    AliTPCCalPad *calPad = fViewer->GetCalPad(desiredData.Data(), (char*)cutsStr.Data(), (char*)calPadName);
1843    // finally export calPad to Cint:
1844    gROOT->ProcessLine(Form("AliTPCCalPad* %s = (AliTPCCalPad*)0x%lx;", calPadName, (ULong_t)calPad));
1845    fPreprocessor->AddComponent(calPad);
1846    Info("ExportCalPad", "Current 2D view has been exported to an AliTPCCalPad* with name '%s'", calPadName);
1847 }
1848
1849
1850 void AliTPCCalibViewerGUI::DoExportNorm() {
1851    //
1852    // function to export a CalPad to Cint
1853    //
1854    
1855    if ( fRadio2D->GetState() != kButtonDown){
1856       Error("ExportCalPad", "Adding an AliTPCCalPad to the normalization works only in 2D mode.");
1857       return;
1858    }
1859    
1860    Error("DoExportNorm", "Not yet implemented.");
1861 /*  
1862    return;
1863    
1864    // specify data to plot:
1865    TString desiredData(GetDrawString()->Data());
1866    // specify sector:
1867    TString sectorStr(GetSectorString()->Data());
1868    // specify cuts:
1869    TString cutsStr(GetCutString()->Data());
1870    
1871    // get name for the calPad   
1872    const char* calPadName = fComboExportName->GetTextEntry()->GetText();
1873    // create calPad according to drawCommand and cuts
1874    AliTPCCalPad *calPad = fViewer->GetCalPad(desiredData.Data(), (char*)cutsStr.Data(), (char*)fComboExportName->GetTextEntry()->GetText());
1875    // finally export calPad to Cint:
1876    gROOT->ProcessLine(Form("AliTPCCalPad* %s = (AliTPCCalPad*)0x%lx;", calPadName, (ULong_t) calPad));
1877    Info("ExportCalPad", "Current 2D view has been exported to an AliTPCCalPad* with name '%s'", calPadName);
1878   */
1879 }
1880
1881
1882 void AliTPCCalibViewerGUI::GetMinMax() {
1883    //
1884    // Read current Min & Max from the plot and set it to fTxtSetMin & fTxtSetMax
1885    //
1886    if (fChkGetMinMaxAuto->GetState() == kButtonUp) return;
1887    TList* listOfPrimitives = fCanvMain->GetCanvas()->GetListOfPrimitives();
1888    TObject* ptr = 0;
1889    for (Int_t i = 0; i < listOfPrimitives->GetEntries(); i++) {
1890       ptr = listOfPrimitives->At(i);
1891       if ( ptr->InheritsFrom("TH1") ) break;
1892    }
1893    if ( !ptr || !ptr->InheritsFrom("TH1") ) return;      // if the loop did not find a TH1
1894    TH1 *hist = (TH1*)ptr;
1895
1896 //    Double_t histMax = hist->GetMaximum();
1897 //    Double_t histMin = hist->GetMinimum();
1898 //    fTxtSetMax->SetText(Form("%f",histMax));
1899 //    fTxtSetMin->SetText(Form("%f",histMin));
1900
1901    if (fRadio2D->GetState() == kButtonDown) {
1902       if (fChkSetMax->GetState() == kButtonUp)
1903          fTxtSetMax->SetText(Form("%f", hist->GetMaximum()));
1904       if (fChkSetMin->GetState() == kButtonUp)
1905          fTxtSetMin->SetText(Form("%f", hist->GetMinimum()));
1906    }
1907    else if (fRadio1D->GetState() == kButtonDown) {
1908       if (fChkSetMax->GetState() == kButtonUp)
1909          fTxtSetMax->SetText( Form("%f", hist->GetXaxis()->GetXmax()) );
1910       if (fChkSetMin->GetState() == kButtonUp)
1911          fTxtSetMin->SetText( Form("%f", hist->GetXaxis()->GetXmin()) );
1912    }
1913 }
1914
1915
1916 void AliTPCCalibViewerGUI::SetMinMaxLabel() {
1917    // 
1918    // Set Minimum, Maximum and labels without redrawing the plot
1919    // (faster)
1920    // 
1921    
1922    // search for histogram
1923    TList* listOfPrimitives = fCanvMain->GetCanvas()->GetListOfPrimitives();
1924    TObject* ptr = 0;
1925    for (Int_t i = 0; i < listOfPrimitives->GetEntries(); i++) {
1926       ptr = listOfPrimitives->At(i);
1927       if ( ptr->InheritsFrom("TH1") ) break;
1928    }
1929    if ( ptr == 0 || !ptr->InheritsFrom("TH1") ) {  // if the loop did not find a TH1
1930       fCanvMain->GetCanvas()->Update();
1931       Warning("SetMinMaxLabel","No Histogram found!");
1932       return;
1933       // unable to find histogram, no min and max wil be read out
1934    }
1935    
1936    TH1 *hist = (TH1*)ptr; 
1937    TString minTxt(fTxtSetMin->GetText());
1938    TString maxTxt(fTxtSetMax->GetText());
1939    
1940    // set min and max according to specified values, if checkbox is checked
1941    if (fRadio2D->GetState() == kButtonDown) {
1942       if (fChkSetMax->GetState() == kButtonDown && fChkSetMax->GetState() == kButtonDown &&(maxTxt.IsDigit() || maxTxt.IsFloat()) )
1943          hist->SetMaximum(maxTxt.Atof());
1944       if (fChkSetMax->GetState() == kButtonUp)
1945          hist->SetMaximum(-1111);  // default value, to unzoom
1946       if (fChkSetMin->GetState() == kButtonDown && (minTxt.IsDigit() || minTxt.IsFloat()) )
1947          hist->SetMinimum(minTxt.Atof());
1948       if (fChkSetMin->GetState() == kButtonUp)
1949          hist->SetMinimum(-1111);  // default value, to unzoom
1950    }
1951    else if (fRadio2D->GetState() == kButtonDown) {
1952       if (fChkSetMin->GetState() == kButtonDown && 
1953           fChkSetMax->GetState() == kButtonDown && hist->GetXaxis())
1954          hist->GetXaxis()->SetRangeUser(hist->GetXaxis()->GetXmin(), hist->GetXaxis()->GetXmax());
1955       else if (fChkSetMax->GetState() == kButtonDown && hist->GetXaxis())
1956          hist->GetXaxis()->SetRangeUser(hist->GetXaxis()->GetXmin(), maxTxt.Atof());
1957       else if (fChkSetMin->GetState() == kButtonDown && hist->GetXaxis())
1958          hist->GetXaxis()->SetRangeUser(minTxt.Atof(), hist->GetXaxis()->GetXmax());
1959       hist->SetTitle(hist->GetTitle());  // trick to update the histogram
1960    }
1961    
1962    // get min and max from plot       
1963    GetMinMax();
1964    
1965    // set labels according to specification, if cehckboxes are checked
1966    if (fChkLabelTitle->GetState() == kButtonDown) 
1967       hist->SetTitle(fTxtLabelTitle->GetText());
1968    if (fChkLabelXaxis->GetState() == kButtonDown)
1969       hist->GetXaxis()->SetTitle(fTxtLabelXaxis->GetText());
1970    if (fChkLabelYaxis->GetState() == kButtonDown)
1971       hist->GetYaxis()->SetTitle(fTxtLabelYaxis->GetText());
1972    // get and/or set labels and title
1973    if (fChkLabelGetAuto->GetState() == kButtonDown) {
1974       fTxtLabelTitle->SetText(hist->GetTitle());
1975       fTxtLabelXaxis->SetTitle(hist->GetXaxis()->GetTitle());
1976       fTxtLabelYaxis->SetTitle(hist->GetYaxis()->GetTitle());
1977    }
1978    hist->SetTitle(hist->GetTitle());  // trick to update the histogram
1979    fCanvMain->GetCanvas()->Update();
1980 }
1981    
1982    
1983 void AliTPCCalibViewerGUI::ChangeSector(){
1984    // 
1985    // function that is called, when the number of the sector is changed
1986    // to change the sector label
1987    //
1988    if ( fRadioROC->GetState()!=kButtonDown && fRadioSector->GetState()!=kButtonDown ){
1989        fLblSector->SetText("not used");
1990        return;
1991    }
1992
1993    Int_t sector = (Int_t)(fNmbSector->GetNumber());
1994    TString secLabel = "";
1995    if ( sector < 36 )
1996        secLabel = "IROC";
1997    else
1998        secLabel = "OROC";
1999
2000    if (fRadioSector->GetState()==kButtonDown)
2001        secLabel="Sector";
2002
2003    if ( sector%36<18 ) //A-Side
2004        secLabel += ", A";
2005    else
2006        secLabel += ", C";
2007
2008    secLabel += Form("%02d",sector%18);
2009
2010    fLblSector->SetText(secLabel);
2011    DoNewSelection();
2012 }
2013
2014
2015 void AliTPCCalibViewerGUI::AddFitFunction() const { 
2016    //
2017    // adds the last fit function to the normalization list
2018    // 
2019    std::cout << "Not yet implemented." << std::endl;
2020 }
2021
2022
2023 void AliTPCCalibViewerGUI::UnchekAllStat() {
2024    // 
2025    // Disable all statistical legend entries, no statistical legend.
2026    // 
2027    fChkStatName->SetState(kButtonUp);
2028    fChkStatEntries->SetState(kButtonUp);
2029    fChkStatMean->SetState(kButtonUp);
2030    fChkStatMeanPM->SetState(kButtonUp);
2031    fChkStatRMS->SetState(kButtonUp);
2032    fChkStatRMSPM->SetState(kButtonUp);
2033    fChkStatUnderflow->SetState(kButtonUp);
2034    fChkStatOverflow->SetState(kButtonUp);
2035    fChkStatIntegral->SetState(kButtonUp);
2036    fChkStatSkewness->SetState(kButtonUp);
2037    fChkStatSkewnessPM->SetState(kButtonUp);
2038    fChkStatKurtosis->SetState(kButtonUp);
2039    fChkStatKurtosisPM->SetState(kButtonUp);
2040    
2041    HandleButtonsStat(0);
2042 }
2043
2044
2045 void AliTPCCalibViewerGUI::MouseMove(Int_t event, Int_t x, Int_t y, TObject *selectedObject) { 
2046    //
2047    // mouse move
2048    // zoom to sector works ONLY in 2D mode, if one side is specified
2049    // 
2050    Double_t pi = TMath::Pi();
2051    if (event != kButton1Double )
2052       return;
2053    if (!selectedObject->InheritsFrom("TH2")) return;
2054    // zoom to sector works ONLY in 2D mode, if one side is specified
2055    if (fRadio2D->GetState() == kButtonUp) return;
2056    if (fRadioROC->GetState() == kButtonDown) { // return to full side view
2057       // return to full side view
2058       Int_t sector = (Int_t)(fNmbSector->GetNumber());
2059       if ( (sector >= 0 && sector <= 17) || (sector >= 36 &&  sector <= 53) ) {
2060          // A-Side
2061          fRadioSideA->Clicked();
2062          fRadioSideA->SetState(kButtonDown);
2063          DoNewSelection();
2064       }
2065       if ( (sector >= 18 && sector <= 35) || (sector >= 54 &&  sector <= 71) ) {
2066          // C-Side
2067          fRadioSideC->Clicked();
2068          fRadioSideC->SetState(kButtonDown);
2069          DoNewSelection();
2070       }
2071       return;
2072    }
2073    if (!(fRadioSideA->GetState() == kButtonDown || fRadioSideC->GetState() == kButtonDown)) return;
2074    
2075    // Int_t    px        = gPad->GetEventX();
2076    // Int_t    py        = gPad->GetEventY();
2077    Float_t  upy       = gPad->AbsPixeltoY(y);
2078    Float_t  upx       = gPad->AbsPixeltoX(x);
2079    Float_t  gy         = gPad->PadtoY(upy);
2080    Float_t  gx         = gPad->PadtoX(upx);
2081    Int_t quadrant = -1;
2082    if (gx >= 0 && gy >= 0) quadrant = 1;
2083    if (gx <  0 && gy >= 0) quadrant = 2;
2084    if (gx <  0 && gy <  0) quadrant = 3;
2085    if (gx >= 0 && gy <  0) quadrant = 4;
2086    gx = TMath::Abs(gx);
2087    gy = TMath::Abs(gy);
2088    Double_t phi = TMath::ATan(gy/gx);        // angle phi is in Pi- units
2089    Double_t r   = TMath::Sqrt(gx*gx + gy*gy);
2090    if (quadrant == 2) phi = pi - phi;
2091    if (quadrant == 3) phi = pi + phi;
2092    if (quadrant == 4) phi = 2 * pi - phi;
2093    Double_t phiGrad = phi / pi * 180;
2094    Int_t sector = (Int_t) phiGrad / 20;  // one sector coresponds to 20�
2095    // IROC starts at 84.5 cm
2096    // IROC ends at 135.5 cm, OROC begins
2097    // OROC ends at 250 cm
2098    if (r < 84.5 || r > 250) return; // outside TPC
2099    if (r < 135.5) { // IROC 
2100       if (fRadioSideC->GetState() == kButtonDown) sector += 18;
2101    }
2102    else {// OROC
2103       sector += 36;
2104       if (fRadioSideC->GetState() == kButtonDown) sector += 18;
2105    }
2106    // printf("r: %f, phi: %f, phiGrad: %f, gy/gx: %f, quadrant: %i, sector: %i \n", r, phi, phiGrad, gy/gx, quadrant, sector);
2107    fNmbSector->SetNumber(sector);
2108    fRadioROC->Clicked();
2109    fRadioROC->SetState(kButtonDown);
2110    ChangeSector();   
2111 }
2112
2113
2114 void AliTPCCalibViewerGUI::SavePicture() {
2115    // 
2116    // saves the current picture
2117    // 
2118    // use the following combination of file type and save options:
2119    // (see also TCanvas::Print)
2120    // 
2121    //       "ps"  - Postscript file is produced (see special cases below)
2122    //    "Portrait" - Postscript file is produced (Portrait)
2123    // "Landscape" - Postscript file is produced (Landscape)
2124    //       "eps" - an Encapsulated Postscript file is produced
2125    //    "Preview" - an Encapsulated Postscript file with preview is produced.
2126    //       "pdf" - a PDF file is produced
2127    //       "svg" - a SVG file is produced
2128    //       "gif" - a GIF file is produced
2129    //       "gif+NN" - an animated GIF file is produced, where NN is delay in 10ms units
2130    //       "xpm" - a XPM file is produced
2131    //       "png" - a PNG file is produced
2132    //       "jpg" - a JPEG file is produced
2133    //       "tiff" - a TIFF file is produced
2134    //       "cxx" - a C++ macro file is produced
2135    //       "xml" - a XML file
2136    //       "root" - a ROOT binary file
2137    
2138    const char *kSaveAsTypes[] = {
2139       "Postscript",  "*.ps",
2140       "Encapsulated Postscript",   "*.eps",
2141       "PDF",   "*.pdf",
2142       "JPEG",   "*.jpg",
2143       "PNG",   "*.png",
2144       "TIFF",   "*.tiff",
2145       "GIF",   "*.gif",
2146       "XPM",   "*.xpm",
2147       "SVG",   "*.svg",
2148       "XML",   "*.xml",
2149       "C++ macro",   "*.cxx",
2150       "Macro file",  "*.C",
2151       "ROOT file",   "*.root",
2152       "All file",    "*",
2153        0,              0
2154    };
2155    TString addSaveOpt("");
2156    if (fChkAddSaveOpt->GetState() == kButtonDown)
2157    addSaveOpt += fComboAddSaveOpt->GetTextEntry()->GetText();
2158    TString dir(".");
2159    TGFileInfo fi;
2160    fi.fFileTypes = kSaveAsTypes;
2161    // fi.fIniDir    = StrDup(dir);
2162    fi.fOverwrite = kFALSE;
2163    new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDSave, &fi);
2164    if (fi.fFilename && strlen(fi.fFilename)) {
2165       if (addSaveOpt != "")
2166          fCanvMain->GetCanvas()->Print(fi.fFilename, addSaveOpt.Data());
2167       else 
2168          fCanvMain->GetCanvas()->Print(fi.fFilename);
2169    }
2170
2171 // TList*       fFileNamesList  list of selected file names
2172 // Int_t        fFileTypeIdx    selected file type, index in fFileTypes
2173 // const char** fFileTypes      file types used to filter selectable files
2174 // char*        fFilename       selected file name
2175 // char*        fIniDir on input: initial directory, on output: new directory
2176 // Bool_t       fMultipleSelection      if true, allow multiple file selection
2177 // Bool_t       fOverwrite      if true overwrite the file with existing name on save
2178    
2179 }
2180    
2181
2182 void AliTPCCalibViewerGUI::DoDumpToFile() {
2183    // 
2184    // This function is called, when the "Dump to File" button is pressed. 
2185    // All the exported CalPads will be written into an new CalibTree, 
2186    // a Save File dialog will appear to specify the filename
2187    // 
2188    const char *kSaveAsTypes[] = {
2189       "ROOT file",   "*.root",
2190        0,              0
2191    };
2192    TString dir(".");
2193    TGFileInfo fi;
2194    fi.fFileTypes = kSaveAsTypes;
2195    // fi.fIniDir    = StrDup(dir);
2196    fi.fOverwrite = kFALSE;
2197    new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDSave, &fi);
2198    if (fi.fFilename && strlen(fi.fFilename)) {
2199       fPreprocessor->DumpToFile(fi.fFilename);
2200       Info("DumpToFile","New CalibTree has been writen to file '%s'", fi.fFilename);
2201    }
2202 }
2203
2204
2205 void AliTPCCalibViewerGUI::DoLoadTree() {
2206    // function to load a new calib tree
2207    // 
2208    // 
2209    const char *kFileTypes[] = {
2210       "ROOT file",   "*.root",
2211        0,              0
2212    };
2213    TString dir(".");
2214    TGFileInfo fi;
2215    fi.fFileTypes = kFileTypes;
2216    // fi.fIniDir    = StrDup(dir);
2217    fi.fOverwrite = kFALSE;
2218    new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDOpen, &fi);
2219    if (fi.fFilename && strlen(fi.fFilename) && fChkAddAsReference->GetState() == kButtonUp) {
2220       Initialize(fi.fFilename);
2221       Reload();
2222    }
2223    else if (fi.fFilename && strlen(fi.fFilename) && fChkAddAsReference->GetState() == kButtonDown) {
2224       fViewer->AddReferenceTree(fi.fFilename, "calPads", fTxtRefName->GetText());
2225       Reload();
2226    }
2227 }
2228
2229
2230 TObjArray* AliTPCCalibViewerGUI::ShowGUI(const char* fileName) {
2231    //
2232    // Initialize and show GUI for presentation for demonstration purposes
2233    // or for fast standalone use
2234    // 
2235    TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
2236    frmMain->SetWindowName("AliTPCCalibViewer GUI");
2237    frmMain->SetCleanup(kDeepCleanup);
2238    
2239    TGTab* tabMain = new TGTab(frmMain, 1000, 600);
2240    frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
2241
2242    TGCompositeFrame* tabCont1 = tabMain->AddTab("Viewer 1");
2243    TGCompositeFrame* tabCont2 = tabMain->AddTab("Viewer 2");
2244    
2245    AliTPCCalibViewerGUI* calibViewer1 = new AliTPCCalibViewerGUI(tabCont1, 1000, 600, (char*)fileName);
2246    tabCont1->AddFrame(calibViewer1, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
2247
2248    AliTPCCalibViewerGUI* calibViewer2 = new AliTPCCalibViewerGUI(tabCont2, 1000, 600, (char*)fileName);
2249    tabCont2->AddFrame(calibViewer2, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
2250    
2251    TObjArray *guiArray = new TObjArray();
2252    guiArray->Add(calibViewer1);
2253    guiArray->Add(calibViewer2);
2254    
2255    frmMain->MapSubwindows();
2256    frmMain->Resize();
2257    frmMain->MapWindow();
2258    
2259    return guiArray;
2260 }
2261