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"
50 const Float_t AliDisplay::fgkPtCutMax = 2;
51 const Float_t AliDisplay::fgkEtaCutMax = 1.5;
52 const Int_t AliDisplay::fgkMaxZooms = 20;
58 //_______________________________________________________________________
59 AliDisplay::AliDisplay():
89 // Default constructor
93 //_____________________________________________________________________________
94 AliDisplay::AliDisplay(Int_t size):
96 fDrawAllViews(kFALSE),
97 fDrawParticles(kTRUE),
123 // Create an event display object.
124 // A canvas named "edisplay" is created with a vertical size in pixels
126 // A QUICK Overview of the Event Display functions
127 // ===============================================
129 // The event display can ve invoked by executing the macro "display.C"
130 // A canvas like in the picture below will appear.
132 // On the left side of the canvas, the following buttons appear:
133 // *Next* to move to the next event
134 // *Previous* to move to the previous event
135 // *Top View* to display a top view of the current event
136 // *Side View* to display a side view of the current event
137 // *Front View* to display a front view of the current event
138 // *All Views* to display front/side/top/30-30 views of the current event
139 // *OpenGL* to use OpenGl to view the current event.
140 // Note that OpenGL cannot be used across the network.
141 // Before using OpenGL, load the GL libraries
142 // by executing the macro GL.C (in $ROOTSYS/macros/GL.C.
143 // Once in GL, click the HELP button of the GL canvas.
144 // *X3D* to use X3D to view the current event (Unix only).
145 // Once in X3D, type M to see the list of all possible options.
146 // for example type J to zoom, K to unzoom
147 // use the mouse to rotate.
148 // *Pick* Select this option to be able to point on a track with the
149 // mouse. Once on the track, use the right button to select
150 // an action. For example, select SetMarkerAttributes to
151 // change the marker type/color/size for the track.
152 // *Zoom* Select this option (default) if you want to zoom.
153 // To zoom, simply select the selected area with the left button.
154 // *UnZoom* To revert to the previous picture size.
156 // slider R On the left side, the vertical slider can be used to
157 // set the default picture size.
158 // slider pcut At the top of the canvas, a slider can be used to change
159 // the momentum cut (or range) to display tracks.
160 // slider eta On the right side of the canvas, a vertical slider can be used
161 // to specify a rapidity range for the tracks.
163 // When you are in Zoom mode, you can click on the black part of the canvas
164 // to select special options with the right mouse button.
165 // This will display a pop-up menu with items like:
166 // *Disable detector*
167 // *Enable detector*, etc.
168 // For example select "Disable detector". You get a dialog box.
169 // Diable detector TRD for example.
171 // When you are in pick mode, you can "Inspect" the object pointed by the mouse.
172 // When you are on a track, select the menu item "InspectParticle"
173 // to display the current particle attributes.
175 // You can activate the Root browser by selecting the Inspect menu
176 // in the canvas tool bar menu. Then select "Start Browser"
177 // This will open a new canvas with the browser. At this point, you may want
178 // to display some histograms (from the Trees). Go to the "File" menu
179 // of the browser and click on "New canvas".
180 // In the browser, click on item "ROOT files" in the left pane.
181 // Click on galice.root.
183 // Click on TPC for example
184 // Click on any variable (eg TPC.fX) to histogram the variable.
186 // If you are lost, you can click on HELP in any Root canvas or browser.
189 <img src="picts/alidisplay.gif">
193 gAlice->SetDisplay(this);
195 // Initialize display default parameters
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);
225 fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
226 fRangeSlider->SetObject(this);
227 char pickmode[] = "gAlice->Display()->SetPickMode()";
229 fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
230 fPickButton->SetFillColor(38);
232 char zoommode[] = "gAlice->Display()->SetZoomMode()";
233 fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
234 fZoomButton->SetFillColor(38);
236 fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
237 fArcButton->SetFillColor(kGreen);
239 char butUnzoom[] = "gAlice->Display()->UnZoom()";
240 TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
241 button->SetFillColor(38);
243 AppendPad(); // append display object as last object to force selection
244 // Create momentum cut slider pad
246 fCutPad = new TPad("cutSlider", "pcut slider pad",dxtr,.96,1,1);
249 fCutPad->SetFillColor(22);
250 fCutPad->SetBorderSize(2);
251 fCutSlider = new TSlider("pcut","Momentum cut",0,0,1,1);
252 fCutSlider->SetRange(fPTcut/fgkPtCutMax,1);
253 fCutSlider->SetObject(this);
254 fCutSlider->SetFillColor(45);
255 TSliderBox *sbox = dynamic_cast<TSliderBox*>(fCutSlider->GetListOfPrimitives()->First());
256 sbox->SetFillColor(46);
258 TGaxis *cutaxis = new TGaxis(0.02,0.8,0.98,0.8,0,fgkPtCutMax,510,"");
259 cutaxis->SetLabelSize(0.5);
260 cutaxis->SetTitleSize(0.6);
261 cutaxis->SetTitleOffset(0.5);
262 cutaxis->SetTitle("pcut . ");
263 fCutSlider->GetListOfPrimitives()->AddFirst(cutaxis);
264 // Create rapidity cut slider pad
266 fEtaPad = new TPad("EtaSlider", "Eta slider pad",0.97,0,1,0.96);
269 fEtaPad->SetFillColor(22);
270 fEtaPad->SetBorderSize(2);
271 fEtaSlider = new TSlider("etacut","Rapidity cut",0,0,1,1);
272 fEtaSlider->SetObject(this);
273 fEtaSlider->SetFillColor(45);
274 TSliderBox *sbox2 = dynamic_cast<TSliderBox*>(fEtaSlider->GetListOfPrimitives()->First());
275 sbox2->SetFillColor(46);
277 TGaxis *etaaxis = new TGaxis(0.9,0.02,0.9,0.98,-fgkEtaCutMax,fgkEtaCutMax,510,"");
278 etaaxis->SetLabelSize(0.5);
279 etaaxis->SetTitleSize(0.6);
280 etaaxis->SetTitleOffset(0.2);
281 cutaxis->SetTitle("Etacut . ");
282 fEtaSlider->GetListOfPrimitives()->AddFirst(etaaxis);
285 fTrigPad->SetEditable(kFALSE);
286 fButtons->SetEditable(kFALSE);
288 fNTracksToDisplay =0;
295 //_______________________________________________________________________
296 AliDisplay::AliDisplay(const AliDisplay &disp):
332 //_____________________________________________________________________________
333 AliDisplay::~AliDisplay()
340 //_____________________________________________________________________________
341 void AliDisplay::Clear(Option_t *)
343 // Delete graphics temporary objects
346 //_____________________________________________________________________________
347 void AliDisplay::Copy(TObject &) const
350 // Copy *this onto disp -- not implemented
352 Fatal("Copy","Not implemented~\n");
355 //----------------------------------------------------------------------------
356 void AliDisplay::ShowTrack(Int_t idx)
361 AliDetector *mTPC=dynamic_cast<AliDetector*>(gAlice->GetModule("TPC"));
362 TObjArray *points=mTPC->Points();
363 int ntracks=points->GetEntriesFast();
364 for (int track=0;track<ntracks;track++) {
365 AliPoints *pm = dynamic_cast<AliPoints*>(points->UncheckedAt(track));
367 if (idx == pm->GetIndex()) {
368 pm->SetMarkerColor(2);
369 pm->SetMarkerStyle(22);
373 // TClonesArray *particles=gAlice->Particles();
374 // TParticle *p = (TParticle*)particles->UncheckedAt(idx);
375 TParticle *p = gAlice->GetMCApp()->Particle(idx);
376 printf("\nTrack index %d\n",idx);
377 printf("Particle ID %d\n",p->GetPdgCode());
378 printf("Parent %d\n",p->GetFirstMother());
379 printf("First child %d\n",p->GetFirstDaughter());
380 printf("Px,Py,Pz %f %f %f\n",p->Px(),p->Py(),p->Pz());
386 //----------------------------------------------------------------------------
387 void AliDisplay::HideTrack(Int_t idx) const
390 // Hide track on display
392 AliDetector *mTPC=dynamic_cast<AliDetector*>(gAlice->GetModule("TPC"));
393 TObjArray *points=mTPC->Points();
394 int ntracks=points->GetEntriesFast();
395 for (int track=0;track<ntracks;track++) {
396 AliPoints *pm = dynamic_cast<AliPoints*>(points->UncheckedAt(track));
398 if (idx == pm->GetIndex()) {
399 pm->SetMarkerColor(5);
400 pm->SetMarkerStyle(1);
409 //_____________________________________________________________________________
410 void AliDisplay::DisableDetector(const char *name)
412 // Disable detector name from graphics views
414 AliModule *module = dynamic_cast<AliModule*>(gAlice->Modules()->FindObject(name));
420 //_____________________________________________________________________________
421 void AliDisplay::DisplayButtons()
423 // Create the user interface buttons
425 fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
427 fButtons->SetFillColor(38);
428 fButtons->SetBorderSize(2);
432 Float_t dbutton = 0.08;
439 char but1[] = "gAlice->Display()->ShowNextEvent(1)";
440 button = new TButton("Next",but1,x0,y-dbutton,x1,y);
441 button->SetFillColor(38);
445 char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
446 button = new TButton("Previous",but2,x0,y-dbutton,x1,y);
447 button->SetFillColor(38);
451 char but3[] = "gAlice->Display()->SetView(90,-90,90)";
452 button = new TButton("Top View",but3,x0,y-dbutton,x1,y);
453 button->SetFillColor(butcolor);
457 char but4[] = "gAlice->Display()->SetView(90,0,-90)";
458 button = new TButton("Side View",but4,x0,y-dbutton,x1,y);
459 button->SetFillColor(butcolor);
463 char but5[] = "gAlice->Display()->SetView(0,-90,0)";
464 button = new TButton("Front View",but5,x0,y-dbutton,x1,y);
465 button->SetFillColor(butcolor);
469 char but6[] = "gAlice->Display()->DrawAllViews()";
470 button = new TButton("All Views",but6,x0,y-dbutton,x1,y);
471 button->SetFillColor(butcolor);
475 char but7[] = "gAlice->Display()->DrawViewGL()";
476 button = new TButton("OpenGL",but7,x0,y-dbutton,x1,y);
477 button->SetFillColor(38);
481 char but8[] = "gAlice->Display()->DrawViewX3D()";
482 button = new TButton("X3D",but8,x0,y-dbutton,x1,y);
483 button->SetFillColor(38);
487 TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
488 diamond->SetFillColor(50);
489 diamond->SetTextAlign(22);
490 diamond->SetTextColor(5);
491 diamond->SetTextSize(0.11);
493 diamond->AddText(".. ");
494 diamond->AddText("ROOT");
495 diamond->AddText("ALICE");
496 diamond->AddText("... ");
497 diamond->AddText(" ");
500 //______________________________________________________________________________
501 Int_t AliDisplay::DistancetoPrimitive(Int_t px, Int_t)
503 // Compute distance from point px,py to objects in event
505 gPad->SetCursor(kCross);
507 if (gPad == fTrigPad) return 9999;
508 if (gPad == fCutPad) return 9999;
509 if (gPad == fEtaPad) return 9999;
511 const Int_t kbig = 9999;
513 Float_t xmin = gPad->GetX1();
514 Float_t xmax = gPad->GetX2();
515 Float_t dx = 0.02*(xmax - xmin);
516 Float_t x = gPad->AbsPixeltoX(px);
517 if (x < xmin+dx || x > xmax-dx) return dist;
519 if (fZoomMode) return 0;
523 //_____________________________________________________________________________
524 void AliDisplay::Draw(Option_t *)
526 // Display current event
535 DrawView(fTheta, fPhi, fPsi);
537 // Display the event number and title
542 //_____________________________________________________________________________
543 void AliDisplay::DrawAllViews()
545 // Draw front,top,side and 30 deg views
547 fDrawAllViews = kTRUE;
549 fPad->SetFillColor(15);
565 DrawView(90, -90, 90);
570 DrawView(90, 0, -90);
576 //_____________________________________________________________________________
577 void AliDisplay::DrawHits()
579 // Draw hits for all ALICE detectors
581 Float_t cutmin, cutmax, etamin, etamax, pmom, smin, smax, eta, theta, r;
589 smax = fCutSlider->GetMaximum();
590 smin = fCutSlider->GetMinimum();
591 cutmin = fgkPtCutMax*smin;
592 if (smax < 0.98) cutmax = fgkPtCutMax*smax;
593 else cutmax = 100000;
596 smax = fEtaSlider->GetMaximum();
597 smin = fEtaSlider->GetMinimum();
598 etamin = fgkEtaCutMax*(2*smin-1);
599 etamax = fgkEtaCutMax*(2*smax-1);
600 if (smin < 0.02) etamin = -1000;
601 if (smax > 0.98) etamax = 1000;
603 TIter next(gAlice->Modules());
606 while((module = dynamic_cast<AliModule*>(next()))) {
607 if (!module->IsActive()) continue;
608 points = module->Points();
609 if (!points) continue;
610 ntracks = points->GetEntriesFast();
611 for (track=0;track<ntracks;track++) {
612 pm = dynamic_cast<AliPoints*>(points->UncheckedAt(track));
614 particle = pm->GetParticle();
615 if (!particle) continue;
616 pmom = particle->P();
617 if (pmom < cutmin) continue;
618 if (pmom > cutmax) continue;
619 // as a first approximation, take eta of first point
621 r = TMath::Sqrt(pxyz[0]*pxyz[0] + pxyz[1]*pxyz[1]);
622 theta = TMath::ATan2(r,TMath::Abs(pxyz[2]));
623 if(theta) eta = -TMath::Log(TMath::Abs(TMath::Tan(0.5*theta))); else eta = 1e10;
624 if (pxyz[2] < 0) eta = -eta;
625 if (eta < etamin || eta > etamax) continue;
627 fHitsCuts += pm->GetN();
632 //_____________________________________________________________________________
633 void AliDisplay::DrawTitle(Option_t *option)
635 // Draw the event title
637 Float_t xmin = gPad->GetX1();
638 Float_t xmax = gPad->GetX2();
639 Float_t ymin = gPad->GetY1();
640 Float_t ymax = gPad->GetY2();
641 Float_t dx = xmax-xmin;
642 Float_t dy = ymax-ymin;
644 if (strlen(option) == 0) {
645 TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
646 title->SetBit(kCanDelete);
647 title->SetFillColor(42);
650 sprintf(ptitle,"Alice event: %d, Run:%d",gAlice->GetHeader()->GetEvent(), gAlice->GetHeader()->GetRun());
651 title->AddText(ptitle);
652 Int_t nparticles = gAlice->GetMCApp()->Particles()->GetEntriesFast();
653 sprintf(ptitle,"Nparticles = %d Nhits = %d",nparticles, fHitsCuts);
654 title->AddText(ptitle);
656 TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
657 label->SetBit(kCanDelete);
658 label->SetFillColor(42);
663 //_____________________________________________________________________________
664 void AliDisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
666 // Draw a view of ALICE
668 gPad->SetCursor(kWatch);
669 gPad->SetFillColor(1);
673 TView *view = new TView(1);
674 Float_t range = fRrange*fRangeSlider->GetMaximum();
675 view->SetRange(-range,-range,-range,range, range, range);
682 // Display Alice Geometry
683 gAlice->GetGeometry()->Draw("same");
685 //Loop on all detectors to add their products to the pad
688 // add itself to the list (must be last)
691 view->SetView(phi, theta, psi, iret);
694 //_____________________________________________________________________________
695 void AliDisplay::DrawViewGL()
697 // Draw current view using OPENGL
699 TPad *pad = dynamic_cast<TPad*>(gPad->GetPadSave());
701 TView *view = pad->GetView();
706 //_____________________________________________________________________________
707 void AliDisplay::DrawViewX3D()
709 // Draw current view using X3D
711 TPad *pad = dynamic_cast<TPad*>(gPad->GetPadSave());
713 TView *view = pad->GetView();
718 //_____________________________________________________________________________
719 void AliDisplay::EnableDetector(const char *name)
721 // Enable detector name in graphics views
723 AliModule *module = dynamic_cast<AliModule*>(gAlice->Modules()->FindObject(name));
729 //______________________________________________________________________________
730 void AliDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
732 // Execute action corresponding to the mouse event
734 static Float_t x0, y0, x1, y1;
736 static Int_t pxold, pyold;
737 static Int_t px0, py0;
738 static Int_t linedrawn;
741 if (px == 0 && py == 0) { //when called by sliders
742 if (event == kButton1Up) {
747 if (!fZoomMode && gPad->GetView()) {
748 gPad->GetView()->ExecuteRotateView(event, px, py);
752 // something to zoom ?
753 // fPad->SetCursor(kCross);
754 gPad->SetCursor(kCross);
759 gVirtualX->SetLineColor(-1);
760 gPad->TAttLine::Modify(); //Change line attributes only if necessary
761 x0 = gPad->AbsPixeltoX(px);
762 y0 = gPad->AbsPixeltoY(py);
764 pxold = px; pyold = py;
769 if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
773 gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
777 gPad->GetCanvas()->FeedbackMode(kFALSE);
778 if (px == px0) return;
779 if (py == py0) return;
780 x1 = gPad->AbsPixeltoX(px);
781 y1 = gPad->AbsPixeltoY(py);
783 if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
784 if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
785 gPad->Range(x0,y0,x1,y1);
786 if (fZooms < fgkMaxZooms-1) {
788 fZoomX0[fZooms] = x0;
789 fZoomY0[fZooms] = y0;
790 fZoomX1[fZooms] = x1;
791 fZoomY1[fZooms] = y1;
793 gPad->Modified(kTRUE);
800 void AliDisplay::SetTracksToDisplay(Int_t *tracks, Int_t n){
802 // set tracks to display - MI
803 fTracksToDisplay = tracks;
804 fNTracksToDisplay = n;
806 //___________________________________________
807 void AliDisplay::LoadPoints()
809 // Read hits info and store x,y,z info in arrays fPoints
810 // Loop on all detectors
812 gAlice->ResetPoints();
813 TIter next(gAlice->Modules());
815 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
817 while((module = (AliModule*)next()))
819 AliDetector* detector = dynamic_cast<AliDetector*>(module);
820 if(detector) detector->SetTreeAddress();
824 // load only wanted tracks
825 if (fNTracksToDisplay>0)
827 Int_t nprim = gAlice->Stack()->GetNprimary();
828 for (Int_t track=0; track<fNTracksToDisplay;track++)
831 Int_t nev = nprim-1-gAlice->GetMCApp()->GetPrimary(fTracksToDisplay[track]);
832 while((module = (AliModule*)next()))
834 AliDetector* detector = dynamic_cast<AliDetector*>(module);
837 detector->TreeH()->GetEvent(nev);
838 module->LoadPoints(nprim-1-gAlice->GetMCApp()->GetPrimary(fTracksToDisplay[track]));
847 for (Int_t track=0; track<ntracks;track++) {
849 while((module = (AliModule*)next())) {
850 AliDetector* detector = dynamic_cast<AliDetector*>(module);
853 if (detector->TreeH()->GetEvent(track))
854 detector->LoadPoints(track);
862 //_____________________________________________________________________________
863 void AliDisplay::Paint(Option_t *)
865 // Paint miscellaneous items
869 //_____________________________________________________________________________
870 void AliDisplay::SetPickMode()
873 // Set Pick Mode -- disable zoom
877 fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
878 fTrigPad->Modified();
881 //_____________________________________________________________________________
882 void AliDisplay::SetZoomMode()
885 // Set Zoom Mode -- disable pick
889 fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
890 fTrigPad->Modified();
893 //_____________________________________________________________________________
894 void AliDisplay::SetPTcut(Float_t ptcut)
906 //_____________________________________________________________________________
907 void AliDisplay::SetRange(Float_t rrange, Float_t zrange)
909 // Set view range along R and Z
918 //_____________________________________________________________________________
919 void AliDisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
921 // change viewing angles for current event
924 fDrawAllViews = kFALSE;
930 TView *view = gPad->GetView();
931 if (view) view->SetView(fPhi, fTheta, fPsi, iret);
937 //_____________________________________________________________________________
938 void AliDisplay::ShowNextEvent(Int_t delta)
940 // Display (current event_number+delta)
941 // delta = 1 shown next event
942 // delta = -1 show previous event
946 //Int_t currentEvent = gAlice->GetHeader()->GetEvent();//event number is not filled correctly
947 Int_t currentEvent = gAlice->GetRunLoader()->GetEventNumber();
948 Int_t newEvent = currentEvent + delta;
949 gAlice->GetEvent(newEvent);
950 cout<<"AliDisplay::ShowNextEvent: delta = "<<delta
951 <<" currentEvent = "<<currentEvent
952 <<" newEvent = "<<newEvent<<endl;
959 //______________________________________________________________________________
960 void AliDisplay::UnZoom()
965 if (fZooms <= 0) return;
967 TPad *pad = dynamic_cast<TPad*>(gPad->GetPadSave());
968 pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);
972 //_____________________________________________________________________________
973 AliDisplay & AliDisplay::operator=(const AliDisplay &disp)
976 // Assignment operator