]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpSubZonePainter.cxx
Fix in AliMpSectorSegmentation::PadByPosition;
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSubZonePainter.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 // $Id$
17 // $MpId: AliMpSubZonePainter.cxx,v 1.8 2006/05/24 13:58:32 ivana Exp $
18 // Category: graphics
19
20 //-----------------------------------------------------------------------------
21 // Class AliMpSubZonePainter
22 // -------------------------
23 // Class for drawing a subzone into canvas
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, IPN Orsay
26 //-----------------------------------------------------------------------------
27   
28 #include "AliMpSubZonePainter.h"
29 #include "AliMpGraphContext.h"
30 #include "AliMpSubZone.h"
31 #include "AliMpVRowSegment.h"
32 #include "AliMpVMotif.h"
33
34 #include <TVirtualX.h>
35 #include <TPad.h>
36
37 /// \cond CLASSIMP
38 ClassImp(AliMpSubZonePainter)
39 /// \endcond
40
41 //_______________________________________________________________________
42 AliMpSubZonePainter::AliMpSubZonePainter()
43   : AliMpVPainter(),
44     fSubZone(0)
45 {
46   /// Default constructor
47 }
48
49 //_______________________________________________________________________
50 AliMpSubZonePainter::AliMpSubZonePainter(AliMpSubZone *subZone)
51   : AliMpVPainter(),
52     fSubZone(subZone)
53 {
54   /// Standard constructor 
55
56 }
57
58 //_______________________________________________________________________
59 AliMpSubZonePainter::~AliMpSubZonePainter()
60 {
61   /// Destructor
62 }
63
64 //_______________________________________________________________________
65 Int_t AliMpSubZonePainter::DistancetoPrimitive(Int_t x, Int_t y)
66 {
67   /// Dist to the nearest segment center if (x,y) is inside the sub-zone
68   /// 9999 otherwise
69   
70   if (fSubZone->GetNofRowSegments()<1) return 9999;
71   AliMpGraphContext *gr = AliMpGraphContext::Instance();
72
73   gr->Push();
74   InitGraphContext();
75
76
77   TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
78
79   Double_t res=9999.;
80   for (Int_t iseg=0;iseg<fSubZone->GetNofRowSegments();++iseg){
81     //for each row segments
82     AliMpVRowSegment* seg = fSubZone->GetRowSegment(iseg);
83
84     TVector2 pos,dim;
85     gr->RealToPad(seg->Position(),seg->Dimensions(),pos,dim);
86
87     if ( IsInside(point,pos,dim) ){
88       Double_t value = (point-pos).Mod();
89       if (value<res) res=value;
90     }
91   }
92   gr->Pop();
93   return (Int_t)res;
94 }
95
96 //_______________________________________________________________________
97 void AliMpSubZonePainter::DumpObject()
98 {
99   /// Draw the owned object
100   
101   fSubZone->Dump();
102 }
103
104 //_______________________________________________________________________
105 TVector2 AliMpSubZonePainter::GetPosition() const
106 {
107   /// Get the owned object's position
108
109   if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
110   AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
111
112   // bl = bottom left position;
113   TVector2 bl = seg->Position()-seg->Dimensions();
114   // ur = upper right position
115   TVector2 ur = seg->Position()+seg->Dimensions();
116
117   for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
118     seg = fSubZone->GetRowSegment(iseg);
119     // update the bottom-left corner
120     if (bl.X()>seg->Position().X()-seg->Dimensions().X())
121       bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
122     if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
123       bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
124     // update the upper-right corner
125     if (ur.X()<seg->Position().X()+seg->Dimensions().X())
126       ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
127     if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
128       ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
129   }
130   return (ur+bl)/2.;
131 }
132
133 //_______________________________________________________________________
134 TVector2 AliMpSubZonePainter::GetDimensions() const
135 {
136   /// Get the owned object's dimensions
137
138   if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
139   AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
140
141   // bl = bottom left position;
142   TVector2 bl = seg->Position()-seg->Dimensions();
143   // ur = upper right position
144   TVector2 ur = seg->Position()+seg->Dimensions();
145
146   for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
147     seg = fSubZone->GetRowSegment(iseg);
148     // update the bottom-left corner
149     if (bl.X()>seg->Position().X()-seg->Dimensions().X())
150       bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
151     if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
152       bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
153     // update the upper-right corner
154     if (ur.X()<seg->Position().X()+seg->Dimensions().X())
155       ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
156     if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
157       ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
158   }
159   return (ur-bl)/2.;
160 }
161
162 //_______________________________________________________________________
163 void AliMpSubZonePainter::Draw(Option_t *option)
164 {
165 /// Draw the sector on the current pad
166 /// The first letter of \a option is treated as follows:
167 /// - case "S" : each row segments are drawn separately
168 /// - case ""  : the whole subzone is drawn at once
169 /// in both cases, the rest of the option is passed
170 /// as argument to the Draw function of respectively
171 /// zone or row objects.
172
173   if (!fSubZone) return;
174   AliMpGraphContext *gr = AliMpGraphContext::Instance();
175
176   gr->Push();
177   InitGraphContext();
178   switch (option[0]){
179   case 'S':
180     {
181
182         for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
183           gr->Push();
184           AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg);
185
186           gr->SetPadPosForReal(rowSegment->Position(),
187                                rowSegment->Dimensions());
188           gr->SetColor(GetColor());
189           DrawObject(rowSegment,option+1);
190       
191           gr->Pop();
192         }
193     }
194     break;
195   default: AppendPad(option);
196   }
197   gr->Pop();
198 }
199
200
201 //_______________________________________________________________________
202 void AliMpSubZonePainter::Paint(Option_t *option)
203 {
204 /// Paint the object
205
206   AliMpGraphContext *gr = AliMpGraphContext::Instance();
207   if (!fSubZone) return;
208   if (fSubZone->GetNofRowSegments()<1) return;
209   gr->Push();
210   gPad->Range(0.,0.,1.,1.);
211   Int_t col=gVirtualX->GetFillColor();
212   InitGraphContext();
213   
214   gVirtualX->SetFillColor(GetColor());
215   for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
216     AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg);
217     TVector2 pos,dim;
218     gr->RealToPad(rowSegment->Position(),rowSegment->Dimensions(),
219                   pos,dim);
220     gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
221                    pos.X()+dim.X(),pos.Y()+dim.Y());
222     if (option[0]=='T'){
223       Float_t textSize =   gVirtualX->GetTextSize();
224       gVirtualX->SetTextSize(15);
225       gPad->PaintText(pos.X()-0.01,pos.Y()-0.01,
226                       fSubZone->GetMotif()->GetID());
227       gVirtualX->SetTextSize(textSize);
228     }
229   }
230
231   gVirtualX->SetFillColor(col);
232   gr->Pop();
233 }