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 //-----------------------------------------------------------------------------
21 // Class AliMpZonePainter
22 // ----------------------
23 // Class for drawing a zone into canvas
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, IPN Orsay
26 //-----------------------------------------------------------------------------
28 #include "AliMpZonePainter.h"
29 #include "AliMpGraphContext.h"
30 #include "AliMpZone.h"
31 #include "AliMpSubZone.h"
32 #include "AliMpVRowSegment.h"
34 #include <TVirtualX.h>
38 ClassImp(AliMpZonePainter)
41 //_______________________________________________________________________
42 AliMpZonePainter::AliMpZonePainter()
46 /// Default constructor
49 //_______________________________________________________________________
50 AliMpZonePainter::AliMpZonePainter(AliMpZone *zone)
54 /// Standard constructor
58 //_______________________________________________________________________
59 AliMpZonePainter::~AliMpZonePainter()
64 //_______________________________________________________________________
65 Int_t AliMpZonePainter::DistancetoPrimitive(Int_t x, Int_t y)
67 /// Distance to the nearest segment center if (x,y) is inside the zone
70 if (fZone->GetNofSubZones()<1) return 9999;
71 AliMpGraphContext *gr = AliMpGraphContext::Instance();
76 TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
79 for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
81 AliMpSubZone* sub = fZone->GetSubZone(isub);
82 for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
83 //for each row segments
84 AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
87 gr->RealToPad(seg->Position(),seg->Dimensions(),pos,dim);
89 if ( IsInside(point,pos,dim) ){
90 Double_t value = (point-pos).Mod();
91 if (value<res) res=value;
99 //_______________________________________________________________________
100 void AliMpZonePainter::DumpObject()
102 /// Dump the owned object
107 //_______________________________________________________________________
108 TVector2 AliMpZonePainter::GetPosition() const
110 //// Get the owned object's position
112 if (fZone->GetNofSubZones()<1) return TVector2(0.,0.);
114 TVector2 bl(9999,9999),ur(-9999,-9999);
116 for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
117 // for each sub-zones
118 AliMpSubZone* sub = fZone->GetSubZone(isub);
119 for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
120 //for each row segments
121 AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
123 // update the bottom-left corner
124 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
125 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
126 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
127 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
128 // update the upper-right corner
129 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
130 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
131 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
132 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
138 //_______________________________________________________________________
139 TVector2 AliMpZonePainter::GetDimensions() const
141 //// Get the owned object's dimensions
143 if (fZone->GetNofSubZones()<1) return TVector2(0.,0.);
145 TVector2 bl(9999,9999),ur(-9999,-9999);
147 for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
148 // for each sub-zones
149 AliMpSubZone* sub = fZone->GetSubZone(isub);
150 for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
151 //for each row segments
152 AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
154 // update the bottom-left corner
155 if (bl.X()>seg->Position().X()-seg->Dimensions().X())
156 bl.Set(seg->Position().X()-seg->Dimensions().X(),bl.Y());
157 if (bl.Y()>seg->Position().Y()-seg->Dimensions().Y())
158 bl.Set(bl.X(),seg->Position().Y()-seg->Dimensions().Y());
159 // update the upper-right corner
160 if (ur.X()<seg->Position().X()+seg->Dimensions().X())
161 ur.Set(seg->Position().X()+seg->Dimensions().X(),ur.Y());
162 if (ur.Y()<seg->Position().Y()+seg->Dimensions().Y())
163 ur.Set(ur.X(),seg->Position().Y()+seg->Dimensions().Y());
169 //_______________________________________________________________________
170 void AliMpZonePainter::Draw(Option_t *option)
172 /// Draw the sector on the current pad
173 /// The first letter of \a option is treated as follows:
174 /// - case "S" : each sub zones are drawn separately
175 /// - case "" : the whole zone is drawn at once
176 /// in both cases, the rest of the option is passed
177 /// as argument to the Draw function of respectively
178 /// zone or row objects.
180 AliMpGraphContext *gr = AliMpGraphContext::Instance();
188 for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){
189 AliMpSubZone *subZone = fZone->GetSubZone(iSubZone);
192 Double_t blx= 9999, bly= 9999;
193 Double_t urx= -9999, ury= -9999;
195 for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
196 AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
198 TVector2 bl = rowSegment->Position();
199 bl-=rowSegment->Dimensions();
200 TVector2 ur = rowSegment->Position();
201 ur+=rowSegment->Dimensions();
203 if (bl.X()<blx) blx=bl.X();
204 if (bl.Y()<bly) bly=bl.Y();
205 if (ur.X()>urx) urx=ur.X();
206 if (ur.Y()>ury) ury=ur.Y();
208 TVector2 position ( (urx+blx)/2.,(ury+bly)/2. );
209 TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. );
211 gr->SetPadPosForReal(position,dimensions);
212 gr->SetColor((fZone->GetID()-1)*5+iSubZone+2);
213 DrawObject(subZone,option+1);
219 default: AppendPad(option);
224 //_______________________________________________________________________
225 void AliMpZonePainter::Paint(Option_t *option)
227 //// Paint the object
229 AliMpGraphContext *gr = AliMpGraphContext::Instance();
231 if (fZone->GetNofSubZones()<1) return;
233 gPad->Range(0.,0.,1.,1.);
235 Int_t col=gVirtualX->GetFillColor();
238 gVirtualX->SetFillColor(GetColor());
239 Float_t textSize = gVirtualX->GetTextSize();
240 for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){
241 AliMpSubZone *subZone = fZone->GetSubZone(iSubZone);
242 for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
243 AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
245 gr->RealToPad(rowSegment->Position(),rowSegment->Dimensions(),
247 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
248 pos.X()+dim.X(),pos.Y()+dim.Y());
250 gVirtualX->SetTextSize(15);
251 gPad->PaintText(pos.X()-0.01,pos.Y()-0.01,
252 Form("%d",fZone->GetID()));
256 gVirtualX->SetTextSize(textSize);
257 gVirtualX->SetFillColor(col);