4 // Class AliMpZonePainter
5 // ----------------------
6 // Class for drawing a zone into canvas
8 // Authors: David Guez, IPN Orsay
10 #include <TVirtualX.h>
14 #include "AliMpZonePainter.h"
15 #include "AliMpGraphContext.h"
16 #include "AliMpZone.h"
17 #include "AliMpSubZone.h"
18 #include "AliMpVRowSegment.h"
20 ClassImp(AliMpZonePainter)
22 //_______________________________________________________________________
23 AliMpZonePainter::AliMpZonePainter()
27 // default dummy constructor
30 //_______________________________________________________________________
31 AliMpZonePainter::AliMpZonePainter(AliMpZone *zone)
39 //_____________________________________________________________________________
40 AliMpZonePainter::AliMpZonePainter(const AliMpZonePainter& right)
41 : AliMpVPainter(right)
43 // copy constructor (not implemented)
45 Fatal("AliMpZonePainter", "Copy constructor not provided.");
48 //_______________________________________________________________________
49 AliMpZonePainter::~AliMpZonePainter()
55 //_____________________________________________________________________________
57 AliMpZonePainter::operator=(const AliMpZonePainter& right)
59 // assignement operator (not implemented)
61 // check assignement to self
62 if (this == &right) return *this;
64 Fatal("operator =", "Assignement operator not provided.");
69 //_______________________________________________________________________
70 Int_t AliMpZonePainter::DistancetoPrimitive(Int_t x, Int_t y)
72 // dist to the nearest segment center if (x,y) is inside the zone
74 if (fZone->GetNofSubZones()<1) return 9999;
75 AliMpGraphContext *gr = AliMpGraphContext::Instance();
80 TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
83 for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
85 AliMpSubZone* sub = fZone->GetSubZone(isub);
86 for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
87 //for each row segments
88 AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
91 gr->RealToPad(seg->Position(),seg->Dimensions(),pos,dim);
93 if ( IsInside(point,pos,dim) ){
94 Double_t value = (point-pos).Mod();
95 if (value<res) res=value;
103 //_______________________________________________________________________
104 void AliMpZonePainter::DumpObject()
106 // Draw the owned object
111 //_______________________________________________________________________
112 TVector2 AliMpZonePainter::GetPosition() const
114 // Get the owned object's position
116 if (fZone->GetNofSubZones()<1) return TVector2(0.,0.);
118 TVector2 bl(9999,9999),ur(-9999,-9999);
120 for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
121 // for each sub-zones
122 AliMpSubZone* sub = fZone->GetSubZone(isub);
123 for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
124 //for each row segments
125 AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
127 // update the bottom-left corner
128 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
129 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
130 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
131 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
132 // update the upper-right corner
133 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
134 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
135 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
136 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
142 //_______________________________________________________________________
143 TVector2 AliMpZonePainter::GetDimensions() const
145 // Get the owned object's dimensions
147 if (fZone->GetNofSubZones()<1) return TVector2(0.,0.);
149 TVector2 bl(9999,9999),ur(-9999,-9999);
151 for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
152 // for each sub-zones
153 AliMpSubZone* sub = fZone->GetSubZone(isub);
154 for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
155 //for each row segments
156 AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
158 // update the bottom-left corner
159 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
160 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
161 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
162 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
163 // update the upper-right corner
164 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
165 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
166 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
167 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
173 //_______________________________________________________________________
174 void AliMpZonePainter::Draw(Option_t *option)
176 // Draw the sector on the current pad
177 // The first letter of <option> is treated as follows:
178 // case "S" : each sub zones are drawn separately
179 // case "" : the whole zone is drawn at once
180 // in both cases, the rest of the option is passed
181 // as argument to the Draw function of respectively
182 // zone or row objects.
185 AliMpGraphContext *gr = AliMpGraphContext::Instance();
193 for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){
194 AliMpSubZone *subZone = fZone->GetSubZone(iSubZone);
197 Double_t blx= 9999, bly= 9999;
198 Double_t urx= -9999, ury= -9999;
200 for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
201 AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
203 TVector2 bl = rowSegment->Position();
204 bl-=rowSegment->Dimensions();
205 TVector2 ur = rowSegment->Position();
206 ur+=rowSegment->Dimensions();
208 if (bl.X()<blx) blx=bl.X();
209 if (bl.Y()<bly) bly=bl.Y();
210 if (ur.X()>urx) urx=ur.X();
211 if (ur.Y()>ury) ury=ur.Y();
213 TVector2 position ( (urx+blx)/2.,(ury+bly)/2. );
214 TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. );
216 gr->SetPadPosForReal(position,dimensions);
217 gr->SetColor((fZone->GetID()-1)*5+iSubZone+2);
218 DrawObject(subZone,option+1);
224 default: AppendPad(option);
229 //_______________________________________________________________________
230 void AliMpZonePainter::Paint(Option_t *option)
233 AliMpGraphContext *gr = AliMpGraphContext::Instance();
235 if (fZone->GetNofSubZones()<1) return;
237 gPad->Range(0.,0.,1.,1.);
239 Int_t col=gVirtualX->GetFillColor();
242 gVirtualX->SetFillColor(GetColor());
243 Float_t textSize = gVirtualX->GetTextSize();
244 for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){
245 AliMpSubZone *subZone = fZone->GetSubZone(iSubZone);
246 for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
247 AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
249 gr->RealToPad(rowSegment->Position(),rowSegment->Dimensions(),
251 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
252 pos.X()+dim.X(),pos.Y()+dim.Y());
254 gVirtualX->SetTextSize(15);
255 gPad->PaintText(pos.X()-0.01,pos.Y()-0.01,
256 Form("%d",fZone->GetID()));
260 gVirtualX->SetTextSize(textSize);
261 gVirtualX->SetFillColor(col);