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