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