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 **************************************************************************/
8 // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
11 // Class to visualize the TOF digit information
12 // in TOF sector frame
14 // Author: A. De Caro (email: decaro@sa.infn.t)
17 #include <TGeoManager.h>
18 #include <TClonesArray.h>
21 #include <TEveTrans.h>
23 #include <AliTOFdigit.h>
24 #include <AliTOFGeometry.h>
26 #include "AliEveTOFSector.h"
28 Bool_t AliEveTOFSector::fgStaticInitDone = kFALSE;
29 TEveFrameBox* AliEveTOFSector::fgTOFsectorFrameBox = 0;
30 TEveRGBAPalette* AliEveTOFSector::fgTOFsectorPalette = 0;
32 //_______________________________________________________
33 ClassImp(AliEveTOFSector)
35 /* ************************************************************************ */
37 AliEveTOFSector::AliEveTOFSector(const Text_t* n, const Text_t* t) :
39 fTOFgeometry(new AliTOFGeometry()),
43 fDx(0), fDy(0), fDz(0),
45 //fMinTime (0), fMaxTime (0),
46 fThreshold (5), fMaxVal (80),
48 //fPlateFlag0(kTRUE), fPlateFlag1(kTRUE), fPlateFlag2(kTRUE), fPlateFlag3(kTRUE), fPlateFlag4(kTRUE),
57 fPlateFlag = new Bool_t[5];
58 for (Int_t ii=0; ii<5; ii++) fPlateFlag[ii]=kTRUE;
61 //fGeoManager = AliEveEventManager::AssertGeometry();
63 printf("ERROR: no TGeo\n");
67 /* ************************************************************************ */
69 AliEveTOFSector::AliEveTOFSector(TGeoManager *localGeoManager,
72 TEveQuadSet(Form("Sector%i",nSector)),
73 fTOFgeometry(new AliTOFGeometry()),
77 fDx(0), fDy(0), fDz(0),
79 //fMinTime (0), fMaxTime (0),
80 fThreshold (5), fMaxVal (80),
82 //fPlateFlag0(kTRUE), fPlateFlag1(kTRUE), fPlateFlag2(kTRUE), fPlateFlag3(kTRUE), fPlateFlag4(kTRUE),
86 fGeoManager(localGeoManager)
91 fPlateFlag = new Bool_t[5];
92 for (Int_t ii=0; ii<5; ii++) fPlateFlag[ii]=kTRUE;
96 printf("ERROR: no TGeo\n");
103 /* ************************************************************************ */
105 AliEveTOFSector::AliEveTOFSector(TGeoManager *localGeoManager,
107 TClonesArray *tofArray)
109 TEveQuadSet(Form("Sector%i",nSector)),
110 fTOFgeometry(new AliTOFGeometry()),
114 fDx(0), fDy(0), fDz(0),
116 //fMinTime (0), fMaxTime (0),
117 fThreshold (5), fMaxVal (80),
119 //fPlateFlag0(kTRUE), fPlateFlag1(kTRUE), fPlateFlag2(kTRUE), fPlateFlag3(kTRUE), fPlateFlag4(kTRUE),
122 //fRnrFrame (kFALSE),
123 fGeoManager(localGeoManager)
128 fPlateFlag = new Bool_t[5];
129 for (Int_t ii=0; ii<5; ii++) fPlateFlag[ii]=kTRUE;
134 /* ************************************************************************ */
136 AliEveTOFSector::AliEveTOFSector(TGeoManager *localGeoManager,
140 TEveQuadSet(Form("Sector%i",nSector)),
141 fTOFgeometry(new AliTOFGeometry()),
145 fDx(0), fDy(0), fDz(0),
147 //fMinTime (0), fMaxTime (0),
148 fThreshold (5), fMaxVal (80),
150 //fPlateFlag0(kTRUE), fPlateFlag1(kTRUE), fPlateFlag2(kTRUE), fPlateFlag3(kTRUE), fPlateFlag4(kTRUE),
153 //fRnrFrame (kFALSE),
154 fGeoManager(localGeoManager)
159 fPlateFlag = new Bool_t[5];
160 for (Int_t ii=0; ii<5; ii++) fPlateFlag[ii]=kTRUE;
165 /* ************************************************************************ */
167 AliEveTOFSector::~AliEveTOFSector()
183 /* ************************************************************************ */
185 void AliEveTOFSector::SetDigitsInfo(AliEveTOFDigitsInfo* info)
187 if(fInfo) fInfo->DecRefCount();
189 if(fInfo) fInfo->IncRefCount();
193 /* ************************************************************************ */
194 void AliEveTOFSector::InitStatics()
197 // To initialize statistic variables
200 if (fgStaticInitDone) return;
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();
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();
218 fgStaticInitDone = kTRUE;
221 /* ************************************************************************ */
222 void AliEveTOFSector::InitModule()
225 // To initialize TOF sector frame variables
228 fDx = fTOFgeometry->XPad()*fTOFgeometry->NpadX();
229 //fDy = fTOFgeometry->XPad()*fTOFgeometry->NpadX();
230 fDz = fTOFgeometry->ZPad()*fTOFgeometry->NpadZ();
232 if (!fgStaticInitDone) InitStatics();
234 SetFrame(fgTOFsectorFrameBox);
235 SetPalette(fgTOFsectorPalette);
236 //fFrame = fgTOFsectorFrameBox;
237 //fPalette = fgTOFsectorPalette;
245 /* ************************************************************************ */
246 void AliEveTOFSector::LoadQuads()
249 // Load TOF digit as illuminated pad
252 //Int_t n_col = gStyle->GetNumberOfColors();
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};
260 Double_t **coord = new Double_t*[4];
261 for (Int_t ii=0; ii<4; ii++) coord[ii] = new Double_t[3];
263 Reset(kQT_FreeQuad, kFALSE, 32);
265 //printf(" fTOFarray->GetEntries() = %4i \n",fTOFarray->GetEntries());
267 if (fTOFtree && !fTOFarray) {
268 //printf("Hello world\n");
269 TClonesArray* digitsTOFnew = new TClonesArray("AliTOFdigit", 300);
271 fTOFarray = new TClonesArray("AliTOFdigit", 300);
272 TClonesArray &ldigits = *fTOFarray;
273 Int_t newCounter = 0;
277 fTOFtree->SetBranchAddress("TOF",&digitsTOFnew);
278 fTOFtree->GetEntry(0);
279 for (Int_t digitNumber=0; digitNumber<digitsTOFnew->GetEntries(); digitNumber++) {
281 //if (digitNumber==digitsTOF->GetEntries()-1) printf(" Hello 4 -> %3i digit of %i \n", digitNumber+1, digitsTOF->GetEntries());
283 digs = (AliTOFdigit*)digitsTOFnew->UncheckedAt(digitNumber);
285 if (digs->GetSector()!=fSectorID) continue;
287 vol[1] = digs->GetPlate(); // Plate Number (0-4)
288 vol[2] = digs->GetStrip(); // Strip Number (0-14/18)
289 vol[3] = digs->GetPadx(); // Pad Number in x direction (0-47)
290 vol[4] = digs->GetPadz(); // Pad Number in z direction (0-1)
292 informations[0] = digs->GetTdc();
293 informations[1] = digs->GetAdc();
294 informations[2] = digs->GetToT();
295 informations[3] = digs->GetTdcND();
296 new (ldigits[newCounter++]) AliTOFdigit(dummy, vol, informations);
300 AliTOFdigit *tofDigit;
301 //printf(" 0x%lx\n",fTOFarray);
302 for (Int_t ii=0; ii<fTOFarray->GetEntries(); ii++) {
304 tofDigit = (AliTOFdigit*)fTOFarray->UncheckedAt(ii);
306 if (fPlateFlag[tofDigit->GetPlate()]) {
308 vol[1] = tofDigit->GetPlate();
309 vol[2] = tofDigit->GetStrip();
310 vol[3] = tofDigit->GetPadz();
311 vol[4] = tofDigit->GetPadx();
313 tot = tofDigit->GetToT();
314 tdc = tofDigit->GetTdc();
316 //if (fSector==4 && fPlate==2 && fStrip==0) printf(" %2i %1i\n", iPadX, iPadZ);
317 //if (iPadX==23 || iPadX==24) printf(" %2i %1i %2i \n", fSector, fPlate, fStrip);
318 //if (vol[0]==4 && vol[1]==2 && vol[2]==7) {
320 for (Int_t kk=0; kk<4; kk++) for (Int_t jj=0; jj<3; jj++) coord[kk][jj]=0.;
322 fTOFgeometry->DetToSectorRF(vol, coord);
325 printf(" %1i %2i, %f %f %f \n", vol[3], vol[4], coord[0][0], coord[0][1], coord[0][2]);
326 printf(" %1i %2i, %f %f %f \n", vol[3], vol[4], coord[1][0], coord[1][1], coord[1][2]);
327 printf(" %1i %2i, %f %f %f \n", vol[3], vol[4], coord[2][0], coord[2][1], coord[2][2]);
328 printf(" %1i %2i, %f %f %f \n", vol[3], vol[4], coord[3][0], coord[3][1], coord[3][2]);
330 Float_t vertices[12]={(Float_t)coord[0][0], (Float_t)coord[0][1], (Float_t)coord[0][2],
331 (Float_t)coord[1][0], (Float_t)coord[1][1], (Float_t)coord[1][2],
332 (Float_t)coord[2][0], (Float_t)coord[2][1], (Float_t)coord[2][2],
333 (Float_t)coord[3][0], (Float_t)coord[3][1], (Float_t)coord[3][2]};
336 //AddQuad((Float_t*)coord);
337 //AddQuad(coord[0], coord[1], coord[2], 2.5, 3.5);
338 //AddQuad(-2.5*0.5, -3.5*0.5, 2.5, 3.5);
340 // In principle could have color based on number of neigbours. We
341 // can insert the time-of-flight value for each pad
343 //QuadValue((Int_t)tot);
344 QuadValue((Int_t)tdc);
348 } // closed if control on plates switched on
349 } // closed loop on TOF sector digits
357 /* ************************************************************ */
358 void AliEveTOFSector::SetTrans()
361 // Set the translation matrix for TOF sector
365 TEveTrans& t = RefMainTrans();
367 //Int_t det[5] = {fSector, -1, -1, -1, -1};
370 Int_t localSector = fSector;
371 if (!fAutoTrans) localSector = 4;
373 //fTOFgeometry->GetVolumePath(det,path);
374 fTOFgeometry->GetVolumePath(localSector,path);
375 fGeoManager->cd(path);
376 TGeoHMatrix global = *fGeoManager->GetCurrentMatrix();
377 Double_t *rotMat = global.GetRotationMatrix();
378 Double_t *tr = global.GetTranslation();
380 t.SetBaseVec(1, rotMat[0], rotMat[3], rotMat[6]);
381 t.SetBaseVec(2, rotMat[1], rotMat[4], rotMat[7]);
382 t.SetBaseVec(3, rotMat[2], rotMat[5], rotMat[8]);
386 //-----------------------------------------------------
388 void AliEveTOFSector::SetSectorID(Int_t id)
391 // Set TOF sector ID to be visualized
397 SetTrans(); // Force repositioning.
402 //-----------------------------------------------------
404 void AliEveTOFSector::SetPlate(Int_t nPlate, Bool_t r)
407 // Set visualization flag to visualize TOF modules
410 fPlateFlag[nPlate] = r;
412 //printf(" HELLO World ! %i %i %i \n", nPlate, r, fPlateFlag[nPlate]);
415 /******************************************************************************/
417 void AliEveTOFSector::SetThreshold(Short_t t)
420 // Set visualization threshold
423 fThreshold = TMath::Min(t, (Short_t)(fMaxVal - 1));
424 // ClearColorArray();
427 /******************************************************************************/
429 void AliEveTOFSector::SetMaxVal(Int_t mv)
432 // Set visualization max value
435 fMaxVal = TMath::Max(mv, (Int_t)(fThreshold + 1));
439 /******************************************************************************/
441 void AliEveTOFSector::DigitSelected(Int_t idx)
444 // Override control-click from TEveQuadSet
447 TObject* obj = GetId(idx);
448 AliTOFdigit* digs = dynamic_cast<AliTOFdigit*>(obj);
449 // printf("AliEveTOFSector::QuadSelected "); Print();
451 printf("\n Sector = %2i Plate = %1i Strip = %2i PadZ = %1i PadX = %2i ToT = %3i Tof = %5i\n",
452 fSector , digs->GetPlate(), digs->GetStrip(), digs->GetPadz(), digs->GetPadx(), digs->GetToT(), digs->GetTdc());
457 /******************************************************************************/