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 map TOF digit/raw data information
13 // Author: A. De Caro (email: decaro@sa.infn.it)
16 #include <TClonesArray.h>
19 //#include <TEveTreeTools.h>
23 #include <AliRawReader.h>
25 #include <AliTOFCableLengthMap.h>
26 #include <AliTOFdigit.h>
27 #include <AliTOFGeometry.h>
28 #include <AliTOFrawData.h>
29 #include <AliTOFRawStream.h>
30 #include <AliTOFDigitMap.h>
32 #include "AliEveTOFDigitsInfo.h"
34 //_________________________________________________________
36 ClassImp(AliEveTOFDigitsInfo)
38 AliEveTOFDigitsInfo::AliEveTOFDigitsInfo():
43 fGeom (new AliTOFGeometry()),
44 fTOFdigitMap(new AliTOFDigitMap())
46 /* ******************************************************* */
48 AliEveTOFDigitsInfo:: ~AliEveTOFDigitsInfo()
58 /* ******************************************************* */
60 void AliEveTOFDigitsInfo::SetTree(TTree * const tree)
63 // Set fTree global variable
66 static const TEveException kEH("AliEveTOFDigitsInfo::SetTree ");
69 fGeom = new AliTOFGeometry();
78 /* ******************************************************* */
79 void AliEveTOFDigitsInfo::ReadRaw(AliRawReader* rawReader, Bool_t newDecoder)
82 // Read raw-data. AliTOFdigit is used to
83 // store raw-adata for all sub-detectors.
86 AliTOFCableLengthMap *cableLength = new AliTOFCableLengthMap();
89 //Char_t fileName[100];
90 //sprintf(fileName,"TOFrawDataReadingFromEVE%d.txt",nEvent);
92 //ftxt.open(fileName,ios::app);
94 //ftxt << " " << nEvent << endl;
96 //if (nEvent<0) printf("%3i\n", nEvent); // only to use nEvent variable
98 const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
100 TClonesArray *tofDigits = new TClonesArray("AliTOFdigit",10000);
102 fTree->Branch("TOF", &tofDigits, 32000);
105 TClonesArray * clonesRawData = 0x0;
107 Int_t detectorIndex[5];
110 AliTOFRawStream stream(rawReader);
112 for (Int_t indexDDL = 0; indexDDL < kDDL; indexDDL++) {
115 if (!newDecoder) stream.LoadRawData(indexDDL);
116 else stream.LoadRawDataBuffers(indexDDL);
118 clonesRawData = (TClonesArray*)stream.GetRawData();
120 if (clonesRawData->GetEntriesFast()) AliDebug(2, Form(" Number of TOF digits in the sector number %2i: %5i", indexDDL, clonesRawData->GetEntriesFast()));
122 for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
124 AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
126 if (tofRawDatum->GetTOF()==-1) continue;
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();
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();
145 stream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
146 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
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",
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.));
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];
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;
186 TClonesArray &aDigits = *tofDigits;
187 Int_t last = tofDigits->GetEntriesFast();
189 fTOFdigitMap->AddDigit(detectorIndex, last);
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]));
196 Int_t tracknum[3]={-1,-1,-1};
197 new (aDigits[last]) AliTOFdigit(tracknum, detectorIndex, digit);
201 clonesRawData->Clear();
214 /* ******************************************************* */
215 void AliEveTOFDigitsInfo::LoadDigits()
221 TClonesArray *digitsTOF = 0x0;
224 fTree->SetBranchAddress("TOF",&digitsTOF);
227 Int_t vol[5] = {-1,-1,-1,-1,-1};
229 for (Int_t digitNumber=0; digitNumber<digitsTOF->GetEntries(); digitNumber++) {
231 if (digitNumber==digitsTOF->GetEntries()-1)
232 AliDebug(2,Form(" Hello 4 -> %3i digit of %i \n", digitNumber+1, digitsTOF->GetEntries()));
234 digs = (AliTOFdigit*)digitsTOF->UncheckedAt(digitNumber);
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)
242 fTOFdigitMap->AddDigit(vol, digitNumber);
243 if (digitNumber==digitsTOF->GetEntries()-1)
244 AliDebug(2,Form(" I am inside LoadDigits %3i \n", digitNumber));
250 /* ******************************************************* */
252 void AliEveTOFDigitsInfo::GetDigits(Int_t nSector, Int_t nPlate,
253 Int_t nStrip, Int_t nPadZ, Int_t nPadX,
257 // Get TOF digit indices in the TOF volume
258 // (nSector, nPlate,nStrip,nPadZ,nPadX)
261 Int_t vol[5] = {nSector,nPlate,nStrip,nPadX,nPadZ};
263 fTOFdigitMap->GetDigitIndex(vol, indexDigit);
264 //for (Int_t ii=1; ii<3; ii++) indexDigit[ii]=-1;
267 /* ******************************************************* */
269 TClonesArray* AliEveTOFDigitsInfo::GetDigits(Int_t nSector, Int_t nPlate,
273 // Get TOF digits in the TOF volume
274 // (nSector, nPlate,nStrip)
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};
282 TClonesArray* digitsTOFnew = new TClonesArray("AliTOFdigit", 300);
283 TClonesArray &ldigits = *digitsTOFnew;
287 TClonesArray *digitsTOF = 0x0;
288 fTree->SetBranchAddress("TOF",&digitsTOF);
291 Int_t vol[5] = {nSector,nPlate,nStrip,-1,-1};
293 for(Int_t iPadZ=0; iPadZ<fGeom->NpadZ(); iPadZ++){
295 for(Int_t iPadX=0; iPadX<fGeom->NpadX(); iPadX++) {
298 fTOFdigitMap->GetDigitIndex(vol, nDigitsInVolume);
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);
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;
323 AliDebug(2, Form("Sector %2i Plate %1i Strip %2i -> number of digits %3i \n",
324 nSector, nPlate, nStrip, digitsTOFnew->GetEntries()));
329 /* ******************************************************* */
331 TClonesArray* AliEveTOFDigitsInfo::GetDigits(Int_t nSector)
334 // Get TOF digits in the TOF SM nSector
337 const Int_t kND = AliTOFDigitMap::kMaxDigitsPerPad;
339 Int_t newCounter = 0;
340 Int_t nDigitsInVolume[kND];
342 Int_t informations[4];
346 TClonesArray* digitsTOFnew = new TClonesArray("AliTOFdigit", 300);
347 TClonesArray &ldigits = *digitsTOFnew;
351 TClonesArray *digitsTOF = 0x0;
352 fTree->SetBranchAddress("TOF",&digitsTOF);
356 Int_t vol[5] = {nSector,-1,-1,-1,-1};
358 for(Int_t iPlate=0; iPlate<fGeom->NPlates(); iPlate++){
360 if(iPlate==2) nStrips=15;
363 for(Int_t iStrip=0; iStrip<nStrips; iStrip++){
366 for(Int_t iPadZ=0; iPadZ<fGeom->NpadZ(); iPadZ++){
369 for(Int_t iPadX=0; iPadX<fGeom->NpadX(); iPadX++) {
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;
377 fTOFdigitMap->GetDigitIndex(vol, nDigitsInVolume);
379 for (Int_t ii=0; ii<kND; ii++) {
380 //if (ii!=0) continue;
381 if (nDigitsInVolume[ii]>=0 ) {
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);
391 AliDebug(2,Form(" %2i -> %2i %2i %2i %2i %2i %7i %7i\n",
393 vol[0], vol[1], vol[2], vol[4], vol[3],
394 informations[1], informations[0]));
406 AliDebug(2,Form("Sector %2i -> number of digits %3i \n",
407 nSector, digitsTOFnew->GetEntries()));
412 /* ******************************************************* */
414 Int_t AliEveTOFDigitsInfo::GetTOFInfos() const
417 // Return number of TOF digits
420 return fTOFdigitMap->GetFilledCellNumber();
424 /* ******************************************************* */
425 Int_t AliEveTOFDigitsInfo::IsStripFilled(Int_t iSector, Int_t iPlate, Int_t iStrip)
428 // Return number of TOF digits
429 // in volume (iSector,iPlate,iStrip)
432 Int_t vol[5] = {iSector, iPlate, iStrip, -1, -1};
436 for (Int_t iPadZ=0; iPadZ<fGeom->NpadZ(); iPadZ++)
437 for (Int_t iPadX=0; iPadX<fGeom->NpadX(); iPadX++)
441 if (fTOFdigitMap->GetDigitIndex(vol,0)>=0) index++;
448 /* ******************************************************* */
450 void AliEveTOFDigitsInfo::GetDigits()
453 for (Int_t iSector=0; iSector<fGeom->NSectors(); iSector++) {
455 fNewTree = new TTree();