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