Line data Source code
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 <TArray.h>
28 :
29 : #include "AliTRDarraySignal.h"
30 : #include "AliTRDfeeParam.h"
31 :
32 48 : ClassImp(AliTRDarraySignal)
33 :
34 : Short_t *AliTRDarraySignal::fgLutPadNumbering = 0x0;
35 :
36 : //_______________________________________________________________________
37 : AliTRDarraySignal::AliTRDarraySignal()
38 7208 : :TObject()
39 7208 : ,fNdet(0)
40 7208 : ,fNrow(0)
41 7208 : ,fNcol(0)
42 7208 : ,fNumberOfChannels(0)
43 7208 : ,fNtime(0)
44 7208 : ,fNdim(0)
45 7208 : ,fSignal(0)
46 36040 : {
47 :
48 : //
49 : // AliTRDarraySignal default constructor
50 : //
51 :
52 7208 : CreateLut();
53 :
54 14416 : }
55 :
56 : //_______________________________________________________________________
57 : AliTRDarraySignal::AliTRDarraySignal(Int_t nrow, Int_t ncol,Int_t ntime)
58 0 : :TObject()
59 0 : ,fNdet(0)
60 0 : ,fNrow(0)
61 0 : ,fNcol(0)
62 0 : ,fNumberOfChannels(0)
63 0 : ,fNtime(0)
64 0 : ,fNdim(0)
65 0 : ,fSignal(0)
66 0 : {
67 : //
68 : // AliTRDarraySignal constructor
69 : //
70 :
71 0 : CreateLut();
72 0 : Allocate(nrow,ncol,ntime);
73 :
74 0 : }
75 :
76 : //_______________________________________________________________________
77 : AliTRDarraySignal::AliTRDarraySignal(const AliTRDarraySignal &d)
78 0 : :TObject()
79 0 : ,fNdet(d.fNdet)
80 0 : ,fNrow(d.fNrow)
81 0 : ,fNcol(d.fNcol)
82 0 : ,fNumberOfChannels(d.fNumberOfChannels)
83 0 : ,fNtime(d.fNtime)
84 0 : ,fNdim(d.fNdim)
85 0 : ,fSignal(0)
86 0 : {
87 : //
88 : // AliTRDarraySignal copy constructor
89 : //
90 :
91 0 : fSignal = new Float_t[fNdim];
92 0 : memcpy(fSignal, d.fSignal, fNdim*sizeof(Float_t));
93 :
94 0 : }
95 :
96 : //_______________________________________________________________________
97 : AliTRDarraySignal::~AliTRDarraySignal()
98 43248 : {
99 : //
100 : // AliTRDarraySignal destructor
101 : //
102 :
103 7960 : delete [] fSignal;
104 7208 : fSignal=0;
105 :
106 21624 : }
107 :
108 : //_______________________________________________________________________
109 : AliTRDarraySignal &AliTRDarraySignal::operator=(const AliTRDarraySignal &d)
110 : {
111 : //
112 : // Assignment operator
113 : //
114 :
115 0 : if (this==&d)
116 : {
117 0 : return *this;
118 : }
119 :
120 0 : if (fSignal)
121 : {
122 0 : delete [] fSignal;
123 : }
124 0 : fNdet=d.fNdet;
125 0 : fNrow=d.fNrow;
126 0 : fNcol=d.fNcol;
127 0 : fNumberOfChannels = d.fNumberOfChannels;
128 0 : fNtime=d.fNtime;
129 0 : fNdim=d.fNdim;
130 0 : fSignal = new Float_t[fNdim];
131 0 : memcpy(fSignal,d.fSignal, fNdim*sizeof(Float_t));
132 :
133 0 : return *this;
134 :
135 0 : }
136 :
137 : //_______________________________________________________________________
138 : void AliTRDarraySignal::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
139 : {
140 : //
141 : // Allocates memory for an AliTRDarraySignal object with dimensions
142 : // Row*NumberOfNecessaryMCMs*ADCchannelsInMCM*Time
143 : // To be consistent with AliTRDarrayADC
144 : //
145 :
146 752 : fNrow=nrow;
147 376 : fNcol=ncol;
148 376 : fNtime=ntime;
149 376 : Int_t adcchannelspermcm = AliTRDfeeParam::GetNadcMcm();
150 376 : Int_t padspermcm = AliTRDfeeParam::GetNcolMcm();
151 376 : Int_t numberofmcms = fNcol/padspermcm;
152 376 : fNumberOfChannels = numberofmcms*adcchannelspermcm;
153 376 : fNdim = nrow*fNumberOfChannels*ntime;
154 376 : if (fSignal)
155 : {
156 0 : delete [] fSignal;
157 : }
158 376 : fSignal = new Float_t[fNdim];
159 376 : memset(fSignal,0,sizeof(Float_t)*fNdim);
160 :
161 376 : }
162 :
163 : //_______________________________________________________________________
164 : Int_t AliTRDarraySignal::GetOverThreshold(Float_t threshold) const
165 : {
166 : //
167 : // Get the number of entries over the threshold
168 : //
169 :
170 : Int_t counter=0;
171 0 : for(Int_t i=0; i<fNdim; i++)
172 : {
173 0 : if(fSignal[i]>threshold)
174 : {
175 0 : counter++;
176 0 : }
177 : }
178 0 : return counter;
179 :
180 : }
181 :
182 : //_______________________________________________________________________
183 : void AliTRDarraySignal::Compress(Float_t minval)
184 : {
185 : //
186 : // Compress the array, setting values equal or
187 : // below minval to zero (minval>=0)
188 : //
189 :
190 : Int_t counter=0;
191 : Int_t newDim=0;
192 : Int_t j;
193 : Int_t r=0;
194 : Int_t k=0;
195 :
196 376 : Int_t *longArr = new Int_t[fNdim];
197 :
198 188 : if(longArr)
199 : {
200 :
201 : //Initialize the array
202 188 : memset(longArr,0,sizeof(Int_t)*fNdim);
203 :
204 121222 : for(Int_t i=0;i<fNdim; i++)
205 : {
206 : j=0;
207 60423 : if(fSignal[i]<=minval)
208 : {
209 23470500 : for(k=i;k<fNdim;k++)
210 : {
211 11735062 : if(fSignal[k]<=minval)
212 : {
213 11733365 : j=j+1;
214 11733365 : longArr[r]=j;
215 : }
216 : else
217 : {
218 : break;
219 : }
220 : }
221 1885 : r=r+1;
222 1885 : }
223 60423 : i=i+j;
224 : }
225 :
226 : //Calculate the size of the compressed array
227 23587576 : for(Int_t i=0; i<fNdim;i++)
228 : {
229 11793600 : if(longArr[i]!=0)
230 : {
231 1885 : counter=counter+longArr[i]-1;
232 1885 : }
233 : }
234 188 : newDim=fNdim-counter; //New dimension
235 :
236 : //Fill the buffer of the compressed array
237 188 : Float_t* buffer = new Float_t[newDim];
238 : Int_t counterTwo=0;
239 :
240 188 : if(buffer)
241 : {
242 :
243 : //Write the new array
244 : Int_t g=0;
245 124616 : for(Int_t i=0; i<newDim; i++)
246 : {
247 62120 : if(counterTwo<fNdim)
248 : {
249 62120 : if(fSignal[counterTwo]>minval)
250 : {
251 60235 : buffer[i]=fSignal[counterTwo];
252 60235 : }
253 62120 : if(fSignal[counterTwo]<=minval)
254 : {
255 1885 : buffer[i]=-(longArr[g]);
256 1885 : counterTwo=counterTwo+longArr[g]-1;
257 1885 : g++;
258 1885 : }
259 62120 : counterTwo++;
260 62120 : }
261 : }
262 :
263 : //Copy the buffer
264 188 : if(fSignal)
265 : {
266 376 : delete [] fSignal;
267 188 : fSignal=0;
268 188 : }
269 188 : fSignal = new Float_t[newDim];
270 188 : fNdim = newDim;
271 124616 : for(Int_t i=0; i<newDim; i++)
272 : {
273 62120 : fSignal[i] = buffer[i];
274 : }
275 :
276 376 : delete [] buffer;
277 : buffer=0;
278 :
279 188 : }
280 :
281 376 : delete [] longArr;
282 : longArr=0;
283 :
284 188 : }
285 :
286 188 : }
287 :
288 : //_______________________________________________________________________
289 : void AliTRDarraySignal::Expand()
290 : {
291 : //
292 : // Expand the array
293 : //
294 :
295 752 : if(fSignal)
296 : {
297 :
298 : //Check if the array has not been already expanded
299 : Int_t verif=0;
300 249232 : for(Int_t i=0; i<fNdim; i++)
301 : {
302 124240 : if(fSignal[i]<0)
303 : {
304 3770 : verif++;
305 3770 : }
306 : }
307 :
308 376 : if(verif==0)
309 : {
310 0 : return;
311 : }
312 :
313 : Int_t dimexp=0;
314 376 : Int_t *longArr = new Int_t[fNdim];
315 :
316 376 : if(longArr)
317 : {
318 :
319 376 : memset(longArr,0,sizeof(Int_t)*fNdim);
320 :
321 : Int_t r2=0;
322 249232 : for(Int_t i=0; i<fNdim;i++)
323 : {
324 124240 : if(fSignal[i]<0)
325 : {
326 3770 : longArr[r2]=(Int_t)(-fSignal[i]);
327 3770 : r2++;
328 3770 : }
329 : }
330 :
331 : //Calculate new dimensions
332 249232 : for(Int_t i=0; i<fNdim;i++)
333 : {
334 124240 : if(longArr[i]!=0)
335 : {
336 3770 : dimexp=dimexp+longArr[i]-1;
337 3770 : }
338 : }
339 376 : dimexp=dimexp+fNdim; //Dimension of the expanded array
340 :
341 : //Write in the buffer the new array
342 : Int_t contaexp =0;
343 : Int_t h=0;
344 376 : Float_t* bufferE = new Float_t[dimexp];
345 :
346 376 : if(bufferE)
347 : {
348 :
349 249232 : for(Int_t i=0; i<dimexp; i++)
350 : {
351 124240 : if(fSignal[contaexp]>0)
352 : {
353 120470 : bufferE[i]=fSignal[contaexp];
354 120470 : }
355 124240 : if(fSignal[contaexp]<0)
356 : {
357 46941000 : for(Int_t j=0; j<longArr[h];j++)
358 : {
359 23466730 : bufferE[i+j]=0;
360 : }
361 3770 : i=i+longArr[h]-1;
362 3770 : h++;
363 3770 : }
364 124240 : contaexp++;
365 : }
366 :
367 : //Copy the buffer
368 752 : delete [] fSignal;
369 376 : fSignal=0;
370 376 : fSignal = new Float_t[dimexp];
371 376 : fNdim = dimexp;
372 47175152 : for(Int_t i=0; i<dimexp; i++)
373 : {
374 23587200 : fSignal[i] = bufferE[i];
375 : }
376 :
377 752 : delete [] bufferE;
378 :
379 : }
380 :
381 752 : delete [] longArr;
382 :
383 376 : }
384 :
385 376 : }
386 :
387 0 : }
388 : //________________________________________________________________________________
389 : void AliTRDarraySignal::Reset()
390 : {
391 : //
392 : // Reset the array, the old contents are deleted
393 : // The array keeps the same dimensions as before
394 : //
395 :
396 0 : memset(fSignal,0,sizeof(Float_t)*fNdim);
397 :
398 0 : }
399 : //________________________________________________________________________________
400 : Float_t AliTRDarraySignal::GetData(Int_t nrow, Int_t ncol, Int_t ntime) const
401 : {
402 : //
403 : // Get the data using the pad numbering.
404 : // To access data using the mcm scheme use instead
405 : // the method GetDataByAdcCol
406 : //
407 :
408 121734242 : Int_t corrcolumn = fgLutPadNumbering[ncol];
409 :
410 60867121 : return fSignal[(nrow*fNumberOfChannels+corrcolumn)*fNtime+ntime];
411 :
412 : }
413 : //________________________________________________________________________________
414 : void AliTRDarraySignal::SetData(Int_t nrow, Int_t ncol, Int_t ntime, Float_t value)
415 : {
416 : //
417 : // Set the data using the pad numbering.
418 : // To write data using the mcm scheme use instead
419 : // the method SetDataByAdcCol
420 : //
421 :
422 81299042 : Int_t colnumb = fgLutPadNumbering[ncol];
423 :
424 40649521 : fSignal[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime]=value;
425 :
426 40649521 : }
427 :
428 : //________________________________________________________________________________
429 : void AliTRDarraySignal::CreateLut()
430 : {
431 : //
432 : // Initializes the Look Up Table to relate
433 : // pad numbering and mcm channel numbering
434 : //
435 :
436 14416 : if(fgLutPadNumbering) return;
437 :
438 1 : fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
439 1 : memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
440 :
441 18 : for(Int_t mcm=0; mcm<8; mcm++)
442 : {
443 8 : Int_t lowerlimit=0+mcm*18;
444 8 : Int_t upperlimit=18+mcm*18;
445 8 : Int_t shiftposition = 1+3*mcm;
446 304 : for(Int_t index=lowerlimit;index<upperlimit;index++)
447 : {
448 144 : fgLutPadNumbering[index]=index+shiftposition;
449 : }
450 : }
451 7208 : }
|