]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDisplay.cxx
Drawing coarse slats and quadrants in the MUONdisplay (Christian, Gines)
[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 /* $Id$ */
17
18 //////////////////////////////////////////////////////////////////////////
19 //                                                                      //
20 // AliDisplay                                                           //
21 //                                                                      //
22 // Utility class to display ALICE outline, tracks, hits,..              //
23 //                                                                      //
24 //////////////////////////////////////////////////////////////////////////
25
26 #include <TButton.h>
27 #include <TColor.h>
28 #include <TCanvas.h>
29 #include <TView.h>
30 #include <TText.h>
31 #include <TPaveLabel.h>
32 #include <TPaveText.h>
33 #include <TDiamond.h>
34 #include <TNode.h>
35 #include <TArc.h>
36 #include <TSlider.h>
37 #include <TVirtualX.h>
38 #include <TMath.h>
39 #include <TGeometry.h>
40 #include <TMarker3DBox.h>
41 #include <TParticle.h>
42 #include <TPolyLine3D.h>
43 #include <TBox.h>
44
45 #include "AliMUONDisplay.h"
46 #include "AliRun.h"
47 #include "AliMUON.h"
48 #include "AliMUONPoints.h"
49 #include "AliMUONGlobalTrigger.h"
50 #include "AliHeader.h"
51
52 #include "AliMUONHit.h"
53 #include "AliMUONDigit.h"
54 #include "AliMUONRawCluster.h"
55 #include "AliMUONTrack.h"
56 #include "AliMUONTrackParam.h"
57
58 #include "AliMUONSegmentationManager.h"
59 #include "AliMUONGeometryModule.h"
60 #include "AliMpSlatSegmentation.h"
61 #include "AliMpSlat.h"
62  
63
64 #include "AliMUONGeometrySegmentation.h"
65 #include "AliMUONChamber.h"
66 #include "AliMUONConstants.h"
67 #include "AliMC.h"
68 #include "AliLog.h"
69 // to manage the same zoom on both cathodes
70
71
72
73 ClassImp(AliMUONDisplay)
74
75
76 //_____________________________________________________________________________
77 AliMUONDisplay::AliMUONDisplay()
78   : AliDisplay()
79 {
80 // Constructor
81     fPoints = 0;
82     fPhits = 0;
83     fRpoints = 0;
84     fCanvas = 0;
85     fNextCathode = kFALSE; 
86     fColPad = 0;
87 }
88
89 //_____________________________________________________________________________
90 AliMUONDisplay::AliMUONDisplay(Int_t size, AliLoader * loader)
91   : AliDisplay()
92 {
93 // Create an event display object.
94 // A canvas named "edisplay" is created with a vertical size in pixels
95 //
96 //    A QUICK Overview of the Event Display functions
97 //    ===============================================
98 //
99 //  The event display can ve invoked by executing the macro "display.C"
100 // A canvas like in the picture below will appear.
101 //
102 //  On the left side of the canvas, the following buttons appear:
103 //   *Next*       to move to the next event
104 //   *Previous*   to move to the previous event
105
106 //   *Pick*       Select this option to be able to point on a track with the
107 //                mouse. Once on the track, use the right button to select
108 //                an action. For example, select SetMarkerAttributes to
109 //                change the marker type/color/size for the track.
110 //   *Zoom*       Select this option (default) if you want to zoom.
111 //                To zoom, simply select the selected area with the left button.
112 //   *UnZoom*     To revert to the previous picture size.
113 //
114 //   slider R     On the left side, the vertical slider can be used to
115 //                set the default picture size.
116 //
117 //    When you are in Zoom mode, you can click on the black part of the canvas
118 //  to select special options with the right mouse button.
119
120 //
121 //  When you are in pick mode, you can "Inspect" the object pointed by the mouse.
122 //  When you are on a track, select the menu item "InspectParticle"
123 //  to display the current particle attributes.
124 //
125 //  You can activate the Root browser by selecting the Inspect menu
126 //  in the canvas tool bar menu. Then select "Start Browser"
127 //  This will open a new canvas with the browser. At this point, you may want
128 //  to display some histograms (from the Trees). Go to the "File" menu
129 //  of the browser and click on "New canvas".
130 //  In the browser, click on item "ROOT files" in the left pane.
131 //  Click on galice.root.
132 //  Click on TH
133 //  Click on TPC for example
134 //  Click on any variable (eg TPC.fX) to histogram the variable.
135 //
136 //   If you are lost, you can click on HELP in any Root canvas or browser.
137 //Begin_Html
138 /*
139 <img src="gif/AliMUONDisplay.gif">
140 */
141 //End_Html
142
143
144     fPad = 0;
145     
146     gAlice->SetDisplay(this);
147    
148    // Initialize display default parameters
149     SetRange(200,2000);
150    // Set front view by default
151     fTheta =   0;
152     fPhi   = -90;
153     fPsi   =   0;
154     fChamber = 1;
155     fCathode = 1;
156     //   fRzone   = 1.e10;
157     fDrawClusters  = kTRUE;
158     fDrawCoG       = kTRUE;
159     fDrawTracks    = kFALSE;
160     fZoomMode      = 1;
161     fZooms         = 0;
162     fClustersCuts  = 0;
163     fPoints        = 0;
164     fPhits         = 0;
165     fRpoints       = 0;
166     // Create colors
167     CreateColors();
168     // Create display canvas
169     Int_t ysize = size;
170     if (ysize < 100) ysize = 750;
171     Int_t xsize = Int_t(size*830./ysize);
172     fCanvas = new TCanvas("Canvas", "MUON Display",14,47,xsize,ysize);
173     fCanvas->ToggleEventStatus();
174     
175    // Create main display pad
176     fPad = new TPad("viewpad", "MUON display",0.15,0,0.9,1);
177     fPad->Draw();
178     fPad->Modified();
179     fPad->SetFillColor(30);
180     fPad->SetBorderSize(2);
181
182     fCanvas->cd();
183
184    // Create colors pad
185     fColPad = new TPad("colpad", "Colors pad",0.9,0,1,1);
186     fColPad->Draw();
187     fColPad->SetFillColor(17);
188     fColPad->SetBorderSize(2);
189     fColPad->cd();
190     DisplayColorScale();
191
192     fCanvas->cd();
193    // Create user interface control pad
194     DisplayButtons();
195     fCanvas->cd();
196
197    // Create Range and mode pad
198     Float_t dxtr     = 0.15;
199     Float_t dytr     = 0.45;
200     fTrigPad = new TPad("trigger", "range and mode pad",0,0,dxtr,dytr);
201     fTrigPad->Draw();
202     fTrigPad->cd();
203     fTrigPad->SetFillColor(22);
204     fTrigPad->SetBorderSize(2);
205     fRangeSlider = new TSlider("range","range",0.7,0.42,0.9,0.98);
206     fRangeSlider->SetObject(this);
207     char pickmode[] = "gAlice->Display()->SetPickMode()";
208     Float_t db = 0.09;
209     fPickButton = new TButton("Pick",pickmode,0.05,0.32,0.65,0.32+db);
210     fPickButton->SetFillColor(38);
211     fPickButton->Draw();
212     char zoommode[] = "gAlice->Display()->SetZoomMode()";
213     fZoomButton = new TButton("Zoom",zoommode,0.05,0.21,0.65,0.21+db);
214     fZoomButton->SetFillColor(38);
215     fZoomButton->Draw();
216     fArcButton = new TArc(.8,fZoomButton->GetYlowNDC()+0.5*db,0.33*db);
217     fArcButton->SetFillColor(kGreen);
218     fArcButton->Draw();
219     char butUnzoom[] = "gAlice->Display()->UnZoom()";
220     TButton *button = new TButton("UnZoom",butUnzoom,0.05,0.05,0.95,0.15);
221     button->SetFillColor(38);
222     button->Draw();
223     AppendPad(); // append display object as last object to force selection
224     
225     fCanvas->cd();
226     fTrigPad->SetEditable(kFALSE);
227     fButtons->SetEditable(kFALSE);
228     fCanvas->Update();
229     fNextCathode = kFALSE; 
230     fLoader = loader;
231     // initialize container
232     if(fLoader) 
233       fMUONData = new AliMUONData(fLoader,"MUON","MUON");
234     else
235       fMUONData =0x0;
236 }
237
238 AliMUONDisplay::AliMUONDisplay(const AliMUONDisplay & display)
239   : AliDisplay(display)
240 {
241 // Protected copy constructor
242
243   AliFatal("Not implemented.");
244 }
245
246
247
248 //_____________________________________________________________________________
249 AliMUONDisplay::~AliMUONDisplay()
250 {
251   // Delete space point structure
252     if (fPoints) fPoints->Delete();
253     delete fPoints;
254     fPoints     = 0;
255     //
256     if (fPhits) fPhits->Delete();
257     delete fPhits;
258     fPhits     = 0;
259     //
260     if (fRpoints) fRpoints->Delete();
261     delete fRpoints;
262     fRpoints     = 0;
263 }
264
265 //_____________________________________________________________________________
266 void AliMUONDisplay::Clear(Option_t *)
267 {
268 //    Delete graphics temporary objects
269 }
270
271 //_____________________________________________________________________________
272 void AliMUONDisplay::DisplayButtons()
273 {
274 //    Create the user interface buttons
275
276
277     fButtons = new TPad("buttons", "newpad",0,0.45,0.15,1);
278     fButtons->Draw();
279     fButtons->SetFillColor(38);
280     fButtons->SetBorderSize(2);
281     fButtons->cd();
282     
283 //   Int_t butcolor = 33;
284     Float_t dbutton = 0.08;
285     Float_t y  = 0.96;
286     Float_t dy = 0.014;
287     Float_t x0 = 0.05;
288     Float_t x1 = 0.95;
289     
290     TButton *button;
291     char but1[] = "gAlice->Display()->ShowNextEvent(1)";
292     button = new TButton("Event +", but1, x0, y - dbutton, x1, y);
293     button->SetFillColor(38);
294     button->Draw();
295     
296     y -= dbutton + dy;
297     char but2[] = "gAlice->Display()->ShowNextEvent(-1)";
298     button = new TButton("Event -", but2, x0, y - dbutton, x1, y);
299     button->SetFillColor(38);
300     button->Draw();
301    
302     y -= dbutton + dy;
303     char but3[] = "((AliMUONDisplay*)(gAlice->Display()))->NextChamber(1)";
304     button = new TButton("Chamber +", but3, x0, y - dbutton, x1, y);
305     button->SetFillColor(38);
306     button->Draw();
307     
308     y -= dbutton + dy;
309     char but4[] = "((AliMUONDisplay*)(gAlice->Display()))->NextChamber(-1)";
310     button = new TButton("Chamber -", but4, x0, y - dbutton, x1, y);
311     button->SetFillColor(38);
312     button->Draw();
313     
314     y -= dbutton + dy;
315     char but5[] = "((AliMUONDisplay*)(gAlice->Display()))->SetChamberAndCathode(1,1)";
316     button = new TButton("Chamber 1", but5, x0, y - dbutton, x1, y);
317     button->SetFillColor(38);
318     button->Draw();
319    
320     y -= dbutton + dy;
321     char but6[] = "((AliMUONDisplay*)(gAlice->Display()))->NextCathode()";
322     button = new TButton("Cathode <>", but6, x0, y - dbutton, x1, y);
323     button->SetFillColor(38);
324     button->Draw();
325
326     y -= dbutton + dy;
327     char but7[] = "((AliMUONDisplay*)(gAlice->Display()))->Trigger()";
328     button = new TButton("Trigger", but7, x0, y - dbutton, x1, y);
329     button->SetFillColor(38);
330     button->Draw();
331     
332     y -= dbutton + dy;
333     char but8[] = "((AliMUONDisplay*)(gAlice->Display()))->DrawReco()";
334     button = new TButton("Tracking", but8, x0, y - dbutton, x1, y);
335     button->SetFillColor(38);
336     button->Draw();
337
338    // display logo
339     TDiamond *diamond = new TDiamond(0.05,0.015,0.95,0.22);
340     diamond->SetFillColor(50);
341     diamond->SetTextAlign(22);
342     diamond->SetTextColor(5);
343     diamond->SetTextSize(0.11);
344     diamond->Draw();
345     diamond->AddText(".. ");
346     diamond->AddText("ROOT");
347     diamond->AddText("MUON");
348     diamond->AddText("... ");
349     diamond->AddText(" ");
350 }
351
352 //_____________________________________________________________________________
353 void AliMUONDisplay::CreateColors() const
354 {
355 //    Create the colors palette used to display clusters
356
357     Int_t k,i;
358     Int_t color;
359     Float_t r,g,b;
360     
361     for (k=1;k<=5;k++) {
362         switch(k) {
363         case 1:
364             for (i=1;i<=5;i++) {
365                 r=1.;
366                 g=i*0.2;  
367                 b=0.;
368                 color=i;
369                 color=260+23-color;
370                 new TColor(color,r,g,b);
371             } 
372             break;
373         case 2:
374             for (i=1;i<=4;i++) {
375                 r=1.1-i*0.2;
376                 g=1.;  
377                 b=0.;
378                 color=i+5;
379                 color=260+23-color;
380                 new TColor(color,r,g,b);
381             } 
382             break;
383         case 3:
384             for (i=1;i<=4;i++) {
385                 r=0.;
386                 g=1.;  
387                 b=i*0.2+0.2;
388                 color=i+9;
389                 color=260+23-color;
390                 new TColor(color,r,g,b);
391             } 
392             break;
393         case 4:
394             for (i=1;i<=4;i++) {
395                 r=0.;
396                 g=1.1-i*0.2;  
397                 b=1.;
398                 color=i+13;
399                 color=260+23-color;
400                 new TColor(color,r,g,b);
401             } 
402             break;
403         case 5:
404             for (i=1;i<=5;i++) {
405                 r=i*0.2;
406                 g=0.;  
407                 b=1.;
408                 color=i+17;
409                 color=260+23-color;
410                 new TColor(color,r,g,b);
411             } 
412             break;
413         }
414     }
415 }
416
417 //_____________________________________________________________________________
418 void AliMUONDisplay::DisplayColorScale()
419 {
420 // Display pulse height color scale
421     Int_t i;
422     Int_t color;
423     Float_t xlow, ylow, xup, yup, hs;
424     Float_t x1, y1, x2, y2;
425     x1 = y1 = 0;
426     x2 = y2 = 1.0;
427     
428     TText *text = new TText(0,0,"");
429     text->SetTextFont(61);
430     text->SetTextSize(0.2);
431     text->SetTextAlign(22);
432     
433
434     Int_t adcmax=4096; // default 12 bits ADC
435
436     
437
438     TBox *box;
439     char label[8];
440 //*-* draw colortable boxes
441     hs = (y2-y1)/Float_t(22);
442     xlow=x1+.05;
443     xup=x2-0.5;
444     for (i=0;i<22;i++) {
445         ylow = y1 + hs*(Float_t(i));
446         yup  = y1 + hs*(Float_t(i+1));
447         color = 261+i;
448         Double_t logscale=Double_t(i+1)*(TMath::Log(adcmax)/22);
449         Int_t scale=(Int_t)TMath::Exp(logscale);
450         sprintf(label,"%d",scale);
451         box = new TBox(xlow, ylow, xup, yup);
452         box->Draw();
453         box->SetFillColor(color);
454         text->DrawText(xlow+0.7, 0.5*(ylow+yup),label);
455     }
456 }
457
458 //______________________________________________________________________________
459 Int_t AliMUONDisplay::DistancetoPrimitive(Int_t px, Int_t)
460 {
461 // Compute distance from point px,py to objects in event
462
463     gPad->SetCursor(kCross);
464     
465     if (gPad == fTrigPad) return 9999;
466     
467     const Int_t kBig = 9999;
468     Int_t dist   = kBig;
469     Float_t xmin = gPad->GetX1();
470     Float_t xmax = gPad->GetX2();
471     Float_t dx   = 0.02*(xmax - xmin);
472     Float_t x    = gPad->AbsPixeltoX(px);
473     if (x < xmin+dx || x > xmax-dx) return dist;
474     
475     if (fZoomMode) return 0;
476     else           return 7;
477 }
478
479 //_____________________________________________________________________________
480 void AliMUONDisplay::Draw(Option_t *)
481 {
482 //    Display current event
483
484     if (!fDrawTracks) 
485       DrawChamber();   
486     else 
487       DrawReco();
488     
489 }
490 //_____________________________________________________________________________
491 void AliMUONDisplay::DrawChamber()
492 {
493
494   fDrawTracks = kFALSE;
495   fPad->cd();
496   DrawView(fTheta, fPhi, fPsi);   
497   // Display the event number and title
498   fPad->cd();
499   DrawTitle();
500  
501 }
502 //_____________________________________________________________________________
503 void AliMUONDisplay::DrawReco(Option_t *)
504 {
505 //    Display current event
506
507   fDrawTracks = kTRUE;
508   // print kinematics of generated particles
509     PrintKinematics();
510     // Draw global view of muon system
511     fPad->cd();
512     DrawGlobalView(135, -50, -140); 
513   
514     // Display the event number and title
515     fPad->cd();
516     DrawTitle();
517 }
518
519 //_____________________________________________________________________________
520 void AliMUONDisplay::PrintKinematics()
521 {
522   AliRunLoader * runLoader;
523   TParticle *particle = new TParticle();
524   Int_t nPart;
525   Float_t vertex[3], momentum[3];
526
527   if (fLoader)
528     runLoader = fLoader->GetRunLoader();
529   else
530     runLoader = 0x0;
531   
532   printf("******  Event # %d ******\n",runLoader->GetEventNumber());
533   runLoader->TreeK()->GetBranch("Particles")->SetAddress(&particle);
534   nPart = (Int_t)runLoader->TreeK()->GetEntries();
535   for(Int_t iPart = 0; iPart < nPart; iPart++) {
536     runLoader->TreeK()->GetEvent(iPart);
537     vertex[0] = particle->Vx();
538     vertex[1] = particle->Vy();
539     vertex[2] = particle->Vz();
540     momentum[0] = particle->Px();
541     momentum[1] = particle->Py();
542     momentum[2] = particle->Pz();
543     
544     printf("===================================================\n");
545     printf(" Generated particle # %d \n",iPart);
546     printf(" name: %s \n",particle->GetName());
547     printf(" vertex x,y,z (cm): %f %f %f \n",vertex[0],vertex[1],vertex[2]); 
548     printf(" momentum Px,Py,Pz (GeV/c): %f %f %f \n",momentum[0],momentum[1],momentum[2]);
549   }
550   delete particle;    
551 }
552
553 void AliMUONDisplay::DrawSegmentation()
554 {
555   // to be re-written for new seg
556 // Draw graphical representation of segmenatation
557 // Attention: still experimental code
558 //     Int_t icat=1;
559     
560 //     AliMUON *pMUON  = (AliMUON*)gAlice->GetModule("MUON");
561 //     AliMUONChamber*   iChamber;
562
563 //     AliSegmentation*  seg;
564 //     iChamber = &(pMUON->Chamber(fChamber));
565 //     seg=iChamber->SegmentationModel(icat);
566
567 //     Float_t zpos=iChamber->Z();
568 //     Float_t r=iChamber->ROuter();
569     
570 //     TMarker3DBox *marker;
571 //     if (icat == 1) {
572 //      for (Int_t j=0; j<seg->Npy(); j++) {
573 //          Float_t y0;
574 //          y0=j*seg->Dpy()-seg->Dpy()/2.;
575 //          for (seg->FirstPad(0.,y0,0,300,0.); 
576 //               seg->MorePads();
577 //               seg->NextPad())
578 //          {
579 //              if (seg->ISector()==0) continue;
580 //              Float_t x,y,z;
581 //              seg->GetPadC(seg->Ix(), seg->Iy(), x, y, z);
582 //              Float_t dpx=seg->Dpx(seg->ISector())/2;
583 //              Float_t dpy=seg->Dpy(seg->ISector())/2;
584 //              marker=new TMarker3DBox(x,y,zpos,dpx,dpy,0,0,0);
585 //              marker->SetLineColor(seg->ISector()+1);
586 //              marker->SetFillStyle(1001);
587 //              marker->SetFillColor(0);
588 //              marker->Draw();
589 //          }
590 //      }
591 //     } else {
592 //      for (Int_t j=0; j<250; j++) {
593 //          Float_t x0=j*seg->Dpx();
594 //          Float_t y0=TMath::Sqrt(r*r-x0*x0);
595             
596 //          for (seg->FirstPad(x0,0,0,0,y0); 
597 //               seg->MorePads();
598 //               seg->NextPad())
599 //          {
600 //              if (seg->ISector()==0) continue;
601                 
602 //              Float_t x,y,z;
603 //              seg->GetPadC(seg->Ix(), seg->Iy(), x, y, z);
604 //              Float_t dpx=seg->Dpx(seg->ISector())/2;
605 //              Float_t dpy=seg->Dpy(seg->ISector())/2;
606 //              marker=new TMarker3DBox(x,y,zpos,dpx,dpy,0,0,0);
607 //              marker->SetLineColor(seg->ISector()+1);
608 //              marker->SetFillStyle(1001);
609 //              marker->SetFillColor(0);
610 //              marker->Draw();
611 //          }
612 //      }
613 //     }
614  }
615
616 //_____________________________________________________________________________
617 void AliMUONDisplay::DrawClusters()
618 {
619 //    Draw clusters for MUON chambers
620
621     Int_t ndigits, digit;
622     TObjArray *points;
623     AliMUONPoints *pm;
624
625       
626     fClustersCuts = 0;
627     points = Points();
628     if (!points) return;
629     ndigits = points->GetEntriesFast();
630     for (digit=0;digit<ndigits;digit++){
631         pm = (AliMUONPoints*)points->UncheckedAt(digit);
632         if (!pm) continue;
633         Float_t *pxyz;
634         pxyz=pm->GetP();
635         for (Int_t im=0;im<3;im++) {
636             TMarker3DBox *marker=pm->GetMarker(im);
637             if (marker)
638                 marker->Draw();
639         }
640         pm->Draw();
641         fClustersCuts += pm->GetN();
642     }
643 }
644
645 //_____________________________________________________________________________
646 void AliMUONDisplay::DrawHits()
647 {
648 //    Draw hits for MUON chambers
649
650     LoadHits(fChamber);
651
652     Int_t ntracks, track;
653     TObjArray *points;
654     AliMUONPoints *pm;
655     
656     fHitsCuts = 0;
657     points = Phits();
658     if (!points) return;
659     ntracks = points->GetEntriesFast();
660     for (track=0;track<ntracks;track++) {
661         pm = (AliMUONPoints*)points->UncheckedAt(track);
662         if (!pm) continue;
663         pm->Draw();
664         fHitsCuts += pm->GetN();
665     }
666 }
667
668
669 //_____________________________________________________________________________
670 void AliMUONDisplay::DrawCoG()
671 {
672 //    Draw hits for MUON chambers
673     if (!fDrawCoG) return;
674     if (fChamber > 10) return;
675     LoadCoG(fChamber,fCathode);
676     
677     Int_t ncog, icog;
678     TObjArray *points;
679     AliMUONPoints *pm;
680
681     points = Rpoints();
682     if (!points) return;
683     ncog = points->GetEntriesFast();
684     for (icog=0;icog<ncog;icog++) {
685         pm = (AliMUONPoints*)points->UncheckedAt(icog);
686         if (!pm) continue;
687         pm->Draw();
688     }
689 }
690 //_____________________________________________________________________________
691 void AliMUONDisplay::DrawTracks()
692 {
693 //    Draw tracks
694     if (!fDrawTracks) return;
695     LoadTracks();
696     
697     Int_t nTrack, iTrack;
698     TObjArray *points;
699     TPolyLine3D *pm;
700
701     points = Rpoints();
702     if (!points) return;
703     nTrack = points->GetEntriesFast();
704     for ( iTrack = 0; iTrack < nTrack; iTrack++) {
705         pm = (TPolyLine3D*)points->UncheckedAt(iTrack);
706         if (!pm) continue;
707         pm->Draw();
708     }
709 }
710 //_____________________________________________________________________________
711
712 void AliMUONDisplay::DrawTitle(Option_t *option)
713 {
714 //    Draw the event title
715
716     Float_t xmin = gPad->GetX1();
717     Float_t xmax = gPad->GetX2();
718     Float_t ymin = gPad->GetY1();
719     Float_t ymax = gPad->GetY2();
720     Float_t dx   = xmax-xmin;
721     Float_t dy   = ymax-ymin;
722     
723     AliRunLoader * runLoader;
724     if (fLoader)
725       runLoader = fLoader->GetRunLoader();
726     else
727       runLoader = 0x0;
728
729
730     if (strlen(option) == 0) {
731         TPaveText *title = new TPaveText(xmin +0.01*dx, ymax-0.09*dy, xmin +0.5*dx, ymax-0.01*dy);
732 //      title->SetTextSize(0.023932);
733         title->SetTextSize(0.02);
734         title->SetBit(kCanDelete);
735         title->SetFillColor(42);
736         title->Draw();
737         char ptitle[100];
738         sprintf(ptitle, "Alice event:%d Run:%d Chamber:%d Cathode:%d",
739                 runLoader->GetEventNumber(),
740                 gAlice->GetHeader()->GetRun(),
741                 fChamber,
742                 fCathode);
743         title->AddText(ptitle);
744         Int_t nparticles = gAlice->GetMCApp()->Particles()->GetEntriesFast();
745         sprintf(ptitle,"Nparticles = %d Nhits = %d Npads fired = %d",
746                 nparticles, fHitsCuts,fClustersCuts);
747         title->AddText(ptitle);
748     } else {
749         TPaveLabel *label = new TPaveLabel(xmin +0.01*dx, ymax-0.07*dy, xmin +0.2*dx, ymax-0.01*dy,option);
750         label->SetBit(kCanDelete);
751         label->SetFillColor(42);
752         label->Draw();
753     }
754 }
755
756 //_____________________________________________________________________________
757 void AliMUONDisplay::DrawView(Float_t theta, Float_t phi, Float_t psi)
758 {
759 //    Draw a view of MUON clusters
760     AliInfo(" Draw View");
761     
762     gPad->SetCursor(kWatch);
763     // gPad->SetFillColor(39);
764     gPad->SetFillColor(1);
765     gPad->Clear();
766     // gPad->SetFillColor(39);
767     gPad->SetFillColor(1);
768     
769
770     Int_t iret=0;
771     TView *view = new TView(1);
772     
773     Float_t range = fRrange*fRangeSlider->GetMaximum();
774     view->SetRange(-range,-range,-range,range, range, range);
775     // zoom back to full scale only if DrawView not called from NextCathode
776     if (!fNextCathode) {
777         fZoomX0[0] = -1;
778         fZoomY0[0] = -1;
779         fZoomX1[0] =  1;
780         fZoomY1[0] =  1;
781         fZooms = 0;
782     }
783     // Recovering the chamber 
784     AliMUON *pMUON  = (AliMUON*)gAlice->GetModule("MUON");
785     AliMUONChamber*  iChamber;
786     iChamber = &(pMUON->Chamber(fChamber-1));
787
788 // Display MUON Chamber Geometry
789     char nodeName[7];
790     sprintf(nodeName,"MUON%d",100+fChamber);
791     printf(">>>> chamber is %d\n",fChamber);
792
793     if(fChamber < 5) {
794       // drawing inner circle
795       TPolyLine3D* poly1 = new  TPolyLine3D();
796       Int_t nPoint = 0;
797       for (Float_t d = 0; d < 6.3; d+= 0.1) {
798         Double_t x = AliMUONConstants::Dmin((fChamber-1)/2) * TMath::Cos(d)/2.;
799         Double_t y = AliMUONConstants::Dmin((fChamber-1)/2) * TMath::Sin(d)/2.;
800         poly1->SetPoint(nPoint++, x, y, 0.);
801       }
802       poly1->SetLineColor(2);
803       poly1->Draw("s");
804
805       // drawing outer circle
806       TPolyLine3D* poly2 = new  TPolyLine3D();
807       nPoint = 0;
808       for (Float_t d = 0; d < 6.3; d+= 0.1) {
809         Double_t x = AliMUONConstants::Dmax((fChamber-1)/2) * TMath::Cos(d)/2.;
810         Double_t y = AliMUONConstants::Dmax((fChamber-1)/2) * TMath::Sin(d)/2.;
811         poly2->SetPoint(nPoint++, x, y, 0.);
812       }
813       poly2->SetLineColor(2);
814       poly2->Draw("s");
815     }
816
817
818     if(fChamber >4 && fChamber <11) {
819       Int_t id=0;
820       for(id=0; id<26; id++) {
821         Int_t detElemId = fChamber*100+id;
822         if (  AliMUONSegmentationManager::IsValidDetElemId(detElemId) ) {
823           AliMpSlatSegmentation * seg =   
824             (AliMpSlatSegmentation *) AliMUONSegmentationManager::Segmentation(detElemId, kBendingPlane);
825           const AliMpSlat * slat = seg->Slat();
826           Float_t deltax = slat->DX()/10.;
827           Float_t deltay = slat->DY()/10.;
828           Float_t xlocal1 =  -deltax;
829           Float_t ylocal1 =  -deltay;
830           Float_t xlocal2 =  +deltax;
831           Float_t ylocal2 =  +deltay;
832           Float_t xg1, xg2, yg1, yg2, zg1, zg2;
833           iChamber->GetGeometry()->Local2Global(detElemId, xlocal1, ylocal1, 0, xg1, yg1, zg1);
834           iChamber->GetGeometry()->Local2Global(detElemId, xlocal2, ylocal2, 0, xg2, yg2, zg2);
835
836           // drawing slat active volumes
837           Float_t xCenter = (xg1 + xg2)/2.;
838           Float_t yCenter = (yg1 + yg2)/2.;
839
840           TMarker3DBox* box = new TMarker3DBox(xCenter,yCenter,0,xlocal1,ylocal2,0,0,0);
841
842           box->SetFillStyle(0);
843           box->SetLineColor(2);
844           box->Draw("s");
845
846           // drawing inner circle + disc
847           TPolyLine3D* poly  = new  TPolyLine3D();
848           TPolyLine3D* poly1 = new  TPolyLine3D();
849
850           Int_t nPoint = 0;
851           Int_t nPoint1 = 0;
852           for (Float_t d = 0; d < 6.24; d+= 0.005) {
853             Double_t x = AliMUONConstants::Dmin((fChamber-1)/2) * TMath::Cos(d)/2.;
854             Double_t y = AliMUONConstants::Dmin((fChamber-1)/2) * TMath::Sin(d)/2.;
855             if (nPoint % 2 == 0) poly->SetPoint(nPoint++, 0., 0., 0.);
856             poly->SetPoint(nPoint++, x, y, 0.);
857             poly1->SetPoint(nPoint1++, x, y, 0.);
858
859           }
860           poly->SetLineColor(1);
861           poly->Draw("s");
862           poly1->SetLineColor(2);
863           poly1->Draw("s");
864         }
865       }
866     }  
867 //add clusters to the pad
868     DrawClusters();
869     DrawHits();
870     DrawCoG();
871 //     DrawSegmentation();
872     // add itself to the list (must be last)
873     AppendPad();
874     view->SetView(phi, theta, psi, iret);
875 }
876
877 //_____________________________________________________________________________
878 void AliMUONDisplay::DrawGlobalView(Float_t theta, Float_t phi, Float_t psi)
879 {
880 //    Draw a view of muons chambers with tracks
881     
882     gPad->SetCursor(kWatch);
883     // gPad->SetFillColor(39);
884     gPad->SetFillColor(1);
885     gPad->Clear();
886     // gPad->SetFillColor(39);
887     gPad->SetFillColor(1);
888     
889
890     Int_t iret=0;
891     TView *view = new TView(1);
892     
893     Float_t range = fRrange*fRangeSlider->GetMaximum()*3.;
894     view->SetRange(-range,-range,-range,range,range,range);
895
896 // Display all MUON Chambers segmentation
897     char nodeName[7];
898     TNode *node1;
899     sprintf(nodeName,"alice");
900     
901     node1=gAlice->GetGeometry()->GetNode(nodeName);
902     if (node1) node1->Draw("same"); 
903      
904       
905 // Draw clusters for all chambers
906     Int_t chamberSave = fChamber;
907     for (fChamber = 1; fChamber <= 10; fChamber++){
908       DrawCoG();
909     }
910     fChamber = chamberSave;
911 // Draw reconstructed tracks
912     DrawTracks();
913
914     AppendPad();
915
916     Float_t zoom = 2.;
917     Float_t shift = 0.9;
918     Float_t x0 = (-1+shift)/zoom;
919     Float_t y0 = (-1+shift)/zoom;
920     Float_t x1 = (1+shift)/zoom;
921     Float_t y1 = (1+shift)/zoom;
922     gPad->Range(x0,y0,x1,y1);
923     view->SetView(phi, theta, psi, iret);
924
925 }
926
927 //______________________________________________________________________________
928 void AliMUONDisplay::ExecuteEvent(Int_t event, Int_t px, Int_t py)
929 {
930 //  Execute action corresponding to the mouse event
931
932     static Float_t x0, y0, x1, y1;
933     
934     static Int_t pxold, pyold;
935     static Int_t px0, py0;
936     static Int_t linedrawn;
937     Float_t temp;
938     
939     if (px == 0 && py == 0) { //when called by sliders
940         if (event == kButton1Up) {
941             Draw();
942         }
943         return;
944     }
945     if (!fZoomMode && gPad->GetView()) {
946         gPad->GetView()->ExecuteRotateView(event, px, py);
947         return;
948     }
949
950     // something to zoom ?
951     gPad->SetCursor(kCross);
952     
953     switch (event) {
954
955     case kButton1Down:
956         gVirtualX->SetLineColor(-1);
957         gPad->TAttLine::Modify();  //Change line attributes only if necessary
958         x0 = gPad->AbsPixeltoX(px);
959         y0 = gPad->AbsPixeltoY(py);
960         px0   = px; py0   = py;
961         pxold = px; pyold = py;
962         linedrawn = 0;
963         return;
964         
965     case kButton1Motion:
966         if (linedrawn) gVirtualX->DrawBox(px0, py0, pxold, pyold, TVirtualX::kHollow);
967         pxold = px;
968         pyold = py;
969         linedrawn = 1;
970         gVirtualX->DrawBox(px0, py0, pxold, pyold,  TVirtualX::kHollow);
971         return;
972         
973     case kButton1Up:
974         gPad->GetCanvas()->FeedbackMode(kFALSE);
975         if (px == px0) return;
976         if (py == py0) return;
977         x1 = gPad->AbsPixeltoX(px);
978         y1 = gPad->AbsPixeltoY(py);
979         
980         if (x1 < x0) {temp = x0; x0 = x1; x1 = temp;}
981         if (y1 < y0) {temp = y0; y0 = y1; y1 = temp;}
982         gPad->Range(x0,y0,x1,y1);
983         if (fZooms < AliMUONConstants::MaxZoom()-1) {
984             fZooms++;
985             fZoomX0[fZooms] = x0;
986             fZoomY0[fZooms] = y0;
987             fZoomX1[fZooms] = x1;
988             fZoomY1[fZooms] = y1;
989         }
990         gPad->Modified(kTRUE);
991         return;
992     }
993 }
994  
995 //___________________________________________
996 void AliMUONDisplay::LoadDigits(Int_t chamber, Int_t cathode)
997 {
998 // Read digits info and store x,y,z info in arrays fPoints
999 // Loop on all detectors
1000
1001     if (chamber > 14) return;
1002     fChamber = chamber;
1003     fCathode = cathode;
1004     
1005     ResetPoints();
1006     
1007     AliMUON *pMUON  =     (AliMUON*)gAlice->GetModule("MUON");
1008     AliMUONChamber*       iChamber;
1009     AliMUONGeometrySegmentation*  segmentation2 = 0x0;
1010
1011     GetMUONData()->SetTreeAddress("D");
1012
1013     TClonesArray *muonDigits  = GetMUONData()->Digits(chamber-1);
1014     if (muonDigits == 0) return;
1015
1016     gAlice->ResetDigits();
1017     Int_t nent = 0;
1018  
1019    if (GetLoader()->TreeD()) {
1020      nent = (Int_t) GetLoader()->TreeD()->GetEntries();
1021      //     gAlice->TreeD()->GetEvent(nent-2+cathode-1);
1022      GetMUONData()->GetDigits();
1023     }
1024     
1025     Int_t ndigits = muonDigits->GetEntriesFast();
1026     if (ndigits == 0) return;
1027     if (fPoints == 0) fPoints = new TObjArray(ndigits);
1028     
1029     iChamber = &(pMUON->Chamber(chamber-1));
1030
1031     segmentation2 = iChamber->SegmentationModel2(cathode);
1032
1033     Float_t zpos = iChamber->Z();
1034
1035     AliMUONDigit  *mdig;
1036     AliMUONPoints *points  = 0;
1037     TMarker3DBox  *marker  = 0;
1038     //
1039     //loop over all digits and store their position
1040     
1041     Int_t npoints  = 1;
1042     Float_t adcmax = 1024; // default
1043     if (chamber<11) adcmax = 4096;
1044
1045     for (Int_t digit = 0; digit < ndigits; digit++) {
1046         mdig    = (AliMUONDigit*)muonDigits->UncheckedAt(digit);
1047         if (mdig->Cathode() != cathode-1) continue;
1048         
1049         //
1050         // First get all needed parameters
1051         //
1052         Int_t charge = mdig->Signal();
1053         Int_t index  = Int_t(TMath::Log(charge)/(TMath::Log(adcmax)/22));
1054         Int_t color  = 261+index;
1055         Int_t colorTrigger = 2;   
1056         if (color > 282) color = 282;
1057
1058         if (chamber > 10) { // trigger chamber 
1059
1060             Int_t sumCharge = 0;
1061             for (Int_t icharge = 0; icharge < 10; icharge++) {
1062                 sumCharge = sumCharge+mdig->TrackCharge(icharge);
1063             }
1064             Int_t testCharge = sumCharge-(Int_t(sumCharge/10))*10;
1065             if(sumCharge <= 10 || testCharge > 0) {
1066                 colorTrigger = color; 
1067             } else {
1068                 colorTrigger = 5; 
1069             }
1070         }
1071
1072         // get the center of the pad - add on x and y half of pad size
1073         Float_t xpad, ypad, zpad;
1074         Int_t isec;
1075         Float_t dpx, dpy;
1076
1077         Int_t detElemId = mdig->DetElemId();
1078         segmentation2->GetPadC(detElemId, mdig->PadX(), mdig->PadY(), xpad, ypad, zpad);
1079         isec = segmentation2->Sector(detElemId, mdig->PadX(), mdig->PadY());
1080         dpx = segmentation2->Dpx(detElemId, isec)/2;
1081         dpy = segmentation2->Dpy(detElemId, isec)/2;
1082 //
1083 //      segmentation->Dump();
1084         
1085         //
1086         // Then set the objects
1087         //
1088         points = new AliMUONPoints(npoints);
1089         fPoints->AddAt(points,digit);
1090         if (chamber > 10) {
1091             points->SetMarkerColor(colorTrigger);
1092         } else {  
1093             points->SetMarkerColor(color);
1094         }
1095         points->SetMarkerStyle(21);
1096         points->SetMarkerSize(0.5);
1097         points->SetParticle(-1);
1098         points->SetHitIndex(-1);
1099         points->SetTrackIndex(-1);
1100         points->SetDigitIndex(digit);
1101         points->SetPoint(0,xpad,ypad,zpos);
1102         
1103         Int_t lineColor = (zpad-zpos > 0) ? 2:3;
1104         marker=new TMarker3DBox(xpad,ypad,zpos,dpx,dpy,0,0,0);
1105
1106             
1107         marker->SetLineColor(lineColor);
1108         marker->SetFillStyle(1001);
1109         marker->SetFillColor(color);
1110         marker->SetRefObject((TObject*)points);
1111         points->Set3DMarker(0, marker);
1112     }
1113 }
1114 //___________________________________________
1115 void AliMUONDisplay::LoadCoG(Int_t chamber, Int_t /*cathode*/)
1116 {
1117 // Read raw clusters info and store x,y,z info in arrays fRpoints
1118 // Loop on all detectors
1119
1120     if (chamber > 10) return;
1121     
1122     ResetRpoints();
1123     
1124     AliMUON *pMUON  = (AliMUON*)gAlice->GetModule("MUON");
1125     AliMUONChamber*  iChamber;
1126     
1127     GetMUONData()->SetTreeAddress("RC");
1128     TClonesArray *muonRawClusters  = GetMUONData()->RawClusters(chamber-1);
1129
1130     if (muonRawClusters == 0) return;
1131
1132     Int_t nent = 0;
1133     if (GetMUONData()->TreeR()) {
1134         nent=(Int_t) GetMUONData()->TreeR()->GetEntries();
1135         GetMUONData()->TreeR()->GetEvent(0);
1136     }
1137     
1138     Int_t nrawcl = muonRawClusters->GetEntriesFast();
1139     if (nrawcl == 0) return;
1140     if (fRpoints == 0) fRpoints = new TObjArray(nrawcl);
1141     
1142     iChamber = &(pMUON->Chamber(chamber-1));
1143     Float_t zpos=iChamber->Z();  
1144     AliMUONRawCluster  *mRaw;
1145     AliMUONPoints *points = 0;
1146     //
1147     //loop over all raw clusters and store their position
1148     points = new AliMUONPoints(nrawcl);
1149     for (Int_t iraw=0;iraw<nrawcl;iraw++) {
1150         mRaw   = (AliMUONRawCluster*)muonRawClusters->UncheckedAt(iraw);
1151         points->SetMarkerColor(51);
1152         points->SetMarkerStyle(2);
1153         points->SetMarkerSize(1.);
1154         points->SetParticle(-1);
1155         points->SetHitIndex(-1);
1156         points->SetTrackIndex(-1);
1157         points->SetDigitIndex(-1);
1158         points->SetPoint(iraw,mRaw->GetX(0),mRaw->GetY(0),zpos);
1159         fRpoints->AddAt(points,iraw);
1160         //      printf("%f and %f and %f\n",mRaw->GetX(0),mRaw->GetY(0),mRaw->GetZ(0));
1161     }
1162 }
1163
1164 //___________________________________________
1165 void AliMUONDisplay::LoadTracks()
1166 {
1167 // Load tracks
1168   AliMUONTrack* recTrack = 0;
1169   AliMUONTrackParam* trackParam = 0;
1170   TClonesArray *  trackParamAtHit = 0;   
1171
1172   ResetRpoints();
1173
1174   GetMUONData()->SetTreeAddress("RT");
1175   TClonesArray* recTracksArray = GetMUONData()->RecTracks();
1176   if (recTracksArray == NULL) return;
1177   GetMUONData()->GetRecTracks();
1178
1179   Int_t nRecTracks = 0;
1180   if (recTracksArray)
1181     nRecTracks = (Int_t) recTracksArray->GetEntriesFast();
1182
1183
1184   if (fRpoints == 0) fRpoints = new TObjArray(nRecTracks);
1185
1186   for (Int_t iRecTracks = 0; iRecTracks <  nRecTracks;  iRecTracks++) {
1187     // reading info from tracks
1188     recTrack = (AliMUONTrack*) recTracksArray->At(iRecTracks);
1189
1190     Int_t nTrackHits = recTrack->GetNTrackHits();
1191
1192     if (nTrackHits == 0) continue;
1193
1194     Int_t iPoint = 0;
1195     TPolyLine3D *points = new TPolyLine3D(nTrackHits+1); 
1196     points->SetLineColor(6);
1197     points->SetLineWidth(1);
1198     fRpoints->AddAt(points,iRecTracks);
1199
1200     Float_t xRec=0;
1201     Float_t yRec=0;
1202     Float_t zRec=0;
1203
1204     trackParam = recTrack->GetTrackParamAtVertex(); 
1205     xRec  = trackParam->GetNonBendingCoor();
1206     yRec  = trackParam->GetBendingCoor();
1207     zRec  = trackParam->GetZ();
1208     points->SetPoint(iPoint,xRec,yRec,zRec);
1209     iPoint++;   
1210
1211     for (Int_t iHit = 0; iHit < nTrackHits; iHit++){
1212       trackParamAtHit = recTrack->GetTrackParamAtHit();
1213       trackParam = (AliMUONTrackParam*) trackParamAtHit->At(iHit); 
1214       xRec  = trackParam->GetNonBendingCoor();
1215       yRec  = trackParam->GetBendingCoor();
1216       zRec  = trackParam->GetZ();
1217       points->SetPoint(iPoint,xRec,yRec,zRec);
1218       iPoint++; 
1219     } // end loop rec. hits
1220     PrintTrack(iRecTracks,recTrack);
1221   } // end loop tracks
1222   
1223
1224 }
1225
1226 void AliMUONDisplay::PrintTrack(Int_t iRecTracks, AliMUONTrack *recTrack)
1227 {
1228   AliMUONTrackParam *trackParam;
1229   Float_t vertex[3], momentum[3];
1230   Float_t pYZ, bendingSlope, nonBendingSlope, chi2dof;
1231   Int_t charge;
1232
1233   trackParam = recTrack->GetTrackParamAtVertex();
1234   vertex[0] = trackParam->GetNonBendingCoor();
1235   vertex[1] = trackParam->GetBendingCoor();
1236   vertex[2] = trackParam->GetZ();
1237   pYZ =  1./TMath::Abs(trackParam->GetInverseBendingMomentum());
1238   bendingSlope = trackParam->GetBendingSlope();
1239   nonBendingSlope = trackParam->GetNonBendingSlope();
1240   momentum[2] = -pYZ / TMath::Sqrt(1.0 + bendingSlope*bendingSlope);
1241   momentum[0] = momentum[2] * nonBendingSlope;
1242   momentum[1] = momentum[2] * bendingSlope;
1243   charge = Int_t(TMath::Sign(1.,trackParam->GetInverseBendingMomentum()));
1244   chi2dof = recTrack->GetFitFMin()/(2.0 * recTrack->GetNTrackHits() - 5.);
1245   
1246   printf("===================================================\n");
1247   printf(" Reconstructed track # %d \n",iRecTracks);
1248   printf(" charge: %d \n",charge);
1249   printf(" vertex x,y,z (cm): %f %f %f \n",vertex[0],vertex[1],vertex[2]); 
1250   printf(" momentum Px,Py,Pz (GeV/c): %f %f %f \n",momentum[0],momentum[1],momentum[2]);
1251   printf(" track chi2/dof: %f \n",chi2dof); 
1252   
1253 }
1254
1255 //___________________________________________
1256 void AliMUONDisplay::LoadHits(Int_t chamber)
1257 {
1258   // Read hits info and store x,y,z info in arrays fPhits
1259   // Loop on all detectors
1260
1261     if (chamber > 14) return;
1262     Int_t track;
1263
1264     fChamber=chamber;
1265  
1266     ResetPhits();
1267     
1268     AliMUON *pMUON  = (AliMUON*)gAlice->GetModule("MUON");
1269     AliMUONChamber*  iChamber;
1270
1271     iChamber = &(pMUON->Chamber(chamber-1));
1272     Float_t zpos=iChamber->Z();
1273
1274
1275     if (GetMUONData()->TreeH()) {
1276       GetMUONData()->SetTreeAddress("H");
1277       Int_t ntracks = (Int_t)GetMUONData()->TreeH()->GetEntries(); //skowron
1278       Int_t nthits  = 0;
1279       for (track = 0; track < ntracks; track++) {
1280         GetMUONData()->ResetHits();
1281         GetMUONData()->GetTrack(track);//skowron
1282         TClonesArray *muonHits  = GetMUONData()->Hits();
1283         if (muonHits == 0) return;
1284         nthits += muonHits->GetEntriesFast();
1285       } 
1286       if (fPhits == 0) fPhits = new TObjArray(nthits);
1287       Int_t nhold=0;
1288       for (track=0; track<ntracks;track++) {
1289         GetMUONData()->ResetHits();
1290         GetMUONData()->GetTrack(track);//skowron
1291         TClonesArray *muonHits  = GetMUONData()->Hits();
1292         if (muonHits == 0) return;
1293         Int_t nhits = muonHits->GetEntriesFast();
1294         if (nhits == 0) continue;
1295         AliMUONHit *mHit;
1296         AliMUONPoints *points = 0;
1297         Int_t npoints=1;
1298         for (Int_t hit=0;hit<nhits;hit++) {
1299           mHit = (AliMUONHit*)muonHits->UncheckedAt(hit);
1300           Int_t nch  = mHit->Chamber();              // chamber number
1301           if (nch != chamber) continue;
1302           //
1303           // Retrieve info and set the objects
1304           //
1305           points = new AliMUONPoints(npoints);
1306           fPhits->AddAt(points,nhold+hit);
1307           points->SetMarkerColor(kRed);
1308           points->SetMarkerStyle(5);
1309           points->SetMarkerSize(1.);
1310           points->SetParticle(mHit->Track());
1311           points->SetHitIndex(hit);
1312           points->SetTrackIndex(track);
1313           points->SetDigitIndex(-1);
1314           points->SetPoint(0,mHit->X(),mHit->Y(),zpos);
1315           //        printf("%f and %f and %f\n",mHit->X(),mHit->Y(),mHit->Z());
1316         }
1317         nhold+=nhits;
1318       }
1319     }
1320 }
1321
1322 //_____________________________________________________________________________
1323 void AliMUONDisplay::Paint(Option_t *)
1324 {
1325 //    Paint miscellaneous items
1326 }
1327
1328 //_____________________________________________________________________________
1329 void AliMUONDisplay::SetPickMode()
1330 {
1331 // Set parameters for pick mode.
1332 // 
1333     fZoomMode = 0;
1334
1335     fArcButton->SetY1(fPickButton->GetYlowNDC()+0.5*fPickButton->GetHNDC());
1336     fTrigPad->Modified();
1337 }
1338
1339 //_____________________________________________________________________________
1340 void AliMUONDisplay::SetZoomMode()
1341 {
1342 //  Set parameters for zoom mode
1343     fZoomMode = 1;
1344     
1345     fArcButton->SetY1(fZoomButton->GetYlowNDC()+0.5*fZoomButton->GetHNDC());
1346     fTrigPad->Modified();
1347 }
1348
1349 //_____________________________________________________________________________
1350 void AliMUONDisplay::NextChamber(Int_t delta)
1351 {
1352   // to go from chamber to next chamber if delta = 1
1353   // or previous chamber otherwise
1354     if (delta == 1) {
1355         if (fChamber < AliMUONConstants::NCh()) fChamber++;
1356     } else {
1357         if (fChamber > 1) fChamber--;
1358     }
1359     if (!fPad) return;
1360     fPad->Clear();
1361     LoadDigits(fChamber, fCathode);
1362     DrawChamber();
1363 }
1364
1365 //_____________________________________________________________________________
1366 void AliMUONDisplay::NextCathode()
1367 {
1368     // to switch to other cathode plane
1369     if (!fPad) return;
1370     fPad->Clear();
1371     if (fCathode == 1) {
1372         LoadDigits(fChamber, 2);        
1373     } else {
1374         LoadDigits(fChamber, 1);
1375     }
1376     fNextCathode = kTRUE; // to keep the same zoom
1377     DrawChamber();
1378     fNextCathode = kFALSE;
1379     TPad *pad = (TPad*)gPad->GetPadSave();
1380     pad->Range(fZoomX0[fZooms], fZoomY0[fZooms],
1381                fZoomX1[fZooms], fZoomY1[fZooms]);
1382     pad->Modified();
1383     fPad->cd();
1384     DrawTitle();
1385 }
1386
1387 //_____________________________________________________________________________
1388 void AliMUONDisplay::Trigger()
1389 {
1390
1391   AliMUONGlobalTrigger* globalTrig;
1392
1393   GetMUONData()->SetTreeAddress("GLT");
1394   GetMUONData()->GetTriggerD();
1395
1396   globalTrig =  (AliMUONGlobalTrigger*)GetMUONData()->GlobalTrigger()->UncheckedAt(0);
1397   if (globalTrig == 0) return;
1398
1399   printf("===================================================\n");
1400   printf(" Global Trigger output       Low pt  High pt   All\n");
1401
1402   printf(" number of Single Plus      :\t");
1403   printf("%i\t",globalTrig->SinglePlusLpt());
1404   printf("%i\t",globalTrig->SinglePlusHpt());
1405   printf("%i\t",globalTrig->SinglePlusApt());
1406   printf("\n");
1407
1408   printf(" number of Single Minus     :\t");
1409   printf("%i\t",globalTrig->SingleMinusLpt());
1410   printf("%i\t",globalTrig->SingleMinusHpt());
1411   printf("%i\t",globalTrig->SingleMinusApt());
1412   printf("\n");
1413
1414   printf(" number of Single Undefined :\t"); 
1415   printf("%i\t",globalTrig->SingleUndefLpt());
1416   printf("%i\t",globalTrig->SingleUndefHpt());
1417   printf("%i\t",globalTrig->SingleUndefApt());
1418   printf("\n");
1419
1420   printf(" number of UnlikeSign pair  :\t"); 
1421   printf("%i\t",globalTrig->PairUnlikeLpt());
1422   printf("%i\t",globalTrig->PairUnlikeHpt());
1423   printf("%i\t",globalTrig->PairUnlikeApt());
1424   printf("\n");
1425
1426   printf(" number of LikeSign pair    :\t");  
1427   printf("%i\t",globalTrig->PairLikeLpt());
1428   printf("%i\t",globalTrig->PairLikeHpt());
1429   printf("%i\t",globalTrig->PairLikeApt());
1430   printf("\n");
1431   printf("===================================================\n");
1432   printf("\n");
1433   
1434
1435  //  // returns Trigger Decision for current event
1436 //   AliMUONTriggerDecision* decision= new AliMUONTriggerDecision(GetLoader(),1);
1437
1438 //   //  AliMUONTriggerDecision* decision= new AliMUONTriggerDecision(1);
1439 //   AliMUONData* muonData = decision->GetMUONData();
1440 //   muonData->SetTreeAddress("D");
1441 //   decision->Trigger(); 
1442 }
1443 //_____________________________________________________________________________
1444 void AliMUONDisplay::SetChamberAndCathode(Int_t chamber, Int_t cathode)
1445 {
1446 // Set chamber and cathode number
1447    fChamber = chamber;
1448    fCathode = cathode;
1449
1450    if (!fPad) return;
1451    fPad->Clear();
1452    LoadDigits(chamber,cathode);
1453    DrawChamber();
1454 }
1455
1456 void AliMUONDisplay::SetEvent(Int_t newevent)
1457 {
1458 // Chose event 
1459     gAlice->GetEvent(newevent);
1460     fEvent=newevent;
1461     if (!gAlice->TreeD()) return; 
1462     if (!fPad) return;
1463     fPad->Clear();
1464     LoadDigits(fChamber,fCathode);
1465     Draw();
1466 }
1467
1468 //_____________________________________________________________________________
1469 void AliMUONDisplay::SetRange(Float_t rrange, Float_t zrange)
1470 {
1471 // Set view range along R and Z
1472     fRrange = rrange;
1473     fZrange = zrange;
1474
1475     if (!fPad) return;
1476     fPad->Clear();
1477     Draw();
1478 }
1479    
1480 //_____________________________________________________________________________
1481 void AliMUONDisplay::SetView(Float_t theta, Float_t phi, Float_t psi)
1482 {
1483 //  change viewing angles for current event
1484
1485     fPad->cd();
1486     fPhi   = phi;
1487     fTheta = theta;
1488     fPsi   = psi;
1489     Int_t iret = 0;
1490     
1491     TView *view = gPad->GetView();
1492     if (view) view->SetView(fPhi, fTheta, fPsi, iret);
1493     else      Draw();
1494     gPad->Modified();
1495 }
1496
1497 //_____________________________________________________________________________
1498 void AliMUONDisplay::ShowNextEvent(Int_t delta)
1499 {
1500   AliRunLoader * runLoader;
1501   if (fLoader)
1502     runLoader = fLoader->GetRunLoader();
1503   else
1504     runLoader = 0x0;
1505     
1506 //  Display (current event_number + delta)
1507 //    delta =  1  shown next event
1508 //    delta = -1 show previous event
1509     if (delta) {
1510       //runLoader->CleanDetectors();
1511       //runLoader->CleanKinematics();
1512       Int_t currentEvent = runLoader->GetEventNumber();
1513       Int_t newEvent     = currentEvent + delta;
1514       runLoader->GetEvent(newEvent);
1515       fEvent=newEvent;
1516     }
1517     LoadDigits(fChamber, fCathode);
1518     fPad->cd(); 
1519     Draw();
1520 }
1521
1522 //______________________________________________________________________________
1523 void AliMUONDisplay::UnZoom()
1524 {
1525 // Unzoom 
1526     if (fZooms <= 0) return;
1527     fZooms--;
1528     TPad *pad = (TPad*)gPad->GetPadSave();
1529     pad->Range(fZoomX0[fZooms],fZoomY0[fZooms], fZoomX1[fZooms],fZoomY1[fZooms]);
1530     pad->Modified();
1531 }
1532
1533 //_____________________________________________________________________________
1534 void AliMUONDisplay::ResetPoints()
1535 {
1536     //
1537     // Reset array of points
1538     //
1539     if (fPoints) {
1540         fPoints->Delete();
1541         delete fPoints;
1542         fPoints = 0;
1543     }
1544 }
1545 //_____________________________________________________________________________
1546 void AliMUONDisplay::ResetPhits()
1547 {
1548     //
1549     // Reset array of points
1550     //
1551     if (fPhits) {
1552         fPhits->Delete();
1553         delete fPhits;
1554         fPhits = 0;
1555     }
1556 }
1557 //_____________________________________________________________________________
1558 void AliMUONDisplay::ResetRpoints()
1559 {
1560   //
1561   // Reset array of points
1562   //
1563     if (fRpoints) {
1564         fRpoints->Clear();
1565         //      delete fRpoints;
1566         fRpoints = 0;
1567     }
1568 }
1569
1570 AliMUONDisplay & AliMUONDisplay::operator = (const AliMUONDisplay & rhs)
1571 {
1572 // Protected assignement operator
1573
1574   if (this == &rhs) return *this;
1575
1576   AliFatal("Not implemented.");
1577     
1578   return *this;  
1579 }
1580
1581
1582
1583
1584
1585
1586
1587
1588