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: AliMpMotifPainter.cxx,v 1.9 2006/05/24 13:58:32 ivana Exp $
20 //-----------------------------------------------------------------------------
21 // Class AliMpMotifPainter
22 // -----------------------
23 // Class for drawing a motif into canvas
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, IPN Orsay
26 //-----------------------------------------------------------------------------
28 #include "AliMpMotifPainter.h"
29 #include "AliMpGraphContext.h"
30 #include "AliMpMotifPosition.h"
31 #include "AliMpMotifType.h"
32 #include "AliMpMotif.h"
33 #include "AliMpConnection.h"
36 #include <TVirtualX.h>
42 ClassImp(AliMpMotifPainter)
45 //_______________________________________________________________________
46 AliMpMotifPainter::AliMpMotifPainter()
50 /// Default constructor
53 //_______________________________________________________________________
54 AliMpMotifPainter::AliMpMotifPainter(AliMpMotifPosition *motifPos)
58 /// Standard constructor
59 AliDebug(1,"Default ctor");
62 //_______________________________________________________________________
63 AliMpMotifPainter::AliMpMotifPainter(AliMpMotifType* motifType)
67 /// Constructor from a motif Type. We hereby create a MotifPosition
68 /// object from it, using arbitrary pad sizes, as this is just a way
69 /// to visualize the *shape* of the motif.
71 AliDebug(1,"Ctor from motifType");
73 const Double_t kdx = 5;
74 const Double_t kdy = 5; // cm but arbitrary anyway
76 AliMpVMotif* motif = new AliMpMotif(motifType->GetID(),
80 fMotifPos = new AliMpMotifPosition(-1,motif,
81 motif->DimensionX(), motif->DimensionY());
84 //_______________________________________________________________________
85 AliMpMotifPainter::~AliMpMotifPainter()
87 /// Default constructor
90 //_______________________________________________________________________
91 void AliMpMotifPainter::DumpObject()
93 /// Dump the owned object
98 //_______________________________________________________________________
99 TVector2 AliMpMotifPainter::GetPosition() const
101 /// Get the owned object's position
103 return TVector2(fMotifPos->GetPositionX(), fMotifPos->GetPositionY());
106 //_______________________________________________________________________
107 TVector2 AliMpMotifPainter::GetDimensions() const
109 /// Get the owned object's dimensions
111 return TVector2(fMotifPos->GetDimensionX(), fMotifPos->GetDimensionY());
114 //_______________________________________________________________________
115 void AliMpMotifPainter::Paint(Option_t *option)
119 AliMpGraphContext *gr = AliMpGraphContext::Instance();
120 if (!fMotifPos) return;
121 Int_t col=gVirtualX->GetFillColor();
123 gPad->Range(0.,0.,1.,1.);
126 gVirtualX->SetLineWidth(1);
134 Float_t textSize = gVirtualX->GetTextSize();
135 gVirtualX->SetTextSize(10);
139 str = Form("%d",fMotifPos->GetID());
144 str = Form("(%d,%d)",fMotifPos->GetHighLimitIx(),
145 fMotifPos->GetHighLimitIy());
148 str = Form("(%d,%d)",fMotifPos->GetLowLimitIx(),
149 fMotifPos->GetLowLimitIy());
154 str = Form("(%f,%f)",(GetPosition()-GetDimensions()).X(),
155 (GetPosition()-GetDimensions()).Y());
158 gPad->PaintText(GetPadPosition().X()-0.01,GetPadPosition().Y()-0.01,str);
160 gVirtualX->SetTextSize(textSize);
166 //PaintWholeBox(kFALSE);
167 AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
168 for (Int_t j=motifType->GetNofPadsY()-1;j>=0;j--){
169 for (Int_t i=0;i<motifType->GetNofPadsX();i++){
170 AliMpConnection* connect =
171 motifType->FindConnectionByLocalIndices(i,j);
173 Double_t localPosX, localPosY;
174 fMotifPos->GetMotif()->PadPositionLocal(i, j, localPosX, localPosY);
175 TVector2 realPadPos =
176 GetPosition()+TVector2(localPosX, localPosY);
179 fMotifPos->GetMotif()->GetPadDimensionsByIndices(i,j, dx, dy);
181 TVector2 padPadPos,padPadDim;
182 gr->RealToPad(realPadPos,
184 padPadPos,padPadDim);
185 TVector2 bl = padPadPos - padPadDim;
186 TVector2 ur = padPadPos + padPadDim;
188 Style_t sty = gVirtualX->GetFillStyle();
189 gVirtualX->SetFillStyle(1);
190 gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
191 gVirtualX->SetFillStyle(0);
192 gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
193 gVirtualX->SetFillStyle(sty);
196 Float_t textSize = gVirtualX->GetTextSize();
197 gVirtualX->SetTextSize(10);
198 gVirtualX->SetTextAlign(22);
199 gPad->PaintText((bl.X()+ur.X())/2.0,(bl.Y()+ur.Y())/2.0,
200 Form("%d",connect->GetManuChannel()));
202 gVirtualX->SetTextSize(textSize);
207 if ( option[0]=='Z' )
209 PaintContour(option,kFALSE);
215 PaintContour(option,kTRUE);
219 PaintWholeBox(kFALSE);
222 gVirtualX->SetFillColor(col);
225 //_______________________________________________________________________
226 void AliMpMotifPainter::PaintContour(Option_t* option, Bool_t fill)
228 /// Drawing real motif (not envelop) the real contour
230 AliMpGraphContext *gr = AliMpGraphContext::Instance();
235 Int_t searchMotif = -1;
236 TVector2 bl0 = TVector2(999, 999);
237 TVector2 ur0 = TVector2(0,0);
238 TVector2 padPadPos,padPadDim;
240 AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
241 manuId = fMotifPos->GetID();
246 gVirtualX->SetFillColor(0);
248 gVirtualX->SetFillColor(38);
250 gVirtualX->SetFillColor(33);
252 gVirtualX->SetFillColor(16);
254 gVirtualX->SetFillColor(44);
257 Width_t lineW = gPad->GetLineWidth();
258 Width_t lw = lineW*3;
259 Double_t xlw = gPad->PixeltoX(lw/2);
262 if (option[1] == 'I' && option[2] == ':')
263 searchMotif = atoi(&option[3]);
265 gVirtualX->SetLineWidth(lw);
267 for (Int_t i = 0; i < motifType->GetNofPadsX(); i++){
269 for (Int_t j = 0; j < motifType->GetNofPadsY(); j++){
271 AliMpConnection* connect = motifType->FindConnectionByLocalIndices(i,j);
274 Double_t localPosX, localPosY;
275 fMotifPos->GetMotif()->PadPositionLocal(i, j, localPosX, localPosY);
277 TVector2 realPadPos =
278 GetPosition()+TVector2(localPosX, localPosY);
281 fMotifPos->GetMotif()->GetPadDimensionsByIndices(i,j, dx, dy);
283 gr->RealToPad(realPadPos,
285 padPadPos, padPadDim);
287 TVector2 bl = padPadPos - padPadDim;
288 TVector2 ur = padPadPos + padPadDim;
290 if (bl0.X() > bl.X())
293 if (ur0.Y() < ur.Y())
298 Style_t csty = gVirtualX->GetFillColor();
299 Style_t sty = gVirtualX->GetFillStyle();
300 gVirtualX->SetFillStyle(1);
301 if (manuId == searchMotif)
302 gVirtualX->SetFillColor(5); // yellow
303 gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
304 gVirtualX->SetFillStyle(sty);
305 gVirtualX->SetFillColor(csty);
308 if (!motifType->FindConnectionByLocalIndices(i,j-1))
310 gPad->PaintLine(bl.X()-xlw, bl.Y(), bl.X()+ padPadDim.X()*2 + xlw, bl.Y());
313 if (!motifType->FindConnectionByLocalIndices(i,j+1))
315 gPad->PaintLine(bl.X()-xlw, bl.Y() + padPadDim.Y()*2, bl.X()+ padPadDim.X()*2+xlw, bl.Y() + padPadDim.Y()*2);
317 if (!motifType->FindConnectionByLocalIndices(i-1,j))
319 gPad->PaintLine(bl.X(), bl.Y(), bl.X(), bl.Y()+ padPadDim.Y()*2);
322 if (!motifType->FindConnectionByLocalIndices(i+1,j))
324 gPad->PaintLine(bl.X()+padPadDim.X()*2, bl.Y(), bl.X()+padPadDim.X()*2, bl.Y()+ padPadDim.Y()*2);
332 // add manudId indexes
334 xl = bl0.X()+ padPadDim.X()/2.;
336 yl = bl0.Y() + 1.5*padPadDim.Y();
338 Float_t textSize = gVirtualX->GetTextSize();
339 gVirtualX->SetTextSize(12);
340 gVirtualX->SetTextAlign(13);
341 gVirtualX->SetTextAngle(90.);
343 gPad->PaintText(xl, yl, Form("%d", manuId));
345 gVirtualX->SetTextAngle(0.);
346 gVirtualX->SetTextSize(textSize);
350 gVirtualX->SetLineWidth(lineW);