1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.10 2000/10/02 21:28:14 fca
19 Removal of useless dependecies via forward declarations
21 Revision 1.9 2000/07/13 16:19:09 fca
22 Mainly coding conventions + some small bug fixes
24 Revision 1.8 2000/07/11 18:24:59 fca
25 Coding convention corrections + few minor bug fixes
27 Revision 1.7 1999/11/10 07:37:06 fca
28 Pads do not inherit editability from canvas any more
30 Revision 1.6 1999/11/09 07:38:52 fca
31 Changes for compatibility with version 2.23 of ROOT
33 Revision 1.5 1999/09/29 09:24:29 fca
34 Introduction of the Copyright and cvs Log
39 //////////////////////////////////////////////////////////////////////////
43 // Utility class to display ALICE outline, tracks, hits,.. //
45 //////////////////////////////////////////////////////////////////////////
51 #include <TPaveLabel.h>
52 #include <TPaveText.h>
56 #include <TSliderBox.h>
58 #include <TVirtualX.h>
62 #include "AliDetector.h"
63 #include "AliDisplay.h"
64 #include "AliPoints.h"
65 #include "TParticle.h"
66 #include "TGeometry.h"
68 static const Float_t kptcutmax = 2;
69 static const Float_t ketacutmax = 1.5;
74 //_____________________________________________________________________________
75 AliDisplay::AliDisplay()
78 // Default constructor
83 //_____________________________________________________________________________
84 AliDisplay::AliDisplay(Int_t size)
86 // Create an event display object.
87 // A canvas named "edisplay" is created with a vertical size in pixels
89 // A QUICK Overview of the Event Display functions
90 // ===============================================
92 // The event display can ve invoked by executing the macro "display.C"
93 // A canvas like in the picture below will appear.
95 // On the left side of the canvas, the following buttons appear:
96 // *Next* to move to the next event
97 // *Previous* to move to the previous event
98 // *Top View* to display a top view of the current event
99 // *Side View* to display a side view of the current event
100 // *Front View* to display a front view of the current event
101 // *All Views* to display front/side/top/30-30 views of the current event
102 // *OpenGL* to use OpenGl to view the current event.
103 // Note that OpenGL cannot be used across the network.
104 // Before using OpenGL, load the GL libraries
105 // by executing the macro GL.C (in $ROOTSYS/macros/GL.C.
106 // Once in GL, click the HELP button of the GL canvas.
107 // *X3D* to use X3D to view the current event (Unix only).
108 // Once in X3D, type M to see the list of all possible options.
109 // for example type J to zoom, K to unzoom
110 // use the mouse to rotate.
111 // *Pick* Select this option to be able to point on a track with the
112 // mouse. Once on the track, use the right button to select
113 // an action. For example, select SetMarkerAttributes to
114 // change the marker type/color/size for the track.
115 // *Zoom* Select this option (default) if you want to zoom.
116 // To zoom, simply select the selected area with the left button.
117 // *UnZoom* To revert to the previous picture size.
119 // slider R On the left side, the vertical slider can be used to
120 // set the default picture size.
121 // slider pcut At the top of the canvas, a slider can be used to change
122 // the momentum cut (or range) to display tracks.
123 // slider eta On the right side of the canvas, a vertical slider can be used
124 // to specify a rapidity range for the tracks.
126 // When you are in Zoom mode, you can click on the black part of the canvas
127 // to select special options with the right mouse button.
128 // This will display a pop-up menu with items like:
129 // *Disable detector*
130 // *Enable detector*, etc.
131 // For example select "Disable detector". You get a dialog box.
132 // Diable detector TRD for example.
134 // When you are in pick mode, you can "Inspect" the object pointed by the mouse.
135 // When you are on a track, select the menu item "InspectParticle"
136 // to display the current particle attributes.
138 // You can activate the Root browser by selecting the Inspect menu
139 // in the canvas tool bar menu. Then select "Start Browser"
140 // This will open a new canvas with the browser. At this point, you may want
141 // to display some histograms (from the Trees). Go to the "File" menu
142 // of the browser and click on "New canvas".
143 // In the browser, click on item "ROOT files" in the left pane.
144 // Click on galice.root.
146 // Click on TPC for example
147 // Click on any variable (eg TPC.fX) to histogram the variable.
149 // If you are lost, you can click on HELP in any Root canvas or browser.
152 <img src="picts/alidisplay.gif">
157 gAlice->SetDisplay(this);
159 // Initialize display default parameters
163 // Set front view by default
167 fDrawAllViews = kFALSE;
169 fDrawParticles = kTRUE;
174 // Create display canvas
176 if (ysize < 100) ysize = 750;
177 Int_t xsize = Int_t(size*830./ysize);
178 fCanvas = new TCanvas("Canvas", "ALICE Event Display",14,47,xsize,ysize);
179 fCanvas->ToggleEventStatus();
181 // Create main display pad
182 fPad = new TPad("viewpad", "Alice display",0.15,0,0.97,0.96);
185 fPad->SetFillColor(1);
186 fPad->SetBorderSize(2);
188 // Create user interface control pad
192 // Create Range and mode pad
195 fTrigPad = new TPad("trigger", "range and mode pad",0,0,dxtr,dytr);
196 fTrigPad->SetEditable(kFALSE);
199 fTrigPad->SetFillColor(22);
200 fTrigPad->SetBorderSize(2);
201 fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
202 fRangeSlider->SetObject(this);
203 char pickmode[] = "gAlice->Display()->SetPickMode()";
205 fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
206 fPickButton->SetFillColor(38);
208 char zoommode[] = "gAlice->Display()->SetZoomMode()";
209 fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
210 fZoomButton->SetFillColor(38);
212 fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
213 fArcButton->SetFillColor(kGreen);
215 char butUnzoom[] = "gAlice->Display()->UnZoom()";
216 TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
217 button->SetFillColor(38);
219 AppendPad(); // append display object as last object to force selection
221 // Create momentum cut slider pad
223 fCutPad = new TPad("cutSlider", "pcut slider pad",dxtr,.96,1,1);
226 fCutPad->SetFillColor(22);
227 fCutPad->SetBorderSize(2);
228 fCutSlider = new TSlider("pcut","Momentum cut",0,0,1,1);
229 fCutSlider->SetRange(fPTcut/kptcutmax,1);
230 fCutSlider->SetObject(this);
231 fCutSlider->SetFillColor(45);
232 TSliderBox *sbox = (TSliderBox*)fCutSlider->GetListOfPrimitives()->First();
233 sbox->SetFillColor(46);
235 TGaxis *cutaxis = new TGaxis(0.02,0.8,0.98,0.8,0,kptcutmax,510,"");
236 cutaxis->SetLabelSize(0.5);
237 cutaxis->SetTitleSize(0.6);
238 cutaxis->SetTitleOffset(0.5);
239 cutaxis->SetTitle("pcut . ");
240 fCutSlider->GetListOfPrimitives()->AddFirst(cutaxis);
242 // Create rapidity cut slider pad
244 fEtaPad = new TPad("EtaSlider", "Eta slider pad",0.97,0,1,0.96);
247 fEtaPad->SetFillColor(22);
248 fEtaPad->SetBorderSize(2);
249 fEtaSlider = new TSlider("etacut","Rapidity cut",0,0,1,1);
250 fEtaSlider->SetObject(this);
251 fEtaSlider->SetFillColor(45);
252 TSliderBox *sbox2 = (TSliderBox*)fEtaSlider->GetListOfPrimitives()->First();
253 sbox2->SetFillColor(46);
255 TGaxis *etaaxis = new TGaxis(0.9,0.02,0.9,0.98,-ketacutmax,ketacutmax,510,"");
256 etaaxis->SetLabelSize(0.5);
257 etaaxis->SetTitleSize(0.6);
258 etaaxis->SetTitleOffset(0.2);
259 cutaxis->SetTitle("Etacut . ");
260 fEtaSlider->GetListOfPrimitives()->AddFirst(etaaxis);
269 //_____________________________________________________________________________
270 AliDisplay::AliDisplay(const AliDisplay &disp)
278 //_____________________________________________________________________________
279 AliDisplay::~AliDisplay()
286 //_____________________________________________________________________________
287 void AliDisplay::Clear(Option_t *)
289 // Delete graphics temporary objects
292 //_____________________________________________________________________________
293 void AliDisplay::Copy(AliDisplay &disp) const
296 // Copy *this onto disp -- not implemented
298 Fatal("Copy","Not implemented~\n");
301 //----------------------------------------------------------------------------
302 void AliDisplay::ShowTrack(Int_t idx) {
303 AliDetector *mTPC=(AliDetector*)gAlice->GetModule("TPC");
304 TObjArray *points=mTPC->Points();
305 int ntracks=points->GetEntriesFast();
306 for (int track=0;track<ntracks;track++) {
307 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
309 if (idx == pm->GetIndex()) {
310 pm->SetMarkerColor(2);
311 pm->SetMarkerStyle(22);
315 TClonesArray *particles=gAlice->Particles();
316 TParticle *p = (TParticle*)particles->UncheckedAt(idx);
317 printf("\nTrack index %d\n",idx);
318 printf("Particle ID %d\n",p->GetPdgCode());
319 printf("Parent %d\n",p->GetFirstMother());
320 printf("First child %d\n",p->GetFirstDaughter());
321 printf("Px,Py,Pz %f %f %f\n",p->Px(),p->Py(),p->Pz());
327 //----------------------------------------------------------------------------
328 void AliDisplay::HideTrack(Int_t idx) {
330 // Hide track on display
332 AliDetector *mTPC=(AliDetector*)gAlice->GetModule("TPC");
333 TObjArray *points=mTPC->Points();
334 int ntracks=points->GetEntriesFast();
335 for (int track=0;track<ntracks;track++) {
336 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
338 if (idx == pm->GetIndex()) {
339 pm->SetMarkerColor(5);
340 pm->SetMarkerStyle(1);
349 //_____________________________________________________________________________
350 void AliDisplay::DisableDetector(const char *name)
352 // Disable detector name from graphics views
354 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
360 //_____________________________________________________________________________
361 void AliDisplay::DisplayButtons()
363 // Create the user interface buttons
365 fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
366 fButtons->SetEditable(kFALSE);
368 fButtons->SetFillColor(38);
369 fButtons->SetBorderSize(2);
373 Float_t dbutton = 0.08;
380 char but1[] = "gAlice->Display()->ShowNextEvent(1)";
381 button = new TButton("Next",but1,x0,y-dbutton,x1,y);
382 button->SetFillColor(38);
386 char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
387 button = new TButton("Previous",but2,x0,y-dbutton,x1,y);
388 button->SetFillColor(38);
392 char but3[] = "gAlice->Display()->SetView(90,-90,90)";
393 button = new TButton("Top View",but3,x0,y-dbutton,x1,y);
394 button->SetFillColor(butcolor);
398 char but4[] = "gAlice->Display()->SetView(90,0,-90)";
399 button = new TButton("Side View",but4,x0,y-dbutton,x1,y);
400 button->SetFillColor(butcolor);
404 char but5[] = "gAlice->Display()->SetView(0,-90,0)";
405 button = new TButton("Front View",but5,x0,y-dbutton,x1,y);
406 button->SetFillColor(butcolor);
410 char but6[] = "gAlice->Display()->DrawAllViews()";
411 button = new TButton("All Views",but6,x0,y-dbutton,x1,y);
412 button->SetFillColor(butcolor);
416 char but7[] = "gAlice->Display()->DrawViewGL()";
417 button = new TButton("OpenGL",but7,x0,y-dbutton,x1,y);
418 button->SetFillColor(38);
422 char but8[] = "gAlice->Display()->DrawViewX3D()";
423 button = new TButton("X3D",but8,x0,y-dbutton,x1,y);
424 button->SetFillColor(38);
428 TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
429 diamond->SetFillColor(50);
430 diamond->SetTextAlign(22);
431 diamond->SetTextColor(5);
432 diamond->SetTextSize(0.11);
434 diamond->AddText(".. ");
435 diamond->AddText("ROOT");
436 diamond->AddText("ALICE");
437 diamond->AddText("... ");
438 diamond->AddText(" ");
441 //______________________________________________________________________________
442 Int_t AliDisplay::DistancetoPrimitive(Int_t px, Int_t)
444 // Compute distance from point px,py to objects in event
446 gPad->SetCursor(kCross);
448 if (gPad == fTrigPad) return 9999;
449 if (gPad == fCutPad) return 9999;
450 if (gPad == fEtaPad) return 9999;
452 const Int_t kbig = 9999;
454 Float_t xmin = gPad->GetX1();
455 Float_t xmax = gPad->GetX2();
456 Float_t dx = 0.02*(xmax - xmin);
457 Float_t x = gPad->AbsPixeltoX(px);
458 if (x < xmin+dx || x > xmax-dx) return dist;
460 if (fZoomMode) return 0;
464 //_____________________________________________________________________________
465 void AliDisplay::Draw(Option_t *)
467 // Display current event
476 DrawView(fTheta, fPhi, fPsi);
478 // Display the event number and title
483 //_____________________________________________________________________________
484 void AliDisplay::DrawAllViews()
486 // Draw front,top,side and 30 deg views
488 fDrawAllViews = kTRUE;
490 fPad->SetFillColor(15);
506 DrawView(90, -90, 90);
511 DrawView(90, 0, -90);
517 //_____________________________________________________________________________
518 void AliDisplay::DrawHits()
520 // Draw hits for all ALICE detectors
522 Float_t cutmin, cutmax, etamin, etamax, pmom, smin, smax, eta, theta, r;
530 smax = fCutSlider->GetMaximum();
531 smin = fCutSlider->GetMinimum();
532 cutmin = kptcutmax*smin;
533 if (smax < 0.98) cutmax = kptcutmax*smax;
534 else cutmax = 100000;
537 smax = fEtaSlider->GetMaximum();
538 smin = fEtaSlider->GetMinimum();
539 etamin = ketacutmax*(2*smin-1);
540 etamax = ketacutmax*(2*smax-1);
541 if (smin < 0.02) etamin = -1000;
542 if (smax > 0.98) etamax = 1000;
544 TIter next(gAlice->Modules());
547 while((module = (AliModule*)next())) {
548 if (!module->IsActive()) continue;
549 points = module->Points();
550 if (!points) continue;
551 ntracks = points->GetEntriesFast();
552 for (track=0;track<ntracks;track++) {
553 pm = (AliPoints*)points->UncheckedAt(track);
555 particle = pm->GetParticle();
556 if (!particle) continue;
557 pmom = particle->P();
558 if (pmom < cutmin) continue;
559 if (pmom > cutmax) continue;
560 // as a first approximation, take eta of first point
562 r = TMath::Sqrt(pxyz[0]*pxyz[0] + pxyz[1]*pxyz[1]);
563 theta = TMath::ATan2(r,TMath::Abs(pxyz[2]));
564 if(theta) eta = -TMath::Log(TMath::Tan(0.5*theta)); else eta = 1e10;
565 if (pxyz[2] < 0) eta = -eta;
566 if (eta < etamin || eta > etamax) continue;
568 fHitsCuts += pm->GetN();
573 //_____________________________________________________________________________
574 void AliDisplay::DrawTitle(Option_t *option)
576 // Draw the event title
578 Float_t xmin = gPad->GetX1();
579 Float_t xmax = gPad->GetX2();
580 Float_t ymin = gPad->GetY1();
581 Float_t ymax = gPad->GetY2();
582 Float_t dx = xmax-xmin;
583 Float_t dy = ymax-ymin;
585 if (strlen(option) == 0) {
586 TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
587 title->SetBit(kCanDelete);
588 title->SetFillColor(42);
591 sprintf(ptitle,"Alice event: %d, Run:%d",gAlice->GetHeader()->GetEvent(), gAlice->GetHeader()->GetRun());
592 title->AddText(ptitle);
593 Int_t nparticles = gAlice->Particles()->GetEntriesFast();
594 sprintf(ptitle,"Nparticles = %d Nhits = %d",nparticles, fHitsCuts);
595 title->AddText(ptitle);
597 TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
598 label->SetBit(kCanDelete);
599 label->SetFillColor(42);
604 //_____________________________________________________________________________
605 void AliDisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
607 // Draw a view of ALICE
609 gPad->SetCursor(kWatch);
610 gPad->SetFillColor(1);
614 TView *view = new TView(1);
615 Float_t range = fRrange*fRangeSlider->GetMaximum();
616 view->SetRange(-range,-range,-range,range, range, range);
623 // Display Alice Geometry
624 gAlice->GetGeometry()->Draw("same");
626 //Loop on all detectors to add their products to the pad
629 // add itself to the list (must be last)
632 view->SetView(phi, theta, psi, iret);
635 //_____________________________________________________________________________
636 void AliDisplay::DrawViewGL()
638 // Draw current view using OPENGL
640 TPad *pad = (TPad*)gPad->GetPadSave();
642 TView *view = pad->GetView();
647 //_____________________________________________________________________________
648 void AliDisplay::DrawViewX3D()
650 // Draw current view using X3D
652 TPad *pad = (TPad*)gPad->GetPadSave();
654 TView *view = pad->GetView();
659 //_____________________________________________________________________________
660 void AliDisplay::EnableDetector(const char *name)
662 // Enable detector name in graphics views
664 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
670 //______________________________________________________________________________
671 void AliDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
673 // Execute action corresponding to the mouse event
675 static Float_t x0, y0, x1, y1;
677 static Int_t pxold, pyold;
678 static Int_t px0, py0;
679 static Int_t linedrawn;
682 if (px == 0 && py == 0) { //when called by sliders
683 if (event == kButton1Up) {
688 if (!fZoomMode && gPad->GetView()) {
689 gPad->GetView()->ExecuteRotateView(event, px, py);
693 // something to zoom ?
694 // fPad->SetCursor(kCross);
695 gPad->SetCursor(kCross);
700 gVirtualX->SetLineColor(-1);
701 gPad->TAttLine::Modify(); //Change line attributes only if necessary
702 x0 = gPad->AbsPixeltoX(px);
703 y0 = gPad->AbsPixeltoY(py);
705 pxold = px; pyold = py;
710 if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
714 gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
718 gPad->GetCanvas()->FeedbackMode(kFALSE);
719 if (px == px0) return;
720 if (py == py0) return;
721 x1 = gPad->AbsPixeltoX(px);
722 y1 = gPad->AbsPixeltoY(py);
724 if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
725 if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
726 gPad->Range(x0,y0,x1,y1);
727 if (fZooms < kMAXZOOMS-1) {
729 fZoomX0[fZooms] = x0;
730 fZoomY0[fZooms] = y0;
731 fZoomX1[fZooms] = x1;
732 fZoomY1[fZooms] = y1;
734 gPad->Modified(kTRUE);
740 //___________________________________________
741 void AliDisplay::LoadPoints()
743 // Read hits info and store x,y,z info in arrays fPoints
744 // Loop on all detectors
746 gAlice->ResetPoints();
747 TIter next(gAlice->Modules());
749 Int_t ntracks = gAlice->GetNtrack();
750 for (Int_t track=0; track<ntracks;track++) {
752 gAlice->TreeH()->GetEvent(track);
753 while((module = (AliModule*)next())) {
754 module->LoadPoints(track);
760 //_____________________________________________________________________________
761 void AliDisplay::Paint(Option_t *)
763 // Paint miscellaneous items
767 //_____________________________________________________________________________
768 void AliDisplay::SetPickMode()
771 // Set Pick Mode -- disable zoom
775 fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
776 fTrigPad->Modified();
779 //_____________________________________________________________________________
780 void AliDisplay::SetZoomMode()
783 // Set Zoom Mode -- disable pick
787 fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
788 fTrigPad->Modified();
791 //_____________________________________________________________________________
792 void AliDisplay::SetPTcut(Float_t ptcut)
804 //_____________________________________________________________________________
805 void AliDisplay::SetRange(Float_t rrange, Float_t zrange)
807 // Set view range along R and Z
816 //_____________________________________________________________________________
817 void AliDisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
819 // change viewing angles for current event
822 fDrawAllViews = kFALSE;
828 TView *view = gPad->GetView();
829 if (view) view->SetView(fPhi, fTheta, fPsi, iret);
835 //_____________________________________________________________________________
836 void AliDisplay::ShowNextEvent(Int_t delta)
838 // Display (current event_number+delta)
839 // delta = 1 shown next event
840 // delta = -1 show previous event
844 Int_t currentEvent = gAlice->GetHeader()->GetEvent();
845 Int_t newEvent = currentEvent + delta;
846 gAlice->GetEvent(newEvent);
847 if (!gAlice->TreeH()) return;
854 //______________________________________________________________________________
855 void AliDisplay::UnZoom()
860 if (fZooms <= 0) return;
862 TPad *pad = (TPad*)gPad->GetPadSave();
863 pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);
867 //_____________________________________________________________________________
868 AliDisplay & AliDisplay::operator=(const AliDisplay &disp)
871 // Assignment operator