Added script to extract MC corrections from forward_mccorr.root
[u/mrichter/AliRoot.git] / TPC / AliTPCCalibViewerGUItime.cxx
CommitLineData
5312f439 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// //
20///////////////////////////////////////////////////////////////////////////////
21
6e7d7dc4 22
5312f439 23#include <iostream>
24//Root includes
25#include <TROOT.h>
26#include <TDirectory.h>
27#include <TStyle.h>
28#include <TCanvas.h>
29#include <TPad.h>
30#include <TVirtualPad.h>
31#include <TObject.h>
32#include <TObjArray.h>
33#include <TObjString.h>
6fb51ca4 34#include <TSystem.h>
5312f439 35#include <TVector.h>
36#include <TH1.h>
37#include <TCut.h>
38#include <TFile.h>
39#include <TTree.h>
e6970ab5 40#include <TChain.h>
5312f439 41#include <TBranch.h>
42#include <TIterator.h>
43#include <TGraph.h>
44#include <TAxis.h>
45#include <TTimeStamp.h>
46#include <TMath.h>
7390f655 47#include <TMap.h>
5312f439 48//
49#include <TGFileDialog.h>
50#include <TGInputDialog.h>
51//
52#include <TGButton.h>
53#include <TGListBox.h>
54#include <TGComboBox.h>
55#include <TGNumberEntry.h>
56#include <TGLayout.h>
57#include <TRootEmbeddedCanvas.h>
58#include <TGSplitter.h>
59#include <TGButtonGroup.h>
60#include <TGLabel.h>
61#include <TGTab.h>
62#include <TGString.h>
63
64//AliRoot includes
6fb51ca4 65#include <AliLog.h>
5312f439 66#include "AliTPCCalibViewerGUI.h"
7390f655 67#include "AliTPCCalibViewer.h"
5312f439 68#include "AliTPCcalibDB.h"
949d8707 69#include "AliTPCcalibDButil.h"
6fb51ca4 70#include "AliTPCConfigParser.h"
5312f439 71
72#include "AliTPCCalibViewerGUItime.h"
73
74ClassImp(AliTPCCalibViewerGUItime)
75
76AliTPCCalibViewerGUItime::AliTPCCalibViewerGUItime(const TGWindow *p, UInt_t w, UInt_t h) :
77TGCompositeFrame(p,w,h),
78 fFile(0x0),
79 fTree(0x0),
80 fCalibViewerGUI(0x0),
81 fCalibViewerGUItab(0x0),
82 fCurrentHist(0x0),
83 fCurrentGraph(0x0),
84 fCurrentRunDetails(-1),
85 fOutputCacheDir("/tmp"),
86 fDrawString(""),
6e7d7dc4 87 fConfigFile(""),
88 fConfigParser(new AliTPCConfigParser),
5312f439 89 fIsCustomDraw(kFALSE),
90 fRunNumbers(10),
91 fTimeStamps(10),
92 fValuesX(10),
93 fValuesY(10),
6e7d7dc4 94 fNoGraph(kFALSE),
95 fGraphLimitEntries(10000),
7390f655 96 fMapRefTrees(new TMap),
5312f439 97 //GUI elements
98 //main canvas Top part, bottom part
99 fContTopBottom(0x0),
100 //top left, centre, right
101 fContLCR(0x0),
102 //content left
103 fContLeft(0x0),
6e7d7dc4 104 fContDrawOpt(0x0),
105 fChkDrawOptSame(0x0),
106 fComboAddDrawOpt(0x0),
5312f439 107 fContDrawSel(0x0),
108 fContDrawSelSubRunTime(0x0),
109 fRadioXhist(0x0),
110 fRadioXrun(0x0),
111 fRadioXtime(0x0),
112 fListVariables(0x0),
113 fComboRunType(0x0),
114 fLblRunType(0x0),
115 fNmbPar(0x0),
116 fLblPar(0x0),
6fb51ca4 117 fListCalibType(0x0),
118 fContCalibType(0x0),
5312f439 119 //content centre
120 fContCenter(0x0),
121 fCanvMain(0x0),
122 //content right
123 fContRight(0x0),
124 fContValues(0x0),
125 fLblRunNumber(0x0),
126 fLblRunTime(0x0),
127 fLblValueX(0x0),
128 fLblValueY(0x0),
129 fLblRunNumberVal(0x0),
130 fLblRunTimeVal(0x0),
131 fLblValueXVal(0x0),
132 fLblValueYVal(0x0),
133 fBtnDumpRuns(0x0),
514fcaf7 134 fContAliases(0x0),
135 fListAliases(0x0),
5312f439 136 //content bottom
137 fContCustom(0x0),
138 fContCustomCuts(0x0),
139 fLblCustomDraw(0x0),
140 fLblCustomCuts(0x0),
141 fComboCustomDraw(0x0),
6e7d7dc4 142 fComboCustomCuts(0x0),
143 fTrashBox(new TObjArray)
5312f439 144{
145 //
146 // ctor
147 //
7390f655 148 fMapRefTrees->SetOwnerKeyValue();
149 fTrashBox->SetOwner();
5312f439 150 DrawGUI(p,w,h);
6e7d7dc4 151 gStyle->SetMarkerStyle(20);
152 gStyle->SetMarkerSize(0.5);
5312f439 153 SetInitialValues();
154}
155//______________________________________________________________________________
156AliTPCCalibViewerGUItime::~AliTPCCalibViewerGUItime(){
157 //
158 // dtor
159 //
6e7d7dc4 160 delete fConfigParser;
161 delete fTrashBox;
7390f655 162 delete fMapRefTrees;
5312f439 163}
164//______________________________________________________________________________
6fb51ca4 165void AliTPCCalibViewerGUItime::DrawGUI(const TGWindow */*p*/, UInt_t w, UInt_t h) {
5312f439 166 //
167 // draw the GUI
168 //
169 // ======================================================================
170 // ************************* Display everything *************************
171 // ======================================================================
172
173 SetCleanup(kDeepCleanup);
5312f439 174
175 // *****************************************************************************
176 // ************************* content of this MainFrame *************************
177 // *****************************************************************************
178 // top level container with horizontal layout
179 fContTopBottom = new TGCompositeFrame(this, w, h, kVerticalFrame | kFixedWidth | kFixedHeight);
180 AddFrame(fContTopBottom, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
181
182 fContLCR = new TGCompositeFrame(fContTopBottom, w, h, kHorizontalFrame | kFixedWidth | kFixedHeight);
183 fContTopBottom->AddFrame(fContLCR, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
184
185 // ***********************************************************************
186 // ************************* content of fContLCR *************************
187 // ***********************************************************************
188 // left container
189 fContLeft = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
190 fContLCR->AddFrame(fContLeft, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 5, 3, 3, 3));
191
192 // left vertical splitter
193 TGVSplitter *splitLeft = new TGVSplitter(fContLCR);
194 splitLeft->SetFrame(fContLeft, kTRUE);
195 fContLCR->AddFrame(splitLeft, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
196
197 // right container
198 fContRight = new TGCompositeFrame(fContLCR, 150, 200, kVerticalFrame | kFixedWidth | kFitHeight);
199 fContLCR->AddFrame(fContRight, new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandY, 3, 5, 3, 3));
200
201 // center container
202 fContCenter = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
203 fContLCR->AddFrame(fContCenter, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
204
205 // right vertical splitter
206 TGVSplitter *splitRight = new TGVSplitter(fContLCR);
207 splitRight->SetFrame(fContRight, kFALSE);
208 fContLCR->AddFrame(splitRight, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
209
210
211 // ========================================================================
212 // ************************* content of fContLeft *************************
213 // ========================================================================
214 // --- draw button and tabLeft ---
6e7d7dc4 215 // draw options
216 fContDrawOpt = new TGGroupFrame(fContLeft, "Draw options", kVerticalFrame | kFitWidth | kFitHeight);
217 fContLeft->AddFrame(fContDrawOpt, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
218 fChkDrawOptSame = new TGCheckButton(fContDrawOpt, "Same");
219 fContDrawOpt->AddFrame(fChkDrawOptSame, new TGLayoutHints(kLHintsNormal, 0, 2, 0, 0));
220 fChkDrawOptSame->SetToolTipText("Add draw option 'same'");
221 // additional draw options combo box
222 fComboAddDrawOpt = new TGComboBox(fContDrawOpt);
223 fComboAddDrawOpt->Resize(0, 22);
224 fComboAddDrawOpt->EnableTextInput(kTRUE);
225 fContDrawOpt->AddFrame(fComboAddDrawOpt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
226// fComboAddDrawOpt->Connect("ReturnPressed()", "AliTPCCalibViewerGUI", this, "HandleButtonsGeneral(=14)");
227// fComboAddDrawOpt->Connect("Selected(Int_t)", "AliTPCCalibViewerGUI", this, "DoNewSelection()");
bf05fdb7 228 fComboAddDrawOpt->GetTextEntry()->SetText("",kFALSE);
6e7d7dc4 229
5312f439 230 // draw selection group
231 fContDrawSel = new TGGroupFrame(fContLeft, "Draw selection", kVerticalFrame | kFitWidth | kFitHeight);
232 fContLeft->AddFrame(fContDrawSel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 10, 0));
233 //x-axis variables selection, Run of Time
234 fContDrawSelSubRunTime = new TGCompositeFrame(fContDrawSel, 200, 23, kHorizontalFrame | kFitWidth | kFixedHeight);
235 fContDrawSel->AddFrame(fContDrawSelSubRunTime, new TGLayoutHints(kLHintsCenterX | kLHintsExpandX , 0, 0, 0, 0));
236
237 // ------------------------- content of fContDrawOpt -------------------------
238 //
239 // Run radio button
240 // Time radio button
241 fRadioXhist = new TGRadioButton(fContDrawSelSubRunTime, "hist", kRadioXhist);
242 fContDrawSelSubRunTime->AddFrame(fRadioXhist, new TGLayoutHints(kLHintsNormal, 0, 2, 0, 0));
243 fRadioXhist->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
244 fRadioXhist->SetToolTipText("Draw the distribution of the variable");
245
246 fRadioXrun = new TGRadioButton(fContDrawSelSubRunTime, ":Run", kRadioXrun);
247 fContDrawSelSubRunTime->AddFrame(fRadioXrun, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
248 fRadioXrun->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
249 fRadioXrun->SetToolTipText("Use run number as x-value");
250
251 // Time radio button
252 fRadioXtime = new TGRadioButton(fContDrawSelSubRunTime, ":Time", kRadioXtime);
253 fContDrawSelSubRunTime->AddFrame(fRadioXtime, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
254 fRadioXtime->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
255 fRadioXtime->SetToolTipText("Use time stamp number as x-value");
256
257
258 // list of variables
259 fListVariables = new TGListBox(fContDrawSel);
260 fContDrawSel->AddFrame(fListVariables, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
261 fListVariables->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoNewSelection()");
262
6fb51ca4 263
264//-------------------- run type selection ------------------------
5312f439 265 // Parameter label
266 fLblRunType = new TGLabel(fContDrawSel, "Run Type:");
267 fLblRunType->SetTextJustify(kTextLeft);
268 fContDrawSel->AddFrame(fLblRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
269
270 fComboRunType = new TGComboBox(fContDrawSel);
271 fComboRunType->EnableTextInput(kFALSE);
272 fContDrawSel->AddFrame(fComboRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
273 fComboRunType->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoDraw()");
274// fComboRunType->SetEnabled(kFALSE);
275 fComboRunType->Resize(0, 22);
276
277 //-------------------- parameter selection ------------------------
278 // Parameter label
279 fLblPar = new TGLabel(fContDrawSel, "Parameter:");
280 fLblPar->SetTextJustify(kTextLeft);
281 fContDrawSel->AddFrame(fLblPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
282
283 fNmbPar = new TGNumberEntry(fContDrawSel, 0, 1, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, 71);
284 fContDrawSel->AddFrame(fNmbPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
285 fNmbPar->Connect("ValueSet(Long_t)", "AliTPCCalibViewerGUItime", this, "DoParLimitChange()");
286 fNmbPar->SetState(kFALSE);
287
6fb51ca4 288 //-------------------- calibration type selection ------------------------
289 // label
290 // draw selection group
291 fContCalibType = new TGGroupFrame(fContLeft, "Calib type selection", kVerticalFrame | kFitWidth | kFitHeight);
292 fContLeft->AddFrame(fContCalibType, new TGLayoutHints(kLHintsExpandX , 0, 0, 10, 0));
293
294 // list of variables
295 fListCalibType = new TGListBox(fContCalibType);
296 fContCalibType->AddFrame(fListCalibType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX , 0, 0, 0, 0));
297 fListCalibType->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoChangeSelectionList()");
298 fListCalibType->Resize(0,88);
299 fListCalibType->SetMultipleSelections();
300
5312f439 301
302 // ==========================================================================
303 // ************************* content of fContCenter *************************
304 // ========================================================================
305 // main drawing canvas
306 fCanvMain = new TRootEmbeddedCanvas("GUItime_Canvas", fContCenter, 200, 200, kFitWidth | kFitHeight);
307 fContCenter->AddFrame(fCanvMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
308 fCanvMain->GetCanvas()->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)", "AliTPCCalibViewerGUItime", this, "MouseMove(Int_t, Int_t, Int_t, TObject*)");
309// fCanvMain->GetCanvas()->Connect("RangeAxisChanged()", "AliTPCCalibViewerGUItime", this, "GetMinMax()");
310 fCanvMain->GetCanvas()->SetToolTipText("The Main_Canvas, here your plots are displayed.");
6fb51ca4 311 fCanvMain->GetCanvas()->SetRightMargin(0.062);
312 fCanvMain->GetCanvas()->SetLeftMargin(0.15);
5312f439 313
314 // =========================================================================
315 // ************************* content of fContRight *************************
316 // ========================================================================
317 //group frame for value information
318 fContValues = new TGGroupFrame(fContRight, "Data point info", kVerticalFrame | kFitWidth | kFitHeight);
319 fContRight->AddFrame(fContValues, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
320 //set layout manager
321 fContValues->SetLayoutManager(new TGMatrixLayout(fContValues, 0, 2, 5));
322 //value information labels
323
324 //run number label
325 fLblRunNumber = new TGLabel(fContValues, "Run:");
326 fLblRunNumber->SetTextJustify(kTextLeft);
327 fContValues->AddFrame(fLblRunNumber, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
328 //run number
909c8c99 329 fLblRunNumberVal = new TGLabel(fContValues, "000000");
5312f439 330 fLblRunNumberVal->SetTextJustify(kTextLeft);
331 fContValues->AddFrame(fLblRunNumberVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
332 //time stamp label
333 fLblRunTime = new TGLabel(fContValues, "Time:");
334 fLblRunTime->SetTextJustify(kTextLeft);
335 fContValues->AddFrame(fLblRunTime, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
336 //run number
337 fLblRunTimeVal = new TGLabel(fContValues, "00.00.0000\n00:00:00");
338 fLblRunTimeVal->SetTextJustify(kTextLeft);
339 fContValues->AddFrame(fLblRunTimeVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
340 //value label x
341 fLblValueX = new TGLabel(fContValues, "x-Value:");
342 fLblValueX->SetTextJustify(kTextLeft);
343 fContValues->AddFrame(fLblValueX, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
344 //value x
892226be 345 fLblValueXVal = new TGLabel(fContValues, "00.000e+00");
5312f439 346 fLblValueXVal->SetTextJustify(kTextRight);
347 fContValues->AddFrame(fLblValueXVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
348 //value label y
349 fLblValueY = new TGLabel(fContValues, "y-Value:");
350 fLblValueY->SetTextJustify(kTextLeft);
351 fContValues->AddFrame(fLblValueY, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
352 //value y
892226be 353 fLblValueYVal = new TGLabel(fContValues, "00.000e+00");
5312f439 354 fLblValueYVal->SetTextJustify(kTextRight);
355 fContValues->AddFrame(fLblValueYVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
356 // draw button
357 fBtnDumpRuns = new TGTextButton(fContRight, "&Dump runs");
6fb51ca4 358 fContRight->AddFrame(fBtnDumpRuns, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
5312f439 359 fBtnDumpRuns->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "DoDumpRuns()");
360 fBtnDumpRuns->SetToolTipText("Press to dump the run numbers of the current selection.");
514fcaf7 361 //group frame for value information
362 fContAliases = new TGGroupFrame(fContRight, "Aliases", kVerticalFrame | kFitWidth | kFitHeight);
363 fContRight->AddFrame(fContAliases, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 10, 0));
364 // list of aliases
365 fListAliases = new TGListBox(fContAliases);
366 fContAliases->AddFrame(fListAliases, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
367 fListAliases->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoNewSelectionAliases()");
368// fListAliases->Resize(0,88);
369 //buttons
370 TGCompositeFrame *frame1 = new TGCompositeFrame(fContAliases, 200, 23, kHorizontalFrame | kFitWidth | kFitHeight);
371 fContAliases->AddFrame(frame1, new TGLayoutHints(kLHintsCenterX | kLHintsExpandX , 0, 0, 0, 0));
372 // add button
373 TGTextButton *btnAdd = new TGTextButton(frame1, "&Add");
374 frame1->AddFrame(btnAdd, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
375 btnAdd->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "DoAddAlias()");
376 btnAdd->SetToolTipText("Press to add an alias.");
377 btnAdd->Resize(0,22);
378 // del button
379 TGTextButton *btnDel = new TGTextButton(frame1, "&Del");
380 frame1->AddFrame(btnDel, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
381 btnDel->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "DoDelAlias()");
382 btnDel->SetToolTipText("Press to delete the selected alias.");
383 btnDel->Resize(0,22);
384 // update button
385 TGTextButton *btnUp = new TGTextButton(frame1, "&Upd");
386 frame1->AddFrame(btnUp, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
387 btnUp->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "UpdateAliasList()");
388 btnUp->SetToolTipText("Press to update the alias list.");
389 btnUp->Resize(0,22);
390
391
5312f439 392
393 // =========================================================================
394 // ****************** bottom content of fContTopBottom *********************
395 // =========================================================================
396
397 // custom options container
398 // --- fComboCustom --- the custom draw line on the very low
399 fContCustom = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
400 fContTopBottom->AddFrame(fContCustom, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
401
402 // ------------------------- content of fContCustom -------------------------
403 fLblCustomDraw = new TGLabel(fContCustom, "Custom draw: ");
404 fLblCustomDraw->SetTextJustify(kTextLeft);
405 fContCustom->AddFrame(fLblCustomDraw, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
406 // text field for custom draw command
407 fComboCustomDraw = new TGComboBox(fContCustom);
408// fComboCustomDraw->Resize(0, fLblValueY->GetDefaultHeight());
409 fComboCustomDraw->Resize(0, 22);
410 fComboCustomDraw->EnableTextInput(kTRUE);
411 fContCustom->AddFrame(fComboCustomDraw, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
412 fComboCustomDraw->Connect("ReturnPressed()", "AliTPCCalibViewerGUItime", this, "DoCustomDraw()");
413 fComboCustomDraw->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoCustomDraw()");
bf05fdb7 414 fComboCustomDraw->GetTextEntry()->SetText("",kFALSE);
5312f439 415
416 // additional cuts container
417 fContCustomCuts = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
418 fContTopBottom->AddFrame(fContCustomCuts, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
419
420 // ------------------------- content of fContCustomCuts -------------------------
421 fLblCustomCuts = new TGLabel(fContCustomCuts, "Custom cuts: ");
422 fLblCustomCuts->SetTextJustify(kTextLeft);
423 fContCustomCuts->AddFrame(fLblCustomCuts, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
424 // combo text field for additional cuts
425 fComboCustomCuts = new TGComboBox(fContCustomCuts);
426// fComboCustomCuts->Resize(0, fLblValueY->GetDefaultHeight());
427 fComboCustomCuts->Resize(0, 22);
428 fComboCustomCuts->EnableTextInput(kTRUE);
429 fContCustomCuts->AddFrame(fComboCustomCuts, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
6fb51ca4 430 fComboCustomCuts->Connect("ReturnPressed()", "AliTPCCalibViewerGUItime", this, "DoCustomCutsDraw()");
431 fComboCustomCuts->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoCustomCutsDraw()");
bf05fdb7 432 fComboCustomCuts->GetTextEntry()->SetText("",kFALSE);
433
5312f439 434 SetWindowName("AliTPCCalibViewer GUI - Time");
435 MapSubwindows();
436 Resize(GetDefaultSize());
437 MapWindow();
438}
439//______________________________________________________________________________
440void AliTPCCalibViewerGUItime::SetInitialValues(){
441 //
442 // Set inital selections of the gui
443 //
444 fRadioXrun->SetState(kButtonDown);
445 fRadioXtime->SetState(kButtonUp);
446}
447
448//______________________________________________________________________________
6e7d7dc4 449void AliTPCCalibViewerGUItime::UseFile(const char* fileName, const char* treeName) {
5312f439 450 //
451 // retrieve tree from file
452 //
5d0d653f 453 TObjArray *arr=0x0;
454 TString file(fileName);
455 if (file.Contains("://")) {
456 if (file.Contains(";")) {
457 arr=file.Tokenize(";");
458 } else {
459 arr=new TObjArray;
460 arr->Add(new TObjString(fileName));
461 }
462 } else {
463 TString s=gSystem->GetFromPipe(Form("ls %s",fileName));
464 arr=s.Tokenize("\n");
465 }
466
467 if (!arr) return;
e6970ab5 468 TIter next(arr);
469 TObject *o=0;
470 if (fTree) delete fTree;
6e7d7dc4 471 fTree=new TChain(treeName);
e6970ab5 472 while ( (o=next()) ){
473 fTree->AddFile(o->GetName());
474 }
5d0d653f 475 arr->SetOwner();
e6970ab5 476 delete arr;
6e7d7dc4 477 if (!CheckChain()) return;
478 UseConfigFile(fConfigFile.Data());
479 Reload();
480
481}
482//______________________________________________________________________________
798017c7 483void AliTPCCalibViewerGUItime::UseChain(TChain *const chain = 0)
6e7d7dc4 484{
485 //
486 //
487 //
488 fTree=chain;
489 if (!CheckChain()) return;
490 //set configuration file
491 UseConfigFile(fConfigFile.Data());
492 Reload();
493}
494//______________________________________________________________________________
495Bool_t AliTPCCalibViewerGUItime::CheckChain()
496{
497 //
498 // check whether cahin has entries
499 // decide whether to draw graphs in 2D
500 //
501 if (!fTree) return kFALSE;
e6970ab5 502 fTree->Lookup();
6e7d7dc4 503 Long64_t entries=fTree->GetEntries();
504 if (entries==0){
e6970ab5 505 AliError("No entries found in chain");
6e7d7dc4 506 return kFALSE;
6fb51ca4 507 }
6e7d7dc4 508 //check whether to draw graphs
509 CheckDrawGraph();
510 return kTRUE;
511}
512//______________________________________________________________________________
513void AliTPCCalibViewerGUItime::UseConfigFile(const char* file)
514{
515 //
516 // Use 'file' as configuration file
517 //
518 fConfigFile=file;
519 fConfigParser->ParseConfigFileTxt(fConfigFile.Data());
520 FillCalibTypes();
5312f439 521}
522//______________________________________________________________________________
6fb51ca4 523void AliTPCCalibViewerGUItime::FillRunTypes()
524{
5312f439 525 //
6fb51ca4 526 //Loop over the tree entries and fill the run types
5312f439 527 //
6fb51ca4 528 if (!fTree) return;
5312f439 529 Int_t id=0;
5312f439 530 fComboRunType->RemoveAll();
531 fComboRunType->AddEntry("ALL",id++);
532 fComboRunType->Select(0,kFALSE);
6e7d7dc4 533 if (!fTree->GetBranch("runType.")) return;
5312f439 534 TObjString *runType=0x0;
535 Int_t nevets=fTree->GetEntries();
5312f439 536 fTree->SetBranchStatus("*",0);
537 fTree->SetBranchStatus("runType.*",1);
e6970ab5 538 fTree->SetBranchAddress("runType.",&runType);
5312f439 539 for (Int_t iev=0;iev<nevets;++iev){
540 fTree->GetEntry(iev);
541 TString type=runType->String();
542 if (!type.IsNull()&&!fComboRunType->FindEntry(type)) fComboRunType->AddEntry(type,id++);
543 }
e6970ab5 544 fTree->ResetBranchAddresses();
5312f439 545 fTree->SetBranchStatus("*",1);
546}
547//______________________________________________________________________________
6fb51ca4 548void AliTPCCalibViewerGUItime::FillCalibTypes()
549{
550 //
551 // loop over configuration and fill calibration types
552 //
6fb51ca4 553 Int_t id=0;
554 fListCalibType->RemoveAll();
555 TObject *o=0x0;
556 fConfigParser->ResetIter();
557 TString type;
558 while ( (o=fConfigParser->NextKey()) ){
559 type=fConfigParser->GetData(o,kCalibType);
560 //remove whitespcaces
561 type.Remove(TString::kBoth,' ');
562 type.Remove(TString::kBoth,'\t');
563 if (type.IsNull()) type="UNSPECIFIED";
564// printf("CalibType: '%s'\n",type.Data());
565 if (!fListCalibType->FindEntry(type.Data())) {
bf05fdb7 566 fListCalibType->AddEntry(type.Data(),id);
6fb51ca4 567 fListCalibType->Select(id++);
568 }
569 }
570 //add type for unspecified calibration type
571 type="UNSPECIFIED";
572 if (!fListCalibType->FindEntry(type.Data())) {
bf05fdb7 573 fListCalibType->AddEntry(type.Data(),id);
6fb51ca4 574 fListCalibType->Select(id++);
575 }
576}
577//______________________________________________________________________________
6e7d7dc4 578void AliTPCCalibViewerGUItime::CheckDrawGraph()
579{
580 //
581 // Check whether to draw graphs in 2D mode based on the number of entries in the chain
582 // GetEstimate() returns the maximum size of the arrays stored in GetV1()...
583 //
584 if (!fTree) return;
585 fNoGraph=kTRUE;
586 if (fTree->GetEntries()<fTree->GetEstimate()) fNoGraph=kFALSE;
587}
588//______________________________________________________________________________
589void AliTPCCalibViewerGUItime::Reload(Int_t first)
590{
6fb51ca4 591 //
592 // reload the gui contents, this is needed after the input tree has changed
593 //
594
595 if ( !fTree ) return;
596 //in case of the first call create run type and calibration type entries
597 if (first){
598 FillRunTypes();
599 FillCalibTypes();
600 }
601 //activate all branches
602 fTree->SetBranchStatus("*",1);
603 //reset variables list
604 fListVariables->RemoveAll();
605 //get selected calibration types
606 TList calibTypes;
607 fListCalibType->GetSelectedEntries(&calibTypes);
608
609 TObjArray *branchList = fTree->GetListOfBranches();
610 if ( !branchList ) return;
611 TIter nextBranch(branchList);
612 Int_t idCount=0,id=0;
613 TObject *objBranch=0;
614 while ( (objBranch=nextBranch()) ){
615 TString branchName(objBranch->GetName());
616 TString branchTitle(objBranch->GetName());
617 if (branchName == "run" || branchName == "time" || branchName == "runType.") continue;
618 Bool_t active=kTRUE;
619 TString calibType="UNSPECIFIED";
620 if (fConfigParser){
621 const TObject *key=(*fConfigParser)(branchName.Data());
622 if (key){
623 //test if branch is active
624 active=fConfigParser->GetValue(branchName.Data(),kBranchOnOff);
625 id=(*fConfigParser)()->IndexOf(key);
892226be 626// branchTitle=fConfigParser->GetData(key,kBranchTitle);
6fb51ca4 627 calibType=fConfigParser->GetData(key,kCalibType);
628 }
629 else{
630 id=1000+idCount;
631 }
632 } else {
633 id=idCount;
634 }
e6970ab5 635 if (calibType.IsNull()) calibType="UNSPECIFIED";
6fb51ca4 636 //check if branch is in selected calibration types
637 //if not, don't show it in the list and deactivate the branch.
638 Bool_t calibActive=kFALSE;
639 TIter nextCalib(&calibTypes);
640 TObject *objCalib=0;
e6970ab5 641 while ( (objCalib=nextCalib()) )
6fb51ca4 642 if (calibType==objCalib->GetTitle()) calibActive=kTRUE;
643 active&=calibActive;
644 if (!active){
645 TString s=branchName;
646 if (branchName.EndsWith(".")) s+="*";
949d8707 647// fTree->SetBranchStatus(s.Data(),0);
6fb51ca4 648 continue;
649 }
1d32f273 650// fListVariables->AddEntry(SubstituteUnderscores(branchTitle.Data()),id);
651 fListVariables->AddEntry(branchTitle.Data(),id);
6fb51ca4 652 ++idCount;
653 }
654 //trick to display modifications
1d32f273 655 fListVariables->Resize(fListVariables->GetWidth()-1, fListVariables->GetHeight());
656 fListVariables->Resize(fListVariables->GetWidth()+1, fListVariables->GetHeight());
6fb51ca4 657}
658//______________________________________________________________________________
7390f655 659void AliTPCCalibViewerGUItime::AddReferenceTree(const char* treeFileName, const char* refName)
660{
661 //
662 // map of reference trees that should always be attached to the CalibViewerGUI
663 //
664 fMapRefTrees->Add(new TObjString(refName), new TObjString(treeFileName));
665
666}
667//______________________________________________________________________________
bf05fdb7 668const TString AliTPCCalibViewerGUItime::GetDrawString(){
5312f439 669 //
670 // create draw string for ttree by combining the user requestsa
671 //
672
673 TString selectedVariable="";
6fb51ca4 674 Int_t id=-1;
675 if (!fListVariables->GetSelectedEntry()) return "";
676 selectedVariable = fListVariables->GetSelectedEntry()->GetTitle();
677 id=fListVariables->GetSelectedEntry()->EntryId();
678// printf("id: %d\n",id);
679 TString branchName=selectedVariable;
a3b590cf 680 if (fConfigParser){
681 const TObject *key=(*fConfigParser)(id);
682 if (key) branchName=(*fConfigParser)(id)->GetName();
683 }
5312f439 684 //treat case of TVector
6fb51ca4 685 if (branchName.EndsWith(".")){
5312f439 686 Int_t par = (Int_t)(fNmbPar->GetNumber());
6fb51ca4 687 branchName.Append(Form("fElements[%d]",par));
5312f439 688 }
689// if (fRadioXrun->GetState()==kButtonDown)
690// selectedVariable.Append(":run");
691// if (fRadioXtime->GetState()==kButtonDown)
692// selectedVariable.Append(":time");
693
bf05fdb7 694 return branchName;
5312f439 695}
696//______________________________________________________________________________
bf05fdb7 697const TString AliTPCCalibViewerGUItime::GetDrawOptionString(){
6e7d7dc4 698 //
699 // get user selected draw options
700 //
701 TString drawOpt;
702 if (fComboAddDrawOpt->GetSelectedEntry()) drawOpt=fComboAddDrawOpt->GetSelectedEntry()->GetTitle();
703 if (fChkDrawOptSame->GetState()==kButtonDown && !drawOpt.Contains("same",TString::kIgnoreCase))
704 drawOpt+="same";
bf05fdb7 705 return drawOpt;
6e7d7dc4 706}
707//______________________________________________________________________________
708void AliTPCCalibViewerGUItime::GetCutString(TString &cutStr){
5312f439 709 //
710 // create cut string
711 //
712 TCut cuts(fComboCustomCuts->GetTextEntry()->GetText());
713 TString runType="";
714 if (fComboRunType->GetSelectedEntry()) runType=fComboRunType->GetSelectedEntry()->GetTitle();
715 if (runType!="ALL"&&!runType.IsNull()) cuts+=Form("runType.String().Data()==\"%s\"",runType.Data());
6e7d7dc4 716 cutStr=cuts.GetTitle();
717}
718//______________________________________________________________________________
93425263 719void AliTPCCalibViewerGUItime::UpdateValueArrays(Bool_t withGraph, const Double_t *xArr)
6e7d7dc4 720{
721 //
722 //
723 //
724 if (!withGraph){
725 fValuesX.ResizeTo(1);
726 fValuesY.ResizeTo(1);
727 fRunNumbers.ResizeTo(1);
728 fTimeStamps.ResizeTo(1);
729 } else {
93425263 730 const Long64_t nrows=fTree->GetSelectedRows();
731 fValuesX.ResizeTo(nrows);
732 fValuesY.ResizeTo(nrows);
733 fRunNumbers.ResizeTo(nrows);
734 fTimeStamps.ResizeTo(nrows);
735 long long *index=new long long[nrows];
736 TMath::Sort(nrows,fTree->GetV2(),index,kFALSE);
737 for (Long64_t i=0; i<nrows; ++i){
738 fValuesX.GetMatrixArray()[i]=xArr[index[i]];
739 fValuesY.GetMatrixArray()[i]=fTree->GetV3()[index[i]];
740 fRunNumbers.GetMatrixArray()[i]=fTree->GetV1()[index[i]];
741 fTimeStamps.GetMatrixArray()[i]=fTree->GetV2()[index[i]];
742 }
743 delete [] index;
6e7d7dc4 744 }
745}
746//______________________________________________________________________________
747void AliTPCCalibViewerGUItime::GetHistogramTitle(TString &title)
748{
749 //
750 // Create string for histogram title
751 //
752
753 title=fDrawString;
754 Int_t pos=title.First(">>");
755 if (pos>0) title=title(0,pos);
1d32f273 756// if (!fIsCustomDraw){
6e7d7dc4 757 if (fRadioXrun->GetState()==kButtonDown){
758 title+=":Run";
759 } else if (fRadioXtime->GetState()==kButtonDown){
760 title+=":Date";
761 }
1d32f273 762// }
6e7d7dc4 763 TString cuts;
764 GetCutString(cuts);
765 TObjArray *arr=title.Tokenize(":");
766 TObject *o=0x0;
767 title+=" {";
768 title+=cuts;
769 title+="}";
770 TIter next(arr,kIterBackward);
771 while ( (o=next()) ){
772 TString varName=o->GetName();
773 title+=";";
774 //substitue variable names with names in configuration file if available
775 if ((*fConfigParser)()->GetEntries()){
776 TString branchName=varName;
777 Int_t par=0;
778 if (branchName.Contains('.')) branchName=branchName(0,branchName.First('.')+1);
779 //chek if a configuration for that branch is available
780 const TObject *oBranch=(*fConfigParser)(branchName.Data());
781 if (oBranch){
782 TString branchTitle=fConfigParser->GetData(oBranch,kBranchTitle);
783 if (!branchTitle.IsNull()){
784 //check for TVectorT type branch
785 //add parameter name if available
786 if (varName.Contains("fElements")){
787 TString parStr=varName(varName.First('[')+1,varName.Length()-varName.First('[')-2);
788 par=parStr.Atoi();
789 branchTitle+=": ";
790 TString yparname=fConfigParser->GetData(oBranch,par+kParamNames);
791 if (!yparname.IsNull()){
792 branchTitle+=yparname;
793 } else {
794 branchTitle+="[";
795 branchTitle+=par;
796 branchTitle+="]";
797 }
798 }
799 }
bf05fdb7 800 varName=branchTitle;
801 SubstituteUnderscores(varName);
6e7d7dc4 802 }
803 }
804 title+=varName;
805 }
806 delete arr;
5312f439 807}
808//______________________________________________________________________________
7390f655 809void AliTPCCalibViewerGUItime::AdjustYRange()
810{
811 //
812 //
813 //
814 TIter nextGraphicObject(fTrashBox);
815 TObject *o=0x0;
816 Float_t min=0,max=0;
817 while ( (o=nextGraphicObject()) ){
818 if (o->IsA()==TGraph::Class()){
819 TGraph *gr=(TGraph*)o;
820 if (min==max) {
821 min=TMath::MinElement(gr->GetN(),gr->GetY());
822 max=TMath::MaxElement(gr->GetN(),gr->GetY());
823 } else {
824 Float_t currmin=TMath::MinElement(gr->GetN(),gr->GetY());
825 Float_t currmax=TMath::MaxElement(gr->GetN(),gr->GetY());
826 if (currmax>max) max=currmax;
827 if (currmin<min) min=currmin;
828 }
829 }
830 }
831 if (min!=max){
832 if (min!=0) min=min-(max-min)/10;
833 if (max!=0) max=max+(max-min)/10;
834 fCurrentHist->SetMinimum(min);
835 fCurrentHist->SetMaximum(max);
836 }
837}
838//______________________________________________________________________________
5312f439 839void AliTPCCalibViewerGUItime::DoDraw() {
7390f655 840 //
841 // Draw graphics
842 //
5312f439 843 TString drawString=fDrawString;
6e7d7dc4 844 TString cutString;
845 GetCutString(cutString);
514fcaf7 846 TString optString = GetDrawOptionString();
6e7d7dc4 847 Bool_t graphOutput=!fNoGraph; //ttree buffer for V1, V2... too small
848 graphOutput&=(drawString.First(">>")<0); //histogram output in custom draw
849 graphOutput&=fRadioXhist->GetState()!=kButtonDown; //histogram drawing selected
514fcaf7 850// graphOutput&=!(fIsCustomDraw&&!fDrawString.Contains(":")); //custom draw 1D
851// graphOutput&=fDrawString.CountChar(':')<2; //custom draw 1D
852 if (fIsCustomDraw&&fDrawString.Contains(":")) HandleButtonsDrawSel(-kRadioXhist);
1d32f273 853 if (fIsCustomDraw&&fDrawString.Contains(":")) HandleButtonsDrawSel(-kRadioXhist);
6e7d7dc4 854 Bool_t drawSame=optString.Contains("same",TString::kIgnoreCase);
855// optString+="goff";
856 if (graphOutput) {
857 drawString.Prepend("run:time:");
858 optString="goff";
859 }else{
1d32f273 860// if (!fIsCustomDraw){
6e7d7dc4 861 if (fRadioXrun->GetState()==kButtonDown){
862 drawString+=":run";
863 } else if (fRadioXtime->GetState()==kButtonDown){
864 drawString+=":time";
865 }
1d32f273 866// }
6e7d7dc4 867 }
5312f439 868 TVirtualPad *padsave=gPad;
869 fCanvMain->GetCanvas()->cd();
6e7d7dc4 870 //delete old histograms and graphs
871 if (!drawSame){
872 fTrashBox->Delete();
5312f439 873 fCurrentGraph=0x0;
5312f439 874 fCurrentHist=0x0;
875 }
bf05fdb7 876// printf("%s (%s) [%s]\n",drawString.Data(), cutString.Data(), optString.Data());
5312f439 877 //select data
878 fTree->Draw(drawString.Data(),cutString.Data(),optString.Data());
879 if (fTree->GetSelectedRows()==-1) return;
93425263 880
6e7d7dc4 881 TString title;
882 GetHistogramTitle(title);
5312f439 883 Bool_t drawGraph=kFALSE;
93425263 884 Double_t *xArr=0;
6e7d7dc4 885 if (graphOutput){
514fcaf7 886 drawGraph=kTRUE;
887 if (fIsCustomDraw&&fDrawString.Contains(":")){
93425263 888// fValuesX.SetElements(fTree->GetV4());
889 xArr=fTree->GetV4();
6e7d7dc4 890 }else{
6e7d7dc4 891 if (fRadioXrun->GetState()==kButtonDown){
93425263 892// fValuesX.SetElements(fTree->GetV1());
893 xArr=fTree->GetV1();
6e7d7dc4 894 } else if (fRadioXtime->GetState()==kButtonDown){
93425263 895// fValuesX.SetElements(fTree->GetV2());
896 xArr=fTree->GetV2();
6e7d7dc4 897 } else {
898 drawGraph=kFALSE;
6fb51ca4 899 }
900 }
514fcaf7 901 }
a3b590cf 902 if (xArr) UpdateValueArrays(graphOutput, xArr);
514fcaf7 903// if (graphOutput){
904// if (fIsCustomDraw){
905// if (fDrawString.Contains(":")){
906// fValuesX.SetElements(fTree->GetV4());
907// drawGraph=kTRUE;
908// } else {
909// drawGraph=kFALSE;
910// }
911// }else{
912// drawGraph=kTRUE;
913// if (fRadioXrun->GetState()==kButtonDown){
914// fValuesX.SetElements(fTree->GetV1());
915// } else if (fRadioXtime->GetState()==kButtonDown){
916// fValuesX.SetElements(fTree->GetV2());
917// } else {
918// drawGraph=kFALSE;
919// }
920// }
921// }
922//create graph according to selection
5312f439 923 if (drawGraph){
6e7d7dc4 924 TGraph *graph=new TGraph(fValuesX,fValuesY);
28af3ae3 925 graph->Sort();
6e7d7dc4 926 TString grDraw="p";
927 if (!drawSame) grDraw+="a";
928 if (!fIsCustomDraw) grDraw+="l";
929 graph->Draw(grDraw.Data());
930 graph->SetEditable(kFALSE);
931 TH1 *hist=graph->GetHistogram();
932 hist->SetTitle(title.Data());
933 fTrashBox->Add(graph);
934 graph->SetLineColor(fTrashBox->GetEntries());
935 graph->SetMarkerColor(fTrashBox->GetEntries());
936 if (!drawSame) {
937 fCurrentGraph=graph;
938 fCurrentHist=hist;
939 }
5312f439 940 } else {
6e7d7dc4 941 TH1 *hist=fTree->GetHistogram();
942 hist->SetTitle(title.Data());
943// hist->Draw(optString.Data());
944 fTrashBox->Add(hist);
945 hist->SetLineColor(fTrashBox->GetEntries());
946 hist->SetMarkerColor(fTrashBox->GetEntries());
947 if (!drawSame) fCurrentHist=hist;
5312f439 948 }
949
5312f439 950 //Set time axis if choosen as x-variables
1d32f273 951// if (fRadioXtime->GetState()==kButtonDown&&!fIsCustomDraw&&!drawSame){
952 if (fRadioXtime->GetState()==kButtonDown&&!drawSame){
5312f439 953 TAxis *xaxis=fCurrentHist->GetXaxis();
954 xaxis->SetTimeFormat("#splitline{%d.%m}{%H:%M}");
955 xaxis->SetTimeDisplay(1);
956 xaxis->SetLabelOffset(xaxis->GetLabelOffset()*3);
957 xaxis->SetLabelSize(xaxis->GetLabelSize()/1.3);
958 }
7390f655 959 if (!drawSame) {
6fb51ca4 960 //Set title offset
7390f655 961 fCurrentHist->GetYaxis()->SetTitleOffset(1.5);
962 } else {
963 //adjust y-range
964 AdjustYRange();
965 }
5312f439 966 gPad->Modified();
967 gPad->Update();
968 padsave->cd();
969}
970
971//______________________________________________________________________________
972void AliTPCCalibViewerGUItime::DoDumpRuns()
973{
974 //
975 // Dump the current run numbers to stdout
976 //
6fb51ca4 977 Int_t npoints=fRunNumbers.GetNrows();
978 Int_t *sortIndex = new Int_t[npoints];
979 TMath::Sort(npoints,fRunNumbers.GetMatrixArray(),sortIndex,kFALSE);
980 Int_t run=0, prevRun=-1;
981
982 for (Int_t irun=0;irun<npoints;++irun){
983 run=(Int_t)fRunNumbers.GetMatrixArray()[sortIndex[irun]];
984 if (run!=prevRun) std::cout << Form("%d",run) << std::endl;
985 prevRun=run;
5312f439 986 }
4ce766eb 987 delete [] sortIndex;
5312f439 988}
989//______________________________________________________________________________
990void AliTPCCalibViewerGUItime::DoParLimitChange()
991{
992 //
993 //
994 //
6fb51ca4 995 UpdateParName();
5312f439 996 DoDraw();
997}
998//______________________________________________________________________________
999void AliTPCCalibViewerGUItime::DoNewSelection() {
1000 //
1001 // decides whether to redraw if user makes another selection
1002 //
1003 UpdateParLimits();
1004 fDrawString=GetDrawString();
1005 fIsCustomDraw=kFALSE;
1006 DoDraw();
1007}
1008//______________________________________________________________________________
1009void AliTPCCalibViewerGUItime::DoCustomDraw()
1010{
1011 //
1012 //
1013 //
1014 fDrawString=fComboCustomDraw->GetTextEntry()->GetText();
6e7d7dc4 1015// if (fDrawString.Contains(">>")){
1016// Warning("DoCustomDraw","Currently no user defined histograms allowed!");
1017// return;
1018// }
1019 fNmbPar->SetState(kFALSE);
5312f439 1020 fIsCustomDraw=kTRUE;
1021 DoDraw();
1022}
1023//______________________________________________________________________________
1024void AliTPCCalibViewerGUItime::DoCustomCutsDraw()
1025{
1026 //
1027 //
1028 //
1029 if (fIsCustomDraw) DoCustomDraw();
1030 else {
1031 fDrawString=GetDrawString();
1032 fIsCustomDraw=kFALSE;
1033 DoDraw();
1034 }
1035}
1036//______________________________________________________________________________
1037void AliTPCCalibViewerGUItime::HandleButtonsDrawSel(Int_t id)
1038{
1039 //
1040 // Draw selection button handling (x-variable)
1041 //
1042
1043 if (id == -1) {
1044 TGButton *btn = (TGButton *) gTQSender;
1045 id = btn->WidgetId();
1046 }
1047
1048 Bool_t doDraw=kFALSE;
1d32f273 1049 Bool_t noDraw=kFALSE;
1050 if (id<-1){
1051 noDraw=kTRUE;
1052 id=TMath::Abs(id);
1053 }
5312f439 1054 switch (id) {
1055 case (kRadioXhist):
1056 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
1057 if (doDraw){
1058 fRadioXrun->SetState(kButtonUp);
1059 fRadioXtime->SetState(kButtonUp);
1d32f273 1060 fRadioXhist->SetState(kButtonDown);
5312f439 1061 }
1062 break;
1063 case (kRadioXrun):
1064 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXhist->GetState()==kButtonDown);
1065 if (doDraw){
1066 fRadioXhist->SetState(kButtonUp);
1067 fRadioXtime->SetState(kButtonUp);
1d32f273 1068 fRadioXrun->SetState(kButtonDown);
5312f439 1069 }
1070 break;
1071 case (kRadioXtime):
1072 doDraw=(fRadioXhist->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
1073 if (doDraw){
1074 fRadioXrun->SetState(kButtonUp);
1075 fRadioXhist->SetState(kButtonUp);
1d32f273 1076 fRadioXtime->SetState(kButtonDown);
5312f439 1077 }
1078 break;
1079 }
1d32f273 1080 if (doDraw&&!noDraw) DoCustomCutsDraw();
5312f439 1081}
1082//______________________________________________________________________________
6fb51ca4 1083void AliTPCCalibViewerGUItime::UpdateParName()
1084{
1085 //
1086 // change parameter name
1087 //
1088
1089 Int_t par = (Int_t)(fNmbPar->GetNumber());
7390f655 1090 TString parName="";
6fb51ca4 1091 Int_t id=fListVariables->GetSelectedEntry()->EntryId();
1092 if (fConfigParser && (*fConfigParser)(id)) parName=fConfigParser->GetData((*fConfigParser)(id),par+kParamNames);
7390f655 1093 if (parName=="") parName.Form("%d",par);
6fb51ca4 1094 fLblPar->SetText(Form("Parameter: %s",parName.Data()));
1095 fDrawString=GetDrawString();
1096 fIsCustomDraw=kFALSE;
1097}
1098
1099//______________________________________________________________________________
5312f439 1100void AliTPCCalibViewerGUItime::UpdateParLimits()
1101{
1102 //
1103 // Adjust limits for TVectorT based variables
1104 //
1105 if (!fTree) return;
6fb51ca4 1106 TString selectedVariableTitle="";
1107 Int_t id=-1;
1108 if (!fListVariables->GetSelectedEntry()) return;
1109 selectedVariableTitle = fListVariables->GetSelectedEntry()->GetTitle();
1110 id=fListVariables->GetSelectedEntry()->EntryId();
1111// printf("id: %d\n",id);
1112 TString selectedVariable=selectedVariableTitle;
1113 const TObject *key=(*fConfigParser)(id);
1114 if (key) selectedVariable=(*fConfigParser)(id)->GetName();
1115
5312f439 1116 if (selectedVariable.IsNull()||!selectedVariable.EndsWith(".")) {
1117 fNmbPar->SetState(kFALSE);
6fb51ca4 1118 fLblPar->SetText("Parameter: none");
5312f439 1119 return;
1120 }
1121 TVectorD *vD=0x0;
1122 TVectorF *vF=0x0;
1123 Int_t maxPar=0;
e6970ab5 1124 fTree->GetEntry(1);
1125 TBranch *branch=fTree->GetTree()->GetBranch(selectedVariable.Data());
5312f439 1126 TString branchClass=branch->GetClassName();
e6970ab5 1127 Int_t event=0;
5312f439 1128 if (branchClass=="TVectorT<double>"){
e6970ab5 1129// branch->SetAddress(&vD);
1130 fTree->SetBranchAddress(selectedVariable.Data(),&vD);
1131 while (maxPar<2&&event<fTree->GetEntries()){
1132 fTree->GetEntry(event++);
1133 maxPar=vD->GetNrows();
1134 }
5312f439 1135 } else if (branchClass=="TVectorT<float>"){
e6970ab5 1136// branch->SetAddress(&vF);
1137 fTree->SetBranchAddress(selectedVariable.Data(),&vF);
1138 while (maxPar<2&&event<fTree->GetEntries()){
1139 fTree->GetEntry(event++);
1140 maxPar=vF->GetNrows();
1141 }
5312f439 1142 } else {
1143 //class not known
1144 fNmbPar->SetState(kFALSE);
1145 return;
1146 }
e6970ab5 1147// branch->ResetAddress();
6e7d7dc4 1148 fTree->SetBranchAddress(selectedVariable.Data(),0x0);
7390f655 1149 if (fNmbPar->GetNumMax()!=maxPar-1) fNmbPar->SetNumber(0);
5312f439 1150 fNmbPar->SetLimitValues(0,maxPar-1);
1151 fNmbPar->SetState(kTRUE);
6fb51ca4 1152 UpdateParName();
5312f439 1153}
1154//______________________________________________________________________________
6fb51ca4 1155void AliTPCCalibViewerGUItime::MouseMove(Int_t event, Int_t x, Int_t y, TObject */*selected*/)
5312f439 1156{
1157 //
1158 // handle mouse events in the draw canvas
1159 //
5312f439 1160 UInt_t dd=0,mm=0,yy=0,HH=0,MM=0,SS=0,run=0;
1161 Double_t valx=0.,valy=0.;
1162 if (!fCurrentGraph) {
909c8c99 1163 fLblRunNumberVal->SetText(Form("%06u",run));
e6970ab5 1164 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u:%02u:%02u",dd,mm,yy,HH,MM,SS));
892226be 1165 fLblValueXVal->SetText(Form("%.3e", valx));
1166 fLblValueYVal->SetText(Form("%.3e", valy));
5312f439 1167 return;
1168 }
1169 TVirtualPad *padsave=gPad;
1170 fCanvMain->GetCanvas()->cd();
1171 Int_t n=fValuesY.GetNrows();
1172 Double_t *arr=0x0;
1173 arr=fValuesX.GetMatrixArray();
1174
1175 Int_t minDist=1000000;
1176 Int_t minPoint=-1;
1177 for (Int_t i=0;i<n;++i){
1178 Int_t pxp = gPad->XtoAbsPixel(gPad->XtoPad(arr[i]));
1179 Int_t pyp = gPad->YtoAbsPixel(gPad->YtoPad(fValuesY[i]));
e6970ab5 1180 Int_t d = TMath::Nint(TMath::Sqrt(TMath::Abs(pxp-x) + TMath::Abs(pyp-y)));
5312f439 1181 if (d < minDist) {
1182 minDist = d;
1183 minPoint = i;
1184 }
1185 }
1186 if (minDist<2){
1187 TTimeStamp t((Int_t)fTimeStamps[minPoint]);
1188 t.GetDate(kTRUE,0,&yy,&mm,&dd);
1189 t.GetTime(kTRUE,0,&HH,&MM,&SS);
1190 run=(UInt_t)fRunNumbers[minPoint];
1191 valx=fValuesX[minPoint];
1192 valy=fValuesY[minPoint];
1193 } else {
1194 dd=0;mm=0;yy=0;HH=0;MM=0;SS=0;run=0;
1195 valx=0.;
1196 valy=0.;
1197 }
909c8c99 1198 fLblRunNumberVal->SetText(Form("%06u",run));
5312f439 1199 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u.%02u.%02u",dd,mm,yy,HH,MM,SS));
1200 if (fIsCustomDraw){
892226be 1201 fLblValueXVal->SetText(Form("%.3e", valx));
5312f439 1202 }else{
1203 if (fRadioXrun->GetState()==kButtonDown){
1204 fLblValueXVal->SetText("Run");
1205 } else if (fRadioXtime->GetState()==kButtonDown){
1206 fLblValueXVal->SetText("Time");
1207 }
1208 }
892226be 1209 fLblValueYVal->SetText(Form("%.3e", valy));
5312f439 1210 padsave->cd();
1211 if (run==0) return;
1212 if (event == kButton1Double ){
1213 SetGuiTree(run);
1214 }
1215 //find closes point of current selection
1216}
1217//______________________________________________________________________________
1218void AliTPCCalibViewerGUItime::SetGuiTree(Int_t run)
1219{
1220 //
1221 // create the AliTPCCalibViewerGUI tree for run
1222 // cache tree in directory fOutputCacheDir
1223 // retrieve file from this directory if it already exists
1224 //
1225
949d8707 1226 //
1227 //Create and set GUI tree
1228 //
5312f439 1229 //try to find file for run in fOutputCacheDir
1230 TString fileName=fOutputCacheDir;
1231 if (!fileName.EndsWith("/")) fileName+="/";
1232 fileName+=Form("guiTreeRun_%d.root",run);
7390f655 1233 Bool_t load=kTRUE;
949d8707 1234 if (gSystem->AccessPathName(fileName.Data())){
7390f655 1235 load=AliTPCcalibDB::CreateGUITree(run,fileName.Data());
1236 if (!load){
1237 fCalibViewerGUI->Reset();
1238 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - XXXXX")));
1239 return;
1240 }
5312f439 1241 }
7390f655 1242 fCalibViewerGUI->Initialize(fileName.Data());
1243 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %05d",run)));
949d8707 1244
1245 //
1246 //Create and set Reference GUI tree
1247 //
1248 AliTPCcalibDButil util;
1249 util.SetReferenceRun(run);
1250 fileName=fOutputCacheDir;
1251 if (!fileName.EndsWith("/")) fileName+="/";
1252 fileName+=util.GetGUIRefTreeDefaultName();
1253 //only update if file does not exist
1254 if (gSystem->AccessPathName(fileName.Data())){
1255 util.UpdateRefDataFromOCDB();
1256 util.CreateGUIRefTree(fileName.Data());
1257 }
1258
1259 fCalibViewerGUI->GetViewer()->AddReferenceTree(fileName.Data(),"calPads","Ref");
1260
1261 //
1262 // Process additional reference trees
1263 //
7390f655 1264 TIter nextRefTree(fMapRefTrees);
1265 TObject *o=0x0;
949d8707 1266 //Set static reference data
7390f655 1267 while ( (o=nextRefTree()) ){
1268 fCalibViewerGUI->GetViewer()->AddReferenceTree(fMapRefTrees->GetValue(o)->GetName(),"calPads",o->GetName());
5312f439 1269 }
7390f655 1270 fCalibViewerGUI->Reload();
5312f439 1271}
1272//______________________________________________________________________________
bf05fdb7 1273void AliTPCCalibViewerGUItime::SubstituteUnderscores(TString &s)
6fb51ca4 1274{
1275 //
1276 //
1277 //
6fb51ca4 1278 s.ReplaceAll("_{","|{");
1279 s.ReplaceAll("_"," ");
1280 s.ReplaceAll("|{","_{");
6fb51ca4 1281}
514fcaf7 1282
1283//______________________________________________________________________________
1284void AliTPCCalibViewerGUItime::DoNewSelectionAliases()
1285{
1286 //
1287 //
1288 //
1289 if (!fTree) return;
1290 TList *l=fTree->GetListOfAliases();
1291 if (!l) return;
1292 TString selectedVariable="";
1293 if (!fListAliases->GetSelectedEntry()) return;
1294 selectedVariable = fListAliases->GetSelectedEntry()->GetTitle();
1295 fDrawString=selectedVariable;
1296 fIsCustomDraw=kFALSE;
1297 DoDraw();
1298}
1299//______________________________________________________________________________
1300void AliTPCCalibViewerGUItime::DoAddAlias()
1301{
1302 //
1303 //
1304 //
1305 new AliTPCCalibViewerGUItimeAddAliasFrame(gClient->GetRoot(), fContTopBottom, 400, 200, kVerticalFrame, this);
1306}
1307//______________________________________________________________________________
1308void AliTPCCalibViewerGUItime::DoDelAlias()
1309{
1310 //
1311 //
1312 //
1313 if (!fTree) return;
1314 TList *l=fTree->GetListOfAliases();
1315 if (!l) return;
1316 TString selectedVariable="";
1317 if (!fListAliases->GetSelectedEntry()) return;
1318 selectedVariable = fListAliases->GetSelectedEntry()->GetTitle();
1319 l->Remove(l->FindObject(selectedVariable.Data()));
1320 UpdateAliasList();
1321}
1322
1323//______________________________________________________________________________
1324void AliTPCCalibViewerGUItime::UpdateAliasList()
1325{
1326 //
1327 //
1328 //
1329 printf("UpdateAliasList\n");
1330 if (!fTree) return;
1331 TList *l=fTree->GetListOfAliases();
1332 if (!l) return;
1333 TIter nextAlias(l);
1334 TObject *o;
1335 fListAliases->RemoveAll();
1336 Int_t id=0;
1337 while( (o=nextAlias()) ){
1338 fListAliases->AddEntry(o->GetName(),id++);
1339 }
1340 fListAliases->Resize(fListAliases->GetWidth()-1, fListAliases->GetHeight());
1341 fListAliases->Resize(fListAliases->GetWidth()+1, fListAliases->GetHeight());
1342}
6fb51ca4 1343//______________________________________________________________________________
6e7d7dc4 1344TObjArray* AliTPCCalibViewerGUItime::ShowGUI(const char* fileName, const char* treeName) {
5312f439 1345 //
1346 // Initialize and show GUI for presentation for demonstration purposes
1347 // or for fast standalone use
1348 //
1349 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
1350 frmMain->SetWindowName("AliTPCCalibViewer GUItime");
1351 frmMain->SetCleanup(kDeepCleanup);
1352
1353 TGTab* tabMain = new TGTab(frmMain, 1000, 600);
1354 frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1355
1356 TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
1357 TGCompositeFrame* tabCont2 = tabMain->AddTab("Detail - XXXXX");
1358
1359 AliTPCCalibViewerGUItime* calibViewerTime = new AliTPCCalibViewerGUItime(tabCont1, 1000, 600);
1360 tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
6e7d7dc4 1361 calibViewerTime->SetConfigFileName("$ALICE_ROOT/TPC/CalibMacros/calibVarDescription.txt");
1362 calibViewerTime->UseFile(fileName, treeName);
5312f439 1363
1364 AliTPCCalibViewerGUI* calibViewer = new AliTPCCalibViewerGUI(tabCont2, 1000, 600, 0);
1365 tabCont2->AddFrame(calibViewer, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1366 calibViewerTime->SetCalibViewerGUI(calibViewer);
1367 calibViewerTime->SetCalibViewerGUItab(tabMain->GetTabTab(1));
1368
1369
1370 TObjArray *guiArray = new TObjArray();
1371 guiArray->Add(calibViewerTime);
1372 guiArray->Add(calibViewer);
1373
1374 frmMain->MapSubwindows();
1375 frmMain->Resize();
1376 frmMain->MapWindow();
1377
1378 return guiArray;
1379}
1380
6e7d7dc4 1381//______________________________________________________________________________
1382TObjArray* AliTPCCalibViewerGUItime::ShowGUI(TChain *chain) {
1383 //
1384 // Initialize and show GUI for presentation for demonstration purposes
1385 // or for fast standalone use
1386 //
1387 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
1388 frmMain->SetWindowName("AliTPCCalibViewer GUItime");
1389 frmMain->SetCleanup(kDeepCleanup);
1390
1391 TGTab* tabMain = new TGTab(frmMain, 1000, 600);
1392 frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1393
1394 TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
1395
1396 AliTPCCalibViewerGUItime* calibViewerTime = new AliTPCCalibViewerGUItime(tabCont1, 1000, 600);
1397 tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
1398 calibViewerTime->UseChain(chain);
1399
1400 TObjArray *guiArray = new TObjArray();
1401 guiArray->Add(calibViewerTime);
1402
1403 frmMain->MapSubwindows();
1404 frmMain->Resize();
1405 frmMain->MapWindow();
1406
1407 return guiArray;
1408}
514fcaf7 1409
1410
1411////////////////////////////////////////////////////////////////////////
1412//
1413// GUI Alias frame
1414//
1415////////////////////////////////////////////////////////////////////////
1416
1417
1418ClassImp(AliTPCCalibViewerGUItimeAddAliasFrame)
1419
1420AliTPCCalibViewerGUItimeAddAliasFrame::AliTPCCalibViewerGUItimeAddAliasFrame(const TGWindow *p, const TGWindow *main,
1421 UInt_t w, UInt_t h, UInt_t options,
1422 AliTPCCalibViewerGUItime *gui, TString strAlias) :
1423 fMain(0x0),
1424 fTxt1(0x0),
1425 fTxt2(0x0),
1426 fGUI(0x0)
1427{
1428 fMain = new TGTransientFrame(p, main, w, h, options);
1429 fMain->Connect("CloseWindow()", "AliTPCCalibViewerGUItimeAddAliasFrame", this, "DoCancel()");
1430 fMain->DontCallClose(); // to avoid double deletions.
1431
1432 // use hierarchical cleaning
1433 fMain->SetCleanup(kDeepCleanup);
1434
1435 //layout
1436 TGLayoutHints *l1 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2);
1437 TGLayoutHints *l2 = new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandX, 2, 2, 0, 5);
1438// TGLayoutHints *l3 = new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 5, 5, 5);
1439
1440 //input fields
1441 TGCompositeFrame *f1 = new TGCompositeFrame(fMain, 60, 20, kVerticalFrame);
1442 fMain->AddFrame(f1, l1);
1443 TGCompositeFrame *frameName = new TGCompositeFrame(f1);
1444 TGCompositeFrame *frameFormula = new TGCompositeFrame(f1);
1445 f1->AddFrame(frameName,l2);
1446 f1->AddFrame(frameFormula,l2);
1447 TGLabel *lblTxt1 = new TGLabel(frameName, "Name:");
1448 TGLabel *lblTxt2 = new TGLabel(frameFormula, "Formula:");
1449 fTxt1 = new TGTextEntry(frameName, new TGTextBuffer(1000));
1450 fTxt2 = new TGTextEntry(frameFormula, new TGTextBuffer(1000));
1451
1452 frameName->AddFrame(lblTxt1, l2);
1453 frameName->AddFrame(fTxt1, l2);
1454 frameFormula->AddFrame(lblTxt2, l2);
1455 frameFormula->AddFrame(fTxt2, l2);
1456
1457 fTxt1->Resize(350, fTxt1->GetDefaultHeight());
1458 fTxt2->Resize(350, fTxt2->GetDefaultHeight());
1459
1460 //ok and cancel buttons
1461 TGHorizontalFrame *frame = new TGHorizontalFrame(fMain, 60, 20, kFixedWidth);
1462
1463 TGTextButton *okButton = new TGTextButton(frame, "&Ok", 1);
1464 okButton->Connect("Clicked()", "AliTPCCalibViewerGUItimeAddAliasFrame", this, "DoOK()");
1465 TGTextButton *cancelButton = new TGTextButton(frame, "&Cancel", 2);
1466 cancelButton->Connect("Clicked()", "AliTPCCalibViewerGUItimeAddAliasFrame", this, "DoCancel()");
1467
1468
1469 frame->AddFrame(okButton, l1);
1470 frame->AddFrame(cancelButton, l1);
1471
1472 frame->Resize(150, okButton->GetDefaultHeight());
1473
1474 fMain->AddFrame(frame, new TGLayoutHints(kLHintsBottom | kLHintsRight, 2, 2, 5, 1));
1475
1476 fGUI=gui;
1477 TString aliasName, alias;
1478 if (!strAlias.IsNull()){
1479 TChain *c=fGUI->GetChain();
1480 if (c){
1481 TList *l=c->GetListOfAliases();
1482 if (l){
1483 TNamed *d=(TNamed*)l->FindObject(strAlias);
1484 if (d){
1485 aliasName=d->GetName();
1486 alias=d->GetTitle();
1487 }
1488 }
1489 }
1490 }else{
1491 alias=fGUI->GetCustomDrawString();
1492 }
1493 fTxt1->SetText(aliasName.Data(),kFALSE);
1494 fTxt2->SetText(alias.Data(),kFALSE);
1495
1496 fMain->MapSubwindows();
1497 fMain->Resize();
1498
1499 // position relative to the parent's window
1500 fMain->CenterOnParent();
1501
1502 fMain->SetWindowName("Alias Editor");
1503
1504 fMain->MapWindow();
1505
1506}
1507//______________________________________________________________________________
1508AliTPCCalibViewerGUItimeAddAliasFrame::~AliTPCCalibViewerGUItimeAddAliasFrame()
1509{
1510 //
1511 //
1512 //
1513 fMain->DeleteWindow(); // deletes fMain
1514}
1515//______________________________________________________________________________
1516void AliTPCCalibViewerGUItimeAddAliasFrame::DoOK()
1517{
1518 //
1519 //
1520 //
1521 TString aliasName=fTxt1->GetText();
1522 TString alias=fTxt2->GetText();
1523 if (!aliasName.IsNull()&&!alias.IsNull()){
1524 TChain *c=fGUI->GetChain();
1525 if (c){
1526 c->SetAlias(aliasName.Data(),alias.Data());
1527 }
1528 }
1529 fGUI->UpdateAliasList();
1530 delete this;
1531}
1532//______________________________________________________________________________
1533void AliTPCCalibViewerGUItimeAddAliasFrame::DoCancel()
1534{
1535 //
1536 //
1537 //
1538 delete this;
1539}
1540