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 **************************************************************************/
21 //////////////////////////////////////////////////////////////////////////
25 // Utility class to display ALICE outline, tracks, hits,.. //
27 //////////////////////////////////////////////////////////////////////////
35 #include <TPolyMarker3D.h>
36 #include <TPaveLabel.h>
37 #include <TPaveText.h>
44 #include <TSliderBox.h>
48 #include <X3DBuffer.h>
51 #include "AliDetector.h"
52 #include "AliDisplay.h"
53 #include "AliPoints.h"
54 #include "TParticle.h"
56 const Float_t ptcutmax = 2;
57 const Float_t etacutmax = 1.5;
62 //_____________________________________________________________________________
63 AliDisplay::AliDisplay()
68 //_____________________________________________________________________________
69 AliDisplay::AliDisplay(Int_t size)
71 // Create an event display object.
72 // A canvas named "edisplay" is created with a vertical size in pixels
74 // A QUICK Overview of the Event Display functions
75 // ===============================================
77 // The event display can ve invoked by executing the macro "display.C"
78 // A canvas like in the picture below will appear.
80 // On the left side of the canvas, the following buttons appear:
81 // *Next* to move to the next event
82 // *Previous* to move to the previous event
83 // *Top View* to display a top view of the current event
84 // *Side View* to display a side view of the current event
85 // *Front View* to display a front view of the current event
86 // *All Views* to display front/side/top/30-30 views of the current event
87 // *OpenGL* to use OpenGl to view the current event.
88 // Note that OpenGL cannot be used across the network.
89 // Before using OpenGL, load the GL libraries
90 // by executing the macro GL.C (in $ROOTSYS/macros/GL.C.
91 // Once in GL, click the HELP button of the GL canvas.
92 // *X3D* to use X3D to view the current event (Unix only).
93 // Once in X3D, type M to see the list of all possible options.
94 // for example type J to zoom, K to unzoom
95 // use the mouse to rotate.
96 // *Pick* Select this option to be able to point on a track with the
97 // mouse. Once on the track, use the right button to select
98 // an action. For example, select SetMarkerAttributes to
99 // change the marker type/color/size for the track.
100 // *Zoom* Select this option (default) if you want to zoom.
101 // To zoom, simply select the selected area with the left button.
102 // *UnZoom* To revert to the previous picture size.
104 // slider R On the left side, the vertical slider can be used to
105 // set the default picture size.
106 // slider pcut At the top of the canvas, a slider can be used to change
107 // the momentum cut (or range) to display tracks.
108 // slider eta On the right side of the canvas, a vertical slider can be used
109 // to specify a rapidity range for the tracks.
111 // When you are in Zoom mode, you can click on the black part of the canvas
112 // to select special options with the right mouse button.
113 // This will display a pop-up menu with items like:
114 // *Disable detector*
115 // *Enable detector*, etc.
116 // For example select "Disable detector". You get a dialog box.
117 // Diable detector TRD for example.
119 // When you are in pick mode, you can "Inspect" the object pointed by the mouse.
120 // When you are on a track, select the menu item "InspectParticle"
121 // to display the current particle attributes.
123 // You can activate the Root browser by selecting the Inspect menu
124 // in the canvas tool bar menu. Then select "Start Browser"
125 // This will open a new canvas with the browser. At this point, you may want
126 // to display some histograms (from the Trees). Go to the "File" menu
127 // of the browser and click on "New canvas".
128 // In the browser, click on item "ROOT files" in the left pane.
129 // Click on galice.root.
131 // Click on TPC for example
132 // Click on any variable (eg TPC.fX) to histogram the variable.
134 // If you are lost, you can click on HELP in any Root canvas or browser.
137 <img src="picts/alidisplay.gif">
142 gAlice->SetDisplay(this);
144 // Initialize display default parameters
148 // Set front view by default
152 fDrawAllViews = kFALSE;
154 fDrawParticles = kTRUE;
159 // Create display canvas
161 if (ysize < 100) ysize = 750;
162 Int_t xsize = Int_t(size*830./ysize);
163 fCanvas = new TCanvas("Canvas", "ALICE Event Display",14,47,xsize,ysize);
164 fCanvas->SetEditable(kIsNotEditable);
165 fCanvas->ToggleEventStatus();
167 // Create main display pad
168 fPad = new TPad("viewpad", "Alice display",0.15,0,0.97,0.96);
171 fPad->SetFillColor(1);
172 fPad->SetBorderSize(2);
174 // Create user interface control pad
178 // Create Range and mode pad
181 fTrigPad = new TPad("trigger", "range and mode pad",0,0,dxtr,dytr);
184 fTrigPad->SetFillColor(22);
185 fTrigPad->SetBorderSize(2);
186 fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
187 fRangeSlider->SetObject(this);
188 char pickmode[] = "gAlice->Display()->SetPickMode()";
190 fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
191 fPickButton->SetFillColor(38);
193 char zoommode[] = "gAlice->Display()->SetZoomMode()";
194 fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
195 fZoomButton->SetFillColor(38);
197 fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
198 fArcButton->SetFillColor(kGreen);
200 char butUnzoom[] = "gAlice->Display()->UnZoom()";
201 TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
202 button->SetFillColor(38);
204 AppendPad(); // append display object as last object to force selection
206 // Create momentum cut slider pad
208 fCutPad = new TPad("cutSlider", "pcut slider pad",dxtr,.96,1,1);
211 fCutPad->SetFillColor(22);
212 fCutPad->SetBorderSize(2);
213 fCutSlider = new TSlider("pcut","Momentum cut",0,0,1,1);
214 fCutSlider->SetRange(fPTcut/ptcutmax,1);
215 fCutSlider->SetObject(this);
216 fCutSlider->SetFillColor(45);
217 TSliderBox *sbox = (TSliderBox*)fCutSlider->GetListOfPrimitives()->First();
218 sbox->SetFillColor(46);
220 TGaxis *cutaxis = new TGaxis(0.02,0.8,0.98,0.8,0,ptcutmax,510,"");
221 cutaxis->SetLabelSize(0.5);
222 cutaxis->SetTitleSize(0.6);
223 cutaxis->SetTitleOffset(0.5);
224 cutaxis->SetTitle("pcut . ");
225 fCutSlider->GetListOfPrimitives()->AddFirst(cutaxis);
227 // Create rapidity cut slider pad
229 fEtaPad = new TPad("EtaSlider", "Eta slider pad",0.97,0,1,0.96);
232 fEtaPad->SetFillColor(22);
233 fEtaPad->SetBorderSize(2);
234 fEtaSlider = new TSlider("etacut","Rapidity cut",0,0,1,1);
235 fEtaSlider->SetObject(this);
236 fEtaSlider->SetFillColor(45);
237 TSliderBox *sbox2 = (TSliderBox*)fEtaSlider->GetListOfPrimitives()->First();
238 sbox2->SetFillColor(46);
240 TGaxis *etaaxis = new TGaxis(0.9,0.02,0.9,0.98,-etacutmax,etacutmax,510,"");
241 etaaxis->SetLabelSize(0.5);
242 etaaxis->SetTitleSize(0.6);
243 etaaxis->SetTitleOffset(0.2);
244 cutaxis->SetTitle("Etacut . ");
245 fEtaSlider->GetListOfPrimitives()->AddFirst(etaaxis);
254 //_____________________________________________________________________________
255 AliDisplay::~AliDisplay()
259 //_____________________________________________________________________________
260 void AliDisplay::Clear(Option_t *)
262 // Delete graphics temporary objects
265 //----------------------------------------------------------------------------
266 void AliDisplay::ShowTrack(Int_t idx) {
267 AliDetector *TPC=(AliDetector*)gAlice->GetModule("TPC");
268 TObjArray *points=TPC->Points();
269 int ntracks=points->GetEntriesFast();
270 for (int track=0;track<ntracks;track++) {
271 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
273 if (idx == pm->GetIndex()) {
274 pm->SetMarkerColor(2);
275 pm->SetMarkerStyle(22);
279 TClonesArray *particles=gAlice->Particles();
280 TParticle *p = (TParticle*)particles->UncheckedAt(idx);
281 printf("\nTrack index %d\n",idx);
282 printf("Particle ID %d\n",p->GetPdgCode());
283 printf("Parent %d\n",p->GetFirstMother());
284 printf("First child %d\n",p->GetFirstDaughter());
285 printf("Px,Py,Pz %f %f %f\n",p->Px(),p->Py(),p->Pz());
291 //----------------------------------------------------------------------------
292 void AliDisplay::HideTrack(Int_t idx) {
293 AliDetector *TPC=(AliDetector*)gAlice->GetModule("TPC");
294 TObjArray *points=TPC->Points();
295 int ntracks=points->GetEntriesFast();
296 for (int track=0;track<ntracks;track++) {
297 AliPoints *pm = (AliPoints*)points->UncheckedAt(track);
299 if (idx == pm->GetIndex()) {
300 pm->SetMarkerColor(5);
301 pm->SetMarkerStyle(1);
310 //_____________________________________________________________________________
311 void AliDisplay::DisableDetector(const char *name)
313 // Disable detector name from graphics views
315 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
321 //_____________________________________________________________________________
322 void AliDisplay::DisplayButtons()
324 // Create the user interface buttons
326 fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
328 fButtons->SetFillColor(38);
329 fButtons->SetBorderSize(2);
333 Float_t dbutton = 0.08;
340 char but1[] = "gAlice->Display()->ShowNextEvent(1)";
341 button = new TButton("Next",but1,x0,y-dbutton,x1,y);
342 button->SetFillColor(38);
346 char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
347 button = new TButton("Previous",but2,x0,y-dbutton,x1,y);
348 button->SetFillColor(38);
352 char but3[] = "gAlice->Display()->SetView(90,-90,90)";
353 button = new TButton("Top View",but3,x0,y-dbutton,x1,y);
354 button->SetFillColor(butcolor);
358 char but4[] = "gAlice->Display()->SetView(90,0,-90)";
359 button = new TButton("Side View",but4,x0,y-dbutton,x1,y);
360 button->SetFillColor(butcolor);
364 char but5[] = "gAlice->Display()->SetView(0,-90,0)";
365 button = new TButton("Front View",but5,x0,y-dbutton,x1,y);
366 button->SetFillColor(butcolor);
370 char but6[] = "gAlice->Display()->DrawAllViews()";
371 button = new TButton("All Views",but6,x0,y-dbutton,x1,y);
372 button->SetFillColor(butcolor);
376 char but7[] = "gAlice->Display()->DrawViewGL()";
377 button = new TButton("OpenGL",but7,x0,y-dbutton,x1,y);
378 button->SetFillColor(38);
382 char but8[] = "gAlice->Display()->DrawViewX3D()";
383 button = new TButton("X3D",but8,x0,y-dbutton,x1,y);
384 button->SetFillColor(38);
388 TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
389 diamond->SetFillColor(50);
390 diamond->SetTextAlign(22);
391 diamond->SetTextColor(5);
392 diamond->SetTextSize(0.11);
394 diamond->AddText(".. ");
395 diamond->AddText("ROOT");
396 diamond->AddText("ALICE");
397 diamond->AddText("... ");
398 diamond->AddText(" ");
401 //______________________________________________________________________________
402 Int_t AliDisplay::DistancetoPrimitive(Int_t px, Int_t)
404 // Compute distance from point px,py to objects in event
406 gPad->SetCursor(kCross);
408 if (gPad == fTrigPad) return 9999;
409 if (gPad == fCutPad) return 9999;
410 if (gPad == fEtaPad) return 9999;
412 const Int_t big = 9999;
414 Float_t xmin = gPad->GetX1();
415 Float_t xmax = gPad->GetX2();
416 Float_t dx = 0.02*(xmax - xmin);
417 Float_t x = gPad->AbsPixeltoX(px);
418 if (x < xmin+dx || x > xmax-dx) return dist;
420 if (fZoomMode) return 0;
424 //_____________________________________________________________________________
425 void AliDisplay::Draw(Option_t *)
427 // Display current event
436 DrawView(fTheta, fPhi, fPsi);
438 // Display the event number and title
443 //_____________________________________________________________________________
444 void AliDisplay::DrawAllViews()
446 // Draw front,top,side and 30 deg views
448 fDrawAllViews = kTRUE;
450 fPad->SetFillColor(15);
466 DrawView(90, -90, 90);
471 DrawView(90, 0, -90);
477 //_____________________________________________________________________________
478 void AliDisplay::DrawHits()
480 // Draw hits for all ALICE detectors
482 Float_t cutmin, cutmax, etamin, etamax, pmom, smin, smax, eta, theta, r;
490 smax = fCutSlider->GetMaximum();
491 smin = fCutSlider->GetMinimum();
492 cutmin = ptcutmax*smin;
493 if (smax < 0.98) cutmax = ptcutmax*smax;
494 else cutmax = 100000;
497 smax = fEtaSlider->GetMaximum();
498 smin = fEtaSlider->GetMinimum();
499 etamin = etacutmax*(2*smin-1);
500 etamax = etacutmax*(2*smax-1);
501 if (smin < 0.02) etamin = -1000;
502 if (smax > 0.98) etamax = 1000;
504 TIter next(gAlice->Modules());
507 while((module = (AliModule*)next())) {
508 if (!module->IsActive()) continue;
509 points = module->Points();
510 if (!points) continue;
511 ntracks = points->GetEntriesFast();
512 for (track=0;track<ntracks;track++) {
513 pm = (AliPoints*)points->UncheckedAt(track);
515 particle = pm->GetParticle();
516 if (!particle) continue;
517 pmom = particle->P();
518 if (pmom < cutmin) continue;
519 if (pmom > cutmax) continue;
520 // as a first approximation, take eta of first point
522 r = TMath::Sqrt(pxyz[0]*pxyz[0] + pxyz[1]*pxyz[1]);
523 theta = TMath::ATan2(r,TMath::Abs(pxyz[2]));
524 if(theta) eta = -TMath::Log(TMath::Tan(0.5*theta)); else eta = 1e10;
525 if (pxyz[2] < 0) eta = -eta;
526 if (eta < etamin || eta > etamax) continue;
528 fHitsCuts += pm->GetN();
533 //_____________________________________________________________________________
534 void AliDisplay::DrawTitle(Option_t *option)
536 // Draw the event title
538 Float_t xmin = gPad->GetX1();
539 Float_t xmax = gPad->GetX2();
540 Float_t ymin = gPad->GetY1();
541 Float_t ymax = gPad->GetY2();
542 Float_t dx = xmax-xmin;
543 Float_t dy = ymax-ymin;
545 if (strlen(option) == 0) {
546 TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
547 title->SetBit(kCanDelete);
548 title->SetFillColor(42);
551 sprintf(ptitle,"Alice event: %d, Run:%d",gAlice->GetHeader()->GetEvent(), gAlice->GetHeader()->GetRun());
552 title->AddText(ptitle);
553 Int_t nparticles = gAlice->Particles()->GetEntriesFast();
554 sprintf(ptitle,"Nparticles = %d Nhits = %d",nparticles, fHitsCuts);
555 title->AddText(ptitle);
557 TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
558 label->SetBit(kCanDelete);
559 label->SetFillColor(42);
564 //_____________________________________________________________________________
565 void AliDisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
567 // Draw a view of ALICE
569 gPad->SetCursor(kWatch);
570 gPad->SetFillColor(1);
574 TView *view = new TView(1);
575 Float_t range = fRrange*fRangeSlider->GetMaximum();
576 view->SetRange(-range,-range,-range,range, range, range);
583 // Display Alice Geometry
584 gAlice->GetGeometry()->Draw("same");
586 //Loop on all detectors to add their products to the pad
589 // add itself to the list (must be last)
592 view->SetView(phi, theta, psi, iret);
595 //_____________________________________________________________________________
596 void AliDisplay::DrawViewGL()
598 // Draw current view using OPENGL
600 TPad *pad = (TPad*)gPad->GetPadSave();
602 TView *view = pad->GetView();
607 //_____________________________________________________________________________
608 void AliDisplay::DrawViewX3D()
610 // Draw current view using X3D
612 TPad *pad = (TPad*)gPad->GetPadSave();
614 TView *view = pad->GetView();
619 //_____________________________________________________________________________
620 void AliDisplay::EnableDetector(const char *name)
622 // Enable detector name in graphics views
624 AliModule *module = (AliModule*)gAlice->Modules()->FindObject(name);
630 //______________________________________________________________________________
631 void AliDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
633 // Execute action corresponding to the mouse event
635 static Float_t x0, y0, x1, y1;
637 static Int_t pxold, pyold;
638 static Int_t px0, py0;
639 static Int_t linedrawn;
642 if (px == 0 && py == 0) { //when called by sliders
643 if (event == kButton1Up) {
648 if (!fZoomMode && gPad->GetView()) {
649 gPad->GetView()->ExecuteRotateView(event, px, py);
653 // something to zoom ?
654 // fPad->SetCursor(kCross);
655 gPad->SetCursor(kCross);
660 gGXW->SetLineColor(-1);
661 gPad->TAttLine::Modify(); //Change line attributes only if necessary
662 x0 = gPad->AbsPixeltoX(px);
663 y0 = gPad->AbsPixeltoY(py);
665 pxold = px; pyold = py;
670 if (linedrawn) gGXW->DrawBox(px0, py0, pxold, pyold, TGXW::kHollow);
674 gGXW->DrawBox(px0, py0, pxold, pyold, TGXW::kHollow);
678 gPad->GetCanvas()->FeedbackMode(kFALSE);
679 if (px == px0) return;
680 if (py == py0) return;
681 x1 = gPad->AbsPixeltoX(px);
682 y1 = gPad->AbsPixeltoY(py);
684 if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
685 if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
686 gPad->Range(x0,y0,x1,y1);
687 if (fZooms < kMAXZOOMS-1) {
689 fZoomX0[fZooms] = x0;
690 fZoomY0[fZooms] = y0;
691 fZoomX1[fZooms] = x1;
692 fZoomY1[fZooms] = y1;
694 gPad->Modified(kTRUE);
700 //___________________________________________
701 void AliDisplay::LoadPoints()
703 // Read hits info and store x,y,z info in arrays fPoints
704 // Loop on all detectors
706 gAlice->ResetPoints();
707 TIter next(gAlice->Modules());
709 Int_t ntracks = gAlice->GetNtrack();
710 for (Int_t track=0; track<ntracks;track++) {
712 gAlice->TreeH()->GetEvent(track);
713 while((module = (AliModule*)next())) {
714 module->LoadPoints(track);
720 //_____________________________________________________________________________
721 void AliDisplay::Paint(Option_t *)
723 // Paint miscellaneous items
727 //_____________________________________________________________________________
728 void AliDisplay::SetPickMode()
732 fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
733 fTrigPad->Modified();
736 //_____________________________________________________________________________
737 void AliDisplay::SetZoomMode()
741 fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
742 fTrigPad->Modified();
745 //_____________________________________________________________________________
746 void AliDisplay::SetPTcut(Float_t ptcut)
755 //_____________________________________________________________________________
756 void AliDisplay::SetRange(Float_t rrange, Float_t zrange)
758 // Set view range along R and Z
767 //_____________________________________________________________________________
768 void AliDisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
770 // change viewing angles for current event
773 fDrawAllViews = kFALSE;
779 TView *view = gPad->GetView();
780 if (view) view->SetView(fPhi, fTheta, fPsi, iret);
786 //_____________________________________________________________________________
787 void AliDisplay::ShowNextEvent(Int_t delta)
789 // Display (current event_number+delta)
790 // delta = 1 shown next event
791 // delta = -1 show previous event
795 Int_t current_event = gAlice->GetHeader()->GetEvent();
796 Int_t new_event = current_event + delta;
797 gAlice->GetEvent(new_event);
798 if (!gAlice->TreeH()) return;
805 //______________________________________________________________________________
806 void AliDisplay::UnZoom()
808 if (fZooms <= 0) return;
810 TPad *pad = (TPad*)gPad->GetPadSave();
811 pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);