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