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.9 2000/07/13 16:19:09 fca
19 Mainly coding conventions + some small bug fixes
21 Revision 1.8 2000/07/11 18:24:59 fca
22 Coding convention corrections + few minor bug fixes
24 Revision 1.7 1999/11/10 07:37:06 fca
25 Pads do not inherit editability from canvas any more
27 Revision 1.6 1999/11/09 07:38:52 fca
28 Changes for compatibility with version 2.23 of ROOT
30 Revision 1.5 1999/09/29 09:24:29 fca
31 Introduction of the Copyright and cvs Log
36 //////////////////////////////////////////////////////////////////////////
40 // Utility class to display ALICE outline, tracks, hits,.. //
42 //////////////////////////////////////////////////////////////////////////
50 #include <TPolyMarker3D.h>
51 #include <TPaveLabel.h>
52 #include <TPaveText.h>
59 #include <TSliderBox.h>
61 #include <TVirtualX.h>
63 #include <X3DBuffer.h>
66 #include "AliDetector.h"
67 #include "AliDisplay.h"
68 #include "AliPoints.h"
69 #include "TParticle.h"
70 #include "AliGeometry.h"
71 #include "TGeometry.h"
73 static const Float_t kptcutmax = 2;
74 static const Float_t ketacutmax = 1.5;
79 //_____________________________________________________________________________
80 AliDisplay::AliDisplay()
83 // Default constructor
88 //_____________________________________________________________________________
89 AliDisplay::AliDisplay(Int_t size)
91 // Create an event display object.
92 // A canvas named "edisplay" is created with a vertical size in pixels
94 // A QUICK Overview of the Event Display functions
95 // ===============================================
97 // The event display can ve invoked by executing the macro "display.C"
98 // A canvas like in the picture below will appear.
100 // On the left side of the canvas, the following buttons appear:
101 // *Next* to move to the next event
102 // *Previous* to move to the previous event
103 // *Top View* to display a top view of the current event
104 // *Side View* to display a side view of the current event
105 // *Front View* to display a front view of the current event
106 // *All Views* to display front/side/top/30-30 views of the current event
107 // *OpenGL* to use OpenGl to view the current event.
108 // Note that OpenGL cannot be used across the network.
109 // Before using OpenGL, load the GL libraries
110 // by executing the macro GL.C (in $ROOTSYS/macros/GL.C.
111 // Once in GL, click the HELP button of the GL canvas.
112 // *X3D* to use X3D to view the current event (Unix only).
113 // Once in X3D, type M to see the list of all possible options.
114 // for example type J to zoom, K to unzoom
115 // use the mouse to rotate.
116 // *Pick* Select this option to be able to point on a track with the
117 // mouse. Once on the track, use the right button to select
118 // an action. For example, select SetMarkerAttributes to
119 // change the marker type/color/size for the track.
120 // *Zoom* Select this option (default) if you want to zoom.
121 // To zoom, simply select the selected area with the left button.
122 // *UnZoom* To revert to the previous picture size.
124 // slider R On the left side, the vertical slider can be used to
125 // set the default picture size.
126 // slider pcut At the top of the canvas, a slider can be used to change
127 // the momentum cut (or range) to display tracks.
128 // slider eta On the right side of the canvas, a vertical slider can be used
129 // to specify a rapidity range for the tracks.
131 // When you are in Zoom mode, you can click on the black part of the canvas
132 // to select special options with the right mouse button.
133 // This will display a pop-up menu with items like:
134 // *Disable detector*
135 // *Enable detector*, etc.
136 // For example select "Disable detector". You get a dialog box.
137 // Diable detector TRD for example.
139 // When you are in pick mode, you can "Inspect" the object pointed by the mouse.
140 // When you are on a track, select the menu item "InspectParticle"
141 // to display the current particle attributes.
143 // You can activate the Root browser by selecting the Inspect menu
144 // in the canvas tool bar menu. Then select "Start Browser"
145 // This will open a new canvas with the browser. At this point, you may want
146 // to display some histograms (from the Trees). Go to the "File" menu
147 // of the browser and click on "New canvas".
148 // In the browser, click on item "ROOT files" in the left pane.
149 // Click on galice.root.
151 // Click on TPC for example
152 // Click on any variable (eg TPC.fX) to histogram the variable.
154 // If you are lost, you can click on HELP in any Root canvas or browser.
157 <img src="picts/alidisplay.gif">
162 gAlice->SetDisplay(this);
164 // Initialize display default parameters
168 // Set front view by default
172 fDrawAllViews = kFALSE;
174 fDrawParticles = kTRUE;
179 // Create display canvas
181 if (ysize < 100) ysize = 750;
182 Int_t xsize = Int_t(size*830./ysize);
183 fCanvas = new TCanvas("Canvas", "ALICE Event Display",14,47,xsize,ysize);
184 fCanvas->ToggleEventStatus();
186 // Create main display pad
187 fPad = new TPad("viewpad", "Alice display",0.15,0,0.97,0.96);
190 fPad->SetFillColor(1);
191 fPad->SetBorderSize(2);
193 // Create user interface control pad
197 // Create Range and mode pad
200 fTrigPad = new TPad("trigger", "range and mode pad",0,0,dxtr,dytr);
201 fTrigPad->SetEditable(kFALSE);
204 fTrigPad->SetFillColor(22);
205 fTrigPad->SetBorderSize(2);
206 fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
207 fRangeSlider->SetObject(this);
208 char pickmode[] = "gAlice->Display()->SetPickMode()";
210 fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
211 fPickButton->SetFillColor(38);
213 char zoommode[] = "gAlice->Display()->SetZoomMode()";
214 fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
215 fZoomButton->SetFillColor(38);
217 fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
218 fArcButton->SetFillColor(kGreen);
220 char butUnzoom[] = "gAlice->Display()->UnZoom()";
221 TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
222 button->SetFillColor(38);
224 AppendPad(); // append display object as last object to force selection
226 // Create momentum cut slider pad
228 fCutPad = new TPad("cutSlider", "pcut slider pad",dxtr,.96,1,1);
231 fCutPad->SetFillColor(22);
232 fCutPad->SetBorderSize(2);
233 fCutSlider = new TSlider("pcut","Momentum cut",0,0,1,1);
234 fCutSlider->SetRange(fPTcut/kptcutmax,1);
235 fCutSlider->SetObject(this);
236 fCutSlider->SetFillColor(45);
237 TSliderBox *sbox = (TSliderBox*)fCutSlider->GetListOfPrimitives()->First();
238 sbox->SetFillColor(46);
240 TGaxis *cutaxis = new TGaxis(0.02,0.8,0.98,0.8,0,kptcutmax,510,"");
241 cutaxis->SetLabelSize(0.5);
242 cutaxis->SetTitleSize(0.6);
243 cutaxis->SetTitleOffset(0.5);
244 cutaxis->SetTitle("pcut . ");
245 fCutSlider->GetListOfPrimitives()->AddFirst(cutaxis);
247 // Create rapidity cut slider pad
249 fEtaPad = new TPad("EtaSlider", "Eta slider pad",0.97,0,1,0.96);
252 fEtaPad->SetFillColor(22);
253 fEtaPad->SetBorderSize(2);
254 fEtaSlider = new TSlider("etacut","Rapidity cut",0,0,1,1);
255 fEtaSlider->SetObject(this);
256 fEtaSlider->SetFillColor(45);
257 TSliderBox *sbox2 = (TSliderBox*)fEtaSlider->GetListOfPrimitives()->First();
258 sbox2->SetFillColor(46);
260 TGaxis *etaaxis = new TGaxis(0.9,0.02,0.9,0.98,-ketacutmax,ketacutmax,510,"");
261 etaaxis->SetLabelSize(0.5);
262 etaaxis->SetTitleSize(0.6);
263 etaaxis->SetTitleOffset(0.2);
264 cutaxis->SetTitle("Etacut . ");
265 fEtaSlider->GetListOfPrimitives()->AddFirst(etaaxis);
274 //_____________________________________________________________________________
275 AliDisplay::AliDisplay(const AliDisplay &disp)
283 //_____________________________________________________________________________
284 AliDisplay::~AliDisplay()
291 //_____________________________________________________________________________
292 void AliDisplay::Clear(Option_t *)
294 // Delete graphics temporary objects
297 //_____________________________________________________________________________
298 void AliDisplay::Copy(AliDisplay &disp) const
301 // Copy *this onto disp -- not implemented
303 Fatal("Copy","Not implemented~\n");
306 //----------------------------------------------------------------------------
307 void AliDisplay::ShowTrack(Int_t idx) {
308 AliDetector *mTPC=(AliDetector*)gAlice->GetModule("TPC");
309 TObjArray *points=mTPC->Points();
310 int ntracks=points->GetEntriesFast();
311 for (int track=0;track<ntracks;track++) {
312 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
314 if (idx == pm->GetIndex()) {
315 pm->SetMarkerColor(2);
316 pm->SetMarkerStyle(22);
320 TClonesArray *particles=gAlice->Particles();
321 TParticle *p = (TParticle*)particles->UncheckedAt(idx);
322 printf("\nTrack index %d\n",idx);
323 printf("Particle ID %d\n",p->GetPdgCode());
324 printf("Parent %d\n",p->GetFirstMother());
325 printf("First child %d\n",p->GetFirstDaughter());
326 printf("Px,Py,Pz %f %f %f\n",p->Px(),p->Py(),p->Pz());
332 //----------------------------------------------------------------------------
333 void AliDisplay::HideTrack(Int_t idx) {
335 // Hide track on display
337 AliDetector *mTPC=(AliDetector*)gAlice->GetModule("TPC");
338 TObjArray *points=mTPC->Points();
339 int ntracks=points->GetEntriesFast();
340 for (int track=0;track<ntracks;track++) {
341 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
343 if (idx == pm->GetIndex()) {
344 pm->SetMarkerColor(5);
345 pm->SetMarkerStyle(1);
354 //_____________________________________________________________________________
355 void AliDisplay::DisableDetector(const char *name)
357 // Disable detector name from graphics views
359 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
365 //_____________________________________________________________________________
366 void AliDisplay::DisplayButtons()
368 // Create the user interface buttons
370 fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
371 fButtons->SetEditable(kFALSE);
373 fButtons->SetFillColor(38);
374 fButtons->SetBorderSize(2);
378 Float_t dbutton = 0.08;
385 char but1[] = "gAlice->Display()->ShowNextEvent(1)";
386 button = new TButton("Next",but1,x0,y-dbutton,x1,y);
387 button->SetFillColor(38);
391 char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
392 button = new TButton("Previous",but2,x0,y-dbutton,x1,y);
393 button->SetFillColor(38);
397 char but3[] = "gAlice->Display()->SetView(90,-90,90)";
398 button = new TButton("Top View",but3,x0,y-dbutton,x1,y);
399 button->SetFillColor(butcolor);
403 char but4[] = "gAlice->Display()->SetView(90,0,-90)";
404 button = new TButton("Side View",but4,x0,y-dbutton,x1,y);
405 button->SetFillColor(butcolor);
409 char but5[] = "gAlice->Display()->SetView(0,-90,0)";
410 button = new TButton("Front View",but5,x0,y-dbutton,x1,y);
411 button->SetFillColor(butcolor);
415 char but6[] = "gAlice->Display()->DrawAllViews()";
416 button = new TButton("All Views",but6,x0,y-dbutton,x1,y);
417 button->SetFillColor(butcolor);
421 char but7[] = "gAlice->Display()->DrawViewGL()";
422 button = new TButton("OpenGL",but7,x0,y-dbutton,x1,y);
423 button->SetFillColor(38);
427 char but8[] = "gAlice->Display()->DrawViewX3D()";
428 button = new TButton("X3D",but8,x0,y-dbutton,x1,y);
429 button->SetFillColor(38);
433 TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
434 diamond->SetFillColor(50);
435 diamond->SetTextAlign(22);
436 diamond->SetTextColor(5);
437 diamond->SetTextSize(0.11);
439 diamond->AddText(".. ");
440 diamond->AddText("ROOT");
441 diamond->AddText("ALICE");
442 diamond->AddText("... ");
443 diamond->AddText(" ");
446 //______________________________________________________________________________
447 Int_t AliDisplay::DistancetoPrimitive(Int_t px, Int_t)
449 // Compute distance from point px,py to objects in event
451 gPad->SetCursor(kCross);
453 if (gPad == fTrigPad) return 9999;
454 if (gPad == fCutPad) return 9999;
455 if (gPad == fEtaPad) return 9999;
457 const Int_t kbig = 9999;
459 Float_t xmin = gPad->GetX1();
460 Float_t xmax = gPad->GetX2();
461 Float_t dx = 0.02*(xmax - xmin);
462 Float_t x = gPad->AbsPixeltoX(px);
463 if (x < xmin+dx || x > xmax-dx) return dist;
465 if (fZoomMode) return 0;
469 //_____________________________________________________________________________
470 void AliDisplay::Draw(Option_t *)
472 // Display current event
481 DrawView(fTheta, fPhi, fPsi);
483 // Display the event number and title
488 //_____________________________________________________________________________
489 void AliDisplay::DrawAllViews()
491 // Draw front,top,side and 30 deg views
493 fDrawAllViews = kTRUE;
495 fPad->SetFillColor(15);
511 DrawView(90, -90, 90);
516 DrawView(90, 0, -90);
522 //_____________________________________________________________________________
523 void AliDisplay::DrawHits()
525 // Draw hits for all ALICE detectors
527 Float_t cutmin, cutmax, etamin, etamax, pmom, smin, smax, eta, theta, r;
535 smax = fCutSlider->GetMaximum();
536 smin = fCutSlider->GetMinimum();
537 cutmin = kptcutmax*smin;
538 if (smax < 0.98) cutmax = kptcutmax*smax;
539 else cutmax = 100000;
542 smax = fEtaSlider->GetMaximum();
543 smin = fEtaSlider->GetMinimum();
544 etamin = ketacutmax*(2*smin-1);
545 etamax = ketacutmax*(2*smax-1);
546 if (smin < 0.02) etamin = -1000;
547 if (smax > 0.98) etamax = 1000;
549 TIter next(gAlice->Modules());
552 while((module = (AliModule*)next())) {
553 if (!module->IsActive()) continue;
554 points = module->Points();
555 if (!points) continue;
556 ntracks = points->GetEntriesFast();
557 for (track=0;track<ntracks;track++) {
558 pm = (AliPoints*)points->UncheckedAt(track);
560 particle = pm->GetParticle();
561 if (!particle) continue;
562 pmom = particle->P();
563 if (pmom < cutmin) continue;
564 if (pmom > cutmax) continue;
565 // as a first approximation, take eta of first point
567 r = TMath::Sqrt(pxyz[0]*pxyz[0] + pxyz[1]*pxyz[1]);
568 theta = TMath::ATan2(r,TMath::Abs(pxyz[2]));
569 if(theta) eta = -TMath::Log(TMath::Tan(0.5*theta)); else eta = 1e10;
570 if (pxyz[2] < 0) eta = -eta;
571 if (eta < etamin || eta > etamax) continue;
573 fHitsCuts += pm->GetN();
578 //_____________________________________________________________________________
579 void AliDisplay::DrawTitle(Option_t *option)
581 // Draw the event title
583 Float_t xmin = gPad->GetX1();
584 Float_t xmax = gPad->GetX2();
585 Float_t ymin = gPad->GetY1();
586 Float_t ymax = gPad->GetY2();
587 Float_t dx = xmax-xmin;
588 Float_t dy = ymax-ymin;
590 if (strlen(option) == 0) {
591 TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
592 title->SetBit(kCanDelete);
593 title->SetFillColor(42);
596 sprintf(ptitle,"Alice event: %d, Run:%d",gAlice->GetHeader()->GetEvent(), gAlice->GetHeader()->GetRun());
597 title->AddText(ptitle);
598 Int_t nparticles = gAlice->Particles()->GetEntriesFast();
599 sprintf(ptitle,"Nparticles = %d Nhits = %d",nparticles, fHitsCuts);
600 title->AddText(ptitle);
602 TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
603 label->SetBit(kCanDelete);
604 label->SetFillColor(42);
609 //_____________________________________________________________________________
610 void AliDisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
612 // Draw a view of ALICE
614 gPad->SetCursor(kWatch);
615 gPad->SetFillColor(1);
619 TView *view = new TView(1);
620 Float_t range = fRrange*fRangeSlider->GetMaximum();
621 view->SetRange(-range,-range,-range,range, range, range);
628 // Display Alice Geometry
629 gAlice->GetGeometry()->Draw("same");
631 //Loop on all detectors to add their products to the pad
634 // add itself to the list (must be last)
637 view->SetView(phi, theta, psi, iret);
640 //_____________________________________________________________________________
641 void AliDisplay::DrawViewGL()
643 // Draw current view using OPENGL
645 TPad *pad = (TPad*)gPad->GetPadSave();
647 TView *view = pad->GetView();
652 //_____________________________________________________________________________
653 void AliDisplay::DrawViewX3D()
655 // Draw current view using X3D
657 TPad *pad = (TPad*)gPad->GetPadSave();
659 TView *view = pad->GetView();
664 //_____________________________________________________________________________
665 void AliDisplay::EnableDetector(const char *name)
667 // Enable detector name in graphics views
669 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
675 //______________________________________________________________________________
676 void AliDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
678 // Execute action corresponding to the mouse event
680 static Float_t x0, y0, x1, y1;
682 static Int_t pxold, pyold;
683 static Int_t px0, py0;
684 static Int_t linedrawn;
687 if (px == 0 && py == 0) { //when called by sliders
688 if (event == kButton1Up) {
693 if (!fZoomMode && gPad->GetView()) {
694 gPad->GetView()->ExecuteRotateView(event, px, py);
698 // something to zoom ?
699 // fPad->SetCursor(kCross);
700 gPad->SetCursor(kCross);
705 gVirtualX->SetLineColor(-1);
706 gPad->TAttLine::Modify(); //Change line attributes only if necessary
707 x0 = gPad->AbsPixeltoX(px);
708 y0 = gPad->AbsPixeltoY(py);
710 pxold = px; pyold = py;
715 if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
719 gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
723 gPad->GetCanvas()->FeedbackMode(kFALSE);
724 if (px == px0) return;
725 if (py == py0) return;
726 x1 = gPad->AbsPixeltoX(px);
727 y1 = gPad->AbsPixeltoY(py);
729 if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
730 if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
731 gPad->Range(x0,y0,x1,y1);
732 if (fZooms < kMAXZOOMS-1) {
734 fZoomX0[fZooms] = x0;
735 fZoomY0[fZooms] = y0;
736 fZoomX1[fZooms] = x1;
737 fZoomY1[fZooms] = y1;
739 gPad->Modified(kTRUE);
745 //___________________________________________
746 void AliDisplay::LoadPoints()
748 // Read hits info and store x,y,z info in arrays fPoints
749 // Loop on all detectors
751 gAlice->ResetPoints();
752 TIter next(gAlice->Modules());
754 Int_t ntracks = gAlice->GetNtrack();
755 for (Int_t track=0; track<ntracks;track++) {
757 gAlice->TreeH()->GetEvent(track);
758 while((module = (AliModule*)next())) {
759 module->LoadPoints(track);
765 //_____________________________________________________________________________
766 void AliDisplay::Paint(Option_t *)
768 // Paint miscellaneous items
772 //_____________________________________________________________________________
773 void AliDisplay::SetPickMode()
776 // Set Pick Mode -- disable zoom
780 fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
781 fTrigPad->Modified();
784 //_____________________________________________________________________________
785 void AliDisplay::SetZoomMode()
788 // Set Zoom Mode -- disable pick
792 fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
793 fTrigPad->Modified();
796 //_____________________________________________________________________________
797 void AliDisplay::SetPTcut(Float_t ptcut)
809 //_____________________________________________________________________________
810 void AliDisplay::SetRange(Float_t rrange, Float_t zrange)
812 // Set view range along R and Z
821 //_____________________________________________________________________________
822 void AliDisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
824 // change viewing angles for current event
827 fDrawAllViews = kFALSE;
833 TView *view = gPad->GetView();
834 if (view) view->SetView(fPhi, fTheta, fPsi, iret);
840 //_____________________________________________________________________________
841 void AliDisplay::ShowNextEvent(Int_t delta)
843 // Display (current event_number+delta)
844 // delta = 1 shown next event
845 // delta = -1 show previous event
849 Int_t currentEvent = gAlice->GetHeader()->GetEvent();
850 Int_t newEvent = currentEvent + delta;
851 gAlice->GetEvent(newEvent);
852 if (!gAlice->TreeH()) return;
859 //______________________________________________________________________________
860 void AliDisplay::UnZoom()
865 if (fZooms <= 0) return;
867 TPad *pad = (TPad*)gPad->GetPadSave();
868 pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);
872 //_____________________________________________________________________________
873 AliDisplay & AliDisplay::operator=(const AliDisplay &disp)
876 // Assignment operator