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