]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveTRDTrackListEditor.cxx
GPU compilateion update
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveTRDTrackListEditor.cxx
1 // Author: Benjamin Hess   25/09/2008
2
3 /*************************************************************************
4  * Copyright (C) 2008, 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 <EveDet/AliEveTRDData.h>
24 #include <EveDet/AliEveTRDTrackList.h>
25 #include "AliEveTRDTrackListEditor.h"
26
27 #include <EveBase/AliEveEventManager.h>
28 #include <AliTRDReconstructor.h>
29 #include <AliTRDtrackV1.h>
30 #include <TGButton.h>
31 #include <TCanvas.h>     
32 #include <TEveBrowser.h>
33 #include <TEveGedEditor.h> 
34 #include <TEveMacro.h>
35 #include <TEveManager.h>
36 #include <TFile.h>
37 #include <TG3DLine.h>
38 #include <TGButtonGroup.h>
39 #include <TGFileDialog.h>
40 #include <TGLabel.h>
41 #include <TGListBox.h>
42 #include <TGMsgBox.h>
43 #include <TGTab.h>
44 #include <TMap.h>
45 #include <TObjString.h>
46 #include <TROOT.h>
47 #include <TSystem.h>
48 #include <TGTextEntry.h>
49 #include <TGTextEdit.h>
50 #include <TGComboBox.h>
51 #include <TGTextView.h>
52 #include <TH1.h>
53 #include <TTreeStream.h>
54
55
56 ClassImp(AliEveTRDTrackListEditor)
57
58 ///////////////////////////////////////////////////////////
59 /////////////   AliEveTRDTrackListEditor //////////////////
60 ///////////////////////////////////////////////////////////
61 AliEveTRDTrackListEditor::AliEveTRDTrackListEditor(const TGWindow* p, Int_t width, Int_t height,
62                                                    UInt_t options, Pixel_t back) :
63   TGedFrame(p, width, height, options, back),
64   fM(0),
65   fHistoCanvas(0),
66   fHistoCanvasName(0),
67   fInheritedMacroList(0),
68   fInheritSettings(kFALSE),
69   fStyleFrame(0),
70   fMainFrame(0),
71   fHistoFrame(0),
72   fHistoSubFrame(0),
73   fBrowseFrame(0),
74   fbgStyleColor(0),
75   fbgStyleTrack(0),
76   frbColor(new TGRadioButton*[3]),
77   frbTrack(new TGRadioButton*[3]),
78   fbBrowse(0),
79   fbNew(0),
80   fbApplyMacros(0),
81   fbRemoveMacros(0),
82   fbDrawHisto(0),
83   fteField(0),
84   ftlMacroList(0),
85   ftlMacroSelList(0),
86   fFileInfo(0),
87   fFileTypes(0),
88   fLabel1(0), fLabel2(0), fLabel3(0), fLabel4(0),
89   fLine1(0), fLine2(0), fLine3(0), fLine4(0), fLine5(0),
90   fCheckButtons(0)
91 {
92   // Creates the AliEveTRDTrackListEditor.
93
94   // Style stuff
95   fLine5 = new TGHorizontal3DLine(this, 194, 8);
96   AddFrame(fLine5, new TGLayoutHints(kLHintsLeft  | kLHintsTop, 2, 2, 8, 8));
97   fStyleFrame = new TGHorizontalFrame(this);
98   AddFrame(fStyleFrame);
99
100   // Style - Track model
101   fbgStyleTrack = new TGButtonGroup(fStyleFrame, "Track model");
102   fbgStyleTrack->SetMapSubwindows(kTRUE);
103   fbgStyleTrack->Resize(194, 200);
104   fStyleFrame->AddFrame(fbgStyleTrack);
105
106   frbTrack[0] = new TGRadioButton(fbgStyleTrack, "Rieman", 0);
107   frbTrack[0]->SetToolTipText("Set the track model to \"Rieman\" (i.e. the used fit method)");
108   fbgStyleTrack->AddFrame(frbTrack[0]);
109   frbTrack[1] = new TGRadioButton(fbgStyleTrack, "Kalman", 1);
110   frbTrack[1]->SetToolTipText("Set the track model to \"Kalman\" (i.e. the used fit method)");
111   fbgStyleTrack->AddFrame(frbTrack[1]);
112   frbTrack[2] = new TGRadioButton(fbgStyleTrack, "Line", 2);
113   frbTrack[2]->SetToolTipText("Set the track model to \"Line\" (i.e. the used fit method)");
114   fbgStyleTrack->AddFrame(frbTrack[2]);  
115
116   // Style - Color model
117   fbgStyleColor = new TGButtonGroup(fStyleFrame, "Color model");
118   fbgStyleColor->SetMapSubwindows(kTRUE);
119   fbgStyleColor->Resize(194, 200);
120   fStyleFrame->AddFrame(fbgStyleColor);
121
122   frbColor[0] = new TGRadioButton(fbgStyleColor, "PID LQ", 0);
123   frbColor[0]->SetToolTipText("Set color model to \"PID LQ\" -> 2 dimensional likelihood particle identification");
124   fbgStyleColor->AddFrame(frbColor[0]);
125   frbColor[1] = new TGRadioButton(fbgStyleColor, "PID NN", 1);
126   frbColor[1]->SetToolTipText("Set color model to \"PID NN\" -> Neural network particle identification");
127   fbgStyleColor->AddFrame(frbColor[1]);
128   frbColor[2] = new TGRadioButton(fbgStyleColor, "ESD Source", 2);
129   frbColor[2]->SetToolTipText("Set color model to \"ESD Source\" -> By source (TPC track prolongation or TRD stand alone)");
130   fbgStyleColor->AddFrame(frbColor[2]);  
131   
132
133   // Functionality for adding macros  
134   fMainFrame = CreateEditorTabSubFrame("Process");
135    
136   fLabel1 = new TGLabel(fMainFrame,"Add macro(s):");
137   fMainFrame->AddFrame(fLabel1);
138   fBrowseFrame = new TGHorizontalFrame(fMainFrame);
139
140   fteField = new TGTextEntry(fBrowseFrame);
141   fteField->SetToolTipText("Enter the pathname of the macro you want to add here and press \"Enter\"");
142   fteField->Connect("ReturnPressed()","AliEveTRDTrackListEditor", this, "HandleMacroPathSet()"); 
143   fBrowseFrame->AddFrame(fteField);
144   
145   fbBrowse = new TGTextButton(fBrowseFrame, "Browse");
146   fbBrowse->SetToolTipText("Browse the macro you want to add");
147   fbBrowse->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "BrowseMacros()");
148   fBrowseFrame->AddFrame(fbBrowse);
149   
150   fbNew = new TGTextButton(fBrowseFrame, "New");
151   fbNew->SetToolTipText("Start macro creation wizzard");
152   fbNew->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "NewMacros()");
153   fBrowseFrame->AddFrame(fbNew);
154   fMainFrame->AddFrame(fBrowseFrame);
155
156   fLine1 = new TGHorizontal3DLine(fMainFrame, 194, 8);
157   fMainFrame->AddFrame(fLine1, new TGLayoutHints(kLHintsLeft  | kLHintsTop, 2, 2, 8, 2));
158   fLabel2 = new TGLabel(fMainFrame,"Selection macros:");
159   fMainFrame->AddFrame(fLabel2);
160
161   ftlMacroSelList = new TGListBox(fMainFrame);
162   ftlMacroSelList->Resize(194, 94);
163   ftlMacroSelList->SetMultipleSelections(kTRUE);
164   fMainFrame->AddFrame(ftlMacroSelList);
165
166   fLine2 = new TGHorizontal3DLine(fMainFrame, 194, 8);
167   fMainFrame->AddFrame(fLine2, new TGLayoutHints(kLHintsLeft  | kLHintsTop, 2, 2, 8, 2));
168   fLabel3 = new TGLabel(fMainFrame,"Process plugins:");
169   fMainFrame->AddFrame(fLabel3);
170
171   ftlMacroList = new TGListBox(fMainFrame);
172   ftlMacroList->Resize(194, 94);
173   ftlMacroList->SetMultipleSelections(kTRUE);
174   fMainFrame->AddFrame(ftlMacroList);
175
176   fLine3 = new TGHorizontal3DLine(fMainFrame, 194, 8);
177   fMainFrame->AddFrame(fLine3, new TGLayoutHints(kLHintsLeft  | kLHintsTop, 2, 2, 8, 2));  
178
179   fbApplyMacros = new TGTextButton(fMainFrame, "Apply plugin(s)");
180   fbApplyMacros->SetToolTipText("Apply all selected macros/class functins to the list of tracks -> A data file will be generated");
181   fbApplyMacros->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "ApplyMacros()");
182   fbApplyMacros->SetRightMargin(12);
183   fMainFrame->AddFrame(fbApplyMacros);
184
185   fbRemoveMacros = new TGTextButton(fMainFrame, "Remove plugin(s)");
186   fbRemoveMacros->SetToolTipText("Remove the selected macros/class functions from the list(s)");
187   fbRemoveMacros->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "RemoveMacros()");
188   fMainFrame->AddFrame(fbRemoveMacros);
189
190   // Stuff for displaying histograms
191   fHistoFrame = CreateEditorTabSubFrame("Results");  
192   fHistoFrame->SetMapSubwindows(kTRUE);
193   fLabel4 = new TGLabel(fHistoFrame,"Data from plugins:");
194   fHistoFrame->AddFrame(fLabel4);
195
196   fHistoSubFrame = new TGVerticalFrame(fHistoFrame);
197   fHistoSubFrame->SetMapSubwindows(kTRUE);
198   fHistoSubFrame->Resize(194, 200);
199   fHistoFrame->AddFrame(fHistoSubFrame);
200
201   fLine4 = new TGHorizontal3DLine(fHistoFrame, 194, 8);
202   fHistoFrame->AddFrame(fLine4, new TGLayoutHints(kLHintsLeft  | kLHintsTop, 2, 2, 8, 2));  
203
204   fbDrawHisto = new TGTextButton(fHistoFrame, "Draw projections");
205   fbDrawHisto->SetToolTipText("Uses the data file created by the last \"Apply selected macro(s)\".\nClick here to display the data histograms of the selected macros.\nSelect multiple macros to create multi-dimensional plots.\nHisto macros cannot be used for multi-dimensional plots!");
206   fbDrawHisto->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "DrawHistos()");
207   fHistoFrame->AddFrame(fbDrawHisto);
208
209   // Set up file dialog
210   fFileInfo = new TGFileInfo();
211   fFileInfo->SetMultipleSelection(kTRUE);
212
213   fFileTypes = new Char_t*[6];
214   fFileTypes[0] = (Char_t*)"All files"; fFileTypes[1] = (Char_t*)"*";
215   fFileTypes[2] = (Char_t*)"ROOT macros"; fFileTypes[3] = (Char_t*)"*.C";
216   fFileTypes[4] = 0; fFileTypes[5] = 0;
217   fFileInfo->fFileTypes = (const Char_t**)fFileTypes;
218   fFileInfo->fFileTypeIdx = 2;
219   fFileInfo->fMultipleSelection = kTRUE;
220
221   fHistoCanvasName = new TGString("");
222
223   // Handle style changed signals:
224   fbgStyleTrack->Connect("Clicked(Int_t)", "AliEveTRDTrackListEditor", this, "SetTrackModel(Int_t)");
225   fbgStyleColor->Connect("Clicked(Int_t)", "AliEveTRDTrackListEditor", this, "SetTrackColor(Int_t)");
226
227   // Handle the signal "Selected(Int_t ind)"
228   ftlMacroList->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor", this, "UpdateMacroListSelection(Int_t)");
229   ftlMacroSelList->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor", this, "UpdateMacroListSelection(Int_t)");
230
231   // Handle the signal "NewEventLoaded"
232   AliEveEventManager::GetMaster()->Connect("NewEventLoaded()", "AliEveTRDTrackListEditor", this, "HandleNewEventLoaded()");
233
234   // Handle the signal "Selected" (another tab has been selected)
235   GetGedEditor()->GetTab()->Connect("Selected(Int_t)", "AliEveTRDTrackListEditor", this, "HandleTabChangedToIndex(Int_t)");
236 }
237
238 //______________________________________________________
239 AliEveTRDTrackListEditor::~AliEveTRDTrackListEditor()
240 {
241   // Destructor: Closes all tabs created by this object and
242   // frees the corresponding memory.
243
244   if (fFileTypes != 0)
245   {
246     delete [] fFileTypes;
247     fFileTypes = 0;
248   }
249
250   if (fFileInfo != 0)
251   {
252     delete fFileInfo; 
253     fFileInfo = 0;
254   }
255   // Close and delete all tabs that have been created by this class
256   CloseTabs();
257
258   if (fHistoCanvasName != 0)
259   {
260     delete fHistoCanvasName;
261     fHistoCanvasName = 0;
262   }
263   if (fInheritedMacroList != 0)
264   {
265     fInheritedMacroList->Delete();
266     delete fInheritedMacroList;
267     fInheritedMacroList = 0;
268   }
269 }
270
271 //______________________________________________________
272 void AliEveTRDTrackListEditor::AddMacro(const Char_t* name, const Char_t* path)
273 {
274   // Adds the macro path/name to the macro list. A warning is provided, if there is
275   // something wrong, e.g. if the macro does not have the correct signature.
276   Int_t result = fM->AddMacro(path, name);
277
278   switch (result)
279   {
280   case SUCCESS:
281     UpdateMacroList();
282     break;
283   case WARNING:
284     new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Warning", "Macro is already in list (won't be added again)!",
285                  kMBIconExclamation, kMBOk);
286     break;
287   case ERROR:
288     new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", "Fail to load the macro (check messages in the terminal)!",
289                  kMBIconExclamation, kMBOk);
290     break;
291   case SIGNATURE_ERROR:
292     new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", 
293                  "Macro has not the signature of...\n...a single track selection macro: Bool_t YourMacro(const AliTRDtrackV1*)\n...a correlated tracks selection macro: Bool_t YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*)\n...a single track analyse macro: void YourMacro(const AliTRDtrackV1*, Double_t*&, Int_t&)\n...a correlated tracks analyse macro: void YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*, Double_t*&, Int_t&)\n...a single track histo macro: TH1* YourMacro(const AliTRDtrackV1*)\n...a correlated tracks histo macro: TH1* YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*)", 
294                  kMBIconExclamation, kMBOk);
295     break;               
296   case NOT_EXIST_ERROR:
297     new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", 
298                  "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
299     break;
300   default:
301     new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", 
302                  Form("AliEveTRDTrackList::AddMacro exited with unknown return value: %d", result),
303                  kMBIconExclamation, kMBOk);
304     break;
305   }
306 }
307
308 //______________________________________________________
309 void AliEveTRDTrackListEditor::ApplyMacros()
310 {
311   // Applies the selected macros and updates the view.
312
313   Bool_t success = kFALSE;
314
315   // First apply the single track selection macros
316   TList* selIterator = new TList();
317   ftlMacroSelList->GetSelectedEntries(selIterator);
318   fM->ApplySTSelectionMacros(selIterator);
319   
320   // Update view
321   gEve->Redraw3D();
322
323   // Now apply the process macros
324   TList* procIterator = new TList();
325   ftlMacroList->GetSelectedEntries(procIterator);
326   success = fM->ApplyProcessMacros(selIterator, procIterator);
327
328   // Update histogram tab (data has to be reloaded)
329   SetModel(fM);
330   Update();
331
332   // AlieveTRDTrackList::ApplyProcessMacros() automatically selects a macro -> Draw the histogram for it,
333   // if a process macro has been applied
334   if (success && procIterator->GetEntries() > 0) 
335   {
336     // Set focus on "Histograms" tab
337     GetGedEditor()->GetTab()->SetTab("Results");
338
339     DrawHistos();
340   }
341
342   if (selIterator != 0) delete selIterator;
343   selIterator = 0;  
344   if (procIterator != 0)  delete procIterator;  
345   procIterator = 0;  
346   
347   if (!success)
348   {
349     new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", 
350                  "AliEveTRDTrackList::ApplyProcessMacros experienced an error (cf. CINT-output)!", 
351                  kMBIconExclamation, kMBOk);  
352   }
353 }
354
355 //______________________________________________________
356 void AliEveTRDTrackListEditor::NewMacros()
357 {
358   // Start the macro creation wizzard.
359   // thanks to Jacek Otwinowski<J.Otwinowski@GSI.DE> for this suggestion
360
361   AliEveTRDMacroWizzard *wizz = new AliEveTRDMacroWizzard();
362   wizz->Connect("Create(Char_t*)", "AliEveTRDTrackListEditor", this, "AddMacro(Char_t*)");
363 }
364
365
366 //______________________________________________________
367 void AliEveTRDTrackListEditor::BrowseMacros()
368 {
369   // Creates a file-dialog. The selected files will be added to the macro list
370   // via AddMacro(...).
371
372   new TGFileDialog(gClient->GetRoot(), GetMainFrame(), kFDOpen, fFileInfo);
373   
374   if (fFileInfo->fIniDir != 0 && fFileInfo->fFileNamesList != 0)
375   {       
376     // Extract filenames
377     TObject* iter = fFileInfo->fFileNamesList->First();
378  
379     Char_t* name = 0;
380
381     while (iter != 0)
382     {
383       // NOTE: fileInfo->fFileNamesList will be changed by that, too!
384       name = (Char_t*)strrchr(iter->GetName(), '/');
385       // Delete '"' at the end
386       name[strlen(name)] = '\0';
387               
388       AddMacro(name + 1, fFileInfo->fIniDir); 
389       iter = (TObjString*)fFileInfo->fFileNamesList->After(iter);
390     }
391   }
392
393   // -> The following problem has been fixed (trunk -> Changes according to 03 September 2008):
394   // Some error occurs, when one ends the filedialog with "cancel": fileInfo->fFileNamesList is set to 0x0, but
395   // in the next launch no new memory is allocated. So do this manually.
396   //if (fileInfo->fFileNamesList == 0)  fileInfo->fFileNamesList = new TList();
397 }
398
399 //______________________________________________________
400 void AliEveTRDTrackListEditor::CloseTabs()
401 {
402   // Closes + deletes the tabs created by this object
403
404   if (fHistoCanvas != 0)
405   {
406     // Close the created tab, if it exists
407     if (fHistoCanvasName != 0)
408     {
409       if (gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString()))
410       {
411         // Now the created tab is the current one and can be deleted
412         gEve->GetBrowser()->GetTab(1)->RemoveTab();
413       }
414     }
415     // With the tab removal, the canvas will be deleted automatically!
416     fHistoCanvas = 0;
417   }
418 }
419
420 //______________________________________________________
421 void AliEveTRDTrackListEditor::DrawHistos()
422 {
423   // Accesses the temporary data file created by the last call of ApplyMacros() and draws
424   // histograms according to the selection in the "Histograms"-tab.
425  
426   Int_t nHistograms = GetNSelectedHistograms();
427   if (nHistograms <= 0)
428   {
429     new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", 
430                  "No data selected. Please select the data you want to plot!", kMBIconExclamation, kMBOk);
431     return;
432   }
433   if (nHistograms > 3)
434   {
435     new TGMsgBox(gClient->GetRoot(), GetMainFrame(), 
436                  "Error", "Only histograms with up to 3 dimensions supported. Please select 1,2 or 3 data macros!",
437                  kMBIconExclamation, kMBOk);
438     return;
439   }
440
441   // Check, if a histo macro shall be drawn
442   Int_t indexOfHistoMacro = -1;
443   Int_t selectedChecked = 0;
444   for (Int_t j = 0; j < fM->fDataFromMacroList->GetEntries(); j++)
445   {
446     if (fCheckButtons[j]->TGButton::GetState() == kButtonDown)
447     {
448       selectedChecked++;
449
450       // Histo macro? -> To check this, look for the substring "(histo macro)"
451       if (strstr(fM->fDataFromMacroList->At(j)->GetName(), "(histo macro)") != 0)
452       {
453         // Is also another macro selected?
454         if (nHistograms > 1)
455         {
456           // Histo macros cannot(!) be correlated!
457           new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms", 
458                        "Histo macros (return value \"TH1*\") cannot be combined with other macros", 
459                        kMBIconExclamation, kMBOk);
460           return;        
461         }
462
463         // Mark this histo macro for drawing
464         indexOfHistoMacro = j;
465
466         // Have all selected macros been checked? -> If yes, we are done with this
467         if (selectedChecked == nHistograms)  break;
468       }
469     }
470   }
471
472   TFile* file = new TFile(Form("/tmp/TRD.TrackListMacroData_%s.root", gSystem->Getenv("USER")), "READ");
473   if (!file)  
474   {
475     Error("Draw histograms", Form("Cannot open file \"/tmp/TRD.TrackListMacroData_%s.root\"", 
476                                   gSystem->Getenv("USER")));
477     new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms", 
478                  Form("Cannot open file \"/tmp/TRD.TrackListMacroData_%s.root\"", gSystem->Getenv("USER")),
479                  kMBIconExclamation, kMBOk);
480     return;
481   }
482   
483   TTree* t = 0;
484   TTree* tFriend1 = 0;
485   TTree* tFriend2 = 0;
486
487   Int_t indexOfMacro1 = 0;
488   Int_t indexOfMacro2 = 0;
489   Int_t indexOfMacro3 = 0;
490
491   // Variable for the loop below -> Will be set to aborting value, if a histo macro is drawn
492   Int_t i = 0;
493   
494   // Draw histo macro?
495   if (indexOfHistoMacro >= 0)
496   {
497     if ((t = (TTree*)file->Get(Form("TrackData%d", indexOfHistoMacro))))
498     {
499       SetDrawingToHistoCanvasTab();
500  
501       TH1* myHist = 0;
502       t->SetBranchAddress(Form("Macro%d", indexOfHistoMacro), &myHist);
503       t->GetEntry(0);
504       if (myHist != 0)  myHist->Draw();
505       else
506       {
507         Error("Draw histograms", Form("No histogram for histo macro \"%s\" found!", 
508                                       fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()));
509         new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms", 
510                      Form("No histogram for histo macro \"%s\" found!", 
511                           fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()), kMBIconExclamation, kMBOk);
512                
513       }
514
515       UpdateHistoCanvasTab();    
516     }
517     else
518     {
519       Error("Draw histograms", Form("No data for histo macro \"%s\" found!\nMaybe no tracks have been selected.", 
520                                     fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()));
521       new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms", 
522                    Form("No data for histo macro \"%s\" found!\nMaybe no tracks have been selected.", 
523                         fM->fDataFromMacroList->At(indexOfHistoMacro)->GetName()), kMBIconExclamation, kMBOk);
524     }
525
526     // Skip the loop below
527     i = fM->fDataFromMacroList->GetEntries();
528   }
529
530   // Load the trees in succession and remember the entries -> Plot the analyse macros
531   for ( ; i < fM->fDataFromMacroList->GetEntries(); i++)
532   {
533     if (fCheckButtons[i]->TGButton::GetState() == kButtonDown)
534     {
535       if (t == 0)
536       {
537         indexOfMacro1 = i;
538         if (!(t = (TTree*)file->Get(Form("TrackData%d", i))))
539         { 
540           Error("Draw histograms", Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.", 
541                                         fM->fDataFromMacroList->At(i)->GetName()));
542           new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms", 
543                        Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.", 
544                             fM->fDataFromMacroList->At(i)->GetName()), kMBIconExclamation, kMBOk);
545           break;   
546         }
547
548         // 1d histogram
549         if (nHistograms == 1) 
550         {
551           SetDrawingToHistoCanvasTab();
552       
553           t->Draw(Form("Macro%d", indexOfMacro1), "1");
554           ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s;%s",
555             fM->fDataFromMacroList->At(indexOfMacro1)->GetName(),
556             fM->fDataFromMacroList->At(indexOfMacro1)->GetName()));
557           UpdateHistoCanvasTab();        
558
559           break;     
560         }
561       }
562       else if (tFriend1 == 0)
563       {
564         indexOfMacro2 = i;
565         if (!(tFriend1 = (TTree*)file->Get(Form("TrackData%d", i))))
566         { 
567           Error("Draw histograms", Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.", 
568                                         fM->fDataFromMacroList->At(i)->GetName()));
569           new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms", 
570                        Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.", 
571                             fM->fDataFromMacroList->At(i)->GetName()),
572                             kMBIconExclamation, kMBOk);
573           break;   
574         }
575         
576         // 2d histogram
577         if (nHistograms == 2) 
578         {
579           SetDrawingToHistoCanvasTab();
580
581           t->AddFriend(tFriend1);
582           t->Draw(Form("Macro%d:Macro%d", indexOfMacro1, indexOfMacro2), "1");
583           ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s - %s;%s;%s",
584             fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
585             fM->fDataFromMacroList->At(indexOfMacro1)->GetName(),
586             fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
587             fM->fDataFromMacroList->At(indexOfMacro1)->GetName()));
588
589           UpdateHistoCanvasTab();
590  
591           break;     
592         }
593       }    
594       // 3d histogram
595       else
596       {
597         indexOfMacro3 = i;
598         if (!(tFriend2 = (TTree*)file->Get(Form("TrackData%d", i))))
599         { 
600           Error("Draw histograms", Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.", 
601                                         fM->fDataFromMacroList->At(i)->GetName()));
602           new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error - Draw histograms", 
603                        Form("No data for macro \"%s\" found!\nMaybe no tracks have been selected.", 
604                             fM->fDataFromMacroList->At(i)->GetName()), kMBIconExclamation, kMBOk);
605           break;   
606         }
607
608         SetDrawingToHistoCanvasTab();
609
610         t->AddFriend(tFriend1);
611         t->AddFriend(tFriend2);
612         t->Draw(Form("Macro%d:Macro%d:Macro%d", indexOfMacro1, indexOfMacro2, indexOfMacro3), "1");
613         ((TH1*)gPad->GetPrimitive("htemp"))->SetTitle(Form("%s - %s - %s;%s;%s;%s",
614             fM->fDataFromMacroList->At(indexOfMacro3)->GetName(),
615             fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
616             fM->fDataFromMacroList->At(indexOfMacro1)->GetName(),
617             fM->fDataFromMacroList->At(indexOfMacro3)->GetName(),
618             fM->fDataFromMacroList->At(indexOfMacro2)->GetName(),
619             fM->fDataFromMacroList->At(indexOfMacro1)->GetName()));
620         
621         UpdateHistoCanvasTab();
622  
623         break;     
624       }
625     }
626   }
627
628   if (t != 0) delete t;
629   t = 0;
630   if (tFriend1 != 0)  delete tFriend1;
631   tFriend1 = 0;
632   if (tFriend2 != 0)  delete tFriend2;
633   tFriend2 = 0;
634
635   file->Close("R");
636   delete file;
637   file = 0;
638 }
639
640 //______________________________________________________
641 Int_t AliEveTRDTrackListEditor::GetNSelectedHistograms() const
642 {
643   // Returns the number of selected macros (or rather: of their selected data) in the "Histograms"-tab
644
645   Int_t count = 0;
646   
647   for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
648   {
649     if (fCheckButtons[i]->TGButton::GetState() == kButtonDown)  count++;
650   }
651
652   return count;
653 }
654
655 //______________________________________________________
656 void AliEveTRDTrackListEditor::HandleMacroPathSet()
657 {
658   // Takes the input of the text field (adding a macro), checks if the macro can be
659   // accessed (and that it exists) and adds the macro to the macro list via AddMacro(...).
660   // You can use environment variables in the text field, e.g. "$ALICE_ROOT/Eve/alice-macro/myMacro.C".
661
662   if (strlen(fteField->GetText()) != 0)
663   {  
664     // Expand the pathname
665     Char_t* systemPath = gSystem->ExpandPathName(fteField->GetText());
666     fteField->SetText(systemPath);
667     delete systemPath;
668     systemPath = 0;
669                         
670     // Check if file exists
671     FILE* fp = NULL;
672
673     fp = fopen(fteField->GetText(), "rb");
674     if (fp != NULL)
675     {
676       fclose(fp);
677
678       // Extract filename
679       Char_t* name = (Char_t*)strrchr(fteField->GetText(), '/');
680
681       // Current path
682       if (name == NULL)
683       {
684         name = new Char_t[AliEveTRDTrackList::fkMaxMacroNameLength];
685         memset(name, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroNameLength);
686         sprintf(name, "%s", fteField->GetText());
687
688         // Add path to textfield -> Path is "./" -> Use length for the name + 2
689         Char_t pathname[AliEveTRDTrackList::fkMaxMacroNameLength + 2];
690         memset(pathname, '\0', sizeof(Char_t) * (AliEveTRDTrackList::fkMaxMacroNameLength + 2));
691         sprintf(pathname, "./%s", fteField->GetText());
692         fteField->SetText(pathname);
693
694         AddMacro(name);  
695         if (name != 0)  delete name;
696         name = 0;
697       }
698       // Different path
699       else
700       {
701         // Extract path
702         Char_t* path = new Char_t[AliEveTRDTrackList::fkMaxMacroPathLength];
703         memset(path, '\0', sizeof(Char_t) * AliEveTRDTrackList::fkMaxMacroPathLength);
704         strncpy(path, fteField->GetText(), strlen(fteField->GetText()) - strlen(name));
705         
706         // Ignore the slash "/" in name
707         AddMacro(name + 1, path);  
708   
709         if (path != 0)  delete path;
710         path = 0;
711       }       
712     }
713     else
714     {
715       new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error", 
716                    "File does not exist or you do not have read permission!", kMBIconExclamation, kMBOk);
717     }
718   }
719 }
720
721 //______________________________________________________
722 void AliEveTRDTrackListEditor::HandleNewEventLoaded()
723 {
724   // Closes the tabs created by this object and sets a flag that will
725   // cause the function SetModel() to inherit the macro lists + style
726   // for the next AliEveTRDTrackList from the current one.
727
728   // Inherit the macro list and track style for the next track list!
729   fInheritSettings = kTRUE;
730
731   // Close the tabs
732   CloseTabs();
733 }
734
735 //______________________________________________________
736 void AliEveTRDTrackListEditor::HandleTabChangedToIndex(Int_t index)
737 {
738   // Saves the current tab in the current AliEveTRDTrackList.
739
740   fM->SetSelectedTab(index);
741 }
742
743 //______________________________________________________
744 void AliEveTRDTrackListEditor::InheritMacroList()
745 {
746   // The old macro list is possibly stored in the corresponding interior map. This function will 
747   // use this interior map to move the data from the interior map to the newly loaded AliEveTRDTrackList. 
748   // Then the interior map will be cleaned up. With this, the settings will be inherited from the previously 
749   // loaded AliEveTRDTrackList.
750
751   if (fInheritedMacroList == 0)  return;
752
753   // Clear list  
754   fM->fMacroList->Delete();
755
756   // Store data from interior list in the track list's map
757   TMapIter* iter = (TMapIter*)fInheritedMacroList->MakeIterator();
758   
759   TObject* key = 0;
760   TMacroData* macro = 0;
761   
762   while ((key = iter->Next()) != 0)
763   {
764     macro = (TMacroData*)fInheritedMacroList->GetValue(key);
765     if (macro != 0)  fM->fMacroList->Add(new TObjString(key->GetName()), 
766                                          new TMacroData(macro->GetName(), macro->GetPath(), macro->GetType()));
767     else
768     {
769       Error("AliEveTRDTrackListEditor::InheritMacroList", Form("Failed to inherit the macro \"%s\"!", key));
770     }
771   }
772   
773   fInheritedMacroList->Delete();
774   delete fInheritedMacroList;
775   fInheritedMacroList = 0;
776 }
777
778 //______________________________________________________
779 void AliEveTRDTrackListEditor::InheritStyle()
780 {
781   // The old styles are stored in the corresponding button groups. This function will replace
782   // the style settings of the newly loaded AliEveTRDTrackList with the old styles. With this, the settings
783   // will be inherited from the previously loaded AliEveTRDTrackList.
784
785   for (Int_t ind = 0; ind < 3; ind++)
786   {
787     if (fbgStyleTrack->GetButton(ind)->IsOn())
788     {
789       SetTrackModel(ind);
790       break;
791     }
792   }
793   for (Int_t ind = 0; ind < 3; ind++)
794   {
795     if (fbgStyleColor->GetButton(ind)->IsOn())
796     {
797       SetTrackColor(ind);
798       break;
799     }
800   }
801 }
802
803 //______________________________________________________
804 void AliEveTRDTrackListEditor::RemoveMacros()
805 {
806   // Removes the selected macros from the corresponding list.
807
808   TList* iterator = new TList();
809   
810   ftlMacroList->GetSelectedEntries(iterator);
811   fM->RemoveSelectedMacros(iterator);
812
813   if (iterator != 0)  delete iterator;
814
815   iterator = new TList();
816   ftlMacroSelList->GetSelectedEntries(iterator);
817   fM->RemoveSelectedMacros(iterator);
818
819   // Selected macros are deleted from the list -> No selected entries left
820   fM->fMacroListSelected = 0;
821
822   UpdateMacroList();
823
824   if (iterator != 0)  delete iterator;
825   iterator = 0;
826 }
827
828 //______________________________________________________
829 void AliEveTRDTrackListEditor::SetDrawingToHistoCanvasTab()
830 {
831   // Sets gPad to the tab with the name of the current AliEveTRDTrackList. If this tab does
832   // not exist, it will be created. Otherwise, it is re-used.
833
834   // If the tab with the canvas has been closed, the canvas will be deleted.
835   // So, if there is no tab, set the canvas pointer to zero and recreate it in a new tab.
836   if (fHistoCanvas != 0) 
837   {
838     if (gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString()) == 0)
839     {
840       fHistoCanvas = 0;
841     }
842   }
843
844   if (!fHistoCanvas)
845   {
846     fHistoCanvas = gEve->AddCanvasTab(fM->GetName());     
847   }
848                            
849   gPad = fHistoCanvas;
850 }
851
852 //______________________________________________________
853 void AliEveTRDTrackListEditor::SetModel(TObject* obj)
854 {  
855   // Sets the model object, updates the related data in the GUI and
856   // inherits settings (cf. Inherit*(...)), if the flag fInheritSettings is set to kTRUE.
857
858   fM = dynamic_cast<AliEveTRDTrackList*>(obj);
859
860   if (fM == 0) 
861   {
862     Error("SetModel", "Parameter is zero pointer");
863     return;
864   }
865
866   // Provide a pointer to this editor
867   fM->fEditor = this;
868
869   // If macro list + track style shall be inherited from previously loaded track list, do so
870   if (fInheritSettings)
871   {
872     InheritMacroList();
873     InheritStyle();
874
875     fInheritSettings = kFALSE;
876   }
877
878   // Select the correct styles
879   Int_t b = 0;
880   UChar_t style = fM->GetSelectedTrackStyle();
881   if (TESTBIT(style, AliEveTRDTrack::kSource)) b = 2;
882   else 
883   {
884     if (TESTBIT(style, AliEveTRDTrack::kPID)) b = 1;
885     else b = 0;
886   } 
887   fbgStyleColor->SetButton(b, kTRUE);
888
889
890   if (TESTBIT(style, AliEveTRDTrack::kTrackCosmics)) b = 2;
891   else
892   {
893     if (TESTBIT(style, AliEveTRDTrack::kTrackModel)) b = 1;
894     else b = 0;
895   }
896   fbgStyleTrack->SetButton(b, kTRUE);
897   
898   UpdateMacroList();
899   UpdateHistoList(); 
900
901   // View correct tab
902   GetGedEditor()->GetTab()->SetTab(fM->GetSelectedTab()); 
903 }
904
905 //______________________________________________________
906 void AliEveTRDTrackListEditor::SaveMacroList(TMap* list)
907 {
908   // Saves the provided macro list in an interior list. This list will be used by
909   // InheritMacroList() to restore the data in "list". With this method one is able
910   // to inherit the macro list from track list to track list (i.e. from event to event).
911
912   if (fInheritedMacroList != 0)
913   {
914     fInheritedMacroList->Delete();
915     delete fInheritedMacroList;
916   }
917   fInheritedMacroList = new TMap();
918   fInheritedMacroList->SetOwnerKeyValue(kTRUE, kTRUE);
919
920   TMapIter* iter = (TMapIter*)list->MakeIterator();
921   TObject* key = 0;
922   TMacroData* macro = 0;
923   
924   while ((key = iter->Next()) != 0)
925   {
926     macro = (TMacroData*)fM->fMacroList->GetValue(key);
927     if (macro != 0) fInheritedMacroList->Add(new TObjString(key->GetName()), 
928                                              new TMacroData(macro->GetName(), macro->GetPath(), macro->GetType()));
929     else
930     {
931       Error("AliEveTRDTrackListEditor::SaveMacroList", Form("Failed to inherit the macro \"%s\"!", key));
932     }
933   }
934 }
935
936 //______________________________________________________
937 void AliEveTRDTrackListEditor::SetTrackColor(Int_t ind)
938 {
939   // Sets the color model for the tracks, updates the tracks with this model and
940   // redraws the scene.
941
942   switch(ind)
943   { 
944     case AliTRDpidUtil::kLQ:
945       fM->UpdateTrackStyle(AliEveTRDTrack::kPID, AliTRDpidUtil::kLQ);
946       break;
947     case AliTRDpidUtil::kNN:
948       fM->UpdateTrackStyle(AliEveTRDTrack::kPID, AliTRDpidUtil::kNN);
949       break;
950     default:
951       fM->UpdateTrackStyle(AliEveTRDTrack::kSource);
952       break;
953   }
954
955   gEve->Redraw3D();
956 }
957
958 //______________________________________________________
959 void AliEveTRDTrackListEditor::SetTrackModel(Int_t ind)
960 {
961   // Sets the track model for the tracks, updates the tracks with this model and
962   // redraws the scene.
963
964   switch(ind)
965   { 
966     case AliEveTRDTrack::kRieman:
967       fM->UpdateTrackStyle(AliEveTRDTrack::kTrackModel, AliEveTRDTrack::kRieman);
968       break;
969     case AliEveTRDTrack::kKalman:
970       fM->UpdateTrackStyle(AliEveTRDTrack::kTrackModel, AliEveTRDTrack::kKalman);
971       break;
972     default:
973       fM->UpdateTrackStyle(AliEveTRDTrack::kTrackCosmics);
974       break;
975   }
976
977   gEve->Redraw3D();
978 }
979
980 //______________________________________________________
981 void AliEveTRDTrackListEditor::UpdateDataFromMacroListSelection()
982 {
983   // Saves the current selection in the "Histograms"-tab to the current
984   // AliEveTRDTrackList. This means that the selection is updated and won't
985   // get lost, if another editor is loaded in Eve.
986
987   for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries(); i++)
988   {
989     fM->SetHistoDataSelection(i, fCheckButtons[i]->IsOn());
990   }
991 }
992
993 //______________________________________________________
994 void AliEveTRDTrackListEditor::UpdateHistoCanvasTab()
995 {
996    // Updates the histogram and the corresponding tab (including titles).
997
998   // Update name of the tab (tab has been set to current tab!)
999   fHistoCanvasName->SetString(fM->GetName());  
1000
1001   // Use a copy of fHistoCanvasName!! -> If the user closes a tab manually, the TGString
1002   // will be deleted -> Error might occur, when accessing the pointer   
1003   gEve->GetBrowser()->GetTab(1)->GetCurrentTab()->SetText(new TGString(fHistoCanvasName));
1004
1005   // Switch tabs to force redrawing
1006   gEve->GetBrowser()->GetTab(1)->SetTab(0);
1007   gEve->GetBrowser()->GetTab(1)->SetTab(fHistoCanvasName->GetString());
1008   fHistoCanvas->Update();
1009 }
1010
1011 //______________________________________________________
1012 void AliEveTRDTrackListEditor::UpdateHistoList()
1013 {
1014   // Reloads (updates) the buttons in the "Histograms"-tab via
1015   // the current AliEveTRDTrackList (data).
1016
1017   fHistoSubFrame->TGCompositeFrame::Cleanup();
1018   
1019   // Set buttons for histograms
1020   if (fCheckButtons != 0) delete fCheckButtons;
1021   fCheckButtons = new TGCheckButton*[fM->fDataFromMacroList->GetEntries()];
1022   
1023   TObjString* iter = (TObjString*)fM->fDataFromMacroList->First();
1024   for (Int_t i = 0; i < fM->fDataFromMacroList->GetEntries() && iter != 0; i++)
1025   {
1026     fCheckButtons[i] = new TGCheckButton(fHistoSubFrame, iter->GetName());
1027     fHistoSubFrame->AddFrame(fCheckButtons[i]);
1028     
1029     fCheckButtons[i]->SetState(kButtonUp, kFALSE);
1030     fCheckButtons[i]->MapRaised();
1031     fCheckButtons[i]->SetOn(fM->HistoDataIsSelected(i));
1032     fCheckButtons[i]->Connect("Clicked()", "AliEveTRDTrackListEditor", this, "UpdateDataFromMacroListSelection()");
1033             
1034     iter = (TObjString*)fM->fDataFromMacroList->After(iter);
1035   }  
1036 }
1037
1038 //______________________________________________________
1039 void AliEveTRDTrackListEditor::UpdateMacroList()
1040 {
1041   // Reloads (updates) the macro list (selection AND process macros) via
1042   // the current AliEveTRDTrackList (data).
1043
1044   ftlMacroList->RemoveAll();
1045   ftlMacroSelList->RemoveAll();
1046    
1047   TMapIter* iter = (TMapIter*)fM->fMacroList->MakeIterator();
1048   TObject* key = 0;
1049   TMacroData* macro = 0;
1050
1051   Int_t ind = 0;
1052   while ((key = iter->Next()) != 0)
1053   {
1054     macro = (TMacroData*)fM->fMacroList->GetValue(key);
1055     if (macro != 0)
1056     {
1057       if (macro->IsProcessMacro())
1058       {
1059         ftlMacroList->AddEntry(macro->GetName(), ind);
1060         // Select, what has been selected before
1061         ftlMacroList->Select(ind, fM->MacroListIsSelected(ind));
1062         ind++;
1063       }
1064       else if (macro->IsSelectionMacro())
1065       {
1066         ftlMacroSelList->AddEntry(macro->GetName(), ind);
1067         // Select, what has been selected before
1068         ftlMacroSelList->Select(ind, fM->MacroListIsSelected(ind));
1069         ind++;
1070       }
1071       else
1072       {
1073         Error("AliEveTRDTrackListEditor::UpdateMacroList()", 
1074               Form("Macro \"%s/%s.C\" has neither a selection macro nor a process macro!",
1075                    macro->GetPath(), macro->GetName()));                                        
1076       }
1077     }
1078     else
1079     {
1080       Error("AliEveTRDTrackListEditor::UpdateMacroList()", 
1081               Form("Macro list is corrupted: Macro \"%s\" not found!", key->GetName()));            
1082     }     
1083   }
1084
1085   ftlMacroList->SortByName(); 
1086   ftlMacroSelList->SortByName(); 
1087 }
1088
1089 //______________________________________________________
1090 void AliEveTRDTrackListEditor::UpdateMacroListSelection(Int_t ind)
1091 {
1092   // Saves the current selection in the macro listS to the current
1093   // AliEveTRDTrackList. This means that the selection is updated and won't
1094   // get lost, if another editor is loaded in Eve.
1095   // NOTE: The indices in BOTH lists will be unique!
1096
1097   // Toggle selected item
1098   fM->SetMacroListSelection(ind, !fM->MacroListIsSelected(ind));
1099 }
1100
1101
1102 /////////////////////////////////////////////////
1103 ClassImp(AliEveTRDMacroWizzard)
1104
1105 //______________________________________________________
1106 AliEveTRDMacroWizzard::AliEveTRDMacroWizzard(const TGWindow* p)
1107   :TGMainFrame(p ? p : gClient->GetRoot(), 10, 10, kMainFrame | kVerticalFrame)
1108   ,fText(0x0)
1109   ,fCombo(0x0)
1110   ,fTextEdit(0x0)
1111 {
1112   const Int_t width = 300;
1113
1114   // horizontal frame
1115   TGHorizontalFrame *fFrameName = new TGHorizontalFrame(this, 10, 10, kHorizontalFrame);
1116   TGLabel *fLabel = new TGLabel(fFrameName, "Name*");
1117   fLabel->SetTextJustify(36);
1118   fLabel->SetMargins(0,0,0,0);
1119   fLabel->SetWrapLength(-1);
1120   fFrameName->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1121
1122   fText = new TGTextEntry(fFrameName);
1123   fText->SetMaxLength(255);
1124   fText->SetAlignment(kTextLeft);
1125   fText->SetText("");
1126   fText->Resize(width, fText->GetDefaultHeight());
1127   fFrameName->AddFrame(fText, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1128
1129
1130   // horizontal frame
1131   TGHorizontalFrame *fFrameComment = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1132   fLabel = new TGLabel(fFrameComment, "Comment");
1133   fLabel->SetTextJustify(36);
1134   fLabel->SetMargins(0,0,0,0);
1135   fLabel->SetWrapLength(-1);
1136   fFrameComment->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1137
1138   fTextEdit = new TGTextEdit(fFrameComment, width, 5*fText->GetDefaultHeight());
1139   fFrameComment->AddFrame(fTextEdit, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1140
1141   // horizontal frame
1142   TGHorizontalFrame *fFrameType = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1143   fLabel = new TGLabel(fFrameType, "Type*");
1144   fLabel->SetTextJustify(36);
1145   fLabel->SetMargins(0,0,0,0);
1146   fLabel->SetWrapLength(-1);
1147   fFrameType->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1148
1149   fCombo = new TGComboBox(fFrameType, -1, kHorizontalFrame | kSunkenFrame | kDoubleBorder | kOwnBackground);
1150   fCombo->AddEntry("Single Track Selection", AliEveTRDTrackList::kSingleTrackSelect);
1151   fCombo->AddEntry("Pair Tracks Selection", AliEveTRDTrackList::kCorrelTrackSelect);
1152   fCombo->AddEntry("Single Track Analyse", AliEveTRDTrackList::kSingleTrackAnalyse);
1153   fCombo->AddEntry("Single Track Histo", AliEveTRDTrackList::kSingleTrackHisto);
1154   fCombo->AddEntry("Pair Tracks Analyse", AliEveTRDTrackList::kCorrelTrackAnalyse);
1155   fCombo->AddEntry("Pair Tracks Histo", AliEveTRDTrackList::kCorrelTrackHisto);
1156   fCombo->Select(-1);
1157   fCombo->Resize(width, fText->GetDefaultHeight());
1158   fFrameType->AddFrame(fCombo, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
1159
1160
1161   // horizontal frame
1162   TGHorizontalFrame *fFrameText = new TGHorizontalFrame(this,10,10,kHorizontalFrame);
1163   fLabel = new TGLabel(fFrameText, "(*) Mandatory fields");
1164   fLabel->SetTextJustify(36);
1165   fLabel->SetMargins(0,0,0,0);
1166   fLabel->SetWrapLength(-1);
1167   fFrameText->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
1168
1169   // put things together  
1170   AddFrame(fFrameName, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1171   AddFrame(fFrameComment, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1172   AddFrame(fFrameType, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1173
1174   TGHorizontal3DLine *fLine = new TGHorizontal3DLine(this, 281, 2);
1175   AddFrame(fLine, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1176   AddFrame(fFrameText, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX,2,2,2,2));
1177
1178
1179   SetWindowName("TRD Macro Wizzard");
1180   SetMWMHints(kMWMDecorAll,
1181               kMWMFuncAll,
1182               kMWMInputModeless);
1183   MapSubwindows();
1184
1185   Resize(GetDefaultSize());
1186   MapWindow();
1187
1188   // Do the linking
1189   fCombo->Connect("Selected(Int_t)", "AliEveTRDMacroWizzard", this, "Create(Int_t)");
1190 }  
1191
1192 const Char_t *fIncludes = 
1193 "#if !defined(__CINT__) || defined(__MAKECINT__)\n"
1194 "#include <TROOT.h>\n"
1195 "#include <TH1.h>\n"
1196 "#include <TRD/AliTRDgeometry.h>\n"
1197 "#include <TRD/AliTRDcluster.h>\n"
1198 "#include <TRD/AliTRDseedV1.h>\n"
1199 "#include <TRD/AliTRDtrackV1.h>\n"
1200 "#endif\n";
1201
1202 const Char_t *fMacroTemplate[7] = {
1203 ""
1204 ,"  if (!track) return kFALSE;\n"
1205 "  return kFALSE;\n"
1206
1207 ,"  n = 0;\n"
1208 "  r=0x0;\n"
1209 "  if (!track) return;\n"
1210
1211 ,"  if (!track) return 0x0;\n"
1212 "  TH1* h = 0x0;\n"
1213 "  if(!(h = (TH1*)gROOT->FindObject(\"h\"))){\n"
1214 "    h = new TH1(\"h\", \"Title\", n, xmin, xmax);\n"
1215 "    h->GetXaxis()->SetTitle("");\n"
1216 "    h->GetYaxis()->SetTitle("");\n"
1217 "  } else h->Reset();\n"
1218 "  return h;\n"
1219
1220 ,"  if (!track) return kFALSE;\n"
1221 "  if (!track2) return kFALSE;\n"
1222 "  return kFALSE;\n"
1223
1224 ,"  n = 0;\n"
1225 "  r=0x0;\n"
1226 "  if (!track) return;\n"
1227 "  if (!track2) return;\n"
1228
1229 ,"  if (!track) return 0x0;\n"
1230 "  if (!track2) return 0x0;\n"
1231 "  TH1* h = 0x0;\n"
1232 "  if(!(h = (TH1*)gROOT->FindObject(\"h\"))){\n"
1233 "    h = new TH1(\"h\", \"Title\", n, xmin, xmax);\n"
1234 "    h->GetXaxis()->SetTitle("");\n"
1235 "    h->GetYaxis()->SetTitle("");\n"
1236 "  } else h->Reset();\n"
1237 "  return h;\n"
1238 };
1239 //______________________________________________________
1240 void AliEveTRDMacroWizzard::Create(Int_t typ)
1241 {
1242   const Char_t *name = fText->GetText();
1243   if(strcmp(name,"")==0){
1244     AliInfo("Please specify a name for your macro.");
1245     fCombo->Select(-1);
1246     return;
1247   }
1248
1249   FILE* fp = 0x0;
1250   if(!(fp = fopen(Form("%s.C", name), "wt"))){
1251     AliInfo("Couldn't create macro file.");
1252     fCombo->Select(-1);
1253     return;
1254   }
1255
1256   TGText *comment = fTextEdit->GetText();
1257   Char_t *line = 0x0; Int_t iline = 0;
1258   while((line = comment->GetLine(TGLongPosition(0,iline++), 200))) fprintf(fp, "// %s\n", line);
1259
1260   fprintf(fp, "\n%s\n", fIncludes);
1261
1262   switch(typ){
1263   case AliEveTRDTrackList::kSingleTrackSelect:
1264     fprintf(fp, "Bool_t %s(const AliTRDtrackV1 *track)\n", name);
1265     break;
1266   case AliEveTRDTrackList::kCorrelTrackSelect:
1267     fprintf(fp, "Bool_t %s(const AliTRDtrackV1 *track, const AliTRDtrackV1 *track2)\n", name);
1268     break;
1269   case AliEveTRDTrackList::kSingleTrackAnalyse:
1270     fprintf(fp, "void %s(const AliTRDtrackV1 *track, Double_t*& r, Int_t& n)\n", name);
1271     break;
1272   case AliEveTRDTrackList::kSingleTrackHisto:
1273     fprintf(fp, "TH1* %s(const AliTRDtrackV1 *track)\n", name);
1274     break;
1275   case AliEveTRDTrackList::kCorrelTrackAnalyse:
1276     fprintf(fp, "void %s(const AliTRDtrackV1 *track, const AliTRDtrackV1 *track2, Double_t*& r, Int_t& n)\n", name);
1277     break;
1278   case AliEveTRDTrackList::kCorrelTrackHisto:
1279     fprintf(fp, "TH1* %s(const AliTRDtrackV1 *track, const AliTRDtrackV1 *track2)\n", name);
1280     break;
1281   default:
1282     AliInfo(Form("Unknown typ[%d]", typ));
1283     fclose(fp);
1284     gSystem->Exec(Form("rm -f %s.C", name));
1285     fCombo->Select(-1);
1286     return;
1287   }
1288   
1289   fprintf(fp, "{\n%s\n", fMacroTemplate[typ]);
1290   fprintf(fp, "// add your own code here\n\n\n}\n");
1291   fclose(fp);
1292
1293   Emit("Create(Int_t)", typ);
1294   Create((Char_t*)name);
1295   CloseWindow();
1296 }
1297
1298 //______________________________________________________
1299 void AliEveTRDMacroWizzard::Create(Char_t *name)
1300 {
1301   Emit("Create(Char_t*)", Form("%s.C", name));
1302 }