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