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