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