]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONManuPadPainter.cxx
Compilation on Windows/Cygwin. Corrected dependences
[u/mrichter/AliRoot.git] / MUON / AliMUONManuPadPainter.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
18 #include "AliMUONManuPadPainter.h"
19
20 #include "AliMUONPainterHelper.h"
21 #include "AliMUONPainterPadStore.h"
22 #include "AliMUONVCalibParam.h"
23 #include "AliMUONVDigit.h"
24 #include "AliMUONVTrackerData.h"
25 #include "AliMpConnection.h"
26 #include "AliMpConstants.h"
27 #include "AliMpDDLStore.h"
28 #include "AliMpDetElement.h"
29 #include "AliMpPad.h"
30 #include "AliMpSegmentation.h"
31 #include "AliMpVSegmentation.h"
32 #include "AliLog.h"
33 #include <float.h>
34 #include <TVirtualPad.h>
35 #include <TVirtualX.h>
36
37 ///\class AliMUONManuPadPainter
38 ///
39 /// Painter for the pads of one manu
40 ///
41 ///\author Laurent Aphecetche, Subatech
42
43 ///\cond CLASSIMP
44 ClassImp(AliMUONManuPadPainter)
45 ///\endcond
46
47 //_____________________________________________________________________________
48 AliMUONManuPadPainter::AliMUONManuPadPainter()
49 : AliMUONVPainter(), 
50 fDetElemId(-1), 
51 fManuId(-1),
52 fLineColorBck(-1),
53 fLineWidthBck(-1),
54 fFillColorBck(-1),
55 fFillStyleBck(-1)
56 {
57   /// ctor
58 }
59
60 //_____________________________________________________________________________
61 AliMUONManuPadPainter::AliMUONManuPadPainter(const AliMUONVPainter& mother,
62                                              Int_t detElemId,
63                                              Int_t manuId)
64 : AliMUONVPainter("PAD"),
65 fDetElemId(detElemId),
66 fManuId(manuId),
67 fLineColorBck(-1),
68 fLineWidthBck(-1),
69 fFillColorBck(-1),
70 fFillStyleBck(-1)
71 {
72   /// ctor
73   SetID(detElemId,manuId);
74   SetName(Form("%s/PAD",mother.GetName()));
75   SetPathName(Form("%s/PAD",mother.PathName().Data()));
76   SetContour(mother.Contour());
77 }
78
79 //_____________________________________________________________________________
80 AliMUONManuPadPainter::~AliMUONManuPadPainter()
81 {
82   /// dtor
83 }
84
85 //_____________________________________________________________________________
86 void
87 AliMUONManuPadPainter::BackupStyle()
88 {
89   /// Remember line and fill style values
90   
91   fFillStyleBck = gVirtualX->GetFillStyle();
92   fFillColorBck = gVirtualX->GetFillColor();
93   fLineColorBck = gVirtualX->GetLineColor();
94   fLineWidthBck = gVirtualX->GetLineWidth();
95 }
96
97 //_____________________________________________________________________________
98 void
99 AliMUONManuPadPainter::ComputeDataRange(const AliMUONVTrackerData& data,
100                                         Int_t dataIndex,
101                                         Double_t& dataMin, Double_t& dataMax) const
102 {
103   /// Compute data range spanned by this manu pads
104   AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(fDetElemId);
105   
106   dataMin = FLT_MAX;
107   dataMax = -FLT_MAX;
108   
109   for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); 
110         ++manuChannel )
111   {
112     if ( de->IsConnectedChannel(fManuId,manuChannel) )
113     {
114       Double_t value = data.Channel(fDetElemId, fManuId, manuChannel, dataIndex);
115       dataMin = TMath::Min(value,dataMin);
116       dataMax = TMath::Max(value,dataMax);
117     }
118   }
119 }
120
121 //_____________________________________________________________________________
122 char* 
123 AliMUONManuPadPainter::GetObjectInfo(Int_t px, Int_t py) const
124 {
125   /// Get object info
126   return const_cast<char*>(Form("%s:%d:%d",GetName(),px,py));
127 }
128
129 //_____________________________________________________________________________
130 TString
131 AliMUONManuPadPainter::NameAtPosition(Double_t x, Double_t y) const
132 {
133   /// Specific name, dependent on the position within this painter
134   
135   TString name("invalid");
136
137   AliMpPad pad = PadByPosition(x,y);
138   
139   if ( pad.IsValid() )
140   {  
141     name = Form("%s%d",PathName().Data(),pad.GetLocation().GetSecond());
142   }
143   
144   return name;
145 }
146
147 //_____________________________________________________________________________
148 TString 
149 AliMUONManuPadPainter::Describe(const AliMUONVTrackerData& data, Int_t dataIndex,
150                                 Double_t x, Double_t y)
151 {
152   /// Describe data at given location
153   
154   if ( ! data.HasManu(fDetElemId,fManuId) ) return "";
155
156   AliMpPad pad = PadByPosition(x,y);
157   
158   if ( pad.IsValid() ) 
159   {
160     Double_t value = data.Channel(fDetElemId,fManuId,pad.GetLocation().GetSecond(),dataIndex);
161   
162     return AliMUONPainterHelper::Instance()->FormatValue(data.DimensionName(dataIndex).Data(),value);
163   }
164   else
165   {
166     return "invalid";
167   }
168 }
169
170 //_____________________________________________________________________________
171 void
172 AliMUONManuPadPainter::PaintArea(const AliMUONVTrackerData& data,
173                                  Int_t dataIndex,
174                                  Double_t min,
175                                  Double_t max)
176 {
177     /// Paint area of this manu pads according to the data
178   
179   if ( !gPad ) return;
180   
181   if ( ! data.HasManu(fDetElemId,fManuId) ) return;
182   
183   AliMUONPainterHelper* h = AliMUONPainterHelper::Instance();
184   
185   BackupStyle();
186   
187   Int_t cathode = h->GetCathodeType(fDetElemId,fManuId);
188   
189   gVirtualX->SetLineColor(-1);
190   gVirtualX->SetFillStyle(1);
191   
192   for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i ) 
193   {    
194     Int_t id = AliMUONVDigit::BuildUniqueID(fDetElemId,fManuId,i,cathode);
195     
196     TVector2 position;
197     TVector2 dimensions;
198     
199     h->PadStore().GetPadGeometry(id,position,dimensions);
200     
201     if ( dimensions.X() > 0 ) 
202     {
203       Double_t value = data.Channel(fDetElemId,fManuId,i,dataIndex);
204       
205       if ( value >= AliMUONVCalibParam::InvalidFloatValue() ) continue;
206       
207       Int_t color = h->ColorFromValue(value,min,max);
208       
209       if ( value > 0 )
210       {
211         AliDebug(1,Form("DE %d manuId %d channel %d value %e min %e max %e color %d",
212                         fDetElemId,fManuId,i,value,min,max,
213                         color));
214       }
215       
216       gVirtualX->SetFillColor(color);
217       
218       TVector2 bl(position-dimensions);
219       TVector2 ur(position+dimensions);
220       
221       gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
222     }
223   }
224   
225   RestoreStyle();
226 }
227                       
228 //_____________________________________________________________________________
229 void
230 AliMUONManuPadPainter::PaintPad(Int_t padId) const
231 {
232   /// Paint a single pad
233   
234   TVector2 position;
235   TVector2 dimensions;
236
237   AliMUONPainterHelper::Instance()->PadStore().GetPadGeometry(padId,position,dimensions);
238
239   if ( dimensions.X() > 0 ) 
240   {
241     TVector2 bl(position-dimensions);
242     TVector2 ur(position+dimensions);    
243   
244     gPad->PaintBox(bl.X(),bl.Y(),ur.X(),ur.Y());
245   }
246 }
247
248 //_____________________________________________________________________________
249 void
250 AliMUONManuPadPainter::PaintOutline(Int_t color, Int_t, Double_t x, Double_t y)
251 {
252   /// Paint the outline of our pads
253
254   if ( !gPad ) return;
255   
256   Int_t lineColor = color >= 0 ? color : GetLineColor();
257   
258   AliMUONPainterHelper* h = AliMUONPainterHelper::Instance();
259
260   AliDebug(1,Form("color=%d lineColor=%d x=%7.3f y=%7.3f",color,lineColor,x,y));
261   
262   if ( lineColor > 0 )
263   {
264     BackupStyle();
265     
266     Int_t cathode = h->GetCathodeType(fDetElemId,fManuId);
267     
268     gVirtualX->SetLineColor(lineColor);
269     gVirtualX->SetFillStyle(0);
270     
271     if ( x < FLT_MAX && y < FLT_MAX ) 
272     {
273       // find pad to be drawn
274       AliMpPad pad = PadByPosition(x,y);
275       
276       Int_t id = AliMUONVDigit::BuildUniqueID(fDetElemId,fManuId,pad.GetLocation().GetSecond(),cathode);
277
278       PaintPad(id);        
279     }
280     else
281     {
282       for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i ) 
283       {    
284         Int_t id = AliMUONVDigit::BuildUniqueID(fDetElemId,fManuId,i,cathode);
285       
286         PaintPad(id);        
287       }
288     }
289     RestoreStyle();
290   }  
291   
292 }
293
294 //_____________________________________________________________________________
295 AliMpPad
296 AliMUONManuPadPainter::PadByPosition(Double_t x, Double_t y) const
297 {
298   /// Find the pad at given exploded-position (x,y)
299   
300   const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(fDetElemId,fManuId);
301   
302   Double_t xg,yg,zg;
303   Double_t xl,yl,zl;
304   
305   AliMUONPainterHelper::Instance()->Local2Global(fDetElemId,0.0,0.0,0.0,xg,yg,zg); // to get zg
306   
307   AliMUONPainterHelper::Instance()->Global2Local(fDetElemId,x,y,zg,xl,yl,zl);
308   
309   return seg->PadByPosition(TVector2(xl,yl));
310 }
311
312 //_____________________________________________________________________________
313 void
314 AliMUONManuPadPainter::RestoreStyle()
315 {
316   /// Restore line and fill style values
317   
318   gVirtualX->SetFillStyle(fFillStyleBck);
319   gVirtualX->SetFillColor(fFillColorBck);
320   gVirtualX->SetLineColor(fLineColorBck);
321   gVirtualX->SetLineWidth(fLineWidthBck);
322 }
323
324