]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveDet/AliEveTRDTrackListEditor.cxx
Removing unnecessary and slightly misleading printout. Anyway we now in which event...
[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
90ae0503 335 delete selIterator;
336 delete procIterator;
ea24e1bc 337
90ae0503 338 if (!success) {
ea24e1bc 339 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
340 "AliEveTRDTrackList::ApplyProcessMacros experienced an error (cf. CINT-output)!",
341 kMBIconExclamation, kMBOk);
342 }
8e27fca1 343}
c04e790a 344
db16b708 345//______________________________________________________
346void AliEveTRDTrackListEditor::NewMacros()
347{
00dc25ef 348 // Start the macro creation wizard.
db16b708 349 // thanks to Jacek Otwinowski<J.Otwinowski@GSI.DE> for this suggestion
350
00dc25ef 351 AliEveTRDMacroWizard *wizz = new AliEveTRDMacroWizard();
57d55fae 352 wizz->Connect("Create(Char_t*)", "AliEveTRDTrackListEditor", this, "AddMacro(Char_t*)");
db16b708 353}
354
355
c04e790a 356//______________________________________________________
2ef0687e 357void AliEveTRDTrackListEditor::BrowseMacros()
358{
16db6074 359 // Creates a file-dialog. The selected files will be added to the macro list
360 // via AddMacro(...).
361
caaf90d2 362 new TGFileDialog(gClient->GetRoot(), GetMainFrame(), kFDOpen, fFileInfo);
2ef0687e 363
caaf90d2 364 if (fFileInfo->fIniDir != 0 && fFileInfo->fFileNamesList != 0)
3f797131 365 {
2ef0687e 366 // Extract filenames
caaf90d2 367 TObject* iter = fFileInfo->fFileNamesList->First();
2ef0687e 368
369 Char_t* name = 0;
370
371 while (iter != 0)
372 {
caaf90d2 373 // NOTE: fileInfo->fFileNamesList will be changed by that, too!
71f50468 374 name = (Char_t*)strrchr(iter->GetName(), '/');
2ef0687e 375 // Delete '"' at the end
376 name[strlen(name)] = '\0';
caaf90d2 377
db16b708 378 AddMacro(name + 1, fFileInfo->fIniDir);
caaf90d2 379 iter = (TObjString*)fFileInfo->fFileNamesList->After(iter);
2ef0687e 380 }
381 }
3f797131 382
caaf90d2 383 // -> The following problem has been fixed (trunk -> Changes according to 03 September 2008):
3f797131 384 // Some error occurs, when one ends the filedialog with "cancel": fileInfo->fFileNamesList is set to 0x0, but
385 // in the next launch no new memory is allocated. So do this manually.
caaf90d2 386 //if (fileInfo->fFileNamesList == 0) fileInfo->fFileNamesList = new TList();
387}
388
4f6473f6 389//______________________________________________________
390void AliEveTRDTrackListEditor::CloseTabs()
391{
16db6074 392 // Closes + deletes the tabs created by this object
393
4f6473f6 394 if (fHistoCanvas != 0)
395 {
396 // Close the created tab, if it exists
397 if (fHistoCanvasName != 0)
398 {
399 if (gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString()))
400 {
401 // Now the created tab is the current one and can be deleted
402 gEve->GetBrowser()->GetTab(1)->RemoveTab();
403 }
404 }
405 // With the tab removal, the canvas will be deleted automatically!
406 fHistoCanvas = 0;
407 }
408}
409
c04e790a 410//______________________________________________________
caaf90d2 411void AliEveTRDTrackListEditor::DrawHistos()
412{
16db6074 413 // Accesses the temporary data file created by the last call of ApplyMacros() and draws
414 // histograms according to the selection in the "Histograms"-tab.
415
caaf90d2 416 Int_t nHistograms = GetNSelectedHistograms();
417 if (nHistograms <= 0)
418 {
419 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
420 "No data selected. Please select the data you want to plot!", kMBIconExclamation, kMBOk);
421 return;
422 }
423 if (nHistograms > 3)
424 {
425 new TGMsgBox(gClient->GetRoot(), GetMainFrame(),
426 "Error", "Only histograms with up to 3 dimensions supported. Please select 1,2 or 3 data macros!",
427 kMBIconExclamation, kMBOk);
428 return;
429 }
430
bcb45225 431 // Check, if a histo macro shall be drawn
432 Int_t indexOfHistoMacro = -1;
433 Int_t selectedChecked = 0;
434 for (Int_t j = 0; j < fM->fDataFromMacroList->GetEntries(); j++)
435 {
436 if (fCheckButtons[j]->TGButton::GetState() == kButtonDown)
437 {
438 selectedChecked++;
439
8bdeb570 440 // Histo macro? -> To check this, look for the substring "(histo macro)"
441 if (strstr(fM->fDataFromMacroList->At(j)->GetName(), "(histo macro)") != 0)
bcb45225 442 {
443 // Is also another macro selected?
444 if (nHistograms > 1)
445 {
446 // Histo macros cannot(!) be correlated!
447 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
2f9b41fd 448 "Histo macros (return value \"TH1*\") cannot be combined with other macros",
bcb45225 449 kMBIconExclamation, kMBOk);
450 return;
451 }
452
453 // Mark this histo macro for drawing
454 indexOfHistoMacro = j;
455
456 // Have all selected macros been checked? -> If yes, we are done with this
457 if (selectedChecked == nHistograms) break;
458 }
459 }
460 }
461
8bdeb570 462 TFile* file = new TFile(Form("/tmp/TRD.TrackListMacroData_%s.root", gSystem->Getenv("USER")), "READ");
caaf90d2 463 if (!file)
464 {
8bdeb570 465 Error("Draw histograms", Form("Cannot open file \"/tmp/TRD.TrackListMacroData_%s.root\"",
466 gSystem->Getenv("USER")));
caaf90d2 467 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
8bdeb570 468 Form("Cannot open file \"/tmp/TRD.TrackListMacroData_%s.root\"", gSystem->Getenv("USER")),
469 kMBIconExclamation, kMBOk);
caaf90d2 470 return;
471 }
472
473 TTree* t = 0;
474 TTree* tFriend1 = 0;
475 TTree* tFriend2 = 0;
476
477 Int_t indexOfMacro1 = 0;
478 Int_t indexOfMacro2 = 0;
479 Int_t indexOfMacro3 = 0;
480
bcb45225 481 // Variable for the loop below -> Will be set to aborting value, if a histo macro is drawn
482 Int_t i = 0;
483
484 // Draw histo macro?
485 if (indexOfHistoMacro >= 0)
486 {
487 if ((t = (TTree*)file->Get(Form("TrackData%d", indexOfHistoMacro))))
488 {
489 SetDrawingToHistoCanvasTab();
490
491 TH1* myHist = 0;
492 t->SetBranchAddress(Form("Macro%d", indexOfHistoMacro), &myHist);
493 t->GetEntry(0);
494 if (myHist != 0) myHist->Draw();
495 else
496 {
497 Error("Draw histograms", Form("No histogram for histo macro \"%s\" found!",
498 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()));
499 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
500 Form("No histogram for histo macro \"%s\" found!",
501 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()), kMBIconExclamation, kMBOk);
502
503 }
504
5715955a 505 UpdateHistoCanvasTab();
bcb45225 506 }
507 else
508 {
2670605d 509 Error("Draw histograms", Form("No data for histo macro \"%s\" found!\nMaybe no tracks have been selected.",
bcb45225 510 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()));
511 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
2670605d 512 Form("No data for histo macro \"%s\" found!\nMaybe no tracks have been selected.",
bcb45225 513 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()), kMBIconExclamation, kMBOk);
514 }
515
516 // Skip the loop below
517 i = fM->fDataFromMacroList->GetEntries();
518 }
519
2f9b41fd 520 // Load the trees in succession and remember the entries -> Plot the analyse macros
bcb45225 521 for ( ; i < fM->fDataFromMacroList->GetEntries(); i++)
caaf90d2 522 {
523 if (fCheckButtons[i]->TGButton::GetState() == kButtonDown)
524 {
525 if (t == 0)
526 {
527 indexOfMacro1 = i;
528 if (!(t = (TTree*)file->Get(Form("TrackData%d", i))))
529 {
2670605d 530 Error("Draw histograms", Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.",
531 fM->fDataFromMacroList->At(i)->GetName()));
caaf90d2 532 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
2670605d 533 Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.",
534 fM->fDataFromMacroList->At(i)->GetName()), kMBIconExclamation, kMBOk);
caaf90d2 535 break;
536 }
bcb45225 537
2f9b41fd 538 // 1d histogram
caaf90d2 539 if (nHistograms == 1)
540 {
bcb45225 541 SetDrawingToHistoCanvasTab();
8bdeb570 542
bcb45225 543 t->Draw(Form("Macro%d", indexOfMacro1), "1");
544 ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s;%s",
545 fM->fDataFromMacroList->At(indexOfMacro1)->GetName(),
546 fM->fDataFromMacroList->At(indexOfMacro1)->GetName()));
8bdeb570 547 UpdateHistoCanvasTab();
caaf90d2 548
549 break;
550 }
551 }
552 else if (tFriend1 == 0)
553 {
554 indexOfMacro2 = i;
555 if (!(tFriend1 = (TTree*)file->Get(Form("TrackData%d", i))))
556 {
2670605d 557 Error("Draw histograms", Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.",
558 fM->fDataFromMacroList->At(i)->GetName()));
caaf90d2 559 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
2670605d 560 Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.",
561 fM->fDataFromMacroList->At(i)->GetName()),
bcb45225 562 kMBIconExclamation, kMBOk);
caaf90d2 563 break;
564 }
565
566 // 2d histogram
567 if (nHistograms == 2)
568 {
bcb45225 569 SetDrawingToHistoCanvasTab();
570
caaf90d2 571 t->AddFriend(tFriend1);
572 t->Draw(Form("Macro%d:Macro%d", indexOfMacro1, indexOfMacro2), "1");
bcb45225 573 ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s - %s;%s;%s",
574 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
575 fM->fDataFromMacroList->At(indexOfMacro1)->GetName(),
576 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
577 fM->fDataFromMacroList->At(indexOfMacro1)->GetName()));
4f6473f6 578
bcb45225 579 UpdateHistoCanvasTab();
caaf90d2 580
581 break;
582 }
583 }
584 // 3d histogram
585 else
586 {
587 indexOfMacro3 = i;
588 if (!(tFriend2 = (TTree*)file->Get(Form("TrackData%d", i))))
589 {
2670605d 590 Error("Draw histograms", Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.",
591 fM->fDataFromMacroList->At(i)->GetName()));
caaf90d2 592 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
2670605d 593 Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.",
594 fM->fDataFromMacroList->At(i)->GetName()), kMBIconExclamation, kMBOk);
caaf90d2 595 break;
596 }
4f6473f6 597
bcb45225 598 SetDrawingToHistoCanvasTab();
4f6473f6 599
caaf90d2 600 t->AddFriend(tFriend1);
601 t->AddFriend(tFriend2);
602 t->Draw(Form("Macro%d:Macro%d:Macro%d", indexOfMacro1, indexOfMacro2, indexOfMacro3), "1");
bcb45225 603 ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s - %s - %s;%s;%s;%s",
604 fM->fDataFromMacroList->At(indexOfMacro3)->GetName(),
605 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
606 fM->fDataFromMacroList->At(indexOfMacro1)->GetName(),
607 fM->fDataFromMacroList->At(indexOfMacro3)->GetName(),
608 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
609 fM->fDataFromMacroList->At(indexOfMacro1)->GetName()));
610
611 UpdateHistoCanvasTab();
caaf90d2 612
613 break;
614 }
615 }
616 }
617
618 if (t != 0) delete t;
619 t = 0;
620 if (tFriend1 != 0) delete tFriend1;
621 tFriend1 = 0;
622 if (tFriend2 != 0) delete tFriend2;
623 tFriend2 = 0;
624
625 file->Close("R");
626 delete file;
627 file = 0;
628}
629
c04e790a 630//______________________________________________________
2670605d 631Int_t AliEveTRDTrackListEditor::GetNSelectedHistograms() const
caaf90d2 632{
38a30030 633 // Returns the number of selected macros (or rather: of their selected data) in the "Histograms"-tab
16db6074 634
caaf90d2 635 Int_t count = 0;
636
637 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
638 {
639 if (fCheckButtons[i]->TGButton::GetState() == kButtonDown) count++;
640 }
641
642 return count;
2ef0687e 643}
644
c04e790a 645//______________________________________________________
2ef0687e 646void AliEveTRDTrackListEditor::HandleMacroPathSet()
647{
16db6074 648 // Takes the input of the text field (adding a macro), checks if the macro can be
649 // accessed (and that it exists) and adds the macro to the macro list via AddMacro(...).
650 // You can use environment variables in the text field, e.g. "$ALICE_ROOT/Eve/alice-macro/myMacro.C".
651
90ae0503 652 Char_t bname[AliEveTRDTrackList::fkMaxMacroNameLength]; // allocate buffers
653
caaf90d2 654 if (strlen(fteField->GetText()) != 0)
5715955a 655 {
656 // Expand the pathname
657 Char_t* systemPath = gSystem->ExpandPathName(fteField->GetText());
658 fteField->SetText(systemPath);
659 delete systemPath;
660 systemPath = 0;
661
2ef0687e 662 // Check if file exists
663 FILE* fp = NULL;
664
caaf90d2 665 fp = fopen(fteField->GetText(), "rb");
39b891ff 666 if (fp != NULL)
667 {
3f797131 668 fclose(fp);
caaf90d2 669
3f797131 670 // Extract filename
71f50468 671 Char_t* name = (Char_t*)strrchr(fteField->GetText(), '/');
3f797131 672
673 // Current path
90ae0503 674 if (!name) {
675 name= bname;
4f6473f6 676 memset(name, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroNameLength);
90ae0503 677 snprintf(name, AliEveTRDTrackList::fkMaxMacroNameLength, "%s", fteField->GetText());
3f797131 678
4f6473f6 679 // Add path to textfield -> Path is "./" -> Use length for the name + 2
680 Char_t pathname[AliEveTRDTrackList::fkMaxMacroNameLength + 2];
681 memset(pathname, '\0', sizeof(Char_t) * (AliEveTRDTrackList::fkMaxMacroNameLength + 2));
90ae0503 682 snprintf(pathname, AliEveTRDTrackList::fkMaxMacroNameLength + 2, "./%s", fteField->GetText());
caaf90d2 683 fteField->SetText(pathname);
684
db16b708 685 AddMacro(name);
39b891ff 686 }
687 // Different path
688 else
689 {
3f797131 690 // Extract path
90ae0503 691 Char_t path[AliEveTRDTrackList::fkMaxMacroPathLength];
4f6473f6 692 memset(path, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroPathLength);
90ae0503 693 snprintf(path, strlen(fteField->GetText()) - strlen(name), "%s", fteField->GetText());
caaf90d2 694
695 // Ignore the slash "/" in name
db16b708 696 AddMacro(name + 1, path);
90ae0503 697 }
39b891ff 698 }
699 else
700 {
3f797131 701 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
39b891ff 702 "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
2ef0687e 703 }
704 }
705}
706
4f6473f6 707//______________________________________________________
708void AliEveTRDTrackListEditor::HandleNewEventLoaded()
709{
16db6074 710 // Closes the tabs created by this object and sets a flag that will
711 // cause the function SetModel() to inherit the macro lists + style
712 // for the next AliEveTRDTrackList from the current one.
713
8bdeb570 714 // Inherit the macro list and track style for the next track list!
715 fInheritSettings = kTRUE;
bcb45225 716
717 // Close the tabs
4f6473f6 718 CloseTabs();
719}
720
721//______________________________________________________
722void AliEveTRDTrackListEditor::HandleTabChangedToIndex(Int_t index)
723{
16db6074 724 // Saves the current tab in the current AliEveTRDTrackList.
725
4f6473f6 726 fM->SetSelectedTab(index);
727}
728
bcb45225 729//______________________________________________________
730void AliEveTRDTrackListEditor::InheritMacroList()
731{
38a30030 732 // The old macro list is possibly stored in the corresponding interior map. This function will
733 // use this interior map to move the data from the interior map to the newly loaded AliEveTRDTrackList.
734 // Then the interior map will be cleaned up. With this, the settings will be inherited from the previously
735 // loaded AliEveTRDTrackList.
bcb45225 736
38a30030 737 if (fInheritedMacroList == 0) return;
738
739 // Clear list
bcb45225 740 fM->fMacroList->Delete();
38a30030 741
742 // Store data from interior list in the track list's map
743 TMapIter* iter = (TMapIter*)fInheritedMacroList->MakeIterator();
744
745 TObject* key = 0;
746 TMacroData* macro = 0;
747
748 while ((key = iter->Next()) != 0)
bcb45225 749 {
38a30030 750 macro = (TMacroData*)fInheritedMacroList->GetValue(key);
751 if (macro != 0) fM->fMacroList->Add(new TObjString(key->GetName()),
752 new TMacroData(macro->GetName(), macro->GetPath(), macro->GetType()));
753 else
754 {
c1869a7c 755 Error("AliEveTRDTrackListEditor::InheritMacroList", Form("Failed to inherit the macro \"%s\"!", key->GetName()));
38a30030 756 }
8bdeb570 757 }
38a30030 758
759 fInheritedMacroList->Delete();
760 delete fInheritedMacroList;
761 fInheritedMacroList = 0;
8bdeb570 762}
763
764//______________________________________________________
765void AliEveTRDTrackListEditor::InheritStyle()
766{
16db6074 767 // The old styles are stored in the corresponding button groups. This function will replace
768 // the style settings of the newly loaded AliEveTRDTrackList with the old styles. With this, the settings
769 // will be inherited from the previously loaded AliEveTRDTrackList.
8bdeb570 770
771 for (Int_t ind = 0; ind < 3; ind++)
772 {
773 if (fbgStyleTrack->GetButton(ind)->IsOn())
774 {
775 SetTrackModel(ind);
776 break;
777 }
778 }
779 for (Int_t ind = 0; ind < 3; ind++)
780 {
781 if (fbgStyleColor->GetButton(ind)->IsOn())
782 {
783 SetTrackColor(ind);
784 break;
785 }
bcb45225 786 }
787}
788
c04e790a 789//______________________________________________________
2ef0687e 790void AliEveTRDTrackListEditor::RemoveMacros()
791{
38a30030 792 // Removes the selected macros from the corresponding list.
16db6074 793
90ae0503 794 TList iterator;
795 ftlMacroList->GetSelectedEntries(&iterator);
796 fM->RemoveSelectedMacros(&iterator);
3f797131 797
3f797131 798
90ae0503 799 iterator.Clear();
800 ftlMacroSelList->GetSelectedEntries(&iterator);
801 fM->RemoveSelectedMacros(&iterator);
2ef0687e 802
4f6473f6 803 // Selected macros are deleted from the list -> No selected entries left
804 fM->fMacroListSelected = 0;
2ef0687e 805 UpdateMacroList();
806}
807
6e420565 808//______________________________________________________
809void AliEveTRDTrackListEditor::SaveMacroList(TMap* list)
810{
811 // Saves the provided macro list in an interior list. This list will be used by
812 // InheritMacroList() to restore the data in "list". With this method one is able
813 // to inherit the macro list from track list to track list (i.e. from event to event).
814
815 if (fInheritedMacroList != 0)
816 {
817 fInheritedMacroList->Delete();
818 delete fInheritedMacroList;
819 }
820 fInheritedMacroList = new TMap();
821 fInheritedMacroList->SetOwnerKeyValue(kTRUE, kTRUE);
822
823 TMapIter* iter = (TMapIter*)list->MakeIterator();
824 TObject* key = 0;
825 TMacroData* macro = 0;
826
827 while ((key = iter->Next()) != 0)
828 {
829 macro = (TMacroData*)fM->fMacroList->GetValue(key);
830 if (macro != 0) fInheritedMacroList->Add(new TObjString(key->GetName()),
831 new TMacroData(macro->GetName(), macro->GetPath(), macro->GetType()));
832 else
833 {
c1869a7c 834 Error("AliEveTRDTrackListEditor::SaveMacroList", Form("Failed to inherit the macro \"%s\"!", key->GetName()));
6e420565 835 }
836 }
837}
838
bcb45225 839//______________________________________________________
840void AliEveTRDTrackListEditor::SetDrawingToHistoCanvasTab()
841{
16db6074 842 // Sets gPad to the tab with the name of the current AliEveTRDTrackList. If this tab does
843 // not exist, it will be created. Otherwise, it is re-used.
844
bcb45225 845 // If the tab with the canvas has been closed, the canvas will be deleted.
846 // So, if there is no tab, set the canvas pointer to zero and recreate it in a new tab.
847 if (fHistoCanvas != 0)
848 {
849 if (gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString()) == 0)
850 {
851 fHistoCanvas = 0;
852 }
853 }
854
855 if (!fHistoCanvas)
856 {
857 fHistoCanvas = gEve->AddCanvasTab(fM->GetName());
858 }
859
860 gPad = fHistoCanvas;
861}
862
c04e790a 863//______________________________________________________
2ef0687e 864void AliEveTRDTrackListEditor::SetModel(TObject* obj)
8e27fca1 865{
16db6074 866 // Sets the model object, updates the related data in the GUI and
867 // inherits settings (cf. Inherit*(...)), if the flag fInheritSettings is set to kTRUE.
868
2ef0687e 869 fM = dynamic_cast<AliEveTRDTrackList*>(obj);
870
8bdeb570 871 if (fM == 0)
872 {
8e27fca1 873 Error("SetModel", "Parameter is zero pointer");
874 return;
875 }
876
38a30030 877 // Provide a pointer to this editor
878 fM->fEditor = this;
879
8bdeb570 880 // If macro list + track style shall be inherited from previously loaded track list, do so
881 if (fInheritSettings)
bcb45225 882 {
883 InheritMacroList();
8bdeb570 884 InheritStyle();
885
886 fInheritSettings = kFALSE;
bcb45225 887 }
ecbbe371 888
8bdeb570 889 // Select the correct styles
ecbbe371 890 Int_t b = 0;
891 UChar_t style = fM->GetSelectedTrackStyle();
8bdeb570 892 if (TESTBIT(style, AliEveTRDTrack::kSource)) b = 2;
893 else
894 {
895 if (TESTBIT(style, AliEveTRDTrack::kPID)) b = 1;
ecbbe371 896 else b = 0;
897 }
898 fbgStyleColor->SetButton(b, kTRUE);
899
900
8bdeb570 901 if (TESTBIT(style, AliEveTRDTrack::kTrackCosmics)) b = 2;
902 else
903 {
904 if (TESTBIT(style, AliEveTRDTrack::kTrackModel)) b = 1;
ecbbe371 905 else b = 0;
906 }
907 fbgStyleTrack->SetButton(b, kTRUE);
bcb45225 908
2ef0687e 909 UpdateMacroList();
8e27fca1 910 UpdateHistoList();
911
4f6473f6 912 // View correct tab
ecbbe371 913 GetGedEditor()->GetTab()->SetTab(fM->GetSelectedTab());
4f6473f6 914}
915
4cbab605 916//______________________________________________________
8bdeb570 917void AliEveTRDTrackListEditor::SetTrackColor(Int_t ind)
4cbab605 918{
16db6074 919 // Sets the color model for the tracks, updates the tracks with this model and
920 // redraws the scene.
921
8bdeb570 922 switch(ind)
923 {
9443fb9d 924 case AliTRDpidUtil::kLQ:
925 fM->UpdateTrackStyle(AliEveTRDTrack::kPID, AliTRDpidUtil::kLQ);
2f9b41fd 926 break;
9443fb9d 927 case AliTRDpidUtil::kNN:
928 fM->UpdateTrackStyle(AliEveTRDTrack::kPID, AliTRDpidUtil::kNN);
2f9b41fd 929 break;
930 default:
931 fM->UpdateTrackStyle(AliEveTRDTrack::kSource);
932 break;
ecbbe371 933 }
8bdeb570 934
ecbbe371 935 gEve->Redraw3D();
4cbab605 936}
937
938//______________________________________________________
8bdeb570 939void AliEveTRDTrackListEditor::SetTrackModel(Int_t ind)
4cbab605 940{
16db6074 941 // Sets the track model for the tracks, updates the tracks with this model and
942 // redraws the scene.
943
8bdeb570 944 switch(ind)
945 {
2f9b41fd 946 case AliEveTRDTrack::kRieman:
947 fM->UpdateTrackStyle(AliEveTRDTrack::kTrackModel, AliEveTRDTrack::kRieman);
948 break;
949 case AliEveTRDTrack::kKalman:
950 fM->UpdateTrackStyle(AliEveTRDTrack::kTrackModel, AliEveTRDTrack::kKalman);
951 break;
952 default:
953 fM->UpdateTrackStyle(AliEveTRDTrack::kTrackCosmics);
954 break;
ecbbe371 955 }
8bdeb570 956
ecbbe371 957 gEve->Redraw3D();
4cbab605 958}
959
4f6473f6 960//______________________________________________________
961void AliEveTRDTrackListEditor::UpdateDataFromMacroListSelection()
962{
16db6074 963 // Saves the current selection in the "Histograms"-tab to the current
964 // AliEveTRDTrackList. This means that the selection is updated and won't
965 // get lost, if another editor is loaded in Eve.
966
4f6473f6 967 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
8e27fca1 968 {
4f6473f6 969 fM->SetHistoDataSelection(i, fCheckButtons[i]->IsOn());
8e27fca1 970 }
caaf90d2 971}
972
ecbbe371 973//______________________________________________________
974void AliEveTRDTrackListEditor::UpdateHistoCanvasTab()
975{
ce239ca6 976 // Updates the histogram and the corresponding tab (including titles).
16db6074 977
ecbbe371 978 // Update name of the tab (tab has been set to current tab!)
979 fHistoCanvasName->SetString(fM->GetName());
980
981 // Use a copy of fHistoCanvasName!! -> If the user closes a tab manually, the TGString
982 // will be deleted -> Error might occur, when accessing the pointer
983 gEve->GetBrowser()->GetTab(1)->GetCurrentTab()->SetText(new TGString(fHistoCanvasName));
984
985 // Switch tabs to force redrawing
986 gEve->GetBrowser()->GetTab(1)->SetTab(0);
987 gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString());
988 fHistoCanvas->Update();
989}
990
c04e790a 991//______________________________________________________
caaf90d2 992void AliEveTRDTrackListEditor::UpdateHistoList()
993{
16db6074 994 // Reloads (updates) the buttons in the "Histograms"-tab via
995 // the current AliEveTRDTrackList (data).
996
4f6473f6 997 fHistoSubFrame->TGCompositeFrame::Cleanup();
caaf90d2 998
999 // Set buttons for histograms
1000 if (fCheckButtons != 0) delete fCheckButtons;
1001 fCheckButtons = new TGCheckButton*[fM->fDataFromMacroList->GetEntries()];
1002
1003 TObjString* iter = (TObjString*)fM->fDataFromMacroList->First();
1004 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries() && iter != 0; i++)
1005 {
1006 fCheckButtons[i] = new TGCheckButton(fHistoSubFrame, iter->GetName());
1007 fHistoSubFrame->AddFrame(fCheckButtons[i]);
1008
1009 fCheckButtons[i]->SetState(kButtonUp, kFALSE);
1010 fCheckButtons[i]->MapRaised();
4f6473f6 1011 fCheckButtons[i]->SetOn(fM->HistoDataIsSelected(i));
1012 fCheckButtons[i]->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "UpdateDataFromMacroListSelection()");
caaf90d2 1013
1014 iter = (TObjString*)fM->fDataFromMacroList->After(iter);
1015 }
2ef0687e 1016}
1017
c04e790a 1018//______________________________________________________
2ef0687e 1019void AliEveTRDTrackListEditor::UpdateMacroList()
1020{
16db6074 1021 // Reloads (updates) the macro list (selection AND process macros) via
1022 // the current AliEveTRDTrackList (data).
1023
caaf90d2 1024 ftlMacroList->RemoveAll();
caaf90d2 1025 ftlMacroSelList->RemoveAll();
38a30030 1026
1027 TMapIter* iter = (TMapIter*)fM->fMacroList->MakeIterator();
1028 TObject* key = 0;
1029 TMacroData* macro = 0;
3f797131 1030
38a30030 1031 Int_t ind = 0;
1032 while ((key = iter->Next()) != 0)
3f797131 1033 {
38a30030 1034 macro = (TMacroData*)fM->fMacroList->GetValue(key);
1035 if (macro != 0)
1036 {
1037 if (macro->IsProcessMacro())
1038 {
1039 ftlMacroList->AddEntry(macro->GetName(), ind);
1040 // Select, what has been selected before
1041 ftlMacroList->Select(ind, fM->MacroListIsSelected(ind));
1042 ind++;
1043 }
1044 else if (macro->IsSelectionMacro())
1045 {
1046 ftlMacroSelList->AddEntry(macro->GetName(), ind);
1047 // Select, what has been selected before
1048 ftlMacroSelList->Select(ind, fM->MacroListIsSelected(ind));
1049 ind++;
1050 }
1051 else
1052 {
1053 Error("AliEveTRDTrackListEditor::UpdateMacroList()",
00dc25ef 1054 Form("Macro \"%s/%s.C\" is neither a selection macro nor a process macro!",
38a30030 1055 macro->GetPath(), macro->GetName()));
1056 }
1057 }
1058 else
1059 {
1060 Error("AliEveTRDTrackListEditor::UpdateMacroList()",
1061 Form("Macro list is corrupted: Macro \"%s\" not found!", key->GetName()));
1062 }
3f797131 1063 }
1064
38a30030 1065 ftlMacroList->SortByName();
caaf90d2 1066 ftlMacroSelList->SortByName();
4f6473f6 1067}
1068
1069//______________________________________________________
1070void AliEveTRDTrackListEditor::UpdateMacroListSelection(Int_t ind)
1071{
38a30030 1072 // Saves the current selection in the macro listS to the current
16db6074 1073 // AliEveTRDTrackList. This means that the selection is updated and won't
1074 // get lost, if another editor is loaded in Eve.
38a30030 1075 // NOTE: The indices in BOTH lists will be unique!
16db6074 1076
4f6473f6 1077 // Toggle selected item
1078 fM->SetMacroListSelection(ind, !fM->MacroListIsSelected(ind));
1079}
db16b708 1080
1081
ce239ca6 1082//______________________________________________________
1083//______________________________________________________
1084//______________________________________________________
1085
1086
db16b708 1087/////////////////////////////////////////////////
00dc25ef 1088ClassImp(AliEveTRDMacroWizard)
ce239ca6 1089/////////////////////////////////////////////////
db16b708 1090
1091//______________________________________________________
00dc25ef 1092AliEveTRDMacroWizard::AliEveTRDMacroWizard(const TGWindow* p)
db16b708 1093 :TGMainFrame(p ? p : gClient->GetRoot(), 10, 10, kMainFrame | kVerticalFrame)
1094 ,fText(0x0)
1095 ,fCombo(0x0)
1096 ,fTextEdit(0x0)
9a11b2ee 1097 ,fbCreate(0x0)
1098 ,fbCancel(0x0)
db16b708 1099{
ce239ca6 1100 // Creates the macro wizard.
1101
db16b708 1102 const Int_t width = 300;
1103
1104 // horizontal frame
1105 TGHorizontalFrame *fFrameName = new TGHorizontalFrame(this, 10, 10, kHorizontalFrame);
1106 TGLabel *fLabel = new TGLabel(fFrameName, "Name*");
1107 fLabel->SetTextJustify(36);
1108 fLabel->SetMargins(0,0,0,0);
1109 fLabel->SetWrapLength(-1);
1110 fFrameName->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1111
1112 fText = new TGTextEntry(fFrameName);
1113 fText->SetMaxLength(255);
1114 fText->SetAlignment(kTextLeft);
1115 fText->SetText("");
1116 fText->Resize(width, fText->GetDefaultHeight());
1117 fFrameName->AddFrame(fText, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1118
1119
1120 // horizontal frame
1121 TGHorizontalFrame *fFrameComment = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1122 fLabel = new TGLabel(fFrameComment, "Comment");
1123 fLabel->SetTextJustify(36);
1124 fLabel->SetMargins(0,0,0,0);
1125 fLabel->SetWrapLength(-1);
1126 fFrameComment->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1127
1128 fTextEdit = new TGTextEdit(fFrameComment, width, 5*fText->GetDefaultHeight());
1129 fFrameComment->AddFrame(fTextEdit, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1130
1131 // horizontal frame
1132 TGHorizontalFrame *fFrameType = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1133 fLabel = new TGLabel(fFrameType, "Type*");
1134 fLabel->SetTextJustify(36);
1135 fLabel->SetMargins(0,0,0,0);
1136 fLabel->SetWrapLength(-1);
1137 fFrameType->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1138
1139 fCombo = new TGComboBox(fFrameType, -1, kHorizontalFrame | kSunkenFrame | kDoubleBorder | kOwnBackground);
1140 fCombo->AddEntry("Single Track Selection", AliEveTRDTrackList::kSingleTrackSelect);
1141 fCombo->AddEntry("Pair Tracks Selection", AliEveTRDTrackList::kCorrelTrackSelect);
1142 fCombo->AddEntry("Single Track Analyse", AliEveTRDTrackList::kSingleTrackAnalyse);
1143 fCombo->AddEntry("Single Track Histo", AliEveTRDTrackList::kSingleTrackHisto);
1144 fCombo->AddEntry("Pair Tracks Analyse", AliEveTRDTrackList::kCorrelTrackAnalyse);
1145 fCombo->AddEntry("Pair Tracks Histo", AliEveTRDTrackList::kCorrelTrackHisto);
1146 fCombo->Select(-1);
1147 fCombo->Resize(width, fText->GetDefaultHeight());
1148 fFrameType->AddFrame(fCombo, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1149
9a11b2ee 1150 // horizontal frame
1151 TGHorizontalFrame *fFrameAction = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1152 fbCancel = new TGTextButton(fFrameAction, "Cancel");
00dc25ef 1153 fbCancel->SetToolTipText("Exit macro creation wizard");
9a11b2ee 1154 fFrameAction->AddFrame(fbCancel, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1155 fbCreate = new TGTextButton(fFrameAction, "Done");
1156 fbCreate->SetToolTipText("Use settings to create the macro");
1157 fFrameAction->AddFrame(fbCreate, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1158
db16b708 1159
1160 // horizontal frame
1161 TGHorizontalFrame *fFrameText = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1162 fLabel = new TGLabel(fFrameText, "(*) Mandatory fields");
1163 fLabel->SetTextJustify(36);
1164 fLabel->SetMargins(0,0,0,0);
1165 fLabel->SetWrapLength(-1);
1166 fFrameText->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1167
1168 // put things together
1169 AddFrame(fFrameName, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1170 AddFrame(fFrameComment, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1171 AddFrame(fFrameType, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
9a11b2ee 1172 AddFrame(fFrameAction, new TGLayoutHints(kLHintsRight | kLHintsTop | kLHintsExpandX,2,2,2,2));
db16b708 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
00dc25ef 1179 SetWindowName("TRD Macro Wizard");
db16b708 1180 SetMWMHints(kMWMDecorAll,
1181 kMWMFuncAll,
1182 kMWMInputModeless);
1183 MapSubwindows();
1184
1185 Resize(GetDefaultSize());
1186 MapWindow();
1187
1188 // Do the linking
00dc25ef 1189 //fCombo->Connect("Selected(Int_t)", "AliEveTRDMacroWizard", this, "Create(Int_t)");
1190 fbCreate->Connect("Clicked()", "AliEveTRDMacroWizard", this, "HandleCreate()");
1191 fbCancel->Connect("Clicked()", "AliEveTRDMacroWizard", this, "CloseWindow()");
9a11b2ee 1192
1193 // Standard choice
1194 fCombo->Select(1, kFALSE);
db16b708 1195}
1196
a6e0ebfe 1197const Char_t *fIncludes =
db16b708 1198"#if !defined(__CINT__) || defined(__MAKECINT__)\n"
1199"#include <TROOT.h>\n"
1200"#include <TH1.h>\n"
1201"#include <TRD/AliTRDgeometry.h>\n"
1202"#include <TRD/AliTRDcluster.h>\n"
1203"#include <TRD/AliTRDseedV1.h>\n"
1204"#include <TRD/AliTRDtrackV1.h>\n"
1205"#endif\n";
1206
a6e0ebfe 1207const Char_t *fMacroTemplate[7] = {
db16b708 1208""
1209," if (!track) return kFALSE;\n"
1210
1211," n = 0;\n"
9a11b2ee 1212" r = 0x0;\n"
db16b708 1213" if (!track) return;\n"
1214
1215," if (!track) return 0x0;\n"
9a11b2ee 1216" TH1* h = 0x0;\n\n"
1217"// Set bins, xmin and xmax here\n"
1218" Int_t n = 1;\n"
1219" Double_t xmin = 0;\n"
1220" Double_t xmax = 100;\n\n"
db16b708 1221" if(!(h = (TH1*)gROOT->FindObject(\"h\"))){\n"
1222" h = new TH1(\"h\", \"Title\", n, xmin, xmax);\n"
1223" h->GetXaxis()->SetTitle("");\n"
1224" h->GetYaxis()->SetTitle("");\n"
1225" } else h->Reset();\n"
1226
1227," if (!track) return kFALSE;\n"
1228" if (!track2) return kFALSE;\n"
1229
1230," n = 0;\n"
9a11b2ee 1231" r = 0x0;\n"
db16b708 1232" if (!track) return;\n"
1233" if (!track2) return;\n"
1234
1235," if (!track) return 0x0;\n"
1236" if (!track2) return 0x0;\n"
9a11b2ee 1237" TH1* h = 0x0;\n\n"
1238"// Set bins, xmin and xmax here\n"
1239" Int_t n = 1;\n"
1240" Double_t xmin = 0;\n"
1241" Double_t xmax = 100;\n\n"
db16b708 1242" if(!(h = (TH1*)gROOT->FindObject(\"h\"))){\n"
1243" h = new TH1(\"h\", \"Title\", n, xmin, xmax);\n"
1244" h->GetXaxis()->SetTitle("");\n"
1245" h->GetYaxis()->SetTitle("");\n"
1246" } else h->Reset();\n"
1247};
1248//______________________________________________________
00dc25ef 1249void AliEveTRDMacroWizard::Create(Int_t type)
db16b708 1250{
ce239ca6 1251 // Creates the macro with the selected type (combo box).
1252
db16b708 1253 const Char_t *name = fText->GetText();
1254 if(strcmp(name,"")==0){
1255 AliInfo("Please specify a name for your macro.");
9a11b2ee 1256 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
1257 "Please specify a name for your macro.", kMBIconExclamation, kMBOk);
1258 //fCombo->Select(-1);
1259 return;
1260 }
1261
1262 // Note: gSystem->AccessPathName(...) returns kTRUE, if the access FAILED!
1263 if(!gSystem->AccessPathName(Form("./%s.C", name))){
1264 // If there is already a file with this name -> Error
1265 AliInfo(Form("A macro \"%s.C\" already exists in the current directory!\nPlease choose another name!", name));
1266 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
1267 Form("A macro \"%s.C\" already exists in the current directory!\nPlease choose another name!", name), kMBIconExclamation, kMBOk);
1268 //fCombo->Select(-1);
db16b708 1269 return;
1270 }
1271
1272 FILE* fp = 0x0;
1273 if(!(fp = fopen(Form("%s.C", name), "wt"))){
1274 AliInfo("Couldn't create macro file.");
9a11b2ee 1275 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
1276 "Couldn't create macro file.", kMBIconExclamation, kMBOk);
1277 //fCombo->Select(-1);
db16b708 1278 return;
1279 }
1280
1281 TGText *comment = fTextEdit->GetText();
1282 Char_t *line = 0x0; Int_t iline = 0;
1283 while((line = comment->GetLine(TGLongPosition(0,iline++), 200))) fprintf(fp, "// %s\n", line);
1284
1285 fprintf(fp, "\n%s\n", fIncludes);
1286
00dc25ef 1287 switch(type){
db16b708 1288 case AliEveTRDTrackList::kSingleTrackSelect:
1289 fprintf(fp, "Bool_t %s(const AliTRDtrackV1 *track)\n", name);
1290 break;
1291 case AliEveTRDTrackList::kCorrelTrackSelect:
1292 fprintf(fp, "Bool_t %s(const AliTRDtrackV1 *track, const AliTRDtrackV1 *track2)\n", name);
1293 break;
1294 case AliEveTRDTrackList::kSingleTrackAnalyse:
1295 fprintf(fp, "void %s(const AliTRDtrackV1 *track, Double_t*& r, Int_t& n)\n", name);
1296 break;
1297 case AliEveTRDTrackList::kSingleTrackHisto:
1298 fprintf(fp, "TH1* %s(const AliTRDtrackV1 *track)\n", name);
1299 break;
1300 case AliEveTRDTrackList::kCorrelTrackAnalyse:
1301 fprintf(fp, "void %s(const AliTRDtrackV1 *track, const AliTRDtrackV1 *track2, Double_t*& r, Int_t& n)\n", name);
1302 break;
1303 case AliEveTRDTrackList::kCorrelTrackHisto:
1304 fprintf(fp, "TH1* %s(const AliTRDtrackV1 *track, const AliTRDtrackV1 *track2)\n", name);
1305 break;
1306 default:
00dc25ef 1307 AliInfo(Form("Unknown type[%d]", type));
9a11b2ee 1308 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
00dc25ef 1309 Form("Unknown type[%d]", type), kMBIconExclamation, kMBOk);
db16b708 1310 fclose(fp);
1311 gSystem->Exec(Form("rm -f %s.C", name));
9a11b2ee 1312 //fCombo->Select(-1);
db16b708 1313 return;
1314 }
1315
00dc25ef 1316 fprintf(fp, "{\n%s\n", fMacroTemplate[type]);
db16b708 1317 fprintf(fp, "// add your own code here\n\n\n}\n");
1318 fclose(fp);
57d55fae 1319
00dc25ef 1320 Emit("Create(Int_t)", type);
57d55fae 1321 Create((Char_t*)name);
db16b708 1322 CloseWindow();
1323}
57d55fae 1324
1325//______________________________________________________
00dc25ef 1326void AliEveTRDMacroWizard::Create(Char_t *name)
57d55fae 1327{
ce239ca6 1328 // Emits the creation signal.
1329
57d55fae 1330 Emit("Create(Char_t*)", Form("%s.C", name));
1331}
9a11b2ee 1332
1333//______________________________________________________
00dc25ef 1334void AliEveTRDMacroWizard::HandleCreate()
9a11b2ee 1335{
ce239ca6 1336 // Handles the signal, when the creation button is pressed.
1337
9a11b2ee 1338 Create(fCombo->GetSelected());
1339}