]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALTriggerElectronics.cxx
Fix for #91510: Reconstruction able to deal with different triggers
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerElectronics.cxx
index aecd8296ca88059fd0d533171bf39eaf425ca3f0..fa0183247e623f14f041d070d1168a00287ecbee 100644 (file)
@@ -36,9 +36,9 @@ Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
 #include "AliEMCALDigit.h"
 #include "AliEMCALTriggerRawDigit.h"
 #include "AliEMCALTriggerPatch.h"
+#include "AliEMCALTriggerSTUDCSConfig.h"
 
 #include <TVector2.h>
-#include <TClonesArray.h>
 
 namespace
 {
@@ -52,6 +52,8 @@ AliEMCALTriggerElectronics::AliEMCALTriggerElectronics(const AliEMCALTriggerDCSC
 fTRU(new TClonesArray("AliEMCALTriggerTRU",32)),
 fSTU(0x0)
 {
+       // Ctor
+       
        TVector2 rSize;
        
        rSize.Set( 24.,  4. );
@@ -80,7 +82,8 @@ fSTU(0x0)
 //________________
 AliEMCALTriggerElectronics::~AliEMCALTriggerElectronics()
 {
-       //
+       // Dtor
+       
        fTRU->Delete();
        delete fSTU;
 }
@@ -88,7 +91,8 @@ AliEMCALTriggerElectronics::~AliEMCALTriggerElectronics()
 //__________________
 void AliEMCALTriggerElectronics::Digits2Trigger(TClonesArray* digits, const Int_t V0M[], AliEMCALTriggerData* data)
 {
-       //
+       // Digits to trigger
+
        AliEMCALGeometry* geom = 0x0;
        
        AliRunLoader *rl = AliRunLoader::Instance();
@@ -101,7 +105,7 @@ void AliEMCALTriggerElectronics::Digits2Trigger(TClonesArray* digits, const Int_
        
        if(!geom) AliError("Cannot access geometry!");
        
-       //      digits->Sort();
+       Int_t pos, px, py, id; 
        
        Int_t region[48][64], posMap[48][64];
        for (Int_t i = 0; i < 48; i++) for (Int_t j = 0; j < 64; j++) 
@@ -114,12 +118,14 @@ void AliEMCALTriggerElectronics::Digits2Trigger(TClonesArray* digits, const Int_
        {
                AliEMCALTriggerRawDigit* digit = (AliEMCALTriggerRawDigit*)digits->At(i);
                
-               Int_t id = digit->GetId();
+               id = digit->GetId();
                
                Int_t iTRU, iADC;
                
                Bool_t isOK1 = geom->GetTRUFromAbsFastORIndex(id, iTRU, iADC);
                
+               if ((isOK1 && iTRU >= kNTRU) || !isOK1) continue;
+
                for (Int_t j = 0; j < digit->GetNSamples(); j++)
                {
                        Int_t time, amp;
@@ -128,225 +134,235 @@ void AliEMCALTriggerElectronics::Digits2Trigger(TClonesArray* digits, const Int_
                        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;
-                       
-                       if (fSTU->GetRawData() && digit->GetL1TimeSum() >= 0) 
-                       {
-                               region[px][py] = digit->GetL1TimeSum();
-                       }
-               }
+               if (geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py)) posMap[px][py] = i;
        }
 
        Int_t iL0 = 0;
 
+       Int_t timeL0[kNTRU] = {0}, timeL0min = 999;
+       
        for (Int_t i=0; i<kNTRU; i++) 
        {
                AliDebug(999, Form("===========< TRU %2d >============\n", i));
                
                AliEMCALTriggerTRU* iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
-
-               // L0 is always computed from F-ALTRO
-               if (iTRU->L0()) 
+               
+               if (iTRU->L0()) // L0 recomputation: *ALWAYS* done from FALTRO
                {
-                       iL0 += iTRU->L0();
+                       iL0++;
+                       
+                       timeL0[i] = iTRU->GetL0Time();
                        
-                       Int_t sizeX = (Int_t) ((iTRU->PatchSize())->X() * (iTRU->SubRegionSize())->X());
+                       if (!timeL0[i]) AliWarning(Form("TRU# %d has 0 trigger time",i));
                        
-                       Int_t sizeY = (Int_t) ((iTRU->PatchSize())->Y() * (iTRU->SubRegionSize())->Y());
+                       if (timeL0[i] < timeL0min) timeL0min = timeL0[i];
+                       
+                       data->SetL0Trigger(0, i, 1); // TRU# i has issued a L0
+               }
+               else
+                       data->SetL0Trigger(0, i, 0);
+       }
+
+       AliDebug(999, Form("=== %2d TRU (out of %2d) has issued a L0 / Min L0 time: %d\n", iL0, kNTRU, timeL0min));
+       
+       AliEMCALTriggerRawDigit* dig = 0x0;
+       
+       if (iL0 && (!data->GetMode() || !fSTU->GetDCSConfig()->GetRawData())) 
+       {
+               // Update digits after L0 calculation
+               for (Int_t i = 0; i < kNTRU; i++)
+               {
+                       AliEMCALTriggerTRU *iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
+
+                       Int_t reg[24][4];
+                       for (int j = 0; j < 24; j++) for (int k = 0; k < 4; k++) reg[j][k] = 0;
+                                       
+                       iTRU->GetL0Region(timeL0min, reg);
                        
+                       for (int j = 0; j < iTRU->RegionSize()->X(); j++)
+                       {
+                               for (int k = 0; k < iTRU->RegionSize()->Y(); k++)
+                               {
+                                       if (reg[j][k]
+                                                       && 
+                                                       geom->GetAbsFastORIndexFromPositionInTRU(i, j, k, id)
+                                                       &&
+                                                       geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py))
+                                       {
+                                               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->SetL1TimeSum(reg[j][k]);
+                                       }
+                               }
+                       }
+               }
+       }
+
+       if (iL0 && !data->GetMode())
+       {
                        // transform local to global 
-                       TIter Next(&iTRU->Patches());
-                       while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)Next())
+               
+               for (Int_t i = 0; i < kNTRU; i++)
+               {
+                       AliEMCALTriggerTRU* iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
+                       
+                       TIter next(&iTRU->Patches());
+                       while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)next())
                        {
-                               Int_t px, py, id; p->Position(px, py);
+                               p->Position(px, py);
+                       
+                       // Local 2 Global       
+                               if (geom->GetAbsFastORIndexFromPositionInTRU(i, px, py, id) && 
+                                                               geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py)) p->SetPosition(px, py);
                                
-                               if (geom->GetAbsFastORIndexFromPositionInTRU(i, px, py, id) 
-                                       && 
-                                       geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py)) p->SetPosition(px, py);
+                               Int_t peaks = p->Peaks();
                                
-                               if (!data->GetMode()) // Simulation
-                               {
-                                       Int_t peaks = p->Peaks();
+                               Int_t sizeX = (Int_t) ((iTRU->PatchSize())->X() * (iTRU->SubRegionSize())->X());
+                               Int_t sizeY = (Int_t) ((iTRU->PatchSize())->Y() * (iTRU->SubRegionSize())->Y());
                                        
-                                       Int_t pos;
-                                       AliEMCALTriggerRawDigit* dig = 0x0;
-                                       
-                                       for (Int_t j = 0; j < sizeX * sizeY; j++)
+                               for (Int_t j = 0; j < sizeX * sizeY; j++)
+                               {
+                                       if (peaks & (1 << j))
                                        {
-                                               if (peaks & (1 << j))
-                                               {
-                                                       pos = posMap[px + j % sizeX][py + j / sizeX];
+                                               pos = posMap[px + j % sizeX][py + j / sizeX];
                                                        
-                                                       if (pos == -1)
-                                                       {
+                                               if (pos == -1)
+                                               {
                                                                // Add a new digit
-                                                               new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
+                                                       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());
+                                                       dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
+                                               }
+                                               else
+                                               {
+                                                       dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
                                                }
+                                                       
+                                               dig->SetL0Time(timeL0min);
                                        }
+                               }
                                        
-                                       pos = posMap[px][py];
+                               pos = posMap[px][py];
                                        
-                                       if (pos == -1)
-                                       {
+                               if (pos == -1)
+                               {
                                                // Add a new digit
-                                               new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
+                                       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);
+                                       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
-       // 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) 
+       
+       //
+       // Prepare STU for L1 calculation
+       
+       for (int i = 0; i < (fSTU->RegionSize())->X(); i++)
        {
-               // Use L1 threshold from raw data when reconstructing raw data
-               if (data->GetMode())
+               for (int j = 0; j < (fSTU->RegionSize())->Y(); j++)
                {
-                       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)  );
-               }
+                       pos = posMap[i][j];
                
-               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());
+                       if (pos >= 0) 
+                       {
+                               AliEMCALTriggerRawDigit *digit = (AliEMCALTriggerRawDigit*)digits->At(pos);
+               
+                               if (digit->GetL1TimeSum() > -1) region[i][j] = digit->GetL1TimeSum();
+                       }
                }
+       }
+       
+       fSTU->SetRegion(region);
+       
+       if (data->GetMode()) 
+       {
+               fSTU->SetThreshold(kL1Gamma, data->GetL1GammaThreshold());
+               fSTU->SetThreshold(kL1Jet,   data->GetL1JetThreshold()  );
+       }
+       else
+       {
+               fSTU->ComputeThFromV0(kL1Gamma, V0M); 
+               data->SetL1GammaThreshold( fSTU->GetThreshold(kL1Gamma));
+               fSTU->ComputeThFromV0(kL1Jet,   V0M);
+               data->SetL1JetThreshold(   fSTU->GetThreshold(kL1Jet)  );
+       }
 
-               fSTU->L1(kL1Gamma);
+       fSTU->L1(kL1Gamma);
                
-               Int_t id, px, py;
-               AliEMCALTriggerRawDigit* dig = 0x0;
+       TIterator* nP = 0x0;
                
-               TIterator* nP = 0x0;
-               
-               nP = (fSTU->Patches()).MakeIterator();
-               
-               while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next()) 
-               {                       
-                       p->Position(px, py);
+       nP = (fSTU->Patches()).MakeIterator();
+       
+       while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next()) 
+       {                       
+               p->Position(px, py);
                        
-                       if (geom->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
+               if (geom->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
+               {
+                       if (posMap[px][py] == -1)
                        {
-                               if (posMap[px][py] == -1)
-                               {
                                        // Add a new digit
-                                       new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
+                               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);
+                               dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
+                       } 
+                       else
+                       {
+                               dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[px][py]);                                                             
                        }
+                               
+                       dig->SetTriggerBit(kL1Gamma,0);
                }
+       }
 
-               fSTU->Reset();
+       fSTU->Reset();
 
-               fSTU->L1(kL1Jet);
+       fSTU->L1(kL1Jet);
                
-               nP = (fSTU->Patches()).MakeIterator();
-               
-               while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next()) 
-               {                       
-                       p->Position(px, py);
+       nP = (fSTU->Patches()).MakeIterator();
+                       
+       while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next()) 
+       {                       
+               p->Position(px, py);
 
-                       px *= (Int_t)((fSTU->SubRegionSize())->X());
+               px *= (Int_t)((fSTU->SubRegionSize())->X());
 
-                       py *= (Int_t)((fSTU->SubRegionSize())->Y());
+               py *= (Int_t)((fSTU->SubRegionSize())->Y());
                        
-                       if (geom->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
+               if (geom->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
+               {
+                       if (posMap[px][py] == -1)
                        {
-                               if (posMap[px][py] == -1)
-                               {
                                        // Add a new digit
-                                       new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
+                               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++)
+                               dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
+                       } 
+                       else
                        {
-                               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]);
-                                               }
-                                       }
-                               }
+                               dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[px][py]);
                        }
+                               
+                       dig->SetTriggerBit(kL1Jet, 0);
                }
        }
 
@@ -359,9 +375,10 @@ void AliEMCALTriggerElectronics::Digits2Trigger(TClonesArray* digits, const Int_
 //__________________
 void AliEMCALTriggerElectronics::Reset()
 {
-       //
-       TIter NextTRU(fTRU);
-       while ( AliEMCALTriggerTRU *TRU = (AliEMCALTriggerTRU*)NextTRU() ) TRU->Reset();
+       // Reset
+       
+       TIter nextTRU(fTRU);
+       while ( AliEMCALTriggerTRU *TRU = (AliEMCALTriggerTRU*)nextTRU() ) TRU->Reset();
        
        fSTU->Reset();
 }