]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFDigitMap.cxx
TrainSetup version of official QA train
[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     delete [] fDigitMap;
112   }
113
114
115 }
116
117 ////////////////////////////////////////////////////////////////////////
118 void AliTOFDigitMap::Clear(const Option_t*)
119 {
120   //
121   // Clear digitmap
122   //
123
124   for(Int_t ii=0; ii<fMaxIndex; ii++) {
125     for (Int_t jj=0; jj<kMaxDigitsPerPad; jj++) {
126       fDigitMap[ii][jj] = 0;
127     }
128   }
129  
130 }
131
132 ////////////////////////////////////////////////////////////////////////
133 Int_t AliTOFDigitMap::CheckedIndex(Int_t * const vol) const
134 {
135   //
136   // Return checked index for vol
137   //
138
139   Int_t index =
140     vol[0]*fNplate*fNstrip*fNpx*fNpz+             // sector
141     vol[1]*fNstrip*fNpx*fNpz+                     // plate
142     vol[2]*fNpx*fNpz+                             // strip
143     vol[3]*fNpz+                                  // padx
144     vol[4];                                       // padz
145
146     if (index >= fMaxIndex || index < 0) {
147       AliError("CheckedIndex - input outside bounds");
148       return -1;
149     } else {
150       return index;
151     }
152 }
153
154 ////////////////////////////////////////////////////////////////////////
155 void AliTOFDigitMap::AddDigit(Int_t *vol, Int_t idigit)
156 {
157   //
158   // Assign digit to pad vol
159   //
160   // 0 means empty pad, we need to shift indeces by 1
161
162   if (fDigitMap[CheckedIndex(vol)][kMaxDigitsPerPad-1]!=0) {
163     AliDebug(1,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]));
164     AliDebug(1,Form("Then, the digit number %i will be not inserted in the digit map, i.e. it will be lost.", idigit));
165     AliDebug(1,Form("Please, check the possibility to increase the digit map size (succently set to %i)", kMaxDigitsPerPad));
166     return;
167   }
168
169   for (Int_t slot=0; slot<kMaxDigitsPerPad; slot++) {
170
171     if (fDigitMap[CheckedIndex(vol)][slot]==0) {
172       fDigitMap[CheckedIndex(vol)][slot]=idigit+1;
173       break;
174     }
175     //else continue;
176
177   }
178
179 }
180
181 ////////////////////////////////////////////////////////////////////////
182 void AliTOFDigitMap::GetDigitIndex(Int_t *vol, Int_t *digitLabels) const
183 {
184   //
185   // Get all contents (digitLabels) of pad volume (vol)
186   //
187
188   // 0 means empty pad, we need to shift indeces by 1
189
190   Int_t dummy;
191     for (Int_t j=0; j<kMaxDigitsPerPad; j++) {
192       dummy = GetDigitIndex(vol,j);
193       if (dummy>=0) digitLabels[j] = dummy;
194       else break;
195     }
196 }
197
198 ////////////////////////////////////////////////////////////////////////
199 Int_t AliTOFDigitMap::GetDigitIndex(Int_t *vol, Int_t label) const
200 {
201   //
202   // Get one of the contents (label) of pad volume (vol)
203   //
204
205   // 0 means empty pad, we need to shift indeces by 1
206
207   if (!(label<kMaxDigitsPerPad)) {
208     AliWarning(Form("label (=%i) >= kMaxDigitsPerPad (=%i)", label, kMaxDigitsPerPad));
209     return -1;
210   }
211
212   Int_t ci = CheckedIndex(vol);
213   if (ci==-1) return -1;
214   
215   Int_t dummy = fDigitMap[ci][label];
216   
217   if (dummy>0) return dummy-1;
218   else return -1;
219
220 }
221
222 ////////////////////////////////////////////////////////////////////////
223 FlagType AliTOFDigitMap::TestDigit(Int_t *vol) const
224 {
225 //
226 // Check if hit cell is empty, used or unused
227 //
228   Int_t inf=fDigitMap[CheckedIndex(vol)][0]; // to be modified
229     if (inf > 0) {
230         return kUsed;
231     } else if (inf == 0) {
232         return kEmpty;
233     } else {
234         return kUnused;
235     }
236 }
237
238 ////////////////////////////////////////////////////////////////////////
239 Int_t AliTOFDigitMap::GetFilledCellNumber() const
240 {
241   //
242   // Returns the number of filled cells of the TOF digit map
243   //
244
245   Int_t counter = 0;
246
247   for (Int_t index = 0; index < fMaxIndex; ++index)
248   {
249     for (Int_t label = 0; label < kMaxDigitsPerPad; ++label)
250     {
251       if (fDigitMap[index][label] > 0)
252       {
253         ++counter;
254         break;
255       }
256     }
257   }
258
259   return counter;
260 }
261
262 ////////////////////////////////////////////////////////////////////////
263 Bool_t AliTOFDigitMap::StripDigitCheck(Int_t iSector, Int_t iPlate, Int_t iStrip) const
264 {
265   //
266   // Returns:
267   //           kFALSE if the strip doesn't contain digits
268   //           kTRUE  if the strip contains at least one digit
269   //
270
271   Int_t volume[5] = {iSector, iPlate, iStrip, -1, -1};
272   Bool_t counter = kFALSE;
273
274   for (Int_t iPadX=0; iPadX<fNpx; iPadX++)
275     for (Int_t iPadZ=0; iPadZ<fNpz; iPadZ++)
276       {
277         volume[3] = iPadX;
278         volume[4] = iPadZ;
279         for (Int_t label=0; label<kMaxDigitsPerPad; label++) {
280           if (GetDigitIndex(volume, label)>=0) {
281             counter = kTRUE;
282             break;
283           }
284         }
285       }
286
287   return counter;
288
289 }
290
291 ////////////////////////////////////////////////////////////////////////
292 Int_t AliTOFDigitMap::DigitInStrip(Int_t iSector, Int_t iPlate, Int_t iStrip) const
293 {
294   //
295   // Returns number of digits in the strip iStrip,
296   //         in the plate iPlate of the sector iSector
297   //
298
299   Int_t volume[5] = {iSector, iPlate, iStrip, -1, -1};
300   Int_t counter = 0;
301
302   for (Int_t iPadX=0; iPadX<fNpx; iPadX++)
303     for (Int_t iPadZ=0; iPadZ<fNpz; iPadZ++)
304       for (Int_t label=0; label<kMaxDigitsPerPad; label++) {
305         volume[3] = iPadX;
306         volume[4] = iPadZ;
307         if (GetDigitIndex(volume, label)>=0)
308           counter++;
309       }
310
311   return counter;
312
313 }
314
315 ////////////////////////////////////////////////////////////////////////
316 Int_t AliTOFDigitMap::FilledCellsInStrip(Int_t iSector, Int_t iPlate, Int_t iStrip) const
317 {
318   //
319   // Returns number of digits in the strip iStrip,
320   //         in the plate iPlate of the sector iSector
321   //
322
323   Int_t volume[5] = {iSector, iPlate, iStrip, -1, -1};
324   Int_t counter = 0;
325
326   for (Int_t iPadX=0; iPadX<fNpx; iPadX++)
327     for (Int_t iPadZ=0; iPadZ<fNpz; iPadZ++) {
328       volume[3] = iPadX;
329       volume[4] = iPadZ;
330       if (GetDigitIndex(volume, 0)>=0)
331         counter++;
332     }
333
334   return counter;
335
336 }
337
338 ////////////////////////////////////////////////////////////////////////
339 void AliTOFDigitMap::ResetDigitNumber(Int_t *vol, Int_t dig)
340 {
341   //
342   // Reset digit into pad vol
343   //
344
345   for (Int_t slot=0; slot<kMaxDigitsPerPad; slot++) {
346     if (fDigitMap[CheckedIndex(vol)][slot]-1==dig) {
347       fDigitMap[CheckedIndex(vol)][slot] = 0;
348     }
349   }
350
351 }
352
353 ////////////////////////////////////////////////////////////////////////
354 void AliTOFDigitMap::ResetDigit(Int_t *vol, Int_t dig)
355 {
356   //
357   // Reset digit into pad vol
358   //
359   // 0 means empty pad, we need to shift indeces by 1
360
361   fDigitMap[CheckedIndex(vol)][dig] = 0;
362
363 }
364
365 ////////////////////////////////////////////////////////////////////////
366 void AliTOFDigitMap::ResetDigit(Int_t *vol)
367 {
368   //
369   // Reset digit into pad vol
370   //
371   // 0 means empty pad, we need to shift indices by 1
372
373   for (Int_t slot=0; slot<kMaxDigitsPerPad; slot++)
374     fDigitMap[CheckedIndex(vol)][slot] = 0;
375
376 }
377
378 ////////////////////////////////////////////////////////////////////////
379 Int_t AliTOFDigitMap::GetNumberOfDigits(Int_t *vol)
380 {
381   //
382   // Returns the number of digit
383   //   into pad volume vol
384   //
385   // 0 means empty pad
386   //
387
388   Int_t counter = 0;
389
390   for (Int_t slot=0; slot<kMaxDigitsPerPad; slot++)
391     if (GetDigitIndex(vol, slot)>=0) counter++;
392
393   return counter;
394
395 }