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