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(TVector2(seg->GetPositionX(), seg->GetPositionY()),
88 TVector2(seg->GetDimensionX(),seg->GetDimensionY()),pos,dim);
90 if ( IsInside(point,pos,dim) ){
91 Double_t value = (point-pos).Mod();
92 if (value<res) res=value;
100 //_______________________________________________________________________
101 void AliMpZonePainter::DumpObject()
103 /// Dump the owned object
108 //_______________________________________________________________________
109 TVector2 AliMpZonePainter::GetPosition() const
111 //// Get the owned object's position
113 if (fZone->GetNofSubZones()<1) return TVector2(0.,0.);
115 TVector2 bl(9999,9999),ur(-9999,-9999);
117 for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
118 // for each sub-zones
119 AliMpSubZone* sub = fZone->GetSubZone(isub);
120 for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
121 //for each row segments
122 AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
124 // update the bottom-left corner
125 if (bl.X()>seg->GetPositionX()-seg->GetDimensionX())
126 bl.Set(seg->GetPositionX()-seg->GetDimensionX(),bl.Y());
127 if (bl.Y()>seg->GetPositionY()-seg->GetDimensionY())
128 bl.Set(bl.X(),seg->GetPositionY()-seg->GetDimensionY());
129 // update the upper-right corner
130 if (ur.X()<seg->GetPositionX()+seg->GetDimensionX())
131 ur.Set(seg->GetPositionX()+seg->GetDimensionX(),ur.Y());
132 if (ur.Y()<seg->GetPositionY()+seg->GetDimensionY())
133 ur.Set(ur.X(),seg->GetPositionY()+seg->GetDimensionY());
139 //_______________________________________________________________________
140 TVector2 AliMpZonePainter::GetDimensions() const
142 //// Get the owned object's dimensions
144 if (fZone->GetNofSubZones()<1) return TVector2(0.,0.);
146 TVector2 bl(9999,9999),ur(-9999,-9999);
148 for (Int_t isub=0;isub<fZone->GetNofSubZones();++isub){
149 // for each sub-zones
150 AliMpSubZone* sub = fZone->GetSubZone(isub);
151 for (Int_t iseg=0;iseg<sub->GetNofRowSegments();++iseg){
152 //for each row segments
153 AliMpVRowSegment* seg = sub->GetRowSegment(iseg);
155 // update the bottom-left corner
156 if (bl.X()>seg->GetPositionX()-seg->GetDimensionX())
157 bl.Set(seg->GetPositionX()-seg->GetDimensionX(),bl.Y());
158 if (bl.Y()>seg->GetPositionY()-seg->GetDimensionY())
159 bl.Set(bl.X(),seg->GetPositionY()-seg->GetDimensionY());
160 // update the upper-right corner
161 if (ur.X()<seg->GetPositionX()+seg->GetDimensionX())
162 ur.Set(seg->GetPositionX()+seg->GetDimensionX(),ur.Y());
163 if (ur.Y()<seg->GetPositionY()+seg->GetDimensionY())
164 ur.Set(ur.X(),seg->GetPositionY()+seg->GetDimensionY());
170 //_______________________________________________________________________
171 void AliMpZonePainter::Draw(Option_t *option)
173 /// Draw the sector on the current pad
174 /// The first letter of \a option is treated as follows:
175 /// - case "S" : each sub zones are drawn separately
176 /// - case "" : the whole zone is drawn at once
177 /// in both cases, the rest of the option is passed
178 /// as argument to the Draw function of respectively
179 /// zone or row objects.
181 AliMpGraphContext *gr = AliMpGraphContext::Instance();
189 for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){
190 AliMpSubZone *subZone = fZone->GetSubZone(iSubZone);
193 Double_t blx= 9999, bly= 9999;
194 Double_t urx= -9999, ury= -9999;
196 for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
197 AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
199 TVector2 bl = TVector2(rowSegment->GetPositionX(),rowSegment->GetPositionY());
200 bl -= TVector2(rowSegment->GetDimensionX(),rowSegment->GetDimensionY());
201 TVector2 ur = TVector2(rowSegment->GetPositionX(),rowSegment->GetPositionY());
202 ur += TVector2(rowSegment->GetDimensionX(),rowSegment->GetDimensionY());
204 if (bl.X()<blx) blx=bl.X();
205 if (bl.Y()<bly) bly=bl.Y();
206 if (ur.X()>urx) urx=ur.X();
207 if (ur.Y()>ury) ury=ur.Y();
209 TVector2 position ( (urx+blx)/2.,(ury+bly)/2. );
210 TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. );
212 gr->SetPadPosForReal(position,dimensions);
213 gr->SetColor((fZone->GetID()-1)*5+iSubZone+2);
214 DrawObject(subZone,option+1);
220 default: AppendPad(option);
225 //_______________________________________________________________________
226 void AliMpZonePainter::Paint(Option_t *option)
228 //// Paint the object
230 AliMpGraphContext *gr = AliMpGraphContext::Instance();
232 if (fZone->GetNofSubZones()<1) return;
234 gPad->Range(0.,0.,1.,1.);
236 Int_t col=gVirtualX->GetFillColor();
239 gVirtualX->SetFillColor(GetColor());
240 Float_t textSize = gVirtualX->GetTextSize();
241 for (Int_t iSubZone=0;iSubZone<fZone->GetNofSubZones();++iSubZone){
242 AliMpSubZone *subZone = fZone->GetSubZone(iSubZone);
243 for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
244 AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
246 gr->RealToPad(TVector2(rowSegment->GetPositionX(),rowSegment->GetPositionY()),
247 TVector2(rowSegment->GetDimensionX(),rowSegment->GetDimensionY()),
249 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
250 pos.X()+dim.X(),pos.Y()+dim.Y());
252 gVirtualX->SetTextSize(15);
253 gPad->PaintText(pos.X()-0.01,pos.Y()-0.01,
254 Form("%d",fZone->GetID()));
258 gVirtualX->SetTextSize(textSize);
259 gVirtualX->SetFillColor(col);