Updates to handle functionalities in TOF online/offline calibration according to...
[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$
18*/
bf6bf84c 19
20////////////////////////////////////////////////////////////////////////
21//
22// AliTOFDigitMap class
23//
d0eb8f39 24// digitmap enables fast check if the pad was already digit.
25
26// The index of a AliTOFdigit is saved in the each digitmap "cell"
27// (there is an offset +1, because the index can be zero and zero
28// means empty cell).
bf6bf84c 29// In TOF, number of strips varies according plate type, the highest
d0eb8f39 30// number is in plate C. For all plates is used this number, so the
31// size of the digitmap is a little bit greater than necessary, but it
32// simplifies the access algorithm.
bf6bf84c 33//
34//
35// Author: F. Pierella based on AliTOFHitMap
36//
d0eb8f39 37// Modified by A. De Caro
38//
39///////////////////////////////////////////////////////////////////////
bf6bf84c 40
d0eb8f39 41#include "AliLog.h"
bf6bf84c 42
43#include "AliTOFDigitMap.h"
0f4a7374 44#include "AliTOFGeometry.h"
bf6bf84c 45
bf6bf84c 46ClassImp(AliTOFDigitMap)
47
655e379f 48AliTOFDigitMap::AliTOFDigitMap():
49 fNSector(-1),
50 fNplate(-1),
51 fNstrip(-1),
52 fNpx(-1),
53 fNpz(-1),
54 fMaxIndex(-1),
55 fDigitMap(0x0),
56 fTOFGeometry(new AliTOFGeometry())
bf6bf84c 57{
58//
59// Default ctor
60//
d3c7bfac 61
0f4a7374 62 fNSector = AliTOFGeometry::NSectors();
63 fNplate = AliTOFGeometry::NPlates();
d0eb8f39 64 fNstrip = fTOFGeometry->NStripC();//fTOFGeometry->NMaxNstrip();
0f4a7374 65 fNpx = AliTOFGeometry::NpadX();
66 fNpz = AliTOFGeometry::NpadZ();
a06668b9 67 fMaxIndex=fNSector*fNplate*fNstrip*fNpx*fNpz;
d0eb8f39 68
69 fDigitMap = new Int_t*[fMaxIndex];
70 for (Int_t i=0; i<fMaxIndex; i++) fDigitMap[i] = new Int_t[kMaxDigitsPerPad];
bf6bf84c 71 Clear();
72}
73
74////////////////////////////////////////////////////////////////////////
655e379f 75AliTOFDigitMap::AliTOFDigitMap(const AliTOFDigitMap & /*digitMap*/):
76 TObject(),
77 fNSector(-1),
78 fNplate(-1),
79 fNstrip(-1),
80 fNpx(-1),
81 fNpz(-1),
82 fMaxIndex(-1),
83 fDigitMap(0x0),
84 fTOFGeometry(new AliTOFGeometry())
bf6bf84c 85{
86//
87// Dummy copy constructor
88//
d3c7bfac 89 ;
90
bf6bf84c 91}
92
93
94////////////////////////////////////////////////////////////////////////
95AliTOFDigitMap::~AliTOFDigitMap()
96{
97//
98// Destructor
99//
d0eb8f39 100 if (fDigitMap) {
101 for (Int_t i=0; i<fMaxIndex; i++) delete[] fDigitMap[i];
102 }
d3c7bfac 103
afd804a3 104 fTOFGeometry = 0;
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}