]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveTOFSector.cxx
Added cast to Color_t - needed by GCC 4.3
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveTOFSector.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 "AliEveTOFSector.h"
10
11 #include <AliTOFdigit.h>
12 #include <AliTOFGeometry.h>
13
14 #include <TEveTrans.h>
15 #include <TEveManager.h>
16 #include <TStyle.h>
17
18 Bool_t           AliEveTOFSector::fgStaticInitDone    = kFALSE;
19 TEveFrameBox*    AliEveTOFSector::fgTOFsectorFrameBox = 0;
20 TEveRGBAPalette* AliEveTOFSector::fgTOFsectorPalette  = 0;
21
22 //_______________________________________________________
23 ClassImp(AliEveTOFSector)
24
25 /* ************************************************************************ */
26
27 AliEveTOFSector::AliEveTOFSector(const Text_t* n, const Text_t* t) :
28   TEveQuadSet(n, t),
29   fTOFgeometry(new AliTOFGeometry()),
30   fTOFarray(0x0),
31   fTOFtree(0x0),
32   fSector(-1),
33   fDx(0), fDy(0), fDz(0),
34   fAutoTrans (kTRUE),
35   //fMinTime   (0), fMaxTime (0),
36   fThreshold (5), fMaxVal (80),
37   fSectorID  (0),
38   //fPlateFlag0(kTRUE), fPlateFlag1(kTRUE), fPlateFlag2(kTRUE), fPlateFlag3(kTRUE), fPlateFlag4(kTRUE),
39   fPlateFlag (0x0),
40   //fFrameColor(4),
41   //fRnrFrame  (kFALSE),
42   fGeoManager(0)
43 {
44
45   fPlateFlag = new Bool_t[5];
46   for (Int_t ii=0; ii<5; ii++) fPlateFlag[ii]=kTRUE;
47
48
49   //fGeoManager = AliEveEventManager::AssertGeometry();
50   if (!fGeoManager) {
51     printf("ERROR: no TGeo\n");
52   }
53
54 }
55 /* ************************************************************************ */
56
57 AliEveTOFSector::AliEveTOFSector(TGeoManager *localGeoManager,
58                      Int_t nSector)
59   :
60   TEveQuadSet(Form("Sector%i",nSector)),
61   fTOFgeometry(new AliTOFGeometry()),
62   fTOFarray(0x0),
63   fTOFtree(0x0),
64   fSector(nSector),
65   fDx(0), fDy(0), fDz(0),
66   fAutoTrans (kTRUE),
67   //fMinTime   (0), fMaxTime (0),
68   fThreshold (5), fMaxVal  (80),
69   fSectorID  (nSector),
70   //fPlateFlag0(kTRUE), fPlateFlag1(kTRUE), fPlateFlag2(kTRUE), fPlateFlag3(kTRUE), fPlateFlag4(kTRUE),
71   fPlateFlag (0x0),
72   //fFrameColor(4),
73   //fRnrFrame  (kFALSE),
74   fGeoManager(localGeoManager)
75 {
76
77   fPlateFlag = new Bool_t[5];
78   for (Int_t ii=0; ii<5; ii++) fPlateFlag[ii]=kTRUE;
79
80   /*
81   if (!fGeoManager) {
82     printf("ERROR: no TGeo\n");
83   }
84   */
85
86   InitModule();
87
88 }
89 /* ************************************************************************ */
90
91 AliEveTOFSector::AliEveTOFSector(TGeoManager *localGeoManager,
92                      Int_t nSector,
93                      TClonesArray *tofArray)
94   :
95   TEveQuadSet(Form("Sector%i",nSector)),
96   fTOFgeometry(new AliTOFGeometry()),
97   fTOFarray(tofArray),
98   fTOFtree(0x0),
99   fSector(nSector),
100   fDx(0), fDy(0), fDz(0),
101   fAutoTrans (kTRUE),
102   //fMinTime   (0), fMaxTime (0),
103   fThreshold (5), fMaxVal    (80),
104   fSectorID  (nSector),
105   //fPlateFlag0(kTRUE), fPlateFlag1(kTRUE), fPlateFlag2(kTRUE), fPlateFlag3(kTRUE), fPlateFlag4(kTRUE),
106   fPlateFlag (0x0),
107   //fFrameColor(4),
108   //fRnrFrame  (kFALSE),
109   fGeoManager(localGeoManager)
110 {
111
112   fPlateFlag = new Bool_t[5];
113   for (Int_t ii=0; ii<5; ii++) fPlateFlag[ii]=kTRUE;
114
115   InitModule();
116
117 }
118 /* ************************************************************************ */
119
120 AliEveTOFSector::AliEveTOFSector(TGeoManager *localGeoManager,
121                      Int_t nSector,
122                      TTree *tofTree)
123   :
124   TEveQuadSet(Form("Sector%i",nSector)),
125   fTOFgeometry(new AliTOFGeometry()),
126   fTOFarray(0x0),
127   fTOFtree(tofTree),
128   fSector(nSector),
129   fDx(0), fDy(0), fDz(0),
130   fAutoTrans (kTRUE),
131   //fMinTime   (0), fMaxTime (0),
132   fThreshold (5), fMaxVal    (80),
133   fSectorID  (nSector),
134   //fPlateFlag0(kTRUE), fPlateFlag1(kTRUE), fPlateFlag2(kTRUE), fPlateFlag3(kTRUE), fPlateFlag4(kTRUE),
135   fPlateFlag (0x0),
136   //fFrameColor(4),
137   //fRnrFrame  (kFALSE),
138   fGeoManager(localGeoManager)
139 {
140
141   fPlateFlag = new Bool_t[5];
142   for (Int_t ii=0; ii<5; ii++) fPlateFlag[ii]=kTRUE;
143
144   InitModule();
145
146 }
147 /* ************************************************************************ */
148
149 AliEveTOFSector::~AliEveTOFSector()
150 {
151   /*
152   fGeoManager = 0x0;
153   delete fGeoManager;
154
155   delete fTOFarray;
156   fTOFarray = 0x0;
157   */
158   delete fPlateFlag;
159
160 }
161
162 /* ************************************************************************ */
163 /*
164 void AliEveTOFSector::SetDigitsInfo(AliEveTOFDigitsInfo* info)
165 {
166   if(fInfo) fInfo->DecRefCount();
167   fInfo = info;
168   if(fInfo) fInfo->IncRefCount();
169
170 }
171 */
172 /* ************************************************************************ */
173 void AliEveTOFSector::InitStatics()
174 {
175   if (fgStaticInitDone) return;
176
177   Float_t dx = 124.5;
178   Float_t dz =  29.;
179   Float_t dy = 370.6*2.;
180   fgTOFsectorFrameBox = new TEveFrameBox();
181   fgTOFsectorFrameBox->SetAABox(-dx*0.5, -dy*0.5, -dz*0.5, dx, dy, dz);
182   fgTOFsectorFrameBox->SetFrameColor(Color_t(32));
183   fgTOFsectorFrameBox->IncRefCount();
184
185   //fgTOFsectorPalette  = new TEveRGBAPalette(0, 2048); // TOT
186   //fgTOFsectorPalette->SetLimits(0, 2048); 
187   //fgTOFsectorPalette  = new TEveRGBAPalette(0, 8192); // TDC
188   fgTOFsectorPalette  = new TEveRGBAPalette(0, 100000); // TDC
189   fgTOFsectorPalette->SetOverflowAction(2);
190   fgTOFsectorPalette->SetUnderflowAction(2);
191   fgTOFsectorPalette->IncRefCount();
192
193   fgStaticInitDone = kTRUE;
194 }
195
196 /* ************************************************************************ */
197 void AliEveTOFSector::InitModule()
198 {
199
200   fDx = fTOFgeometry->XPad()*fTOFgeometry->NpadX();
201   //fDy = fTOFgeometry->XPad()*fTOFgeometry->NpadX();
202   fDz = fTOFgeometry->ZPad()*fTOFgeometry->NpadZ();
203
204   if (!fgStaticInitDone) InitStatics();
205
206   SetFrame(fgTOFsectorFrameBox);
207   SetPalette(fgTOFsectorPalette);
208   //fFrame   = fgTOFsectorFrameBox;
209   //fPalette = fgTOFsectorPalette;
210
211   LoadQuads();
212   ComputeBBox();
213   SetTrans();
214
215 }
216
217 /* ************************************************************************ */
218 void AliEveTOFSector::LoadQuads()
219 {
220
221   //Int_t n_col = gStyle->GetNumberOfColors();
222
223   Int_t vol[5] = {fSectorID, -1, -1, -1, -1};
224   Int_t informations[4] = {-1, -1, -1, -1};
225   Int_t dummy[3] = {-1, -1, -1};
226   Int_t tdc = -1;
227   Int_t tot = -1;
228
229   Double_t **coord = new Double_t*[4];
230   for (Int_t ii=0; ii<4; ii++) coord[ii] = new Double_t[3];
231
232   Reset(kQT_FreeQuad, kFALSE, 32);
233
234   //printf(" fTOFarray->GetEntries() = %4i \n",fTOFarray->GetEntries());
235
236   if (fTOFtree && !fTOFarray) {
237     //printf("Hello world\n");
238     TClonesArray* digitsTOFnew = new TClonesArray("AliTOFdigit",  300);
239
240     fTOFarray = new TClonesArray("AliTOFdigit",  300);
241     TClonesArray &ldigits = *fTOFarray;
242     Int_t newCounter = 0;
243
244     AliTOFdigit *digs;
245
246     fTOFtree->SetBranchAddress("TOF",&digitsTOFnew);
247     fTOFtree->GetEntry(0);
248     for (Int_t digitNumber=0; digitNumber<digitsTOFnew->GetEntries(); digitNumber++) {
249
250       //if (digitNumber==digitsTOF->GetEntries()-1) printf(" Hello  4 -> %3i digit of %i \n", digitNumber+1, digitsTOF->GetEntries());
251
252       digs = (AliTOFdigit*)digitsTOFnew->UncheckedAt(digitNumber);
253
254       if (digs->GetSector()!=fSectorID) continue;
255
256       vol[1] = digs->GetPlate();  // Plate Number (0-4)
257       vol[2] = digs->GetStrip();  // Strip Number (0-14/18)
258       vol[3] = digs->GetPadx();   // Pad Number in x direction (0-47)
259       vol[4] = digs->GetPadz();   // Pad Number in z direction (0-1)
260
261       informations[0] = digs->GetTdc();
262       informations[1] = digs->GetAdc();
263       informations[2] = digs->GetToT();
264       informations[3] = digs->GetTdcND();
265       new (ldigits[newCounter++]) AliTOFdigit(dummy, vol, informations);
266     }
267   }
268
269   AliTOFdigit *tofDigit;
270   //printf("  0x%lx\n",fTOFarray);
271   for (Int_t ii=0; ii<fTOFarray->GetEntries(); ii++) {
272
273     tofDigit = (AliTOFdigit*)fTOFarray->UncheckedAt(ii);
274
275     if (fPlateFlag[tofDigit->GetPlate()]) {
276
277       vol[1] = tofDigit->GetPlate();
278       vol[2] = tofDigit->GetStrip();
279       vol[3] = tofDigit->GetPadz();
280       vol[4] = tofDigit->GetPadx();
281
282       tot = tofDigit->GetToT();
283       tdc = tofDigit->GetTdc();
284
285       //if (fSector==4 && fPlate==2 && fStrip==0) printf(" %2i  %1i\n", iPadX, iPadZ);
286       //if (iPadX==23 || iPadX==24) printf(" %2i  %1i %2i \n", fSector, fPlate, fStrip);
287       //if (vol[0]==4 && vol[1]==2 && vol[2]==7) {
288
289       for (Int_t kk=0; kk<4; kk++) for (Int_t jj=0; jj<3; jj++) coord[kk][jj]=0.;
290
291       fTOFgeometry->DetToSectorRF(vol, coord);
292       /*
293         printf("\n");
294         printf("  %1i   %2i,   %f  %f  %f \n", vol[3], vol[4], coord[0][0], coord[0][1], coord[0][2]);
295         printf("  %1i   %2i,   %f  %f  %f \n", vol[3], vol[4], coord[1][0], coord[1][1], coord[1][2]);
296         printf("  %1i   %2i,   %f  %f  %f \n", vol[3], vol[4], coord[2][0], coord[2][1], coord[2][2]);
297         printf("  %1i   %2i,   %f  %f  %f \n", vol[3], vol[4], coord[3][0], coord[3][1], coord[3][2]);
298       */
299       Float_t vertices[12]={(Float_t)coord[0][0], (Float_t)coord[0][1], (Float_t)coord[0][2],
300                             (Float_t)coord[1][0], (Float_t)coord[1][1], (Float_t)coord[1][2],
301                             (Float_t)coord[2][0], (Float_t)coord[2][1], (Float_t)coord[2][2],
302                             (Float_t)coord[3][0], (Float_t)coord[3][1], (Float_t)coord[3][2]};
303
304       AddQuad(vertices);
305       //AddQuad((Float_t*)coord);
306       //AddQuad(coord[0], coord[1], coord[2], 2.5, 3.5);
307       //AddQuad(-2.5*0.5, -3.5*0.5, 2.5, 3.5);
308
309       // In principle could have color based on number of neigbours. We
310       // can insert the time-of-flight value for each pad
311
312       //QuadValue((Int_t)tot);
313       QuadValue((Int_t)tdc);
314       QuadId(tofDigit);
315
316     //}
317     } // closed if control on plates switched on
318   } // closed loop on TOF sector digits
319
320   RefitPlex();
321
322   fTOFarray = 0x0;
323
324 }
325
326 /* ************************************************************ */
327 void AliEveTOFSector::SetTrans()
328 {
329   InitMainTrans();
330   TEveTrans& t = RefMainTrans();
331
332   //Int_t det[5] = {fSector, -1, -1, -1, -1};
333   Char_t path[100];
334
335   Int_t localSector = fSector;
336   if (!fAutoTrans) localSector = 4;
337
338   //fTOFgeometry->GetVolumePath(det,path);
339   fTOFgeometry->GetVolumePath(localSector,path);
340   fGeoManager->cd(path);
341   TGeoHMatrix global = *fGeoManager->GetCurrentMatrix();
342   Double_t *rotMat = global.GetRotationMatrix();
343   Double_t *tr = global.GetTranslation();
344
345   t.SetBaseVec(1, rotMat[0], rotMat[3], rotMat[6]);
346   t.SetBaseVec(2, rotMat[1], rotMat[4], rotMat[7]);
347   t.SetBaseVec(3, rotMat[2], rotMat[5], rotMat[8]);
348   t.SetBaseVec(4, tr);
349 }
350
351 //-----------------------------------------------------
352
353 void AliEveTOFSector::SetSectorID(Int_t id)
354 {
355   fSectorID = id;
356   fSector   = id;
357   if (fAutoTrans)
358     SetTrans(); // Force repositioning.
359
360   LoadQuads();
361 }
362
363 //-----------------------------------------------------
364
365 void AliEveTOFSector::SetPlate(Int_t nPlate, Bool_t r)
366 {
367
368   fPlateFlag[nPlate] = r;
369
370   //printf("   HELLO World ! %i %i %i \n", nPlate, r, fPlateFlag[nPlate]);
371 }
372
373 /******************************************************************************/
374
375 void AliEveTOFSector::SetThreshold(Short_t t)
376 {
377   fThreshold = TMath::Min(t, (Short_t)(fMaxVal - 1));
378   // ClearColorArray();
379 }
380
381 /******************************************************************************/
382
383 void AliEveTOFSector::SetMaxVal(Int_t mv)
384 {
385   fMaxVal = TMath::Max(mv, (Int_t)(fThreshold + 1));
386   //ClearColorArray();
387 }
388
389 /******************************************************************************/
390
391 void AliEveTOFSector::DigitSelected(Int_t idx)
392 {
393   // Override control-click from TEveQuadSet
394
395   DigitBase_t* qb   = GetDigit(idx);
396   TObject* obj   = qb->fId.GetObject();
397   AliTOFdigit* digs = dynamic_cast<AliTOFdigit*>(obj);
398   // printf("AliEveTOFSector::QuadSelected "); Print();
399   /*
400   printf("  idx = %5i, value = %5d, obj = 0x%lx, digit = 0x%lx  ",
401          idx, qb->fValue, (ULong_t)obj, (ULong_t)digs);
402   */
403   if (digs)
404     printf("\n Sector = %2i  Plate = %1i  Strip = %2i  PadZ = %1i PadX = %2i  ToT = %3i  Tof = %5i\n",
405            fSector , digs->GetPlate(), digs->GetStrip(), digs->GetPadz(), digs->GetPadx(), digs->GetToT(), digs->GetTdc());
406   else printf("\n");
407
408 }
409
410 /******************************************************************************/