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