1 // Author: Benjamin Hess 25/09/2008
3 /*************************************************************************
4 * Copyright (C) 2008, 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 //////////////////////////////////////////////////////////////////////////
23 #include <EveDet/AliEveTRDData.h>
24 #include <EveDet/AliEveTRDTrackList.h>
25 #include "AliEveTRDTrackListEditor.h"
27 #include <EveBase/AliEveEventManager.h>
28 #include <AliTRDReconstructor.h>
29 #include <AliTRDtrackV1.h>
32 #include <TEveBrowser.h>
33 #include <TEveGedEditor.h>
34 #include <TEveMacro.h>
35 #include <TEveManager.h>
38 #include <TGButtonGroup.h>
39 #include <TGFileDialog.h>
41 #include <TGListBox.h>
45 #include <TObjString.h>
48 #include <TGTextEntry.h>
49 #include <TGTextEdit.h>
50 #include <TGComboBox.h>
51 #include <TGTextView.h>
53 #include <TTreeStream.h>
56 ClassImp(AliEveTRDTrackListEditor)
58 ///////////////////////////////////////////////////////////
59 ///////////// AliEveTRDTrackListEditor //////////////////
60 ///////////////////////////////////////////////////////////
61 AliEveTRDTrackListEditor::AliEveTRDTrackListEditor(const TGWindow* p, Int_t width, Int_t height,
62 UInt_t options, Pixel_t back) :
63 TGedFrame(p, width, height, options, back),
67 fInheritedMacroList(0),
68 fInheritSettings(kFALSE),
76 frbColor(new TGRadioButton*[3]),
77 frbTrack(new TGRadioButton*[3]),
88 fLabel1(0), fLabel2(0), fLabel3(0), fLabel4(0),
89 fLine1(0), fLine2(0), fLine3(0), fLine4(0), fLine5(0),
92 // Creates the AliEveTRDTrackListEditor.
95 fLine5 = new TGHorizontal3DLine(this, 194, 8);
96 AddFrame(fLine5, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 8));
97 fStyleFrame = new TGHorizontalFrame(this);
98 AddFrame(fStyleFrame);
100 // Style - Track model
101 fbgStyleTrack = new TGButtonGroup(fStyleFrame, "Track model");
102 fbgStyleTrack->SetMapSubwindows(kTRUE);
103 fbgStyleTrack->Resize(194, 200);
104 fStyleFrame->AddFrame(fbgStyleTrack);
106 frbTrack[0] = new TGRadioButton(fbgStyleTrack, "Rieman", 0);
107 frbTrack[0]->SetToolTipText("Set the track model to \"Rieman\" (i.e. the used fit method)");
108 fbgStyleTrack->AddFrame(frbTrack[0]);
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 fbgStyleTrack->AddFrame(frbTrack[1]);
112 frbTrack[2] = new TGRadioButton(fbgStyleTrack, "Line", 2);
113 frbTrack[2]->SetToolTipText("Set the track model to \"Line\" (i.e. the used fit method)");
114 fbgStyleTrack->AddFrame(frbTrack[2]);
116 // Style - Color model
117 fbgStyleColor = new TGButtonGroup(fStyleFrame, "Color model");
118 fbgStyleColor->SetMapSubwindows(kTRUE);
119 fbgStyleColor->Resize(194, 200);
120 fStyleFrame->AddFrame(fbgStyleColor);
122 frbColor[0] = new TGRadioButton(fbgStyleColor, "PID LQ", 0);
123 frbColor[0]->SetToolTipText("Set color model to \"PID LQ\" -> 2 dimensional likelihood particle identification");
124 fbgStyleColor->AddFrame(frbColor[0]);
125 frbColor[1] = new TGRadioButton(fbgStyleColor, "PID NN", 1);
126 frbColor[1]->SetToolTipText("Set color model to \"PID NN\" -> Neural network particle identification");
127 fbgStyleColor->AddFrame(frbColor[1]);
128 frbColor[2] = new TGRadioButton(fbgStyleColor, "ESD Source", 2);
129 frbColor[2]->SetToolTipText("Set color model to \"ESD Source\" -> By source (TPC track prolongation or TRD stand alone)");
130 fbgStyleColor->AddFrame(frbColor[2]);
133 // Functionality for adding macros
134 fMainFrame = CreateEditorTabSubFrame("Process");
136 fLabel1 = new TGLabel(fMainFrame,"Add macro(s):");
137 fMainFrame->AddFrame(fLabel1);
138 fBrowseFrame = new TGHorizontalFrame(fMainFrame);
140 fteField = new TGTextEntry(fBrowseFrame);
141 fteField->SetToolTipText("Enter the pathname of the macro you want to add here and press \"Enter\"");
142 fteField->Connect("ReturnPressed()","AliEveTRDTrackListEditor", this, "HandleMacroPathSet()");
143 fBrowseFrame->AddFrame(fteField);
145 fbBrowse = new TGTextButton(fBrowseFrame, "Browse");
146 fbBrowse->SetToolTipText("Browse the macro you want to add");
147 fbBrowse->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "BrowseMacros()");
148 fBrowseFrame->AddFrame(fbBrowse);
150 fbNew = new TGTextButton(fBrowseFrame, "New");
151 fbNew->SetToolTipText("Start macro creation wizzard");
152 fbNew->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "NewMacros()");
153 fBrowseFrame->AddFrame(fbNew);
154 fMainFrame->AddFrame(fBrowseFrame);
156 fLine1 = new TGHorizontal3DLine(fMainFrame, 194, 8);
157 fMainFrame->AddFrame(fLine1, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
158 fLabel2 = new TGLabel(fMainFrame,"Selection macros:");
159 fMainFrame->AddFrame(fLabel2);
161 ftlMacroSelList = new TGListBox(fMainFrame);
162 ftlMacroSelList->Resize(194, 94);
163 ftlMacroSelList->SetMultipleSelections(kTRUE);
164 fMainFrame->AddFrame(ftlMacroSelList);
166 fLine2 = new TGHorizontal3DLine(fMainFrame, 194, 8);
167 fMainFrame->AddFrame(fLine2, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
168 fLabel3 = new TGLabel(fMainFrame,"Process plugins:");
169 fMainFrame->AddFrame(fLabel3);
171 ftlMacroList = new TGListBox(fMainFrame);
172 ftlMacroList->Resize(194, 94);
173 ftlMacroList->SetMultipleSelections(kTRUE);
174 fMainFrame->AddFrame(ftlMacroList);
176 fLine3 = new TGHorizontal3DLine(fMainFrame, 194, 8);
177 fMainFrame->AddFrame(fLine3, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
179 fbApplyMacros = new TGTextButton(fMainFrame, "Apply plugin(s)");
180 fbApplyMacros->SetToolTipText("Apply all selected macros/class functins to the list of tracks -> A data file will be generated");
181 fbApplyMacros->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "ApplyMacros()");
182 fbApplyMacros->SetRightMargin(12);
183 fMainFrame->AddFrame(fbApplyMacros);
185 fbRemoveMacros = new TGTextButton(fMainFrame, "Remove plugin(s)");
186 fbRemoveMacros->SetToolTipText("Remove the selected macros/class functions from the list(s)");
187 fbRemoveMacros->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "RemoveMacros()");
188 fMainFrame->AddFrame(fbRemoveMacros);
190 // Stuff for displaying histograms
191 fHistoFrame = CreateEditorTabSubFrame("Results");
192 fHistoFrame->SetMapSubwindows(kTRUE);
193 fLabel4 = new TGLabel(fHistoFrame,"Data from plugins:");
194 fHistoFrame->AddFrame(fLabel4);
196 fHistoSubFrame = new TGVerticalFrame(fHistoFrame);
197 fHistoSubFrame->SetMapSubwindows(kTRUE);
198 fHistoSubFrame->Resize(194, 200);
199 fHistoFrame->AddFrame(fHistoSubFrame);
201 fLine4 = new TGHorizontal3DLine(fHistoFrame, 194, 8);
202 fHistoFrame->AddFrame(fLine4, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
204 fbDrawHisto = new TGTextButton(fHistoFrame, "Draw projections");
205 fbDrawHisto->SetToolTipText("Uses the data file created by the last \"Apply selected macro(s)\".\nClick here to display the data histograms of the selected macros.\nSelect multiple macros to create multi-dimensional plots.\nHisto macros cannot be used for multi-dimensional plots!");
206 fbDrawHisto->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "DrawHistos()");
207 fHistoFrame->AddFrame(fbDrawHisto);
209 // Set up file dialog
210 fFileInfo = new TGFileInfo();
211 fFileInfo->SetMultipleSelection(kTRUE);
213 fFileTypes = new Char_t*[6];
214 fFileTypes[0] = (Char_t*)"All files"; fFileTypes[1] = (Char_t*)"*";
215 fFileTypes[2] = (Char_t*)"ROOT macros"; fFileTypes[3] = (Char_t*)"*.C";
216 fFileTypes[4] = 0; fFileTypes[5] = 0;
217 fFileInfo->fFileTypes = (const Char_t**)fFileTypes;
218 fFileInfo->fFileTypeIdx = 2;
219 fFileInfo->fMultipleSelection = kTRUE;
221 fHistoCanvasName = new TGString("");
223 // Handle style changed signals:
224 fbgStyleTrack->Connect("Clicked(Int_t)", "AliEveTRDTrackListEditor", this, "SetTrackModel(Int_t)");
225 fbgStyleColor->Connect("Clicked(Int_t)", "AliEveTRDTrackListEditor", this, "SetTrackColor(Int_t)");
227 // Handle the signal "Selected(Int_t ind)"
228 ftlMacroList->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor", this, "UpdateMacroListSelection(Int_t)");
229 ftlMacroSelList->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor", this, "UpdateMacroListSelection(Int_t)");
231 // Handle the signal "NewEventLoaded"
232 AliEveEventManager::GetMaster()->Connect("NewEventLoaded()", "AliEveTRDTrackListEditor", this, "HandleNewEventLoaded()");
234 // Handle the signal "Selected" (another tab has been selected)
235 GetGedEditor()->GetTab()->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor", this, "HandleTabChangedToIndex(Int_t)");
238 //______________________________________________________
239 AliEveTRDTrackListEditor::~AliEveTRDTrackListEditor()
241 // Destructor: Closes all tabs created by this object and
242 // frees the corresponding memory.
246 delete [] fFileTypes;
255 // Close and delete all tabs that have been created by this class
258 if (fHistoCanvasName != 0)
260 delete fHistoCanvasName;
261 fHistoCanvasName = 0;
263 if (fInheritedMacroList != 0)
265 fInheritedMacroList->Delete();
266 delete fInheritedMacroList;
267 fInheritedMacroList = 0;
271 //______________________________________________________
272 void AliEveTRDTrackListEditor::AddMacro(const Char_t* name, const Char_t* path)
274 // Adds the macro path/name to the macro list. A warning is provided, if there is
275 // something wrong, e.g. if the macro does not have the correct signature.
276 Int_t result = fM->AddMacro(path, name);
284 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Warning", "Macro is already in list (won't be added again)!",
285 kMBIconExclamation, kMBOk);
288 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", "Fail to load the macro (check messages in the terminal)!",
289 kMBIconExclamation, kMBOk);
291 case SIGNATURE_ERROR:
292 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
293 "Macro has not the signature of...\n...a single track selection macro: Bool_t YourMacro(const AliTRDtrackV1*)\n...a correlated tracks selection macro: Bool_t YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*)\n...a single track analyse macro: void YourMacro(const AliTRDtrackV1*, Double_t*&, Int_t&)\n...a correlated tracks analyse macro: void YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*, Double_t*&, Int_t&)\n...a single track histo macro: TH1* YourMacro(const AliTRDtrackV1*)\n...a correlated tracks histo macro: TH1* YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*)",
294 kMBIconExclamation, kMBOk);
296 case NOT_EXIST_ERROR:
297 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
298 "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
301 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
302 Form("AliEveTRDTrackList::AddMacro exited with unknown return value: %d", result),
303 kMBIconExclamation, kMBOk);
308 //______________________________________________________
309 void AliEveTRDTrackListEditor::ApplyMacros()
311 // Applies the selected macros and updates the view.
313 Bool_t success = kFALSE;
315 // First apply the single track selection macros
316 TList* selIterator = new TList();
317 ftlMacroSelList->GetSelectedEntries(selIterator);
318 fM->ApplySTSelectionMacros(selIterator);
323 // Now apply the process macros
324 TList* procIterator = new TList();
325 ftlMacroList->GetSelectedEntries(procIterator);
326 success = fM->ApplyProcessMacros(selIterator, procIterator);
328 // Update histogram tab (data has to be reloaded)
332 // AlieveTRDTrackList::ApplyProcessMacros() automatically selects a macro -> Draw the histogram for it,
333 // if a process macro has been applied
334 if (success && procIterator->GetEntries() > 0)
336 // Set focus on "Histograms" tab
337 GetGedEditor()->GetTab()->SetTab("Results");
342 if (selIterator != 0) delete selIterator;
344 if (procIterator != 0) delete procIterator;
349 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
350 "AliEveTRDTrackList::ApplyProcessMacros experienced an error (cf. CINT-output)!",
351 kMBIconExclamation, kMBOk);
355 //______________________________________________________
356 void AliEveTRDTrackListEditor::NewMacros()
358 // Start the macro creation wizzard.
359 // thanks to Jacek Otwinowski<J.Otwinowski@GSI.DE> for this suggestion
361 AliEveTRDMacroWizzard *wizz = new AliEveTRDMacroWizzard();
362 wizz->Connect("Create(Char_t*)", "AliEveTRDTrackListEditor", this, "AddMacro(Char_t*)");
366 //______________________________________________________
367 void AliEveTRDTrackListEditor::BrowseMacros()
369 // Creates a file-dialog. The selected files will be added to the macro list
370 // via AddMacro(...).
372 new TGFileDialog(gClient->GetRoot(), GetMainFrame(), kFDOpen, fFileInfo);
374 if (fFileInfo->fIniDir != 0 && fFileInfo->fFileNamesList != 0)
377 TObject* iter = fFileInfo->fFileNamesList->First();
383 // NOTE: fileInfo->fFileNamesList will be changed by that, too!
384 name = (Char_t*)strrchr(iter->GetName(), '/');
385 // Delete '"' at the end
386 name[strlen(name)] = '\0';
388 AddMacro(name + 1, fFileInfo->fIniDir);
389 iter = (TObjString*)fFileInfo->fFileNamesList->After(iter);
393 // -> The following problem has been fixed (trunk -> Changes according to 03 September 2008):
394 // Some error occurs, when one ends the filedialog with "cancel": fileInfo->fFileNamesList is set to 0x0, but
395 // in the next launch no new memory is allocated. So do this manually.
396 //if (fileInfo->fFileNamesList == 0) fileInfo->fFileNamesList = new TList();
399 //______________________________________________________
400 void AliEveTRDTrackListEditor::CloseTabs()
402 // Closes + deletes the tabs created by this object
404 if (fHistoCanvas != 0)
406 // Close the created tab, if it exists
407 if (fHistoCanvasName != 0)
409 if (gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString()))
411 // Now the created tab is the current one and can be deleted
412 gEve->GetBrowser()->GetTab(1)->RemoveTab();
415 // With the tab removal, the canvas will be deleted automatically!
420 //______________________________________________________
421 void AliEveTRDTrackListEditor::DrawHistos()
423 // Accesses the temporary data file created by the last call of ApplyMacros() and draws
424 // histograms according to the selection in the "Histograms"-tab.
426 Int_t nHistograms = GetNSelectedHistograms();
427 if (nHistograms <= 0)
429 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
430 "No data selected. Please select the data you want to plot!", kMBIconExclamation, kMBOk);
435 new TGMsgBox(gClient->GetRoot(), GetMainFrame(),
436 "Error", "Only histograms with up to 3 dimensions supported. Please select 1,2 or 3 data macros!",
437 kMBIconExclamation, kMBOk);
441 // Check, if a histo macro shall be drawn
442 Int_t indexOfHistoMacro = -1;
443 Int_t selectedChecked = 0;
444 for (Int_t j = 0; j < fM->fDataFromMacroList->GetEntries(); j++)
446 if (fCheckButtons[j]->TGButton::GetState() == kButtonDown)
450 // Histo macro? -> To check this, look for the substring "(histo macro)"
451 if (strstr(fM->fDataFromMacroList->At(j)->GetName(), "(histo macro)") != 0)
453 // Is also another macro selected?
456 // Histo macros cannot(!) be correlated!
457 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
458 "Histo macros (return value \"TH1*\") cannot be combined with other macros",
459 kMBIconExclamation, kMBOk);
463 // Mark this histo macro for drawing
464 indexOfHistoMacro = j;
466 // Have all selected macros been checked? -> If yes, we are done with this
467 if (selectedChecked == nHistograms) break;
472 TFile* file = new TFile(Form("/tmp/TRD.TrackListMacroData_%s.root", gSystem->Getenv("USER")), "READ");
475 Error("Draw histograms", Form("Cannot open file \"/tmp/TRD.TrackListMacroData_%s.root\"",
476 gSystem->Getenv("USER")));
477 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
478 Form("Cannot open file \"/tmp/TRD.TrackListMacroData_%s.root\"", gSystem->Getenv("USER")),
479 kMBIconExclamation, kMBOk);
487 Int_t indexOfMacro1 = 0;
488 Int_t indexOfMacro2 = 0;
489 Int_t indexOfMacro3 = 0;
491 // Variable for the loop below -> Will be set to aborting value, if a histo macro is drawn
495 if (indexOfHistoMacro >= 0)
497 if ((t = (TTree*)file->Get(Form("TrackData%d", indexOfHistoMacro))))
499 SetDrawingToHistoCanvasTab();
502 t->SetBranchAddress(Form("Macro%d", indexOfHistoMacro), &myHist);
504 if (myHist != 0) myHist->Draw();
507 Error("Draw histograms", Form("No histogram for histo macro \"%s\" found!",
508 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()));
509 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
510 Form("No histogram for histo macro \"%s\" found!",
511 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()), kMBIconExclamation, kMBOk);
515 UpdateHistoCanvasTab();
519 Error("Draw histograms", Form("No data for histo macro \"%s\" found!\nMaybe no tracks have been selected.",
520 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()));
521 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
522 Form("No data for histo macro \"%s\" found!\nMaybe no tracks have been selected.",
523 fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()), kMBIconExclamation, kMBOk);
526 // Skip the loop below
527 i = fM->fDataFromMacroList->GetEntries();
530 // Load the trees in succession and remember the entries -> Plot the analyse macros
531 for ( ; i < fM->fDataFromMacroList->GetEntries(); i++)
533 if (fCheckButtons[i]->TGButton::GetState() == kButtonDown)
538 if (!(t = (TTree*)file->Get(Form("TrackData%d", i))))
540 Error("Draw histograms", Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.",
541 fM->fDataFromMacroList->At(i)->GetName()));
542 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
543 Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.",
544 fM->fDataFromMacroList->At(i)->GetName()), kMBIconExclamation, kMBOk);
549 if (nHistograms == 1)
551 SetDrawingToHistoCanvasTab();
553 t->Draw(Form("Macro%d", indexOfMacro1), "1");
554 ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s;%s",
555 fM->fDataFromMacroList->At(indexOfMacro1)->GetName(),
556 fM->fDataFromMacroList->At(indexOfMacro1)->GetName()));
557 UpdateHistoCanvasTab();
562 else if (tFriend1 == 0)
565 if (!(tFriend1 = (TTree*)file->Get(Form("TrackData%d", i))))
567 Error("Draw histograms", Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.",
568 fM->fDataFromMacroList->At(i)->GetName()));
569 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
570 Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.",
571 fM->fDataFromMacroList->At(i)->GetName()),
572 kMBIconExclamation, kMBOk);
577 if (nHistograms == 2)
579 SetDrawingToHistoCanvasTab();
581 t->AddFriend(tFriend1);
582 t->Draw(Form("Macro%d:Macro%d", indexOfMacro1, indexOfMacro2), "1");
583 ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s - %s;%s;%s",
584 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
585 fM->fDataFromMacroList->At(indexOfMacro1)->GetName(),
586 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
587 fM->fDataFromMacroList->At(indexOfMacro1)->GetName()));
589 UpdateHistoCanvasTab();
598 if (!(tFriend2 = (TTree*)file->Get(Form("TrackData%d", i))))
600 Error("Draw histograms", Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.",
601 fM->fDataFromMacroList->At(i)->GetName()));
602 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms",
603 Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.",
604 fM->fDataFromMacroList->At(i)->GetName()), kMBIconExclamation, kMBOk);
608 SetDrawingToHistoCanvasTab();
610 t->AddFriend(tFriend1);
611 t->AddFriend(tFriend2);
612 t->Draw(Form("Macro%d:Macro%d:Macro%d", indexOfMacro1, indexOfMacro2, indexOfMacro3), "1");
613 ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s - %s - %s;%s;%s;%s",
614 fM->fDataFromMacroList->At(indexOfMacro3)->GetName(),
615 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
616 fM->fDataFromMacroList->At(indexOfMacro1)->GetName(),
617 fM->fDataFromMacroList->At(indexOfMacro3)->GetName(),
618 fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
619 fM->fDataFromMacroList->At(indexOfMacro1)->GetName()));
621 UpdateHistoCanvasTab();
628 if (t != 0) delete t;
630 if (tFriend1 != 0) delete tFriend1;
632 if (tFriend2 != 0) delete tFriend2;
640 //______________________________________________________
641 Int_t AliEveTRDTrackListEditor::GetNSelectedHistograms() const
643 // Returns the number of selected macros (or rather: of their selected data) in the "Histograms"-tab
647 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
649 if (fCheckButtons[i]->TGButton::GetState() == kButtonDown) count++;
655 //______________________________________________________
656 void AliEveTRDTrackListEditor::HandleMacroPathSet()
658 // Takes the input of the text field (adding a macro), checks if the macro can be
659 // accessed (and that it exists) and adds the macro to the macro list via AddMacro(...).
660 // You can use environment variables in the text field, e.g. "$ALICE_ROOT/Eve/alice-macro/myMacro.C".
662 if (strlen(fteField->GetText()) != 0)
664 // Expand the pathname
665 Char_t* systemPath = gSystem->ExpandPathName(fteField->GetText());
666 fteField->SetText(systemPath);
670 // Check if file exists
673 fp = fopen(fteField->GetText(), "rb");
679 Char_t* name = (Char_t*)strrchr(fteField->GetText(), '/');
684 name = new Char_t[AliEveTRDTrackList::fkMaxMacroNameLength];
685 memset(name, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroNameLength);
686 sprintf(name, "%s", fteField->GetText());
688 // Add path to textfield -> Path is "./" -> Use length for the name + 2
689 Char_t pathname[AliEveTRDTrackList::fkMaxMacroNameLength + 2];
690 memset(pathname, '\0', sizeof(Char_t) * (AliEveTRDTrackList::fkMaxMacroNameLength + 2));
691 sprintf(pathname, "./%s", fteField->GetText());
692 fteField->SetText(pathname);
695 if (name != 0) delete name;
702 Char_t* path = new Char_t[AliEveTRDTrackList::fkMaxMacroPathLength];
703 memset(path, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroPathLength);
704 strncpy(path, fteField->GetText(), strlen(fteField->GetText()) - strlen(name));
706 // Ignore the slash "/" in name
707 AddMacro(name + 1, path);
709 if (path != 0) delete path;
715 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
716 "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
721 //______________________________________________________
722 void AliEveTRDTrackListEditor::HandleNewEventLoaded()
724 // Closes the tabs created by this object and sets a flag that will
725 // cause the function SetModel() to inherit the macro lists + style
726 // for the next AliEveTRDTrackList from the current one.
728 // Inherit the macro list and track style for the next track list!
729 fInheritSettings = kTRUE;
735 //______________________________________________________
736 void AliEveTRDTrackListEditor::HandleTabChangedToIndex(Int_t index)
738 // Saves the current tab in the current AliEveTRDTrackList.
740 fM->SetSelectedTab(index);
743 //______________________________________________________
744 void AliEveTRDTrackListEditor::InheritMacroList()
746 // The old macro list is possibly stored in the corresponding interior map. This function will
747 // use this interior map to move the data from the interior map to the newly loaded AliEveTRDTrackList.
748 // Then the interior map will be cleaned up. With this, the settings will be inherited from the previously
749 // loaded AliEveTRDTrackList.
751 if (fInheritedMacroList == 0) return;
754 fM->fMacroList->Delete();
756 // Store data from interior list in the track list's map
757 TMapIter* iter = (TMapIter*)fInheritedMacroList->MakeIterator();
760 TMacroData* macro = 0;
762 while ((key = iter->Next()) != 0)
764 macro = (TMacroData*)fInheritedMacroList->GetValue(key);
765 if (macro != 0) fM->fMacroList->Add(new TObjString(key->GetName()),
766 new TMacroData(macro->GetName(), macro->GetPath(), macro->GetType()));
769 Error("AliEveTRDTrackListEditor::InheritMacroList", Form("Failed to inherit the macro \"%s\"!", key));
773 fInheritedMacroList->Delete();
774 delete fInheritedMacroList;
775 fInheritedMacroList = 0;
778 //______________________________________________________
779 void AliEveTRDTrackListEditor::InheritStyle()
781 // The old styles are stored in the corresponding button groups. This function will replace
782 // the style settings of the newly loaded AliEveTRDTrackList with the old styles. With this, the settings
783 // will be inherited from the previously loaded AliEveTRDTrackList.
785 for (Int_t ind = 0; ind < 3; ind++)
787 if (fbgStyleTrack->GetButton(ind)->IsOn())
793 for (Int_t ind = 0; ind < 3; ind++)
795 if (fbgStyleColor->GetButton(ind)->IsOn())
803 //______________________________________________________
804 void AliEveTRDTrackListEditor::RemoveMacros()
806 // Removes the selected macros from the corresponding list.
808 TList* iterator = new TList();
810 ftlMacroList->GetSelectedEntries(iterator);
811 fM->RemoveSelectedMacros(iterator);
813 if (iterator != 0) delete iterator;
815 iterator = new TList();
816 ftlMacroSelList->GetSelectedEntries(iterator);
817 fM->RemoveSelectedMacros(iterator);
819 // Selected macros are deleted from the list -> No selected entries left
820 fM->fMacroListSelected = 0;
824 if (iterator != 0) delete iterator;
828 //______________________________________________________
829 void AliEveTRDTrackListEditor::SetDrawingToHistoCanvasTab()
831 // Sets gPad to the tab with the name of the current AliEveTRDTrackList. If this tab does
832 // not exist, it will be created. Otherwise, it is re-used.
834 // If the tab with the canvas has been closed, the canvas will be deleted.
835 // So, if there is no tab, set the canvas pointer to zero and recreate it in a new tab.
836 if (fHistoCanvas != 0)
838 if (gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString()) == 0)
846 fHistoCanvas = gEve->AddCanvasTab(fM->GetName());
852 //______________________________________________________
853 void AliEveTRDTrackListEditor::SetModel(TObject* obj)
855 // Sets the model object, updates the related data in the GUI and
856 // inherits settings (cf. Inherit*(...)), if the flag fInheritSettings is set to kTRUE.
858 fM = dynamic_cast<AliEveTRDTrackList*>(obj);
862 Error("SetModel", "Parameter is zero pointer");
866 // Provide a pointer to this editor
869 // If macro list + track style shall be inherited from previously loaded track list, do so
870 if (fInheritSettings)
875 fInheritSettings = kFALSE;
878 // Select the correct styles
880 UChar_t style = fM->GetSelectedTrackStyle();
881 if (TESTBIT(style, AliEveTRDTrack::kSource)) b = 2;
884 if (TESTBIT(style, AliEveTRDTrack::kPID)) b = 1;
887 fbgStyleColor->SetButton(b, kTRUE);
890 if (TESTBIT(style, AliEveTRDTrack::kTrackCosmics)) b = 2;
893 if (TESTBIT(style, AliEveTRDTrack::kTrackModel)) b = 1;
896 fbgStyleTrack->SetButton(b, kTRUE);
902 GetGedEditor()->GetTab()->SetTab(fM->GetSelectedTab());
905 //______________________________________________________
906 void AliEveTRDTrackListEditor::SaveMacroList(TMap* list)
908 // Saves the provided macro list in an interior list. This list will be used by
909 // InheritMacroList() to restore the data in "list". With this method one is able
910 // to inherit the macro list from track list to track list (i.e. from event to event).
912 if (fInheritedMacroList != 0)
914 fInheritedMacroList->Delete();
915 delete fInheritedMacroList;
917 fInheritedMacroList = new TMap();
918 fInheritedMacroList->SetOwnerKeyValue(kTRUE, kTRUE);
920 TMapIter* iter = (TMapIter*)list->MakeIterator();
922 TMacroData* macro = 0;
924 while ((key = iter->Next()) != 0)
926 macro = (TMacroData*)fM->fMacroList->GetValue(key);
927 if (macro != 0) fInheritedMacroList->Add(new TObjString(key->GetName()),
928 new TMacroData(macro->GetName(), macro->GetPath(), macro->GetType()));
931 Error("AliEveTRDTrackListEditor::SaveMacroList", Form("Failed to inherit the macro \"%s\"!", key));
936 //______________________________________________________
937 void AliEveTRDTrackListEditor::SetTrackColor(Int_t ind)
939 // Sets the color model for the tracks, updates the tracks with this model and
940 // redraws the scene.
944 case AliTRDpidUtil::kLQ:
945 fM->UpdateTrackStyle(AliEveTRDTrack::kPID, AliTRDpidUtil::kLQ);
947 case AliTRDpidUtil::kNN:
948 fM->UpdateTrackStyle(AliEveTRDTrack::kPID, AliTRDpidUtil::kNN);
951 fM->UpdateTrackStyle(AliEveTRDTrack::kSource);
958 //______________________________________________________
959 void AliEveTRDTrackListEditor::SetTrackModel(Int_t ind)
961 // Sets the track model for the tracks, updates the tracks with this model and
962 // redraws the scene.
966 case AliEveTRDTrack::kRieman:
967 fM->UpdateTrackStyle(AliEveTRDTrack::kTrackModel, AliEveTRDTrack::kRieman);
969 case AliEveTRDTrack::kKalman:
970 fM->UpdateTrackStyle(AliEveTRDTrack::kTrackModel, AliEveTRDTrack::kKalman);
973 fM->UpdateTrackStyle(AliEveTRDTrack::kTrackCosmics);
980 //______________________________________________________
981 void AliEveTRDTrackListEditor::UpdateDataFromMacroListSelection()
983 // Saves the current selection in the "Histograms"-tab to the current
984 // AliEveTRDTrackList. This means that the selection is updated and won't
985 // get lost, if another editor is loaded in Eve.
987 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
989 fM->SetHistoDataSelection(i, fCheckButtons[i]->IsOn());
993 //______________________________________________________
994 void AliEveTRDTrackListEditor::UpdateHistoCanvasTab()
996 // Updates the histogram and the corresponding tab (including titles).
998 // Update name of the tab (tab has been set to current tab!)
999 fHistoCanvasName->SetString(fM->GetName());
1001 // Use a copy of fHistoCanvasName!! -> If the user closes a tab manually, the TGString
1002 // will be deleted -> Error might occur, when accessing the pointer
1003 gEve->GetBrowser()->GetTab(1)->GetCurrentTab()->SetText(new TGString(fHistoCanvasName));
1005 // Switch tabs to force redrawing
1006 gEve->GetBrowser()->GetTab(1)->SetTab(0);
1007 gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString());
1008 fHistoCanvas->Update();
1011 //______________________________________________________
1012 void AliEveTRDTrackListEditor::UpdateHistoList()
1014 // Reloads (updates) the buttons in the "Histograms"-tab via
1015 // the current AliEveTRDTrackList (data).
1017 fHistoSubFrame->TGCompositeFrame::Cleanup();
1019 // Set buttons for histograms
1020 if (fCheckButtons != 0) delete fCheckButtons;
1021 fCheckButtons = new TGCheckButton*[fM->fDataFromMacroList->GetEntries()];
1023 TObjString* iter = (TObjString*)fM->fDataFromMacroList->First();
1024 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries() && iter != 0; i++)
1026 fCheckButtons[i] = new TGCheckButton(fHistoSubFrame, iter->GetName());
1027 fHistoSubFrame->AddFrame(fCheckButtons[i]);
1029 fCheckButtons[i]->SetState(kButtonUp, kFALSE);
1030 fCheckButtons[i]->MapRaised();
1031 fCheckButtons[i]->SetOn(fM->HistoDataIsSelected(i));
1032 fCheckButtons[i]->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "UpdateDataFromMacroListSelection()");
1034 iter = (TObjString*)fM->fDataFromMacroList->After(iter);
1038 //______________________________________________________
1039 void AliEveTRDTrackListEditor::UpdateMacroList()
1041 // Reloads (updates) the macro list (selection AND process macros) via
1042 // the current AliEveTRDTrackList (data).
1044 ftlMacroList->RemoveAll();
1045 ftlMacroSelList->RemoveAll();
1047 TMapIter* iter = (TMapIter*)fM->fMacroList->MakeIterator();
1049 TMacroData* macro = 0;
1052 while ((key = iter->Next()) != 0)
1054 macro = (TMacroData*)fM->fMacroList->GetValue(key);
1057 if (macro->IsProcessMacro())
1059 ftlMacroList->AddEntry(macro->GetName(), ind);
1060 // Select, what has been selected before
1061 ftlMacroList->Select(ind, fM->MacroListIsSelected(ind));
1064 else if (macro->IsSelectionMacro())
1066 ftlMacroSelList->AddEntry(macro->GetName(), ind);
1067 // Select, what has been selected before
1068 ftlMacroSelList->Select(ind, fM->MacroListIsSelected(ind));
1073 Error("AliEveTRDTrackListEditor::UpdateMacroList()",
1074 Form("Macro \"%s/%s.C\" has neither a selection macro nor a process macro!",
1075 macro->GetPath(), macro->GetName()));
1080 Error("AliEveTRDTrackListEditor::UpdateMacroList()",
1081 Form("Macro list is corrupted: Macro \"%s\" not found!", key->GetName()));
1085 ftlMacroList->SortByName();
1086 ftlMacroSelList->SortByName();
1089 //______________________________________________________
1090 void AliEveTRDTrackListEditor::UpdateMacroListSelection(Int_t ind)
1092 // Saves the current selection in the macro listS to the current
1093 // AliEveTRDTrackList. This means that the selection is updated and won't
1094 // get lost, if another editor is loaded in Eve.
1095 // NOTE: The indices in BOTH lists will be unique!
1097 // Toggle selected item
1098 fM->SetMacroListSelection(ind, !fM->MacroListIsSelected(ind));
1102 /////////////////////////////////////////////////
1103 ClassImp(AliEveTRDMacroWizzard)
1105 //______________________________________________________
1106 AliEveTRDMacroWizzard::AliEveTRDMacroWizzard(const TGWindow* p)
1107 :TGMainFrame(p ? p : gClient->GetRoot(), 10, 10, kMainFrame | kVerticalFrame)
1112 const Int_t width = 300;
1115 TGHorizontalFrame *fFrameName = new TGHorizontalFrame(this, 10, 10, kHorizontalFrame);
1116 TGLabel *fLabel = new TGLabel(fFrameName, "Name*");
1117 fLabel->SetTextJustify(36);
1118 fLabel->SetMargins(0,0,0,0);
1119 fLabel->SetWrapLength(-1);
1120 fFrameName->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1122 fText = new TGTextEntry(fFrameName);
1123 fText->SetMaxLength(255);
1124 fText->SetAlignment(kTextLeft);
1126 fText->Resize(width, fText->GetDefaultHeight());
1127 fFrameName->AddFrame(fText, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1131 TGHorizontalFrame *fFrameComment = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1132 fLabel = new TGLabel(fFrameComment, "Comment");
1133 fLabel->SetTextJustify(36);
1134 fLabel->SetMargins(0,0,0,0);
1135 fLabel->SetWrapLength(-1);
1136 fFrameComment->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1138 fTextEdit = new TGTextEdit(fFrameComment, width, 5*fText->GetDefaultHeight());
1139 fFrameComment->AddFrame(fTextEdit, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1142 TGHorizontalFrame *fFrameType = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1143 fLabel = new TGLabel(fFrameType, "Type*");
1144 fLabel->SetTextJustify(36);
1145 fLabel->SetMargins(0,0,0,0);
1146 fLabel->SetWrapLength(-1);
1147 fFrameType->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1149 fCombo = new TGComboBox(fFrameType, -1, kHorizontalFrame | kSunkenFrame | kDoubleBorder | kOwnBackground);
1150 fCombo->AddEntry("Single Track Selection", AliEveTRDTrackList::kSingleTrackSelect);
1151 fCombo->AddEntry("Pair Tracks Selection", AliEveTRDTrackList::kCorrelTrackSelect);
1152 fCombo->AddEntry("Single Track Analyse", AliEveTRDTrackList::kSingleTrackAnalyse);
1153 fCombo->AddEntry("Single Track Histo", AliEveTRDTrackList::kSingleTrackHisto);
1154 fCombo->AddEntry("Pair Tracks Analyse", AliEveTRDTrackList::kCorrelTrackAnalyse);
1155 fCombo->AddEntry("Pair Tracks Histo", AliEveTRDTrackList::kCorrelTrackHisto);
1157 fCombo->Resize(width, fText->GetDefaultHeight());
1158 fFrameType->AddFrame(fCombo, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1162 TGHorizontalFrame *fFrameText = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1163 fLabel = new TGLabel(fFrameText, "(*) Mandatory fields");
1164 fLabel->SetTextJustify(36);
1165 fLabel->SetMargins(0,0,0,0);
1166 fLabel->SetWrapLength(-1);
1167 fFrameText->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1169 // put things together
1170 AddFrame(fFrameName, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1171 AddFrame(fFrameComment, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1172 AddFrame(fFrameType, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
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));
1179 SetWindowName("TRD Macro Wizzard");
1180 SetMWMHints(kMWMDecorAll,
1185 Resize(GetDefaultSize());
1189 fCombo->Connect("Selected(Int_t)", "AliEveTRDMacroWizzard", this, "Create(Int_t)");
1192 const Char_t *fIncludes =
1193 "#if !defined(__CINT__) || defined(__MAKECINT__)\n"
1194 "#include <TROOT.h>\n"
1195 "#include <TH1.h>\n"
1196 "#include <TRD/AliTRDgeometry.h>\n"
1197 "#include <TRD/AliTRDcluster.h>\n"
1198 "#include <TRD/AliTRDseedV1.h>\n"
1199 "#include <TRD/AliTRDtrackV1.h>\n"
1202 const Char_t *fMacroTemplate[7] = {
1204 ," if (!track) return kFALSE;\n"
1209 " if (!track) return;\n"
1211 ," if (!track) return 0x0;\n"
1213 " if(!(h = (TH1*)gROOT->FindObject(\"h\"))){\n"
1214 " h = new TH1(\"h\", \"Title\", n, xmin, xmax);\n"
1215 " h->GetXaxis()->SetTitle("");\n"
1216 " h->GetYaxis()->SetTitle("");\n"
1217 " } else h->Reset();\n"
1220 ," if (!track) return kFALSE;\n"
1221 " if (!track2) return kFALSE;\n"
1226 " if (!track) return;\n"
1227 " if (!track2) return;\n"
1229 ," if (!track) return 0x0;\n"
1230 " if (!track2) return 0x0;\n"
1232 " if(!(h = (TH1*)gROOT->FindObject(\"h\"))){\n"
1233 " h = new TH1(\"h\", \"Title\", n, xmin, xmax);\n"
1234 " h->GetXaxis()->SetTitle("");\n"
1235 " h->GetYaxis()->SetTitle("");\n"
1236 " } else h->Reset();\n"
1239 //______________________________________________________
1240 void AliEveTRDMacroWizzard::Create(Int_t typ)
1242 const Char_t *name = fText->GetText();
1243 if(strcmp(name,"")==0){
1244 AliInfo("Please specify a name for your macro.");
1250 if(!(fp = fopen(Form("%s.C", name), "wt"))){
1251 AliInfo("Couldn't create macro file.");
1256 TGText *comment = fTextEdit->GetText();
1257 Char_t *line = 0x0; Int_t iline = 0;
1258 while((line = comment->GetLine(TGLongPosition(0,iline++), 200))) fprintf(fp, "// %s\n", line);
1260 fprintf(fp, "\n%s\n", fIncludes);
1263 case AliEveTRDTrackList::kSingleTrackSelect:
1264 fprintf(fp, "Bool_t %s(const AliTRDtrackV1 *track)\n", name);
1266 case AliEveTRDTrackList::kCorrelTrackSelect:
1267 fprintf(fp, "Bool_t %s(const AliTRDtrackV1 *track, const AliTRDtrackV1 *track2)\n", name);
1269 case AliEveTRDTrackList::kSingleTrackAnalyse:
1270 fprintf(fp, "void %s(const AliTRDtrackV1 *track, Double_t*& r, Int_t& n)\n", name);
1272 case AliEveTRDTrackList::kSingleTrackHisto:
1273 fprintf(fp, "TH1* %s(const AliTRDtrackV1 *track)\n", name);
1275 case AliEveTRDTrackList::kCorrelTrackAnalyse:
1276 fprintf(fp, "void %s(const AliTRDtrackV1 *track, const AliTRDtrackV1 *track2, Double_t*& r, Int_t& n)\n", name);
1278 case AliEveTRDTrackList::kCorrelTrackHisto:
1279 fprintf(fp, "TH1* %s(const AliTRDtrackV1 *track, const AliTRDtrackV1 *track2)\n", name);
1282 AliInfo(Form("Unknown typ[%d]", typ));
1284 gSystem->Exec(Form("rm -f %s.C", name));
1289 fprintf(fp, "{\n%s\n", fMacroTemplate[typ]);
1290 fprintf(fp, "// add your own code here\n\n\n}\n");
1293 Emit("Create(Int_t)", typ);
1294 Create((Char_t*)name);
1298 //______________________________________________________
1299 void AliEveTRDMacroWizzard::Create(Char_t *name)
1301 Emit("Create(Char_t*)", Form("%s.C", name));