]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCCalibViewerGUItime.cxx
Jens Wiechula modifications.
[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
22#include <iostream>
23//Root includes
24#include <TROOT.h>
25#include <TDirectory.h>
26#include <TStyle.h>
27#include <TCanvas.h>
28#include <TPad.h>
29#include <TVirtualPad.h>
30#include <TObject.h>
31#include <TObjArray.h>
32#include <TObjString.h>
6fb51ca4 33#include <TSystem.h>
5312f439 34#include <TVector.h>
35#include <TH1.h>
36#include <TCut.h>
37#include <TFile.h>
38#include <TTree.h>
39#include <TBranch.h>
40#include <TIterator.h>
41#include <TGraph.h>
42#include <TAxis.h>
43#include <TTimeStamp.h>
44#include <TMath.h>
45//
46#include <TGFileDialog.h>
47#include <TGInputDialog.h>
48//
49#include <TGButton.h>
50#include <TGListBox.h>
51#include <TGComboBox.h>
52#include <TGNumberEntry.h>
53#include <TGLayout.h>
54#include <TRootEmbeddedCanvas.h>
55#include <TGSplitter.h>
56#include <TGButtonGroup.h>
57#include <TGLabel.h>
58#include <TGTab.h>
59#include <TGString.h>
60
61//AliRoot includes
6fb51ca4 62#include <AliLog.h>
5312f439 63#include "AliTPCCalibViewerGUI.h"
64#include "AliTPCcalibDB.h"
6fb51ca4 65#include "AliTPCConfigParser.h"
5312f439 66
67#include "AliTPCCalibViewerGUItime.h"
68
69ClassImp(AliTPCCalibViewerGUItime)
70
71AliTPCCalibViewerGUItime::AliTPCCalibViewerGUItime(const TGWindow *p, UInt_t w, UInt_t h) :
72TGCompositeFrame(p,w,h),
73 fFile(0x0),
74 fTree(0x0),
75 fCalibViewerGUI(0x0),
76 fCalibViewerGUItab(0x0),
77 fCurrentHist(0x0),
78 fCurrentGraph(0x0),
79 fCurrentRunDetails(-1),
80 fOutputCacheDir("/tmp"),
81 fDrawString(""),
6fb51ca4 82 fConfigFile("$ALICE_ROOT/TPC/CalibMacros/calibVarDescription.txt"),
83 fConfigParser(0x0),
5312f439 84 fIsCustomDraw(kFALSE),
85 fRunNumbers(10),
86 fTimeStamps(10),
87 fValuesX(10),
88 fValuesY(10),
89 //GUI elements
90 //main canvas Top part, bottom part
91 fContTopBottom(0x0),
92 //top left, centre, right
93 fContLCR(0x0),
94 //content left
95 fContLeft(0x0),
96 fContDrawSel(0x0),
97 fContDrawSelSubRunTime(0x0),
98 fRadioXhist(0x0),
99 fRadioXrun(0x0),
100 fRadioXtime(0x0),
101 fListVariables(0x0),
102 fComboRunType(0x0),
103 fLblRunType(0x0),
104 fNmbPar(0x0),
105 fLblPar(0x0),
6fb51ca4 106 fListCalibType(0x0),
107 fContCalibType(0x0),
5312f439 108 //content centre
109 fContCenter(0x0),
110 fCanvMain(0x0),
111 //content right
112 fContRight(0x0),
113 fContValues(0x0),
114 fLblRunNumber(0x0),
115 fLblRunTime(0x0),
116 fLblValueX(0x0),
117 fLblValueY(0x0),
118 fLblRunNumberVal(0x0),
119 fLblRunTimeVal(0x0),
120 fLblValueXVal(0x0),
121 fLblValueYVal(0x0),
122 fBtnDumpRuns(0x0),
123 //content bottom
124 fContCustom(0x0),
125 fContCustomCuts(0x0),
126 fLblCustomDraw(0x0),
127 fLblCustomCuts(0x0),
128 fComboCustomDraw(0x0),
129 fComboCustomCuts(0x0)
130{
131 //
132 // ctor
133 //
134 DrawGUI(p,w,h);
135 SetInitialValues();
136}
137//______________________________________________________________________________
138AliTPCCalibViewerGUItime::~AliTPCCalibViewerGUItime(){
139 //
140 // dtor
141 //
142
143}
144//______________________________________________________________________________
6fb51ca4 145void AliTPCCalibViewerGUItime::DrawGUI(const TGWindow */*p*/, UInt_t w, UInt_t h) {
5312f439 146 //
147 // draw the GUI
148 //
149 // ======================================================================
150 // ************************* Display everything *************************
151 // ======================================================================
152
153 SetCleanup(kDeepCleanup);
5312f439 154
155 // *****************************************************************************
156 // ************************* content of this MainFrame *************************
157 // *****************************************************************************
158 // top level container with horizontal layout
159 fContTopBottom = new TGCompositeFrame(this, w, h, kVerticalFrame | kFixedWidth | kFixedHeight);
160 AddFrame(fContTopBottom, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
161
162 fContLCR = new TGCompositeFrame(fContTopBottom, w, h, kHorizontalFrame | kFixedWidth | kFixedHeight);
163 fContTopBottom->AddFrame(fContLCR, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
164
165 // ***********************************************************************
166 // ************************* content of fContLCR *************************
167 // ***********************************************************************
168 // left container
169 fContLeft = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
170 fContLCR->AddFrame(fContLeft, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 5, 3, 3, 3));
171
172 // left vertical splitter
173 TGVSplitter *splitLeft = new TGVSplitter(fContLCR);
174 splitLeft->SetFrame(fContLeft, kTRUE);
175 fContLCR->AddFrame(splitLeft, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
176
177 // right container
178 fContRight = new TGCompositeFrame(fContLCR, 150, 200, kVerticalFrame | kFixedWidth | kFitHeight);
179 fContLCR->AddFrame(fContRight, new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandY, 3, 5, 3, 3));
180
181 // center container
182 fContCenter = new TGCompositeFrame(fContLCR, 200, 200, kVerticalFrame | kFixedWidth | kFitHeight);
183 fContLCR->AddFrame(fContCenter, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
184
185 // right vertical splitter
186 TGVSplitter *splitRight = new TGVSplitter(fContLCR);
187 splitRight->SetFrame(fContRight, kFALSE);
188 fContLCR->AddFrame(splitRight, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0));
189
190
191 // ========================================================================
192 // ************************* content of fContLeft *************************
193 // ========================================================================
194 // --- draw button and tabLeft ---
195
196 // draw selection group
197 fContDrawSel = new TGGroupFrame(fContLeft, "Draw selection", kVerticalFrame | kFitWidth | kFitHeight);
198 fContLeft->AddFrame(fContDrawSel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 10, 0));
199 //x-axis variables selection, Run of Time
200 fContDrawSelSubRunTime = new TGCompositeFrame(fContDrawSel, 200, 23, kHorizontalFrame | kFitWidth | kFixedHeight);
201 fContDrawSel->AddFrame(fContDrawSelSubRunTime, new TGLayoutHints(kLHintsCenterX | kLHintsExpandX , 0, 0, 0, 0));
202
203 // ------------------------- content of fContDrawOpt -------------------------
204 //
205 // Run radio button
206 // Time radio button
207 fRadioXhist = new TGRadioButton(fContDrawSelSubRunTime, "hist", kRadioXhist);
208 fContDrawSelSubRunTime->AddFrame(fRadioXhist, new TGLayoutHints(kLHintsNormal, 0, 2, 0, 0));
209 fRadioXhist->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
210 fRadioXhist->SetToolTipText("Draw the distribution of the variable");
211
212 fRadioXrun = new TGRadioButton(fContDrawSelSubRunTime, ":Run", kRadioXrun);
213 fContDrawSelSubRunTime->AddFrame(fRadioXrun, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
214 fRadioXrun->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
215 fRadioXrun->SetToolTipText("Use run number as x-value");
216
217 // Time radio button
218 fRadioXtime = new TGRadioButton(fContDrawSelSubRunTime, ":Time", kRadioXtime);
219 fContDrawSelSubRunTime->AddFrame(fRadioXtime, new TGLayoutHints(kLHintsNormal, 2, 2, 0, 0));
220 fRadioXtime->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "HandleButtonsDrawSel()");
221 fRadioXtime->SetToolTipText("Use time stamp number as x-value");
222
223
224 // list of variables
225 fListVariables = new TGListBox(fContDrawSel);
226 fContDrawSel->AddFrame(fListVariables, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
227 fListVariables->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoNewSelection()");
228
6fb51ca4 229
230//-------------------- run type selection ------------------------
5312f439 231 // Parameter label
232 fLblRunType = new TGLabel(fContDrawSel, "Run Type:");
233 fLblRunType->SetTextJustify(kTextLeft);
234 fContDrawSel->AddFrame(fLblRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
235
236 fComboRunType = new TGComboBox(fContDrawSel);
237 fComboRunType->EnableTextInput(kFALSE);
238 fContDrawSel->AddFrame(fComboRunType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
239 fComboRunType->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoDraw()");
240// fComboRunType->SetEnabled(kFALSE);
241 fComboRunType->Resize(0, 22);
242
243 //-------------------- parameter selection ------------------------
244 // Parameter label
245 fLblPar = new TGLabel(fContDrawSel, "Parameter:");
246 fLblPar->SetTextJustify(kTextLeft);
247 fContDrawSel->AddFrame(fLblPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
248
249 fNmbPar = new TGNumberEntry(fContDrawSel, 0, 1, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, 71);
250 fContDrawSel->AddFrame(fNmbPar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
251 fNmbPar->Connect("ValueSet(Long_t)", "AliTPCCalibViewerGUItime", this, "DoParLimitChange()");
252 fNmbPar->SetState(kFALSE);
253
6fb51ca4 254 //-------------------- calibration type selection ------------------------
255 // label
256 // draw selection group
257 fContCalibType = new TGGroupFrame(fContLeft, "Calib type selection", kVerticalFrame | kFitWidth | kFitHeight);
258 fContLeft->AddFrame(fContCalibType, new TGLayoutHints(kLHintsExpandX , 0, 0, 10, 0));
259
260 // list of variables
261 fListCalibType = new TGListBox(fContCalibType);
262 fContCalibType->AddFrame(fListCalibType, new TGLayoutHints(kLHintsNormal | kLHintsExpandX , 0, 0, 0, 0));
263 fListCalibType->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoChangeSelectionList()");
264 fListCalibType->Resize(0,88);
265 fListCalibType->SetMultipleSelections();
266
5312f439 267
268 // ==========================================================================
269 // ************************* content of fContCenter *************************
270 // ========================================================================
271 // main drawing canvas
272 fCanvMain = new TRootEmbeddedCanvas("GUItime_Canvas", fContCenter, 200, 200, kFitWidth | kFitHeight);
273 fContCenter->AddFrame(fCanvMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
274 fCanvMain->GetCanvas()->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)", "AliTPCCalibViewerGUItime", this, "MouseMove(Int_t, Int_t, Int_t, TObject*)");
275// fCanvMain->GetCanvas()->Connect("RangeAxisChanged()", "AliTPCCalibViewerGUItime", this, "GetMinMax()");
276 fCanvMain->GetCanvas()->SetToolTipText("The Main_Canvas, here your plots are displayed.");
6fb51ca4 277 fCanvMain->GetCanvas()->SetRightMargin(0.062);
278 fCanvMain->GetCanvas()->SetLeftMargin(0.15);
5312f439 279
280 // =========================================================================
281 // ************************* content of fContRight *************************
282 // ========================================================================
283 //group frame for value information
284 fContValues = new TGGroupFrame(fContRight, "Data point info", kVerticalFrame | kFitWidth | kFitHeight);
285 fContRight->AddFrame(fContValues, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
286 //set layout manager
287 fContValues->SetLayoutManager(new TGMatrixLayout(fContValues, 0, 2, 5));
288 //value information labels
289
290 //run number label
291 fLblRunNumber = new TGLabel(fContValues, "Run:");
292 fLblRunNumber->SetTextJustify(kTextLeft);
293 fContValues->AddFrame(fLblRunNumber, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
294 //run number
295 fLblRunNumberVal = new TGLabel(fContValues, "00000");
296 fLblRunNumberVal->SetTextJustify(kTextLeft);
297 fContValues->AddFrame(fLblRunNumberVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
298 //time stamp label
299 fLblRunTime = new TGLabel(fContValues, "Time:");
300 fLblRunTime->SetTextJustify(kTextLeft);
301 fContValues->AddFrame(fLblRunTime, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
302 //run number
303 fLblRunTimeVal = new TGLabel(fContValues, "00.00.0000\n00:00:00");
304 fLblRunTimeVal->SetTextJustify(kTextLeft);
305 fContValues->AddFrame(fLblRunTimeVal, new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0));
306 //value label x
307 fLblValueX = new TGLabel(fContValues, "x-Value:");
308 fLblValueX->SetTextJustify(kTextLeft);
309 fContValues->AddFrame(fLblValueX, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
310 //value x
311 fLblValueXVal = new TGLabel(fContValues, "00000.000");
312 fLblValueXVal->SetTextJustify(kTextRight);
313 fContValues->AddFrame(fLblValueXVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
314 //value label y
315 fLblValueY = new TGLabel(fContValues, "y-Value:");
316 fLblValueY->SetTextJustify(kTextLeft);
317 fContValues->AddFrame(fLblValueY, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
318 //value y
319 fLblValueYVal = new TGLabel(fContValues, "00000.000");
320 fLblValueYVal->SetTextJustify(kTextRight);
321 fContValues->AddFrame(fLblValueYVal, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
322 // draw button
323 fBtnDumpRuns = new TGTextButton(fContRight, "&Dump runs");
6fb51ca4 324 fContRight->AddFrame(fBtnDumpRuns, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
5312f439 325 fBtnDumpRuns->Connect("Clicked()", "AliTPCCalibViewerGUItime", this, "DoDumpRuns()");
326 fBtnDumpRuns->SetToolTipText("Press to dump the run numbers of the current selection.");
327
328 // =========================================================================
329 // ****************** bottom content of fContTopBottom *********************
330 // =========================================================================
331
332 // custom options container
333 // --- fComboCustom --- the custom draw line on the very low
334 fContCustom = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
335 fContTopBottom->AddFrame(fContCustom, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
336
337 // ------------------------- content of fContCustom -------------------------
338 fLblCustomDraw = new TGLabel(fContCustom, "Custom draw: ");
339 fLblCustomDraw->SetTextJustify(kTextLeft);
340 fContCustom->AddFrame(fLblCustomDraw, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
341 // text field for custom draw command
342 fComboCustomDraw = new TGComboBox(fContCustom);
343// fComboCustomDraw->Resize(0, fLblValueY->GetDefaultHeight());
344 fComboCustomDraw->Resize(0, 22);
345 fComboCustomDraw->EnableTextInput(kTRUE);
346 fContCustom->AddFrame(fComboCustomDraw, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
347 fComboCustomDraw->Connect("ReturnPressed()", "AliTPCCalibViewerGUItime", this, "DoCustomDraw()");
348 fComboCustomDraw->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoCustomDraw()");
349
350
351 // additional cuts container
352 fContCustomCuts = new TGCompositeFrame(fContTopBottom, 200, 200, kHorizontalFrame | kFitWidth | kFitHeight);
353 fContTopBottom->AddFrame(fContCustomCuts, new TGLayoutHints(kLHintsExpandX, 10, 0, 0, 0));
354
355 // ------------------------- content of fContCustomCuts -------------------------
356 fLblCustomCuts = new TGLabel(fContCustomCuts, "Custom cuts: ");
357 fLblCustomCuts->SetTextJustify(kTextLeft);
358 fContCustomCuts->AddFrame(fLblCustomCuts, new TGLayoutHints(kLHintsNormal, 5, 0, 0, 0));
359 // combo text field for additional cuts
360 fComboCustomCuts = new TGComboBox(fContCustomCuts);
361// fComboCustomCuts->Resize(0, fLblValueY->GetDefaultHeight());
362 fComboCustomCuts->Resize(0, 22);
363 fComboCustomCuts->EnableTextInput(kTRUE);
364 fContCustomCuts->AddFrame(fComboCustomCuts, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 0, 0));
6fb51ca4 365 fComboCustomCuts->Connect("ReturnPressed()", "AliTPCCalibViewerGUItime", this, "DoCustomCutsDraw()");
366 fComboCustomCuts->Connect("Selected(Int_t)", "AliTPCCalibViewerGUItime", this, "DoCustomCutsDraw()");
5312f439 367
368 SetWindowName("AliTPCCalibViewer GUI - Time");
369 MapSubwindows();
370 Resize(GetDefaultSize());
371 MapWindow();
372}
373//______________________________________________________________________________
374void AliTPCCalibViewerGUItime::SetInitialValues(){
375 //
376 // Set inital selections of the gui
377 //
378 fRadioXrun->SetState(kButtonDown);
379 fRadioXtime->SetState(kButtonUp);
380}
381
382//______________________________________________________________________________
383void AliTPCCalibViewerGUItime::UseFile(const char* fileName) {
384 //
385 // retrieve tree from file
386 //
387 TDirectory *save=gDirectory;
388 if (fFile) delete fFile;
389 fFile = TFile::Open(fileName);
6fb51ca4 390 if (!fFile) return;
391 if (!fFile->IsOpen()) return;
5312f439 392 fTree=(TTree*)fFile->Get("dcs");
6fb51ca4 393 if (!fTree){
394 AliError(Form("Could not get tree from file '%s'",fileName));
395 return;
396 }
5312f439 397 save->cd();
6fb51ca4 398 if (fConfigParser) delete fConfigParser;
399 fConfigParser=new AliTPCConfigParser(gSystem->ExpandPathName(fConfigFile.Data()));
5312f439 400 Reload();
401}
402//______________________________________________________________________________
6fb51ca4 403void AliTPCCalibViewerGUItime::FillRunTypes()
404{
5312f439 405 //
6fb51ca4 406 //Loop over the tree entries and fill the run types
5312f439 407 //
6fb51ca4 408 if (!fTree) return;
5312f439 409 Int_t id=0;
5312f439 410 fComboRunType->RemoveAll();
411 fComboRunType->AddEntry("ALL",id++);
412 fComboRunType->Select(0,kFALSE);
413 TObjString *runType=0x0;
414 Int_t nevets=fTree->GetEntries();
415 TBranch *branch=fTree->GetBranch("runType.");
416 if (!branch) return;
417 branch->SetAddress(&runType);
418 fTree->SetBranchStatus("*",0);
419 fTree->SetBranchStatus("runType.*",1);
420 for (Int_t iev=0;iev<nevets;++iev){
421 fTree->GetEntry(iev);
422 TString type=runType->String();
423 if (!type.IsNull()&&!fComboRunType->FindEntry(type)) fComboRunType->AddEntry(type,id++);
424 }
425 branch->ResetAddress();
426 fTree->SetBranchStatus("*",1);
427}
428//______________________________________________________________________________
6fb51ca4 429void AliTPCCalibViewerGUItime::FillCalibTypes()
430{
431 //
432 // loop over configuration and fill calibration types
433 //
434 if (!fConfigParser) return;
435 Int_t id=0;
436 fListCalibType->RemoveAll();
437 TObject *o=0x0;
438 fConfigParser->ResetIter();
439 TString type;
440 while ( (o=fConfigParser->NextKey()) ){
441 type=fConfigParser->GetData(o,kCalibType);
442 //remove whitespcaces
443 type.Remove(TString::kBoth,' ');
444 type.Remove(TString::kBoth,'\t');
445 if (type.IsNull()) type="UNSPECIFIED";
446// printf("CalibType: '%s'\n",type.Data());
447 if (!fListCalibType->FindEntry(type.Data())) {
448 fListCalibType->AddEntry(type,id);
449 fListCalibType->Select(id++);
450 }
451 }
452 //add type for unspecified calibration type
453 type="UNSPECIFIED";
454 if (!fListCalibType->FindEntry(type.Data())) {
455 fListCalibType->AddEntry(SubstituteUnderscores(type.Data()),id);
456 fListCalibType->Select(id++);
457 }
458}
459//______________________________________________________________________________
460void AliTPCCalibViewerGUItime::Reload(Int_t first){
461 //
462 // reload the gui contents, this is needed after the input tree has changed
463 //
464
465 if ( !fTree ) return;
466 //in case of the first call create run type and calibration type entries
467 if (first){
468 FillRunTypes();
469 FillCalibTypes();
470 }
471 //activate all branches
472 fTree->SetBranchStatus("*",1);
473 //reset variables list
474 fListVariables->RemoveAll();
475 //get selected calibration types
476 TList calibTypes;
477 fListCalibType->GetSelectedEntries(&calibTypes);
478
479 TObjArray *branchList = fTree->GetListOfBranches();
480 if ( !branchList ) return;
481 TIter nextBranch(branchList);
482 Int_t idCount=0,id=0;
483 TObject *objBranch=0;
484 while ( (objBranch=nextBranch()) ){
485 TString branchName(objBranch->GetName());
486 TString branchTitle(objBranch->GetName());
487 if (branchName == "run" || branchName == "time" || branchName == "runType.") continue;
488 Bool_t active=kTRUE;
489 TString calibType="UNSPECIFIED";
490 if (fConfigParser){
491 const TObject *key=(*fConfigParser)(branchName.Data());
492 if (key){
493 //test if branch is active
494 active=fConfigParser->GetValue(branchName.Data(),kBranchOnOff);
495 id=(*fConfigParser)()->IndexOf(key);
496 branchTitle=fConfigParser->GetData(key,kBranchTitle);
497 calibType=fConfigParser->GetData(key,kCalibType);
498 }
499 else{
500 id=1000+idCount;
501 }
502 } else {
503 id=idCount;
504 }
505 //check if branch is in selected calibration types
506 //if not, don't show it in the list and deactivate the branch.
507 Bool_t calibActive=kFALSE;
508 TIter nextCalib(&calibTypes);
509 TObject *objCalib=0;
510 while (objCalib=nextCalib())
511 if (calibType==objCalib->GetTitle()) calibActive=kTRUE;
512 active&=calibActive;
513 if (!active){
514 TString s=branchName;
515 if (branchName.EndsWith(".")) s+="*";
516 fTree->SetBranchStatus(s.Data(),0);
517 continue;
518 }
519 fListVariables->AddEntry(SubstituteUnderscores(branchTitle.Data()),id);
520 ++idCount;
521 }
522 //trick to display modifications
523 if (!first){
524 fListVariables->Resize(fListVariables->GetWidth()-1, fListVariables->GetHeight());
525 fListVariables->Resize(fListVariables->GetWidth()+1, fListVariables->GetHeight());
526 }
527}
528//______________________________________________________________________________
5312f439 529const char* AliTPCCalibViewerGUItime::GetDrawString(){
530 //
531 // create draw string for ttree by combining the user requestsa
532 //
533
534 TString selectedVariable="";
6fb51ca4 535 Int_t id=-1;
536 if (!fListVariables->GetSelectedEntry()) return "";
537 selectedVariable = fListVariables->GetSelectedEntry()->GetTitle();
538 id=fListVariables->GetSelectedEntry()->EntryId();
539// printf("id: %d\n",id);
540 TString branchName=selectedVariable;
541 const TObject *key=(*fConfigParser)(id);
542 if (key) branchName=(*fConfigParser)(id)->GetName();
5312f439 543 //treat case of TVector
6fb51ca4 544 if (branchName.EndsWith(".")){
5312f439 545 Int_t par = (Int_t)(fNmbPar->GetNumber());
6fb51ca4 546 branchName.Append(Form("fElements[%d]",par));
5312f439 547 }
548// if (fRadioXrun->GetState()==kButtonDown)
549// selectedVariable.Append(":run");
550// if (fRadioXtime->GetState()==kButtonDown)
551// selectedVariable.Append(":time");
552
6fb51ca4 553 return branchName.Data();
5312f439 554}
555//______________________________________________________________________________
556const char* AliTPCCalibViewerGUItime::GetCutString(){
557 //
558 // create cut string
559 //
560 TCut cuts(fComboCustomCuts->GetTextEntry()->GetText());
561 TString runType="";
562 if (fComboRunType->GetSelectedEntry()) runType=fComboRunType->GetSelectedEntry()->GetTitle();
563 if (runType!="ALL"&&!runType.IsNull()) cuts+=Form("runType.String().Data()==\"%s\"",runType.Data());
564 return cuts.GetTitle();
565}
566//______________________________________________________________________________
567void AliTPCCalibViewerGUItime::DoDraw() {
568 TString drawString=fDrawString;
569 drawString.Prepend("run:time:");
570 TString cutString = GetCutString();
571 TString optString = "goff";
572 TVirtualPad *padsave=gPad;
573 fCanvMain->GetCanvas()->cd();
574 //delete old histogram and graph
575 if (fCurrentGraph) {
576 delete fCurrentGraph;
577 fCurrentGraph=0x0;
578 //fCurrentHist in case of graph is the internal histogram,
579 // which is deletet by the graph itself.
580 fCurrentHist=0x0;
581 }
582 if (fCurrentHist) delete fCurrentHist;
583 //select data
584 fTree->Draw(drawString.Data(),cutString.Data(),optString.Data());
585 if (fTree->GetSelectedRows()==-1) return;
586 fValuesX.ResizeTo(fTree->GetSelectedRows());
587 fValuesY.ResizeTo(fTree->GetSelectedRows());
588 fRunNumbers.ResizeTo(fTree->GetSelectedRows());
589 fTimeStamps.ResizeTo(fTree->GetSelectedRows());
590 fValuesY.SetElements(fTree->GetV3());
591 fRunNumbers.SetElements(fTree->GetV1());
592 fTimeStamps.SetElements(fTree->GetV2());
593 TString title="";
594 Bool_t drawGraph=kFALSE;
595 if (fIsCustomDraw){
596 if (fDrawString.Contains(":")){
597 fValuesX.SetElements(fTree->GetV4());
598 TString yname=fDrawString(0,fDrawString.First(':'));
599 TString xname=fDrawString(fDrawString.First(':')+1,fDrawString.Length());
600 title=Form("%s;%s;%s",fDrawString.Data(),xname.Data(),yname.Data());
601 drawGraph=kTRUE;
602 } else {
603 drawGraph=kFALSE;
604 }
605 }else{
606 drawGraph=kTRUE;
6fb51ca4 607 TString yname=fDrawString.Data();
608 if (fConfigParser ){
609 Int_t id=fListVariables->GetSelectedEntry()->EntryId();
610 if ((*fConfigParser)(id)) yname=fConfigParser->GetData((*fConfigParser)(id),kBranchTitle);
611 yname=SubstituteUnderscores(yname.Data());
612 if (fNmbPar->GetButtonUp()->GetState()!=kButtonDisabled){
613 yname+=": ";
614 Int_t par = (Int_t)(fNmbPar->GetNumber());
615 if (fConfigParser && (*fConfigParser)(id)) {
616 TString yparname=fConfigParser->GetData((*fConfigParser)(id),par+kParamNames);
617 yparname=SubstituteUnderscores(yparname);
618 yname+=yparname;
619 }
620 }
621 }
5312f439 622 if (fRadioXrun->GetState()==kButtonDown){
623 fValuesX.SetElements(fTree->GetV1());
6fb51ca4 624 title=Form("%s:Run;Run;%s",fDrawString.Data(),yname.Data());
5312f439 625 } else if (fRadioXtime->GetState()==kButtonDown){
626 fValuesX.SetElements(fTree->GetV2());
6fb51ca4 627 title=Form("%s:Time;Time;%s",fDrawString.Data(),yname.Data());
5312f439 628 } else {
629 drawGraph=kFALSE;
630 }
631 }
632 //create graph according to selection
633 if (drawGraph){
634 fCurrentGraph=new TGraph(fValuesX,fValuesY);
635 fCurrentGraph->Draw("alp");
636 fCurrentHist=fCurrentGraph->GetHistogram();
637 fCurrentHist->SetTitle(title.Data());
638 } else {
639 fCurrentGraph=0x0;
640 Float_t add=TMath::Abs(fValuesY.Min()*.05);
641 fCurrentHist=new TH1D("hist",Form("%s;%s",fDrawString.Data(),fDrawString.Data()),100,fValuesY.Min()-add,fValuesY.Max()+add);
642 fCurrentHist->FillN(fValuesY.GetNrows(),fValuesY.GetMatrixArray(),0);
643 fCurrentHist->Draw();
644 }
645
5312f439 646 //Set time axis if choosen as x-variables
647 if (fRadioXtime->GetState()==kButtonDown&&!fIsCustomDraw){
648 TAxis *xaxis=fCurrentHist->GetXaxis();
649 xaxis->SetTimeFormat("#splitline{%d.%m}{%H:%M}");
650 xaxis->SetTimeDisplay(1);
651 xaxis->SetLabelOffset(xaxis->GetLabelOffset()*3);
652 xaxis->SetLabelSize(xaxis->GetLabelSize()/1.3);
653 }
654 if (fCurrentGraph){
655 fCurrentGraph->SetEditable(kFALSE);
656 fCurrentGraph->SetMarkerStyle(20);
657 fCurrentGraph->SetMarkerSize(0.5);
658 }
6fb51ca4 659 //Set title offset
660 fCurrentHist->GetYaxis()->SetTitleOffset(1.5);
5312f439 661 gPad->Modified();
662 gPad->Update();
663 padsave->cd();
664}
665
666//______________________________________________________________________________
667void AliTPCCalibViewerGUItime::DoDumpRuns()
668{
669 //
670 // Dump the current run numbers to stdout
671 //
6fb51ca4 672 Int_t npoints=fRunNumbers.GetNrows();
673 Int_t *sortIndex = new Int_t[npoints];
674 TMath::Sort(npoints,fRunNumbers.GetMatrixArray(),sortIndex,kFALSE);
675 Int_t run=0, prevRun=-1;
676
677 for (Int_t irun=0;irun<npoints;++irun){
678 run=(Int_t)fRunNumbers.GetMatrixArray()[sortIndex[irun]];
679 if (run!=prevRun) std::cout << Form("%d",run) << std::endl;
680 prevRun=run;
5312f439 681 }
6fb51ca4 682 delete sortIndex;
5312f439 683}
684//______________________________________________________________________________
685void AliTPCCalibViewerGUItime::DoParLimitChange()
686{
687 //
688 //
689 //
6fb51ca4 690 UpdateParName();
5312f439 691 DoDraw();
692}
693//______________________________________________________________________________
694void AliTPCCalibViewerGUItime::DoNewSelection() {
695 //
696 // decides whether to redraw if user makes another selection
697 //
698 UpdateParLimits();
699 fDrawString=GetDrawString();
700 fIsCustomDraw=kFALSE;
701 DoDraw();
702}
703//______________________________________________________________________________
704void AliTPCCalibViewerGUItime::DoCustomDraw()
705{
706 //
707 //
708 //
709 fDrawString=fComboCustomDraw->GetTextEntry()->GetText();
710 if (fDrawString.Contains(">>")){
711 Warning("DoCustomDraw","Currently no user defined histograms allowed!");
712 return;
713 }
714 fIsCustomDraw=kTRUE;
715 DoDraw();
716}
717//______________________________________________________________________________
718void AliTPCCalibViewerGUItime::DoCustomCutsDraw()
719{
720 //
721 //
722 //
723 if (fIsCustomDraw) DoCustomDraw();
724 else {
725 fDrawString=GetDrawString();
726 fIsCustomDraw=kFALSE;
727 DoDraw();
728 }
729}
730//______________________________________________________________________________
731void AliTPCCalibViewerGUItime::HandleButtonsDrawSel(Int_t id)
732{
733 //
734 // Draw selection button handling (x-variable)
735 //
736
737 if (id == -1) {
738 TGButton *btn = (TGButton *) gTQSender;
739 id = btn->WidgetId();
740 }
741
742 Bool_t doDraw=kFALSE;
743 switch (id) {
744 case (kRadioXhist):
745 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
746 if (doDraw){
747 fRadioXrun->SetState(kButtonUp);
748 fRadioXtime->SetState(kButtonUp);
749 }
750 break;
751 case (kRadioXrun):
752 doDraw=(fRadioXtime->GetState()==kButtonDown||fRadioXhist->GetState()==kButtonDown);
753 if (doDraw){
754 fRadioXhist->SetState(kButtonUp);
755 fRadioXtime->SetState(kButtonUp);
756 }
757 break;
758 case (kRadioXtime):
759 doDraw=(fRadioXhist->GetState()==kButtonDown||fRadioXrun->GetState()==kButtonDown);
760 if (doDraw){
761 fRadioXrun->SetState(kButtonUp);
762 fRadioXhist->SetState(kButtonUp);
763 }
764 break;
765 }
6fb51ca4 766 if (doDraw) DoCustomCutsDraw();
5312f439 767}
6fb51ca4 768//______________________________________________________________________________
769void AliTPCCalibViewerGUItime::UpdateParName()
770{
771 //
772 // change parameter name
773 //
774
775 Int_t par = (Int_t)(fNmbPar->GetNumber());
776 TString parName=par;
777 Int_t id=fListVariables->GetSelectedEntry()->EntryId();
778 if (fConfigParser && (*fConfigParser)(id)) parName=fConfigParser->GetData((*fConfigParser)(id),par+kParamNames);
779 fLblPar->SetText(Form("Parameter: %s",parName.Data()));
780 fDrawString=GetDrawString();
781 fIsCustomDraw=kFALSE;
782}
783
5312f439 784//______________________________________________________________________________
785void AliTPCCalibViewerGUItime::UpdateParLimits()
786{
787 //
788 // Adjust limits for TVectorT based variables
789 //
790 if (!fTree) return;
6fb51ca4 791 TString selectedVariableTitle="";
792 Int_t id=-1;
793 if (!fListVariables->GetSelectedEntry()) return;
794 selectedVariableTitle = fListVariables->GetSelectedEntry()->GetTitle();
795 id=fListVariables->GetSelectedEntry()->EntryId();
796// printf("id: %d\n",id);
797 TString selectedVariable=selectedVariableTitle;
798 const TObject *key=(*fConfigParser)(id);
799 if (key) selectedVariable=(*fConfigParser)(id)->GetName();
800
5312f439 801 if (selectedVariable.IsNull()||!selectedVariable.EndsWith(".")) {
802 fNmbPar->SetState(kFALSE);
6fb51ca4 803 fLblPar->SetText("Parameter: none");
5312f439 804 return;
805 }
806 TVectorD *vD=0x0;
807 TVectorF *vF=0x0;
808 Int_t maxPar=0;
809 TBranch *branch=fTree->GetBranch(selectedVariable.Data());
810 TString branchClass=branch->GetClassName();
811 if (branchClass=="TVectorT<double>"){
812 branch->SetAddress(&vD);
813 fTree->GetEntry(0);
814 maxPar=vD->GetNrows();
815 } else if (branchClass=="TVectorT<float>"){
816 branch->SetAddress(&vF);
817 fTree->GetEntry(0);
818 maxPar=vF->GetNrows();
819 } else {
820 //class not known
821 fNmbPar->SetState(kFALSE);
822 return;
823 }
824 branch->ResetAddress();
825 fNmbPar->SetNumber(0);
826 fNmbPar->SetLimitValues(0,maxPar-1);
827 fNmbPar->SetState(kTRUE);
6fb51ca4 828 UpdateParName();
5312f439 829}
830//______________________________________________________________________________
6fb51ca4 831void AliTPCCalibViewerGUItime::MouseMove(Int_t event, Int_t x, Int_t y, TObject */*selected*/)
5312f439 832{
833 //
834 // handle mouse events in the draw canvas
835 //
5312f439 836 UInt_t dd=0,mm=0,yy=0,HH=0,MM=0,SS=0,run=0;
837 Double_t valx=0.,valy=0.;
838 if (!fCurrentGraph) {
839 fLblRunNumberVal->SetText(Form("%05u",run));
840 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u.%02u.%02u",dd,mm,yy,HH,MM,SS));
841 fLblValueXVal->SetText(Form("%.3f", valx));
842 fLblValueYVal->SetText(Form("%.3f", valy));
843 return;
844 }
845 TVirtualPad *padsave=gPad;
846 fCanvMain->GetCanvas()->cd();
847 Int_t n=fValuesY.GetNrows();
848 Double_t *arr=0x0;
849 arr=fValuesX.GetMatrixArray();
850
851 Int_t minDist=1000000;
852 Int_t minPoint=-1;
853 for (Int_t i=0;i<n;++i){
854 Int_t pxp = gPad->XtoAbsPixel(gPad->XtoPad(arr[i]));
855 Int_t pyp = gPad->YtoAbsPixel(gPad->YtoPad(fValuesY[i]));
6fb51ca4 856 Int_t d = TMath::Sqrt(TMath::Abs(pxp-x) + TMath::Abs(pyp-y));
5312f439 857 if (d < minDist) {
858 minDist = d;
859 minPoint = i;
860 }
861 }
862 if (minDist<2){
863 TTimeStamp t((Int_t)fTimeStamps[minPoint]);
864 t.GetDate(kTRUE,0,&yy,&mm,&dd);
865 t.GetTime(kTRUE,0,&HH,&MM,&SS);
866 run=(UInt_t)fRunNumbers[minPoint];
867 valx=fValuesX[minPoint];
868 valy=fValuesY[minPoint];
869 } else {
870 dd=0;mm=0;yy=0;HH=0;MM=0;SS=0;run=0;
871 valx=0.;
872 valy=0.;
873 }
874 fLblRunNumberVal->SetText(Form("%05u",run));
875 fLblRunTimeVal->SetText(Form("%02u.%02u.%04u\n%02u.%02u.%02u",dd,mm,yy,HH,MM,SS));
876 if (fIsCustomDraw){
877 fLblValueXVal->SetText(Form("%.3f", valx));
878 }else{
879 if (fRadioXrun->GetState()==kButtonDown){
880 fLblValueXVal->SetText("Run");
881 } else if (fRadioXtime->GetState()==kButtonDown){
882 fLblValueXVal->SetText("Time");
883 }
884 }
885 fLblValueYVal->SetText(Form("%.3f", valy));
886 padsave->cd();
887 if (run==0) return;
888 if (event == kButton1Double ){
889 SetGuiTree(run);
890 }
891 //find closes point of current selection
892}
893//______________________________________________________________________________
894void AliTPCCalibViewerGUItime::SetGuiTree(Int_t run)
895{
896 //
897 // create the AliTPCCalibViewerGUI tree for run
898 // cache tree in directory fOutputCacheDir
899 // retrieve file from this directory if it already exists
900 //
901
902 //try to find file for run in fOutputCacheDir
903 TString fileName=fOutputCacheDir;
904 if (!fileName.EndsWith("/")) fileName+="/";
905 fileName+=Form("guiTreeRun_%d.root",run);
906 TFile f(fileName.Data());
907 if (f.IsOpen()){
908 f.Close();
909 fCalibViewerGUI->Initialize(fileName.Data());
910 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %05d",run)));
911 return;
912 }
913 f.Close();
914 Bool_t sucess=AliTPCcalibDB::CreateGUITree(run,fileName.Data());
915 if (sucess){
916 fCalibViewerGUI->Initialize(fileName.Data());
917 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - %05d",run)));
918 }else{
919 fCalibViewerGUI->Reset();
920 if (fCalibViewerGUItab) fCalibViewerGUItab->SetText(new TGString(Form("Detail - XXXXX")));
921 }
922}
923//______________________________________________________________________________
6fb51ca4 924const char* AliTPCCalibViewerGUItime::SubstituteUnderscores(const char* in)
925{
926 //
927 //
928 //
929 TString s(in);
930 s.ReplaceAll("_{","|{");
931 s.ReplaceAll("_"," ");
932 s.ReplaceAll("|{","_{");
933 return s.Data();
934}
935//______________________________________________________________________________
5312f439 936TObjArray* AliTPCCalibViewerGUItime::ShowGUI(const char* fileName) {
937 //
938 // Initialize and show GUI for presentation for demonstration purposes
939 // or for fast standalone use
940 //
941 TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
942 frmMain->SetWindowName("AliTPCCalibViewer GUItime");
943 frmMain->SetCleanup(kDeepCleanup);
944
945 TGTab* tabMain = new TGTab(frmMain, 1000, 600);
946 frmMain->AddFrame(tabMain, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
947
948 TGCompositeFrame* tabCont1 = tabMain->AddTab("Time");
949 TGCompositeFrame* tabCont2 = tabMain->AddTab("Detail - XXXXX");
950
951 AliTPCCalibViewerGUItime* calibViewerTime = new AliTPCCalibViewerGUItime(tabCont1, 1000, 600);
952 tabCont1->AddFrame(calibViewerTime, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
953 calibViewerTime->UseFile(fileName);
954
955 AliTPCCalibViewerGUI* calibViewer = new AliTPCCalibViewerGUI(tabCont2, 1000, 600, 0);
956 tabCont2->AddFrame(calibViewer, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
957 calibViewerTime->SetCalibViewerGUI(calibViewer);
958 calibViewerTime->SetCalibViewerGUItab(tabMain->GetTabTab(1));
959
960
961 TObjArray *guiArray = new TObjArray();
962 guiArray->Add(calibViewerTime);
963 guiArray->Add(calibViewer);
964
965 frmMain->MapSubwindows();
966 frmMain->Resize();
967 frmMain->MapWindow();
968
969 return guiArray;
970}
971