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