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