]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveDet/AliEveEMCALSModule.cxx
Small correction for shifts in SSD (M. Van Leeuwen)
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveEMCALSModule.cxx
CommitLineData
c3e34498 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
33ClassImp(AliEveEMCALSModule)
34
a312477b 35Bool_t AliEveEMCALSModule::fStaticInit = kFALSE;
36
c3e34498 37TEveFrameBox* AliEveEMCALSModule::fFrameBigBox = 0;
38TEveFrameBox* AliEveEMCALSModule::fFrameSmallBox = 0;
39TEveRGBAPalette* AliEveEMCALSModule::fFrameDigPalette = 0;
40TEveRGBAPalette* AliEveEMCALSModule::fFrameCluPalette = 0;
41
42AliEveEMCALSModule::AliEveEMCALSModule(Int_t smid, const Text_t* n, const Text_t* t) :
43 TEveElement(fFrameColor),
44 TNamed(n,t),
a312477b 45 TAtt3D(),
46 TAttBBox(),
c3e34498 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
87AliEveEMCALSModule::AliEveEMCALSModule(const AliEveEMCALSModule &esm) :
88 TEveElement(fFrameColor),
89 TNamed(),
a312477b 90 TAtt3D(),
91 TAttBBox(),
c3e34498 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{
a312477b 107 // Copy constructor.
c3e34498 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
132AliEveEMCALSModule::~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//______________________________________________________________________________
150void 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//______________________________________________________________________________
165void AliEveEMCALSModule::ComputeBBox()
166{
167 //
a312477b 168 // Bounding box, Framebox and Palette
c3e34498 169 //
170
171 fEMCALSModuleData->GetSModuleBigBox(fSMBigBBox[0],fSMBigBBox[1], fSMBigBBox[2]);
172 fEMCALSModuleData->GetSModuleSmallBox(fSMSmallBBox[0],fSMSmallBBox[1], fSMSmallBBox[2]);
173
a312477b 174 if (fStaticInit) return;
175 fStaticInit = kTRUE;
c3e34498 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//______________________________________________________________________________
203void AliEveEMCALSModule::SetThreshold(Short_t t)
204{
205 //
a312477b 206 // Digit amplitude threshold
c3e34498 207 //
208
209 fThreshold = TMath::Min(t, (Short_t)(fMaxVal - 1));
210 ClearColorArray();
211 IncRTS();
212
213}
214
215//______________________________________________________________________________
216void AliEveEMCALSModule::SetMaxVal(Int_t mv)
217{
218 //
a312477b 219 // Digit amplitude maximum value
c3e34498 220 //
221
222 fMaxVal = TMath::Max(mv, (Int_t)(fThreshold + 1));
223 ClearColorArray();
224 IncRTS();
225
226}
227
228//______________________________________________________________________________
229void AliEveEMCALSModule::SetClusterSize(Int_t size)
230{
231 //
a312477b 232 // Cluster point size
c3e34498 233 //
234
235 fClusterSize = TMath::Max(1, size);
236 IncRTS();
237
238}
239
240//______________________________________________________________________________
241void 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//______________________________________________________________________________
253void 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//______________________________________________________________________________
268Int_t AliEveEMCALSModule::ColorIndex(Int_t val) const
269{
270 //
a312477b 271 // Index color
c3e34498 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//______________________________________________________________________________
286void AliEveEMCALSModule::SetupColorArray() const
287{
288 //
a312477b 289 // Build array of colors
c3e34498 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//______________________________________________________________________________
303void AliEveEMCALSModule::ClearColorArray()
304{
305 //
a312477b 306 // Delete array of colors
c3e34498 307 //
308
309 if(fColorArray) {
310 delete [] fColorArray;
311 fColorArray = 0;
312 }
313}
314
315//______________________________________________________________________________
316void AliEveEMCALSModule::SetDataSource(AliEveEMCALData* data)
317{
a312477b 318 //
c3e34498 319 // Set source of data.
a312477b 320 //
c3e34498 321
322 if (data == fEMCALData) return;
323 if(fEMCALData) fEMCALData->DecRefCount();
324 fEMCALData = data;
325 if(fEMCALData) fEMCALData->IncRefCount();
326
a312477b 327 // Get pointer on SM data
c3e34498 328 fEMCALSModuleData = GetSModuleData();
329
330 IncRTS();
331}
332
333//______________________________________________________________________________
334AliEveEMCALSModuleData* AliEveEMCALSModule::GetSModuleData() const
335{
a312477b 336 //
c3e34498 337 // Return source of data.
a312477b 338 //
c3e34498 339
340 return fEMCALData ? fEMCALData->GetSModuleData(fSModuleID) : 0;
341}
342
343//______________________________________________________________________________
344void AliEveEMCALSModule::UpdateQuads()
345{
a312477b 346 //
c3e34498 347 // Update hit/digit/cluster representation.
a312477b 348 //
c3e34498 349
a312477b 350 vector< vector<Double_t> > bufferDigit;
351 vector< vector<Double_t> > bufferCluster;
c3e34498 352 vector< vector<Float_t> > bufferHit;
a312477b 353 Int_t nDigits, nClusters, nHits, oldSize;
c3e34498 354 Float_t hitX, hitY, hitZ;
355 Int_t smId = fEMCALSModuleData->GetSmId();
356
357 //--------------------------
358 // Hits from runloader
359 //--------------------------
360 fPointSet->Reset();
361
a312477b 362 /*
c3e34498 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
a312477b 374 */
375
c3e34498 376 if (fEMCALSModuleData != 0) {
377
378 // digits ------------------------
a312477b 379
380 // Define TEveQuadSet for digits
c3e34498 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
a312477b 391 // Get the digit information from the buffer
c3e34498 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++) {
a312477b 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];
c3e34498 406
a312477b 407 // Add digit information to the TEveQuadSet
c3e34498 408 fQuadSet->AddQuad(iy, iz);
a312477b 409 fQuadSet->QuadValue(amp);
c3e34498 410 } // end digits loop
411 }
412 else { printf("There is no digits in SM %d \n", smId); }
413
414 // hits --------------------------
a312477b 415 bufferHit = fEMCALSModuleData->GetHitBuffer();
c3e34498 416 if(!bufferHit.empty())
417 {
a312477b 418 char form[1000];
c3e34498 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++) {
a312477b 424 hitX = bufferHit[ih][3];
425 hitY = bufferHit[ih][4];
426 hitZ = bufferHit[ih][5];
c3e34498 427 fPointSet->SetPoint(ih,hitX,hitY,hitZ);
a312477b 428 sprintf(form,"N=%d", fPointSet->Size());
429 fPointSet->SetTitle(form);
430 fPointSet->SetMarkerSize(.5);
431 fPointSet->SetMarkerColor((Color_t)2);
c3e34498 432 }
433 }
434 else {printf("There is no hits in SM %d \n", smId); }
435
436 // clusters ------------------------
a312477b 437
438 // Define TEveQuadSet for clusters
c3e34498 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
a312477b 449 // Get the cluster information from the buffer
c3e34498 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 }
a312477b 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];
c3e34498 470
a312477b 471 // Add cluster information to the TEveQuadSet
c3e34498 472 fQuadSet2->AddQuad(iy, iz);
a312477b 473 fQuadSet2->QuadValue(amp);
c3e34498 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//______________________________________________________________________________
485void AliEveEMCALSModule::SetSModuleID(Int_t id)
486{
a312477b 487 //
488 // Set id of the SM to display.
489 //
c3e34498 490
491 if (id < 0) id = 0;
492 if (id > 12) id = 12;
493
494 fSModuleID = id;
495 IncRTS();
496}