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