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