Re-enable trigger calculation removing STU OCDB access. Improve simulation (L0 time...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerSTU.cxx
index c1c6368..bf1eb1b 100644 (file)
@@ -24,7 +24,7 @@ Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
 #include "AliEMCALTriggerSTU.h"
 #include "AliCDBManager.h"
 #include "AliCDBEntry.h"
-#include "AliEMCALCalibData.h"
+#include "AliEMCALTriggerSTUDCSConfig.h"
 #include "AliVZEROCalibData.h"
 #include "AliVZEROdigit.h"
 #include "AliEMCALTriggerPatch.h"
@@ -45,68 +45,101 @@ ClassImp(AliEMCALTriggerSTU)
 
 //_______________
 AliEMCALTriggerSTU::AliEMCALTriggerSTU() : AliEMCALTriggerBoard()
+,fGammaTh(0)
+,fJetTh(0)
+,fDCSConfig(0x0)
 {
-       //
-       fV0M[0] = fV0M[1] = 0;
+       // Ctor
 }
 
 //_______________
-AliEMCALTriggerSTU::AliEMCALTriggerSTU(AliEMCALCalibData *calibData, const TVector2& RS) : 
-AliEMCALTriggerBoard(calibData, RS)
+AliEMCALTriggerSTU::AliEMCALTriggerSTU(AliEMCALTriggerSTUDCSConfig *dcsConf, const TVector2& RS) : AliEMCALTriggerBoard(RS)
+,fGammaTh(0)
+,fJetTh(0)
+,fDCSConfig(dcsConf)
 {
-       //
-       fV0M[0] = fV0M[1] = 0;
+       // Ctor
 }
 
 //_______________
 AliEMCALTriggerSTU::~AliEMCALTriggerSTU()
 {
-       //
+       // Dtor
 }
 
 //_______________
-void AliEMCALTriggerSTU::BuildMap( Int_t iTRU, Int_t** M, const TVector2* rSize )
+void AliEMCALTriggerSTU::Build( TString& str, Int_t iTRU, Int_t** M, const TVector2* rSize )
 {
-       //
-       if ( iTRU == 31 ) iTRU = 35;
+       // Build
        
-       Int_t i2y = iTRU / 3 / 2;
+       str.ToLower();
        
-       if ( ( iTRU / 3 ) % 2 ) // odd (z<0) C side
-       {
-               Int_t i1y = 2 - ( iTRU - int( iTRU / 3 ) * 3 ); // 0 1 2 w/ increasing phi
+       Int_t ix = (iTRU % 2) ? 24 : 0;
 
-               for (Int_t i=0; i<rSize->X(); i++) 
-                       for (Int_t j=0; j<rSize->Y(); j++) fMap[24+i][j + i1y * 4 + i2y * 12] = M[i][j];
+       Int_t iy =  iTRU / 2;
+       
+       Int_t** v = 0x0;
+       
+       if (str.Contains("map"))
+       {
+               v = fMap;
        }
-       else                   // A side
+       else if (str.Contains("region"))
        {
-               Int_t i1y =       iTRU - int( iTRU / 3 ) * 3;
-               
-               for (Int_t i=0; i<rSize->X(); i++)
-                       for (Int_t j=0; j<rSize->Y(); j++) fMap[   i][j + i1y * 4 + i2y * 12] = M[i][j];
-       }       
+               v = fRegion;
+       }
+       else
+       {
+               AliError("Operation not allowed: STU won't be configured properly!");
+       }
+  
+  if(v){       
+    for (Int_t i=0; i<rSize->X(); i++)
+      for (Int_t j=0; j<rSize->Y(); j++) v[i + ix][j + iy * 4] = M[i][j];
+  }
 }
 
 //_______________
-void AliEMCALTriggerSTU::L1( L1TriggerType_t type )
+void AliEMCALTriggerSTU::L1(TriggerType_t type)
 {
-       //
-       SlidingWindow( type, int(ThresholdFromV0( type )) );    
+       // L1
+       
+       TVector2 s1, s2, s3, s4;
+       fDCSConfig->GetSegmentation(s1, s2, s3, s4);
+       
+       switch (type)
+       {
+               case kL1Gamma:
+                       SetSubRegionSize(s1); 
+                       SetPatchSize(s2);
+                       break;
+               case kL1Jet:
+                       SetSubRegionSize(s3);
+                       SetPatchSize(s4);
+                       break;
+               default:
+                       AliError("Not supported L1 trigger type");
+                       return;
+                       break;
+       }
+       
+       SlidingWindow(type, GetThreshold(type));        
 }
 
 //________________
-void AliEMCALTriggerSTU::PrintADC( L1TriggerType_t type, TVector2& pos, TVector2& idx )
+void AliEMCALTriggerSTU::PrintADC( TriggerType_t type, TVector2& pos, TVector2& idx )
 {
-       //
-        Int_t ix = (Int_t) (( pos.X() + fPatchSize->X() ) * fSubRegionSize->X());
-        Int_t iy = (Int_t) (( pos.Y() + fPatchSize->Y() ) * fSubRegionSize->Y());
+       // Dump
+       
+       Int_t ix = (Int_t) (( pos.X() + fPatchSize->X() ) * fSubRegionSize->X());
+       
+       Int_t iy = (Int_t) (( pos.Y() + fPatchSize->Y() ) * fSubRegionSize->Y());
        
        TString subRegionADC[] = {"0->15", "16->31", "32->47", "48->63", "64->79", "80->95"};
        
        switch ( type )
        {
-               case kGamma:
+               case kL1Gamma:
                {
                        Int_t iTRU = ( (ix-1) < 24 ) ? 31 - int(pos.Y() / 4) : 15 - int(pos.Y() / 4);
                        
@@ -124,13 +157,13 @@ void AliEMCALTriggerSTU::PrintADC( L1TriggerType_t type, TVector2& pos, TVector2
                        cout << endl;
                }       
                break;
-               case kJet:
+               case kL1Jet:
                {
                        //Int_t jTRU = ( (ix-1) < 24 ) ? 31 - (iy-1) / 4 : 15 - (iy-1) / 4;
                        
                        printf("jet found at row : %d and col : %d",int(idx.X()),int(idx.Y()));
                        
-                       Char_t* vPair = 0x0;
+                       Char_t vPair[100];
                        Int_t nSubRegion = 0;
                        
                        for (Int_t i=(Int_t)(pos.X() * fSubRegionSize->X());i<ix;i++) 
@@ -153,8 +186,6 @@ void AliEMCALTriggerSTU::PrintADC( L1TriggerType_t type, TVector2& pos, TVector2
                                        if (!isFound) 
                                        {       
                                                nSubRegion++;
-                                               vPair = (Char_t*)realloc(vPair, nSubRegion * sizeof(Char_t));
-                                               if (vPair == NULL) {AliError("Error (re)allocating PrintADC() memory");}
                                                
                                                vPair[nSubRegion-1] = value;
                                        }
@@ -168,7 +199,6 @@ void AliEMCALTriggerSTU::PrintADC( L1TriggerType_t type, TVector2& pos, TVector2
                        }
                
                        cout << endl;
-                       if (vPair) delete[] vPair;
                }
                break;
                default:
@@ -176,84 +206,11 @@ void AliEMCALTriggerSTU::PrintADC( L1TriggerType_t type, TVector2& pos, TVector2
        }
 }
 
-//________________
-void AliEMCALTriggerSTU::V0Multiplicity( TTree& treeV0 )
-{  
-       //
-    AliCDBManager *man = AliCDBManager::Instance();
-    AliCDBEntry *entry = man->Get("VZERO/Calib/Data");
-    AliVZEROCalibData *calibdata = (AliVZEROCalibData*)entry->GetObject();
-       
-    TClonesArray* digitsArray = 0x0;
-    treeV0.SetBranchAddress("VZERODigit",&digitsArray);
-
-       Float_t mult[64];
-       Short_t  adc[64];
-   
-       for (Int_t i=0; i<64; i++)
-       {
-               adc[i]    = 0;
-               mult[i]   = 0.0;
-       }
-
-       Int_t nEntries = (Int_t)treeV0.GetEntries();
-
-       for (Int_t e=0; e<nEntries; e++) 
-       {
-               treeV0.GetEvent(e);
-
-               Int_t nDigits = digitsArray->GetEntriesFast();
-          
-               for (Int_t d=0; d<nDigits; d++) 
-               {    
-                       AliVZEROdigit* digit = (AliVZEROdigit*)digitsArray->At(d);      
-                       Int_t  pmNumber      = digit->PMNumber();
-                       
-                       if (adc[pmNumber] > (int(1.0/calibdata->GetMIPperADC(pmNumber)) /2) ) 
-                               mult[pmNumber] += float(adc[pmNumber])*calibdata->GetMIPperADC(pmNumber);
-               }
-       }
-  
-       //  0..31 V0C 
-       // 32..63 V0A
-       for (Int_t j=0; j<32; j++) 
-       {
-               fV0M[0] += short(mult[j   ]+0.5); 
-               fV0M[1] += short(mult[j+32]+0.5); 
-       }
-}
-
-//________________
-void AliEMCALTriggerSTU::FetchFOR( Int_t iTRU, Int_t **R, const TVector2* rSize )
-{
-       // L1 triggers run over the whole EMCal surface
-       // STU builds its own fRegion aggregating TRU fRegion into one 
-       
-       // STU I from TRUs O in Olivier's coordinate system
-       
-       if ( iTRU == 31 ) iTRU = 35;
-               
-       Int_t i2y = iTRU / 3 / 2;       
-       
-       if ( ( iTRU / 3 ) % 2 ) // C side odd (z<0)
-       {
-               Int_t i1y = 2 - ( iTRU - int( iTRU / 3 ) * 3 ); // 0 1 2 w/ increasing phi
-               
-               for (Int_t i=0; i<rSize->X(); i++)                                            //  0:23 0:4 
-                       for (Int_t j=0; j<rSize->Y(); j++) fRegion[24+i][j + i1y * 4 + i2y * 12] = R[i][j];
-       }
-       else                    // A side
-       {
-               Int_t i1y =       iTRU - int( iTRU / 3 ) * 3;
-               
-               for (Int_t i=0; i<rSize->X(); i++)
-                       for (Int_t j=0; j<rSize->Y(); j++) fRegion[   i][j + i1y * 4 + i2y * 12] = R[i][j];
-       }
-}
-
 //___________
 void AliEMCALTriggerSTU::PatchGenerator(const TClonesArray* lpos, Int_t val)
 {
+       // Patch generator
+       
        ZeroRegion();
        
        Int_t vTRU[32][24][4] ;//= {0};
@@ -322,27 +279,87 @@ void AliEMCALTriggerSTU::PatchGenerator(const TClonesArray* lpos, Int_t val)
 }
 
 //___________
-Float_t AliEMCALTriggerSTU::ThresholdFromV0( L1TriggerType_t type )
+void AliEMCALTriggerSTU::ComputeThFromV0(TriggerType_t type, const Int_t M[])
+{
+       // Compute threshold from V0
+       
+       Short_t P[3] = {0};
+       
+       switch (type)
+       {
+               case kL1Gamma:
+                       P[0] = fDCSConfig->GetGA();
+                       P[1] = fDCSConfig->GetGB();
+                       P[2] = fDCSConfig->GetGC();                     
+                       break;
+               case kL1Jet:
+                       P[0] = fDCSConfig->GetJA();
+                       P[1] = fDCSConfig->GetJB();
+                       P[2] = fDCSConfig->GetJC();                     
+                       break;
+               default:
+                       AliError("AliEMCALTriggerSTU::ComputeThFromV0(): Undefined trigger type, pls check!");
+                       return;
+       }
+       
+       ULong64_t v0sum = M[0] + M[1];
+       
+       ULong64_t sqrV0 = v0sum * v0sum;
+       
+       sqrV0 *= P[0];  
+       sqrV0 >>= 32;
+       
+       v0sum *= P[1];
+       
+       v0sum >>= 16;
+       
+       SetThreshold(type, (UShort_t)(sqrV0 + v0sum + P[2]));
+}
+
+//___________
+void AliEMCALTriggerSTU::SetThreshold(TriggerType_t type, Int_t v)
+{
+       // Set threshold
+       
+       switch (type)
+       {
+               case kL1Gamma:
+                       fGammaTh = v;
+                       break;
+               case kL1Jet:
+                       fJetTh = v;             
+                       break;
+               default:
+                       AliError("AliEMCALTriggerSTU::SetThreshold(): Undefined trigger type, pls check!");
+       }
+}
+
+//___________
+Int_t AliEMCALTriggerSTU::GetThreshold(TriggerType_t type)
 {      
        // Compute threshold FIXME: need an access to the OCDB
        // to get f(V0) parameters depending on trigger type
        
-       switch ( type )
+       
+       switch (type)
        {
-               case kGamma:
+               case kL1Gamma:
+                       return fGammaTh;
                        break;
-               case kJet:
-//                     return 15.;
+               case kL1Jet:
+                       return fJetTh;          
                        break;
                default:
-                       AliError("AliEMCALTriggerSTU::ThresholdFromV0(): Undefined trigger type, pls check!");
+                       AliError("AliEMCALTriggerSTU::GetThreshold(): Undefined trigger type, pls check!");
        }
        
-       return 0.;
+       return 0;
 }
 
 //__________
 void AliEMCALTriggerSTU::Reset()
 {
+       // Reset
+       
        fPatches->Delete();
 }