]>
Commit | Line | Data |
---|---|---|
b65e5048 | 1 | /************************************************************************* |
2 | * Copyright(c) 1998-2008, 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 | /* $Id: AliTRDarraySignal.cxx 25392 2008-04-23 19:40:29Z cblume $ */ | |
17 | ||
18 | ///////////////////////////////////////////////////////// | |
19 | // // | |
20 | // Container Class for Signals // | |
21 | // // | |
22 | // Author: // | |
23 | // Hermes Leon Vargas (hleon@ikf.uni-frankfurt.de) // | |
24 | // // | |
25 | ///////////////////////////////////////////////////////// | |
26 | ||
27 | #include "AliTRDarraySignal.h" | |
28 | //#include "AliLog.h" | |
29 | ||
30 | ClassImp(AliTRDarraySignal) | |
31 | ||
32 | //_______________________________________________________________________ | |
33 | AliTRDarraySignal::AliTRDarraySignal() | |
34 | :TObject() | |
35 | ,fNdet(0) | |
36 | ,fNrow(0) | |
37 | ,fNcol(0) | |
38 | ,fNtime(0) | |
39 | ,fNdim(0) | |
40 | ,fSignal(0) | |
41 | { | |
42 | ||
43 | // | |
44 | // AliTRDarraySignal default constructor | |
45 | // | |
46 | ||
47 | } | |
48 | ||
49 | //_______________________________________________________________________ | |
50 | AliTRDarraySignal::AliTRDarraySignal(Int_t nrow, Int_t ncol,Int_t ntime) | |
51 | :TObject() | |
52 | ,fNdet(0) | |
53 | ,fNrow(0) | |
54 | ,fNcol(0) | |
55 | ,fNtime(0) | |
56 | ,fNdim(0) | |
57 | ,fSignal(0) | |
58 | { | |
59 | // | |
60 | // AliTRDarraySignal constructor | |
61 | // | |
62 | ||
63 | Allocate(nrow,ncol,ntime); | |
64 | ||
65 | } | |
66 | ||
67 | //_______________________________________________________________________ | |
68 | AliTRDarraySignal::AliTRDarraySignal(const AliTRDarraySignal &d) | |
69 | :TObject() | |
70 | ,fNdet(d.fNdet) | |
71 | ,fNrow(d.fNrow) | |
72 | ,fNcol(d.fNcol) | |
73 | ,fNtime(d.fNtime) | |
74 | ,fNdim(d.fNdim) | |
75 | ,fSignal(0) | |
76 | { | |
77 | // | |
78 | // AliTRDarraySignal copy constructor | |
79 | // | |
80 | ||
81 | fSignal = new Float_t[fNdim]; | |
82 | for(Int_t i=0; i<fNdim; i++) | |
83 | { | |
84 | fSignal[i]=d.fSignal[i]; | |
85 | } | |
86 | ||
87 | } | |
88 | ||
89 | //_______________________________________________________________________ | |
90 | AliTRDarraySignal::~AliTRDarraySignal() | |
91 | { | |
92 | // | |
93 | // AliTRDarraySignal destructor | |
94 | // | |
95 | ||
96 | if (fSignal) | |
97 | { | |
98 | delete [] fSignal; | |
99 | fSignal=0; | |
100 | } | |
101 | ||
102 | } | |
103 | ||
104 | //_______________________________________________________________________ | |
105 | AliTRDarraySignal &AliTRDarraySignal::operator=(const AliTRDarraySignal &d) | |
106 | { | |
107 | // | |
108 | // Assignment operator | |
109 | // | |
110 | ||
111 | if (this==&d) | |
112 | { | |
113 | return *this; | |
114 | } | |
115 | ||
116 | if (fSignal) | |
117 | { | |
118 | delete [] fSignal; | |
119 | } | |
120 | fNdet=d.fNdet; | |
121 | fNrow=d.fNrow; | |
122 | fNcol=d.fNcol; | |
123 | fNtime=d.fNtime; | |
124 | fNdim=d.fNdim; | |
125 | fSignal = new Float_t[fNdim]; | |
126 | ||
127 | for(Int_t i=0; i<fNdim; i++) | |
128 | { | |
129 | fSignal[i]=d.fSignal[i]; | |
130 | } | |
131 | ||
132 | return *this; | |
133 | ||
134 | } | |
135 | ||
136 | //_______________________________________________________________________ | |
137 | void AliTRDarraySignal::Allocate(Int_t nrow, Int_t ncol, Int_t ntime) | |
138 | { | |
139 | // | |
140 | // Allocates memory for an AliTRDarraySignal object with dimensions | |
141 | // Row*Col*Time | |
142 | // | |
143 | ||
144 | fNrow=nrow; | |
145 | fNcol=ncol; | |
146 | fNtime=ntime; | |
147 | fNdim = nrow*ncol*ntime; | |
148 | if (fSignal) | |
149 | { | |
150 | delete [] fSignal; | |
151 | } | |
152 | fSignal = new Float_t[fNdim]; | |
153 | for(Int_t i=0; i<fNdim; i++) | |
154 | { | |
155 | fSignal[i]=0; | |
156 | } | |
157 | ||
158 | } | |
159 | ||
160 | //_______________________________________________________________________ | |
161 | Int_t AliTRDarraySignal::GetOverThreshold(Float_t threshold) | |
162 | { | |
163 | // | |
164 | // Get the number of entries over the threshold | |
165 | // | |
166 | ||
167 | Int_t counter=0; | |
168 | for(Int_t i=0; i<fNdim; i++) | |
169 | { | |
170 | if(fSignal[i]>threshold) | |
171 | { | |
172 | counter++; | |
173 | } | |
174 | } | |
175 | return counter; | |
176 | ||
177 | } | |
178 | ||
179 | //_______________________________________________________________________ | |
180 | void AliTRDarraySignal::Compress(Float_t minval) | |
181 | { | |
182 | // | |
183 | // Compress the array, setting values equal or | |
184 | // below minval to zero (minval>=0) | |
185 | // | |
186 | ||
187 | Int_t counter=0; | |
188 | Int_t newDim=0; | |
189 | Int_t j; | |
190 | Int_t r=0; | |
191 | Int_t *longArr; | |
192 | longArr = new Int_t[fNdim]; | |
193 | Int_t k=0; | |
194 | ||
195 | //Initialize the array | |
196 | for(Int_t i=0; i<fNdim;i++) | |
197 | { | |
198 | longArr[i]=0; | |
199 | } | |
200 | ||
201 | for(Int_t i=0;i<fNdim; i++) | |
202 | { | |
203 | j=0; | |
204 | if(fSignal[i]<=minval) | |
205 | { | |
206 | for(k=i;k<fNdim;k++) | |
207 | { | |
208 | if(fSignal[k]<=minval) | |
209 | { | |
210 | j=j+1; | |
211 | longArr[r]=j; | |
212 | } | |
213 | else | |
214 | { | |
215 | break; | |
216 | } | |
217 | } | |
218 | r=r+1; | |
219 | } | |
220 | i=i+j; | |
221 | } | |
222 | ||
223 | //Calculate the size of the compressed array | |
224 | for(Int_t i=0; i<fNdim;i++) | |
225 | { | |
226 | if(longArr[i]!=0) | |
227 | { | |
228 | counter=counter+longArr[i]-1; | |
229 | } | |
230 | } | |
231 | newDim=fNdim-counter; //New dimension | |
232 | ||
233 | //Fill the buffer of the compressed array | |
234 | Float_t* buffer; | |
235 | buffer = new Float_t[newDim]; | |
236 | Int_t counterTwo=0; | |
237 | ||
238 | //Write the new array | |
239 | Int_t g=0; | |
240 | for(Int_t i=0; i<newDim; i++) | |
241 | { | |
242 | if(counterTwo<fNdim) | |
243 | { | |
244 | if(fSignal[counterTwo]>minval) | |
245 | { | |
246 | buffer[i]=fSignal[counterTwo]; | |
247 | } | |
248 | if(fSignal[counterTwo]<=minval) | |
249 | { | |
250 | buffer[i]=-(longArr[g]); | |
251 | counterTwo=counterTwo+longArr[g]-1; | |
252 | g++; | |
253 | } | |
254 | counterTwo++; | |
255 | } | |
256 | } | |
257 | ||
258 | //Copy the buffer | |
259 | if(fSignal) | |
260 | { | |
261 | delete [] fSignal; | |
262 | fSignal=0; | |
263 | } | |
264 | fSignal = new Float_t[newDim]; | |
265 | fNdim = newDim; | |
266 | for(Int_t i=0; i<newDim; i++) | |
267 | { | |
268 | fSignal[i] = buffer[i]; | |
269 | } | |
270 | if(buffer) | |
271 | { | |
272 | delete [] buffer; | |
273 | buffer=0; | |
274 | } | |
275 | if(longArr) | |
276 | { | |
277 | delete [] longArr; | |
278 | longArr=0; | |
279 | } | |
280 | ||
281 | } | |
282 | ||
283 | //_______________________________________________________________________ | |
284 | void AliTRDarraySignal::Expand() | |
285 | { | |
286 | // | |
287 | // Expand the array | |
288 | // | |
289 | ||
290 | //Check if the array has not been already expanded | |
291 | Int_t verif=0; | |
292 | for(Int_t i=0; i<fNdim; i++) | |
293 | { | |
294 | if(fSignal[i]<0) | |
295 | { | |
296 | verif++; | |
297 | } | |
298 | } | |
299 | ||
300 | if(verif==0) | |
301 | { | |
302 | return; | |
303 | } | |
304 | ||
305 | Int_t *longArr; | |
306 | longArr = new Int_t[fNdim]; | |
307 | Int_t dimexp=0; | |
308 | for(Int_t i=0; i<fNdim;i++) | |
309 | { | |
310 | longArr[i]=0; | |
311 | } | |
312 | ||
313 | Int_t r2=0; | |
314 | for(Int_t i=0; i<fNdim;i++) | |
315 | { | |
316 | if(fSignal[i]<0) | |
317 | { | |
318 | longArr[r2]=(Int_t)(-fSignal[i]); | |
319 | r2++; | |
320 | } | |
321 | } | |
322 | ||
323 | //Calculate new dimensions | |
324 | for(Int_t i=0; i<fNdim;i++) | |
325 | { | |
326 | if(longArr[i]!=0) | |
327 | { | |
328 | dimexp=dimexp+longArr[i]-1; | |
329 | } | |
330 | } | |
331 | dimexp=dimexp+fNdim; //Dimension of the expanded array | |
332 | ||
333 | //Write in the buffer the new array | |
334 | Float_t* bufferE; | |
335 | bufferE = new Float_t[dimexp]; | |
336 | Int_t contaexp =0; | |
337 | Int_t h=0; | |
338 | for(Int_t i=0; i<dimexp; i++) | |
339 | { | |
340 | if(fSignal[contaexp]>0) | |
341 | { | |
342 | bufferE[i]=fSignal[contaexp]; | |
343 | } | |
344 | if(fSignal[contaexp]<0) | |
345 | { | |
346 | for(Int_t j=0; j<longArr[h];j++) | |
347 | { | |
348 | bufferE[i+j]=0; | |
349 | } | |
350 | i=i+longArr[h]-1; | |
351 | h++; | |
352 | } | |
353 | contaexp++; | |
354 | } | |
355 | ||
356 | //Copy the buffer | |
357 | if(fSignal) | |
358 | { | |
359 | delete [] fSignal; | |
360 | fSignal=0; | |
361 | } | |
362 | ||
363 | fSignal = new Float_t[dimexp]; | |
364 | fNdim = dimexp; | |
365 | for(Int_t i=0; i<dimexp; i++) | |
366 | { | |
367 | fSignal[i] = bufferE[i]; | |
368 | } | |
369 | ||
370 | if(bufferE) delete [] bufferE; | |
371 | if(longArr) delete [] longArr; | |
372 | ||
373 | } |