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