Coverity
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveMUONChamber.cxx
CommitLineData
d810d0de 1// $Id$
fafff680 2// Main authors: Matevz Tadel & Alja Mrak-Tadel & Bogdan Vulpescu: 2006, 2007
3626c858 3
d810d0de 4/**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
51346b82 7 * full copyright notice. *
d810d0de 8 **************************************************************************/
9#include "AliEveMUONChamber.h"
10
cb4245bb 11#include <EveDet/AliEveMUONData.h>
12#include <EveDet/AliEveMUONChamberData.h>
3626c858 13
14#include <TBuffer3D.h>
15#include <TBuffer3DTypes.h>
16#include <TVirtualPad.h>
17#include <TVirtualViewer3D.h>
3626c858 18#include <TStyle.h>
d05591ca 19#include <TMath.h>
3626c858 20
3626c858 21
57ffa5fb 22//______________________________________________________________________________
d810d0de 23// AliEveMUONChamber
3626c858 24//
25
d810d0de 26ClassImp(AliEveMUONChamber)
3626c858 27
57ffa5fb 28//______________________________________________________________________________
d810d0de 29AliEveMUONChamber::AliEveMUONChamber(Int_t id, const Text_t* n, const Text_t* t) :
fd31e9de 30 TEveElement(fFrameColor),
31 TNamed(n,t),
32 fMUONData(0),
fbc350a3 33 fFrameColor(2),
fd31e9de 34 fRTS(1),
35 fChamberID(0),
36 fQuadSet1(n,t),
37 fQuadSet2(n,t),
38 fPointSet1(n),
39 fPointSet2(n),
40 fThreshold(0),
41 fMaxVal(4096),
42 fClusterSize(5),
43 fHitSize(5),
44 fColorArray(0)
3626c858 45{
46 //
47 // constructor
48 //
49
eadce74d 50 Char_t name[256];
51 if (id < 10) {
a69a01ce 52 snprintf(name,256,"Chamber %02d (trac)",id);
eadce74d 53 } else {
a69a01ce 54 snprintf(name,256,"Chamber %02d (trig)",id);
eadce74d 55 }
56 SetName(name);
57
3626c858 58 ComputeBBox();
59
60}
61
57ffa5fb 62//______________________________________________________________________________
d810d0de 63AliEveMUONChamber::~AliEveMUONChamber()
3626c858 64{
65 //
66 // destructor
67 //
68
69 if(fMUONData) fMUONData->DecRefCount();
70
71}
72
57ffa5fb 73//______________________________________________________________________________
d810d0de 74void AliEveMUONChamber::ComputeBBox()
3626c858 75{
76 //
77 // bounding box
78 //
79
80#if ROOT_VERSION_CODE <= ROOT_VERSION(5,11,2)
81 bbox_init();
82#else
83 BBoxInit();
84#endif
51346b82 85
eadce74d 86 fBBox[0] = - 400.0;
87 fBBox[1] = + 400.0;
88 fBBox[2] = - 400.0;
89 fBBox[3] = + 400.0;
3626c858 90 fBBox[4] = -1800.0;
eadce74d 91 fBBox[5] = + 500.0;
3626c858 92
93 Float_t* b1 = fQuadSet1.AssertBBox();
94 for(Int_t i=0; i<6; ++i) { b1[i] = fBBox[i]; }
95 Float_t* b2 = fQuadSet2.AssertBBox();
96 for(Int_t i=0; i<6; ++i) { b2[i] = fBBox[i]; }
eadce74d 97 Float_t* b3 = fPointSet1.AssertBBox();
98 for(Int_t i=0; i<6; ++i) { b3[i] = fBBox[i]; }
99 Float_t* b4 = fPointSet2.AssertBBox();
100 for(Int_t i=0; i<6; ++i) { b4[i] = fBBox[i]; }
51346b82 101
3626c858 102}
103
57ffa5fb 104//______________________________________________________________________________
d810d0de 105void AliEveMUONChamber::Paint(Option_t*)
3626c858 106{
107 //
108 // draw...
109 //
110
2caed564 111 if(fRnrSelf == kFALSE)
3626c858 112 return;
113
114 TBuffer3D buffer(TBuffer3DTypes::kGeneric);
115
116 buffer.fID = this;
117 buffer.fColor = 2;
118 buffer.fTransparency = 0;
119 buffer.fLocalFrame = 0;
120
121 buffer.SetSectionsValid(TBuffer3D::kCore);
122 Int_t reqSections = gPad->GetViewer3D()->AddObject(buffer);
123 if (reqSections == TBuffer3D::kNone) {
d810d0de 124 //printf("AliEveMUONChamber::Paint viewer was happy with Core buff3d.\n");
3626c858 125 return;
126 }
127
d810d0de 128 printf("AliEveMUONChamber::Paint only GL supported.\n");
3626c858 129 return;
130
131}
132
57ffa5fb 133//______________________________________________________________________________
d810d0de 134void AliEveMUONChamber::SetThreshold(Short_t t)
3626c858 135{
136 //
137 // digits amplitude threshold
138 //
139
140 fThreshold = TMath::Min(t, (Short_t)(fMaxVal - 1));
141 ClearColorArray();
142 IncRTS();
143
144}
145
57ffa5fb 146//______________________________________________________________________________
d810d0de 147void AliEveMUONChamber::SetMaxVal(Int_t mv)
3626c858 148{
149 //
150 // digits amplitude maximum value
151 //
152
153 fMaxVal = TMath::Max(mv, (Int_t)(fThreshold + 1));
154 ClearColorArray();
155 IncRTS();
156
157}
158
57ffa5fb 159//______________________________________________________________________________
d810d0de 160void AliEveMUONChamber::SetClusterSize(Int_t size)
eadce74d 161{
162 //
163 // cluster point size
164 //
165
166 fClusterSize = TMath::Max(1, size);
167 IncRTS();
168
169}
170
57ffa5fb 171//______________________________________________________________________________
d810d0de 172void AliEveMUONChamber::SetHitSize(Int_t size)
eadce74d 173{
174 //
175 // hit point size
176 //
177
178 fHitSize = TMath::Max(1, size);
179 IncRTS();
180
181}
182
57ffa5fb 183//______________________________________________________________________________
d810d0de 184void AliEveMUONChamber::SetupColor(Int_t val, UChar_t* pixel) const
3626c858 185{
186 //
187 // RGBA color for amplitude "val"
188 //
189
190 Float_t div = TMath::Max(1, fMaxVal - fThreshold);
191 Int_t nCol = gStyle->GetNumberOfColors();
192 Int_t cBin = (Int_t) TMath::Nint(nCol*(val - fThreshold)/div);
193
d810d0de 194 TEveUtil::TEveUtil::ColorFromIdx(gStyle->GetColorPalette(TMath::Min(nCol - 1, cBin)), pixel);
3626c858 195
196}
197
57ffa5fb 198//______________________________________________________________________________
d810d0de 199Int_t AliEveMUONChamber::ColorIndex(Int_t val) const
3626c858 200{
201 //
51346b82 202 // index color
3626c858 203 //
204
205 if(val < fThreshold) val = fThreshold;
206 if(val > fMaxVal) val = fMaxVal;
207
208 Float_t div = TMath::Max(1, fMaxVal - fThreshold);
209 Int_t nCol = gStyle->GetNumberOfColors();
210 Int_t cBin = (Int_t) TMath::Nint(nCol*(val - fThreshold)/div);
211
212 return gStyle->GetColorPalette(TMath::Min(nCol - 1, cBin));
213
214}
215
57ffa5fb 216//______________________________________________________________________________
d810d0de 217void AliEveMUONChamber::SetupColorArray() const
3626c858 218{
219 //
220 // build array of colors
221 //
222
223 if(fColorArray)
224 return;
225
226 fColorArray = new UChar_t [4 * (fMaxVal - fThreshold + 1)];
227 UChar_t* p = fColorArray;
228 for(Int_t v=fThreshold; v<=fMaxVal; ++v, p+=4)
229 SetupColor(v, p);
230
231}
232
57ffa5fb 233//______________________________________________________________________________
d810d0de 234void AliEveMUONChamber::ClearColorArray()
3626c858 235{
236 //
237 // delete array of colors
238 //
239
240 if(fColorArray) {
241 delete [] fColorArray;
242 fColorArray = 0;
243 }
244}
245
57ffa5fb 246//______________________________________________________________________________
d810d0de 247void AliEveMUONChamber::SetDataSource(AliEveMUONData* data)
3626c858 248{
a15e6d7d 249 // Set source of data.
3626c858 250
251 if (data == fMUONData) return;
252 if(fMUONData) fMUONData->DecRefCount();
253 fMUONData = data;
254 if(fMUONData) fMUONData->IncRefCount();
255 IncRTS();
3626c858 256}
257
57ffa5fb 258//______________________________________________________________________________
d810d0de 259AliEveMUONChamberData* AliEveMUONChamber::GetChamberData() const
3626c858 260{
a15e6d7d 261 // Return source of data.
51346b82 262
3626c858 263 return fMUONData ? fMUONData->GetChamberData(fChamberID) : 0;
3626c858 264}
265
57ffa5fb 266//______________________________________________________________________________
d810d0de 267void AliEveMUONChamber::UpdateQuads()
3626c858 268{
a15e6d7d 269 // Update digit representation.
3626c858 270
84aff7a4 271 fQuadSet1.Reset(TEveQuadSet::kQT_RectangleXY, kTRUE, 32);
272 fQuadSet2.Reset(TEveQuadSet::kQT_RectangleXY, kTRUE, 32);
eadce74d 273 fPointSet1.Reset();
274 fPointSet2.Reset();
3626c858 275
d810d0de 276 AliEveMUONChamberData* data = GetChamberData();
51346b82 277
3626c858 278 Float_t *buffer;
84aff7a4 279 Float_t x0, y0, z, w, h, clsq;
eadce74d 280 Int_t charge, cathode, nDigits, nClusters, nHits, oldSize, ic1, ic2;
281 Double_t clsX, clsY, clsZ;
282 Float_t hitX, hitY, hitZ;
51346b82 283
3626c858 284 if (data != 0) {
285
286 SetupColorArray();
287
eadce74d 288 // digits
289
290 nDigits = data->GetNDigits();
51346b82 291
eadce74d 292 for (Int_t id = 0; id < nDigits; id++) {
3626c858 293
294 buffer = data->GetDigitBuffer(id);
295
296 x0 = buffer[0]-buffer[2];
297 y0 = buffer[1]-buffer[3];
84aff7a4 298 w = 2*buffer[2];
299 h = 2*buffer[3];
3626c858 300 z = buffer[4];
301 charge = (Int_t)buffer[5];
302 cathode = (Int_t)buffer[6];
51346b82 303
eadce74d 304 if (charge <= fThreshold) continue;
305
3626c858 306 if (cathode == 0) {
307
84aff7a4 308 fQuadSet1.AddQuad(x0, y0, z, w, h);
309 fQuadSet1.QuadColor(ColorIndex(charge));
51346b82 310
3626c858 311 }
312
313 if (cathode == 1) {
314
84aff7a4 315 fQuadSet2.AddQuad(x0, y0, z, w, h);
316 fQuadSet2.QuadColor(ColorIndex(charge));
51346b82 317
3626c858 318 }
319
320 } // end digits loop
321
eadce74d 322 // clusters
51346b82 323
eadce74d 324 nClusters = data->GetNClusters()/2; // only one cathode plane
325 oldSize = fPointSet1.GrowFor(nClusters);
326 ic1 = ic2 = 0;
327 for (Int_t ic = 0; ic < (nClusters*2); ic++) {
328
329 buffer = data->GetClusterBuffer(ic);
330
331 clsX = (Double_t)buffer[0];
332 clsY = (Double_t)buffer[1];
333 clsZ = (Double_t)buffer[2];
51346b82 334 clsq = buffer[3];
eadce74d 335 cathode = (Int_t)buffer[4];
336
337 if (cathode == 0) {
338 fPointSet1.SetPoint(ic1,clsX,clsY,clsZ);
339 ic1++;
340 }
341
342 } // end clusters loop
343
344 // hits
345
346 nHits = data->GetNHits();
347 oldSize = fPointSet2.GrowFor(nHits);
348 for (Int_t ih = 0; ih < nHits; ih++) {
349 buffer = data->GetHitBuffer(ih);
350 hitX = buffer[0];
351 hitY = buffer[1];
352 hitZ = buffer[2];
353 fPointSet2.SetPoint(ih,hitX,hitY,hitZ);
354 }
355
356 } // end data
3626c858 357
358}
359
57ffa5fb 360//______________________________________________________________________________
d810d0de 361void AliEveMUONChamber::SetChamberID(Int_t id)
3626c858 362{
a15e6d7d 363 // Set id of chamber to display.
3626c858 364
365 if (id < 0) id = 0;
366 if (id > 13) id = 13;
367
368 fChamberID = id;
369 IncRTS();
3626c858 370}
371