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