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