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