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