]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveTOFDigitsInfo.cxx
Coverity
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveTOFDigitsInfo.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 map TOF digit/raw data information
12 //
13 // Author: A. De Caro (email: decaro@sa.infn.it)
14 //
15
16 #include <TClonesArray.h>
17 #include <TTree.h>
18
19 //#include <TEveTreeTools.h>
20
21 #include <AliDAQ.h>
22 #include <AliLog.h>
23 #include <AliRawReader.h>
24
25 #include <AliTOFCableLengthMap.h>
26 #include <AliTOFdigit.h>
27 #include <AliTOFGeometry.h>
28 #include <AliTOFrawData.h>
29 #include <AliTOFRawStream.h>
30 #include <AliTOFDigitMap.h>
31
32 #include "AliEveTOFDigitsInfo.h"
33
34 //_________________________________________________________
35
36 ClassImp(AliEveTOFDigitsInfo)
37
38   AliEveTOFDigitsInfo::AliEveTOFDigitsInfo(): 
39     TObject(),
40     TEveRefCnt(),
41     fTree (0),
42     fNewTree (0),
43     fGeom (new AliTOFGeometry()),
44     fTOFdigitMap(new AliTOFDigitMap())
45 {}
46 /* ******************************************************* */
47
48 AliEveTOFDigitsInfo:: ~AliEveTOFDigitsInfo() 
49 {
50   //dtr
51
52   delete fGeom;
53   delete fTree;
54   delete fNewTree;
55   delete fTOFdigitMap;
56
57 }
58 /* ******************************************************* */
59
60 void AliEveTOFDigitsInfo::SetTree(TTree * const tree)
61 {
62   //
63   // Set fTree global variable
64   //
65
66   static const TEveException kEH("AliEveTOFDigitsInfo::SetTree ");
67   
68   if(fGeom == 0) {
69     fGeom = new AliTOFGeometry();
70   }
71
72   fTree = tree;
73   /*
74   DecRefCount();
75   IncRefCount();
76   */
77 }
78 /* ******************************************************* */
79 void AliEveTOFDigitsInfo::ReadRaw(AliRawReader* rawReader, Bool_t newDecoder)
80 {
81   //
82   // Read raw-data. AliTOFdigit is used to
83   // store raw-adata for all sub-detectors.
84   //
85
86   AliTOFCableLengthMap *cableLength = new AliTOFCableLengthMap();
87
88   //ofstream ftxt;
89   //Char_t fileName[100];
90   //sprintf(fileName,"TOFrawDataReadingFromEVE%d.txt",nEvent);
91
92   //ftxt.open(fileName,ios::app);
93   //ftxt << endl;
94   //ftxt << "  " << nEvent << endl;
95
96   //if (nEvent<0) printf("%3i\n", nEvent); // only to use nEvent variable
97
98   const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
99
100   TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000);
101   fTree = new TTree();
102   fTree->Branch("TOF", &tofDigits, 32000);
103   fTree->GetEntry(0);
104
105   TClonesArray * clonesRawData = 0x0;
106
107   Int_t detectorIndex[5];
108   Int_t digit[4];
109
110   AliTOFRawStream stream(rawReader);
111
112   for (Int_t indexDDL = 0; indexDDL < kDDL; indexDDL++) {
113
114     rawReader->Reset();
115     if (!newDecoder) stream.LoadRawData(indexDDL);
116     else stream.LoadRawDataBuffers(indexDDL);
117
118     clonesRawData = (TClonesArray*)stream.GetRawData();
119
120     if (clonesRawData->GetEntriesFast()) AliDebug(2, Form(" Number of TOF digits in the sector number %2i: %5i", indexDDL, clonesRawData->GetEntriesFast()));
121
122     for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
123
124       AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
125
126       if (tofRawDatum->GetTOF()==-1) continue;
127
128       Int_t cLenInt = Int_t(cableLength->GetCableTimeShift(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),tofRawDatum->GetTDC())*1000./AliTOFGeometry::TdcBinWidth());
129       digit[0] = tofRawDatum->GetTOF() - cLenInt;
130       digit[1] = tofRawDatum->GetTOT();
131       digit[2] = tofRawDatum->GetTOT();
132       digit[3] = -1;
133
134       /*
135       if (indexDDL<10) ftxt << "  " << indexDDL;
136       else             ftxt << " " << indexDDL;
137       if (tofRawDatum->GetTRM()<10) ftxt << "  " << tofRawDatum->GetTRM();
138       else                          ftxt << " " << tofRawDatum->GetTRM();
139       ftxt << "  " << tofRawDatum->GetTRMchain();
140       if (tofRawDatum->GetTDC()<10) ftxt << "  " << tofRawDatum->GetTDC();
141       else                          ftxt << " " << tofRawDatum->GetTDC();
142       ftxt << "  " << tofRawDatum->GetTDCchannel();
143       */
144
145       stream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
146                                   tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
147
148       if (detectorIndex[0]==0 || detectorIndex[0]==10)
149         AliDebug(2, Form(" %2i %2i %1i %2i %1i --- %2i %1i %2i %1i %2i     %5i -  %4i =  %5i (%f ns)\n",
150                          indexDDL,
151                          tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
152                          tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(),
153                          detectorIndex[0], detectorIndex[1],
154                          detectorIndex[2], detectorIndex[3],
155                          detectorIndex[4], tofRawDatum->GetTOF(),
156                          cLenInt, tofRawDatum->GetTOF()-cLenInt,
157                          (tofRawDatum->GetTOF()-cLenInt)*
158                          AliTOFGeometry::TdcBinWidth()/1000.));
159
160       /*
161       if (detectorIndex[0]<10) ftxt  << "  ->  " << detectorIndex[0];
162       else                     ftxt  << "  -> " << detectorIndex[0];
163       ftxt << "  " << detectorIndex[1];
164       if (detectorIndex[2]<10) ftxt << "  " << detectorIndex[2];
165       else                     ftxt << " " << detectorIndex[2];
166       ftxt << "  " << detectorIndex[3];
167       if (detectorIndex[4]<10) ftxt << "  " << detectorIndex[4];
168       else                     ftxt << " " << detectorIndex[4];
169
170       if (tofRawDatum->GetTOT()<10)                                            ftxt << "        " << tofRawDatum->GetTOT();
171       else if (tofRawDatum->GetTOT()>=10 && tofRawDatum->GetTOT()<100)         ftxt << "       " << tofRawDatum->GetTOT();
172       else if (tofRawDatum->GetTOT()>=100 && tofRawDatum->GetTOT()<1000)       ftxt << "      " << tofRawDatum->GetTOT();
173       else if (tofRawDatum->GetTOT()>=1000 && tofRawDatum->GetTOT()<10000)     ftxt << "     " << tofRawDatum->GetTOT();
174       else if (tofRawDatum->GetTOT()>=10000 && tofRawDatum->GetTOT()<100000)   ftxt << "    " << tofRawDatum->GetTOT();
175       else if (tofRawDatum->GetTOT()>=100000 && tofRawDatum->GetTOT()<1000000) ftxt << "   " << tofRawDatum->GetTOT();
176       else                                                                     ftxt << "  " << tofRawDatum->GetTOT();
177       if (tofRawDatum->GetTOF()<10)                                            ftxt << "        " << tofRawDatum->GetTOF() << endl;
178       else if (tofRawDatum->GetTOF()>=10 && tofRawDatum->GetTOF()<100)         ftxt << "       " << tofRawDatum->GetTOF() << endl;
179       else if (tofRawDatum->GetTOF()>=100 && tofRawDatum->GetTOF()<1000)       ftxt << "      " << tofRawDatum->GetTOF() << endl;
180       else if (tofRawDatum->GetTOF()>=1000 && tofRawDatum->GetTOF()<10000)     ftxt << "     " << tofRawDatum->GetTOF() << endl;
181       else if (tofRawDatum->GetTOF()>=10000 && tofRawDatum->GetTOF()<100000)   ftxt << "    " << tofRawDatum->GetTOF() << endl;
182       else if (tofRawDatum->GetTOF()>=100000 && tofRawDatum->GetTOF()<1000000) ftxt << "   " << tofRawDatum->GetTOF() << endl;
183       else                                                                     ftxt << "  " << tofRawDatum->GetTOF() << endl;
184       */
185
186       TClonesArray &aDigits = *tofDigits;
187       Int_t last = tofDigits->GetEntriesFast();
188
189       fTOFdigitMap->AddDigit(detectorIndex, last);
190
191       AliDebug(2,Form(" %3i -> %2i %2i %2i %2i %2i   %i  %i\n",
192                       last, detectorIndex[0], detectorIndex[1],
193                       detectorIndex[2], detectorIndex[4], detectorIndex[3],
194                       digit[1], digit[0]));
195
196       Int_t tracknum[3]={-1,-1,-1};
197       new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
198
199     } // while loop
200
201     clonesRawData->Clear();
202
203   } // DDL Loop
204
205   fTree->Fill();
206
207   //ftxt.close();
208
209   delete cableLength;
210
211 }
212
213
214 /* ******************************************************* */
215 void AliEveTOFDigitsInfo::LoadDigits()
216 {
217   //
218   // Load TOF digits
219   //
220
221   TClonesArray *digitsTOF = 0x0;
222   AliTOFdigit *digs;
223
224   fTree->SetBranchAddress("TOF",&digitsTOF);
225   fTree->GetEntry(0);
226
227   Int_t vol[5] = {-1,-1,-1,-1,-1};
228
229   for (Int_t digitNumber=0; digitNumber<digitsTOF->GetEntries(); digitNumber++) {
230
231     if (digitNumber==digitsTOF->GetEntries()-1)
232       AliDebug(2,Form(" Hello  4 -> %3i digit of %i \n", digitNumber+1, digitsTOF->GetEntries()));
233
234     digs = (AliTOFdigit*)digitsTOF->UncheckedAt(digitNumber);
235
236     vol[0] = digs->GetSector(); // Sector Number (0-17)
237     vol[1] = digs->GetPlate();  // Plate Number (0-4)
238     vol[2] = digs->GetStrip();  // Strip Number (0-14/18)
239     vol[3] = digs->GetPadx();   // Pad Number in x direction (0-47)
240     vol[4] = digs->GetPadz();   // Pad Number in z direction (0-1)
241
242     fTOFdigitMap->AddDigit(vol, digitNumber);
243     if (digitNumber==digitsTOF->GetEntries()-1)
244       AliDebug(2,Form(" I am inside LoadDigits %3i \n", digitNumber));
245
246   }
247
248 }
249
250 /* ******************************************************* */
251
252 void AliEveTOFDigitsInfo::GetDigits(Int_t nSector, Int_t nPlate,
253                                     Int_t nStrip, Int_t nPadZ, Int_t nPadX,
254                                     Int_t indexDigit[3])
255 {
256   //
257   // Get TOF digit indices in the TOF volume
258   // (nSector, nPlate,nStrip,nPadZ,nPadX)
259   //
260
261   Int_t vol[5] = {nSector,nPlate,nStrip,nPadX,nPadZ};
262
263   fTOFdigitMap->GetDigitIndex(vol, indexDigit);
264   //for (Int_t ii=1; ii<3; ii++) indexDigit[ii]=-1;
265
266 }
267 /* ******************************************************* */
268
269 TClonesArray* AliEveTOFDigitsInfo::GetDigits(Int_t nSector, Int_t nPlate,
270                                              Int_t nStrip)
271 {
272   //
273   // Get TOF digits in the TOF volume
274   // (nSector, nPlate,nStrip)
275   //
276
277   Int_t newCounter = 0;
278   Int_t nDigitsInVolume[3] = {-1, -1, -1};
279   Int_t dummy[3] = {-1, -1, -1};
280   Int_t informations[4] = {-1, -1, -1, -1};
281
282   TClonesArray* digitsTOFnew = new TClonesArray("AliTOFdigit",  300);
283   TClonesArray &ldigits = *digitsTOFnew;
284
285   AliTOFdigit *digs;
286
287   TClonesArray *digitsTOF = 0x0;
288   fTree->SetBranchAddress("TOF",&digitsTOF);
289   fTree->GetEntry(0);
290
291   Int_t vol[5] = {nSector,nPlate,nStrip,-1,-1};
292
293   for(Int_t iPadZ=0; iPadZ<fGeom->NpadZ(); iPadZ++){
294     vol[4] = iPadZ;
295     for(Int_t iPadX=0; iPadX<fGeom->NpadX(); iPadX++) {
296       vol[3] = iPadX;
297
298       fTOFdigitMap->GetDigitIndex(vol, nDigitsInVolume);
299
300       for (Int_t ii=0; ii<3; ii++) {
301         //if (ii!=0) continue;
302         if (nDigitsInVolume[ii]>=0 ) {
303           AliDebug(2,Form("  nDigitsInVolume[%2i]  = %3i\n ", ii, nDigitsInVolume[ii]));
304           digs = (AliTOFdigit*)digitsTOF->UncheckedAt(nDigitsInVolume[ii]);
305           informations[0] = digs->GetTdc();
306           informations[1] = digs->GetAdc();
307           informations[2] = digs->GetToT();
308           informations[3] = digs->GetTdcND();
309           for(Int_t kk=0; kk<3; kk++) dummy[kk] = digs->GetTrack(kk);
310           new (ldigits[newCounter++]) AliTOFdigit(dummy, vol, informations);
311         }
312
313       }
314
315       for (Int_t ii=0; ii<4; ii++) informations[ii]=-1;
316       for (Int_t ii=0; ii<3; ii++) dummy[ii]=-1;
317       for (Int_t ii=0; ii<3; ii++) nDigitsInVolume[ii]=-1;
318
319     }
320   }
321
322   if (digitsTOFnew)
323     AliDebug(2, Form("Sector %2i   Plate %1i  Strip %2i  -> number of digits %3i \n",
324                      nSector, nPlate, nStrip, digitsTOFnew->GetEntries()));
325
326   return digitsTOFnew;
327
328 }
329 /* ******************************************************* */
330
331 TClonesArray* AliEveTOFDigitsInfo::GetDigits(Int_t nSector)
332 {
333   //
334   // Get TOF digits in the TOF SM nSector
335   //
336
337   const Int_t kND = AliTOFDigitMap::kMaxDigitsPerPad;
338
339   Int_t newCounter = 0;
340   Int_t nDigitsInVolume[kND];
341   Int_t dummy[3];
342   Int_t informations[4];
343
344   Int_t nStrips=19;
345
346   TClonesArray* digitsTOFnew = new TClonesArray("AliTOFdigit",  300);
347   TClonesArray &ldigits = *digitsTOFnew;
348
349   AliTOFdigit *digs;
350
351   TClonesArray *digitsTOF = 0x0;
352   fTree->SetBranchAddress("TOF",&digitsTOF);
353   fTree->GetEntry(0);
354
355   //Int_t nSector = 1;
356   Int_t vol[5] = {nSector,-1,-1,-1,-1};
357  
358   for(Int_t iPlate=0; iPlate<fGeom->NPlates(); iPlate++){
359     vol[1] = iPlate;
360     if(iPlate==2) nStrips=15;
361     else nStrips=19;
362
363     for(Int_t iStrip=0; iStrip<nStrips; iStrip++){
364       vol[2] = iStrip;
365
366       for(Int_t iPadZ=0; iPadZ<fGeom->NpadZ(); iPadZ++){
367         vol[4] = iPadZ;
368
369         for(Int_t iPadX=0; iPadX<fGeom->NpadX(); iPadX++) {
370
371           for (Int_t ii=0; ii<4; ii++) informations[ii]=-1;
372           for (Int_t ii=0; ii<3; ii++) dummy[ii]=-1;
373           for (Int_t ii=0; ii<kND; ii++) nDigitsInVolume[ii]=-1;
374
375           vol[3] = iPadX;
376
377           fTOFdigitMap->GetDigitIndex(vol, nDigitsInVolume);
378
379           for (Int_t ii=0; ii<kND; ii++) {
380             //if (ii!=0) continue;
381             if (nDigitsInVolume[ii]>=0 ) {
382
383               digs = (AliTOFdigit*)digitsTOF->UncheckedAt(nDigitsInVolume[ii]);
384               informations[0] = digs->GetTdc();
385               informations[1] = digs->GetAdc();
386               informations[2] = digs->GetToT();
387               informations[3] = digs->GetTdcND();
388               for(Int_t kk=0; kk<3; kk++) dummy[kk] = digs->GetTrack(kk);
389               new (ldigits[newCounter++]) AliTOFdigit(dummy, vol, informations);
390
391               AliDebug(2,Form(" %2i -> %2i %2i %2i %2i %2i %7i %7i\n",
392                               nDigitsInVolume[ii],
393                               vol[0], vol[1], vol[2], vol[4], vol[3],
394                               informations[1], informations[0]));
395
396             }
397
398           }
399
400         }
401       }
402     }
403   }
404
405   if (digitsTOFnew)
406     AliDebug(2,Form("Sector %2i  -> number of digits %3i \n",
407                     nSector, digitsTOFnew->GetEntries()));
408
409   return digitsTOFnew;
410
411 }
412 /* ******************************************************* */
413
414 Int_t AliEveTOFDigitsInfo::GetTOFInfos() const
415 {
416   //
417   // Return number of TOF digits
418   //
419
420   return fTOFdigitMap->GetFilledCellNumber();
421
422 }
423
424 /* ******************************************************* */
425 Int_t AliEveTOFDigitsInfo::IsStripFilled(Int_t iSector, Int_t iPlate, Int_t iStrip)
426 {
427   //
428   // Return number of TOF digits
429   // in volume (iSector,iPlate,iStrip)
430   //
431
432   Int_t vol[5] = {iSector, iPlate, iStrip, -1, -1};
433
434   Int_t index = 0;
435
436   for (Int_t iPadZ=0; iPadZ<fGeom->NpadZ(); iPadZ++) 
437     for (Int_t iPadX=0; iPadX<fGeom->NpadX(); iPadX++) 
438       {
439         vol[3] = iPadX;
440         vol[4] = iPadZ;
441         if (fTOFdigitMap->GetDigitIndex(vol,0)>=0) index++;
442       }
443
444   return index;
445
446 }
447
448 /* ******************************************************* */
449 /*
450 void AliEveTOFDigitsInfo::GetDigits()
451 {
452
453   for (Int_t iSector=0; iSector<fGeom->NSectors(); iSector++) {
454
455     fNewTree = new TTree();
456
457
458
459
460   }
461
462 }
463 */