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