1 //*************************************************************************
3 // Visualization of an EMCAL super module.
5 // Author: Magali Estienne (magali.estienne@cern.ch)
7 //*************************************************************************
12 #include <TEveTrans.h>
13 #include <TEveElement.h>
14 #include <TEveFrameBox.h>
15 #include <TEveQuadSet.h>
16 #include <TEvePointSet.h>
17 #include <TClonesArray.h>
20 #include <TBuffer3DTypes.h>
21 #include <TBuffer3D.h>
22 #include <TVirtualPad.h>
23 #include <TVirtualViewer3D.h>
24 #include <TEveRGBAPalette.h>
26 #include "AliEveEMCALData.h"
27 #include "AliEveEMCALSModule.h"
28 #include "AliEveEMCALSModuleData.h"
29 #include "AliEMCALHit.h"
30 #include "AliEMCALDigit.h"
33 ClassImp(AliEveEMCALSModule)
35 Bool_t AliEveEMCALSModule::fStaticInit = kFALSE;
37 TEveFrameBox* AliEveEMCALSModule::fFrameBigBox = 0;
38 TEveFrameBox* AliEveEMCALSModule::fFrameSmallBox = 0;
39 TEveRGBAPalette* AliEveEMCALSModule::fFrameDigPalette = 0;
40 TEveRGBAPalette* AliEveEMCALSModule::fFrameCluPalette = 0;
42 AliEveEMCALSModule::AliEveEMCALSModule(Int_t smid, const Text_t* n, const Text_t* t) :
43 TEveElement(fFrameColor),
49 fFrameColor((Color_t)10),
52 fQuadSet(new TEveQuadSet(n,t)),
53 fQuadSet2(new TEveQuadSet(n,t)),
54 fPointSet(new TEvePointSet(n)),
65 sprintf(name,"Full Super Module %02d",smid);
67 sprintf(name,"Half Super Module %02d",smid);
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.;
76 fPointSet->IncDenyDestroy();
77 AddElement(fPointSet);
79 fQuadSet->IncDenyDestroy();
82 fQuadSet2->IncDenyDestroy();
83 AddElement(fQuadSet2);
87 AliEveEMCALSModule::AliEveEMCALSModule(const AliEveEMCALSModule &esm) :
88 TEveElement(fFrameColor),
92 fEMCALData(esm.fEMCALData),
93 fEMCALSModuleData(esm.fEMCALSModuleData),
94 fFrameColor(esm.fFrameColor),
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),
109 if (fSModuleID < 10) {
110 sprintf(name,"Full Super Module %02d",fSModuleID);
112 sprintf(name,"Half Super Module %02d",fSModuleID);
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.;
121 fPointSet->IncDenyDestroy();
122 AddElement(fPointSet);
124 fQuadSet->IncDenyDestroy();
125 AddElement(fQuadSet);
127 fQuadSet2->IncDenyDestroy();
128 AddElement(fQuadSet2);
132 AliEveEMCALSModule::~AliEveEMCALSModule()
138 fPointSet->DecDenyDestroy();
139 fQuadSet->DecDenyDestroy();
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();
149 //______________________________________________________________________________
150 void AliEveEMCALSModule::DropData()
153 // release the sm data
164 //______________________________________________________________________________
165 void AliEveEMCALSModule::ComputeBBox()
168 // Bounding box, Framebox and Palette
171 fEMCALSModuleData->GetSModuleBigBox(fSMBigBBox[0],fSMBigBBox[1], fSMBigBBox[2]);
172 fEMCALSModuleData->GetSModuleSmallBox(fSMSmallBBox[0],fSMSmallBBox[1], fSMSmallBBox[2]);
174 if (fStaticInit) return;
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();
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();
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];
202 //______________________________________________________________________________
203 void AliEveEMCALSModule::SetThreshold(Short_t t)
206 // Digit amplitude threshold
209 fThreshold = TMath::Min(t, (Short_t)(fMaxVal - 1));
215 //______________________________________________________________________________
216 void AliEveEMCALSModule::SetMaxVal(Int_t mv)
219 // Digit amplitude maximum value
222 fMaxVal = TMath::Max(mv, (Int_t)(fThreshold + 1));
228 //______________________________________________________________________________
229 void AliEveEMCALSModule::SetClusterSize(Int_t size)
232 // Cluster point size
235 fClusterSize = TMath::Max(1, size);
240 //______________________________________________________________________________
241 void AliEveEMCALSModule::SetHitSize(Int_t size)
247 fHitSize = TMath::Max(1, size);
252 //______________________________________________________________________________
253 void AliEveEMCALSModule::SetupColor(Int_t val, UChar_t* pixel) const
256 // RGBA color for amplitude "val"
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);
263 TEveUtil::TEveUtil::ColorFromIdx(gStyle->GetColorPalette(TMath::Min(nCol - 1, cBin)), pixel);
267 //______________________________________________________________________________
268 Int_t AliEveEMCALSModule::ColorIndex(Int_t val) const
274 if(val < fThreshold) val = fThreshold;
275 if(val > fMaxVal) val = fMaxVal;
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);
281 return gStyle->GetColorPalette(TMath::Min(nCol - 1, cBin));
285 //______________________________________________________________________________
286 void AliEveEMCALSModule::SetupColorArray() const
289 // Build array of colors
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)
302 //______________________________________________________________________________
303 void AliEveEMCALSModule::ClearColorArray()
306 // Delete array of colors
310 delete [] fColorArray;
315 //______________________________________________________________________________
316 void AliEveEMCALSModule::SetDataSource(AliEveEMCALData* data)
319 // Set source of data.
322 if (data == fEMCALData) return;
323 if(fEMCALData) fEMCALData->DecRefCount();
325 if(fEMCALData) fEMCALData->IncRefCount();
327 // Get pointer on SM data
328 fEMCALSModuleData = GetSModuleData();
333 //______________________________________________________________________________
334 AliEveEMCALSModuleData* AliEveEMCALSModule::GetSModuleData() const
337 // Return source of data.
340 return fEMCALData ? fEMCALData->GetSModuleData(fSModuleID) : 0;
343 //______________________________________________________________________________
344 void AliEveEMCALSModule::UpdateQuads()
347 // Update hit/digit/cluster representation.
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();
357 //--------------------------
358 // Hits from runloader
359 //--------------------------
363 TEvePointSet* points = fEMCALData->GetPointSetData();
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);
372 else {printf("There is no hits in Runloader \n"); }
376 if (fEMCALSModuleData != 0) {
378 // digits ------------------------
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);
391 // Get the digit information from the buffer
392 bufferDigit = fEMCALSModuleData->GetDigitBuffer();
393 if(!bufferDigit.empty())
395 nDigits = fEMCALSModuleData->GetNDigits();
396 if(fDebug>1) cout << "nDigits: " << nDigits << endl;
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];
407 // Add digit information to the TEveQuadSet
408 fQuadSet->AddQuad(iy, iz);
409 fQuadSet->QuadValue(amp);
412 else { printf("There is no digits in SM %d \n", smId); }
414 // hits --------------------------
415 bufferHit = fEMCALSModuleData->GetHitBuffer();
416 if(!bufferHit.empty())
419 nHits = fEMCALSModuleData->GetNHits();
420 if(fDebug>1) cout << "nHits: " << nHits << endl;
421 oldSize = fPointSet->GrowFor(nHits);
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);
434 else {printf("There is no hits in SM %d \n", smId); }
436 // clusters ------------------------
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);
449 // Get the cluster information from the buffer
450 bufferCluster = fEMCALSModuleData->GetClusterBuffer();
451 if(!bufferCluster.empty())
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++) {
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;
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];
471 // Add cluster information to the TEveQuadSet
472 fQuadSet2->AddQuad(iy, iz);
473 fQuadSet2->QuadValue(amp);
474 // fQuadSet2->QuadId(iid);
476 } // end clusters loop
478 else { printf("There is no clusters in SM %d \n", smId); }
480 } // end if (fEMCALSModuleData != 0)
484 //______________________________________________________________________________
485 void AliEveEMCALSModule::SetSModuleID(Int_t id)
488 // Set id of the SM to display.
492 if (id > 12) id = 12;