Re-enable trigger calculation removing STU OCDB access. Improve simulation (L0 time...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerRawDigitMaker.cxx
index 1218843559cfd76a98d82c30859f81ea434597f4..0dee4f20fa348d62205b7555a7e263d27337b8dc 100644 (file)
@@ -32,6 +32,9 @@ Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
 #include "AliCaloBunchInfo.h"
 #include "AliRawReader.h"
 #include "AliEMCALTriggerDCSConfigDB.h"
+#include "AliEMCALTriggerDCSConfig.h"
+#include "AliEMCALTriggerTRUDCSConfig.h"
+#include "AliEMCALTriggerSTUDCSConfig.h"
 #include "AliEMCALTriggerData.h"
 #include "AliEMCALTriggerPatch.h"
 #include "AliLog.h"
@@ -43,6 +46,10 @@ Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
 #include "AliRawVEquipment.h"
 #include "AliRawEquipmentHeader.h"
 
+#include "Riostream.h"
+
+#include "AliCaloRawAnalyzerFactory.h"
+
 namespace
 {
        const Int_t kSTUEqId = 4652;
@@ -61,22 +68,27 @@ fRawAnalyzer(0x0),
 fDCSConfig(0x0),
 fTriggerData(0x0)
 {
-       // def ctor
-       
-       AliRunLoader* rl = AliRunLoader::Instance();
-       if (rl && rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")) 
-               fGeometry = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
-       else 
-       {
-               AliDebug(1, Form("Using default geometry"));
-               fGeometry =  AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
-       }
-       
-       fRawAnalyzer = new AliCaloRawAnalyzerFakeALTRO();
-       
-       fDCSConfig = AliEMCALTriggerDCSConfigDB::Instance();
-       
-       for (Int_t i=0; i<3072; i++) fRawDigitIndex[i] = -1;
+  // def ctor
+  
+  AliRunLoader* rl = AliRunLoader::Instance();
+  if (rl && rl->GetAliRun()){
+    AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"));
+    if(emcal) fGeometry = emcal->GetGeometry();
+  }
+  
+  if(!fGeometry)
+    {
+      AliDebug(1, Form("Using default geometry"));
+      fGeometry =  AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
+    }
+  
+  //  fRawAnalyzer = new AliCaloRawAnalyzerFakeALTRO ();
+  
+  fRawAnalyzer =  (AliCaloRawAnalyzerFakeALTRO*)AliCaloRawAnalyzerFactory::CreateAnalyzer(kFakeAltro);
+
+  fDCSConfig = AliEMCALTriggerDCSConfigDB::Instance();
+  
+  for (Int_t i=0; i<3072; i++) fRawDigitIndex[i] = -1;
 }      
 
 //_______________
@@ -88,7 +100,8 @@ AliEMCALTriggerRawDigitMaker::~AliEMCALTriggerRawDigitMaker()
 //_______________
 void AliEMCALTriggerRawDigitMaker::SetIO(AliRawReader* reader, AliCaloRawStreamV3& in, AliEMCALTriggerSTURawStream& inSTU, TClonesArray* digits, AliEMCALTriggerData* data)
 {
-       //
+       // Connect I/O
+       
        fRawReader     = reader;
        fCaloRawStream = &in;
        fRawDigits     = digits;
@@ -99,7 +112,8 @@ void AliEMCALTriggerRawDigitMaker::SetIO(AliRawReader* reader, AliCaloRawStreamV
 //_______________
 void AliEMCALTriggerRawDigitMaker::Add(const std::vector<AliCaloBunchInfo> &bunchlist)
 {
-       //
+       // Add bunch list
+       
        Int_t    hwAdd   = fCaloRawStream->GetHWAddress();
        UShort_t iRCU    = fCaloRawStream->GetDDLNumber() % 2; // 0/1
        UShort_t iBranch = ( hwAdd >> 11 ) & 0x1;              // 0/1
@@ -187,7 +201,7 @@ void AliEMCALTriggerRawDigitMaker::Add(const std::vector<AliCaloBunchInfo> &bunc
                                                }
                                                else
                                                {
-                                                       AliError("L0: Trying to update trigger info of a non-existent digit!");
+                                                       AliDebug(100,"L0: Trying to update trigger info of a non-existent digit!");
                                                        
                                                        fRawDigitIndex[idx] = fRawDigits->GetEntriesFast();
                                                        new((*fRawDigits)[fRawDigits->GetEntriesFast()]) AliEMCALTriggerRawDigit(idx, 0x0, 0);
@@ -195,7 +209,6 @@ void AliEMCALTriggerRawDigitMaker::Add(const std::vector<AliCaloBunchInfo> &bunc
                                                        dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
                                                }
                                                
-                                               dig->SetL0Trigger(1);
                                                dig->SetL0Time(iBin);
                                        }
                                }
@@ -269,42 +282,76 @@ void AliEMCALTriggerRawDigitMaker::Add(const std::vector<AliCaloBunchInfo> &bunc
 //_______________
 void AliEMCALTriggerRawDigitMaker::PostProcess()
 {      
-       //
+       // Post process digits
+       
+        AliDebug(2,"Start post processing the raw digit maker");
        Int_t idx;
        
        AliEMCALTriggerRawDigit* dig = 0x0;
        
-       Int_t sizeL1gsubr[2], sizeL1gpatch[2], sizeL1jsubr[2], sizeL1jpatch[2];
+       TVector2 sizeL1gsubr, sizeL1gpatch, sizeL1jsubr, sizeL1jpatch;
        
-       fDCSConfig->GetSTUSegmentation(sizeL1gsubr, sizeL1gpatch, sizeL1jsubr, sizeL1jpatch);
+       fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->GetSegmentation(sizeL1gsubr, sizeL1gpatch, sizeL1jsubr, sizeL1jpatch);
        
        fRawReader->Reset();
        fRawReader->Select("EMCAL",44); 
 
-       Bool_t STUin = kFALSE;
+       Bool_t isSTUin = kFALSE;
        
        Int_t nSubEv = fRawReader->GetEvent()->GetNSubEvents();
        
        for ( Int_t iSubEv=0; iSubEv<nSubEv; iSubEv++)
        {
-               AliRawVEvent *SubEv = ((AliRawEvent*)fRawReader->GetEvent())->GetSubEvent(iSubEv);
-               if ( !SubEv ) continue;
+               AliRawVEvent *subEv = ((AliRawEvent*)fRawReader->GetEvent())->GetSubEvent(iSubEv);
+               if ( !subEv ) continue;
                
-               for (Int_t iEquip = 0; iEquip < SubEv->GetNEquipments(); iEquip++)
+               for (Int_t iEquip = 0; iEquip < subEv->GetNEquipments(); iEquip++)
                {
-                       Int_t eqId = SubEv->GetEquipment(iEquip)->GetEquipmentHeader()->GetId();
+                       Int_t eqId = subEv->GetEquipment(iEquip)->GetEquipmentHeader()->GetId();
                        
-                       if (eqId == kSTUEqId) STUin = kTRUE;
+                       if (eqId == kSTUEqId) isSTUin = kTRUE;
                }
        }
        
        fRawReader->Reset();
        
-       if (STUin && fSTURawStream && fSTURawStream->ReadPayLoad())
+       if (isSTUin && fSTURawStream && fSTURawStream->ReadPayLoad())
        {
+               fTriggerData->SetL1DataDecoded(1);
+               
                fTriggerData->SetL1GammaThreshold(fSTURawStream->GetL1GammaThreshold());
                fTriggerData->SetL1JetThreshold(  fSTURawStream->GetL1JetThreshold()  );
                
+               Int_t v0[2] = {fSTURawStream->GetV0A(), fSTURawStream->GetV0C()};
+               
+               Int_t type[8] = 
+               {
+                       fSTURawStream->GetGA(),
+                       fSTURawStream->GetGB(),
+                       fSTURawStream->GetGC(),
+                       fSTURawStream->GetJA(),
+                       fSTURawStream->GetJB(),
+                       fSTURawStream->GetJC(),
+                       fSTURawStream->GetRegionEnable(), 
+                       fSTURawStream->GetFwVersion()
+               };              
+
+               // Modify DCS config from STU payload content
+               fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetGA(type[0]);
+               fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetGB(type[1]);
+               fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetGC(type[2]);
+               fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetJA(type[3]);
+               fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetJB(type[4]);
+               fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetJC(type[5]);
+               fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetFw(type[7]);
+               fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetRawData(fSTURawStream->GetRawData());
+               
+               fTriggerData->SetL1FrameMask(fSTURawStream->GetFrameReceived());
+               fTriggerData->SetL1V0(v0);
+               fTriggerData->SetL1TriggerType(type);
+               
+               fTriggerData->SetL1RawData(fSTURawStream->GetRawData());
+               
                Int_t iTRU, x, y;
 
                if (fSTURawStream->GetRawData())
@@ -318,11 +365,9 @@ void AliEMCALTriggerRawDigitMaker::PostProcess()
                                UInt_t adc[96]; for (Int_t j = 0; j < 96; j++) adc[j] = 0;
                                
                                fSTURawStream->GetADC(i, adc);
-                               
+
                                for (Int_t j = 0; j < 96; j++)
                                {
-                                       if (adc[j] < 5) continue;
-                                       
                                        if (AliDebugLevel()) printf("| STU => TRU# %2d raw data: ADC# %2d: %d\n", iTRU, j, adc[j]);
                                        
                                        fGeometry->GetAbsFastORIndexFromTRU(iTRU, j, idx);
@@ -331,60 +376,67 @@ void AliEMCALTriggerRawDigitMaker::PostProcess()
                                        {
                                                dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
                                                
-                                               if (!dig->GetNSamples())
-                                                       AliWarning(Form("TRG digit of id: %4d found in STU but has 0 sample in F-ALTRO!",idx));
-                                                       
-                                               dig->SetL1TimeSum(adc[j]);
+                                               if (!dig->GetNSamples()) AliDebug(10,Form("TRG digit of id: %4d found in STU but has no time sample in F-ALTRO!",idx));
                                        }
                                        else
                                        {
-                                               AliWarning(Form("TRG digit of id: %4d found in STU but not in F-ALTRO! Create a new digit!",idx));
+                                               AliDebug(10,Form("TRG digit of id: %4d found in STU but not in F-ALTRO! Create a new digit!",idx));
                                                
                                                fRawDigitIndex[idx] = fRawDigits->GetEntriesFast();
                                                new((*fRawDigits)[fRawDigits->GetEntriesFast()]) AliEMCALTriggerRawDigit(idx, 0x0, 0);
                                                
                                                dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
-                                               dig->SetL1TimeSum(adc[j]);
                                        }
+                                       
+                                       dig->SetL1TimeSum(adc[j]);
                                }
                        }
                }
                
                // List of patches in EMCal coordinate system
-               TClonesArray* patches = new TClonesArray("AliEMCALTriggerPatch", 96);
                
                for (Int_t i = 0; i < fSTURawStream->GetNL0GammaPatch(); i++)
                {
                        fSTURawStream->GetL0GammaPatch(i, iTRU, x);
-                       
+
                        iTRU = fGeometry->GetTRUIndexFromSTUIndex(iTRU);
                        
-                       if (AliDebugLevel()) printf("| STU => Found L0 patch id: %2d in TRU# %2d\n", x, iTRU);
-                       
-                       const Int_t sizePatchL0 = fDCSConfig->GetTRUSegmentation(i) * fDCSConfig->GetTRUSegmentation(i);
-                       
-                       Int_t* idFastOR = new Int_t[sizePatchL0]; 
+                       const Int_t sizePatchL0 = 
+                       ((AliEMCALTriggerTRUDCSConfig*)fDCSConfig->GetTriggerDCSConfig()->GetTRUArr()->At(fGeometry->GetOnlineIndexFromTRUIndex(iTRU)))->GetSegmentation() 
+                       * 
+                       ((AliEMCALTriggerTRUDCSConfig*)fDCSConfig->GetTriggerDCSConfig()->GetTRUArr()->At(fGeometry->GetOnlineIndexFromTRUIndex(iTRU)))->GetSegmentation();
                        
-                       for (Int_t j = 0; j < sizePatchL0; i++) idFastOR[j] = -1;
+                       if (AliDebugLevel()) printf("| STU => Found L0 patch id: %2d in TRU# %2d\n", x, iTRU);
+                                               
+                       Int_t idFastOR[4];
+                       for (Int_t j = 0; j < 4; j++) idFastOR[j] = -1;
                        
                        if (fGeometry->GetFastORIndexFromL0Index(iTRU, x, idFastOR, sizePatchL0))
                        {
+                               idx = idFastOR[1];
+                               
                                Int_t px, py;
-                               if (fGeometry->GetPositionInEMCALFromAbsFastORIndex(idFastOR[1], px, py))
+                               if (fGeometry->GetPositionInEMCALFromAbsFastORIndex(idx, px, py))
                                {
-                                       new((*patches)[patches->GetEntriesFast()]) AliEMCALTriggerPatch(px, py);
-                                       
                                        if (AliDebugLevel()) printf("| STU => Add L0 patch at (%2d , %2d)\n", px, py);
+                                                                               
+                                       if (fRawDigitIndex[idx] >= 0)
+                                       {
+                                               dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
+                                       }
+                                       else
+                                       {
+                                               fRawDigitIndex[idx] = fRawDigits->GetEntriesFast();
+                                               new((*fRawDigits)[fRawDigits->GetEntriesFast()]) AliEMCALTriggerRawDigit(idx, 0x0, 0);
+                       
+                                               dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
+                                       }
+               
+                                       dig->SetTriggerBit(kL0,1);
                                }
                        }
-                       
-                       delete [] idFastOR;
                }
                
-               fTriggerData->SetPatches(kL0, 1, *patches);                     
-               
-               patches->Delete();
-               
                for (Int_t i = 0; i < fSTURawStream->GetNL1GammaPatch(); i++)
                {
                        if (fSTURawStream->GetL1GammaPatch(i, iTRU, x, y)) // col (0..23), row (0..3)
@@ -397,20 +449,31 @@ void AliEMCALTriggerRawDigitMaker::PostProcess()
                                
                                if (iTRU % 2) vx += 24; // C side
                                
-                               vx = vx - sizeL1gsubr[0] * sizeL1gpatch[0] + 1;
-                               
-                               if (vx >= 0) 
+                               vx = vx - int(sizeL1gsubr.X()) * int(sizeL1gpatch.X()) + 1;
+
+                               if (vx >= 0 && vy < 63
                                {
-                                       new((*patches)[patches->GetEntriesFast()]) AliEMCALTriggerPatch(vx, vy);
-                                       
+                                       if (fGeometry->GetAbsFastORIndexFromPositionInEMCAL(vx, vy, idx))
+                                       {
                                        if (AliDebugLevel()) printf("| STU => Add L1 gamma patch at (%2d , %2d)\n", vx, vy);
+                                               
+                                               if (fRawDigitIndex[idx] >= 0)
+                                               {
+                                                       dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
                                }
-                       }
-               }
+                                               else
+                                               {
+                                                       fRawDigitIndex[idx] = fRawDigits->GetEntriesFast();
+                                                       new((*fRawDigits)[fRawDigits->GetEntriesFast()]) AliEMCALTriggerRawDigit(idx, 0x0, 0);
 
-               fTriggerData->SetPatches(kL1Gamma, 1, *patches);                        
+                                                       dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
+                                               }
                
-               patches->Delete();
+                                               dig->SetTriggerBit(kL1Gamma,1);
+                                       }
+                               }
+                       }
+               }
                
                for (Int_t i = 0; i < fSTURawStream->GetNL1JetPatch(); i++)
                {
@@ -418,33 +481,43 @@ void AliEMCALTriggerRawDigitMaker::PostProcess()
                        {
                                if (AliDebugLevel()) printf("| STU => Found L1 jet patch at (%2d , %2d)\n", x, y);
                                
-                               Int_t ix = sizeL1jsubr[0] * (11 - y - sizeL1jpatch[0] + 1);
-
-                               Int_t iy = sizeL1jsubr[1] * (15 - x - sizeL1jpatch[1] + 1);
+                               Int_t ix = int(sizeL1jsubr.X()) * (11 - y - int(sizeL1jpatch.X()) + 1);
+                               
+                               Int_t iy = int(sizeL1jsubr.Y()) * (15 - x - int(sizeL1jpatch.Y()) + 1);
                                
                                // FIXME: x = 0 || y = 0 (Olivier's CS) patches a lost?
                                
                                if (ix >= 0 && iy >= 0)
                                {       
-                                       new((*patches)[patches->GetEntriesFast()]) AliEMCALTriggerPatch(ix, iy);
-                                       
+                                       if (fGeometry->GetAbsFastORIndexFromPositionInEMCAL(ix, iy, idx))
+                                       {
                                        if (AliDebugLevel()) printf("| STU => Add L1 jet patch at (%2d , %2d)\n", ix, iy);
-                               }
-                       }
-               }
                
-               fTriggerData->SetPatches(kL1Jet, 1, *patches);                  
+                                               if (fRawDigitIndex[idx] >= 0)
+                                               {
+                                                       dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
+                                               }
+                                               else
+                                               {
+                                                       fRawDigitIndex[idx] = fRawDigits->GetEntriesFast();
+                                                       new((*fRawDigits)[fRawDigits->GetEntriesFast()]) AliEMCALTriggerRawDigit(idx, 0x0, 0);
                
-               patches->Delete();
+                                                       dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
+                                               }
                
-               delete patches;
+                                               dig->SetTriggerBit(kL1Jet,1);
+                                       }
+                               }
+                       }
+               }               
        }
 }
 
 //_______________
 void AliEMCALTriggerRawDigitMaker::Reset()
 {
-       //      
+       // Reset
+       
        for (Int_t i = 0; i < 3072; i++) fRawDigitIndex[i] = -1;
 }