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.12 2000/12/12 13:18:59 hristov
19 Protection against FPE
21 Revision 1.11 2000/11/30 07:12:48 alibrary
22 Introducing new Rndm and QA classes
24 Revision 1.10 2000/10/02 21:28:14 fca
25 Removal of useless dependecies via forward declarations
27 Revision 1.9 2000/07/13 16:19:09 fca
28 Mainly coding conventions + some small bug fixes
30 Revision 1.8 2000/07/11 18:24:59 fca
31 Coding convention corrections + few minor bug fixes
33 Revision 1.7 1999/11/10 07:37:06 fca
34 Pads do not inherit editability from canvas any more
36 Revision 1.6 1999/11/09 07:38:52 fca
37 Changes for compatibility with version 2.23 of ROOT
39 Revision 1.5 1999/09/29 09:24:29 fca
40 Introduction of the Copyright and cvs Log
45 //////////////////////////////////////////////////////////////////////////
49 // Utility class to display ALICE outline, tracks, hits,.. //
51 //////////////////////////////////////////////////////////////////////////
57 #include <TPaveLabel.h>
58 #include <TPaveText.h>
62 #include <TSliderBox.h>
64 #include <TVirtualX.h>
68 #include "AliDetector.h"
69 #include "AliDisplay.h"
70 #include "AliPoints.h"
71 #include "TParticle.h"
72 #include "TGeometry.h"
74 static const Float_t kptcutmax = 2;
75 static const Float_t ketacutmax = 1.5;
80 //_____________________________________________________________________________
81 AliDisplay::AliDisplay()
84 // Default constructor
89 //_____________________________________________________________________________
90 AliDisplay::AliDisplay(Int_t size)
92 // Create an event display object.
93 // A canvas named "edisplay" is created with a vertical size in pixels
95 // A QUICK Overview of the Event Display functions
96 // ===============================================
98 // The event display can ve invoked by executing the macro "display.C"
99 // A canvas like in the picture below will appear.
101 // On the left side of the canvas, the following buttons appear:
102 // *Next* to move to the next event
103 // *Previous* to move to the previous event
104 // *Top View* to display a top view of the current event
105 // *Side View* to display a side view of the current event
106 // *Front View* to display a front view of the current event
107 // *All Views* to display front/side/top/30-30 views of the current event
108 // *OpenGL* to use OpenGl to view the current event.
109 // Note that OpenGL cannot be used across the network.
110 // Before using OpenGL, load the GL libraries
111 // by executing the macro GL.C (in $ROOTSYS/macros/GL.C.
112 // Once in GL, click the HELP button of the GL canvas.
113 // *X3D* to use X3D to view the current event (Unix only).
114 // Once in X3D, type M to see the list of all possible options.
115 // for example type J to zoom, K to unzoom
116 // use the mouse to rotate.
117 // *Pick* Select this option to be able to point on a track with the
118 // mouse. Once on the track, use the right button to select
119 // an action. For example, select SetMarkerAttributes to
120 // change the marker type/color/size for the track.
121 // *Zoom* Select this option (default) if you want to zoom.
122 // To zoom, simply select the selected area with the left button.
123 // *UnZoom* To revert to the previous picture size.
125 // slider R On the left side, the vertical slider can be used to
126 // set the default picture size.
127 // slider pcut At the top of the canvas, a slider can be used to change
128 // the momentum cut (or range) to display tracks.
129 // slider eta On the right side of the canvas, a vertical slider can be used
130 // to specify a rapidity range for the tracks.
132 // When you are in Zoom mode, you can click on the black part of the canvas
133 // to select special options with the right mouse button.
134 // This will display a pop-up menu with items like:
135 // *Disable detector*
136 // *Enable detector*, etc.
137 // For example select "Disable detector". You get a dialog box.
138 // Diable detector TRD for example.
140 // When you are in pick mode, you can "Inspect" the object pointed by the mouse.
141 // When you are on a track, select the menu item "InspectParticle"
142 // to display the current particle attributes.
144 // You can activate the Root browser by selecting the Inspect menu
145 // in the canvas tool bar menu. Then select "Start Browser"
146 // This will open a new canvas with the browser. At this point, you may want
147 // to display some histograms (from the Trees). Go to the "File" menu
148 // of the browser and click on "New canvas".
149 // In the browser, click on item "ROOT files" in the left pane.
150 // Click on galice.root.
152 // Click on TPC for example
153 // Click on any variable (eg TPC.fX) to histogram the variable.
155 // If you are lost, you can click on HELP in any Root canvas or browser.
158 <img src="picts/alidisplay.gif">
163 gAlice->SetDisplay(this);
165 // Initialize display default parameters
169 // Set front view by default
173 fDrawAllViews = kFALSE;
175 fDrawParticles = kTRUE;
180 // Create display canvas
182 if (ysize < 100) ysize = 750;
183 Int_t xsize = Int_t(size*830./ysize);
184 fCanvas = new TCanvas("Canvas", "ALICE Event Display",14,47,xsize,ysize);
185 fCanvas->ToggleEventStatus();
187 // Create main display pad
188 fPad = new TPad("viewpad", "Alice display",0.15,0,0.97,0.96);
191 fPad->SetFillColor(1);
192 fPad->SetBorderSize(2);
194 // Create user interface control pad
198 // Create Range and mode pad
201 fTrigPad = new TPad("trigger", "range and mode pad",0,0,dxtr,dytr);
202 fTrigPad->SetEditable(kFALSE);
205 fTrigPad->SetFillColor(22);
206 fTrigPad->SetBorderSize(2);
207 fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
208 fRangeSlider->SetObject(this);
209 char pickmode[] = "gAlice->Display()->SetPickMode()";
211 fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
212 fPickButton->SetFillColor(38);
214 char zoommode[] = "gAlice->Display()->SetZoomMode()";
215 fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
216 fZoomButton->SetFillColor(38);
218 fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
219 fArcButton->SetFillColor(kGreen);
221 char butUnzoom[] = "gAlice->Display()->UnZoom()";
222 TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
223 button->SetFillColor(38);
225 AppendPad(); // append display object as last object to force selection
227 // Create momentum cut slider pad
229 fCutPad = new TPad("cutSlider", "pcut slider pad",dxtr,.96,1,1);
232 fCutPad->SetFillColor(22);
233 fCutPad->SetBorderSize(2);
234 fCutSlider = new TSlider("pcut","Momentum cut",0,0,1,1);
235 fCutSlider->SetRange(fPTcut/kptcutmax,1);
236 fCutSlider->SetObject(this);
237 fCutSlider->SetFillColor(45);
238 TSliderBox *sbox = (TSliderBox*)fCutSlider->GetListOfPrimitives()->First();
239 sbox->SetFillColor(46);
241 TGaxis *cutaxis = new TGaxis(0.02,0.8,0.98,0.8,0,kptcutmax,510,"");
242 cutaxis->SetLabelSize(0.5);
243 cutaxis->SetTitleSize(0.6);
244 cutaxis->SetTitleOffset(0.5);
245 cutaxis->SetTitle("pcut . ");
246 fCutSlider->GetListOfPrimitives()->AddFirst(cutaxis);
248 // Create rapidity cut slider pad
250 fEtaPad = new TPad("EtaSlider", "Eta slider pad",0.97,0,1,0.96);
253 fEtaPad->SetFillColor(22);
254 fEtaPad->SetBorderSize(2);
255 fEtaSlider = new TSlider("etacut","Rapidity cut",0,0,1,1);
256 fEtaSlider->SetObject(this);
257 fEtaSlider->SetFillColor(45);
258 TSliderBox *sbox2 = (TSliderBox*)fEtaSlider->GetListOfPrimitives()->First();
259 sbox2->SetFillColor(46);
261 TGaxis *etaaxis = new TGaxis(0.9,0.02,0.9,0.98,-ketacutmax,ketacutmax,510,"");
262 etaaxis->SetLabelSize(0.5);
263 etaaxis->SetTitleSize(0.6);
264 etaaxis->SetTitleOffset(0.2);
265 cutaxis->SetTitle("Etacut . ");
266 fEtaSlider->GetListOfPrimitives()->AddFirst(etaaxis);
275 //_____________________________________________________________________________
276 AliDisplay::AliDisplay(const AliDisplay &disp)
284 //_____________________________________________________________________________
285 AliDisplay::~AliDisplay()
292 //_____________________________________________________________________________
293 void AliDisplay::Clear(Option_t *)
295 // Delete graphics temporary objects
298 //_____________________________________________________________________________
299 void AliDisplay::Copy(AliDisplay &disp) const
302 // Copy *this onto disp -- not implemented
304 Fatal("Copy","Not implemented~\n");
307 //----------------------------------------------------------------------------
308 void AliDisplay::ShowTrack(Int_t idx)
313 AliDetector *mTPC=(AliDetector*)gAlice->GetModule("TPC");
314 TObjArray *points=mTPC->Points();
315 int ntracks=points->GetEntriesFast();
316 for (int track=0;track<ntracks;track++) {
317 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
319 if (idx == pm->GetIndex()) {
320 pm->SetMarkerColor(2);
321 pm->SetMarkerStyle(22);
325 TClonesArray *particles=gAlice->Particles();
326 TParticle *p = (TParticle*)particles->UncheckedAt(idx);
327 printf("\nTrack index %d\n",idx);
328 printf("Particle ID %d\n",p->GetPdgCode());
329 printf("Parent %d\n",p->GetFirstMother());
330 printf("First child %d\n",p->GetFirstDaughter());
331 printf("Px,Py,Pz %f %f %f\n",p->Px(),p->Py(),p->Pz());
337 //----------------------------------------------------------------------------
338 void AliDisplay::HideTrack(Int_t idx) {
340 // Hide track on display
342 AliDetector *mTPC=(AliDetector*)gAlice->GetModule("TPC");
343 TObjArray *points=mTPC->Points();
344 int ntracks=points->GetEntriesFast();
345 for (int track=0;track<ntracks;track++) {
346 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
348 if (idx == pm->GetIndex()) {
349 pm->SetMarkerColor(5);
350 pm->SetMarkerStyle(1);
359 //_____________________________________________________________________________
360 void AliDisplay::DisableDetector(const char *name)
362 // Disable detector name from graphics views
364 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
370 //_____________________________________________________________________________
371 void AliDisplay::DisplayButtons()
373 // Create the user interface buttons
375 fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
376 fButtons->SetEditable(kFALSE);
378 fButtons->SetFillColor(38);
379 fButtons->SetBorderSize(2);
383 Float_t dbutton = 0.08;
390 char but1[] = "gAlice->Display()->ShowNextEvent(1)";
391 button = new TButton("Next",but1,x0,y-dbutton,x1,y);
392 button->SetFillColor(38);
396 char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
397 button = new TButton("Previous",but2,x0,y-dbutton,x1,y);
398 button->SetFillColor(38);
402 char but3[] = "gAlice->Display()->SetView(90,-90,90)";
403 button = new TButton("Top View",but3,x0,y-dbutton,x1,y);
404 button->SetFillColor(butcolor);
408 char but4[] = "gAlice->Display()->SetView(90,0,-90)";
409 button = new TButton("Side View",but4,x0,y-dbutton,x1,y);
410 button->SetFillColor(butcolor);
414 char but5[] = "gAlice->Display()->SetView(0,-90,0)";
415 button = new TButton("Front View",but5,x0,y-dbutton,x1,y);
416 button->SetFillColor(butcolor);
420 char but6[] = "gAlice->Display()->DrawAllViews()";
421 button = new TButton("All Views",but6,x0,y-dbutton,x1,y);
422 button->SetFillColor(butcolor);
426 char but7[] = "gAlice->Display()->DrawViewGL()";
427 button = new TButton("OpenGL",but7,x0,y-dbutton,x1,y);
428 button->SetFillColor(38);
432 char but8[] = "gAlice->Display()->DrawViewX3D()";
433 button = new TButton("X3D",but8,x0,y-dbutton,x1,y);
434 button->SetFillColor(38);
438 TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
439 diamond->SetFillColor(50);
440 diamond->SetTextAlign(22);
441 diamond->SetTextColor(5);
442 diamond->SetTextSize(0.11);
444 diamond->AddText(".. ");
445 diamond->AddText("ROOT");
446 diamond->AddText("ALICE");
447 diamond->AddText("... ");
448 diamond->AddText(" ");
451 //______________________________________________________________________________
452 Int_t AliDisplay::DistancetoPrimitive(Int_t px, Int_t)
454 // Compute distance from point px,py to objects in event
456 gPad->SetCursor(kCross);
458 if (gPad == fTrigPad) return 9999;
459 if (gPad == fCutPad) return 9999;
460 if (gPad == fEtaPad) return 9999;
462 const Int_t kbig = 9999;
464 Float_t xmin = gPad->GetX1();
465 Float_t xmax = gPad->GetX2();
466 Float_t dx = 0.02*(xmax - xmin);
467 Float_t x = gPad->AbsPixeltoX(px);
468 if (x < xmin+dx || x > xmax-dx) return dist;
470 if (fZoomMode) return 0;
474 //_____________________________________________________________________________
475 void AliDisplay::Draw(Option_t *)
477 // Display current event
486 DrawView(fTheta, fPhi, fPsi);
488 // Display the event number and title
493 //_____________________________________________________________________________
494 void AliDisplay::DrawAllViews()
496 // Draw front,top,side and 30 deg views
498 fDrawAllViews = kTRUE;
500 fPad->SetFillColor(15);
516 DrawView(90, -90, 90);
521 DrawView(90, 0, -90);
527 //_____________________________________________________________________________
528 void AliDisplay::DrawHits()
530 // Draw hits for all ALICE detectors
532 Float_t cutmin, cutmax, etamin, etamax, pmom, smin, smax, eta, theta, r;
540 smax = fCutSlider->GetMaximum();
541 smin = fCutSlider->GetMinimum();
542 cutmin = kptcutmax*smin;
543 if (smax < 0.98) cutmax = kptcutmax*smax;
544 else cutmax = 100000;
547 smax = fEtaSlider->GetMaximum();
548 smin = fEtaSlider->GetMinimum();
549 etamin = ketacutmax*(2*smin-1);
550 etamax = ketacutmax*(2*smax-1);
551 if (smin < 0.02) etamin = -1000;
552 if (smax > 0.98) etamax = 1000;
554 TIter next(gAlice->Modules());
557 while((module = (AliModule*)next())) {
558 if (!module->IsActive()) continue;
559 points = module->Points();
560 if (!points) continue;
561 ntracks = points->GetEntriesFast();
562 for (track=0;track<ntracks;track++) {
563 pm = (AliPoints*)points->UncheckedAt(track);
565 particle = pm->GetParticle();
566 if (!particle) continue;
567 pmom = particle->P();
568 if (pmom < cutmin) continue;
569 if (pmom > cutmax) continue;
570 // as a first approximation, take eta of first point
572 r = TMath::Sqrt(pxyz[0]*pxyz[0] + pxyz[1]*pxyz[1]);
573 theta = TMath::ATan2(r,TMath::Abs(pxyz[2]));
574 if(theta) eta = -TMath::Log(TMath::Abs(TMath::Tan(0.5*theta))); else eta = 1e10;
575 if (pxyz[2] < 0) eta = -eta;
576 if (eta < etamin || eta > etamax) continue;
578 fHitsCuts += pm->GetN();
583 //_____________________________________________________________________________
584 void AliDisplay::DrawTitle(Option_t *option)
586 // Draw the event title
588 Float_t xmin = gPad->GetX1();
589 Float_t xmax = gPad->GetX2();
590 Float_t ymin = gPad->GetY1();
591 Float_t ymax = gPad->GetY2();
592 Float_t dx = xmax-xmin;
593 Float_t dy = ymax-ymin;
595 if (strlen(option) == 0) {
596 TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
597 title->SetBit(kCanDelete);
598 title->SetFillColor(42);
601 sprintf(ptitle,"Alice event: %d, Run:%d",gAlice->GetHeader()->GetEvent(), gAlice->GetHeader()->GetRun());
602 title->AddText(ptitle);
603 Int_t nparticles = gAlice->Particles()->GetEntriesFast();
604 sprintf(ptitle,"Nparticles = %d Nhits = %d",nparticles, fHitsCuts);
605 title->AddText(ptitle);
607 TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
608 label->SetBit(kCanDelete);
609 label->SetFillColor(42);
614 //_____________________________________________________________________________
615 void AliDisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
617 // Draw a view of ALICE
619 gPad->SetCursor(kWatch);
620 gPad->SetFillColor(1);
624 TView *view = new TView(1);
625 Float_t range = fRrange*fRangeSlider->GetMaximum();
626 view->SetRange(-range,-range,-range,range, range, range);
633 // Display Alice Geometry
634 gAlice->GetGeometry()->Draw("same");
636 //Loop on all detectors to add their products to the pad
639 // add itself to the list (must be last)
642 view->SetView(phi, theta, psi, iret);
645 //_____________________________________________________________________________
646 void AliDisplay::DrawViewGL()
648 // Draw current view using OPENGL
650 TPad *pad = (TPad*)gPad->GetPadSave();
652 TView *view = pad->GetView();
657 //_____________________________________________________________________________
658 void AliDisplay::DrawViewX3D()
660 // Draw current view using X3D
662 TPad *pad = (TPad*)gPad->GetPadSave();
664 TView *view = pad->GetView();
669 //_____________________________________________________________________________
670 void AliDisplay::EnableDetector(const char *name)
672 // Enable detector name in graphics views
674 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
680 //______________________________________________________________________________
681 void AliDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
683 // Execute action corresponding to the mouse event
685 static Float_t x0, y0, x1, y1;
687 static Int_t pxold, pyold;
688 static Int_t px0, py0;
689 static Int_t linedrawn;
692 if (px == 0 && py == 0) { //when called by sliders
693 if (event == kButton1Up) {
698 if (!fZoomMode && gPad->GetView()) {
699 gPad->GetView()->ExecuteRotateView(event, px, py);
703 // something to zoom ?
704 // fPad->SetCursor(kCross);
705 gPad->SetCursor(kCross);
710 gVirtualX->SetLineColor(-1);
711 gPad->TAttLine::Modify(); //Change line attributes only if necessary
712 x0 = gPad->AbsPixeltoX(px);
713 y0 = gPad->AbsPixeltoY(py);
715 pxold = px; pyold = py;
720 if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
724 gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
728 gPad->GetCanvas()->FeedbackMode(kFALSE);
729 if (px == px0) return;
730 if (py == py0) return;
731 x1 = gPad->AbsPixeltoX(px);
732 y1 = gPad->AbsPixeltoY(py);
734 if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
735 if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
736 gPad->Range(x0,y0,x1,y1);
737 if (fZooms < kMAXZOOMS-1) {
739 fZoomX0[fZooms] = x0;
740 fZoomY0[fZooms] = y0;
741 fZoomX1[fZooms] = x1;
742 fZoomY1[fZooms] = y1;
744 gPad->Modified(kTRUE);
750 //___________________________________________
751 void AliDisplay::LoadPoints()
753 // Read hits info and store x,y,z info in arrays fPoints
754 // Loop on all detectors
756 gAlice->ResetPoints();
757 TIter next(gAlice->Modules());
759 Int_t ntracks = gAlice->GetNtrack();
760 for (Int_t track=0; track<ntracks;track++) {
762 gAlice->TreeH()->GetEvent(track);
763 while((module = (AliModule*)next())) {
764 module->LoadPoints(track);
770 //_____________________________________________________________________________
771 void AliDisplay::Paint(Option_t *)
773 // Paint miscellaneous items
777 //_____________________________________________________________________________
778 void AliDisplay::SetPickMode()
781 // Set Pick Mode -- disable zoom
785 fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
786 fTrigPad->Modified();
789 //_____________________________________________________________________________
790 void AliDisplay::SetZoomMode()
793 // Set Zoom Mode -- disable pick
797 fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
798 fTrigPad->Modified();
801 //_____________________________________________________________________________
802 void AliDisplay::SetPTcut(Float_t ptcut)
814 //_____________________________________________________________________________
815 void AliDisplay::SetRange(Float_t rrange, Float_t zrange)
817 // Set view range along R and Z
826 //_____________________________________________________________________________
827 void AliDisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
829 // change viewing angles for current event
832 fDrawAllViews = kFALSE;
838 TView *view = gPad->GetView();
839 if (view) view->SetView(fPhi, fTheta, fPsi, iret);
845 //_____________________________________________________________________________
846 void AliDisplay::ShowNextEvent(Int_t delta)
848 // Display (current event_number+delta)
849 // delta = 1 shown next event
850 // delta = -1 show previous event
854 Int_t currentEvent = gAlice->GetHeader()->GetEvent();
855 Int_t newEvent = currentEvent + delta;
856 gAlice->GetEvent(newEvent);
857 if (!gAlice->TreeH()) return;
864 //______________________________________________________________________________
865 void AliDisplay::UnZoom()
870 if (fZooms <= 0) return;
872 TPad *pad = (TPad*)gPad->GetPadSave();
873 pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);
877 //_____________________________________________________________________________
878 AliDisplay & AliDisplay::operator=(const AliDisplay &disp)
881 // Assignment operator