]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFDigitMap.cxx
added new TOFFEE file
[u/mrichter/AliRoot.git] / TOF / AliTOFDigitMap.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17 $Log$
18 Revision 1.12  2007/02/20 15:57:00  decaro
19 Raw data update: to read the TOF raw data defined in UNPACKED mode
20
21 */
22
23 ////////////////////////////////////////////////////////////////////////
24 //
25 // AliTOFDigitMap class
26 //
27 // digitmap enables fast check if the pad was already digit.
28
29 // The index of a AliTOFdigit is saved in the each digitmap "cell"
30 // (there is an offset +1, because the index can be zero and zero
31 // means empty cell).
32 // In TOF, number of strips varies according plate type, the highest
33 // number is in plate C. For all plates is used this number, so the
34 // size of the digitmap is a little bit greater than necessary, but it
35 // simplifies the access algorithm.
36 // 
37 //
38 // Author: F. Pierella based on AliTOFHitMap
39 //
40 // Modified by A. De Caro
41 //
42 ///////////////////////////////////////////////////////////////////////
43
44 #include "AliLog.h"
45
46 #include "AliTOFDigitMap.h"
47 #include "AliTOFGeometry.h"
48
49 ClassImp(AliTOFDigitMap)
50
51 AliTOFDigitMap::AliTOFDigitMap():
52   fNSector(AliTOFGeometry::NSectors()),
53   fNplate(AliTOFGeometry::NPlates()),
54   fNstrip(AliTOFGeometry::NStripC()),
55   fNpx(AliTOFGeometry::NpadX()),
56   fNpz(AliTOFGeometry::NpadZ()),
57   fMaxIndex(-1),
58   fDigitMap(0x0)
59 {
60 //
61 // Default ctor
62 //
63
64   fMaxIndex=fNSector*fNplate*fNstrip*fNpx*fNpz;
65   fDigitMap = new Int_t*[fMaxIndex];
66
67   for (Int_t i=0; i<fMaxIndex; i++) fDigitMap[i] = new Int_t[kMaxDigitsPerPad];
68   Clear();
69 }
70
71 ////////////////////////////////////////////////////////////////////////
72 AliTOFDigitMap::AliTOFDigitMap(const AliTOFDigitMap & digitMap):
73   TObject(digitMap),
74   fNSector(digitMap.fNSector),
75   fNplate(digitMap.fNplate),
76   fNstrip(digitMap.fNstrip),
77   fNpx(digitMap.fNpx),
78   fNpz(digitMap.fNpz),
79   fMaxIndex(digitMap.fMaxIndex),
80   fDigitMap(0x0)
81 {
82 //
83 // dummy copy constructor
84 //
85   
86   fMaxIndex=fNSector*fNplate*fNstrip*fNpx*fNpz;
87   fDigitMap = new Int_t*[fMaxIndex];
88
89   for (Int_t i=0; i<fMaxIndex; i++) fDigitMap[i] = new Int_t[kMaxDigitsPerPad];
90 }
91
92 ////////////////////////////////////////////////////////////////////////
93 AliTOFDigitMap &
94 AliTOFDigitMap::operator=(const AliTOFDigitMap & /*digitMap*/)
95 {
96 //
97 // dummy copy const
98 //
99     return *this;
100 }
101
102  
103 ////////////////////////////////////////////////////////////////////////
104 AliTOFDigitMap::~AliTOFDigitMap()
105 {
106 //
107 // Destructor
108 //
109   if (fDigitMap) {
110     for (Int_t i=0; i<fMaxIndex; i++)  delete[] fDigitMap[i];
111   }
112
113
114 }
115
116 ////////////////////////////////////////////////////////////////////////
117 void AliTOFDigitMap::Clear(const Option_t*)
118 {
119   //
120   // Clear digitmap
121   //
122
123   for(Int_t ii=0; ii<fMaxIndex; ii++) {
124     for (Int_t jj=0; jj<kMaxDigitsPerPad; jj++) {
125       fDigitMap[ii][jj] = 0;
126     }
127   }
128  
129 }
130
131 ////////////////////////////////////////////////////////////////////////
132 Int_t AliTOFDigitMap::CheckedIndex(Int_t *vol) const
133 {
134   //
135   // Return checked index for vol
136   //
137
138   Int_t index =
139     vol[0]*fNplate*fNstrip*fNpx*fNpz+             // sector
140     vol[1]*fNstrip*fNpx*fNpz+                     // plate
141     vol[2]*fNpx*fNpz+                             // strip
142     vol[3]*fNpz+                                  // padx
143     vol[4];                                       // padz
144
145     if (index >= fMaxIndex || index < 0) {
146       AliError("CheckedIndex - input outside bounds");
147       return -1;
148     } else {
149       return index;
150     }
151 }
152
153 ////////////////////////////////////////////////////////////////////////
154 void AliTOFDigitMap::AddDigit(Int_t *vol, Int_t idigit)
155 {
156   //
157   // Assign digit to pad vol
158   //
159   // 0 means empty pad, we need to shift indeces by 1
160
161   if (fDigitMap[CheckedIndex(vol)][kMaxDigitsPerPad-1]!=0) {
162     AliWarning(Form("In the volume (Se%i, Pl%i, St%i, PadR%i, Pad%i) there is not more possibility to add other digits.", vol[0], vol[1], vol[2], vol[4], vol[3]));
163     AliWarning(Form("Then, the digit number %i will be not inserted in the digit map, i.e. it will be lost.", idigit));
164     return;
165   }
166
167   for (Int_t slot=0; slot<kMaxDigitsPerPad; slot++) {
168
169     if (fDigitMap[CheckedIndex(vol)][slot]==0) {
170       fDigitMap[CheckedIndex(vol)][slot]=idigit+1;
171       break;
172     }
173     //else continue;
174
175   }
176
177 }
178
179 ////////////////////////////////////////////////////////////////////////
180 void AliTOFDigitMap::GetDigitIndex(Int_t *vol, Int_t *digitLabels) const
181 {
182   //
183   // Get all contents (digitLabels) of pad volume (vol)
184   //
185
186   // 0 means empty pad, we need to shift indeces by 1
187
188   Int_t dummy;
189     for (Int_t j=0; j<kMaxDigitsPerPad; j++) {
190       dummy = GetDigitIndex(vol,j);
191       if (dummy>=0) digitLabels[j] = dummy;
192       else break;
193     }
194 }
195
196 ////////////////////////////////////////////////////////////////////////
197 Int_t AliTOFDigitMap::GetDigitIndex(Int_t *vol, Int_t label) const
198 {
199   //
200   // Get one of the contents (label) of pad volume (vol)
201   //
202
203   // 0 means empty pad, we need to shift indeces by 1
204
205   if (!(label<kMaxDigitsPerPad)) {
206     AliWarning(Form("label (=%i) >= kMaxDigitsPerPad (=%i)", label, kMaxDigitsPerPad));
207     return -1;
208   }
209
210   if (CheckedIndex(vol)==-1) return -1;
211   
212   Int_t dummy = fDigitMap[CheckedIndex(vol)][label];
213   
214   if (dummy>0) return dummy-1;
215   else return -1;
216
217 }
218
219 ////////////////////////////////////////////////////////////////////////
220 FlagType AliTOFDigitMap::TestDigit(Int_t *vol) const
221 {
222 //
223 // Check if hit cell is empty, used or unused
224 //
225   Int_t inf=fDigitMap[CheckedIndex(vol)][0]; // to be modified
226     if (inf > 0) {
227         return kUsed;
228     } else if (inf == 0) {
229         return kEmpty;
230     } else {
231         return kUnused;
232     }
233 }
234
235 ////////////////////////////////////////////////////////////////////////
236 Int_t AliTOFDigitMap::GetFilledCellNumber() const
237 {
238   //
239   // Returns the number of filled cells of the TOF digit map
240   //
241
242   Int_t volume[5] = {-1, -1, -1, -1, -1};
243   Int_t counter = 0;
244
245   Bool_t checkContent = kFALSE;
246
247   for (Int_t iSector=0; iSector<fNSector; iSector++)
248     for (Int_t iPlate=0; iPlate<fNplate; iPlate++)
249       for (Int_t iStrip=0; iStrip<fNstrip; iStrip++)
250         for (Int_t iPadX=0; iPadX<fNpx; iPadX++)
251           for (Int_t iPadZ=0; iPadZ<fNpz; iPadZ++)
252             {
253
254               volume[0] = iSector;
255               volume[1] = iPlate;
256               volume[2] = iStrip;
257               volume[3] = iPadX;
258               volume[4] = iPadZ;
259
260               checkContent = kFALSE;
261               for (Int_t label=0; label<kMaxDigitsPerPad; label++)
262                 checkContent = checkContent || (GetDigitIndex(volume, label)>=0);
263
264               //if (CheckedIndex(volume)!=-1) counter++;
265               if (checkContent) counter++;
266             }
267
268   return counter;
269
270 }
271
272 ////////////////////////////////////////////////////////////////////////
273 Bool_t AliTOFDigitMap::StripDigitCheck(Int_t iSector, Int_t iPlate, Int_t iStrip) const
274 {
275   //
276   // Returns:
277   //           kFALSE if the strip doesn't contain digits
278   //           kTRUE  if the strip contains at least one digit
279   //
280
281   Int_t volume[5] = {iSector, iPlate, iStrip, -1, -1};
282   Bool_t counter = kFALSE;
283
284   for (Int_t iPadX=0; iPadX<fNpx; iPadX++)
285     for (Int_t iPadZ=0; iPadZ<fNpz; iPadZ++)
286       {
287         volume[3] = iPadX;
288         volume[4] = iPadZ;
289         for (Int_t label=0; label<kMaxDigitsPerPad; label++) {
290           if (GetDigitIndex(volume, label)>=0) {
291             counter = kTRUE;
292             break;
293           }
294         }
295       }
296
297   return counter;
298
299 }
300
301 ////////////////////////////////////////////////////////////////////////
302 Int_t AliTOFDigitMap::DigitInStrip(Int_t iSector, Int_t iPlate, Int_t iStrip) const
303 {
304   //
305   // Returns number of digits in the strip iStrip,
306   //         in the plate iPlate of the sector iSector
307   //
308
309   Int_t volume[5] = {iSector, iPlate, iStrip, -1, -1};
310   Int_t counter = 0;
311
312   for (Int_t iPadX=0; iPadX<fNpx; iPadX++)
313     for (Int_t iPadZ=0; iPadZ<fNpz; iPadZ++)
314       for (Int_t label=0; label<kMaxDigitsPerPad; label++) {
315         volume[3] = iPadX;
316         volume[4] = iPadZ;
317         if (GetDigitIndex(volume, label)>=0)
318           counter++;
319       }
320
321   return counter;
322
323 }
324
325 ////////////////////////////////////////////////////////////////////////
326 void AliTOFDigitMap::ResetDigitNumber(Int_t *vol, Int_t dig)
327 {
328   //
329   // Reset digit into pad vol
330   //
331
332   for (Int_t slot=0; slot<kMaxDigitsPerPad; slot++) {
333     if (fDigitMap[CheckedIndex(vol)][slot]-1==dig) {
334       fDigitMap[CheckedIndex(vol)][slot] = 0;
335     }
336   }
337
338 }
339
340 ////////////////////////////////////////////////////////////////////////
341 void AliTOFDigitMap::ResetDigit(Int_t *vol, Int_t dig)
342 {
343   //
344   // Reset digit into pad vol
345   //
346   // 0 means empty pad, we need to shift indeces by 1
347
348   fDigitMap[CheckedIndex(vol)][dig] = 0;
349
350 }
351
352 ////////////////////////////////////////////////////////////////////////
353 void AliTOFDigitMap::ResetDigit(Int_t *vol)
354 {
355   //
356   // Reset digit into pad vol
357   //
358   // 0 means empty pad, we need to shift indices by 1
359
360   for (Int_t slot=0; slot<kMaxDigitsPerPad; slot++)
361     fDigitMap[CheckedIndex(vol)][slot] = 0;
362
363 }
364
365 ////////////////////////////////////////////////////////////////////////
366 Int_t AliTOFDigitMap::GetNumberOfDigits(Int_t *vol)
367 {
368   //
369   // Returns the number of digit
370   //   into pad volume vol
371   //
372   // 0 means empty pad
373   //
374
375   Int_t counter = 0;
376
377   for (Int_t slot=0; slot<kMaxDigitsPerPad; slot++)
378     if (GetDigitIndex(vol, slot)>=0) counter++;
379
380   return counter;
381
382 }