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