]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDarraySignal.cxx
Merge with TRDdev.2.0
[u/mrichter/AliRoot.git] / TRD / AliTRDarraySignal.cxx
index 68749de2dd508ae016c158b7df74d6256f2880d7..1293a206f042a852cabff1795675959e5536dd60 100644 (file)
 //                                                     //
 /////////////////////////////////////////////////////////
 
+#include <TArray.h>
+
 #include "AliTRDarraySignal.h"
-//#include "AliLog.h"
-#include "TArray.h" //for memset
+#include "AliTRDfeeParam.h"
 
 ClassImp(AliTRDarraySignal)
 
+Short_t *AliTRDarraySignal::fgLutPadNumbering = 0x0;
+
 //_______________________________________________________________________
 AliTRDarraySignal::AliTRDarraySignal()
                   :TObject()
                   ,fNdet(0)
                   ,fNrow(0)
                   ,fNcol(0)
+                 ,fNumberOfChannels(0)
                   ,fNtime(0)
                   ,fNdim(0)  
                   ,fSignal(0)
@@ -44,6 +48,8 @@ AliTRDarraySignal::AliTRDarraySignal()
   //
   // AliTRDarraySignal default constructor
   //
+
+  CreateLut();
           
 }
 
@@ -53,6 +59,7 @@ AliTRDarraySignal::AliTRDarraySignal(Int_t nrow, Int_t ncol,Int_t ntime)
                   ,fNdet(0)
                   ,fNrow(0)
                   ,fNcol(0)
+                 ,fNumberOfChannels(0)
                   ,fNtime(0)
                   ,fNdim(0)
                   ,fSignal(0)
@@ -60,7 +67,8 @@ AliTRDarraySignal::AliTRDarraySignal(Int_t nrow, Int_t ncol,Int_t ntime)
   //
   // AliTRDarraySignal constructor
   //
+
+  CreateLut(); 
   Allocate(nrow,ncol,ntime);
 
 }
@@ -71,6 +79,7 @@ AliTRDarraySignal::AliTRDarraySignal(const AliTRDarraySignal &d)
                  ,fNdet(d.fNdet)
                  ,fNrow(d.fNrow)
                  ,fNcol(d.fNcol)
+                  ,fNumberOfChannels(d.fNumberOfChannels)
                  ,fNtime(d.fNtime)
                  ,fNdim(d.fNdim)
                  ,fSignal(0)
@@ -91,11 +100,8 @@ AliTRDarraySignal::~AliTRDarraySignal()
   // AliTRDarraySignal destructor
   //
 
-  if (fSignal)   
-    {
-      delete [] fSignal;
-      fSignal=0;  
-    }
+  delete [] fSignal;
+  fSignal=0;  
 
 }
 
@@ -118,6 +124,7 @@ AliTRDarraySignal &AliTRDarraySignal::operator=(const AliTRDarraySignal &d)
   fNdet=d.fNdet;
   fNrow=d.fNrow;
   fNcol=d.fNcol;
+  fNumberOfChannels = d.fNumberOfChannels;
   fNtime=d.fNtime;
   fNdim=d.fNdim;
   fSignal = new Float_t[fNdim];
@@ -132,13 +139,18 @@ void AliTRDarraySignal::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
 {
   //
   // Allocates memory for an AliTRDarraySignal object with dimensions 
-  // Row*Col*Time
+  // Row*NumberOfNecessaryMCMs*ADCchannelsInMCM*Time
+  // To be consistent with AliTRDarrayADC
   //
 
   fNrow=nrow;
   fNcol=ncol;
   fNtime=ntime;
-  fNdim = nrow*ncol*ntime;
+  Int_t adcchannelspermcm = AliTRDfeeParam::GetNadcMcm(); 
+  Int_t padspermcm = AliTRDfeeParam::GetNcolMcm(); 
+  Int_t numberofmcms = fNcol/padspermcm; 
+  fNumberOfChannels = numberofmcms*adcchannelspermcm;
+  fNdim = nrow*fNumberOfChannels*ntime;
   if (fSignal)   
     {
       delete [] fSignal;
@@ -149,7 +161,7 @@ void AliTRDarraySignal::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
 }
 
 //_______________________________________________________________________
-Int_t AliTRDarraySignal::GetOverThreshold(Float_t threshold)
+Int_t AliTRDarraySignal::GetOverThreshold(Float_t threshold) const
 {
   //
   // Get the number of entries over the threshold 
@@ -179,91 +191,96 @@ void AliTRDarraySignal::Compress(Float_t minval)
   Int_t newDim=0;
   Int_t j;                 
   Int_t r=0;
-  Int_t *longArr;
-  longArr = new Int_t[fNdim];  
   Int_t k=0;
 
-  //Initialize the array
-  memset(longArr,0,sizeof(Int_t)*fNdim);
-
-  for(Int_t i=0;i<fNdim; i++)
-    {
-      j=0;
-      if(fSignal[i]<=minval) 
-       {
-         for(k=i;k<fNdim;k++)
-           {
-             if(fSignal[k]<=minval)
-               {
-                 j=j+1;
-                 longArr[r]=j;
-               }
-             else
-               {
-                 break;
-               }
-           } 
-         r=r+1;          
-       }
-      i=i+j;
-    }
+  Int_t *longArr = new Int_t[fNdim];  
 
-  //Calculate the size of the compressed array
-  for(Int_t i=0; i<fNdim;i++)
+  if(longArr) 
     {
-      if(longArr[i]!=0)   
-       {
-         counter=counter+longArr[i]-1;
-       }
-    }
-  newDim=fNdim-counter;   //New dimension
 
-  //Fill the buffer of the compressed array
-  Float_t* buffer;
-  buffer = new Float_t[newDim];
-  Int_t counterTwo=0;
+      //Initialize the array
+      memset(longArr,0,sizeof(Int_t)*fNdim);
 
-  //Write the new array
-  Int_t g=0;
-  for(Int_t i=0; i<newDim; i++)
-    {
-      if(counterTwo<fNdim)
-       {
-         if(fSignal[counterTwo]>minval)   
+      for(Int_t i=0;i<fNdim; i++)
+        {
+          j=0;
+          if(fSignal[i]<=minval) 
            {
-             buffer[i]=fSignal[counterTwo];
+             for(k=i;k<fNdim;k++)
+               {
+                 if(fSignal[k]<=minval)
+                   {
+                     j=j+1;
+                     longArr[r]=j;
+                   }
+                 else
+                   {
+                     break;
+                   }
+               } 
+             r=r+1;          
            }
-         if(fSignal[counterTwo]<=minval)   
+          i=i+j;
+        }
+
+      //Calculate the size of the compressed array
+      for(Int_t i=0; i<fNdim;i++)
+        {
+          if(longArr[i]!=0)   
            {
-             buffer[i]=-(longArr[g]);
-             counterTwo=counterTwo+longArr[g]-1;
-             g++;
-           }  
-         counterTwo++;
-       }
-    }
+             counter=counter+longArr[i]-1;
+           }
+        }
+      newDim=fNdim-counter;   //New dimension
+
+      //Fill the buffer of the compressed array
+      Float_t* buffer = new Float_t[newDim];
+      Int_t counterTwo=0;
+
+      if(buffer)
+        {
+
+          //Write the new array
+          Int_t g=0;
+          for(Int_t i=0; i<newDim; i++)
+            {
+              if(counterTwo<fNdim)
+               {
+                 if(fSignal[counterTwo]>minval)   
+                   {
+                     buffer[i]=fSignal[counterTwo];
+                   }
+                 if(fSignal[counterTwo]<=minval)   
+                   {
+                     buffer[i]=-(longArr[g]);
+                     counterTwo=counterTwo+longArr[g]-1;
+                     g++;
+                   }  
+                 counterTwo++;
+               }
+            }
+
+          //Copy the buffer
+          if(fSignal)
+            {
+              delete [] fSignal;
+              fSignal=0;
+            }
+          fSignal = new Float_t[newDim];
+          fNdim = newDim;
+          for(Int_t i=0; i<newDim; i++)
+            {
+              fSignal[i] = buffer[i]; 
+            }
+
+          delete [] buffer;
+          buffer=0;
+
+        } 
 
-  //Copy the buffer
-  if(fSignal)
-    {
-      delete [] fSignal;
-      fSignal=0;
-    }
-  fSignal = new Float_t[newDim];
-  fNdim = newDim;
-  for(Int_t i=0; i<newDim; i++)
-    {
-      fSignal[i] = buffer[i]; 
-    }
-  if(buffer)
-    {
-      delete [] buffer;
-      buffer=0;
-    } 
-  if(longArr) 
-    {
       delete [] longArr;
       longArr=0;
+
     }
 
 }
@@ -275,84 +292,160 @@ void AliTRDarraySignal::Expand()
   // Expand the array
   //
 
-  //Check if the array has not been already expanded
-  Int_t verif=0;
-  for(Int_t i=0; i<fNdim; i++)
+  if(fSignal)
     {
-      if(fSignal[i]<0)
-       {
-         verif++;
-       }
-    }
 
-  if(verif==0)
-    {
-      return;
-    }
+      //Check if the array has not been already expanded
+      Int_t verif=0;
+      for(Int_t i=0; i<fNdim; i++)
+        {
+          if(fSignal[i]<0)
+           {
+             verif++;
+           }
+        }
 
-  Int_t *longArr; 
-  longArr = new Int_t[fNdim];
-  Int_t dimexp=0;
-  memset(longArr,0,sizeof(Int_t)*fNdim);
+      if(verif==0)
+        {
+          return;
+        }
 
-  Int_t r2=0;
-  for(Int_t i=0; i<fNdim;i++)
-    {
-      if(fSignal[i]<0)  
-       {
-         longArr[r2]=(Int_t)(-fSignal[i]); 
-         r2++;
-       }
-    }
+      Int_t dimexp=0;
+      Int_t *longArr = new Int_t[fNdim];
 
-  //Calculate new dimensions
-  for(Int_t i=0; i<fNdim;i++)
-    {
-      if(longArr[i]!=0)      
+      if(longArr)
        {
-         dimexp=dimexp+longArr[i]-1;
-       }
-    }
-  dimexp=dimexp+fNdim;   //Dimension of the expanded array
-
-  //Write in the buffer the new array
-  Float_t* bufferE;
-  bufferE = new Float_t[dimexp];
-  Int_t contaexp =0;    
-  Int_t h=0;
-  for(Int_t i=0; i<dimexp; i++)
-    {
-      if(fSignal[contaexp]>0)  
-       {
-         bufferE[i]=fSignal[contaexp];
-       }
-      if(fSignal[contaexp]<0)  
-       {
-         for(Int_t j=0; j<longArr[h];j++)
+
+          memset(longArr,0,sizeof(Int_t)*fNdim);
+
+          Int_t r2=0;
+          for(Int_t i=0; i<fNdim;i++)
+            {
+              if(fSignal[i]<0)  
+               {
+                 longArr[r2]=(Int_t)(-fSignal[i]); 
+                 r2++;
+               }
+            }
+
+          //Calculate new dimensions
+          for(Int_t i=0; i<fNdim;i++)
+            {
+              if(longArr[i]!=0)      
+               {
+                 dimexp=dimexp+longArr[i]-1;
+               }
+            }
+          dimexp=dimexp+fNdim;   //Dimension of the expanded array
+
+          //Write in the buffer the new array
+          Int_t contaexp =0;    
+          Int_t h=0;
+          Float_t* bufferE = new Float_t[dimexp];
+
+          if(bufferE)
            {
-             bufferE[i+j]=0;
+
+              for(Int_t i=0; i<dimexp; i++)
+                {
+                  if(fSignal[contaexp]>0)  
+                   {
+                     bufferE[i]=fSignal[contaexp];
+                   }
+                  if(fSignal[contaexp]<0)  
+                   {
+                     for(Int_t j=0; j<longArr[h];j++)
+                       {
+                         bufferE[i+j]=0;
+                       }
+                     i=i+longArr[h]-1;
+                     h++;
+                   }
+                  contaexp++;
+                }
+
+              //Copy the buffer
+              delete [] fSignal;
+              fSignal=0;
+              fSignal = new Float_t[dimexp];
+              fNdim = dimexp;
+              for(Int_t i=0; i<dimexp; i++)
+                {
+                  fSignal[i] = bufferE[i]; 
+                }
+
+              delete [] bufferE;
+
            }
-         i=i+longArr[h]-1;
-         h++;
-       }
-      contaexp++;
-    }
 
-  //Copy the buffer
-  if(fSignal)
-    {
-      delete [] fSignal;
-      fSignal=0;
-    }
+          delete [] longArr;
+
+        }
 
-  fSignal = new Float_t[dimexp];
-  fNdim = dimexp;
-  for(Int_t i=0; i<dimexp; i++)
-    {
-      fSignal[i] = bufferE[i]; 
     }
 
-  if(bufferE) delete [] bufferE;
-  if(longArr) delete [] longArr;
+}
+//________________________________________________________________________________
+void AliTRDarraySignal::Reset()
+{
+  //
+  // Reset the array, the old contents are deleted
+  // The array keeps the same dimensions as before
+  //
+
+  memset(fSignal,0,sizeof(Float_t)*fNdim);
 
 }
+//________________________________________________________________________________
+Float_t AliTRDarraySignal::GetData(Int_t nrow, Int_t ncol, Int_t ntime) const
+{
+  //
+  // Get the data using the pad numbering.
+  // To access data using the mcm scheme use instead
+  // the method GetDataByAdcCol
+  //
+
+  Int_t corrcolumn = fgLutPadNumbering[ncol];
+
+  return fSignal[(nrow*fNumberOfChannels+corrcolumn)*fNtime+ntime];
+
+}
+//________________________________________________________________________________
+void AliTRDarraySignal::SetData(Int_t nrow, Int_t ncol, Int_t ntime, Float_t value)
+{
+  //
+  // Set the data using the pad numbering.
+  // To write data using the mcm scheme use instead
+  // the method SetDataByAdcCol
+  //
+
+  Int_t colnumb = fgLutPadNumbering[ncol];
+
+  fSignal[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime]=value;
+
+}
+
+//________________________________________________________________________________
+void AliTRDarraySignal::CreateLut()
+{
+  //
+  // Initializes the Look Up Table to relate
+  // pad numbering and mcm channel numbering
+  //
+
+  if(fgLutPadNumbering)  return;
+  
+   fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
+   memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
+
+  for(Int_t mcm=0; mcm<8; mcm++)
+    {
+      Int_t lowerlimit=0+mcm*18;
+      Int_t upperlimit=18+mcm*18;
+      Int_t shiftposition = 1+3*mcm;
+      for(Int_t index=lowerlimit;index<upperlimit;index++)
+       {
+         fgLutPadNumbering[index]=index+shiftposition;
+       }
+    }
+}