1 // Author: Benjamin Hess 29/01/2010
3 /*************************************************************************
4 * Copyright (C) 2009-2010, Alexandru Bercuci, Benjamin Hess. *
5 * All rights reserved. *
6 *************************************************************************/
8 //////////////////////////////////////////////////////////////////////////
10 // AliEveTRDTrackListEditor //
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. //
21 //////////////////////////////////////////////////////////////////////////
24 #include <AliEveTRDData.h>
25 #include <AliEveTRDTrackList.h>
26 #include "AliEveTRDTrackListEditor.h"
27 #include <AliEveEventManager.h>
28 #include <AliTRDReconstructor.h>
29 #include <AliTRDtrackV1.h>
33 #include <TEveBrowser.h>
34 #include <TEveGedEditor.h>
35 #include <TEveMacro.h>
36 #include <TEveManager.h>
39 #include <TGButtonGroup.h>
40 #include <TGFileDialog.h>
42 #include <TGListBox.h>
46 #include <TObjString.h>
49 #include <TGTextEntry.h>
50 #include <TGTextEdit.h>
51 #include <TGComboBox.h>
52 #include <TGTextView.h>
54 #include <TTreeStream.h>
57 ClassImp(AliEveTRDTrackListEditor)
59 ///////////////////////////////////////////////////////////
60 ///////////// AliEveTRDTrackListEditor //////////////////
61 ///////////////////////////////////////////////////////////
62 AliEveTRDTrackListEditor::AliEveTRDTrackListEditor(const TGWindow* p, Int_t width, Int_t height,
63 UInt_t options, Pixel_t back) :
64 TGedFrame(p, width, height, options, back),
68 fInheritedMacroList(0),
69 fInheritSettings(kFALSE),
77 frbColor(new TGRadioButton*[3]),
78 frbTrack(new TGRadioButton*[3]),
89 fLabel1(0), fLabel2(0), fLabel3(0), fLabel4(0),
90 fLine1(0), fLine2(0), fLine3(0), fLine4(0), fLine5(0),
93 // Creates the AliEveTRDTrackListEditor.
96 fLine5 = new TGHorizontal3DLine(this, 194, 8);
97 AddFrame(fLine5, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 8));
98 fStyleFrame = new TGHorizontalFrame(this);
99 AddFrame(fStyleFrame);
101 // Style - Track model
102 fbgStyleTrack = new TGButtonGroup(fStyleFrame, "Track model");
103 fbgStyleTrack->SetMapSubwindows(kTRUE);
104 fbgStyleTrack->Resize(194, 200);
105 fStyleFrame->AddFrame(fbgStyleTrack);
107 frbTrack[0] = new TGRadioButton(fbgStyleTrack, "Rieman", 0);
108 frbTrack[0]->SetToolTipText("Set the track model to \"Rieman\" (i.e. the used fit method)");
109 frbTrack[1] = new TGRadioButton(fbgStyleTrack, "Kalman", 1);
110 frbTrack[1]->SetToolTipText("Set the track model to \"Kalman\" (i.e. the used fit method)");
111 frbTrack[2] = new TGRadioButton(fbgStyleTrack, "Line", 2);
112 frbTrack[2]->SetToolTipText("Set the track model to \"Line\" (i.e. the used fit method)");
114 // Style - Color model
115 fbgStyleColor = new TGButtonGroup(fStyleFrame, "Color model");
116 fbgStyleColor->SetMapSubwindows(kTRUE);
117 fbgStyleColor->Resize(194, 200);
118 fStyleFrame->AddFrame(fbgStyleColor);
120 frbColor[0] = new TGRadioButton(fbgStyleColor, "PID LQ", 0);
121 frbColor[0]->SetToolTipText("Set color model to \"PID LQ\" -> 2 dimensional likelihood particle identification");
122 frbColor[1] = new TGRadioButton(fbgStyleColor, "PID NN", 1);
123 frbColor[1]->SetToolTipText("Set color model to \"PID NN\" -> Neural network particle identification");
124 frbColor[2] = new TGRadioButton(fbgStyleColor, "ESD Source", 2);
125 frbColor[2]->SetToolTipText("Set color model to \"ESD Source\" -> By source (TPC track prolongation or TRD stand alone)");
127 // Functionality for adding plugins
128 fMainFrame = CreateEditorTabSubFrame("Process");
130 fLabel1 = new TGLabel(fMainFrame,"Add plugin(s):");
131 fMainFrame->AddFrame(fLabel1);
132 fBrowseFrame = new TGHorizontalFrame(fMainFrame);
134 fteField = new TGTextEntry(fBrowseFrame);
135 fteField->SetToolTipText("Enter the pathname of the macro you want to add here and press \"Enter\"");
136 fteField->Connect("ReturnPressed()","AliEveTRDTrackListEditor", this, "HandleMacroPathSet()");
137 fBrowseFrame->AddFrame(fteField);
139 fbBrowse = new TGTextButton(fBrowseFrame, "Browse");
140 fbBrowse->SetToolTipText("Browse the macro you want to add");
141 fbBrowse->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "BrowseMacros()");
142 fBrowseFrame->AddFrame(fbBrowse);
144 fbNew = new TGTextButton(fBrowseFrame, "New");
145 fbNew->SetToolTipText("Start macro creation wizard");
146 fbNew->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "NewMacros()");
147 fBrowseFrame->AddFrame(fbNew);
148 fMainFrame->AddFrame(fBrowseFrame);
150 fLine1 = new TGHorizontal3DLine(fMainFrame, 194, 8);
151 fMainFrame->AddFrame(fLine1, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
152 fLabel2 = new TGLabel(fMainFrame,"Selection plugins:");
153 fMainFrame->AddFrame(fLabel2);
155 ftlMacroSelList = new TGListBox(fMainFrame);
156 ftlMacroSelList->Resize(194, 94);
157 ftlMacroSelList->SetMultipleSelections(kTRUE);
158 fMainFrame->AddFrame(ftlMacroSelList);
160 fLine2 = new TGHorizontal3DLine(fMainFrame, 194, 8);
161 fMainFrame->AddFrame(fLine2, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
162 fLabel3 = new TGLabel(fMainFrame,"Process plugins:");
163 fMainFrame->AddFrame(fLabel3);
165 ftlMacroList = new TGListBox(fMainFrame);
166 ftlMacroList->Resize(194, 94);
167 ftlMacroList->SetMultipleSelections(kTRUE);
168 fMainFrame->AddFrame(ftlMacroList);
170 fLine3 = new TGHorizontal3DLine(fMainFrame, 194, 8);
171 fMainFrame->AddFrame(fLine3, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
173 fbApplyMacros = new TGTextButton(fMainFrame, "Apply plugin(s)");
174 fbApplyMacros->SetToolTipText("Apply all selected macros/class functins to the list of tracks -> A data file will be generated");
175 fbApplyMacros->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "ApplyMacros()");
176 fbApplyMacros->SetRightMargin(12);
177 fMainFrame->AddFrame(fbApplyMacros);
179 fbRemoveMacros = new TGTextButton(fMainFrame, "Remove plugin(s)");
180 fbRemoveMacros->SetToolTipText("Remove the selected macros/class functions from the list(s)");
181 fbRemoveMacros->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "RemoveMacros()");
182 fMainFrame->AddFrame(fbRemoveMacros);
184 // Stuff for displaying histograms
185 fHistoFrame = CreateEditorTabSubFrame("Results");
186 fHistoFrame->SetMapSubwindows(kTRUE);
187 fLabel4 = new TGLabel(fHistoFrame,"Data from plugins:");
188 fHistoFrame->AddFrame(fLabel4);
190 fHistoSubFrame = new TGVerticalFrame(fHistoFrame);
191 fHistoSubFrame->SetMapSubwindows(kTRUE);
192 fHistoSubFrame->Resize(194, 200);
193 fHistoFrame->AddFrame(fHistoSubFrame);
195 fLine4 = new TGHorizontal3DLine(fHistoFrame, 194, 8);
196 fHistoFrame->AddFrame(fLine4, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
198 fbDrawHisto = new TGTextButton(fHistoFrame, "Draw projections");
199 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!");
200 fbDrawHisto->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "DrawHistos()");
201 fHistoFrame->AddFrame(fbDrawHisto);
203 // Set up file dialog
204 fFileInfo = new TGFileInfo();
205 fFileInfo->SetMultipleSelection(kTRUE);
207 fFileTypes = new Char_t*[6];
208 fFileTypes[0] = (Char_t*)"All files"; fFileTypes[1] = (Char_t*)"*";
209 fFileTypes[2] = (Char_t*)"ROOT macros"; fFileTypes[3] = (Char_t*)"*.C";
210 fFileTypes[4] = 0; fFileTypes[5] = 0;
211 fFileInfo->fFileTypes = (const Char_t**)fFileTypes;
212 fFileInfo->fIniDir = (Char_t*)"$ALICE_ROOT/PWGPP/TRD/macros/EVE";
213 fFileInfo->fFileTypeIdx = 2;
214 fFileInfo->fMultipleSelection = kTRUE;
216 fHistoCanvasName = new TGString("");
218 // Handle style changed signals:
219 fbgStyleTrack->Connect("Clicked(Int_t)", "AliEveTRDTrackListEditor", this, "SetTrackModel(Int_t)");
220 fbgStyleColor->Connect("Clicked(Int_t)", "AliEveTRDTrackListEditor", this, "SetTrackColor(Int_t)");
222 // Handle the signal "Selected(Int_t ind)"
223 ftlMacroList->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor", this, "UpdateMacroListSelection(Int_t)");
224 ftlMacroSelList->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor", this, "UpdateMacroListSelection(Int_t)");
226 // Handle the signal "NewEventLoaded"
227 AliEveEventManager::GetMaster()->Connect("NewEventLoaded()", "AliEveTRDTrackListEditor", this, "HandleNewEventLoaded()");
229 // Handle the signal "Selected" (another tab has been selected)
230 GetGedEditor()->GetTab()->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor", this, "HandleTabChangedToIndex(Int_t)");
233 //______________________________________________________
234 AliEveTRDTrackListEditor::~AliEveTRDTrackListEditor()
236 // Destructor: Closes all tabs created by this object and
237 // frees the corresponding memory.
241 delete [] fFileTypes;
250 // Close and delete all tabs that have been created by this class
253 if (fHistoCanvasName != 0)
255 delete fHistoCanvasName;
256 fHistoCanvasName = 0;
258 if (fInheritedMacroList != 0)
260 fInheritedMacroList->Delete();
261 delete fInheritedMacroList;
262 fInheritedMacroList = 0;
266 //______________________________________________________
267 void AliEveTRDTrackListEditor::AddMacro(const Char_t* name, const Char_t* path)
269 // Adds the macro path/name to the macro list. A warning is provided, if there is
270 // something wrong, e.g. if the macro does not have the correct signature.
271 Int_t result = fM->AddMacro(path, name);
279 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Warning", "Macro is already in list (won't be added again)!",
280 kMBIconExclamation, kMBOk);
283 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", "Failed to load the macro (check messages in the terminal)!",
284 kMBIconExclamation, kMBOk);
286 case SIGNATURE_ERROR:
287 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
288 "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*)",
289 kMBIconExclamation, kMBOk);
291 case NOT_EXIST_ERROR:
292 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
293 "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
296 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
297 Form("AliEveTRDTrackList::AddMacro exited with unknown return value: %d", result),
298 kMBIconExclamation, kMBOk);
303 //______________________________________________________
304 void AliEveTRDTrackListEditor::ApplyMacros()
306 // Applies the selected macros and updates the view.
308 Bool_t success = kFALSE;
310 // First apply the single track selection macros
311 TList* selIterator = new TList();
312 ftlMacroSelList->GetSelectedEntries(selIterator);
313 fM->ApplySTSelectionMacros(selIterator);
318 // Now apply the process macros
319 TList* procIterator = new TList();
320 ftlMacroList->GetSelectedEntries(procIterator);
321 success = fM->ApplyProcessMacros(selIterator, procIterator);
323 // Update histogram tab (data has to be reloaded)
327 // AlieveTRDTrackList::ApplyProcessMacros() automatically selects a macro -> Draw the histogram for it,
328 // if a process macro has been applied
329 if (success && procIterator->GetEntries() > 0)
331 // Set focus on "Histograms" tab
332 GetGedEditor()->GetTab()->SetTab("Results");
341 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
342 "AliEveTRDTrackList::ApplyProcessMacros experienced an error (cf. CINT-output)!",
343 kMBIconExclamation, kMBOk);
347 //______________________________________________________
348 void AliEveTRDTrackListEditor::NewMacros()
350 // Start the macro creation wizard.
351 // thanks to Jacek Otwinowski<J.Otwinowski@GSI.DE> for this suggestion
353 AliEveTRDMacroWizard *wizz = new AliEveTRDMacroWizard();
354 wizz->Connect("Create(Char_t*)", "AliEveTRDTrackListEditor", this, "AddMacro(Char_t*)");
358 //______________________________________________________
359 void AliEveTRDTrackListEditor::BrowseMacros()
361 // Creates a file-dialog. The selected files will be added to the macro list
362 // via AddMacro(...).
364 new TGFileDialog(gClient->GetRoot(), GetMainFrame(), kFDOpen, fFileInfo);
366 if (fFileInfo->fIniDir != 0 && fFileInfo->fFileNamesList != 0)
369 TObject* iter = fFileInfo->fFileNamesList->First();
375 // NOTE: fileInfo->fFileNamesList will be changed by that, too!
376 name = (Char_t*)strrchr(iter->GetName(), '/');
377 // Delete '"' at the end
378 name[strlen(name)] = '\0';
380 AddMacro(name + 1, fFileInfo->fIniDir);
381 iter = (TObjString*)fFileInfo->fFileNamesList->After(iter);
385 // -> The following problem has been fixed (trunk -> Changes according to 03 September 2008):
386 // Some error occurs, when one ends the filedialog with "cancel": fileInfo->fFileNamesList is set to 0x0, but
387 // in the next launch no new memory is allocated. So do this manually.
388 //if (fileInfo->fFileNamesList == 0) fileInfo->fFileNamesList = new TList();
391 //______________________________________________________
392 void AliEveTRDTrackListEditor::CloseTabs()
394 // Closes + deletes the tabs created by this object
396 if (fHistoCanvas != 0)
398 // Close the created tab, if it exists
399 if (fHistoCanvasName != 0)
401 if (gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString()))
403 // Now the created tab is the current one and can be deleted
404 gEve->GetBrowser()->GetTab(1)->RemoveTab();
407 // With the tab removal, the canvas will be deleted automatically!
412 //______________________________________________________
413 void AliEveTRDTrackListEditor::DrawHistos()
415 // Accesses the temporary data file created by the last call of ApplyMacros() and draws
416 // histograms according to the selection in the "Histograms"-tab.
418 // Int_t nHistograms = GetNSelectedHistograms();
419 // if (nHistograms<=0 || nHistograms>3) {
420 // new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
421 // Form("Number of selected projections [%d] outside range [1-3]!", nHistograms), kMBIconExclamation, kMBOk);
426 if (!(file=TFile::Open(Form("/tmp/TRD.TrackListMacroData_%s.root", gSystem->Getenv("USER")), "READ"))) {
427 AliError(Form("Cannot open file \"/tmp/TRD.TrackListMacroData_%s.root\"",
428 gSystem->Getenv("USER")));
429 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
430 Form("Cannot open file \"/tmp/TRD.TrackListMacroData_%s.root\"", gSystem->Getenv("USER")),
431 kMBIconExclamation, kMBOk);
434 TTree *ts(NULL);//, *tc(NULL);
435 if (!(ts=(TTree*)file->Get("sTrack"))) {
436 AliError(Form("Cannot find tree \"sTrack\" in file \"/tmp/TRD.TrackListMacroData_%s.root\"",
437 gSystem->Getenv("USER")));
438 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
439 Form("Cannot find tree \"sTrack\" in file \"/tmp/TRD.TrackListMacroData_%s.root\"", gSystem->Getenv("USER")),
440 kMBIconExclamation, kMBOk);
443 // if (!(tc=(TTree*)file->Get("cTrack"))) {
444 // AliError(Form("Cannot find tree \"cTrack\" in file \"/tmp/TRD.TrackListMacroData_%s.root\"",
445 // gSystem->Getenv("USER")));
446 // new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
447 // Form("Cannot find tree \"cTrack\" in file \"/tmp/TRD.TrackListMacroData_%s.root\"", gSystem->Getenv("USER")),
448 // kMBIconExclamation, kMBOk);
452 // Close any potential tab left from previous plottings
453 TGTab *tab(gEve->GetBrowser()->GetTab(1)); TGTabElement *tt(NULL);
454 TString vs; Int_t canvas(0), singleSelected(0);
455 while((tt=tab->GetTabTab(1))){
456 AliDebug(1, Form("Deleting tab[%s]", tt->GetString()));
457 tab->CloseTab(1); // trick. always close second tab due to internal renumbering inside TGTab
459 // Check, if a histo macro shall be drawn
462 for (Int_t j = 0; j < fM->fDataFromMacroList->GetEntries(); j++) {
463 if (fCheckButtons[j]->TGButton::GetState() != kButtonDown) continue;
464 TString s(fCheckButtons[j]->GetTitle()); Int_t idx(s.Index('['));
467 if (!(myHist = (TH1*)file->Get(s.Data()))) {
468 AliError(Form("No histo[%s] found !", s.Data()));
469 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
470 Form("No histo[%s] found !", s.Data()), kMBIconExclamation, kMBOk);
472 SetDrawingToHistoCanvasTab(++canvas);
474 UpdateHistoCanvasTab(canvas);
477 TString ss=s(0, idx);
478 if (!ts->GetBranch(ss.Data())) {
479 AliError(Form("No data for macro \"%s\" found !", ss.Data()));
480 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw tree",
481 Form("No data for macro \"%s\" found !",
482 ss.Data()), kMBIconExclamation, kMBOk);
488 } else if(singleSelected<3){
492 AliError(Form("Variable \"%s\" can no longer be attached to plot !", s.Data()));
498 SetDrawingToHistoCanvasTab(++canvas);
500 UpdateHistoCanvasTab(canvas);
509 //______________________________________________________
510 Int_t AliEveTRDTrackListEditor::GetNSelectedHistograms() const
512 // Returns the number of selected macros (or rather: of their selected data) in the "Histograms"-tab
516 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
518 if (fCheckButtons[i]->TGButton::GetState() == kButtonDown) count++;
524 //______________________________________________________
525 void AliEveTRDTrackListEditor::HandleMacroPathSet()
527 // Takes the input of the text field (adding a macro), checks if the macro can be
528 // accessed (and that it exists) and adds the macro to the macro list via AddMacro(...).
529 // You can use environment variables in the text field, e.g. "$ALICE_ROOT/Eve/alice-macro/myMacro.C".
531 Char_t bname[AliEveTRDTrackList::fkMaxMacroNameLength]; // allocate buffers
533 if (strlen(fteField->GetText()) != 0)
535 // Expand the pathname
536 Char_t* systemPath = gSystem->ExpandPathName(fteField->GetText());
537 fteField->SetText(systemPath);
541 // Check if file exists
544 fp = fopen(fteField->GetText(), "rb");
550 Char_t* name = (Char_t*)strrchr(fteField->GetText(), '/');
555 memset(name, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroNameLength);
556 snprintf(name, AliEveTRDTrackList::fkMaxMacroNameLength, "%s", fteField->GetText());
558 // Add path to textfield -> Path is "./" -> Use length for the name + 2
559 Char_t pathname[AliEveTRDTrackList::fkMaxMacroNameLength + 2];
560 memset(pathname, '\0', sizeof(Char_t) * (AliEveTRDTrackList::fkMaxMacroNameLength + 2));
561 snprintf(pathname, AliEveTRDTrackList::fkMaxMacroNameLength + 2, "./%s", fteField->GetText());
562 fteField->SetText(pathname);
570 Char_t path[AliEveTRDTrackList::fkMaxMacroPathLength];
571 memset(path, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroPathLength);
572 snprintf(path, strlen(fteField->GetText()) - strlen(name), "%s", fteField->GetText());
574 // Ignore the slash "/" in name
575 AddMacro(name + 1, path);
580 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
581 "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
586 //______________________________________________________
587 void AliEveTRDTrackListEditor::HandleNewEventLoaded()
589 // Closes the tabs created by this object and sets a flag that will
590 // cause the function SetModel() to inherit the macro lists + style
591 // for the next AliEveTRDTrackList from the current one.
593 // Inherit the macro list and track style for the next track list!
594 fInheritSettings = kTRUE;
600 //______________________________________________________
601 void AliEveTRDTrackListEditor::HandleTabChangedToIndex(Int_t index)
603 // Saves the current tab in the current AliEveTRDTrackList.
605 fM->SetSelectedTab(index);
608 //______________________________________________________
609 void AliEveTRDTrackListEditor::InheritMacroList()
611 // The old macro list is possibly stored in the corresponding interior map. This function will
612 // use this interior map to move the data from the interior map to the newly loaded AliEveTRDTrackList.
613 // Then the interior map will be cleaned up. With this, the settings will be inherited from the previously
614 // loaded AliEveTRDTrackList.
616 if (fInheritedMacroList == 0) return;
619 fM->fMacroList->Delete();
621 // Store data from interior list in the track list's map
622 TMapIter* iter = (TMapIter*)fInheritedMacroList->MakeIterator();
625 TMacroData* macro = 0;
627 while ((key = iter->Next()) != 0)
629 macro = (TMacroData*)fInheritedMacroList->GetValue(key);
630 if (macro != 0) fM->fMacroList->Add(new TObjString(key->GetName()),
631 new TMacroData(macro->GetName(), macro->GetPath(), macro->GetType()));
634 Error("AliEveTRDTrackListEditor::InheritMacroList", "Failed to inherit the macro \"%s\"!", key->GetName());
638 fInheritedMacroList->Delete();
639 delete fInheritedMacroList;
640 fInheritedMacroList = 0;
643 //______________________________________________________
644 void AliEveTRDTrackListEditor::InheritStyle()
646 // The old styles are stored in the corresponding button groups. This function will replace
647 // the style settings of the newly loaded AliEveTRDTrackList with the old styles. With this, the settings
648 // will be inherited from the previously loaded AliEveTRDTrackList.
650 for (Int_t ind = 0; ind < 3; ind++)
652 if (fbgStyleTrack->GetButton(ind)->IsOn())
658 for (Int_t ind = 0; ind < 3; ind++)
660 if (fbgStyleColor->GetButton(ind)->IsOn())
668 //______________________________________________________
669 void AliEveTRDTrackListEditor::RemoveMacros()
671 // Removes the selected macros from the corresponding list.
674 ftlMacroList->GetSelectedEntries(&iterator);
675 fM->RemoveSelectedMacros(&iterator);
679 ftlMacroSelList->GetSelectedEntries(&iterator);
680 fM->RemoveSelectedMacros(&iterator);
682 // Selected macros are deleted from the list -> No selected entries left
683 fM->fMacroListSelected = 0;
687 //______________________________________________________
688 void AliEveTRDTrackListEditor::SaveMacroList(TMap* list)
690 // Saves the provided macro list in an interior list. This list will be used by
691 // InheritMacroList() to restore the data in "list". With this method one is able
692 // to inherit the macro list from track list to track list (i.e. from event to event).
694 if (fInheritedMacroList != 0)
696 fInheritedMacroList->Delete();
697 delete fInheritedMacroList;
699 fInheritedMacroList = new TMap();
700 fInheritedMacroList->SetOwnerKeyValue(kTRUE, kTRUE);
702 TMapIter* iter = (TMapIter*)list->MakeIterator();
704 TMacroData* macro = 0;
706 while ((key = iter->Next()) != 0)
708 macro = (TMacroData*)fM->fMacroList->GetValue(key);
709 if (macro != 0) fInheritedMacroList->Add(new TObjString(key->GetName()),
710 new TMacroData(macro->GetName(), macro->GetPath(), macro->GetType()));
713 Error("AliEveTRDTrackListEditor::SaveMacroList", "Failed to inherit the macro \"%s\"!", key->GetName());
718 //______________________________________________________
719 void AliEveTRDTrackListEditor::SetDrawingToHistoCanvasTab(Int_t canvas)
721 // Sets gPad to the tab with the name of the current AliEveTRDTrackList. If this tab does
722 // not exist, it will be created. Otherwise, it is re-used.
724 // If the tab with the canvas has been closed, the canvas will be deleted.
725 // So, if there is no tab, set the canvas pointer to zero and recreate it in a new tab.
727 AliDebug(1, Form("Build Tab[%s_%d]", fM->GetName(), canvas));
728 fHistoCanvas = gEve->AddCanvasTab(Form("%s_%d", fM->GetName(), canvas));
729 fHistoCanvas->SetName(Form("c_%d", canvas));
733 //______________________________________________________
734 void AliEveTRDTrackListEditor::SetModel(TObject* obj)
736 // Sets the model object, updates the related data in the GUI and
737 // inherits settings (cf. Inherit*(...)), if the flag fInheritSettings is set to kTRUE.
739 fM = dynamic_cast<AliEveTRDTrackList*>(obj);
743 Error("SetModel", "Parameter is zero pointer");
747 // Provide a pointer to this editor
750 // If macro list + track style shall be inherited from previously loaded track list, do so
751 if (fInheritSettings)
756 fInheritSettings = kFALSE;
759 // Select the correct styles
761 UChar_t style = fM->GetSelectedTrackStyle();
762 if (TESTBIT(style, AliEveTRDTrack::kSource)) b = 2;
765 if (TESTBIT(style, AliEveTRDTrack::kPID)) b = 1;
768 fbgStyleColor->SetButton(b, kTRUE);
771 if (TESTBIT(style, AliEveTRDTrack::kTrackCosmics)) b = 2;
774 if (TESTBIT(style, AliEveTRDTrack::kTrackModel)) b = 1;
777 fbgStyleTrack->SetButton(b, kTRUE);
783 GetGedEditor()->GetTab()->SetTab(fM->GetSelectedTab());
786 //______________________________________________________
787 void AliEveTRDTrackListEditor::SetTrackColor(Int_t ind)
789 // Sets the color model for the tracks, updates the tracks with this model and
790 // redraws the scene.
794 case AliTRDpidUtil::kLQ:
795 fM->UpdateTrackStyle(AliEveTRDTrack::kPID, AliTRDpidUtil::kLQ);
797 case AliTRDpidUtil::kNN:
798 fM->UpdateTrackStyle(AliEveTRDTrack::kPID, AliTRDpidUtil::kNN);
801 fM->UpdateTrackStyle(AliEveTRDTrack::kSource);
808 //______________________________________________________
809 void AliEveTRDTrackListEditor::SetTrackModel(Int_t ind)
811 // Sets the track model for the tracks, updates the tracks with this model and
812 // redraws the scene.
816 case AliEveTRDTrack::kRieman:
817 fM->UpdateTrackStyle(AliEveTRDTrack::kTrackModel, AliEveTRDTrack::kRieman);
819 case AliEveTRDTrack::kKalman:
820 fM->UpdateTrackStyle(AliEveTRDTrack::kTrackModel, AliEveTRDTrack::kKalman);
823 fM->UpdateTrackStyle(AliEveTRDTrack::kTrackCosmics);
830 //______________________________________________________
831 void AliEveTRDTrackListEditor::UpdateDataFromMacroListSelection()
833 // Saves the current selection in the "Histograms"-tab to the current
834 // AliEveTRDTrackList. This means that the selection is updated and won't
835 // get lost, if another editor is loaded in Eve.
837 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
839 fM->SetHistoDataSelection(i, fCheckButtons[i]->IsOn());
843 //______________________________________________________
844 void AliEveTRDTrackListEditor::UpdateHistoCanvasTab(Int_t canvas)
846 // Updates the histogram and the corresponding tab (including titles).
848 // Update name of the tab (tab has been set to current tab!)
849 //fHistoCanvasName->SetString(Form("%s_%d", fM->GetName(), canvas));
851 // Use a copy of fHistoCanvasName!! -> If the user closes a tab manually, the TGString
852 // will be deleted -> Error might occur, when accessing the pointer
853 //gEve->GetBrowser()->GetTab(canvas)->GetCurrentTab()->SetText(new TGString(fHistoCanvasName));
855 // Switch tabs to force redrawing
856 TGTab *tab(gEve->GetBrowser()->GetTab(1));
857 if(tab->GetCurrent() != canvas){
858 AliError(Form("Curent tab[%s] tabId[%d] mismatch %d", tab->GetCurrentTab()->GetString(), tab->GetCurrent(), canvas));
861 if(!tab->SetTab(canvas)){
862 AliError(Form("Failed updating tab[%d]", canvas));
865 fHistoCanvas->Modified();
866 fHistoCanvas->Update();
869 //______________________________________________________
870 void AliEveTRDTrackListEditor::UpdateHistoList()
872 // Reloads (updates) the buttons in the "Histograms"-tab via
873 // the current AliEveTRDTrackList (data).
875 fHistoSubFrame->TGCompositeFrame::Cleanup();
877 // Set buttons for histograms
878 if (fCheckButtons != 0) delete fCheckButtons;
879 fCheckButtons = new TGCheckButton*[fM->fDataFromMacroList->GetEntries()];
881 TObjString* iter = (TObjString*)fM->fDataFromMacroList->First();
882 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries() && iter != 0; i++)
884 fCheckButtons[i] = new TGCheckButton(fHistoSubFrame, iter->GetName());
885 fHistoSubFrame->AddFrame(fCheckButtons[i]);
887 fCheckButtons[i]->SetState(kButtonUp, kFALSE);
888 fCheckButtons[i]->MapRaised();
889 fCheckButtons[i]->SetOn(fM->HistoDataIsSelected(i));
890 fCheckButtons[i]->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "UpdateDataFromMacroListSelection()");
892 iter = (TObjString*)fM->fDataFromMacroList->After(iter);
896 //______________________________________________________
897 void AliEveTRDTrackListEditor::UpdateMacroList()
899 // Reloads (updates) the macro list (selection AND process macros) via
900 // the current AliEveTRDTrackList (data).
902 ftlMacroList->RemoveAll();
903 ftlMacroSelList->RemoveAll();
905 TMapIter* iter = (TMapIter*)fM->fMacroList->MakeIterator();
907 TMacroData* macro = 0;
910 while ((key = iter->Next()) != 0)
912 macro = (TMacroData*)fM->fMacroList->GetValue(key);
915 if (macro->IsProcessMacro())
917 ftlMacroList->AddEntry(macro->GetName(), ind);
918 // Select, what has been selected before
919 ftlMacroList->Select(ind, fM->MacroListIsSelected(ind));
922 else if (macro->IsSelectionMacro())
924 ftlMacroSelList->AddEntry(macro->GetName(), ind);
925 // Select, what has been selected before
926 ftlMacroSelList->Select(ind, fM->MacroListIsSelected(ind));
931 Error("AliEveTRDTrackListEditor::UpdateMacroList()",
932 "Macro \"%s/%s.C\" is neither a selection macro nor a process macro!",
933 macro->GetPath(), macro->GetName());
938 Error("AliEveTRDTrackListEditor::UpdateMacroList()",
939 "Macro list is corrupted: Macro \"%s\" not found!", key->GetName());
943 ftlMacroList->SortByName();
944 ftlMacroSelList->SortByName();
947 //______________________________________________________
948 void AliEveTRDTrackListEditor::UpdateMacroListSelection(Int_t ind)
950 // Saves the current selection in the macro listS to the current
951 // AliEveTRDTrackList. This means that the selection is updated and won't
952 // get lost, if another editor is loaded in Eve.
953 // NOTE: The indices in BOTH lists will be unique!
955 // Toggle selected item
956 fM->SetMacroListSelection(ind, !fM->MacroListIsSelected(ind));
960 //______________________________________________________
961 //______________________________________________________
962 //______________________________________________________
965 /////////////////////////////////////////////////
966 ClassImp(AliEveTRDMacroWizard)
967 /////////////////////////////////////////////////
969 //______________________________________________________
970 AliEveTRDMacroWizard::AliEveTRDMacroWizard(const TGWindow* p)
971 :TGMainFrame(p ? p : gClient->GetRoot(), 10, 10, kMainFrame | kVerticalFrame)
978 // Creates the macro wizard.
980 const Int_t width = 300;
983 TGHorizontalFrame *fFrameName = new TGHorizontalFrame(this, 10, 10, kHorizontalFrame);
984 TGLabel *fLabel = new TGLabel(fFrameName, "Name*");
985 fLabel->SetTextJustify(36);
986 fLabel->SetMargins(0,0,0,0);
987 fLabel->SetWrapLength(-1);
988 fFrameName->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
990 fText = new TGTextEntry(fFrameName);
991 fText->SetMaxLength(255);
992 fText->SetAlignment(kTextLeft);
994 fText->Resize(width, fText->GetDefaultHeight());
995 fFrameName->AddFrame(fText, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
999 TGHorizontalFrame *fFrameComment = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1000 fLabel = new TGLabel(fFrameComment, "Comment");
1001 fLabel->SetTextJustify(36);
1002 fLabel->SetMargins(0,0,0,0);
1003 fLabel->SetWrapLength(-1);
1004 fFrameComment->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1006 fTextEdit = new TGTextEdit(fFrameComment, width, 5*fText->GetDefaultHeight());
1007 fFrameComment->AddFrame(fTextEdit, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1010 TGHorizontalFrame *fFrameType = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1011 fLabel = new TGLabel(fFrameType, "Type*");
1012 fLabel->SetTextJustify(36);
1013 fLabel->SetMargins(0,0,0,0);
1014 fLabel->SetWrapLength(-1);
1015 fFrameType->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1017 fCombo = new TGComboBox(fFrameType, -1, kHorizontalFrame | kSunkenFrame | kDoubleBorder | kOwnBackground);
1018 fCombo->AddEntry("Single Track Selection", AliEveTRDTrackList::kSingleTrackSelect);
1019 fCombo->AddEntry("Pair Tracks Selection", AliEveTRDTrackList::kCorrelTrackSelect);
1020 fCombo->AddEntry("Single Track Analyse", AliEveTRDTrackList::kSingleTrackAnalyse);
1021 fCombo->AddEntry("Single Track Histo", AliEveTRDTrackList::kSingleTrackHisto);
1022 fCombo->AddEntry("Pair Tracks Analyse", AliEveTRDTrackList::kCorrelTrackAnalyse);
1023 fCombo->AddEntry("Pair Tracks Histo", AliEveTRDTrackList::kCorrelTrackHisto);
1025 fCombo->Resize(width, fText->GetDefaultHeight());
1026 fFrameType->AddFrame(fCombo, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1029 TGHorizontalFrame *fFrameAction = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1030 fbCancel = new TGTextButton(fFrameAction, "Cancel");
1031 fbCancel->SetToolTipText("Exit macro creation wizard");
1032 fFrameAction->AddFrame(fbCancel, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1033 fbCreate = new TGTextButton(fFrameAction, "Done");
1034 fbCreate->SetToolTipText("Use settings to create the macro");
1035 fFrameAction->AddFrame(fbCreate, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1039 TGHorizontalFrame *fFrameText = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1040 fLabel = new TGLabel(fFrameText, "(*) Mandatory fields");
1041 fLabel->SetTextJustify(36);
1042 fLabel->SetMargins(0,0,0,0);
1043 fLabel->SetWrapLength(-1);
1044 fFrameText->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1046 // put things together
1047 AddFrame(fFrameName, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1048 AddFrame(fFrameComment, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1049 AddFrame(fFrameType, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1050 AddFrame(fFrameAction, new TGLayoutHints(kLHintsRight | kLHintsTop | kLHintsExpandX,2,2,2,2));
1052 TGHorizontal3DLine *fLine = new TGHorizontal3DLine(this, 281, 2);
1053 AddFrame(fLine, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1054 AddFrame(fFrameText, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1057 SetWindowName("TRD Macro Wizard");
1058 SetMWMHints(kMWMDecorAll,
1063 Resize(GetDefaultSize());
1067 //fCombo->Connect("Selected(Int_t)", "AliEveTRDMacroWizard", this, "Create(Int_t)");
1068 fbCreate->Connect("Clicked()", "AliEveTRDMacroWizard", this, "HandleCreate()");
1069 fbCancel->Connect("Clicked()", "AliEveTRDMacroWizard", this, "CloseWindow()");
1072 fCombo->Select(1, kFALSE);
1075 const Char_t *fIncludes =
1076 "#if !defined(__CINT__) || defined(__MAKECINT__)\n"
1077 "#include <TROOT.h>\n"
1078 "#include <TH1.h>\n"
1079 "#include <TRD/AliTRDgeometry.h>\n"
1080 "#include <TRD/AliTRDcluster.h>\n"
1081 "#include <TRD/AliTRDseedV1.h>\n"
1082 "#include <TRD/AliTRDtrackV1.h>\n"
1085 const Char_t *fMacroTemplate[7] = {
1087 ," if (!track) return kFALSE;\n"
1091 " if (!track) return;\n"
1093 ," if (!track) return 0x0;\n"
1094 " TH1* h = 0x0;\n\n"
1095 "// Set bins, xmin and xmax here\n"
1097 " Double_t xmin = 0;\n"
1098 " Double_t xmax = 100;\n\n"
1099 " if(!(h = (TH1*)gROOT->FindObject(\"h\"))){\n"
1100 " h = new TH1(\"h\", \"Title\", n, xmin, xmax);\n"
1101 " h->GetXaxis()->SetTitle("");\n"
1102 " h->GetYaxis()->SetTitle("");\n"
1103 " } else h->Reset();\n"
1105 ," if (!track) return kFALSE;\n"
1106 " if (!track2) return kFALSE;\n"
1110 " if (!track) return;\n"
1111 " if (!track2) return;\n"
1113 ," if (!track) return 0x0;\n"
1114 " if (!track2) return 0x0;\n"
1115 " TH1* h = 0x0;\n\n"
1116 "// Set bins, xmin and xmax here\n"
1118 " Double_t xmin = 0;\n"
1119 " Double_t xmax = 100;\n\n"
1120 " if(!(h = (TH1*)gROOT->FindObject(\"h\"))){\n"
1121 " h = new TH1(\"h\", \"Title\", n, xmin, xmax);\n"
1122 " h->GetXaxis()->SetTitle("");\n"
1123 " h->GetYaxis()->SetTitle("");\n"
1124 " } else h->Reset();\n"
1126 //______________________________________________________
1127 void AliEveTRDMacroWizard::Create(Int_t type)
1129 // Creates the macro with the selected type (combo box).
1131 const Char_t *name = fText->GetText();
1132 if(strcmp(name,"")==0){
1133 AliInfo("Please specify a name for your macro.");
1134 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
1135 "Please specify a name for your macro.", kMBIconExclamation, kMBOk);
1136 //fCombo->Select(-1);
1140 // Note: gSystem->AccessPathName(...) returns kTRUE, if the access FAILED!
1141 if(!gSystem->AccessPathName(Form("./%s.C", name))){
1142 // If there is already a file with this name -> Error
1143 AliInfo(Form("A macro \"%s.C\" already exists in the current directory!\nPlease choose another name!", name));
1144 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
1145 Form("A macro \"%s.C\" already exists in the current directory!\nPlease choose another name!", name), kMBIconExclamation, kMBOk);
1146 //fCombo->Select(-1);
1151 if(!(fp = fopen(Form("%s.C", name), "wt"))){
1152 AliInfo("Couldn't create macro file.");
1153 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
1154 "Couldn't create macro file.", kMBIconExclamation, kMBOk);
1155 //fCombo->Select(-1);
1159 TGText *comment = fTextEdit->GetText();
1160 Char_t *line = 0x0; Int_t iline = 0;
1161 while((line = comment->GetLine(TGLongPosition(0,iline++), 200))) fprintf(fp, "// %s\n", line);
1163 fprintf(fp, "\n%s\n", fIncludes);
1166 case AliEveTRDTrackList::kSingleTrackSelect:
1167 fprintf(fp, "Bool_t %s(const AliTRDtrackV1 *track)\n", name);
1169 case AliEveTRDTrackList::kCorrelTrackSelect:
1170 fprintf(fp, "Bool_t %s(const AliTRDtrackV1 *track, const AliTRDtrackV1 *track2)\n", name);
1172 case AliEveTRDTrackList::kSingleTrackAnalyse:
1173 fprintf(fp, "void %s(const AliTRDtrackV1 *track, Double_t*& r, Int_t& n)\n", name);
1175 case AliEveTRDTrackList::kSingleTrackHisto:
1176 fprintf(fp, "TH1* %s(const AliTRDtrackV1 *track)\n", name);
1178 case AliEveTRDTrackList::kCorrelTrackAnalyse:
1179 fprintf(fp, "void %s(const AliTRDtrackV1 *track, const AliTRDtrackV1 *track2, Double_t*& r, Int_t& n)\n", name);
1181 case AliEveTRDTrackList::kCorrelTrackHisto:
1182 fprintf(fp, "TH1* %s(const AliTRDtrackV1 *track, const AliTRDtrackV1 *track2)\n", name);
1185 AliInfo(Form("Unknown type[%d]", type));
1186 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
1187 Form("Unknown type[%d]", type), kMBIconExclamation, kMBOk);
1189 gSystem->Exec(Form("rm -f %s.C", name));
1190 //fCombo->Select(-1);
1194 fprintf(fp, "{\n%s\n", fMacroTemplate[type]);
1195 fprintf(fp, "// add your own code here\n\n\n}\n");
1198 Emit("Create(Int_t)", type);
1199 Create((Char_t*)name);
1203 //______________________________________________________
1204 void AliEveTRDMacroWizard::Create(Char_t *name)
1206 // Emits the creation signal.
1208 Emit("Create(Char_t*)", Form("%s.C", name));
1211 //______________________________________________________
1212 void AliEveTRDMacroWizard::HandleCreate()
1214 // Handles the signal, when the creation button is pressed.
1216 Create(fCombo->GetSelected());