]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RICH/AliRICHDisplay.cxx
Adopt to const declaration of some of the methods in AliSegmentation.
[u/mrichter/AliRoot.git] / RICH / AliRICHDisplay.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 /*
17   $Log$
18   Revision 1.7  2000/10/02 21:28:12  fca
19   Removal of useless dependecies via forward declarations
20
21   Revision 1.6  2000/10/02 15:46:38  jbarbosa
22   Fixed forward declarations.
23
24   Revision 1.5  2000/06/30 16:49:34  dibari
25   Different call for ring drawing.
26
27   Revision 1.4  2000/06/12 15:21:08  jbarbosa
28   Cleaned up version.
29
30   Revision 1.3  2000/06/09 14:52:08  jbarbosa
31   New tentative ellipse drawing routine
32
33   Revision 1.1  2000/04/19 13:07:45  morsch
34   Digits, clusters and reconstruction results added.
35
36 */
37
38
39 //////////////////////////////////////////////////////////////////////////
40 //                                                                      //
41 // AliDisplay                                                           //
42 //                                                                      //
43 // Utility class to display ALICE outline, tracks, hits,..              //
44 //                                                                      //
45 //////////////////////////////////////////////////////////////////////////
46
47 #include <TROOT.h>
48 #include <TTree.h>
49 #include <TButton.h>
50 #include <TColor.h>
51 #include <TCanvas.h>
52 #include <TView.h>
53 #include <TText.h>
54 #include <TPolyMarker3D.h>
55 #include <TAtt3D.h>
56 #include <TAttLine.h>
57 #include <TPolyMarker.h>
58 #include <TPaveLabel.h>
59 #include <TPaveText.h>
60 #include <TList.h>
61 #include <TDiamond.h>
62 #include <TNode.h>
63 #include <TArc.h>
64 #include <TTUBE.h>
65 #include <TSlider.h>
66 #include <TGeometry.h>
67 #include <TSliderBox.h>
68 #include <TGaxis.h>
69 #include <TVirtualX.h>
70 #include <TMath.h>
71 #include <TRandom.h>
72 #include <X3DBuffer.h>
73 #include <TParticle.h>
74
75 #include "AliRun.h"
76 #include "AliPDG.h"
77 #include "AliDetector.h"
78 #include "AliRICH.h"
79 #include "AliRICHConst.h"
80 #include "AliRICHDisplay.h"
81 #include "AliRICHPoints.h"
82
83 #include "AliRICHHit.h"
84 #include "AliRICHCerenkov.h"
85 #include "AliRICHPadHit.h"
86 #include "AliRICHDigit.h"
87 #include "AliRICHRawCluster.h"
88 #include "AliRICHRecHit.h"
89 #include "AliRICHEllipse.h"
90
91 ClassImp(AliRICHDisplay)
92     
93
94 //____________________________________________________________________________
95 AliRICHDisplay::AliRICHDisplay()
96
97
98 // default constructor
99
100     fPoints = 0;
101     fPhits = 0;
102     fPCerenkovs = 0;
103     fCanvas = 0;
104     fRpoints = 0;
105     fRecpoints = 0; 
106 }
107
108 //_____________________________________________________________________________
109 AliRICHDisplay::AliRICHDisplay(Int_t size)
110 {
111 // Create an event display object.
112 // A canvas named "edisplay" is created with a vertical size in pixels
113 //
114 //    A QUICK Overview of the Event Display functions
115 //    ===============================================
116 //
117 //  The event display can ve invoked by executing the macro "display.C"
118 // A canvas like in the picture below will appear.
119 //
120 //  On the left side of the canvas, the following buttons appear:
121 //   *Next*       to move to the next event
122 //   *Previous*   to move to the previous event
123
124 //   *Pick*       Select this option to be able to point on a track with the
125 //                mouse. Once on the track, use the right button to select
126 //                an action. For example, select SetMarkerAttributes to
127 //                change the marker type/color/size for the track.
128 //   *Zoom*       Select this option (default) if you want to zoom.
129 //                To zoom, simply select the selected area with the left button.
130 //   *UnZoom*     To revert to the previous picture size.
131 //
132 //   slider R     On the left side, the vertical slider can be used to
133 //                set the default picture size.
134 //
135 //    When you are in Zoom mode, you can click on the black part of the canvas
136 //  to select special options with the right mouse button.
137
138 //
139 //  When you are in pick mode, you can "Inspect" the object pointed by the mouse.
140 //  When you are on a track, select the menu item "InspectParticle"
141 //  to display the current particle attributes.
142 //
143 //  You can activate the Root browser by selecting the Inspect menu
144 //  in the canvas tool bar menu. Then select "Start Browser"
145 //  This will open a new canvas with the browser. At this point, you may want
146 //  to display some histograms (from the Trees). Go to the "File" menu
147 //  of the browser and click on "New canvas".
148 //  In the browser, click on item "ROOT files" in the left pane.
149 //  Click on galice.root.
150 //  Click on TH
151 //  Click on TPC for example
152 //  Click on any variable (eg TPC.fX) to histogram the variable.
153 //
154 //   If you are lost, you can click on HELP in any Root canvas or browser.
155 //Begin_Html
156 /*
157   <img src="gif/AliRICHDisplay.gif">
158 */
159 //End_Html
160     
161     
162     fPad = 0;
163     
164     gAlice->SetDisplay(this);
165     
166     // Initialize display default parameters
167     SetRange();
168     
169     // Set front view by default
170     fTheta = 90;
171     fPhi   = 90;
172     fPsi   = 0;
173     fChamber = 1;
174     fCathode = 1;
175     //   fRzone   = 1.e10;
176     fDrawClusters  = kTRUE;
177     fDrawCoG       = kTRUE;
178     fDrawRecHits   = kTRUE;
179     fZoomMode      = 1;
180     fZooms         = 0;
181     fClustersCuts  = 0;
182     fPoints        = 0;
183     fPCerenkovs    = 0;
184     fPhits         = 0;
185     fRpoints       = 0;   
186     fRecpoints       = 0;
187     // Create colors
188     CreateColors();
189     // Create display canvas
190     Int_t ysize = size;
191     if (ysize < 100) ysize = 750;
192     Int_t xsize = Int_t(size*830./ysize);
193     fCanvas = new TCanvas("Canvas", "RICH Clusters Display",14,47,xsize,ysize);
194     fCanvas->ToggleEventStatus();
195     
196     // Create main display pad
197     fPad = new TPad("viewpad", "RICH display",0.15,0,0.9,1);
198     fPad->Draw();
199     fPad->Modified();
200     fPad->SetFillColor(1);
201     fPad->SetBorderSize(2);
202     
203     fCanvas->cd();
204     
205     // Create colors pad
206     fColPad = new TPad("colpad", "Colors pad",0.9,0,1,1);
207     fColPad->Draw();
208     fColPad->Modified();
209     fColPad->SetFillColor(19);
210     fColPad->SetBorderSize(2);
211     fColPad->cd();
212     DisplayColorScale();
213     
214     fCanvas->cd();
215     
216     // Create user interface control pad
217     DisplayButtons();
218     fCanvas->cd();
219     
220     // Create Range and mode pad
221     Float_t dxtr     = 0.15;
222     Float_t dytr     = 0.45;
223     fTrigPad = new TPad("trigger", "range and mode pad",0,0,dxtr,dytr);
224     fTrigPad->SetEditable(kFALSE);
225     fTrigPad->Draw();
226     fTrigPad->cd();
227     fTrigPad->SetFillColor(22);
228     fTrigPad->SetBorderSize(2);
229     fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
230     fRangeSlider->SetObject(this);
231     char pickmode[] = "gAlice->Display()->SetPickMode()";
232     Float_t db = 0.09;
233     fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
234     fPickButton->SetFillColor(38);
235     fPickButton->Draw();
236     char zoommode[] = "gAlice->Display()->SetZoomMode()";
237     fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
238     fZoomButton->SetFillColor(38);
239     fZoomButton->Draw();
240     fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
241     fArcButton->SetFillColor(kGreen);
242     fArcButton->Draw();
243     char butUnzoom[] = "gAlice->Display()->UnZoom()";
244     TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
245     button->SetFillColor(38);
246     button->Draw();
247     AppendPad(); // append display object as last object to force selection
248     
249     fCanvas->cd();
250     fCanvas->Update();
251 }
252
253
254 //_____________________________________________________________________________
255 AliRICHDisplay::~AliRICHDisplay()
256 {
257     // Delete space point structure
258     if (fPoints) fPoints->Delete();
259     delete fPoints;
260     fPoints     = 0;
261     //
262     if (fPhits) fPhits->Delete();
263     delete fPhits;
264     fPhits     = 0;
265     //
266     if (fRpoints) fRpoints->Delete();
267     delete fRpoints;
268     fRpoints     = 0;
269     //
270     if (fRecpoints) fRecpoints->Delete();
271     delete fRecpoints;
272     fRecpoints     = 0;
273     //
274     if (fPCerenkovs) fPCerenkovs->Delete();
275     delete fPCerenkovs;
276     fPCerenkovs     = 0;
277 }
278
279 //_____________________________________________________________________________
280 void AliRICHDisplay::Clear(Option_t *)
281 {
282 //    Delete graphics temporary objects
283 }
284
285 //_____________________________________________________________________________
286 void AliRICHDisplay::DisplayButtons()
287 {
288 //    Create the user interface buttons
289     
290     
291     fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
292     fButtons->SetEditable(kFALSE);
293     fButtons->Draw();
294     fButtons->SetFillColor(38);
295     fButtons->SetBorderSize(2);
296     fButtons->cd();
297     
298     //   Int_t butcolor = 33;
299     Float_t dbutton = 0.08;
300     Float_t y  = 0.96;
301     Float_t dy = 0.014;
302     Float_t x0 = 0.05;
303     Float_t x1 = 0.95;
304     
305     TButton *button;
306     char but1[] = "gAlice->Display()->ShowNextEvent(1)";
307     button = new TButton("Next",but1,x0,y-dbutton,x1,y);
308     button->SetFillColor(38);
309     button->Draw();
310     
311     y -= dbutton +dy;
312     char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
313     button = new TButton("Previous",but2,x0,y-dbutton,x1,y);
314     button->SetFillColor(38);
315     button->Draw();
316
317     y -= dbutton +dy;
318     char but7[] = "gAlice->Display()->DrawViewGL()";
319     button = new TButton("OpenGL",but7,x0,y-dbutton,x1,y);
320     button->SetFillColor(38);
321     button->Draw();
322     
323     y -= dbutton +dy;
324     char but8[] = "gAlice->Display()->DrawViewX3D()";
325     button = new TButton("X3D",but8,x0,y-dbutton,x1,y);
326     button->SetFillColor(38);
327     button->Draw();
328     
329     // display logo
330     TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
331     diamond->SetFillColor(50);
332     diamond->SetTextAlign(22);
333     diamond->SetTextColor(5);
334     diamond->SetTextSize(0.11);
335     diamond->Draw();
336     diamond->AddText(".. ");
337     diamond->AddText("ROOT");
338     diamond->AddText("RICH");
339     diamond->AddText("... ");
340     diamond->AddText(" ");
341 }
342
343 //_____________________________________________________________________________
344 void AliRICHDisplay::CreateColors()
345 {
346 //    Create the colors palette used to display clusters
347     
348     Int_t k,i;
349     Int_t color;
350     Float_t r,g,b;
351     
352     for (k=1;k<=5;k++) {
353         switch(k) {
354         case 1:
355             for (i=1;i<=5;i++) {
356                 r=1.;
357                 g=i*0.2;  
358                 b=0.;
359                 color=i;
360                 color=700+23-color;
361                 new TColor(color,r,g,b);
362             } 
363             break;
364         case 2:
365             for (i=1;i<=4;i++) {
366                 r=1.1-i*0.2;
367                 g=1.;  
368                 b=0.;
369                 color=i+5;
370                 color=700+23-color;
371                 new TColor(color,r,g,b);
372             } 
373             break;
374     case 3:
375         for (i=1;i<=4;i++) {
376             r=0.;
377             g=1.;  
378             b=i*0.2+0.2;
379             color=i+9;
380             color=700+23-color;
381             new TColor(color,r,g,b);
382         } 
383         break;
384         case 4:
385             for (i=1;i<=4;i++) {
386                 r=0.;
387                 g=1.1-i*0.2;  
388                 b=1.;
389                 color=i+13;
390                 color=700+23-color;
391                 new TColor(color,r,g,b);
392             } 
393             break;
394         case 5:
395             for (i=1;i<=5;i++) {
396                 r=i*0.2;
397                 g=0.;  
398                 b=1.;
399                 color=i+17;
400                 color=700+23-color;
401                 new TColor(color,r,g,b);
402             } 
403             break;
404         }
405     }
406 }
407
408 //_____________________________________________________________________________
409 void AliRICHDisplay::DisplayColorScale()
410 {
411
412 // Draw the color scale in the RICH display canvas
413     
414     Int_t i;
415     Int_t color;
416     Float_t xlow, ylow, xup, yup, hs;
417     Float_t x1, y1, x2, y2;
418     x1 = y1 = 0;
419     x2 = y2 = 20;
420     
421     gPad->SetFillColor(0);
422     gPad->Clear();
423     gPad->Range(x1,y1,x2,y2);
424     TText *text = new TText(0,0,"");
425     text->SetTextFont(61);
426     text->SetTextSize(0.03);
427     text->SetTextAlign(22);
428     
429     TBox *box;
430     char label[8];
431 //*-* draw colortable boxes
432     hs = (y2-y1)/Float_t(22);
433     xlow=x1+1;
434     xup=x2-9;
435     for (i=0;i<22;i++) {
436         ylow = y1 + hs*(Float_t(i));
437         yup  = y1 + hs*(Float_t(i+1));
438         color = 701+i;
439         Double_t logscale=Double_t(i+1)*(TMath::Log(adc_satm)/22);
440         Int_t scale=(Int_t)TMath::Exp(logscale);
441         sprintf(label,"%d",scale);
442         box = new TBox(xlow, ylow, xup, yup);
443         box->SetFillColor(color);
444         box->Draw();
445         text->DrawText(xup+4, 0.5*(ylow+yup),label);
446     }
447 }
448
449 //______________________________________________________________________________
450 Int_t AliRICHDisplay::DistancetoPrimitive(Int_t px, Int_t)
451 {
452 // Compute distance from point px,py to objects in event
453     
454     gPad->SetCursor(kCross);
455     
456     if (gPad == fTrigPad) return 9999;
457     
458     const Int_t kBig = 9999;
459     Int_t dist   = kBig;
460     Float_t xmin = gPad->GetX1();
461     Float_t xmax = gPad->GetX2();
462     Float_t dx   = 0.02*(xmax - xmin);
463     Float_t x    = gPad->AbsPixeltoX(px);
464     if (x < xmin+dx || x > xmax-dx) return dist;
465     if (fZoomMode) return 0;
466     else           return 7;
467 }
468
469 //_____________________________________________________________________________
470 void AliRICHDisplay::Draw(Option_t *)
471 {
472 //    Display current event
473
474     fPad->cd();
475     
476     DrawView(fTheta, fPhi, fPsi);      // see how to draw PGON+inner frames
477     
478     // Display the event number and title
479     fPad->cd();
480     DrawTitle();
481 }
482
483 //_____________________________________________________________________________
484 void AliRICHDisplay::DrawCoG()
485 {
486 //    Draw hits for RICH chambers
487
488     if (!fDrawCoG) return;
489     ResetRpoints();
490     for (Int_t chamber=0;chamber<kNCH;chamber++) {
491         LoadCoG(chamber,1);
492     }
493     
494     Int_t ncog, icog;
495     TObjArray *points;
496     AliRICHPoints *pm;
497     points = fRpoints;
498     if (!points) return;
499     ncog = points->GetEntriesFast();
500     for (icog=0; icog < ncog; icog++) {
501         pm = (AliRICHPoints*)points->UncheckedAt(icog);
502         if (!pm) continue;
503         pm->Draw();
504     }
505 }
506
507 void AliRICHDisplay::DrawRecHits()
508 {
509 //    Draw rec hits for RICH chambers
510
511     if (!fDrawRecHits) return;
512     //ResetRecpoints();
513     for (Int_t chamber=0;chamber<kNCH;chamber++) {
514         LoadRecHits(chamber,1);
515     }
516     
517     Int_t nrec, irec;
518     TObjArray *points;
519     AliRICHPoints *pm;
520     points = fRecpoints;
521     if (!points) return;
522     nrec = points->GetEntriesFast();
523     printf("Nrec %d\n",nrec);
524     for (irec=0; irec < nrec; irec++) {
525         pm = (AliRICHPoints*)points->UncheckedAt(irec);
526         if (!pm) continue;
527         pm->Draw();
528     }
529 }
530
531 //_____________________________________________________________________________
532
533 void AliRICHDisplay::DrawCerenkovs()
534 {
535 //    Draw cerenkovs hits for RICH chambers
536     
537     LoadCerenkovs(fChamber);
538     //printf("\nDrawCerenkovs\n");
539     
540     Int_t ntracks, track;
541     TObjArray *cpoints;
542     AliRICHPoints *pm;
543     
544     fHitsCuts = 0;
545     cpoints = fPCerenkovs;
546     //printf ("Cpoints: %p",cpoints);
547     if (!cpoints) return;
548     ntracks = cpoints->GetEntriesFast();
549     //printf("DrawCerenkovs - ntracks %d \n",ntracks);
550     for (track=0;track<ntracks;track++) {
551         pm = (AliRICHPoints*)cpoints->UncheckedAt(track);
552         if (!pm) continue;
553         pm->Draw();
554         fHitsCuts += pm->GetN();
555     }
556 }
557
558 //_____________________________________________________________________________
559
560 void AliRICHDisplay::DrawClusters()
561 {
562 //    Draw clusterss for RICH chambers
563     
564     Int_t ndigits, digit;
565     TObjArray *points;
566     AliRICHPoints *pm;
567     
568     fClustersCuts = 0;
569     points = fPoints;
570     if (!points) return;
571     ndigits = points->GetEntriesFast();
572     for (digit=0;digit<ndigits;digit++){
573         pm = (AliRICHPoints*)points->UncheckedAt(digit);
574         if (!pm) continue;
575         pm->Draw();
576         Float_t *pxyz;
577         pxyz=pm->GetP();
578         for (Int_t im=0;im<3;im++) {
579             TMarker3DBox *marker=pm->GetMarker(im);
580             if (marker)
581                 marker->Draw();
582         }
583         fClustersCuts +=pm->GetN();
584     }
585 }
586
587 //_____________________________________________________________________________
588 void AliRICHDisplay::DrawHits()
589 {
590 //    Draw hits for RICH chambers
591     
592     LoadHits(fChamber);
593     
594     Int_t ntracks, track;
595     TObjArray *points;
596     AliRICHPoints *pm;
597     
598     fHitsCuts = 0;
599     points = Phits();
600     if (!fPhits) return;
601 //    ntracks = points->GetEntriesFast();
602     ntracks = fPhits->GetEntriesFast();
603     
604     //printf("DrawHits - ntracks %d \n",ntracks);
605     for (track=0;track<ntracks;track++) {
606         pm = (AliRICHPoints*)fPhits->UncheckedAt(track);
607         if (!pm) continue;
608         pm->Draw();
609         fHitsCuts += pm->GetN();
610     }
611 }
612
613
614 //_____________________________________________________________________________
615 void AliRICHDisplay::DrawTitle(Option_t *option)
616 {
617 //    Draw the event title
618     
619     Float_t xmin = gPad->GetX1();
620     Float_t xmax = gPad->GetX2();
621     Float_t ymin = gPad->GetY1();
622     Float_t ymax = gPad->GetY2();
623     Float_t dx   = xmax-xmin;
624     Float_t dy   = ymax-ymin;
625     
626     if (strlen(option) == 0) {
627         TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
628         title->SetBit(kCanDelete);
629         title->SetFillColor(42);
630         title->Draw();
631         char ptitle[100];
632         sprintf(ptitle,"Alice event: %d, Run:%d",
633                 gAlice->GetHeader()->GetEvent(), gAlice->GetHeader()->GetRun());
634         title->AddText(ptitle);
635         Int_t nparticles = gAlice->Particles()->GetEntriesFast();
636         sprintf(ptitle,"Nparticles = %d Nhits = %d Npads fired = %d",
637                 nparticles, fHitsCuts,fClustersCuts);
638         title->AddText(ptitle);
639     } else {
640         TPaveLabel *label = 
641             new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
642         label->SetBit(kCanDelete);
643         label->SetFillColor(42);
644         label->Draw();
645     }
646 }
647
648 //_____________________________________________________________________________
649 void AliRICHDisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
650 {
651 //    Draw a view of RICH clusters
652     
653    gPad->SetCursor(kWatch);
654    gPad->SetFillColor(1);
655    gPad->Clear();
656    
657    Int_t iret;
658    TView *view = new TView(1);
659    Float_t range = fRrange*fRangeSlider->GetMaximum();
660    view->SetRange(-range,-range,-range,range, range, range);
661    fZoomX0[0] = -1;
662    fZoomY0[0] = -1;
663    fZoomX1[0] =  1;
664    fZoomY1[0] =  1;
665    fZooms = 0;
666    
667    //Display RICH Chamber Geometry
668    gAlice->GetGeometry()->Draw("same");
669    
670    //add clusters to the pad
671    DrawClusters();
672    DrawHits();
673 //   DrawCerenkovs();
674    printf("Calling DrawCoG\n");
675    DrawCoG();
676    printf("Calling DrawRecHits\n");
677    DrawRecHits();
678    /*for (Int_t i=0;i<7;i++)
679      LoadRecHits(i,1);*/
680    
681    // add itself to the list (must be last)
682    AppendPad();
683    
684    view->SetView(phi, theta, psi, iret);
685 }
686
687 //______________________________________________________________________________
688 void AliRICHDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
689 {
690 //  Execute action corresponding to the mouse event
691     
692     static Float_t x0, y0, x1, y1;
693     
694    static Int_t pxold, pyold;
695    static Int_t px0, py0;
696    static Int_t linedrawn;
697    Float_t temp;
698    
699    if (px == 0 && py == 0) { //when called by sliders
700        if (event == kButton1Up) {
701            Draw();
702        }
703        return;
704    }
705    if (!fZoomMode && gPad->GetView()) {
706        gPad->GetView()->ExecuteRotateView(event, px, py);
707        return;
708    }
709
710    // something to zoom ?
711    gPad->SetCursor(kCross);
712    
713    switch (event) {
714        
715    case kButton1Down:
716        gVirtualX->SetLineColor(-1);
717        gPad->TAttLine::Modify();  //Change line attributes only if necessary
718        x0 = gPad->AbsPixeltoX(px);
719        y0 = gPad->AbsPixeltoY(py);
720        px0   = px; py0   = py;
721        pxold = px; pyold = py;
722        linedrawn = 0;
723        return;
724        
725    case kButton1Motion:
726        if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
727        pxold = px;
728        pyold = py;
729        linedrawn = 1;
730        gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
731        return;
732        
733    case kButton1Up:
734        gPad->GetCanvas()->FeedbackMode(kFALSE);
735        if (px == px0) return;
736        if (py == py0) return;
737        x1 = gPad->AbsPixeltoX(px);
738        y1 = gPad->AbsPixeltoY(py);
739        
740        if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
741        if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
742        gPad->Range(x0,y0,x1,y1);
743        if (fZooms < kMAXZOOM-1) {
744            fZooms++;
745            fZoomX0[fZooms] = x0;
746            fZoomY0[fZooms] = y0;
747            fZoomX1[fZooms] = x1;
748            fZoomY1[fZooms] = y1;
749        }
750        gPad->Modified(kTRUE);
751        return;
752    }
753    
754 }
755 //___________________________________________
756 void AliRICHDisplay::LoadCoG(Int_t chamber, Int_t cathode)
757 {
758 // Read raw clusters info and store x,y,z info in arrays fRpoints
759 // Loop on all detectors
760
761    if (chamber > 6) return;
762
763    printf("Entering LoadCoG\n");
764
765
766    AliRICH *pRICH  = (AliRICH*)gAlice->GetModule("RICH");
767    AliRICHChamber*  iChamber;
768
769    TClonesArray *pRICHrawclust  = pRICH->RawClustAddress(chamber);
770    printf ("Chamber:%d has adress:%p\n", chamber, pRICHrawclust );
771    if (pRICHrawclust == 0) return;
772
773    pRICH->ResetRawClusters();
774
775
776    Int_t nent=(Int_t)gAlice->TreeR()->GetEntries();
777    gAlice->TreeR()->GetEvent(nent-1+cathode-1);
778    Int_t nrawcl = pRICHrawclust->GetEntriesFast();
779    printf ("nrawcl:%d\n",nrawcl);
780    if (nrawcl == 0) return;
781    if (fRpoints == 0) fRpoints = new TObjArray(nrawcl);
782    
783    iChamber = &(pRICH->Chamber(chamber));
784    AliRICHRawCluster  *mRaw;
785    AliRICHPoints *points = 0;
786    //
787    //loop over all raw clusters and store their position
788    points = new AliRICHPoints(nrawcl);
789    for (Int_t iraw=0;iraw<nrawcl;iraw++) {
790        mRaw   = (AliRICHRawCluster*)pRICHrawclust->UncheckedAt(iraw);
791        fRpoints->AddAt(points,iraw);
792        points->SetMarkerColor(3);
793        points->SetMarkerStyle(3);
794        points->SetMarkerSize(1.);
795        points->SetParticle(-1);
796        points->SetHitIndex(-1);
797        points->SetTrackIndex(-1);
798        points->SetDigitIndex(-1);
799        Float_t  vectorLoc[3]={mRaw->fX,6.276,mRaw->fY};
800        Float_t  vectorGlob[3];
801        iChamber->LocaltoGlobal(vectorLoc,vectorGlob);
802        points->SetPoint(iraw,vectorGlob[0],vectorGlob[1],vectorGlob[2]);
803    }
804 }
805 //___________________________________________
806 void AliRICHDisplay::LoadRecHits(Int_t chamber, Int_t cathode)
807 {
808 // Read rec. hits info 
809 // Loop on all detectors
810
811    if (chamber > 6) return;
812
813    printf("Entering LoadRecHits\n");
814
815
816    AliRICH *pRICH  = (AliRICH*)gAlice->GetModule("RICH");
817    AliRICHChamber*  iChamber;
818
819    TClonesArray *pRICHrechits  = pRICH->RecHitsAddress(chamber);
820    printf ("Chamber:%d\n", chamber);
821    if (pRICHrechits == 0) return;
822
823    //RICH->ResetRecHits();
824
825
826    Int_t nent=(Int_t)gAlice->TreeR()->GetEntries();
827    gAlice->TreeR()->GetEvent(nent-1+cathode-1);
828    Int_t nrechits = pRICHrechits->GetEntriesFast();
829    printf ("nrechits:%d\n",nrechits);
830    if (nrechits == 0) return;
831    if (fRecpoints == 0) fRecpoints = new TObjArray(50);
832    
833    iChamber = &(pRICH->Chamber(chamber));
834    AliRICHRecHit  *mRec;
835    AliRICHPoints *points = 0;
836    //AliRICHEllipse *ellipse = 0;
837    //
838    //loop over all rechits and store their position  
839
840    points = new AliRICHPoints(nrechits);
841    for (Int_t irec=0;irec<nrechits;irec++) {
842        mRec   = (AliRICHRecHit*)pRICHrechits->UncheckedAt(irec);
843        fRecpoints->AddAt(points,irec);
844        points->SetMarkerColor(38);
845        points->SetMarkerStyle(8);
846        points->SetMarkerSize(1.);
847        points->SetParticle(-1);
848        points->SetHitIndex(-1);
849        points->SetTrackIndex(-1);
850        points->SetDigitIndex(-1);
851        Float_t  vectorLoc[3]={mRec->fX,6.276,mRec->fY};
852        Float_t  vectorGlob[3];
853        iChamber->LocaltoGlobal(vectorLoc,vectorGlob);
854        points->SetPoint(irec,vectorGlob[0],vectorGlob[1],vectorGlob[2]);
855        //Float_t theta = iChamber->GetRotMatrix()->GetTheta();
856        //Float_t phi   = iChamber->GetRotMatrix()->GetPhi();       
857        //ellipse=new TEllipse(vectorGlob[0],vectorGlob[2],10,10,0,360,phi);
858        printf("Generating ellipse %d\n",irec);
859        AliRICHEllipse *ellipse=new AliRICHEllipse(mRec->fX,mRec->fY,mRec->fOmega,mRec->fTheta,mRec->fPhi,mRec->fEmissPoint);
860        ellipse->CerenkovRingDrawing(chamber,irec);
861        //ellipse->SetFillStyle(1001);
862        ellipse->SetMarkerColor(38);
863        ellipse->Draw();
864        //marker->SetRefObject((TObject*)points);
865        //points->Set3DMarker(0, marker); 
866    }
867 }
868 //___________________________________________
869 void AliRICHDisplay::LoadDigits()
870 {
871 // Read digits info and store x,y,z info in arrays fPoints
872 // Loop on all detectors
873     
874    ResetPoints();
875    AliRICH *pRICH  = (AliRICH*)gAlice->GetDetector("RICH");
876    AliRICHChamber*       iChamber;
877    AliSegmentation*      segmentation;
878    Int_t nAllDigits=0;
879    Int_t ich;
880    
881    for (ich=0; ich<kNCH; ich++) {
882        TClonesArray *pRICHdigits  = pRICH->DigitsAddress(ich);
883        if (pRICHdigits == 0) continue;
884        gAlice->ResetDigits();
885        gAlice->TreeD()->GetEvent(1);
886        Int_t ndigits = pRICHdigits->GetEntriesFast();
887         nAllDigits+=ndigits;
888    }
889    if (fPoints == 0) fPoints = new TObjArray(nAllDigits);   
890    Int_t counter=0;
891    for (ich=0; ich<kNCH; ich++) {
892        TClonesArray *pRICHdigits  = pRICH->DigitsAddress(ich);
893        if (pRICHdigits == 0) continue;
894        gAlice->ResetDigits();
895        gAlice->TreeD()->GetEvent(1);
896        Int_t ndigits = pRICHdigits->GetEntriesFast();
897        if (ndigits == 0) continue;
898        iChamber = &(pRICH->Chamber(ich));
899        segmentation=iChamber->GetSegmentationModel();
900        Float_t dpx  = segmentation->Dpx();
901        Float_t dpy  = segmentation->Dpy();
902
903        //printf("Dpx:%d, Dpy:%d\n",dpx,dpy);
904        
905        AliRICHDigit  *mdig;
906        AliRICHPoints *points = 0;
907        TMarker3DBox  *marker = 0;
908        //
909        //loop over all digits and store their position
910        Int_t npoints=1;
911        
912        for (Int_t digit=0;digit<ndigits;digit++) {
913            mdig    = (AliRICHDigit*)pRICHdigits->UncheckedAt(digit);
914            points = new AliRICHPoints(npoints);
915            fPoints->AddAt(points,counter);
916            counter++;
917            Int_t charge=mdig->fSignal;
918            Int_t index=Int_t(TMath::Log(charge)/(TMath::Log(adc_satm)/22));
919            Int_t color=701+index;
920            if (color>722) color=722;
921            points->SetMarkerColor(color);
922            points->SetMarkerStyle(21);
923            points->SetMarkerSize(0.5);
924            Float_t xpad, ypad, zpad;
925            segmentation->GetPadC(mdig->fPadX, mdig->fPadY,xpad, ypad, zpad);
926            Float_t vectorLoc[3]={xpad,6.276,ypad};
927            Float_t  vectorGlob[3];
928            iChamber->LocaltoGlobal(vectorLoc,vectorGlob);
929            points->SetParticle(-1);
930            points->SetHitIndex(-1);
931            points->SetTrackIndex(-1);
932            points->SetDigitIndex(digit);
933            points->SetPoint(0,vectorGlob[0],vectorGlob[1],vectorGlob[2]);
934            
935            segmentation->GetPadC(mdig->fPadX, mdig->fPadY, xpad, ypad, zpad);
936            Float_t theta = iChamber->GetRotMatrix()->GetTheta();
937            Float_t phi   = iChamber->GetRotMatrix()->GetPhi();     
938            marker=new TMarker3DBox(vectorGlob[0],vectorGlob[1],vectorGlob[2],
939                                    dpy/2,0,dpx/2,theta,phi);
940            marker->SetLineColor(2);
941            marker->SetFillStyle(1001);
942            marker->SetFillColor(color);
943            marker->SetRefObject((TObject*)points);
944            points->Set3DMarker(0, marker);
945        } // loop over digits
946    } // loop over chambers 
947 }
948
949
950 //___________________________________________
951 void AliRICHDisplay::LoadHits(Int_t chamber)
952 {
953 // Read hits info and store x,y,z info in arrays fPhits
954 // Loop on all detectors
955     
956     
957     fChamber=chamber; 
958     ResetPhits();
959     
960     AliRICH *pRICH  = (AliRICH*)gAlice->GetDetector("RICH");
961     AliRICHChamber*  iChamber;
962     
963     iChamber = &(pRICH->Chamber(chamber-1));
964     Int_t ntracks = (Int_t)gAlice->TreeH()->GetEntries();
965     Int_t track;
966     
967     if (fPhits == 0) fPhits = new TObjArray(ntracks);
968     //TVector *xp = new TVector(1000);
969     //TVector *yp = new TVector(1000);
970     //TVector *zp = new TVector(1000);
971     //TVector *ptrk = new TVector(1000);
972     //TVector *phit = new TVector(1000);
973     Int_t nAllHits=0;
974     for (track=0; track<ntracks;track++) {
975         gAlice->ResetHits();
976         gAlice->TreeH()->GetEvent(track);
977         TClonesArray *pRICHhits  = pRICH->Hits();
978         if (pRICHhits == 0) return;
979         Int_t nhits = pRICHhits->GetEntriesFast();
980         nAllHits+=nhits;
981     }
982
983     fPhits = new TObjArray(nAllHits);
984
985     Int_t npoints=0;
986     for (track=0; track<ntracks;track++) {
987         gAlice->ResetHits();
988         gAlice->TreeH()->GetEvent(track);
989         TClonesArray *pRICHhits  = pRICH->Hits();
990         if (pRICHhits == 0) return;
991         Int_t nhits = pRICHhits->GetEntriesFast();
992         if (nhits == 0) continue;
993         AliRICHHit *mHit;
994         AliRICHPoints *points = 0;
995         for (Int_t hit=0;hit<nhits;hit++) {
996             points = new AliRICHPoints(1);
997             fPhits->AddAt(points,npoints);
998             mHit = (AliRICHHit*)pRICHhits->UncheckedAt(hit);
999             TParticle *current = 
1000                 (TParticle*)(*gAlice->Particles())[mHit->Track()];
1001             if (current->GetPdgCode() == 50000050) {
1002                 points->SetMarkerColor(kBlue);
1003             } else if (current->GetPdgCode() == 50000051) {
1004                 points->SetMarkerColor(kYellow);
1005             } else {
1006                 points->SetMarkerColor(kRed);
1007             }
1008             points->SetMarkerStyle(5);
1009             points->SetMarkerSize(1.);
1010             points->SetParticle(mHit->Track());
1011             points->SetHitIndex(hit);
1012             points->SetTrackIndex(track);
1013             points->SetDigitIndex(-1);
1014             points->SetPoint(hit,mHit->X(), mHit->Y(), mHit->Z());
1015             npoints++;
1016         }
1017     }
1018 }
1019
1020 //_____________________________________________________________________________
1021
1022 void AliRICHDisplay::LoadCerenkovs(Int_t chamber)
1023 {
1024 // Read cerenkov hits info and store x,y,z info in array fPCerenkovs
1025 // Loop on all detectors
1026     
1027     fChamber=chamber; 
1028     ResetPCerenkovs();
1029     
1030     AliRICH *pRICH  = (AliRICH*)gAlice->GetDetector("RICH");
1031     AliRICHChamber*  iChamber;
1032     
1033     iChamber = &(pRICH->Chamber(chamber-1));
1034     
1035     pRICH->SetTreeAddress();
1036     Int_t ntracks = (Int_t)gAlice->TreeH()->GetEntries();
1037     
1038     if (fPCerenkovs == 0) fPCerenkovs = new TObjArray(ntracks);
1039     TVector *xp = new TVector(1000);
1040     TVector *yp = new TVector(1000);
1041     TVector *zp = new TVector(1000);
1042     TVector *ptrk = new TVector(1000);
1043     TVector *phit = new TVector(1000);
1044     for (Int_t track=0; track<ntracks;track++) {
1045         gAlice->ResetHits();
1046         gAlice->TreeH()->GetEvent(track);
1047         TClonesArray *pRICHCerenkovs  = pRICH->Cerenkovs();
1048         if (pRICHCerenkovs == 0) return;
1049         Int_t nhits = pRICHCerenkovs->GetEntriesFast();
1050         if (nhits == 0) continue;
1051         AliRICHCerenkov *mCerenkov;
1052         AliRICHPoints *cpoints = 0;
1053         Int_t npoints=0;
1054         
1055         
1056 //Display Cerenkov hits in blue
1057         
1058         for (Int_t hit=0;hit<nhits;hit++) {
1059             mCerenkov = (AliRICHCerenkov*)pRICHCerenkovs->UncheckedAt(hit);
1060             (*xp)(npoints)=mCerenkov->X();
1061             (*yp)(npoints)=mCerenkov->Y();
1062             (*zp)(npoints)=mCerenkov->Z();
1063             (*ptrk)(npoints)=Float_t(mCerenkov->GetTrack());
1064             (*phit)(npoints)=Float_t(hit);
1065             npoints++;
1066         }
1067         if (npoints == 0) continue;
1068         cpoints = new AliRICHPoints(npoints);
1069         for (Int_t p=0;p<npoints;p++) {
1070             cpoints->SetMarkerColor(kBlue);
1071             cpoints->SetMarkerStyle(5);
1072             cpoints->SetMarkerSize(1.);
1073             cpoints->SetParticle(Int_t((*ptrk)(p)));
1074             cpoints->SetHitIndex(Int_t((*phit)(p)));
1075             cpoints->SetTrackIndex(track);
1076             cpoints->SetDigitIndex(-1);
1077             cpoints->SetPoint(p,(*xp)(p),(*yp)(p),(*zp)(p));
1078         }
1079         xp->Zero();
1080         yp->Zero();
1081         ptrk->Zero();
1082         phit->Zero();
1083         fPCerenkovs->AddAt(cpoints,track);
1084     }
1085 }
1086
1087 //_____________________________________________________________________________
1088 void AliRICHDisplay::Paint(Option_t *)
1089 {
1090 //    Paint miscellaneous items
1091
1092 }
1093
1094 //_____________________________________________________________________________
1095 void AliRICHDisplay::SetPickMode()
1096 {
1097
1098 // Toggle pick mode
1099
1100     fZoomMode = 0;
1101     
1102     fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
1103     fTrigPad->Modified();
1104 }
1105
1106 //_____________________________________________________________________________
1107 void AliRICHDisplay::SetZoomMode()
1108 {
1109
1110 // Toggle Zoom mode
1111
1112     fZoomMode = 1;
1113     
1114     fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
1115     fTrigPad->Modified();
1116 }
1117
1118 //_____________________________________________________________________________
1119 void AliRICHDisplay::SetChamberAndCathode(Int_t chamber, Int_t cathode)
1120 {
1121 // Set chamber and cathode number
1122     fChamber = chamber;
1123     fCathode = cathode;
1124     
1125     printf("SetChamberAndCathode - fChamber fCathode %d %d\n",fChamber,fCathode);
1126     if (!fPad) return;
1127     fPad->Clear();
1128     LoadDigits();
1129     Draw();
1130 }
1131
1132 //_____________________________________________________________________________
1133 void AliRICHDisplay::SetRange(Float_t rrange, Float_t zrange)
1134 {
1135 // Set view range along R and Z
1136     fRrange = rrange;
1137     fZrange = zrange;
1138     
1139    if (!fPad) return;
1140    fPad->Clear();
1141    Draw();
1142 }
1143
1144 //_____________________________________________________________________________
1145 void AliRICHDisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
1146 {
1147 //  change viewing angles for current event
1148     
1149     fPad->cd();
1150     fPhi   = phi;
1151     fTheta = theta;
1152     fPsi   = psi;
1153     Int_t iret = 0;
1154     
1155     TView *view = gPad->GetView();
1156     if (view) view->SetView(fPhi, fTheta, fPsi, iret);
1157     else      Draw();
1158     
1159     gPad->Modified();
1160 }
1161
1162 //_____________________________________________________________________________
1163 void AliRICHDisplay::ShowNextEvent(Int_t delta)
1164 {
1165 //  Display (current event_number+delta)
1166 //    delta =  1  shown next event
1167 //    delta = -1 show previous event
1168     
1169     if (delta) {
1170         gAlice->Clear();
1171         Int_t currentEvent = gAlice->GetHeader()->GetEvent();
1172         Int_t newEvent     = currentEvent + delta;
1173         gAlice->GetEvent(newEvent);
1174         if (!gAlice->TreeD()) return; 
1175     }
1176     LoadDigits();
1177     DrawClusters();
1178     fPad->cd(); 
1179     Draw();
1180
1181   
1182 }
1183
1184 //______________________________________________________________________________
1185 void AliRICHDisplay::UnZoom()
1186 {
1187
1188 // Return to previous zoom factor
1189
1190     if (fZooms <= 0) return;
1191     fZooms--;
1192     TPad *pad = (TPad*)gPad->GetPadSave();
1193     pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);
1194     pad->Modified();
1195 }
1196
1197 //_____________________________________________________________________________
1198 void AliRICHDisplay::ResetPoints()
1199 {
1200     //
1201     // Reset array of points
1202     //
1203     if (fPoints) {
1204         fPoints->Delete();
1205         delete fPoints;
1206         fPoints = 0;
1207   }
1208 }
1209 //_____________________________________________________________________________
1210 void AliRICHDisplay::ResetRpoints()
1211 {
1212   //
1213   // Reset array of points
1214   //
1215   if (fRpoints) {
1216     fRpoints->Delete();
1217     delete fRpoints;
1218     fRpoints = 0;
1219   }
1220 }
1221 //_____________________________________________________________________________
1222 void AliRICHDisplay::ResetRecpoints()
1223 {
1224   //
1225   // Reset array of points
1226   //
1227   if (fRecpoints) {
1228     fRecpoints->Delete();
1229     delete fRecpoints;
1230     fRecpoints = 0;
1231   }
1232 }
1233 //_____________________________________________________________________________
1234 void AliRICHDisplay::ResetPhits()
1235 {
1236     //
1237     // Reset array of points
1238     //
1239     if (fPhits) {
1240         fPhits->Delete();
1241         delete fPhits;
1242         fPhits = 0;
1243     }
1244 }
1245 //_____________________________________________________________________________
1246 void AliRICHDisplay::ResetPCerenkovs()
1247 {
1248     //
1249     // Reset array of points
1250     //
1251     if (fPCerenkovs) {
1252         fPCerenkovs->Delete();
1253         delete fPCerenkovs;
1254         fPCerenkovs = 0;
1255     }
1256 }
1257
1258 //_____________________________________________________________________________
1259
1260 void AliRICHDisplay::DrawViewGL()
1261 {
1262 //    Draw current view using OPENGL
1263
1264    TPad *pad = (TPad*)gPad->GetPadSave();
1265    pad->cd();
1266    TView *view = pad->GetView();
1267    if (!view) return;
1268    pad->x3d("OPENGL");
1269 }
1270
1271 //_____________________________________________________________________________
1272 void AliRICHDisplay::DrawViewX3D()
1273 {
1274 //    Draw current view using X3D
1275
1276    TPad *pad = (TPad*)gPad->GetPadSave();
1277    pad->cd();
1278    TView *view = pad->GetView();
1279    if (!view) return;
1280    pad->x3d();
1281 }