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.15 2001/05/16 14:57:22 alibrary
19 New files for folders and Stack
21 Revision 1.14 2001/01/26 19:58:48 hristov
22 Major upgrade of AliRoot code
24 Revision 1.13 2000/12/21 15:30:18 fca
25 Correcting coding convention violations
27 Revision 1.12 2000/12/12 13:18:59 hristov
28 Protection against FPE
30 Revision 1.11 2000/11/30 07:12:48 alibrary
31 Introducing new Rndm and QA classes
33 Revision 1.10 2000/10/02 21:28:14 fca
34 Removal of useless dependecies via forward declarations
36 Revision 1.9 2000/07/13 16:19:09 fca
37 Mainly coding conventions + some small bug fixes
39 Revision 1.8 2000/07/11 18:24:59 fca
40 Coding convention corrections + few minor bug fixes
42 Revision 1.7 1999/11/10 07:37:06 fca
43 Pads do not inherit editability from canvas any more
45 Revision 1.6 1999/11/09 07:38:52 fca
46 Changes for compatibility with version 2.23 of ROOT
48 Revision 1.5 1999/09/29 09:24:29 fca
49 Introduction of the Copyright and cvs Log
54 //////////////////////////////////////////////////////////////////////////
58 // Utility class to display ALICE outline, tracks, hits,.. //
60 //////////////////////////////////////////////////////////////////////////
66 #include <TPaveLabel.h>
67 #include <TPaveText.h>
71 #include <TSliderBox.h>
73 #include <TVirtualX.h>
77 #include "AliDetector.h"
78 #include "AliDisplay.h"
79 #include "AliPoints.h"
80 #include "TParticle.h"
81 #include "TGeometry.h"
82 #include "AliHeader.h"
84 static const Float_t kptcutmax = 2;
85 static const Float_t ketacutmax = 1.5;
90 //_____________________________________________________________________________
91 AliDisplay::AliDisplay()
94 // Default constructor
99 //_____________________________________________________________________________
100 AliDisplay::AliDisplay(Int_t size)
102 // Create an event display object.
103 // A canvas named "edisplay" is created with a vertical size in pixels
105 // A QUICK Overview of the Event Display functions
106 // ===============================================
108 // The event display can ve invoked by executing the macro "display.C"
109 // A canvas like in the picture below will appear.
111 // On the left side of the canvas, the following buttons appear:
112 // *Next* to move to the next event
113 // *Previous* to move to the previous event
114 // *Top View* to display a top view of the current event
115 // *Side View* to display a side view of the current event
116 // *Front View* to display a front view of the current event
117 // *All Views* to display front/side/top/30-30 views of the current event
118 // *OpenGL* to use OpenGl to view the current event.
119 // Note that OpenGL cannot be used across the network.
120 // Before using OpenGL, load the GL libraries
121 // by executing the macro GL.C (in $ROOTSYS/macros/GL.C.
122 // Once in GL, click the HELP button of the GL canvas.
123 // *X3D* to use X3D to view the current event (Unix only).
124 // Once in X3D, type M to see the list of all possible options.
125 // for example type J to zoom, K to unzoom
126 // use the mouse to rotate.
127 // *Pick* Select this option to be able to point on a track with the
128 // mouse. Once on the track, use the right button to select
129 // an action. For example, select SetMarkerAttributes to
130 // change the marker type/color/size for the track.
131 // *Zoom* Select this option (default) if you want to zoom.
132 // To zoom, simply select the selected area with the left button.
133 // *UnZoom* To revert to the previous picture size.
135 // slider R On the left side, the vertical slider can be used to
136 // set the default picture size.
137 // slider pcut At the top of the canvas, a slider can be used to change
138 // the momentum cut (or range) to display tracks.
139 // slider eta On the right side of the canvas, a vertical slider can be used
140 // to specify a rapidity range for the tracks.
142 // When you are in Zoom mode, you can click on the black part of the canvas
143 // to select special options with the right mouse button.
144 // This will display a pop-up menu with items like:
145 // *Disable detector*
146 // *Enable detector*, etc.
147 // For example select "Disable detector". You get a dialog box.
148 // Diable detector TRD for example.
150 // When you are in pick mode, you can "Inspect" the object pointed by the mouse.
151 // When you are on a track, select the menu item "InspectParticle"
152 // to display the current particle attributes.
154 // You can activate the Root browser by selecting the Inspect menu
155 // in the canvas tool bar menu. Then select "Start Browser"
156 // This will open a new canvas with the browser. At this point, you may want
157 // to display some histograms (from the Trees). Go to the "File" menu
158 // of the browser and click on "New canvas".
159 // In the browser, click on item "ROOT files" in the left pane.
160 // Click on galice.root.
162 // Click on TPC for example
163 // Click on any variable (eg TPC.fX) to histogram the variable.
165 // If you are lost, you can click on HELP in any Root canvas or browser.
168 <img src="picts/alidisplay.gif">
173 gAlice->SetDisplay(this);
175 // Initialize display default parameters
179 // Set front view by default
183 fDrawAllViews = kFALSE;
185 fDrawParticles = kTRUE;
190 // Create display canvas
192 if (ysize < 100) ysize = 750;
193 Int_t xsize = Int_t(size*830./ysize);
194 fCanvas = new TCanvas("Canvas", "ALICE Event Display",14,47,xsize,ysize);
195 fCanvas->ToggleEventStatus();
197 // Create main display pad
198 fPad = new TPad("viewpad", "Alice display",0.15,0,0.97,0.96);
201 fPad->SetFillColor(1);
202 fPad->SetBorderSize(2);
204 // Create user interface control pad
208 // Create Range and mode pad
211 fTrigPad = new TPad("trigger", "range and mode pad",0,0,dxtr,dytr);
214 fTrigPad->SetFillColor(22);
215 fTrigPad->SetBorderSize(2);
216 fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
217 fRangeSlider->SetObject(this);
218 char pickmode[] = "gAlice->Display()->SetPickMode()";
220 fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
221 fPickButton->SetFillColor(38);
223 char zoommode[] = "gAlice->Display()->SetZoomMode()";
224 fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
225 fZoomButton->SetFillColor(38);
227 fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
228 fArcButton->SetFillColor(kGreen);
230 char butUnzoom[] = "gAlice->Display()->UnZoom()";
231 TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
232 button->SetFillColor(38);
234 AppendPad(); // append display object as last object to force selection
236 // Create momentum cut slider pad
238 fCutPad = new TPad("cutSlider", "pcut slider pad",dxtr,.96,1,1);
241 fCutPad->SetFillColor(22);
242 fCutPad->SetBorderSize(2);
243 fCutSlider = new TSlider("pcut","Momentum cut",0,0,1,1);
244 fCutSlider->SetRange(fPTcut/kptcutmax,1);
245 fCutSlider->SetObject(this);
246 fCutSlider->SetFillColor(45);
247 TSliderBox *sbox = (TSliderBox*)fCutSlider->GetListOfPrimitives()->First();
248 sbox->SetFillColor(46);
250 TGaxis *cutaxis = new TGaxis(0.02,0.8,0.98,0.8,0,kptcutmax,510,"");
251 cutaxis->SetLabelSize(0.5);
252 cutaxis->SetTitleSize(0.6);
253 cutaxis->SetTitleOffset(0.5);
254 cutaxis->SetTitle("pcut . ");
255 fCutSlider->GetListOfPrimitives()->AddFirst(cutaxis);
257 // Create rapidity cut slider pad
259 fEtaPad = new TPad("EtaSlider", "Eta slider pad",0.97,0,1,0.96);
262 fEtaPad->SetFillColor(22);
263 fEtaPad->SetBorderSize(2);
264 fEtaSlider = new TSlider("etacut","Rapidity cut",0,0,1,1);
265 fEtaSlider->SetObject(this);
266 fEtaSlider->SetFillColor(45);
267 TSliderBox *sbox2 = (TSliderBox*)fEtaSlider->GetListOfPrimitives()->First();
268 sbox2->SetFillColor(46);
270 TGaxis *etaaxis = new TGaxis(0.9,0.02,0.9,0.98,-ketacutmax,ketacutmax,510,"");
271 etaaxis->SetLabelSize(0.5);
272 etaaxis->SetTitleSize(0.6);
273 etaaxis->SetTitleOffset(0.2);
274 cutaxis->SetTitle("Etacut . ");
275 fEtaSlider->GetListOfPrimitives()->AddFirst(etaaxis);
278 fTrigPad->SetEditable(kFALSE);
279 fButtons->SetEditable(kFALSE);
287 //_____________________________________________________________________________
288 AliDisplay::AliDisplay(const AliDisplay &disp)
296 //_____________________________________________________________________________
297 AliDisplay::~AliDisplay()
304 //_____________________________________________________________________________
305 void AliDisplay::Clear(Option_t *)
307 // Delete graphics temporary objects
310 //_____________________________________________________________________________
311 void AliDisplay::Copy(AliDisplay &disp) const
314 // Copy *this onto disp -- not implemented
316 Fatal("Copy","Not implemented~\n");
319 //----------------------------------------------------------------------------
320 void AliDisplay::ShowTrack(Int_t idx)
325 AliDetector *mTPC=(AliDetector*)gAlice->GetModule("TPC");
326 TObjArray *points=mTPC->Points();
327 int ntracks=points->GetEntriesFast();
328 for (int track=0;track<ntracks;track++) {
329 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
331 if (idx == pm->GetIndex()) {
332 pm->SetMarkerColor(2);
333 pm->SetMarkerStyle(22);
337 // TClonesArray *particles=gAlice->Particles();
338 // TParticle *p = (TParticle*)particles->UncheckedAt(idx);
339 TParticle *p = gAlice->Particle(idx);
340 printf("\nTrack index %d\n",idx);
341 printf("Particle ID %d\n",p->GetPdgCode());
342 printf("Parent %d\n",p->GetFirstMother());
343 printf("First child %d\n",p->GetFirstDaughter());
344 printf("Px,Py,Pz %f %f %f\n",p->Px(),p->Py(),p->Pz());
350 //----------------------------------------------------------------------------
351 void AliDisplay::HideTrack(Int_t idx) {
353 // Hide track on display
355 AliDetector *mTPC=(AliDetector*)gAlice->GetModule("TPC");
356 TObjArray *points=mTPC->Points();
357 int ntracks=points->GetEntriesFast();
358 for (int track=0;track<ntracks;track++) {
359 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
361 if (idx == pm->GetIndex()) {
362 pm->SetMarkerColor(5);
363 pm->SetMarkerStyle(1);
372 //_____________________________________________________________________________
373 void AliDisplay::DisableDetector(const char *name)
375 // Disable detector name from graphics views
377 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
383 //_____________________________________________________________________________
384 void AliDisplay::DisplayButtons()
386 // Create the user interface buttons
388 fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
390 fButtons->SetFillColor(38);
391 fButtons->SetBorderSize(2);
395 Float_t dbutton = 0.08;
402 char but1[] = "gAlice->Display()->ShowNextEvent(1)";
403 button = new TButton("Next",but1,x0,y-dbutton,x1,y);
404 button->SetFillColor(38);
408 char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
409 button = new TButton("Previous",but2,x0,y-dbutton,x1,y);
410 button->SetFillColor(38);
414 char but3[] = "gAlice->Display()->SetView(90,-90,90)";
415 button = new TButton("Top View",but3,x0,y-dbutton,x1,y);
416 button->SetFillColor(butcolor);
420 char but4[] = "gAlice->Display()->SetView(90,0,-90)";
421 button = new TButton("Side View",but4,x0,y-dbutton,x1,y);
422 button->SetFillColor(butcolor);
426 char but5[] = "gAlice->Display()->SetView(0,-90,0)";
427 button = new TButton("Front View",but5,x0,y-dbutton,x1,y);
428 button->SetFillColor(butcolor);
432 char but6[] = "gAlice->Display()->DrawAllViews()";
433 button = new TButton("All Views",but6,x0,y-dbutton,x1,y);
434 button->SetFillColor(butcolor);
438 char but7[] = "gAlice->Display()->DrawViewGL()";
439 button = new TButton("OpenGL",but7,x0,y-dbutton,x1,y);
440 button->SetFillColor(38);
444 char but8[] = "gAlice->Display()->DrawViewX3D()";
445 button = new TButton("X3D",but8,x0,y-dbutton,x1,y);
446 button->SetFillColor(38);
450 TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
451 diamond->SetFillColor(50);
452 diamond->SetTextAlign(22);
453 diamond->SetTextColor(5);
454 diamond->SetTextSize(0.11);
456 diamond->AddText(".. ");
457 diamond->AddText("ROOT");
458 diamond->AddText("ALICE");
459 diamond->AddText("... ");
460 diamond->AddText(" ");
463 //______________________________________________________________________________
464 Int_t AliDisplay::DistancetoPrimitive(Int_t px, Int_t)
466 // Compute distance from point px,py to objects in event
468 gPad->SetCursor(kCross);
470 if (gPad == fTrigPad) return 9999;
471 if (gPad == fCutPad) return 9999;
472 if (gPad == fEtaPad) return 9999;
474 const Int_t kbig = 9999;
476 Float_t xmin = gPad->GetX1();
477 Float_t xmax = gPad->GetX2();
478 Float_t dx = 0.02*(xmax - xmin);
479 Float_t x = gPad->AbsPixeltoX(px);
480 if (x < xmin+dx || x > xmax-dx) return dist;
482 if (fZoomMode) return 0;
486 //_____________________________________________________________________________
487 void AliDisplay::Draw(Option_t *)
489 // Display current event
498 DrawView(fTheta, fPhi, fPsi);
500 // Display the event number and title
505 //_____________________________________________________________________________
506 void AliDisplay::DrawAllViews()
508 // Draw front,top,side and 30 deg views
510 fDrawAllViews = kTRUE;
512 fPad->SetFillColor(15);
528 DrawView(90, -90, 90);
533 DrawView(90, 0, -90);
539 //_____________________________________________________________________________
540 void AliDisplay::DrawHits()
542 // Draw hits for all ALICE detectors
544 Float_t cutmin, cutmax, etamin, etamax, pmom, smin, smax, eta, theta, r;
552 smax = fCutSlider->GetMaximum();
553 smin = fCutSlider->GetMinimum();
554 cutmin = kptcutmax*smin;
555 if (smax < 0.98) cutmax = kptcutmax*smax;
556 else cutmax = 100000;
559 smax = fEtaSlider->GetMaximum();
560 smin = fEtaSlider->GetMinimum();
561 etamin = ketacutmax*(2*smin-1);
562 etamax = ketacutmax*(2*smax-1);
563 if (smin < 0.02) etamin = -1000;
564 if (smax > 0.98) etamax = 1000;
566 TIter next(gAlice->Modules());
569 while((module = (AliModule*)next())) {
570 if (!module->IsActive()) continue;
571 points = module->Points();
572 if (!points) continue;
573 ntracks = points->GetEntriesFast();
574 for (track=0;track<ntracks;track++) {
575 pm = (AliPoints*)points->UncheckedAt(track);
577 particle = pm->GetParticle();
578 if (!particle) continue;
579 pmom = particle->P();
580 if (pmom < cutmin) continue;
581 if (pmom > cutmax) continue;
582 // as a first approximation, take eta of first point
584 r = TMath::Sqrt(pxyz[0]*pxyz[0] + pxyz[1]*pxyz[1]);
585 theta = TMath::ATan2(r,TMath::Abs(pxyz[2]));
586 if(theta) eta = -TMath::Log(TMath::Abs(TMath::Tan(0.5*theta))); else eta = 1e10;
587 if (pxyz[2] < 0) eta = -eta;
588 if (eta < etamin || eta > etamax) continue;
590 fHitsCuts += pm->GetN();
595 //_____________________________________________________________________________
596 void AliDisplay::DrawTitle(Option_t *option)
598 // Draw the event title
600 Float_t xmin = gPad->GetX1();
601 Float_t xmax = gPad->GetX2();
602 Float_t ymin = gPad->GetY1();
603 Float_t ymax = gPad->GetY2();
604 Float_t dx = xmax-xmin;
605 Float_t dy = ymax-ymin;
607 if (strlen(option) == 0) {
608 TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
609 title->SetBit(kCanDelete);
610 title->SetFillColor(42);
613 sprintf(ptitle,"Alice event: %d, Run:%d",gAlice->GetHeader()->GetEvent(), gAlice->GetHeader()->GetRun());
614 title->AddText(ptitle);
615 Int_t nparticles = gAlice->Particles()->GetEntriesFast();
616 sprintf(ptitle,"Nparticles = %d Nhits = %d",nparticles, fHitsCuts);
617 title->AddText(ptitle);
619 TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
620 label->SetBit(kCanDelete);
621 label->SetFillColor(42);
626 //_____________________________________________________________________________
627 void AliDisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
629 // Draw a view of ALICE
631 gPad->SetCursor(kWatch);
632 gPad->SetFillColor(1);
636 TView *view = new TView(1);
637 Float_t range = fRrange*fRangeSlider->GetMaximum();
638 view->SetRange(-range,-range,-range,range, range, range);
645 // Display Alice Geometry
646 gAlice->GetGeometry()->Draw("same");
648 //Loop on all detectors to add their products to the pad
651 // add itself to the list (must be last)
654 view->SetView(phi, theta, psi, iret);
657 //_____________________________________________________________________________
658 void AliDisplay::DrawViewGL()
660 // Draw current view using OPENGL
662 TPad *pad = (TPad*)gPad->GetPadSave();
664 TView *view = pad->GetView();
669 //_____________________________________________________________________________
670 void AliDisplay::DrawViewX3D()
672 // Draw current view using X3D
674 TPad *pad = (TPad*)gPad->GetPadSave();
676 TView *view = pad->GetView();
681 //_____________________________________________________________________________
682 void AliDisplay::EnableDetector(const char *name)
684 // Enable detector name in graphics views
686 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
692 //______________________________________________________________________________
693 void AliDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
695 // Execute action corresponding to the mouse event
697 static Float_t x0, y0, x1, y1;
699 static Int_t pxold, pyold;
700 static Int_t px0, py0;
701 static Int_t linedrawn;
704 if (px == 0 && py == 0) { //when called by sliders
705 if (event == kButton1Up) {
710 if (!fZoomMode && gPad->GetView()) {
711 gPad->GetView()->ExecuteRotateView(event, px, py);
715 // something to zoom ?
716 // fPad->SetCursor(kCross);
717 gPad->SetCursor(kCross);
722 gVirtualX->SetLineColor(-1);
723 gPad->TAttLine::Modify(); //Change line attributes only if necessary
724 x0 = gPad->AbsPixeltoX(px);
725 y0 = gPad->AbsPixeltoY(py);
727 pxold = px; pyold = py;
732 if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
736 gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
740 gPad->GetCanvas()->FeedbackMode(kFALSE);
741 if (px == px0) return;
742 if (py == py0) return;
743 x1 = gPad->AbsPixeltoX(px);
744 y1 = gPad->AbsPixeltoY(py);
746 if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
747 if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
748 gPad->Range(x0,y0,x1,y1);
749 if (fZooms < kMAXZOOMS-1) {
751 fZoomX0[fZooms] = x0;
752 fZoomY0[fZooms] = y0;
753 fZoomX1[fZooms] = x1;
754 fZoomY1[fZooms] = y1;
756 gPad->Modified(kTRUE);
762 //___________________________________________
763 void AliDisplay::LoadPoints()
765 // Read hits info and store x,y,z info in arrays fPoints
766 // Loop on all detectors
768 gAlice->ResetPoints();
769 TIter next(gAlice->Modules());
771 Int_t ntracks = gAlice->GetNtrack();
772 for (Int_t track=0; track<ntracks;track++) {
774 gAlice->TreeH()->GetEvent(track);
775 while((module = (AliModule*)next())) {
776 module->LoadPoints(track);
782 //_____________________________________________________________________________
783 void AliDisplay::Paint(Option_t *)
785 // Paint miscellaneous items
789 //_____________________________________________________________________________
790 void AliDisplay::SetPickMode()
793 // Set Pick Mode -- disable zoom
797 fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
798 fTrigPad->Modified();
801 //_____________________________________________________________________________
802 void AliDisplay::SetZoomMode()
805 // Set Zoom Mode -- disable pick
809 fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
810 fTrigPad->Modified();
813 //_____________________________________________________________________________
814 void AliDisplay::SetPTcut(Float_t ptcut)
826 //_____________________________________________________________________________
827 void AliDisplay::SetRange(Float_t rrange, Float_t zrange)
829 // Set view range along R and Z
838 //_____________________________________________________________________________
839 void AliDisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
841 // change viewing angles for current event
844 fDrawAllViews = kFALSE;
850 TView *view = gPad->GetView();
851 if (view) view->SetView(fPhi, fTheta, fPsi, iret);
857 //_____________________________________________________________________________
858 void AliDisplay::ShowNextEvent(Int_t delta)
860 // Display (current event_number+delta)
861 // delta = 1 shown next event
862 // delta = -1 show previous event
866 Int_t currentEvent = gAlice->GetHeader()->GetEvent();
867 Int_t newEvent = currentEvent + delta;
868 gAlice->GetEvent(newEvent);
869 if (!gAlice->TreeH()) return;
876 //______________________________________________________________________________
877 void AliDisplay::UnZoom()
882 if (fZooms <= 0) return;
884 TPad *pad = (TPad*)gPad->GetPadSave();
885 pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);
889 //_____________________________________________________________________________
890 AliDisplay & AliDisplay::operator=(const AliDisplay &disp)
893 // Assignment operator