1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpZonePainter.cxx,v 1.8 2006/05/24 13:58:32 ivana Exp $
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
26 #include "AliMpZonePainter.h"
27 #include "AliMpGraphContext.h"
28 #include "AliMpZone.h"
29 #include "AliMpSubZone.h"
30 #include "AliMpVRowSegment.h"
32 #include <TVirtualX.h>
36 ClassImp(AliMpZonePainter)
39 //_______________________________________________________________________
40 AliMpZonePainter::AliMpZonePainter()
44 /// Default constructor
47 //_______________________________________________________________________
48 AliMpZonePainter::AliMpZonePainter(AliMpZone *zone)
52 /// Standard constructor
56 //_______________________________________________________________________
57 AliMpZonePainter::~AliMpZonePainter()
62 //_______________________________________________________________________
63 Int_t AliMpZonePainter::DistancetoPrimitive(Int_t x, Int_t y)
65 /// Distance to the nearest segment center if (x,y) is inside the zone
68 if (fZone->GetNofSubZones()<1) return 9999;
69 AliMpGraphContext *gr = AliMpGraphContext::Instance();
74 TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
77 for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
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);
85 gr->RealToPad(seg->Position(),seg->Dimensions(),pos,dim);
87 if ( IsInside(point,pos,dim) ){
88 Double_t value = (point-pos).Mod();
89 if (value<res) res=value;
97 //_______________________________________________________________________
98 void AliMpZonePainter::DumpObject()
100 /// Dump the owned object
105 //_______________________________________________________________________
106 TVector2 AliMpZonePainter::GetPosition() const
108 //// Get the owned object's position
110 if (fZone->GetNofSubZones()<1) return TVector2(0.,0.);
112 TVector2 bl(9999,9999),ur(-9999,-9999);
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);
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());
136 //_______________________________________________________________________
137 TVector2 AliMpZonePainter::GetDimensions() const
139 //// Get the owned object's dimensions
141 if (fZone->GetNofSubZones()<1) return TVector2(0.,0.);
143 TVector2 bl(9999,9999),ur(-9999,-9999);
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);
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());
167 //_______________________________________________________________________
168 void AliMpZonePainter::Draw(Option_t *option)
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.
178 AliMpGraphContext *gr = AliMpGraphContext::Instance();
186 for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){
187 AliMpSubZone *subZone = fZone->GetSubZone(iSubZone);
190 Double_t blx= 9999, bly= 9999;
191 Double_t urx= -9999, ury= -9999;
193 for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
194 AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
196 TVector2 bl = rowSegment->Position();
197 bl-=rowSegment->Dimensions();
198 TVector2 ur = rowSegment->Position();
199 ur+=rowSegment->Dimensions();
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();
206 TVector2 position ( (urx+blx)/2.,(ury+bly)/2. );
207 TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. );
209 gr->SetPadPosForReal(position,dimensions);
210 gr->SetColor((fZone->GetID()-1)*5+iSubZone+2);
211 DrawObject(subZone,option+1);
217 default: AppendPad(option);
222 //_______________________________________________________________________
223 void AliMpZonePainter::Paint(Option_t *option)
225 //// Paint the object
227 AliMpGraphContext *gr = AliMpGraphContext::Instance();
229 if (fZone->GetNofSubZones()<1) return;
231 gPad->Range(0.,0.,1.,1.);
233 Int_t col=gVirtualX->GetFillColor();
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);
243 gr->RealToPad(rowSegment->Position(),rowSegment->Dimensions(),
245 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
246 pos.X()+dim.X(),pos.Y()+dim.Y());
248 gVirtualX->SetTextSize(15);
249 gPad->PaintText(pos.X()-0.01,pos.Y()-0.01,
250 Form("%d",fZone->GetID()));
254 gVirtualX->SetTextSize(textSize);
255 gVirtualX->SetFillColor(col);