AliRoot Core  v5-06-15 (45dab64)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMpSubZonePainter.cxx
Go to the documentation of this file.
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 
16 // $Id$
17 // $MpId: AliMpSubZonePainter.cxx,v 1.8 2006/05/24 13:58:32 ivana Exp $
18 // Category: graphics
19 
20 //-----------------------------------------------------------------------------
21 // Class AliMpSubZonePainter
22 // -------------------------
23 // Class for drawing a subzone into canvas
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, IPN Orsay
26 //-----------------------------------------------------------------------------
27 
28 #include "AliMpSubZonePainter.h"
29 #include "AliMpGraphContext.h"
30 #include "AliMpSubZone.h"
31 #include "AliMpVRowSegment.h"
32 #include "AliMpVMotif.h"
33 
34 #include <TVirtualX.h>
35 #include <TPad.h>
36 
40 
41 //_______________________________________________________________________
43  : AliMpVPainter(),
44  fSubZone(0)
45 {
47 }
48 
49 //_______________________________________________________________________
51  : AliMpVPainter(),
52  fSubZone(subZone)
53 {
55 
56 }
57 
58 //_______________________________________________________________________
60 {
62 }
63 
64 //_______________________________________________________________________
66 {
69 
70  if (fSubZone->GetNofRowSegments()<1) return 9999;
72 
73  gr->Push();
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
83 
84  TVector2 pos,dim;
85  gr->RealToPad(TVector2(seg->GetPositionX(), seg->GetPositionY()),
86  TVector2(seg->GetDimensionX(),seg->GetDimensionY()),pos,dim);
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 //_______________________________________________________________________
99 {
101 
102  fSubZone->Dump();
103 }
104 
105 //_______________________________________________________________________
107 {
109 
110  if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
112 
113  // bl = bottom left position;
114  TVector2 bl = TVector2(seg->GetPositionX(), seg->GetPositionY()) -
115  TVector2(seg->GetDimensionX(),seg->GetDimensionY());
116  // ur = upper right position
117  TVector2 ur = TVector2(seg->GetPositionX(), seg->GetPositionY()) +
118  TVector2(seg->GetDimensionX(),seg->GetDimensionY());
119 
120  for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
121  seg = fSubZone->GetRowSegment(iseg);
122  // update the bottom-left corner
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());
127  // update the upper-right corner
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());
132  }
133  return (ur+bl)/2.;
134 }
135 
136 //_______________________________________________________________________
138 {
140 
141  if (fSubZone->GetNofRowSegments()<1) return TVector2(0.,0.);
143 
144  // bl = bottom left position;
145  TVector2 bl = TVector2(seg->GetPositionX(), seg->GetPositionY()) -
146  TVector2(seg->GetDimensionX(),seg->GetDimensionY());
147  // ur = upper right position
148  TVector2 ur = TVector2(seg->GetPositionX(), seg->GetPositionY()) +
149  TVector2(seg->GetDimensionX(),seg->GetDimensionY());
150 
151  for (Int_t iseg=1;iseg<fSubZone->GetNofRowSegments();++iseg){
152  seg = fSubZone->GetRowSegment(iseg);
153  // update the bottom-left corner
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());
158  // update the upper-right corner
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());
163  }
164  return (ur-bl)/2.;
165 }
166 
167 //_______________________________________________________________________
168 void AliMpSubZonePainter::Draw(Option_t *option)
169 {
177 
178  if (!fSubZone) return;
180 
181  gr->Push();
183  switch (option[0]){
184  case 'S':
185  {
186 
187  for (Int_t iRowSeg=0;iRowSeg<fSubZone->GetNofRowSegments();++iRowSeg){
188  gr->Push();
189  AliMpVRowSegment* rowSegment = fSubZone->GetRowSegment(iRowSeg);
190 
191  gr->SetPadPosForReal(TVector2(rowSegment->GetPositionX(),rowSegment->GetPositionY()),
192  TVector2(rowSegment->GetDimensionX(),rowSegment->GetDimensionY()));
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 //_______________________________________________________________________
207 void AliMpSubZonePainter::Paint(Option_t *option)
208 {
210 
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();
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;
223  gr->RealToPad(TVector2(rowSegment->GetPositionX(),rowSegment->GetPositionY()),
224  TVector2(rowSegment->GetDimensionX(),rowSegment->GetDimensionY()),
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 }
virtual Double_t GetDimensionX() const =0
Return the x dimension of the row segment centre.
AliMpVMotif * GetMotif() const
Int_t GetColor() const
Return the color.
Definition: AliMpVPainter.h:41
virtual TVector2 GetDimensions() const
Return the owned object's dimensions.
Int_t GetNofRowSegments() const
static AliMpGraphContext * Instance()
virtual Int_t DistancetoPrimitive(Int_t x, Int_t y)
void SetPadPosForReal(const TVector2 &position, const TVector2 &dimensions)
virtual TVector2 GetPosition() const
Return the owned object's position.
void SetColor(Int_t color)
Set color to use.
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
Bool_t IsInside(const TVector2 &point, const TVector2 &pos, const TVector2 &dim)
An interface for a row segment.
TString GetID() const
Return the motif identifier.
Definition: AliMpVMotif.h:90
AliMpSubZone * fSubZone
the subzone to draw
virtual Double_t GetPositionX() const =0
Return the x position of the row segment centre.
virtual void Paint(Option_t *option)
Paint the associated object.
virtual Double_t GetPositionY() const =0
Return the y position of the row segment centre.
TGraph * gr
Definition: CalibTime.C:25
Abstract base class for drawing objects into canvas.
Definition: AliMpVPainter.h:21
virtual Double_t GetDimensionY() const =0
Return the y dimension of the row segment centre.
virtual void Draw(Option_t *option)
AliMpVPainter * DrawObject(TObject *object, Option_t *option="")
Not implemented.
TVector2 RealToPad(const TVector2 &position) const
Class describing the correspondance between a given area in pad, and a zone of real (cm) position...
Class for drawing a subzone into canvas.
AliMpVRowSegment * GetRowSegment(Int_t i) const
void InitGraphContext()
A region in zone composed of the row segments with the same motif type.
Definition: AliMpSubZone.h:23