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.14 2001/01/26 19:58:48 hristov
19 Major upgrade of AliRoot code
21 Revision 1.13 2000/12/21 15:30:18 fca
22 Correcting coding convention violations
24 Revision 1.12 2000/12/12 13:18:59 hristov
25 Protection against FPE
27 Revision 1.11 2000/11/30 07:12:48 alibrary
28 Introducing new Rndm and QA classes
30 Revision 1.10 2000/10/02 21:28:14 fca
31 Removal of useless dependecies via forward declarations
33 Revision 1.9 2000/07/13 16:19:09 fca
34 Mainly coding conventions + some small bug fixes
36 Revision 1.8 2000/07/11 18:24:59 fca
37 Coding convention corrections + few minor bug fixes
39 Revision 1.7 1999/11/10 07:37:06 fca
40 Pads do not inherit editability from canvas any more
42 Revision 1.6 1999/11/09 07:38:52 fca
43 Changes for compatibility with version 2.23 of ROOT
45 Revision 1.5 1999/09/29 09:24:29 fca
46 Introduction of the Copyright and cvs Log
51 //////////////////////////////////////////////////////////////////////////
55 // Utility class to display ALICE outline, tracks, hits,.. //
57 //////////////////////////////////////////////////////////////////////////
63 #include <TPaveLabel.h>
64 #include <TPaveText.h>
68 #include <TSliderBox.h>
70 #include <TVirtualX.h>
74 #include "AliDetector.h"
75 #include "AliDisplay.h"
76 #include "AliPoints.h"
77 #include "TParticle.h"
78 #include "TGeometry.h"
79 #include "AliHeader.h"
81 static const Float_t kptcutmax = 2;
82 static const Float_t ketacutmax = 1.5;
87 //_____________________________________________________________________________
88 AliDisplay::AliDisplay()
91 // Default constructor
96 //_____________________________________________________________________________
97 AliDisplay::AliDisplay(Int_t size)
99 // Create an event display object.
100 // A canvas named "edisplay" is created with a vertical size in pixels
102 // A QUICK Overview of the Event Display functions
103 // ===============================================
105 // The event display can ve invoked by executing the macro "display.C"
106 // A canvas like in the picture below will appear.
108 // On the left side of the canvas, the following buttons appear:
109 // *Next* to move to the next event
110 // *Previous* to move to the previous event
111 // *Top View* to display a top view of the current event
112 // *Side View* to display a side view of the current event
113 // *Front View* to display a front view of the current event
114 // *All Views* to display front/side/top/30-30 views of the current event
115 // *OpenGL* to use OpenGl to view the current event.
116 // Note that OpenGL cannot be used across the network.
117 // Before using OpenGL, load the GL libraries
118 // by executing the macro GL.C (in $ROOTSYS/macros/GL.C.
119 // Once in GL, click the HELP button of the GL canvas.
120 // *X3D* to use X3D to view the current event (Unix only).
121 // Once in X3D, type M to see the list of all possible options.
122 // for example type J to zoom, K to unzoom
123 // use the mouse to rotate.
124 // *Pick* Select this option to be able to point on a track with the
125 // mouse. Once on the track, use the right button to select
126 // an action. For example, select SetMarkerAttributes to
127 // change the marker type/color/size for the track.
128 // *Zoom* Select this option (default) if you want to zoom.
129 // To zoom, simply select the selected area with the left button.
130 // *UnZoom* To revert to the previous picture size.
132 // slider R On the left side, the vertical slider can be used to
133 // set the default picture size.
134 // slider pcut At the top of the canvas, a slider can be used to change
135 // the momentum cut (or range) to display tracks.
136 // slider eta On the right side of the canvas, a vertical slider can be used
137 // to specify a rapidity range for the tracks.
139 // When you are in Zoom mode, you can click on the black part of the canvas
140 // to select special options with the right mouse button.
141 // This will display a pop-up menu with items like:
142 // *Disable detector*
143 // *Enable detector*, etc.
144 // For example select "Disable detector". You get a dialog box.
145 // Diable detector TRD for example.
147 // When you are in pick mode, you can "Inspect" the object pointed by the mouse.
148 // When you are on a track, select the menu item "InspectParticle"
149 // to display the current particle attributes.
151 // You can activate the Root browser by selecting the Inspect menu
152 // in the canvas tool bar menu. Then select "Start Browser"
153 // This will open a new canvas with the browser. At this point, you may want
154 // to display some histograms (from the Trees). Go to the "File" menu
155 // of the browser and click on "New canvas".
156 // In the browser, click on item "ROOT files" in the left pane.
157 // Click on galice.root.
159 // Click on TPC for example
160 // Click on any variable (eg TPC.fX) to histogram the variable.
162 // If you are lost, you can click on HELP in any Root canvas or browser.
165 <img src="picts/alidisplay.gif">
170 gAlice->SetDisplay(this);
172 // Initialize display default parameters
176 // Set front view by default
180 fDrawAllViews = kFALSE;
182 fDrawParticles = kTRUE;
187 // Create display canvas
189 if (ysize < 100) ysize = 750;
190 Int_t xsize = Int_t(size*830./ysize);
191 fCanvas = new TCanvas("Canvas", "ALICE Event Display",14,47,xsize,ysize);
192 fCanvas->ToggleEventStatus();
194 // Create main display pad
195 fPad = new TPad("viewpad", "Alice display",0.15,0,0.97,0.96);
198 fPad->SetFillColor(1);
199 fPad->SetBorderSize(2);
201 // Create user interface control pad
205 // Create Range and mode pad
208 fTrigPad = new TPad("trigger", "range and mode pad",0,0,dxtr,dytr);
209 fTrigPad->SetEditable(kFALSE);
212 fTrigPad->SetFillColor(22);
213 fTrigPad->SetBorderSize(2);
214 fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
215 fRangeSlider->SetObject(this);
216 char pickmode[] = "gAlice->Display()->SetPickMode()";
218 fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
219 fPickButton->SetFillColor(38);
221 char zoommode[] = "gAlice->Display()->SetZoomMode()";
222 fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
223 fZoomButton->SetFillColor(38);
225 fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
226 fArcButton->SetFillColor(kGreen);
228 char butUnzoom[] = "gAlice->Display()->UnZoom()";
229 TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
230 button->SetFillColor(38);
232 AppendPad(); // append display object as last object to force selection
234 // Create momentum cut slider pad
236 fCutPad = new TPad("cutSlider", "pcut slider pad",dxtr,.96,1,1);
239 fCutPad->SetFillColor(22);
240 fCutPad->SetBorderSize(2);
241 fCutSlider = new TSlider("pcut","Momentum cut",0,0,1,1);
242 fCutSlider->SetRange(fPTcut/kptcutmax,1);
243 fCutSlider->SetObject(this);
244 fCutSlider->SetFillColor(45);
245 TSliderBox *sbox = (TSliderBox*)fCutSlider->GetListOfPrimitives()->First();
246 sbox->SetFillColor(46);
248 TGaxis *cutaxis = new TGaxis(0.02,0.8,0.98,0.8,0,kptcutmax,510,"");
249 cutaxis->SetLabelSize(0.5);
250 cutaxis->SetTitleSize(0.6);
251 cutaxis->SetTitleOffset(0.5);
252 cutaxis->SetTitle("pcut . ");
253 fCutSlider->GetListOfPrimitives()->AddFirst(cutaxis);
255 // Create rapidity cut slider pad
257 fEtaPad = new TPad("EtaSlider", "Eta slider pad",0.97,0,1,0.96);
260 fEtaPad->SetFillColor(22);
261 fEtaPad->SetBorderSize(2);
262 fEtaSlider = new TSlider("etacut","Rapidity cut",0,0,1,1);
263 fEtaSlider->SetObject(this);
264 fEtaSlider->SetFillColor(45);
265 TSliderBox *sbox2 = (TSliderBox*)fEtaSlider->GetListOfPrimitives()->First();
266 sbox2->SetFillColor(46);
268 TGaxis *etaaxis = new TGaxis(0.9,0.02,0.9,0.98,-ketacutmax,ketacutmax,510,"");
269 etaaxis->SetLabelSize(0.5);
270 etaaxis->SetTitleSize(0.6);
271 etaaxis->SetTitleOffset(0.2);
272 cutaxis->SetTitle("Etacut . ");
273 fEtaSlider->GetListOfPrimitives()->AddFirst(etaaxis);
282 //_____________________________________________________________________________
283 AliDisplay::AliDisplay(const AliDisplay &disp)
291 //_____________________________________________________________________________
292 AliDisplay::~AliDisplay()
299 //_____________________________________________________________________________
300 void AliDisplay::Clear(Option_t *)
302 // Delete graphics temporary objects
305 //_____________________________________________________________________________
306 void AliDisplay::Copy(AliDisplay &disp) const
309 // Copy *this onto disp -- not implemented
311 Fatal("Copy","Not implemented~\n");
314 //----------------------------------------------------------------------------
315 void AliDisplay::ShowTrack(Int_t idx)
320 AliDetector *mTPC=(AliDetector*)gAlice->GetModule("TPC");
321 TObjArray *points=mTPC->Points();
322 int ntracks=points->GetEntriesFast();
323 for (int track=0;track<ntracks;track++) {
324 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
326 if (idx == pm->GetIndex()) {
327 pm->SetMarkerColor(2);
328 pm->SetMarkerStyle(22);
332 // TClonesArray *particles=gAlice->Particles();
333 // TParticle *p = (TParticle*)particles->UncheckedAt(idx);
334 TParticle *p = gAlice->Particle(idx);
335 printf("\nTrack index %d\n",idx);
336 printf("Particle ID %d\n",p->GetPdgCode());
337 printf("Parent %d\n",p->GetFirstMother());
338 printf("First child %d\n",p->GetFirstDaughter());
339 printf("Px,Py,Pz %f %f %f\n",p->Px(),p->Py(),p->Pz());
345 //----------------------------------------------------------------------------
346 void AliDisplay::HideTrack(Int_t idx) {
348 // Hide track on display
350 AliDetector *mTPC=(AliDetector*)gAlice->GetModule("TPC");
351 TObjArray *points=mTPC->Points();
352 int ntracks=points->GetEntriesFast();
353 for (int track=0;track<ntracks;track++) {
354 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
356 if (idx == pm->GetIndex()) {
357 pm->SetMarkerColor(5);
358 pm->SetMarkerStyle(1);
367 //_____________________________________________________________________________
368 void AliDisplay::DisableDetector(const char *name)
370 // Disable detector name from graphics views
372 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
378 //_____________________________________________________________________________
379 void AliDisplay::DisplayButtons()
381 // Create the user interface buttons
383 fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
384 fButtons->SetEditable(kFALSE);
386 fButtons->SetFillColor(38);
387 fButtons->SetBorderSize(2);
391 Float_t dbutton = 0.08;
398 char but1[] = "gAlice->Display()->ShowNextEvent(1)";
399 button = new TButton("Next",but1,x0,y-dbutton,x1,y);
400 button->SetFillColor(38);
404 char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
405 button = new TButton("Previous",but2,x0,y-dbutton,x1,y);
406 button->SetFillColor(38);
410 char but3[] = "gAlice->Display()->SetView(90,-90,90)";
411 button = new TButton("Top View",but3,x0,y-dbutton,x1,y);
412 button->SetFillColor(butcolor);
416 char but4[] = "gAlice->Display()->SetView(90,0,-90)";
417 button = new TButton("Side View",but4,x0,y-dbutton,x1,y);
418 button->SetFillColor(butcolor);
422 char but5[] = "gAlice->Display()->SetView(0,-90,0)";
423 button = new TButton("Front View",but5,x0,y-dbutton,x1,y);
424 button->SetFillColor(butcolor);
428 char but6[] = "gAlice->Display()->DrawAllViews()";
429 button = new TButton("All Views",but6,x0,y-dbutton,x1,y);
430 button->SetFillColor(butcolor);
434 char but7[] = "gAlice->Display()->DrawViewGL()";
435 button = new TButton("OpenGL",but7,x0,y-dbutton,x1,y);
436 button->SetFillColor(38);
440 char but8[] = "gAlice->Display()->DrawViewX3D()";
441 button = new TButton("X3D",but8,x0,y-dbutton,x1,y);
442 button->SetFillColor(38);
446 TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
447 diamond->SetFillColor(50);
448 diamond->SetTextAlign(22);
449 diamond->SetTextColor(5);
450 diamond->SetTextSize(0.11);
452 diamond->AddText(".. ");
453 diamond->AddText("ROOT");
454 diamond->AddText("ALICE");
455 diamond->AddText("... ");
456 diamond->AddText(" ");
459 //______________________________________________________________________________
460 Int_t AliDisplay::DistancetoPrimitive(Int_t px, Int_t)
462 // Compute distance from point px,py to objects in event
464 gPad->SetCursor(kCross);
466 if (gPad == fTrigPad) return 9999;
467 if (gPad == fCutPad) return 9999;
468 if (gPad == fEtaPad) return 9999;
470 const Int_t kbig = 9999;
472 Float_t xmin = gPad->GetX1();
473 Float_t xmax = gPad->GetX2();
474 Float_t dx = 0.02*(xmax - xmin);
475 Float_t x = gPad->AbsPixeltoX(px);
476 if (x < xmin+dx || x > xmax-dx) return dist;
478 if (fZoomMode) return 0;
482 //_____________________________________________________________________________
483 void AliDisplay::Draw(Option_t *)
485 // Display current event
494 DrawView(fTheta, fPhi, fPsi);
496 // Display the event number and title
501 //_____________________________________________________________________________
502 void AliDisplay::DrawAllViews()
504 // Draw front,top,side and 30 deg views
506 fDrawAllViews = kTRUE;
508 fPad->SetFillColor(15);
524 DrawView(90, -90, 90);
529 DrawView(90, 0, -90);
535 //_____________________________________________________________________________
536 void AliDisplay::DrawHits()
538 // Draw hits for all ALICE detectors
540 Float_t cutmin, cutmax, etamin, etamax, pmom, smin, smax, eta, theta, r;
548 smax = fCutSlider->GetMaximum();
549 smin = fCutSlider->GetMinimum();
550 cutmin = kptcutmax*smin;
551 if (smax < 0.98) cutmax = kptcutmax*smax;
552 else cutmax = 100000;
555 smax = fEtaSlider->GetMaximum();
556 smin = fEtaSlider->GetMinimum();
557 etamin = ketacutmax*(2*smin-1);
558 etamax = ketacutmax*(2*smax-1);
559 if (smin < 0.02) etamin = -1000;
560 if (smax > 0.98) etamax = 1000;
562 TIter next(gAlice->Modules());
565 while((module = (AliModule*)next())) {
566 if (!module->IsActive()) continue;
567 points = module->Points();
568 if (!points) continue;
569 ntracks = points->GetEntriesFast();
570 for (track=0;track<ntracks;track++) {
571 pm = (AliPoints*)points->UncheckedAt(track);
573 particle = pm->GetParticle();
574 if (!particle) continue;
575 pmom = particle->P();
576 if (pmom < cutmin) continue;
577 if (pmom > cutmax) continue;
578 // as a first approximation, take eta of first point
580 r = TMath::Sqrt(pxyz[0]*pxyz[0] + pxyz[1]*pxyz[1]);
581 theta = TMath::ATan2(r,TMath::Abs(pxyz[2]));
582 if(theta) eta = -TMath::Log(TMath::Abs(TMath::Tan(0.5*theta))); else eta = 1e10;
583 if (pxyz[2] < 0) eta = -eta;
584 if (eta < etamin || eta > etamax) continue;
586 fHitsCuts += pm->GetN();
591 //_____________________________________________________________________________
592 void AliDisplay::DrawTitle(Option_t *option)
594 // Draw the event title
596 Float_t xmin = gPad->GetX1();
597 Float_t xmax = gPad->GetX2();
598 Float_t ymin = gPad->GetY1();
599 Float_t ymax = gPad->GetY2();
600 Float_t dx = xmax-xmin;
601 Float_t dy = ymax-ymin;
603 if (strlen(option) == 0) {
604 TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
605 title->SetBit(kCanDelete);
606 title->SetFillColor(42);
609 sprintf(ptitle,"Alice event: %d, Run:%d",gAlice->GetHeader()->GetEvent(), gAlice->GetHeader()->GetRun());
610 title->AddText(ptitle);
611 Int_t nparticles = gAlice->Particles()->GetEntriesFast();
612 sprintf(ptitle,"Nparticles = %d Nhits = %d",nparticles, fHitsCuts);
613 title->AddText(ptitle);
615 TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
616 label->SetBit(kCanDelete);
617 label->SetFillColor(42);
622 //_____________________________________________________________________________
623 void AliDisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
625 // Draw a view of ALICE
627 gPad->SetCursor(kWatch);
628 gPad->SetFillColor(1);
632 TView *view = new TView(1);
633 Float_t range = fRrange*fRangeSlider->GetMaximum();
634 view->SetRange(-range,-range,-range,range, range, range);
641 // Display Alice Geometry
642 gAlice->GetGeometry()->Draw("same");
644 //Loop on all detectors to add their products to the pad
647 // add itself to the list (must be last)
650 view->SetView(phi, theta, psi, iret);
653 //_____________________________________________________________________________
654 void AliDisplay::DrawViewGL()
656 // Draw current view using OPENGL
658 TPad *pad = (TPad*)gPad->GetPadSave();
660 TView *view = pad->GetView();
665 //_____________________________________________________________________________
666 void AliDisplay::DrawViewX3D()
668 // Draw current view using X3D
670 TPad *pad = (TPad*)gPad->GetPadSave();
672 TView *view = pad->GetView();
677 //_____________________________________________________________________________
678 void AliDisplay::EnableDetector(const char *name)
680 // Enable detector name in graphics views
682 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
688 //______________________________________________________________________________
689 void AliDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
691 // Execute action corresponding to the mouse event
693 static Float_t x0, y0, x1, y1;
695 static Int_t pxold, pyold;
696 static Int_t px0, py0;
697 static Int_t linedrawn;
700 if (px == 0 && py == 0) { //when called by sliders
701 if (event == kButton1Up) {
706 if (!fZoomMode && gPad->GetView()) {
707 gPad->GetView()->ExecuteRotateView(event, px, py);
711 // something to zoom ?
712 // fPad->SetCursor(kCross);
713 gPad->SetCursor(kCross);
718 gVirtualX->SetLineColor(-1);
719 gPad->TAttLine::Modify(); //Change line attributes only if necessary
720 x0 = gPad->AbsPixeltoX(px);
721 y0 = gPad->AbsPixeltoY(py);
723 pxold = px; pyold = py;
728 if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
732 gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
736 gPad->GetCanvas()->FeedbackMode(kFALSE);
737 if (px == px0) return;
738 if (py == py0) return;
739 x1 = gPad->AbsPixeltoX(px);
740 y1 = gPad->AbsPixeltoY(py);
742 if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
743 if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
744 gPad->Range(x0,y0,x1,y1);
745 if (fZooms < kMAXZOOMS-1) {
747 fZoomX0[fZooms] = x0;
748 fZoomY0[fZooms] = y0;
749 fZoomX1[fZooms] = x1;
750 fZoomY1[fZooms] = y1;
752 gPad->Modified(kTRUE);
758 //___________________________________________
759 void AliDisplay::LoadPoints()
761 // Read hits info and store x,y,z info in arrays fPoints
762 // Loop on all detectors
764 gAlice->ResetPoints();
765 TIter next(gAlice->Modules());
767 Int_t ntracks = gAlice->GetNtrack();
768 for (Int_t track=0; track<ntracks;track++) {
770 gAlice->TreeH()->GetEvent(track);
771 while((module = (AliModule*)next())) {
772 module->LoadPoints(track);
778 //_____________________________________________________________________________
779 void AliDisplay::Paint(Option_t *)
781 // Paint miscellaneous items
785 //_____________________________________________________________________________
786 void AliDisplay::SetPickMode()
789 // Set Pick Mode -- disable zoom
793 fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
794 fTrigPad->Modified();
797 //_____________________________________________________________________________
798 void AliDisplay::SetZoomMode()
801 // Set Zoom Mode -- disable pick
805 fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
806 fTrigPad->Modified();
809 //_____________________________________________________________________________
810 void AliDisplay::SetPTcut(Float_t ptcut)
822 //_____________________________________________________________________________
823 void AliDisplay::SetRange(Float_t rrange, Float_t zrange)
825 // Set view range along R and Z
834 //_____________________________________________________________________________
835 void AliDisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
837 // change viewing angles for current event
840 fDrawAllViews = kFALSE;
846 TView *view = gPad->GetView();
847 if (view) view->SetView(fPhi, fTheta, fPsi, iret);
853 //_____________________________________________________________________________
854 void AliDisplay::ShowNextEvent(Int_t delta)
856 // Display (current event_number+delta)
857 // delta = 1 shown next event
858 // delta = -1 show previous event
862 Int_t currentEvent = gAlice->GetHeader()->GetEvent();
863 Int_t newEvent = currentEvent + delta;
864 gAlice->GetEvent(newEvent);
865 if (!gAlice->TreeH()) return;
872 //______________________________________________________________________________
873 void AliDisplay::UnZoom()
878 if (fZooms <= 0) return;
880 TPad *pad = (TPad*)gPad->GetPadSave();
881 pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);
885 //_____________________________________________________________________________
886 AliDisplay & AliDisplay::operator=(const AliDisplay &disp)
889 // Assignment operator