]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpMotifPainter.cxx
Fix in AliMpSectorSegmentation::PadByPosition;
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifPainter.cxx
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: AliMpMotifPainter.cxx,v 1.9 2006/05/24 13:58:32 ivana Exp $
18 // Category: graphics
19
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 //-----------------------------------------------------------------------------
27
28 #include <cstdlib>
29 #include "AliMpMotifPainter.h"
30 #include "AliMpGraphContext.h"
31 #include "AliMpMotifPosition.h"
32 #include "AliMpMotifType.h"
33 #include "AliMpMotif.h"
34 #include "AliMpConnection.h"
35 #include "AliMpIntPair.h"
36 #include "AliLog.h"
37
38 #include <TVirtualX.h>
39 #include <TPad.h>
40  
41 /// \cond CLASSIMP
42 ClassImp(AliMpMotifPainter)
43 /// \endcond
44
45 //_______________________________________________________________________
46 AliMpMotifPainter::AliMpMotifPainter()
47   : AliMpVPainter(),
48     fMotifPos(0)
49 {
50   /// Default constructor
51 }
52
53 //_______________________________________________________________________
54 AliMpMotifPainter::AliMpMotifPainter(AliMpMotifPosition *motifPos)
55   : AliMpVPainter(),
56     fMotifPos(motifPos)
57 {
58   /// Standard constructor 
59       AliDebug(1,"Default ctor");
60 }
61
62 //_______________________________________________________________________
63 AliMpMotifPainter::AliMpMotifPainter(AliMpMotifType* motifType)
64 : AliMpVPainter(),
65 fMotifPos(0x0)
66 {
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.
70   
71   AliDebug(1,"Ctor from motifType");
72   
73   const Double_t kdx = 5;
74   const Double_t kdy = 5; // cm but arbitrary anyway
75   
76   AliMpVMotif* motif = new AliMpMotif(motifType->GetID(),
77                                       motifType,
78                                       TVector2(kdx,kdy));
79
80   fMotifPos = new AliMpMotifPosition(-1,motif,motif->Dimensions());
81 }
82
83 //_______________________________________________________________________
84 AliMpMotifPainter::~AliMpMotifPainter()
85 {
86   /// Default constructor
87 }
88
89 //_______________________________________________________________________
90 void AliMpMotifPainter::DumpObject()
91 {
92 /// Dump the owned object
93
94   fMotifPos->Dump();
95 }
96
97 //_______________________________________________________________________
98 TVector2 AliMpMotifPainter::GetPosition() const
99 {
100 /// Get the owned object's position
101
102   return fMotifPos->Position();
103 }
104
105 //_______________________________________________________________________
106 TVector2 AliMpMotifPainter::GetDimensions() const
107 {
108 /// Get the owned object's dimensions
109
110   return fMotifPos->Dimensions();
111 }
112
113 //_______________________________________________________________________
114 void AliMpMotifPainter::Paint(Option_t *option)
115 {
116 /// Paint the object
117
118   AliMpGraphContext *gr = AliMpGraphContext::Instance();
119   if (!fMotifPos) return;
120   Int_t col=gVirtualX->GetFillColor();
121   gr->Push();
122   gPad->Range(0.,0.,1.,1.);
123   InitGraphContext();
124
125   gVirtualX->SetLineWidth(1);
126   
127   switch (option[0]){
128     case 'T':
129     case 'I':
130     case 'X':
131     {
132       PaintWholeBox();
133       Float_t textSize =   gVirtualX->GetTextSize();
134       gVirtualX->SetTextSize(10);
135       TString str;
136       switch (option[0]) {
137         case 'T' : 
138           str = Form("%d",fMotifPos->GetID());
139           break;
140         case 'I':{
141           switch (option[1]){
142             case '+' :
143               str = Form("(%d,%d)",fMotifPos->GetHighIndicesLimit().GetFirst(),
144                          fMotifPos->GetHighIndicesLimit().GetSecond());
145               break;
146             default:
147               str = Form("(%d,%d)",fMotifPos->GetLowIndicesLimit().GetFirst(),
148                          fMotifPos->GetLowIndicesLimit().GetSecond());
149           }
150         }
151           break;
152         case 'X' :
153           str = Form("(%f,%f)",(GetPosition()-GetDimensions()).X(),
154                      (GetPosition()-GetDimensions()).Y());
155           break;
156       }
157       gPad->PaintText(GetPadPosition().X()-0.01,GetPadPosition().Y()-0.01,str);
158       
159       gVirtualX->SetTextSize(textSize);
160     }
161       break;
162     case 'P':
163     case 'Z':
164     {
165       //PaintWholeBox(kFALSE);
166       AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
167       for (Int_t j=motifType->GetNofPadsY()-1;j>=0;j--){
168         for (Int_t i=0;i<motifType->GetNofPadsX();i++){
169           AliMpIntPair indices(i,j);
170           AliMpConnection* connect = 
171             motifType->FindConnectionByLocalIndices(indices);
172           if (connect){
173             TVector2 realPadPos = 
174             GetPosition()+fMotifPos->GetMotif()->PadPositionLocal(indices);
175             TVector2 padPadPos,padPadDim;
176             gr->RealToPad(realPadPos,
177                           fMotifPos->GetMotif()->GetPadDimensions(indices),
178                           padPadPos,padPadDim);
179             TVector2 bl = padPadPos - padPadDim;
180             TVector2 ur = padPadPos + padPadDim;
181
182             Style_t sty = gVirtualX->GetFillStyle();
183             gVirtualX->SetFillStyle(1);
184             gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
185             gVirtualX->SetFillStyle(0);
186             gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
187             gVirtualX->SetFillStyle(sty);
188
189             if (option[1]=='T'){
190               Float_t textSize =   gVirtualX->GetTextSize();
191               gVirtualX->SetTextSize(10);
192               gVirtualX->SetTextAlign(22);
193               gPad->PaintText((bl.X()+ur.X())/2.0,(bl.Y()+ur.Y())/2.0,
194                               Form("%d",connect->GetManuChannel()));
195               
196               gVirtualX->SetTextSize(textSize);
197                  }
198             }
199           }
200       }
201       if ( option[0]=='Z' )
202       {
203         PaintContour(option,kFALSE);
204       }
205     }
206       break;
207       
208     case 'C':
209       PaintContour(option,kTRUE);
210       break;
211       
212     default:
213       PaintWholeBox(kFALSE);
214   }
215   gr->Pop();
216   gVirtualX->SetFillColor(col);
217 }
218
219 //_______________________________________________________________________
220 void AliMpMotifPainter::PaintContour(Option_t* option, Bool_t fill)
221 {
222 /// Drawing real motif (not envelop) the real contour
223
224   AliMpGraphContext *gr = AliMpGraphContext::Instance();
225   
226   Float_t xl = 0;
227   Float_t yl = 0;
228   Int_t manuId = 0;
229   Int_t searchMotif = -1;
230   TVector2 bl0 = TVector2(999, 999);
231   TVector2 ur0 = TVector2(0,0); 
232   TVector2 padPadPos,padPadDim;
233   
234   AliMpMotifType *motifType = fMotifPos->GetMotif()->GetMotifType();
235   manuId = fMotifPos->GetID();
236   
237   if ( fill )
238   {
239     if (manuId % 5 == 0) 
240       gVirtualX->SetFillColor(0);
241     if (manuId % 5 == 1) 
242       gVirtualX->SetFillColor(38);
243     if (manuId % 5 == 2) 
244       gVirtualX->SetFillColor(33);
245     if (manuId % 5 == 3) 
246       gVirtualX->SetFillColor(16);
247     if (manuId % 5 == 4) 
248       gVirtualX->SetFillColor(44);
249   }
250   
251   Width_t lineW = gPad->GetLineWidth();
252   Width_t lw = lineW*3;
253   Double_t xlw = gPad->PixeltoX(lw/2);
254   
255
256   if (option[1] == 'I' && option[2] == ':')
257       searchMotif = atoi(&option[3]);
258
259   gVirtualX->SetLineWidth(lw);
260     
261     for (Int_t i = 0; i < motifType->GetNofPadsX(); i++){
262       
263       for (Int_t j = 0; j < motifType->GetNofPadsY(); j++){
264         
265         AliMpIntPair indices = AliMpIntPair(i,j);
266         AliMpConnection* connect =  motifType->FindConnectionByLocalIndices(indices);
267
268         if (connect){
269           TVector2 realPadPos = 
270           GetPosition()+fMotifPos->GetMotif()->PadPositionLocal(indices);
271           gr->RealToPad(realPadPos, fMotifPos->GetMotif()->GetPadDimensions(indices),
272                         padPadPos, padPadDim);
273           
274           TVector2 bl = padPadPos - padPadDim;
275           TVector2 ur = padPadPos + padPadDim;
276
277           if (bl0.X() > bl.X())
278             bl0 = bl;
279           
280           if (ur0.Y() < ur.Y())
281             ur0 = ur;
282           
283           if ( fill )
284           {
285             Style_t csty = gVirtualX->GetFillColor();
286             Style_t sty = gVirtualX->GetFillStyle();
287             gVirtualX->SetFillStyle(1);
288             if (manuId == searchMotif) 
289                 gVirtualX->SetFillColor(5); // yellow
290             gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
291             gVirtualX->SetFillStyle(sty);
292             gVirtualX->SetFillColor(csty);
293           } 
294
295           if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i,j-1)))
296           {
297             gPad->PaintLine(bl.X()-xlw, bl.Y(), bl.X()+ padPadDim.X()*2 + xlw, bl.Y());
298           }
299           
300           if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i,j+1)))
301           {
302             gPad->PaintLine(bl.X()-xlw, bl.Y() + padPadDim.Y()*2, bl.X()+ padPadDim.X()*2+xlw, bl.Y() +  padPadDim.Y()*2);
303           }
304           if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i-1,j)))
305           {
306             gPad->PaintLine(bl.X(), bl.Y(), bl.X(), bl.Y()+ padPadDim.Y()*2);                  
307           }          
308
309           if (!motifType->FindConnectionByLocalIndices(AliMpIntPair(i+1,j)))
310           {
311             gPad->PaintLine(bl.X()+padPadDim.X()*2, bl.Y(), bl.X()+padPadDim.X()*2, bl.Y()+ padPadDim.Y()*2);  
312           } 
313         }
314
315       }
316     }
317     
318     switch (option[1]) {
319       // add manudId indexes
320       case 'I' :
321         xl = bl0.X()+ padPadDim.X()/2.;
322         
323         yl = bl0.Y() + 1.5*padPadDim.Y();
324         
325         Float_t textSize =   gVirtualX->GetTextSize();
326         gVirtualX->SetTextSize(12);
327         gVirtualX->SetTextAlign(13);
328         gVirtualX->SetTextAngle(90.);
329         
330         gPad->PaintText(xl, yl, Form("%d", manuId));
331         
332         gVirtualX->SetTextAngle(0.);
333         gVirtualX->SetTextSize(textSize);
334         break;
335     }
336
337     gVirtualX->SetLineWidth(lineW);
338
339 }