]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveEMCALSModule.cxx
Using the new altro raw-data format. Removing some obsolete macros.
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveEMCALSModule.cxx
1 //*************************************************************************
2 // EMCAL event display
3 // Visualization of an EMCAL super module.
4 //
5 //  Author: Magali Estienne (magali.estienne@cern.ch)
6 //  June 30 2008
7 //*************************************************************************
8
9 #include <Riostream.h>
10 #include <vector>
11
12 #include <TEveTrans.h>
13 #include <TEveElement.h>
14 #include <TEveFrameBox.h>
15 #include <TEveQuadSet.h>
16 #include <TEvePointSet.h>
17 #include <TClonesArray.h>
18 #include <TVectorT.h>
19 #include <TStyle.h>
20 #include <TBuffer3DTypes.h>
21 #include <TBuffer3D.h>
22 #include <TVirtualPad.h>
23 #include <TVirtualViewer3D.h>
24 #include <TEveRGBAPalette.h>
25
26 #include "AliEveEMCALData.h"
27 #include "AliEveEMCALSModule.h"
28 #include "AliEveEMCALSModuleData.h"
29 #include "AliEMCALHit.h"
30 #include "AliEMCALDigit.h"
31
32
33 ClassImp(AliEveEMCALSModule)
34
35 Bool_t AliEveEMCALSModule::fStaticInit = kFALSE;
36
37 TEveFrameBox*    AliEveEMCALSModule::fFrameBigBox = 0;
38 TEveFrameBox*    AliEveEMCALSModule::fFrameSmallBox = 0;
39 TEveRGBAPalette* AliEveEMCALSModule::fFrameDigPalette = 0;
40 TEveRGBAPalette* AliEveEMCALSModule::fFrameCluPalette = 0;
41
42 AliEveEMCALSModule::AliEveEMCALSModule(Int_t smid, const Text_t* n, const Text_t* t) :
43   TEveElement(fFrameColor),
44   TNamed(n,t),
45   TAtt3D(),
46   TAttBBox(),
47   fEMCALData(0),
48   fEMCALSModuleData(0),
49   fFrameColor((Color_t)10),
50   fRTS(1),
51   fSModuleID(smid),
52   fQuadSet(new TEveQuadSet(n,t)),
53   fQuadSet2(new TEveQuadSet(n,t)),
54   fPointSet(new TEvePointSet(n)),
55   fThreshold(0),
56   fMaxVal(4096),
57   fClusterSize(5),
58   fHitSize(5),
59   fColorArray(0),
60   fDebug(0)
61 {
62   // Constructor.
63   Char_t name[256];
64   if (smid < 10) {
65     sprintf(name,"Full Super Module %02d",smid);
66   } else {
67     sprintf(name,"Half Super Module %02d",smid);
68   }
69   SetName(name);
70
71   for(Int_t i=0; i<3; i++) fSMBigBBox[i] = 0.;
72   for(Int_t i=0; i<3; i++) fSMSmallBBox[i] = 0.;
73   for(Int_t i=0; i<3; i++) fSMBBoxCenter[i] = 0.;
74
75   // Hits
76   fPointSet->IncDenyDestroy();
77   AddElement(fPointSet);
78   // Digits
79   fQuadSet->IncDenyDestroy();
80   AddElement(fQuadSet);
81   // Clusters
82   fQuadSet2->IncDenyDestroy();
83   AddElement(fQuadSet2);
84
85 }
86
87 AliEveEMCALSModule::AliEveEMCALSModule(const AliEveEMCALSModule &esm) :
88   TEveElement(fFrameColor),
89   TNamed(),
90   TAtt3D(),
91   TAttBBox(),
92   fEMCALData(esm.fEMCALData),
93   fEMCALSModuleData(esm.fEMCALSModuleData),
94   fFrameColor(esm.fFrameColor),
95   fRTS(esm.fRTS),
96   fSModuleID(esm.fSModuleID),
97   fQuadSet(esm.fQuadSet),
98   fQuadSet2(esm.fQuadSet2),
99   fPointSet(esm.fPointSet),
100   fThreshold(esm.fThreshold),
101   fMaxVal(esm.fMaxVal),
102   fClusterSize(esm.fClusterSize),
103   fHitSize(esm.fHitSize),
104   fColorArray(esm.fColorArray),
105   fDebug(esm.fDebug)
106 {
107   // Copy constructor.
108   Char_t name[256];
109   if (fSModuleID < 10) {
110     sprintf(name,"Full Super Module %02d",fSModuleID);
111   } else {
112     sprintf(name,"Half Super Module %02d",fSModuleID);
113   }
114   SetName(name);
115
116   for(Int_t i=0; i<3; i++) fSMBigBBox[i] = 0.;
117   for(Int_t i=0; i<3; i++) fSMSmallBBox[i] = 0.;
118   for(Int_t i=0; i<3; i++) fSMBBoxCenter[i] = 0.;
119
120   // Hits
121   fPointSet->IncDenyDestroy();
122   AddElement(fPointSet);
123   // Digits
124   fQuadSet->IncDenyDestroy();
125   AddElement(fQuadSet);
126   // Clusters
127   fQuadSet2->IncDenyDestroy();
128   AddElement(fQuadSet2);
129
130 }
131
132 AliEveEMCALSModule::~AliEveEMCALSModule()
133 {
134   //
135   // Destructor.
136   //
137
138   fPointSet->DecDenyDestroy();
139   fQuadSet->DecDenyDestroy();
140
141   if(fEMCALData) fEMCALData->DecRefCount();
142   if(fFrameBigBox)   fFrameBigBox->Delete();
143   if(fFrameSmallBox) fFrameSmallBox->Delete();
144   if(fFrameDigPalette) fFrameDigPalette->Delete();
145   if(fFrameCluPalette) fFrameCluPalette->Delete();
146
147 }
148
149 //______________________________________________________________________________
150 void AliEveEMCALSModule::DropData()
151 {
152   //
153   // release the sm data
154   //
155
156 //   fNDigits   = 0;
157 //   fNClusters = 0;
158 //   fNHits     = 0;
159
160   return;
161
162 }
163
164 //______________________________________________________________________________
165 void AliEveEMCALSModule::ComputeBBox()
166 {
167   //
168   // Bounding box, Framebox and Palette
169   //
170
171   fEMCALSModuleData->GetSModuleBigBox(fSMBigBBox[0],fSMBigBBox[1], fSMBigBBox[2]);
172   fEMCALSModuleData->GetSModuleSmallBox(fSMSmallBBox[0],fSMSmallBBox[1], fSMSmallBBox[2]);
173
174   if (fStaticInit) return;
175   fStaticInit = kTRUE;
176
177   fFrameBigBox = new TEveFrameBox();
178   fFrameBigBox->SetAABoxCenterHalfSize(0, 0, 0, fSMBigBBox[0], fSMBigBBox[1], fSMBigBBox[2]);
179   fFrameBigBox->SetFrameColor((Color_t)10);
180   fFrameDigPalette = new TEveRGBAPalette(0,512);
181   fFrameDigPalette->SetLimits(0, 1024);
182   fFrameDigPalette->IncRefCount();
183
184   fFrameSmallBox = new TEveFrameBox();
185   fFrameSmallBox->SetAABoxCenterHalfSize(0, 0, 0, fSMSmallBBox[0], fSMSmallBBox[1], fSMSmallBBox[2]);
186   fFrameSmallBox->SetFrameColor((Color_t)10);
187   fFrameCluPalette  = new TEveRGBAPalette(0,512);
188   fFrameCluPalette->SetLimits(0, 1024);
189   fFrameCluPalette->IncRefCount();
190
191   BBoxInit();
192
193   fBBox[0] = - 2*fSMBigBBox[0];
194   fBBox[1] = + 2*fSMBigBBox[0];
195   fBBox[2] = - 2*fSMBigBBox[1];
196   fBBox[3] = + 2*fSMBigBBox[1];
197   fBBox[4] = - 2*fSMBigBBox[2];
198   fBBox[5] = + 2*fSMBigBBox[2];
199
200 }
201
202 //______________________________________________________________________________
203 void AliEveEMCALSModule::SetThreshold(Short_t t)
204 {
205   //
206   // Digit amplitude threshold
207   //
208
209   fThreshold = TMath::Min(t, (Short_t)(fMaxVal - 1));
210   ClearColorArray();
211   IncRTS();
212
213 }
214
215 //______________________________________________________________________________
216 void AliEveEMCALSModule::SetMaxVal(Int_t mv)
217 {
218   //
219   // Digit amplitude maximum value
220   //
221
222   fMaxVal = TMath::Max(mv, (Int_t)(fThreshold + 1));
223   ClearColorArray();
224   IncRTS();
225
226 }
227
228 //______________________________________________________________________________
229 void AliEveEMCALSModule::SetClusterSize(Int_t size)
230 {
231   //
232   // Cluster point size
233   //
234
235   fClusterSize = TMath::Max(1, size);
236   IncRTS();
237
238 }
239
240 //______________________________________________________________________________
241 void AliEveEMCALSModule::SetHitSize(Int_t size)
242 {
243   //
244   // hit point size
245   //
246
247   fHitSize = TMath::Max(1, size);
248   IncRTS();
249
250 }
251
252 //______________________________________________________________________________
253 void AliEveEMCALSModule::SetupColor(Int_t val, UChar_t* pixel) const
254 {
255   //
256   // RGBA color for amplitude "val"
257   //
258
259   Float_t div  = TMath::Max(1, fMaxVal - fThreshold);
260   Int_t   nCol = gStyle->GetNumberOfColors();
261   Int_t   cBin = (Int_t) TMath::Nint(nCol*(val - fThreshold)/div);
262
263   TEveUtil::TEveUtil::ColorFromIdx(gStyle->GetColorPalette(TMath::Min(nCol - 1, cBin)), pixel);
264
265 }
266
267 //______________________________________________________________________________
268 Int_t AliEveEMCALSModule::ColorIndex(Int_t val) const
269 {
270   //
271   // Index color
272   //
273
274   if(val < fThreshold) val = fThreshold;
275   if(val > fMaxVal)    val = fMaxVal;
276
277   Float_t div  = TMath::Max(1, fMaxVal - fThreshold);
278   Int_t   nCol = gStyle->GetNumberOfColors();
279   Int_t   cBin = (Int_t) TMath::Nint(nCol*(val - fThreshold)/div);
280
281   return gStyle->GetColorPalette(TMath::Min(nCol - 1, cBin));
282
283 }
284
285 //______________________________________________________________________________
286 void AliEveEMCALSModule::SetupColorArray() const
287 {
288   //
289   // Build array of colors
290   //
291
292   if(fColorArray)
293     return;
294
295   fColorArray = new UChar_t [4 * (fMaxVal - fThreshold + 1)];
296   UChar_t* p = fColorArray;
297   for(Int_t v=fThreshold; v<=fMaxVal; ++v, p+=4)
298     SetupColor(v, p);
299
300 }
301
302 //______________________________________________________________________________
303 void AliEveEMCALSModule::ClearColorArray()
304 {
305   //
306   // Delete array of colors
307   //
308
309   if(fColorArray) {
310     delete [] fColorArray;
311     fColorArray = 0;
312   }
313 }
314
315 //______________________________________________________________________________
316 void AliEveEMCALSModule::SetDataSource(AliEveEMCALData* data)
317 {
318   //
319   // Set source of data.
320   //
321
322   if (data == fEMCALData) return;
323   if(fEMCALData) fEMCALData->DecRefCount();
324   fEMCALData = data;
325   if(fEMCALData) fEMCALData->IncRefCount();
326
327   // Get pointer on SM data
328   fEMCALSModuleData = GetSModuleData();
329
330   IncRTS();
331 }
332
333 //______________________________________________________________________________
334 AliEveEMCALSModuleData* AliEveEMCALSModule::GetSModuleData() const
335 {
336   //
337   // Return source of data.
338   //
339
340   return fEMCALData ? fEMCALData->GetSModuleData(fSModuleID) : 0;
341 }
342
343 //______________________________________________________________________________
344 void AliEveEMCALSModule::UpdateQuads()
345 {
346   //
347   // Update hit/digit/cluster representation.
348   //
349
350   vector< vector<Double_t> > bufferDigit;
351   vector< vector<Double_t> > bufferCluster;
352   vector< vector<Float_t> > bufferHit;
353   Int_t nDigits, nClusters, nHits, oldSize;
354   Float_t hitX, hitY, hitZ;
355   Int_t smId = fEMCALSModuleData->GetSmId();
356
357   //--------------------------
358   // Hits from runloader
359   //--------------------------
360   fPointSet->Reset();
361
362   /*
363   TEvePointSet* points = fEMCALData->GetPointSetData();
364   char form[1000];
365   if(points){
366     sprintf(form,"N=%d", points->Size());
367     points->SetTitle(form);
368     points->SetMarkerSize(.5);
369     points->SetMarkerColor((Color_t)2);
370     fPointSet->AddElement(points);
371   }
372   else {printf("There is no hits in Runloader \n"); }
373   
374   */
375
376   if (fEMCALSModuleData != 0) {
377     
378     // digits ------------------------
379
380     // Define TEveQuadSet for digits
381     fQuadSet->SetOwnIds(kTRUE);
382     fQuadSet->Reset(TEveQuadSet::kQT_RectangleYZFixedDimX, kFALSE, 32);
383     fQuadSet->SetDefWidth (fEMCALSModuleData->GetPhiTileSize());
384     fQuadSet->SetDefHeight(fEMCALSModuleData->GetEtaTileSize());
385     fQuadSet->RefMainTrans().SetFrom(*fEMCALSModuleData->GetSModuleMatrix());
386     fQuadSet->SetPalette(fFrameDigPalette);
387     if(smId<fEMCALSModuleData->GetNsmf()) 
388       fQuadSet->SetFrame(fFrameBigBox);
389     else fQuadSet->SetFrame(fFrameSmallBox);
390
391     // Get the digit information from the buffer
392     bufferDigit = fEMCALSModuleData->GetDigitBuffer();
393     if(!bufferDigit.empty())
394       {
395         nDigits = fEMCALSModuleData->GetNDigits();
396         if(fDebug>1) cout << "nDigits: " << nDigits << endl;
397         // loop over digits
398         for (Int_t id = 0; id < nDigits; id++) {
399           //      Int_t iid = (Int_t)bufferDigit[id][0];
400           //      Int_t isupMod = (Int_t)bufferDigit[id][1];
401           Double_t iamp = bufferDigit[id][2];
402           Int_t amp = (Int_t)(iamp+0.5);
403           //      Double_t ix = bufferDigit[id][3];
404           Double_t iy = bufferDigit[id][4];
405           Double_t iz = bufferDigit[id][5];
406           
407           // Add digit information to the TEveQuadSet
408           fQuadSet->AddQuad(iy, iz);
409           fQuadSet->QuadValue(amp);
410         } // end digits loop
411       }
412     else { printf("There is no digits in SM %d \n", smId); }
413
414     // hits --------------------------
415     bufferHit = fEMCALSModuleData->GetHitBuffer();
416     if(!bufferHit.empty())
417       {
418         char form[1000];
419         nHits = fEMCALSModuleData->GetNHits();
420         if(fDebug>1) cout << "nHits: " << nHits << endl;
421         oldSize = fPointSet->GrowFor(nHits);
422         // Loop over hits
423         for (Int_t ih = 0; ih < nHits; ih++) {
424           hitX = bufferHit[ih][3];
425           hitY = bufferHit[ih][4];
426           hitZ = bufferHit[ih][5];
427           fPointSet->SetPoint(ih,hitX,hitY,hitZ);
428           sprintf(form,"N=%d", fPointSet->Size());
429           fPointSet->SetTitle(form);
430           fPointSet->SetMarkerSize(.5);
431           fPointSet->SetMarkerColor((Color_t)2);
432         }
433       }
434     else {printf("There is no hits in SM %d \n", smId); }
435
436     // clusters ------------------------
437
438     // Define TEveQuadSet for clusters
439     fQuadSet2->SetOwnIds(kTRUE);
440     fQuadSet2->Reset(TEveQuadSet::kQT_RectangleYZFixedDimX, kFALSE, 32);
441     fQuadSet2->SetDefWidth (fEMCALSModuleData->GetPhiTileSize());
442     fQuadSet2->SetDefHeight(fEMCALSModuleData->GetEtaTileSize());
443     fQuadSet2->RefMainTrans().SetFrom(*fEMCALSModuleData->GetSModuleMatrix());
444     fQuadSet2->SetPalette(fFrameCluPalette);
445     if(smId<fEMCALSModuleData->GetNsmf()) 
446       fQuadSet2->SetFrame(fFrameBigBox);
447     else fQuadSet2->SetFrame(fFrameSmallBox);
448
449     // Get the cluster information from the buffer
450     bufferCluster = fEMCALSModuleData->GetClusterBuffer();
451     if(!bufferCluster.empty())
452       {
453         nClusters = fEMCALSModuleData->GetNClusters();
454         if(fDebug>1) cout << "nClusters: " << nClusters << endl;
455         // loop over clusters
456         for (Int_t id = 0; id < nClusters; id++) {
457           if(fDebug>1) {
458             cout << "bufferCluster[" << id << "][0]: " << bufferCluster[id][0] << endl;
459             cout << "bufferCluster[" << id << "][1]: " << bufferCluster[id][1] << endl;
460             cout << "bufferCluster[" << id << "][2]: " << bufferCluster[id][2] << endl;
461             cout << "bufferCluster[" << id << "][3]: " << bufferCluster[id][3] << endl;
462             cout << "bufferCluster[" << id << "][4]: " << bufferCluster[id][4] << endl;
463           }
464           //      Int_t isupMod = (Int_t)bufferCluster[id][0];
465           Double_t iamp = bufferCluster[id][1];
466           Int_t amp = (Int_t)(iamp+0.5);
467           //      Double_t ix = bufferCluster[id][2];
468           Double_t iy = bufferCluster[id][3];
469           Double_t iz = bufferCluster[id][4];
470           
471           // Add cluster information to the TEveQuadSet
472           fQuadSet2->AddQuad(iy, iz);
473           fQuadSet2->QuadValue(amp);
474           //      fQuadSet2->QuadId(iid);
475
476         } // end clusters loop
477       }
478     else { printf("There is no clusters in SM %d \n", smId); }
479
480   } // end if (fEMCALSModuleData != 0)
481
482 }
483
484 //______________________________________________________________________________
485 void AliEveEMCALSModule::SetSModuleID(Int_t id)
486 {
487   //
488   // Set id of the SM to display.
489   //
490
491   if (id <  0) id = 0;
492   if (id > 12) id = 12;
493
494   fSModuleID = id;
495   IncRTS();
496 }