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.5 1999/09/29 09:24:29 fca
19 Introduction of the Copyright and cvs Log
24 //////////////////////////////////////////////////////////////////////////
28 // Utility class to display ALICE outline, tracks, hits,.. //
30 //////////////////////////////////////////////////////////////////////////
38 #include <TPolyMarker3D.h>
39 #include <TPaveLabel.h>
40 #include <TPaveText.h>
47 #include <TSliderBox.h>
49 #include <TVirtualX.h>
51 #include <X3DBuffer.h>
54 #include "AliDetector.h"
55 #include "AliDisplay.h"
56 #include "AliPoints.h"
57 #include "TParticle.h"
59 const Float_t ptcutmax = 2;
60 const Float_t etacutmax = 1.5;
65 //_____________________________________________________________________________
66 AliDisplay::AliDisplay()
71 //_____________________________________________________________________________
72 AliDisplay::AliDisplay(Int_t size)
74 // Create an event display object.
75 // A canvas named "edisplay" is created with a vertical size in pixels
77 // A QUICK Overview of the Event Display functions
78 // ===============================================
80 // The event display can ve invoked by executing the macro "display.C"
81 // A canvas like in the picture below will appear.
83 // On the left side of the canvas, the following buttons appear:
84 // *Next* to move to the next event
85 // *Previous* to move to the previous event
86 // *Top View* to display a top view of the current event
87 // *Side View* to display a side view of the current event
88 // *Front View* to display a front view of the current event
89 // *All Views* to display front/side/top/30-30 views of the current event
90 // *OpenGL* to use OpenGl to view the current event.
91 // Note that OpenGL cannot be used across the network.
92 // Before using OpenGL, load the GL libraries
93 // by executing the macro GL.C (in $ROOTSYS/macros/GL.C.
94 // Once in GL, click the HELP button of the GL canvas.
95 // *X3D* to use X3D to view the current event (Unix only).
96 // Once in X3D, type M to see the list of all possible options.
97 // for example type J to zoom, K to unzoom
98 // use the mouse to rotate.
99 // *Pick* Select this option to be able to point on a track with the
100 // mouse. Once on the track, use the right button to select
101 // an action. For example, select SetMarkerAttributes to
102 // change the marker type/color/size for the track.
103 // *Zoom* Select this option (default) if you want to zoom.
104 // To zoom, simply select the selected area with the left button.
105 // *UnZoom* To revert to the previous picture size.
107 // slider R On the left side, the vertical slider can be used to
108 // set the default picture size.
109 // slider pcut At the top of the canvas, a slider can be used to change
110 // the momentum cut (or range) to display tracks.
111 // slider eta On the right side of the canvas, a vertical slider can be used
112 // to specify a rapidity range for the tracks.
114 // When you are in Zoom mode, you can click on the black part of the canvas
115 // to select special options with the right mouse button.
116 // This will display a pop-up menu with items like:
117 // *Disable detector*
118 // *Enable detector*, etc.
119 // For example select "Disable detector". You get a dialog box.
120 // Diable detector TRD for example.
122 // When you are in pick mode, you can "Inspect" the object pointed by the mouse.
123 // When you are on a track, select the menu item "InspectParticle"
124 // to display the current particle attributes.
126 // You can activate the Root browser by selecting the Inspect menu
127 // in the canvas tool bar menu. Then select "Start Browser"
128 // This will open a new canvas with the browser. At this point, you may want
129 // to display some histograms (from the Trees). Go to the "File" menu
130 // of the browser and click on "New canvas".
131 // In the browser, click on item "ROOT files" in the left pane.
132 // Click on galice.root.
134 // Click on TPC for example
135 // Click on any variable (eg TPC.fX) to histogram the variable.
137 // If you are lost, you can click on HELP in any Root canvas or browser.
140 <img src="picts/alidisplay.gif">
145 gAlice->SetDisplay(this);
147 // Initialize display default parameters
151 // Set front view by default
155 fDrawAllViews = kFALSE;
157 fDrawParticles = kTRUE;
162 // Create display canvas
164 if (ysize < 100) ysize = 750;
165 Int_t xsize = Int_t(size*830./ysize);
166 fCanvas = new TCanvas("Canvas", "ALICE Event Display",14,47,xsize,ysize);
167 fCanvas->SetEditable(kFALSE);
168 fCanvas->ToggleEventStatus();
170 // Create main display pad
171 fPad = new TPad("viewpad", "Alice display",0.15,0,0.97,0.96);
174 fPad->SetFillColor(1);
175 fPad->SetBorderSize(2);
177 // Create user interface control pad
181 // Create Range and mode pad
184 fTrigPad = new TPad("trigger", "range and mode pad",0,0,dxtr,dytr);
187 fTrigPad->SetFillColor(22);
188 fTrigPad->SetBorderSize(2);
189 fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
190 fRangeSlider->SetObject(this);
191 char pickmode[] = "gAlice->Display()->SetPickMode()";
193 fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
194 fPickButton->SetFillColor(38);
196 char zoommode[] = "gAlice->Display()->SetZoomMode()";
197 fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
198 fZoomButton->SetFillColor(38);
200 fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
201 fArcButton->SetFillColor(kGreen);
203 char butUnzoom[] = "gAlice->Display()->UnZoom()";
204 TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
205 button->SetFillColor(38);
207 AppendPad(); // append display object as last object to force selection
209 // Create momentum cut slider pad
211 fCutPad = new TPad("cutSlider", "pcut slider pad",dxtr,.96,1,1);
214 fCutPad->SetFillColor(22);
215 fCutPad->SetBorderSize(2);
216 fCutSlider = new TSlider("pcut","Momentum cut",0,0,1,1);
217 fCutSlider->SetRange(fPTcut/ptcutmax,1);
218 fCutSlider->SetObject(this);
219 fCutSlider->SetFillColor(45);
220 TSliderBox *sbox = (TSliderBox*)fCutSlider->GetListOfPrimitives()->First();
221 sbox->SetFillColor(46);
223 TGaxis *cutaxis = new TGaxis(0.02,0.8,0.98,0.8,0,ptcutmax,510,"");
224 cutaxis->SetLabelSize(0.5);
225 cutaxis->SetTitleSize(0.6);
226 cutaxis->SetTitleOffset(0.5);
227 cutaxis->SetTitle("pcut . ");
228 fCutSlider->GetListOfPrimitives()->AddFirst(cutaxis);
230 // Create rapidity cut slider pad
232 fEtaPad = new TPad("EtaSlider", "Eta slider pad",0.97,0,1,0.96);
235 fEtaPad->SetFillColor(22);
236 fEtaPad->SetBorderSize(2);
237 fEtaSlider = new TSlider("etacut","Rapidity cut",0,0,1,1);
238 fEtaSlider->SetObject(this);
239 fEtaSlider->SetFillColor(45);
240 TSliderBox *sbox2 = (TSliderBox*)fEtaSlider->GetListOfPrimitives()->First();
241 sbox2->SetFillColor(46);
243 TGaxis *etaaxis = new TGaxis(0.9,0.02,0.9,0.98,-etacutmax,etacutmax,510,"");
244 etaaxis->SetLabelSize(0.5);
245 etaaxis->SetTitleSize(0.6);
246 etaaxis->SetTitleOffset(0.2);
247 cutaxis->SetTitle("Etacut . ");
248 fEtaSlider->GetListOfPrimitives()->AddFirst(etaaxis);
257 //_____________________________________________________________________________
258 AliDisplay::~AliDisplay()
262 //_____________________________________________________________________________
263 void AliDisplay::Clear(Option_t *)
265 // Delete graphics temporary objects
268 //----------------------------------------------------------------------------
269 void AliDisplay::ShowTrack(Int_t idx) {
270 AliDetector *TPC=(AliDetector*)gAlice->GetModule("TPC");
271 TObjArray *points=TPC->Points();
272 int ntracks=points->GetEntriesFast();
273 for (int track=0;track<ntracks;track++) {
274 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
276 if (idx == pm->GetIndex()) {
277 pm->SetMarkerColor(2);
278 pm->SetMarkerStyle(22);
282 TClonesArray *particles=gAlice->Particles();
283 TParticle *p = (TParticle*)particles->UncheckedAt(idx);
284 printf("\nTrack index %d\n",idx);
285 printf("Particle ID %d\n",p->GetPdgCode());
286 printf("Parent %d\n",p->GetFirstMother());
287 printf("First child %d\n",p->GetFirstDaughter());
288 printf("Px,Py,Pz %f %f %f\n",p->Px(),p->Py(),p->Pz());
294 //----------------------------------------------------------------------------
295 void AliDisplay::HideTrack(Int_t idx) {
296 AliDetector *TPC=(AliDetector*)gAlice->GetModule("TPC");
297 TObjArray *points=TPC->Points();
298 int ntracks=points->GetEntriesFast();
299 for (int track=0;track<ntracks;track++) {
300 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
302 if (idx == pm->GetIndex()) {
303 pm->SetMarkerColor(5);
304 pm->SetMarkerStyle(1);
313 //_____________________________________________________________________________
314 void AliDisplay::DisableDetector(const char *name)
316 // Disable detector name from graphics views
318 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
324 //_____________________________________________________________________________
325 void AliDisplay::DisplayButtons()
327 // Create the user interface buttons
329 fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
331 fButtons->SetFillColor(38);
332 fButtons->SetBorderSize(2);
336 Float_t dbutton = 0.08;
343 char but1[] = "gAlice->Display()->ShowNextEvent(1)";
344 button = new TButton("Next",but1,x0,y-dbutton,x1,y);
345 button->SetFillColor(38);
349 char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
350 button = new TButton("Previous",but2,x0,y-dbutton,x1,y);
351 button->SetFillColor(38);
355 char but3[] = "gAlice->Display()->SetView(90,-90,90)";
356 button = new TButton("Top View",but3,x0,y-dbutton,x1,y);
357 button->SetFillColor(butcolor);
361 char but4[] = "gAlice->Display()->SetView(90,0,-90)";
362 button = new TButton("Side View",but4,x0,y-dbutton,x1,y);
363 button->SetFillColor(butcolor);
367 char but5[] = "gAlice->Display()->SetView(0,-90,0)";
368 button = new TButton("Front View",but5,x0,y-dbutton,x1,y);
369 button->SetFillColor(butcolor);
373 char but6[] = "gAlice->Display()->DrawAllViews()";
374 button = new TButton("All Views",but6,x0,y-dbutton,x1,y);
375 button->SetFillColor(butcolor);
379 char but7[] = "gAlice->Display()->DrawViewGL()";
380 button = new TButton("OpenGL",but7,x0,y-dbutton,x1,y);
381 button->SetFillColor(38);
385 char but8[] = "gAlice->Display()->DrawViewX3D()";
386 button = new TButton("X3D",but8,x0,y-dbutton,x1,y);
387 button->SetFillColor(38);
391 TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
392 diamond->SetFillColor(50);
393 diamond->SetTextAlign(22);
394 diamond->SetTextColor(5);
395 diamond->SetTextSize(0.11);
397 diamond->AddText(".. ");
398 diamond->AddText("ROOT");
399 diamond->AddText("ALICE");
400 diamond->AddText("... ");
401 diamond->AddText(" ");
404 //______________________________________________________________________________
405 Int_t AliDisplay::DistancetoPrimitive(Int_t px, Int_t)
407 // Compute distance from point px,py to objects in event
409 gPad->SetCursor(kCross);
411 if (gPad == fTrigPad) return 9999;
412 if (gPad == fCutPad) return 9999;
413 if (gPad == fEtaPad) return 9999;
415 const Int_t big = 9999;
417 Float_t xmin = gPad->GetX1();
418 Float_t xmax = gPad->GetX2();
419 Float_t dx = 0.02*(xmax - xmin);
420 Float_t x = gPad->AbsPixeltoX(px);
421 if (x < xmin+dx || x > xmax-dx) return dist;
423 if (fZoomMode) return 0;
427 //_____________________________________________________________________________
428 void AliDisplay::Draw(Option_t *)
430 // Display current event
439 DrawView(fTheta, fPhi, fPsi);
441 // Display the event number and title
446 //_____________________________________________________________________________
447 void AliDisplay::DrawAllViews()
449 // Draw front,top,side and 30 deg views
451 fDrawAllViews = kTRUE;
453 fPad->SetFillColor(15);
469 DrawView(90, -90, 90);
474 DrawView(90, 0, -90);
480 //_____________________________________________________________________________
481 void AliDisplay::DrawHits()
483 // Draw hits for all ALICE detectors
485 Float_t cutmin, cutmax, etamin, etamax, pmom, smin, smax, eta, theta, r;
493 smax = fCutSlider->GetMaximum();
494 smin = fCutSlider->GetMinimum();
495 cutmin = ptcutmax*smin;
496 if (smax < 0.98) cutmax = ptcutmax*smax;
497 else cutmax = 100000;
500 smax = fEtaSlider->GetMaximum();
501 smin = fEtaSlider->GetMinimum();
502 etamin = etacutmax*(2*smin-1);
503 etamax = etacutmax*(2*smax-1);
504 if (smin < 0.02) etamin = -1000;
505 if (smax > 0.98) etamax = 1000;
507 TIter next(gAlice->Modules());
510 while((module = (AliModule*)next())) {
511 if (!module->IsActive()) continue;
512 points = module->Points();
513 if (!points) continue;
514 ntracks = points->GetEntriesFast();
515 for (track=0;track<ntracks;track++) {
516 pm = (AliPoints*)points->UncheckedAt(track);
518 particle = pm->GetParticle();
519 if (!particle) continue;
520 pmom = particle->P();
521 if (pmom < cutmin) continue;
522 if (pmom > cutmax) continue;
523 // as a first approximation, take eta of first point
525 r = TMath::Sqrt(pxyz[0]*pxyz[0] + pxyz[1]*pxyz[1]);
526 theta = TMath::ATan2(r,TMath::Abs(pxyz[2]));
527 if(theta) eta = -TMath::Log(TMath::Tan(0.5*theta)); else eta = 1e10;
528 if (pxyz[2] < 0) eta = -eta;
529 if (eta < etamin || eta > etamax) continue;
531 fHitsCuts += pm->GetN();
536 //_____________________________________________________________________________
537 void AliDisplay::DrawTitle(Option_t *option)
539 // Draw the event title
541 Float_t xmin = gPad->GetX1();
542 Float_t xmax = gPad->GetX2();
543 Float_t ymin = gPad->GetY1();
544 Float_t ymax = gPad->GetY2();
545 Float_t dx = xmax-xmin;
546 Float_t dy = ymax-ymin;
548 if (strlen(option) == 0) {
549 TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
550 title->SetBit(kCanDelete);
551 title->SetFillColor(42);
554 sprintf(ptitle,"Alice event: %d, Run:%d",gAlice->GetHeader()->GetEvent(), gAlice->GetHeader()->GetRun());
555 title->AddText(ptitle);
556 Int_t nparticles = gAlice->Particles()->GetEntriesFast();
557 sprintf(ptitle,"Nparticles = %d Nhits = %d",nparticles, fHitsCuts);
558 title->AddText(ptitle);
560 TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
561 label->SetBit(kCanDelete);
562 label->SetFillColor(42);
567 //_____________________________________________________________________________
568 void AliDisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
570 // Draw a view of ALICE
572 gPad->SetCursor(kWatch);
573 gPad->SetFillColor(1);
577 TView *view = new TView(1);
578 Float_t range = fRrange*fRangeSlider->GetMaximum();
579 view->SetRange(-range,-range,-range,range, range, range);
586 // Display Alice Geometry
587 gAlice->GetGeometry()->Draw("same");
589 //Loop on all detectors to add their products to the pad
592 // add itself to the list (must be last)
595 view->SetView(phi, theta, psi, iret);
598 //_____________________________________________________________________________
599 void AliDisplay::DrawViewGL()
601 // Draw current view using OPENGL
603 TPad *pad = (TPad*)gPad->GetPadSave();
605 TView *view = pad->GetView();
610 //_____________________________________________________________________________
611 void AliDisplay::DrawViewX3D()
613 // Draw current view using X3D
615 TPad *pad = (TPad*)gPad->GetPadSave();
617 TView *view = pad->GetView();
622 //_____________________________________________________________________________
623 void AliDisplay::EnableDetector(const char *name)
625 // Enable detector name in graphics views
627 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
633 //______________________________________________________________________________
634 void AliDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
636 // Execute action corresponding to the mouse event
638 static Float_t x0, y0, x1, y1;
640 static Int_t pxold, pyold;
641 static Int_t px0, py0;
642 static Int_t linedrawn;
645 if (px == 0 && py == 0) { //when called by sliders
646 if (event == kButton1Up) {
651 if (!fZoomMode && gPad->GetView()) {
652 gPad->GetView()->ExecuteRotateView(event, px, py);
656 // something to zoom ?
657 // fPad->SetCursor(kCross);
658 gPad->SetCursor(kCross);
663 gVirtualX->SetLineColor(-1);
664 gPad->TAttLine::Modify(); //Change line attributes only if necessary
665 x0 = gPad->AbsPixeltoX(px);
666 y0 = gPad->AbsPixeltoY(py);
668 pxold = px; pyold = py;
673 if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
677 gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
681 gPad->GetCanvas()->FeedbackMode(kFALSE);
682 if (px == px0) return;
683 if (py == py0) return;
684 x1 = gPad->AbsPixeltoX(px);
685 y1 = gPad->AbsPixeltoY(py);
687 if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
688 if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
689 gPad->Range(x0,y0,x1,y1);
690 if (fZooms < kMAXZOOMS-1) {
692 fZoomX0[fZooms] = x0;
693 fZoomY0[fZooms] = y0;
694 fZoomX1[fZooms] = x1;
695 fZoomY1[fZooms] = y1;
697 gPad->Modified(kTRUE);
703 //___________________________________________
704 void AliDisplay::LoadPoints()
706 // Read hits info and store x,y,z info in arrays fPoints
707 // Loop on all detectors
709 gAlice->ResetPoints();
710 TIter next(gAlice->Modules());
712 Int_t ntracks = gAlice->GetNtrack();
713 for (Int_t track=0; track<ntracks;track++) {
715 gAlice->TreeH()->GetEvent(track);
716 while((module = (AliModule*)next())) {
717 module->LoadPoints(track);
723 //_____________________________________________________________________________
724 void AliDisplay::Paint(Option_t *)
726 // Paint miscellaneous items
730 //_____________________________________________________________________________
731 void AliDisplay::SetPickMode()
735 fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
736 fTrigPad->Modified();
739 //_____________________________________________________________________________
740 void AliDisplay::SetZoomMode()
744 fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
745 fTrigPad->Modified();
748 //_____________________________________________________________________________
749 void AliDisplay::SetPTcut(Float_t ptcut)
758 //_____________________________________________________________________________
759 void AliDisplay::SetRange(Float_t rrange, Float_t zrange)
761 // Set view range along R and Z
770 //_____________________________________________________________________________
771 void AliDisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
773 // change viewing angles for current event
776 fDrawAllViews = kFALSE;
782 TView *view = gPad->GetView();
783 if (view) view->SetView(fPhi, fTheta, fPsi, iret);
789 //_____________________________________________________________________________
790 void AliDisplay::ShowNextEvent(Int_t delta)
792 // Display (current event_number+delta)
793 // delta = 1 shown next event
794 // delta = -1 show previous event
798 Int_t current_event = gAlice->GetHeader()->GetEvent();
799 Int_t new_event = current_event + delta;
800 gAlice->GetEvent(new_event);
801 if (!gAlice->TreeH()) return;
808 //______________________________________________________________________________
809 void AliDisplay::UnZoom()
811 if (fZooms <= 0) return;
813 TPad *pad = (TPad*)gPad->GetPadSave();
814 pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);