Modifications to access and use OCDB information during tracking (A. Dainese, D....
[u/mrichter/AliRoot.git] / TOF / AliTOFDigitMap.cxx
CommitLineData
bf6bf84c 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
15ec34b9 16/*
17$Log$
10056aa6 18Revision 1.12 2007/02/20 15:57:00 decaro
19Raw data update: to read the TOF raw data defined in UNPACKED mode
20
15ec34b9 21*/
bf6bf84c 22
23////////////////////////////////////////////////////////////////////////
24//
25// AliTOFDigitMap class
26//
d0eb8f39 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).
bf6bf84c 32// In TOF, number of strips varies according plate type, the highest
d0eb8f39 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.
bf6bf84c 36//
37//
38// Author: F. Pierella based on AliTOFHitMap
39//
d0eb8f39 40// Modified by A. De Caro
41//
42///////////////////////////////////////////////////////////////////////
bf6bf84c 43
d0eb8f39 44#include "AliLog.h"
bf6bf84c 45
46#include "AliTOFDigitMap.h"
0f4a7374 47#include "AliTOFGeometry.h"
bf6bf84c 48
bf6bf84c 49ClassImp(AliTOFDigitMap)
50
655e379f 51AliTOFDigitMap::AliTOFDigitMap():
52 fNSector(-1),
53 fNplate(-1),
54 fNstrip(-1),
55 fNpx(-1),
56 fNpz(-1),
57 fMaxIndex(-1),
10056aa6 58 fDigitMap(0x0)
bf6bf84c 59{
60//
61// Default ctor
62//
d3c7bfac 63
0f4a7374 64 fNSector = AliTOFGeometry::NSectors();
65 fNplate = AliTOFGeometry::NPlates();
10056aa6 66 fNstrip = AliTOFGeometry::NStripC();
0f4a7374 67 fNpx = AliTOFGeometry::NpadX();
68 fNpz = AliTOFGeometry::NpadZ();
a06668b9 69 fMaxIndex=fNSector*fNplate*fNstrip*fNpx*fNpz;
d0eb8f39 70
71 fDigitMap = new Int_t*[fMaxIndex];
72 for (Int_t i=0; i<fMaxIndex; i++) fDigitMap[i] = new Int_t[kMaxDigitsPerPad];
bf6bf84c 73 Clear();
74}
75
76////////////////////////////////////////////////////////////////////////
655e379f 77AliTOFDigitMap::AliTOFDigitMap(const AliTOFDigitMap & /*digitMap*/):
78 TObject(),
79 fNSector(-1),
80 fNplate(-1),
81 fNstrip(-1),
82 fNpx(-1),
83 fNpz(-1),
84 fMaxIndex(-1),
10056aa6 85 fDigitMap(0x0)
bf6bf84c 86{
87//
88// Dummy copy constructor
89//
d3c7bfac 90 ;
91
bf6bf84c 92}
93
94
95////////////////////////////////////////////////////////////////////////
96AliTOFDigitMap::~AliTOFDigitMap()
97{
98//
99// Destructor
100//
d0eb8f39 101 if (fDigitMap) {
102 for (Int_t i=0; i<fMaxIndex; i++) delete[] fDigitMap[i];
103 }
d3c7bfac 104
d3c7bfac 105
bf6bf84c 106}
107
108////////////////////////////////////////////////////////////////////////
d0eb8f39 109void AliTOFDigitMap::Clear(const Option_t*)
bf6bf84c 110{
d0eb8f39 111 //
112 // Clear digitmap
113 //
114
115 for(Int_t ii=0; ii<fMaxIndex; ii++) {
116 for (Int_t jj=0; jj<kMaxDigitsPerPad; jj++) {
117 fDigitMap[ii][jj] = 0;
118 }
119 }
120
bf6bf84c 121}
122
123////////////////////////////////////////////////////////////////////////
124Int_t AliTOFDigitMap::CheckedIndex(Int_t *vol) const
125{
d0eb8f39 126 //
127 // Return checked index for vol
128 //
129
130 Int_t index =
d3c7bfac 131 vol[0]*fNplate*fNstrip*fNpx*fNpz+ // sector
132 vol[1]*fNstrip*fNpx*fNpz+ // plate
133 vol[2]*fNpx*fNpz+ // strip
134 vol[3]*fNpz+ // padx
135 vol[4]; // padz
bf6bf84c 136
d0eb8f39 137 if (index >= fMaxIndex || index < 0) {
138 AliError("CheckedIndex - input outside bounds");
139 return -1;
bf6bf84c 140 } else {
d0eb8f39 141 return index;
bf6bf84c 142 }
143}
144
145////////////////////////////////////////////////////////////////////////
d0eb8f39 146void AliTOFDigitMap::AddDigit(Int_t *vol, Int_t idigit)
bf6bf84c 147{
d0eb8f39 148 //
149 // Assign digit to pad vol
150 //
151 // 0 means empty pad, we need to shift indeces by 1
bf6bf84c 152
d0eb8f39 153 for (Int_t slot=0; slot<kMaxDigitsPerPad; slot++) {
bf6bf84c 154
d0eb8f39 155 if (fDigitMap[CheckedIndex(vol)][slot]==0) {
156 fDigitMap[CheckedIndex(vol)][slot]=idigit+1;
157 break;
158 }
159 //else continue;
bf6bf84c 160
d0eb8f39 161 }
bf6bf84c 162}
163
164////////////////////////////////////////////////////////////////////////
d0eb8f39 165void AliTOFDigitMap::GetDigitIndex(Int_t *vol, Int_t *digitLabels) const
bf6bf84c 166{
d0eb8f39 167 //
168 // Get all contents (digitLabels) of pad volume (vol)
169 //
170
171 // 0 means empty pad, we need to shift indeces by 1
bf6bf84c 172
d0eb8f39 173 Int_t dummy;
174 for (Int_t j=0; j<kMaxDigitsPerPad; j++) {
175 dummy = GetDigitIndex(vol,j);
176 if (dummy>=0) digitLabels[j] = dummy;
177 else break;
178 }
bf6bf84c 179}
180
181////////////////////////////////////////////////////////////////////////
d0eb8f39 182Int_t AliTOFDigitMap::GetDigitIndex(Int_t *vol, Int_t label) const
bf6bf84c 183{
d0eb8f39 184 //
185 // Get one of the contents (label) of pad volume (vol)
186 //
187
188 // 0 means empty pad, we need to shift indeces by 1
189
190 if (!(label<kMaxDigitsPerPad)) {
191 AliWarning(Form("label (=%i) >= kMaxDigitsPerPad (=%i)", label, kMaxDigitsPerPad));
192 return -1;
193 }
194
195 if (CheckedIndex(vol)==-1) return -1;
196
197 Int_t dummy = fDigitMap[CheckedIndex(vol)][label];
198
199 if (dummy>0) return dummy-1;
200 else return -1;
201
bf6bf84c 202}
203
204////////////////////////////////////////////////////////////////////////
d0eb8f39 205FlagType AliTOFDigitMap::TestDigit(Int_t *vol) const
bf6bf84c 206{
207//
208// Check if hit cell is empty, used or unused
209//
d0eb8f39 210 Int_t inf=fDigitMap[CheckedIndex(vol)][0]; // to be modified
0085f44e 211 if (inf > 0) {
bf6bf84c 212 return kUsed;
213 } else if (inf == 0) {
214 return kEmpty;
215 } else {
216 return kUnused;
217 }
218}
219
220////////////////////////////////////////////////////////////////////////
5c016a7b 221AliTOFDigitMap & AliTOFDigitMap::operator = (const AliTOFDigitMap & /*rhs*/)
bf6bf84c 222{
223// Dummy assignment operator
224 return *this;
225}
15ec34b9 226////////////////////////////////////////////////////////////////////////
227Int_t AliTOFDigitMap::GetFilledCellNumber() const
228{
229 //
230 // Returns the number of filled cells of the TOF digit map
231 //
232
233 Int_t volume[5] = {-1, -1, -1, -1, -1};
234 Int_t counter = 0;
235
236 for (Int_t iSector=0; iSector<fNSector; iSector++)
237 for (Int_t iPlate=0; iPlate<fNplate; iPlate++)
238 for (Int_t iStrip=0; iStrip<fNstrip; iStrip++)
239 for (Int_t iPadX=0; iPadX<fNpx; iPadX++)
240 for (Int_t iPadZ=0; iPadZ<fNpz; iPadZ++)
241 {
242
243 volume[0] = iSector;
244 volume[1] = iPlate;
245 volume[2] = iStrip;
246 volume[3] = iPadX;
247 volume[4] = iPadZ;
248
249 //if (CheckedIndex(volume)!=-1) counter++;
250 if (GetDigitIndex(volume, 0)>0) counter++;
251 }
252
253 return counter;
254
255}
dfa56f14 256
257////////////////////////////////////////////////////////////////////////
258void AliTOFDigitMap::ResetDigit(Int_t *vol)
259{
260 //
261 // Reset digit into pad vol
262 //
263 // 0 means empty pad, we need to shift indeces by 1
264
265 for (Int_t slot=0; slot<kMaxDigitsPerPad; slot++)
266 fDigitMap[CheckedIndex(vol)][slot] = 0;
267
268}