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: AliMpSectorPainter.cxx,v 1.8 2006/05/24 13:58:32 ivana Exp $
19 //-----------------------------------------------------------------------------
20 // Class AliMpSectorPainter
21 // ------------------------
22 // Class for drawing a sector into canvas
23 // Included in AliRoot: 2003/05/02
24 // Authors: David Guez, IPN Orsay
25 //-----------------------------------------------------------------------------
27 #include "AliMpSectorPainter.h"
28 #include "AliMpGraphContext.h"
29 #include "AliMpSector.h"
30 #include "AliMpZone.h"
31 #include "AliMpSubZone.h"
33 #include "AliMpVRowSegment.h"
35 #include <TVirtualX.h>
39 ClassImp(AliMpSectorPainter)
42 //_______________________________________________________________________
43 AliMpSectorPainter::AliMpSectorPainter()
47 /// Default constructor
49 //_______________________________________________________________________
50 AliMpSectorPainter::AliMpSectorPainter(AliMpSector *sector)
54 /// Standard constructor
58 //_______________________________________________________________________
59 AliMpSectorPainter::~AliMpSectorPainter()
64 //_______________________________________________________________________
65 void AliMpSectorPainter::DumpObject()
67 /// Draw the owned object
72 //_______________________________________________________________________
73 TVector2 AliMpSectorPainter::GetPosition() const
75 /// Get the owned object's position
77 if (fSector->GetNofRows()<1) return TVector2(0.,0.);
78 AliMpRow* row = fSector->GetRow(0);
80 // bl = bottom left position;
81 TVector2 bl = TVector2(row->GetPositionX(), row->GetPositionY())-
82 TVector2(row->GetDimensionX(), row->GetDimensionY());
83 // ur = upper right position
84 TVector2 ur = TVector2(row->GetPositionX(), row->GetPositionY())+
85 TVector2(row->GetDimensionX(), row->GetDimensionY());;
87 for (Int_t irow=1;irow<fSector->GetNofRows();++irow){
88 row = fSector->GetRow(irow);
89 // update the bottom-left corner
90 if (bl.X()>row->GetPositionX()-row->GetDimensionX())
91 bl.Set(row->GetPositionX()-row->GetPositionX(),bl.Y());
92 if (bl.Y()>row->GetPositionY()-row->GetDimensionY())
93 bl.Set(bl.X(),row->GetPositionY()-row->GetDimensionY());
94 // update the upper-right corner
95 if (ur.X()<row->GetPositionX()+row->GetDimensionX())
96 ur.Set(row->GetPositionX()+row->GetDimensionX(),ur.Y());
97 if (ur.Y()<row->GetPositionY()+row->GetDimensionY())
98 ur.Set(ur.X(),row->GetPositionY()+row->GetDimensionY());
103 //_______________________________________________________________________
104 TVector2 AliMpSectorPainter::GetDimensions() const
106 /// Get the owned object's dimensions
108 if (fSector->GetNofRows()<1) return TVector2(0.,0.);
109 AliMpRow* row = fSector->GetRow(0);
112 // bl = bottom left position
113 TVector2 bl = TVector2(row->GetPositionX(), row->GetPositionY())-
114 TVector2(row->GetDimensionX(), row->GetDimensionY());
115 // ur = upper right position
116 TVector2 ur = TVector2(row->GetPositionX(), row->GetPositionY())+
117 TVector2(row->GetDimensionX(), row->GetDimensionY());
119 for (Int_t irow=1;irow<fSector->GetNofRows();++irow){
120 row = fSector->GetRow(irow);
121 // update the bottom-left corner
122 if (bl.X()>row->GetPositionX()-row->GetDimensionX())
123 bl.Set(row->GetPositionX()-row->GetDimensionX(),bl.Y());
124 if (bl.Y()>row->GetPositionY()-row->GetDimensionY())
125 bl.Set(bl.X(),row->GetPositionY()-row->GetDimensionY());
126 // update the upper-right corner
127 if (ur.X()<row->GetPositionX()+row->GetDimensionX())
128 ur.Set(row->GetPositionX()+row->GetDimensionX(),ur.Y());
129 if (ur.Y()<row->GetPositionY()+row->GetDimensionY())
130 ur.Set(ur.X(),row->GetPositionY()+row->GetDimensionY());
135 //_______________________________________________________________________
136 void AliMpSectorPainter::Draw(Option_t *option)
138 /// Draw the sector on the current pad
139 /// The first letter of \a option is treated as follows:
140 /// - case "Z" : each zones are drawn separately
141 /// - case "R" : each rows are drawn separately
142 /// - case "" : the whole sector is drawn at once
143 /// in both cases, the rest of the option is passed
144 /// as argument to the Draw function of respectively
145 /// zone or row objects.
147 AliMpGraphContext *gr = AliMpGraphContext::Instance();
148 if (!fSector) return;
155 for (Int_t iZone=1;iZone<=fSector->GetNofZones();++iZone){
156 AliMpZone *zone = fSector->GetZone(iZone);
159 Double_t blx= 9999, bly= 9999;
160 Double_t urx= -9999, ury= -9999;
162 for (Int_t iSubZone=0;iSubZone<zone->GetNofSubZones();++iSubZone){
163 AliMpSubZone *subZone = zone->GetSubZone(iSubZone);
164 for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
165 AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
167 TVector2 bl = TVector2(rowSegment->GetPositionX(),
168 rowSegment->GetPositionY()) -
169 TVector2(rowSegment->GetDimensionX(),
170 rowSegment->GetDimensionY());
171 TVector2 ur = TVector2(rowSegment->GetPositionX(),
172 rowSegment->GetPositionY())+
173 TVector2(rowSegment->GetDimensionX(),
174 rowSegment->GetDimensionY());
176 if (bl.X()<blx) blx=bl.X();
177 if (bl.Y()<bly) bly=bl.Y();
178 if (ur.X()>urx) urx=ur.X();
179 if (ur.Y()>ury) ury=ur.Y();
182 TVector2 position ( (urx+blx)/2.,(ury+bly)/2. );
183 TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. );
185 gr->SetPadPosForReal(position,dimensions);
186 gr->SetColor(iZone+3);
187 DrawObject(zone,option+1);
195 for (Int_t iRow=0;iRow<fSector->GetNofRows();++iRow){
196 AliMpRow *row = fSector->GetRow(iRow);
198 gr->SetPadPosForReal(TVector2(row->GetPositionX(), row->GetPositionY()),
199 TVector2(row->GetDimensionX(), row->GetDimensionY()));
200 DrawObject(row,option+1);
205 default: AppendPad(option);
210 //_______________________________________________________________________
211 void AliMpSectorPainter::Paint(Option_t* /*option*/)
215 AliMpGraphContext *gr = AliMpGraphContext::Instance();
216 if (!fSector) return;
217 if (fSector->GetNofRows()<1) return;
218 Int_t col=gVirtualX->GetFillColor();
221 gPad->Range(0.,0.,1.,1.);
227 for (iRow=0;iRow<fSector->GetNofRows();++iRow){
228 AliMpRow *row = fSector->GetRow(iRow);
230 gr->RealToPad(TVector2(row->GetPositionX(), row->GetPositionY()),
231 TVector2(row->GetDimensionX(), row->GetDimensionY()),pos,dim);
232 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
233 pos.X()+dim.X(),pos.Y()+dim.Y());
234 gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),
235 pos.X()-dim.X(),pos.Y()+dim.Y());
236 gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(),
237 pos.X()+dim.X(),pos.Y()+dim.Y());
240 gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),lx1,pos.Y()-dim.Y());
241 gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(),lx2,pos.Y()-dim.Y());
247 // now we draw the lower and upper horizontal lines
249 AliMpRow *row = fSector->GetRow(0);
251 gr->RealToPad(TVector2(row->GetPositionX(), row->GetPositionY()),
252 TVector2(row->GetDimensionX(), row->GetDimensionY()),pos,dim);
253 gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),
254 pos.X()+dim.X(),pos.Y()-dim.Y());
256 row = fSector->GetRow(fSector->GetNofRows()-1);
257 gr->RealToPad(TVector2(row->GetPositionX(), row->GetPositionY()),
258 TVector2(row->GetDimensionX(), row->GetDimensionY()),pos,dim);
259 gPad->PaintLine(pos.X()-dim.X(),pos.Y()+dim.Y(),
260 pos.X()+dim.X(),pos.Y()+dim.Y());
263 gVirtualX->SetFillColor(col);