]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveDet/AliEveTRDTrackListEditor.cxx
Compatibility with ROOT trunk
[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
ed0e1245 23#include <AliLog.h>
8bdeb570 24#include <EveDet/AliEveTRDData.h>
25#include <EveDet/AliEveTRDTrackList.h>
26#include "AliEveTRDTrackListEditor.h"
8bdeb570 27#include <EveBase/AliEveEventManager.h>
28#include <AliTRDReconstructor.h>
29#include <AliTRDtrackV1.h>
ed0e1245 30
caaf90d2 31#include <TGButton.h>
8e27fca1 32#include <TCanvas.h>
4f6473f6 33#include <TEveBrowser.h>
8e27fca1 34#include <TEveGedEditor.h>
caaf90d2 35#include <TEveMacro.h>
36#include <TEveManager.h>
8e27fca1 37#include <TFile.h>
38#include <TG3DLine.h>
4cbab605 39#include <TGButtonGroup.h>
8e27fca1 40#include <TGFileDialog.h>
41#include <TGLabel.h>
42#include <TGListBox.h>
43#include <TGMsgBox.h>
44#include <TGTab.h>
38a30030 45#include <TMap.h>
caaf90d2 46#include <TObjString.h>
caaf90d2 47#include <TROOT.h>
8e27fca1 48#include <TSystem.h>
49#include <TGTextEntry.h>
db16b708 50#include <TGTextEdit.h>
51#include <TGComboBox.h>
8e27fca1 52#include <TGTextView.h>
bcb45225 53#include <TH1.h>
8e27fca1 54#include <TTreeStream.h>
55
caaf90d2 56
2ef0687e 57ClassImp(AliEveTRDTrackListEditor)
58
59///////////////////////////////////////////////////////////
60///////////// AliEveTRDTrackListEditor //////////////////
61///////////////////////////////////////////////////////////
62AliEveTRDTrackListEditor::AliEveTRDTrackListEditor(const TGWindow* p, Int_t width, Int_t height,
63 UInt_t options, Pixel_t back) :
64 TGedFrame(p, width, height, options, back),
65 fM(0),
4f6473f6 66 fHistoCanvas(0),
67 fHistoCanvasName(0),
38a30030 68 fInheritedMacroList(0),
8bdeb570 69 fInheritSettings(kFALSE),
ecbbe371 70 fStyleFrame(0),
2ef0687e 71 fMainFrame(0),
caaf90d2 72 fHistoFrame(0),
73 fHistoSubFrame(0),
2ef0687e 74 fBrowseFrame(0),
4cbab605 75 fbgStyleColor(0),
76 fbgStyleTrack(0),
77 frbColor(new TGRadioButton*[3]),
78 frbTrack(new TGRadioButton*[3]),
caaf90d2 79 fbBrowse(0),
db16b708 80 fbNew(0),
caaf90d2 81 fbApplyMacros(0),
82 fbRemoveMacros(0),
83 fbDrawHisto(0),
84 fteField(0),
85 ftlMacroList(0),
86 ftlMacroSelList(0),
87 fFileInfo(0),
88 fFileTypes(0),
89 fLabel1(0), fLabel2(0), fLabel3(0), fLabel4(0),
4cbab605 90 fLine1(0), fLine2(0), fLine3(0), fLine4(0), fLine5(0),
caaf90d2 91 fCheckButtons(0)
4cbab605 92{
16db6074 93 // Creates the AliEveTRDTrackListEditor.
94
4cbab605 95 // Style stuff
96 fLine5 = new TGHorizontal3DLine(this, 194, 8);
97 AddFrame(fLine5, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 8));
ecbbe371 98 fStyleFrame = new TGHorizontalFrame(this);
99 AddFrame(fStyleFrame);
4cbab605 100
101 // Style - Track model
ecbbe371 102 fbgStyleTrack = new TGButtonGroup(fStyleFrame, "Track model");
4cbab605 103 fbgStyleTrack->SetMapSubwindows(kTRUE);
104 fbgStyleTrack->Resize(194, 200);
ecbbe371 105 fStyleFrame->AddFrame(fbgStyleTrack);
4cbab605 106
ecbbe371 107 frbTrack[0] = new TGRadioButton(fbgStyleTrack, "Rieman", 0);
2670605d 108 frbTrack[0]->SetToolTipText("Set the track model to \"Rieman\" (i.e. the used fit method)");
ecbbe371 109 frbTrack[1] = new TGRadioButton(fbgStyleTrack, "Kalman", 1);
2670605d 110 frbTrack[1]->SetToolTipText("Set the track model to \"Kalman\" (i.e. the used fit method)");
ecbbe371 111 frbTrack[2] = new TGRadioButton(fbgStyleTrack, "Line", 2);
2670605d 112 frbTrack[2]->SetToolTipText("Set the track model to \"Line\" (i.e. the used fit method)");
4cbab605 113
114 // Style - Color model
8bdeb570 115 fbgStyleColor = new TGButtonGroup(fStyleFrame, "Color model");
4cbab605 116 fbgStyleColor->SetMapSubwindows(kTRUE);
117 fbgStyleColor->Resize(194, 200);
ecbbe371 118 fStyleFrame->AddFrame(fbgStyleColor);
4cbab605 119
ecbbe371 120 frbColor[0] = new TGRadioButton(fbgStyleColor, "PID LQ", 0);
2670605d 121 frbColor[0]->SetToolTipText("Set color model to \"PID LQ\" -> 2 dimensional likelihood particle identification");
ecbbe371 122 frbColor[1] = new TGRadioButton(fbgStyleColor, "PID NN", 1);
2670605d 123 frbColor[1]->SetToolTipText("Set color model to \"PID NN\" -> Neural network particle identification");
ecbbe371 124 frbColor[2] = new TGRadioButton(fbgStyleColor, "ESD Source", 2);
2670605d 125 frbColor[2]->SetToolTipText("Set color model to \"ESD Source\" -> By source (TPC track prolongation or TRD stand alone)");
4cbab605 126
c1869a7c 127 // Functionality for adding plugins
db16b708 128 fMainFrame = CreateEditorTabSubFrame("Process");
4cbab605 129
c1869a7c 130 fLabel1 = new TGLabel(fMainFrame,"Add plugin(s):");
3f797131 131 fMainFrame->AddFrame(fLabel1);
2ef0687e 132 fBrowseFrame = new TGHorizontalFrame(fMainFrame);
133
caaf90d2 134 fteField = new TGTextEntry(fBrowseFrame);
8bdeb570 135 fteField->SetToolTipText("Enter the pathname of the macro you want to add here and press \"Enter\"");
caaf90d2 136 fteField->Connect("ReturnPressed()","AliEveTRDTrackListEditor", this, "HandleMacroPathSet()");
137 fBrowseFrame->AddFrame(fteField);
2ef0687e 138
caaf90d2 139 fbBrowse = new TGTextButton(fBrowseFrame, "Browse");
8bdeb570 140 fbBrowse->SetToolTipText("Browse the macro you want to add");
caaf90d2 141 fbBrowse->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "BrowseMacros()");
142 fBrowseFrame->AddFrame(fbBrowse);
db16b708 143
144 fbNew = new TGTextButton(fBrowseFrame, "New");
00dc25ef 145 fbNew->SetToolTipText("Start macro creation wizard");
db16b708 146 fbNew->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "NewMacros()");
147 fBrowseFrame->AddFrame(fbNew);
2ef0687e 148 fMainFrame->AddFrame(fBrowseFrame);
149
3f797131 150 fLine1 = new TGHorizontal3DLine(fMainFrame, 194, 8);
caaf90d2 151 fMainFrame->AddFrame(fLine1, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
c1869a7c 152 fLabel2 = new TGLabel(fMainFrame,"Selection plugins:");
3f797131 153 fMainFrame->AddFrame(fLabel2);
154
caaf90d2 155 ftlMacroSelList = new TGListBox(fMainFrame);
156 ftlMacroSelList->Resize(194, 94);
157 ftlMacroSelList->SetMultipleSelections(kTRUE);
158 fMainFrame->AddFrame(ftlMacroSelList);
3f797131 159
160 fLine2 = new TGHorizontal3DLine(fMainFrame, 194, 8);
caaf90d2 161 fMainFrame->AddFrame(fLine2, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
db16b708 162 fLabel3 = new TGLabel(fMainFrame,"Process plugins:");
3f797131 163 fMainFrame->AddFrame(fLabel3);
164
caaf90d2 165 ftlMacroList = new TGListBox(fMainFrame);
166 ftlMacroList->Resize(194, 94);
167 ftlMacroList->SetMultipleSelections(kTRUE);
168 fMainFrame->AddFrame(ftlMacroList);
2ef0687e 169
3f797131 170 fLine3 = new TGHorizontal3DLine(fMainFrame, 194, 8);
caaf90d2 171 fMainFrame->AddFrame(fLine3, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
3f797131 172
db16b708 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");
caaf90d2 175 fbApplyMacros->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "ApplyMacros()");
176 fbApplyMacros->SetRightMargin(12);
177 fMainFrame->AddFrame(fbApplyMacros);
2ef0687e 178
db16b708 179 fbRemoveMacros = new TGTextButton(fMainFrame, "Remove plugin(s)");
180 fbRemoveMacros->SetToolTipText("Remove the selected macros/class functions from the list(s)");
caaf90d2 181 fbRemoveMacros->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "RemoveMacros()");
182 fMainFrame->AddFrame(fbRemoveMacros);
2ef0687e 183
caaf90d2 184 // Stuff for displaying histograms
db16b708 185 fHistoFrame = CreateEditorTabSubFrame("Results");
caaf90d2 186 fHistoFrame->SetMapSubwindows(kTRUE);
db16b708 187 fLabel4 = new TGLabel(fHistoFrame,"Data from plugins:");
caaf90d2 188 fHistoFrame->AddFrame(fLabel4);
189
190 fHistoSubFrame = new TGVerticalFrame(fHistoFrame);
191 fHistoSubFrame->SetMapSubwindows(kTRUE);
192 fHistoSubFrame->Resize(194, 200);
193 fHistoFrame->AddFrame(fHistoSubFrame);
194
195 fLine4 = new TGHorizontal3DLine(fHistoFrame, 194, 8);
196 fHistoFrame->AddFrame(fLine4, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 8, 2));
197
db16b708 198 fbDrawHisto = new TGTextButton(fHistoFrame, "Draw projections");
c1869a7c 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!");
caaf90d2 200 fbDrawHisto->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "DrawHistos()");
201 fHistoFrame->AddFrame(fbDrawHisto);
2ef0687e 202
203 // Set up file dialog
caaf90d2 204 fFileInfo = new TGFileInfo();
205 fFileInfo->SetMultipleSelection(kTRUE);
206
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;
ed0e1245 212 fFileInfo->fIniDir = (Char_t*)"$ALICE_ROOT/PWGPP/TRD/macros/EVE";
caaf90d2 213 fFileInfo->fFileTypeIdx = 2;
214 fFileInfo->fMultipleSelection = kTRUE;
4f6473f6 215
216 fHistoCanvasName = new TGString("");
217
4cbab605 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)");
221
4f6473f6 222 // Handle the signal "Selected(Int_t ind)"
223 ftlMacroList->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor", this, "UpdateMacroListSelection(Int_t)");
38a30030 224 ftlMacroSelList->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor", this, "UpdateMacroListSelection(Int_t)");
4f6473f6 225
226 // Handle the signal "NewEventLoaded"
4d62585e 227 AliEveEventManager::GetMaster()->Connect("NewEventLoaded()", "AliEveTRDTrackListEditor", this, "HandleNewEventLoaded()");
4f6473f6 228
229 // Handle the signal "Selected" (another tab has been selected)
db16b708 230 GetGedEditor()->GetTab()->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor", this, "HandleTabChangedToIndex(Int_t)");
2ef0687e 231}
232
c04e790a 233//______________________________________________________
caaf90d2 234AliEveTRDTrackListEditor::~AliEveTRDTrackListEditor()
3f797131 235{
16db6074 236 // Destructor: Closes all tabs created by this object and
237 // frees the corresponding memory.
238
caaf90d2 239 if (fFileTypes != 0)
39b891ff 240 {
caaf90d2 241 delete [] fFileTypes;
242 fFileTypes = 0;
2ef0687e 243 }
3f797131 244
caaf90d2 245 if (fFileInfo != 0)
39b891ff 246 {
caaf90d2 247 delete fFileInfo;
248 fFileInfo = 0;
39b891ff 249 }
4f6473f6 250 // Close and delete all tabs that have been created by this class
251 CloseTabs();
252
253 if (fHistoCanvasName != 0)
254 {
255 delete fHistoCanvasName;
256 fHistoCanvasName = 0;
257 }
38a30030 258 if (fInheritedMacroList != 0)
259 {
260 fInheritedMacroList->Delete();
261 delete fInheritedMacroList;
262 fInheritedMacroList = 0;
263 }
caaf90d2 264}
265
c04e790a 266//______________________________________________________
db16b708 267void AliEveTRDTrackListEditor::AddMacro(const Char_t* name, const Char_t* path)
caaf90d2 268{
16db6074 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.
caaf90d2 271 Int_t result = fM->AddMacro(path, name);
272
273 switch (result)
39b891ff 274 {
caaf90d2 275 case SUCCESS:
276 UpdateMacroList();
277 break;
278 case WARNING:
39b891ff 279 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Warning", "Macro is already in list (won't be added again)!",
280 kMBIconExclamation, kMBOk);
caaf90d2 281 break;
db16b708 282 case ERROR:
c1869a7c 283 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", "Failed to load the macro (check messages in the terminal)!",
db16b708 284 kMBIconExclamation, kMBOk);
285 break;
caaf90d2 286 case SIGNATURE_ERROR:
287 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
2f9b41fd 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*)",
caaf90d2 289 kMBIconExclamation, kMBOk);
290 break;
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);
294 break;
295 default:
296 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
297 Form("AliEveTRDTrackList::AddMacro exited with unknown return value: %d", result),
298 kMBIconExclamation, kMBOk);
299 break;
2ef0687e 300 }
301}
302
c04e790a 303//______________________________________________________
2ef0687e 304void AliEveTRDTrackListEditor::ApplyMacros()
305{
16db6074 306 // Applies the selected macros and updates the view.
307
ea24e1bc 308 Bool_t success = kFALSE;
309
2670605d 310 // First apply the single track selection macros
311 TList* selIterator = new TList();
312 ftlMacroSelList->GetSelectedEntries(selIterator);
313 fM->ApplySTSelectionMacros(selIterator);
caaf90d2 314
39b891ff 315 // Update view
316 gEve->Redraw3D();
39b891ff 317
3f797131 318 // Now apply the process macros
2670605d 319 TList* procIterator = new TList();
320 ftlMacroList->GetSelectedEntries(procIterator);
321 success = fM->ApplyProcessMacros(selIterator, procIterator);
2ef0687e 322
caaf90d2 323 // Update histogram tab (data has to be reloaded)
324 SetModel(fM);
325 Update();
2ef0687e 326
bcb45225 327 // AlieveTRDTrackList::ApplyProcessMacros() automatically selects a macro -> Draw the histogram for it,
328 // if a process macro has been applied
2670605d 329 if (success && procIterator->GetEntries() > 0)
4f6473f6 330 {
331 // Set focus on "Histograms" tab
db16b708 332 GetGedEditor()->GetTab()->SetTab("Results");
4f6473f6 333
334 DrawHistos();
335 }
bcb45225 336
90ae0503 337 delete selIterator;
338 delete procIterator;
ea24e1bc 339
90ae0503 340 if (!success) {
ea24e1bc 341 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
342 "AliEveTRDTrackList::ApplyProcessMacros experienced an error (cf. CINT-output)!",
343 kMBIconExclamation, kMBOk);
344 }
8e27fca1 345}
c04e790a 346
db16b708 347//______________________________________________________
348void AliEveTRDTrackListEditor::NewMacros()
349{
00dc25ef 350 // Start the macro creation wizard.
db16b708 351 // thanks to Jacek Otwinowski<J.Otwinowski@GSI.DE> for this suggestion
352
00dc25ef 353 AliEveTRDMacroWizard *wizz = new AliEveTRDMacroWizard();
57d55fae 354 wizz->Connect("Create(Char_t*)", "AliEveTRDTrackListEditor", this, "AddMacro(Char_t*)");
db16b708 355}
356
357
c04e790a 358//______________________________________________________
2ef0687e 359void AliEveTRDTrackListEditor::BrowseMacros()
360{
16db6074 361 // Creates a file-dialog. The selected files will be added to the macro list
362 // via AddMacro(...).
363
caaf90d2 364 new TGFileDialog(gClient->GetRoot(), GetMainFrame(), kFDOpen, fFileInfo);
2ef0687e 365
caaf90d2 366 if (fFileInfo->fIniDir != 0 && fFileInfo->fFileNamesList != 0)
3f797131 367 {
2ef0687e 368 // Extract filenames
caaf90d2 369 TObject* iter = fFileInfo->fFileNamesList->First();
2ef0687e 370
371 Char_t* name = 0;
372
373 while (iter != 0)
374 {
caaf90d2 375 // NOTE: fileInfo->fFileNamesList will be changed by that, too!
71f50468 376 name = (Char_t*)strrchr(iter->GetName(), '/');
2ef0687e 377 // Delete '"' at the end
378 name[strlen(name)] = '\0';
caaf90d2 379
db16b708 380 AddMacro(name + 1, fFileInfo->fIniDir);
caaf90d2 381 iter = (TObjString*)fFileInfo->fFileNamesList->After(iter);
2ef0687e 382 }
383 }
3f797131 384
caaf90d2 385 // -> The following problem has been fixed (trunk -> Changes according to 03 September 2008):
3f797131 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.
caaf90d2 388 //if (fileInfo->fFileNamesList == 0) fileInfo->fFileNamesList = new TList();
389}
390
4f6473f6 391//______________________________________________________
392void AliEveTRDTrackListEditor::CloseTabs()
393{
16db6074 394 // Closes + deletes the tabs created by this object
395
4f6473f6 396 if (fHistoCanvas != 0)
397 {
398 // Close the created tab, if it exists
399 if (fHistoCanvasName != 0)
400 {
401 if (gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString()))
402 {
403 // Now the created tab is the current one and can be deleted
404 gEve->GetBrowser()->GetTab(1)->RemoveTab();
405 }
406 }
407 // With the tab removal, the canvas will be deleted automatically!
408 fHistoCanvas = 0;
409 }
410}
411
c04e790a 412//______________________________________________________
caaf90d2 413void AliEveTRDTrackListEditor::DrawHistos()
414{
16db6074 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.
417
ed0e1245 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);
422// return;
423// }
424
425 TFile* file(NULL);
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);
caaf90d2 432 return;
433 }
5894f34d 434 TTree *ts(NULL);//, *tc(NULL);
ed0e1245 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")),
caaf90d2 440 kMBIconExclamation, kMBOk);
441 return;
442 }
5894f34d 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);
449// return;
450// }
bcb45225 451
ed0e1245 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
bcb45225 458 }
ed0e1245 459 // Check, if a histo macro shall be drawn
460 canvas=0;
5894f34d 461 TH1* myHist(NULL);
ed0e1245 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('['));
465 // Histo macro
466 if(idx<0) {
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);
471 } else {
472 SetDrawingToHistoCanvasTab(++canvas);
473 myHist->DrawCopy();
474 UpdateHistoCanvasTab(canvas);
caaf90d2 475 }
ed0e1245 476 } else {
477 TString ss=s(0, idx);
5894f34d 478 if (!ts->GetBranch(ss.Data())) {
ed0e1245 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);
483 continue;
484 } else {
485 if(!singleSelected){
486 vs=s;
487 singleSelected++;
488 } else if(singleSelected<3){
489 vs+=":";vs+=s;
490 singleSelected++;
491 } else {
492 AliError(Form("Variable \"%s\" can no longer be attached to plot !", s.Data()));
caaf90d2 493 }
caaf90d2 494 }
495 }
496 }
ed0e1245 497 if(singleSelected){
498 SetDrawingToHistoCanvasTab(++canvas);
499 ts->Draw(vs.Data());
500 UpdateHistoCanvasTab(canvas);
501 }
caaf90d2 502
caaf90d2 503
504 file->Close("R");
505 delete file;
ed0e1245 506 file = NULL;
caaf90d2 507}
508
c04e790a 509//______________________________________________________
2670605d 510Int_t AliEveTRDTrackListEditor::GetNSelectedHistograms() const
caaf90d2 511{
38a30030 512 // Returns the number of selected macros (or rather: of their selected data) in the "Histograms"-tab
16db6074 513
caaf90d2 514 Int_t count = 0;
515
516 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
517 {
518 if (fCheckButtons[i]->TGButton::GetState() == kButtonDown) count++;
519 }
520
521 return count;
2ef0687e 522}
523
c04e790a 524//______________________________________________________
2ef0687e 525void AliEveTRDTrackListEditor::HandleMacroPathSet()
526{
16db6074 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".
530
90ae0503 531 Char_t bname[AliEveTRDTrackList::fkMaxMacroNameLength]; // allocate buffers
532
caaf90d2 533 if (strlen(fteField->GetText()) != 0)
5715955a 534 {
535 // Expand the pathname
536 Char_t* systemPath = gSystem->ExpandPathName(fteField->GetText());
537 fteField->SetText(systemPath);
538 delete systemPath;
539 systemPath = 0;
540
2ef0687e 541 // Check if file exists
542 FILE* fp = NULL;
543
caaf90d2 544 fp = fopen(fteField->GetText(), "rb");
39b891ff 545 if (fp != NULL)
546 {
3f797131 547 fclose(fp);
caaf90d2 548
3f797131 549 // Extract filename
71f50468 550 Char_t* name = (Char_t*)strrchr(fteField->GetText(), '/');
3f797131 551
552 // Current path
90ae0503 553 if (!name) {
554 name= bname;
4f6473f6 555 memset(name, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroNameLength);
90ae0503 556 snprintf(name, AliEveTRDTrackList::fkMaxMacroNameLength, "%s", fteField->GetText());
3f797131 557
4f6473f6 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));
90ae0503 561 snprintf(pathname, AliEveTRDTrackList::fkMaxMacroNameLength + 2, "./%s", fteField->GetText());
caaf90d2 562 fteField->SetText(pathname);
563
db16b708 564 AddMacro(name);
39b891ff 565 }
566 // Different path
567 else
568 {
3f797131 569 // Extract path
90ae0503 570 Char_t path[AliEveTRDTrackList::fkMaxMacroPathLength];
4f6473f6 571 memset(path, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroPathLength);
90ae0503 572 snprintf(path, strlen(fteField->GetText()) - strlen(name), "%s", fteField->GetText());
caaf90d2 573
574 // Ignore the slash "/" in name
db16b708 575 AddMacro(name + 1, path);
90ae0503 576 }
39b891ff 577 }
578 else
579 {
3f797131 580 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
39b891ff 581 "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
2ef0687e 582 }
583 }
584}
585
4f6473f6 586//______________________________________________________
587void AliEveTRDTrackListEditor::HandleNewEventLoaded()
588{
16db6074 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.
592
8bdeb570 593 // Inherit the macro list and track style for the next track list!
594 fInheritSettings = kTRUE;
bcb45225 595
596 // Close the tabs
4f6473f6 597 CloseTabs();
598}
599
600//______________________________________________________
601void AliEveTRDTrackListEditor::HandleTabChangedToIndex(Int_t index)
602{
16db6074 603 // Saves the current tab in the current AliEveTRDTrackList.
604
4f6473f6 605 fM->SetSelectedTab(index);
606}
607
bcb45225 608//______________________________________________________
609void AliEveTRDTrackListEditor::InheritMacroList()
610{
38a30030 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.
bcb45225 615
38a30030 616 if (fInheritedMacroList == 0) return;
617
618 // Clear list
bcb45225 619 fM->fMacroList->Delete();
38a30030 620
621 // Store data from interior list in the track list's map
622 TMapIter* iter = (TMapIter*)fInheritedMacroList->MakeIterator();
623
624 TObject* key = 0;
625 TMacroData* macro = 0;
626
627 while ((key = iter->Next()) != 0)
bcb45225 628 {
38a30030 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()));
632 else
633 {
ea41d018 634 Error("AliEveTRDTrackListEditor::InheritMacroList", "Failed to inherit the macro \"%s\"!", key->GetName());
38a30030 635 }
8bdeb570 636 }
38a30030 637
638 fInheritedMacroList->Delete();
639 delete fInheritedMacroList;
640 fInheritedMacroList = 0;
8bdeb570 641}
642
643//______________________________________________________
644void AliEveTRDTrackListEditor::InheritStyle()
645{
16db6074 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.
8bdeb570 649
650 for (Int_t ind = 0; ind < 3; ind++)
651 {
652 if (fbgStyleTrack->GetButton(ind)->IsOn())
653 {
654 SetTrackModel(ind);
655 break;
656 }
657 }
658 for (Int_t ind = 0; ind < 3; ind++)
659 {
660 if (fbgStyleColor->GetButton(ind)->IsOn())
661 {
662 SetTrackColor(ind);
663 break;
664 }
bcb45225 665 }
666}
667
c04e790a 668//______________________________________________________
2ef0687e 669void AliEveTRDTrackListEditor::RemoveMacros()
670{
38a30030 671 // Removes the selected macros from the corresponding list.
16db6074 672
90ae0503 673 TList iterator;
674 ftlMacroList->GetSelectedEntries(&iterator);
675 fM->RemoveSelectedMacros(&iterator);
3f797131 676
3f797131 677
90ae0503 678 iterator.Clear();
679 ftlMacroSelList->GetSelectedEntries(&iterator);
680 fM->RemoveSelectedMacros(&iterator);
2ef0687e 681
4f6473f6 682 // Selected macros are deleted from the list -> No selected entries left
683 fM->fMacroListSelected = 0;
2ef0687e 684 UpdateMacroList();
685}
686
6e420565 687//______________________________________________________
688void AliEveTRDTrackListEditor::SaveMacroList(TMap* list)
689{
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).
693
694 if (fInheritedMacroList != 0)
695 {
696 fInheritedMacroList->Delete();
697 delete fInheritedMacroList;
698 }
699 fInheritedMacroList = new TMap();
700 fInheritedMacroList->SetOwnerKeyValue(kTRUE, kTRUE);
701
702 TMapIter* iter = (TMapIter*)list->MakeIterator();
703 TObject* key = 0;
704 TMacroData* macro = 0;
705
706 while ((key = iter->Next()) != 0)
707 {
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()));
711 else
712 {
ea41d018 713 Error("AliEveTRDTrackListEditor::SaveMacroList", "Failed to inherit the macro \"%s\"!", key->GetName());
6e420565 714 }
715 }
716}
717
bcb45225 718//______________________________________________________
ed0e1245 719void AliEveTRDTrackListEditor::SetDrawingToHistoCanvasTab(Int_t canvas)
bcb45225 720{
16db6074 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.
723
bcb45225 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.
bcb45225 726
ed0e1245 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));
730 fHistoCanvas->cd();
bcb45225 731}
732
c04e790a 733//______________________________________________________
2ef0687e 734void AliEveTRDTrackListEditor::SetModel(TObject* obj)
8e27fca1 735{
16db6074 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.
738
2ef0687e 739 fM = dynamic_cast<AliEveTRDTrackList*>(obj);
740
8bdeb570 741 if (fM == 0)
742 {
8e27fca1 743 Error("SetModel", "Parameter is zero pointer");
744 return;
745 }
746
38a30030 747 // Provide a pointer to this editor
748 fM->fEditor = this;
749
8bdeb570 750 // If macro list + track style shall be inherited from previously loaded track list, do so
751 if (fInheritSettings)
bcb45225 752 {
753 InheritMacroList();
8bdeb570 754 InheritStyle();
755
756 fInheritSettings = kFALSE;
bcb45225 757 }
ecbbe371 758
8bdeb570 759 // Select the correct styles
ecbbe371 760 Int_t b = 0;
761 UChar_t style = fM->GetSelectedTrackStyle();
8bdeb570 762 if (TESTBIT(style, AliEveTRDTrack::kSource)) b = 2;
763 else
764 {
765 if (TESTBIT(style, AliEveTRDTrack::kPID)) b = 1;
ecbbe371 766 else b = 0;
767 }
768 fbgStyleColor->SetButton(b, kTRUE);
769
770
8bdeb570 771 if (TESTBIT(style, AliEveTRDTrack::kTrackCosmics)) b = 2;
772 else
773 {
774 if (TESTBIT(style, AliEveTRDTrack::kTrackModel)) b = 1;
ecbbe371 775 else b = 0;
776 }
777 fbgStyleTrack->SetButton(b, kTRUE);
bcb45225 778
2ef0687e 779 UpdateMacroList();
8e27fca1 780 UpdateHistoList();
781
4f6473f6 782 // View correct tab
ecbbe371 783 GetGedEditor()->GetTab()->SetTab(fM->GetSelectedTab());
4f6473f6 784}
785
4cbab605 786//______________________________________________________
8bdeb570 787void AliEveTRDTrackListEditor::SetTrackColor(Int_t ind)
4cbab605 788{
16db6074 789 // Sets the color model for the tracks, updates the tracks with this model and
790 // redraws the scene.
791
8bdeb570 792 switch(ind)
793 {
9443fb9d 794 case AliTRDpidUtil::kLQ:
795 fM->UpdateTrackStyle(AliEveTRDTrack::kPID, AliTRDpidUtil::kLQ);
2f9b41fd 796 break;
9443fb9d 797 case AliTRDpidUtil::kNN:
798 fM->UpdateTrackStyle(AliEveTRDTrack::kPID, AliTRDpidUtil::kNN);
2f9b41fd 799 break;
800 default:
801 fM->UpdateTrackStyle(AliEveTRDTrack::kSource);
802 break;
ecbbe371 803 }
8bdeb570 804
ecbbe371 805 gEve->Redraw3D();
4cbab605 806}
807
808//______________________________________________________
8bdeb570 809void AliEveTRDTrackListEditor::SetTrackModel(Int_t ind)
4cbab605 810{
16db6074 811 // Sets the track model for the tracks, updates the tracks with this model and
812 // redraws the scene.
813
8bdeb570 814 switch(ind)
815 {
2f9b41fd 816 case AliEveTRDTrack::kRieman:
817 fM->UpdateTrackStyle(AliEveTRDTrack::kTrackModel, AliEveTRDTrack::kRieman);
818 break;
819 case AliEveTRDTrack::kKalman:
820 fM->UpdateTrackStyle(AliEveTRDTrack::kTrackModel, AliEveTRDTrack::kKalman);
821 break;
822 default:
823 fM->UpdateTrackStyle(AliEveTRDTrack::kTrackCosmics);
824 break;
ecbbe371 825 }
8bdeb570 826
ecbbe371 827 gEve->Redraw3D();
4cbab605 828}
829
4f6473f6 830//______________________________________________________
831void AliEveTRDTrackListEditor::UpdateDataFromMacroListSelection()
832{
16db6074 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.
836
4f6473f6 837 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
8e27fca1 838 {
4f6473f6 839 fM->SetHistoDataSelection(i, fCheckButtons[i]->IsOn());
8e27fca1 840 }
caaf90d2 841}
842
ecbbe371 843//______________________________________________________
ed0e1245 844void AliEveTRDTrackListEditor::UpdateHistoCanvasTab(Int_t canvas)
ecbbe371 845{
ce239ca6 846 // Updates the histogram and the corresponding tab (including titles).
16db6074 847
ecbbe371 848 // Update name of the tab (tab has been set to current tab!)
ed0e1245 849 //fHistoCanvasName->SetString(Form("%s_%d", fM->GetName(), canvas));
ecbbe371 850
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
ed0e1245 853 //gEve->GetBrowser()->GetTab(canvas)->GetCurrentTab()->SetText(new TGString(fHistoCanvasName));
ecbbe371 854
855 // Switch tabs to force redrawing
ed0e1245 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));
859 return;
860 }
861 if(!tab->SetTab(canvas)){
862 AliError(Form("Failed updating tab[%d]", canvas));
863 return;
864 }
865 fHistoCanvas->Modified();
ecbbe371 866 fHistoCanvas->Update();
867}
868
c04e790a 869//______________________________________________________
caaf90d2 870void AliEveTRDTrackListEditor::UpdateHistoList()
871{
16db6074 872 // Reloads (updates) the buttons in the "Histograms"-tab via
873 // the current AliEveTRDTrackList (data).
874
4f6473f6 875 fHistoSubFrame->TGCompositeFrame::Cleanup();
caaf90d2 876
877 // Set buttons for histograms
878 if (fCheckButtons != 0) delete fCheckButtons;
879 fCheckButtons = new TGCheckButton*[fM->fDataFromMacroList->GetEntries()];
880
881 TObjString* iter = (TObjString*)fM->fDataFromMacroList->First();
882 for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries() && iter != 0; i++)
883 {
884 fCheckButtons[i] = new TGCheckButton(fHistoSubFrame, iter->GetName());
885 fHistoSubFrame->AddFrame(fCheckButtons[i]);
886
887 fCheckButtons[i]->SetState(kButtonUp, kFALSE);
888 fCheckButtons[i]->MapRaised();
4f6473f6 889 fCheckButtons[i]->SetOn(fM->HistoDataIsSelected(i));
890 fCheckButtons[i]->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "UpdateDataFromMacroListSelection()");
caaf90d2 891
892 iter = (TObjString*)fM->fDataFromMacroList->After(iter);
893 }
2ef0687e 894}
895
c04e790a 896//______________________________________________________
2ef0687e 897void AliEveTRDTrackListEditor::UpdateMacroList()
898{
16db6074 899 // Reloads (updates) the macro list (selection AND process macros) via
900 // the current AliEveTRDTrackList (data).
901
caaf90d2 902 ftlMacroList->RemoveAll();
caaf90d2 903 ftlMacroSelList->RemoveAll();
38a30030 904
905 TMapIter* iter = (TMapIter*)fM->fMacroList->MakeIterator();
906 TObject* key = 0;
907 TMacroData* macro = 0;
3f797131 908
38a30030 909 Int_t ind = 0;
910 while ((key = iter->Next()) != 0)
3f797131 911 {
38a30030 912 macro = (TMacroData*)fM->fMacroList->GetValue(key);
913 if (macro != 0)
914 {
915 if (macro->IsProcessMacro())
916 {
917 ftlMacroList->AddEntry(macro->GetName(), ind);
918 // Select, what has been selected before
919 ftlMacroList->Select(ind, fM->MacroListIsSelected(ind));
920 ind++;
921 }
922 else if (macro->IsSelectionMacro())
923 {
924 ftlMacroSelList->AddEntry(macro->GetName(), ind);
925 // Select, what has been selected before
926 ftlMacroSelList->Select(ind, fM->MacroListIsSelected(ind));
927 ind++;
928 }
929 else
930 {
931 Error("AliEveTRDTrackListEditor::UpdateMacroList()",
ea41d018 932 "Macro \"%s/%s.C\" is neither a selection macro nor a process macro!",
933 macro->GetPath(), macro->GetName());
38a30030 934 }
935 }
936 else
937 {
938 Error("AliEveTRDTrackListEditor::UpdateMacroList()",
ea41d018 939 "Macro list is corrupted: Macro \"%s\" not found!", key->GetName());
940 }
3f797131 941 }
942
38a30030 943 ftlMacroList->SortByName();
caaf90d2 944 ftlMacroSelList->SortByName();
4f6473f6 945}
946
947//______________________________________________________
948void AliEveTRDTrackListEditor::UpdateMacroListSelection(Int_t ind)
949{
38a30030 950 // Saves the current selection in the macro listS to the current
16db6074 951 // AliEveTRDTrackList. This means that the selection is updated and won't
952 // get lost, if another editor is loaded in Eve.
38a30030 953 // NOTE: The indices in BOTH lists will be unique!
16db6074 954
4f6473f6 955 // Toggle selected item
956 fM->SetMacroListSelection(ind, !fM->MacroListIsSelected(ind));
957}
db16b708 958
959
ce239ca6 960//______________________________________________________
961//______________________________________________________
962//______________________________________________________
963
964
db16b708 965/////////////////////////////////////////////////
00dc25ef 966ClassImp(AliEveTRDMacroWizard)
ce239ca6 967/////////////////////////////////////////////////
db16b708 968
969//______________________________________________________
00dc25ef 970AliEveTRDMacroWizard::AliEveTRDMacroWizard(const TGWindow* p)
db16b708 971 :TGMainFrame(p ? p : gClient->GetRoot(), 10, 10, kMainFrame | kVerticalFrame)
972 ,fText(0x0)
973 ,fCombo(0x0)
974 ,fTextEdit(0x0)
9a11b2ee 975 ,fbCreate(0x0)
976 ,fbCancel(0x0)
db16b708 977{
ce239ca6 978 // Creates the macro wizard.
979
db16b708 980 const Int_t width = 300;
981
982 // horizontal frame
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));
989
990 fText = new TGTextEntry(fFrameName);
991 fText->SetMaxLength(255);
992 fText->SetAlignment(kTextLeft);
993 fText->SetText("");
994 fText->Resize(width, fText->GetDefaultHeight());
995 fFrameName->AddFrame(fText, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
996
997
998 // horizontal frame
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));
1005
1006 fTextEdit = new TGTextEdit(fFrameComment, width, 5*fText->GetDefaultHeight());
1007 fFrameComment->AddFrame(fTextEdit, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1008
1009 // horizontal frame
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));
1016
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);
1024 fCombo->Select(-1);
1025 fCombo->Resize(width, fText->GetDefaultHeight());
1026 fFrameType->AddFrame(fCombo, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1027
9a11b2ee 1028 // horizontal frame
1029 TGHorizontalFrame *fFrameAction = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1030 fbCancel = new TGTextButton(fFrameAction, "Cancel");
00dc25ef 1031 fbCancel->SetToolTipText("Exit macro creation wizard");
9a11b2ee 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));
1036
db16b708 1037
1038 // horizontal frame
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));
1045
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));
9a11b2ee 1050 AddFrame(fFrameAction, new TGLayoutHints(kLHintsRight | kLHintsTop | kLHintsExpandX,2,2,2,2));
db16b708 1051
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));
1055
1056
00dc25ef 1057 SetWindowName("TRD Macro Wizard");
db16b708 1058 SetMWMHints(kMWMDecorAll,
1059 kMWMFuncAll,
1060 kMWMInputModeless);
1061 MapSubwindows();
1062
1063 Resize(GetDefaultSize());
1064 MapWindow();
1065
1066 // Do the linking
00dc25ef 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()");
9a11b2ee 1070
1071 // Standard choice
1072 fCombo->Select(1, kFALSE);
db16b708 1073}
1074
a6e0ebfe 1075const Char_t *fIncludes =
db16b708 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"
1083"#endif\n";
1084
a6e0ebfe 1085const Char_t *fMacroTemplate[7] = {
db16b708 1086""
1087," if (!track) return kFALSE;\n"
1088
1089," n = 0;\n"
9a11b2ee 1090" r = 0x0;\n"
db16b708 1091" if (!track) return;\n"
1092
1093," if (!track) return 0x0;\n"
9a11b2ee 1094" TH1* h = 0x0;\n\n"
1095"// Set bins, xmin and xmax here\n"
1096" Int_t n = 1;\n"
1097" Double_t xmin = 0;\n"
1098" Double_t xmax = 100;\n\n"
db16b708 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"
1104
1105," if (!track) return kFALSE;\n"
1106" if (!track2) return kFALSE;\n"
1107
1108," n = 0;\n"
9a11b2ee 1109" r = 0x0;\n"
db16b708 1110" if (!track) return;\n"
1111" if (!track2) return;\n"
1112
1113," if (!track) return 0x0;\n"
1114" if (!track2) return 0x0;\n"
9a11b2ee 1115" TH1* h = 0x0;\n\n"
1116"// Set bins, xmin and xmax here\n"
1117" Int_t n = 1;\n"
1118" Double_t xmin = 0;\n"
1119" Double_t xmax = 100;\n\n"
db16b708 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"
1125};
1126//______________________________________________________
00dc25ef 1127void AliEveTRDMacroWizard::Create(Int_t type)
db16b708 1128{
ce239ca6 1129 // Creates the macro with the selected type (combo box).
1130
db16b708 1131 const Char_t *name = fText->GetText();
1132 if(strcmp(name,"")==0){
1133 AliInfo("Please specify a name for your macro.");
9a11b2ee 1134 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
1135 "Please specify a name for your macro.", kMBIconExclamation, kMBOk);
1136 //fCombo->Select(-1);
1137 return;
1138 }
1139
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);
db16b708 1147 return;
1148 }
1149
1150 FILE* fp = 0x0;
1151 if(!(fp = fopen(Form("%s.C", name), "wt"))){
1152 AliInfo("Couldn't create macro file.");
9a11b2ee 1153 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
1154 "Couldn't create macro file.", kMBIconExclamation, kMBOk);
1155 //fCombo->Select(-1);
db16b708 1156 return;
1157 }
1158
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);
1162
1163 fprintf(fp, "\n%s\n", fIncludes);
1164
00dc25ef 1165 switch(type){
db16b708 1166 case AliEveTRDTrackList::kSingleTrackSelect:
1167 fprintf(fp, "Bool_t %s(const AliTRDtrackV1 *track)\n", name);
1168 break;
1169 case AliEveTRDTrackList::kCorrelTrackSelect:
1170 fprintf(fp, "Bool_t %s(const AliTRDtrackV1 *track, const AliTRDtrackV1 *track2)\n", name);
1171 break;
1172 case AliEveTRDTrackList::kSingleTrackAnalyse:
1173 fprintf(fp, "void %s(const AliTRDtrackV1 *track, Double_t*& r, Int_t& n)\n", name);
1174 break;
1175 case AliEveTRDTrackList::kSingleTrackHisto:
1176 fprintf(fp, "TH1* %s(const AliTRDtrackV1 *track)\n", name);
1177 break;
1178 case AliEveTRDTrackList::kCorrelTrackAnalyse:
1179 fprintf(fp, "void %s(const AliTRDtrackV1 *track, const AliTRDtrackV1 *track2, Double_t*& r, Int_t& n)\n", name);
1180 break;
1181 case AliEveTRDTrackList::kCorrelTrackHisto:
1182 fprintf(fp, "TH1* %s(const AliTRDtrackV1 *track, const AliTRDtrackV1 *track2)\n", name);
1183 break;
1184 default:
00dc25ef 1185 AliInfo(Form("Unknown type[%d]", type));
9a11b2ee 1186 new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
00dc25ef 1187 Form("Unknown type[%d]", type), kMBIconExclamation, kMBOk);
db16b708 1188 fclose(fp);
1189 gSystem->Exec(Form("rm -f %s.C", name));
9a11b2ee 1190 //fCombo->Select(-1);
db16b708 1191 return;
1192 }
1193
00dc25ef 1194 fprintf(fp, "{\n%s\n", fMacroTemplate[type]);
db16b708 1195 fprintf(fp, "// add your own code here\n\n\n}\n");
1196 fclose(fp);
57d55fae 1197
00dc25ef 1198 Emit("Create(Int_t)", type);
57d55fae 1199 Create((Char_t*)name);
db16b708 1200 CloseWindow();
1201}
57d55fae 1202
1203//______________________________________________________
00dc25ef 1204void AliEveTRDMacroWizard::Create(Char_t *name)
57d55fae 1205{
ce239ca6 1206 // Emits the creation signal.
1207
57d55fae 1208 Emit("Create(Char_t*)", Form("%s.C", name));
1209}
9a11b2ee 1210
1211//______________________________________________________
00dc25ef 1212void AliEveTRDMacroWizard::HandleCreate()
9a11b2ee 1213{
ce239ca6 1214 // Handles the signal, when the creation button is pressed.
1215
9a11b2ee 1216 Create(fCombo->GetSelected());
1217}