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