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