Update from Alberica. Addition of VZERO equalized signals and ZNC.
[u/mrichter/AliRoot.git] / MUON / AliMUONManuPadPainter.cxx
CommitLineData
0145e89a 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
49419555 20#include "AliLog.h"
21#include "AliMUONPainterGroup.h"
0145e89a 22#include "AliMUONPainterHelper.h"
49419555 23#include "AliMUONTrackerDataHistogrammer.h"
0145e89a 24#include "AliMUONVCalibParam.h"
25#include "AliMUONVDigit.h"
26#include "AliMUONVTrackerData.h"
27#include "AliMpConnection.h"
28#include "AliMpConstants.h"
29#include "AliMpDDLStore.h"
0145e89a 30#include "AliMpPad.h"
31#include "AliMpSegmentation.h"
32#include "AliMpVSegmentation.h"
49419555 33#include <TCanvas.h>
34#include <TH1.h>
0145e89a 35#include <TVirtualPad.h>
36#include <TVirtualX.h>
49419555 37#include <float.h>
0145e89a 38
39///\class AliMUONManuPadPainter
40///
41/// Painter for the pads of one manu
42///
43///\author Laurent Aphecetche, Subatech
44
45///\cond CLASSIMP
46ClassImp(AliMUONManuPadPainter)
47///\endcond
48
49//_____________________________________________________________________________
50AliMUONManuPadPainter::AliMUONManuPadPainter()
51: AliMUONVPainter(),
52fDetElemId(-1),
53fManuId(-1),
54fLineColorBck(-1),
55fLineWidthBck(-1),
56fFillColorBck(-1),
57fFillStyleBck(-1)
58{
59 /// ctor
60}
61
62//_____________________________________________________________________________
1ffbeb9d 63AliMUONManuPadPainter::AliMUONManuPadPainter(TRootIOCtor* ioCtor)
64: AliMUONVPainter(ioCtor),
65fDetElemId(-1),
66fManuId(-1),
67fLineColorBck(-1),
68fLineWidthBck(-1),
69fFillColorBck(-1),
70fFillStyleBck(-1)
71{
72 /// ctor
73}
74
75//_____________________________________________________________________________
0145e89a 76AliMUONManuPadPainter::AliMUONManuPadPainter(const AliMUONVPainter& mother,
77 Int_t detElemId,
78 Int_t manuId)
79: AliMUONVPainter("PAD"),
80fDetElemId(detElemId),
81fManuId(manuId),
82fLineColorBck(-1),
83fLineWidthBck(-1),
84fFillColorBck(-1),
85fFillStyleBck(-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//_____________________________________________________________________________
95AliMUONManuPadPainter::~AliMUONManuPadPainter()
96{
97 /// dtor
98}
99
100//_____________________________________________________________________________
101void
102AliMUONManuPadPainter::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//_____________________________________________________________________________
113void
114AliMUONManuPadPainter::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
8f0acce4 119 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(fDetElemId,fManuId);
0145e89a 120
121 dataMin = FLT_MAX;
122 dataMax = -FLT_MAX;
123
124 for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels();
125 ++manuChannel )
126 {
8f0acce4 127 if ( seg->HasPadByLocation(fManuId,manuChannel) )
0145e89a 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//_____________________________________________________________________________
137char*
138AliMUONManuPadPainter::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//_____________________________________________________________________________
145TString
146AliMUONManuPadPainter::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 {
168e9c4d 156 name = Form("%s%d",PathName().Data(),pad.GetManuChannel());
0145e89a 157 }
158
159 return name;
160}
161
162//_____________________________________________________________________________
1ffbeb9d 163Bool_t
164AliMUONManuPadPainter::IsIncluded() const
165{
166 /// whether this manu is included in the readout or not
167 return ( InteractiveReadOutConfig()->Manu(fDetElemId,fManuId) > 0 );
168}
169
170//_____________________________________________________________________________
0145e89a 171TString
172AliMUONManuPadPainter::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 {
168e9c4d 183 Double_t value = data.Channel(fDetElemId,fManuId,pad.GetManuChannel(),dataIndex);
0145e89a 184
185 return AliMUONPainterHelper::Instance()->FormatValue(data.DimensionName(dataIndex).Data(),value);
186 }
187 else
188 {
189 return "invalid";
190 }
191}
192
193//_____________________________________________________________________________
49419555 194void
195AliMUONManuPadPainter::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
8f0acce4 211 fHistogram = tdh.CreateChannelHisto(fDetElemId, fManuId,pad.GetManuChannel());
212
49419555 213 if (fHistogram)
214 {
215 new TCanvas();
216 fHistogram->Draw();
217 }
218}
219
220//_____________________________________________________________________________
0145e89a 221void
222AliMUONManuPadPainter::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();
8f0acce4 236
0145e89a 237 gVirtualX->SetLineColor(-1);
238 gVirtualX->SetFillStyle(1);
239
8f0acce4 240 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(fDetElemId,fManuId);
241
0145e89a 242 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
243 {
8f0acce4 244 AliMpPad pad = seg->PadByLocation(fManuId,i,kFALSE);
0145e89a 245
8f0acce4 246 if ( pad.IsValid() )
0145e89a 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 }
8f0acce4 260
0145e89a 261 gVirtualX->SetFillColor(color);
262
8f0acce4 263 PaintPad(pad);
0145e89a 264
0145e89a 265 }
266 }
267
268 RestoreStyle();
269}
270
271//_____________________________________________________________________________
272void
8f0acce4 273AliMUONManuPadPainter::PaintPad(const AliMpPad& pad) const
0145e89a 274{
8f0acce4 275 Double_t blx = pad.GetPositionX()-pad.GetDimensionX();
276 Double_t bly = pad.GetPositionY()-pad.GetDimensionY();
0145e89a 277
8f0acce4 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;
0145e89a 282
8f0acce4 283 AliMUONPainterHelper::Instance()->Local2Global(fDetElemId,blx,bly,0,xe1,ye1,z);
284 AliMUONPainterHelper::Instance()->Local2Global(fDetElemId,urx,ury,0,xe2,ye2,z);
0145e89a 285
8f0acce4 286 gPad->PaintBox(xe1,ye1,xe2,ye2);
0145e89a 287}
288
289//_____________________________________________________________________________
290void
291AliMUONManuPadPainter::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
0145e89a 299 if ( lineColor > 0 )
300 {
301 BackupStyle();
302
0145e89a 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
8f0acce4 311 PaintPad(pad);
0145e89a 312 }
313 else
314 {
8f0acce4 315 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(fDetElemId,fManuId);
316
0145e89a 317 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
318 {
8f0acce4 319 AliMpPad pad = seg->PadByLocation(fManuId,i,kFALSE);
320
321 if (pad.IsValid()) PaintPad(pad);
0145e89a 322
8f0acce4 323 PaintPad(pad);
0145e89a 324 }
325 }
326 RestoreStyle();
327 }
328
329}
330
331//_____________________________________________________________________________
332AliMpPad
333AliMUONManuPadPainter::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
6e97fbb8 346 return seg->PadByPosition(xl,yl);
0145e89a 347}
348
349//_____________________________________________________________________________
350void
351AliMUONManuPadPainter::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