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