]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCCalibViewerGUI.cxx
Jens Wiechula changes.
[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()){
1542       desiredData += ((TGTextLBEntry*)(fListVariables->GetSelectedEntry()))->GetTitle();
1543       str.ReplaceAll(drawPlaceHolder,desiredData);
1544     }
1545 //    desiredData += fViewer->GetAbbreviation();
1546
1547     //current normalisation
1548     TString normalizationData("");
1549     if (fListNormalization->GetSelectedEntry()){
1550       normalizationData += ((TGTextLBEntry*)(fListNormalization->GetSelectedEntry()))->GetTitle();
1551       if (! (TString(((TGTextLBEntry*)(fListNormalization->GetSelectedEntry()))->GetTitle())).BeginsWith("Fit"))
1552         if ( normalizationData.BeginsWith("_") ) normalizationData = desiredData+normalizationData;
1553       if ( fListVariables->FindEntry(normalizationData.Data()) )
1554         normalizationData+="~";
1555       str.ReplaceAll(normPlaceHolder,normalizationData);
1556     }
1557 }
1558
1559 void AliTPCCalibViewerGUI::DoNewSelection() {
1560    //
1561    // decides whether to redraw if user makes another selection
1562    //
1563    if (fChkAuto->GetState() == kButtonDown) DoDraw();
1564 }
1565
1566
1567 TString* AliTPCCalibViewerGUI::GetDrawString() {
1568    // 
1569    // create the draw string out of selection
1570    // 
1571    
1572    // specify data to plot
1573    TString desiredData("");
1574    if (!fListVariables->GetSelectedEntry()) return 0;
1575    desiredData += ((TGTextLBEntry*)(fListVariables->GetSelectedEntry()))->GetTitle();
1576    desiredData += fViewer->GetAbbreviation();
1577
1578    // specify normalization
1579    if (fRadioPredefined->GetState() == kButtonDown && fRadioNormalized->GetState() == kButtonDown) {
1580       TString op("");
1581       switch (fComboMethod->GetSelected()) {
1582          case 0:        // subtraction
1583             op += "-";
1584             break;
1585          case 1:        // division
1586             op += "/";
1587             break;
1588       }
1589       TString normalizationData("");
1590       if (!fListNormalization->GetSelectedEntry()) return 0;
1591       normalizationData += ((TGTextLBEntry*)(fListNormalization->GetSelectedEntry()))->GetTitle();
1592       
1593       if ( normalizationData.BeginsWith("Fit")) {
1594          // create fit formula, evaluate it an replace normalizationData-String
1595          // ********** create cut string **********
1596          TString cutStr("");
1597          if (fRadioTPC->GetState() == kButtonDown)
1598             cutStr += ""; // whole TPC is used for fitting
1599          if (fRadioSideA->GetState() == kButtonDown)
1600             cutStr += "(sector/18)%2==0"; // side A
1601          if (fRadioSideC->GetState() == kButtonDown)
1602             cutStr+= "(sector/18)%2==1"; // side C
1603          if (fRadioROC->GetState() == kButtonDown) {
1604             Int_t sector = (Int_t)(fNmbSector->GetNumber());
1605             cutStr += "sector==";
1606             cutStr += sector; 
1607          }
1608          if (fRadioSector->GetState() == kButtonDown) {
1609             Int_t sector = ((Int_t)(fNmbSector->GetNumber()))%36;
1610             cutStr += "sector%36==";
1611             cutStr += sector; 
1612          }
1613          if (fChkAddCuts->GetState() == kButtonDown && strcmp(fComboAddCuts->GetTextEntry()->GetText(), "") != 0){
1614             if (fRadioTPC->GetState() != kButtonDown) cutStr += " && ";
1615             cutStr += fComboAddCuts->GetTextEntry()->GetText();  
1616          }
1617          Double_t chi2 = 0;
1618          TVectorD fitParam(0);
1619          TMatrixD covMatrix(0,0);
1620          TString formulaStr("");
1621          if (normalizationData.CompareTo("FitLinLocal") == 0)
1622             formulaStr = "lx~ ++ ly~";
1623          if (normalizationData.CompareTo("FitLinGlobal") == 0) 
1624             formulaStr = "gx~ ++ gy~";
1625          if (normalizationData.CompareTo("FitParLocal") == 0)
1626             formulaStr = "lx~ ++ ly~ ++ lx~^2 ++ ly~^2 ++ lx~*ly~";
1627          if (normalizationData.CompareTo("FitParGlobal") == 0)
1628             formulaStr = "gx~ ++ gy~ ++ gx~^2 ++ gy~^2 ++ gx~*gy~";
1629          formulaStr.ReplaceAll("~", fViewer->GetAbbreviation());
1630          normalizationData = *fViewer->Fit(desiredData.Data(), formulaStr.Data(), cutStr.Data(), chi2, fitParam, covMatrix);
1631       }  // if ( normalizationData.BeginsWith("Fit")
1632
1633       desiredData += op;
1634       if (! (TString(((TGTextLBEntry*)(fListNormalization->GetSelectedEntry()))->GetTitle())).BeginsWith("Fit"))
1635          if ( normalizationData.BeginsWith("_") ) desiredData += ((TGTextLBEntry*)(fListVariables->GetSelectedEntry()))->GetTitle();
1636       if ( fListVariables->FindEntry(normalizationData.Data()) )
1637           normalizationData+="~";
1638       desiredData += normalizationData;
1639    }
1640    else if (fRadioCustom->GetState() == kButtonDown) {
1641       desiredData = fComboCustom->GetTextEntry()->GetText();
1642       if (desiredData == "") return 0;
1643       ReplacePlaceHolders(desiredData);
1644    }
1645    
1646    // try to add forgotten '~'
1647    if (fChkAutoAppend->GetState() == kButtonDown) 
1648       desiredData = TString(fViewer->AddAbbreviations((char*)desiredData.Data()));
1649    return new TString(desiredData.Data());
1650 }   
1651
1652   
1653 TString* AliTPCCalibViewerGUI::GetSectorString() {
1654    // 
1655    // create the sector string out of selection
1656    // 
1657
1658    TString sectorStr("");
1659    if (fRadioTPC->GetState() == kButtonDown)
1660       sectorStr += "ALL";
1661    if (fRadioSideA->GetState() == kButtonDown)
1662       sectorStr += "A"; //cuts += "(sector/18)%2==0";
1663    if (fRadioSideC->GetState() == kButtonDown)
1664       sectorStr+= "C"; //cuts += "(sector/18)%2==1";
1665    if (fRadioROC->GetState() == kButtonDown) {
1666       Int_t sector = (Int_t)(fNmbSector->GetNumber());
1667       sectorStr += sector; //cuts += "sector==";
1668    }
1669    if (fRadioSector->GetState() == kButtonDown) {
1670       Int_t sector = ((Int_t)(fNmbSector->GetNumber()))%36;
1671       sectorStr += "S";
1672       sectorStr += sector; //cuts += "sector%36==";
1673    }
1674    return new TString(sectorStr.Data());
1675 }   
1676   
1677  
1678  TString* AliTPCCalibViewerGUI::GetCutString() {
1679    // 
1680    // create the cut string out of selection
1681    // 
1682   
1683    TString cutsStr("");
1684    if (fChkCutZero->GetState() == kButtonDown) {
1685       TString cutZerosStr(GetDrawString()->Data());
1686       if (cutZerosStr.Contains(">>")) {
1687          cutZerosStr.Remove(cutZerosStr.First(">>"));
1688       }
1689       if (cutZerosStr.Contains(":")) {
1690          cutZerosStr.Remove(cutZerosStr.First(":"));
1691       }
1692       cutsStr += cutZerosStr.Data();
1693       cutsStr += "!=0";
1694       if (fChkAddCuts->GetState() == kButtonDown) cutsStr += " && ";
1695    }
1696    if (fChkAddCuts->GetState() == kButtonDown){
1697        cutsStr += fComboAddCuts->GetTextEntry()->GetText();
1698        ReplacePlaceHolders(cutsStr);
1699    }
1700
1701    
1702    // try to add forgotten '~'
1703    if (fChkAutoAppend->GetState() == kButtonDown) 
1704       cutsStr = TString(fViewer->AddAbbreviations((char*)cutsStr.Data()));
1705    return new TString(cutsStr.Data());
1706 }
1707
1708
1709 void AliTPCCalibViewerGUI::DoDraw() {
1710    //
1711    // main method for drawing according to user selection
1712    //
1713    
1714    // specify data to plot:
1715   if (!GetDrawString()) return;
1716    TString desiredData(GetDrawString()->Data());
1717    // specify sector:
1718    TString sectorStr(GetSectorString()->Data());
1719    // specify cuts:
1720    TString cutsStr(GetCutString()->Data());
1721
1722    TString addDrawOpt("");
1723    if (fChkAddDrawOpt->GetState() == kButtonDown)
1724       addDrawOpt += fComboAddDrawOpt->GetTextEntry()->GetText();
1725    
1726    // remove last picture
1727    if (!addDrawOpt.Contains("same"))
1728       for (Int_t i = 0; i < fCanvMain->GetCanvas()->GetListOfPrimitives()->GetEntries(); i++) {
1729          if (strcmp(fCanvMain->GetCanvas()->GetListOfPrimitives()->At(i)->ClassName(), "TFrame") != 0)
1730             fCanvMain->GetCanvas()->GetListOfPrimitives()->At(i)->Delete();
1731       }
1732    //fCanvMain->GetCanvas()->Clear();
1733    fCanvMain->GetCanvas()->cd();
1734    Int_t entries = -1;
1735    // draw finally
1736    if (fRadio1D->GetState() == kButtonDown){
1737       // 1D-Drawing
1738       TString strSigmaMax(fTxtSigmaMax->GetText());  // get sigmaMax from text enty
1739       Double_t sigmaMax = (strSigmaMax.IsFloat()) ? strSigmaMax.Atof() : 5; // convert to double, if not convertable, set to 5
1740       Bool_t plotMean   = fChkMean->GetState() == kButtonDown;
1741       Bool_t plotMedian = fChkMedian->GetState() == kButtonDown;
1742       Bool_t plotLTM    = fChkLTM->GetState() == kButtonDown;
1743       if (fRadioNorm->GetState() == kButtonDown)  // normal 1D drawing
1744          entries = fViewer->EasyDraw1D(desiredData.Data(), sectorStr.Data(), cutsStr.Data(), addDrawOpt.Data());
1745       if (fRadioSigma->GetState() == kButtonDown) // sigma 1D drawing
1746          entries = fViewer->DrawHisto1D(desiredData.Data(), sectorStr.Data(), cutsStr.Data(), // 
1747             fTxtSigmas->GetText(), plotMean, plotMedian, plotLTM);
1748       if (fRadioCumulative->GetState() == kButtonDown)  // cumulative 1D drawing
1749          entries = fViewer->SigmaCut(desiredData.Data(), sectorStr.Data(), cutsStr.Data(), //
1750             sigmaMax, plotMean, plotMedian, plotLTM, // 
1751             fCheckCumulativePM->GetState() == kButtonDown, fTxtSigmas->GetText(), /* Float_t sigmaStep =*/ -1);
1752       if (fRadioIntegrate->GetState() == kButtonDown)  // integral 1D drawing  
1753          entries = fViewer->Integrate(desiredData.Data(), sectorStr.Data(), cutsStr.Data(), //
1754             sigmaMax, plotMean, plotMedian, plotLTM, // 
1755             fTxtSigmas->GetText(), /* Float_t sigmaStep =*/ -1);            
1756    }
1757    else if (fRadio2D->GetState() == kButtonDown) {
1758       // 2D-Drawing
1759       entries = fViewer->EasyDraw(desiredData.Data(), sectorStr.Data(), cutsStr.Data(), addDrawOpt.Data());
1760    }
1761    if (entries == -1) return; // nothing was drawn, there is no histogram to get min and max
1762    
1763    SetMinMaxLabel();
1764    fCanvMain->GetCanvas()->Update();
1765 }
1766
1767
1768 void AliTPCCalibViewerGUI::DoFit() {
1769    //
1770    // main method for fitting
1771    //
1772    
1773    Double_t chi2 = 0;
1774    TVectorD fitParam(0);
1775    TMatrixD covMatrix(0,0);
1776    TString cutStr("");
1777    TString formulaStr("");
1778    TString *returnStr = new TString("");
1779
1780    // specify data to plot:
1781    TString drawStr(GetDrawString()->Data());
1782    
1783    // ********** create cut string **********
1784    if (fRadioTPC->GetState() == kButtonDown)
1785       cutStr += ""; // whole TPC is used for fitting
1786    if (fRadioSideA->GetState() == kButtonDown)
1787       cutStr += "(sector/18)%2==0"; // side A
1788    if (fRadioSideC->GetState() == kButtonDown)
1789       cutStr+= "(sector/18)%2==1"; // side C
1790    if (fRadioROC->GetState() == kButtonDown) {
1791       Int_t sector = (Int_t)(fNmbSector->GetNumber());
1792       cutStr += "sector==";
1793       cutStr += sector; 
1794    }
1795    if (fRadioSector->GetState() == kButtonDown) {
1796       Int_t sector = (Int_t)(fNmbSector->GetNumber())%36;
1797       cutStr += "sector%36==";
1798       cutStr += sector; 
1799    }
1800    if (fChkAddCuts->GetState() == kButtonDown && strcmp(fComboAddCuts->GetTextEntry()->GetText(), "") != 0){
1801       if (fRadioTPC->GetState() != kButtonDown) cutStr += " && ";
1802       cutStr += fComboAddCuts->GetTextEntry()->GetText();  
1803    }
1804    // try to add forgotten '~'
1805    if (fChkAutoAppend->GetState() == kButtonDown) 
1806       cutStr = TString(fViewer->AddAbbreviations((char*)cutStr.Data()));
1807    
1808    // ********** get formula string **********
1809    formulaStr += fComboCustomFit->GetTextEntry()->GetText();
1810    if (fChkAutoAppend->GetState() == kButtonDown) 
1811       formulaStr = TString(fViewer->AddAbbreviations((char*)formulaStr.Data()));
1812
1813    // ********** call AliTPCCalibViewer's fit-function
1814   ReplacePlaceHolders(drawStr);
1815   ReplacePlaceHolders(cutStr);
1816   returnStr = fViewer->Fit(drawStr.Data(), formulaStr.Data(), cutStr.Data(), chi2, fitParam, covMatrix);
1817    
1818    std::cout << std::endl;
1819    std::cout << "Your fit formula reads as follows:" << std::endl;
1820    std::cout << returnStr->Data() << std::endl;
1821    std::cout << "chi2 = " << chi2 << std::endl;
1822 }
1823
1824
1825 void AliTPCCalibViewerGUI::DoExport() {
1826    //
1827    // function to export a CalPad to Cint
1828    //
1829    if ( fRadio2D->GetState() != kButtonDown){
1830       Error("ExportCalPad", "Export of AliTPCCalPad to CINT works only in 2D mode.");
1831       return;
1832    }
1833    // specify data to plot:
1834    TString desiredData(GetDrawString()->Data());
1835    // specify cuts:
1836    TString cutsStr(GetCutString()->Data());
1837    // get name for the calPad   
1838    const char* calPadName = fComboExportName->GetTextEntry()->GetText();
1839    // create calPad according to drawCommand and cuts
1840    AliTPCCalPad *calPad = fViewer->GetCalPad(desiredData.Data(), (char*)cutsStr.Data(), (char*)calPadName);
1841    // finally export calPad to Cint:
1842    gROOT->ProcessLine(Form("AliTPCCalPad* %s = (AliTPCCalPad*)0x%lx;", calPadName, calPad));
1843    fPreprocessor->AddComponent(calPad);
1844    Info("ExportCalPad", "Current 2D view has been exported to an AliTPCCalPad* with name '%s'", calPadName);
1845 }
1846
1847
1848 void AliTPCCalibViewerGUI::DoExportNorm() {
1849    //
1850    // function to export a CalPad to Cint
1851    //
1852    
1853    if ( fRadio2D->GetState() != kButtonDown){
1854       Error("ExportCalPad", "Adding an AliTPCCalPad to the normalization works only in 2D mode.");
1855       return;
1856    }
1857    
1858    Error("DoExportNorm", "Not yet implemented.");
1859    return;
1860    
1861    // specify data to plot:
1862    TString desiredData(GetDrawString()->Data());
1863    // specify sector:
1864    TString sectorStr(GetSectorString()->Data());
1865    // specify cuts:
1866    TString cutsStr(GetCutString()->Data());
1867    
1868    // get name for the calPad   
1869    const char* calPadName = fComboExportName->GetTextEntry()->GetText();
1870    // create calPad according to drawCommand and cuts
1871    AliTPCCalPad *calPad = fViewer->GetCalPad(desiredData.Data(), (char*)cutsStr.Data(), (char*)fComboExportName->GetTextEntry()->GetText());
1872    // finally export calPad to Cint:
1873    gROOT->ProcessLine(Form("AliTPCCalPad* %s = (AliTPCCalPad*)0x%lx;", calPadName, calPad));
1874    Info("ExportCalPad", "Current 2D view has been exported to an AliTPCCalPad* with name '%s'", calPadName);
1875 }
1876
1877
1878 void AliTPCCalibViewerGUI::GetMinMax() {
1879    //
1880    // Read current Min & Max from the plot and set it to fTxtSetMin & fTxtSetMax
1881    //
1882    if (fChkGetMinMaxAuto->GetState() == kButtonUp) return;
1883    TList* listOfPrimitives = fCanvMain->GetCanvas()->GetListOfPrimitives();
1884    TObject* ptr = 0;
1885    for (Int_t i = 0; i < listOfPrimitives->GetEntries(); i++) {
1886       ptr = listOfPrimitives->At(i);
1887       if ( ptr->InheritsFrom("TH1") ) break;
1888    }
1889    if ( ptr != 0 && !ptr->InheritsFrom("TH1") ) return;      // if the loop did not find a TH1
1890    TH1 *hist = (TH1*)ptr;
1891
1892 //    Double_t histMax = hist->GetMaximum();
1893 //    Double_t histMin = hist->GetMinimum();
1894 //    fTxtSetMax->SetText(Form("%f",histMax));
1895 //    fTxtSetMin->SetText(Form("%f",histMin));
1896
1897    if (fRadio2D->GetState() == kButtonDown) {
1898       if (fChkSetMax->GetState() == kButtonUp)
1899          fTxtSetMax->SetText(Form("%f", hist->GetMaximum()));
1900       if (fChkSetMin->GetState() == kButtonUp)
1901          fTxtSetMin->SetText(Form("%f", hist->GetMinimum()));
1902    }
1903    else if (fRadio1D->GetState() == kButtonDown) {
1904       if (fChkSetMax->GetState() == kButtonUp)
1905          fTxtSetMax->SetText( Form("%f", hist->GetXaxis()->GetXmax()) );
1906       if (fChkSetMin->GetState() == kButtonUp)
1907          fTxtSetMin->SetText( Form("%f", hist->GetXaxis()->GetXmin()) );
1908    }
1909 }
1910
1911
1912 void AliTPCCalibViewerGUI::SetMinMaxLabel() {
1913    // 
1914    // Set Minimum, Maximum and labels without redrawing the plot
1915    // (faster)
1916    // 
1917    
1918    // search for histogram
1919    TList* listOfPrimitives = fCanvMain->GetCanvas()->GetListOfPrimitives();
1920    TObject* ptr = 0;
1921    for (Int_t i = 0; i < listOfPrimitives->GetEntries(); i++) {
1922       ptr = listOfPrimitives->At(i);
1923       if ( ptr->InheritsFrom("TH1") ) break;
1924    }
1925    if ( ptr == 0 || !ptr->InheritsFrom("TH1") ) {  // if the loop did not find a TH1
1926       fCanvMain->GetCanvas()->Update();
1927       Warning("SetMinMaxLabel","No Histogram found!");
1928       return;
1929       // unable to find histogram, no min and max wil be read out
1930    }
1931    
1932    TH1 *hist = (TH1*)ptr; 
1933    TString minTxt(fTxtSetMin->GetText());
1934    TString maxTxt(fTxtSetMax->GetText());
1935    
1936    // set min and max according to specified values, if checkbox is checked
1937    if (fRadio2D->GetState() == kButtonDown) {
1938       if (fChkSetMax->GetState() == kButtonDown && fChkSetMax->GetState() == kButtonDown &&(maxTxt.IsDigit() || maxTxt.IsFloat()) )
1939          hist->SetMaximum(maxTxt.Atof());
1940       if (fChkSetMax->GetState() == kButtonUp)
1941          hist->SetMaximum(-1111);  // default value, to unzoom
1942       if (fChkSetMin->GetState() == kButtonDown && (minTxt.IsDigit() || minTxt.IsFloat()) )
1943          hist->SetMinimum(minTxt.Atof());
1944       if (fChkSetMin->GetState() == kButtonUp)
1945          hist->SetMinimum(-1111);  // default value, to unzoom
1946    }
1947    else if (fRadio2D->GetState() == kButtonDown) {
1948       if (fChkSetMin->GetState() == kButtonDown && 
1949           fChkSetMax->GetState() == kButtonDown && hist->GetXaxis())
1950          hist->GetXaxis()->SetRangeUser(hist->GetXaxis()->GetXmin(), hist->GetXaxis()->GetXmax());
1951       else if (fChkSetMax->GetState() == kButtonDown && hist->GetXaxis())
1952          hist->GetXaxis()->SetRangeUser(hist->GetXaxis()->GetXmin(), maxTxt.Atof());
1953       else if (fChkSetMin->GetState() == kButtonDown && hist->GetXaxis())
1954          hist->GetXaxis()->SetRangeUser(minTxt.Atof(), hist->GetXaxis()->GetXmax());
1955       hist->SetTitle(hist->GetTitle());  // trick to update the histogram
1956    }
1957    
1958    // get min and max from plot       
1959    GetMinMax();
1960    
1961    // set labels according to specification, if cehckboxes are checked
1962    if (fChkLabelTitle->GetState() == kButtonDown) 
1963       hist->SetTitle(fTxtLabelTitle->GetText());
1964    if (fChkLabelXaxis->GetState() == kButtonDown)
1965       hist->GetXaxis()->SetTitle(fTxtLabelXaxis->GetText());
1966    if (fChkLabelYaxis->GetState() == kButtonDown)
1967       hist->GetYaxis()->SetTitle(fTxtLabelYaxis->GetText());
1968    // get and/or set labels and title
1969    if (fChkLabelGetAuto->GetState() == kButtonDown) {
1970       fTxtLabelTitle->SetText(hist->GetTitle());
1971       fTxtLabelXaxis->SetTitle(hist->GetXaxis()->GetTitle());
1972       fTxtLabelYaxis->SetTitle(hist->GetYaxis()->GetTitle());
1973    }
1974    hist->SetTitle(hist->GetTitle());  // trick to update the histogram
1975    fCanvMain->GetCanvas()->Update();
1976 }
1977    
1978    
1979 void AliTPCCalibViewerGUI::ChangeSector(){
1980    // 
1981    // function that is called, when the number of the sector is changed
1982    // to change the sector label
1983    //
1984    if ( fRadioROC->GetState()!=kButtonDown && fRadioSector->GetState()!=kButtonDown ){
1985        fLblSector->SetText("not used");
1986        return;
1987    }
1988
1989    Int_t sector = (Int_t)(fNmbSector->GetNumber());
1990    TString secLabel = "";
1991    if ( sector < 36 )
1992        secLabel = "IROC";
1993    else
1994        secLabel = "OROC";
1995
1996    if (fRadioSector->GetState()==kButtonDown)
1997        secLabel="Sector";
1998
1999    if ( sector%36<18 ) //A-Side
2000        secLabel += ", A";
2001    else
2002        secLabel += ", C";
2003
2004    secLabel += Form("%02d",sector%18);
2005
2006    fLblSector->SetText(secLabel);
2007    DoNewSelection();
2008 }
2009
2010
2011 void AliTPCCalibViewerGUI::AddFitFunction() const { 
2012    //
2013    // adds the last fit function to the normalization list
2014    // 
2015    std::cout << "Not yet implemented." << std::endl;
2016 }
2017
2018
2019 void AliTPCCalibViewerGUI::UnchekAllStat() {
2020    // 
2021    // Disable all statistical legend entries, no statistical legend.
2022    // 
2023    fChkStatName->SetState(kButtonUp);
2024    fChkStatEntries->SetState(kButtonUp);
2025    fChkStatMean->SetState(kButtonUp);
2026    fChkStatMeanPM->SetState(kButtonUp);
2027    fChkStatRMS->SetState(kButtonUp);
2028    fChkStatRMSPM->SetState(kButtonUp);
2029    fChkStatUnderflow->SetState(kButtonUp);
2030    fChkStatOverflow->SetState(kButtonUp);
2031    fChkStatIntegral->SetState(kButtonUp);
2032    fChkStatSkewness->SetState(kButtonUp);
2033    fChkStatSkewnessPM->SetState(kButtonUp);
2034    fChkStatKurtosis->SetState(kButtonUp);
2035    fChkStatKurtosisPM->SetState(kButtonUp);
2036    
2037    HandleButtonsStat(0);
2038 }
2039
2040
2041 void AliTPCCalibViewerGUI::MouseMove(Int_t event, Int_t x, Int_t y, TObject *selectedObject) { 
2042    //
2043    // mouse move
2044    // zoom to sector works ONLY in 2D mode, if one side is specified
2045    // 
2046    Double_t pi = TMath::Pi();
2047    if (event != kButton1Double )
2048       return;
2049    if (!selectedObject->InheritsFrom("TH2")) return;
2050    // zoom to sector works ONLY in 2D mode, if one side is specified
2051    if (fRadio2D->GetState() == kButtonUp) return;
2052    if (fRadioROC->GetState() == kButtonDown) { // return to full side view
2053       // return to full side view
2054       Int_t sector = (Int_t)(fNmbSector->GetNumber());
2055       if ( (sector >= 0 && sector <= 17) || (sector >= 36 &&  sector <= 53) ) {
2056          // A-Side
2057          fRadioSideA->Clicked();
2058          fRadioSideA->SetState(kButtonDown);
2059          DoNewSelection();
2060       }
2061       if ( (sector >= 18 && sector <= 35) || (sector >= 54 &&  sector <= 71) ) {
2062          // C-Side
2063          fRadioSideC->Clicked();
2064          fRadioSideC->SetState(kButtonDown);
2065          DoNewSelection();
2066       }
2067       return;
2068    }
2069    if (!(fRadioSideA->GetState() == kButtonDown || fRadioSideC->GetState() == kButtonDown)) return;
2070    
2071    // Int_t    px        = gPad->GetEventX();
2072    // Int_t    py        = gPad->GetEventY();
2073    Float_t  upy       = gPad->AbsPixeltoY(y);
2074    Float_t  upx       = gPad->AbsPixeltoX(x);
2075    Float_t  gy         = gPad->PadtoY(upy);
2076    Float_t  gx         = gPad->PadtoX(upx);
2077    Int_t quadrant = -1;
2078    if (gx >= 0 && gy >= 0) quadrant = 1;
2079    if (gx <  0 && gy >= 0) quadrant = 2;
2080    if (gx <  0 && gy <  0) quadrant = 3;
2081    if (gx >= 0 && gy <  0) quadrant = 4;
2082    gx = TMath::Abs(gx);
2083    gy = TMath::Abs(gy);
2084    Double_t phi = TMath::ATan(gy/gx);        // angle phi is in Pi- units
2085    Double_t r   = TMath::Sqrt(gx*gx + gy*gy);
2086    if (quadrant == 2) phi = pi - phi;
2087    if (quadrant == 3) phi = pi + phi;
2088    if (quadrant == 4) phi = 2 * pi - phi;
2089    Double_t phiGrad = phi / pi * 180;
2090    Int_t sector = (Int_t) phiGrad / 20;  // one sector coresponds to 20�
2091    // IROC starts at 84.5 cm
2092    // IROC ends at 135.5 cm, OROC begins
2093    // OROC ends at 250 cm
2094    if (r < 84.5 || r > 250) return; // outside TPC
2095    if (r < 135.5) { // IROC 
2096       if (fRadioSideC->GetState() == kButtonDown) sector += 18;
2097    }
2098    else {// OROC
2099       sector += 36;
2100       if (fRadioSideC->GetState() == kButtonDown) sector += 18;
2101    }
2102    // printf("r: %f, phi: %f, phiGrad: %f, gy/gx: %f, quadrant: %i, sector: %i \n", r, phi, phiGrad, gy/gx, quadrant, sector);
2103    fNmbSector->SetNumber(sector);
2104    fRadioROC->Clicked();
2105    fRadioROC->SetState(kButtonDown);
2106    ChangeSector();   
2107 }
2108
2109
2110 void AliTPCCalibViewerGUI::SavePicture() {
2111    // 
2112    // saves the current picture
2113    // 
2114    // use the following combination of file type and save options:
2115    // (see also TCanvas::Print)
2116    // 
2117    //       "ps"  - Postscript file is produced (see special cases below)
2118    //    "Portrait" - Postscript file is produced (Portrait)
2119    // "Landscape" - Postscript file is produced (Landscape)
2120    //       "eps" - an Encapsulated Postscript file is produced
2121    //    "Preview" - an Encapsulated Postscript file with preview is produced.
2122    //       "pdf" - a PDF file is produced
2123    //       "svg" - a SVG file is produced
2124    //       "gif" - a GIF file is produced
2125    //       "gif+NN" - an animated GIF file is produced, where NN is delay in 10ms units
2126    //       "xpm" - a XPM file is produced
2127    //       "png" - a PNG file is produced
2128    //       "jpg" - a JPEG file is produced
2129    //       "tiff" - a TIFF file is produced
2130    //       "cxx" - a C++ macro file is produced
2131    //       "xml" - a XML file
2132    //       "root" - a ROOT binary file
2133    
2134    const char *kSaveAsTypes[] = {
2135       "Postscript",  "*.ps",
2136       "Encapsulated Postscript",   "*.eps",
2137       "PDF",   "*.pdf",
2138       "JPEG",   "*.jpg",
2139       "PNG",   "*.png",
2140       "TIFF",   "*.tiff",
2141       "GIF",   "*.gif",
2142       "XPM",   "*.xpm",
2143       "SVG",   "*.svg",
2144       "XML",   "*.xml",
2145       "C++ macro",   "*.cxx",
2146       "Macro file",  "*.C",
2147       "ROOT file",   "*.root",
2148       "All file",    "*",
2149        0,              0
2150    };
2151    TString addSaveOpt("");
2152    if (fChkAddSaveOpt->GetState() == kButtonDown)
2153    addSaveOpt += fComboAddSaveOpt->GetTextEntry()->GetText();
2154    TString dir(".");
2155    TGFileInfo fi;
2156    fi.fFileTypes = kSaveAsTypes;
2157    // fi.fIniDir    = StrDup(dir);
2158    fi.fOverwrite = kFALSE;
2159    new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDSave, &fi);
2160    if (fi.fFilename && strlen(fi.fFilename)) {
2161       if (addSaveOpt != "")
2162          fCanvMain->GetCanvas()->Print(fi.fFilename, addSaveOpt.Data());
2163       else 
2164          fCanvMain->GetCanvas()->Print(fi.fFilename);
2165    }
2166
2167 // TList*       fFileNamesList  list of selected file names
2168 // Int_t        fFileTypeIdx    selected file type, index in fFileTypes
2169 // const char** fFileTypes      file types used to filter selectable files
2170 // char*        fFilename       selected file name
2171 // char*        fIniDir on input: initial directory, on output: new directory
2172 // Bool_t       fMultipleSelection      if true, allow multiple file selection
2173 // Bool_t       fOverwrite      if true overwrite the file with existing name on save
2174    
2175 }
2176    
2177
2178 void AliTPCCalibViewerGUI::DoDumpToFile() {
2179    // 
2180    // This function is called, when the "Dump to File" button is pressed. 
2181    // All the exported CalPads will be written into an new CalibTree, 
2182    // a Save File dialog will appear to specify the filename
2183    // 
2184    const char *kSaveAsTypes[] = {
2185       "ROOT file",   "*.root",
2186        0,              0
2187    };
2188    TString dir(".");
2189    TGFileInfo fi;
2190    fi.fFileTypes = kSaveAsTypes;
2191    // fi.fIniDir    = StrDup(dir);
2192    fi.fOverwrite = kFALSE;
2193    new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDSave, &fi);
2194    if (fi.fFilename && strlen(fi.fFilename)) {
2195       fPreprocessor->DumpToFile(fi.fFilename);
2196       Info("DumpToFile", Form("New CalibTree has been writen to file '%s'", fi.fFilename));
2197    }
2198 }
2199
2200
2201 void AliTPCCalibViewerGUI::DoLoadTree() {
2202    // function to load a new calib tree
2203    // 
2204    // 
2205    const char *kFileTypes[] = {
2206       "ROOT file",   "*.root",
2207        0,              0
2208    };
2209    TString dir(".");
2210    TGFileInfo fi;
2211    fi.fFileTypes = kFileTypes;
2212    // fi.fIniDir    = StrDup(dir);
2213    fi.fOverwrite = kFALSE;
2214    new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDOpen, &fi);
2215    if (fi.fFilename && strlen(fi.fFilename) && fChkAddAsReference->GetState() == kButtonUp) {
2216       Initialize(fi.fFilename);
2217       Reload();
2218    }
2219    else if (fi.fFilename && strlen(fi.fFilename) && fChkAddAsReference->GetState() == kButtonDown) {
2220       fViewer->AddReferenceTree(fi.fFilename, "calPads", fTxtRefName->GetText());
2221       Reload();
2222    }
2223 }
2224
2225
2226 TObjArray* AliTPCCalibViewerGUI::ShowGUI(const char* fileName) {
2227    //
2228    // Initialize and show GUI for presentation for demonstration purposes
2229    // or for fast standalone use
2230    // 
2231    TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
2232    frmMain->SetWindowName("AliTPCCalibViewer GUI");
2233    frmMain->SetCleanup(kDeepCleanup);
2234    
2235    TGTab* tabMain = new TGTab(frmMain, 1000, 600);
2236    frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
2237
2238    TGCompositeFrame* tabCont1 = tabMain->AddTab("Viewer 1");
2239    TGCompositeFrame* tabCont2 = tabMain->AddTab("Viewer 2");
2240    
2241    AliTPCCalibViewerGUI* calibViewer1 = new AliTPCCalibViewerGUI(tabCont1, 1000, 600, (char*)fileName);
2242    tabCont1->AddFrame(calibViewer1, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
2243
2244    AliTPCCalibViewerGUI* calibViewer2 = new AliTPCCalibViewerGUI(tabCont2, 1000, 600, (char*)fileName);
2245    tabCont2->AddFrame(calibViewer2, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
2246    
2247    TObjArray *guiArray = new TObjArray();
2248    guiArray->Add(calibViewer1);
2249    guiArray->Add(calibViewer2);
2250    
2251    frmMain->MapSubwindows();
2252    frmMain->Resize();
2253    frmMain->MapWindow();
2254    
2255    return guiArray;
2256 }
2257