]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliAnalysisTaskSE.cxx
ANALYSIS and ANALYSIScalib
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskSE.cxx
index d1a5ad3bde39631fb11b2efef85567fcbf27d27e..34b2610d606ba91e64034ccedfb2858ee3ef2685 100644 (file)
@@ -33,6 +33,8 @@
 #include "AliESD.h"
 #include "AliAODEvent.h"
 #include "AliAODHeader.h"
+#include "AliAODVZERO.h"
+#include "AliTOFHeader.h"
 #include "AliAODTracklets.h"
 #include "AliAODCaloCells.h"
 #include "AliAODCaloTrigger.h"
@@ -53,7 +55,9 @@
 ClassImp(AliAnalysisTaskSE)
 
 ////////////////////////////////////////////////////////////////////////
-AliAODHeader*    AliAnalysisTaskSE::fgAODHeader         = NULL;
+AliVHeader*      AliAnalysisTaskSE::fgAODHeader         = NULL;
+AliTOFHeader*    AliAnalysisTaskSE::fgTOFHeader         = NULL;
+AliAODVZERO*     AliAnalysisTaskSE::fgAODVZERO          = NULL;
 TClonesArray*    AliAnalysisTaskSE::fgAODTracks         = NULL;
 TClonesArray*    AliAnalysisTaskSE::fgAODVertices       = NULL;
 TClonesArray*    AliAnalysisTaskSE::fgAODV0s            = NULL;
@@ -68,6 +72,7 @@ AliAODCaloCells* AliAnalysisTaskSE::fgAODPhosCells      = NULL;
 AliAODCaloTrigger* AliAnalysisTaskSE::fgAODEMCALTrigger = NULL;
 AliAODCaloTrigger* AliAnalysisTaskSE::fgAODPHOSTrigger  = NULL;
 TClonesArray*    AliAnalysisTaskSE::fgAODDimuons        = NULL;
+TClonesArray*    AliAnalysisTaskSE::fgAODHmpidRings     = NULL;
 
 AliAnalysisTaskSE::AliAnalysisTaskSE():
     AliAnalysisTask(),
@@ -143,6 +148,9 @@ AliAnalysisTaskSE::AliAnalysisTaskSE(const AliAnalysisTaskSE& obj):
 AliAnalysisTaskSE& AliAnalysisTaskSE::operator=(const AliAnalysisTaskSE& other)
 {
 // Assignment
+  if(&other == this) return *this;
+  AliAnalysisTask::operator=(other);
+
     AliAnalysisTask::operator=(other);
     fDebug            = other.fDebug;
     fEntry            = other.fEntry;
@@ -169,8 +177,8 @@ void AliAnalysisTaskSE::ConnectInputData(Option_t* /*option*/)
    // Connect input handlers (multi input handler is handled)
     ConnectMultiHandler();
     
-    if (fInputHandler) {
-       if ((fInputHandler->GetTree())->GetBranch("ESDfriend."))
+    if (fInputHandler && fInputHandler->GetTree()) {
+       if (fInputHandler->GetTree()->GetBranch("ESDfriend."))
            fESDfriend = ((AliESDInputHandler*)fInputHandler)->GetESDfriend();
 
        fInputEvent = fInputHandler->GetEvent();
@@ -211,6 +219,19 @@ void AliAnalysisTaskSE::CreateOutputObjects()
                 fgAODHeader = new AliAODHeader;
                 handler->AddBranch("AliAODHeader", &fgAODHeader);
                }
+            if ((handler->NeedsTOFHeaderReplication() || merging) && !(fgTOFHeader))
+                {
+                 if (fDebug > 1) AliInfo("Replicating TOFheader");
+                 fgTOFHeader = new AliTOFHeader;
+                 handler->AddBranch("AliTOFHeader", &fgTOFHeader);
+                }
+            if ((handler->NeedsVZEROReplication() || merging) && !(fgAODVZERO))
+                {
+                 if (fDebug > 1) AliInfo("Replicating VZERO");
+                 fgAODVZERO = new AliAODVZERO;
+                 handler->AddBranch("AliAODVZERO", &fgAODVZERO);
+                }
+
            if ((handler->NeedsTracksBranchReplication() || merging) && !(fgAODTracks))      
            {   
                if (fDebug > 1) AliInfo("Replicating track branch\n");
@@ -291,13 +312,21 @@ void AliAnalysisTaskSE::CreateOutputObjects()
                fgAODMCParticles->SetName("mcparticles");
                handler->AddBranch("TClonesArray", &fgAODMCParticles);
            }
-           if ((handler->NeedsDimuonsBranchReplication() || merging) && !(fgAODDimuons))      
+            if ((handler->NeedsDimuonsBranchReplication() || merging) && !(fgAODDimuons))      
            {   
                if (fDebug > 1) AliInfo("Replicating dimuon branch\n");
                fgAODDimuons = new TClonesArray("AliAODDimuon",0);
                fgAODDimuons->SetName("dimuons");
                handler->AddBranch("TClonesArray", &fgAODDimuons);
            }    
+           if ((handler->NeedsHMPIDBranchReplication() || merging) && !(fgAODHmpidRings))      
+           {   
+               if (fDebug > 1) AliInfo("Replicating HMPID branch\n");
+               fgAODHmpidRings = new TClonesArray("AliAODHMPIDrings",0);
+               fgAODHmpidRings->SetName("hmpidRings");
+               handler->AddBranch("TClonesArray", &fgAODHmpidRings);
+           }
+                
 
            // cache the pointerd in the AODEvent
            fOutputAOD->GetStdContent();
@@ -312,16 +341,19 @@ void AliAnalysisTaskSE::Exec(Option_t* option)
 {
 //
 // Exec analysis of one event
-
+    
     ConnectMultiHandler();
-
+    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+    if (mgr->GetDebugLevel() > 1) {
+       if (!mgr->GetTopTasks()->FindObject(this))
+          printf("    -> Executing sub-task %s\n", GetName());
+    }   
     if ( fDebug >= 10)
       printf("Task is active %5d\n", IsActive());
     
     if (fDebug > 1) AliInfo("AliAnalysisTaskSE::Exec() \n");
 //
-    AliAODHandler* handler = dynamic_cast<AliAODHandler*> 
-       ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
+    AliAODHandler* handler = dynamic_cast<AliAODHandler*>(mgr->GetOutputEventHandler());
 
     AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
 //
@@ -331,52 +363,43 @@ void AliAnalysisTaskSE::Exec(Option_t* option)
       // Get the actual offline trigger mask for the event and AND it with the
       // requested mask. If no mask requested select by default the event.
       if (fOfflineTriggerMask)
-         isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
+       isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
     }
 //  Functionality below moved in the filter tasks (AG)
 //    if (handler) handler->SetFillAOD(isSelected);
 
     if( fInputHandler ) {
-       fEntry = fInputHandler->GetReadEntry();
-       fESDfriend = ((AliESDInputHandler*)fInputHandler)->GetESDfriend();
+      fEntry = fInputHandler->GetReadEntry();
+      fESDfriend = ((AliESDInputHandler*)fInputHandler)->GetESDfriend();
     }
     
 
-// Notify the change of run number
+    // Notify the change of run number
     if (InputEvent() && (InputEvent()->GetRunNumber() != fCurrentRunNumber)) {
        fCurrentRunNumber = InputEvent()->GetRunNumber();
        NotifyRun();
-    }    
-          
-    else if( fMCEvent )
-       fEntry = fMCEvent->Header()->GetEvent(); 
-    if ( !((Entry()-1)%100) && fDebug > 0) 
-         AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
+    } else if( fMCEvent )
+      fEntry = fMCEvent->Header()->GetEvent(); 
 
+    if ( !((Entry()-1)%100) && fDebug > 0) 
+      AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
     
-    
+    if (aodH) fMCEvent = aodH->MCEvent();
 
     if (handler && aodH) {
-       fMCEvent = aodH->MCEvent();
        Bool_t merging = aodH->GetMergeEvents();
-      
-  // Do not analyze merged events if last embedded file has less events than normal event, 
-  // skip analysis after last embeded event 
-  if(merging){
-    if(aodH->GetReadEntry() + aodH->GetMergeOffset() >= aodH->GetTreeToMerge()->GetEntriesFast()){
-      //printf("Skip Entry %lld, Offset %d, Tree Entries %d\n",aodH->GetReadEntry(),aodH->GetMergeOffset(), aodH->GetTreeToMerge()->GetEntries());
-          
-      // Do I need to add the lines before the return?
-      // Added protection in case the derived task is not an AOD producer.
-      AliAnalysisDataSlot *out0 = GetOutputSlot(0);
-      if (out0 && out0->IsConnected()) PostData(0, fTreeA);    
-          
-      DisconnectMultiHandler();
-          
-      return;
-    }
-    //else   printf("MERGE Entry %lld, Offset %d, Tree Entries %d\n",aodH->GetReadEntry(),aodH->GetMergeOffset(), aodH->GetTreeToMerge()->GetEntries());
-  }
+       // Do not analyze merged events if last embedded file has less events than normal event, 
+       // skip analysis after last embeded event 
+       if(merging){
+         if(aodH->GetReadEntry() + aodH->GetMergeOffset() >= aodH->GetTreeToMerge()->GetEntriesFast()){
+           // Do I need to add the lines before the return?
+           // Added protection in case the derived task is not an AOD producer.
+           AliAnalysisDataSlot *out0 = GetOutputSlot(0);
+           if (out0 && out0->IsConnected()) PostData(0, fTreeA);    
+           DisconnectMultiHandler();
+           return;
+         }
+       }
       
        AliAODEvent* aod = dynamic_cast<AliAODEvent*>(InputEvent());
 
@@ -386,6 +409,15 @@ void AliAnalysisTaskSE::Exec(Option_t* option)
              // copy the contents by assigment
              *fgAODHeader =  *(aod->GetHeader());
            }
+            if ((handler->NeedsTOFHeaderReplication() || merging) && (fgTOFHeader))
+            {
+              if (aod->GetTOFHeader()) *fgTOFHeader =  *(aod->GetTOFHeader());
+            }
+            if ((handler->NeedsVZEROReplication() || merging) && (fgAODVZERO) && aod->GetVZEROData())
+            {
+              *fgAODVZERO = *(aod->GetVZEROData());
+            }
+
            if ((handler->NeedsTracksBranchReplication() || (merging &&  aodH->GetMergeTracks())) && (fgAODTracks))
            {
                TClonesArray* tracks = aod->GetTracks();
@@ -466,6 +498,14 @@ void AliAnalysisTaskSE::Exec(Option_t* option)
                    }    
                }
            }
+            if ((handler->NeedsHMPIDBranchReplication()) && (fgAODHmpidRings))
+           {
+               TClonesArray* hmpidRings = aod->GetHMPIDrings();
+               new (fgAODHmpidRings) TClonesArray(*hmpidRings);
+           }
+            
+            
+            
            // Additional merging if needed
            if (merging) {
              Int_t nc;
@@ -516,125 +556,200 @@ void AliAnalysisTaskSE::Exec(Option_t* option)
 
                // EMCAL cells
                //*fgAODEmcalCells =  *(aod->GetEMCALCells()); // This will be valid after 10.Mar.2011.
-               if(aodH->GetMergeEMCALCells()) {
+               if(aodH->GetMergeEMCALCells()) 
+                 {
                    AliAODCaloCells* copycells = aod->GetEMCALCells();
                    fgAODEmcalCells->CreateContainer(copycells->GetNumberOfCells());
                    nc  = copycells->GetNumberOfCells();
-                   while( nc-- ){ fgAODEmcalCells->SetCell(nc,copycells->GetCellNumber(nc),copycells->GetAmplitude(nc)); }
-
+                   
+                   while( nc-- ){ fgAODEmcalCells->SetCell(nc,copycells->GetCellNumber(nc),copycells->GetAmplitude(nc),
+                                                           copycells->GetTime(nc),copycells->GetMCLabel(nc),copycells->GetEFraction(nc)); }
+                   
                    AliAODCaloCells* cellsA = aodH->GetEventToMerge()->GetEMCALCells();
-                   if( cellsA ){
+                   if( cellsA )
+                     {
                        Int_t ncells  = cellsA->GetNumberOfCells();
                        nc = fgAODEmcalCells->GetNumberOfCells();
-                       for (Int_t i  = 0; i < ncells; i++) {
+                       
+                       for (Int_t i  = 0; i < ncells; i++) 
+                         {
                            Int_t cn  = cellsA->GetCellNumber(i);
                            Int_t pos = fgAODEmcalCells->GetCellPosition(cn);
-                           if (pos >= 0) {
+                           
+                           if (pos >= 0) 
+                             {
                                Double_t amp = cellsA->GetAmplitude(i) + fgAODEmcalCells->GetAmplitude(pos);
-                               fgAODEmcalCells->SetCell(pos, cn, amp);
-                           } else {
+                               
+                               //Check if it is MC, depending on that assing the mc lable, time and e fraction
+//                             Double_t time    = 0;
+                               Int_t    mclabel =-1;
+                               Double_t efrac   = 0;
+                               if(cellsA->GetMCLabel(i) >= 0 && fgAODEmcalCells->GetMCLabel(pos) < 0)
+                                 {
+                                   mclabel = cellsA->GetMCLabel(i) ;
+//                                 time    = fgAODEmcalCells->GetTime(pos) ; // Time from data
+                                   if(amp > 0) efrac = cellsA->GetAmplitude(i) / amp;
+                                 }
+                               else if(fgAODEmcalCells->GetMCLabel(pos) >= 0 &&  cellsA->GetMCLabel(i) < 0)
+                                 {
+                                   mclabel = fgAODEmcalCells->GetMCLabel(pos) ;
+//                                 time    = cellsA->GetTime(i) ; // Time from data
+                                   if(amp > 0) efrac = fgAODEmcalCells->GetAmplitude(pos) / amp;
+                                 }
+                               else 
+                                 { // take all from input
+                                   mclabel = cellsA->GetMCLabel(i) ;
+//                                 time    = cellsA->GetTime(i) ; 
+                                   if(amp > 0) efrac = cellsA->GetAmplitude(i) / amp;  
+                                 }
+                               
+                               fgAODEmcalCells->SetCell(pos, cn, amp,cellsA->GetTime(i),mclabel,efrac);
+                               
+                             } else 
+                             {
                                AliAODCaloCells* copycells1 = new AliAODCaloCells(*fgAODEmcalCells);
                                fgAODEmcalCells->CreateContainer(nc+1);
                                Int_t nn = copycells1->GetNumberOfCells();
-                               while( nn-- ){ fgAODEmcalCells->SetCell(nn,copycells1->GetCellNumber(nn),copycells1->GetAmplitude(nn)); }
-                               fgAODEmcalCells->SetCell(nc++,cn,cellsA->GetAmplitude(i));
+                               
+                               while( nn-- ){ fgAODEmcalCells->SetCell(nn,copycells1->GetCellNumber(nn),copycells1->GetAmplitude(nn),
+                                                                       copycells1->GetTime(nn),copycells1->GetMCLabel(nn),copycells1->GetEFraction(nn)); }
+                               
+                               fgAODEmcalCells->SetCell(nc++,cn,cellsA->GetAmplitude(i),cellsA->GetTime(i), cellsA->GetMCLabel(i),1.);
+                               
                                delete copycells1;
-                           }
-                       }
+                             }
+                         }
                        fgAODEmcalCells->Sort();
-                   }
-               } // merge emcal cells
+                     }
+                 } // merge emcal cells
                
                
                // PHOS cells
                //*fgAODPhosCells =  *(aod->GetPHOSCells()); // This will be valid after 10.Mar.2011.
-               if(aodH->GetMergePHOSCells()) {
+               if(aodH->GetMergePHOSCells()) 
+                 {
                    AliAODCaloCells* copycells = aod->GetPHOSCells();
                    fgAODPhosCells->CreateContainer(copycells->GetNumberOfCells());
                    nc  = copycells->GetNumberOfCells();
-                   while( nc-- ){ fgAODPhosCells->SetCell(nc,copycells->GetCellNumber(nc),copycells->GetAmplitude(nc)); }
+                   
+                   while( nc-- ){ fgAODPhosCells->SetCell(nc,copycells->GetCellNumber(nc),copycells->GetAmplitude(nc),
+                                                          copycells->GetTime(nc),copycells->GetMCLabel(nc),copycells->GetEFraction(nc)); }
+                   
                    AliAODCaloCells* cellsP = aodH->GetEventToMerge()->GetPHOSCells();
-                   if( cellsP ){
+                   if( cellsP )
+                     {
                        Int_t ncellsP  = cellsP->GetNumberOfCells();
                        nc = fgAODPhosCells->GetNumberOfCells();
                        
-                       for (Int_t i  = 0; i < ncellsP; i++) {
+                       for (Int_t i  = 0; i < ncellsP; i++) 
+                         {
                            Int_t cn  = cellsP->GetCellNumber(i);
                            Int_t pos = fgAODPhosCells->GetCellPosition(cn);
-                           if (pos >= 0) {
+                           
+                           if (pos >= 0) 
+                             {
                                Double_t amp = cellsP->GetAmplitude(i) + fgAODPhosCells->GetAmplitude(pos);
-                               fgAODPhosCells->SetCell(pos, cn, amp);
-                           } else {
+                               
+                               //Check if it is MC, depending on that assing the mc lable, time and e fraction
+//                             Double_t time    = 0;
+                               Int_t    mclabel =-1;
+                               Double_t    efrac   = 0;
+                               if(cellsP->GetMCLabel(i) >= 0 && fgAODPhosCells->GetMCLabel(pos) < 0)
+                                 {
+                                   mclabel = cellsP->GetMCLabel(i) ;
+//                                 time    = fgAODPhosCells->GetTime(pos) ; // Time from data
+                                   if(amp > 0) efrac = cellsP->GetAmplitude(i) / amp;
+                                 }
+                               else if(fgAODPhosCells->GetMCLabel(pos) >= 0 &&  cellsP->GetMCLabel(i) < 0)
+                                 {
+                                   mclabel = fgAODPhosCells->GetMCLabel(pos) ;
+//                                 time    = cellsP->GetTime(i) ; // Time from data
+                                   if(amp > 0) efrac = fgAODPhosCells->GetAmplitude(pos) / amp;
+                                 }
+                               else 
+                                 { // take all from input
+                                   mclabel = cellsP->GetMCLabel(i) ;
+//                                 time    = cellsP->GetTime(i) ; 
+                                   if(amp > 0) efrac = cellsP->GetAmplitude(i) / amp;  
+                                 }
+                               
+                               fgAODPhosCells->SetCell(pos, cn, amp,cellsP->GetTime(i),mclabel,efrac);                
+                               
+                             } else 
+                             {
                                AliAODCaloCells* copycells1 = new AliAODCaloCells(*fgAODPhosCells);
                                fgAODPhosCells->CreateContainer(nc+1);
                                Int_t nn = copycells1->GetNumberOfCells();
-                               while( nn-- ){ fgAODPhosCells->SetCell(nn,copycells1->GetCellNumber(nn),copycells1->GetAmplitude(nn)); }
-                               fgAODPhosCells->SetCell(nc++,cn,cellsP->GetAmplitude(i));
+                               
+                               while( nn-- ){ fgAODPhosCells->SetCell(nn,copycells1->GetCellNumber(nn),copycells1->GetAmplitude(nn), 
+                                                                      copycells1->GetTime(nn),copycells1->GetMCLabel(nn),copycells1->GetEFraction(nn)); }
+                               
+                               fgAODPhosCells->SetCell(nc++,cn,cellsP->GetAmplitude(i),cellsP->GetTime(i), cellsP->GetMCLabel(i),1.);
+                               
                                delete copycells1;
-                           }
-                       }
+                             }
+                         }
                        fgAODPhosCells->Sort();
-                   }
-               } // Merge PHOS Cells
+                     }
+                 } // Merge PHOS Cells
                
-               if (aodH->GetMergeEMCALTrigger()) 
+               if (aodH->GetMergeEMCALTrigger() && aod->GetCaloTrigger("EMCAL")
                {
-                       Int_t   EMCALts[48][64], px, py, ts;
-                       Float_t EMCALfo[48][64], am;
+                       Int_t   tsEMCAL[48][64], px, py, ts;
+                       Float_t foEMCAL[48][64], am;
                        
                        for (Int_t i = 0; i < 48; i++) for (Int_t j = 0; j < 64; j++) 
                        {
-                               EMCALts[i][j] = 0;
-                               EMCALfo[i][j] = 0.;
+                               tsEMCAL[i][j] = 0;
+                               foEMCAL[i][j] = 0.;
                        }
-                       
-                       AliAODCaloTrigger& trg0 = *(aod->GetCaloTrigger("EMCAL"));
-                       
-                       trg0.Reset();
-                       while (trg0.Next())
-                       {
-                               trg0.GetPosition(px, py);
-                               
-                               if (px > -1 && py > -1) 
-                               {
-                                       trg0.GetL1TimeSum(ts);
-                                       if (ts > -1) EMCALts[px][py] += ts;
-                                       
-                                       trg0.GetAmplitude(am);
-                                       if (am > -1) EMCALfo[px][py] += am;
-                               }
-                       }
-                       
-                       AliAODCaloTrigger& trg1 = *((aodH->GetEventToMerge())->GetCaloTrigger("EMCAL"));
-                       
-                       trg1.Reset();
-                       while (trg1.Next())
-                       {
-                               trg1.GetPosition(px, py);
-                               
-                               if (px > -1 && py > -1) 
-                               {
-                                       trg1.GetL1TimeSum(ts);
-                                       if (ts > -1) EMCALts[px][py] += ts;
-                                       
-                                       trg1.GetAmplitude(am);
-                                       if (am > -1) EMCALfo[px][py] += am;
-                               }
-                       }
-                       
-                       int nEntries = 0;
-                       for (Int_t i = 0; i < 48; i++) 
-                               for (Int_t j = 0; j < 64; j++) 
-                                       if (EMCALts[i][j] || EMCALfo[i][j]) nEntries++;
-               
-                       fgAODEMCALTrigger->Allocate(nEntries);
-                       Int_t L0times[10]; for (int i = 0; i < 10; i++) L0times[i] = -1;
-               
-                       for (Int_t i = 0; i < 48; i++) 
-                               for (Int_t j = 0; j < 64; j++) 
-                                       if (EMCALts[i][j] || EMCALfo[i][j]) 
-                                               fgAODEMCALTrigger->Add(i, j, EMCALfo[i][j], -1., L0times, 0, EMCALts[i][j], 0);
-               }
+      
+      AliAODCaloTrigger& trg0 = *(aod->GetCaloTrigger("EMCAL"));
+      trg0.Reset();
+      while (trg0.Next())
+      {
+        trg0.GetPosition(px, py);
+        
+        if (px > -1 && py > -1) 
+        {
+          trg0.GetL1TimeSum(ts);
+          if (ts > -1) tsEMCAL[px][py] += ts;
+          
+          trg0.GetAmplitude(am);
+          if (am > -1) foEMCAL[px][py] += am;
+        }
+      }
+      
+      AliAODCaloTrigger& trg1 = *((aodH->GetEventToMerge())->GetCaloTrigger("EMCAL"));
+      
+      trg1.Reset();
+      while (trg1.Next())
+      {
+        trg1.GetPosition(px, py);
+        
+        if (px > -1 && py > -1) 
+        {
+          trg1.GetL1TimeSum(ts);
+          if (ts > -1) tsEMCAL[px][py] += ts;
+          
+          trg1.GetAmplitude(am);
+          if (am > -1) foEMCAL[px][py] += am;
+        }
+      }
+      
+      int nEntries = 0;
+      for (Int_t i = 0; i < 48; i++) 
+        for (Int_t j = 0; j < 64; j++) 
+          if (tsEMCAL[i][j] || foEMCAL[i][j]) nEntries++;
+      
+      fgAODEMCALTrigger->Allocate(nEntries);
+      Int_t timesL0[10]; for (int i = 0; i < 10; i++) timesL0[i] = -1;
+      
+      for (Int_t i = 0; i < 48; i++) 
+        for (Int_t j = 0; j < 64; j++) 
+          if (tsEMCAL[i][j] || foEMCAL[i][j]) 
+            fgAODEMCALTrigger->Add(i, j, foEMCAL[i][j], -1., timesL0, 0, tsEMCAL[i][j], 0);
+    }
                
                if (aodH->GetMergePHOSTrigger()) 
                {
@@ -648,13 +763,7 @@ void AliAnalysisTaskSE::Exec(Option_t* option)
 
 
 // Call the user analysis    
-    if (!fMCEventHandler) {
-       if (isSelected) 
-           UserExec(option);
-    } else {
-       if (isSelected && (fMCEventHandler->InitOk())) 
-           UserExec(option);
-    }
+       if (isSelected) UserExec(option);
     
 // Added protection in case the derived task is not an AOD producer.
     AliAnalysisDataSlot *out0 = GetOutputSlot(0);
@@ -728,6 +837,7 @@ void AliAnalysisTaskSE::LoadBranches() const
   TIter next(arr);
   TObject *obj;
   while ((obj=next())) mgr->LoadBranch(obj->GetName());
+  delete arr;
 }
 
 
@@ -741,9 +851,9 @@ void AliAnalysisTaskSE::ConnectMultiHandler()
    fMultiInputHandler = dynamic_cast<AliMultiInputEventHandler *>(fInputHandler);
    if (fMultiInputHandler) {
       fInputHandler = dynamic_cast<AliInputEventHandler *>(fMultiInputHandler->GetFirstInputEventHandler());
-      fMCEventHandler = dynamic_cast<AliMCEventHandler *>(fMultiInputHandler->GetFirstMCEventHandler());
+      fMCEventHandler = dynamic_cast<AliInputEventHandler *>(fMultiInputHandler->GetFirstMCEventHandler());
    } else { 
-      fMCEventHandler = dynamic_cast<AliMCEventHandler *>((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
+      fMCEventHandler = dynamic_cast<AliInputEventHandler *>((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
    }
    if (fMCEventHandler) fMCEvent = fMCEventHandler->MCEvent();
 }