]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveMUONChamber.cxx
Temporary fix to avoid xrootd thrashing
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveMUONChamber.cxx
1 // $Id$
2 // Main authors: Matevz Tadel & Alja Mrak-Tadel: 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
19 #include <TStyle.h>
20 #include <TColor.h>
21 #include <TMath.h>
22
23
24 //______________________________________________________________________________
25 // AliEveMUONChamber
26 //
27
28 ClassImp(AliEveMUONChamber)
29
30 //______________________________________________________________________________
31 AliEveMUONChamber::AliEveMUONChamber(Int_t id, const Text_t* n, const Text_t* t) :
32 TEveElement(fFrameColor),
33 TNamed(n,t),
34 fMUONData(0),
35 fFrameColor((Color_t)2),
36 fRTS(1),
37 fChamberID(0),
38 fQuadSet1(n,t),
39 fQuadSet2(n,t),
40 fPointSet1(n),
41 fPointSet2(n),
42 fThreshold(0),
43 fMaxVal(4096),
44 fClusterSize(5),
45 fHitSize(5)
46 {
47   //
48   // constructor
49   //
50
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
59   ComputeBBox();
60
61 }
62
63 //______________________________________________________________________________
64 AliEveMUONChamber::~AliEveMUONChamber()
65 {
66   //
67   // destructor
68   //
69
70   if(fMUONData) fMUONData->DecRefCount();
71
72 }
73
74 //______________________________________________________________________________
75 void AliEveMUONChamber::ComputeBBox()
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
86
87   fBBox[0] = - 400.0;
88   fBBox[1] = + 400.0;
89   fBBox[2] = - 400.0;
90   fBBox[3] = + 400.0;
91   fBBox[4] = -1800.0;
92   fBBox[5] = + 500.0;
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]; }
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]; }
102
103 }
104
105 //______________________________________________________________________________
106 void AliEveMUONChamber::Paint(Option_t*)
107 {
108   //
109   // draw...
110   //
111
112   if(fRnrSelf == kFALSE)
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) {
125     //printf("AliEveMUONChamber::Paint viewer was happy with Core buff3d.\n");
126     return;
127   }
128
129   printf("AliEveMUONChamber::Paint only GL supported.\n");
130   return;
131
132 }
133
134 //______________________________________________________________________________
135 void AliEveMUONChamber::SetThreshold(Short_t t)
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 //______________________________________________________________________________
148 void AliEveMUONChamber::SetMaxVal(Int_t mv)
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
160 //______________________________________________________________________________
161 void AliEveMUONChamber::SetClusterSize(Int_t size)
162 {
163   //
164   // cluster point size
165   //
166
167   fClusterSize = TMath::Max(1, size);
168   IncRTS();
169
170 }
171
172 //______________________________________________________________________________
173 void AliEveMUONChamber::SetHitSize(Int_t size)
174 {
175   //
176   // hit point size
177   //
178
179   fHitSize = TMath::Max(1, size);
180   IncRTS();
181
182 }
183
184 //______________________________________________________________________________
185 void AliEveMUONChamber::SetupColor(Int_t val, UChar_t* pixel) const
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
195   TEveUtil::TEveUtil::ColorFromIdx(gStyle->GetColorPalette(TMath::Min(nCol - 1, cBin)), pixel);
196
197 }
198
199 //______________________________________________________________________________
200 Int_t AliEveMUONChamber::ColorIndex(Int_t val) const
201 {
202   //
203   // index color
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 //______________________________________________________________________________
218 void AliEveMUONChamber::SetupColorArray() const
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 //______________________________________________________________________________
235 void AliEveMUONChamber::ClearColorArray()
236 {
237   //
238   // delete array of colors
239   //
240
241   if(fColorArray) {
242     delete [] fColorArray;
243     fColorArray = 0;
244   }
245 }
246
247 //______________________________________________________________________________
248 void AliEveMUONChamber::SetDataSource(AliEveMUONData* data)
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 //______________________________________________________________________________
260 AliEveMUONChamberData* AliEveMUONChamber::GetChamberData() const
261 {
262
263   return fMUONData ? fMUONData->GetChamberData(fChamberID) : 0;
264
265 }
266
267 //______________________________________________________________________________
268 void AliEveMUONChamber::UpdateQuads()
269 {
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
364   if (id <  0) id = 0;
365   if (id > 13) id = 13;
366
367   fChamberID = id;
368   IncRTS();
369
370 }
371