]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveEMCALSModule.cxx
With Magali: improve handling of static data members with frame and palette data.
[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 Float_t          AliEveEMCALSModule::fgSMBigBBox[3];
37 Float_t          AliEveEMCALSModule::fgSMSmallBBox[3];
38 TEveFrameBox*    AliEveEMCALSModule::fgFrameBigBox = 0;
39 TEveFrameBox*    AliEveEMCALSModule::fgFrameSmallBox = 0;
40 TEveRGBAPalette* AliEveEMCALSModule::fgFrameDigPalette = 0;
41 TEveRGBAPalette* AliEveEMCALSModule::fgFrameCluPalette = 0;
42
43 AliEveEMCALSModule::AliEveEMCALSModule(Int_t smid, const Text_t* n, const Text_t* t) :
44   TEveElement(fFrameColor),
45   TNamed(n,t),
46   TAtt3D(),
47   fEMCALData(0),
48   fEMCALSModuleData(0),
49   fFrameColor((Color_t)10),
50   fSModuleID(smid),
51   fQuadSet(new TEveQuadSet(n,t)),
52   fQuadSet2(new TEveQuadSet(n,t)),
53   fPointSet(new TEvePointSet(n)),
54   fClusterSize(5),
55   fHitSize(5),
56   fDebug(0)
57 {
58   // Constructor.
59   Char_t name[256];
60   if (smid < 10) {
61     sprintf(name,"Full Super Module %02d",smid);
62   } else {
63     sprintf(name,"Half Super Module %02d",smid);
64   }
65   SetName(name);
66
67   // Hits
68   fPointSet->IncDenyDestroy();
69   AddElement(fPointSet);
70   // Digits
71   fQuadSet->IncDenyDestroy();
72   AddElement(fQuadSet);
73   // Clusters
74   fQuadSet2->IncDenyDestroy();
75   AddElement(fQuadSet2);
76
77 }
78
79 AliEveEMCALSModule::AliEveEMCALSModule(const AliEveEMCALSModule &esm) :
80   TEveElement(fFrameColor),
81   TNamed(),
82   TAtt3D(),
83   fEMCALData(esm.fEMCALData),
84   fEMCALSModuleData(esm.fEMCALSModuleData),
85   fFrameColor(esm.fFrameColor),
86   fSModuleID(esm.fSModuleID),
87   fQuadSet(esm.fQuadSet),
88   fQuadSet2(esm.fQuadSet2),
89   fPointSet(esm.fPointSet),
90   fClusterSize(esm.fClusterSize),
91   fHitSize(esm.fHitSize),
92   fDebug(esm.fDebug)
93 {
94   // Copy constructor.
95   Char_t name[256];
96   if (fSModuleID < 10) {
97     sprintf(name,"Full Super Module %02d",fSModuleID);
98   } else {
99     sprintf(name,"Half Super Module %02d",fSModuleID);
100   }
101   SetName(name);
102
103   // Hits
104   fPointSet->IncDenyDestroy();
105   AddElement(fPointSet);
106   // Digits
107   fQuadSet->IncDenyDestroy();
108   AddElement(fQuadSet);
109   // Clusters
110   fQuadSet2->IncDenyDestroy();
111   AddElement(fQuadSet2);
112
113 }
114
115 AliEveEMCALSModule::~AliEveEMCALSModule()
116 {
117   //
118   // Destructor.
119   //
120
121   fPointSet->DecDenyDestroy();
122   fQuadSet->DecDenyDestroy();
123   fQuadSet2->DecDenyDestroy();
124
125   if(fEMCALData) fEMCALData->DecRefCount();
126 }
127
128 //______________________________________________________________________________
129 void AliEveEMCALSModule::DropData()
130 {
131   //
132   // release the sm data
133   //
134
135 //   fNDigits   = 0;
136 //   fNClusters = 0;
137 //   fNHits     = 0;
138
139   return;
140
141 }
142
143 //______________________________________________________________________________
144 void AliEveEMCALSModule::InitStatics(AliEveEMCALSModuleData* md)
145 {
146   //
147   // Bounding box, Framebox and Palette
148   //
149
150   if (fStaticInit) return;
151   fStaticInit = kTRUE;
152
153   md->GetSModuleBigBox(fgSMBigBBox[0],fgSMBigBBox[1], fgSMBigBBox[2]);
154   md->GetSModuleSmallBox(fgSMSmallBBox[0],fgSMSmallBBox[1], fgSMSmallBBox[2]);
155
156   fgFrameBigBox = new TEveFrameBox();
157   fgFrameBigBox->SetAABoxCenterHalfSize(0, 0, 0, fgSMBigBBox[0], fgSMBigBBox[1], fgSMBigBBox[2]);
158   fgFrameBigBox->SetFrameColor((Color_t)10);
159   fgFrameBigBox->IncRefCount();
160   fgFrameDigPalette = new TEveRGBAPalette(0,512);
161   fgFrameDigPalette->SetLimits(0, 1024);
162   fgFrameDigPalette->IncRefCount();
163
164   fgFrameSmallBox = new TEveFrameBox();
165   fgFrameSmallBox->SetAABoxCenterHalfSize(0, 0, 0, fgSMSmallBBox[0], fgSMSmallBBox[1], fgSMSmallBBox[2]);
166   fgFrameSmallBox->SetFrameColor((Color_t)10);
167   fgFrameSmallBox->IncRefCount();
168   fgFrameCluPalette  = new TEveRGBAPalette(0,512);
169   fgFrameCluPalette->SetLimits(0, 1024);
170   fgFrameCluPalette->IncRefCount();
171 }
172
173 //______________________________________________________________________________
174 void AliEveEMCALSModule::SetClusterSize(Int_t size)
175 {
176   //
177   // Cluster point size
178   //
179
180   fClusterSize = TMath::Max(1, size);
181 }
182
183 //______________________________________________________________________________
184 void AliEveEMCALSModule::SetHitSize(Int_t size)
185 {
186   //
187   // hit point size
188   //
189
190   fHitSize = TMath::Max(1, size);
191 }
192
193 //______________________________________________________________________________
194 void AliEveEMCALSModule::SetDataSource(AliEveEMCALData* data)
195 {
196   //
197   // Set source of data.
198   //
199
200   if (data == fEMCALData) return;
201   if(fEMCALData) fEMCALData->DecRefCount();
202   fEMCALData = data;
203   if(fEMCALData) fEMCALData->IncRefCount();
204
205   // Get pointer on SM data
206   fEMCALSModuleData = GetSModuleData();
207 }
208
209 //______________________________________________________________________________
210 AliEveEMCALSModuleData* AliEveEMCALSModule::GetSModuleData() const
211 {
212   //
213   // Return source of data.
214   //
215
216   return fEMCALData ? fEMCALData->GetSModuleData(fSModuleID) : 0;
217 }
218
219 //______________________________________________________________________________
220 void AliEveEMCALSModule::UpdateQuads()
221 {
222   //
223   // Update hit/digit/cluster representation.
224   //
225
226   vector< vector<Double_t> > bufferDigit;
227   vector< vector<Double_t> > bufferCluster;
228   vector< vector<Float_t> > bufferHit;
229   Int_t nDigits, nClusters, nHits, oldSize;
230   Float_t hitX, hitY, hitZ;
231   Int_t smId = fEMCALSModuleData->GetSmId();
232
233   //--------------------------
234   // Hits from runloader
235   //--------------------------
236   fPointSet->Reset();
237
238   /*
239   TEvePointSet* points = fEMCALData->GetPointSetData();
240   char form[1000];
241   if(points){
242     sprintf(form,"N=%d", points->Size());
243     points->SetTitle(form);
244     points->SetMarkerSize(.5);
245     points->SetMarkerColor((Color_t)2);
246     fPointSet->AddElement(points);
247   }
248   else {printf("There is no hits in Runloader \n"); }
249   
250   */
251
252   if (fEMCALSModuleData != 0) {
253
254     if (!fStaticInit)
255       InitStatics(fEMCALSModuleData);
256
257     // digits ------------------------
258
259     // Define TEveQuadSet for digits
260     fQuadSet->SetOwnIds(kTRUE);
261     fQuadSet->Reset(TEveQuadSet::kQT_RectangleYZFixedDimX, kFALSE, 32);
262     fQuadSet->SetDefWidth (fEMCALSModuleData->GetPhiTileSize());
263     fQuadSet->SetDefHeight(fEMCALSModuleData->GetEtaTileSize());
264     fQuadSet->RefMainTrans().SetFrom(*fEMCALSModuleData->GetSModuleMatrix());
265     fQuadSet->SetPalette(fgFrameDigPalette);
266     if(smId<fEMCALSModuleData->GetNsmf()) 
267       fQuadSet->SetFrame(fgFrameBigBox);
268     else fQuadSet->SetFrame(fgFrameSmallBox);
269
270     // Get the digit information from the buffer
271     bufferDigit = fEMCALSModuleData->GetDigitBuffer();
272     if(!bufferDigit.empty())
273       {
274         nDigits = fEMCALSModuleData->GetNDigits();
275         if(fDebug>1) cout << "nDigits: " << nDigits << endl;
276         // loop over digits
277         for (Int_t id = 0; id < nDigits; id++) {
278           //      Int_t iid = (Int_t)bufferDigit[id][0];
279           //      Int_t isupMod = (Int_t)bufferDigit[id][1];
280           Double_t iamp = bufferDigit[id][2];
281           Int_t amp = (Int_t)(iamp+0.5);
282           //      Double_t ix = bufferDigit[id][3];
283           Double_t iy = bufferDigit[id][4];
284           Double_t iz = bufferDigit[id][5];
285           
286           // Add digit information to the TEveQuadSet
287           fQuadSet->AddQuad(iy, iz);
288           fQuadSet->QuadValue(amp);
289         } // end digits loop
290       }
291     else { if (fDebug) printf("There is no digits in SM %d \n", smId); }
292
293     // hits --------------------------
294     bufferHit = fEMCALSModuleData->GetHitBuffer();
295     if(!bufferHit.empty())
296       {
297         char form[1000];
298         nHits = fEMCALSModuleData->GetNHits();
299         if(fDebug>1) cout << "nHits: " << nHits << endl;
300         oldSize = fPointSet->GrowFor(nHits);
301         // Loop over hits
302         for (Int_t ih = 0; ih < nHits; ih++) {
303           hitX = bufferHit[ih][3];
304           hitY = bufferHit[ih][4];
305           hitZ = bufferHit[ih][5];
306           fPointSet->SetPoint(ih,hitX,hitY,hitZ);
307           sprintf(form,"N=%d", fPointSet->Size());
308           fPointSet->SetTitle(form);
309           fPointSet->SetMarkerSize(.5);
310           fPointSet->SetMarkerColor((Color_t)2);
311         }
312       }
313     else { if (fDebug) printf("There is no hits in SM %d \n", smId); }
314
315     // clusters ------------------------
316
317     // Define TEveQuadSet for clusters
318     fQuadSet2->SetOwnIds(kTRUE);
319     fQuadSet2->Reset(TEveQuadSet::kQT_RectangleYZFixedDimX, kFALSE, 32);
320     fQuadSet2->SetDefWidth (fEMCALSModuleData->GetPhiTileSize());
321     fQuadSet2->SetDefHeight(fEMCALSModuleData->GetEtaTileSize());
322     fQuadSet2->RefMainTrans().SetFrom(*fEMCALSModuleData->GetSModuleMatrix());
323     fQuadSet2->SetPalette(fgFrameCluPalette);
324     if(smId<fEMCALSModuleData->GetNsmf()) 
325       fQuadSet2->SetFrame(fgFrameBigBox);
326     else fQuadSet2->SetFrame(fgFrameSmallBox);
327
328     // Get the cluster information from the buffer
329     bufferCluster = fEMCALSModuleData->GetClusterBuffer();
330     if(!bufferCluster.empty())
331       {
332         nClusters = fEMCALSModuleData->GetNClusters();
333         if(fDebug>1) cout << "nClusters: " << nClusters << endl;
334         // loop over clusters
335         for (Int_t id = 0; id < nClusters; id++) {
336           if(fDebug>1) {
337             cout << "bufferCluster[" << id << "][0]: " << bufferCluster[id][0] << endl;
338             cout << "bufferCluster[" << id << "][1]: " << bufferCluster[id][1] << endl;
339             cout << "bufferCluster[" << id << "][2]: " << bufferCluster[id][2] << endl;
340             cout << "bufferCluster[" << id << "][3]: " << bufferCluster[id][3] << endl;
341             cout << "bufferCluster[" << id << "][4]: " << bufferCluster[id][4] << endl;
342           }
343           //      Int_t isupMod = (Int_t)bufferCluster[id][0];
344           Double_t iamp = bufferCluster[id][1];
345           Int_t amp = (Int_t)(iamp+0.5);
346           //      Double_t ix = bufferCluster[id][2];
347           Double_t iy = bufferCluster[id][3];
348           Double_t iz = bufferCluster[id][4];
349           
350           // Add cluster information to the TEveQuadSet
351           fQuadSet2->AddQuad(iy, iz);
352           fQuadSet2->QuadValue(amp);
353           //      fQuadSet2->QuadId(iid);
354
355         } // end clusters loop
356       }
357     else { if (fDebug) printf("There is no clusters in SM %d \n", smId); }
358
359   } // end if (fEMCALSModuleData != 0)
360
361 }
362
363 //______________________________________________________________________________
364 void AliEveEMCALSModule::SetSModuleID(Int_t id)
365 {
366   //
367   // Set id of the SM to display.
368   //
369
370   if (id <  0) id = 0;
371   if (id > 12) id = 12;
372
373   fSModuleID = id;
374 }