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: AliTRDarrayADC.cxx 25392 2008-04-23 19:40:29Z cblume $ */
17 :
18 : ////////////////////////////////////////////////////////
19 : // //
20 : // Container class for ADC values //
21 : // //
22 : // Author: //
23 : // Hermes Leon Vargas (hleon@ikf.uni-frankfurt.de) //
24 : // //
25 : ////////////////////////////////////////////////////////
26 :
27 : #include "AliTRDarrayADC.h"
28 : #include "AliTRDCalPadStatus.h"
29 : #include "AliTRDfeeParam.h"
30 : #include "AliTRDSignalIndex.h"
31 : #include "AliLog.h"
32 :
33 48 : ClassImp(AliTRDarrayADC)
34 :
35 : Short_t *AliTRDarrayADC::fgLutPadNumbering = 0x0;
36 :
37 : //____________________________________________________________________________________
38 : AliTRDarrayADC::AliTRDarrayADC()
39 7562 : :TObject()
40 7562 : ,fNdet(0)
41 7562 : ,fNrow(0)
42 7562 : ,fNcol(0)
43 7562 : ,fNumberOfChannels(0)
44 7562 : ,fNtime(0)
45 7562 : ,fNAdim(0)
46 7562 : ,fADC(0)
47 37810 : {
48 : //
49 : // AliTRDarrayADC default constructor
50 : //
51 :
52 7562 : CreateLut();
53 :
54 15124 : }
55 :
56 : //____________________________________________________________________________________
57 : AliTRDarrayADC::AliTRDarrayADC(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 : ,fNAdim(0)
65 0 : ,fADC(0)
66 0 : {
67 : //
68 : // AliTRDarrayADC constructor
69 : //
70 :
71 0 : CreateLut();
72 0 : Allocate(nrow,ncol,ntime);
73 :
74 0 : }
75 :
76 : //____________________________________________________________________________________
77 : AliTRDarrayADC::AliTRDarrayADC(const AliTRDarrayADC &b)
78 376 : :TObject(b)
79 376 : ,fNdet(b.fNdet)
80 376 : ,fNrow(b.fNrow)
81 376 : ,fNcol(b.fNcol)
82 376 : ,fNumberOfChannels(b.fNumberOfChannels)
83 376 : ,fNtime(b.fNtime)
84 376 : ,fNAdim(b.fNAdim)
85 376 : ,fADC(0)
86 1880 : {
87 : //
88 : // AliTRDarrayADC copy constructor
89 : //
90 :
91 752 : fADC = new Short_t[fNAdim];
92 376 : memcpy(fADC,b.fADC, fNAdim*sizeof(Short_t));
93 :
94 752 : }
95 :
96 : //____________________________________________________________________________________
97 : AliTRDarrayADC::~AliTRDarrayADC()
98 46880 : {
99 : //
100 : // AliTRDarrayADC destructor
101 : //
102 :
103 9468 : delete [] fADC;
104 7938 : fADC=0;
105 :
106 23440 : }
107 :
108 : //____________________________________________________________________________________
109 : AliTRDarrayADC &AliTRDarrayADC::operator=(const AliTRDarrayADC &b)
110 : {
111 : //
112 : // Assignment operator
113 : //
114 :
115 0 : if(this==&b)
116 : {
117 0 : return *this;
118 : }
119 0 : if(fADC)
120 : {
121 0 : delete [] fADC;
122 : }
123 0 : TObject::operator=(b);
124 0 : fNdet=b.fNdet;
125 0 : fNrow=b.fNrow;
126 0 : fNcol=b.fNcol;
127 0 : fNumberOfChannels = b.fNumberOfChannels;
128 0 : fNtime=b.fNtime;
129 0 : fNAdim=b.fNAdim;
130 0 : fADC = new Short_t[fNAdim];
131 0 : memcpy(fADC,b.fADC, fNAdim*sizeof(Short_t));
132 :
133 0 : return *this;
134 :
135 0 : }
136 :
137 : //____________________________________________________________________________________
138 : void AliTRDarrayADC::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
139 : {
140 : //
141 : // Allocate memory for an AliTRDarrayADC array with dimensions
142 : // Row*NumberOfNecessaryMCMs*ADCchannelsInMCM*Time
143 : //
144 :
145 1458 : fNrow=nrow;
146 729 : fNcol=ncol;
147 729 : fNtime=ntime;
148 729 : Int_t adcchannelspermcm = AliTRDfeeParam::GetNadcMcm();
149 729 : Int_t padspermcm = AliTRDfeeParam::GetNcolMcm();
150 729 : Int_t numberofmcms = fNcol/padspermcm;
151 729 : fNumberOfChannels = numberofmcms*adcchannelspermcm;
152 729 : fNAdim=nrow*fNumberOfChannels*ntime;
153 :
154 729 : if(fADC)
155 : {
156 0 : delete [] fADC;
157 : }
158 :
159 729 : fADC = new Short_t[fNAdim];
160 729 : memset(fADC,0,sizeof(Short_t)*fNAdim);
161 :
162 729 : }
163 :
164 : //____________________________________________________________________________________
165 : Short_t AliTRDarrayADC::GetDataBits(Int_t row, Int_t col, Int_t time) const
166 : {
167 : //
168 : // Get the ADC value for a given position: row, col, time
169 : // Taking bit masking into account
170 : //
171 : // Adapted from code of the class AliTRDclusterizer
172 : //
173 :
174 20217600 : Short_t tempval = GetData(row,col,time);
175 : // Be aware of manipulations introduced by pad masking in the RawReader
176 : // Only output the manipulated Value
177 10108800 : CLRBIT(tempval, 10);
178 10108800 : CLRBIT(tempval, 11);
179 10108800 : CLRBIT(tempval, 12);
180 10108800 : return tempval;
181 :
182 : }
183 :
184 : //____________________________________________________________________________________
185 : UChar_t AliTRDarrayADC::GetPadStatus(Int_t row, Int_t col, Int_t time) const
186 : {
187 : //
188 : // Returns the pad status stored in the pad signal
189 : //
190 : // Output is a UChar_t value
191 : // Status Codes:
192 : // Noisy Masking: 2
193 : // Bridged Left Masking 8
194 : // Bridged Right Masking 8
195 : // Not Connected Masking Digits
196 : //
197 : // Adapted from code of the class AliTRDclusterizer
198 : //
199 :
200 : UChar_t padstatus = 0;
201 0 : Short_t signal = GetData(row,col,time);
202 0 : if(signal > 0 && TESTBIT(signal, 10)){
203 0 : if(TESTBIT(signal, 11))
204 0 : if(TESTBIT(signal, 12))
205 0 : padstatus = AliTRDCalPadStatus::kPadBridgedRight;
206 : else
207 : padstatus = AliTRDCalPadStatus::kNotConnected;
208 : else
209 0 : if(TESTBIT(signal, 12))
210 0 : padstatus = AliTRDCalPadStatus::kPadBridgedLeft;
211 : else
212 : padstatus = AliTRDCalPadStatus::kMasked;
213 : }
214 :
215 0 : return padstatus;
216 :
217 : }
218 :
219 : //____________________________________________________________________________________
220 : void AliTRDarrayADC::SetPadStatus(Int_t row, Int_t col, Int_t time, UChar_t status)
221 : {
222 : //
223 : // Setting the pad status into the signal using the Bits 10 to 14
224 : // (currently used: 10 to 12)
225 : //
226 : // Input codes (Unsigned char):
227 : // Noisy Masking: 2
228 : // Bridged Left Masking 8
229 : // Bridged Right Masking 8
230 : // Not Connected Masking 32
231 : //
232 : // Status codes: Any masking: Bit 10(1)
233 : // Noisy masking: Bit 11(0), Bit 12(0)
234 : // No Connection masking: Bit 11(1), Bit 12(0)
235 : // Bridged Left masking: Bit 11(0), Bit 12(1)
236 : // Bridged Right masking: Bit 11(1), Bit 12(1)
237 : //
238 : // Adapted from code of the class AliTRDclusterizer
239 : //
240 :
241 0 : Short_t signal = GetData(row,col,time);
242 :
243 : // Only set the Pad Status if the signal is > 0
244 0 : if(signal > 0)
245 : {
246 0 : switch(status)
247 : {
248 : case AliTRDCalPadStatus::kMasked:
249 0 : SETBIT(signal, 10);
250 0 : CLRBIT(signal, 11);
251 0 : CLRBIT(signal, 12);
252 0 : break;
253 : case AliTRDCalPadStatus::kNotConnected:
254 0 : SETBIT(signal, 10);
255 0 : SETBIT(signal, 11);
256 0 : CLRBIT(signal, 12);
257 0 : break;
258 : case AliTRDCalPadStatus::kPadBridgedLeft:
259 0 : SETBIT(signal, 10);
260 0 : CLRBIT(signal, 11);
261 0 : SETBIT(signal, 12);
262 0 : break;
263 : case AliTRDCalPadStatus::kPadBridgedRight:
264 0 : SETBIT(signal, 10);
265 0 : SETBIT(signal, 11);
266 0 : SETBIT(signal, 12);
267 0 : break;
268 : default:
269 0 : CLRBIT(signal, 10);
270 0 : CLRBIT(signal, 11);
271 0 : CLRBIT(signal, 12);
272 0 : }
273 0 : SetData(row, col, time, signal);
274 0 : }
275 :
276 0 : }
277 :
278 : //____________________________________________________________________________________
279 : Bool_t AliTRDarrayADC::IsPadCorrupted(Int_t row, Int_t col, Int_t time)
280 : {
281 : //
282 : // Checks if the pad has any masking as corrupted (Bit 10 in signal set)
283 : //
284 : // Adapted from code of the class AliTRDclusterizer
285 : //
286 :
287 0 : Short_t signal = GetData(row,col,time);
288 0 : return (signal > 0 && TESTBIT(signal, 10)) ? kTRUE : kFALSE;
289 :
290 : }
291 :
292 : //____________________________________________________________________________________
293 : void AliTRDarrayADC::Compress()
294 : {
295 : //
296 : // Compress the array
297 : //
298 :
299 376 : if(fNAdim!=fNrow*fNumberOfChannels*fNtime)
300 : {
301 0 : AliDebug(1,"The ADC array is already compressed");
302 : return;
303 : }
304 :
305 : Int_t counter=0;
306 : Int_t newDim=0;
307 : Int_t j;
308 : Int_t l;
309 : Int_t r=0;
310 : Int_t s=0;
311 : Int_t k=0;
312 :
313 188 : Int_t *longm = new Int_t[fNAdim];
314 188 : Int_t *longz = new Int_t[fNAdim];
315 :
316 376 : if(longz && longm && fADC)
317 : {
318 :
319 188 : memset(longz,0,sizeof(Int_t)*fNAdim);
320 188 : memset(longm,0,sizeof(Int_t)*fNAdim);
321 :
322 207524 : for(Int_t i=0;i<fNAdim; i++)
323 : {
324 : j=0;
325 103574 : if(fADC[i]==-1)
326 : {
327 23384704 : for(k=i;k<fNAdim;k++)
328 : {
329 11692164 : if((fADC[k]==-1)&&(j<16000))
330 : {
331 11691189 : j=j+1;
332 11691189 : longm[r]=j;
333 : }
334 : else
335 : {
336 : break;
337 : }
338 : }
339 1163 : r=r+1;
340 1163 : }
341 : l=16001;
342 103574 : if(fADC[i]==0)
343 : {
344 0 : for(k=i;k<fNAdim;k++)
345 : {
346 0 : if((fADC[k]==0)&&(l<32767))
347 : {
348 0 : l=l+1;
349 0 : longz[s]=l;
350 : }
351 : else
352 : {
353 : break;
354 : }
355 : }
356 0 : s=s+1;
357 0 : }
358 103574 : if(fADC[i]>0)
359 : {
360 102411 : i=i+1;
361 102411 : }
362 103574 : i=i+j+(l-16001-1);
363 : }
364 :
365 : //Calculate the size of the compressed array
366 23587576 : for(Int_t i=0; i<fNAdim;i++)
367 : {
368 11793600 : if(longm[i]!=0)
369 : {
370 1163 : counter=counter+longm[i]-1;
371 1163 : }
372 11793600 : if(longz[i]!=0)
373 : {
374 0 : counter=counter+(longz[i]-16001)-1;
375 0 : }
376 : }
377 :
378 : Int_t counterTwo=0;
379 188 : newDim = fNAdim-counter; //Dimension of the compressed array
380 188 : Short_t* buffer = new Short_t[newDim];
381 :
382 188 : if(buffer)
383 : {
384 :
385 : //Fill the buffer of the compressed array
386 : Int_t g=0;
387 : Int_t h=0;
388 207524 : for(Int_t i=0; i<newDim; i++)
389 : {
390 103574 : if(counterTwo<fNAdim)
391 : {
392 103574 : if(fADC[counterTwo]>0)
393 : {
394 102411 : buffer[i]=fADC[counterTwo];
395 102411 : }
396 103574 : if(fADC[counterTwo]==-1)
397 : {
398 1163 : buffer[i]=-(longm[g]);
399 1163 : counterTwo=counterTwo+longm[g]-1;
400 1163 : g++;
401 1163 : }
402 103574 : if(fADC[counterTwo]==0)
403 : {
404 0 : buffer[i]=-(longz[h]);
405 0 : counterTwo=counterTwo+(longz[h]-16001)-1;
406 0 : h++;
407 0 : }
408 103574 : counterTwo++;
409 103574 : }
410 : }
411 :
412 : //Copy the buffer
413 376 : delete [] fADC;
414 188 : fADC=0;
415 188 : fADC = new Short_t[newDim];
416 188 : fNAdim = newDim;
417 207524 : for(Int_t i=0; i<newDim; i++)
418 : {
419 103574 : fADC[i] = buffer[i];
420 : }
421 :
422 : //Delete auxiliary arrays
423 376 : delete [] buffer;
424 : buffer=0;
425 188 : }
426 :
427 188 : }
428 :
429 188 : if (longz)
430 : {
431 376 : delete [] longz;
432 : longz=0;
433 188 : }
434 188 : if (longm)
435 : {
436 376 : delete [] longm;
437 : longm=0;
438 :
439 188 : }
440 :
441 376 : }
442 :
443 : //____________________________________________________________________________________
444 : void AliTRDarrayADC::Expand()
445 : {
446 : //
447 : // Expand the array
448 : //
449 :
450 1504 : if (fADC)
451 : {
452 :
453 : //Check if the array has not been already expanded
454 : Int_t verif=0;
455 24210148 : for(Int_t i=0; i<fNAdim; i++)
456 : {
457 12104322 : if(fADC[i]<-1)
458 : {
459 3489 : verif++;
460 3489 : }
461 : }
462 :
463 752 : if(verif==0)
464 : {
465 564 : AliDebug(1,"Nothing to expand");
466 188 : return;
467 : }
468 :
469 : Int_t dimexp=0;
470 564 : Int_t *longz = new Int_t[fNAdim];
471 564 : Int_t *longm = new Int_t[fNAdim];
472 :
473 564 : if (longz && longm)
474 : {
475 :
476 : //Initialize arrays
477 564 : memset(longz,0,sizeof(Int_t)*fNAdim);
478 564 : memset(longm,0,sizeof(Int_t)*fNAdim);
479 : Int_t r2=0;
480 : Int_t r3=0;
481 622572 : for(Int_t i=0; i<fNAdim;i++)
482 : {
483 314211 : if((fADC[i]<0)&&(fADC[i]>=-16000))
484 : {
485 3489 : longm[r2]=-fADC[i];
486 3489 : r2++;
487 3489 : }
488 310722 : if(fADC[i]<-16000)
489 : {
490 0 : longz[r3]=-fADC[i]-16001;
491 0 : r3++;
492 0 : }
493 : }
494 :
495 : //Calculate the new dimensions of the array
496 622572 : for(Int_t i=0; i<fNAdim;i++)
497 : {
498 310722 : if(longm[i]!=0)
499 : {
500 3489 : dimexp=dimexp+longm[i]-1;
501 3489 : }
502 310722 : if(longz[i]!=0)
503 : {
504 0 : dimexp=dimexp+longz[i]-1;
505 0 : }
506 : }
507 564 : dimexp=dimexp+fNAdim;
508 :
509 : //Write in the buffer the new array
510 : Int_t contaexp =0;
511 : Int_t h=0;
512 : Int_t l=0;
513 564 : Short_t* bufferE = new Short_t[dimexp];
514 564 : if(bufferE)
515 : {
516 622572 : for(Int_t i=0; i<dimexp; i++)
517 : {
518 310722 : if(fADC[contaexp]>0)
519 : {
520 307233 : bufferE[i]=fADC[contaexp];
521 307233 : }
522 314211 : if((fADC[contaexp]<0)&&(fADC[contaexp]>=-16000))
523 : {
524 70154112 : for(Int_t j=0; j<longm[h];j++)
525 : {
526 35073567 : bufferE[i+j]=-1;
527 : }
528 3489 : i=i+longm[h]-1;
529 3489 : h++;
530 3489 : }
531 310722 : if(fADC[contaexp]<-16000)
532 : {
533 0 : for(Int_t j=0; j<longz[l];j++)
534 : {
535 0 : bufferE[i+j]=0;
536 : }
537 0 : i=i+longz[l]-1;
538 0 : l++;
539 0 : }
540 310722 : contaexp++;
541 : }
542 : //Copy the buffer
543 1128 : delete [] fADC;
544 564 : fADC = new Short_t[dimexp];
545 564 : fNAdim = dimexp;
546 70762728 : for(Int_t i=0; i<dimexp; i++)
547 : {
548 35380800 : fADC[i] = bufferE[i];
549 : }
550 :
551 1128 : delete [] bufferE;
552 :
553 : }
554 :
555 : //Delete auxiliary arrays
556 1128 : delete [] longm;
557 1128 : delete [] longz;
558 :
559 564 : }
560 :
561 564 : }
562 :
563 0 : }
564 : //____________________________________________________________________________________
565 : void AliTRDarrayADC::DeleteNegatives()
566 : {
567 :
568 : //
569 : //This method modifies the digits array, changing the negative values (-1)
570 : //Produced during digitization into zero.
571 : //
572 :
573 23587764 : for(Int_t a=0; a<fNAdim; a++)
574 : {
575 11793600 : if(fADC[a]==-1)
576 : {
577 11691189 : fADC[a]=0;
578 11691189 : }
579 : }
580 188 : }
581 : //________________________________________________________________________________
582 : void AliTRDarrayADC::Reset()
583 : {
584 : //
585 : // Reset the array, the old contents are deleted
586 : // The array keeps the same dimensions as before
587 : //
588 :
589 0 : memset(fADC,0,sizeof(Short_t)*fNAdim);
590 0 : }
591 : //________________________________________________________________________________
592 : void AliTRDarrayADC::ConditionalReset(AliTRDSignalIndex* idx)
593 : {
594 : //
595 : // Reset the array, the old contents are deleted
596 : // The array keeps the same dimensions as before
597 : //
598 :
599 752 : if(idx->GetNoOfIndexes()>25)
600 54 : memset(fADC,0,sizeof(Short_t)*fNAdim);
601 : else
602 : {
603 322 : Int_t row, col;
604 6722 : while(idx->NextRCIndex(row, col)){
605 3039 : Int_t colnumb = fgLutPadNumbering[col];
606 3039 : memset(&fADC[(row*fNumberOfChannels+colnumb)*fNtime],0,fNtime);
607 : }
608 322 : }
609 :
610 376 : }
611 :
612 : //________________________________________________________________________________
613 : void AliTRDarrayADC::CreateLut()
614 : {
615 : //
616 : // Initializes the Look Up Table to relate
617 : // pad numbering and mcm channel numbering
618 : //
619 :
620 15124 : if(fgLutPadNumbering) return;
621 :
622 3 : fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
623 3 : memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
624 :
625 54 : for(Int_t mcm=0; mcm<8; mcm++)
626 : {
627 24 : Int_t lowerlimit=0+mcm*18;
628 24 : Int_t upperlimit=18+mcm*18;
629 24 : Int_t shiftposition = 1+3*mcm;
630 912 : for(Int_t index=lowerlimit;index<upperlimit;index++)
631 : {
632 432 : fgLutPadNumbering[index]=index+shiftposition;
633 : }
634 : }
635 7562 : }
|