]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliDisplay.cxx
pyquen added.
[u/mrichter/AliRoot.git] / STEER / AliDisplay.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //////////////////////////////////////////////////////////////////////////
19 //                                                                      //
20 // AliDisplay                                                           //
21 //                                                                      //
22 // Utility class to display ALICE outline, tracks, hits,..              //
23 //                                                                      //
24 //////////////////////////////////////////////////////////////////////////
25
26 #include <TArc.h>
27 #include <TButton.h>
28 #include <TCanvas.h>
29 #include <TDiamond.h>
30 #include <TGaxis.h>
31 #include <TMath.h>
32 #include <TPaveLabel.h>
33 #include <TPaveText.h>
34 #include <TSlider.h>
35 #include <TSliderBox.h>
36 //#include <TTree.h>
37 #include <TView.h>
38 #include <TVirtualX.h>
39
40 #include "AliDetector.h"
41 #include "AliDisplay.h"
42 #include "AliHeader.h"
43 #include "AliPoints.h"
44 #include "AliRun.h"
45 #include "AliStack.h"
46 #include "TGeometry.h"
47 #include "TParticle.h"
48 #include "AliMC.h"
49
50 const Float_t AliDisplay::fgkPtCutMax  = 2;
51 const Float_t AliDisplay::fgkEtaCutMax = 1.5;
52 const Int_t   AliDisplay::fgkMaxZooms = 20;
53
54
55 ClassImp(AliDisplay)
56
57
58 //_______________________________________________________________________
59 AliDisplay::AliDisplay():
60   fZoomMode(0),
61   fDrawAllViews(0),
62   fDrawParticles(0),
63   fDrawHits(0),
64   fPTcut(0),
65   fTheta(0),
66   fPhi(0),
67   fPsi(0),
68   fRrange(0),
69   fZrange(0),
70   fZooms(0),
71   fHitsCuts(0),
72   fCanvas(0),
73   fTrigPad(0),
74   fCutPad(0),
75   fEtaPad(0),
76   fButtons(0),
77   fPad(0),
78   fCutSlider(0),
79   fEtaSlider(0),
80   fRangeSlider(0),
81   fPickButton(0),
82   fZoomButton(0),
83   fArcButton(0),
84   fFruits(0),
85   fTracksToDisplay(0),
86   fNTracksToDisplay(0)
87 {
88   //
89   // Default constructor
90   //
91 }
92
93 //_____________________________________________________________________________
94 AliDisplay::AliDisplay(Int_t size):
95   fZoomMode(1),
96   fDrawAllViews(kFALSE),
97   fDrawParticles(kTRUE),
98   fDrawHits(kTRUE),
99   fPTcut(0),
100   fTheta(0),
101   fPhi(-90),
102   fPsi(0),
103   fRrange(0),
104   fZrange(0),
105   fZooms(1),
106   fHitsCuts(0),
107   fCanvas(0),
108   fTrigPad(0),
109   fCutPad(0),
110   fEtaPad(0),
111   fButtons(0),
112   fPad(0),
113   fCutSlider(0),
114   fEtaSlider(0),
115   fRangeSlider(0),
116   fPickButton(0),
117   fZoomButton(0),
118   fArcButton(0),
119   fFruits(0),
120   fTracksToDisplay(0),
121   fNTracksToDisplay(0)
122 {
123 // Create an event display object.
124 // A canvas named "edisplay" is created with a vertical size in pixels
125 //
126 //    A QUICK Overview of the Event Display functions
127 //    ===============================================
128 //
129 //  The event display can ve invoked by executing the macro "display.C"
130 // A canvas like in the picture below will appear.
131 //
132 //  On the left side of the canvas, the following buttons appear:
133 //   *Next*       to move to the next event
134 //   *Previous*   to move to the previous event
135 //   *Top View*   to display a top view of the current event
136 //   *Side View*  to display a side view of the current event
137 //   *Front View* to display a front view of the current event
138 //   *All Views*  to display front/side/top/30-30 views of the current event
139 //   *OpenGL*     to use OpenGl to view the current event.
140 //                Note that OpenGL cannot be used across the network.
141 //                Before using OpenGL, load the GL libraries
142 //                by executing the macro GL.C (in $ROOTSYS/macros/GL.C.
143 //                Once in GL, click the HELP button of the GL canvas.
144 //   *X3D*        to use X3D to view the current event (Unix only).
145 //                Once in X3D, type M to see the list of all possible options.
146 //                for example type J to zoom, K to unzoom
147 //                use the mouse to rotate.
148 //   *Pick*       Select this option to be able to point on a track with the
149 //                mouse. Once on the track, use the right button to select
150 //                an action. For example, select SetMarkerAttributes to
151 //                change the marker type/color/size for the track.
152 //   *Zoom*       Select this option (default) if you want to zoom.
153 //                To zoom, simply select the selected area with the left button.
154 //   *UnZoom*     To revert to the previous picture size.
155 //
156 //   slider R     On the left side, the vertical slider can be used to
157 //                set the default picture size.
158 //   slider pcut  At the top of the canvas, a slider can be used to change
159 //                the momentum cut (or range) to display tracks.
160 //   slider eta   On the right side of the canvas, a vertical slider can be used
161 //                to specify a rapidity range for the tracks.
162 //
163 //    When you are in Zoom mode, you can click on the black part of the canvas
164 //  to select special options with the right mouse button.
165 //  This will display a pop-up menu with items like:
166 //     *Disable detector* 
167 //     *Enable detector*, etc.
168 //  For example select "Disable detector". You get a dialog box.
169 //  Diable detector TRD for example.
170 //
171 //  When you are in pick mode, you can "Inspect" the object pointed by the mouse.
172 //  When you are on a track, select the menu item "InspectParticle"
173 //  to display the current particle attributes.
174 //
175 //  You can activate the Root browser by selecting the Inspect menu
176 //  in the canvas tool bar menu. Then select "Start Browser"
177 //  This will open a new canvas with the browser. At this point, you may want
178 //  to display some histograms (from the Trees). Go to the "File" menu
179 //  of the browser and click on "New canvas".
180 //  In the browser, click on item "ROOT files" in the left pane.
181 //  Click on galice.root.
182 //  Click on TH
183 //  Click on TPC for example
184 //  Click on any variable (eg TPC.fX) to histogram the variable.
185 //
186 //   If you are lost, you can click on HELP in any Root canvas or browser.
187 //Begin_Html
188 /*
189 <img src="picts/alidisplay.gif">
190 */
191 //End_Html
192    
193   gAlice->SetDisplay(this);
194    
195   // Initialize display default parameters
196   SetRange();
197   SetPTcut();
198   
199   // Create display canvas
200   Int_t ysize = size;
201   if (ysize < 100) ysize = 750;
202   Int_t xsize = Int_t(size*830./ysize);
203   fCanvas = new TCanvas("Canvas", "ALICE Event Display",14,47,xsize,ysize);
204   fCanvas->ToggleEventStatus();
205
206   // Create main display pad
207   fPad = new TPad("viewpad", "Alice display",0.15,0,0.97,0.96);
208   fPad->Draw();
209   fPad->Modified();
210   fPad->SetFillColor(1);
211   fPad->SetBorderSize(2);
212
213   // Create user interface control pad
214   DisplayButtons();
215   fCanvas->cd();
216
217   // Create Range and mode pad
218   Float_t dxtr     = 0.15;
219   Float_t dytr     = 0.45;
220   fTrigPad = new TPad("trigger", "range and mode pad",0,0,dxtr,dytr);
221   fTrigPad->Draw();
222   fTrigPad->cd();
223   fTrigPad->SetFillColor(22);
224   fTrigPad->SetBorderSize(2);
225   fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
226   fRangeSlider->SetObject(this);
227   char pickmode[] = "gAlice->Display()->SetPickMode()";
228   Float_t db = 0.09;
229   fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
230   fPickButton->SetFillColor(38);
231   fPickButton->Draw();
232   char zoommode[] = "gAlice->Display()->SetZoomMode()";
233   fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
234   fZoomButton->SetFillColor(38);
235   fZoomButton->Draw();
236   fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
237   fArcButton->SetFillColor(kGreen);
238   fArcButton->Draw();
239   char butUnzoom[] = "gAlice->Display()->UnZoom()";
240   TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
241   button->SetFillColor(38);
242   button->Draw();
243   AppendPad(); // append display object as last object to force selection
244   // Create momentum cut slider pad
245   fCanvas->cd();
246   fCutPad = new TPad("cutSlider", "pcut slider pad",dxtr,.96,1,1);
247   fCutPad->Draw();
248   fCutPad->cd();
249   fCutPad->SetFillColor(22);
250   fCutPad->SetBorderSize(2);
251   fCutSlider = new TSlider("pcut","Momentum cut",0,0,1,1);
252   fCutSlider->SetRange(fPTcut/fgkPtCutMax,1);
253   fCutSlider->SetObject(this);
254   fCutSlider->SetFillColor(45);
255   TSliderBox *sbox = dynamic_cast<TSliderBox*>(fCutSlider->GetListOfPrimitives()->First());
256   sbox->SetFillColor(46);
257   fCutSlider->cd();
258   TGaxis *cutaxis = new TGaxis(0.02,0.8,0.98,0.8,0,fgkPtCutMax,510,"");
259   cutaxis->SetLabelSize(0.5);
260   cutaxis->SetTitleSize(0.6);
261   cutaxis->SetTitleOffset(0.5);
262   cutaxis->SetTitle("pcut .  ");
263   fCutSlider->GetListOfPrimitives()->AddFirst(cutaxis);
264   // Create rapidity cut slider pad
265   fCanvas->cd();
266   fEtaPad = new TPad("EtaSlider", "Eta slider pad",0.97,0,1,0.96);
267   fEtaPad->Draw();
268   fEtaPad->cd();
269   fEtaPad->SetFillColor(22);
270   fEtaPad->SetBorderSize(2);
271   fEtaSlider = new TSlider("etacut","Rapidity cut",0,0,1,1);
272   fEtaSlider->SetObject(this);
273   fEtaSlider->SetFillColor(45);
274   TSliderBox *sbox2 = dynamic_cast<TSliderBox*>(fEtaSlider->GetListOfPrimitives()->First());
275   sbox2->SetFillColor(46);
276   fEtaSlider->cd();
277   TGaxis *etaaxis = new TGaxis(0.9,0.02,0.9,0.98,-fgkEtaCutMax,fgkEtaCutMax,510,"");
278   etaaxis->SetLabelSize(0.5);
279   etaaxis->SetTitleSize(0.6);
280   etaaxis->SetTitleOffset(0.2);
281   cutaxis->SetTitle("Etacut .  ");
282   fEtaSlider->GetListOfPrimitives()->AddFirst(etaaxis);
283   fCanvas->cd();
284
285   fTrigPad->SetEditable(kFALSE);
286   fButtons->SetEditable(kFALSE);
287   fTracksToDisplay =0;
288   fNTracksToDisplay =0;   
289
290   fCanvas->cd();
291   fCanvas->Update();
292 }
293
294
295 //_______________________________________________________________________
296 AliDisplay::AliDisplay(const AliDisplay &disp):
297   TObject(disp),
298   fZoomMode(0),
299   fDrawAllViews(0),
300   fDrawParticles(0),
301   fDrawHits(0),
302   fPTcut(0),
303   fTheta(0),
304   fPhi(0),
305   fPsi(0),
306   fRrange(0),
307   fZrange(0),
308   fZooms(0),
309   fHitsCuts(0),
310   fCanvas(0),
311   fTrigPad(0),
312   fCutPad(0),
313   fEtaPad(0),
314   fButtons(0),
315   fPad(0),
316   fCutSlider(0),
317   fEtaSlider(0),
318   fRangeSlider(0),
319   fPickButton(0),
320   fZoomButton(0),
321   fArcButton(0),
322   fFruits(0),
323   fTracksToDisplay(0),
324   fNTracksToDisplay(0)
325 {
326   //
327   // Copy constructor
328   //
329   disp.Copy(*this);
330 }
331
332 //_____________________________________________________________________________
333 AliDisplay::~AliDisplay()
334 {
335   //
336   // Destructor
337   //
338 }
339
340 //_____________________________________________________________________________
341 void AliDisplay::Clear(Option_t *)
342 {
343 //    Delete graphics temporary objects
344 }
345
346 //_____________________________________________________________________________
347 void AliDisplay::Copy(TObject &) const
348 {
349   //
350   // Copy *this onto disp -- not implemented
351   //
352   Fatal("Copy","Not implemented~\n");
353 }
354
355 //----------------------------------------------------------------------------
356 void AliDisplay::ShowTrack(Int_t idx) 
357 {
358   //
359   // Display track idx
360   //
361    AliDetector *mTPC=dynamic_cast<AliDetector*>(gAlice->GetModule("TPC"));
362    TObjArray *points=mTPC->Points();
363    int ntracks=points->GetEntriesFast();
364    for (int track=0;track<ntracks;track++) {
365       AliPoints *pm = dynamic_cast<AliPoints*>(points->UncheckedAt(track));
366       if (!pm) continue;
367       if (idx == pm->GetIndex()) {
368          pm->SetMarkerColor(2);
369          pm->SetMarkerStyle(22);
370          pm->Draw("same");
371 //       fPad->Update();
372 //       fPad->Modified();
373          //         TClonesArray *particles=gAlice->Particles();
374          //         TParticle *p = (TParticle*)particles->UncheckedAt(idx);
375          TParticle *p = gAlice->GetMCApp()->Particle(idx);
376          printf("\nTrack index %d\n",idx);
377          printf("Particle ID %d\n",p->GetPdgCode());
378          printf("Parent %d\n",p->GetFirstMother());
379          printf("First child %d\n",p->GetFirstDaughter());
380          printf("Px,Py,Pz %f %f %f\n",p->Px(),p->Py(),p->Pz());
381          return;
382       }
383    }
384 }
385
386 //----------------------------------------------------------------------------
387 void AliDisplay::HideTrack(Int_t idx) const
388 {
389   //
390   // Hide track on display
391   //
392    AliDetector *mTPC=dynamic_cast<AliDetector*>(gAlice->GetModule("TPC"));
393    TObjArray *points=mTPC->Points();
394    int ntracks=points->GetEntriesFast();
395    for (int track=0;track<ntracks;track++) {
396       AliPoints *pm = dynamic_cast<AliPoints*>(points->UncheckedAt(track));
397       if (!pm) continue;
398       if (idx == pm->GetIndex()) {
399          pm->SetMarkerColor(5);
400          pm->SetMarkerStyle(1);
401          pm->Draw("same");
402 //       fPad->Update();
403 //       fPad->Modified();
404          return;
405       }
406    }
407 }
408
409 //_____________________________________________________________________________
410 void AliDisplay::DisableDetector(const char *name)
411 {
412 //    Disable detector name from graphics views
413    
414    AliModule *module = dynamic_cast<AliModule*>(gAlice->Modules()->FindObject(name));
415    if (!module) return;
416    module->Disable();
417    Draw();
418 }
419
420 //_____________________________________________________________________________
421 void AliDisplay::DisplayButtons()
422 {
423 //    Create the user interface buttons
424
425    fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
426    fButtons->Draw();
427    fButtons->SetFillColor(38);
428    fButtons->SetBorderSize(2);
429    fButtons->cd();
430
431    Int_t butcolor = 33;
432    Float_t dbutton = 0.08;
433    Float_t y  = 0.96;
434    Float_t dy = 0.014;
435    Float_t x0 = 0.05;
436    Float_t x1 = 0.95;
437
438    TButton *button;
439    char but1[] = "gAlice->Display()->ShowNextEvent(1)";
440    button = new TButton("Next",but1,x0,y-dbutton,x1,y);
441    button->SetFillColor(38);
442    button->Draw();
443
444    y -= dbutton +dy;
445    char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
446    button = new TButton("Previous",but2,x0,y-dbutton,x1,y);
447    button->SetFillColor(38);
448    button->Draw();
449
450    y -= dbutton +dy;
451    char but3[] = "gAlice->Display()->SetView(90,-90,90)";
452    button = new TButton("Top View",but3,x0,y-dbutton,x1,y);
453    button->SetFillColor(butcolor);
454    button->Draw();
455
456    y -= dbutton +dy;
457    char but4[] = "gAlice->Display()->SetView(90,0,-90)";
458    button = new TButton("Side View",but4,x0,y-dbutton,x1,y);
459    button->SetFillColor(butcolor);
460    button->Draw();
461
462    y -= dbutton +dy;
463    char but5[] = "gAlice->Display()->SetView(0,-90,0)";
464    button = new TButton("Front View",but5,x0,y-dbutton,x1,y);
465    button->SetFillColor(butcolor);
466    button->Draw();
467
468    y -= dbutton +dy;
469    char but6[] = "gAlice->Display()->DrawAllViews()";
470    button = new TButton("All Views",but6,x0,y-dbutton,x1,y);
471    button->SetFillColor(butcolor);
472    button->Draw();
473
474    y -= dbutton +dy;
475    char but7[] = "gAlice->Display()->DrawViewGL()";
476    button = new TButton("OpenGL",but7,x0,y-dbutton,x1,y);
477    button->SetFillColor(38);
478    button->Draw();
479
480    y -= dbutton +dy;
481    char but8[] = "gAlice->Display()->DrawViewX3D()";
482    button = new TButton("X3D",but8,x0,y-dbutton,x1,y);
483    button->SetFillColor(38);
484    button->Draw();
485
486    // display logo
487    TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
488    diamond->SetFillColor(50);
489    diamond->SetTextAlign(22);
490    diamond->SetTextColor(5);
491    diamond->SetTextSize(0.11);
492    diamond->Draw();
493    diamond->AddText(".. ");
494    diamond->AddText("ROOT");
495    diamond->AddText("ALICE");
496    diamond->AddText("... ");
497    diamond->AddText(" ");
498 }
499
500 //______________________________________________________________________________
501 Int_t AliDisplay::DistancetoPrimitive(Int_t px, Int_t)
502 {
503 // Compute distance from point px,py to objects in event
504
505    gPad->SetCursor(kCross);
506    
507    if (gPad == fTrigPad) return 9999;
508    if (gPad == fCutPad)  return 9999;
509    if (gPad == fEtaPad)  return 9999;
510
511    const Int_t kbig = 9999;
512    Int_t dist   = kbig;
513    Float_t xmin = gPad->GetX1();
514    Float_t xmax = gPad->GetX2();
515    Float_t dx   = 0.02*(xmax - xmin);
516    Float_t x    = gPad->AbsPixeltoX(px);
517    if (x < xmin+dx || x > xmax-dx) return dist;
518
519    if (fZoomMode) return 0;
520    else           return 7;
521 }
522
523 //_____________________________________________________________________________
524 void AliDisplay::Draw(Option_t *)
525 {
526 //    Display current event
527
528    if (fDrawAllViews) {
529       DrawAllViews();
530       return;
531    }
532
533    fPad->cd();
534
535    DrawView(fTheta, fPhi, fPsi);
536
537    // Display the event number and title
538    fPad->cd();
539    DrawTitle();
540 }
541
542 //_____________________________________________________________________________
543 void AliDisplay::DrawAllViews()
544 {
545 //    Draw front,top,side and 30 deg views
546
547    fDrawAllViews = kTRUE;
548    fPad->cd();
549    fPad->SetFillColor(15);
550    fPad->Clear();
551    fPad->Divide(2,2);
552
553    // draw 30 deg view
554    fPad->cd(1);
555    DrawView(30, 30, 0);
556    DrawTitle();
557
558    // draw front view
559    fPad->cd(2);
560    DrawView(0, -90,0);
561    DrawTitle("Front");
562
563    // draw top view
564    fPad->cd(3);
565    DrawView(90, -90, 90);
566    DrawTitle("Top");
567
568    // draw side view
569    fPad->cd(4);
570    DrawView(90, 0, -90);
571    DrawTitle("Side");
572
573    fPad->cd(2);
574 }
575
576 //_____________________________________________________________________________
577 void AliDisplay::DrawHits()
578 {
579 //    Draw hits for all ALICE detectors
580
581    Float_t cutmin, cutmax, etamin, etamax, pmom, smin, smax, eta, theta, r;
582    Float_t *pxyz;
583    Int_t ntracks,track;
584    TParticle *particle;
585    TObjArray *points;
586    AliPoints *pm;
587       
588    //Get cut slider
589    smax   = fCutSlider->GetMaximum();
590    smin   = fCutSlider->GetMinimum();
591    cutmin = fgkPtCutMax*smin;
592    if (smax < 0.98) cutmax = fgkPtCutMax*smax;
593    else             cutmax = 100000;
594    
595    //Get eta slider
596    smax   = fEtaSlider->GetMaximum();
597    smin   = fEtaSlider->GetMinimum();
598    etamin = fgkEtaCutMax*(2*smin-1);
599    etamax = fgkEtaCutMax*(2*smax-1);
600    if (smin < 0.02) etamin = -1000;
601    if (smax > 0.98) etamax =  1000;
602       
603    TIter next(gAlice->Modules());
604    AliModule *module;
605    fHitsCuts = 0;
606    while((module = dynamic_cast<AliModule*>(next()))) {
607       if (!module->IsActive()) continue;
608       points = module->Points();
609       if (!points) continue;
610       ntracks = points->GetEntriesFast();
611       for (track=0;track<ntracks;track++) {
612          pm = dynamic_cast<AliPoints*>(points->UncheckedAt(track));
613          if (!pm) continue;
614          particle = pm->GetParticle();
615          if (!particle) continue;
616          pmom = particle->P();
617          if (pmom < cutmin) continue;
618          if (pmom > cutmax) continue;
619          // as a first approximation, take eta of first point
620          pxyz  = pm->GetP();
621          r     = TMath::Sqrt(pxyz[0]*pxyz[0] + pxyz[1]*pxyz[1]);
622          theta = TMath::ATan2(r,TMath::Abs(pxyz[2]));
623          if(theta) eta = -TMath::Log(TMath::Abs(TMath::Tan(0.5*theta))); else eta = 1e10;
624          if (pxyz[2] < 0) eta = -eta;
625          if (eta < etamin || eta > etamax) continue;
626          pm->Draw();
627          fHitsCuts += pm->GetN();
628       }
629    }
630 }
631
632 //_____________________________________________________________________________
633 void AliDisplay::DrawTitle(Option_t *option)
634 {
635 //    Draw the event title
636
637    Float_t xmin = gPad->GetX1();
638    Float_t xmax = gPad->GetX2();
639    Float_t ymin = gPad->GetY1();
640    Float_t ymax = gPad->GetY2();
641    Float_t dx   = xmax-xmin;
642    Float_t dy   = ymax-ymin;
643
644    if (strlen(option) == 0) {
645       TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
646       title->SetBit(kCanDelete);
647       title->SetFillColor(42);
648       title->Draw();
649       char ptitle[100];
650       sprintf(ptitle,"Alice event: %d, Run:%d",gAlice->GetHeader()->GetEvent(), gAlice->GetHeader()->GetRun());
651       title->AddText(ptitle);
652       Int_t nparticles = gAlice->GetMCApp()->Particles()->GetEntriesFast();
653       sprintf(ptitle,"Nparticles = %d  Nhits = %d",nparticles, fHitsCuts);
654       title->AddText(ptitle);
655    } else {
656       TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
657       label->SetBit(kCanDelete);
658       label->SetFillColor(42);
659       label->Draw();
660    }
661 }
662
663 //_____________________________________________________________________________
664 void AliDisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
665 {
666 //    Draw a view of ALICE
667
668    gPad->SetCursor(kWatch);
669    gPad->SetFillColor(1);
670    gPad->Clear();
671
672    Int_t iret;
673    TView *view = new TView(1);
674    Float_t range = fRrange*fRangeSlider->GetMaximum();
675    view->SetRange(-range,-range,-range,range, range, range);
676    fZoomX0[0] = -1;
677    fZoomY0[0] = -1;
678    fZoomX1[0] =  1;
679    fZoomY1[0] =  1;
680    fZooms = 0;
681    
682    // Display Alice Geometry
683    gAlice->GetGeometry()->Draw("same");
684    
685    //Loop on all detectors to add their products to the pad
686    DrawHits();
687
688     // add itself to the list (must be last)
689    AppendPad();
690    
691    view->SetView(phi, theta, psi, iret);
692 }
693
694 //_____________________________________________________________________________
695 void AliDisplay::DrawViewGL()
696 {
697 //    Draw current view using OPENGL
698
699    TPad *pad = dynamic_cast<TPad*>(gPad->GetPadSave());
700    pad->cd();
701    TView *view = pad->GetView();
702    if (!view) return;
703    pad->x3d("OPENGL");
704 }
705
706 //_____________________________________________________________________________
707 void AliDisplay::DrawViewX3D()
708 {
709 //    Draw current view using X3D
710
711    TPad *pad = dynamic_cast<TPad*>(gPad->GetPadSave());
712    pad->cd();
713    TView *view = pad->GetView();
714    if (!view) return;
715    pad->x3d();
716 }
717
718 //_____________________________________________________________________________
719 void AliDisplay::EnableDetector(const char *name)
720 {
721 //    Enable detector name in graphics views
722    
723    AliModule *module = dynamic_cast<AliModule*>(gAlice->Modules()->FindObject(name));
724    if (!module) return;
725    module->Enable();
726    Draw();
727 }
728
729 //______________________________________________________________________________
730 void AliDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
731 {
732 //  Execute action corresponding to the mouse event
733
734    static Float_t x0, y0, x1, y1;
735
736    static Int_t pxold, pyold;
737    static Int_t px0, py0;
738    static Int_t linedrawn;
739    Float_t temp;
740
741    if (px == 0 && py == 0) { //when called by sliders
742       if (event == kButton1Up) {
743          Draw();
744       }
745       return;
746    }
747    if (!fZoomMode && gPad->GetView()) {
748       gPad->GetView()->ExecuteRotateView(event, px, py);
749       return;
750    }
751
752    // something to zoom ?
753 //   fPad->SetCursor(kCross);
754    gPad->SetCursor(kCross);
755    
756    switch (event) {
757
758    case kButton1Down:
759       gVirtualX->SetLineColor(-1);
760       gPad->TAttLine::Modify();  //Change line attributes only if necessary
761       x0 = gPad->AbsPixeltoX(px);
762       y0 = gPad->AbsPixeltoY(py);
763       px0   = px; py0   = py;
764       pxold = px; pyold = py;
765       linedrawn = 0;
766       return;
767
768    case kButton1Motion:
769       if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
770       pxold = px;
771       pyold = py;
772       linedrawn = 1;
773       gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
774       return;
775
776    case kButton1Up:
777       gPad->GetCanvas()->FeedbackMode(kFALSE);
778       if (px == px0) return;
779       if (py == py0) return;
780       x1 = gPad->AbsPixeltoX(px);
781       y1 = gPad->AbsPixeltoY(py);
782
783       if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
784       if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
785       gPad->Range(x0,y0,x1,y1);
786       if (fZooms < fgkMaxZooms-1) {
787          fZooms++;
788          fZoomX0[fZooms] = x0;
789          fZoomY0[fZooms] = y0;
790          fZoomX1[fZooms] = x1;
791          fZoomY1[fZooms] = y1;
792       }
793       gPad->Modified(kTRUE);
794       return;
795    }
796
797 }
798  
799
800 void AliDisplay::SetTracksToDisplay(Int_t *tracks, Int_t n){
801   //
802   // set tracks to display  - MI
803   fTracksToDisplay = tracks;
804   fNTracksToDisplay = n;
805 }
806 //___________________________________________
807 void AliDisplay::LoadPoints()
808 {
809 // Read hits info and store x,y,z info in arrays fPoints
810 // Loop on all detectors
811  
812    gAlice->ResetPoints();
813    TIter next(gAlice->Modules());
814    AliModule *module;
815    Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
816
817    while((module = (AliModule*)next())) 
818     {
819      AliDetector* detector = dynamic_cast<AliDetector*>(module);
820      if(detector) detector->SetTreeAddress();
821     }
822    next.Reset();
823
824    // load only wanted tracks
825    if (fNTracksToDisplay>0)
826     {
827       Int_t nprim =  gAlice->Stack()->GetNprimary();
828       for (Int_t track=0; track<fNTracksToDisplay;track++) 
829        {
830         gAlice->ResetHits();
831         Int_t nev = nprim-1-gAlice->GetMCApp()->GetPrimary(fTracksToDisplay[track]);
832         while((module = (AliModule*)next())) 
833          {
834           AliDetector* detector = dynamic_cast<AliDetector*>(module);
835           if(detector)
836            {
837             detector->TreeH()->GetEvent(nev);
838             module->LoadPoints(nprim-1-gAlice->GetMCApp()->GetPrimary(fTracksToDisplay[track]));
839            }
840          }
841         next.Reset();
842      }
843    }
844    else
845     {
846       
847       for (Int_t track=0; track<ntracks;track++) {
848       gAlice->ResetHits();
849       while((module = (AliModule*)next())) {
850          AliDetector* detector = dynamic_cast<AliDetector*>(module);
851          if(detector)
852            {
853              if (detector->TreeH()->GetEvent(track))
854                detector->LoadPoints(track);
855            }
856       }
857       next.Reset();
858      }
859    }
860 }
861
862 //_____________________________________________________________________________
863 void AliDisplay::Paint(Option_t *)
864 {
865 //    Paint miscellaneous items
866
867 }
868
869 //_____________________________________________________________________________
870 void AliDisplay::SetPickMode()
871 {
872   //
873   // Set Pick Mode -- disable zoom
874   //
875    fZoomMode = 0;
876
877    fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
878    fTrigPad->Modified();
879 }
880
881 //_____________________________________________________________________________
882 void AliDisplay::SetZoomMode()
883 {
884   //
885   // Set Zoom Mode -- disable pick
886   //
887    fZoomMode = 1;
888
889    fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
890    fTrigPad->Modified();
891 }
892
893 //_____________________________________________________________________________
894 void AliDisplay::SetPTcut(Float_t ptcut)
895 {
896   //
897   // Set Pt Cut
898   //
899    fPTcut = ptcut;
900
901    if (!fPad) return;
902    fPad->Clear();
903    Draw();
904 }
905
906 //_____________________________________________________________________________
907 void AliDisplay::SetRange(Float_t rrange, Float_t zrange)
908 {
909 // Set view range along R and Z
910    fRrange = rrange;
911    fZrange = zrange;
912
913    if (!fPad) return;
914    fPad->Clear();
915    Draw();
916 }
917    
918 //_____________________________________________________________________________
919 void AliDisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
920 {
921 //  change viewing angles for current event
922
923    fPad->cd();
924    fDrawAllViews = kFALSE;
925    fPhi   = phi;
926    fTheta = theta;
927    fPsi   = psi;
928    Int_t iret = 0;
929
930    TView *view = gPad->GetView();
931    if (view) view->SetView(fPhi, fTheta, fPsi, iret);
932    else      Draw();
933
934    gPad->Modified();
935 }
936
937 //_____________________________________________________________________________
938 void AliDisplay::ShowNextEvent(Int_t delta)
939 {
940 //  Display (current event_number+delta)
941 //    delta =  1  shown next event
942 //    delta = -1 show previous event
943
944   if (delta) {
945 //     gAlice->Clear();
946      //Int_t currentEvent = gAlice->GetHeader()->GetEvent();//event number is not filled correctly
947      Int_t currentEvent = gAlice->GetRunLoader()->GetEventNumber();
948      Int_t newEvent     = currentEvent + delta;
949      gAlice->GetEvent(newEvent);
950      cout<<"AliDisplay::ShowNextEvent: delta = "<<delta
951          <<"  currentEvent = "<<currentEvent
952          <<"  newEvent = "<<newEvent<<endl;
953    }
954   LoadPoints();
955   fPad->cd(); 
956   Draw();
957 }
958
959 //______________________________________________________________________________
960 void AliDisplay::UnZoom()
961 {
962   //
963   // Resets ZOOM 
964   //
965   if (fZooms <= 0) return;
966   fZooms--;
967   TPad *pad = dynamic_cast<TPad*>(gPad->GetPadSave());
968   pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);
969   pad->Modified();
970 }
971
972 //_____________________________________________________________________________
973 AliDisplay & AliDisplay::operator=(const AliDisplay &disp)
974 {
975   //
976   // Assignment operator
977   //
978   disp.Copy(*this);
979   return (*this);
980 }