]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliAnalysisTaskSE.cxx
ANALYSIS and ANALYSIScalib
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskSE.cxx
index 82963b66d7a6b00d7d1481a89669cc4d2caf83d1..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(),
@@ -172,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();
@@ -214,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");
@@ -294,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();
@@ -315,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);
 //
@@ -334,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());
 
@@ -389,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();
@@ -469,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;
@@ -544,25 +581,25 @@ void AliAnalysisTaskSE::Exec(Option_t* option)
                                Double_t amp = cellsA->GetAmplitude(i) + fgAODEmcalCells->GetAmplitude(pos);
                                
                                //Check if it is MC, depending on that assing the mc lable, time and e fraction
-                               Double_t time    = 0;
+//                             Double_t time    = 0;
                                Int_t    mclabel =-1;
-                               Int_t    efrac   = 0;
-                               if(cellsA->GetMCLabel(i) >= 0 && fgAODEmcalCells->GetMCLabel(i) < 0)
+                               Double_t efrac   = 0;
+                               if(cellsA->GetMCLabel(i) >= 0 && fgAODEmcalCells->GetMCLabel(pos) < 0)
                                  {
                                    mclabel = cellsA->GetMCLabel(i) ;
-                                   time    = fgAODEmcalCells->GetTime(i) ; // Time from data
+//                                 time    = fgAODEmcalCells->GetTime(pos) ; // Time from data
                                    if(amp > 0) efrac = cellsA->GetAmplitude(i) / amp;
                                  }
-                               else if(fgAODEmcalCells->GetMCLabel(i) >= 0 &&  cellsA->GetMCLabel(i) < 0)
+                               else if(fgAODEmcalCells->GetMCLabel(pos) >= 0 &&  cellsA->GetMCLabel(i) < 0)
                                  {
-                                   mclabel = fgAODEmcalCells->GetMCLabel(i) ;
-                                   time    = cellsA->GetTime(i) ; // Time from data
-                                   if(amp > 0) efrac = fgAODEmcalCells->GetAmplitude(i) / amp;              
+                                   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) ; 
+//                                 time    = cellsA->GetTime(i) ; 
                                    if(amp > 0) efrac = cellsA->GetAmplitude(i) / amp;  
                                  }
                                
@@ -575,9 +612,9 @@ void AliAnalysisTaskSE::Exec(Option_t* option)
                                Int_t nn = copycells1->GetNumberOfCells();
                                
                                while( nn-- ){ fgAODEmcalCells->SetCell(nn,copycells1->GetCellNumber(nn),copycells1->GetAmplitude(nn),
-                                                                       copycells1->GetTime(nn),copycells1->GetMCLabel(nn),0.); }
+                                                                       copycells1->GetTime(nn),copycells1->GetMCLabel(nn),copycells1->GetEFraction(nn)); }
                                
-                               fgAODEmcalCells->SetCell(nc++,cn,cellsA->GetAmplitude(i),cellsA->GetTime(i), cellsA->GetMCLabel(i),0.);
+                               fgAODEmcalCells->SetCell(nc++,cn,cellsA->GetAmplitude(i),cellsA->GetTime(i), cellsA->GetMCLabel(i),1.);
                                
                                delete copycells1;
                              }
@@ -614,25 +651,25 @@ void AliAnalysisTaskSE::Exec(Option_t* option)
                                Double_t amp = cellsP->GetAmplitude(i) + fgAODPhosCells->GetAmplitude(pos);
                                
                                //Check if it is MC, depending on that assing the mc lable, time and e fraction
-                               Double_t time    = 0;
+//                             Double_t time    = 0;
                                Int_t    mclabel =-1;
-                               Int_t    efrac   = 0;
-                               if(cellsP->GetMCLabel(i) >= 0 && fgAODPhosCells->GetMCLabel(i) < 0)
+                               Double_t    efrac   = 0;
+                               if(cellsP->GetMCLabel(i) >= 0 && fgAODPhosCells->GetMCLabel(pos) < 0)
                                  {
                                    mclabel = cellsP->GetMCLabel(i) ;
-                                   time    = fgAODPhosCells->GetTime(i) ; // Time from data
+//                                 time    = fgAODPhosCells->GetTime(pos) ; // Time from data
                                    if(amp > 0) efrac = cellsP->GetAmplitude(i) / amp;
                                  }
-                               else if(fgAODPhosCells->GetMCLabel(i) >= 0 &&  cellsP->GetMCLabel(i) < 0)
+                               else if(fgAODPhosCells->GetMCLabel(pos) >= 0 &&  cellsP->GetMCLabel(i) < 0)
                                  {
-                                   mclabel = fgAODPhosCells->GetMCLabel(i) ;
-                                   time    = cellsP->GetTime(i) ; // Time from data
-                                   if(amp > 0) efrac = fgAODPhosCells->GetAmplitude(i) / amp;              
+                                   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) ; 
+//                                 time    = cellsP->GetTime(i) ; 
                                    if(amp > 0) efrac = cellsP->GetAmplitude(i) / amp;  
                                  }
                                
@@ -645,9 +682,9 @@ void AliAnalysisTaskSE::Exec(Option_t* option)
                                Int_t nn = copycells1->GetNumberOfCells();
                                
                                while( nn-- ){ fgAODPhosCells->SetCell(nn,copycells1->GetCellNumber(nn),copycells1->GetAmplitude(nn), 
-                                                                      copycells1->GetTime(nn),copycells1->GetMCLabel(nn),0.); }
+                                                                      copycells1->GetTime(nn),copycells1->GetMCLabel(nn),copycells1->GetEFraction(nn)); }
                                
-                               fgAODPhosCells->SetCell(nc++,cn,cellsP->GetAmplitude(i),cellsP->GetTime(i), cellsP->GetMCLabel(i),0.);
+                               fgAODPhosCells->SetCell(nc++,cn,cellsP->GetAmplitude(i),cellsP->GetTime(i), cellsP->GetMCLabel(i),1.);
                                
                                delete copycells1;
                              }
@@ -726,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);
@@ -806,6 +837,7 @@ void AliAnalysisTaskSE::LoadBranches() const
   TIter next(arr);
   TObject *obj;
   while ((obj=next())) mgr->LoadBranch(obj->GetName());
+  delete arr;
 }
 
 
@@ -819,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();
 }