]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALTriggerElectronics.cxx
Optimisation
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerElectronics.cxx
index e78c6b010b618326c2ea2a31772f4010c0eb4f31..9a3ef252af929f0067f7db38fa6e306a551d559d 100644 (file)
@@ -28,17 +28,17 @@ Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
 #include "AliRunLoader.h"
 #include "AliEMCAL.h" 
 #include "AliRun.h" 
+#include "AliEMCALTriggerDCSConfig.h"
 #include "AliEMCALTriggerData.h"
 #include "AliEMCALDigit.h"
 #include "AliCaloRawStreamV3.h"
-//#include "AliVZERORawStream.h"
 #include "AliEMCALTriggerSTURawStream.h"
 #include "AliEMCALDigit.h"
-#include "AliEMCALRawDigit.h"
+#include "AliEMCALTriggerRawDigit.h"
+#include "AliEMCALTriggerPatch.h"
 
 #include <TVector2.h>
 #include <TClonesArray.h>
-//#include <Riostream.h>
 
 namespace
 {
@@ -48,7 +48,7 @@ namespace
 ClassImp(AliEMCALTriggerElectronics)
 
 //__________________
-AliEMCALTriggerElectronics::AliEMCALTriggerElectronics(AliEMCALCalibData *calibData) : TObject(),
+AliEMCALTriggerElectronics::AliEMCALTriggerElectronics(const AliEMCALTriggerDCSConfig *dcsConf) : TObject(),
 fTRU(new TClonesArray("AliEMCALTriggerTRU",32)),
 fSTU(0x0)
 {
@@ -57,17 +57,24 @@ fSTU(0x0)
        rSize.Set( 24.,  4. );
 
        // 32 TRUs
-       for (Int_t i=0;i<kNTRU;i++) new ((*fTRU)[i]) AliEMCALTriggerTRU(calibData, rSize, int(i/3) % 2);
-   
+       for (Int_t i=0;i<kNTRU;i++) 
+       {
+               AliEMCALTriggerTRUDCSConfig* truConf = dcsConf->GetTRUDCSConfig(i);
+               new ((*fTRU)[i]) AliEMCALTriggerTRU(truConf, rSize, i % 2);
+       }
+       
        rSize.Set( 48., 64. );
        
        // 1 STU
-       fSTU = new AliEMCALTriggerSTU(calibData, rSize);
+       AliEMCALTriggerSTUDCSConfig* stuConf = dcsConf->GetSTUDCSConfig();
+       fSTU = new AliEMCALTriggerSTU(stuConf, rSize);
        
-       for (Int_t i=0;i<kNTRU;i++) fSTU->BuildMap( i, 
-                                                                                         (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->Map(), 
-                                                                                         (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->RegionSize() 
-                                                                                         );
+       TString str = "map";
+       for (Int_t i=0;i<kNTRU;i++) fSTU->Build(str,
+                                                                                       i,
+                                                                                       (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->Map(),
+                                                                                       (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->RegionSize() 
+                                                                                   );
 }
 
 //________________
@@ -79,130 +86,272 @@ AliEMCALTriggerElectronics::~AliEMCALTriggerElectronics()
 }
 
 //__________________
-void AliEMCALTriggerElectronics::Digits2Trigger(const TClonesArray* digits, const TTree* treeV0, AliEMCALTriggerData* data)
+void AliEMCALTriggerElectronics::Digits2Trigger(TClonesArray* digits, const Int_t V0M[], AliEMCALTriggerData* data)
 {
        //
        AliEMCALGeometry* geom = 0x0;
        
        AliRunLoader *rl = AliRunLoader::Instance();
-       if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL"))
-               geom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
-       else 
-               geom =  AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
-
-       if (!geom) AliError("Cannot access geometry!");
+       if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")){
+         AliEMCAL* emcal = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"));
+         if(emcal)geom = emcal->GetGeometry();
+       }
+       
+       if(!geom) geom =  AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
+       
+       if(!geom) AliError("Cannot access geometry!");
+       
+       //      digits->Sort();
+       
+       Int_t region[48][64], posMap[48][64];
+       for (Int_t i = 0; i < 48; i++) for (Int_t j = 0; j < 64; j++) 
+       {
+               region[i][j] =  0;
+               posMap[i][j] = -1;
+       }
        
-       TIter NextDigit(digits);
-       while (AliEMCALRawDigit* digit = (AliEMCALRawDigit*)NextDigit())
+       for (Int_t i = 0; i < digits->GetEntriesFast(); i++)
        {
-               if ( digit )
+               AliEMCALTriggerRawDigit* digit = (AliEMCALTriggerRawDigit*)digits->At(i);
+               
+               Int_t id = digit->GetId();
+               
+               Int_t iTRU, iADC;
+               
+               Bool_t isOK1 = geom->GetTRUFromAbsFastORIndex(id, iTRU, iADC);
+               
+               for (Int_t j = 0; j < digit->GetNSamples(); j++)
                {
-                       Int_t id = digit->GetId();
-                       
-//                     digit->Print();
+                       Int_t time, amp;
+                       Bool_t isOK2 = digit->GetTimeSample(j, time, amp);
                        
-                       Int_t iTRU, iADC;
-                       Bool_t isOK1 = geom->GetTRUFromAbsFastORIndex(id, iTRU, iADC);
+                       if (isOK1 && isOK2 && amp) (static_cast<AliEMCALTriggerTRU*>(fTRU->At(iTRU)))->SetADC(iADC, time, amp);
+               }
+               
+               Int_t px, py;
+               if (geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py))
+               {
+                       posMap[px][py] = i;
                        
-                       for (Int_t i = 0; i < digit->GetNSamples(); i++)
+                       if (fSTU->GetRawData() && digit->GetL1TimeSum() >= 0) 
                        {
-                               Int_t time, amp;
-                               Bool_t isOK2 = digit->GetTimeSample(i, time, amp);
-                               
-                               if (isOK1 && isOK2 && amp) (static_cast<AliEMCALTriggerTRU*>(fTRU->At(iTRU)))->SetADC(iADC, time, amp);
+                               region[px][py] = digit->GetL1TimeSum();
                        }
                }
        }
-       /*
-       for (Int_t i=0; i<kNTRU; i++) 
-       {
-               printf("===========< TRU %2d >============\n",i);
-               (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->Scan();
-       }
-       */
-       Int_t iL0 = 0;
 
-       // At this point all FastOR are available for digitization
-       // digitization is done in the TRU and produces time samples
-       // Now run the trigger algo & consecutively write trigger outputs in TreeD dedicated branch
+       Int_t iL0 = 0;
 
        for (Int_t i=0; i<kNTRU; i++) 
        {
-               AliDebug(1,Form("===========< TRU %2d >============\n",i));
+               AliDebug(999, Form("===========< TRU %2d >============\n", i));
                
-               AliEMCALTriggerTRU *iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
-
-               iL0 += iTRU->L0v1();
-
-               Int_t vL0Peaks[96][2]; iTRU->Peaks( vL0Peaks );
-                       
-               data->SetL0Patches( i , iTRU->Patches() );                      
-               data->SetL0Peaks(   i , vL0Peaks );
+               AliEMCALTriggerTRU* iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
 
-               if ( !i ) // do it once since identical for all TRU 
+               // L0 is always computed from F-ALTRO
+               if (iTRU->L0()) 
                {
-                       data->SetL0RegionSize(    *iTRU->RegionSize()    );
-                       data->SetL0SubRegionSize( *iTRU->SubRegionSize() );
-               data->SetL0PatchSize(     *iTRU->PatchSize()     );
-               } 
-               
-               //              if ( i == 31 ) i = 35;
-               //
-               //              if ( ( i / 3 ) % 2 ) {
-               //                      TRU->Print( 15 - 2 + ( i - int( i / 3 ) * 3 ) - 3 * ( (i / 3) / 2 ) , runLoader->GetEventNumber() );
-               //                      printf("print data of TRU: from %2d to %2d\n",i,15 - 2 + ( i - int( i / 3 ) * 3 ) - 3 * ( (i / 3) / 2));
-               //              }
-               //              else
-               //              {
-               //                      TRU->Print( 31 - i % 3 - 3 * ( (i / 3) / 2 ) , runLoader->GetEventNumber() );
-               //                      printf("print data of TRU: from %2d to %2d\n",i,31 - i % 3 - 3 * ( (i / 3) / 2 ));
-               //              }               
+                       iL0 += iTRU->L0();
+                       
+                       Int_t sizeX = (Int_t) ((iTRU->PatchSize())->X() * (iTRU->SubRegionSize())->X());
+                       
+                       Int_t sizeY = (Int_t) ((iTRU->PatchSize())->Y() * (iTRU->SubRegionSize())->Y());
+                       
+                       // transform local to global 
+                       TIter Next(&iTRU->Patches());
+                       while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)Next())
+                       {
+                               Int_t px, py, id; p->Position(px, py);
+                               
+                               if (geom->GetAbsFastORIndexFromPositionInTRU(i, px, py, id) 
+                                       && 
+                                       geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py)) p->SetPosition(px, py);
+                               
+                               if (!data->GetMode()) // Simulation
+                               {
+                                       Int_t peaks = p->Peaks();
+                                       
+                                       Int_t pos;
+                                       AliEMCALTriggerRawDigit* dig = 0x0;
+                                       
+                                       for (Int_t j = 0; j < sizeX * sizeY; j++)
+                                       {
+                                               if (peaks & (1 << j))
+                                               {
+                                                       pos = posMap[px + j % sizeX][py + j / sizeX];
+                                                       
+                                                       if (pos == -1)
+                                                       {
+                                                               // Add a new digit
+                                                               new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
+                                                               
+                                                               dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
+                                                       }
+                                                       else
+                                                       {
+                                                               dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
+                                                       }
+                                                       
+                                                       dig->SetL0Time(p->Time());
+                                               }
+                                       }
+                                       
+                                       pos = posMap[px][py];
+                                       
+                                       if (pos == -1)
+                                       {
+                                               // Add a new digit
+                                               new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
+                                               
+                                               dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
+                                       }
+                                       else
+                                       {
+                                               dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
+                                       }
+                                       
+                                       dig->SetTriggerBit(kL0,0);
+                               }
+                       }
+                       
+                       data->SetL0Trigger(0, i, 1);
+               }
+               else
+                       data->SetL0Trigger(0, i, 0);
        }
 
        // A L0 has been issued, run L1
-       if ( iL0 ) 
+       // Depending on raw data enabled or not in STU data: L1 computation 
+       // should be done from F-ALTRO or directly on TRU time sums in STU raw data
+       if (iL0) 
        {
-               for (Int_t i=0; i<kNTRU; i++) fSTU->FetchFOR( i, 
-                                                                                                   (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->Region(), 
-                                                                                                   (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->RegionSize() 
-                                                                                                   );
-
-//             fSTU->Scan();
+               // Use L1 threshold from raw data when reconstructing raw data
+               if (data->GetMode())
+               {
+                       fSTU->SetThreshold(kL1Gamma, data->GetL1GammaThreshold());
+                       fSTU->SetThreshold(kL1Jet,   data->GetL1JetThreshold()  );                      
+               }
+               else
+               {
+                       fSTU->ComputeThFromV0(V0M); // C/A
+                       data->SetL1GammaThreshold(fSTU->GetThreshold(kL1Gamma));
+                       data->SetL1JetThreshold(  fSTU->GetThreshold(kL1Jet)  );
+               }
                
-               TTree* tr = const_cast<TTree*>(treeV0);
-               if ( tr ) fSTU->V0Multiplicity( *tr );
-
-               TVector2 size;
+               if (fSTU->GetRawData())
+               {
+                       // Compute L1 from STU raw data
+                       fSTU->SetRegion(region);
+               }
+               else
+               {
+                       // Build STU raw data from F-ALTRO
+                       TString str = "region";
+                       for (Int_t i = 0; i < kNTRU; i++) fSTU->Build(str,
+                                                                                                                 i, 
+                                                                                                                 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->Region(), 
+                                                                                                                 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->RegionSize());
+               }
 
-               size.Set( 1. , 1. );
-               fSTU->SetSubRegionSize( size ); data->SetL1GammaSubRegionSize( size );
+               fSTU->L1(kL1Gamma);
                
-               size.Set( 2. , 2. );
-               fSTU->SetPatchSize( size );     data->SetL1GammaPatchSize(     size );
-
-               fSTU->L1( kGamma );
-
-               data->SetL1GammaPatches(       fSTU->Patches()       );
+               Int_t id, px, py;
+               AliEMCALTriggerRawDigit* dig = 0x0;
+               
+               TIterator* nP = 0x0;
+               
+               nP = (fSTU->Patches()).MakeIterator();
+               
+               while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next()) 
+               {                       
+                       p->Position(px, py);
+                       
+                       if (geom->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
+                       {
+                               if (posMap[px][py] == -1)
+                               {
+                                       // Add a new digit
+                                       new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
+                                       
+                                       dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
+                               } 
+                               else
+                               {
+                                       dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[px][py]);                                                             
+                               }
+                               
+                               dig->SetTriggerBit(kL1Gamma,0);
+                       }
+               }
 
                fSTU->Reset();
 
-               size.Set( 4. , 4. ); 
-               fSTU->SetSubRegionSize( size ); data->SetL1JetSubRegionSize( size );
+               fSTU->L1(kL1Jet);
                
-               size.Set( 2. , 2. ); 
-               fSTU->SetPatchSize( size );     data->SetL1JetPatchSize(     size );
-
-               fSTU->L1( kJet );
+               nP = (fSTU->Patches()).MakeIterator();
+               
+               while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next()) 
+               {                       
+                       p->Position(px, py);
 
-               data->SetL1JetPatches(         fSTU->Patches()       );
-               data->SetL1RegionSize(        *fSTU->RegionSize()    );
+                       px *= (Int_t)((fSTU->SubRegionSize())->X());
 
-               Int_t** region = fSTU->Region();
-               data->SetL1Region(      region      );
-               const Int_t* mv0 = fSTU->V0(); 
-               data->SetL1V0(          mv0         );
+                       py *= (Int_t)((fSTU->SubRegionSize())->Y());
+                       
+                       if (geom->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
+                       {
+                               if (posMap[px][py] == -1)
+                               {
+                                       // Add a new digit
+                                       new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
+                                       
+                                       dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
+                               } 
+                               else
+                               {
+                                       dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[px][py]);                                                             
+                               }
+                               
+                               dig->SetTriggerBit(kL1Jet,0);
+                       }
+               }
+               
+               Int_t** reg = fSTU->Region();
+               
+               if (!fSTU->GetRawData())
+               {
+                       // Update digits w/ L1 time sum
+                       // Done in raw digit maker when raw data enabled
+                       for (Int_t i = 0; i < 48; i++)
+                       {
+                               for (Int_t j = 0; j < 64; j++)
+                               {
+                                       if (reg[i][j])
+                                       {
+                                               if (geom->GetAbsFastORIndexFromPositionInEMCAL(i, j, id))
+                                               {
+                                                       if (posMap[i][j] == -1)
+                                                       {
+                                                               // Add a new digit with L1 time sum
+                                                               new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
+                                                               
+                                                               dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
+                                                       } 
+                                                       else
+                                                       {
+                                                               dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[i][j]);                                                               
+                                                       }
+                                                       
+                                                       dig->SetL1TimeSum(reg[i][j]);
+                                               }
+                                       }
+                               }
+                       }
+               }
        }
 
+       if (AliDebugLevel() >= 999) data->Scan();
+       
        // Now reset the electronics for a fresh start with next event
        Reset();
 }