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