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