]>
Commit | Line | Data |
---|---|---|
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 "Cal/AliTRDCalPadStatus.h" | |
29 | #include "AliTRDfeeParam.h" | |
30 | #include "AliTRDSignalIndex.h" | |
31 | ClassImp(AliTRDarrayADC) | |
32 | ||
33 | Short_t *AliTRDarrayADC::fgLutPadNumbering = 0x0; | |
34 | ||
35 | //____________________________________________________________________________________ | |
36 | AliTRDarrayADC::AliTRDarrayADC() | |
37 | :TObject() | |
38 | ,fNdet(0) | |
39 | ,fNrow(0) | |
40 | ,fNcol(0) | |
41 | ,fNumberOfChannels(0) | |
42 | ,fNtime(0) | |
43 | ,fNAdim(0) | |
44 | ,fADC(0) | |
45 | { | |
46 | // | |
47 | // AliTRDarrayADC default constructor | |
48 | // | |
49 | ||
50 | CreateLut(); | |
51 | ||
52 | } | |
53 | ||
54 | //____________________________________________________________________________________ | |
55 | AliTRDarrayADC::AliTRDarrayADC(Int_t nrow, Int_t ncol, Int_t ntime) | |
56 | :TObject() | |
57 | ,fNdet(0) | |
58 | ,fNrow(0) | |
59 | ,fNcol(0) | |
60 | ,fNumberOfChannels(0) | |
61 | ,fNtime(0) | |
62 | ,fNAdim(0) | |
63 | ,fADC(0) | |
64 | { | |
65 | // | |
66 | // AliTRDarrayADC constructor | |
67 | // | |
68 | ||
69 | CreateLut(); | |
70 | Allocate(nrow,ncol,ntime); | |
71 | ||
72 | } | |
73 | ||
74 | //____________________________________________________________________________________ | |
75 | AliTRDarrayADC::AliTRDarrayADC(const AliTRDarrayADC &b) | |
76 | :TObject() | |
77 | ,fNdet(b.fNdet) | |
78 | ,fNrow(b.fNrow) | |
79 | ,fNcol(b.fNcol) | |
80 | ,fNumberOfChannels(b.fNumberOfChannels) | |
81 | ,fNtime(b.fNtime) | |
82 | ,fNAdim(b.fNAdim) | |
83 | ,fADC(0) | |
84 | { | |
85 | // | |
86 | // AliTRDarrayADC copy constructor | |
87 | // | |
88 | ||
89 | fADC = new Short_t[fNAdim]; | |
90 | memcpy(fADC,b.fADC, fNAdim*sizeof(Short_t)); | |
91 | ||
92 | } | |
93 | ||
94 | //____________________________________________________________________________________ | |
95 | AliTRDarrayADC::~AliTRDarrayADC() | |
96 | { | |
97 | // | |
98 | // AliTRDarrayADC destructor | |
99 | // | |
100 | ||
101 | if(fADC) | |
102 | { | |
103 | delete [] fADC; | |
104 | fADC=0; | |
105 | } | |
106 | ||
107 | } | |
108 | ||
109 | //____________________________________________________________________________________ | |
110 | AliTRDarrayADC &AliTRDarrayADC::operator=(const AliTRDarrayADC &b) | |
111 | { | |
112 | // | |
113 | // Assignment operator | |
114 | // | |
115 | ||
116 | if(this==&b) | |
117 | { | |
118 | return *this; | |
119 | } | |
120 | if(fADC) | |
121 | { | |
122 | delete [] fADC; | |
123 | } | |
124 | fNdet=b.fNdet; | |
125 | fNrow=b.fNrow; | |
126 | fNcol=b.fNcol; | |
127 | fNumberOfChannels = b.fNumberOfChannels; | |
128 | fNtime=b.fNtime; | |
129 | fNAdim=b.fNAdim; | |
130 | fADC = new Short_t[fNAdim]; | |
131 | memcpy(fADC,b.fADC, fNAdim*sizeof(Short_t)); | |
132 | ||
133 | return *this; | |
134 | ||
135 | } | |
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 | fNrow=nrow; | |
146 | fNcol=ncol; | |
147 | fNtime=ntime; | |
148 | Int_t adcchannelspermcm = AliTRDfeeParam::GetNadcMcm(); | |
149 | Int_t padspermcm = AliTRDfeeParam::GetNcolMcm(); | |
150 | Int_t numberofmcms = fNcol/padspermcm; | |
151 | fNumberOfChannels = numberofmcms*adcchannelspermcm; | |
152 | fNAdim=nrow*fNumberOfChannels*ntime; | |
153 | ||
154 | if(fADC) | |
155 | { | |
156 | delete [] fADC; | |
157 | } | |
158 | ||
159 | fADC = new Short_t[fNAdim]; | |
160 | memset(fADC,0,sizeof(Short_t)*fNAdim); | |
161 | ||
162 | } | |
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 AliTRDdataArrayDigits | |
172 | // | |
173 | ||
174 | 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 | CLRBIT(tempval, 10); | |
178 | CLRBIT(tempval, 11); | |
179 | CLRBIT(tempval, 12); | |
180 | 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 AliTRDdataArrayDigits | |
198 | // | |
199 | ||
200 | UChar_t padstatus = 0; | |
201 | Short_t signal = GetData(row,col,time); | |
202 | if(signal > 0 && TESTBIT(signal, 10)){ | |
203 | if(TESTBIT(signal, 11)) | |
204 | if(TESTBIT(signal, 12)) | |
205 | padstatus = AliTRDCalPadStatus::kPadBridgedRight; | |
206 | else | |
207 | padstatus = AliTRDCalPadStatus::kNotConnected; | |
208 | else | |
209 | if(TESTBIT(signal, 12)) | |
210 | padstatus = AliTRDCalPadStatus::kPadBridgedLeft; | |
211 | else | |
212 | padstatus = AliTRDCalPadStatus::kMasked; | |
213 | } | |
214 | ||
215 | 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 AliTRDdataArrayDigits | |
239 | // | |
240 | ||
241 | Short_t signal = GetData(row,col,time); | |
242 | ||
243 | // Only set the Pad Status if the signal is > 0 | |
244 | if(signal > 0) | |
245 | { | |
246 | switch(status) | |
247 | { | |
248 | case AliTRDCalPadStatus::kMasked: | |
249 | SETBIT(signal, 10); | |
250 | CLRBIT(signal, 11); | |
251 | CLRBIT(signal, 12); | |
252 | break; | |
253 | case AliTRDCalPadStatus::kNotConnected: | |
254 | SETBIT(signal, 10); | |
255 | SETBIT(signal, 11); | |
256 | CLRBIT(signal, 12); | |
257 | break; | |
258 | case AliTRDCalPadStatus::kPadBridgedLeft: | |
259 | SETBIT(signal, 10); | |
260 | CLRBIT(signal, 11); | |
261 | SETBIT(signal, 12); | |
262 | break; | |
263 | case AliTRDCalPadStatus::kPadBridgedRight: | |
264 | SETBIT(signal, 10); | |
265 | SETBIT(signal, 11); | |
266 | SETBIT(signal, 12); | |
267 | break; | |
268 | default: | |
269 | CLRBIT(signal, 10); | |
270 | CLRBIT(signal, 11); | |
271 | CLRBIT(signal, 12); | |
272 | } | |
273 | SetData(row, col, time, signal); | |
274 | } | |
275 | ||
276 | } | |
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 AliTRDdataArrayDigits | |
285 | // | |
286 | ||
287 | Short_t signal = GetData(row,col,time); | |
288 | 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 | Int_t counter=0; | |
300 | Int_t newDim=0; | |
301 | Int_t j; | |
302 | Int_t l; | |
303 | Int_t r=0; | |
304 | Int_t s=0; | |
305 | Int_t k=0; | |
306 | ||
307 | Int_t *longm = new Int_t[fNAdim]; | |
308 | Int_t *longz = new Int_t[fNAdim]; | |
309 | ||
310 | if(longz && longm && fADC) | |
311 | { | |
312 | ||
313 | memset(longz,0,sizeof(Int_t)*fNAdim); | |
314 | memset(longm,0,sizeof(Int_t)*fNAdim); | |
315 | ||
316 | for(Int_t i=0;i<fNAdim; i++) | |
317 | { | |
318 | j=0; | |
319 | if(fADC[i]==-1) | |
320 | { | |
321 | for(k=i;k<fNAdim;k++) | |
322 | { | |
323 | if((fADC[k]==-1)&&(j<16000)) | |
324 | { | |
325 | j=j+1; | |
326 | longm[r]=j; | |
327 | } | |
328 | else | |
329 | { | |
330 | break; | |
331 | } | |
332 | } | |
333 | r=r+1; | |
334 | } | |
335 | l=16001; | |
336 | if(fADC[i]==0) | |
337 | { | |
338 | for(k=i;k<fNAdim;k++) | |
339 | { | |
340 | if((fADC[k]==0)&&(l<32767)) | |
341 | { | |
342 | l=l+1; | |
343 | longz[s]=l; | |
344 | } | |
345 | else | |
346 | { | |
347 | break; | |
348 | } | |
349 | } | |
350 | s=s+1; | |
351 | } | |
352 | if(fADC[i]>0) | |
353 | { | |
354 | i=i+1; | |
355 | } | |
356 | i=i+j+(l-16001-1); | |
357 | } | |
358 | ||
359 | //Calculate the size of the compressed array | |
360 | for(Int_t i=0; i<fNAdim;i++) | |
361 | { | |
362 | if(longm[i]!=0) | |
363 | { | |
364 | counter=counter+longm[i]-1; | |
365 | } | |
366 | if(longz[i]!=0) | |
367 | { | |
368 | counter=counter+(longz[i]-16001)-1; | |
369 | } | |
370 | } | |
371 | ||
372 | Int_t counterTwo=0; | |
373 | newDim = fNAdim-counter; //Dimension of the compressed array | |
374 | Short_t* buffer = new Short_t[newDim]; | |
375 | ||
376 | if(buffer) | |
377 | { | |
378 | ||
379 | //Fill the buffer of the compressed array | |
380 | Int_t g=0; | |
381 | Int_t h=0; | |
382 | for(Int_t i=0; i<newDim; i++) | |
383 | { | |
384 | if(counterTwo<fNAdim) | |
385 | { | |
386 | if(fADC[counterTwo]>0) | |
387 | { | |
388 | buffer[i]=fADC[counterTwo]; | |
389 | } | |
390 | if(fADC[counterTwo]==-1) | |
391 | { | |
392 | buffer[i]=-(longm[g]); | |
393 | counterTwo=counterTwo+longm[g]-1; | |
394 | g++; | |
395 | } | |
396 | if(fADC[counterTwo]==0) | |
397 | { | |
398 | buffer[i]=-(longz[h]); | |
399 | counterTwo=counterTwo+(longz[h]-16001)-1; | |
400 | h++; | |
401 | } | |
402 | counterTwo++; | |
403 | } | |
404 | } | |
405 | ||
406 | //Copy the buffer | |
407 | delete [] fADC; | |
408 | fADC=0; | |
409 | fADC = new Short_t[newDim]; | |
410 | fNAdim = newDim; | |
411 | for(Int_t i=0; i<newDim; i++) | |
412 | { | |
413 | fADC[i] = buffer[i]; | |
414 | } | |
415 | ||
416 | //Delete auxiliary arrays | |
417 | delete [] buffer; | |
418 | buffer=0; | |
419 | } | |
420 | ||
421 | delete [] longz; | |
422 | longz=0; | |
423 | delete [] longm; | |
424 | longm=0; | |
425 | ||
426 | } | |
427 | ||
428 | } | |
429 | ||
430 | //____________________________________________________________________________________ | |
431 | void AliTRDarrayADC::Expand() | |
432 | { | |
433 | // | |
434 | // Expand the array | |
435 | // | |
436 | ||
437 | if (fADC) | |
438 | { | |
439 | ||
440 | //Check if the array has not been already expanded | |
441 | Int_t verif=0; | |
442 | for(Int_t i=0; i<fNAdim; i++) | |
443 | { | |
444 | if(fADC[i]<-1) | |
445 | { | |
446 | verif++; | |
447 | } | |
448 | } | |
449 | ||
450 | if(verif==0) | |
451 | { | |
452 | //AliDebug(1,"Nothing to expand"); | |
453 | return; | |
454 | } | |
455 | ||
456 | Int_t dimexp=0; | |
457 | Int_t *longz = new Int_t[fNAdim]; | |
458 | Int_t *longm = new Int_t[fNAdim]; | |
459 | ||
460 | if (longz && longm) | |
461 | { | |
462 | ||
463 | //Initialize arrays | |
464 | memset(longz,0,sizeof(Int_t)*fNAdim); | |
465 | memset(longm,0,sizeof(Int_t)*fNAdim); | |
466 | Int_t r2=0; | |
467 | Int_t r3=0; | |
468 | for(Int_t i=0; i<fNAdim;i++) | |
469 | { | |
470 | if((fADC[i]<0)&&(fADC[i]>=-16000)) | |
471 | { | |
472 | longm[r2]=-fADC[i]; | |
473 | r2++; | |
474 | } | |
475 | if(fADC[i]<-16000) | |
476 | { | |
477 | longz[r3]=-fADC[i]-16001; | |
478 | r3++; | |
479 | } | |
480 | } | |
481 | ||
482 | //Calculate the new dimensions of the array | |
483 | for(Int_t i=0; i<fNAdim;i++) | |
484 | { | |
485 | if(longm[i]!=0) | |
486 | { | |
487 | dimexp=dimexp+longm[i]-1; | |
488 | } | |
489 | if(longz[i]!=0) | |
490 | { | |
491 | dimexp=dimexp+longz[i]-1; | |
492 | } | |
493 | } | |
494 | dimexp=dimexp+fNAdim; | |
495 | ||
496 | //Write in the buffer the new array | |
497 | Int_t contaexp =0; | |
498 | Int_t h=0; | |
499 | Int_t l=0; | |
500 | Short_t* bufferE = new Short_t[dimexp]; | |
501 | if(bufferE) | |
502 | { | |
503 | for(Int_t i=0; i<dimexp; i++) | |
504 | { | |
505 | if(fADC[contaexp]>0) | |
506 | { | |
507 | bufferE[i]=fADC[contaexp]; | |
508 | } | |
509 | if((fADC[contaexp]<0)&&(fADC[contaexp]>=-16000)) | |
510 | { | |
511 | for(Int_t j=0; j<longm[h];j++) | |
512 | { | |
513 | bufferE[i+j]=-1; | |
514 | } | |
515 | i=i+longm[h]-1; | |
516 | h++; | |
517 | } | |
518 | if(fADC[contaexp]<-16000) | |
519 | { | |
520 | for(Int_t j=0; j<longz[l];j++) | |
521 | { | |
522 | bufferE[i+j]=0; | |
523 | } | |
524 | i=i+longz[l]-1; | |
525 | l++; | |
526 | } | |
527 | contaexp++; | |
528 | } | |
529 | //Copy the buffer | |
530 | delete [] fADC; | |
531 | fADC = new Short_t[dimexp]; | |
532 | fNAdim = dimexp; | |
533 | for(Int_t i=0; i<dimexp; i++) | |
534 | { | |
535 | fADC[i] = bufferE[i]; | |
536 | } | |
537 | ||
538 | delete [] bufferE; | |
539 | ||
540 | } | |
541 | ||
542 | //Delete auxiliary arrays | |
543 | delete [] longm; | |
544 | delete [] longz; | |
545 | ||
546 | } | |
547 | ||
548 | } | |
549 | ||
550 | } | |
551 | //____________________________________________________________________________________ | |
552 | void AliTRDarrayADC::DeleteNegatives() | |
553 | { | |
554 | ||
555 | // | |
556 | //This method modifies the digits array, changing the negative values (-1) | |
557 | //Produced during digitization into zero. | |
558 | // | |
559 | ||
560 | for(Int_t a=0; a<fNAdim; a++) | |
561 | { | |
562 | if(fADC[a]==-1) | |
563 | { | |
564 | fADC[a]=0; | |
565 | } | |
566 | } | |
567 | } | |
568 | //________________________________________________________________________________ | |
569 | void AliTRDarrayADC::Reset() | |
570 | { | |
571 | // | |
572 | // Reset the array, the old contents are deleted | |
573 | // The array keeps the same dimensions as before | |
574 | // | |
575 | ||
576 | memset(fADC,0,sizeof(Short_t)*fNAdim); | |
577 | } | |
578 | //________________________________________________________________________________ | |
579 | void AliTRDarrayADC::ConditionalReset(AliTRDSignalIndex* idx) | |
580 | { | |
581 | // | |
582 | // Reset the array, the old contents are deleted | |
583 | // The array keeps the same dimensions as before | |
584 | // | |
585 | ||
586 | if(idx->GetNoOfIndexes()>25) | |
587 | memset(fADC,0,sizeof(Short_t)*fNAdim); | |
588 | else | |
589 | { | |
590 | Int_t row, col; | |
591 | while(idx->NextRCIndex(row, col)){ | |
592 | Int_t colnumb = fgLutPadNumbering[col]; | |
593 | memset(&fADC[(row*fNumberOfChannels+colnumb)*fNtime],0,fNtime); | |
594 | } | |
595 | } | |
596 | ||
597 | } | |
598 | ||
599 | //________________________________________________________________________________ | |
600 | void AliTRDarrayADC::CreateLut() | |
601 | { | |
602 | // | |
603 | // Initializes the Look Up Table to relate | |
604 | // pad numbering and mcm channel numbering | |
605 | // | |
606 | ||
607 | if(fgLutPadNumbering) return; | |
608 | ||
609 | fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()]; | |
610 | memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol()); | |
611 | ||
612 | for(Int_t mcm=0; mcm<8; mcm++) | |
613 | { | |
614 | Int_t lowerlimit=0+mcm*18; | |
615 | Int_t upperlimit=18+mcm*18; | |
616 | Int_t shiftposition = 1+3*mcm; | |
617 | for(Int_t index=lowerlimit;index<upperlimit;index++) | |
618 | { | |
619 | fgLutPadNumbering[index]=index+shiftposition; | |
620 | } | |
621 | } | |
622 | } |