]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveMUONChamber.cxx
58ab755f4141e8147a715ab269968a183ff08e6c
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveMUONChamber.cxx
1 // $Id$
2 // Main authors: Matevz Tadel & Alja Mrak-Tadel & Bogdan Vulpescu: 2006, 2007
3
4 /**************************************************************************
5  * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6  * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
7  * full copyright notice.                                                 *
8  **************************************************************************/
9 #include "AliEveMUONChamber.h"
10
11 #include <EveDet/AliEveMUONData.h>
12 #include <EveDet/AliEveMUONChamberData.h>
13
14 #include <TBuffer3D.h>
15 #include <TBuffer3DTypes.h>
16 #include <TVirtualPad.h>
17 #include <TVirtualViewer3D.h>
18 #include <TStyle.h>
19 #include <TMath.h>
20
21
22 //______________________________________________________________________________
23 // AliEveMUONChamber
24 //
25
26 ClassImp(AliEveMUONChamber)
27
28 //______________________________________________________________________________
29 AliEveMUONChamber::AliEveMUONChamber(Int_t id, const Text_t* n, const Text_t* t) :
30   TEveElement(fFrameColor),
31   TNamed(n,t),
32   fMUONData(0),
33   fFrameColor(2),
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)
45 {
46   //
47   // constructor
48   //
49
50   Char_t name[256];
51   if (id < 10) {
52     sprintf(name,"Chamber %02d (trac)",id);
53   } else {
54     sprintf(name,"Chamber %02d (trig)",id);
55   }
56   SetName(name);
57
58   ComputeBBox();
59
60 }
61
62 //______________________________________________________________________________
63 AliEveMUONChamber::~AliEveMUONChamber()
64 {
65   //
66   // destructor
67   //
68
69   if(fMUONData) fMUONData->DecRefCount();
70
71 }
72
73 //______________________________________________________________________________
74 void AliEveMUONChamber::ComputeBBox()
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
85
86   fBBox[0] = - 400.0;
87   fBBox[1] = + 400.0;
88   fBBox[2] = - 400.0;
89   fBBox[3] = + 400.0;
90   fBBox[4] = -1800.0;
91   fBBox[5] = + 500.0;
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]; }
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]; }
101
102 }
103
104 //______________________________________________________________________________
105 void AliEveMUONChamber::Paint(Option_t*)
106 {
107   //
108   // draw...
109   //
110
111   if(fRnrSelf == kFALSE)
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) {
124     //printf("AliEveMUONChamber::Paint viewer was happy with Core buff3d.\n");
125     return;
126   }
127
128   printf("AliEveMUONChamber::Paint only GL supported.\n");
129   return;
130
131 }
132
133 //______________________________________________________________________________
134 void AliEveMUONChamber::SetThreshold(Short_t t)
135 {
136   //
137   // digits amplitude threshold
138   //
139
140   fThreshold = TMath::Min(t, (Short_t)(fMaxVal - 1));
141   ClearColorArray();
142   IncRTS();
143
144 }
145
146 //______________________________________________________________________________
147 void AliEveMUONChamber::SetMaxVal(Int_t mv)
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
159 //______________________________________________________________________________
160 void AliEveMUONChamber::SetClusterSize(Int_t size)
161 {
162   //
163   // cluster point size
164   //
165
166   fClusterSize = TMath::Max(1, size);
167   IncRTS();
168
169 }
170
171 //______________________________________________________________________________
172 void AliEveMUONChamber::SetHitSize(Int_t size)
173 {
174   //
175   // hit point size
176   //
177
178   fHitSize = TMath::Max(1, size);
179   IncRTS();
180
181 }
182
183 //______________________________________________________________________________
184 void AliEveMUONChamber::SetupColor(Int_t val, UChar_t* pixel) const
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
194   TEveUtil::TEveUtil::ColorFromIdx(gStyle->GetColorPalette(TMath::Min(nCol - 1, cBin)), pixel);
195
196 }
197
198 //______________________________________________________________________________
199 Int_t AliEveMUONChamber::ColorIndex(Int_t val) const
200 {
201   //
202   // index color
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
216 //______________________________________________________________________________
217 void AliEveMUONChamber::SetupColorArray() const
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
233 //______________________________________________________________________________
234 void AliEveMUONChamber::ClearColorArray()
235 {
236   //
237   // delete array of colors
238   //
239
240   if(fColorArray) {
241     delete [] fColorArray;
242     fColorArray = 0;
243   }
244 }
245
246 //______________________________________________________________________________
247 void AliEveMUONChamber::SetDataSource(AliEveMUONData* data)
248 {
249   // Set source of data.
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 AliEveMUONChamberData* AliEveMUONChamber::GetChamberData() const
260 {
261   // Return source of data.
262
263   return fMUONData ? fMUONData->GetChamberData(fChamberID) : 0;
264 }
265
266 //______________________________________________________________________________
267 void AliEveMUONChamber::UpdateQuads()
268 {
269   // Update digit representation.
270
271   fQuadSet1.Reset(TEveQuadSet::kQT_RectangleXY, kTRUE, 32);
272   fQuadSet2.Reset(TEveQuadSet::kQT_RectangleXY, kTRUE, 32);
273   fPointSet1.Reset();
274   fPointSet2.Reset();
275
276   AliEveMUONChamberData* data = GetChamberData();
277
278   Float_t *buffer;
279   Float_t x0, y0, z, w, h, clsq;
280   Int_t charge, cathode, nDigits, nClusters, nHits, oldSize, ic1, ic2;
281   Double_t clsX, clsY, clsZ;
282   Float_t hitX, hitY, hitZ;
283
284   if (data != 0) {
285
286     SetupColorArray();
287
288     // digits
289
290     nDigits = data->GetNDigits();
291
292     for (Int_t id = 0; id < nDigits; id++) {
293
294       buffer = data->GetDigitBuffer(id);
295
296       x0 = buffer[0]-buffer[2];
297       y0 = buffer[1]-buffer[3];
298       w  = 2*buffer[2];
299       h  = 2*buffer[3];
300       z  = buffer[4];
301       charge = (Int_t)buffer[5];
302       cathode = (Int_t)buffer[6];
303
304       if (charge <= fThreshold) continue;
305
306       if (cathode == 0) {
307
308         fQuadSet1.AddQuad(x0, y0, z, w, h);
309         fQuadSet1.QuadColor(ColorIndex(charge));
310
311       }
312
313       if (cathode == 1) {
314
315         fQuadSet2.AddQuad(x0, y0, z, w, h);
316         fQuadSet2.QuadColor(ColorIndex(charge));
317
318       }
319
320     } // end digits loop
321
322     // clusters
323
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];
334       clsq    = buffer[3];
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
357
358 }
359
360 //______________________________________________________________________________
361 void AliEveMUONChamber::SetChamberID(Int_t id)
362 {
363   // Set id of chamber to display.
364
365   if (id <  0) id = 0;
366   if (id > 13) id = 13;
367
368   fChamberID = id;
369   IncRTS();
370 }
371