]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG2/FLOW/AliAnalysisTaskScalarProduct.cxx
new methods and possiility to run all methods in same run
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliAnalysisTaskScalarProduct.cxx
index f777d11063fed5a4df213cd14533533655748374..7106fcfb366a6f46951890fe6f9e6798588b5856 100644 (file)
@@ -32,9 +32,12 @@ class AliAnalysisTask;
 #include "AliMCEventHandler.h"
 #include "AliMCEvent.h"
 
+#include "../../CORRFW/AliCFManager.h"
+
 #include "AliAnalysisTaskScalarProduct.h"
 #include "AliFlowEventSimpleMaker.h"
 #include "AliFlowAnalysisWithScalarProduct.h"
+#include "AliFlowCommonHist.h"
 
 // AliAnalysisTaskScalarProduct:
 //
@@ -45,14 +48,19 @@ class AliAnalysisTask;
 ClassImp(AliAnalysisTaskScalarProduct)
 
 //________________________________________________________________________
-AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct(const char *name) : 
+AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct(const char *name, Bool_t on) : 
   AliAnalysisTask(name, ""), 
   fESD(NULL),
   fAOD(NULL),
   fSP(NULL),
   fEventMaker(NULL),
   fAnalysisType("ESD"),
-  fListHistos(NULL)
+  fCFManager1(NULL),
+  fCFManager2(NULL),
+  fListHistos(NULL),
+  fQAInt(NULL),
+  fQADiff(NULL),
+  fQA(on)
 {
   // Constructor
   cout<<"AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct(const char *name)"<<endl;
@@ -62,12 +70,43 @@ AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct(const char *name) :
   DefineInput(0, TChain::Class());
   // Output slot #0 writes into a TList container
   DefineOutput(0, TList::Class());  
+  if(on) {
+    DefineOutput(1, TList::Class());
+    DefineOutput(2, TList::Class()); }  
+}
 
- //event maker
-  fEventMaker = new AliFlowEventSimpleMaker();
-  //Analyser
-  fSP  = new AliFlowAnalysisWithScalarProduct() ;
-  fSP-> Init();
+//________________________________________________________________________
+AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct() : 
+  fESD(NULL),
+  fAOD(NULL),
+  fSP(NULL),
+  fEventMaker(NULL),
+  fAnalysisType("ESD"),
+  fCFManager1(NULL),
+  fCFManager2(NULL),
+  fListHistos(NULL),
+  fQAInt(NULL),
+  fQADiff(NULL),
+  fQA(kFALSE)
+{
+  // Constructor
+  cout<<"AliAnalysisTaskScalarProduct::AliAnalysisTaskScalarProduct()"<<endl;
+}
+
+//________________________________________________________________________
+AliAnalysisTaskScalarProduct::~AliAnalysisTaskScalarProduct()
+{
+  //
+  // Destructor
+  //
+
+  // histograms are in the output list and deleted when the output
+  // list is deleted by the TSelector dtor
+
+  //  if (ListHistos) {
+  //    delete fListHistos;
+  //    fListHistos = NULL;
+  //  }
 }
 
 //________________________________________________________________________
@@ -83,7 +122,6 @@ void AliAnalysisTaskScalarProduct::ConnectInputData(Option_t *)
   } else {
     // Disable all branches and enable only the needed ones
     if (fAnalysisType == "MC") {
-      cout<<"!!!!!reading MC kinematics only"<<endl;
       // we want to process only MC
       tree->SetBranchStatus("*", kFALSE);
 
@@ -95,8 +133,7 @@ void AliAnalysisTaskScalarProduct::ConnectInputData(Option_t *)
        fESD = esdH->GetEvent();
       }
     }
-    else if (fAnalysisType == "ESD") {
-      cout<<"!!!!!reading the ESD only"<<endl;
+    else if (fAnalysisType == "ESD" || fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1") {
       tree->SetBranchStatus("*", kFALSE);
       tree->SetBranchStatus("Tracks.*", kTRUE);
 
@@ -108,7 +145,6 @@ void AliAnalysisTaskScalarProduct::ConnectInputData(Option_t *)
        fESD = esdH->GetEvent();
     }
     else if (fAnalysisType == "AOD") {
-      cout<<"!!!!!reading the AOD only"<<endl;
       AliAODInputHandler *aodH = dynamic_cast<AliAODInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
 
       if (!aodH) {
@@ -119,7 +155,7 @@ void AliAnalysisTaskScalarProduct::ConnectInputData(Option_t *)
       }
     }
     else {
-      Printf("!!!!!Wrong analysis type: Only ESD, AOD and MC types are allowed!");
+      Printf("!!!!!Wrong analysis type: Only ESD, ESDMC0, ESDMC1, AOD and MC types are allowed!");
       exit(1);
       
     }
@@ -129,14 +165,25 @@ void AliAnalysisTaskScalarProduct::ConnectInputData(Option_t *)
 //________________________________________________________________________
 void AliAnalysisTaskScalarProduct::CreateOutputObjects() 
 {
-  // Called once
+  // Called at every worker node to initialize
   cout<<"AliAnalysisTaskScalarProduct::CreateOutputObjects()"<<endl;
+
+  if (!(fAnalysisType == "AOD" || fAnalysisType == "ESD" || fAnalysisType == "ESDMC0"  || fAnalysisType == "ESDMC1" || fAnalysisType == "MC")) {
+    cout<<"WRONG ANALYSIS TYPE! only ESD, ESDMC0, ESDMC1, AOD and MC are allowed."<<endl;
+    exit(1);
+  }
+
+  //event maker
+  fEventMaker = new AliFlowEventSimpleMaker();
+  //Analyser
+  fSP  = new AliFlowAnalysisWithScalarProduct() ;
+  fSP-> Init();
   
 
   if (fSP->GetHistList()) {
-       fSP->GetHistList()->Print();
-//     *fListHistos = new TList();
+    //fSP->GetHistList()->Print();
        fListHistos = fSP->GetHistList();
+       fListHistos->Print();
   }
   else {Printf("ERROR: Could not retrieve histogram list"); }
 }
@@ -147,27 +194,30 @@ void AliAnalysisTaskScalarProduct::Exec(Option_t *)
   // Main loop
   // Called for each event
 
-  
-  // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
-  // This handler can return the current MC event
+        
+  if (fAnalysisType == "MC") {
 
-  AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
-  if (!eventHandler) {
-    Printf("ERROR: Could not retrieve MC event handler");
-    return;
-  }
+    // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
+    // This handler can return the current MC event
 
-  AliMCEvent* mcEvent = eventHandler->MCEvent();
-  if (!mcEvent) {
-    Printf("ERROR: Could not retrieve MC event");
-    return;
-  }
+    AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
+    if (!eventHandler) {
+      Printf("ERROR: Could not retrieve MC event handler");
+      return;
+    }
+
+    AliMCEvent* mcEvent = eventHandler->MCEvent();
+    if (!mcEvent) {
+      Printf("ERROR: Could not retrieve MC event");
+      return;
+    }
+
+    fCFManager1->SetEventInfo(mcEvent);
+    fCFManager2->SetEventInfo(mcEvent);
 
-  Printf("MC particles: %d", mcEvent->GetNumberOfTracks());
-      
-  if (fAnalysisType == "MC") {
     // analysis 
-    AliFlowEventSimple* fEvent = fEventMaker->FillTracks(mcEvent);
+    Printf("MC particles: %d", mcEvent->GetNumberOfTracks());
+    AliFlowEventSimple* fEvent = fEventMaker->FillTracks(mcEvent,fCFManager1,fCFManager2);
     fSP->Make(fEvent);
 
     delete fEvent;
@@ -180,10 +230,44 @@ void AliAnalysisTaskScalarProduct::Exec(Option_t *)
     Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
     
     // analysis 
-    AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fESD);
+    AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fESD,fCFManager1,fCFManager2);
+    fSP->Make(fEvent);
+    delete fEvent;
+  }
+else if (fAnalysisType == "ESDMC0" || fAnalysisType == "ESDMC1" ) {
+    if (!fESD) {
+      Printf("ERROR: fESD not available");
+      return;
+    }
+    Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
+    
+    AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
+    if (!eventHandler) {
+      Printf("ERROR: Could not retrieve MC event handler");
+      return;
+    }
+
+    AliMCEvent* mcEvent = eventHandler->MCEvent();
+    if (!mcEvent) {
+      Printf("ERROR: Could not retrieve MC event");
+      return;
+    }
+
+    fCFManager1->SetEventInfo(mcEvent);
+    fCFManager2->SetEventInfo(mcEvent);
+
+    //lee yang zeros analysis 
+    AliFlowEventSimple* fEvent=NULL;
+    if (fAnalysisType == "ESDMC0") { 
+      fEvent = fEventMaker->FillTracks(fESD, mcEvent, fCFManager1, fCFManager2, 0); //0 = kine from ESD, 1 = kine from MC
+    } else if (fAnalysisType == "ESDMC1") {
+      fEvent = fEventMaker->FillTracks(fESD, mcEvent, fCFManager1, fCFManager2, 1); //0 = kine from ESD, 1 = kine from MC
+    }
     fSP->Make(fEvent);
     delete fEvent;
+    //delete mcEvent;
   }
+  
   else if (fAnalysisType == "AOD") {
     if (!fAOD) {
       Printf("ERROR: fAOD not available");
@@ -192,21 +276,31 @@ void AliAnalysisTaskScalarProduct::Exec(Option_t *)
     Printf("There are %d tracks in this event", fAOD->GetNumberOfTracks());
 
     // analysis 
+    //For the moment don't use CF //AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD,fCFManager1,fCFManager2);
     AliFlowEventSimple* fEvent = fEventMaker->FillTracks(fAOD);
     fSP->Make(fEvent);
     delete fEvent;
   }
 
+  //fListHistos->Print();      
   PostData(0,fListHistos);
-}      
+  if (fQA) {
+    PostData(1,fQAInt);
+    PostData(2,fQADiff); }
+} 
 
 //________________________________________________________________________
 void AliAnalysisTaskScalarProduct::Terminate(Option_t *) 
 {
-  // Called once at the end of the query
-  fSP->Finish();
-  PostData(0,fListHistos);
+  // Called once at the end of the query -- do not call in case of CAF
+  //  fSP->Finish();
+  //  PostData(0,fListHistos);
+
+  fListHistos = (TList*)GetOutputData(0);
+  cout << "histgram list in Terminate" << endl;
+  if (fListHistos)  {
+    fListHistos->Print();
+  }    
+  else { cout << "histgram list pointer is empty" << endl; }
 
-  delete fSP;
-  delete fEventMaker;
 }