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