2 //////////////////////////////////////////////////////////////////////////
6 // Utility class to display ALICE outline, tracks, hits,.. //
8 //////////////////////////////////////////////////////////////////////////
17 #include <TPolyMarker3D.h>
18 #include <TPolyMarker.h>
19 #include <TPaveLabel.h>
20 #include <TPaveText.h>
27 #include <TSliderBox.h>
31 #include <X3DBuffer.h>
34 #include "AliDetector.h"
36 #include "AliRICHConst.h"
37 #include "AliRICHdisplay.h"
38 #include "AliRICHpoints.h"
39 #include "TParticle.h"
42 ClassImp(AliRICHdisplay)
45 //____________________________________________________________________________
46 AliRICHdisplay::AliRICHdisplay()
54 //_____________________________________________________________________________
55 AliRICHdisplay::AliRICHdisplay(Int_t size)
57 // Create an event display object.
58 // A canvas named "edisplay" is created with a vertical size in pixels
60 // A QUICK Overview of the Event Display functions
61 // ===============================================
63 // The event display can ve invoked by executing the macro "display.C"
64 // A canvas like in the picture below will appear.
66 // On the left side of the canvas, the following buttons appear:
67 // *Next* to move to the next event
68 // *Previous* to move to the previous event
70 // *Pick* Select this option to be able to point on a track with the
71 // mouse. Once on the track, use the right button to select
72 // an action. For example, select SetMarkerAttributes to
73 // change the marker type/color/size for the track.
74 // *Zoom* Select this option (default) if you want to zoom.
75 // To zoom, simply select the selected area with the left button.
76 // *UnZoom* To revert to the previous picture size.
78 // slider R On the left side, the vertical slider can be used to
79 // set the default picture size.
81 // When you are in Zoom mode, you can click on the black part of the canvas
82 // to select special options with the right mouse button.
85 // When you are in pick mode, you can "Inspect" the object pointed by the mouse.
86 // When you are on a track, select the menu item "InspectParticle"
87 // to display the current particle attributes.
89 // You can activate the Root browser by selecting the Inspect menu
90 // in the canvas tool bar menu. Then select "Start Browser"
91 // This will open a new canvas with the browser. At this point, you may want
92 // to display some histograms (from the Trees). Go to the "File" menu
93 // of the browser and click on "New canvas".
94 // In the browser, click on item "ROOT files" in the left pane.
95 // Click on galice.root.
97 // Click on TPC for example
98 // Click on any variable (eg TPC.fX) to histogram the variable.
100 // If you are lost, you can click on HELP in any Root canvas or browser.
103 <img src="gif/aliRICHdisplay.gif">
110 gAlice->SetDisplay(this);
112 // Initialize display default parameters
115 // Set front view by default
122 fDrawClusters = kTRUE;
131 // Create display canvas
133 if (ysize < 100) ysize = 750;
134 Int_t xsize = Int_t(size*830./ysize);
135 fCanvas = new TCanvas("Canvas", "RICH Clusters Display",14,47,xsize,ysize);
136 fCanvas->SetEditable(kIsNotEditable);
137 fCanvas->ToggleEventStatus();
139 // Create main display pad
140 fPad = new TPad("viewpad", "RICH display",0.15,0,0.9,1);
143 fPad->SetFillColor(1);
144 fPad->SetBorderSize(2);
149 fColPad = new TPad("colpad", "Colors pad",0.9,0,1,1);
152 fColPad->SetFillColor(19);
153 fColPad->SetBorderSize(2);
159 // Create user interface control pad
163 // Create Range and mode pad
166 fTrigPad = new TPad("trigger", "range and mode pad",0,0,dxtr,dytr);
169 fTrigPad->SetFillColor(22);
170 fTrigPad->SetBorderSize(2);
171 fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
172 fRangeSlider->SetObject(this);
173 char pickmode[] = "gAlice->Display()->SetPickMode()";
175 fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
176 fPickButton->SetFillColor(38);
178 char zoommode[] = "gAlice->Display()->SetZoomMode()";
179 fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
180 fZoomButton->SetFillColor(38);
182 fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
183 fArcButton->SetFillColor(kGreen);
185 char butUnzoom[] = "gAlice->Display()->UnZoom()";
186 TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
187 button->SetFillColor(38);
189 AppendPad(); // append display object as last object to force selection
196 //_____________________________________________________________________________
197 AliRICHdisplay::~AliRICHdisplay()
199 // Delete space point structure
200 if (fPoints) fPoints->Delete();
204 if (fPhits) fPhits->Delete();
208 if (fPCerenkovs) fPCerenkovs->Delete();
213 //_____________________________________________________________________________
214 void AliRICHdisplay::Clear(Option_t *)
216 // Delete graphics temporary objects
219 //_____________________________________________________________________________
220 void AliRICHdisplay::DisplayButtons()
222 // Create the user interface buttons
225 fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
227 fButtons->SetFillColor(38);
228 fButtons->SetBorderSize(2);
231 // Int_t butcolor = 33;
232 Float_t dbutton = 0.08;
239 char but1[] = "gAlice->Display()->ShowNextEvent(1)";
240 button = new TButton("Next",but1,x0,y-dbutton,x1,y);
241 button->SetFillColor(38);
245 char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
246 button = new TButton("Previous",but2,x0,y-dbutton,x1,y);
247 button->SetFillColor(38);
251 TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
252 diamond->SetFillColor(50);
253 diamond->SetTextAlign(22);
254 diamond->SetTextColor(5);
255 diamond->SetTextSize(0.11);
257 diamond->AddText(".. ");
258 diamond->AddText("ROOT");
259 diamond->AddText("RICH");
260 diamond->AddText("... ");
261 diamond->AddText(" ");
264 //_____________________________________________________________________________
265 void AliRICHdisplay::CreateColors()
267 // Create the colors palette used to display clusters
282 new TColor(color,r,g,b);
292 new TColor(color,r,g,b);
302 new TColor(color,r,g,b);
312 new TColor(color,r,g,b);
322 new TColor(color,r,g,b);
331 //_____________________________________________________________________________
332 void AliRICHdisplay::DisplayColorScale()
337 Float_t xlow, ylow, xup, yup, hs;
338 Float_t x1, y1, x2, y2;
342 gPad->SetFillColor(0);
344 gPad->Range(x1,y1,x2,y2);
345 TText *text = new TText(0,0,"");
346 text->SetTextFont(61);
347 text->SetTextSize(0.03);
348 text->SetTextAlign(22);
352 //*-* draw colortable boxes
353 hs = (y2-y1)/Float_t(22);
357 ylow = y1 + hs*(Float_t(i));
358 yup = y1 + hs*(Float_t(i+1));
360 Double_t logscale=Double_t(i+1)*(TMath::Log(adc_satm)/22);
361 Int_t scale=(Int_t)TMath::Exp(logscale);
362 sprintf(label,"%d",scale);
363 box = new TBox(xlow, ylow, xup, yup);
364 box->SetFillColor(color);
366 text->DrawText(xup+4, 0.5*(ylow+yup),label);
370 //______________________________________________________________________________
371 Int_t AliRICHdisplay::DistancetoPrimitive(Int_t px, Int_t)
373 // Compute distance from point px,py to objects in event
375 gPad->SetCursor(kCross);
377 if (gPad == fTrigPad) return 9999;
379 const Int_t big = 9999;
381 Float_t xmin = gPad->GetX1();
382 Float_t xmax = gPad->GetX2();
383 Float_t dx = 0.02*(xmax - xmin);
384 Float_t x = gPad->AbsPixeltoX(px);
385 if (x < xmin+dx || x > xmax-dx) return dist;
387 if (fZoomMode) return 0;
391 //_____________________________________________________________________________
392 void AliRICHdisplay::Draw(Option_t *)
394 // Display current event
398 DrawView(fTheta, fPhi, fPsi); // see how to draw PGON+inner frames
400 // Display the event number and title
406 //_____________________________________________________________________________
408 void AliRICHdisplay::DrawCerenkovs()
410 // Draw cerenkovs hits for RICH chambers
412 LoadCerenkovs(fChamber);
413 printf("\nDrawCerenkovs\n");
415 Int_t ntracks, track;
420 cpoints = fPCerenkovs;
421 printf ("Cpoints: %p",cpoints);
422 if (!cpoints) return;
423 ntracks = cpoints->GetEntriesFast();
424 printf("DrawCerenkovs - ntracks %d \n",ntracks);
425 for (track=0;track<ntracks;track++) {
426 pm = (AliRICHpoints*)cpoints->UncheckedAt(track);
429 fHitsCuts += pm->GetN();
433 //_____________________________________________________________________________
434 void AliRICHdisplay::DrawClusters()
436 // Draw clusterss for RICH chambers
438 Int_t ndigits, digit;
445 ndigits = points->GetEntriesFast();
446 printf("DrawClusters - ndigits %d \n",ndigits);
447 for (digit=0;digit<ndigits;digit++){
448 pm = (AliRICHpoints*)points->UncheckedAt(digit);
451 fClustersCuts +=pm->GetN();
455 //_____________________________________________________________________________
456 void AliRICHdisplay::DrawHits()
458 // Draw hits for RICH chambers
462 Int_t ntracks, track;
469 ntracks = points->GetEntriesFast();
470 printf("DrawHits - ntracks %d \n",ntracks);
471 for (track=0;track<ntracks;track++) {
472 pm = (AliRICHpoints*)points->UncheckedAt(track);
475 fHitsCuts += pm->GetN();
480 //_____________________________________________________________________________
481 void AliRICHdisplay::DrawTitle(Option_t *option)
483 // Draw the event title
485 Float_t xmin = gPad->GetX1();
486 Float_t xmax = gPad->GetX2();
487 Float_t ymin = gPad->GetY1();
488 Float_t ymax = gPad->GetY2();
489 Float_t dx = xmax-xmin;
490 Float_t dy = ymax-ymin;
492 if (strlen(option) == 0) {
493 TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
494 title->SetBit(kCanDelete);
495 title->SetFillColor(42);
498 sprintf(ptitle,"Alice event: %d, Run:%d",gAlice->GetHeader()->GetEvent(), gAlice->GetHeader()->GetRun());
499 title->AddText(ptitle);
500 Int_t nparticles = gAlice->Particles()->GetEntriesFast();
501 sprintf(ptitle,"Nparticles = %d Nhits = %d Npads fired = %d",nparticles, fHitsCuts,fClustersCuts);
502 title->AddText(ptitle);
504 TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
505 label->SetBit(kCanDelete);
506 label->SetFillColor(42);
511 //_____________________________________________________________________________
512 void AliRICHdisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
514 // Draw a view of RICH clusters
516 gPad->SetCursor(kWatch);
517 gPad->SetFillColor(1);
521 TView *view = new TView(1);
522 Float_t range = fRrange*fRangeSlider->GetMaximum();
523 view->SetRange(-range,-range,-range,range, range, range);
530 //Display RICH Chamber Geometry
531 gAlice->GetGeometry()->Draw("same");
533 //add clusters to the pad
538 // add itself to the list (must be last)
541 view->SetView(phi, theta, psi, iret);
545 //______________________________________________________________________________
546 void AliRICHdisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
548 // Execute action corresponding to the mouse event
550 static Float_t x0, y0, x1, y1;
552 static Int_t pxold, pyold;
553 static Int_t px0, py0;
554 static Int_t linedrawn;
557 if (px == 0 && py == 0) { //when called by sliders
558 if (event == kButton1Up) {
563 if (!fZoomMode && gPad->GetView()) {
564 gPad->GetView()->ExecuteRotateView(event, px, py);
568 // something to zoom ?
569 gPad->SetCursor(kCross);
574 gGXW->SetLineColor(-1);
575 gPad->TAttLine::Modify(); //Change line attributes only if necessary
576 x0 = gPad->AbsPixeltoX(px);
577 y0 = gPad->AbsPixeltoY(py);
579 pxold = px; pyold = py;
584 if (linedrawn) gGXW->DrawBox(px0, py0, pxold, pyold, TGXW::kHollow);
588 gGXW->DrawBox(px0, py0, pxold, pyold, TGXW::kHollow);
592 gPad->GetCanvas()->FeedbackMode(kFALSE);
593 if (px == px0) return;
594 if (py == py0) return;
595 x1 = gPad->AbsPixeltoX(px);
596 y1 = gPad->AbsPixeltoY(py);
598 if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
599 if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
600 gPad->Range(x0,y0,x1,y1);
601 if (fZooms < kMAXZOOM-1) {
603 fZoomX0[fZooms] = x0;
604 fZoomY0[fZooms] = y0;
605 fZoomX1[fZooms] = x1;
606 fZoomY1[fZooms] = y1;
608 gPad->Modified(kTRUE);
614 //___________________________________________
615 void AliRICHdisplay::LoadDigits()
617 // Read digits info and store x,y,z info in arrays fPoints
618 // Loop on all detectors
622 printf("Entering Load-digits");
626 AliRICH *RICH = (AliRICH*)gAlice->GetDetector("RICH");
627 AliRICHchamber* iChamber;
628 AliRICHsegmentation* segmentation;
631 for (ich=0; ich<7; ich++) {
632 TClonesArray *RICHdigits = RICH->DigitsAddress(ich);
633 if (RICHdigits == 0) continue;
634 gAlice->ResetDigits();
635 gAlice->TreeD()->GetEvent(1);
636 Int_t ndigits = RICHdigits->GetEntriesFast();
637 printf("Found %d digits in chamber %d \n",ndigits,ich);
640 if (fPoints == 0) fPoints = new TObjArray(NallDigits);
642 for (ich=0; ich<7; ich++) {
643 TClonesArray *RICHdigits = RICH->DigitsAddress(ich);
644 if (RICHdigits == 0) continue;
645 gAlice->ResetDigits();
646 gAlice->TreeD()->GetEvent(1);
647 Int_t ndigits = RICHdigits->GetEntriesFast();
648 printf("Found %d digits in chamber %d \n",ndigits,ich);
649 if (ndigits == 0) continue;
653 iChamber = &(RICH->Chamber(ich));
654 printf("LoadPoints - chamber %d \n",ich);
655 segmentation=iChamber->GetSegmentationModel(1);
656 Float_t dpx = segmentation->Dpx();
657 Float_t dpy = segmentation->Dpy();
658 printf("LoadPoints - dpx, dpy %f %f \n",dpx,dpy);
660 AliRICHpoints *points = 0;
662 //loop over all digits and store their position
665 for (Int_t digit=0;digit<ndigits;digit++) {
666 mdig = (AliRICHdigit*)RICHdigits->UncheckedAt(digit);
667 points = new AliRICHpoints(npoints);
668 fPoints->AddAt(points,counter);
670 Int_t charge=mdig->fSignal;
671 Int_t index=Int_t(TMath::Log(charge)/(TMath::Log(adc_satm)/22));
672 Int_t color=51+index;
673 if (color>72) color=72;
674 points->SetMarkerColor(color);
675 points->SetMarkerStyle(21);
676 points->SetMarkerSize(0.5);
677 // get the center of the pad - add on x and y half of pad size
679 segmentation->GetPadCxy(mdig->fPadX, mdig->fPadY,xpad, ypad);
680 printf("\n chamber x,y, %d %f %f ", ich, xpad, ypad);
682 Float_t VecLoc[3]={xpad,0,ypad};
684 iChamber->LocaltoGlobal(VecLoc,VecGlob);
685 points->SetParticle(-1);
686 points->SetHitIndex(-1);
687 points->SetTrackIndex(-1);
688 points->SetDigitIndex(digit);
689 points->SetPoint(0,VecGlob[0],VecGlob[1],VecGlob[2]);
690 } // loop over digits
691 } // loop over chambers
695 //___________________________________________
696 void AliRICHdisplay::LoadHits(Int_t chamber)
698 // Read hits info and store x,y,z info in arrays fPhits
699 // Loop on all detectors
701 printf("Entering Load-hits");
706 AliRICH *RICH = (AliRICH*)gAlice->GetDetector("RICH");
707 AliRICHchamber* iChamber;
709 iChamber = &(RICH->Chamber(chamber-1));
710 Float_t zpos=iChamber->ZPosition();
711 printf("LoadHits - zpos %f \n",zpos);
713 Int_t ntracks = (Int_t)gAlice->TreeH()->GetEntries();
714 printf("ntracks %d\n",ntracks);
715 Int_t ntrks = gAlice->GetNtrack();
716 printf("ntrks %d\n",ntrks);
718 if (fPhits == 0) fPhits = new TObjArray(ntracks);
719 TVector *xp = new TVector(1000);
720 TVector *yp = new TVector(1000);
721 TVector *zp = new TVector(1000);
722 TVector *ptrk = new TVector(1000);
723 TVector *phit = new TVector(1000);
724 for (Int_t track=0; track<ntracks;track++) {
726 gAlice->TreeH()->GetEvent(track);
727 TClonesArray *RICHhits = RICH->Hits();
728 if (RICHhits == 0) return;
729 Int_t nhits = RICHhits->GetEntriesFast();
730 if (nhits == 0) continue;
732 AliRICHpoints *points = 0;
734 for (Int_t hit=0;hit<nhits;hit++) {
735 mHit = (AliRICHhit*)RICHhits->UncheckedAt(hit);
736 (*xp)(npoints)=mHit->fX;
737 (*yp)(npoints)=mHit->fY;
738 (*zp)(npoints)=mHit->fZ;
739 (*ptrk)(npoints)=Float_t(mHit->GetTrack());
740 (*phit)(npoints)=Float_t(hit);
744 if (npoints == 0) continue;
745 points = new AliRICHpoints(npoints);
746 for (Int_t p=0;p<npoints;p++) {
747 points->SetMarkerColor(kRed);
748 points->SetMarkerStyle(5);
749 points->SetMarkerSize(1.);
750 points->SetParticle(Int_t((*ptrk)(p)));
751 points->SetHitIndex(Int_t((*phit)(p)));
752 points->SetTrackIndex(track);
753 points->SetDigitIndex(-1);
754 points->SetPoint(p,(*xp)(p),(*yp)(p),(*zp)(p));
760 fPhits->AddAt(points,track);
765 //_____________________________________________________________________________
767 void AliRICHdisplay::LoadCerenkovs(Int_t chamber)
769 // Read cerenkov hits info and store x,y,z info in array fPCerenkovs
770 // Loop on all detectors
772 printf("Entering Load-Cerenkovs");
777 AliRICH *RICH = (AliRICH*)gAlice->GetDetector("RICH");
778 AliRICHchamber* iChamber;
780 iChamber = &(RICH->Chamber(chamber-1));
781 Float_t zpos=iChamber->ZPosition();
782 printf("LoadCerenkovs - zpos %f \n",zpos);
784 RICH->SetTreeAddress();
785 Int_t ntracks = (Int_t)gAlice->TreeH()->GetEntries();
786 printf("ntracks %d\n",ntracks);
787 Int_t ntrks = gAlice->GetNtrack();
788 printf("ntrks %d\n",ntrks);
790 if (fPCerenkovs == 0) fPCerenkovs = new TObjArray(ntracks);
791 TVector *xp = new TVector(1000);
792 TVector *yp = new TVector(1000);
793 TVector *zp = new TVector(1000);
794 TVector *ptrk = new TVector(1000);
795 TVector *phit = new TVector(1000);
796 for (Int_t track=0; track<ntracks;track++) {
798 gAlice->TreeH()->GetEvent(track);
799 TClonesArray *RICHCerenkovs = RICH->Cerenkovs();
800 printf("RICHCerenkovs %p\n",RICHCerenkovs);
801 if (RICHCerenkovs == 0) return;
802 Int_t nhits = RICHCerenkovs->GetEntriesFast();
803 if (nhits == 0) continue;
804 printf("nhits %d \n",nhits);
805 AliRICHCerenkov *mCerenkov;
806 AliRICHpoints *cpoints = 0;
809 //Display Cerenkov hits in blue
811 for (Int_t hit=0;hit<nhits;hit++) {
812 mCerenkov = (AliRICHCerenkov*)RICHCerenkovs->UncheckedAt(hit);
813 (*xp)(npoints)=mCerenkov->fX;
814 (*yp)(npoints)=mCerenkov->fY;
815 (*zp)(npoints)=mCerenkov->fZ;
816 (*ptrk)(npoints)=Float_t(mCerenkov->GetTrack());
817 (*phit)(npoints)=Float_t(hit);
818 printf("track, trk %d %d\n",track,mCerenkov->GetTrack());
821 if (npoints == 0) continue;
822 printf("npoints %d \n",npoints);
823 cpoints = new AliRICHpoints(npoints);
824 for (Int_t p=0;p<npoints;p++) {
825 cpoints->SetMarkerColor(kBlue);
826 cpoints->SetMarkerStyle(3);
827 cpoints->SetMarkerSize(1.);
828 cpoints->SetParticle(Int_t((*ptrk)(p)));
829 Int_t index=cpoints->GetIndex();
830 printf("index %d \n",index);
831 cpoints->SetHitIndex(Int_t((*phit)(p)));
832 cpoints->SetTrackIndex(track);
833 cpoints->SetDigitIndex(-1);
834 cpoints->SetPoint(p,(*xp)(p),(*yp)(p),(*zp)(p));
840 fPCerenkovs->AddAt(cpoints,track);
844 //_____________________________________________________________________________
845 void AliRICHdisplay::Paint(Option_t *)
847 // Paint miscellaneous items
851 //_____________________________________________________________________________
852 void AliRICHdisplay::SetPickMode()
856 fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
857 fTrigPad->Modified();
860 //_____________________________________________________________________________
861 void AliRICHdisplay::SetZoomMode()
865 fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
866 fTrigPad->Modified();
869 //_____________________________________________________________________________
870 void AliRICHdisplay::SetChamberAndCathode(Int_t chamber, Int_t cathode)
872 // Set chamber and cathode number
876 printf("SetChamberAndCathode - fChamber fCathode %d %d\n",fChamber,fCathode);
883 //_____________________________________________________________________________
884 void AliRICHdisplay::SetRange(Float_t rrange, Float_t zrange)
886 // Set view range along R and Z
895 //_____________________________________________________________________________
896 void AliRICHdisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
898 // change viewing angles for current event
906 TView *view = gPad->GetView();
907 if (view) view->SetView(fPhi, fTheta, fPsi, iret);
913 //_____________________________________________________________________________
914 void AliRICHdisplay::ShowNextEvent(Int_t delta)
916 // Display (current event_number+delta)
917 // delta = 1 shown next event
918 // delta = -1 show previous event
922 Int_t current_event = gAlice->GetHeader()->GetEvent();
923 Int_t new_event = current_event + delta;
924 gAlice->GetEvent(new_event);
925 if (!gAlice->TreeD()) return;
935 //______________________________________________________________________________
936 void AliRICHdisplay::UnZoom()
938 if (fZooms <= 0) return;
940 TPad *pad = (TPad*)gPad->GetPadSave();
941 pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);
945 //_____________________________________________________________________________
946 void AliRICHdisplay::ResetPoints()
949 // Reset array of points
957 //_____________________________________________________________________________
958 void AliRICHdisplay::ResetPhits()
961 // Reset array of points
969 //_____________________________________________________________________________
970 void AliRICHdisplay::ResetPCerenkovs()
973 // Reset array of points
976 fPCerenkovs->Delete();