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