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.16 2001/07/25 15:23:50 hristov
19 Changes needed to run with Root 3.01 (R.Brun)
21 Revision 1.15 2001/05/16 14:57:22 alibrary
22 New files for folders and Stack
24 Revision 1.14 2001/01/26 19:58:48 hristov
25 Major upgrade of AliRoot code
27 Revision 1.13 2000/12/21 15:30:18 fca
28 Correcting coding convention violations
30 Revision 1.12 2000/12/12 13:18:59 hristov
31 Protection against FPE
33 Revision 1.11 2000/11/30 07:12:48 alibrary
34 Introducing new Rndm and QA classes
36 Revision 1.10 2000/10/02 21:28:14 fca
37 Removal of useless dependecies via forward declarations
39 Revision 1.9 2000/07/13 16:19:09 fca
40 Mainly coding conventions + some small bug fixes
42 Revision 1.8 2000/07/11 18:24:59 fca
43 Coding convention corrections + few minor bug fixes
45 Revision 1.7 1999/11/10 07:37:06 fca
46 Pads do not inherit editability from canvas any more
48 Revision 1.6 1999/11/09 07:38:52 fca
49 Changes for compatibility with version 2.23 of ROOT
51 Revision 1.5 1999/09/29 09:24:29 fca
52 Introduction of the Copyright and cvs Log
57 //////////////////////////////////////////////////////////////////////////
61 // Utility class to display ALICE outline, tracks, hits,.. //
63 //////////////////////////////////////////////////////////////////////////
69 #include <TPaveLabel.h>
70 #include <TPaveText.h>
74 #include <TSliderBox.h>
76 #include <TVirtualX.h>
80 #include "AliDetector.h"
81 #include "AliDisplay.h"
82 #include "AliPoints.h"
83 #include "TParticle.h"
84 #include "TGeometry.h"
85 #include "AliHeader.h"
87 static const Float_t kptcutmax = 2;
88 static const Float_t ketacutmax = 1.5;
93 //_____________________________________________________________________________
94 AliDisplay::AliDisplay()
97 // Default constructor
114 //_____________________________________________________________________________
115 AliDisplay::AliDisplay(Int_t size)
117 // Create an event display object.
118 // A canvas named "edisplay" is created with a vertical size in pixels
120 // A QUICK Overview of the Event Display functions
121 // ===============================================
123 // The event display can ve invoked by executing the macro "display.C"
124 // A canvas like in the picture below will appear.
126 // On the left side of the canvas, the following buttons appear:
127 // *Next* to move to the next event
128 // *Previous* to move to the previous event
129 // *Top View* to display a top view of the current event
130 // *Side View* to display a side view of the current event
131 // *Front View* to display a front view of the current event
132 // *All Views* to display front/side/top/30-30 views of the current event
133 // *OpenGL* to use OpenGl to view the current event.
134 // Note that OpenGL cannot be used across the network.
135 // Before using OpenGL, load the GL libraries
136 // by executing the macro GL.C (in $ROOTSYS/macros/GL.C.
137 // Once in GL, click the HELP button of the GL canvas.
138 // *X3D* to use X3D to view the current event (Unix only).
139 // Once in X3D, type M to see the list of all possible options.
140 // for example type J to zoom, K to unzoom
141 // use the mouse to rotate.
142 // *Pick* Select this option to be able to point on a track with the
143 // mouse. Once on the track, use the right button to select
144 // an action. For example, select SetMarkerAttributes to
145 // change the marker type/color/size for the track.
146 // *Zoom* Select this option (default) if you want to zoom.
147 // To zoom, simply select the selected area with the left button.
148 // *UnZoom* To revert to the previous picture size.
150 // slider R On the left side, the vertical slider can be used to
151 // set the default picture size.
152 // slider pcut At the top of the canvas, a slider can be used to change
153 // the momentum cut (or range) to display tracks.
154 // slider eta On the right side of the canvas, a vertical slider can be used
155 // to specify a rapidity range for the tracks.
157 // When you are in Zoom mode, you can click on the black part of the canvas
158 // to select special options with the right mouse button.
159 // This will display a pop-up menu with items like:
160 // *Disable detector*
161 // *Enable detector*, etc.
162 // For example select "Disable detector". You get a dialog box.
163 // Diable detector TRD for example.
165 // When you are in pick mode, you can "Inspect" the object pointed by the mouse.
166 // When you are on a track, select the menu item "InspectParticle"
167 // to display the current particle attributes.
169 // You can activate the Root browser by selecting the Inspect menu
170 // in the canvas tool bar menu. Then select "Start Browser"
171 // This will open a new canvas with the browser. At this point, you may want
172 // to display some histograms (from the Trees). Go to the "File" menu
173 // of the browser and click on "New canvas".
174 // In the browser, click on item "ROOT files" in the left pane.
175 // Click on galice.root.
177 // Click on TPC for example
178 // Click on any variable (eg TPC.fX) to histogram the variable.
180 // If you are lost, you can click on HELP in any Root canvas or browser.
183 <img src="picts/alidisplay.gif">
188 gAlice->SetDisplay(this);
190 // Initialize display default parameters
194 // Set front view by default
198 fDrawAllViews = kFALSE;
200 fDrawParticles = kTRUE;
205 // Create display canvas
207 if (ysize < 100) ysize = 750;
208 Int_t xsize = Int_t(size*830./ysize);
209 fCanvas = new TCanvas("Canvas", "ALICE Event Display",14,47,xsize,ysize);
210 fCanvas->ToggleEventStatus();
212 // Create main display pad
213 fPad = new TPad("viewpad", "Alice display",0.15,0,0.97,0.96);
216 fPad->SetFillColor(1);
217 fPad->SetBorderSize(2);
219 // Create user interface control pad
223 // Create Range and mode pad
226 fTrigPad = new TPad("trigger", "range and mode pad",0,0,dxtr,dytr);
229 fTrigPad->SetFillColor(22);
230 fTrigPad->SetBorderSize(2);
231 fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
232 fRangeSlider->SetObject(this);
233 char pickmode[] = "gAlice->Display()->SetPickMode()";
235 fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
236 fPickButton->SetFillColor(38);
238 char zoommode[] = "gAlice->Display()->SetZoomMode()";
239 fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
240 fZoomButton->SetFillColor(38);
242 fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
243 fArcButton->SetFillColor(kGreen);
245 char butUnzoom[] = "gAlice->Display()->UnZoom()";
246 TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
247 button->SetFillColor(38);
249 AppendPad(); // append display object as last object to force selection
251 // Create momentum cut slider pad
253 fCutPad = new TPad("cutSlider", "pcut slider pad",dxtr,.96,1,1);
256 fCutPad->SetFillColor(22);
257 fCutPad->SetBorderSize(2);
258 fCutSlider = new TSlider("pcut","Momentum cut",0,0,1,1);
259 fCutSlider->SetRange(fPTcut/kptcutmax,1);
260 fCutSlider->SetObject(this);
261 fCutSlider->SetFillColor(45);
262 TSliderBox *sbox = (TSliderBox*)fCutSlider->GetListOfPrimitives()->First();
263 sbox->SetFillColor(46);
265 TGaxis *cutaxis = new TGaxis(0.02,0.8,0.98,0.8,0,kptcutmax,510,"");
266 cutaxis->SetLabelSize(0.5);
267 cutaxis->SetTitleSize(0.6);
268 cutaxis->SetTitleOffset(0.5);
269 cutaxis->SetTitle("pcut . ");
270 fCutSlider->GetListOfPrimitives()->AddFirst(cutaxis);
272 // Create rapidity cut slider pad
274 fEtaPad = new TPad("EtaSlider", "Eta slider pad",0.97,0,1,0.96);
277 fEtaPad->SetFillColor(22);
278 fEtaPad->SetBorderSize(2);
279 fEtaSlider = new TSlider("etacut","Rapidity cut",0,0,1,1);
280 fEtaSlider->SetObject(this);
281 fEtaSlider->SetFillColor(45);
282 TSliderBox *sbox2 = (TSliderBox*)fEtaSlider->GetListOfPrimitives()->First();
283 sbox2->SetFillColor(46);
285 TGaxis *etaaxis = new TGaxis(0.9,0.02,0.9,0.98,-ketacutmax,ketacutmax,510,"");
286 etaaxis->SetLabelSize(0.5);
287 etaaxis->SetTitleSize(0.6);
288 etaaxis->SetTitleOffset(0.2);
289 cutaxis->SetTitle("Etacut . ");
290 fEtaSlider->GetListOfPrimitives()->AddFirst(etaaxis);
293 fTrigPad->SetEditable(kFALSE);
294 fButtons->SetEditable(kFALSE);
302 //_____________________________________________________________________________
303 AliDisplay::AliDisplay(const AliDisplay &disp)
311 //_____________________________________________________________________________
312 AliDisplay::~AliDisplay()
319 //_____________________________________________________________________________
320 void AliDisplay::Clear(Option_t *)
322 // Delete graphics temporary objects
325 //_____________________________________________________________________________
326 void AliDisplay::Copy(AliDisplay &disp) const
329 // Copy *this onto disp -- not implemented
331 Fatal("Copy","Not implemented~\n");
334 //----------------------------------------------------------------------------
335 void AliDisplay::ShowTrack(Int_t idx)
340 AliDetector *mTPC=(AliDetector*)gAlice->GetModule("TPC");
341 TObjArray *points=mTPC->Points();
342 int ntracks=points->GetEntriesFast();
343 for (int track=0;track<ntracks;track++) {
344 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
346 if (idx == pm->GetIndex()) {
347 pm->SetMarkerColor(2);
348 pm->SetMarkerStyle(22);
352 // TClonesArray *particles=gAlice->Particles();
353 // TParticle *p = (TParticle*)particles->UncheckedAt(idx);
354 TParticle *p = gAlice->Particle(idx);
355 printf("\nTrack index %d\n",idx);
356 printf("Particle ID %d\n",p->GetPdgCode());
357 printf("Parent %d\n",p->GetFirstMother());
358 printf("First child %d\n",p->GetFirstDaughter());
359 printf("Px,Py,Pz %f %f %f\n",p->Px(),p->Py(),p->Pz());
365 //----------------------------------------------------------------------------
366 void AliDisplay::HideTrack(Int_t idx) {
368 // Hide track on display
370 AliDetector *mTPC=(AliDetector*)gAlice->GetModule("TPC");
371 TObjArray *points=mTPC->Points();
372 int ntracks=points->GetEntriesFast();
373 for (int track=0;track<ntracks;track++) {
374 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
376 if (idx == pm->GetIndex()) {
377 pm->SetMarkerColor(5);
378 pm->SetMarkerStyle(1);
387 //_____________________________________________________________________________
388 void AliDisplay::DisableDetector(const char *name)
390 // Disable detector name from graphics views
392 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
398 //_____________________________________________________________________________
399 void AliDisplay::DisplayButtons()
401 // Create the user interface buttons
403 fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
405 fButtons->SetFillColor(38);
406 fButtons->SetBorderSize(2);
410 Float_t dbutton = 0.08;
417 char but1[] = "gAlice->Display()->ShowNextEvent(1)";
418 button = new TButton("Next",but1,x0,y-dbutton,x1,y);
419 button->SetFillColor(38);
423 char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
424 button = new TButton("Previous",but2,x0,y-dbutton,x1,y);
425 button->SetFillColor(38);
429 char but3[] = "gAlice->Display()->SetView(90,-90,90)";
430 button = new TButton("Top View",but3,x0,y-dbutton,x1,y);
431 button->SetFillColor(butcolor);
435 char but4[] = "gAlice->Display()->SetView(90,0,-90)";
436 button = new TButton("Side View",but4,x0,y-dbutton,x1,y);
437 button->SetFillColor(butcolor);
441 char but5[] = "gAlice->Display()->SetView(0,-90,0)";
442 button = new TButton("Front View",but5,x0,y-dbutton,x1,y);
443 button->SetFillColor(butcolor);
447 char but6[] = "gAlice->Display()->DrawAllViews()";
448 button = new TButton("All Views",but6,x0,y-dbutton,x1,y);
449 button->SetFillColor(butcolor);
453 char but7[] = "gAlice->Display()->DrawViewGL()";
454 button = new TButton("OpenGL",but7,x0,y-dbutton,x1,y);
455 button->SetFillColor(38);
459 char but8[] = "gAlice->Display()->DrawViewX3D()";
460 button = new TButton("X3D",but8,x0,y-dbutton,x1,y);
461 button->SetFillColor(38);
465 TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
466 diamond->SetFillColor(50);
467 diamond->SetTextAlign(22);
468 diamond->SetTextColor(5);
469 diamond->SetTextSize(0.11);
471 diamond->AddText(".. ");
472 diamond->AddText("ROOT");
473 diamond->AddText("ALICE");
474 diamond->AddText("... ");
475 diamond->AddText(" ");
478 //______________________________________________________________________________
479 Int_t AliDisplay::DistancetoPrimitive(Int_t px, Int_t)
481 // Compute distance from point px,py to objects in event
483 gPad->SetCursor(kCross);
485 if (gPad == fTrigPad) return 9999;
486 if (gPad == fCutPad) return 9999;
487 if (gPad == fEtaPad) return 9999;
489 const Int_t kbig = 9999;
491 Float_t xmin = gPad->GetX1();
492 Float_t xmax = gPad->GetX2();
493 Float_t dx = 0.02*(xmax - xmin);
494 Float_t x = gPad->AbsPixeltoX(px);
495 if (x < xmin+dx || x > xmax-dx) return dist;
497 if (fZoomMode) return 0;
501 //_____________________________________________________________________________
502 void AliDisplay::Draw(Option_t *)
504 // Display current event
513 DrawView(fTheta, fPhi, fPsi);
515 // Display the event number and title
520 //_____________________________________________________________________________
521 void AliDisplay::DrawAllViews()
523 // Draw front,top,side and 30 deg views
525 fDrawAllViews = kTRUE;
527 fPad->SetFillColor(15);
543 DrawView(90, -90, 90);
548 DrawView(90, 0, -90);
554 //_____________________________________________________________________________
555 void AliDisplay::DrawHits()
557 // Draw hits for all ALICE detectors
559 Float_t cutmin, cutmax, etamin, etamax, pmom, smin, smax, eta, theta, r;
567 smax = fCutSlider->GetMaximum();
568 smin = fCutSlider->GetMinimum();
569 cutmin = kptcutmax*smin;
570 if (smax < 0.98) cutmax = kptcutmax*smax;
571 else cutmax = 100000;
574 smax = fEtaSlider->GetMaximum();
575 smin = fEtaSlider->GetMinimum();
576 etamin = ketacutmax*(2*smin-1);
577 etamax = ketacutmax*(2*smax-1);
578 if (smin < 0.02) etamin = -1000;
579 if (smax > 0.98) etamax = 1000;
581 TIter next(gAlice->Modules());
584 while((module = (AliModule*)next())) {
585 if (!module->IsActive()) continue;
586 points = module->Points();
587 if (!points) continue;
588 ntracks = points->GetEntriesFast();
589 for (track=0;track<ntracks;track++) {
590 pm = (AliPoints*)points->UncheckedAt(track);
592 particle = pm->GetParticle();
593 if (!particle) continue;
594 pmom = particle->P();
595 if (pmom < cutmin) continue;
596 if (pmom > cutmax) continue;
597 // as a first approximation, take eta of first point
599 r = TMath::Sqrt(pxyz[0]*pxyz[0] + pxyz[1]*pxyz[1]);
600 theta = TMath::ATan2(r,TMath::Abs(pxyz[2]));
601 if(theta) eta = -TMath::Log(TMath::Abs(TMath::Tan(0.5*theta))); else eta = 1e10;
602 if (pxyz[2] < 0) eta = -eta;
603 if (eta < etamin || eta > etamax) continue;
605 fHitsCuts += pm->GetN();
610 //_____________________________________________________________________________
611 void AliDisplay::DrawTitle(Option_t *option)
613 // Draw the event title
615 Float_t xmin = gPad->GetX1();
616 Float_t xmax = gPad->GetX2();
617 Float_t ymin = gPad->GetY1();
618 Float_t ymax = gPad->GetY2();
619 Float_t dx = xmax-xmin;
620 Float_t dy = ymax-ymin;
622 if (strlen(option) == 0) {
623 TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
624 title->SetBit(kCanDelete);
625 title->SetFillColor(42);
628 sprintf(ptitle,"Alice event: %d, Run:%d",gAlice->GetHeader()->GetEvent(), gAlice->GetHeader()->GetRun());
629 title->AddText(ptitle);
630 Int_t nparticles = gAlice->Particles()->GetEntriesFast();
631 sprintf(ptitle,"Nparticles = %d Nhits = %d",nparticles, fHitsCuts);
632 title->AddText(ptitle);
634 TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
635 label->SetBit(kCanDelete);
636 label->SetFillColor(42);
641 //_____________________________________________________________________________
642 void AliDisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
644 // Draw a view of ALICE
646 gPad->SetCursor(kWatch);
647 gPad->SetFillColor(1);
651 TView *view = new TView(1);
652 Float_t range = fRrange*fRangeSlider->GetMaximum();
653 view->SetRange(-range,-range,-range,range, range, range);
660 // Display Alice Geometry
661 gAlice->GetGeometry()->Draw("same");
663 //Loop on all detectors to add their products to the pad
666 // add itself to the list (must be last)
669 view->SetView(phi, theta, psi, iret);
672 //_____________________________________________________________________________
673 void AliDisplay::DrawViewGL()
675 // Draw current view using OPENGL
677 TPad *pad = (TPad*)gPad->GetPadSave();
679 TView *view = pad->GetView();
684 //_____________________________________________________________________________
685 void AliDisplay::DrawViewX3D()
687 // Draw current view using X3D
689 TPad *pad = (TPad*)gPad->GetPadSave();
691 TView *view = pad->GetView();
696 //_____________________________________________________________________________
697 void AliDisplay::EnableDetector(const char *name)
699 // Enable detector name in graphics views
701 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
707 //______________________________________________________________________________
708 void AliDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
710 // Execute action corresponding to the mouse event
712 static Float_t x0, y0, x1, y1;
714 static Int_t pxold, pyold;
715 static Int_t px0, py0;
716 static Int_t linedrawn;
719 if (px == 0 && py == 0) { //when called by sliders
720 if (event == kButton1Up) {
725 if (!fZoomMode && gPad->GetView()) {
726 gPad->GetView()->ExecuteRotateView(event, px, py);
730 // something to zoom ?
731 // fPad->SetCursor(kCross);
732 gPad->SetCursor(kCross);
737 gVirtualX->SetLineColor(-1);
738 gPad->TAttLine::Modify(); //Change line attributes only if necessary
739 x0 = gPad->AbsPixeltoX(px);
740 y0 = gPad->AbsPixeltoY(py);
742 pxold = px; pyold = py;
747 if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
751 gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
755 gPad->GetCanvas()->FeedbackMode(kFALSE);
756 if (px == px0) return;
757 if (py == py0) return;
758 x1 = gPad->AbsPixeltoX(px);
759 y1 = gPad->AbsPixeltoY(py);
761 if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
762 if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
763 gPad->Range(x0,y0,x1,y1);
764 if (fZooms < kMAXZOOMS-1) {
766 fZoomX0[fZooms] = x0;
767 fZoomY0[fZooms] = y0;
768 fZoomX1[fZooms] = x1;
769 fZoomY1[fZooms] = y1;
771 gPad->Modified(kTRUE);
777 //___________________________________________
778 void AliDisplay::LoadPoints()
780 // Read hits info and store x,y,z info in arrays fPoints
781 // Loop on all detectors
783 gAlice->ResetPoints();
784 TIter next(gAlice->Modules());
786 Int_t ntracks = gAlice->GetNtrack();
787 for (Int_t track=0; track<ntracks;track++) {
789 gAlice->TreeH()->GetEvent(track);
790 while((module = (AliModule*)next())) {
791 module->LoadPoints(track);
797 //_____________________________________________________________________________
798 void AliDisplay::Paint(Option_t *)
800 // Paint miscellaneous items
804 //_____________________________________________________________________________
805 void AliDisplay::SetPickMode()
808 // Set Pick Mode -- disable zoom
812 fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
813 fTrigPad->Modified();
816 //_____________________________________________________________________________
817 void AliDisplay::SetZoomMode()
820 // Set Zoom Mode -- disable pick
824 fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
825 fTrigPad->Modified();
828 //_____________________________________________________________________________
829 void AliDisplay::SetPTcut(Float_t ptcut)
841 //_____________________________________________________________________________
842 void AliDisplay::SetRange(Float_t rrange, Float_t zrange)
844 // Set view range along R and Z
853 //_____________________________________________________________________________
854 void AliDisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
856 // change viewing angles for current event
859 fDrawAllViews = kFALSE;
865 TView *view = gPad->GetView();
866 if (view) view->SetView(fPhi, fTheta, fPsi, iret);
872 //_____________________________________________________________________________
873 void AliDisplay::ShowNextEvent(Int_t delta)
875 // Display (current event_number+delta)
876 // delta = 1 shown next event
877 // delta = -1 show previous event
881 Int_t currentEvent = gAlice->GetHeader()->GetEvent();
882 Int_t newEvent = currentEvent + delta;
883 gAlice->GetEvent(newEvent);
884 if (!gAlice->TreeH()) return;
891 //______________________________________________________________________________
892 void AliDisplay::UnZoom()
897 if (fZooms <= 0) return;
899 TPad *pad = (TPad*)gPad->GetPadSave();
900 pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);
904 //_____________________________________________________________________________
905 AliDisplay & AliDisplay::operator=(const AliDisplay &disp)
908 // Assignment operator