]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/Alieve/AliEveMUONChamber.cxx
Remove trailing whitespace.
[u/mrichter/AliRoot.git] / EVE / Alieve / AliEveMUONChamber.cxx
CommitLineData
d810d0de 1// $Id$
2// Main authors: Matevz Tadel & Alja Mrak-Tadel: 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
11#include <Alieve/AliEveMUONData.h>
12#include <Alieve/AliEveMUONChamberData.h>
3626c858 13
14#include <TBuffer3D.h>
15#include <TBuffer3DTypes.h>
16#include <TVirtualPad.h>
17#include <TVirtualViewer3D.h>
18
19#include <TStyle.h>
20#include <TColor.h>
21#include <TMath.h>
22
3626c858 23
24//______________________________________________________________________
d810d0de 25// AliEveMUONChamber
3626c858 26//
27
d810d0de 28ClassImp(AliEveMUONChamber)
3626c858 29
30//______________________________________________________________________
d810d0de 31AliEveMUONChamber::AliEveMUONChamber(Int_t id, const Text_t* n, const Text_t* t) :
84aff7a4 32TEveElement(fFrameColor),
3626c858 33TNamed(n,t),
34fMUONData(0),
35fFrameColor((Color_t)2),
36fRTS(1),
37fChamberID(0),
38fQuadSet1(n,t),
39fQuadSet2(n,t),
eadce74d 40fPointSet1(n),
41fPointSet2(n),
3626c858 42fThreshold(0),
eadce74d 43fMaxVal(4096),
44fClusterSize(5),
45fHitSize(5)
3626c858 46{
47 //
48 // constructor
49 //
50
eadce74d 51 Char_t name[256];
52 if (id < 10) {
53 sprintf(name,"Chamber %02d (trac)",id);
54 } else {
55 sprintf(name,"Chamber %02d (trig)",id);
56 }
57 SetName(name);
58
3626c858 59 ComputeBBox();
60
61}
62
63//______________________________________________________________________
d810d0de 64AliEveMUONChamber::~AliEveMUONChamber()
3626c858 65{
66 //
67 // destructor
68 //
69
70 if(fMUONData) fMUONData->DecRefCount();
71
72}
73
74//______________________________________________________________________
d810d0de 75void AliEveMUONChamber::ComputeBBox()
3626c858 76{
77 //
78 // bounding box
79 //
80
81#if ROOT_VERSION_CODE <= ROOT_VERSION(5,11,2)
82 bbox_init();
83#else
84 BBoxInit();
85#endif
51346b82 86
eadce74d 87 fBBox[0] = - 400.0;
88 fBBox[1] = + 400.0;
89 fBBox[2] = - 400.0;
90 fBBox[3] = + 400.0;
3626c858 91 fBBox[4] = -1800.0;
eadce74d 92 fBBox[5] = + 500.0;
3626c858 93
94 Float_t* b1 = fQuadSet1.AssertBBox();
95 for(Int_t i=0; i<6; ++i) { b1[i] = fBBox[i]; }
96 Float_t* b2 = fQuadSet2.AssertBBox();
97 for(Int_t i=0; i<6; ++i) { b2[i] = fBBox[i]; }
eadce74d 98 Float_t* b3 = fPointSet1.AssertBBox();
99 for(Int_t i=0; i<6; ++i) { b3[i] = fBBox[i]; }
100 Float_t* b4 = fPointSet2.AssertBBox();
101 for(Int_t i=0; i<6; ++i) { b4[i] = fBBox[i]; }
51346b82 102
3626c858 103}
104
105//______________________________________________________________________
d810d0de 106void AliEveMUONChamber::Paint(Option_t*)
3626c858 107{
108 //
109 // draw...
110 //
111
2caed564 112 if(fRnrSelf == kFALSE)
3626c858 113 return;
114
115 TBuffer3D buffer(TBuffer3DTypes::kGeneric);
116
117 buffer.fID = this;
118 buffer.fColor = 2;
119 buffer.fTransparency = 0;
120 buffer.fLocalFrame = 0;
121
122 buffer.SetSectionsValid(TBuffer3D::kCore);
123 Int_t reqSections = gPad->GetViewer3D()->AddObject(buffer);
124 if (reqSections == TBuffer3D::kNone) {
d810d0de 125 //printf("AliEveMUONChamber::Paint viewer was happy with Core buff3d.\n");
3626c858 126 return;
127 }
128
d810d0de 129 printf("AliEveMUONChamber::Paint only GL supported.\n");
3626c858 130 return;
131
132}
133
134//______________________________________________________________________
d810d0de 135void AliEveMUONChamber::SetThreshold(Short_t t)
3626c858 136{
137 //
138 // digits amplitude threshold
139 //
140
141 fThreshold = TMath::Min(t, (Short_t)(fMaxVal - 1));
142 ClearColorArray();
143 IncRTS();
144
145}
146
147//______________________________________________________________________
d810d0de 148void AliEveMUONChamber::SetMaxVal(Int_t mv)
3626c858 149{
150 //
151 // digits amplitude maximum value
152 //
153
154 fMaxVal = TMath::Max(mv, (Int_t)(fThreshold + 1));
155 ClearColorArray();
156 IncRTS();
157
158}
159
eadce74d 160//______________________________________________________________________
d810d0de 161void AliEveMUONChamber::SetClusterSize(Int_t size)
eadce74d 162{
163 //
164 // cluster point size
165 //
166
167 fClusterSize = TMath::Max(1, size);
168 IncRTS();
169
170}
171
172//______________________________________________________________________
d810d0de 173void AliEveMUONChamber::SetHitSize(Int_t size)
eadce74d 174{
175 //
176 // hit point size
177 //
178
179 fHitSize = TMath::Max(1, size);
180 IncRTS();
181
182}
183
3626c858 184//______________________________________________________________________
d810d0de 185void AliEveMUONChamber::SetupColor(Int_t val, UChar_t* pixel) const
3626c858 186{
187 //
188 // RGBA color for amplitude "val"
189 //
190
191 Float_t div = TMath::Max(1, fMaxVal - fThreshold);
192 Int_t nCol = gStyle->GetNumberOfColors();
193 Int_t cBin = (Int_t) TMath::Nint(nCol*(val - fThreshold)/div);
194
d810d0de 195 TEveUtil::TEveUtil::ColorFromIdx(gStyle->GetColorPalette(TMath::Min(nCol - 1, cBin)), pixel);
3626c858 196
197}
198
199//______________________________________________________________________
d810d0de 200Int_t AliEveMUONChamber::ColorIndex(Int_t val) const
3626c858 201{
202 //
51346b82 203 // index color
3626c858 204 //
205
206 if(val < fThreshold) val = fThreshold;
207 if(val > fMaxVal) val = fMaxVal;
208
209 Float_t div = TMath::Max(1, fMaxVal - fThreshold);
210 Int_t nCol = gStyle->GetNumberOfColors();
211 Int_t cBin = (Int_t) TMath::Nint(nCol*(val - fThreshold)/div);
212
213 return gStyle->GetColorPalette(TMath::Min(nCol - 1, cBin));
214
215}
216
217//______________________________________________________________________
d810d0de 218void AliEveMUONChamber::SetupColorArray() const
3626c858 219{
220 //
221 // build array of colors
222 //
223
224 if(fColorArray)
225 return;
226
227 fColorArray = new UChar_t [4 * (fMaxVal - fThreshold + 1)];
228 UChar_t* p = fColorArray;
229 for(Int_t v=fThreshold; v<=fMaxVal; ++v, p+=4)
230 SetupColor(v, p);
231
232}
233
234//______________________________________________________________________
d810d0de 235void AliEveMUONChamber::ClearColorArray()
3626c858 236{
237 //
238 // delete array of colors
239 //
240
241 if(fColorArray) {
242 delete [] fColorArray;
243 fColorArray = 0;
244 }
245}
246
247//______________________________________________________________________
d810d0de 248void AliEveMUONChamber::SetDataSource(AliEveMUONData* data)
3626c858 249{
250
251 if (data == fMUONData) return;
252 if(fMUONData) fMUONData->DecRefCount();
253 fMUONData = data;
254 if(fMUONData) fMUONData->IncRefCount();
255 IncRTS();
256
257}
258
259//______________________________________________________________________
d810d0de 260AliEveMUONChamberData* AliEveMUONChamber::GetChamberData() const
3626c858 261{
51346b82 262
3626c858 263 return fMUONData ? fMUONData->GetChamberData(fChamberID) : 0;
264
265}
266
267//______________________________________________________________________
d810d0de 268void AliEveMUONChamber::UpdateQuads()
3626c858 269{
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
360//______________________________________________________________________
d810d0de 361void AliEveMUONChamber::SetChamberID(Int_t id)
3626c858 362{
363
364 if (id < 0) id = 0;
365 if (id > 13) id = 13;
366
367 fChamberID = id;
368 IncRTS();
369
370}
371