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.7 1999/11/10 07:37:06 fca
19 Pads do not inherit editability from canvas any more
21 Revision 1.6 1999/11/09 07:38:52 fca
22 Changes for compatibility with version 2.23 of ROOT
24 Revision 1.5 1999/09/29 09:24:29 fca
25 Introduction of the Copyright and cvs Log
30 //////////////////////////////////////////////////////////////////////////
34 // Utility class to display ALICE outline, tracks, hits,.. //
36 //////////////////////////////////////////////////////////////////////////
44 #include <TPolyMarker3D.h>
45 #include <TPaveLabel.h>
46 #include <TPaveText.h>
53 #include <TSliderBox.h>
55 #include <TVirtualX.h>
57 #include <X3DBuffer.h>
60 #include "AliDetector.h"
61 #include "AliDisplay.h"
62 #include "AliPoints.h"
63 #include "TParticle.h"
65 static const Float_t kptcutmax = 2;
66 static const Float_t ketacutmax = 1.5;
71 //_____________________________________________________________________________
72 AliDisplay::AliDisplay()
75 // Default constructor
80 //_____________________________________________________________________________
81 AliDisplay::AliDisplay(Int_t size)
83 // Create an event display object.
84 // A canvas named "edisplay" is created with a vertical size in pixels
86 // A QUICK Overview of the Event Display functions
87 // ===============================================
89 // The event display can ve invoked by executing the macro "display.C"
90 // A canvas like in the picture below will appear.
92 // On the left side of the canvas, the following buttons appear:
93 // *Next* to move to the next event
94 // *Previous* to move to the previous event
95 // *Top View* to display a top view of the current event
96 // *Side View* to display a side view of the current event
97 // *Front View* to display a front view of the current event
98 // *All Views* to display front/side/top/30-30 views of the current event
99 // *OpenGL* to use OpenGl to view the current event.
100 // Note that OpenGL cannot be used across the network.
101 // Before using OpenGL, load the GL libraries
102 // by executing the macro GL.C (in $ROOTSYS/macros/GL.C.
103 // Once in GL, click the HELP button of the GL canvas.
104 // *X3D* to use X3D to view the current event (Unix only).
105 // Once in X3D, type M to see the list of all possible options.
106 // for example type J to zoom, K to unzoom
107 // use the mouse to rotate.
108 // *Pick* Select this option to be able to point on a track with the
109 // mouse. Once on the track, use the right button to select
110 // an action. For example, select SetMarkerAttributes to
111 // change the marker type/color/size for the track.
112 // *Zoom* Select this option (default) if you want to zoom.
113 // To zoom, simply select the selected area with the left button.
114 // *UnZoom* To revert to the previous picture size.
116 // slider R On the left side, the vertical slider can be used to
117 // set the default picture size.
118 // slider pcut At the top of the canvas, a slider can be used to change
119 // the momentum cut (or range) to display tracks.
120 // slider eta On the right side of the canvas, a vertical slider can be used
121 // to specify a rapidity range for the tracks.
123 // When you are in Zoom mode, you can click on the black part of the canvas
124 // to select special options with the right mouse button.
125 // This will display a pop-up menu with items like:
126 // *Disable detector*
127 // *Enable detector*, etc.
128 // For example select "Disable detector". You get a dialog box.
129 // Diable detector TRD for example.
131 // When you are in pick mode, you can "Inspect" the object pointed by the mouse.
132 // When you are on a track, select the menu item "InspectParticle"
133 // to display the current particle attributes.
135 // You can activate the Root browser by selecting the Inspect menu
136 // in the canvas tool bar menu. Then select "Start Browser"
137 // This will open a new canvas with the browser. At this point, you may want
138 // to display some histograms (from the Trees). Go to the "File" menu
139 // of the browser and click on "New canvas".
140 // In the browser, click on item "ROOT files" in the left pane.
141 // Click on galice.root.
143 // Click on TPC for example
144 // Click on any variable (eg TPC.fX) to histogram the variable.
146 // If you are lost, you can click on HELP in any Root canvas or browser.
149 <img src="picts/alidisplay.gif">
154 gAlice->SetDisplay(this);
156 // Initialize display default parameters
160 // Set front view by default
164 fDrawAllViews = kFALSE;
166 fDrawParticles = kTRUE;
171 // Create display canvas
173 if (ysize < 100) ysize = 750;
174 Int_t xsize = Int_t(size*830./ysize);
175 fCanvas = new TCanvas("Canvas", "ALICE Event Display",14,47,xsize,ysize);
176 fCanvas->ToggleEventStatus();
178 // Create main display pad
179 fPad = new TPad("viewpad", "Alice display",0.15,0,0.97,0.96);
182 fPad->SetFillColor(1);
183 fPad->SetBorderSize(2);
185 // Create user interface control pad
189 // Create Range and mode pad
192 fTrigPad = new TPad("trigger", "range and mode pad",0,0,dxtr,dytr);
193 fTrigPad->SetEditable(kFALSE);
196 fTrigPad->SetFillColor(22);
197 fTrigPad->SetBorderSize(2);
198 fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
199 fRangeSlider->SetObject(this);
200 char pickmode[] = "gAlice->Display()->SetPickMode()";
202 fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
203 fPickButton->SetFillColor(38);
205 char zoommode[] = "gAlice->Display()->SetZoomMode()";
206 fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
207 fZoomButton->SetFillColor(38);
209 fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
210 fArcButton->SetFillColor(kGreen);
212 char butUnzoom[] = "gAlice->Display()->UnZoom()";
213 TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
214 button->SetFillColor(38);
216 AppendPad(); // append display object as last object to force selection
218 // Create momentum cut slider pad
220 fCutPad = new TPad("cutSlider", "pcut slider pad",dxtr,.96,1,1);
223 fCutPad->SetFillColor(22);
224 fCutPad->SetBorderSize(2);
225 fCutSlider = new TSlider("pcut","Momentum cut",0,0,1,1);
226 fCutSlider->SetRange(fPTcut/kptcutmax,1);
227 fCutSlider->SetObject(this);
228 fCutSlider->SetFillColor(45);
229 TSliderBox *sbox = (TSliderBox*)fCutSlider->GetListOfPrimitives()->First();
230 sbox->SetFillColor(46);
232 TGaxis *cutaxis = new TGaxis(0.02,0.8,0.98,0.8,0,kptcutmax,510,"");
233 cutaxis->SetLabelSize(0.5);
234 cutaxis->SetTitleSize(0.6);
235 cutaxis->SetTitleOffset(0.5);
236 cutaxis->SetTitle("pcut . ");
237 fCutSlider->GetListOfPrimitives()->AddFirst(cutaxis);
239 // Create rapidity cut slider pad
241 fEtaPad = new TPad("EtaSlider", "Eta slider pad",0.97,0,1,0.96);
244 fEtaPad->SetFillColor(22);
245 fEtaPad->SetBorderSize(2);
246 fEtaSlider = new TSlider("etacut","Rapidity cut",0,0,1,1);
247 fEtaSlider->SetObject(this);
248 fEtaSlider->SetFillColor(45);
249 TSliderBox *sbox2 = (TSliderBox*)fEtaSlider->GetListOfPrimitives()->First();
250 sbox2->SetFillColor(46);
252 TGaxis *etaaxis = new TGaxis(0.9,0.02,0.9,0.98,-ketacutmax,ketacutmax,510,"");
253 etaaxis->SetLabelSize(0.5);
254 etaaxis->SetTitleSize(0.6);
255 etaaxis->SetTitleOffset(0.2);
256 cutaxis->SetTitle("Etacut . ");
257 fEtaSlider->GetListOfPrimitives()->AddFirst(etaaxis);
266 //_____________________________________________________________________________
267 AliDisplay::AliDisplay(const AliDisplay &disp)
275 //_____________________________________________________________________________
276 AliDisplay::~AliDisplay()
283 //_____________________________________________________________________________
284 void AliDisplay::Clear(Option_t *)
286 // Delete graphics temporary objects
289 //_____________________________________________________________________________
290 void AliDisplay::Copy(AliDisplay &disp) const
293 // Copy *this onto disp -- not implemented
295 Fatal("Copy","Not implemented~\n");
298 //----------------------------------------------------------------------------
299 void AliDisplay::ShowTrack(Int_t idx) {
300 AliDetector *mTPC=(AliDetector*)gAlice->GetModule("TPC");
301 TObjArray *points=mTPC->Points();
302 int ntracks=points->GetEntriesFast();
303 for (int track=0;track<ntracks;track++) {
304 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
306 if (idx == pm->GetIndex()) {
307 pm->SetMarkerColor(2);
308 pm->SetMarkerStyle(22);
312 TClonesArray *particles=gAlice->Particles();
313 TParticle *p = (TParticle*)particles->UncheckedAt(idx);
314 printf("\nTrack index %d\n",idx);
315 printf("Particle ID %d\n",p->GetPdgCode());
316 printf("Parent %d\n",p->GetFirstMother());
317 printf("First child %d\n",p->GetFirstDaughter());
318 printf("Px,Py,Pz %f %f %f\n",p->Px(),p->Py(),p->Pz());
324 //----------------------------------------------------------------------------
325 void AliDisplay::HideTrack(Int_t idx) {
326 AliDetector *mTPC=(AliDetector*)gAlice->GetModule("TPC");
327 TObjArray *points=mTPC->Points();
328 int ntracks=points->GetEntriesFast();
329 for (int track=0;track<ntracks;track++) {
330 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
332 if (idx == pm->GetIndex()) {
333 pm->SetMarkerColor(5);
334 pm->SetMarkerStyle(1);
343 //_____________________________________________________________________________
344 void AliDisplay::DisableDetector(const char *name)
346 // Disable detector name from graphics views
348 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
354 //_____________________________________________________________________________
355 void AliDisplay::DisplayButtons()
357 // Create the user interface buttons
359 fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
360 fButtons->SetEditable(kFALSE);
362 fButtons->SetFillColor(38);
363 fButtons->SetBorderSize(2);
367 Float_t dbutton = 0.08;
374 char but1[] = "gAlice->Display()->ShowNextEvent(1)";
375 button = new TButton("Next",but1,x0,y-dbutton,x1,y);
376 button->SetFillColor(38);
380 char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
381 button = new TButton("Previous",but2,x0,y-dbutton,x1,y);
382 button->SetFillColor(38);
386 char but3[] = "gAlice->Display()->SetView(90,-90,90)";
387 button = new TButton("Top View",but3,x0,y-dbutton,x1,y);
388 button->SetFillColor(butcolor);
392 char but4[] = "gAlice->Display()->SetView(90,0,-90)";
393 button = new TButton("Side View",but4,x0,y-dbutton,x1,y);
394 button->SetFillColor(butcolor);
398 char but5[] = "gAlice->Display()->SetView(0,-90,0)";
399 button = new TButton("Front View",but5,x0,y-dbutton,x1,y);
400 button->SetFillColor(butcolor);
404 char but6[] = "gAlice->Display()->DrawAllViews()";
405 button = new TButton("All Views",but6,x0,y-dbutton,x1,y);
406 button->SetFillColor(butcolor);
410 char but7[] = "gAlice->Display()->DrawViewGL()";
411 button = new TButton("OpenGL",but7,x0,y-dbutton,x1,y);
412 button->SetFillColor(38);
416 char but8[] = "gAlice->Display()->DrawViewX3D()";
417 button = new TButton("X3D",but8,x0,y-dbutton,x1,y);
418 button->SetFillColor(38);
422 TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
423 diamond->SetFillColor(50);
424 diamond->SetTextAlign(22);
425 diamond->SetTextColor(5);
426 diamond->SetTextSize(0.11);
428 diamond->AddText(".. ");
429 diamond->AddText("ROOT");
430 diamond->AddText("ALICE");
431 diamond->AddText("... ");
432 diamond->AddText(" ");
435 //______________________________________________________________________________
436 Int_t AliDisplay::DistancetoPrimitive(Int_t px, Int_t)
438 // Compute distance from point px,py to objects in event
440 gPad->SetCursor(kCross);
442 if (gPad == fTrigPad) return 9999;
443 if (gPad == fCutPad) return 9999;
444 if (gPad == fEtaPad) return 9999;
446 const Int_t kbig = 9999;
448 Float_t xmin = gPad->GetX1();
449 Float_t xmax = gPad->GetX2();
450 Float_t dx = 0.02*(xmax - xmin);
451 Float_t x = gPad->AbsPixeltoX(px);
452 if (x < xmin+dx || x > xmax-dx) return dist;
454 if (fZoomMode) return 0;
458 //_____________________________________________________________________________
459 void AliDisplay::Draw(Option_t *)
461 // Display current event
470 DrawView(fTheta, fPhi, fPsi);
472 // Display the event number and title
477 //_____________________________________________________________________________
478 void AliDisplay::DrawAllViews()
480 // Draw front,top,side and 30 deg views
482 fDrawAllViews = kTRUE;
484 fPad->SetFillColor(15);
500 DrawView(90, -90, 90);
505 DrawView(90, 0, -90);
511 //_____________________________________________________________________________
512 void AliDisplay::DrawHits()
514 // Draw hits for all ALICE detectors
516 Float_t cutmin, cutmax, etamin, etamax, pmom, smin, smax, eta, theta, r;
524 smax = fCutSlider->GetMaximum();
525 smin = fCutSlider->GetMinimum();
526 cutmin = kptcutmax*smin;
527 if (smax < 0.98) cutmax = kptcutmax*smax;
528 else cutmax = 100000;
531 smax = fEtaSlider->GetMaximum();
532 smin = fEtaSlider->GetMinimum();
533 etamin = ketacutmax*(2*smin-1);
534 etamax = ketacutmax*(2*smax-1);
535 if (smin < 0.02) etamin = -1000;
536 if (smax > 0.98) etamax = 1000;
538 TIter next(gAlice->Modules());
541 while((module = (AliModule*)next())) {
542 if (!module->IsActive()) continue;
543 points = module->Points();
544 if (!points) continue;
545 ntracks = points->GetEntriesFast();
546 for (track=0;track<ntracks;track++) {
547 pm = (AliPoints*)points->UncheckedAt(track);
549 particle = pm->GetParticle();
550 if (!particle) continue;
551 pmom = particle->P();
552 if (pmom < cutmin) continue;
553 if (pmom > cutmax) continue;
554 // as a first approximation, take eta of first point
556 r = TMath::Sqrt(pxyz[0]*pxyz[0] + pxyz[1]*pxyz[1]);
557 theta = TMath::ATan2(r,TMath::Abs(pxyz[2]));
558 if(theta) eta = -TMath::Log(TMath::Tan(0.5*theta)); else eta = 1e10;
559 if (pxyz[2] < 0) eta = -eta;
560 if (eta < etamin || eta > etamax) continue;
562 fHitsCuts += pm->GetN();
567 //_____________________________________________________________________________
568 void AliDisplay::DrawTitle(Option_t *option)
570 // Draw the event title
572 Float_t xmin = gPad->GetX1();
573 Float_t xmax = gPad->GetX2();
574 Float_t ymin = gPad->GetY1();
575 Float_t ymax = gPad->GetY2();
576 Float_t dx = xmax-xmin;
577 Float_t dy = ymax-ymin;
579 if (strlen(option) == 0) {
580 TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
581 title->SetBit(kCanDelete);
582 title->SetFillColor(42);
585 sprintf(ptitle,"Alice event: %d, Run:%d",gAlice->GetHeader()->GetEvent(), gAlice->GetHeader()->GetRun());
586 title->AddText(ptitle);
587 Int_t nparticles = gAlice->Particles()->GetEntriesFast();
588 sprintf(ptitle,"Nparticles = %d Nhits = %d",nparticles, fHitsCuts);
589 title->AddText(ptitle);
591 TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
592 label->SetBit(kCanDelete);
593 label->SetFillColor(42);
598 //_____________________________________________________________________________
599 void AliDisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
601 // Draw a view of ALICE
603 gPad->SetCursor(kWatch);
604 gPad->SetFillColor(1);
608 TView *view = new TView(1);
609 Float_t range = fRrange*fRangeSlider->GetMaximum();
610 view->SetRange(-range,-range,-range,range, range, range);
617 // Display Alice Geometry
618 gAlice->GetGeometry()->Draw("same");
620 //Loop on all detectors to add their products to the pad
623 // add itself to the list (must be last)
626 view->SetView(phi, theta, psi, iret);
629 //_____________________________________________________________________________
630 void AliDisplay::DrawViewGL()
632 // Draw current view using OPENGL
634 TPad *pad = (TPad*)gPad->GetPadSave();
636 TView *view = pad->GetView();
641 //_____________________________________________________________________________
642 void AliDisplay::DrawViewX3D()
644 // Draw current view using X3D
646 TPad *pad = (TPad*)gPad->GetPadSave();
648 TView *view = pad->GetView();
653 //_____________________________________________________________________________
654 void AliDisplay::EnableDetector(const char *name)
656 // Enable detector name in graphics views
658 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
664 //______________________________________________________________________________
665 void AliDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
667 // Execute action corresponding to the mouse event
669 static Float_t x0, y0, x1, y1;
671 static Int_t pxold, pyold;
672 static Int_t px0, py0;
673 static Int_t linedrawn;
676 if (px == 0 && py == 0) { //when called by sliders
677 if (event == kButton1Up) {
682 if (!fZoomMode && gPad->GetView()) {
683 gPad->GetView()->ExecuteRotateView(event, px, py);
687 // something to zoom ?
688 // fPad->SetCursor(kCross);
689 gPad->SetCursor(kCross);
694 gVirtualX->SetLineColor(-1);
695 gPad->TAttLine::Modify(); //Change line attributes only if necessary
696 x0 = gPad->AbsPixeltoX(px);
697 y0 = gPad->AbsPixeltoY(py);
699 pxold = px; pyold = py;
704 if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
708 gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
712 gPad->GetCanvas()->FeedbackMode(kFALSE);
713 if (px == px0) return;
714 if (py == py0) return;
715 x1 = gPad->AbsPixeltoX(px);
716 y1 = gPad->AbsPixeltoY(py);
718 if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
719 if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
720 gPad->Range(x0,y0,x1,y1);
721 if (fZooms < kMAXZOOMS-1) {
723 fZoomX0[fZooms] = x0;
724 fZoomY0[fZooms] = y0;
725 fZoomX1[fZooms] = x1;
726 fZoomY1[fZooms] = y1;
728 gPad->Modified(kTRUE);
734 //___________________________________________
735 void AliDisplay::LoadPoints()
737 // Read hits info and store x,y,z info in arrays fPoints
738 // Loop on all detectors
740 gAlice->ResetPoints();
741 TIter next(gAlice->Modules());
743 Int_t ntracks = gAlice->GetNtrack();
744 for (Int_t track=0; track<ntracks;track++) {
746 gAlice->TreeH()->GetEvent(track);
747 while((module = (AliModule*)next())) {
748 module->LoadPoints(track);
754 //_____________________________________________________________________________
755 void AliDisplay::Paint(Option_t *)
757 // Paint miscellaneous items
761 //_____________________________________________________________________________
762 void AliDisplay::SetPickMode()
766 fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
767 fTrigPad->Modified();
770 //_____________________________________________________________________________
771 void AliDisplay::SetZoomMode()
775 fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
776 fTrigPad->Modified();
779 //_____________________________________________________________________________
780 void AliDisplay::SetPTcut(Float_t ptcut)
789 //_____________________________________________________________________________
790 void AliDisplay::SetRange(Float_t rrange, Float_t zrange)
792 // Set view range along R and Z
801 //_____________________________________________________________________________
802 void AliDisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
804 // change viewing angles for current event
807 fDrawAllViews = kFALSE;
813 TView *view = gPad->GetView();
814 if (view) view->SetView(fPhi, fTheta, fPsi, iret);
820 //_____________________________________________________________________________
821 void AliDisplay::ShowNextEvent(Int_t delta)
823 // Display (current event_number+delta)
824 // delta = 1 shown next event
825 // delta = -1 show previous event
829 Int_t currentEvent = gAlice->GetHeader()->GetEvent();
830 Int_t newEvent = currentEvent + delta;
831 gAlice->GetEvent(newEvent);
832 if (!gAlice->TreeH()) return;
839 //______________________________________________________________________________
840 void AliDisplay::UnZoom()
845 if (fZooms <= 0) return;
847 TPad *pad = (TPad*)gPad->GetPadSave();
848 pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);
852 //_____________________________________________________________________________
853 AliDisplay & AliDisplay::operator=(const AliDisplay &disp)
856 // Assignment operator