]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliAnalysisTaskSE.cxx
Add forward declaration for ROOT
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskSE.cxx
index 864ae3030891949276dff8f352a89dfa5ccbb0f1..679fe1018cdd536f85b780dfc5628af77a2386e6 100644 (file)
 
 #include "AliAnalysisTaskSE.h"
 #include "AliAnalysisManager.h"
+#include "AliAnalysisCuts.h"
 #include "AliAnalysisDataSlot.h"
+
 #include "AliESDEvent.h"
+#include "AliESDfriend.h"
 #include "AliESD.h"
 #include "AliAODEvent.h"
 #include "AliAODHeader.h"
 #include "AliAODInputHandler.h"
 #include "AliMCEventHandler.h"
 #include "AliInputEventHandler.h"
+#include "AliESDInputHandler.h"
 #include "AliMCEvent.h"
 #include "AliStack.h"
 #include "AliLog.h"
+#include "AliAODDimuon.h"
 
 
 ClassImp(AliAnalysisTaskSE)
 
 ////////////////////////////////////////////////////////////////////////
-AliAODHeader*    AliAnalysisTaskSE::fgAODHeader        = NULL;
-TClonesArray*    AliAnalysisTaskSE::fgAODTracks        = NULL;
-TClonesArray*    AliAnalysisTaskSE::fgAODVertices      = NULL;
-TClonesArray*    AliAnalysisTaskSE::fgAODV0s           = NULL;
-TClonesArray*    AliAnalysisTaskSE::fgAODPMDClusters   = NULL;
-TClonesArray*    AliAnalysisTaskSE::fgAODJets          = NULL;
-TClonesArray*    AliAnalysisTaskSE::fgAODFMDClusters   = NULL;
-TClonesArray*    AliAnalysisTaskSE::fgAODCaloClusters  = NULL;
-TClonesArray*    AliAnalysisTaskSE::fgAODMCParticles   = NULL;
-AliAODTracklets* AliAnalysisTaskSE::fgAODTracklets     = NULL;
-AliAODCaloCells* AliAnalysisTaskSE::fgAODEmcalCells    = NULL;
-AliAODCaloCells* AliAnalysisTaskSE::fgAODPhosCells     = NULL;
-
+AliAODHeader*    AliAnalysisTaskSE::fgAODHeader         = NULL;
+TClonesArray*    AliAnalysisTaskSE::fgAODTracks         = NULL;
+TClonesArray*    AliAnalysisTaskSE::fgAODVertices       = NULL;
+TClonesArray*    AliAnalysisTaskSE::fgAODV0s            = NULL;
+TClonesArray*    AliAnalysisTaskSE::fgAODPMDClusters    = NULL;
+TClonesArray*    AliAnalysisTaskSE::fgAODJets           = NULL;
+TClonesArray*    AliAnalysisTaskSE::fgAODFMDClusters    = NULL;
+TClonesArray*    AliAnalysisTaskSE::fgAODCaloClusters   = NULL;
+TClonesArray*    AliAnalysisTaskSE::fgAODMCParticles    = NULL;
+AliAODTracklets* AliAnalysisTaskSE::fgAODTracklets      = NULL;
+AliAODCaloCells* AliAnalysisTaskSE::fgAODEmcalCells     = NULL;
+AliAODCaloCells* AliAnalysisTaskSE::fgAODPhosCells      = NULL;
+TClonesArray*    AliAnalysisTaskSE::fgAODDimuons        = NULL;
 
 AliAnalysisTaskSE::AliAnalysisTaskSE():
     AliAnalysisTask(),
     fDebug(0),
     fEntry(0),
     fInputEvent(0x0),
+    fESDfriend(0x0),
     fInputHandler(0x0),
     fOutputAOD(0x0),
     fMCEvent(0x0),
-    fTreeA(0x0)
+    fTreeA(0x0),
+    fCurrentRunNumber(-1),
+    fHistosQA(0x0),
+    fOfflineTriggerMask(0)
 {
   // Default constructor
 }
@@ -77,12 +86,14 @@ AliAnalysisTaskSE::AliAnalysisTaskSE(const char* name):
     fDebug(0),
     fEntry(0),
     fInputEvent(0x0),
+    fESDfriend(0x0),
     fInputHandler(0x0),
     fOutputAOD(0x0),
     fMCEvent(0x0),
     fTreeA(0x0),
     fCurrentRunNumber(-1),
-    fHistosQA(0x0)
+    fHistosQA(0x0),
+    fOfflineTriggerMask(0)
 {
   // Default constructor
     DefineInput (0, TChain::Class());
@@ -94,23 +105,27 @@ AliAnalysisTaskSE::AliAnalysisTaskSE(const AliAnalysisTaskSE& obj):
     fDebug(0),
     fEntry(0),
     fInputEvent(0x0),
+    fESDfriend(0x0),
     fInputHandler(0x0),
     fOutputAOD(0x0),
     fMCEvent(0x0),
     fTreeA(0x0),
     fCurrentRunNumber(-1),
-    fHistosQA(0x0)
+    fHistosQA(0x0),
+    fOfflineTriggerMask(0)
 {
 // Copy constructor
     fDebug            = obj.fDebug;
     fEntry            = obj.fEntry;
     fInputEvent       = obj.fInputEvent;
+    fESDfriend        = obj.fESDfriend;
     fInputHandler     = obj.fInputHandler;
     fOutputAOD        = obj.fOutputAOD;
     fMCEvent          = obj.fMCEvent;
     fTreeA            = obj.fTreeA;    
     fCurrentRunNumber = obj.fCurrentRunNumber;
     fHistosQA         = obj.fHistosQA;
+
 }
 
 
@@ -121,12 +136,14 @@ AliAnalysisTaskSE& AliAnalysisTaskSE::operator=(const AliAnalysisTaskSE& other)
     fDebug            = other.fDebug;
     fEntry            = other.fEntry;
     fInputEvent       = other.fInputEvent;
+    fESDfriend        = other.fESDfriend;
     fInputHandler     = other.fInputHandler;
     fOutputAOD        = other.fOutputAOD;
     fMCEvent          = other.fMCEvent;
     fTreeA            = other.fTreeA;    
     fCurrentRunNumber = other.fCurrentRunNumber;
     fHistosQA         = other.fHistosQA;
+    fOfflineTriggerMask = other.fOfflineTriggerMask;
     return *this;
 }
 
@@ -150,7 +167,10 @@ void AliAnalysisTaskSE::ConnectInputData(Option_t* /*option*/)
     } 
     
     if (fInputHandler) {
-         fInputEvent = fInputHandler->GetEvent();
+       if ((fInputHandler->GetTree())->GetBranch("ESDfriend."))
+           fESDfriend = ((AliESDInputHandler*)fInputHandler)->GetESDfriend();
+
+       fInputEvent = fInputHandler->GetEvent();
     } else if( fMCEvent ) {
          AliWarning("No Input Event Handler connected, only MC Truth Event Handler") ; 
     } else {
@@ -166,7 +186,7 @@ void AliAnalysisTaskSE::CreateOutputObjects()
 //  Default AOD
     if (fDebug > 1) printf("AnalysisTaskSE::CreateOutPutData() \n");
 
-    AliAODHandler* handler = (AliAODHandler*) 
+    AliAODHandler* handler = dynamic_cast<AliAODHandler*> 
          ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
     
     Bool_t merging = kFALSE;
@@ -175,12 +195,13 @@ void AliAnalysisTaskSE::CreateOutputObjects()
        if (aodIH->GetMergeEvents()) merging = kTRUE;
     }
     
+
     // Check if AOD replication has been required
     
     if (handler) {
        fOutputAOD   = handler->GetAOD();
        fTreeA = handler->GetTree();
-       if (!(handler->IsStandard())) {
+       if (fOutputAOD && !(handler->IsStandard())) {
            if ((handler->NeedsHeaderReplication()) && !(fgAODHeader)) 
                {
                 if (fDebug > 1) AliInfo("Replicating header");
@@ -257,11 +278,17 @@ void AliAnalysisTaskSE::CreateOutputObjects()
                fgAODMCParticles->SetName("mcparticles");
                handler->AddBranch("TClonesArray", &fgAODMCParticles);
            }
+           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);
+           }    
+
            // cache the pointerd in the AODEvent
            fOutputAOD->GetStdContent();
        }
-    } else {
-       AliWarning("No AOD Event Handler connected.") ; 
     }
     UserCreateOutputObjects();
 }
@@ -270,21 +297,46 @@ void AliAnalysisTaskSE::Exec(Option_t* option)
 {
 //
 // Exec analysis of one event
+    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());
+
+    AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
+//
+// Was event selected ? If no event selection mechanism, the event SHOULD be selected (AG)
+    UInt_t isSelected = AliVEvent::kAny;
+    if( fInputHandler && fInputHandler->GetEventSelection()) {
+      // 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();
+    }
+//  Functionality below moved in the filter tasks (AG)
+//    if (handler) handler->SetFillAOD(isSelected);
 
     if( fInputHandler ) {
-       fEntry = fInputHandler->GetReadEntry();
+       fEntry = fInputHandler->GetReadEntry();
+       fESDfriend = ((AliESDInputHandler*)fInputHandler)->GetESDfriend();
     }
     
+
+// 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()));
 
-    AliAODHandler* handler = (AliAODHandler*) 
-       ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
-    AliAODInputHandler* aodH = dynamic_cast<AliAODInputHandler*>(fInputHandler);
+    
+    
 
     if (handler && aodH) {
        fMCEvent = aodH->MCEvent();
@@ -341,7 +393,39 @@ void AliAnalysisTaskSE::Exec(Option_t* option)
                TClonesArray* mcParticles = (TClonesArray*) ((dynamic_cast<AliAODEvent*>(InputEvent()))->FindListObject("mcparticles"));
                new (fgAODMCParticles) TClonesArray(*mcParticles);
            }
-       
+           
+           if ((handler->NeedsDimuonsBranchReplication() || merging) && (fgAODDimuons))
+           {
+               fgAODDimuons->Clear();
+               TClonesArray& dimuons = *fgAODDimuons;
+               TClonesArray& tracksnew = *fgAODTracks;
+               
+                Int_t nMuonTrack[10]; 
+                for(Int_t imuon = 0; imuon < 10; imuon++) nMuonTrack[imuon] = 0;
+                Int_t nMuons=0;
+               for(Int_t ii=0; ii < fgAODTracks->GetEntries(); ii++){
+                   AliAODTrack *track = (AliAODTrack*) fgAODTracks->At(ii);
+                   if(track->IsMuonTrack()) {
+                       nMuonTrack[nMuons]= ii;
+                       nMuons++;
+                   }  
+               }
+                Int_t jDimuons=0;
+               if(nMuons >= 2){
+                   for(Int_t i = 0; i < nMuons; i++){
+                       Int_t index0 = nMuonTrack[i];
+                       for(Int_t j = i+1; j < nMuons; j++){
+                           Int_t index1 = nMuonTrack[j];
+                           tracksnew.At(index0)->ResetBit(kIsReferenced);
+                           tracksnew.At(index0)->SetUniqueID(0); 
+                           tracksnew.At(index1)->ResetBit(kIsReferenced);
+                           tracksnew.At(index1)->SetUniqueID(0);
+                           new(dimuons[jDimuons++]) AliAODDimuon(tracksnew.At(index0),tracksnew.At(index1));
+                       }
+                   }    
+               }
+           }
+           
            // Additional merging if needed
            if (merging) {
                // mcParticles
@@ -362,7 +446,6 @@ void AliAnalysisTaskSE::Exec(Option_t* option)
                for (Int_t i = 0; i < ntr; i++) {
                    AliAODTrack*    track = (AliAODTrack*) tracks->At(i);
                    AliAODTrack* newtrack = new((*fgAODTracks)[nc++]) AliAODTrack(*track);
-
                    newtrack->SetLabel(newtrack->GetLabel() + nc0);
                }
 
@@ -408,8 +491,18 @@ void AliAnalysisTaskSE::Exec(Option_t* option)
     }
 
 // Call the user analysis    
-    UserExec(option);
-    // Added protection in case the derived task is not an AOD producer.
+    AliMCEventHandler*    mcH = 0;
+    mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
+
+    if (!mcH) {
+       if (isSelected) 
+           UserExec(option);
+    } else {
+       if (isSelected && (mcH->InitOk())) 
+           UserExec(option);
+    }
+    
+// Added protection in case the derived task is not an AOD producer.
     AliAnalysisDataSlot *out0 = GetOutputSlot(0);
     if (out0 && out0->IsConnected()) PostData(0, fTreeA);    
 }
@@ -427,7 +520,7 @@ const char* AliAnalysisTaskSE::CurrentFileName()
 void AliAnalysisTaskSE::AddAODBranch(const char* cname, void* addobj, const char *fname)
 {
     // Add a new branch to the aod tree
-    AliAODHandler* handler = (AliAODHandler*) 
+    AliAODHandler* handler = dynamic_cast<AliAODHandler*> 
        ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
     if (handler) {
        handler->AddBranch(cname, addobj, fname);
@@ -438,7 +531,7 @@ Bool_t AliAnalysisTaskSE::IsStandardAOD() const
 {
 // Check if the output AOD handler is configured for standard or delta AOD.
 // Users should first check that AODEvent() returns non-null.
-    AliAODHandler* handler = (AliAODHandler*) 
+    AliAODHandler* handler = dynamic_cast<AliAODHandler*> 
          ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
     if (!handler) {
        Error("IsStandardAOD", "No AOD handler. Please use AODEvent() to check this first");
@@ -449,12 +542,7 @@ Bool_t AliAnalysisTaskSE::IsStandardAOD() const
 
 Bool_t AliAnalysisTaskSE::Notify()
 {
-    // Called for every change of input file
-    if (InputEvent()->GetRunNumber() != fCurrentRunNumber) {
-       fCurrentRunNumber = InputEvent()->GetRunNumber();
-       NotifyRun();
-    }
-    UserNotify();
+    return (UserNotify());
 }