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 //////////////////////////////////////////////////////////////////////////
22 // Utility class to display ALICE outline, tracks, hits,.. //
24 //////////////////////////////////////////////////////////////////////////
32 #include <TPaveLabel.h>
33 #include <TPaveText.h>
35 #include <TSliderBox.h>
38 #include <TVirtualX.h>
40 #include "AliDetector.h"
41 #include "AliDisplay.h"
42 #include "AliHeader.h"
43 #include "AliPoints.h"
46 #include "TGeometry.h"
47 #include "TParticle.h"
49 static const Float_t kptcutmax = 2;
50 static const Float_t ketacutmax = 1.5;
55 //_______________________________________________________________________
56 AliDisplay::AliDisplay():
86 // Default constructor
90 //_____________________________________________________________________________
91 AliDisplay::AliDisplay(Int_t size):
93 fDrawAllViews(kFALSE),
94 fDrawParticles(kTRUE),
120 // Create an event display object.
121 // A canvas named "edisplay" is created with a vertical size in pixels
123 // A QUICK Overview of the Event Display functions
124 // ===============================================
126 // The event display can ve invoked by executing the macro "display.C"
127 // A canvas like in the picture below will appear.
129 // On the left side of the canvas, the following buttons appear:
130 // *Next* to move to the next event
131 // *Previous* to move to the previous event
132 // *Top View* to display a top view of the current event
133 // *Side View* to display a side view of the current event
134 // *Front View* to display a front view of the current event
135 // *All Views* to display front/side/top/30-30 views of the current event
136 // *OpenGL* to use OpenGl to view the current event.
137 // Note that OpenGL cannot be used across the network.
138 // Before using OpenGL, load the GL libraries
139 // by executing the macro GL.C (in $ROOTSYS/macros/GL.C.
140 // Once in GL, click the HELP button of the GL canvas.
141 // *X3D* to use X3D to view the current event (Unix only).
142 // Once in X3D, type M to see the list of all possible options.
143 // for example type J to zoom, K to unzoom
144 // use the mouse to rotate.
145 // *Pick* Select this option to be able to point on a track with the
146 // mouse. Once on the track, use the right button to select
147 // an action. For example, select SetMarkerAttributes to
148 // change the marker type/color/size for the track.
149 // *Zoom* Select this option (default) if you want to zoom.
150 // To zoom, simply select the selected area with the left button.
151 // *UnZoom* To revert to the previous picture size.
153 // slider R On the left side, the vertical slider can be used to
154 // set the default picture size.
155 // slider pcut At the top of the canvas, a slider can be used to change
156 // the momentum cut (or range) to display tracks.
157 // slider eta On the right side of the canvas, a vertical slider can be used
158 // to specify a rapidity range for the tracks.
160 // When you are in Zoom mode, you can click on the black part of the canvas
161 // to select special options with the right mouse button.
162 // This will display a pop-up menu with items like:
163 // *Disable detector*
164 // *Enable detector*, etc.
165 // For example select "Disable detector". You get a dialog box.
166 // Diable detector TRD for example.
168 // When you are in pick mode, you can "Inspect" the object pointed by the mouse.
169 // When you are on a track, select the menu item "InspectParticle"
170 // to display the current particle attributes.
172 // You can activate the Root browser by selecting the Inspect menu
173 // in the canvas tool bar menu. Then select "Start Browser"
174 // This will open a new canvas with the browser. At this point, you may want
175 // to display some histograms (from the Trees). Go to the "File" menu
176 // of the browser and click on "New canvas".
177 // In the browser, click on item "ROOT files" in the left pane.
178 // Click on galice.root.
180 // Click on TPC for example
181 // Click on any variable (eg TPC.fX) to histogram the variable.
183 // If you are lost, you can click on HELP in any Root canvas or browser.
186 <img src="picts/alidisplay.gif">
190 gAlice->SetDisplay(this);
192 // Initialize display default parameters
196 // Create display canvas
198 if (ysize < 100) ysize = 750;
199 Int_t xsize = Int_t(size*830./ysize);
200 fCanvas = new TCanvas("Canvas", "ALICE Event Display",14,47,xsize,ysize);
201 fCanvas->ToggleEventStatus();
203 // Create main display pad
204 fPad = new TPad("viewpad", "Alice display",0.15,0,0.97,0.96);
207 fPad->SetFillColor(1);
208 fPad->SetBorderSize(2);
210 // Create user interface control pad
214 // Create Range and mode pad
217 fTrigPad = new TPad("trigger", "range and mode pad",0,0,dxtr,dytr);
220 fTrigPad->SetFillColor(22);
221 fTrigPad->SetBorderSize(2);
222 fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
223 fRangeSlider->SetObject(this);
224 char pickmode[] = "gAlice->Display()->SetPickMode()";
226 fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
227 fPickButton->SetFillColor(38);
229 char zoommode[] = "gAlice->Display()->SetZoomMode()";
230 fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
231 fZoomButton->SetFillColor(38);
233 fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
234 fArcButton->SetFillColor(kGreen);
236 char butUnzoom[] = "gAlice->Display()->UnZoom()";
237 TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
238 button->SetFillColor(38);
240 AppendPad(); // append display object as last object to force selection
241 // Create momentum cut slider pad
243 fCutPad = new TPad("cutSlider", "pcut slider pad",dxtr,.96,1,1);
246 fCutPad->SetFillColor(22);
247 fCutPad->SetBorderSize(2);
248 fCutSlider = new TSlider("pcut","Momentum cut",0,0,1,1);
249 fCutSlider->SetRange(fPTcut/kptcutmax,1);
250 fCutSlider->SetObject(this);
251 fCutSlider->SetFillColor(45);
252 TSliderBox *sbox = dynamic_cast<TSliderBox*>(fCutSlider->GetListOfPrimitives()->First());
253 sbox->SetFillColor(46);
255 TGaxis *cutaxis = new TGaxis(0.02,0.8,0.98,0.8,0,kptcutmax,510,"");
256 cutaxis->SetLabelSize(0.5);
257 cutaxis->SetTitleSize(0.6);
258 cutaxis->SetTitleOffset(0.5);
259 cutaxis->SetTitle("pcut . ");
260 fCutSlider->GetListOfPrimitives()->AddFirst(cutaxis);
261 // Create rapidity cut slider pad
263 fEtaPad = new TPad("EtaSlider", "Eta slider pad",0.97,0,1,0.96);
266 fEtaPad->SetFillColor(22);
267 fEtaPad->SetBorderSize(2);
268 fEtaSlider = new TSlider("etacut","Rapidity cut",0,0,1,1);
269 fEtaSlider->SetObject(this);
270 fEtaSlider->SetFillColor(45);
271 TSliderBox *sbox2 = dynamic_cast<TSliderBox*>(fEtaSlider->GetListOfPrimitives()->First());
272 sbox2->SetFillColor(46);
274 TGaxis *etaaxis = new TGaxis(0.9,0.02,0.9,0.98,-ketacutmax,ketacutmax,510,"");
275 etaaxis->SetLabelSize(0.5);
276 etaaxis->SetTitleSize(0.6);
277 etaaxis->SetTitleOffset(0.2);
278 cutaxis->SetTitle("Etacut . ");
279 fEtaSlider->GetListOfPrimitives()->AddFirst(etaaxis);
282 fTrigPad->SetEditable(kFALSE);
283 fButtons->SetEditable(kFALSE);
285 fNTracksToDisplay =0;
292 //_______________________________________________________________________
293 AliDisplay::AliDisplay(const AliDisplay &disp):
329 //_____________________________________________________________________________
330 AliDisplay::~AliDisplay()
337 //_____________________________________________________________________________
338 void AliDisplay::Clear(Option_t *)
340 // Delete graphics temporary objects
343 //_____________________________________________________________________________
344 void AliDisplay::Copy(AliDisplay &) const
347 // Copy *this onto disp -- not implemented
349 Fatal("Copy","Not implemented~\n");
352 //----------------------------------------------------------------------------
353 void AliDisplay::ShowTrack(Int_t idx)
358 AliDetector *mTPC=dynamic_cast<AliDetector*>(gAlice->GetModule("TPC"));
359 TObjArray *points=mTPC->Points();
360 int ntracks=points->GetEntriesFast();
361 for (int track=0;track<ntracks;track++) {
362 AliPoints *pm = dynamic_cast<AliPoints*>(points->UncheckedAt(track));
364 if (idx == pm->GetIndex()) {
365 pm->SetMarkerColor(2);
366 pm->SetMarkerStyle(22);
370 // TClonesArray *particles=gAlice->Particles();
371 // TParticle *p = (TParticle*)particles->UncheckedAt(idx);
372 TParticle *p = gAlice->Particle(idx);
373 printf("\nTrack index %d\n",idx);
374 printf("Particle ID %d\n",p->GetPdgCode());
375 printf("Parent %d\n",p->GetFirstMother());
376 printf("First child %d\n",p->GetFirstDaughter());
377 printf("Px,Py,Pz %f %f %f\n",p->Px(),p->Py(),p->Pz());
383 //----------------------------------------------------------------------------
384 void AliDisplay::HideTrack(Int_t idx) const
387 // Hide track on display
389 AliDetector *mTPC=dynamic_cast<AliDetector*>(gAlice->GetModule("TPC"));
390 TObjArray *points=mTPC->Points();
391 int ntracks=points->GetEntriesFast();
392 for (int track=0;track<ntracks;track++) {
393 AliPoints *pm = dynamic_cast<AliPoints*>(points->UncheckedAt(track));
395 if (idx == pm->GetIndex()) {
396 pm->SetMarkerColor(5);
397 pm->SetMarkerStyle(1);
406 //_____________________________________________________________________________
407 void AliDisplay::DisableDetector(const char *name)
409 // Disable detector name from graphics views
411 AliModule *module = dynamic_cast<AliModule*>(gAlice->Modules()->FindObject(name));
417 //_____________________________________________________________________________
418 void AliDisplay::DisplayButtons()
420 // Create the user interface buttons
422 fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
424 fButtons->SetFillColor(38);
425 fButtons->SetBorderSize(2);
429 Float_t dbutton = 0.08;
436 char but1[] = "gAlice->Display()->ShowNextEvent(1)";
437 button = new TButton("Next",but1,x0,y-dbutton,x1,y);
438 button->SetFillColor(38);
442 char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
443 button = new TButton("Previous",but2,x0,y-dbutton,x1,y);
444 button->SetFillColor(38);
448 char but3[] = "gAlice->Display()->SetView(90,-90,90)";
449 button = new TButton("Top View",but3,x0,y-dbutton,x1,y);
450 button->SetFillColor(butcolor);
454 char but4[] = "gAlice->Display()->SetView(90,0,-90)";
455 button = new TButton("Side View",but4,x0,y-dbutton,x1,y);
456 button->SetFillColor(butcolor);
460 char but5[] = "gAlice->Display()->SetView(0,-90,0)";
461 button = new TButton("Front View",but5,x0,y-dbutton,x1,y);
462 button->SetFillColor(butcolor);
466 char but6[] = "gAlice->Display()->DrawAllViews()";
467 button = new TButton("All Views",but6,x0,y-dbutton,x1,y);
468 button->SetFillColor(butcolor);
472 char but7[] = "gAlice->Display()->DrawViewGL()";
473 button = new TButton("OpenGL",but7,x0,y-dbutton,x1,y);
474 button->SetFillColor(38);
478 char but8[] = "gAlice->Display()->DrawViewX3D()";
479 button = new TButton("X3D",but8,x0,y-dbutton,x1,y);
480 button->SetFillColor(38);
484 TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
485 diamond->SetFillColor(50);
486 diamond->SetTextAlign(22);
487 diamond->SetTextColor(5);
488 diamond->SetTextSize(0.11);
490 diamond->AddText(".. ");
491 diamond->AddText("ROOT");
492 diamond->AddText("ALICE");
493 diamond->AddText("... ");
494 diamond->AddText(" ");
497 //______________________________________________________________________________
498 Int_t AliDisplay::DistancetoPrimitive(Int_t px, Int_t)
500 // Compute distance from point px,py to objects in event
502 gPad->SetCursor(kCross);
504 if (gPad == fTrigPad) return 9999;
505 if (gPad == fCutPad) return 9999;
506 if (gPad == fEtaPad) return 9999;
508 const Int_t kbig = 9999;
510 Float_t xmin = gPad->GetX1();
511 Float_t xmax = gPad->GetX2();
512 Float_t dx = 0.02*(xmax - xmin);
513 Float_t x = gPad->AbsPixeltoX(px);
514 if (x < xmin+dx || x > xmax-dx) return dist;
516 if (fZoomMode) return 0;
520 //_____________________________________________________________________________
521 void AliDisplay::Draw(Option_t *)
523 // Display current event
532 DrawView(fTheta, fPhi, fPsi);
534 // Display the event number and title
539 //_____________________________________________________________________________
540 void AliDisplay::DrawAllViews()
542 // Draw front,top,side and 30 deg views
544 fDrawAllViews = kTRUE;
546 fPad->SetFillColor(15);
562 DrawView(90, -90, 90);
567 DrawView(90, 0, -90);
573 //_____________________________________________________________________________
574 void AliDisplay::DrawHits()
576 // Draw hits for all ALICE detectors
578 Float_t cutmin, cutmax, etamin, etamax, pmom, smin, smax, eta, theta, r;
586 smax = fCutSlider->GetMaximum();
587 smin = fCutSlider->GetMinimum();
588 cutmin = kptcutmax*smin;
589 if (smax < 0.98) cutmax = kptcutmax*smax;
590 else cutmax = 100000;
593 smax = fEtaSlider->GetMaximum();
594 smin = fEtaSlider->GetMinimum();
595 etamin = ketacutmax*(2*smin-1);
596 etamax = ketacutmax*(2*smax-1);
597 if (smin < 0.02) etamin = -1000;
598 if (smax > 0.98) etamax = 1000;
600 TIter next(gAlice->Modules());
603 while((module = dynamic_cast<AliModule*>(next()))) {
604 if (!module->IsActive()) continue;
605 points = module->Points();
606 if (!points) continue;
607 ntracks = points->GetEntriesFast();
608 for (track=0;track<ntracks;track++) {
609 pm = dynamic_cast<AliPoints*>(points->UncheckedAt(track));
611 particle = pm->GetParticle();
612 if (!particle) continue;
613 pmom = particle->P();
614 if (pmom < cutmin) continue;
615 if (pmom > cutmax) continue;
616 // as a first approximation, take eta of first point
618 r = TMath::Sqrt(pxyz[0]*pxyz[0] + pxyz[1]*pxyz[1]);
619 theta = TMath::ATan2(r,TMath::Abs(pxyz[2]));
620 if(theta) eta = -TMath::Log(TMath::Abs(TMath::Tan(0.5*theta))); else eta = 1e10;
621 if (pxyz[2] < 0) eta = -eta;
622 if (eta < etamin || eta > etamax) continue;
624 fHitsCuts += pm->GetN();
629 //_____________________________________________________________________________
630 void AliDisplay::DrawTitle(Option_t *option)
632 // Draw the event title
634 Float_t xmin = gPad->GetX1();
635 Float_t xmax = gPad->GetX2();
636 Float_t ymin = gPad->GetY1();
637 Float_t ymax = gPad->GetY2();
638 Float_t dx = xmax-xmin;
639 Float_t dy = ymax-ymin;
641 if (strlen(option) == 0) {
642 TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
643 title->SetBit(kCanDelete);
644 title->SetFillColor(42);
647 sprintf(ptitle,"Alice event: %d, Run:%d",gAlice->GetHeader()->GetEvent(), gAlice->GetHeader()->GetRun());
648 title->AddText(ptitle);
649 Int_t nparticles = gAlice->Particles()->GetEntriesFast();
650 sprintf(ptitle,"Nparticles = %d Nhits = %d",nparticles, fHitsCuts);
651 title->AddText(ptitle);
653 TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
654 label->SetBit(kCanDelete);
655 label->SetFillColor(42);
660 //_____________________________________________________________________________
661 void AliDisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
663 // Draw a view of ALICE
665 gPad->SetCursor(kWatch);
666 gPad->SetFillColor(1);
670 TView *view = new TView(1);
671 Float_t range = fRrange*fRangeSlider->GetMaximum();
672 view->SetRange(-range,-range,-range,range, range, range);
679 // Display Alice Geometry
680 gAlice->GetGeometry()->Draw("same");
682 //Loop on all detectors to add their products to the pad
685 // add itself to the list (must be last)
688 view->SetView(phi, theta, psi, iret);
691 //_____________________________________________________________________________
692 void AliDisplay::DrawViewGL()
694 // Draw current view using OPENGL
696 TPad *pad = dynamic_cast<TPad*>(gPad->GetPadSave());
698 TView *view = pad->GetView();
703 //_____________________________________________________________________________
704 void AliDisplay::DrawViewX3D()
706 // Draw current view using X3D
708 TPad *pad = dynamic_cast<TPad*>(gPad->GetPadSave());
710 TView *view = pad->GetView();
715 //_____________________________________________________________________________
716 void AliDisplay::EnableDetector(const char *name)
718 // Enable detector name in graphics views
720 AliModule *module = dynamic_cast<AliModule*>(gAlice->Modules()->FindObject(name));
726 //______________________________________________________________________________
727 void AliDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
729 // Execute action corresponding to the mouse event
731 static Float_t x0, y0, x1, y1;
733 static Int_t pxold, pyold;
734 static Int_t px0, py0;
735 static Int_t linedrawn;
738 if (px == 0 && py == 0) { //when called by sliders
739 if (event == kButton1Up) {
744 if (!fZoomMode && gPad->GetView()) {
745 gPad->GetView()->ExecuteRotateView(event, px, py);
749 // something to zoom ?
750 // fPad->SetCursor(kCross);
751 gPad->SetCursor(kCross);
756 gVirtualX->SetLineColor(-1);
757 gPad->TAttLine::Modify(); //Change line attributes only if necessary
758 x0 = gPad->AbsPixeltoX(px);
759 y0 = gPad->AbsPixeltoY(py);
761 pxold = px; pyold = py;
766 if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
770 gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
774 gPad->GetCanvas()->FeedbackMode(kFALSE);
775 if (px == px0) return;
776 if (py == py0) return;
777 x1 = gPad->AbsPixeltoX(px);
778 y1 = gPad->AbsPixeltoY(py);
780 if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
781 if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
782 gPad->Range(x0,y0,x1,y1);
783 if (fZooms < kMAXZOOMS-1) {
785 fZoomX0[fZooms] = x0;
786 fZoomY0[fZooms] = y0;
787 fZoomX1[fZooms] = x1;
788 fZoomY1[fZooms] = y1;
790 gPad->Modified(kTRUE);
797 void AliDisplay::SetTracksToDisplay(Int_t *tracks, Int_t n){
799 // set tracks to display - MI
800 fTracksToDisplay = tracks;
801 fNTracksToDisplay = n;
803 //___________________________________________
804 void AliDisplay::LoadPoints()
806 // Read hits info and store x,y,z info in arrays fPoints
807 // Loop on all detectors
809 gAlice->ResetPoints();
810 TIter next(gAlice->Modules());
812 Int_t ntracks = gAlice->GetNtrack();
814 while((module = (AliModule*)next()))
816 AliDetector* detector = dynamic_cast<AliDetector*>(module);
817 if(detector) detector->SetTreeAddress();
821 // load only wanted tracks
822 if (fNTracksToDisplay>0)
824 Int_t nprim = gAlice->Stack()->GetNprimary();
825 for (Int_t track=0; track<fNTracksToDisplay;track++)
828 Int_t nev = nprim-1-gAlice->GetPrimary(fTracksToDisplay[track]);
829 while((module = (AliModule*)next()))
831 AliDetector* detector = dynamic_cast<AliDetector*>(module);
834 detector->TreeH()->GetEvent(nev);
835 module->LoadPoints(nprim-1-gAlice->GetPrimary(fTracksToDisplay[track]));
844 for (Int_t track=0; track<ntracks;track++) {
846 while((module = (AliModule*)next())) {
847 AliDetector* detector = dynamic_cast<AliDetector*>(module);
850 detector->TreeH()->GetEvent(track);
851 detector->LoadPoints(track);
859 //_____________________________________________________________________________
860 void AliDisplay::Paint(Option_t *)
862 // Paint miscellaneous items
866 //_____________________________________________________________________________
867 void AliDisplay::SetPickMode()
870 // Set Pick Mode -- disable zoom
874 fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
875 fTrigPad->Modified();
878 //_____________________________________________________________________________
879 void AliDisplay::SetZoomMode()
882 // Set Zoom Mode -- disable pick
886 fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
887 fTrigPad->Modified();
890 //_____________________________________________________________________________
891 void AliDisplay::SetPTcut(Float_t ptcut)
903 //_____________________________________________________________________________
904 void AliDisplay::SetRange(Float_t rrange, Float_t zrange)
906 // Set view range along R and Z
915 //_____________________________________________________________________________
916 void AliDisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
918 // change viewing angles for current event
921 fDrawAllViews = kFALSE;
927 TView *view = gPad->GetView();
928 if (view) view->SetView(fPhi, fTheta, fPsi, iret);
934 //_____________________________________________________________________________
935 void AliDisplay::ShowNextEvent(Int_t delta)
937 // Display (current event_number+delta)
938 // delta = 1 shown next event
939 // delta = -1 show previous event
943 //Int_t currentEvent = gAlice->GetHeader()->GetEvent();//event number is not filled correctly
944 Int_t currentEvent = gAlice->GetRunLoader()->GetEventNumber();
945 Int_t newEvent = currentEvent + delta;
946 gAlice->GetEvent(newEvent);
947 cout<<"AliDisplay::ShowNextEvent: delta = "<<delta
948 <<" currentEvent = "<<currentEvent
949 <<" newEvent = "<<newEvent<<endl;
956 //______________________________________________________________________________
957 void AliDisplay::UnZoom()
962 if (fZooms <= 0) return;
964 TPad *pad = dynamic_cast<TPad*>(gPad->GetPadSave());
965 pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);
969 //_____________________________________________________________________________
970 AliDisplay & AliDisplay::operator=(const AliDisplay &disp)
973 // Assignment operator