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 **************************************************************************/
19 //////////////////////////////////////////////////////////////////////////
23 // Utility class to display ALICE outline, tracks, hits,.. //
25 //////////////////////////////////////////////////////////////////////////
33 #include <TPaveLabel.h>
34 #include <TPaveText.h>
36 #include <TSliderBox.h>
39 #include <TVirtualX.h>
41 #include "AliDetector.h"
42 #include "AliDisplay.h"
43 #include "AliHeader.h"
44 #include "AliPoints.h"
47 #include "TGeometry.h"
48 #include "TParticle.h"
50 static const Float_t kptcutmax = 2;
51 static const Float_t ketacutmax = 1.5;
56 //_______________________________________________________________________
57 AliDisplay::AliDisplay():
87 // Default constructor
91 //_______________________________________________________________________
92 AliDisplay::AliDisplay(Int_t size):
94 fDrawAllViews(kFALSE),
95 fDrawParticles(kTRUE),
121 // Create an event display object.
122 // A canvas named "edisplay" is created with a vertical size in pixels
124 // A QUICK Overview of the Event Display functions
125 // ===============================================
127 // The event display can ve invoked by executing the macro "display.C"
128 // A canvas like in the picture below will appear.
130 // On the left side of the canvas, the following buttons appear:
131 // *Next* to move to the next event
132 // *Previous* to move to the previous event
133 // *Top View* to display a top view of the current event
134 // *Side View* to display a side view of the current event
135 // *Front View* to display a front view of the current event
136 // *All Views* to display front/side/top/30-30 views of the current event
137 // *OpenGL* to use OpenGl to view the current event.
138 // Note that OpenGL cannot be used across the network.
139 // Before using OpenGL, load the GL libraries
140 // by executing the macro GL.C (in $ROOTSYS/macros/GL.C.
141 // Once in GL, click the HELP button of the GL canvas.
142 // *X3D* to use X3D to view the current event (Unix only).
143 // Once in X3D, type M to see the list of all possible options.
144 // for example type J to zoom, K to unzoom
145 // use the mouse to rotate.
146 // *Pick* Select this option to be able to point on a track with the
147 // mouse. Once on the track, use the right button to select
148 // an action. For example, select SetMarkerAttributes to
149 // change the marker type/color/size for the track.
150 // *Zoom* Select this option (default) if you want to zoom.
151 // To zoom, simply select the selected area with the left button.
152 // *UnZoom* To revert to the previous picture size.
154 // slider R On the left side, the vertical slider can be used to
155 // set the default picture size.
156 // slider pcut At the top of the canvas, a slider can be used to change
157 // the momentum cut (or range) to display tracks.
158 // slider eta On the right side of the canvas, a vertical slider can be used
159 // to specify a rapidity range for the tracks.
161 // When you are in Zoom mode, you can click on the black part of the canvas
162 // to select special options with the right mouse button.
163 // This will display a pop-up menu with items like:
164 // *Disable detector*
165 // *Enable detector*, etc.
166 // For example select "Disable detector". You get a dialog box.
167 // Diable detector TRD for example.
169 // When you are in pick mode, you can "Inspect" the object pointed by the mouse.
170 // When you are on a track, select the menu item "InspectParticle"
171 // to display the current particle attributes.
173 // You can activate the Root browser by selecting the Inspect menu
174 // in the canvas tool bar menu. Then select "Start Browser"
175 // This will open a new canvas with the browser. At this point, you may want
176 // to display some histograms (from the Trees). Go to the "File" menu
177 // of the browser and click on "New canvas".
178 // In the browser, click on item "ROOT files" in the left pane.
179 // Click on galice.root.
181 // Click on TPC for example
182 // Click on any variable (eg TPC.fX) to histogram the variable.
184 // If you are lost, you can click on HELP in any Root canvas or browser.
187 <img src="picts/alidisplay.gif">
191 gAlice->SetDisplay(this);
193 // Initialize display default parameters
197 // Set front view by default
199 // Create display canvas
201 if (ysize < 100) ysize = 750;
202 Int_t xsize = Int_t(size*830./ysize);
203 fCanvas = new TCanvas("Canvas", "ALICE Event Display",14,47,xsize,ysize);
204 fCanvas->ToggleEventStatus();
206 // Create main display pad
207 fPad = new TPad("viewpad", "Alice display",0.15,0,0.97,0.96);
210 fPad->SetFillColor(1);
211 fPad->SetBorderSize(2);
213 // Create user interface control pad
217 // Create Range and mode pad
220 fTrigPad = new TPad("trigger", "range and mode pad",0,0,dxtr,dytr);
223 fTrigPad->SetFillColor(22);
224 fTrigPad->SetBorderSize(2);
226 fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
227 fRangeSlider->SetObject(this);
228 char pickmode[] = "gAlice->Display()->SetPickMode()";
231 fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
232 fPickButton->SetFillColor(38);
234 char zoommode[] = "gAlice->Display()->SetZoomMode()";
235 fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
236 fZoomButton->SetFillColor(38);
238 fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
239 fArcButton->SetFillColor(kGreen);
241 char butUnzoom[] = "gAlice->Display()->UnZoom()";
242 TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
243 button->SetFillColor(38);
245 AppendPad(); // append display object as last object to force selection
247 // Create momentum cut slider pad
249 fCutPad = new TPad("cutSlider", "pcut slider pad",dxtr,.96,1,1);
252 fCutPad->SetFillColor(22);
253 fCutPad->SetBorderSize(2);
255 fCutSlider = new TSlider("pcut","Momentum cut",0,0,1,1);
256 fCutSlider->SetRange(fPTcut/kptcutmax,1);
257 fCutSlider->SetObject(this);
258 fCutSlider->SetFillColor(45);
259 TSliderBox *sbox = dynamic_cast<TSliderBox*>(fCutSlider->GetListOfPrimitives()->First());
260 sbox->SetFillColor(46);
262 TGaxis *cutaxis = new TGaxis(0.02,0.8,0.98,0.8,0,kptcutmax,510,"");
263 cutaxis->SetLabelSize(0.5);
264 cutaxis->SetTitleSize(0.6);
265 cutaxis->SetTitleOffset(0.5);
266 cutaxis->SetTitle("pcut . ");
267 fCutSlider->GetListOfPrimitives()->AddFirst(cutaxis);
269 // Create rapidity cut slider pad
272 fEtaPad = new TPad("EtaSlider", "Eta slider pad",0.97,0,1,0.96);
275 fEtaPad->SetFillColor(22);
276 fEtaPad->SetBorderSize(2);
278 fEtaSlider = new TSlider("etacut","Rapidity cut",0,0,1,1);
279 fEtaSlider->SetObject(this);
280 fEtaSlider->SetFillColor(45);
281 TSliderBox *sbox2 = dynamic_cast<TSliderBox*>(fEtaSlider->GetListOfPrimitives()->First());
282 sbox2->SetFillColor(46);
284 TGaxis *etaaxis = new TGaxis(0.9,0.02,0.9,0.98,-ketacutmax,ketacutmax,510,"");
285 etaaxis->SetLabelSize(0.5);
286 etaaxis->SetTitleSize(0.6);
287 etaaxis->SetTitleOffset(0.2);
288 cutaxis->SetTitle("Etacut . ");
289 fEtaSlider->GetListOfPrimitives()->AddFirst(etaaxis);
292 fTrigPad->SetEditable(kFALSE);
293 fButtons->SetEditable(kFALSE);
295 fNTracksToDisplay =0;
302 //_______________________________________________________________________
303 AliDisplay::AliDisplay(const AliDisplay &disp):
339 //_____________________________________________________________________________
340 AliDisplay::~AliDisplay()
347 //_____________________________________________________________________________
348 void AliDisplay::Clear(Option_t *)
350 // Delete graphics temporary objects
353 //_____________________________________________________________________________
354 void AliDisplay::Copy(AliDisplay &) const
357 // Copy *this onto disp -- not implemented
359 Fatal("Copy","Not implemented~\n");
362 //----------------------------------------------------------------------------
363 void AliDisplay::ShowTrack(Int_t idx)
368 AliDetector *mTPC=dynamic_cast<AliDetector*>(gAlice->GetModule("TPC"));
369 TObjArray *points=mTPC->Points();
370 int ntracks=points->GetEntriesFast();
371 for (int track=0;track<ntracks;track++) {
372 AliPoints *pm = dynamic_cast<AliPoints*>(points->UncheckedAt(track));
374 if (idx == pm->GetIndex()) {
375 pm->SetMarkerColor(2);
376 pm->SetMarkerStyle(22);
380 // TClonesArray *particles=gAlice->Particles();
381 // TParticle *p = (TParticle*)particles->UncheckedAt(idx);
382 TParticle *p = gAlice->Particle(idx);
383 printf("\nTrack index %d\n",idx);
384 printf("Particle ID %d\n",p->GetPdgCode());
385 printf("Parent %d\n",p->GetFirstMother());
386 printf("First child %d\n",p->GetFirstDaughter());
387 printf("Px,Py,Pz %f %f %f\n",p->Px(),p->Py(),p->Pz());
393 //----------------------------------------------------------------------------
394 void AliDisplay::HideTrack(Int_t idx) const
397 // Hide track on display
399 AliDetector *mTPC=dynamic_cast<AliDetector*>(gAlice->GetModule("TPC"));
400 TObjArray *points=mTPC->Points();
401 int ntracks=points->GetEntriesFast();
402 for (int track=0;track<ntracks;track++) {
403 AliPoints *pm = dynamic_cast<AliPoints*>(points->UncheckedAt(track));
405 if (idx == pm->GetIndex()) {
406 pm->SetMarkerColor(5);
407 pm->SetMarkerStyle(1);
416 //_____________________________________________________________________________
417 void AliDisplay::DisableDetector(const char *name)
419 // Disable detector name from graphics views
421 AliModule *module = dynamic_cast<AliModule*>(gAlice->Modules()->FindObject(name));
427 //_____________________________________________________________________________
428 void AliDisplay::DisplayButtons()
430 // Create the user interface buttons
432 fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
434 fButtons->SetFillColor(38);
435 fButtons->SetBorderSize(2);
439 Float_t dbutton = 0.08;
446 char but1[] = "gAlice->Display()->ShowNextEvent(1)";
447 button = new TButton("Next",but1,x0,y-dbutton,x1,y);
448 button->SetFillColor(38);
452 char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
453 button = new TButton("Previous",but2,x0,y-dbutton,x1,y);
454 button->SetFillColor(38);
458 char but3[] = "gAlice->Display()->SetView(90,-90,90)";
459 button = new TButton("Top View",but3,x0,y-dbutton,x1,y);
460 button->SetFillColor(butcolor);
464 char but4[] = "gAlice->Display()->SetView(90,0,-90)";
465 button = new TButton("Side View",but4,x0,y-dbutton,x1,y);
466 button->SetFillColor(butcolor);
470 char but5[] = "gAlice->Display()->SetView(0,-90,0)";
471 button = new TButton("Front View",but5,x0,y-dbutton,x1,y);
472 button->SetFillColor(butcolor);
476 char but6[] = "gAlice->Display()->DrawAllViews()";
477 button = new TButton("All Views",but6,x0,y-dbutton,x1,y);
478 button->SetFillColor(butcolor);
482 char but7[] = "gAlice->Display()->DrawViewGL()";
483 button = new TButton("OpenGL",but7,x0,y-dbutton,x1,y);
484 button->SetFillColor(38);
488 char but8[] = "gAlice->Display()->DrawViewX3D()";
489 button = new TButton("X3D",but8,x0,y-dbutton,x1,y);
490 button->SetFillColor(38);
494 TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
495 diamond->SetFillColor(50);
496 diamond->SetTextAlign(22);
497 diamond->SetTextColor(5);
498 diamond->SetTextSize(0.11);
500 diamond->AddText(".. ");
501 diamond->AddText("ROOT");
502 diamond->AddText("ALICE");
503 diamond->AddText("... ");
504 diamond->AddText(" ");
507 //______________________________________________________________________________
508 Int_t AliDisplay::DistancetoPrimitive(Int_t px, Int_t)
510 // Compute distance from point px,py to objects in event
512 gPad->SetCursor(kCross);
514 if (gPad == fTrigPad) return 9999;
515 if (gPad == fCutPad) return 9999;
516 if (gPad == fEtaPad) return 9999;
518 const Int_t kbig = 9999;
520 Float_t xmin = gPad->GetX1();
521 Float_t xmax = gPad->GetX2();
522 Float_t dx = 0.02*(xmax - xmin);
523 Float_t x = gPad->AbsPixeltoX(px);
524 if (x < xmin+dx || x > xmax-dx) return dist;
526 if (fZoomMode) return 0;
530 //_____________________________________________________________________________
531 void AliDisplay::Draw(Option_t *)
533 // Display current event
542 DrawView(fTheta, fPhi, fPsi);
544 // Display the event number and title
549 //_____________________________________________________________________________
550 void AliDisplay::DrawAllViews()
552 // Draw front,top,side and 30 deg views
554 fDrawAllViews = kTRUE;
556 fPad->SetFillColor(15);
572 DrawView(90, -90, 90);
577 DrawView(90, 0, -90);
583 //_____________________________________________________________________________
584 void AliDisplay::DrawHits()
586 // Draw hits for all ALICE detectors
588 Float_t cutmin, cutmax, etamin, etamax, pmom, smin, smax, eta, theta, r;
596 smax = fCutSlider->GetMaximum();
597 smin = fCutSlider->GetMinimum();
598 cutmin = kptcutmax*smin;
599 if (smax < 0.98) cutmax = kptcutmax*smax;
600 else cutmax = 100000;
603 smax = fEtaSlider->GetMaximum();
604 smin = fEtaSlider->GetMinimum();
605 etamin = ketacutmax*(2*smin-1);
606 etamax = ketacutmax*(2*smax-1);
607 if (smin < 0.02) etamin = -1000;
608 if (smax > 0.98) etamax = 1000;
610 TIter next(gAlice->Modules());
613 while((module = dynamic_cast<AliModule*>(next()))) {
614 if (!module->IsActive()) continue;
615 points = module->Points();
616 if (!points) continue;
617 ntracks = points->GetEntriesFast();
618 for (track=0;track<ntracks;track++) {
619 pm = dynamic_cast<AliPoints*>(points->UncheckedAt(track));
621 particle = pm->GetParticle();
622 if (!particle) continue;
623 pmom = particle->P();
624 if (pmom < cutmin) continue;
625 if (pmom > cutmax) continue;
626 // as a first approximation, take eta of first point
628 r = TMath::Sqrt(pxyz[0]*pxyz[0] + pxyz[1]*pxyz[1]);
629 theta = TMath::ATan2(r,TMath::Abs(pxyz[2]));
630 if(theta) eta = -TMath::Log(TMath::Abs(TMath::Tan(0.5*theta))); else eta = 1e10;
631 if (pxyz[2] < 0) eta = -eta;
632 if (eta < etamin || eta > etamax) continue;
634 fHitsCuts += pm->GetN();
639 //_____________________________________________________________________________
640 void AliDisplay::DrawTitle(Option_t *option)
642 // Draw the event title
644 Float_t xmin = gPad->GetX1();
645 Float_t xmax = gPad->GetX2();
646 Float_t ymin = gPad->GetY1();
647 Float_t ymax = gPad->GetY2();
648 Float_t dx = xmax-xmin;
649 Float_t dy = ymax-ymin;
651 if (strlen(option) == 0) {
652 TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
653 title->SetBit(kCanDelete);
654 title->SetFillColor(42);
657 sprintf(ptitle,"Alice event: %d, Run:%d",gAlice->GetHeader()->GetEvent(), gAlice->GetHeader()->GetRun());
658 title->AddText(ptitle);
659 Int_t nparticles = gAlice->Particles()->GetEntriesFast();
660 sprintf(ptitle,"Nparticles = %d Nhits = %d",nparticles, fHitsCuts);
661 title->AddText(ptitle);
663 TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
664 label->SetBit(kCanDelete);
665 label->SetFillColor(42);
670 //_____________________________________________________________________________
671 void AliDisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
673 // Draw a view of ALICE
675 gPad->SetCursor(kWatch);
676 gPad->SetFillColor(1);
680 TView *view = new TView(1);
681 Float_t range = fRrange*fRangeSlider->GetMaximum();
682 view->SetRange(-range,-range,-range,range, range, range);
689 // Display Alice Geometry
690 gAlice->GetGeometry()->Draw("same");
692 //Loop on all detectors to add their products to the pad
695 // add itself to the list (must be last)
698 view->SetView(phi, theta, psi, iret);
701 //_____________________________________________________________________________
702 void AliDisplay::DrawViewGL()
704 // Draw current view using OPENGL
706 TPad *pad = dynamic_cast<TPad*>(gPad->GetPadSave());
708 TView *view = pad->GetView();
713 //_____________________________________________________________________________
714 void AliDisplay::DrawViewX3D()
716 // Draw current view using X3D
718 TPad *pad = dynamic_cast<TPad*>(gPad->GetPadSave());
720 TView *view = pad->GetView();
725 //_____________________________________________________________________________
726 void AliDisplay::EnableDetector(const char *name)
728 // Enable detector name in graphics views
730 AliModule *module = dynamic_cast<AliModule*>(gAlice->Modules()->FindObject(name));
736 //______________________________________________________________________________
737 void AliDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
739 // Execute action corresponding to the mouse event
741 static Float_t x0, y0, x1, y1;
743 static Int_t pxold, pyold;
744 static Int_t px0, py0;
745 static Int_t linedrawn;
748 if (px == 0 && py == 0) { //when called by sliders
749 if (event == kButton1Up) {
754 if (!fZoomMode && gPad->GetView()) {
755 gPad->GetView()->ExecuteRotateView(event, px, py);
759 // something to zoom ?
760 // fPad->SetCursor(kCross);
761 gPad->SetCursor(kCross);
766 gVirtualX->SetLineColor(-1);
767 gPad->TAttLine::Modify(); //Change line attributes only if necessary
768 x0 = gPad->AbsPixeltoX(px);
769 y0 = gPad->AbsPixeltoY(py);
771 pxold = px; pyold = py;
776 if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
780 gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
784 gPad->GetCanvas()->FeedbackMode(kFALSE);
785 if (px == px0) return;
786 if (py == py0) return;
787 x1 = gPad->AbsPixeltoX(px);
788 y1 = gPad->AbsPixeltoY(py);
790 if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
791 if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
792 gPad->Range(x0,y0,x1,y1);
793 if (fZooms < kMAXZOOMS-1) {
795 fZoomX0[fZooms] = x0;
796 fZoomY0[fZooms] = y0;
797 fZoomX1[fZooms] = x1;
798 fZoomY1[fZooms] = y1;
800 gPad->Modified(kTRUE);
807 void AliDisplay::SetTracksToDisplay(Int_t *tracks, Int_t n){
809 // set tracks to display - MI
810 fTracksToDisplay = tracks;
811 fNTracksToDisplay = n;
813 //___________________________________________
814 void AliDisplay::LoadPoints()
816 // Read hits info and store x,y,z info in arrays fPoints
817 // Loop on all detectors
819 gAlice->ResetPoints();
820 TIter next(gAlice->Modules());
822 Int_t ntracks = gAlice->GetNtrack();
824 // load only wanted tracks
825 if (fNTracksToDisplay>0){
826 Int_t nprim = gAlice->Stack()->GetNprimary();
827 for (Int_t track=0; track<fNTracksToDisplay;track++) {
829 gAlice->TreeH()->GetEvent(nprim-1-gAlice->GetPrimary(fTracksToDisplay[track]));
830 while((module = dynamic_cast<AliModule*>(next()))) {
831 module->LoadPoints(nprim-1-gAlice->GetPrimary(fTracksToDisplay[track]));
837 for (Int_t track=0; track<ntracks;track++) {
839 gAlice->TreeH()->GetEvent(track);
840 while((module = dynamic_cast<AliModule*>(next()))) {
841 module->LoadPoints(track);
847 //_____________________________________________________________________________
848 void AliDisplay::Paint(Option_t *)
850 // Paint miscellaneous items
854 //_____________________________________________________________________________
855 void AliDisplay::SetPickMode()
858 // Set Pick Mode -- disable zoom
862 fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
863 fTrigPad->Modified();
866 //_____________________________________________________________________________
867 void AliDisplay::SetZoomMode()
870 // Set Zoom Mode -- disable pick
874 fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
875 fTrigPad->Modified();
878 //_____________________________________________________________________________
879 void AliDisplay::SetPTcut(Float_t ptcut)
891 //_____________________________________________________________________________
892 void AliDisplay::SetRange(Float_t rrange, Float_t zrange)
894 // Set view range along R and Z
903 //_____________________________________________________________________________
904 void AliDisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
906 // change viewing angles for current event
909 fDrawAllViews = kFALSE;
915 TView *view = gPad->GetView();
916 if (view) view->SetView(fPhi, fTheta, fPsi, iret);
922 //_____________________________________________________________________________
923 void AliDisplay::ShowNextEvent(Int_t delta)
925 // Display (current event_number+delta)
926 // delta = 1 shown next event
927 // delta = -1 show previous event
931 Int_t currentEvent = gAlice->GetHeader()->GetEvent();
932 Int_t newEvent = currentEvent + delta;
933 gAlice->GetEvent(newEvent);
934 if (!gAlice->TreeH()) return;
941 //______________________________________________________________________________
942 void AliDisplay::UnZoom()
947 if (fZooms <= 0) return;
949 TPad *pad = dynamic_cast<TPad*>(gPad->GetPadSave());
950 pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);
954 //_____________________________________________________________________________
955 AliDisplay & AliDisplay::operator=(const AliDisplay &disp)
958 // Assignment operator