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