]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveTRDTrackListEditor.cxx
Update master to aliroot
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveTRDTrackListEditor.cxx
1 // Author: Benjamin Hess   29/01/2010
2
3 /*************************************************************************
4  * Copyright (C) 2009-2010, Alexandru Bercuci, Benjamin Hess.            *
5  * All rights reserved.                                                  *
6  *************************************************************************/
7
8 //////////////////////////////////////////////////////////////////////////
9 //                                                                      //
10 // AliEveTRDTrackListEditor                                             //
11 //                                                                      //
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 //////////////////////////////////////////////////////////////////////////
22
23 #include <AliLog.h>
24 #include <AliEveTRDData.h>
25 #include <AliEveTRDTrackList.h>
26 #include "AliEveTRDTrackListEditor.h"
27 #include <AliEveEventManager.h>
28 #include <AliTRDReconstructor.h>
29 #include <AliTRDtrackV1.h>
30
31 #include <TGButton.h>
32 #include <TCanvas.h>     
33 #include <TEveBrowser.h>
34 #include <TEveGedEditor.h> 
35 #include <TEveMacro.h>
36 #include <TEveManager.h>
37 #include <TFile.h>
38 #include <TG3DLine.h>
39 #include <TGButtonGroup.h>
40 #include <TGFileDialog.h>
41 #include <TGLabel.h>
42 #include <TGListBox.h>
43 #include <TGMsgBox.h>
44 #include <TGTab.h>
45 #include <TMap.h>
46 #include <TObjString.h>
47 #include <TROOT.h>
48 #include <TSystem.h>
49 #include <TGTextEntry.h>
50 #include <TGTextEdit.h>
51 #include <TGComboBox.h>
52 #include <TGTextView.h>
53 #include <TH1.h>
54 #include <TTreeStream.h>
55
56
57 ClassImp(AliEveTRDTrackListEditor)
58
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),
65   fM(0),
66   fHistoCanvas(0),
67   fHistoCanvasName(0),
68   fInheritedMacroList(0),
69   fInheritSettings(kFALSE),
70   fStyleFrame(0),
71   fMainFrame(0),
72   fHistoFrame(0),
73   fHistoSubFrame(0),
74   fBrowseFrame(0),
75   fbgStyleColor(0),
76   fbgStyleTrack(0),
77   frbColor(new TGRadioButton*[3]),
78   frbTrack(new TGRadioButton*[3]),
79   fbBrowse(0),
80   fbNew(0),
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),
90   fLine1(0), fLine2(0), fLine3(0), fLine4(0), fLine5(0),
91   fCheckButtons(0)
92 {
93   // Creates the AliEveTRDTrackListEditor.
94
95   // Style stuff
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);
100
101   // Style - Track model
102   fbgStyleTrack = new TGButtonGroup(fStyleFrame, "Track model");
103   fbgStyleTrack->SetMapSubwindows(kTRUE);
104   fbgStyleTrack->Resize(194, 200);
105   fStyleFrame->AddFrame(fbgStyleTrack);
106
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)");
113
114   // Style - Color model
115   fbgStyleColor = new TGButtonGroup(fStyleFrame, "Color model");
116   fbgStyleColor->SetMapSubwindows(kTRUE);
117   fbgStyleColor->Resize(194, 200);
118   fStyleFrame->AddFrame(fbgStyleColor);
119
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)");
126   
127   // Functionality for adding plugins  
128   fMainFrame = CreateEditorTabSubFrame("Process");
129    
130   fLabel1 = new TGLabel(fMainFrame,"Add plugin(s):");
131   fMainFrame->AddFrame(fLabel1);
132   fBrowseFrame = new TGHorizontalFrame(fMainFrame);
133
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);
138   
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);
143   
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);
149
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);
154
155   ftlMacroSelList = new TGListBox(fMainFrame);
156   ftlMacroSelList->Resize(194, 94);
157   ftlMacroSelList->SetMultipleSelections(kTRUE);
158   fMainFrame->AddFrame(ftlMacroSelList);
159
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);
164
165   ftlMacroList = new TGListBox(fMainFrame);
166   ftlMacroList->Resize(194, 94);
167   ftlMacroList->SetMultipleSelections(kTRUE);
168   fMainFrame->AddFrame(ftlMacroList);
169
170   fLine3 = new TGHorizontal3DLine(fMainFrame, 194, 8);
171   fMainFrame->AddFrame(fLine3, new TGLayoutHints(kLHintsLeft  | kLHintsTop, 2, 2, 8, 2));  
172
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);
178
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);
183
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);
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
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);
202
203   // Set up file dialog
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;
212   fFileInfo->fIniDir = (Char_t*)"$ALICE_ROOT/PWGPP/TRD/macros/EVE";
213   fFileInfo->fFileTypeIdx = 2;
214   fFileInfo->fMultipleSelection = kTRUE;
215
216   fHistoCanvasName = new TGString("");
217
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
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)");
225
226   // Handle the signal "NewEventLoaded"
227   AliEveEventManager::GetMaster()->Connect("NewEventLoaded()", "AliEveTRDTrackListEditor", this, "HandleNewEventLoaded()");
228
229   // Handle the signal "Selected" (another tab has been selected)
230   GetGedEditor()->GetTab()->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor", this, "HandleTabChangedToIndex(Int_t)");
231 }
232
233 //______________________________________________________
234 AliEveTRDTrackListEditor::~AliEveTRDTrackListEditor()
235 {
236   // Destructor: Closes all tabs created by this object and
237   // frees the corresponding memory.
238
239   if (fFileTypes != 0)
240   {
241     delete [] fFileTypes;
242     fFileTypes = 0;
243   }
244
245   if (fFileInfo != 0)
246   {
247     delete fFileInfo; 
248     fFileInfo = 0;
249   }
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   }
258   if (fInheritedMacroList != 0)
259   {
260     fInheritedMacroList->Delete();
261     delete fInheritedMacroList;
262     fInheritedMacroList = 0;
263   }
264 }
265
266 //______________________________________________________
267 void AliEveTRDTrackListEditor::AddMacro(const Char_t* name, const Char_t* path)
268 {
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);
272
273   switch (result)
274   {
275   case SUCCESS:
276     UpdateMacroList();
277     break;
278   case WARNING:
279     new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Warning", "Macro is already in list (won't be added again)!",
280                  kMBIconExclamation, kMBOk);
281     break;
282   case ERROR:
283     new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", "Failed to load the macro (check messages in the terminal)!",
284                  kMBIconExclamation, kMBOk);
285     break;
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);
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;
300   }
301 }
302
303 //______________________________________________________
304 void AliEveTRDTrackListEditor::ApplyMacros()
305 {
306   // Applies the selected macros and updates the view.
307
308   Bool_t success = kFALSE;
309
310   // First apply the single track selection macros
311   TList* selIterator = new TList();
312   ftlMacroSelList->GetSelectedEntries(selIterator);
313   fM->ApplySTSelectionMacros(selIterator);
314   
315   // Update view
316   gEve->Redraw3D();
317
318   // Now apply the process macros
319   TList* procIterator = new TList();
320   ftlMacroList->GetSelectedEntries(procIterator);
321   success = fM->ApplyProcessMacros(selIterator, procIterator);
322
323   // Update histogram tab (data has to be reloaded)
324   SetModel(fM);
325   Update();
326
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) 
330   {
331     // Set focus on "Histograms" tab
332     GetGedEditor()->GetTab()->SetTab("Results");
333
334     DrawHistos();
335   }
336
337   delete selIterator;
338   delete procIterator;  
339   
340   if (!success) {
341     new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", 
342                  "AliEveTRDTrackList::ApplyProcessMacros experienced an error (cf. CINT-output)!", 
343                  kMBIconExclamation, kMBOk);  
344   }
345 }
346
347 //______________________________________________________
348 void AliEveTRDTrackListEditor::NewMacros()
349 {
350   // Start the macro creation wizard.
351   // thanks to Jacek Otwinowski<J.Otwinowski@GSI.DE> for this suggestion
352
353   AliEveTRDMacroWizard *wizz = new AliEveTRDMacroWizard();
354   wizz->Connect("Create(Char_t*)", "AliEveTRDTrackListEditor", this, "AddMacro(Char_t*)");
355 }
356
357
358 //______________________________________________________
359 void AliEveTRDTrackListEditor::BrowseMacros()
360 {
361   // Creates a file-dialog. The selected files will be added to the macro list
362   // via AddMacro(...).
363
364   new TGFileDialog(gClient->GetRoot(), GetMainFrame(), kFDOpen, fFileInfo);
365   
366   if (fFileInfo->fIniDir != 0 && fFileInfo->fFileNamesList != 0)
367   {       
368     // Extract filenames
369     TObject* iter = fFileInfo->fFileNamesList->First();
370  
371     Char_t* name = 0;
372
373     while (iter != 0)
374     {
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';
379               
380       AddMacro(name + 1, fFileInfo->fIniDir); 
381       iter = (TObjString*)fFileInfo->fFileNamesList->After(iter);
382     }
383   }
384
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();
389 }
390
391 //______________________________________________________
392 void AliEveTRDTrackListEditor::CloseTabs()
393 {
394   // Closes + deletes the tabs created by this object
395
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
412 //______________________________________________________
413 void AliEveTRDTrackListEditor::DrawHistos()
414 {
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  
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);
432     return;
433   }
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);
441     return;
442   }
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 //   }
451
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
458   }
459   // Check, if a histo macro shall be drawn
460   canvas=0;
461   TH1* myHist(NULL);
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);
475       }
476     } else {
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);
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()));
493         }
494       }
495     }
496   }
497   if(singleSelected){
498     SetDrawingToHistoCanvasTab(++canvas);
499     ts->Draw(vs.Data());
500     UpdateHistoCanvasTab(canvas);
501   }
502
503
504   file->Close("R");
505   delete file;
506   file = NULL;
507 }
508
509 //______________________________________________________
510 Int_t AliEveTRDTrackListEditor::GetNSelectedHistograms() const
511 {
512   // Returns the number of selected macros (or rather: of their selected data) in the "Histograms"-tab
513
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;
522 }
523
524 //______________________________________________________
525 void AliEveTRDTrackListEditor::HandleMacroPathSet()
526 {
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
531   Char_t bname[AliEveTRDTrackList::fkMaxMacroNameLength]; // allocate buffers
532
533   if (strlen(fteField->GetText()) != 0)
534   {  
535     // Expand the pathname
536     Char_t* systemPath = gSystem->ExpandPathName(fteField->GetText());
537     fteField->SetText(systemPath);
538     delete systemPath;
539     systemPath = 0;
540                         
541     // Check if file exists
542     FILE* fp = NULL;
543
544     fp = fopen(fteField->GetText(), "rb");
545     if (fp != NULL)
546     {
547       fclose(fp);
548
549       // Extract filename
550       Char_t* name = (Char_t*)strrchr(fteField->GetText(), '/');
551
552       // Current path
553       if (!name) {
554         name= bname;
555         memset(name, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroNameLength);
556         snprintf(name, AliEveTRDTrackList::fkMaxMacroNameLength, "%s", fteField->GetText());
557
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);
563
564         AddMacro(name);  
565       }
566       // Different path
567       else
568       {
569         // Extract path
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());
573         
574         // Ignore the slash "/" in name
575         AddMacro(name + 1, path);  
576       }
577     }
578     else
579     {
580       new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", 
581                    "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
582     }
583   }
584 }
585
586 //______________________________________________________
587 void AliEveTRDTrackListEditor::HandleNewEventLoaded()
588 {
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
593   // Inherit the macro list and track style for the next track list!
594   fInheritSettings = kTRUE;
595
596   // Close the tabs
597   CloseTabs();
598 }
599
600 //______________________________________________________
601 void AliEveTRDTrackListEditor::HandleTabChangedToIndex(Int_t index)
602 {
603   // Saves the current tab in the current AliEveTRDTrackList.
604
605   fM->SetSelectedTab(index);
606 }
607
608 //______________________________________________________
609 void AliEveTRDTrackListEditor::InheritMacroList()
610 {
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.
615
616   if (fInheritedMacroList == 0)  return;
617
618   // Clear list  
619   fM->fMacroList->Delete();
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)
628   {
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     {
634       Error("AliEveTRDTrackListEditor::InheritMacroList", "Failed to inherit the macro \"%s\"!", key->GetName());
635     }
636   }
637   
638   fInheritedMacroList->Delete();
639   delete fInheritedMacroList;
640   fInheritedMacroList = 0;
641 }
642
643 //______________________________________________________
644 void AliEveTRDTrackListEditor::InheritStyle()
645 {
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.
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     }
665   }
666 }
667
668 //______________________________________________________
669 void AliEveTRDTrackListEditor::RemoveMacros()
670 {
671   // Removes the selected macros from the corresponding list.
672
673   TList iterator;
674   ftlMacroList->GetSelectedEntries(&iterator);
675   fM->RemoveSelectedMacros(&iterator);
676
677
678   iterator.Clear();
679   ftlMacroSelList->GetSelectedEntries(&iterator);
680   fM->RemoveSelectedMacros(&iterator);
681
682   // Selected macros are deleted from the list -> No selected entries left
683   fM->fMacroListSelected = 0;
684   UpdateMacroList();
685 }
686
687 //______________________________________________________
688 void 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     {
713       Error("AliEveTRDTrackListEditor::SaveMacroList", "Failed to inherit the macro \"%s\"!", key->GetName());
714     }
715   }
716 }
717
718 //______________________________________________________
719 void AliEveTRDTrackListEditor::SetDrawingToHistoCanvasTab(Int_t canvas)
720 {
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
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.
726
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();
731 }
732
733 //______________________________________________________
734 void AliEveTRDTrackListEditor::SetModel(TObject* obj)
735 {  
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
739   fM = dynamic_cast<AliEveTRDTrackList*>(obj);
740
741   if (fM == 0) 
742   {
743     Error("SetModel", "Parameter is zero pointer");
744     return;
745   }
746
747   // Provide a pointer to this editor
748   fM->fEditor = this;
749
750   // If macro list + track style shall be inherited from previously loaded track list, do so
751   if (fInheritSettings)
752   {
753     InheritMacroList();
754     InheritStyle();
755
756     fInheritSettings = kFALSE;
757   }
758
759   // Select the correct styles
760   Int_t b = 0;
761   UChar_t style = fM->GetSelectedTrackStyle();
762   if (TESTBIT(style, AliEveTRDTrack::kSource)) b = 2;
763   else 
764   {
765     if (TESTBIT(style, AliEveTRDTrack::kPID)) b = 1;
766     else b = 0;
767   } 
768   fbgStyleColor->SetButton(b, kTRUE);
769
770
771   if (TESTBIT(style, AliEveTRDTrack::kTrackCosmics)) b = 2;
772   else
773   {
774     if (TESTBIT(style, AliEveTRDTrack::kTrackModel)) b = 1;
775     else b = 0;
776   }
777   fbgStyleTrack->SetButton(b, kTRUE);
778   
779   UpdateMacroList();
780   UpdateHistoList(); 
781
782   // View correct tab
783   GetGedEditor()->GetTab()->SetTab(fM->GetSelectedTab()); 
784 }
785
786 //______________________________________________________
787 void AliEveTRDTrackListEditor::SetTrackColor(Int_t ind)
788 {
789   // Sets the color model for the tracks, updates the tracks with this model and
790   // redraws the scene.
791
792   switch(ind)
793   { 
794     case AliTRDpidUtil::kLQ:
795       fM->UpdateTrackStyle(AliEveTRDTrack::kPID, AliTRDpidUtil::kLQ);
796       break;
797     case AliTRDpidUtil::kNN:
798       fM->UpdateTrackStyle(AliEveTRDTrack::kPID, AliTRDpidUtil::kNN);
799       break;
800     default:
801       fM->UpdateTrackStyle(AliEveTRDTrack::kSource);
802       break;
803   }
804
805   gEve->Redraw3D();
806 }
807
808 //______________________________________________________
809 void AliEveTRDTrackListEditor::SetTrackModel(Int_t ind)
810 {
811   // Sets the track model for the tracks, updates the tracks with this model and
812   // redraws the scene.
813
814   switch(ind)
815   { 
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;
825   }
826
827   gEve->Redraw3D();
828 }
829
830 //______________________________________________________
831 void AliEveTRDTrackListEditor::UpdateDataFromMacroListSelection()
832 {
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
837   for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
838   {
839     fM->SetHistoDataSelection(i, fCheckButtons[i]->IsOn());
840   }
841 }
842
843 //______________________________________________________
844 void AliEveTRDTrackListEditor::UpdateHistoCanvasTab(Int_t canvas)
845 {
846   // Updates the histogram and the corresponding tab (including titles).
847
848   // Update name of the tab (tab has been set to current tab!)
849   //fHistoCanvasName->SetString(Form("%s_%d", fM->GetName(), canvas));
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   
853   //gEve->GetBrowser()->GetTab(canvas)->GetCurrentTab()->SetText(new TGString(fHistoCanvasName));
854
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));
859     return;
860   }
861   if(!tab->SetTab(canvas)){
862     AliError(Form("Failed updating tab[%d]", canvas));
863     return;
864   }
865   fHistoCanvas->Modified();
866   fHistoCanvas->Update();
867 }
868
869 //______________________________________________________
870 void AliEveTRDTrackListEditor::UpdateHistoList()
871 {
872   // Reloads (updates) the buttons in the "Histograms"-tab via
873   // the current AliEveTRDTrackList (data).
874
875   fHistoSubFrame->TGCompositeFrame::Cleanup();
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();
889     fCheckButtons[i]->SetOn(fM->HistoDataIsSelected(i));
890     fCheckButtons[i]->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "UpdateDataFromMacroListSelection()");
891             
892     iter = (TObjString*)fM->fDataFromMacroList->After(iter);
893   }  
894 }
895
896 //______________________________________________________
897 void AliEveTRDTrackListEditor::UpdateMacroList()
898 {
899   // Reloads (updates) the macro list (selection AND process macros) via
900   // the current AliEveTRDTrackList (data).
901
902   ftlMacroList->RemoveAll();
903   ftlMacroSelList->RemoveAll();
904    
905   TMapIter* iter = (TMapIter*)fM->fMacroList->MakeIterator();
906   TObject* key = 0;
907   TMacroData* macro = 0;
908
909   Int_t ind = 0;
910   while ((key = iter->Next()) != 0)
911   {
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()", 
932               "Macro \"%s/%s.C\" is neither a selection macro nor a process macro!",
933                    macro->GetPath(), macro->GetName());
934       }
935     }
936     else
937     {
938       Error("AliEveTRDTrackListEditor::UpdateMacroList()", 
939               "Macro list is corrupted: Macro \"%s\" not found!", key->GetName());
940     }
941   }
942
943   ftlMacroList->SortByName(); 
944   ftlMacroSelList->SortByName(); 
945 }
946
947 //______________________________________________________
948 void AliEveTRDTrackListEditor::UpdateMacroListSelection(Int_t ind)
949 {
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!
954
955   // Toggle selected item
956   fM->SetMacroListSelection(ind, !fM->MacroListIsSelected(ind));
957 }
958
959
960 //______________________________________________________
961 //______________________________________________________
962 //______________________________________________________
963
964
965 /////////////////////////////////////////////////
966 ClassImp(AliEveTRDMacroWizard)
967 /////////////////////////////////////////////////
968
969 //______________________________________________________
970 AliEveTRDMacroWizard::AliEveTRDMacroWizard(const TGWindow* p)
971   :TGMainFrame(p ? p : gClient->GetRoot(), 10, 10, kMainFrame | kVerticalFrame)
972   ,fText(0x0)
973   ,fCombo(0x0)
974   ,fTextEdit(0x0)
975   ,fbCreate(0x0)
976   ,fbCancel(0x0)
977 {
978   // Creates the macro wizard.
979
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
1028   // horizontal frame
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)); 
1036
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));
1050   AddFrame(fFrameAction, new TGLayoutHints(kLHintsRight | kLHintsTop | kLHintsExpandX,2,2,2,2));
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
1057   SetWindowName("TRD Macro Wizard");
1058   SetMWMHints(kMWMDecorAll,
1059               kMWMFuncAll,
1060               kMWMInputModeless);
1061   MapSubwindows();
1062
1063   Resize(GetDefaultSize());
1064   MapWindow();
1065
1066   // Do the linking
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()");
1070
1071   // Standard choice
1072   fCombo->Select(1, kFALSE);
1073 }  
1074
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"
1083 "#endif\n";
1084
1085 const Char_t *fMacroTemplate[7] = {
1086 ""
1087 ,"  if (!track) return kFALSE;\n"
1088
1089 ,"  n = 0;\n"
1090 "  r = 0x0;\n"
1091 "  if (!track) return;\n"
1092
1093 ,"  if (!track) return 0x0;\n"
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" 
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"
1109 "  r = 0x0;\n"
1110 "  if (!track) return;\n"
1111 "  if (!track2) return;\n"
1112
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"
1117 "  Int_t n = 1;\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"
1125 };
1126 //______________________________________________________
1127 void AliEveTRDMacroWizard::Create(Int_t type)
1128 {
1129   // Creates the macro with the selected type (combo box).
1130
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);
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);
1147     return;
1148   }
1149
1150   FILE* fp = 0x0;
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);
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
1165   switch(type){
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:
1185     AliInfo(Form("Unknown type[%d]", type));
1186     new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", 
1187                  Form("Unknown type[%d]", type), kMBIconExclamation, kMBOk);
1188     fclose(fp);
1189     gSystem->Exec(Form("rm -f %s.C", name));
1190     //fCombo->Select(-1);
1191     return;
1192   }
1193   
1194   fprintf(fp, "{\n%s\n", fMacroTemplate[type]);
1195   fprintf(fp, "// add your own code here\n\n\n}\n");
1196   fclose(fp);
1197
1198   Emit("Create(Int_t)", type);
1199   Create((Char_t*)name);
1200   CloseWindow();
1201 }
1202
1203 //______________________________________________________
1204 void AliEveTRDMacroWizard::Create(Char_t *name)
1205 {
1206   // Emits the creation signal.
1207
1208   Emit("Create(Char_t*)", Form("%s.C", name));
1209 }
1210
1211 //______________________________________________________
1212 void AliEveTRDMacroWizard::HandleCreate()
1213 {
1214   // Handles the signal, when the creation button is pressed.
1215
1216   Create(fCombo->GetSelected());
1217 }