]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpZonePainter.cxx
- Added new functions:
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpZonePainter.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: AliMpZonePainter.cxx,v 1.8 2006/05/24 13:58:32 ivana Exp $
18 // Category: graphics
19 //
20 // Class AliMpZonePainter
21 // ----------------------
22 // Class for drawing a zone into canvas
23 // Included in AliRoot: 2003/05/02
24 // Authors: David Guez, IPN Orsay
25  
26 #include "AliMpZonePainter.h"
27 #include "AliMpGraphContext.h"
28 #include "AliMpZone.h"
29 #include "AliMpSubZone.h"
30 #include "AliMpVRowSegment.h"
31
32 #include <TVirtualX.h>
33 #include <TPad.h>
34
35 /// \cond CLASSIMP
36 ClassImp(AliMpZonePainter)
37 /// \endcond
38
39 //_______________________________________________________________________
40 AliMpZonePainter::AliMpZonePainter()
41   : AliMpVPainter(),
42     fZone(0)
43 {
44   /// Default constructor
45 }
46
47 //_______________________________________________________________________
48 AliMpZonePainter::AliMpZonePainter(AliMpZone *zone)
49   : AliMpVPainter(),
50     fZone(zone)
51 {
52   /// Standard constructor 
53
54 }
55
56 //_______________________________________________________________________
57 AliMpZonePainter::~AliMpZonePainter()
58 {
59   /// Destructor 
60 }
61
62 //_______________________________________________________________________
63 Int_t AliMpZonePainter::DistancetoPrimitive(Int_t x, Int_t y)
64 {
65   /// Distance to the nearest segment center if (x,y) is inside the zone
66   /// 9999 otherwise
67
68   if (fZone->GetNofSubZones()<1) return 9999;
69   AliMpGraphContext *gr = AliMpGraphContext::Instance();
70
71   gr->Push();
72   InitGraphContext();
73   
74   TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
75
76   Double_t res=9999.;
77   for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
78     // for each sub-zones
79     AliMpSubZone* sub = fZone->GetSubZone(isub);
80     for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
81       //for each row segments
82       AliMpVRowSegment* seg = sub->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   }
93   gr->Pop();
94   return (Int_t)res;
95 }
96
97 //_______________________________________________________________________
98 void AliMpZonePainter::DumpObject()
99 {
100   /// Dump the owned object
101
102   fZone->Dump();
103 }
104
105 //_______________________________________________________________________
106 TVector2 AliMpZonePainter::GetPosition() const
107 {
108   //// Get the owned object's position
109
110   if (fZone->GetNofSubZones()<1) return TVector2(0.,0.);
111
112   TVector2 bl(9999,9999),ur(-9999,-9999);
113
114   for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
115     // for each sub-zones
116     AliMpSubZone* sub = fZone->GetSubZone(isub);
117     for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
118       //for each row segments
119       AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
120
121       // update the bottom-left corner
122       if (bl.X()>seg->Position().X()-seg->Dimensions().X())
123         bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
124       if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
125         bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
126       // update the upper-right corner
127       if (ur.X()<seg->Position().X()+seg->Dimensions().X())
128         ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
129       if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
130         ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
131     } //iseg
132   } //isub
133   return (ur+bl)/2.;
134 }
135
136 //_______________________________________________________________________
137 TVector2 AliMpZonePainter::GetDimensions() const
138 {
139   //// Get the owned object's dimensions
140
141   if (fZone->GetNofSubZones()<1) return TVector2(0.,0.);
142
143   TVector2 bl(9999,9999),ur(-9999,-9999);
144
145   for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
146     // for each sub-zones
147     AliMpSubZone* sub = fZone->GetSubZone(isub);
148     for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
149       //for each row segments
150       AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
151
152       // update the bottom-left corner
153       if (bl.X()>seg->Position().X()-seg->Dimensions().X())
154         bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
155       if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
156         bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
157       // update the upper-right corner
158       if (ur.X()<seg->Position().X()+seg->Dimensions().X())
159         ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
160       if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
161         ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
162     } //iseg
163   } //isub
164   return (ur-bl)/2.;
165 }
166
167 //_______________________________________________________________________
168 void AliMpZonePainter::Draw(Option_t *option)
169 {
170 /// Draw the sector on the current pad
171 /// The first letter of \a option is treated as follows:
172 /// - case "S" : each sub zones are drawn separately
173 /// - case ""  : the whole zone is drawn at once
174 /// in both cases, the rest of the option is passed
175 /// as argument to the Draw function of respectively
176 /// zone or row objects.
177
178   AliMpGraphContext *gr = AliMpGraphContext::Instance();
179   if (!fZone) return;
180
181   gr->Push();
182   InitGraphContext();
183   switch (option[0]){
184   case 'S':
185     {
186       for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){
187         AliMpSubZone *subZone = fZone->GetSubZone(iSubZone);
188         gr->Push();
189
190         Double_t blx=  9999,  bly=  9999;
191         Double_t urx= -9999,  ury= -9999;
192
193           for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
194             AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
195
196             TVector2 bl = rowSegment->Position();
197             bl-=rowSegment->Dimensions();
198             TVector2 ur = rowSegment->Position();
199             ur+=rowSegment->Dimensions();
200             
201             if (bl.X()<blx) blx=bl.X();
202             if (bl.Y()<bly) bly=bl.Y();
203             if (ur.X()>urx) urx=ur.X();
204             if (ur.Y()>ury) ury=ur.Y();
205           }
206           TVector2 position ( (urx+blx)/2.,(ury+bly)/2. );
207           TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. );
208       
209           gr->SetPadPosForReal(position,dimensions);
210           gr->SetColor((fZone->GetID()-1)*5+iSubZone+2);
211           DrawObject(subZone,option+1);
212       
213           gr->Pop();
214       }
215     }
216     break;
217   default: AppendPad(option);
218   }
219   gr->Pop();
220 }
221
222 //_______________________________________________________________________
223 void AliMpZonePainter::Paint(Option_t *option)
224 {
225 //// Paint the object
226
227   AliMpGraphContext *gr = AliMpGraphContext::Instance();
228   if (!fZone) return;
229   if (fZone->GetNofSubZones()<1) return;
230   gr->Push();
231   gPad->Range(0.,0.,1.,1.);
232
233   Int_t col=gVirtualX->GetFillColor();
234   InitGraphContext();
235   
236   gVirtualX->SetFillColor(GetColor());
237   Float_t textSize =   gVirtualX->GetTextSize();
238   for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){
239     AliMpSubZone *subZone = fZone->GetSubZone(iSubZone);
240     for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
241       AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
242       TVector2 pos,dim;
243       gr->RealToPad(rowSegment->Position(),rowSegment->Dimensions(),
244                     pos,dim);
245       gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
246                      pos.X()+dim.X(),pos.Y()+dim.Y());
247       if (option[0]=='T'){
248         gVirtualX->SetTextSize(15);
249         gPad->PaintText(pos.X()-0.01,pos.Y()-0.01,
250                         Form("%d",fZone->GetID()));
251       }
252     }
253   }
254   gVirtualX->SetTextSize(textSize);
255   gVirtualX->SetFillColor(col);
256   gr->Pop();
257 }