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