]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG2/FLOW/AliFlowTasks/AliAnalysisTaskFlowEvent.cxx
added some QA to flow track cuts and event cuts, trackID fix, better redoFinish and...
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliFlowTasks / AliAnalysisTaskFlowEvent.cxx
index 0ad5447a6efa6310e3b8e598abb6b6a990aa3f0a..eb5d4d7a023c6b251361b1644de164b2f1d76078 100644 (file)
 #include "AliGenGeVSimEventHeader.h"
 #include "AliGenEposEventHeader.h"
 
+// Interface to Load short life particles
+#include "TObjArray.h"
+#include "AliFlowCandidateTrack.h"
+
 // Interface to make the Flow Event Simple used in the flow analysis methods
 #include "AliFlowEvent.h"
 #include "AliFlowTrackCuts.h"
 #include "AliFlowCommonConstants.h"
 #include "AliAnalysisTaskFlowEvent.h"
 
-#include "AliESDpid.h"
-#include "AliTOFcalib.h"
-#include "AliTOFT0maker.h"
-#include "AliCDBManager.h"
-
 #include "AliLog.h"
 
 ClassImp(AliAnalysisTaskFlowEvent)
@@ -87,15 +86,15 @@ AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent() :
   fCutsEvent(NULL),
   fCutsRP(NULL),
   fCutsPOI(NULL),
-  fQAInt(NULL),
-  fQADiff(NULL),
+  fQAList(NULL),
   fMinMult(0),
   fMaxMult(10000000),
   fMinA(-1.0),
   fMaxA(-0.01),
   fMinB(0.01),
   fMaxB(1.0),
-  fQA(kFALSE),
+  fQAon(kFALSE),
+  fLoadCandidates(kFALSE),
   fNbinsMult(10000),
   fNbinsPt(100),   
   fNbinsPhi(100),
@@ -121,18 +120,16 @@ AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent() :
   fV2(0.),
   fV3(0.),
   fV4(0.),
-  fMyTRandom3(NULL),
-  fESDpid(NULL),
-  fTOFresolution(0.0),
-  fTOFcalib(NULL),
-  ftofT0maker(NULL)
+  fV5(0.),
+  fFlowEvent(NULL),
+  fMyTRandom3(NULL)
 {
   // Constructor
   cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent()"<<endl;
 }
 
 //________________________________________________________________________
-AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, TString RPtype, Bool_t on, UInt_t iseed) :
+AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, TString RPtype, Bool_t on, UInt_t iseed, Bool_t bCandidates) :
   AliAnalysisTaskSE(name),
   //  fOutputFile(NULL),
   fAnalysisType("AUTOMATIC"),
@@ -142,15 +139,15 @@ AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, TString RPt
   fCutsEvent(NULL),
   fCutsRP(NULL),
   fCutsPOI(NULL),
-  fQAInt(NULL),
-  fQADiff(NULL),
+  fQAList(NULL),
   fMinMult(0),
   fMaxMult(10000000),
   fMinA(-1.0),
   fMaxA(-0.01),
   fMinB(0.01),
   fMaxB(1.0),
-  fQA(on),
+  fQAon(on),
+  fLoadCandidates(bCandidates),
   fNbinsMult(10000),
   fNbinsPt(100),   
   fNbinsPhi(100),
@@ -176,34 +173,29 @@ AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, TString RPt
   fV2(0.),
   fV3(0.),
   fV4(0.),
-  fMyTRandom3(NULL),
-  fESDpid(NULL),
-  fTOFresolution(0.0),
-  fTOFcalib(NULL),
-  ftofT0maker(NULL)
+  fV5(0.),
+  fFlowEvent(NULL),
+  fMyTRandom3(NULL)
 {
   // Constructor
   cout<<"AliAnalysisTaskFlowEvent::AliAnalysisTaskFlowEvent(const char *name, Bool_t on, UInt_t iseed)"<<endl;
   fMyTRandom3 = new TRandom3(iseed);
   gRandom->SetSeed(fMyTRandom3->Integer(65539));
 
+  int availableINslot=1;
   //FMD input slot
   if (strcmp(RPtype,"FMD")==0) {
-    DefineInput(1, TList::Class());
+    DefineInput(availableINslot++, TList::Class());
   }
-
-  //PID
-  fESDpid=new AliESDpid();
-  fTOFcalib = new AliTOFcalib();
+  //Candidates input slot
+  if( fLoadCandidates )
+    DefineInput(availableINslot, TObjArray::Class());
 
   // Define output slots here
   // Define here the flow event output
   DefineOutput(1, AliFlowEventSimple::Class());
-  if(on)
-  {
-    DefineOutput(2, TList::Class());
-    DefineOutput(3, TList::Class());
-  }
+  DefineOutput(2, TList::Class());
+
   // and for testing open an output file
   //  fOutputFile = new TFile("FlowEvents.root","RECREATE");
 
@@ -216,9 +208,11 @@ AliAnalysisTaskFlowEvent::~AliAnalysisTaskFlowEvent()
   // Destructor
   //
   delete fMyTRandom3;
-  delete fESDpid;
-  delete fTOFcalib;
-  delete ftofT0maker;
+  delete fFlowEvent;
+  delete fCutsEvent;
+  delete fCutsRP;
+  delete fCutsPOI;
+  delete fQAList;
   // objects in the output list are deleted
   // by the TSelector dtor (I hope)
 
@@ -229,18 +223,10 @@ void AliAnalysisTaskFlowEvent::NotifyRun()
 {
   //at the beginning of each new run
        AliESDEvent* fESD = dynamic_cast<AliESDEvent*> (InputEvent());
-       Int_t run = fESD->GetRunNumber();
-       if(fTOFresolution>0.0)
-       {
-               AliCDBManager *cdb = AliCDBManager::Instance();
-    cdb->SetDefaultStorage("raw://");
-    cdb->SetRun(run);
-    fTOFcalib->Init(run);
-    fTOFcalib->CreateCalObjects();
-    delete ftofT0maker;
-    ftofT0maker= new AliTOFT0maker(fESDpid,fTOFcalib);  
-  } 
-   AliInfo(Form("Stariting run #%i",run));
+  if (!fESD) return;
+
+  Int_t run = fESD->GetRunNumber();  
+  AliInfo(Form("Stariting run #%i",run));
 }
 
 //________________________________________________________________________
@@ -255,37 +241,6 @@ void AliAnalysisTaskFlowEvent::UserCreateOutputObjects()
     exit(1);
   }
 
-  if (!(fCutsRP&&fCutsPOI))
-  {
-    AliError("cuts not set");
-    return;
-  }
-  if (fCutsEvent) 
-  {
-    if (!fCutsEvent->IsSelected(InputEvent())) return;
-  }
-
-  //PID
-  if (fCutsRP->GetParamType()==AliFlowTrackCuts::kMC)
-  {
-    fESDpid->GetTPCResponse().SetBetheBlochParameters( 2.15898e+00/50.,
-                                                       1.75295e+01,
-                                                       3.40030e-09,
-                                                       1.96178e+00,
-                                                       3.91720e+00);
-  }
-  else
-  {
-    fESDpid->GetTPCResponse().SetBetheBlochParameters( 0.0283086,
-                                                       2.63394e+01,
-                                                       5.04114e-11,
-                                                       2.12543e+00,
-                                                       4.88663e+00 );
-  }
-
-  fCutsRP->SetESDpid(fESDpid);
-  fCutsPOI->SetESDpid(fESDpid);
-
   //set the common constants
   AliFlowCommonConstants* cc = AliFlowCommonConstants::GetMaster();
   cc->SetNbinsMult(fNbinsMult);
@@ -304,6 +259,17 @@ void AliAnalysisTaskFlowEvent::UserCreateOutputObjects()
   cc->SetQMin(fQMin);
   cc->SetQMax(fQMax);
 
+  fFlowEvent = new AliFlowEvent(3000);
+
+  if (fQAon)
+  {
+    fQAList=new TList();
+    fQAList->SetName(Form("%s QA",GetName()));
+    if (fCutsEvent->GetQA()) fQAList->Add(fCutsEvent->GetQA());
+    if (fCutsRP->GetQA()) fQAList->Add(fCutsRP->GetQA());
+    if (fCutsPOI->GetQA())fQAList->Add(fCutsPOI->GetQA());
+    PostData(2,fQAList);
+  }
 }
 
 //________________________________________________________________________
@@ -311,50 +277,42 @@ void AliAnalysisTaskFlowEvent::UserExec(Option_t *)
 {
   // Main loop
   // Called for each event
-  AliFlowEvent* flowEvent = NULL;
+  //delete fFlowEvent;
   AliMCEvent*  mcEvent = MCEvent();                              // from TaskSE
   AliESDEvent* myESD = dynamic_cast<AliESDEvent*>(InputEvent()); // from TaskSE
   AliAODEvent* myAOD = dynamic_cast<AliAODEvent*>(InputEvent()); // from TaskSE
   AliMultiplicity* myTracklets = NULL;
   AliESDPmdTrack* pmdtracks = NULL;//pmd      
-  TH2F* histFMD = NULL;
 
-  if(GetNinputs()==2) {                   
-    TList* FMDdata = dynamic_cast<TList*>(GetInputData(1));
-    if(!FMDdata) {
-      cout<<" No FMDdata "<<endl;
-      exit(2);
-    }
-    histFMD = dynamic_cast<TH2F*>(FMDdata->FindObject("dNdetadphiHistogramTrVtx"));
-    if (!histFMD) {
-      cout<< "No histFMD"<<endl;
-      exit(2);
-    }
+  int availableINslot=1;
+
+  if (!(fCutsRP&&fCutsPOI&&fCutsEvent))
+  {
+    AliError("cuts not set");
+    return;
   }
-  
-  //use the new and temporarily inclomplete way of doing things
+
+  //DEFAULT - automatically takes care of everything
   if (fAnalysisType == "AUTOMATIC")
   {
-    //PID
-    recalibTOF(dynamic_cast<AliESDEvent*>(InputEvent()));
+    //check event cuts
+    if (!fCutsEvent->IsSelected(InputEvent())) return;
 
     //first attach all possible information to the cuts
-    fCutsRP->SetEvent( InputEvent() );  //attach event
-    fCutsRP->SetMCevent( MCEvent() );   //attach mc truth
-    fCutsPOI->SetEvent( InputEvent() );
-    fCutsPOI->SetMCevent( MCEvent() );
-    fCutsRP->SetESDpid(fESDpid);
-    fCutsPOI->SetESDpid(fESDpid);
+    fCutsRP->SetEvent( InputEvent(), MCEvent() );  //attach event
+    fCutsPOI->SetEvent( InputEvent(), MCEvent() );
 
     //then make the event
-    flowEvent = new AliFlowEvent( fCutsRP, fCutsPOI );
+    fFlowEvent->Fill( fCutsRP, fCutsPOI );
+    //fFlowEvent = new AliFlowEvent( fCutsRP, fCutsPOI );
+
     if (myESD)
-      flowEvent->SetReferenceMultiplicity(fCutsEvent->GetReferenceMultiplicity(InputEvent()));
-    if (mcEvent && mcEvent->GenEventHeader()) flowEvent->SetMCReactionPlaneAngle(mcEvent);
+      fFlowEvent->SetReferenceMultiplicity(fCutsEvent->GetReferenceMultiplicity(InputEvent()));
+    if (mcEvent && mcEvent->GenEventHeader()) fFlowEvent->SetMCReactionPlaneAngle(mcEvent);
   }
 
   // Make the FlowEvent for MC input
-  if (fAnalysisType == "MC")
+  else if (fAnalysisType == "MC")
   {
     // Process MC truth, therefore we receive the AliAnalysisManager and ask it for the AliMCEventHandler
     // This handler can return the current MC event
@@ -380,7 +338,7 @@ void AliAnalysisTaskFlowEvent::UserExec(Option_t *)
       AliWarning("Event does not pass multiplicity cuts"); return;
     }
     //make event
-    flowEvent = new AliFlowEvent(mcEvent,fCFManager1,fCFManager2);
+    fFlowEvent = new AliFlowEvent(mcEvent,fCFManager1,fCFManager2);
   }
 
   // Make the FlowEvent for ESD input
@@ -408,30 +366,39 @@ void AliAnalysisTaskFlowEvent::UserExec(Option_t *)
 
     //make event
     if (fRPType == "Global") {
-      flowEvent = new AliFlowEvent(myESD,fCFManager1,fCFManager2);
+      fFlowEvent = new AliFlowEvent(myESD,fCFManager1,fCFManager2);
     }
-    if (fRPType == "TPCOnly") {
-      flowEvent = new AliFlowEvent(myESD,fCFManager2,kFALSE);
+    else if (fRPType == "TPCOnly") {
+      fFlowEvent = new AliFlowEvent(myESD,fCFManager2,kFALSE);
     }
-    if (fRPType == "TPCHybrid") {
-      flowEvent = new AliFlowEvent(myESD,fCFManager2,kTRUE);
+    else if (fRPType == "TPCHybrid") {
+      fFlowEvent = new AliFlowEvent(myESD,fCFManager2,kTRUE);
     }
     else if (fRPType == "Tracklet"){
-      flowEvent = new AliFlowEvent(myESD,myTracklets,fCFManager2);
+      fFlowEvent = new AliFlowEvent(myESD,myTracklets,fCFManager2);
     }
     else if (fRPType == "FMD"){
-      flowEvent = new AliFlowEvent(myESD,histFMD,fCFManager2);
+      TList* FMDdata = dynamic_cast<TList*>(GetInputData(availableINslot++));
+      if(!FMDdata) {
+        cout<<" No FMDdata "<<endl;
+        return;
+      }
+      TH2F* histFMD = dynamic_cast<TH2F*>(FMDdata->FindObject("dNdetadphiHistogramTrVtx"));
+      if (!histFMD) {
+        cout<< "No histFMD"<<endl;
+        return;
+      }
+      fFlowEvent = new AliFlowEvent(myESD,histFMD,fCFManager2);
     }
-    //pmd
     else if (fRPType == "PMD"){
-      flowEvent = new AliFlowEvent(myESD,pmdtracks,fCFManager2);
+      fFlowEvent = new AliFlowEvent(myESD,pmdtracks,fCFManager2);
     }
-    //pmd
+    else return;
     
     // if monte carlo event get reaction plane from monte carlo (depends on generator)
-    if (mcEvent && mcEvent->GenEventHeader()) flowEvent->SetMCReactionPlaneAngle(mcEvent);
+    if (mcEvent && mcEvent->GenEventHeader()) fFlowEvent->SetMCReactionPlaneAngle(mcEvent);
     //set reference multiplicity, TODO: maybe move it to the constructor?
-    flowEvent->SetReferenceMultiplicity(AliESDtrackCuts::GetReferenceMultiplicity(myESD,kTRUE));
+    fFlowEvent->SetReferenceMultiplicity(AliESDtrackCuts::GetReferenceMultiplicity(myESD,kTRUE));
   }
 
   // Make the FlowEvent for ESD input combined with MC info
@@ -467,16 +434,17 @@ void AliAnalysisTaskFlowEvent::UserExec(Option_t *)
     //make event
     if (fAnalysisType == "ESDMCkineESD")
     {
-      flowEvent = new AliFlowEvent(myESD, mcEvent, AliFlowEvent::kESDkine, fCFManager1, fCFManager2 );
+      fFlowEvent = new AliFlowEvent(myESD, mcEvent, AliFlowEvent::kESDkine, fCFManager1, fCFManager2 );
     }
     else if (fAnalysisType == "ESDMCkineMC")
     {
-      flowEvent = new AliFlowEvent(myESD, mcEvent, AliFlowEvent::kMCkine, fCFManager1, fCFManager2 );
+      fFlowEvent = new AliFlowEvent(myESD, mcEvent, AliFlowEvent::kMCkine, fCFManager1, fCFManager2 );
     }
+    if (!fFlowEvent) return;
     // if monte carlo event get reaction plane from monte carlo (depends on generator)
-    if (mcEvent && mcEvent->GenEventHeader()) flowEvent->SetMCReactionPlaneAngle(mcEvent);
+    if (mcEvent && mcEvent->GenEventHeader()) fFlowEvent->SetMCReactionPlaneAngle(mcEvent);
     //set reference multiplicity, TODO: maybe move it to the constructor?
-    flowEvent->SetReferenceMultiplicity(AliESDtrackCuts::GetReferenceMultiplicity(myESD,kTRUE));
+    fFlowEvent->SetReferenceMultiplicity(AliESDtrackCuts::GetReferenceMultiplicity(myESD,kTRUE));
   }
   // Make the FlowEventSimple for AOD input
   else if (fAnalysisType == "AOD")
@@ -487,11 +455,47 @@ void AliAnalysisTaskFlowEvent::UserExec(Option_t *)
       return;
     }
     AliInfo(Form("AOD has %d tracks", myAOD->GetNumberOfTracks()));
-    flowEvent = new AliFlowEvent(myAOD);
+    fFlowEvent = new AliFlowEvent(myAOD);
+  }
+
+  //inject candidates
+  if(fLoadCandidates) {
+    TObjArray* Candidates = dynamic_cast<TObjArray*>(GetInputData(availableINslot++));
+    //if(Candidates->GetEntriesFast()) 
+      //printf("I received %d candidates\n",Candidates->GetEntriesFast());
+    if (Candidates)
+    {
+      for(int iCand=0; iCand!=Candidates->GetEntriesFast(); ++iCand ) {
+        AliFlowCandidateTrack *cand = dynamic_cast<AliFlowCandidateTrack*>(Candidates->At(iCand));
+        if (!cand) continue;
+        cand->SetForPOISelection(kTRUE);
+        cand->SetForRPSelection(kFALSE);
+        //printf(" Ⱶ Checking at candidate %d with %d daughters\n",iCand,cand->GetNDaughters());
+        for(int iDau=0; iDau!=cand->GetNDaughters(); ++iDau) {
+          //printf("    Ⱶ Daughter %d with fID %d", iDau, cand->GetIDDaughter(iDau) );
+          for(int iRPs=0; iRPs!=fFlowEvent->NumberOfTracks(); ++iRPs ) {
+            AliFlowTrack *iRP = dynamic_cast<AliFlowTrack*>(fFlowEvent->GetTrack( iRPs ));
+            if (!iRP) continue;
+            if( !iRP->InRPSelection() )
+              continue;
+            if( cand->GetIDDaughter(iDau) == iRP->GetID() ) {
+              //printf(" was in RP set");
+              cand->SetDaughter( iDau, iRP );
+              //temporarily untagging all daugters
+              iRP->SetForRPSelection(kFALSE);
+            }
+          }
+          //printf("\n");
+        }
+        fFlowEvent->AddTrack(cand);
+      }
+    }
   }
 
+  if (!fFlowEvent) return; //shuts up coverity
+
   //check final event cuts
-  Int_t mult = flowEvent->NumberOfTracks();
+  Int_t mult = fFlowEvent->NumberOfTracks();
   AliInfo(Form("FlowEvent has %i tracks",mult));
   if (mult<fMinMult || mult>fMaxMult)
   {
@@ -499,7 +503,7 @@ void AliAnalysisTaskFlowEvent::UserExec(Option_t *)
   }
 
   //define dead zone
-  flowEvent->DefineDeadZone(fExcludedEtaMin, fExcludedEtaMax, fExcludedPhiMin, fExcludedPhiMax );
+  fFlowEvent->DefineDeadZone(fExcludedEtaMin, fExcludedEtaMax, fExcludedPhiMin, fExcludedPhiMax );
 
 
   //////////////////////////////////////////////////////////////////////////////
@@ -507,25 +511,20 @@ void AliAnalysisTaskFlowEvent::UserExec(Option_t *)
   if (fAfterburnerOn)
   {
     //if reaction plane not set from elsewhere randomize it before adding flow
-    if (!flowEvent->IsSetMCReactionPlaneAngle())
-      flowEvent->SetMCReactionPlaneAngle(gRandom->Uniform(0.0,TMath::TwoPi()));
+    if (!fFlowEvent->IsSetMCReactionPlaneAngle())
+      fFlowEvent->SetMCReactionPlaneAngle(gRandom->Uniform(0.0,TMath::TwoPi()));
 
-    flowEvent->AddFlow(fV1,fV2,fV3,fV4);     //add flow
-    flowEvent->CloneTracks(fNonFlowNumberOfTrackClones); //add nonflow by cloning tracks
+    fFlowEvent->AddFlow(fV1,fV2,fV3,fV4,fV5);     //add flow
+    fFlowEvent->CloneTracks(fNonFlowNumberOfTrackClones); //add nonflow by cloning tracks
   }
   //////////////////////////////////////////////////////////////////////////////
 
   //tag subEvents
-  flowEvent->TagSubeventsInEta(fMinA,fMaxA,fMinB,fMaxB);
+  fFlowEvent->TagSubeventsInEta(fMinA,fMaxA,fMinB,fMaxB);
 
   //fListHistos->Print();
-  //fOutputFile->WriteObject(flowEvent,"myFlowEventSimple");
-  PostData(1,flowEvent);
-  if (fQA)
-  {
-    PostData(2,fQAInt);
-    PostData(3,fQADiff);
-  }
+  //fOutputFile->WriteObject(fFlowEvent,"myFlowEventSimple");
+  PostData(1,fFlowEvent);
 }
 
 //________________________________________________________________________
@@ -534,12 +533,3 @@ void AliAnalysisTaskFlowEvent::Terminate(Option_t *)
   // Called once at the end of the query -- do not call in case of CAF
 }
 
-//___________________________________________________________
-void AliAnalysisTaskFlowEvent::recalibTOF(AliESDEvent *event)
-{
-       if(!(fTOFresolution>0.0))
-               return;
-       ftofT0maker->SetTimeResolution(fTOFresolution);
-         ftofT0maker->ComputeT0TOF(event);
-       ftofT0maker->WriteInESD(event);
-}