]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpSubZonePainter.cxx
Previous commit had the bad side-effect of changing the behaviour of Raw QA to comput...
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSubZonePainter.cxx
CommitLineData
dee1d5f1 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
5f91c9e8 16// $Id$
13985652 17// $MpId: AliMpSubZonePainter.cxx,v 1.8 2006/05/24 13:58:32 ivana Exp $
5f91c9e8 18// Category: graphics
3d1463c8 19
20//-----------------------------------------------------------------------------
5f91c9e8 21// Class AliMpSubZonePainter
22// -------------------------
23// Class for drawing a subzone into canvas
dbe945cc 24// Included in AliRoot: 2003/05/02
5f91c9e8 25// Authors: David Guez, IPN Orsay
3d1463c8 26//-----------------------------------------------------------------------------
5f91c9e8 27
28#include "AliMpSubZonePainter.h"
29#include "AliMpGraphContext.h"
30#include "AliMpSubZone.h"
31#include "AliMpVRowSegment.h"
32#include "AliMpVMotif.h"
33
2c605e66 34#include <TVirtualX.h>
35#include <TPad.h>
36
13985652 37/// \cond CLASSIMP
5f91c9e8 38ClassImp(AliMpSubZonePainter)
13985652 39/// \endcond
5f91c9e8 40
41//_______________________________________________________________________
42AliMpSubZonePainter::AliMpSubZonePainter()
43 : AliMpVPainter(),
44 fSubZone(0)
45{
dee1d5f1 46 /// Default constructor
5f91c9e8 47}
fb1bf5c0 48
5f91c9e8 49//_______________________________________________________________________
50AliMpSubZonePainter::AliMpSubZonePainter(AliMpSubZone *subZone)
51 : AliMpVPainter(),
52 fSubZone(subZone)
53{
dee1d5f1 54 /// Standard constructor
5f91c9e8 55
56}
fb1bf5c0 57
5f91c9e8 58//_______________________________________________________________________
2998a151 59AliMpSubZonePainter::~AliMpSubZonePainter()
60{
dee1d5f1 61 /// Destructor
2998a151 62}
fb1bf5c0 63
2998a151 64//_______________________________________________________________________
5f91c9e8 65Int_t AliMpSubZonePainter::DistancetoPrimitive(Int_t x, Int_t y)
66{
dee1d5f1 67 /// Dist to the nearest segment center if (x,y) is inside the sub-zone
68 /// 9999 otherwise
69
5f91c9e8 70 if (fSubZone->GetNofRowSegments()<1) return 9999;
71 AliMpGraphContext *gr = AliMpGraphContext::Instance();
72
73 gr->Push();
74 InitGraphContext();
75
76
77 TVector2 point = TVector2(gPad->AbsPixeltoX(x), gPad->AbsPixeltoY(y));
78
79 Double_t res=9999.;
80 for (Int_t iseg=0;iseg<fSubZone->GetNofRowSegments();++iseg){
81 //for each row segments
82 AliMpVRowSegment* seg = fSubZone->GetRowSegment(iseg);
83
84 TVector2 pos,dim;
6e97fbb8 85 gr->RealToPad(TVector2(seg->GetPositionX(), seg->GetPositionY()),
86 TVector2(seg->GetDimensionX(),seg->GetDimensionY()),pos,dim);
5f91c9e8 87
88 if ( IsInside(point,pos,dim) ){
89 Double_t value = (point-pos).Mod();
90 if (value<res) res=value;
91 }
92 }
93 gr->Pop();
94 return (Int_t)res;
95}
96
97//_______________________________________________________________________
98void AliMpSubZonePainter::DumpObject()
99{
f5671fc3 100 /// Draw the owned object
dee1d5f1 101
5f91c9e8 102 fSubZone->Dump();
5f91c9e8 103}
dee1d5f1 104
5f91c9e8 105//_______________________________________________________________________
106TVector2 AliMpSubZonePainter::GetPosition() const
107{
f5671fc3 108 /// Get the owned object's position
5f91c9e8 109
110 if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
111 AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
112
113 // bl = bottom left position;
6e97fbb8 114 TVector2 bl = TVector2(seg->GetPositionX(), seg->GetPositionY()) -
115 TVector2(seg->GetDimensionX(),seg->GetDimensionY());
5f91c9e8 116 // ur = upper right position
6e97fbb8 117 TVector2 ur = TVector2(seg->GetPositionX(), seg->GetPositionY()) +
118 TVector2(seg->GetDimensionX(),seg->GetDimensionY());
5f91c9e8 119
120 for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
121 seg = fSubZone->GetRowSegment(iseg);
122 // update the bottom-left corner
6e97fbb8 123 if (bl.X()>seg->GetPositionX()-seg->GetDimensionX())
124 bl.Set(seg->GetPositionX()-seg->GetDimensionX(),bl.Y());
125 if (bl.Y()>seg->GetPositionY()-seg->GetDimensionY())
126 bl.Set(bl.X(),seg->GetPositionY()-seg->GetDimensionY());
5f91c9e8 127 // update the upper-right corner
6e97fbb8 128 if (ur.X()<seg->GetPositionX()+seg->GetDimensionX())
129 ur.Set(seg->GetPositionX()+seg->GetDimensionX(),ur.Y());
130 if (ur.Y()<seg->GetPositionY()+seg->GetDimensionY())
131 ur.Set(ur.X(),seg->GetPositionY()+seg->GetDimensionY());
5f91c9e8 132 }
133 return (ur+bl)/2.;
134}
dee1d5f1 135
5f91c9e8 136//_______________________________________________________________________
137TVector2 AliMpSubZonePainter::GetDimensions() const
138{
f5671fc3 139 /// Get the owned object's dimensions
5f91c9e8 140
141 if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
142 AliMpVRowSegment* seg = fSubZone->GetRowSegment(0);
143
144 // bl = bottom left position;
6e97fbb8 145 TVector2 bl = TVector2(seg->GetPositionX(), seg->GetPositionY()) -
146 TVector2(seg->GetDimensionX(),seg->GetDimensionY());
5f91c9e8 147 // ur = upper right position
6e97fbb8 148 TVector2 ur = TVector2(seg->GetPositionX(), seg->GetPositionY()) +
149 TVector2(seg->GetDimensionX(),seg->GetDimensionY());
5f91c9e8 150
151 for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
152 seg = fSubZone->GetRowSegment(iseg);
153 // update the bottom-left corner
6e97fbb8 154 if (bl.X()>seg->GetPositionX()-seg->GetDimensionX())
155 bl.Set(seg->GetPositionX()-seg->GetDimensionX(),bl.Y());
156 if (bl.Y()>seg->GetPositionY()-seg->GetDimensionY())
157 bl.Set(bl.X(),seg->GetPositionY()-seg->GetDimensionY());
5f91c9e8 158 // update the upper-right corner
6e97fbb8 159 if (ur.X()<seg->GetPositionX()+seg->GetDimensionX())
160 ur.Set(seg->GetPositionX()+seg->GetDimensionX(),ur.Y());
161 if (ur.Y()<seg->GetPositionY()+seg->GetDimensionY())
162 ur.Set(ur.X(),seg->GetPositionY()+seg->GetDimensionY());
5f91c9e8 163 }
164 return (ur-bl)/2.;
165}
dee1d5f1 166
5f91c9e8 167//_______________________________________________________________________
168void AliMpSubZonePainter::Draw(Option_t *option)
169{
dee1d5f1 170/// Draw the sector on the current pad
13985652 171/// The first letter of \a option is treated as follows:
dee1d5f1 172/// - case "S" : each row segments are drawn separately
173/// - case "" : the whole subzone is drawn at once
174/// in both cases, the rest of the option is passed
175/// as argument to the Draw function of respectively
176/// zone or row objects.
5f91c9e8 177
178 if (!fSubZone) return;
179 AliMpGraphContext *gr = AliMpGraphContext::Instance();
180
181 gr->Push();
182 InitGraphContext();
183 switch (option[0]){
184 case 'S':
185 {
186
187 for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
188 gr->Push();
6e97fbb8 189 AliMpVRowSegment* rowSegment = fSubZone->GetRowSegment(iRowSeg);
5f91c9e8 190
6e97fbb8 191 gr->SetPadPosForReal(TVector2(rowSegment->GetPositionX(),rowSegment->GetPositionY()),
192 TVector2(rowSegment->GetDimensionX(),rowSegment->GetDimensionY()));
5f91c9e8 193 gr->SetColor(GetColor());
194 DrawObject(rowSegment,option+1);
195
196 gr->Pop();
197 }
198 }
199 break;
200 default: AppendPad(option);
201 }
202 gr->Pop();
203}
204
205
206//_______________________________________________________________________
207void AliMpSubZonePainter::Paint(Option_t *option)
208{
f5671fc3 209/// Paint the object
dee1d5f1 210
5f91c9e8 211 AliMpGraphContext *gr = AliMpGraphContext::Instance();
212 if (!fSubZone) return;
213 if (fSubZone->GetNofRowSegments()<1) return;
214 gr->Push();
215 gPad->Range(0.,0.,1.,1.);
216 Int_t col=gVirtualX->GetFillColor();
217 InitGraphContext();
218
219 gVirtualX->SetFillColor(GetColor());
220 for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
221 AliMpVRowSegment *rowSegment = fSubZone->GetRowSegment(iRowSeg);
222 TVector2 pos,dim;
6e97fbb8 223 gr->RealToPad(TVector2(rowSegment->GetPositionX(),rowSegment->GetPositionY()),
224 TVector2(rowSegment->GetDimensionX(),rowSegment->GetDimensionY()),
5f91c9e8 225 pos,dim);
226 gPad->PaintBox(pos.X()-dim.X(),pos.Y()-dim.Y(),
227 pos.X()+dim.X(),pos.Y()+dim.Y());
228 if (option[0]=='T'){
229 Float_t textSize = gVirtualX->GetTextSize();
230 gVirtualX->SetTextSize(15);
231 gPad->PaintText(pos.X()-0.01,pos.Y()-0.01,
232 fSubZone->GetMotif()->GetID());
233 gVirtualX->SetTextSize(textSize);
234 }
235 }
236
237 gVirtualX->SetFillColor(col);
238 gr->Pop();
239}