]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALTriggerTRU.cxx
Wrong array dimension fixed
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerTRU.cxx
index a7c33a4354b69e4c9934d21e2707070c792fad18..679e40b93ce6b9190cf7d785766f6c3ed06f7414 100644 (file)
@@ -42,29 +42,43 @@ namespace
 ClassImp(AliEMCALTriggerTRU)
 
 //________________
-AliEMCALTriggerTRU::AliEMCALTriggerTRU() : AliEMCALTriggerBoard()
-,fDCSConfig(0x0)
+AliEMCALTriggerTRU::AliEMCALTriggerTRU() : AliEMCALTriggerBoard(),
+fDCSConfig(0x0),
+fL0Time(0)
 {
-       //
+       // Ctor
+       
        for (Int_t i=0;i<96;i++) for (Int_t j=0;j<256;j++) fADC[i][j] = 0;
 }
 
 //________________
 AliEMCALTriggerTRU::AliEMCALTriggerTRU(AliEMCALTriggerTRUDCSConfig* dcsConf, const TVector2& rSize, Int_t mapType) : 
-AliEMCALTriggerBoard(rSize)
-,fDCSConfig(dcsConf)
+AliEMCALTriggerBoard(rSize),
+fDCSConfig(dcsConf),
+fL0Time(0)
 {
-       //
+       // Ctor
+       
        for (Int_t i=0;i<96;i++) for (Int_t j=0;j<256;j++) fADC[i][j] = 0;
 
-       // FIXME: use of class AliEMCALTriggerParam to get size
        TVector2 size;
        
-       size.Set( 1. , 1. );
-       SetSubRegionSize( size ); // 1 by 1 FOR
-       
-       size.Set( 2. , 2. );
-       SetPatchSize( size );     // 2 by 2 subregions
+       if (dcsConf->GetL0SEL() & 0x0001) // 4-by-4
+       {
+               size.Set( 1. , 1. );
+               SetSubRegionSize( size );
+               
+               size.Set( 2. , 2. );
+               SetPatchSize( size );
+       }       
+       else                              // 2-by-2
+       {
+               size.Set( 1. , 1. );
+               SetSubRegionSize( size );
+               
+               size.Set( 1. , 1. );
+               SetPatchSize( size );   
+       }       
        
        for (Int_t ietam=0;ietam<24;ietam++)
        {
@@ -82,15 +96,14 @@ AliEMCALTriggerBoard(rSize)
 //________________
 AliEMCALTriggerTRU::~AliEMCALTriggerTRU()
 {
-   // delete TRU digits only used as transient containers 
-   // to compute FastOR from energy deposit
-       delete [] fADC;
+       // Dtor
 }
 
 //________________
 void AliEMCALTriggerTRU::ShowFastOR(Int_t iTimeWindow, Int_t iChannel)
 {
-       //
+       // Dump
+       
        Int_t iChanF, iChanL;
        
        if (iChannel != -1) iChanF = iChanL = iChannel;
@@ -120,24 +133,35 @@ void AliEMCALTriggerTRU::ShowFastOR(Int_t iTimeWindow, Int_t iChannel)
 //________________
 Int_t AliEMCALTriggerTRU::L0()
 {
-       // Mimick the TRU L0 'virtual' since not yet released algo
-       
-       // L0 issuing condition is: (2 up & 1 down) AND (time sum > thres)
+       // L0 issuing condition is: (2 up & 1 down) AND (patch sum > thres)
        // fill a matrix to support sliding window
        // compute the time sum for all the FastOR of a given TRU
        // and then move the space window
 
-       AliDebug(1,"=== Running TRU L0 algorithm ===");
+       AliDebug(999,"=== Running TRU L0 algorithm ===");
        const Int_t xsize    = Int_t(fRegionSize->X());
-       Int_t buffer[xsize][xsize][kNup+kNdown];
+       const Int_t ysize    = Int_t(fRegionSize->Y());
+       const Int_t zsize    = kNup+kNdown;
+
+       Int_t ***buffer = new Int_t**[xsize];
+       for (Int_t x = 0; x < xsize; x++)
+       {
+               buffer[x] = new Int_t*[ysize];
+               
+               for (Int_t y = 0; y < ysize; y++)
+               {
+                       buffer[x][y] = new Int_t[zsize];
+               }
+       }
        
-       for (Int_t i=0; i<fRegionSize->X(); i++) for (Int_t j=0; j<fRegionSize->Y(); j++) 
-               for (Int_t k=0; k<kNup+kNdown; k++)     buffer[i][j][k] = 0;
+       for (Int_t i = 0; i < fRegionSize->X(); i++) 
+               for (Int_t j = 0; j < fRegionSize->Y(); j++) 
+                       for (Int_t k = 0; k < kNup + kNdown; k++) buffer[i][j][k] = 0;
                
        // Time sliding window algorithm
        for (Int_t i=0; i<=(kTimeBins-kTimeWindowSize); i++) 
        {
-               AliDebug(1,Form("----------- Time window: %d\n",i));
+               AliDebug(999,Form("----------- Time window: %d\n",i));
                
                for (Int_t j=0; j<fRegionSize->X(); j++)
                {               
@@ -145,7 +169,6 @@ Int_t AliEMCALTriggerTRU::L0()
                        {
                                for (Int_t l=i; l<i+kTimeWindowSize; l++) 
                                {
-//                                     printf("fRegion[%2d][%2d]: %d += fADC[%2d][%2d]: %d\n",j,k,fRegion[j][k],fMap[j][k],l,fADC[fMap[j][k]][l]);
                                        // [eta][phi][time]
                                        fRegion[j][k] += fADC[fMap[j][k]][l];   
                                }
@@ -162,11 +185,6 @@ Int_t AliEMCALTriggerTRU::L0()
                                {
                                        buffer[j][k][i] = fRegion[j][k];
                                }
-
-/*
-                               for (Int_t v = 0; v<kNup + kNdown; v++) 
-                                       printf("buffer[%2d][%2d][%2d]: %d\n",j,k,v,buffer[j][k][v]);
-*/
                                
 //                             if (kTimeWindowSize > 4) fRegion[j][k] = fRegion[j][k] >> 1; // truncate time sum to fit 14b
                        }
@@ -179,7 +197,11 @@ Int_t AliEMCALTriggerTRU::L0()
                        continue; 
                }
                
-               Int_t peaks[xsize][xsize];
+               Int_t **peaks = new Int_t*[xsize];
+               for (Int_t x = 0; x < xsize; x++)
+               {
+                       peaks[x] = new Int_t[ysize];
+               }
                
                for (Int_t j=0; j<fRegionSize->X(); j++) for (Int_t k=0; k<fRegionSize->Y(); k++) peaks[j][k] = 0;
                
@@ -205,18 +227,16 @@ Int_t AliEMCALTriggerTRU::L0()
                        }
                }
 
-/*             
-               for (Int_t j=0; j<fRegionSize->X(); j++)
-               {               
-                       for (Int_t k=0; k<fRegionSize->Y(); k++)
-                       {
-                               printf("peaks[%2d][%2d]: %d\n",j,k,peaks[j][k]);
-                       }
-               }
-*/             
-               if ( !nPeaks )
+               if (!nPeaks)
                {
                        ZeroRegion();
+
+                       for (Int_t x = 0; x < xsize; x++)
+                       {
+                         delete [] peaks[x];
+                       }
+                       delete [] peaks;
+
                        continue;
                }
                
@@ -226,13 +246,11 @@ Int_t AliEMCALTriggerTRU::L0()
                // return the list of patches above threshold
                // Theshold checked out from OCDB
                
-               SlidingWindow( kGamma, fDCSConfig->GetGTHRL0() );
+               SlidingWindow(kL0, fDCSConfig->GetGTHRL0(), i);
                
 //             for(Int_t j=0; j<fRegionSize->X(); j++)
 //                     for (Int_t k=0; k<fRegionSize->Y(); k++) fRegion[j][k] = fRegion[j][k]>>2; // go to 12b before shipping to STU
                
-               Int_t nP = 0;
-               
                for (Int_t j=0; j<fPatches->GetEntriesFast(); j++)
                {
                        AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)fPatches->At( j );
@@ -247,6 +265,8 @@ Int_t AliEMCALTriggerTRU::L0()
                        
                        const Int_t psize =  sizeX * sizeY; // Number of FastOR in the patch
                        
+                       Int_t foundPeak = 0;
+                       
                        Int_t* idx = new Int_t[psize];
                        
                        for (Int_t xx=0;xx<sizeX;xx++) 
@@ -257,41 +277,100 @@ Int_t AliEMCALTriggerTRU::L0()
                                        
                                        idx[index] = fMap[int(v.X()*fSubRegionSize->X())+xx][int(v.Y()*fSubRegionSize->Y())+yy]; // Get current patch FastOR ADC channels 
                                        
-                                       if (peaks[int(v.X()*fSubRegionSize->X())+xx][int(v.Y()*fSubRegionSize->Y())+yy]) nP++;
+                                       if (peaks[int(v.X() * fSubRegionSize->X()) + xx][int(v.Y() * fSubRegionSize->Y()) + yy]) 
+                                       {
+                                               foundPeak++;
+                                               
+                                               p->SetPeak(xx, yy, sizeX, sizeY);
+                                       }
                                        
-                                       if ( AliDebugLevel() ) ShowFastOR(i,idx[index]);
+                                       if (AliDebugLevel() >= 999) ShowFastOR(i, idx[index]);
                                }
                        }
                        
-                       if ( nP ) 
+                       delete [] idx;
+
+                       if ( !foundPeak ) 
                        {
-//                             cout << "break patch loop" << endl;
-                               break;
+                               fPatches->RemoveAt( j );
+                               fPatches->Compress();
                        }
                }
                
-               if ( !nP ) 
-                       fPatches->Delete();
-               else
+               //Delete, avoid leak
+               for (Int_t x = 0; x < xsize; x++)
                {
-//                     cout << "break time loop" << endl;
-                       break;     // Stop the algo when at least one patch is found ( thres & max )
+                       delete [] peaks[x];
                }
-               
-               ZeroRegion();  // Clear fRegion for this time window before computing the next one              
+               delete [] peaks;
+
+               if ( !fPatches->GetEntriesFast() ) // No patch left
+                       ZeroRegion();
+               else                             // Stop the algo when at least one patch is found ( thres & max )
+               {
+                       fL0Time = i;
+                       
+                       for (Int_t xx = 0; xx < fRegionSize->X(); xx++) 
+                       {
+                               for (Int_t yy = 0; yy < fRegionSize->Y(); yy++) 
+                               {   
+                                       // Prepare data to be sent to STU for further L1 processing
+                                       // Sent time sum (rollback tuning) is the one before L0 is issued (maximum time sum)
+                                       fRegion[xx][yy] = buffer[xx][yy][1];
+                               }
+                       }
+                       
+                       break;
+               }               
        }
        
-//     cout << "Nof patches: " << fPatches->GetEntriesFast() << endl;
-               
+       //Delete, avoid leak
+       for (Int_t x = 0; x < xsize; x++)
+       {
+               for (Int_t y = 0; y < ysize; y++)
+               {
+                       delete [] buffer[x][y];
+               }
+               delete [] buffer[x];
+       }
+       delete [] buffer;
+       
        return fPatches->GetEntriesFast();
 }
 
 //________________
 void AliEMCALTriggerTRU::SetADC( Int_t channel, Int_t bin, Int_t sig )
 {
-       //
-       if (channel>95) AliError("TRU has 96 ADC channels only!");
-       fADC[channel][bin] = sig;
+  //Set ADC value
+  if (channel > 95 || bin > 255) {
+    AliError("TRU has 96 ADC channels and 256 bins only!");
+  }
+  else{ 
+    fADC[channel][bin] = sig;
+  }
+}
+
+//________________
+void AliEMCALTriggerTRU::GetL0Region(const int time, Int_t arr[][4])
+{
+       Int_t r0 = time + fDCSConfig->GetRLBKSTU();
+       
+       if (r0 < 0) 
+       {
+               AliError(Form("TRU buffer not accessible! time: %d rollback: %d", time, fDCSConfig->GetRLBKSTU()));
+               return;
+       }
+       
+       for (Int_t i = 0; i < fRegionSize->X(); i++) 
+       {
+               for (Int_t j = 0; j < fRegionSize->Y(); j++) 
+               {
+                       for (Int_t k = r0; k < r0 + kTimeWindowSize; k++)
+                       {
+                               arr[i][j] += fADC[fMap[i][j]][k];
+                       }
+               }
+       }
 }
 
 //________________
@@ -318,7 +397,8 @@ void AliEMCALTriggerTRU::SaveRegionADC(Int_t iTRU, Int_t iEvent)
 //________________
 void AliEMCALTriggerTRU::Reset()
 {
-       //
+       // Reset
+       
        fPatches->Delete();
        
        ZeroRegion();