]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDarraySignal.cxx
- temporary disabled the weighting for LHC12f1a,f1b,i3
[u/mrichter/AliRoot.git] / TRD / AliTRDarraySignal.cxx
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 ClassImp(AliTRDarraySignal)
33
34 Short_t *AliTRDarraySignal::fgLutPadNumbering = 0x0;
35
36 //_______________________________________________________________________
37 AliTRDarraySignal::AliTRDarraySignal()
38                   :TObject()
39                   ,fNdet(0)
40                   ,fNrow(0)
41                   ,fNcol(0)
42                   ,fNumberOfChannels(0)
43                   ,fNtime(0)
44                   ,fNdim(0)  
45                   ,fSignal(0)
46 {
47
48   //
49   // AliTRDarraySignal default constructor
50   //
51
52   CreateLut();
53            
54 }
55
56 //_______________________________________________________________________
57 AliTRDarraySignal::AliTRDarraySignal(Int_t nrow, Int_t ncol,Int_t ntime)
58                   :TObject()
59                   ,fNdet(0)
60                   ,fNrow(0)
61                   ,fNcol(0)
62                   ,fNumberOfChannels(0)
63                   ,fNtime(0)
64                   ,fNdim(0)
65                   ,fSignal(0)
66 {
67   //
68   // AliTRDarraySignal constructor
69   //
70
71   CreateLut(); 
72   Allocate(nrow,ncol,ntime);
73
74 }
75
76 //_______________________________________________________________________
77 AliTRDarraySignal::AliTRDarraySignal(const AliTRDarraySignal &d)
78                   :TObject()
79                   ,fNdet(d.fNdet)
80                   ,fNrow(d.fNrow)
81                   ,fNcol(d.fNcol)
82                   ,fNumberOfChannels(d.fNumberOfChannels)
83                   ,fNtime(d.fNtime)
84                   ,fNdim(d.fNdim)
85                   ,fSignal(0)
86 {
87   //
88   // AliTRDarraySignal copy constructor
89   //
90
91   fSignal = new Float_t[fNdim];
92   memcpy(fSignal, d.fSignal, fNdim*sizeof(Float_t));
93
94 }
95
96 //_______________________________________________________________________
97 AliTRDarraySignal::~AliTRDarraySignal()
98 {
99   //
100   // AliTRDarraySignal destructor
101   //
102
103   delete [] fSignal;
104   fSignal=0;  
105
106 }
107
108 //_______________________________________________________________________
109 AliTRDarraySignal &AliTRDarraySignal::operator=(const AliTRDarraySignal &d)
110 {
111   //
112   // Assignment operator
113   //
114
115   if (this==&d) 
116     {
117       return *this;
118     }
119
120   if (fSignal)
121     {
122       delete [] fSignal;
123     }
124   fNdet=d.fNdet;
125   fNrow=d.fNrow;
126   fNcol=d.fNcol;
127   fNumberOfChannels = d.fNumberOfChannels;
128   fNtime=d.fNtime;
129   fNdim=d.fNdim;
130   fSignal = new Float_t[fNdim];
131   memcpy(fSignal,d.fSignal, fNdim*sizeof(Float_t));
132
133   return *this;
134
135 }
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   fNrow=nrow;
147   fNcol=ncol;
148   fNtime=ntime;
149   Int_t adcchannelspermcm = AliTRDfeeParam::GetNadcMcm(); 
150   Int_t padspermcm = AliTRDfeeParam::GetNcolMcm(); 
151   Int_t numberofmcms = fNcol/padspermcm; 
152   fNumberOfChannels = numberofmcms*adcchannelspermcm;
153   fNdim = nrow*fNumberOfChannels*ntime;
154   if (fSignal)   
155     {
156       delete [] fSignal;
157     }
158   fSignal = new Float_t[fNdim];
159   memset(fSignal,0,sizeof(Float_t)*fNdim);
160
161 }
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   for(Int_t i=0; i<fNdim; i++)
172     {
173       if(fSignal[i]>threshold)
174         {
175           counter++;
176         }
177     }
178   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   Int_t *longArr = new Int_t[fNdim];  
197
198   if(longArr) 
199     {
200
201       //Initialize the array
202       memset(longArr,0,sizeof(Int_t)*fNdim);
203
204       for(Int_t i=0;i<fNdim; i++)
205         {
206           j=0;
207           if(fSignal[i]<=minval) 
208             {
209               for(k=i;k<fNdim;k++)
210                 {
211                   if(fSignal[k]<=minval)
212                     {
213                       j=j+1;
214                       longArr[r]=j;
215                     }
216                   else
217                     {
218                       break;
219                     }
220                 } 
221               r=r+1;          
222             }
223           i=i+j;
224         }
225
226       //Calculate the size of the compressed array
227       for(Int_t i=0; i<fNdim;i++)
228         {
229           if(longArr[i]!=0)   
230             {
231               counter=counter+longArr[i]-1;
232             }
233         }
234       newDim=fNdim-counter;   //New dimension
235
236       //Fill the buffer of the compressed array
237       Float_t* buffer = new Float_t[newDim];
238       Int_t counterTwo=0;
239
240       if(buffer)
241         {
242
243           //Write the new array
244           Int_t g=0;
245           for(Int_t i=0; i<newDim; i++)
246             {
247               if(counterTwo<fNdim)
248                 {
249                   if(fSignal[counterTwo]>minval)   
250                     {
251                       buffer[i]=fSignal[counterTwo];
252                     }
253                   if(fSignal[counterTwo]<=minval)   
254                     {
255                       buffer[i]=-(longArr[g]);
256                       counterTwo=counterTwo+longArr[g]-1;
257                       g++;
258                     }  
259                   counterTwo++;
260                 }
261             }
262
263           //Copy the buffer
264           if(fSignal)
265             {
266               delete [] fSignal;
267               fSignal=0;
268             }
269           fSignal = new Float_t[newDim];
270           fNdim = newDim;
271           for(Int_t i=0; i<newDim; i++)
272             {
273               fSignal[i] = buffer[i]; 
274             }
275
276           delete [] buffer;
277           buffer=0;
278
279         } 
280
281       delete [] longArr;
282       longArr=0;
283
284     }
285
286 }
287
288 //_______________________________________________________________________
289 void AliTRDarraySignal::Expand()
290 {
291   //
292   // Expand the array
293   //
294
295   if(fSignal)
296     {
297
298       //Check if the array has not been already expanded
299       Int_t verif=0;
300       for(Int_t i=0; i<fNdim; i++)
301         {
302           if(fSignal[i]<0)
303             {
304               verif++;
305             }
306         }
307
308       if(verif==0)
309         {
310           return;
311         }
312
313       Int_t dimexp=0;
314       Int_t *longArr = new Int_t[fNdim];
315
316       if(longArr)
317         {
318
319           memset(longArr,0,sizeof(Int_t)*fNdim);
320
321           Int_t r2=0;
322           for(Int_t i=0; i<fNdim;i++)
323             {
324               if(fSignal[i]<0)  
325                 {
326                   longArr[r2]=(Int_t)(-fSignal[i]); 
327                   r2++;
328                 }
329             }
330
331           //Calculate new dimensions
332           for(Int_t i=0; i<fNdim;i++)
333             {
334               if(longArr[i]!=0)      
335                 {
336                   dimexp=dimexp+longArr[i]-1;
337                 }
338             }
339           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           Float_t* bufferE = new Float_t[dimexp];
345
346           if(bufferE)
347             {
348
349               for(Int_t i=0; i<dimexp; i++)
350                 {
351                   if(fSignal[contaexp]>0)  
352                     {
353                       bufferE[i]=fSignal[contaexp];
354                     }
355                   if(fSignal[contaexp]<0)  
356                     {
357                       for(Int_t j=0; j<longArr[h];j++)
358                         {
359                           bufferE[i+j]=0;
360                         }
361                       i=i+longArr[h]-1;
362                       h++;
363                     }
364                   contaexp++;
365                 }
366
367               //Copy the buffer
368               delete [] fSignal;
369               fSignal=0;
370               fSignal = new Float_t[dimexp];
371               fNdim = dimexp;
372               for(Int_t i=0; i<dimexp; i++)
373                 {
374                   fSignal[i] = bufferE[i]; 
375                 }
376
377               delete [] bufferE;
378
379             }
380
381           delete [] longArr;
382
383         }
384
385     }
386
387 }
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   memset(fSignal,0,sizeof(Float_t)*fNdim);
397
398 }
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   Int_t corrcolumn = fgLutPadNumbering[ncol];
409
410   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   Int_t colnumb = fgLutPadNumbering[ncol];
423
424   fSignal[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime]=value;
425
426 }
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   if(fgLutPadNumbering)  return;
437   
438    fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
439    memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
440
441   for(Int_t mcm=0; mcm<8; mcm++)
442     {
443       Int_t lowerlimit=0+mcm*18;
444       Int_t upperlimit=18+mcm*18;
445       Int_t shiftposition = 1+3*mcm;
446       for(Int_t index=lowerlimit;index<upperlimit;index++)
447         {
448           fgLutPadNumbering[index]=index+shiftposition;
449         }
450     }
451 }