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