]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALTriggerElectronics.cxx
Optimisation
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerElectronics.cxx
index cb175b302d958b6b44239c5df46feec4ded46163..9a3ef252af929f0067f7db38fa6e306a551d559d 100644 (file)
@@ -92,12 +92,14 @@ void AliEMCALTriggerElectronics::Digits2Trigger(TClonesArray* digits, const Int_
        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();
        
@@ -165,23 +167,22 @@ void AliEMCALTriggerElectronics::Digits2Trigger(TClonesArray* digits, const Int_
                                        && 
                                        geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py)) p->SetPosition(px, py);
                                
-                               if (!data->GetMode())
+                               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))
                                                {
-                                                       
-                                                       Int_t pos = posMap[px + j % sizeX][py + j / sizeX];
-                                                       
-//                                                     cout << "px: " << px << " py: " << py << " j: " << j << " mod: " << j%sizeX << " ratio: " << j / sizeX << " pos: " << pos << endl;
-                                                       
-                                                       AliEMCALTriggerRawDigit* dig = 0x0;
+                                                       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);
@@ -193,13 +194,27 @@ void AliEMCALTriggerElectronics::Digits2Trigger(TClonesArray* digits, const Int_
                                                        
                                                        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);
-                                               
-               data->SetPatches(kL0, 0, iTRU->Patches());
                }
                else
                        data->SetL0Trigger(0, i, 0);
@@ -240,13 +255,66 @@ void AliEMCALTriggerElectronics::Digits2Trigger(TClonesArray* digits, const Int_
 
                fSTU->L1(kL1Gamma);
                
-               data->SetPatches(kL1Gamma, 0, 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();
 
                fSTU->L1(kL1Jet);
                
-               data->SetPatches(kL1Jet,   0, fSTU->Patches());
+               nP = (fSTU->Patches()).MakeIterator();
+               
+               while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next()) 
+               {                       
+                       p->Position(px, py);
+
+                       px *= (Int_t)((fSTU->SubRegionSize())->X());
+
+                       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();
                
@@ -260,11 +328,8 @@ void AliEMCALTriggerElectronics::Digits2Trigger(TClonesArray* digits, const Int_
                                {
                                        if (reg[i][j])
                                        {
-                                               Int_t id;
                                                if (geom->GetAbsFastORIndexFromPositionInEMCAL(i, j, id))
                                                {
-                                                       AliEMCALTriggerRawDigit* dig = 0x0;
-
                                                        if (posMap[i][j] == -1)
                                                        {
                                                                // Add a new digit with L1 time sum