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 = row->Position()-row->Dimensions();
82 // ur = upper right position
83 TVector2 ur = row->Position()+row->Dimensions();;
85 for (Int_t irow=1;irow<fSector->GetNofRows();++irow){
86 row = fSector->GetRow(irow);
87 // update the bottom-left corner
88 if (bl.X()>row->Position().X()-row->Dimensions().X())
89 bl.Set(row->Position().X()-row->Position().X(),bl.Y());
90 if (bl.Y()>row->Position().Y()-row->Dimensions().Y())
91 bl.Set(bl.X(),row->Position().Y()-row->Dimensions().Y());
92 // update the upper-right corner
93 if (ur.X()<row->Position().X()+row->Dimensions().X())
94 ur.Set(row->Position().X()+row->Dimensions().X(),ur.Y());
95 if (ur.Y()<row->Position().Y()+row->Dimensions().Y())
96 ur.Set(ur.X(),row->Position().Y()+row->Dimensions().Y());
101 //_______________________________________________________________________
102 TVector2 AliMpSectorPainter::GetDimensions() const
104 /// Get the owned object's dimensions
106 if (fSector->GetNofRows()<1) return TVector2(0.,0.);
107 AliMpRow* row = fSector->GetRow(0);
110 // bl = bottom left position
111 TVector2 bl = row->Position()-row->Dimensions();
112 // ur = upper right position
113 TVector2 ur = row->Position()+row->Dimensions();
115 for (Int_t irow=1;irow<fSector->GetNofRows();++irow){
116 row = fSector->GetRow(irow);
117 // update the bottom-left corner
118 if (bl.X()>row->Position().X()-row->Dimensions().X())
119 bl.Set(row->Position().X()-row->Dimensions().X(),bl.Y());
120 if (bl.Y()>row->Position().Y()-row->Dimensions().Y())
121 bl.Set(bl.X(),row->Position().Y()-row->Dimensions().Y());
122 // update the upper-right corner
123 if (ur.X()<row->Position().X()+row->Dimensions().X())
124 ur.Set(row->Position().X()+row->Dimensions().X(),ur.Y());
125 if (ur.Y()<row->Position().Y()+row->Dimensions().Y())
126 ur.Set(ur.X(),row->Position().Y()+row->Dimensions().Y());
131 //_______________________________________________________________________
132 void AliMpSectorPainter::Draw(Option_t *option)
134 /// Draw the sector on the current pad
135 /// The first letter of \a option is treated as follows:
136 /// - case "Z" : each zones are drawn separately
137 /// - case "R" : each rows are drawn separately
138 /// - case "" : the whole sector is drawn at once
139 /// in both cases, the rest of the option is passed
140 /// as argument to the Draw function of respectively
141 /// zone or row objects.
143 AliMpGraphContext *gr = AliMpGraphContext::Instance();
144 if (!fSector) return;
151 for (Int_t iZone=1;iZone<=fSector->GetNofZones();++iZone){
152 AliMpZone *zone = fSector->GetZone(iZone);
155 Double_t blx= 9999, bly= 9999;
156 Double_t urx= -9999, ury= -9999;
158 for (Int_t iSubZone=0;iSubZone<zone->GetNofSubZones();++iSubZone){
159 AliMpSubZone *subZone = zone->GetSubZone(iSubZone);
160 for (Int_t iRowSeg=0;iRowSeg<subZone->GetNofRowSegments();++iRowSeg){
161 AliMpVRowSegment *rowSegment = subZone->GetRowSegment(iRowSeg);
163 TVector2 bl = rowSegment->Position()-rowSegment->Dimensions();
164 TVector2 ur = rowSegment->Position()+rowSegment->Dimensions();
166 if (bl.X()<blx) blx=bl.X();
167 if (bl.Y()<bly) bly=bl.Y();
168 if (ur.X()>urx) urx=ur.X();
169 if (ur.Y()>ury) ury=ur.Y();
172 TVector2 position ( (urx+blx)/2.,(ury+bly)/2. );
173 TVector2 dimensions( (urx-blx)/2.,(ury-bly)/2. );
175 gr->SetPadPosForReal(position,dimensions);
176 gr->SetColor(iZone+3);
177 DrawObject(zone,option+1);
185 for (Int_t iRow=0;iRow<fSector->GetNofRows();++iRow){
186 AliMpRow *row = fSector->GetRow(iRow);
188 gr->SetPadPosForReal(row->Position(),row->Dimensions());
189 DrawObject(row,option+1);
194 default: AppendPad(option);
199 //_______________________________________________________________________
200 void AliMpSectorPainter::Paint(Option_t* /*option*/)
204 AliMpGraphContext *gr = AliMpGraphContext::Instance();
205 if (!fSector) return;
206 if (fSector->GetNofRows()<1) return;
207 Int_t col=gVirtualX->GetFillColor();
210 gPad->Range(0.,0.,1.,1.);
216 for (iRow=0;iRow<fSector->GetNofRows();++iRow){
217 AliMpRow *row = fSector->GetRow(iRow);
219 gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
220 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
221 pos.X()+dim.X(),pos.Y()+dim.Y());
222 gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),
223 pos.X()-dim.X(),pos.Y()+dim.Y());
224 gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(),
225 pos.X()+dim.X(),pos.Y()+dim.Y());
228 gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),lx1,pos.Y()-dim.Y());
229 gPad->PaintLine(pos.X()+dim.X(),pos.Y()-dim.Y(),lx2,pos.Y()-dim.Y());
235 // now we draw the lower and upper horizontal lines
237 AliMpRow *row = fSector->GetRow(0);
239 gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
240 gPad->PaintLine(pos.X()-dim.X(),pos.Y()-dim.Y(),
241 pos.X()+dim.X(),pos.Y()-dim.Y());
243 row = fSector->GetRow(fSector->GetNofRows()-1);
244 gr->RealToPad(row->Position(),row->Dimensions(),pos,dim);
245 gPad->PaintLine(pos.X()-dim.X(),pos.Y()+dim.Y(),
246 pos.X()+dim.X(),pos.Y()+dim.Y());
249 gVirtualX->SetFillColor(col);