]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveDet/AliEveTRDTrackListEditor.cxx
Changes for bug #70680: AliROOT Coverity DELETE_ARRAY checker fix
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveTRDTrackListEditor.cxx
CommitLineData
c1869a7c 1// Author: Benjamin Hess 29/01/2010
2670605d 2
3/*************************************************************************
c1869a7c 4 * Copyright (C) 2009-2010, Alexandru Bercuci, Benjamin Hess. *
2670605d 5 * All rights reserved. *
6 *************************************************************************/
7
16db6074 8//////////////////////////////////////////////////////////////////////////
9// //
2670605d 10// AliEveTRDTrackListEditor //
11// //
16db6074 12// The AliEveTRDTrackListEditor provides the graphical functionality //
13// for the AliEveTRDTrackList. It creates the tabs and canvases, when //
14// they are needed and, as well, frees allocated memory on destruction //
15// (or if new events are loaded and thus some tabs are closed). //
16// The function DrawHistos() accesses the temporary file created by the //
17// AliEveTRDTrackList and draws the desired data (the file will be //
18// created within the call of ApplyMacros()). Have a look at this //
19// function to learn more about the structure of the file and how to //
20// access the data. //
16db6074 21//////////////////////////////////////////////////////////////////////////
22
8bdeb570 23#include <EveDet/AliEveTRDData.h>
24#include <EveDet/AliEveTRDTrackList.h>
25#include "AliEveTRDTrackListEditor.h"
2ef0687e 26
8bdeb570 27#include <EveBase/AliEveEventManager.h>
28#include <AliTRDReconstructor.h>
29#include <AliTRDtrackV1.h>
caaf90d2 30#include <TGButton.h>
8e27fca1 31#include <TCanvas.h>
4f6473f6 32#include <TEveBrowser.h>
8e27fca1 33#include <TEveGedEditor.h>
caaf90d2 34#include <TEveMacro.h>
35#include <TEveManager.h>
8e27fca1 36#include <TFile.h>
37#include <TG3DLine.h>
4cbab605 38#include <TGButtonGroup.h>
8e27fca1 39#include <TGFileDialog.h>
40#include <TGLabel.h>
41#include <TGListBox.h>
42#include <TGMsgBox.h>
43#include <TGTab.h>
38a30030 44#include <TMap.h>
caaf90d2 45#include <TObjString.h>
caaf90d2 46#include <TROOT.h>
8e27fca1 47#include <TSystem.h>
48#include <TGTextEntry.h>
db16b708 49#include <TGTextEdit.h>
50#include <TGComboBox.h>
8e27fca1 51#include <TGTextView.h>
bcb45225 52#include <TH1.h>
8e27fca1 53#include <TTreeStream.h>
54
caaf90d2 55
2ef0687e 56ClassImp(AliEveTRDTrackListEditor)
57
58///////////////////////////////////////////////////////////
59///////////// AliEveTRDTrackListEditor //////////////////
60///////////////////////////////////////////////////////////
61AliEveTRDTrackListEditor::AliEveTRDTrackListEditor(const TGWindow* p, Int_t width, Int_t height,
62 UInt_t options, Pixel_t back) :
63 TGedFrame(p, width, height, options, back),
64 fM(0),
4f6473f6 65 fHistoCanvas(0),
66 fHistoCanvasName(0),
38a30030 67 fInheritedMacroList(0),
8bdeb570 68 fInheritSettings(kFALSE),
ecbbe371 69 fStyleFrame(0),
2ef0687e 70 fMainFrame(0),
caaf90d2 71 fHistoFrame(0),
72 fHistoSubFrame(0),
2ef0687e 73 fBrowseFrame(0),
4cbab605 74 fbgStyleColor(0),
75 fbgStyleTrack(0),
76 frbColor(new TGRadioButton*[3]),
77 frbTrack(new TGRadioButton*[3]),
caaf90d2 78 fbBrowse(0),
db16b708 79 fbNew(0),
caaf90d2 80 fbApplyMacros(0),
81 fbRemoveMacros(0),
82 fbDrawHisto(0),
83 fteField(0),
84 ftlMacroList(0),
85 ftlMacroSelList(0),
86 fFileInfo(0),
87 fFileTypes(0),
88 fLabel1(0), fLabel2(0), fLabel3(0), fLabel4(0),
4cbab605 89 fLine1(0), fLine2(0), fLine3(0), fLine4(0), fLine5(0),
caaf90d2 90 fCheckButtons(0)
4cbab605 91{
16db6074 92 // Creates the AliEveTRDTrackListEditor.
93
4cbab605 94 // Style stuff
95 fLine5 = new TGHorizontal3DLine(this, 194, 8);
96 AddFrame(fLine5, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 8));
ecbbe371 97 fStyleFrame = new TGHorizontalFrame(this);
98 AddFrame(fStyleFrame);
4cbab605 99
100 // Style - Track model
ecbbe371 101 fbgStyleTrack = new TGButtonGroup(fStyleFrame, "Track model");
4cbab605 102 fbgStyleTrack->SetMapSubwindows(kTRUE);
103 fbgStyleTrack->Resize(194, 200);
ecbbe371 104 fStyleFrame->AddFrame(fbgStyleTrack);
4cbab605 105
ecbbe371 106 frbTrack[0] = new TGRadioButton(fbgStyleTrack, "Rieman", 0);
2670605d 107 frbTrack[0]->SetToolTipText("Set the track model to \"Rieman\" (i.e. the used fit method)");
ecbbe371 108 frbTrack[1] = new TGRadioButton(fbgStyleTrack, "Kalman", 1);
2670605d 109 frbTrack[1]->SetToolTipText("Set the track model to \"Kalman\" (i.e. the used fit method)");
ecbbe371 110 frbTrack[2] = new TGRadioButton(fbgStyleTrack, "Line", 2);
2670605d 111 frbTrack[2]->SetToolTipText("Set the track model to \"Line\" (i.e. the used fit method)");
4cbab605 112
113 // Style - Color model
8bdeb570 114 fbgStyleColor = new TGButtonGroup(fStyleFrame, "Color model");
4cbab605 115 fbgStyleColor->SetMapSubwindows(kTRUE);
116 fbgStyleColor->Resize(194, 200);
ecbbe371 117 fStyleFrame->AddFrame(fbgStyleColor);
4cbab605 118
ecbbe371 119 frbColor[0] = new TGRadioButton(fbgStyleColor, "PID LQ", 0);
2670605d 120 frbColor[0]->SetToolTipText("Set color model to \"PID LQ\" -> 2 dimensional likelihood particle identification");
ecbbe371 121 frbColor[1] = new TGRadioButton(fbgStyleColor, "PID NN", 1);
2670605d 122 frbColor[1]->SetToolTipText("Set color model to \"PID NN\" -> Neural network particle identification");
ecbbe371 123 frbColor[2] = new TGRadioButton(fbgStyleColor, "ESD Source", 2);
2670605d 124 frbColor[2]->SetToolTipText("Set color model to \"ESD Source\" -> By source (TPC track prolongation or TRD stand alone)");
4cbab605 125
c1869a7c 126 // Functionality for adding plugins
db16b708 127 fMainFrame = CreateEditorTabSubFrame("Process");
4cbab605 128
c1869a7c 129 fLabel1 = new TGLabel(fMainFrame,"Add plugin(s):");
3f797131 130 fMainFrame->AddFrame(fLabel1);
2ef0687e 131 fBrowseFrame = new TGHorizontalFrame(fMainFrame);
132
caaf90d2 133 fteField = new TGTextEntry(fBrowseFrame);
8bdeb570 134 fteField->SetToolTipText("Enter the pathname of the macro you want to add here and press \"Enter\"");
caaf90d2 135 fteField->Connect("ReturnPressed()","AliEveTRDTrackListEditor", this, "HandleMacroPathSet()");
136 fBrowseFrame->AddFrame(fteField);
2ef0687e 137
caaf90d2 138 fbBrowse = new TGTextButton(fBrowseFrame, "Browse");
8bdeb570 139 fbBrowse->SetToolTipText("Browse the macro you want to add");
caaf90d2 140 fbBrowse->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "BrowseMacros()");
141 fBrowseFrame->AddFrame(fbBrowse);
db16b708 142
143 fbNew = new TGTextButton(fBrowseFrame, "New");
00dc25ef 144 fbNew->SetToolTipText("Start macro creation wizard");
db16b708 145 fbNew->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "NewMacros()");
146 fBrowseFrame->AddFrame(fbNew);
2ef0687e 147 fMainFrame->AddFrame(fBrowseFrame);
148
3f797131 149 fLine1 = new TGHorizontal3DLine(fMainFrame, 194, 8);
caaf90d2 150 fMainFrame->AddFrame(fLine1, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
c1869a7c 151 fLabel2 = new TGLabel(fMainFrame,"Selection plugins:");
3f797131 152 fMainFrame->AddFrame(fLabel2);
153
caaf90d2 154 ftlMacroSelList = new TGListBox(fMainFrame);
155 ftlMacroSelList->Resize(194, 94);
156 ftlMacroSelList->SetMultipleSelections(kTRUE);
157 fMainFrame->AddFrame(ftlMacroSelList);
3f797131 158
159 fLine2 = new TGHorizontal3DLine(fMainFrame, 194, 8);
caaf90d2 160 fMainFrame->AddFrame(fLine2, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
db16b708 161 fLabel3 = new TGLabel(fMainFrame,"Process plugins:");
3f797131 162 fMainFrame->AddFrame(fLabel3);
163
caaf90d2 164 ftlMacroList = new TGListBox(fMainFrame);
165 ftlMacroList->Resize(194, 94);
166 ftlMacroList->SetMultipleSelections(kTRUE);
167 fMainFrame->AddFrame(ftlMacroList);
2ef0687e 168
3f797131 169 fLine3 = new TGHorizontal3DLine(fMainFrame, 194, 8);
caaf90d2 170 fMainFrame->AddFrame(fLine3, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
3f797131 171
db16b708 172 fbApplyMacros = new TGTextButton(fMainFrame, "Apply plugin(s)");
173 fbApplyMacros->SetToolTipText("Apply all selected macros/class functins to the list of tracks -> A data file will be generated");
caaf90d2 174 fbApplyMacros->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "ApplyMacros()");
175 fbApplyMacros->SetRightMargin(12);
176 fMainFrame->AddFrame(fbApplyMacros);
2ef0687e 177
db16b708 178 fbRemoveMacros = new TGTextButton(fMainFrame, "Remove plugin(s)");
179 fbRemoveMacros->SetToolTipText("Remove the selected macros/class functions from the list(s)");
caaf90d2 180 fbRemoveMacros->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "RemoveMacros()");
181 fMainFrame->AddFrame(fbRemoveMacros);
2ef0687e 182
caaf90d2 183 // Stuff for displaying histograms
db16b708 184 fHistoFrame = CreateEditorTabSubFrame("Results");
caaf90d2 185 fHistoFrame->SetMapSubwindows(kTRUE);
db16b708 186 fLabel4 = new TGLabel(fHistoFrame,"Data from plugins:");
caaf90d2 187 fHistoFrame->AddFrame(fLabel4);
188
189 fHistoSubFrame = new TGVerticalFrame(fHistoFrame);
190 fHistoSubFrame->SetMapSubwindows(kTRUE);
191 fHistoSubFrame->Resize(194, 200);
192 fHistoFrame->AddFrame(fHistoSubFrame);
193
194 fLine4 = new TGHorizontal3DLine(fHistoFrame, 194, 8);
195 fHistoFrame->AddFrame(fLine4, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
196
db16b708 197 fbDrawHisto = new TGTextButton(fHistoFrame, "Draw projections");
c1869a7c 198 fbDrawHisto->SetToolTipText("Uses the data file created by the last \"Apply selected plugin(s)\".\nClick here to display the data histograms of the selected macros.\nSelect multiple macros to create multi-dimensional plots.\nHisto macros cannot be used for multi-dimensional plots!");
caaf90d2 199 fbDrawHisto->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "DrawHistos()");
200 fHistoFrame->AddFrame(fbDrawHisto);
2ef0687e 201
202 // Set up file dialog
caaf90d2 203 fFileInfo = new TGFileInfo();
204 fFileInfo->SetMultipleSelection(kTRUE);
205
206 fFileTypes = new Char_t*[6];
207 fFileTypes[0] = (Char_t*)"All files"; fFileTypes[1] = (Char_t*)"*";
208 fFileTypes[2] = (Char_t*)"ROOT macros"; fFileTypes[3] = (Char_t*)"*.C";
209 fFileTypes[4] = 0; fFileTypes[5] = 0;
210 fFileInfo->fFileTypes = (const Char_t**)fFileTypes;
211 fFileInfo->fFileTypeIdx = 2;
212 fFileInfo->fMultipleSelection = kTRUE;
4f6473f6 213
214 fHistoCanvasName = new TGString("");
215
4cbab605 216 // Handle style changed signals:
217 fbgStyleTrack->Connect("Clicked(Int_t)", "AliEveTRDTrackListEditor", this, "SetTrackModel(Int_t)");
218 fbgStyleColor->Connect("Clicked(Int_t)", "AliEveTRDTrackListEditor", this, "SetTrackColor(Int_t)");
219
4f6473f6 220 // Handle the signal "Selected(Int_t ind)"
221 ftlMacroList->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor", this, "UpdateMacroListSelection(Int_t)");
38a30030 222 ftlMacroSelList->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor", this, "UpdateMacroListSelection(Int_t)");
4f6473f6 223
224 // Handle the signal "NewEventLoaded"
4d62585e 225 AliEveEventManager::GetMaster()->Connect("NewEventLoaded()", "AliEveTRDTrackListEditor", this, "HandleNewEventLoaded()");
4f6473f6 226
227 // Handle the signal "Selected" (another tab has been selected)
db16b708 228 GetGedEditor()->GetTab()->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor", this, "HandleTabChangedToIndex(Int_t)");
2ef0687e 229}
230
c04e790a 231//______________________________________________________
caaf90d2 232AliEveTRDTrackListEditor::~AliEveTRDTrackListEditor()
3f797131 233{
16db6074 234 // Destructor: Closes all tabs created by this object and
235 // frees the corresponding memory.
236
caaf90d2 237 if (fFileTypes != 0)
39b891ff 238 {
caaf90d2 239 delete [] fFileTypes;
240 fFileTypes = 0;
2ef0687e 241 }
3f797131 242
caaf90d2 243 if (fFileInfo != 0)
39b891ff 244 {
caaf90d2 245 delete fFileInfo;
246 fFileInfo = 0;
39b891ff 247 }
4f6473f6 248 // Close and delete all tabs that have been created by this class
249 CloseTabs();
250
251 if (fHistoCanvasName != 0)
252 {
253 delete fHistoCanvasName;
254 fHistoCanvasName = 0;
255 }
38a30030 256 if (fInheritedMacroList != 0)
257 {
258 fInheritedMacroList->Delete();
259 delete fInheritedMacroList;
260 fInheritedMacroList = 0;
261 }
caaf90d2 262}
263
c04e790a 264//______________________________________________________
db16b708 265void AliEveTRDTrackListEditor::AddMacro(const Char_t* name, const Char_t* path)
caaf90d2 266{
16db6074 267 // Adds the macro path/name to the macro list. A warning is provided, if there is
268 // something wrong, e.g. if the macro does not have the correct signature.
caaf90d2 269 Int_t result = fM->AddMacro(path, name);
270
271 switch (result)
39b891ff 272 {
caaf90d2 273 case SUCCESS:
274 UpdateMacroList();
275 break;
276 case WARNING:
39b891ff 277 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Warning", "Macro is already in list (won't be added again)!",
278 kMBIconExclamation, kMBOk);
caaf90d2 279 break;
db16b708 280 case ERROR:
c1869a7c 281 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", "Failed to load the macro (check messages in the terminal)!",
db16b708 282 kMBIconExclamation, kMBOk);
283 break;
caaf90d2 284 case SIGNATURE_ERROR:
285 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
2f9b41fd 286 "Macro has not the signature of...\n...a single track selection macro: Bool_t YourMacro(const AliTRDtrackV1*)\n...a correlated tracks selection macro: Bool_t YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*)\n...a single track analyse macro: void YourMacro(const AliTRDtrackV1*, Double_t*&, Int_t&)\n...a correlated tracks analyse macro: void YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*, Double_t*&, Int_t&)\n...a single track histo macro: TH1* YourMacro(const AliTRDtrackV1*)\n...a correlated tracks histo macro: TH1* YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*)",
caaf90d2 287 kMBIconExclamation, kMBOk);
288 break;
289 case NOT_EXIST_ERROR:
290 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
291 "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
292 break;
293 default:
294 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
295 Form("AliEveTRDTrackList::AddMacro exited with unknown return value: %d", result),
296 kMBIconExclamation, kMBOk);
297 break;
2ef0687e 298 }
299}
300
c04e790a 301//______________________________________________________
2ef0687e 302void AliEveTRDTrackListEditor::ApplyMacros()
303{
16db6074 304 // Applies the selected macros and updates the view.
305
ea24e1bc 306 Bool_t success = kFALSE;
307
2670605d 308 // First apply the single track selection macros
309 TList* selIterator = new TList();
310 ftlMacroSelList->GetSelectedEntries(selIterator);
311 fM->ApplySTSelectionMacros(selIterator);
caaf90d2 312
39b891ff 313 // Update view
314 gEve->Redraw3D();
39b891ff 315
3f797131 316 // Now apply the process macros
2670605d 317 TList* procIterator = new TList();
318 ftlMacroList->GetSelectedEntries(procIterator);
319 success = fM->ApplyProcessMacros(selIterator, procIterator);
2ef0687e 320
caaf90d2 321 // Update histogram tab (data has to be reloaded)
322 SetModel(fM);
323 Update();
2ef0687e 324
bcb45225 325 // AlieveTRDTrackList::ApplyProcessMacros() automatically selects a macro -> Draw the histogram for it,
326 // if a process macro has been applied
2670605d 327 if (success && procIterator->GetEntries() > 0)
4f6473f6 328 {
329 // Set focus on "Histograms" tab
db16b708 330 GetGedEditor()->GetTab()->SetTab("Results");
4f6473f6 331
332 DrawHistos();
333 }
bcb45225 334
2670605d 335 if (selIterator != 0) delete selIterator;
336 selIterator = 0;
337 if (procIterator != 0) delete procIterator;
338 procIterator = 0;
ea24e1bc 339
340 if (!success)
341 {
342 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
343 "AliEveTRDTrackList::ApplyProcessMacros experienced an error (cf. CINT-output)!",
344 kMBIconExclamation, kMBOk);
345 }
8e27fca1 346}
c04e790a 347
db16b708 348//______________________________________________________
349void AliEveTRDTrackListEditor::NewMacros()
350{
00dc25ef 351 // Start the macro creation wizard.
db16b708 352 // thanks to Jacek Otwinowski<J.Otwinowski@GSI.DE> for this suggestion
353
00dc25ef 354 AliEveTRDMacroWizard *wizz = new AliEveTRDMacroWizard();
57d55fae 355 wizz->Connect("Create(Char_t*)", "AliEveTRDTrackListEditor", this, "AddMacro(Char_t*)");
db16b708 356}
357
358
c04e790a 359//______________________________________________________
2ef0687e 360void AliEveTRDTrackListEditor::BrowseMacros()
361{
16db6074 362 // Creates a file-dialog. The selected files will be added to the macro list
363 // via AddMacro(...).
364
caaf90d2 365 new TGFileDialog(gClient->GetRoot(), GetMainFrame(), kFDOpen, fFileInfo);
2ef0687e 366
caaf90d2 367 if (fFileInfo->fIniDir != 0 && fFileInfo->fFileNamesList != 0)
3f797131 368 {
2ef0687e 369 // Extract filenames
caaf90d2 370 TObject* iter = fFileInfo->fFileNamesList->First();
2ef0687e 371
372 Char_t* name = 0;
373
374 while (iter != 0)
375 {
caaf90d2 376 // NOTE: fileInfo->fFileNamesList will be changed by that, too!
71f50468 377 name = (Char_t*)strrchr(iter->GetName(), '/');
2ef0687e 378 // Delete '"' at the end
379 name[strlen(name)] = '\0';
caaf90d2 380
db16b708 381 AddMacro(name + 1, fFileInfo->fIniDir);
caaf90d2 382 iter = (TObjString*)fFileInfo->fFileNamesList->After(iter);
2ef0687e 383 }
384 }
3f797131 385
caaf90d2 386 // -> The following problem has been fixed (trunk -> Changes according to 03 September 2008):
3f797131 387 // Some error occurs, when one ends the filedialog with "cancel": fileInfo->fFileNamesList is set to 0x0, but
388 // in the next launch no new memory is allocated. So do this manually.
caaf90d2 389 //if (fileInfo->fFileNamesList == 0) fileInfo->fFileNamesList = new TList();
390}
391
4f6473f6 392//______________________________________________________
393void AliEveTRDTrackListEditor::CloseTabs()
394{
16db6074 395 // Closes + deletes the tabs created by this object
396
4f6473f6 397 if (fHistoCanvas != 0)
398 {
399 // Close the created tab, if it exists
400 if (fHistoCanvasName != 0)
401 {
402 if (gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString()))
403 {
404 // Now the created tab is the current one and can be deleted
405 gEve->GetBrowser()->GetTab(1)->RemoveTab();
406 }
407 }
408 // With the tab removal, the canvas will be deleted automatically!
409 fHistoCanvas = 0;
410 }
411}
412
c04e790a 413//______________________________________________________
caaf90d2 414void AliEveTRDTrackListEditor::DrawHistos()
415{
16db6074 416 // Accesses the temporary data file created by the last call of ApplyMacros() and draws
417 // histograms according to the selection in the "Histograms"-tab.
418
caaf90d2 419 Int_t nHistograms = GetNSelectedHistograms();
420 if (nHistograms <= 0)
421 {
422 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
423 "No data selected. Please select the data you want to plot!", kMBIconExclamation, kMBOk);
424 return;
425 }
426 if (nHistograms > 3)
427 {
428 new TGMsgBox(gClient->GetRoot(), GetMainFrame(),
429 "Error", "Only histograms with up to 3 dimensions supported. Please select 1,2 or 3 data macros!",
430 kMBIconExclamation, kMBOk);
431 return;
432 }
433
bcb45225 434 // Check, if a histo macro shall be drawn
435 Int_t indexOfHistoMacro = -1;
436 Int_t selectedChecked = 0;
437 for (Int_t j = 0; j < fM->fDataFromMacroList->GetEntries(); j++)
438 {
439 if (fCheckButtons[j]->TGButton::GetState() == kButtonDown)
440 {
441 selectedChecked++;
442
8bdeb570 443 // Histo macro? -> To check this, look for the substring "(histo macro)"
444 if (strstr(fM->fDataFromMacroList->At(j)->GetName(), "(histo macro)") != 0)
bcb45225 445 {
446 // Is also another macro selected?
447 if (nHistograms > 1)
448 {
449 // Histo macros cannot(!) be correlated!
450 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
2f9b41fd 451 "Histo macros (return value \"TH1*\") cannot be combined with other macros",
bcb45225 452 kMBIconExclamation, kMBOk);
453 return;
454 }
455
456 // Mark this histo macro for drawing
457 indexOfHistoMacro = j;
458
459 // Have all selected macros been checked? -> If yes, we are done with this
460 if (selectedChecked == nHistograms) break;
461 }
462 }
463 }
464
8bdeb570 465 TFile* file = new TFile(Form("/tmp/TRD.TrackListMacroData_%s.root", gSystem->Getenv("USER")), "READ");
caaf90d2 466 if (!file)
467 {
8bdeb570 468 Error("Draw histograms", Form("Cannot open file \"/tmp/TRD.TrackListMacroData_%s.root\"",
469 gSystem->Getenv("USER")));
caaf90d2 470 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
8bdeb570 471 Form("Cannot open file \"/tmp/TRD.TrackListMacroData_%s.root\"", gSystem->Getenv("USER")),
472 kMBIconExclamation, kMBOk);
caaf90d2 473 return;
474 }
475
476 TTree* t = 0;
477 TTree* tFriend1 = 0;
478 TTree* tFriend2 = 0;
479
480 Int_t indexOfMacro1 = 0;
481 Int_t indexOfMacro2 = 0;
482 Int_t indexOfMacro3 = 0;
483
bcb45225 484 // Variable for the loop below -> Will be set to aborting value, if a histo macro is drawn
485 Int_t i = 0;
486
487 // Draw histo macro?
488 if (indexOfHistoMacro >= 0)
489 {
490 if ((t = (TTree*)file->Get(Form("TrackData%d", indexOfHistoMacro))))
491 {
492 SetDrawingToHistoCanvasTab();
493
494 TH1* myHist = 0;
495 t->SetBranchAddress(Form("Macro%d", indexOfHistoMacro), &myHist);
496 t->GetEntry(0);
497 if (myHist != 0) myHist->Draw();
498 else
499 {
500 Error("Draw histograms", Form("No histogram for histo macro \"%s\" found!",
501 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()));
502 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
503 Form("No histogram for histo macro \"%s\" found!",
504 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()), kMBIconExclamation, kMBOk);
505
506 }
507
5715955a 508 UpdateHistoCanvasTab();
bcb45225 509 }
510 else
511 {
2670605d 512 Error("Draw histograms", Form("No data for histo macro \"%s\" found!\nMaybe no tracks have been selected.",
bcb45225 513 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()));
514 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
2670605d 515 Form("No data for histo macro \"%s\" found!\nMaybe no tracks have been selected.",
bcb45225 516 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()), kMBIconExclamation, kMBOk);
517 }
518
519 // Skip the loop below
520 i = fM->fDataFromMacroList->GetEntries();
521 }
522
2f9b41fd 523 // Load the trees in succession and remember the entries -> Plot the analyse macros
bcb45225 524 for ( ; i < fM->fDataFromMacroList->GetEntries(); i++)
caaf90d2 525 {
526 if (fCheckButtons[i]->TGButton::GetState() == kButtonDown)
527 {
528 if (t == 0)
529 {
530 indexOfMacro1 = i;
531 if (!(t = (TTree*)file->Get(Form("TrackData%d", i))))
532 {
2670605d 533 Error("Draw histograms", Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.",
534 fM->fDataFromMacroList->At(i)->GetName()));
caaf90d2 535 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
2670605d 536 Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.",
537 fM->fDataFromMacroList->At(i)->GetName()), kMBIconExclamation, kMBOk);
caaf90d2 538 break;
539 }
bcb45225 540
2f9b41fd 541 // 1d histogram
caaf90d2 542 if (nHistograms == 1)
543 {
bcb45225 544 SetDrawingToHistoCanvasTab();
8bdeb570 545
bcb45225 546 t->Draw(Form("Macro%d", indexOfMacro1), "1");
547 ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s;%s",
548 fM->fDataFromMacroList->At(indexOfMacro1)->GetName(),
549 fM->fDataFromMacroList->At(indexOfMacro1)->GetName()));
8bdeb570 550 UpdateHistoCanvasTab();
caaf90d2 551
552 break;
553 }
554 }
555 else if (tFriend1 == 0)
556 {
557 indexOfMacro2 = i;
558 if (!(tFriend1 = (TTree*)file->Get(Form("TrackData%d", i))))
559 {
2670605d 560 Error("Draw histograms", Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.",
561 fM->fDataFromMacroList->At(i)->GetName()));
caaf90d2 562 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
2670605d 563 Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.",
564 fM->fDataFromMacroList->At(i)->GetName()),
bcb45225 565 kMBIconExclamation, kMBOk);
caaf90d2 566 break;
567 }
568
569 // 2d histogram
570 if (nHistograms == 2)
571 {
bcb45225 572 SetDrawingToHistoCanvasTab();
573
caaf90d2 574 t->AddFriend(tFriend1);
575 t->Draw(Form("Macro%d:Macro%d", indexOfMacro1, indexOfMacro2), "1");
bcb45225 576 ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s - %s;%s;%s",
577 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
578 fM->fDataFromMacroList->At(indexOfMacro1)->GetName(),
579 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
580 fM->fDataFromMacroList->At(indexOfMacro1)->GetName()));
4f6473f6 581
bcb45225 582 UpdateHistoCanvasTab();
caaf90d2 583
584 break;
585 }
586 }
587 // 3d histogram
588 else
589 {
590 indexOfMacro3 = i;
591 if (!(tFriend2 = (TTree*)file->Get(Form("TrackData%d", i))))
592 {
2670605d 593 Error("Draw histograms", Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.",
594 fM->fDataFromMacroList->At(i)->GetName()));
caaf90d2 595 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
2670605d 596 Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.",
597 fM->fDataFromMacroList->At(i)->GetName()), kMBIconExclamation, kMBOk);
caaf90d2 598 break;
599 }
4f6473f6 600
bcb45225 601 SetDrawingToHistoCanvasTab();
4f6473f6 602
caaf90d2 603 t->AddFriend(tFriend1);
604 t->AddFriend(tFriend2);
605 t->Draw(Form("Macro%d:Macro%d:Macro%d", indexOfMacro1, indexOfMacro2, indexOfMacro3), "1");
bcb45225 606 ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s - %s - %s;%s;%s;%s",
607 fM->fDataFromMacroList->At(indexOfMacro3)->GetName(),
608 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
609 fM->fDataFromMacroList->At(indexOfMacro1)->GetName(),
610 fM->fDataFromMacroList->At(indexOfMacro3)->GetName(),
611 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
612 fM->fDataFromMacroList->At(indexOfMacro1)->GetName()));
613
614 UpdateHistoCanvasTab();
caaf90d2 615
616 break;
617 }
618 }
619 }
620
621 if (t != 0) delete t;
622 t = 0;
623 if (tFriend1 != 0) delete tFriend1;
624 tFriend1 = 0;
625 if (tFriend2 != 0) delete tFriend2;
626 tFriend2 = 0;
627
628 file->Close("R");
629 delete file;
630 file = 0;
631}
632
c04e790a 633//______________________________________________________
2670605d 634Int_t AliEveTRDTrackListEditor::GetNSelectedHistograms() const
caaf90d2 635{
38a30030 636 // Returns the number of selected macros (or rather: of their selected data) in the "Histograms"-tab
16db6074 637
caaf90d2 638 Int_t count = 0;
639
640 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
641 {
642 if (fCheckButtons[i]->TGButton::GetState() == kButtonDown) count++;
643 }
644
645 return count;
2ef0687e 646}
647
c04e790a 648//______________________________________________________
2ef0687e 649void AliEveTRDTrackListEditor::HandleMacroPathSet()
650{
16db6074 651 // Takes the input of the text field (adding a macro), checks if the macro can be
652 // accessed (and that it exists) and adds the macro to the macro list via AddMacro(...).
653 // You can use environment variables in the text field, e.g. "$ALICE_ROOT/Eve/alice-macro/myMacro.C".
654
caaf90d2 655 if (strlen(fteField->GetText()) != 0)
5715955a 656 {
657 // Expand the pathname
658 Char_t* systemPath = gSystem->ExpandPathName(fteField->GetText());
659 fteField->SetText(systemPath);
660 delete systemPath;
661 systemPath = 0;
662
2ef0687e 663 // Check if file exists
664 FILE* fp = NULL;
665
caaf90d2 666 fp = fopen(fteField->GetText(), "rb");
39b891ff 667 if (fp != NULL)
668 {
3f797131 669 fclose(fp);
caaf90d2 670
3f797131 671 // Extract filename
71f50468 672 Char_t* name = (Char_t*)strrchr(fteField->GetText(), '/');
3f797131 673
674 // Current path
39b891ff 675 if (name == NULL)
676 {
4f6473f6 677 name = new Char_t[AliEveTRDTrackList::fkMaxMacroNameLength];
678 memset(name, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroNameLength);
caaf90d2 679 sprintf(name, "%s", fteField->GetText());
3f797131 680
4f6473f6 681 // Add path to textfield -> Path is "./" -> Use length for the name + 2
682 Char_t pathname[AliEveTRDTrackList::fkMaxMacroNameLength + 2];
683 memset(pathname, '\0', sizeof(Char_t) * (AliEveTRDTrackList::fkMaxMacroNameLength + 2));
caaf90d2 684 sprintf(pathname, "./%s", fteField->GetText());
685 fteField->SetText(pathname);
686
db16b708 687 AddMacro(name);
4ce766eb 688 if (name != 0) delete [] name;
caaf90d2 689 name = 0;
39b891ff 690 }
691 // Different path
692 else
693 {
3f797131 694 // Extract path
4f6473f6 695 Char_t* path = new Char_t[AliEveTRDTrackList::fkMaxMacroPathLength];
696 memset(path, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroPathLength);
caaf90d2 697 strncpy(path, fteField->GetText(), strlen(fteField->GetText()) - strlen(name));
698
699 // Ignore the slash "/" in name
db16b708 700 AddMacro(name + 1, path);
caaf90d2 701
702 if (path != 0) delete path;
703 path = 0;
704 }
39b891ff 705 }
706 else
707 {
3f797131 708 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
39b891ff 709 "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
2ef0687e 710 }
711 }
712}
713
4f6473f6 714//______________________________________________________
715void AliEveTRDTrackListEditor::HandleNewEventLoaded()
716{
16db6074 717 // Closes the tabs created by this object and sets a flag that will
718 // cause the function SetModel() to inherit the macro lists + style
719 // for the next AliEveTRDTrackList from the current one.
720
8bdeb570 721 // Inherit the macro list and track style for the next track list!
722 fInheritSettings = kTRUE;
bcb45225 723
724 // Close the tabs
4f6473f6 725 CloseTabs();
726}
727
728//______________________________________________________
729void AliEveTRDTrackListEditor::HandleTabChangedToIndex(Int_t index)
730{
16db6074 731 // Saves the current tab in the current AliEveTRDTrackList.
732
4f6473f6 733 fM->SetSelectedTab(index);
734}
735
bcb45225 736//______________________________________________________
737void AliEveTRDTrackListEditor::InheritMacroList()
738{
38a30030 739 // The old macro list is possibly stored in the corresponding interior map. This function will
740 // use this interior map to move the data from the interior map to the newly loaded AliEveTRDTrackList.
741 // Then the interior map will be cleaned up. With this, the settings will be inherited from the previously
742 // loaded AliEveTRDTrackList.
bcb45225 743
38a30030 744 if (fInheritedMacroList == 0) return;
745
746 // Clear list
bcb45225 747 fM->fMacroList->Delete();
38a30030 748
749 // Store data from interior list in the track list's map
750 TMapIter* iter = (TMapIter*)fInheritedMacroList->MakeIterator();
751
752 TObject* key = 0;
753 TMacroData* macro = 0;
754
755 while ((key = iter->Next()) != 0)
bcb45225 756 {
38a30030 757 macro = (TMacroData*)fInheritedMacroList->GetValue(key);
758 if (macro != 0) fM->fMacroList->Add(new TObjString(key->GetName()),
759 new TMacroData(macro->GetName(), macro->GetPath(), macro->GetType()));
760 else
761 {
c1869a7c 762 Error("AliEveTRDTrackListEditor::InheritMacroList", Form("Failed to inherit the macro \"%s\"!", key->GetName()));
38a30030 763 }
8bdeb570 764 }
38a30030 765
766 fInheritedMacroList->Delete();
767 delete fInheritedMacroList;
768 fInheritedMacroList = 0;
8bdeb570 769}
770
771//______________________________________________________
772void AliEveTRDTrackListEditor::InheritStyle()
773{
16db6074 774 // The old styles are stored in the corresponding button groups. This function will replace
775 // the style settings of the newly loaded AliEveTRDTrackList with the old styles. With this, the settings
776 // will be inherited from the previously loaded AliEveTRDTrackList.
8bdeb570 777
778 for (Int_t ind = 0; ind < 3; ind++)
779 {
780 if (fbgStyleTrack->GetButton(ind)->IsOn())
781 {
782 SetTrackModel(ind);
783 break;
784 }
785 }
786 for (Int_t ind = 0; ind < 3; ind++)
787 {
788 if (fbgStyleColor->GetButton(ind)->IsOn())
789 {
790 SetTrackColor(ind);
791 break;
792 }
bcb45225 793 }
794}
795
c04e790a 796//______________________________________________________
2ef0687e 797void AliEveTRDTrackListEditor::RemoveMacros()
798{
38a30030 799 // Removes the selected macros from the corresponding list.
16db6074 800
2ef0687e 801 TList* iterator = new TList();
802
caaf90d2 803 ftlMacroList->GetSelectedEntries(iterator);
38a30030 804 fM->RemoveSelectedMacros(iterator);
3f797131 805
caaf90d2 806 if (iterator != 0) delete iterator;
3f797131 807
caaf90d2 808 iterator = new TList();
809 ftlMacroSelList->GetSelectedEntries(iterator);
38a30030 810 fM->RemoveSelectedMacros(iterator);
2ef0687e 811
4f6473f6 812 // Selected macros are deleted from the list -> No selected entries left
813 fM->fMacroListSelected = 0;
4f6473f6 814
2ef0687e 815 UpdateMacroList();
caaf90d2 816
817 if (iterator != 0) delete iterator;
818 iterator = 0;
2ef0687e 819}
820
6e420565 821//______________________________________________________
822void AliEveTRDTrackListEditor::SaveMacroList(TMap* list)
823{
824 // Saves the provided macro list in an interior list. This list will be used by
825 // InheritMacroList() to restore the data in "list". With this method one is able
826 // to inherit the macro list from track list to track list (i.e. from event to event).
827
828 if (fInheritedMacroList != 0)
829 {
830 fInheritedMacroList->Delete();
831 delete fInheritedMacroList;
832 }
833 fInheritedMacroList = new TMap();
834 fInheritedMacroList->SetOwnerKeyValue(kTRUE, kTRUE);
835
836 TMapIter* iter = (TMapIter*)list->MakeIterator();
837 TObject* key = 0;
838 TMacroData* macro = 0;
839
840 while ((key = iter->Next()) != 0)
841 {
842 macro = (TMacroData*)fM->fMacroList->GetValue(key);
843 if (macro != 0) fInheritedMacroList->Add(new TObjString(key->GetName()),
844 new TMacroData(macro->GetName(), macro->GetPath(), macro->GetType()));
845 else
846 {
c1869a7c 847 Error("AliEveTRDTrackListEditor::SaveMacroList", Form("Failed to inherit the macro \"%s\"!", key->GetName()));
6e420565 848 }
849 }
850}
851
bcb45225 852//______________________________________________________
853void AliEveTRDTrackListEditor::SetDrawingToHistoCanvasTab()
854{
16db6074 855 // Sets gPad to the tab with the name of the current AliEveTRDTrackList. If this tab does
856 // not exist, it will be created. Otherwise, it is re-used.
857
bcb45225 858 // If the tab with the canvas has been closed, the canvas will be deleted.
859 // So, if there is no tab, set the canvas pointer to zero and recreate it in a new tab.
860 if (fHistoCanvas != 0)
861 {
862 if (gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString()) == 0)
863 {
864 fHistoCanvas = 0;
865 }
866 }
867
868 if (!fHistoCanvas)
869 {
870 fHistoCanvas = gEve->AddCanvasTab(fM->GetName());
871 }
872
873 gPad = fHistoCanvas;
874}
875
c04e790a 876//______________________________________________________
2ef0687e 877void AliEveTRDTrackListEditor::SetModel(TObject* obj)
8e27fca1 878{
16db6074 879 // Sets the model object, updates the related data in the GUI and
880 // inherits settings (cf. Inherit*(...)), if the flag fInheritSettings is set to kTRUE.
881
2ef0687e 882 fM = dynamic_cast<AliEveTRDTrackList*>(obj);
883
8bdeb570 884 if (fM == 0)
885 {
8e27fca1 886 Error("SetModel", "Parameter is zero pointer");
887 return;
888 }
889
38a30030 890 // Provide a pointer to this editor
891 fM->fEditor = this;
892
8bdeb570 893 // If macro list + track style shall be inherited from previously loaded track list, do so
894 if (fInheritSettings)
bcb45225 895 {
896 InheritMacroList();
8bdeb570 897 InheritStyle();
898
899 fInheritSettings = kFALSE;
bcb45225 900 }
ecbbe371 901
8bdeb570 902 // Select the correct styles
ecbbe371 903 Int_t b = 0;
904 UChar_t style = fM->GetSelectedTrackStyle();
8bdeb570 905 if (TESTBIT(style, AliEveTRDTrack::kSource)) b = 2;
906 else
907 {
908 if (TESTBIT(style, AliEveTRDTrack::kPID)) b = 1;
ecbbe371 909 else b = 0;
910 }
911 fbgStyleColor->SetButton(b, kTRUE);
912
913
8bdeb570 914 if (TESTBIT(style, AliEveTRDTrack::kTrackCosmics)) b = 2;
915 else
916 {
917 if (TESTBIT(style, AliEveTRDTrack::kTrackModel)) b = 1;
ecbbe371 918 else b = 0;
919 }
920 fbgStyleTrack->SetButton(b, kTRUE);
bcb45225 921
2ef0687e 922 UpdateMacroList();
8e27fca1 923 UpdateHistoList();
924
4f6473f6 925 // View correct tab
ecbbe371 926 GetGedEditor()->GetTab()->SetTab(fM->GetSelectedTab());
4f6473f6 927}
928
4cbab605 929//______________________________________________________
8bdeb570 930void AliEveTRDTrackListEditor::SetTrackColor(Int_t ind)
4cbab605 931{
16db6074 932 // Sets the color model for the tracks, updates the tracks with this model and
933 // redraws the scene.
934
8bdeb570 935 switch(ind)
936 {
9443fb9d 937 case AliTRDpidUtil::kLQ:
938 fM->UpdateTrackStyle(AliEveTRDTrack::kPID, AliTRDpidUtil::kLQ);
2f9b41fd 939 break;
9443fb9d 940 case AliTRDpidUtil::kNN:
941 fM->UpdateTrackStyle(AliEveTRDTrack::kPID, AliTRDpidUtil::kNN);
2f9b41fd 942 break;
943 default:
944 fM->UpdateTrackStyle(AliEveTRDTrack::kSource);
945 break;
ecbbe371 946 }
8bdeb570 947
ecbbe371 948 gEve->Redraw3D();
4cbab605 949}
950
951//______________________________________________________
8bdeb570 952void AliEveTRDTrackListEditor::SetTrackModel(Int_t ind)
4cbab605 953{
16db6074 954 // Sets the track model for the tracks, updates the tracks with this model and
955 // redraws the scene.
956
8bdeb570 957 switch(ind)
958 {
2f9b41fd 959 case AliEveTRDTrack::kRieman:
960 fM->UpdateTrackStyle(AliEveTRDTrack::kTrackModel, AliEveTRDTrack::kRieman);
961 break;
962 case AliEveTRDTrack::kKalman:
963 fM->UpdateTrackStyle(AliEveTRDTrack::kTrackModel, AliEveTRDTrack::kKalman);
964 break;
965 default:
966 fM->UpdateTrackStyle(AliEveTRDTrack::kTrackCosmics);
967 break;
ecbbe371 968 }
8bdeb570 969
ecbbe371 970 gEve->Redraw3D();
4cbab605 971}
972
4f6473f6 973//______________________________________________________
974void AliEveTRDTrackListEditor::UpdateDataFromMacroListSelection()
975{
16db6074 976 // Saves the current selection in the "Histograms"-tab to the current
977 // AliEveTRDTrackList. This means that the selection is updated and won't
978 // get lost, if another editor is loaded in Eve.
979
4f6473f6 980 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
8e27fca1 981 {
4f6473f6 982 fM->SetHistoDataSelection(i, fCheckButtons[i]->IsOn());
8e27fca1 983 }
caaf90d2 984}
985
ecbbe371 986//______________________________________________________
987void AliEveTRDTrackListEditor::UpdateHistoCanvasTab()
988{
ce239ca6 989 // Updates the histogram and the corresponding tab (including titles).
16db6074 990
ecbbe371 991 // Update name of the tab (tab has been set to current tab!)
992 fHistoCanvasName->SetString(fM->GetName());
993
994 // Use a copy of fHistoCanvasName!! -> If the user closes a tab manually, the TGString
995 // will be deleted -> Error might occur, when accessing the pointer
996 gEve->GetBrowser()->GetTab(1)->GetCurrentTab()->SetText(new TGString(fHistoCanvasName));
997
998 // Switch tabs to force redrawing
999 gEve->GetBrowser()->GetTab(1)->SetTab(0);
1000 gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString());
1001 fHistoCanvas->Update();
1002}
1003
c04e790a 1004//______________________________________________________
caaf90d2 1005void AliEveTRDTrackListEditor::UpdateHistoList()
1006{
16db6074 1007 // Reloads (updates) the buttons in the "Histograms"-tab via
1008 // the current AliEveTRDTrackList (data).
1009
4f6473f6 1010 fHistoSubFrame->TGCompositeFrame::Cleanup();
caaf90d2 1011
1012 // Set buttons for histograms
1013 if (fCheckButtons != 0) delete fCheckButtons;
1014 fCheckButtons = new TGCheckButton*[fM->fDataFromMacroList->GetEntries()];
1015
1016 TObjString* iter = (TObjString*)fM->fDataFromMacroList->First();
1017 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries() && iter != 0; i++)
1018 {
1019 fCheckButtons[i] = new TGCheckButton(fHistoSubFrame, iter->GetName());
1020 fHistoSubFrame->AddFrame(fCheckButtons[i]);
1021
1022 fCheckButtons[i]->SetState(kButtonUp, kFALSE);
1023 fCheckButtons[i]->MapRaised();
4f6473f6 1024 fCheckButtons[i]->SetOn(fM->HistoDataIsSelected(i));
1025 fCheckButtons[i]->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "UpdateDataFromMacroListSelection()");
caaf90d2 1026
1027 iter = (TObjString*)fM->fDataFromMacroList->After(iter);
1028 }
2ef0687e 1029}
1030
c04e790a 1031//______________________________________________________
2ef0687e 1032void AliEveTRDTrackListEditor::UpdateMacroList()
1033{
16db6074 1034 // Reloads (updates) the macro list (selection AND process macros) via
1035 // the current AliEveTRDTrackList (data).
1036
caaf90d2 1037 ftlMacroList->RemoveAll();
caaf90d2 1038 ftlMacroSelList->RemoveAll();
38a30030 1039
1040 TMapIter* iter = (TMapIter*)fM->fMacroList->MakeIterator();
1041 TObject* key = 0;
1042 TMacroData* macro = 0;
3f797131 1043
38a30030 1044 Int_t ind = 0;
1045 while ((key = iter->Next()) != 0)
3f797131 1046 {
38a30030 1047 macro = (TMacroData*)fM->fMacroList->GetValue(key);
1048 if (macro != 0)
1049 {
1050 if (macro->IsProcessMacro())
1051 {
1052 ftlMacroList->AddEntry(macro->GetName(), ind);
1053 // Select, what has been selected before
1054 ftlMacroList->Select(ind, fM->MacroListIsSelected(ind));
1055 ind++;
1056 }
1057 else if (macro->IsSelectionMacro())
1058 {
1059 ftlMacroSelList->AddEntry(macro->GetName(), ind);
1060 // Select, what has been selected before
1061 ftlMacroSelList->Select(ind, fM->MacroListIsSelected(ind));
1062 ind++;
1063 }
1064 else
1065 {
1066 Error("AliEveTRDTrackListEditor::UpdateMacroList()",
00dc25ef 1067 Form("Macro \"%s/%s.C\" is neither a selection macro nor a process macro!",
38a30030 1068 macro->GetPath(), macro->GetName()));
1069 }
1070 }
1071 else
1072 {
1073 Error("AliEveTRDTrackListEditor::UpdateMacroList()",
1074 Form("Macro list is corrupted: Macro \"%s\" not found!", key->GetName()));
1075 }
3f797131 1076 }
1077
38a30030 1078 ftlMacroList->SortByName();
caaf90d2 1079 ftlMacroSelList->SortByName();
4f6473f6 1080}
1081
1082//______________________________________________________
1083void AliEveTRDTrackListEditor::UpdateMacroListSelection(Int_t ind)
1084{
38a30030 1085 // Saves the current selection in the macro listS to the current
16db6074 1086 // AliEveTRDTrackList. This means that the selection is updated and won't
1087 // get lost, if another editor is loaded in Eve.
38a30030 1088 // NOTE: The indices in BOTH lists will be unique!
16db6074 1089
4f6473f6 1090 // Toggle selected item
1091 fM->SetMacroListSelection(ind, !fM->MacroListIsSelected(ind));
1092}
db16b708 1093
1094
ce239ca6 1095//______________________________________________________
1096//______________________________________________________
1097//______________________________________________________
1098
1099
db16b708 1100/////////////////////////////////////////////////
00dc25ef 1101ClassImp(AliEveTRDMacroWizard)
ce239ca6 1102/////////////////////////////////////////////////
db16b708 1103
1104//______________________________________________________
00dc25ef 1105AliEveTRDMacroWizard::AliEveTRDMacroWizard(const TGWindow* p)
db16b708 1106 :TGMainFrame(p ? p : gClient->GetRoot(), 10, 10, kMainFrame | kVerticalFrame)
1107 ,fText(0x0)
1108 ,fCombo(0x0)
1109 ,fTextEdit(0x0)
9a11b2ee 1110 ,fbCreate(0x0)
1111 ,fbCancel(0x0)
db16b708 1112{
ce239ca6 1113 // Creates the macro wizard.
1114
db16b708 1115 const Int_t width = 300;
1116
1117 // horizontal frame
1118 TGHorizontalFrame *fFrameName = new TGHorizontalFrame(this, 10, 10, kHorizontalFrame);
1119 TGLabel *fLabel = new TGLabel(fFrameName, "Name*");
1120 fLabel->SetTextJustify(36);
1121 fLabel->SetMargins(0,0,0,0);
1122 fLabel->SetWrapLength(-1);
1123 fFrameName->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1124
1125 fText = new TGTextEntry(fFrameName);
1126 fText->SetMaxLength(255);
1127 fText->SetAlignment(kTextLeft);
1128 fText->SetText("");
1129 fText->Resize(width, fText->GetDefaultHeight());
1130 fFrameName->AddFrame(fText, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1131
1132
1133 // horizontal frame
1134 TGHorizontalFrame *fFrameComment = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1135 fLabel = new TGLabel(fFrameComment, "Comment");
1136 fLabel->SetTextJustify(36);
1137 fLabel->SetMargins(0,0,0,0);
1138 fLabel->SetWrapLength(-1);
1139 fFrameComment->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1140
1141 fTextEdit = new TGTextEdit(fFrameComment, width, 5*fText->GetDefaultHeight());
1142 fFrameComment->AddFrame(fTextEdit, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1143
1144 // horizontal frame
1145 TGHorizontalFrame *fFrameType = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1146 fLabel = new TGLabel(fFrameType, "Type*");
1147 fLabel->SetTextJustify(36);
1148 fLabel->SetMargins(0,0,0,0);
1149 fLabel->SetWrapLength(-1);
1150 fFrameType->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1151
1152 fCombo = new TGComboBox(fFrameType, -1, kHorizontalFrame | kSunkenFrame | kDoubleBorder | kOwnBackground);
1153 fCombo->AddEntry("Single Track Selection", AliEveTRDTrackList::kSingleTrackSelect);
1154 fCombo->AddEntry("Pair Tracks Selection", AliEveTRDTrackList::kCorrelTrackSelect);
1155 fCombo->AddEntry("Single Track Analyse", AliEveTRDTrackList::kSingleTrackAnalyse);
1156 fCombo->AddEntry("Single Track Histo", AliEveTRDTrackList::kSingleTrackHisto);
1157 fCombo->AddEntry("Pair Tracks Analyse", AliEveTRDTrackList::kCorrelTrackAnalyse);
1158 fCombo->AddEntry("Pair Tracks Histo", AliEveTRDTrackList::kCorrelTrackHisto);
1159 fCombo->Select(-1);
1160 fCombo->Resize(width, fText->GetDefaultHeight());
1161 fFrameType->AddFrame(fCombo, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1162
9a11b2ee 1163 // horizontal frame
1164 TGHorizontalFrame *fFrameAction = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1165 fbCancel = new TGTextButton(fFrameAction, "Cancel");
00dc25ef 1166 fbCancel->SetToolTipText("Exit macro creation wizard");
9a11b2ee 1167 fFrameAction->AddFrame(fbCancel, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1168 fbCreate = new TGTextButton(fFrameAction, "Done");
1169 fbCreate->SetToolTipText("Use settings to create the macro");
1170 fFrameAction->AddFrame(fbCreate, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1171
db16b708 1172
1173 // horizontal frame
1174 TGHorizontalFrame *fFrameText = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1175 fLabel = new TGLabel(fFrameText, "(*) Mandatory fields");
1176 fLabel->SetTextJustify(36);
1177 fLabel->SetMargins(0,0,0,0);
1178 fLabel->SetWrapLength(-1);
1179 fFrameText->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1180
1181 // put things together
1182 AddFrame(fFrameName, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1183 AddFrame(fFrameComment, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1184 AddFrame(fFrameType, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
9a11b2ee 1185 AddFrame(fFrameAction, new TGLayoutHints(kLHintsRight | kLHintsTop | kLHintsExpandX,2,2,2,2));
db16b708 1186
1187 TGHorizontal3DLine *fLine = new TGHorizontal3DLine(this, 281, 2);
1188 AddFrame(fLine, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1189 AddFrame(fFrameText, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1190
1191
00dc25ef 1192 SetWindowName("TRD Macro Wizard");
db16b708 1193 SetMWMHints(kMWMDecorAll,
1194 kMWMFuncAll,
1195 kMWMInputModeless);
1196 MapSubwindows();
1197
1198 Resize(GetDefaultSize());
1199 MapWindow();
1200
1201 // Do the linking
00dc25ef 1202 //fCombo->Connect("Selected(Int_t)", "AliEveTRDMacroWizard", this, "Create(Int_t)");
1203 fbCreate->Connect("Clicked()", "AliEveTRDMacroWizard", this, "HandleCreate()");
1204 fbCancel->Connect("Clicked()", "AliEveTRDMacroWizard", this, "CloseWindow()");
9a11b2ee 1205
1206 // Standard choice
1207 fCombo->Select(1, kFALSE);
db16b708 1208}
1209
a6e0ebfe 1210const Char_t *fIncludes =
db16b708 1211"#if !defined(__CINT__) || defined(__MAKECINT__)\n"
1212"#include <TROOT.h>\n"
1213"#include <TH1.h>\n"
1214"#include <TRD/AliTRDgeometry.h>\n"
1215"#include <TRD/AliTRDcluster.h>\n"
1216"#include <TRD/AliTRDseedV1.h>\n"
1217"#include <TRD/AliTRDtrackV1.h>\n"
1218"#endif\n";
1219
a6e0ebfe 1220const Char_t *fMacroTemplate[7] = {
db16b708 1221""
1222," if (!track) return kFALSE;\n"
1223
1224," n = 0;\n"
9a11b2ee 1225" r = 0x0;\n"
db16b708 1226" if (!track) return;\n"
1227
1228," if (!track) return 0x0;\n"
9a11b2ee 1229" TH1* h = 0x0;\n\n"
1230"// Set bins, xmin and xmax here\n"
1231" Int_t n = 1;\n"
1232" Double_t xmin = 0;\n"
1233" Double_t xmax = 100;\n\n"
db16b708 1234" if(!(h = (TH1*)gROOT->FindObject(\"h\"))){\n"
1235" h = new TH1(\"h\", \"Title\", n, xmin, xmax);\n"
1236" h->GetXaxis()->SetTitle("");\n"
1237" h->GetYaxis()->SetTitle("");\n"
1238" } else h->Reset();\n"
1239
1240," if (!track) return kFALSE;\n"
1241" if (!track2) return kFALSE;\n"
1242
1243," n = 0;\n"
9a11b2ee 1244" r = 0x0;\n"
db16b708 1245" if (!track) return;\n"
1246" if (!track2) return;\n"
1247
1248," if (!track) return 0x0;\n"
1249" if (!track2) return 0x0;\n"
9a11b2ee 1250" TH1* h = 0x0;\n\n"
1251"// Set bins, xmin and xmax here\n"
1252" Int_t n = 1;\n"
1253" Double_t xmin = 0;\n"
1254" Double_t xmax = 100;\n\n"
db16b708 1255" if(!(h = (TH1*)gROOT->FindObject(\"h\"))){\n"
1256" h = new TH1(\"h\", \"Title\", n, xmin, xmax);\n"
1257" h->GetXaxis()->SetTitle("");\n"
1258" h->GetYaxis()->SetTitle("");\n"
1259" } else h->Reset();\n"
1260};
1261//______________________________________________________
00dc25ef 1262void AliEveTRDMacroWizard::Create(Int_t type)
db16b708 1263{
ce239ca6 1264 // Creates the macro with the selected type (combo box).
1265
db16b708 1266 const Char_t *name = fText->GetText();
1267 if(strcmp(name,"")==0){
1268 AliInfo("Please specify a name for your macro.");
9a11b2ee 1269 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
1270 "Please specify a name for your macro.", kMBIconExclamation, kMBOk);
1271 //fCombo->Select(-1);
1272 return;
1273 }
1274
1275 // Note: gSystem->AccessPathName(...) returns kTRUE, if the access FAILED!
1276 if(!gSystem->AccessPathName(Form("./%s.C", name))){
1277 // If there is already a file with this name -> Error
1278 AliInfo(Form("A macro \"%s.C\" already exists in the current directory!\nPlease choose another name!", name));
1279 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
1280 Form("A macro \"%s.C\" already exists in the current directory!\nPlease choose another name!", name), kMBIconExclamation, kMBOk);
1281 //fCombo->Select(-1);
db16b708 1282 return;
1283 }
1284
1285 FILE* fp = 0x0;
1286 if(!(fp = fopen(Form("%s.C", name), "wt"))){
1287 AliInfo("Couldn't create macro file.");
9a11b2ee 1288 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
1289 "Couldn't create macro file.", kMBIconExclamation, kMBOk);
1290 //fCombo->Select(-1);
db16b708 1291 return;
1292 }
1293
1294 TGText *comment = fTextEdit->GetText();
1295 Char_t *line = 0x0; Int_t iline = 0;
1296 while((line = comment->GetLine(TGLongPosition(0,iline++), 200))) fprintf(fp, "// %s\n", line);
1297
1298 fprintf(fp, "\n%s\n", fIncludes);
1299
00dc25ef 1300 switch(type){
db16b708 1301 case AliEveTRDTrackList::kSingleTrackSelect:
1302 fprintf(fp, "Bool_t %s(const AliTRDtrackV1 *track)\n", name);
1303 break;
1304 case AliEveTRDTrackList::kCorrelTrackSelect:
1305 fprintf(fp, "Bool_t %s(const AliTRDtrackV1 *track, const AliTRDtrackV1 *track2)\n", name);
1306 break;
1307 case AliEveTRDTrackList::kSingleTrackAnalyse:
1308 fprintf(fp, "void %s(const AliTRDtrackV1 *track, Double_t*& r, Int_t& n)\n", name);
1309 break;
1310 case AliEveTRDTrackList::kSingleTrackHisto:
1311 fprintf(fp, "TH1* %s(const AliTRDtrackV1 *track)\n", name);
1312 break;
1313 case AliEveTRDTrackList::kCorrelTrackAnalyse:
1314 fprintf(fp, "void %s(const AliTRDtrackV1 *track, const AliTRDtrackV1 *track2, Double_t*& r, Int_t& n)\n", name);
1315 break;
1316 case AliEveTRDTrackList::kCorrelTrackHisto:
1317 fprintf(fp, "TH1* %s(const AliTRDtrackV1 *track, const AliTRDtrackV1 *track2)\n", name);
1318 break;
1319 default:
00dc25ef 1320 AliInfo(Form("Unknown type[%d]", type));
9a11b2ee 1321 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
00dc25ef 1322 Form("Unknown type[%d]", type), kMBIconExclamation, kMBOk);
db16b708 1323 fclose(fp);
1324 gSystem->Exec(Form("rm -f %s.C", name));
9a11b2ee 1325 //fCombo->Select(-1);
db16b708 1326 return;
1327 }
1328
00dc25ef 1329 fprintf(fp, "{\n%s\n", fMacroTemplate[type]);
db16b708 1330 fprintf(fp, "// add your own code here\n\n\n}\n");
1331 fclose(fp);
57d55fae 1332
00dc25ef 1333 Emit("Create(Int_t)", type);
57d55fae 1334 Create((Char_t*)name);
db16b708 1335 CloseWindow();
1336}
57d55fae 1337
1338//______________________________________________________
00dc25ef 1339void AliEveTRDMacroWizard::Create(Char_t *name)
57d55fae 1340{
ce239ca6 1341 // Emits the creation signal.
1342
57d55fae 1343 Emit("Create(Char_t*)", Form("%s.C", name));
1344}
9a11b2ee 1345
1346//______________________________________________________
00dc25ef 1347void AliEveTRDMacroWizard::HandleCreate()
9a11b2ee 1348{
ce239ca6 1349 // Handles the signal, when the creation button is pressed.
1350
9a11b2ee 1351 Create(fCombo->GetSelected());
1352}