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.13 2000/12/21 15:30:18 fca
19 Correcting coding convention violations
21 Revision 1.12 2000/12/12 13:18:59 hristov
22 Protection against FPE
24 Revision 1.11 2000/11/30 07:12:48 alibrary
25 Introducing new Rndm and QA classes
27 Revision 1.10 2000/10/02 21:28:14 fca
28 Removal of useless dependecies via forward declarations
30 Revision 1.9 2000/07/13 16:19:09 fca
31 Mainly coding conventions + some small bug fixes
33 Revision 1.8 2000/07/11 18:24:59 fca
34 Coding convention corrections + few minor bug fixes
36 Revision 1.7 1999/11/10 07:37:06 fca
37 Pads do not inherit editability from canvas any more
39 Revision 1.6 1999/11/09 07:38:52 fca
40 Changes for compatibility with version 2.23 of ROOT
42 Revision 1.5 1999/09/29 09:24:29 fca
43 Introduction of the Copyright and cvs Log
48 //////////////////////////////////////////////////////////////////////////
52 // Utility class to display ALICE outline, tracks, hits,.. //
54 //////////////////////////////////////////////////////////////////////////
60 #include <TPaveLabel.h>
61 #include <TPaveText.h>
65 #include <TSliderBox.h>
67 #include <TVirtualX.h>
71 #include "AliDetector.h"
72 #include "AliDisplay.h"
73 #include "AliPoints.h"
74 #include "TParticle.h"
75 #include "TGeometry.h"
77 static const Float_t kptcutmax = 2;
78 static const Float_t ketacutmax = 1.5;
83 //_____________________________________________________________________________
84 AliDisplay::AliDisplay()
87 // Default constructor
92 //_____________________________________________________________________________
93 AliDisplay::AliDisplay(Int_t size)
95 // Create an event display object.
96 // A canvas named "edisplay" is created with a vertical size in pixels
98 // A QUICK Overview of the Event Display functions
99 // ===============================================
101 // The event display can ve invoked by executing the macro "display.C"
102 // A canvas like in the picture below will appear.
104 // On the left side of the canvas, the following buttons appear:
105 // *Next* to move to the next event
106 // *Previous* to move to the previous event
107 // *Top View* to display a top view of the current event
108 // *Side View* to display a side view of the current event
109 // *Front View* to display a front view of the current event
110 // *All Views* to display front/side/top/30-30 views of the current event
111 // *OpenGL* to use OpenGl to view the current event.
112 // Note that OpenGL cannot be used across the network.
113 // Before using OpenGL, load the GL libraries
114 // by executing the macro GL.C (in $ROOTSYS/macros/GL.C.
115 // Once in GL, click the HELP button of the GL canvas.
116 // *X3D* to use X3D to view the current event (Unix only).
117 // Once in X3D, type M to see the list of all possible options.
118 // for example type J to zoom, K to unzoom
119 // use the mouse to rotate.
120 // *Pick* Select this option to be able to point on a track with the
121 // mouse. Once on the track, use the right button to select
122 // an action. For example, select SetMarkerAttributes to
123 // change the marker type/color/size for the track.
124 // *Zoom* Select this option (default) if you want to zoom.
125 // To zoom, simply select the selected area with the left button.
126 // *UnZoom* To revert to the previous picture size.
128 // slider R On the left side, the vertical slider can be used to
129 // set the default picture size.
130 // slider pcut At the top of the canvas, a slider can be used to change
131 // the momentum cut (or range) to display tracks.
132 // slider eta On the right side of the canvas, a vertical slider can be used
133 // to specify a rapidity range for the tracks.
135 // When you are in Zoom mode, you can click on the black part of the canvas
136 // to select special options with the right mouse button.
137 // This will display a pop-up menu with items like:
138 // *Disable detector*
139 // *Enable detector*, etc.
140 // For example select "Disable detector". You get a dialog box.
141 // Diable detector TRD for example.
143 // When you are in pick mode, you can "Inspect" the object pointed by the mouse.
144 // When you are on a track, select the menu item "InspectParticle"
145 // to display the current particle attributes.
147 // You can activate the Root browser by selecting the Inspect menu
148 // in the canvas tool bar menu. Then select "Start Browser"
149 // This will open a new canvas with the browser. At this point, you may want
150 // to display some histograms (from the Trees). Go to the "File" menu
151 // of the browser and click on "New canvas".
152 // In the browser, click on item "ROOT files" in the left pane.
153 // Click on galice.root.
155 // Click on TPC for example
156 // Click on any variable (eg TPC.fX) to histogram the variable.
158 // If you are lost, you can click on HELP in any Root canvas or browser.
161 <img src="picts/alidisplay.gif">
166 gAlice->SetDisplay(this);
168 // Initialize display default parameters
172 // Set front view by default
176 fDrawAllViews = kFALSE;
178 fDrawParticles = kTRUE;
183 // Create display canvas
185 if (ysize < 100) ysize = 750;
186 Int_t xsize = Int_t(size*830./ysize);
187 fCanvas = new TCanvas("Canvas", "ALICE Event Display",14,47,xsize,ysize);
188 fCanvas->ToggleEventStatus();
190 // Create main display pad
191 fPad = new TPad("viewpad", "Alice display",0.15,0,0.97,0.96);
194 fPad->SetFillColor(1);
195 fPad->SetBorderSize(2);
197 // Create user interface control pad
201 // Create Range and mode pad
204 fTrigPad = new TPad("trigger", "range and mode pad",0,0,dxtr,dytr);
205 fTrigPad->SetEditable(kFALSE);
208 fTrigPad->SetFillColor(22);
209 fTrigPad->SetBorderSize(2);
210 fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
211 fRangeSlider->SetObject(this);
212 char pickmode[] = "gAlice->Display()->SetPickMode()";
214 fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
215 fPickButton->SetFillColor(38);
217 char zoommode[] = "gAlice->Display()->SetZoomMode()";
218 fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
219 fZoomButton->SetFillColor(38);
221 fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
222 fArcButton->SetFillColor(kGreen);
224 char butUnzoom[] = "gAlice->Display()->UnZoom()";
225 TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
226 button->SetFillColor(38);
228 AppendPad(); // append display object as last object to force selection
230 // Create momentum cut slider pad
232 fCutPad = new TPad("cutSlider", "pcut slider pad",dxtr,.96,1,1);
235 fCutPad->SetFillColor(22);
236 fCutPad->SetBorderSize(2);
237 fCutSlider = new TSlider("pcut","Momentum cut",0,0,1,1);
238 fCutSlider->SetRange(fPTcut/kptcutmax,1);
239 fCutSlider->SetObject(this);
240 fCutSlider->SetFillColor(45);
241 TSliderBox *sbox = (TSliderBox*)fCutSlider->GetListOfPrimitives()->First();
242 sbox->SetFillColor(46);
244 TGaxis *cutaxis = new TGaxis(0.02,0.8,0.98,0.8,0,kptcutmax,510,"");
245 cutaxis->SetLabelSize(0.5);
246 cutaxis->SetTitleSize(0.6);
247 cutaxis->SetTitleOffset(0.5);
248 cutaxis->SetTitle("pcut . ");
249 fCutSlider->GetListOfPrimitives()->AddFirst(cutaxis);
251 // Create rapidity cut slider pad
253 fEtaPad = new TPad("EtaSlider", "Eta slider pad",0.97,0,1,0.96);
256 fEtaPad->SetFillColor(22);
257 fEtaPad->SetBorderSize(2);
258 fEtaSlider = new TSlider("etacut","Rapidity cut",0,0,1,1);
259 fEtaSlider->SetObject(this);
260 fEtaSlider->SetFillColor(45);
261 TSliderBox *sbox2 = (TSliderBox*)fEtaSlider->GetListOfPrimitives()->First();
262 sbox2->SetFillColor(46);
264 TGaxis *etaaxis = new TGaxis(0.9,0.02,0.9,0.98,-ketacutmax,ketacutmax,510,"");
265 etaaxis->SetLabelSize(0.5);
266 etaaxis->SetTitleSize(0.6);
267 etaaxis->SetTitleOffset(0.2);
268 cutaxis->SetTitle("Etacut . ");
269 fEtaSlider->GetListOfPrimitives()->AddFirst(etaaxis);
278 //_____________________________________________________________________________
279 AliDisplay::AliDisplay(const AliDisplay &disp)
287 //_____________________________________________________________________________
288 AliDisplay::~AliDisplay()
295 //_____________________________________________________________________________
296 void AliDisplay::Clear(Option_t *)
298 // Delete graphics temporary objects
301 //_____________________________________________________________________________
302 void AliDisplay::Copy(AliDisplay &disp) const
305 // Copy *this onto disp -- not implemented
307 Fatal("Copy","Not implemented~\n");
310 //----------------------------------------------------------------------------
311 void AliDisplay::ShowTrack(Int_t idx)
316 AliDetector *mTPC=(AliDetector*)gAlice->GetModule("TPC");
317 TObjArray *points=mTPC->Points();
318 int ntracks=points->GetEntriesFast();
319 for (int track=0;track<ntracks;track++) {
320 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
322 if (idx == pm->GetIndex()) {
323 pm->SetMarkerColor(2);
324 pm->SetMarkerStyle(22);
328 // TClonesArray *particles=gAlice->Particles();
329 // TParticle *p = (TParticle*)particles->UncheckedAt(idx);
330 TParticle *p = gAlice->Particle(idx);
331 printf("\nTrack index %d\n",idx);
332 printf("Particle ID %d\n",p->GetPdgCode());
333 printf("Parent %d\n",p->GetFirstMother());
334 printf("First child %d\n",p->GetFirstDaughter());
335 printf("Px,Py,Pz %f %f %f\n",p->Px(),p->Py(),p->Pz());
341 //----------------------------------------------------------------------------
342 void AliDisplay::HideTrack(Int_t idx) {
344 // Hide track on display
346 AliDetector *mTPC=(AliDetector*)gAlice->GetModule("TPC");
347 TObjArray *points=mTPC->Points();
348 int ntracks=points->GetEntriesFast();
349 for (int track=0;track<ntracks;track++) {
350 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
352 if (idx == pm->GetIndex()) {
353 pm->SetMarkerColor(5);
354 pm->SetMarkerStyle(1);
363 //_____________________________________________________________________________
364 void AliDisplay::DisableDetector(const char *name)
366 // Disable detector name from graphics views
368 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
374 //_____________________________________________________________________________
375 void AliDisplay::DisplayButtons()
377 // Create the user interface buttons
379 fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
380 fButtons->SetEditable(kFALSE);
382 fButtons->SetFillColor(38);
383 fButtons->SetBorderSize(2);
387 Float_t dbutton = 0.08;
394 char but1[] = "gAlice->Display()->ShowNextEvent(1)";
395 button = new TButton("Next",but1,x0,y-dbutton,x1,y);
396 button->SetFillColor(38);
400 char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
401 button = new TButton("Previous",but2,x0,y-dbutton,x1,y);
402 button->SetFillColor(38);
406 char but3[] = "gAlice->Display()->SetView(90,-90,90)";
407 button = new TButton("Top View",but3,x0,y-dbutton,x1,y);
408 button->SetFillColor(butcolor);
412 char but4[] = "gAlice->Display()->SetView(90,0,-90)";
413 button = new TButton("Side View",but4,x0,y-dbutton,x1,y);
414 button->SetFillColor(butcolor);
418 char but5[] = "gAlice->Display()->SetView(0,-90,0)";
419 button = new TButton("Front View",but5,x0,y-dbutton,x1,y);
420 button->SetFillColor(butcolor);
424 char but6[] = "gAlice->Display()->DrawAllViews()";
425 button = new TButton("All Views",but6,x0,y-dbutton,x1,y);
426 button->SetFillColor(butcolor);
430 char but7[] = "gAlice->Display()->DrawViewGL()";
431 button = new TButton("OpenGL",but7,x0,y-dbutton,x1,y);
432 button->SetFillColor(38);
436 char but8[] = "gAlice->Display()->DrawViewX3D()";
437 button = new TButton("X3D",but8,x0,y-dbutton,x1,y);
438 button->SetFillColor(38);
442 TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
443 diamond->SetFillColor(50);
444 diamond->SetTextAlign(22);
445 diamond->SetTextColor(5);
446 diamond->SetTextSize(0.11);
448 diamond->AddText(".. ");
449 diamond->AddText("ROOT");
450 diamond->AddText("ALICE");
451 diamond->AddText("... ");
452 diamond->AddText(" ");
455 //______________________________________________________________________________
456 Int_t AliDisplay::DistancetoPrimitive(Int_t px, Int_t)
458 // Compute distance from point px,py to objects in event
460 gPad->SetCursor(kCross);
462 if (gPad == fTrigPad) return 9999;
463 if (gPad == fCutPad) return 9999;
464 if (gPad == fEtaPad) return 9999;
466 const Int_t kbig = 9999;
468 Float_t xmin = gPad->GetX1();
469 Float_t xmax = gPad->GetX2();
470 Float_t dx = 0.02*(xmax - xmin);
471 Float_t x = gPad->AbsPixeltoX(px);
472 if (x < xmin+dx || x > xmax-dx) return dist;
474 if (fZoomMode) return 0;
478 //_____________________________________________________________________________
479 void AliDisplay::Draw(Option_t *)
481 // Display current event
490 DrawView(fTheta, fPhi, fPsi);
492 // Display the event number and title
497 //_____________________________________________________________________________
498 void AliDisplay::DrawAllViews()
500 // Draw front,top,side and 30 deg views
502 fDrawAllViews = kTRUE;
504 fPad->SetFillColor(15);
520 DrawView(90, -90, 90);
525 DrawView(90, 0, -90);
531 //_____________________________________________________________________________
532 void AliDisplay::DrawHits()
534 // Draw hits for all ALICE detectors
536 Float_t cutmin, cutmax, etamin, etamax, pmom, smin, smax, eta, theta, r;
544 smax = fCutSlider->GetMaximum();
545 smin = fCutSlider->GetMinimum();
546 cutmin = kptcutmax*smin;
547 if (smax < 0.98) cutmax = kptcutmax*smax;
548 else cutmax = 100000;
551 smax = fEtaSlider->GetMaximum();
552 smin = fEtaSlider->GetMinimum();
553 etamin = ketacutmax*(2*smin-1);
554 etamax = ketacutmax*(2*smax-1);
555 if (smin < 0.02) etamin = -1000;
556 if (smax > 0.98) etamax = 1000;
558 TIter next(gAlice->Modules());
561 while((module = (AliModule*)next())) {
562 if (!module->IsActive()) continue;
563 points = module->Points();
564 if (!points) continue;
565 ntracks = points->GetEntriesFast();
566 for (track=0;track<ntracks;track++) {
567 pm = (AliPoints*)points->UncheckedAt(track);
569 particle = pm->GetParticle();
570 if (!particle) continue;
571 pmom = particle->P();
572 if (pmom < cutmin) continue;
573 if (pmom > cutmax) continue;
574 // as a first approximation, take eta of first point
576 r = TMath::Sqrt(pxyz[0]*pxyz[0] + pxyz[1]*pxyz[1]);
577 theta = TMath::ATan2(r,TMath::Abs(pxyz[2]));
578 if(theta) eta = -TMath::Log(TMath::Abs(TMath::Tan(0.5*theta))); else eta = 1e10;
579 if (pxyz[2] < 0) eta = -eta;
580 if (eta < etamin || eta > etamax) continue;
582 fHitsCuts += pm->GetN();
587 //_____________________________________________________________________________
588 void AliDisplay::DrawTitle(Option_t *option)
590 // Draw the event title
592 Float_t xmin = gPad->GetX1();
593 Float_t xmax = gPad->GetX2();
594 Float_t ymin = gPad->GetY1();
595 Float_t ymax = gPad->GetY2();
596 Float_t dx = xmax-xmin;
597 Float_t dy = ymax-ymin;
599 if (strlen(option) == 0) {
600 TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
601 title->SetBit(kCanDelete);
602 title->SetFillColor(42);
605 sprintf(ptitle,"Alice event: %d, Run:%d",gAlice->GetHeader()->GetEvent(), gAlice->GetHeader()->GetRun());
606 title->AddText(ptitle);
607 Int_t nparticles = gAlice->Particles()->GetEntriesFast();
608 sprintf(ptitle,"Nparticles = %d Nhits = %d",nparticles, fHitsCuts);
609 title->AddText(ptitle);
611 TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
612 label->SetBit(kCanDelete);
613 label->SetFillColor(42);
618 //_____________________________________________________________________________
619 void AliDisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
621 // Draw a view of ALICE
623 gPad->SetCursor(kWatch);
624 gPad->SetFillColor(1);
628 TView *view = new TView(1);
629 Float_t range = fRrange*fRangeSlider->GetMaximum();
630 view->SetRange(-range,-range,-range,range, range, range);
637 // Display Alice Geometry
638 gAlice->GetGeometry()->Draw("same");
640 //Loop on all detectors to add their products to the pad
643 // add itself to the list (must be last)
646 view->SetView(phi, theta, psi, iret);
649 //_____________________________________________________________________________
650 void AliDisplay::DrawViewGL()
652 // Draw current view using OPENGL
654 TPad *pad = (TPad*)gPad->GetPadSave();
656 TView *view = pad->GetView();
661 //_____________________________________________________________________________
662 void AliDisplay::DrawViewX3D()
664 // Draw current view using X3D
666 TPad *pad = (TPad*)gPad->GetPadSave();
668 TView *view = pad->GetView();
673 //_____________________________________________________________________________
674 void AliDisplay::EnableDetector(const char *name)
676 // Enable detector name in graphics views
678 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
684 //______________________________________________________________________________
685 void AliDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
687 // Execute action corresponding to the mouse event
689 static Float_t x0, y0, x1, y1;
691 static Int_t pxold, pyold;
692 static Int_t px0, py0;
693 static Int_t linedrawn;
696 if (px == 0 && py == 0) { //when called by sliders
697 if (event == kButton1Up) {
702 if (!fZoomMode && gPad->GetView()) {
703 gPad->GetView()->ExecuteRotateView(event, px, py);
707 // something to zoom ?
708 // fPad->SetCursor(kCross);
709 gPad->SetCursor(kCross);
714 gVirtualX->SetLineColor(-1);
715 gPad->TAttLine::Modify(); //Change line attributes only if necessary
716 x0 = gPad->AbsPixeltoX(px);
717 y0 = gPad->AbsPixeltoY(py);
719 pxold = px; pyold = py;
724 if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
728 gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
732 gPad->GetCanvas()->FeedbackMode(kFALSE);
733 if (px == px0) return;
734 if (py == py0) return;
735 x1 = gPad->AbsPixeltoX(px);
736 y1 = gPad->AbsPixeltoY(py);
738 if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
739 if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
740 gPad->Range(x0,y0,x1,y1);
741 if (fZooms < kMAXZOOMS-1) {
743 fZoomX0[fZooms] = x0;
744 fZoomY0[fZooms] = y0;
745 fZoomX1[fZooms] = x1;
746 fZoomY1[fZooms] = y1;
748 gPad->Modified(kTRUE);
754 //___________________________________________
755 void AliDisplay::LoadPoints()
757 // Read hits info and store x,y,z info in arrays fPoints
758 // Loop on all detectors
760 gAlice->ResetPoints();
761 TIter next(gAlice->Modules());
763 Int_t ntracks = gAlice->GetNtrack();
764 for (Int_t track=0; track<ntracks;track++) {
766 gAlice->TreeH()->GetEvent(track);
767 while((module = (AliModule*)next())) {
768 module->LoadPoints(track);
774 //_____________________________________________________________________________
775 void AliDisplay::Paint(Option_t *)
777 // Paint miscellaneous items
781 //_____________________________________________________________________________
782 void AliDisplay::SetPickMode()
785 // Set Pick Mode -- disable zoom
789 fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
790 fTrigPad->Modified();
793 //_____________________________________________________________________________
794 void AliDisplay::SetZoomMode()
797 // Set Zoom Mode -- disable pick
801 fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
802 fTrigPad->Modified();
805 //_____________________________________________________________________________
806 void AliDisplay::SetPTcut(Float_t ptcut)
818 //_____________________________________________________________________________
819 void AliDisplay::SetRange(Float_t rrange, Float_t zrange)
821 // Set view range along R and Z
830 //_____________________________________________________________________________
831 void AliDisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
833 // change viewing angles for current event
836 fDrawAllViews = kFALSE;
842 TView *view = gPad->GetView();
843 if (view) view->SetView(fPhi, fTheta, fPsi, iret);
849 //_____________________________________________________________________________
850 void AliDisplay::ShowNextEvent(Int_t delta)
852 // Display (current event_number+delta)
853 // delta = 1 shown next event
854 // delta = -1 show previous event
858 Int_t currentEvent = gAlice->GetHeader()->GetEvent();
859 Int_t newEvent = currentEvent + delta;
860 gAlice->GetEvent(newEvent);
861 if (!gAlice->TreeH()) return;
868 //______________________________________________________________________________
869 void AliDisplay::UnZoom()
874 if (fZooms <= 0) return;
876 TPad *pad = (TPad*)gPad->GetPadSave();
877 pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);
881 //_____________________________________________________________________________
882 AliDisplay & AliDisplay::operator=(const AliDisplay &disp)
885 // Assignment operator