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.7 2006/03/17 11:35:29 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>
35 ClassImp(AliMpZonePainter)
37 //_______________________________________________________________________
38 AliMpZonePainter::AliMpZonePainter()
42 /// Default constructor
45 //_______________________________________________________________________
46 AliMpZonePainter::AliMpZonePainter(AliMpZone *zone)
50 /// Standard constructor
54 //_____________________________________________________________________________
55 AliMpZonePainter::AliMpZonePainter(const AliMpZonePainter& right)
56 : AliMpVPainter(right)
58 /// Protected copy constructor (not provided)
60 Fatal("AliMpZonePainter", "Copy constructor not provided.");
63 //_______________________________________________________________________
64 AliMpZonePainter::~AliMpZonePainter()
69 //_____________________________________________________________________________
71 AliMpZonePainter::operator=(const AliMpZonePainter& right)
73 /// Assignment operator (not provided)
75 // check assignment to self
76 if (this == &right) return *this;
78 Fatal("operator =", "Assignment operator not provided.");
83 //_______________________________________________________________________
84 Int_t AliMpZonePainter::DistancetoPrimitive(Int_t x, Int_t y)
86 /// Distance to the nearest segment center if (x,y) is inside the zone
89 if (fZone->GetNofSubZones()<1) return 9999;
90 AliMpGraphContext *gr = AliMpGraphContext::Instance();
95 TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
98 for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
100 AliMpSubZone* sub = fZone->GetSubZone(isub);
101 for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
102 //for each row segments
103 AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
106 gr->RealToPad(seg->Position(),seg->Dimensions(),pos,dim);
108 if ( IsInside(point,pos,dim) ){
109 Double_t value = (point-pos).Mod();
110 if (value<res) res=value;
118 //_______________________________________________________________________
119 void AliMpZonePainter::DumpObject()
121 /// Dump the owned object
126 //_______________________________________________________________________
127 TVector2 AliMpZonePainter::GetPosition() const
129 //// Get the owned object's position
131 if (fZone->GetNofSubZones()<1) return TVector2(0.,0.);
133 TVector2 bl(9999,9999),ur(-9999,-9999);
135 for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
136 // for each sub-zones
137 AliMpSubZone* sub = fZone->GetSubZone(isub);
138 for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
139 //for each row segments
140 AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
142 // update the bottom-left corner
143 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
144 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
145 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
146 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
147 // update the upper-right corner
148 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
149 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
150 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
151 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
157 //_______________________________________________________________________
158 TVector2 AliMpZonePainter::GetDimensions() const
160 //// Get the owned object's dimensions
162 if (fZone->GetNofSubZones()<1) return TVector2(0.,0.);
164 TVector2 bl(9999,9999),ur(-9999,-9999);
166 for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
167 // for each sub-zones
168 AliMpSubZone* sub = fZone->GetSubZone(isub);
169 for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
170 //for each row segments
171 AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
173 // update the bottom-left corner
174 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
175 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
176 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
177 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
178 // update the upper-right corner
179 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
180 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
181 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
182 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
188 //_______________________________________________________________________
189 void AliMpZonePainter::Draw(Option_t *option)
191 /// Draw the sector on the current pad
192 /// The first letter of <option> is treated as follows:
193 /// - case "S" : each sub zones are drawn separately
194 /// - case "" : the whole zone is drawn at once
195 /// in both cases, the rest of the option is passed
196 /// as argument to the Draw function of respectively
197 /// zone or row objects.
199 AliMpGraphContext *gr = AliMpGraphContext::Instance();
207 for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){
208 AliMpSubZone *subZone = fZone->GetSubZone(iSubZone);
211 Double_t blx= 9999, bly= 9999;
212 Double_t urx= -9999, ury= -9999;
214 for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
215 AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
217 TVector2 bl = rowSegment->Position();
218 bl-=rowSegment->Dimensions();
219 TVector2 ur = rowSegment->Position();
220 ur+=rowSegment->Dimensions();
222 if (bl.X()<blx) blx=bl.X();
223 if (bl.Y()<bly) bly=bl.Y();
224 if (ur.X()>urx) urx=ur.X();
225 if (ur.Y()>ury) ury=ur.Y();
227 TVector2 position ( (urx+blx)/2.,(ury+bly)/2. );
228 TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. );
230 gr->SetPadPosForReal(position,dimensions);
231 gr->SetColor((fZone->GetID()-1)*5+iSubZone+2);
232 DrawObject(subZone,option+1);
238 default: AppendPad(option);
243 //_______________________________________________________________________
244 void AliMpZonePainter::Paint(Option_t *option)
246 //// Paint the object
248 AliMpGraphContext *gr = AliMpGraphContext::Instance();
250 if (fZone->GetNofSubZones()<1) return;
252 gPad->Range(0.,0.,1.,1.);
254 Int_t col=gVirtualX->GetFillColor();
257 gVirtualX->SetFillColor(GetColor());
258 Float_t textSize = gVirtualX->GetTextSize();
259 for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){
260 AliMpSubZone *subZone = fZone->GetSubZone(iSubZone);
261 for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
262 AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
264 gr->RealToPad(rowSegment->Position(),rowSegment->Dimensions(),
266 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
267 pos.X()+dim.X(),pos.Y()+dim.Y());
269 gVirtualX->SetTextSize(15);
270 gPad->PaintText(pos.X()-0.01,pos.Y()-0.01,
271 Form("%d",fZone->GetID()));
275 gVirtualX->SetTextSize(textSize);
276 gVirtualX->SetFillColor(col);