re-organized filter from Laurent
authoragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 7 Feb 2011 10:12:14 +0000 (10:12 +0000)
committeragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 7 Feb 2011 10:12:14 +0000 (10:12 +0000)
ANALYSIS/AliAnalysisTaskESDfilter.cxx
ANALYSIS/AliAnalysisTaskESDfilter.h
ANALYSIS/macros/AddTaskESDFilter.C

index bf92524..4459d19 100644 (file)
@@ -13,7 +13,7 @@
  * provided "as is" without express or implied warranty.                  *\r
  **************************************************************************/\r
 \r
-/* $Id: AliAnalysisTaskESDfilter.cxx 24535 2008-03-16 22:43:30Z fca $ */\r
+/* $Id$ */\r
  \r
 #include <TChain.h>\r
 #include <TTree.h>\r
 #include "AliESDCaloCells.h"\r
 #include "AliMultiplicity.h"\r
 #include "AliLog.h"\r
-#include "AliTrackerBase.h"\r
+#include "AliCodeTimer.h"\r
 #include "AliESDtrackCuts.h"\r
-#include "AliPID.h"\r
\r
+#include "AliESDpid.h"\r
+#include "Riostream.h"\r
+\r
 ClassImp(AliAnalysisTaskESDfilter)\r
 \r
 ////////////////////////////////////////////////////////////////////////\r
@@ -60,51 +61,129 @@ AliAnalysisTaskESDfilter::AliAnalysisTaskESDfilter():
     fKinkFilter(0x0),\r
     fV0Filter(0x0),\r
     fCascadeFilter(0x0),\r
-    fTPCOnlyFilterMask(0),\r
     fHighPthreshold(0),\r
     fPtshape(0x0),\r
     fEnableFillAOD(kTRUE),\r
-    fTimeZeroType(AliESDpid::kTOF_T0)\r
+fUsedTrack(0x0),\r
+fUsedKink(0x0),\r
+fUsedV0(0x0),\r
+fAODTrackRefs(0x0),\r
+fAODV0VtxRefs(0x0),\r
+fAODV0Refs(0x0),\r
+fMChandler(0x0),\r
+fNumberOfTracks(0),\r
+fNumberOfPositiveTracks(0),\r
+fNumberOfV0s(0),\r
+fNumberOfVertices(0),\r
+fNumberOfCascades(0),\r
+fNumberOfKinks(0),\r
+fOldESDformat(kFALSE),\r
+fPrimaryVertex(0x0),\r
+fTPCOnlyFilterMask(0),\r
+fIsVZEROEnabled(kTRUE),\r
+fAreCascadesEnabled(kTRUE),\r
+fAreV0sEnabled(kTRUE),\r
+fAreKinksEnabled(kTRUE),\r
+fAreTracksEnabled(kTRUE),\r
+fArePmdClustersEnabled(kTRUE),\r
+fAreCaloClustersEnabled(kTRUE),\r
+fAreEMCALCellsEnabled(kTRUE),\r
+fArePHOSCellsEnabled(kTRUE),\r
+fAreTrackletsEnabled(kTRUE),\r
+fESDpid(0x0),\r
+fIsPidOwner(kFALSE),\r
+fTimeZeroType(AliESDpid::kTOF_T0)\r
 {\r
   // Default constructor\r
 }\r
 \r
+//______________________________________________________________________________\r
 AliAnalysisTaskESDfilter::AliAnalysisTaskESDfilter(const char* name):\r
     AliAnalysisTaskSE(name),\r
     fTrackFilter(0x0),\r
     fKinkFilter(0x0),\r
     fV0Filter(0x0),\r
     fCascadeFilter(0x0),\r
-    fTPCOnlyFilterMask(0),\r
     fHighPthreshold(0),\r
     fPtshape(0x0),\r
     fEnableFillAOD(kTRUE),\r
-    fTimeZeroType(AliESDpid::kTOF_T0)\r
+fUsedTrack(0x0),\r
+fUsedKink(0x0),\r
+fUsedV0(0x0),\r
+fAODTrackRefs(0x0),\r
+fAODV0VtxRefs(0x0),\r
+fAODV0Refs(0x0),\r
+fMChandler(0x0),\r
+fNumberOfTracks(0),\r
+fNumberOfPositiveTracks(0),\r
+fNumberOfV0s(0),\r
+fNumberOfVertices(0),\r
+fNumberOfCascades(0),\r
+fNumberOfKinks(0),\r
+fOldESDformat(kFALSE),\r
+fPrimaryVertex(0x0),\r
+fTPCOnlyFilterMask(0),\r
+fIsVZEROEnabled(kTRUE),\r
+fAreCascadesEnabled(kTRUE),\r
+fAreV0sEnabled(kTRUE),\r
+fAreKinksEnabled(kTRUE),\r
+fAreTracksEnabled(kTRUE),\r
+fArePmdClustersEnabled(kTRUE),\r
+fAreCaloClustersEnabled(kTRUE),\r
+fAreEMCALCellsEnabled(kTRUE),\r
+fArePHOSCellsEnabled(kTRUE),\r
+fAreTrackletsEnabled(kTRUE),\r
+fESDpid(0x0),\r
+fIsPidOwner(kFALSE),\r
+fTimeZeroType(AliESDpid::kTOF_T0)\r
 {\r
   // Constructor\r
 }\r
 \r
+//______________________________________________________________________________\r
 void AliAnalysisTaskESDfilter::UserCreateOutputObjects()\r
 {\r
   //\r
   // Create Output Objects conenct filter to outputtree\r
   // \r
-  if(OutputTree()){\r
+  if(OutputTree())\r
+  {\r
     OutputTree()->GetUserInfo()->Add(fTrackFilter);\r
   }\r
-  else{\r
+  else\r
+  {\r
     AliError("No OutputTree() for adding the track filter");\r
   }\r
 }\r
 \r
+//______________________________________________________________________________\r
 void AliAnalysisTaskESDfilter::Init()\r
 {\r
-    // Initialization\r
-    if (fDebug > 1) AliInfo("Init() \n");\r
-    // Call configuration file\r
+  // Initialization\r
+  if (fDebug > 1) AliInfo("Init() \n");\r
+  // Call configuration file\r
 }\r
 \r
+//______________________________________________________________________________\r
+void AliAnalysisTaskESDfilter::PrintTask(Option_t *option, Int_t indent) const\r
+{\r
+  AliInfo("");\r
+  \r
+  AliAnalysisTaskSE::PrintTask(option,indent);\r
+  \r
+  TString spaces(' ',indent+3);\r
+  \r
+  cout << spaces.Data() << Form("Cascades     are %s",fAreCascadesEnabled ? "ENABLED":"DISABLED") << endl;\r
+  cout << spaces.Data() << Form("V0s          are %s",fAreV0sEnabled ? "ENABLED":"DISABLED") << endl;\r
+  cout << spaces.Data() << Form("Kinks        are %s",fAreKinksEnabled ? "ENABLED":"DISABLED") << endl;\r
+  cout << spaces.Data() << Form("Tracks       are %s",fAreTracksEnabled ? "ENABLED":"DISABLED") << endl;\r
+  cout << spaces.Data() << Form("PmdClusters  are %s",fArePmdClustersEnabled ? "ENABLED":"DISABLED") << endl;\r
+  cout << spaces.Data() << Form("CaloClusters are %s",fAreCaloClustersEnabled ? "ENABLED":"DISABLED") << endl;\r
+  cout << spaces.Data() << Form("EMCAL cells  are %s",fAreEMCALCellsEnabled ? "ENABLED":"DISABLED") << endl;\r
+  cout << spaces.Data() << Form("Tracklets    are %s",fAreTrackletsEnabled ? "ENABLED":"DISABLED") << endl;  \r
+}\r
 \r
+//______________________________________________________________________________\r
 void AliAnalysisTaskESDfilter::UserExec(Option_t */*option*/)\r
 {\r
 // Execute analysis for current event\r
@@ -124,1262 +203,1410 @@ void AliAnalysisTaskESDfilter::UserExec(Option_t */*option*/)
   ConvertESDtoAOD();\r
 }\r
 \r
-void AliAnalysisTaskESDfilter::ConvertESDtoAOD() {\r
-    // ESD Filter analysis task executed for each event\r
-\r
-    AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());\r
-    if(!esd)return;\r
-    AliESD*      old = esd->GetAliESDOld();\r
+//______________________________________________________________________________\r
+TClonesArray& AliAnalysisTaskESDfilter::Cascades()\r
+{\r
+  return *(AODEvent()->GetCascades());\r
+}\r
 \r
-    // Fetch Stack for debuggging if available \r
-    AliMCEventHandler *mcH = 0;\r
-    if(MCEvent()){\r
-      mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()); \r
-    }\r
-    // set arrays and pointers\r
-    Float_t posF[3];\r
-    Double_t pos[3];\r
-    Double_t p[3];\r
-    Double_t momPos[3]; \r
-    Double_t momNeg[3];\r
-    Double_t momBach[3];\r
-    Double_t momPosAtV0vtx[3];\r
-    Double_t momNegAtV0vtx[3];\r
-    Double_t momBachAtCascadeVtx[3];\r
-    Double_t covVtx[6];\r
-    Double_t covTr[21];\r
-    Double_t pid[10];\r
-\r
-    for (Int_t i = 0; i < 6; i++)  covVtx[i] = 0.;\r
-    for (Int_t i = 0; i < 21; i++) covTr [i] = 0.;\r
-\r
-    \r
-    // loop over events and fill them\r
-    // Multiplicity information needed by the header (to be revised!)\r
-    Int_t nTracks    = esd->GetNumberOfTracks();\r
-    for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) esd->GetTrack(iTrack)->SetESDEvent(esd);\r
-\r
-    //    if (fDebug > 0) printf("-------------------Bo: Number of ESD tracks %d \n",nTracks);\r
-\r
-    Int_t nPosTracks = 0;\r
-    \r
-    // Update the header\r
-\r
-    AliAODHeader* header = AODEvent()->GetHeader();\r
-    \r
-    header->SetRunNumber(esd->GetRunNumber());\r
-    header->SetOfflineTrigger(fInputHandler->IsEventSelected()); // propagate the decision of the physics selection\r
-    TTree* tree = fInputHandler->GetTree();\r
-    if (tree) {\r
-       TFile* file = tree->GetCurrentFile();\r
-       if (file) header->SetESDFileName(file->GetName());\r
-    }\r
-    \r
-    if (old) {\r
-       header->SetBunchCrossNumber(0);\r
-       header->SetOrbitNumber(0);\r
-       header->SetPeriodNumber(0);\r
-       header->SetEventType(0);\r
-       header->SetMuonMagFieldScale(-999.);\r
-       header->SetCentrality(0);       \r
-    } else {\r
-       header->SetBunchCrossNumber(esd->GetBunchCrossNumber());\r
-       header->SetOrbitNumber(esd->GetOrbitNumber());\r
-       header->SetPeriodNumber(esd->GetPeriodNumber());\r
-       header->SetEventType(esd->GetEventType());\r
-\r
-       header->SetEventNumberESDFile(esd->GetHeader()->GetEventNumberInFile());\r
-       if(esd->GetCentrality()){\r
-         header->SetCentrality(new AliCentrality(*(esd->GetCentrality())));\r
-       }\r
-       else{\r
-         header->SetCentrality(0);\r
-       }\r
-    }\r
-    \r
-    // Trigger\r
-    header->SetFiredTriggerClasses(esd->GetFiredTriggerClasses());\r
-    header->SetTriggerMask(esd->GetTriggerMask()); \r
-    header->SetTriggerCluster(esd->GetTriggerCluster());\r
-    header->SetL0TriggerInputs(esd->GetHeader()->GetL0TriggerInputs());    \r
-    header->SetL1TriggerInputs(esd->GetHeader()->GetL1TriggerInputs());    \r
-    header->SetL2TriggerInputs(esd->GetHeader()->GetL2TriggerInputs());    \r
-\r
-    header->SetMagneticField(esd->GetMagneticField());\r
-    header->SetMuonMagFieldScale(esd->GetCurrentDip()/6000.);\r
-    header->SetZDCN1Energy(esd->GetZDCN1Energy());\r
-    header->SetZDCP1Energy(esd->GetZDCP1Energy());\r
-    header->SetZDCN2Energy(esd->GetZDCN2Energy());\r
-    header->SetZDCP2Energy(esd->GetZDCP2Energy());\r
-    header->SetZDCEMEnergy(esd->GetZDCEMEnergy(0),esd->GetZDCEMEnergy(1));\r
-\r
-    \r
-    Float_t diamxy[2]={esd->GetDiamondX(),esd->GetDiamondY()};\r
-    Float_t diamcov[3]; esd->GetDiamondCovXY(diamcov);\r
-    header->SetDiamond(diamxy,diamcov);\r
-    header->SetDiamondZ(esd->GetDiamondZ(),esd->GetSigma2DiamondZ());\r
-//\r
-//  VZERO\r
-    AliAODVZERO* vzeroData = AODEvent()->GetVZEROData();\r
-    *vzeroData = *esd->GetVZEROData();\r
-//\r
-//\r
-    Int_t nV0s      = esd->GetNumberOfV0s();\r
-    Int_t nCascades = 0; // esd->GetNumberOfCascades();\r
-    Int_t nKinks    = 0; // esd->GetNumberOfKinks();\r
-    Int_t nVertices = nV0s + nCascades /*V0 wihtin cascade already counted*/+ nKinks + 1 /* = prim. vtx*/;\r
-    Int_t nPileSPDVertices=1+esd->GetNumberOfPileupVerticesSPD(); // also SPD main vertex\r
-    Int_t nPileTrkVertices=esd->GetNumberOfPileupVerticesTracks();\r
-    nVertices+=nPileSPDVertices;\r
-    nVertices+=nPileTrkVertices;\r
-    Int_t nJets     = 0;\r
-    Int_t nCaloClus = esd->GetNumberOfCaloClusters();\r
-    Int_t nFmdClus  = 0;\r
-    Int_t nPmdClus  = esd->GetNumberOfPmdTracks();\r
-    \r
-    if (fDebug > 0) \r
-       printf("   NV0=%d  NCASCADES=%d  NKINKS=%d\n", nV0s, nCascades, nKinks);\r
-       \r
-    AODEvent()->ResetStd(nTracks, nVertices, nV0s, nCascades, nJets, nCaloClus, nFmdClus, nPmdClus);\r
+//______________________________________________________________________________\r
+TClonesArray& AliAnalysisTaskESDfilter::Tracks()\r
+{\r
+  return *(AODEvent()->GetTracks());\r
+}\r
 \r
+//______________________________________________________________________________\r
+TClonesArray& AliAnalysisTaskESDfilter::V0s()\r
+{\r
+  return *(AODEvent()->GetV0s());\r
+}\r
 \r
-    AliAODTrack   *aodTrack       = 0x0;\r
-    AliAODPid     *detpid         = 0x0;\r
-    //    Double_t      timezero        = 0;   //not needed anymore \r
-    AliAODVertex  *vV0FromCascade = 0x0;\r
-    AliAODv0      *aodV0          = 0x0;\r
-    AliAODcascade *aodCascade     = 0x0;\r
-    \r
-    // RefArray to store the mapping between esd track number and newly created AOD-Track\r
-    TRefArray   *aodTrackRefs = NULL;\r
-    if (nTracks > 0) aodTrackRefs = new TRefArray(nTracks);\r
+//______________________________________________________________________________\r
+TClonesArray& AliAnalysisTaskESDfilter::Vertices()\r
+{\r
+  return *(AODEvent()->GetVertices());\r
+}\r
 \r
-    // RefArray to store a mapping between esd V0 number and newly created AOD-Vertex V0\r
-    TRefArray   *aodV0VtxRefs = NULL;\r
-    if (nV0s > 0) aodV0VtxRefs = new TRefArray(nV0s);\r
+//______________________________________________________________________________\r
+AliAODHeader* AliAnalysisTaskESDfilter::ConvertHeader(const AliESDEvent& esd)\r
+{\r
+  AliCodeTimerAuto("",0);\r
+  \r
+  AliAODHeader* header = AODEvent()->GetHeader();\r
+  \r
+  header->SetRunNumber(esd.GetRunNumber());\r
+  header->SetOfflineTrigger(fInputHandler->IsEventSelected()); // propagate the decision of the physics selection\r
 \r
-    // RefArray to store the mapping between esd V0 number and newly created AOD-V0\r
-    TRefArray   *aodV0Refs = NULL;\r
-    if (nV0s > 0) aodV0Refs = new TRefArray(nV0s);\r
-\r
-    // Array to take into account the tracks already added to the AOD\r
-    Bool_t * usedTrack = NULL;\r
-    if (nTracks>0) {\r
-       usedTrack = new Bool_t[nTracks];\r
-       for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) usedTrack[iTrack]=kFALSE;\r
-    }\r
-    // Array to take into account the V0s already added to the AOD (V0 within cascades)\r
-    Bool_t * usedV0 = NULL;\r
-    if (nV0s>0) {\r
-       usedV0 = new Bool_t[nV0s];\r
-       for (Int_t iV0=0; iV0<nV0s; ++iV0) usedV0[iV0]=kFALSE;\r
-    }\r
-    // Array to take into account the kinks already added to the AOD\r
-    Bool_t * usedKink = NULL;\r
-    if (nKinks>0) {\r
-       usedKink = new Bool_t[nKinks];\r
-       for (Int_t iKink=0; iKink<nKinks; ++iKink) usedKink[iKink]=kFALSE;\r
-    }\r
+  TTree* tree = fInputHandler->GetTree();\r
+  if (tree) {\r
+    TFile* file = tree->GetCurrentFile();\r
+    if (file) header->SetESDFileName(file->GetName());\r
+  }\r
+  \r
+  if (fOldESDformat) {\r
+    header->SetBunchCrossNumber(0);\r
+    header->SetOrbitNumber(0);\r
+    header->SetPeriodNumber(0);\r
+    header->SetEventType(0);\r
+    header->SetMuonMagFieldScale(-999.);\r
+    header->SetCentrality(0);       \r
+  } else {\r
+    header->SetBunchCrossNumber(esd.GetBunchCrossNumber());\r
+    header->SetOrbitNumber(esd.GetOrbitNumber());\r
+    header->SetPeriodNumber(esd.GetPeriodNumber());\r
+    header->SetEventType(esd.GetEventType());\r
     \r
-    // Access to the AOD container of vertices\r
-    TClonesArray &vertices = *(AODEvent()->GetVertices());\r
-    Int_t jVertices=0;\r
-    \r
-    // Access to the AOD container of tracks\r
-    TClonesArray &tracks = *(AODEvent()->GetTracks());\r
-    Int_t jTracks=0; \r
-    \r
-    // Access to the AOD container of Cascades\r
-    TClonesArray &cascades = *(AODEvent()->GetCascades());\r
-    Int_t jCascades=0;\r
-\r
-    // Access to the AOD container of V0s\r
-    TClonesArray &v0s = *(AODEvent()->GetV0s());\r
-    Int_t jV0s=0;\r
-    \r
-    // Add primary vertex. The primary tracks will be defined\r
-    // after the loops on the composite objects (V0, cascades, kinks)\r
-    const AliESDVertex *vtx = esd->GetPrimaryVertex();\r
-    \r
-    vtx->GetXYZ(pos); // position\r
-    vtx->GetCovMatrix(covVtx); //covariance matrix\r
-    \r
-    AliAODVertex * primary = new(vertices[jVertices++])\r
-       AliAODVertex(pos, covVtx, vtx->GetChi2toNDF(), NULL, -1, AliAODVertex::kPrimary);\r
-    primary->SetName(vtx->GetName());\r
-    primary->SetTitle(vtx->GetTitle());\r
-\r
-    TString vtitle = vtx->GetTitle();\r
-    if (!vtitle.Contains("VertexerTracks")) \r
-      primary->SetNContributors(vtx->GetNContributors());\r
-\r
-    if (fDebug > 0) primary->Print();\r
-\r
-\r
-    // Add SPD "main" vertex \r
-    const AliESDVertex *vtxS = esd->GetPrimaryVertexSPD();\r
-    vtxS->GetXYZ(pos); // position\r
-    vtxS->GetCovMatrix(covVtx); //covariance matrix\r
-    AliAODVertex * mVSPD = new(vertices[jVertices++])\r
-      AliAODVertex(pos, covVtx, vtxS->GetChi2toNDF(), NULL, -1, AliAODVertex::kMainSPD);\r
-    mVSPD->SetName(vtxS->GetName());\r
-    mVSPD->SetTitle(vtxS->GetTitle());\r
-    mVSPD->SetNContributors(vtxS->GetNContributors()); \r
-\r
-    // Add SPD pileup vertices\r
-    for(Int_t iV=0; iV<nPileSPDVertices-1; iV++){\r
-      const AliESDVertex *vtxP = esd->GetPileupVertexSPD(iV);\r
-      vtxP->GetXYZ(pos); // position\r
-      vtxP->GetCovMatrix(covVtx); //covariance matrix\r
-      AliAODVertex * pVSPD =  new(vertices[jVertices++])\r
-       AliAODVertex(pos, covVtx, vtxP->GetChi2toNDF(), NULL, -1, AliAODVertex::kPileupSPD);\r
-      pVSPD->SetName(vtxP->GetName());\r
-      pVSPD->SetTitle(vtxP->GetTitle());\r
-      pVSPD->SetNContributors(vtxP->GetNContributors()); \r
+    header->SetEventNumberESDFile(esd.GetHeader()->GetEventNumberInFile());\r
+    if(const_cast<AliESDEvent&>(esd).GetCentrality()){\r
+      header->SetCentrality(new AliCentrality(*(const_cast<AliESDEvent&>(esd).GetCentrality())));\r
     }\r
-\r
-    // Add TRK pileup vertices\r
-    for(Int_t iV=0; iV<nPileTrkVertices; iV++){\r
-      const AliESDVertex *vtxP = esd->GetPileupVertexTracks(iV);\r
-      vtxP->GetXYZ(pos); // position\r
-      vtxP->GetCovMatrix(covVtx); //covariance matrix\r
-      AliAODVertex * pVTRK = new(vertices[jVertices++])\r
-       AliAODVertex(pos, covVtx, vtxP->GetChi2toNDF(), NULL, -1, AliAODVertex::kPileupTracks);\r
-      pVTRK->SetName(vtxP->GetName());\r
-      pVTRK->SetTitle(vtxP->GetTitle());\r
-      pVTRK->SetNContributors(vtxP->GetNContributors());\r
+    else{\r
+      header->SetCentrality(0);\r
     }\r
+  }\r
+  \r
+  // Trigger\r
+  header->SetFiredTriggerClasses(esd.GetFiredTriggerClasses());\r
+  header->SetTriggerMask(esd.GetTriggerMask()); \r
+  header->SetTriggerCluster(esd.GetTriggerCluster());\r
+  header->SetL0TriggerInputs(esd.GetHeader()->GetL0TriggerInputs());    \r
+  header->SetL1TriggerInputs(esd.GetHeader()->GetL1TriggerInputs());    \r
+  header->SetL2TriggerInputs(esd.GetHeader()->GetL2TriggerInputs());    \r
+  \r
+  header->SetMagneticField(esd.GetMagneticField());\r
+  header->SetMuonMagFieldScale(esd.GetCurrentDip()/6000.);\r
+  header->SetZDCN1Energy(esd.GetZDCN1Energy());\r
+  header->SetZDCP1Energy(esd.GetZDCP1Energy());\r
+  header->SetZDCN2Energy(esd.GetZDCN2Energy());\r
+  header->SetZDCP2Energy(esd.GetZDCP2Energy());\r
+  header->SetZDCEMEnergy(esd.GetZDCEMEnergy(0),esd.GetZDCEMEnergy(1));\r
+  \r
+  \r
+  Float_t diamxy[2]={esd.GetDiamondX(),esd.GetDiamondY()};\r
+  Float_t diamcov[3]; \r
+  esd.GetDiamondCovXY(diamcov);\r
+  header->SetDiamond(diamxy,diamcov);\r
+  header->SetDiamondZ(esd.GetDiamondZ(),esd.GetSigma2DiamondZ());\r
+  \r
+  return header;\r
+}\r
 \r
-    // Create vertices starting from the most complex objects\r
-    Double_t chi2 = 0.;\r
-\r
-\r
-    //setting best TOF PID\r
-    AliESDInputHandler* handler = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());\r
+//______________________________________________________________________________\r
+void AliAnalysisTaskESDfilter::ConvertCascades(const AliESDEvent& esd) \r
+{\r
+  // Convert the cascades part of the ESD.\r
+  // Return the number of cascades\r
\r
+  AliCodeTimerAuto("",0);\r
+  \r
+  // Create vertices starting from the most complex objects\r
+  Double_t chi2 = 0.;\r
+  \r
+  const AliESDVertex* vtx = esd.GetPrimaryVertex();\r
+  Double_t pos[3] = { 0. };\r
+  Double_t covVtx[6] = { 0. };\r
+  Double_t momBach[3]={0.};\r
+  Double_t covTr[21]={0.};\r
+  Double_t pid[10]={0.};\r
+  AliAODPid* detpid(0x0);\r
+  AliAODVertex* vV0FromCascade(0x0);\r
+  AliAODv0* aodV0(0x0);\r
+  AliAODcascade* aodCascade(0x0);\r
+  AliAODTrack* aodTrack(0x0);\r
+  Double_t momPos[3]={0.};\r
+  Double_t momNeg[3] = { 0. };\r
+  Double_t momPosAtV0vtx[3]={0.};\r
+  Double_t momNegAtV0vtx[3]={0.};\r
+\r
+  TClonesArray& verticesArray = Vertices();\r
+  TClonesArray& tracksArray = Tracks();\r
+  TClonesArray& cascadesArray = Cascades();\r
+  \r
+  // Cascades (Modified by A.Maire - February 2009)\r
+  for (Int_t nCascade = 0; nCascade < esd.GetNumberOfCascades(); ++nCascade) {\r
     \r
-    AliESDpid *esdPid = 0;\r
-    if (handler) esdPid = handler->GetESDpid();\r
-\r
-    Bool_t isPidOwner = kFALSE;\r
-    if(!esdPid){ //in case of no Tender attached \r
-      esdPid = new AliESDpid;\r
-      isPidOwner = kTRUE;\r
-    }\r
+    // 0- Preparation\r
+    //\r
+    AliESDcascade *esdCascade = esd.GetCascade(nCascade);\r
+               Int_t  idxPosFromV0Dghter  = esdCascade->GetPindex();\r
+               Int_t  idxNegFromV0Dghter  = esdCascade->GetNindex();\r
+               Int_t  idxBachFromCascade  = esdCascade->GetBindex();\r
     \r
-    if(!esd->GetTOFHeader()){ //protection in case the pass2 LHC10b,c,d have been processed without tender. \r
-      Float_t *t0spread= new Float_t[10];\r
-      Float_t intrinsicTOFres=100; //ps ok for LHC10b,c,d pass2!! \r
-      for (Int_t i=0; i<10; i++) t0spread[i] = (TMath::Sqrt(esd->GetSigma2DiamondZ()))/0.03; //0.03 to convert from cm to ps\r
-      esdPid->GetTOFResponse().SetT0resolution(t0spread);\r
-      esdPid->GetTOFResponse().SetTimeResolution(intrinsicTOFres);\r
-      \r
-      esdPid->SetTOFResponse(esd, (AliESDpid::EStartTimeType_t)fTimeZeroType);\r
+    AliESDtrack  *esdCascadePos  = esd.GetTrack( idxPosFromV0Dghter);\r
+    AliESDtrack  *esdCascadeNeg  = esd.GetTrack( idxNegFromV0Dghter);\r
+    AliESDtrack  *esdCascadeBach = esd.GetTrack( idxBachFromCascade);\r
     \r
-      delete[] t0spread;\r
-      t0spread=0x0;\r
+    // Identification of the V0 within the esdCascade (via both daughter track indices)\r
+    AliESDv0 * currentV0   = 0x0;\r
+    Int_t      idxV0FromCascade = -1;\r
+    \r
+    for (Int_t iV0=0; iV0<esd.GetNumberOfV0s(); ++iV0) {\r
+      \r
+      currentV0 = esd.GetV0(iV0);\r
+      Int_t posCurrentV0 = currentV0->GetPindex();\r
+      Int_t negCurrentV0 = currentV0->GetNindex();\r
+      \r
+      if (posCurrentV0==idxPosFromV0Dghter && negCurrentV0==idxNegFromV0Dghter) {\r
+        idxV0FromCascade = iV0;\r
+        break;\r
+      }\r
     }\r
     \r
-    if(esd->GetTOFHeader() && isPidOwner) esdPid->SetTOFResponse(esd, (AliESDpid::EStartTimeType_t)fTimeZeroType); //in case of AOD production strating form LHC10e without Tender. \r
-\r
-\r
-    // Cascades (Modified by A.Maire - February 2009)\r
-    for (Int_t nCascade = 0; nCascade < nCascades; ++nCascade) {\r
+    if(idxV0FromCascade < 0){\r
+      printf("Cascade - no matching for the V0 (index V0 = -1) ! Skip ... \n");\r
+      continue;\r
+    }// a priori, useless check, but safer ... in case of pb with tracks "out of bounds"\r
+    \r
+    AliESDv0 *esdV0FromCascade   = esd.GetV0(idxV0FromCascade);\r
+        \r
+    // 1 - Cascade selection \r
+    \r
+    // AliESDVertex *esdPrimVtx = new AliESDVertex(*(esd.GetPrimaryVertex()));\r
+    //         TList cascadeObjects;\r
+    //         cascadeObjects.AddAt(esdV0FromCascade, 0);\r
+    //         cascadeObjects.AddAt(esdCascadePos,    1);\r
+    //         cascadeObjects.AddAt(esdCascadeNeg,    2);\r
+    //         cascadeObjects.AddAt(esdCascade,       3);\r
+    //         cascadeObjects.AddAt(esdCascadeBach,   4);\r
+    //         cascadeObjects.AddAt(esdPrimVtx,       5);\r
+    // \r
+    //         UInt_t selectCascade = 0;\r
+    //         if (fCascadeFilter) {\r
+    //           // selectCascade = fCascadeFilter->IsSelected(&cascadeObjects); \r
+    //                 // FIXME AliESDCascadeCuts to be implemented ...\r
+    // \r
+    //                 // Here we may encounter a moot point at the V0 level \r
+    //                 // between the cascade selections and the V0 ones :\r
+    //                 // the V0 selected along with the cascade (secondary V0) may \r
+    //                 // usually be removed from the dedicated V0 selections (prim V0) ...\r
+    //                 // -> To be discussed !\r
+    // \r
+    //           // this is a little awkward but otherwise the \r
+    //           // list wants to access the pointer (delete it) \r
+    //           // again when going out of scope\r
+    //           delete cascadeObjects.RemoveAt(5); // esdPrimVtx created via copy construct\r
+    //           esdPrimVtx = 0;\r
+    //           if (!selectCascade) \r
+    //             continue;\r
+    //         }\r
+    //         else{\r
+    //           delete cascadeObjects.RemoveAt(5); // esdPrimVtx created via copy construct\r
+    //           esdPrimVtx = 0;\r
+    //         }\r
+    \r
+    // 2 - Add the cascade vertex\r
+    \r
+    esdCascade->GetXYZcascade(pos[0], pos[1], pos[2]);\r
+    esdCascade->GetPosCovXi(covVtx);\r
+    chi2 = esdCascade->GetChi2Xi(); \r
+    \r
+    AliAODVertex *vCascade = new(verticesArray[fNumberOfVertices++]) AliAODVertex( pos,\r
+                                                                     covVtx,\r
+                                                                     chi2, // FIXME = Chi2/NDF will be needed\r
+                                                                     fPrimaryVertex,\r
+                                                                     nCascade, // id\r
+                                                                     AliAODVertex::kCascade);\r
+    fPrimaryVertex->AddDaughter(vCascade);\r
+    \r
+//    if (fDebug > 2) {\r
+//      printf("---- Cascade / Cascade Vertex (AOD) : \n");\r
+//      vCascade->Print();\r
+//    }\r
+    \r
+    if(esd.GetTOFHeader() && fIsPidOwner) fESDpid->SetTOFResponse(const_cast<AliESDEvent*>(&esd), AliESDpid::kBest_T0); //in case of AOD production strating form LHC10e without Tender. \r
 \r
-       if (fDebug > 1) \r
-       printf("\n ******** Cascade number : %d/%d *********\n", nCascade, nCascades);\r
 \r
-       // 0- Preparation\r
-       //\r
-       AliESDcascade *esdCascade = esd->GetCascade(nCascade);\r
-               Int_t  idxPosFromV0Dghter  = esdCascade->GetPindex();\r
-               Int_t  idxNegFromV0Dghter  = esdCascade->GetNindex();\r
-               Int_t  idxBachFromCascade  = esdCascade->GetBindex();\r
-       \r
-       AliESDtrack  *esdCascadePos  = esd->GetTrack( idxPosFromV0Dghter);\r
-       AliESDtrack  *esdCascadeNeg  = esd->GetTrack( idxNegFromV0Dghter);\r
-       AliESDtrack  *esdCascadeBach = esd->GetTrack( idxBachFromCascade);\r
-\r
-       // Identification of the V0 within the esdCascade (via both daughter track indices)\r
-       AliESDv0 * currentV0   = 0x0;\r
-       Int_t      idxV0FromCascade = -1;\r
-       \r
-       for (Int_t iV0=0; iV0<nV0s; ++iV0) {\r
-       \r
-                        currentV0 = esd->GetV0(iV0);\r
-               Int_t posCurrentV0 = currentV0->GetPindex();\r
-               Int_t negCurrentV0 = currentV0->GetNindex();\r
-       \r
-               if (posCurrentV0==idxPosFromV0Dghter && negCurrentV0==idxNegFromV0Dghter) {\r
-               idxV0FromCascade = iV0;\r
-               break;\r
-               }\r
-       }\r
-\r
-       if(idxV0FromCascade < 0){\r
-               printf("Cascade - no matching for the V0 (index V0 = -1) ! Skip ... \n");\r
-               continue;\r
-       }// a priori, useless check, but safer ... in case of pb with tracks "out of bounds"\r
-\r
-       if (fDebug > 1) \r
-               printf("Cascade %d - V0fromCascade ind : %d/%d\n", nCascade, idxV0FromCascade, nV0s);\r
-\r
-       AliESDv0 *esdV0FromCascade   = esd->GetV0(idxV0FromCascade);\r
-       \r
-\r
-       // 1 - Cascade selection \r
-       \r
-       //      AliESDVertex *esdPrimVtx = new AliESDVertex(*(esd->GetPrimaryVertex()));\r
-       //      TList cascadeObjects;\r
-       //      cascadeObjects.AddAt(esdV0FromCascade, 0);\r
-       //      cascadeObjects.AddAt(esdCascadePos,    1);\r
-       //      cascadeObjects.AddAt(esdCascadeNeg,    2);\r
-       //      cascadeObjects.AddAt(esdCascade,       3);\r
-       //      cascadeObjects.AddAt(esdCascadeBach,   4);\r
-       //      cascadeObjects.AddAt(esdPrimVtx,       5);\r
-       // \r
-       //      UInt_t selectCascade = 0;\r
-       //      if (fCascadeFilter) {\r
-       //        // selectCascade = fCascadeFilter->IsSelected(&cascadeObjects); \r
-       //              // FIXME AliESDCascadeCuts to be implemented ...\r
-       // \r
-       //              // Here we may encounter a moot point at the V0 level \r
-       //              // between the cascade selections and the V0 ones :\r
-       //              // the V0 selected along with the cascade (secondary V0) may \r
-       //              // usually be removed from the dedicated V0 selections (prim V0) ...\r
-       //              // -> To be discussed !\r
-       // \r
-       //        // this is a little awkward but otherwise the \r
-       //        // list wants to access the pointer (delete it) \r
-       //        // again when going out of scope\r
-       //        delete cascadeObjects.RemoveAt(5); // esdPrimVtx created via copy construct\r
-       //        esdPrimVtx = 0;\r
-       //        if (!selectCascade) \r
-       //          continue;\r
-       //      }\r
-       //      else{\r
-       //        delete cascadeObjects.RemoveAt(5); // esdPrimVtx created via copy construct\r
-       //        esdPrimVtx = 0;\r
-       //      }\r
-\r
-       // 2 - Add the cascade vertex\r
-       \r
-       esdCascade->GetXYZcascade(pos[0], pos[1], pos[2]);\r
-       esdCascade->GetPosCovXi(covVtx);\r
-       chi2 = esdCascade->GetChi2Xi(); \r
-       \r
-       AliAODVertex *vCascade = new(vertices[jVertices++]) AliAODVertex( pos,\r
-                                                                         covVtx,\r
-                                                                         chi2, // FIXME = Chi2/NDF will be needed\r
-                                                                         primary,\r
-                                                                         nCascade, // id\r
-                                                                         AliAODVertex::kCascade);\r
-       primary->AddDaughter(vCascade);\r
-\r
-       if (fDebug > 2) {\r
-               printf("---- Cascade / Cascade Vertex (AOD) : \n");\r
-               vCascade->Print();\r
-       }\r
-\r
-\r
-       // 3 - Add the bachelor track from the cascade\r
-       \r
-       if (!usedTrack[idxBachFromCascade]) {\r
-\r
-       esdCascadeBach->GetPxPyPz(momBach);\r
-       esdCascadeBach->GetXYZ(pos);\r
-       esdCascadeBach->GetCovarianceXYZPxPyPz(covTr);\r
-       esdCascadeBach->GetESDpid(pid);\r
-\r
-           usedTrack[idxBachFromCascade] = kTRUE;\r
+    // 3 - Add the bachelor track from the cascade\r
+    \r
+    if (!fUsedTrack[idxBachFromCascade]) {\r
+      \r
+      esdCascadeBach->GetPxPyPz(momBach);\r
+      esdCascadeBach->GetXYZ(pos);\r
+      esdCascadeBach->GetCovarianceXYZPxPyPz(covTr);\r
+      esdCascadeBach->GetESDpid(pid);\r
+      \r
+           fUsedTrack[idxBachFromCascade] = kTRUE;\r
            UInt_t selectInfo = 0;\r
            if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdCascadeBach);\r
-           if(mcH)mcH->SelectParticle(esdCascadeBach->GetLabel());\r
-           aodTrack = new(tracks[jTracks++]) AliAODTrack(esdCascadeBach->GetID(),\r
-                                                         esdCascadeBach->GetLabel(), \r
-                                                         momBach, \r
-                                                         kTRUE,\r
-                                                         pos,\r
-                                                         kFALSE, // Why kFALSE for "isDCA" ? FIXME\r
-                                                         covTr, \r
-                                                         (Short_t)esdCascadeBach->GetSign(),\r
-                                                         esdCascadeBach->GetITSClusterMap(), \r
-                                                         pid,\r
-                                                         vCascade,\r
-                                                         kTRUE,  // usedForVtxFit = kFALSE ? FIXME\r
-                                                         vtx->UsesTrack(esdCascadeBach->GetID()),\r
-                                                         AliAODTrack::kSecondary,\r
-                                                         selectInfo);\r
+           if (fMChandler) fMChandler->SelectParticle(esdCascadeBach->GetLabel());\r
+           aodTrack = new(tracksArray[fNumberOfTracks++]) AliAODTrack(esdCascadeBach->GetID(),\r
+                                                                           esdCascadeBach->GetLabel(), \r
+                                                                           momBach, \r
+                                                                           kTRUE,\r
+                                                                           pos,\r
+                                                                           kFALSE, // Why kFALSE for "isDCA" ? FIXME\r
+                                                                           covTr, \r
+                                                                           (Short_t)esdCascadeBach->GetSign(),\r
+                                                                           esdCascadeBach->GetITSClusterMap(), \r
+                                                                           pid,\r
+                                                                           vCascade,\r
+                                                                           kTRUE,  // usedForVtxFit = kFALSE ? FIXME\r
+                                                                           vtx->UsesTrack(esdCascadeBach->GetID()),\r
+                                                                           AliAODTrack::kSecondary,\r
+                                                                           selectInfo);\r
            aodTrack->SetTPCClusterMap(esdCascadeBach->GetTPCClusterMap());\r
            aodTrack->SetTPCSharedMap (esdCascadeBach->GetTPCSharedMap());\r
            aodTrack->SetChi2perNDF(Chi2perNDF(esdCascadeBach));\r
-           aodTrackRefs->AddAt(aodTrack,idxBachFromCascade);\r
+           fAODTrackRefs->AddAt(aodTrack,idxBachFromCascade);\r
            \r
-           if (esdCascadeBach->GetSign() > 0) nPosTracks++;\r
+           if (esdCascadeBach->GetSign() > 0) ++fNumberOfPositiveTracks;\r
            aodTrack->ConvertAliPIDtoAODPID();\r
            aodTrack->SetFlags(esdCascadeBach->GetStatus());\r
-            SetAODPID(esdCascadeBach,aodTrack,detpid,esd->GetMagneticField(), esdPid);\r
-       }\r
-       else {\r
-           aodTrack = dynamic_cast<AliAODTrack*>( aodTrackRefs->At(idxBachFromCascade) );\r
-       }\r
-\r
-       vCascade->AddDaughter(aodTrack);\r
-\r
-       if (fDebug > 4) {\r
-               printf("---- Cascade / bach dghter : \n");\r
-               aodTrack->Print();\r
-       }\r
-       \r
-\r
-       // 4 - Add the V0 from the cascade. \r
-       // = V0vtx + both pos and neg daughter tracks + the aodV0 itself\r
-       //\r
-\r
-       if ( !usedV0[idxV0FromCascade] ) {\r
-       // 4.A - if VO structure hasn't been created yet\r
-               \r
-               // 4.A.1 - Create the V0 vertex of the cascade\r
-       \r
-               esdV0FromCascade->GetXYZ(pos[0], pos[1], pos[2]);\r
-               esdV0FromCascade->GetPosCov(covVtx);\r
-               chi2 = esdV0FromCascade->GetChi2V0();  // = chi2/NDF since NDF = 2*2-3 ?\r
+      SetAODPID(esdCascadeBach,aodTrack,detpid,esd.GetMagneticField());\r
+    }\r
+    else {\r
+           aodTrack = static_cast<AliAODTrack*>( fAODTrackRefs->At(idxBachFromCascade) );\r
+    }\r
+    \r
+    vCascade->AddDaughter(aodTrack);\r
+    \r
+//    if (fDebug > 4) {\r
+//      printf("---- Cascade / bach dghter : \n");\r
+//      aodTrack->Print();\r
+//    }\r
+    \r
+    \r
+    // 4 - Add the V0 from the cascade. \r
+    // = V0vtx + both pos and neg daughter tracks + the aodV0 itself\r
+    //\r
+    \r
+    if ( !fUsedV0[idxV0FromCascade] ) {\r
+      // 4.A - if VO structure hasn't been created yet\r
+      \r
+      // 4.A.1 - Create the V0 vertex of the cascade\r
+      \r
+      esdV0FromCascade->GetXYZ(pos[0], pos[1], pos[2]);\r
+      esdV0FromCascade->GetPosCov(covVtx);\r
+      chi2 = esdV0FromCascade->GetChi2V0();  // = chi2/NDF since NDF = 2*2-3 ?\r
                        \r
-               vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,\r
-                                                                       covVtx,\r
-                                                                       chi2,\r
-                                                                       vCascade,\r
-                                                                       idxV0FromCascade, //id of ESDv0\r
-                                                                       AliAODVertex::kV0);\r
-               // Note:\r
-               //    one V0 can be used by several cascades.\r
-               // So, one AOD V0 vtx can have several parent vtx.\r
-               // This is not directly allowed by AliAODvertex.\r
-               // Setting the parent vtx (here = param "vCascade") doesn't lead to a crash\r
-               // but to a problem of consistency within AODEvent.\r
-               // -> See below paragraph 4.B, for the proposed treatment of such a case.\r
-\r
-               // Add the vV0FromCascade to the aodVOVtxRefs\r
-               aodV0VtxRefs->AddAt(vV0FromCascade,idxV0FromCascade);\r
-               \r
-               \r
-               // 4.A.2 - Add the positive tracks from the V0\r
-               \r
-               esdCascadePos->GetPxPyPz(momPos);\r
-               esdCascadePos->GetXYZ(pos);\r
-               esdCascadePos->GetCovarianceXYZPxPyPz(covTr);\r
-               esdCascadePos->GetESDpid(pid);\r
-               \r
-       \r
-               if (!usedTrack[idxPosFromV0Dghter]) {\r
-               usedTrack[idxPosFromV0Dghter] = kTRUE;\r
-       \r
-               UInt_t selectInfo = 0;\r
-               if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdCascadePos);\r
-               if(mcH) mcH->SelectParticle(esdCascadePos->GetLabel());\r
-               aodTrack = new(tracks[jTracks++]) AliAODTrack(  esdCascadePos->GetID(),\r
-                                                               esdCascadePos->GetLabel(), \r
-                                                               momPos, \r
-                                                               kTRUE,\r
-                                                               pos,\r
-                                                               kFALSE, // Why kFALSE for "isDCA" ? FIXME\r
-                                                               covTr, \r
-                                                               (Short_t)esdCascadePos->GetSign(),\r
-                                                               esdCascadePos->GetITSClusterMap(), \r
-                                                               pid,\r
-                                                               vV0FromCascade,\r
-                                                               kTRUE,  // usedForVtxFit = kFALSE ? FIXME\r
-                                                               vtx->UsesTrack(esdCascadePos->GetID()),\r
-                                                               AliAODTrack::kSecondary,\r
-                                                               selectInfo);\r
-               aodTrack->SetTPCClusterMap(esdCascadePos->GetTPCClusterMap());\r
-               aodTrack->SetTPCSharedMap (esdCascadePos->GetTPCSharedMap());\r
-               aodTrack->SetChi2perNDF(Chi2perNDF(esdCascadePos));\r
-               aodTrackRefs->AddAt(aodTrack,idxPosFromV0Dghter);\r
-\r
-               if (esdCascadePos->GetSign() > 0) nPosTracks++;\r
-               aodTrack->ConvertAliPIDtoAODPID();\r
-               aodTrack->SetFlags(esdCascadePos->GetStatus());\r
-               SetAODPID(esdCascadePos,aodTrack,detpid,esd->GetMagneticField(), esdPid);\r
-               }\r
-               else {\r
-                       aodTrack = dynamic_cast<AliAODTrack*>(aodTrackRefs->At(idxPosFromV0Dghter));\r
-               }\r
-               vV0FromCascade->AddDaughter(aodTrack);\r
-       \r
-       \r
-               // 4.A.3 - Add the negative tracks from the V0\r
-               \r
-               esdCascadeNeg->GetPxPyPz(momNeg);\r
-               esdCascadeNeg->GetXYZ(pos);\r
-               esdCascadeNeg->GetCovarianceXYZPxPyPz(covTr);\r
-               esdCascadeNeg->GetESDpid(pid);\r
-               \r
-               \r
-               if (!usedTrack[idxNegFromV0Dghter]) {\r
-               usedTrack[idxNegFromV0Dghter] = kTRUE;\r
-       \r
-               UInt_t selectInfo = 0;\r
-               if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdCascadeNeg);\r
-               if(mcH)mcH->SelectParticle(esdCascadeNeg->GetLabel());\r
-               aodTrack = new(tracks[jTracks++]) AliAODTrack(  esdCascadeNeg->GetID(),\r
-                                                               esdCascadeNeg->GetLabel(),\r
-                                                               momNeg,\r
-                                                               kTRUE,\r
-                                                               pos,\r
-                                                               kFALSE, // Why kFALSE for "isDCA" ? FIXME\r
-                                                               covTr, \r
-                                                               (Short_t)esdCascadeNeg->GetSign(),\r
-                                                               esdCascadeNeg->GetITSClusterMap(), \r
-                                                               pid,\r
-                                                               vV0FromCascade,\r
-                                                               kTRUE,  // usedForVtxFit = kFALSE ? FIXME\r
-                                                               vtx->UsesTrack(esdCascadeNeg->GetID()),\r
-                                                               AliAODTrack::kSecondary,\r
-                                                               selectInfo);\r
-               aodTrack->SetTPCClusterMap(esdCascadeNeg->GetTPCClusterMap());\r
-               aodTrack->SetTPCSharedMap (esdCascadeNeg->GetTPCSharedMap());\r
-               aodTrack->SetChi2perNDF(Chi2perNDF(esdCascadeNeg));\r
-               aodTrackRefs->AddAt(aodTrack,idxNegFromV0Dghter);\r
-               \r
-               if (esdCascadeNeg->GetSign() > 0) nPosTracks++;\r
-               aodTrack->ConvertAliPIDtoAODPID();\r
-               aodTrack->SetFlags(esdCascadeNeg->GetStatus());\r
-               SetAODPID(esdCascadeNeg,aodTrack,detpid,esd->GetMagneticField(),esdPid);\r
-               }\r
-               else {\r
-                       aodTrack = dynamic_cast<AliAODTrack*>(aodTrackRefs->At(idxNegFromV0Dghter));\r
-               }\r
-       \r
-               vV0FromCascade->AddDaughter(aodTrack);\r
-       \r
+      vV0FromCascade = new(verticesArray[fNumberOfVertices++]) AliAODVertex(pos,\r
+                                                                         covVtx,\r
+                                                                         chi2,\r
+                                                                         vCascade,\r
+                                                                         idxV0FromCascade, //id of ESDv0\r
+                                                                         AliAODVertex::kV0);\r
+      // Note:\r
+      //    one V0 can be used by several cascades.\r
+      // So, one AOD V0 vtx can have several parent vtx.\r
+      // This is not directly allowed by AliAODvertex.\r
+      // Setting the parent vtx (here = param "vCascade") doesn't lead to a crash\r
+      // but to a problem of consistency within AODEvent.\r
+      // -> See below paragraph 4.B, for the proposed treatment of such a case.\r
+      \r
+      // Add the vV0FromCascade to the aodVOVtxRefs\r
+      fAODV0VtxRefs->AddAt(vV0FromCascade,idxV0FromCascade);\r
+      \r
+      \r
+      // 4.A.2 - Add the positive tracks from the V0\r
+      \r
+      esdCascadePos->GetPxPyPz(momPos);\r
+      esdCascadePos->GetXYZ(pos);\r
+      esdCascadePos->GetCovarianceXYZPxPyPz(covTr);\r
+      esdCascadePos->GetESDpid(pid);\r
+      \r
+      \r
+      if (!fUsedTrack[idxPosFromV0Dghter]) {\r
+        fUsedTrack[idxPosFromV0Dghter] = kTRUE;\r
+        \r
+        UInt_t selectInfo = 0;\r
+        if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdCascadePos);\r
+        if(fMChandler) fMChandler->SelectParticle(esdCascadePos->GetLabel());\r
+        aodTrack = new(tracksArray[fNumberOfTracks++]) \r
+        AliAODTrack(  esdCascadePos->GetID(),\r
+                    esdCascadePos->GetLabel(), \r
+                    momPos, \r
+                    kTRUE,\r
+                    pos,\r
+                    kFALSE, // Why kFALSE for "isDCA" ? FIXME\r
+                    covTr, \r
+                    (Short_t)esdCascadePos->GetSign(),\r
+                    esdCascadePos->GetITSClusterMap(), \r
+                    pid,\r
+                    vV0FromCascade,\r
+                    kTRUE,  // usedForVtxFit = kFALSE ? FIXME\r
+                    vtx->UsesTrack(esdCascadePos->GetID()),\r
+                    AliAODTrack::kSecondary,\r
+                    selectInfo);\r
+        aodTrack->SetTPCClusterMap(esdCascadePos->GetTPCClusterMap());\r
+        aodTrack->SetTPCSharedMap (esdCascadePos->GetTPCSharedMap());\r
+        aodTrack->SetChi2perNDF(Chi2perNDF(esdCascadePos));\r
+        fAODTrackRefs->AddAt(aodTrack,idxPosFromV0Dghter);\r
+        \r
+        if (esdCascadePos->GetSign() > 0) ++fNumberOfPositiveTracks;\r
+        aodTrack->ConvertAliPIDtoAODPID();\r
+        aodTrack->SetFlags(esdCascadePos->GetStatus());\r
+        SetAODPID(esdCascadePos,aodTrack,detpid,esd.GetMagneticField());\r
+      }\r
+      else {\r
+        aodTrack = static_cast<AliAODTrack*>(fAODTrackRefs->At(idxPosFromV0Dghter));\r
+      }\r
+      vV0FromCascade->AddDaughter(aodTrack);\r
+      \r
+      \r
+      // 4.A.3 - Add the negative tracks from the V0\r
+      \r
+      esdCascadeNeg->GetPxPyPz(momNeg);\r
+      esdCascadeNeg->GetXYZ(pos);\r
+      esdCascadeNeg->GetCovarianceXYZPxPyPz(covTr);\r
+      esdCascadeNeg->GetESDpid(pid);\r
+      \r
+      \r
+      if (!fUsedTrack[idxNegFromV0Dghter]) {\r
+        fUsedTrack[idxNegFromV0Dghter] = kTRUE;\r
+        \r
+        UInt_t selectInfo = 0;\r
+        if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdCascadeNeg);\r
+        if(fMChandler)fMChandler->SelectParticle(esdCascadeNeg->GetLabel());\r
+        aodTrack = new(tracksArray[fNumberOfTracks++]) AliAODTrack(  esdCascadeNeg->GetID(),\r
+                                                      esdCascadeNeg->GetLabel(),\r
+                                                      momNeg,\r
+                                                      kTRUE,\r
+                                                      pos,\r
+                                                      kFALSE, // Why kFALSE for "isDCA" ? FIXME\r
+                                                      covTr, \r
+                                                      (Short_t)esdCascadeNeg->GetSign(),\r
+                                                      esdCascadeNeg->GetITSClusterMap(), \r
+                                                      pid,\r
+                                                      vV0FromCascade,\r
+                                                      kTRUE,  // usedForVtxFit = kFALSE ? FIXME\r
+                                                      vtx->UsesTrack(esdCascadeNeg->GetID()),\r
+                                                      AliAODTrack::kSecondary,\r
+                                                      selectInfo);\r
+        aodTrack->SetTPCClusterMap(esdCascadeNeg->GetTPCClusterMap());\r
+        aodTrack->SetTPCSharedMap (esdCascadeNeg->GetTPCSharedMap());\r
+        aodTrack->SetChi2perNDF(Chi2perNDF(esdCascadeNeg));\r
+        fAODTrackRefs->AddAt(aodTrack,idxNegFromV0Dghter);\r
+        \r
+        if (esdCascadeNeg->GetSign() > 0) ++fNumberOfPositiveTracks;\r
+        aodTrack->ConvertAliPIDtoAODPID();\r
+        aodTrack->SetFlags(esdCascadeNeg->GetStatus());\r
+        SetAODPID(esdCascadeNeg,aodTrack,detpid,esd.GetMagneticField());\r
+      }\r
+      else {\r
+        aodTrack = static_cast<AliAODTrack*>(fAODTrackRefs->At(idxNegFromV0Dghter));\r
+      }\r
+      \r
+      vV0FromCascade->AddDaughter(aodTrack);\r
+      \r
                        \r
-               // 4.A.4 - Add the V0 from cascade to the V0 array\r
-\r
-               Double_t  dcaV0Daughters      = esdV0FromCascade->GetDcaV0Daughters();\r
-               Double_t  dcaV0ToPrimVertex   = esdV0FromCascade->GetD( esd->GetPrimaryVertex()->GetX(),\r
-                                                                       esd->GetPrimaryVertex()->GetY(),\r
-                                                                       esd->GetPrimaryVertex()->GetZ() );\r
-               esdV0FromCascade->GetPPxPyPz( momPosAtV0vtx[0],momPosAtV0vtx[1],momPosAtV0vtx[2] ); \r
-               esdV0FromCascade->GetNPxPyPz( momNegAtV0vtx[0],momNegAtV0vtx[1],momNegAtV0vtx[2] ); \r
-       \r
-               Double_t dcaDaughterToPrimVertex[2] = { 999., 999.}; // ..[0] = DCA in (x,y) for Pos and ..[1] = Neg\r
-               dcaDaughterToPrimVertex[0] = TMath::Abs(esdCascadePos->GetD(    esd->GetPrimaryVertex()->GetX(),\r
-                                                                               esd->GetPrimaryVertex()->GetY(),\r
-                                                                               esd->GetMagneticField())        );\r
-               dcaDaughterToPrimVertex[1] = TMath::Abs(esdCascadeNeg->GetD(    esd->GetPrimaryVertex()->GetX(),\r
-                                                                               esd->GetPrimaryVertex()->GetY(),\r
-                                                                               esd->GetMagneticField())        );\r
-               \r
-               aodV0 = new(v0s[jV0s++]) AliAODv0( vV0FromCascade, \r
-                                                  dcaV0Daughters,\r
-                                                  dcaV0ToPrimVertex, \r
-                                                  momPosAtV0vtx, \r
-                                                  momNegAtV0vtx, \r
-                                                  dcaDaughterToPrimVertex); \r
-               // set the aod v0 on-the-fly status\r
-               aodV0->SetOnFlyStatus(esdV0FromCascade->GetOnFlyStatus());\r
-\r
-               // Add the aodV0 to the aodVORefs\r
-               aodV0Refs->AddAt(aodV0,idxV0FromCascade);\r
-               \r
-       usedV0[idxV0FromCascade] = kTRUE;\r
-\r
-       } else { \r
-       // 4.B - if V0 structure already used\r
-\r
-               // Note :\r
-               //    one V0 can be used by several cascades (frequent in PbPb evts) : \r
-               // same V0 which used but attached to different bachelor tracks\r
-               // -> aodVORefs and aodV0VtxRefs are needed.\r
-               // Goal : avoid a redundancy of the info in "Vertices" and "v0s" clones array.\r
-       \r
-               vV0FromCascade = dynamic_cast<AliAODVertex*>( aodV0VtxRefs->At(idxV0FromCascade) );\r
-               aodV0          = dynamic_cast<AliAODv0*>    ( aodV0Refs   ->At(idxV0FromCascade) );\r
-                \r
-               // - Treatment of the parent for such a "re-used" V0 :\r
-               // Insert the cascade that reuses the V0 vertex in the lineage chain\r
-               // Before : vV0 -> vCascade1 -> vPrimary\r
-               //  - Hyp : cascade2 uses the same V0 as cascade1\r
-               //  After :  vV0 -> vCascade2 -> vCascade1 -> vPrimary\r
-               \r
-               AliAODVertex *vCascadePreviousParent = dynamic_cast<AliAODVertex*> (vV0FromCascade->GetParent());\r
+      // 4.A.4 - Add the V0 from cascade to the V0 array\r
+      \r
+      Double_t  dcaV0Daughters      = esdV0FromCascade->GetDcaV0Daughters();\r
+      Double_t  dcaV0ToPrimVertex   = esdV0FromCascade->GetD( esd.GetPrimaryVertex()->GetX(),\r
+                                                             esd.GetPrimaryVertex()->GetY(),\r
+                                                             esd.GetPrimaryVertex()->GetZ() );\r
+      esdV0FromCascade->GetPPxPyPz( momPosAtV0vtx[0],momPosAtV0vtx[1],momPosAtV0vtx[2] ); \r
+      esdV0FromCascade->GetNPxPyPz( momNegAtV0vtx[0],momNegAtV0vtx[1],momNegAtV0vtx[2] ); \r
+      \r
+      Double_t dcaDaughterToPrimVertex[2] = { 999., 999.}; // ..[0] = DCA in (x,y) for Pos and ..[1] = Neg\r
+      dcaDaughterToPrimVertex[0] = TMath::Abs(esdCascadePos->GetD(     esd.GetPrimaryVertex()->GetX(),\r
+                                                                  esd.GetPrimaryVertex()->GetY(),\r
+                                                                  esd.GetMagneticField())        );\r
+      dcaDaughterToPrimVertex[1] = TMath::Abs(esdCascadeNeg->GetD(     esd.GetPrimaryVertex()->GetX(),\r
+                                                                  esd.GetPrimaryVertex()->GetY(),\r
+                                                                  esd.GetMagneticField())        );\r
+      \r
+      aodV0 = new(V0s()[fNumberOfV0s++]) AliAODv0( vV0FromCascade, \r
+                                                  dcaV0Daughters,\r
+                                                  dcaV0ToPrimVertex, \r
+                                                  momPosAtV0vtx, \r
+                                                  momNegAtV0vtx, \r
+                                                  dcaDaughterToPrimVertex); \r
+      // set the aod v0 on-the-fly status\r
+      aodV0->SetOnFlyStatus(esdV0FromCascade->GetOnFlyStatus());\r
+      \r
+      // Add the aodV0 to the aodVORefs\r
+      fAODV0Refs->AddAt(aodV0,idxV0FromCascade);\r
+      \r
+      fUsedV0[idxV0FromCascade] = kTRUE;\r
+      \r
+    } else { \r
+      // 4.B - if V0 structure already used\r
+      \r
+      // Note :\r
+      //    one V0 can be used by several cascades (frequent in PbPb evts) : \r
+      // same V0 which used but attached to different bachelor tracks\r
+      // -> aodVORefs and fAODV0VtxRefs are needed.\r
+      // Goal : avoid a redundancy of the info in "Vertices" and "v0s" clones array.\r
+      \r
+      vV0FromCascade = static_cast<AliAODVertex*>( fAODV0VtxRefs->At(idxV0FromCascade) );\r
+      aodV0          = static_cast<AliAODv0*>    ( fAODV0Refs   ->At(idxV0FromCascade) );\r
+      \r
+      // - Treatment of the parent for such a "re-used" V0 :\r
+      // Insert the cascade that reuses the V0 vertex in the lineage chain\r
+      // Before : vV0 -> vCascade1 -> vPrimary\r
+      //  - Hyp : cascade2 uses the same V0 as cascade1\r
+      //  After :  vV0 -> vCascade2 -> vCascade1 -> vPrimary\r
+      \r
+      AliAODVertex *vCascadePreviousParent = static_cast<AliAODVertex*> (vV0FromCascade->GetParent());\r
                        vV0FromCascade->SetParent(vCascade);\r
                        vCascade      ->SetParent(vCascadePreviousParent);\r
-\r
-               if(fDebug > 2)  \r
-                       printf("---- Cascade / Lineage insertion\n"\r
-                               "Parent of V0 vtx                 = Cascade vtx %p\n"\r
-                               "Parent of the cascade vtx        = Cascade vtx %p\n"\r
-                               "Parent of the parent cascade vtx = Cascade vtx %p\n", \r
-                                               static_cast<void*> (vV0FromCascade->GetParent()),\r
-                                               static_cast<void*> (vCascade->GetParent()),\r
-                                               static_cast<void*> (vCascadePreviousParent->GetParent()) );\r
-               \r
-       }// end if V0 structure already used\r
-\r
-       if (fDebug > 2) {\r
-               printf("---- Cascade / V0 vertex: \n");\r
-               vV0FromCascade->Print();\r
-       }\r
-\r
-       if (fDebug > 4) {\r
-               printf("---- Cascade / pos dghter : \n");\r
-                       aodTrack->Print();\r
-               printf("---- Cascade / neg dghter : \n");\r
-                       aodTrack->Print();\r
-               printf("---- Cascade / aodV0 : \n");\r
-                       aodV0->Print();\r
-       }\r
-\r
-       // In any case (used V0 or not), add the V0 vertex to the cascade one.\r
-       vCascade->AddDaughter(vV0FromCascade);  \r
-       \r
+      \r
+//      if(fDebug > 2) \r
+//        printf("---- Cascade / Lineage insertion\n"\r
+//               "Parent of V0 vtx                 = Cascade vtx %p\n"\r
+//               "Parent of the cascade vtx        = Cascade vtx %p\n"\r
+//               "Parent of the parent cascade vtx = Cascade vtx %p\n", \r
+//               static_cast<void*> (vV0FromCascade->GetParent()),\r
+//               static_cast<void*> (vCascade->GetParent()),\r
+//               static_cast<void*> (vCascadePreviousParent->GetParent()) );\r
+      \r
+    }// end if V0 structure already used\r
+    \r
+//    if (fDebug > 2) {\r
+//      printf("---- Cascade / V0 vertex: \n");\r
+//      vV0FromCascade->Print();\r
+//    }\r
+//    \r
+//    if (fDebug > 4) {\r
+//      printf("---- Cascade / pos dghter : \n");\r
+//                     aodTrack->Print();\r
+//      printf("---- Cascade / neg dghter : \n");\r
+//                     aodTrack->Print();\r
+//      printf("---- Cascade / aodV0 : \n");\r
+//                     aodV0->Print();\r
+//    }\r
+    \r
+    // In any case (used V0 or not), add the V0 vertex to the cascade one.\r
+    vCascade->AddDaughter(vV0FromCascade);     \r
+    \r
                \r
-       // 5 - Add the primary track of the cascade (if any)\r
-\r
-\r
-       // 6 - Add the cascade to the AOD array of cascades\r
-\r
-       Double_t dcaBachToPrimVertexXY = TMath::Abs(esdCascadeBach->GetD(esd->GetPrimaryVertex()->GetX(),\r
-                                                                        esd->GetPrimaryVertex()->GetY(),\r
-                                                                        esd->GetMagneticField())        );\r
-\r
-       esdCascade->GetBPxPyPz(momBachAtCascadeVtx[0], momBachAtCascadeVtx[1], momBachAtCascadeVtx[2]);\r
-\r
-       aodCascade = new(cascades[jCascades++]) AliAODcascade(  vCascade,\r
-                                                               esdCascade->Charge(),\r
-                                                               esdCascade->GetDcaXiDaughters(),\r
-                                                               -999.,\r
-               // DCAXiToPrimVtx -> needs to be calculated   ----|\r
-               // doesn't exist at ESD level;\r
-               // See AODcascade::DcaXiToPrimVertex(Double, Double, Double)\r
-                                                               dcaBachToPrimVertexXY,\r
-                                                               momBachAtCascadeVtx,\r
-                                                               *aodV0);\r
-       \r
-       if (fDebug > 3) {\r
-               printf("---- Cascade / AOD cascade : \n\n");\r
-               aodCascade->PrintXi(primary->GetX(), primary->GetY(), primary->GetZ());\r
-       }\r
-\r
-    } // end of the loop on cascades\r
+    // 5 - Add the primary track of the cascade (if any)\r
+    \r
+    \r
+    // 6 - Add the cascade to the AOD array of cascades\r
+    \r
+    Double_t dcaBachToPrimVertexXY = TMath::Abs(esdCascadeBach->GetD(esd.GetPrimaryVertex()->GetX(),\r
+                                                                     esd.GetPrimaryVertex()->GetY(),\r
+                                                                     esd.GetMagneticField())        );\r
+    \r
+    Double_t momBachAtCascadeVtx[3]={0.};\r
 \r
-    cascades.Expand(jCascades);\r
+    esdCascade->GetBPxPyPz(momBachAtCascadeVtx[0], momBachAtCascadeVtx[1], momBachAtCascadeVtx[2]);\r
+    \r
+    aodCascade = new(cascadesArray[fNumberOfCascades++]) AliAODcascade(  vCascade,\r
+                                                          esdCascade->Charge(),\r
+                                                          esdCascade->GetDcaXiDaughters(),\r
+                                                          -999.,\r
+                                                          // DCAXiToPrimVtx -> needs to be calculated   ----|\r
+                                                          // doesn't exist at ESD level;\r
+                                                          // See AODcascade::DcaXiToPrimVertex(Double, Double, Double)\r
+                                                          dcaBachToPrimVertexXY,\r
+                                                          momBachAtCascadeVtx,\r
+                                                          *aodV0);\r
+    \r
+//    if (fDebug > 3) {\r
+//      printf("---- Cascade / AOD cascade : \n\n");\r
+//      aodCascade->PrintXi(fPrimaryVertex->GetX(), fPrimaryVertex->GetY(), fPrimaryVertex->GetZ());\r
+//    }\r
+    \r
+  } // end of the loop on cascades\r
+  \r
+  Cascades().Expand(fNumberOfCascades);\r
+}\r
 \r
+//______________________________________________________________________________\r
+void AliAnalysisTaskESDfilter::ConvertV0s(const AliESDEvent& esd)\r
+{\r
+  // Access to the AOD container of V0s\r
+  \r
+  AliCodeTimerAuto("",0);\r
 \r
+  //\r
+  // V0s\r
+  //\r
+  \r
+  Double_t pos[3] = { 0. };      \r
+  Double_t chi2(0.0);\r
+  Double_t covVtx[6] = { 0. };\r
+  Double_t momPos[3]={0.};\r
+  Double_t covTr[21]={0.};\r
+  Double_t pid[10]={0.};\r
+  AliAODTrack* aodTrack(0x0);\r
+  AliAODPid* detpid(0x0);\r
+  Double_t momNeg[3]={0.};\r
+  Double_t momPosAtV0vtx[3]={0.};\r
+  Double_t momNegAtV0vtx[3]={0.};\r
+    \r
+  for (Int_t nV0 = 0; nV0 < esd.GetNumberOfV0s(); ++nV0) \r
+  {\r
+    if (fUsedV0[nV0]) continue; // skip if already added to the AOD\r
+    \r
+    AliESDv0 *v0 = esd.GetV0(nV0);\r
+    Int_t posFromV0 = v0->GetPindex();\r
+    Int_t negFromV0 = v0->GetNindex();\r
+    \r
+    // V0 selection \r
     //\r
-    // V0s\r
-    //\r
+    AliESDVertex *esdVtx   = new AliESDVertex(*(esd.GetPrimaryVertex()));\r
+    AliESDtrack  *esdV0Pos = esd.GetTrack(posFromV0);\r
+    AliESDtrack  *esdV0Neg = esd.GetTrack(negFromV0);\r
+    TList v0objects;\r
+    v0objects.AddAt(v0,                      0);\r
+    v0objects.AddAt(esdV0Pos,                1);\r
+    v0objects.AddAt(esdV0Neg,                2);\r
+    v0objects.AddAt(esdVtx,                  3);\r
+    UInt_t selectV0 = 0;\r
+    if (fV0Filter) {\r
+      selectV0 = fV0Filter->IsSelected(&v0objects);\r
+      // this is a little awkward but otherwise the \r
+      // list wants to access the pointer (delete it) \r
+      // again when going out of scope\r
+      delete v0objects.RemoveAt(3); // esdVtx created via copy construct\r
+      esdVtx = 0;\r
+      if (!selectV0) \r
+        continue;\r
+    }\r
+    else{\r
+      delete v0objects.RemoveAt(3); // esdVtx created via copy construct\r
+      esdVtx = 0;\r
+    }\r
+    \r
+    v0->GetXYZ(pos[0], pos[1], pos[2]);\r
     \r
-    for (Int_t nV0 = 0; nV0 < nV0s; ++nV0) {\r
-       \r
-       if (usedV0[nV0]) continue; // skip if already added to the AOD\r
-       \r
-       AliESDv0 *v0 = esd->GetV0(nV0);\r
-       Int_t posFromV0 = v0->GetPindex();\r
-       Int_t negFromV0 = v0->GetNindex();\r
-       \r
-       // V0 selection \r
-       //\r
-       AliESDVertex *esdVtx   = new AliESDVertex(*(esd->GetPrimaryVertex()));\r
-       AliESDtrack  *esdV0Pos = esd->GetTrack(posFromV0);\r
-       AliESDtrack  *esdV0Neg = esd->GetTrack(negFromV0);\r
-       TList v0objects;\r
-       v0objects.AddAt(v0,                      0);\r
-       v0objects.AddAt(esdV0Pos,                1);\r
-       v0objects.AddAt(esdV0Neg,                2);\r
-       v0objects.AddAt(esdVtx,                  3);\r
-       UInt_t selectV0 = 0;\r
-       if (fV0Filter) {\r
-         selectV0 = fV0Filter->IsSelected(&v0objects);\r
-         // this is a little awkward but otherwise the \r
-         // list wants to access the pointer (delete it) \r
-         // again when going out of scope\r
-         delete v0objects.RemoveAt(3); // esdVtx created via copy construct\r
-         esdVtx = 0;\r
-         if (!selectV0) \r
-           continue;\r
-       }\r
-       else{\r
-         delete v0objects.RemoveAt(3); // esdVtx created via copy construct\r
-         esdVtx = 0;\r
-       }\r
-    \r
-       v0->GetXYZ(pos[0], pos[1], pos[2]);\r
-\r
-       if (!old) {\r
+    if (!fOldESDformat) {\r
            chi2 = v0->GetChi2V0(); // = chi2/NDF since NDF = 2*2-3\r
            v0->GetPosCov(covVtx);\r
-       } else {\r
+    } else {\r
            chi2 = -999.;\r
            for (Int_t i = 0; i < 6; i++)  covVtx[i] = 0.;\r
-       }\r
-\r
-\r
-       AliAODVertex * vV0 = \r
-         new(vertices[jVertices++]) AliAODVertex(pos,\r
-                                                 covVtx,\r
-                                                 chi2,\r
-                                                 primary,\r
-                                                 nV0,\r
-                                                 AliAODVertex::kV0);\r
-       primary->AddDaughter(vV0);\r
-       \r
-\r
-       // Add the positive tracks from the V0\r
-       \r
-       esdV0Pos->GetPxPyPz(momPos);\r
-       esdV0Pos->GetXYZ(pos);\r
-       esdV0Pos->GetCovarianceXYZPxPyPz(covTr);\r
-       esdV0Pos->GetESDpid(pid);\r
-       \r
-       if (!usedTrack[posFromV0]) {\r
-           usedTrack[posFromV0] = kTRUE;\r
+    }\r
+    \r
+    \r
+    AliAODVertex * vV0 = \r
+         new(Vertices()[fNumberOfVertices++]) AliAODVertex(pos,\r
+                                                      covVtx,\r
+                                                      chi2,\r
+                                                      fPrimaryVertex,\r
+                                                      nV0,\r
+                                                      AliAODVertex::kV0);\r
+    fPrimaryVertex->AddDaughter(vV0);\r
+    \r
+    \r
+    // Add the positive tracks from the V0\r
+    \r
+\r
+    esdV0Pos->GetPxPyPz(momPos);\r
+    esdV0Pos->GetXYZ(pos);\r
+    esdV0Pos->GetCovarianceXYZPxPyPz(covTr);\r
+    esdV0Pos->GetESDpid(pid);\r
+    \r
+    const AliESDVertex *vtx = esd.GetPrimaryVertex();\r
+\r
+    if (!fUsedTrack[posFromV0]) {\r
+           fUsedTrack[posFromV0] = kTRUE;\r
            UInt_t selectInfo = 0;\r
            if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdV0Pos);\r
-           if(mcH)mcH->SelectParticle(esdV0Pos->GetLabel());\r
-           aodTrack = new(tracks[jTracks++]) AliAODTrack(esdV0Pos->GetID(),\r
-                                                         esdV0Pos->GetLabel(), \r
-                                                         momPos, \r
-                                                         kTRUE,\r
-                                                         pos,\r
-                                                         kFALSE,\r
-                                                         covTr, \r
-                                                         (Short_t)esdV0Pos->GetSign(),\r
-                                                         esdV0Pos->GetITSClusterMap(), \r
-                                                         pid,\r
-                                                         vV0,\r
-                                                         kTRUE,  // check if this is right\r
-                                                         vtx->UsesTrack(esdV0Pos->GetID()),\r
-                                                         AliAODTrack::kSecondary,\r
-                                                         selectInfo);\r
+           if(fMChandler)fMChandler->SelectParticle(esdV0Pos->GetLabel());\r
+           aodTrack = new(Tracks()[fNumberOfTracks++]) AliAODTrack(esdV0Pos->GetID(),\r
+                                                    esdV0Pos->GetLabel(), \r
+                                                    momPos, \r
+                                                    kTRUE,\r
+                                                    pos,\r
+                                                    kFALSE,\r
+                                                    covTr, \r
+                                                    (Short_t)esdV0Pos->GetSign(),\r
+                                                    esdV0Pos->GetITSClusterMap(), \r
+                                                    pid,\r
+                                                    vV0,\r
+                                                    kTRUE,  // check if this is right\r
+                                                    vtx->UsesTrack(esdV0Pos->GetID()),\r
+                                                    AliAODTrack::kSecondary,\r
+                                                    selectInfo);\r
            aodTrack->SetTPCClusterMap(esdV0Pos->GetTPCClusterMap());\r
            aodTrack->SetTPCSharedMap (esdV0Pos->GetTPCSharedMap());\r
            aodTrack->SetChi2perNDF(Chi2perNDF(esdV0Pos));\r
-           aodTrackRefs->AddAt(aodTrack,posFromV0);\r
+           fAODTrackRefs->AddAt(aodTrack,posFromV0);\r
            //      if (fDebug > 0) printf("-------------------Bo: pos track from original pt %.3f \n",aodTrack->Pt());\r
-           if (esdV0Pos->GetSign() > 0) nPosTracks++;\r
+           if (esdV0Pos->GetSign() > 0) ++fNumberOfPositiveTracks;\r
            aodTrack->ConvertAliPIDtoAODPID();\r
            aodTrack->SetFlags(esdV0Pos->GetStatus());\r
-            SetAODPID(esdV0Pos,aodTrack,detpid,esd->GetMagneticField(),esdPid);\r
-       }\r
-       else {\r
-           aodTrack = dynamic_cast<AliAODTrack*>(aodTrackRefs->At(posFromV0));\r
+      SetAODPID(esdV0Pos,aodTrack,detpid,esd.GetMagneticField());\r
+    }\r
+    else {\r
+           aodTrack = static_cast<AliAODTrack*>(fAODTrackRefs->At(posFromV0));\r
            //      if (fDebug > 0) printf("-------------------Bo pos track from refArray pt %.3f \n",aodTrack->Pt());\r
-       }\r
-       vV0->AddDaughter(aodTrack);\r
-    \r
-       // Add the negative tracks from the V0\r
-       \r
-       esdV0Neg->GetPxPyPz(momNeg);\r
-       esdV0Neg->GetXYZ(pos);\r
-       esdV0Neg->GetCovarianceXYZPxPyPz(covTr);\r
-       esdV0Neg->GetESDpid(pid);\r
-       \r
-       if (!usedTrack[negFromV0]) {\r
-           usedTrack[negFromV0] = kTRUE;\r
+    }\r
+    vV0->AddDaughter(aodTrack);\r
+    \r
+    // Add the negative tracks from the V0\r
+    \r
+    esdV0Neg->GetPxPyPz(momNeg);\r
+    esdV0Neg->GetXYZ(pos);\r
+    esdV0Neg->GetCovarianceXYZPxPyPz(covTr);\r
+    esdV0Neg->GetESDpid(pid);\r
+    \r
+    if (!fUsedTrack[negFromV0]) {\r
+           fUsedTrack[negFromV0] = kTRUE;\r
            UInt_t selectInfo = 0;\r
            if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdV0Neg);\r
-           if(mcH)mcH->SelectParticle(esdV0Neg->GetLabel());\r
-           aodTrack = new(tracks[jTracks++]) AliAODTrack(esdV0Neg->GetID(),\r
-                                                         esdV0Neg->GetLabel(),\r
-                                                         momNeg,\r
-                                                         kTRUE,\r
-                                                         pos,\r
-                                                         kFALSE,\r
-                                                         covTr, \r
-                                                         (Short_t)esdV0Neg->GetSign(),\r
-                                                         esdV0Neg->GetITSClusterMap(), \r
-                                                         pid,\r
-                                                         vV0,\r
-                                                         kTRUE,  // check if this is right\r
-                                                         vtx->UsesTrack(esdV0Neg->GetID()),\r
-                                                         AliAODTrack::kSecondary,\r
-                                                         selectInfo);\r
+           if(fMChandler)fMChandler->SelectParticle(esdV0Neg->GetLabel());\r
+           aodTrack = new(Tracks()[fNumberOfTracks++]) AliAODTrack(esdV0Neg->GetID(),\r
+                                                    esdV0Neg->GetLabel(),\r
+                                                    momNeg,\r
+                                                    kTRUE,\r
+                                                    pos,\r
+                                                    kFALSE,\r
+                                                    covTr, \r
+                                                    (Short_t)esdV0Neg->GetSign(),\r
+                                                    esdV0Neg->GetITSClusterMap(), \r
+                                                    pid,\r
+                                                    vV0,\r
+                                                    kTRUE,  // check if this is right\r
+                                                    vtx->UsesTrack(esdV0Neg->GetID()),\r
+                                                    AliAODTrack::kSecondary,\r
+                                                    selectInfo);\r
            aodTrack->SetTPCClusterMap(esdV0Neg->GetTPCClusterMap());\r
            aodTrack->SetTPCSharedMap (esdV0Neg->GetTPCSharedMap());\r
            aodTrack->SetChi2perNDF(Chi2perNDF(esdV0Neg));\r
            \r
-           aodTrackRefs->AddAt(aodTrack,negFromV0);\r
+           fAODTrackRefs->AddAt(aodTrack,negFromV0);\r
            //      if (fDebug > 0) printf("-------------------Bo: neg track from original pt %.3f \n",aodTrack->Pt());\r
-           if (esdV0Neg->GetSign() > 0) nPosTracks++;\r
+           if (esdV0Neg->GetSign() > 0) ++fNumberOfPositiveTracks;\r
            aodTrack->ConvertAliPIDtoAODPID();\r
            aodTrack->SetFlags(esdV0Neg->GetStatus());\r
-            SetAODPID(esdV0Neg,aodTrack,detpid,esd->GetMagneticField(),esdPid);\r
-       }\r
-       else {\r
-           aodTrack = dynamic_cast<AliAODTrack*>(aodTrackRefs->At(negFromV0));\r
+      SetAODPID(esdV0Neg,aodTrack,detpid,esd.GetMagneticField());\r
+    }\r
+    else {\r
+           aodTrack = static_cast<AliAODTrack*>(fAODTrackRefs->At(negFromV0));\r
            //      if (fDebug > 0) printf("-------------------Bo neg track from refArray pt %.3f \n",aodTrack->Pt());\r
-       }\r
-       vV0->AddDaughter(aodTrack);\r
-\r
-\r
-       // Add the V0 the V0 array as well\r
-       \r
-       Double_t  dcaV0Daughters      = v0->GetDcaV0Daughters();\r
-       Double_t  dcaV0ToPrimVertex   = v0->GetD(esd->GetPrimaryVertex()->GetX(),\r
-                                                esd->GetPrimaryVertex()->GetY(),\r
-                                                esd->GetPrimaryVertex()->GetZ());\r
-       v0->GetPPxPyPz(momPosAtV0vtx[0],momPosAtV0vtx[1],momPosAtV0vtx[2]); \r
-       v0->GetNPxPyPz(momNegAtV0vtx[0],momNegAtV0vtx[1],momNegAtV0vtx[2]); \r
-       \r
-       Double_t dcaDaughterToPrimVertex[2] = { 999., 999.}; // ..[0] = DCA in (x,y) for Pos and ..[1] = Neg\r
-       dcaDaughterToPrimVertex[0] = TMath::Abs(esdV0Pos->GetD(  esd->GetPrimaryVertex()->GetX(),\r
-                                                                esd->GetPrimaryVertex()->GetY(),\r
-                                                                       esd->GetMagneticField()) );\r
-       dcaDaughterToPrimVertex[1] = TMath::Abs(esdV0Neg->GetD(  esd->GetPrimaryVertex()->GetX(),\r
-                                                                esd->GetPrimaryVertex()->GetY(),\r
-                                                                       esd->GetMagneticField()) );\r
-       \r
-       aodV0 = new(v0s[jV0s++]) AliAODv0(vV0, \r
-                                       dcaV0Daughters,\r
-                                       dcaV0ToPrimVertex,\r
-                                       momPosAtV0vtx,\r
-                                       momNegAtV0vtx,\r
-                                       dcaDaughterToPrimVertex);\r
-\r
-       // set the aod v0 on-the-fly status\r
-       aodV0->SetOnFlyStatus(v0->GetOnFlyStatus());\r
-    }//End of loop on V0s \r
-\r
-    v0s.Expand(jV0s);   \r
-\r
-    if (fDebug > 0)   printf("   NAODCascades=%d / NAODV0s=%d\n", jCascades, jV0s);\r
-    // end of V0 parts\r
-\r
-\r
-    // Kinks: it is a big mess the access to the information in the kinks\r
-    // The loop is on the tracks in order to find the mother and daugther of each kink\r
-    \r
-    \r
-    for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) {\r
-       \r
-       AliESDtrack * esdTrack = esd->GetTrack(iTrack);\r
-       \r
-       Int_t ikink = esdTrack->GetKinkIndex(0);\r
-       \r
-       if (ikink && nKinks) {\r
-           // Negative kink index: mother, positive: daughter\r
-           \r
-           // Search for the second track of the kink\r
-           \r
-           for (Int_t jTrack = iTrack+1; jTrack<nTracks; ++jTrack) {\r
-               \r
-               AliESDtrack * esdTrack1 = esd->GetTrack(jTrack);\r
-               \r
-               Int_t jkink = esdTrack1->GetKinkIndex(0);\r
-               \r
-               if ( TMath::Abs(ikink)==TMath::Abs(jkink) ) {\r
-                   \r
-                   // The two tracks are from the same kink\r
-                   \r
-                   if (usedKink[TMath::Abs(ikink)-1]) continue; // skip used kinks\r
-                   \r
-                   Int_t imother = -1;\r
-                   Int_t idaughter = -1;\r
-                   \r
-                   if (ikink<0 && jkink>0) {\r
-                       \r
-                       imother = iTrack;\r
-                       idaughter = jTrack;\r
-                   }\r
-                   else if (ikink>0 && jkink<0) {\r
-                       \r
-                       imother = jTrack;\r
-                       idaughter = iTrack;\r
-                   }\r
-                   else {\r
-//                     cerr << "Error: Wrong combination of kink indexes: "\r
-//                          << ikink << " " << jkink << endl;\r
-                       continue;\r
-                   }\r
-                   \r
-                   // Add the mother track if it passed primary track selection cuts\r
-                   \r
-                   AliAODTrack * mother = NULL;\r
-                   \r
-                   UInt_t selectInfo = 0;\r
-                   if (fTrackFilter) {\r
-                       selectInfo = fTrackFilter->IsSelected(esd->GetTrack(imother));\r
-                       if (!selectInfo) continue;\r
-                   }\r
-                   \r
-                   if (!usedTrack[imother]) {\r
-                       \r
-                       usedTrack[imother] = kTRUE;\r
-                       \r
-                       AliESDtrack *esdTrackM = esd->GetTrack(imother);\r
-                       esdTrackM->GetPxPyPz(p);\r
-                       esdTrackM->GetXYZ(pos);\r
-                       esdTrackM->GetCovarianceXYZPxPyPz(covTr);\r
-                       esdTrackM->GetESDpid(pid);\r
-                       if(mcH)mcH->SelectParticle(esdTrackM->GetLabel());\r
-                       mother = \r
-                           new(tracks[jTracks++]) AliAODTrack(esdTrackM->GetID(),\r
-                                                              esdTrackM->GetLabel(),\r
-                                                              p,\r
-                                                              kTRUE,\r
-                                                              pos,\r
-                                                              kFALSE,\r
-                                                              covTr, \r
-                                                              (Short_t)esdTrackM->GetSign(),\r
-                                                              esdTrackM->GetITSClusterMap(), \r
-                                                              pid,\r
-                                                              primary,\r
-                                                              kTRUE, // check if this is right\r
-                                                              vtx->UsesTrack(esdTrack->GetID()),\r
-                                                              AliAODTrack::kPrimary,\r
-                                                              selectInfo);\r
-                       mother->SetTPCClusterMap(esdTrackM->GetTPCClusterMap());\r
-                       mother->SetTPCSharedMap (esdTrackM->GetTPCSharedMap());\r
-                       mother->SetChi2perNDF(Chi2perNDF(esdTrackM));\r
-\r
-                       aodTrackRefs->AddAt(mother, imother);\r
-                       \r
-                       if (esdTrackM->GetSign() > 0) nPosTracks++;\r
-                       mother->SetFlags(esdTrackM->GetStatus());\r
-                       mother->ConvertAliPIDtoAODPID();\r
-                       primary->AddDaughter(mother);\r
-                       mother->ConvertAliPIDtoAODPID();\r
-                        SetAODPID(esdTrackM,mother,detpid,esd->GetMagneticField(),esdPid);\r
-                   }\r
-                   else {\r
-//                     cerr << "Error: event " << esd->GetEventNumberInFile() << " kink " << TMath::Abs(ikink)-1\r
-//                          << " track " << imother << " has already been used!" << endl;\r
-                 }\r
-                   \r
-                   // Add the kink vertex\r
-                   AliESDkink * kink = esd->GetKink(TMath::Abs(ikink)-1);\r
-                   \r
-                   AliAODVertex * vkink = \r
-                       new(vertices[jVertices++]) AliAODVertex(kink->GetPosition(),\r
-                                                               NULL,\r
-                                                               0.,\r
-                                                               mother,\r
-                                                               esdTrack->GetID(),  // This is the track ID of the mother's track!\r
-                                                               AliAODVertex::kKink);\r
-                   // Add the daughter track\r
-                 \r
-                   AliAODTrack * daughter = NULL;\r
-                   \r
-                   if (!usedTrack[idaughter]) {\r
-                       \r
-                       usedTrack[idaughter] = kTRUE;\r
-                       \r
-                       AliESDtrack *esdTrackD = esd->GetTrack(idaughter);\r
-                       esdTrackD->GetPxPyPz(p);\r
-                       esdTrackD->GetXYZ(pos);\r
-                       esdTrackD->GetCovarianceXYZPxPyPz(covTr);\r
-                       esdTrackD->GetESDpid(pid);\r
-                       selectInfo = 0;\r
-                       if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdTrackD);\r
-                       if(mcH)mcH->SelectParticle(esdTrackD->GetLabel());\r
-                       daughter = \r
-                           new(tracks[jTracks++]) AliAODTrack(esdTrackD->GetID(),\r
-                                                              esdTrackD->GetLabel(),\r
-                                                              p,\r
-                                                              kTRUE,\r
-                                                              pos,\r
-                                                              kFALSE,\r
-                                                              covTr, \r
-                                                              (Short_t)esdTrackD->GetSign(),\r
-                                                              esdTrackD->GetITSClusterMap(), \r
-                                                              pid,\r
-                                                              vkink,\r
-                                                              kTRUE, // check if this is right\r
-                                                              vtx->UsesTrack(esdTrack->GetID()),\r
-                                                              AliAODTrack::kSecondary,\r
-                                                              selectInfo);\r
-                       daughter->SetTPCClusterMap(esdTrackD->GetTPCClusterMap());\r
-                       daughter->SetTPCSharedMap (esdTrackD->GetTPCSharedMap());\r
-                       aodTrackRefs->AddAt(daughter, idaughter);\r
-                       \r
-                       if (esdTrackD->GetSign() > 0) nPosTracks++;\r
-                       daughter->SetFlags(esdTrackD->GetStatus());\r
-                       daughter->ConvertAliPIDtoAODPID();\r
-                       vkink->AddDaughter(daughter);\r
-                       daughter->ConvertAliPIDtoAODPID();\r
-                       SetAODPID(esdTrackD,daughter,detpid,esd->GetMagneticField(),esdPid);\r
-                   }\r
-                   else {\r
-//                     cerr << "Error: event " << esd->GetEventNumberInFile() << " kink " << TMath::Abs(ikink)-1\r
-//                          << " track " << idaughter << " has already been used!" << endl;\r
-                   }\r
-               }\r
-           }\r
-       }      \r
     }\r
+    vV0->AddDaughter(aodTrack);\r
+    \r
+    \r
+    // Add the V0 the V0 array as well\r
+    \r
+    Double_t  dcaV0Daughters      = v0->GetDcaV0Daughters();\r
+    Double_t  dcaV0ToPrimVertex   = v0->GetD(esd.GetPrimaryVertex()->GetX(),\r
+                                             esd.GetPrimaryVertex()->GetY(),\r
+                                             esd.GetPrimaryVertex()->GetZ());\r
+    \r
+    v0->GetPPxPyPz(momPosAtV0vtx[0],momPosAtV0vtx[1],momPosAtV0vtx[2]); \r
+    v0->GetNPxPyPz(momNegAtV0vtx[0],momNegAtV0vtx[1],momNegAtV0vtx[2]); \r
+    \r
+    Double_t dcaDaughterToPrimVertex[2] = { 999., 999.}; // ..[0] = DCA in (x,y) for Pos and ..[1] = Neg\r
+    dcaDaughterToPrimVertex[0] = TMath::Abs(esdV0Pos->GetD(  esd.GetPrimaryVertex()->GetX(),\r
+                                                           esd.GetPrimaryVertex()->GetY(),\r
+                                                           esd.GetMagneticField()) );\r
+    dcaDaughterToPrimVertex[1] = TMath::Abs(esdV0Neg->GetD(  esd.GetPrimaryVertex()->GetX(),\r
+                                                           esd.GetPrimaryVertex()->GetY(),\r
+                                                           esd.GetMagneticField()) );\r
     \r
+    AliAODv0* aodV0 = new(V0s()[fNumberOfV0s++]) AliAODv0(vV0, \r
+                                                dcaV0Daughters,\r
+                                                dcaV0ToPrimVertex,\r
+                                                momPosAtV0vtx,\r
+                                                momNegAtV0vtx,\r
+                                                dcaDaughterToPrimVertex);\r
+    \r
+    // set the aod v0 on-the-fly status\r
+    aodV0->SetOnFlyStatus(v0->GetOnFlyStatus());\r
+  }//End of loop on V0s \r
   \r
-    // Tracks (primary and orphan)\r
+  V0s().Expand(fNumberOfV0s);   \r
+}\r
 \r
-    if (fDebug > 0) printf("NUMBER OF ESD TRACKS %5d\n", nTracks);\r
+//______________________________________________________________________________\r
+void AliAnalysisTaskESDfilter::ConvertTPCOnlyTracks(const AliESDEvent& esd)\r
+{\r
+  // Convert TPC only tracks\r
+  \r
+  AliCodeTimerAuto("",0);\r
+  \r
+  // Loop over the tracks and extract and mask out all aod tracks that pass the selections for AODt racks\r
+  for(int it = 0;it < fNumberOfTracks;++it)\r
+  {\r
+    AliAODTrack *tr = (AliAODTrack*)(Tracks().At(it));\r
+    if(!tr)continue;\r
+    UInt_t map = tr->GetFilterMap();\r
+    if(map&fTPCOnlyFilterMask){\r
+      // we only reset the track select ionfo, no deletion...\r
+      tr->SetFilterMap(map&~fTPCOnlyFilterMask);\r
+    }\r
+  }\r
+  // Loop over the ESD trcks and pick out the tracks passing TPC only cuts\r
+  \r
+  \r
+  const AliESDVertex *vtxSPD = esd.GetPrimaryVertexSPD();\r
+  const AliESDVertex *vtx = esd.GetPrimaryVertex();\r
+\r
+  Double_t pos[3] = { 0. };      \r
+  Double_t covTr[21]={0.};\r
+  Double_t pid[10]={0.};  \r
+  Double_t p[3] = { 0. };\r
+  AliAODTrack* aodTrack(0x0);\r
+  \r
+  for (Int_t nTrack = 0; nTrack < esd.GetNumberOfTracks(); ++nTrack) \r
+  {\r
+    AliESDtrack* esdTrack = esd.GetTrack(nTrack); //carefull do not modify it othwise  need to work with a copy \r
+    \r
+    UInt_t selectInfo = 0;\r
+    //\r
+    // Track selection\r
+    if (fTrackFilter) {\r
+      selectInfo = fTrackFilter->IsSelected(esdTrack);\r
+    }\r
+    selectInfo &= fTPCOnlyFilterMask;\r
+    if (!selectInfo)continue;\r
     \r
-    for (Int_t nTrack = 0; nTrack < nTracks; ++nTrack) {\r
-       \r
-       \r
-      if (usedTrack[nTrack]){\r
-       continue;\r
+    // create a tpc only tracl\r
+    AliESDtrack *track = AliESDtrackCuts::GetTPCOnlyTrack(const_cast<AliESDEvent*>(&esd),esdTrack->GetID());\r
+    if(!track) continue;\r
+    \r
+    if(track->Pt()>0.)\r
+    {\r
+      // only constrain tracks above threshold\r
+      AliExternalTrackParam exParam;\r
+      // take the B-field from the ESD, no 3D fieldMap available at this point\r
+      Bool_t relate = false;\r
+      relate = track->RelateToVertex(vtxSPD,esd.GetMagneticField(),kVeryBig,&exParam);\r
+      if(!relate){\r
+        delete track;\r
+        continue;\r
       }\r
-       AliESDtrack *esdTrack = esd->GetTrack(nTrack);\r
-       UInt_t selectInfo = 0;\r
-       //\r
-       // Track selection\r
-       if (fTrackFilter) {\r
+      track->Set(exParam.GetX(),exParam.GetAlpha(),exParam.GetParameter(),exParam.GetCovariance());\r
+    }\r
+    \r
+    track->GetPxPyPz(p);\r
+    track->GetXYZ(pos);\r
+    track->GetCovarianceXYZPxPyPz(covTr);\r
+    track->GetESDpid(pid);\r
+    if(fMChandler)fMChandler->SelectParticle(esdTrack->GetLabel());\r
+    aodTrack = new(Tracks()[fNumberOfTracks++]) AliAODTrack((track->GetID()+1)*-1,\r
+                                                            track->GetLabel(),\r
+                                                            p,\r
+                                                            kTRUE,\r
+                                                            pos,\r
+                                                            kFALSE,\r
+                                                            covTr, \r
+                                                            (Short_t)track->GetSign(),\r
+                                                            track->GetITSClusterMap(), \r
+                                                            pid,\r
+                                                            fPrimaryVertex,\r
+                                                            kTRUE, // check if this is right\r
+                                                            vtx->UsesTrack(track->GetID()),\r
+                                                            AliAODTrack::kPrimary, \r
+                                                            selectInfo);\r
+    aodTrack->SetTPCClusterMap(track->GetTPCClusterMap());\r
+    aodTrack->SetTPCSharedMap (track->GetTPCSharedMap());\r
+    aodTrack->SetChi2perNDF(Chi2perNDF(track));\r
+    aodTrack->SetFlags(track->GetStatus());\r
+    \r
+    delete track;\r
+  } // end of loop on tracks\r
+  \r
+}\r
+\r
+//______________________________________________________________________________\r
+void AliAnalysisTaskESDfilter::ConvertTracks(const AliESDEvent& esd)\r
+{\r
+  // Tracks (primary and orphan)\r
+\r
+  AliCodeTimerAuto("",0);\r
+  \r
+  AliDebug(1,Form("NUMBER OF ESD TRACKS %5d\n", esd.GetNumberOfTracks()));\r
+  \r
+  const AliESDVertex *vtx = esd.GetPrimaryVertex();\r
+  Double_t p[3] = { 0. };\r
+  Double_t pos[3] = { 0. };\r
+  Double_t covTr[21] = { 0. };\r
+  Double_t pid[10] = { 0. };\r
+  AliAODTrack* aodTrack(0x0);\r
+  AliAODPid* detpid(0x0);\r
+  \r
+  for (Int_t nTrack = 0; nTrack < esd.GetNumberOfTracks(); ++nTrack) \r
+  {\r
+    if (fUsedTrack[nTrack]) continue;\r
+    \r
+    AliESDtrack *esdTrack = esd.GetTrack(nTrack);\r
+    UInt_t selectInfo = 0;\r
+    //\r
+    // Track selection\r
+    if (fTrackFilter) {\r
            selectInfo = fTrackFilter->IsSelected(esdTrack);\r
            if (!selectInfo && !vtx->UsesTrack(esdTrack->GetID())) continue;\r
-       }\r
-       \r
-       //\r
-       esdTrack->GetPxPyPz(p);\r
-       esdTrack->GetXYZ(pos);\r
-       esdTrack->GetCovarianceXYZPxPyPz(covTr);\r
-       esdTrack->GetESDpid(pid);\r
-       if(mcH)mcH->SelectParticle(esdTrack->GetLabel());\r
-       primary->AddDaughter(aodTrack =\r
-                            new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),\r
-                                                               esdTrack->GetLabel(),\r
-                                                               p,\r
-                                                               kTRUE,\r
-                                                               pos,\r
-                                                               kFALSE,\r
-                                                               covTr, \r
-                                                               (Short_t)esdTrack->GetSign(),\r
-                                                               esdTrack->GetITSClusterMap(), \r
-                                                               pid,\r
-                                                               primary,\r
-                                                               kTRUE, // check if this is right\r
-                                                               vtx->UsesTrack(esdTrack->GetID()),\r
-                                                               AliAODTrack::kPrimary, \r
-                                                               selectInfo)\r
-                            );\r
-       aodTrack->SetTPCClusterMap(esdTrack->GetTPCClusterMap());\r
-       aodTrack->SetTPCSharedMap (esdTrack->GetTPCSharedMap());\r
-       aodTrack->SetChi2perNDF(Chi2perNDF(esdTrack));\r
-\r
-       aodTrackRefs->AddAt(aodTrack, nTrack);\r
-\r
-       \r
-       if (esdTrack->GetSign() > 0) nPosTracks++;\r
-       aodTrack->SetFlags(esdTrack->GetStatus());\r
-       aodTrack->ConvertAliPIDtoAODPID();\r
-       SetAODPID(esdTrack,aodTrack,detpid,esd->GetMagneticField(),esdPid);\r
-    } // end of loop on tracks\r
-    \r
-    // Update number of AOD tracks in header at the end of track loop (M.G.)\r
-    header->SetRefMultiplicity(jTracks);\r
-    header->SetRefMultiplicityPos(nPosTracks);\r
-    header->SetRefMultiplicityNeg(jTracks - nPosTracks);\r
-    if (fDebug > 0) \r
-      printf("   NAODTRACKS=%d  NPOS=%d  NNEG=%d\n", jTracks, nPosTracks, jTracks - nPosTracks);\r
-\r
-\r
-    // Do not shrink the array of tracks - other filters may add to it (M.G)\r
-    //   tracks.Expand(jTracks); // remove 'empty slots' due to unwritten tracks\r
-    \r
-    if(fTPCOnlyFilterMask){\r
-    // Loop over the tracks and extract and mask out all aod tracks that pass the selections for AODt racks\r
-      for(int it = 0;it < jTracks;++it){\r
-       AliAODTrack *tr = (AliAODTrack*)tracks.At(it);\r
-       if(!tr)continue;\r
-       UInt_t map = tr->GetFilterMap();\r
-       if(map&fTPCOnlyFilterMask){\r
-         // we only reset the track select ionfo, no deletion...\r
-         tr->SetFilterMap(map&~fTPCOnlyFilterMask);\r
-       }\r
-      }\r
-      // Loop over the ESD trcks and pick out the tracks passing TPC only cuts\r
-      \r
-      \r
-     const AliESDVertex *vtxSPD = esd->GetPrimaryVertexSPD();\r
-      for (Int_t nTrack = 0; nTrack < nTracks; ++nTrack) {\r
-       AliESDtrack* esdTrack = esd->GetTrack(nTrack); //carefull do not modify it othwise  need to work with a copy \r
-       \r
-       UInt_t selectInfo = 0;\r
-       //\r
-       // Track selection\r
-       if (fTrackFilter) {\r
-         selectInfo = fTrackFilter->IsSelected(esdTrack);\r
-       }\r
-       selectInfo &= fTPCOnlyFilterMask;\r
-       if (!selectInfo)continue;\r
-\r
-       // create a tpc only tracl\r
-       AliESDtrack *track = AliESDtrackCuts::GetTPCOnlyTrack(esd,esdTrack->GetID());\r
-       if(!track) continue;\r
-\r
-\r
-\r
-       if(track->Pt()>0.){\r
-         // only constrain tracks above threshold\r
-         AliExternalTrackParam exParam;\r
-         // take the B-feild from the ESD, no 3D fieldMap available at this point\r
-         Bool_t relate = false;\r
-         relate = track->RelateToVertex(vtxSPD,esd->GetMagneticField(),kVeryBig,&exParam);\r
-         if(!relate){\r
-           delete track;\r
-           continue;\r
-         }\r
-         track->Set(exParam.GetX(),exParam.GetAlpha(),exParam.GetParameter(),exParam.GetCovariance());\r
-       }\r
-\r
-       track->GetPxPyPz(p);\r
-       track->GetXYZ(pos);\r
-       track->GetCovarianceXYZPxPyPz(covTr);\r
-       track->GetESDpid(pid);\r
-       if(mcH)mcH->SelectParticle(esdTrack->GetLabel());\r
-       aodTrack = new(tracks[jTracks++]) AliAODTrack((track->GetID()+1)*-1,\r
-                                                     track->GetLabel(),\r
-                                                     p,\r
-                                                     kTRUE,\r
-                                                     pos,\r
-                                                     kFALSE,\r
-                                                     covTr, \r
-                                                     (Short_t)track->GetSign(),\r
-                                                     track->GetITSClusterMap(), \r
-                                                     pid,\r
-                                                     primary,\r
-                                                     kTRUE, // check if this is right\r
-                                                     vtx->UsesTrack(track->GetID()),\r
-                                                     AliAODTrack::kPrimary, \r
-                                                     selectInfo);\r
-       aodTrack->SetTPCClusterMap(track->GetTPCClusterMap());\r
-       aodTrack->SetTPCSharedMap (track->GetTPCSharedMap());\r
-       aodTrack->SetChi2perNDF(Chi2perNDF(track));\r
-       aodTrack->SetFlags(track->GetStatus());\r
-       delete track;\r
-      } // end of loop on tracks\r
-      \r
-    }//end if(fTPCOnlyFilterMask\r
-    \r
-    // Access to the AOD container of PMD clusters\r
-    TClonesArray &pmdClusters = *(AODEvent()->GetPmdClusters());\r
-    Int_t jPmdClusters=0;\r
-  \r
-    for (Int_t iPmd = 0; iPmd < nPmdClus; ++iPmd) {\r
-      // file pmd clusters, to be revised!\r
-      AliESDPmdTrack *pmdTrack = esd->GetPmdTrack(iPmd);\r
-      Int_t nLabel = 0;\r
-      Int_t *label = 0x0;\r
-      Double_t posPmd[3] = { pmdTrack->GetClusterX(), pmdTrack->GetClusterY(), pmdTrack->GetClusterZ()};\r
-      Double_t pidPmd[13] = { 0.}; // to be revised!\r
-      // type not set!\r
-      // assoc cluster not set\r
-      new(pmdClusters[jPmdClusters++]) AliAODPmdCluster(iPmd, nLabel, label, pmdTrack->GetClusterADC(), posPmd, pidPmd);\r
     }\r
+    \r
+    \r
+    esdTrack->GetPxPyPz(p);\r
+    esdTrack->GetXYZ(pos);\r
+    esdTrack->GetCovarianceXYZPxPyPz(covTr);\r
+    esdTrack->GetESDpid(pid);\r
+    if(fMChandler)fMChandler->SelectParticle(esdTrack->GetLabel());\r
+    fPrimaryVertex->AddDaughter(aodTrack =\r
+                         new(Tracks()[fNumberOfTracks++]) AliAODTrack(esdTrack->GetID(),\r
+                                                            esdTrack->GetLabel(),\r
+                                                            p,\r
+                                                            kTRUE,\r
+                                                            pos,\r
+                                                            kFALSE,\r
+                                                            covTr, \r
+                                                            (Short_t)esdTrack->GetSign(),\r
+                                                            esdTrack->GetITSClusterMap(), \r
+                                                            pid,\r
+                                                            fPrimaryVertex,\r
+                                                            kTRUE, // check if this is right\r
+                                                            vtx->UsesTrack(esdTrack->GetID()),\r
+                                                            AliAODTrack::kPrimary, \r
+                                                            selectInfo)\r
+                         );\r
+    aodTrack->SetTPCClusterMap(esdTrack->GetTPCClusterMap());\r
+    aodTrack->SetTPCSharedMap (esdTrack->GetTPCSharedMap());\r
+    aodTrack->SetChi2perNDF(Chi2perNDF(esdTrack));\r
+    \r
+    fAODTrackRefs->AddAt(aodTrack, nTrack);\r
+    \r
+    \r
+    if (esdTrack->GetSign() > 0) ++fNumberOfPositiveTracks;\r
+    aodTrack->SetFlags(esdTrack->GetStatus());\r
+    aodTrack->ConvertAliPIDtoAODPID();\r
+    SetAODPID(esdTrack,aodTrack,detpid,esd.GetMagneticField());\r
+  } // end of loop on tracks\r
+}\r
 \r
-    // Access to the AOD container of clusters\r
-    TClonesArray &caloClusters = *(AODEvent()->GetCaloClusters());\r
-    Int_t jClusters=0;\r
\r
-    for (Int_t iClust=0; iClust<nCaloClus; ++iClust) {\r
-\r
-      AliESDCaloCluster * cluster = esd->GetCaloCluster(iClust);\r
+//______________________________________________________________________________\r
+void AliAnalysisTaskESDfilter::ConvertPmdClusters(const AliESDEvent& esd)\r
+{\r
+  AliCodeTimerAuto("",0);\r
+  Int_t jPmdClusters=0;\r
+  // Access to the AOD container of PMD clusters\r
+  TClonesArray &pmdClusters = *(AODEvent()->GetPmdClusters());\r
+  for (Int_t iPmd = 0; iPmd < esd.GetNumberOfPmdTracks(); ++iPmd) {\r
+    // file pmd clusters, to be revised!\r
+    AliESDPmdTrack *pmdTrack = esd.GetPmdTrack(iPmd);\r
+    Int_t nLabel = 0;\r
+    Int_t *label = 0x0;\r
+    Double_t posPmd[3] = { pmdTrack->GetClusterX(), pmdTrack->GetClusterY(), pmdTrack->GetClusterZ()};\r
+    Double_t pidPmd[13] = { 0.}; // to be revised!\r
+    // type not set!\r
+    // assoc cluster not set\r
+    new(pmdClusters[jPmdClusters++]) AliAODPmdCluster(iPmd, nLabel, label, pmdTrack->GetClusterADC(), posPmd, pidPmd);\r
+  }\r
+}\r
 \r
-      Int_t  id        = cluster->GetID();\r
-      Int_t  nLabel    = cluster->GetNLabels();\r
-      Int_t *labels    = cluster->GetLabels();\r
-      if(labels){ \r
+//______________________________________________________________________________\r
+void AliAnalysisTaskESDfilter::ConvertCaloClusters(const AliESDEvent& esd)\r
+{\r
+  AliCodeTimerAuto("",0);\r
+  \r
+  // Access to the AOD container of clusters\r
+  TClonesArray &caloClusters = *(AODEvent()->GetCaloClusters());\r
+  Int_t jClusters(0);\r
+  \r
+  for (Int_t iClust=0; iClust<esd.GetNumberOfCaloClusters(); ++iClust) {\r
+    \r
+    AliESDCaloCluster * cluster = esd.GetCaloCluster(iClust);\r
+    \r
+    Int_t  id        = cluster->GetID();\r
+    Int_t  nLabel    = cluster->GetNLabels();\r
+    Int_t *labels    = cluster->GetLabels();\r
+    if(labels){ \r
                  for(int i = 0;i < nLabel;++i){\r
-                         if(mcH)mcH->SelectParticle(labels[i]);\r
+                         if(fMChandler)fMChandler->SelectParticle(labels[i]);\r
                  }\r
          }             \r
+    \r
+    Float_t energy = cluster->E();\r
+    Float_t posF[3] = { 0.};\r
+    cluster->GetPosition(posF);\r
+    \r
+    AliAODCaloCluster *caloCluster = new(caloClusters[jClusters++]) AliAODCaloCluster(id,\r
+                                                                                      nLabel,\r
+                                                                                      labels,\r
+                                                                                      energy,\r
+                                                                                      posF,\r
+                                                                                      NULL,\r
+                                                                                      cluster->GetType(),0);\r
+    \r
+    caloCluster->SetCaloCluster(cluster->GetDistanceToBadChannel(),\r
+                                cluster->GetDispersion(),\r
+                                cluster->GetM20(), cluster->GetM02(),\r
+                                cluster->GetEmcCpvDistance(),  \r
+                                cluster->GetNExMax(),cluster->GetTOF()) ;\r
+    \r
+    caloCluster->SetPIDFromESD(cluster->GetPID());\r
+    caloCluster->SetNCells(cluster->GetNCells());\r
+    caloCluster->SetCellsAbsId(cluster->GetCellsAbsId());\r
+    caloCluster->SetCellsAmplitudeFraction(cluster->GetCellsAmplitudeFraction());\r
+    \r
+    TArrayI* matchedT =        cluster->GetTracksMatched();\r
+    if (fNumberOfTracks>0 && matchedT && cluster->GetTrackMatchedIndex() >= 0) {       \r
+      for (Int_t im = 0; im < matchedT->GetSize(); im++) {\r
+        Int_t iESDtrack = matchedT->At(im);;\r
+        if (fAODTrackRefs->At(iESDtrack) != 0) {\r
+          caloCluster->AddTrackMatched((AliAODTrack*)fAODTrackRefs->At(iESDtrack));\r
+        }\r
+      }\r
+    }\r
+    \r
+  } \r
+  caloClusters.Expand(jClusters); // resize TObjArray to 'remove' slots for pseudo clusters     \r
+}\r
 \r
-      Float_t energy = cluster->E();\r
-      cluster->GetPosition(posF);\r
+//______________________________________________________________________________\r
+void AliAnalysisTaskESDfilter::ConvertEMCALCells(const AliESDEvent& esd)\r
+{\r
+  AliCodeTimerAuto("",0);\r
+  // fill EMCAL cell info\r
+  if (esd.GetEMCALCells()) { // protection against missing ESD information\r
+    AliESDCaloCells &esdEMcells = *(esd.GetEMCALCells());\r
+    Int_t nEMcell = esdEMcells.GetNumberOfCells() ;\r
+    \r
+    AliAODCaloCells &aodEMcells = *(AODEvent()->GetEMCALCells());\r
+    aodEMcells.CreateContainer(nEMcell);\r
+    aodEMcells.SetType(AliAODCaloCells::kEMCALCell);\r
+    for (Int_t iCell = 0; iCell < nEMcell; iCell++) {      \r
+      aodEMcells.SetCell(iCell,esdEMcells.GetCellNumber(iCell),esdEMcells.GetAmplitude(iCell));\r
+    }\r
+    aodEMcells.Sort();\r
+  }\r
+}\r
 \r
-      AliAODCaloCluster *caloCluster = new(caloClusters[jClusters++]) AliAODCaloCluster(id,\r
-                                                                                       nLabel,\r
-                                                                                       labels,\r
-                                                                                       energy,\r
-                                                                                       posF,\r
-                                                                                       NULL,\r
-                                                                                       cluster->GetType(),0);\r
-      \r
-      caloCluster->SetCaloCluster(cluster->GetDistanceToBadChannel(),\r
-                                 cluster->GetDispersion(),\r
-                                 cluster->GetM20(), cluster->GetM02(),\r
-                                 cluster->GetEmcCpvDistance(),  \r
-                                 cluster->GetNExMax(),cluster->GetTOF()) ;\r
-\r
-      caloCluster->SetPIDFromESD(cluster->GetPID());\r
-      caloCluster->SetNCells(cluster->GetNCells());\r
-      caloCluster->SetCellsAbsId(cluster->GetCellsAbsId());\r
-      caloCluster->SetCellsAmplitudeFraction(cluster->GetCellsAmplitudeFraction());\r
-\r
-      TArrayI* matchedT =      cluster->GetTracksMatched();\r
-      if (nTracks>0 && matchedT && cluster->GetTrackMatchedIndex() >= 0) {     \r
-       for (Int_t im = 0; im < matchedT->GetSize(); im++) {\r
-           Int_t iESDtrack = matchedT->At(im);;\r
-           if (aodTrackRefs->At(iESDtrack) != 0) {\r
-               caloCluster->AddTrackMatched((AliAODTrack*)aodTrackRefs->At(iESDtrack));\r
-           }\r
-       }\r
-      }\r
-      \r
-    } \r
-    caloClusters.Expand(jClusters); // resize TObjArray to 'remove' slots for pseudo clusters   \r
-    // end of loop on calo clusters\r
-\r
-    // fill EMCAL cell info\r
-    if (esd->GetEMCALCells()) { // protection against missing ESD information\r
-      AliESDCaloCells &esdEMcells = *(esd->GetEMCALCells());\r
-      Int_t nEMcell = esdEMcells.GetNumberOfCells() ;\r
-      \r
-      AliAODCaloCells &aodEMcells = *(AODEvent()->GetEMCALCells());\r
-      aodEMcells.CreateContainer(nEMcell);\r
-      aodEMcells.SetType(AliAODCaloCells::kEMCALCell);\r
-      for (Int_t iCell = 0; iCell < nEMcell; iCell++) {      \r
-       aodEMcells.SetCell(iCell,esdEMcells.GetCellNumber(iCell),esdEMcells.GetAmplitude(iCell));\r
-      }\r
-      aodEMcells.Sort();\r
+//______________________________________________________________________________\r
+void AliAnalysisTaskESDfilter::ConvertPHOSCells(const AliESDEvent& esd)\r
+{\r
+  AliCodeTimerAuto("",0);\r
+  // fill PHOS cell info\r
+  if (esd.GetPHOSCells()) { // protection against missing ESD information\r
+    AliESDCaloCells &esdPHcells = *(esd.GetPHOSCells());\r
+    Int_t nPHcell = esdPHcells.GetNumberOfCells() ;\r
+    \r
+    AliAODCaloCells &aodPHcells = *(AODEvent()->GetPHOSCells());\r
+    aodPHcells.CreateContainer(nPHcell);\r
+    aodPHcells.SetType(AliAODCaloCells::kPHOSCell);\r
+    for (Int_t iCell = 0; iCell < nPHcell; iCell++) {      \r
+      aodPHcells.SetCell(iCell,esdPHcells.GetCellNumber(iCell),esdPHcells.GetAmplitude(iCell));\r
     }\r
+    aodPHcells.Sort();\r
+  }\r
+}\r
 \r
-    // fill PHOS cell info\r
-    if (esd->GetPHOSCells()) { // protection against missing ESD information\r
-      AliESDCaloCells &esdPHcells = *(esd->GetPHOSCells());\r
-      Int_t nPHcell = esdPHcells.GetNumberOfCells() ;\r
+//______________________________________________________________________________\r
+void AliAnalysisTaskESDfilter::ConvertTracklets(const AliESDEvent& esd)\r
+{\r
+  // tracklets    \r
+  AliCodeTimerAuto("",0);\r
+\r
+  AliAODTracklets &SPDTracklets = *(AODEvent()->GetTracklets());\r
+  const AliMultiplicity *mult = esd.GetMultiplicity();\r
+  if (mult) {\r
+    if (mult->GetNumberOfTracklets()>0) {\r
+      SPDTracklets.CreateContainer(mult->GetNumberOfTracklets());\r
       \r
-      AliAODCaloCells &aodPHcells = *(AODEvent()->GetPHOSCells());\r
-      aodPHcells.CreateContainer(nPHcell);\r
-      aodPHcells.SetType(AliAODCaloCells::kPHOSCell);\r
-      for (Int_t iCell = 0; iCell < nPHcell; iCell++) {      \r
-       aodPHcells.SetCell(iCell,esdPHcells.GetCellNumber(iCell),esdPHcells.GetAmplitude(iCell));\r
+      for (Int_t n=0; n<mult->GetNumberOfTracklets(); n++) {\r
+        if(fMChandler){\r
+          fMChandler->SelectParticle(mult->GetLabel(n, 0));\r
+          fMChandler->SelectParticle(mult->GetLabel(n, 1));\r
+        }\r
+        SPDTracklets.SetTracklet(n, mult->GetTheta(n), mult->GetPhi(n), mult->GetDeltaPhi(n), mult->GetLabel(n, 0),mult->GetLabel(n, 1));\r
       }\r
-      aodPHcells.Sort();\r
     }\r
+  } else {\r
+    //Printf("ERROR: AliMultiplicity could not be retrieved from ESD");\r
+  }\r
+}\r
 \r
-    // tracklets    \r
-    AliAODTracklets &SPDTracklets = *(AODEvent()->GetTracklets());\r
-    const AliMultiplicity *mult = esd->GetMultiplicity();\r
-    if (mult) {\r
-      if (mult->GetNumberOfTracklets()>0) {\r
-       SPDTracklets.CreateContainer(mult->GetNumberOfTracklets());\r
-\r
-       for (Int_t n=0; n<mult->GetNumberOfTracklets(); n++) {\r
-         if(mcH){\r
-           mcH->SelectParticle(mult->GetLabel(n, 0));\r
-           mcH->SelectParticle(mult->GetLabel(n, 1));\r
-         }\r
-         SPDTracklets.SetTracklet(n, mult->GetTheta(n), mult->GetPhi(n), mult->GetDeltaPhi(n), mult->GetLabel(n, 0),mult->GetLabel(n, 1));\r
-       }\r
-      }\r
-    } else {\r
-      //Printf("ERROR: AliMultiplicity could not be retrieved from ESD");\r
-    }\r
+//______________________________________________________________________________\r
+void AliAnalysisTaskESDfilter::ConvertKinks(const AliESDEvent& esd)\r
+{\r
+  AliCodeTimerAuto("",0);\r
+  \r
+  // Kinks: it is a big mess the access to the information in the kinks\r
+  // The loop is on the tracks in order to find the mother and daugther of each kink\r
+  \r
+  Double_t covTr[21]={0.};\r
+  Double_t pid[10]={0.};\r
+  AliAODPid* detpid(0x0);\r
+  \r
+  fNumberOfKinks = esd.GetNumberOfKinks();\r
+\r
+  const AliESDVertex* vtx = esd.GetPrimaryVertex();\r
+  \r
+  for (Int_t iTrack=0; iTrack<esd.GetNumberOfTracks(); ++iTrack) \r
+  {\r
+    AliESDtrack * esdTrack = esd.GetTrack(iTrack);\r
+    \r
+    Int_t ikink = esdTrack->GetKinkIndex(0);\r
+    \r
+    if (ikink && fNumberOfKinks) {\r
+           // Negative kink index: mother, positive: daughter\r
+           \r
+           // Search for the second track of the kink\r
+           \r
+           for (Int_t jTrack = iTrack+1; jTrack<esd.GetNumberOfTracks(); ++jTrack) {\r
+        \r
+        AliESDtrack * esdTrack1 = esd.GetTrack(jTrack);\r
+        \r
+        Int_t jkink = esdTrack1->GetKinkIndex(0);\r
+        \r
+        if ( TMath::Abs(ikink)==TMath::Abs(jkink) ) {\r
+          \r
+          // The two tracks are from the same kink\r
+          \r
+          if (fUsedKink[TMath::Abs(ikink)-1]) continue; // skip used kinks\r
+          \r
+          Int_t imother = -1;\r
+          Int_t idaughter = -1;\r
+          \r
+          if (ikink<0 && jkink>0) {\r
+            \r
+            imother = iTrack;\r
+            idaughter = jTrack;\r
+          }\r
+          else if (ikink>0 && jkink<0) {\r
+            \r
+            imother = jTrack;\r
+            idaughter = iTrack;\r
+          }\r
+          else {\r
+            //                 cerr << "Error: Wrong combination of kink indexes: "\r
+            //                      << ikink << " " << jkink << endl;\r
+            continue;\r
+          }\r
+          \r
+          // Add the mother track if it passed primary track selection cuts\r
+          \r
+          AliAODTrack * mother = NULL;\r
+          \r
+          UInt_t selectInfo = 0;\r
+          if (fTrackFilter) {\r
+            selectInfo = fTrackFilter->IsSelected(esd.GetTrack(imother));\r
+            if (!selectInfo) continue;\r
+          }\r
+          \r
+          if (!fUsedTrack[imother]) {\r
+            \r
+            fUsedTrack[imother] = kTRUE;\r
+            \r
+            AliESDtrack *esdTrackM = esd.GetTrack(imother);\r
+            Double_t p[3] = { 0. };\r
+            Double_t pos[3] = { 0. };\r
+            esdTrackM->GetPxPyPz(p);\r
+            esdTrackM->GetXYZ(pos);\r
+            esdTrackM->GetCovarianceXYZPxPyPz(covTr);\r
+            esdTrackM->GetESDpid(pid);\r
+            if(fMChandler)fMChandler->SelectParticle(esdTrackM->GetLabel());\r
+            mother = \r
+            new(Tracks()[fNumberOfTracks++]) AliAODTrack(esdTrackM->GetID(),\r
+                                               esdTrackM->GetLabel(),\r
+                                               p,\r
+                                               kTRUE,\r
+                                               pos,\r
+                                               kFALSE,\r
+                                               covTr, \r
+                                               (Short_t)esdTrackM->GetSign(),\r
+                                               esdTrackM->GetITSClusterMap(), \r
+                                               pid,\r
+                                               fPrimaryVertex,\r
+                                               kTRUE, // check if this is right\r
+                                               vtx->UsesTrack(esdTrack->GetID()),\r
+                                               AliAODTrack::kPrimary,\r
+                                               selectInfo);\r
+            mother->SetTPCClusterMap(esdTrackM->GetTPCClusterMap());\r
+            mother->SetTPCSharedMap (esdTrackM->GetTPCSharedMap());\r
+            mother->SetChi2perNDF(Chi2perNDF(esdTrackM));\r
+            \r
+            fAODTrackRefs->AddAt(mother, imother);\r
+            \r
+            if (esdTrackM->GetSign() > 0) ++fNumberOfPositiveTracks;\r
+            mother->SetFlags(esdTrackM->GetStatus());\r
+            mother->ConvertAliPIDtoAODPID();\r
+            fPrimaryVertex->AddDaughter(mother);\r
+            mother->ConvertAliPIDtoAODPID();\r
+            SetAODPID(esdTrackM,mother,detpid,esd.GetMagneticField());\r
+          }\r
+          else {\r
+            //                 cerr << "Error: event " << esd.GetEventNumberInFile() << " kink " << TMath::Abs(ikink)-1\r
+            //                      << " track " << imother << " has already been used!" << endl;\r
+          }\r
+          \r
+          // Add the kink vertex\r
+          AliESDkink * kink = esd.GetKink(TMath::Abs(ikink)-1);\r
+          \r
+          AliAODVertex * vkink = \r
+          new(Vertices()[fNumberOfVertices++]) AliAODVertex(kink->GetPosition(),\r
+                                                  NULL,\r
+                                                  0.,\r
+                                                  mother,\r
+                                                  esdTrack->GetID(),  // This is the track ID of the mother's track!\r
+                                                  AliAODVertex::kKink);\r
+          // Add the daughter track\r
+          \r
+          AliAODTrack * daughter = NULL;\r
+          \r
+          if (!fUsedTrack[idaughter]) {\r
+            \r
+            fUsedTrack[idaughter] = kTRUE;\r
+            \r
+            AliESDtrack *esdTrackD = esd.GetTrack(idaughter);\r
+            Double_t p[3] = { 0. };\r
+            Double_t pos[3] = { 0. };\r
+\r
+            esdTrackD->GetPxPyPz(p);\r
+            esdTrackD->GetXYZ(pos);\r
+            esdTrackD->GetCovarianceXYZPxPyPz(covTr);\r
+            esdTrackD->GetESDpid(pid);\r
+            selectInfo = 0;\r
+            if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdTrackD);\r
+            if(fMChandler)fMChandler->SelectParticle(esdTrackD->GetLabel());\r
+            daughter = \r
+            new(Tracks()[fNumberOfTracks++]) AliAODTrack(esdTrackD->GetID(),\r
+                                               esdTrackD->GetLabel(),\r
+                                               p,\r
+                                               kTRUE,\r
+                                               pos,\r
+                                               kFALSE,\r
+                                               covTr, \r
+                                               (Short_t)esdTrackD->GetSign(),\r
+                                               esdTrackD->GetITSClusterMap(), \r
+                                               pid,\r
+                                               vkink,\r
+                                               kTRUE, // check if this is right\r
+                                               vtx->UsesTrack(esdTrack->GetID()),\r
+                                               AliAODTrack::kSecondary,\r
+                                               selectInfo);\r
+            daughter->SetTPCClusterMap(esdTrackD->GetTPCClusterMap());\r
+            daughter->SetTPCSharedMap (esdTrackD->GetTPCSharedMap());\r
+            fAODTrackRefs->AddAt(daughter, idaughter);\r
+            \r
+            if (esdTrackD->GetSign() > 0) ++fNumberOfPositiveTracks;\r
+            daughter->SetFlags(esdTrackD->GetStatus());\r
+            daughter->ConvertAliPIDtoAODPID();\r
+            vkink->AddDaughter(daughter);\r
+            daughter->ConvertAliPIDtoAODPID();\r
+            SetAODPID(esdTrackD,daughter,detpid,esd.GetMagneticField());\r
+          }\r
+          else {\r
+            //                 cerr << "Error: event " << esd.GetEventNumberInFile() << " kink " << TMath::Abs(ikink)-1\r
+            //                      << " track " << idaughter << " has already been used!" << endl;\r
+          }\r
+        }\r
+           }\r
+    }      \r
+  }\r
+}\r
+\r
+//______________________________________________________________________________\r
+void AliAnalysisTaskESDfilter::ConvertPrimaryVertices(const AliESDEvent& esd)\r
+{\r
+  AliCodeTimerAuto("",0);\r
+  \r
+  // Access to the AOD container of vertices\r
+  fNumberOfVertices = 0;\r
+  \r
+  Double_t pos[3] = { 0. };\r
+  Double_t covVtx[6] = { 0. };\r
 \r
-    delete [] usedKink;\r
-    delete [] usedV0;\r
-    delete [] usedTrack;    \r
-    delete    aodV0Refs;\r
-    delete    aodV0VtxRefs;\r
-    delete    aodTrackRefs;\r
-    if (isPidOwner) delete  esdPid;\r
-    return;\r
+  // Add primary vertex. The primary tracks will be defined\r
+  // after the loops on the composite objects (V0, cascades, kinks)\r
+  const AliESDVertex *vtx = esd.GetPrimaryVertex();\r
+  \r
+  vtx->GetXYZ(pos); // position\r
+  vtx->GetCovMatrix(covVtx); //covariance matrix\r
+  \r
+  fPrimaryVertex = new(Vertices()[fNumberOfVertices++])\r
+  AliAODVertex(pos, covVtx, vtx->GetChi2toNDF(), NULL, -1, AliAODVertex::kPrimary);\r
+  fPrimaryVertex->SetName(vtx->GetName());\r
+  fPrimaryVertex->SetTitle(vtx->GetTitle());\r
+  \r
+  TString vtitle = vtx->GetTitle();\r
+  if (!vtitle.Contains("VertexerTracks")) \r
+    fPrimaryVertex->SetNContributors(vtx->GetNContributors());\r
+  \r
+  if (fDebug > 0) fPrimaryVertex->Print();  \r
+  \r
+  // Add SPD "main" vertex \r
+  const AliESDVertex *vtxS = esd.GetPrimaryVertexSPD();\r
+  vtxS->GetXYZ(pos); // position\r
+  vtxS->GetCovMatrix(covVtx); //covariance matrix\r
+  AliAODVertex * mVSPD = new(Vertices()[fNumberOfVertices++])\r
+  AliAODVertex(pos, covVtx, vtxS->GetChi2toNDF(), NULL, -1, AliAODVertex::kMainSPD);\r
+  mVSPD->SetName(vtxS->GetName());\r
+  mVSPD->SetTitle(vtxS->GetTitle());\r
+  mVSPD->SetNContributors(vtxS->GetNContributors()); \r
+  \r
+  // Add SPD pileup vertices\r
+  for(Int_t iV=0; iV<esd.GetNumberOfPileupVerticesSPD(); ++iV)\r
+  {\r
+    const AliESDVertex *vtxP = esd.GetPileupVertexSPD(iV);\r
+    vtxP->GetXYZ(pos); // position\r
+    vtxP->GetCovMatrix(covVtx); //covariance matrix\r
+    AliAODVertex * pVSPD =  new(Vertices()[fNumberOfVertices++])\r
+    AliAODVertex(pos, covVtx, vtxP->GetChi2toNDF(), NULL, -1, AliAODVertex::kPileupSPD);\r
+    pVSPD->SetName(vtxP->GetName());\r
+    pVSPD->SetTitle(vtxP->GetTitle());\r
+    pVSPD->SetNContributors(vtxP->GetNContributors()); \r
+  }\r
+  \r
+  // Add TRK pileup vertices\r
+  for(Int_t iV=0; iV<esd.GetNumberOfPileupVerticesTracks(); ++iV)\r
+  {\r
+    const AliESDVertex *vtxP = esd.GetPileupVertexTracks(iV);\r
+    vtxP->GetXYZ(pos); // position\r
+    vtxP->GetCovMatrix(covVtx); //covariance matrix\r
+    AliAODVertex * pVTRK = new(Vertices()[fNumberOfVertices++])\r
+    AliAODVertex(pos, covVtx, vtxP->GetChi2toNDF(), NULL, -1, AliAODVertex::kPileupTracks);\r
+    pVTRK->SetName(vtxP->GetName());\r
+    pVTRK->SetTitle(vtxP->GetTitle());\r
+    pVTRK->SetNContributors(vtxP->GetNContributors());\r
+  }\r
 }\r
 \r
+//______________________________________________________________________________\r
+void AliAnalysisTaskESDfilter::ConvertVZERO(const AliESDEvent& esd)\r
+{\r
+  // Convert VZERO data\r
+  AliAODVZERO* vzeroData = AODEvent()->GetVZEROData();\r
+  *vzeroData = *(esd.GetVZEROData());\r
+}\r
 \r
-void AliAnalysisTaskESDfilter::SetAODPID(AliESDtrack *esdtrack, AliAODTrack *aodtrack, AliAODPid *detpid, Double_t bfield, AliESDpid *esdpid)\r
+//______________________________________________________________________________\r
+void AliAnalysisTaskESDfilter::ConvertESDtoAOD() \r
+{\r
+  // ESD Filter analysis task executed for each event\r
+  \r
+  AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());\r
+  \r
+  if(!esd)return;\r
+\r
+  AliCodeTimerAuto("",0);\r
+  \r
+  fOldESDformat = ( esd->GetAliESDOld() != 0x0 );\r
+  \r
+  fNumberOfTracks = 0;\r
+  fNumberOfPositiveTracks = 0;\r
+  fNumberOfV0s = 0;\r
+  fNumberOfVertices = 0;\r
+  fNumberOfCascades = 0;\r
+  fNumberOfKinks = 0;\r
+    \r
+  AliAODHeader* header = ConvertHeader(*esd);\r
+\r
+  if ( fIsVZEROEnabled ) ConvertVZERO(*esd);\r
+  \r
+  // Fetch Stack for debuggging if available \r
+  fMChandler=0x0;\r
+  if(MCEvent())\r
+  {\r
+    fMChandler = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()); \r
+  }\r
+  \r
+  // loop over events and fill them\r
+  // Multiplicity information needed by the header (to be revised!)\r
+  Int_t nTracks    = esd->GetNumberOfTracks();\r
+  for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) esd->GetTrack(iTrack)->SetESDEvent(esd);\r
+\r
+  // Update the header\r
+\r
+  Int_t nV0s      = esd->GetNumberOfV0s();\r
+  Int_t nCascades = esd->GetNumberOfCascades();\r
+  Int_t nKinks    = esd->GetNumberOfKinks();\r
+  Int_t nVertices = nV0s + nCascades /*V0 wihtin cascade already counted*/+ nKinks + 1 /* = prim. vtx*/;\r
+  Int_t nPileSPDVertices=1+esd->GetNumberOfPileupVerticesSPD(); // also SPD main vertex\r
+  Int_t nPileTrkVertices=esd->GetNumberOfPileupVerticesTracks();\r
+  nVertices+=nPileSPDVertices;\r
+  nVertices+=nPileTrkVertices;\r
+  Int_t nJets     = 0;\r
+  Int_t nCaloClus = esd->GetNumberOfCaloClusters();\r
+  Int_t nFmdClus  = 0;\r
+  Int_t nPmdClus  = esd->GetNumberOfPmdTracks();\r
+    \r
+  AliDebug(1,Form("   NV0=%d  NCASCADES=%d  NKINKS=%d", nV0s, nCascades, nKinks));\r
+       \r
+  AODEvent()->ResetStd(nTracks, nVertices, nV0s, nCascades, nJets, nCaloClus, nFmdClus, nPmdClus);\r
+\r
+  if (nV0s > 0) \r
+  {\r
+    // RefArray to store a mapping between esd V0 number and newly created AOD-Vertex V0\r
+    fAODV0VtxRefs = new TRefArray(nV0s);\r
+    // RefArray to store the mapping between esd V0 number and newly created AOD-V0\r
+    fAODV0Refs = new TRefArray(nV0s); \r
+    // Array to take into account the V0s already added to the AOD (V0 within cascades)\r
+    fUsedV0 = new Bool_t[nV0s];\r
+    for (Int_t iV0=0; iV0<nV0s; ++iV0) fUsedV0[iV0]=kFALSE;\r
+  }\r
+  \r
+  if (nTracks>0) \r
+  {\r
+    // RefArray to store the mapping between esd track number and newly created AOD-Track\r
+    \r
+    fAODTrackRefs = new TRefArray(nTracks);\r
+\r
+    // Array to take into account the tracks already added to the AOD    \r
+    fUsedTrack = new Bool_t[nTracks];\r
+    for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) fUsedTrack[iTrack]=kFALSE;\r
+  }\r
+  \r
+  // Array to take into account the kinks already added to the AOD\r
+  if (nKinks>0) \r
+  {\r
+    fUsedKink = new Bool_t[nKinks];\r
+    for (Int_t iKink=0; iKink<nKinks; ++iKink) fUsedKink[iKink]=kFALSE;\r
+  }\r
+    \r
+  ConvertPrimaryVertices(*esd);\r
+\r
+  //setting best TOF PID\r
+  fESDpid = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler())->GetESDpid();\r
+\r
+  if ( fIsPidOwner) delete fESDpid;\r
+  \r
+  if(!fESDpid)\r
+  { //in case of no Tender attached \r
+    fESDpid = new AliESDpid;\r
+    fIsPidOwner = kTRUE;\r
+  }\r
+  \r
+  if(!esd->GetTOFHeader())\r
+  { //protection in case the pass2 LHC10b,c,d have been processed without tender. \r
+    Float_t t0spread[10];\r
+    Float_t intrinsicTOFres=100; //ps ok for LHC10b,c,d pass2!! \r
+    for (Int_t i=0; i<10; i++) t0spread[i] = (TMath::Sqrt(esd->GetSigma2DiamondZ()))/0.03; //0.03 to convert from cm to ps\r
+    fESDpid->GetTOFResponse().SetT0resolution(t0spread);\r
+    fESDpid->GetTOFResponse().SetTimeResolution(intrinsicTOFres);\r
+    \r
+    fESDpid->SetTOFResponse(esd, (AliESDpid::EStartTimeType_t)fTimeZeroType);    \r
+  }\r
+  \r
+  if(esd->GetTOFHeader() && fIsPidOwner) fESDpid->SetTOFResponse(esd, (AliESDpid::EStartTimeType_t)fTimeZeroType); //in case of AOD production strating form LHC10e without Tender. \r
+  \r
+  if ( fAreCascadesEnabled ) ConvertCascades(*esd);\r
+\r
+  if ( fAreV0sEnabled ) ConvertV0s(*esd);\r
+  \r
+  if ( fAreKinksEnabled ) ConvertKinks(*esd);\r
+  \r
+  if ( fAreTracksEnabled ) ConvertTracks(*esd);\r
+  \r
+  // Update number of AOD tracks in header at the end of track loop (M.G.)\r
+  header->SetRefMultiplicity(fNumberOfTracks);\r
+  header->SetRefMultiplicityPos(fNumberOfPositiveTracks);\r
+  header->SetRefMultiplicityNeg(fNumberOfTracks - fNumberOfPositiveTracks);\r
+\r
+  if ( fTPCOnlyFilterMask ) ConvertTPCOnlyTracks(*esd);\r
+  \r
+  if ( fArePmdClustersEnabled ) ConvertPmdClusters(*esd);\r
+  \r
+  if ( fAreCaloClustersEnabled ) ConvertCaloClusters(*esd);\r
+  \r
+  if ( fAreEMCALCellsEnabled )ConvertEMCALCells(*esd);\r
+  \r
+  if ( fArePHOSCellsEnabled )ConvertPHOSCells(*esd);\r
+  \r
+  if ( fAreTrackletsEnabled ) ConvertTracklets(*esd);\r
+  \r
+  delete fAODTrackRefs; fAODTrackRefs=0x0;\r
+  delete fAODV0VtxRefs; fAODV0VtxRefs=0x0;\r
+  delete fAODV0Refs; fAODV0Refs=0x0;\r
+  \r
+  delete[] fUsedTrack; fUsedTrack=0x0;\r
+  delete[] fUsedV0; fUsedV0=0x0;\r
+  delete[] fUsedKink; fUsedKink=0x0;\r
+}\r
+\r
+\r
+//______________________________________________________________________________\r
+void AliAnalysisTaskESDfilter::SetAODPID(AliESDtrack *esdtrack, AliAODTrack *aodtrack, AliAODPid *detpid, Double_t bfield)\r
 {\r
   //\r
   // Setter for the raw PID detector signals\r
@@ -1410,13 +1637,14 @@ void AliAnalysisTaskESDfilter::SetAODPID(AliESDtrack *esdtrack, AliAODTrack *aod
     if (pidSave) {\r
       if(!aodtrack->GetDetPid()){// prevent memory leak when calling SetAODPID twice for the same track\r
        detpid = new AliAODPid();\r
-       SetDetectorRawSignals(detpid,esdtrack, bfield, esdpid);\r
+       SetDetectorRawSignals(detpid,esdtrack, bfield);\r
        aodtrack->SetDetPID(detpid);\r
       }\r
     }\r
 }\r
 \r
-void AliAnalysisTaskESDfilter::SetDetectorRawSignals(AliAODPid *aodpid, AliESDtrack *track, Double_t bfield, AliESDpid *esdpid)\r
+//______________________________________________________________________________\r
+void AliAnalysisTaskESDfilter::SetDetectorRawSignals(AliAODPid *aodpid, AliESDtrack *track, Double_t bfield)\r
 {\r
 //\r
 //assignment of the detector signals (AliXXXesdPID inspired)\r
@@ -1456,16 +1684,17 @@ void AliAnalysisTaskESDfilter::SetDetectorRawSignals(AliAODPid *aodpid, AliESDtr
  //TOF PID  \r
  Double_t times[AliAODPid::kSPECIES]; track->GetIntegratedTimes(times);\r
  aodpid->SetIntegratedTimes(times);\r
- Float_t tzeroTrack = esdpid->GetTOFResponse().GetStartTime(track->P());\r
- aodpid->SetTOFsignal(track->GetTOFsignal()-tzeroTrack);\r
 \r
- Double_t tofRes[5];\r
- for (Int_t iMass=0; iMass<5; iMass++){\r
-   tofRes[iMass]=(Double_t)esdpid->GetTOFResponse().GetExpectedSigma(track->P(), times[iMass], AliPID::ParticleMass(iMass));\r
- }\r
- aodpid->SetTOFpidResolution(tofRes);\r
\r
- aodpid->SetHMPIDsignal(track->GetHMPIDsignal());\r
+  Float_t tzeroTrack = fESDpid->GetTOFResponse().GetStartTime(track->P());\r
+  aodpid->SetTOFsignal(track->GetTOFsignal()-tzeroTrack);\r
+  \r
+  Double_t tofRes[5];\r
+  for (Int_t iMass=0; iMass<5; iMass++){\r
+    tofRes[iMass]=(Double_t)fESDpid->GetTOFResponse().GetExpectedSigma(track->P(), times[iMass], AliPID::ParticleMass(iMass));\r
+  }\r
+  aodpid->SetTOFpidResolution(tofRes);\r
+\r
+  aodpid->SetHMPIDsignal(track->GetHMPIDsignal());\r
 \r
  //Extrapolate track to EMCAL surface for AOD-level track-cluster matching\r
  Double_t emcpos[3] = {0.,0.,0.};\r
@@ -1501,7 +1730,7 @@ Double_t  AliAnalysisTaskESDfilter::Chi2perNDF(AliESDtrack* track)
  }\r
 \r
 \r
-\r
+//______________________________________________________________________________\r
 void AliAnalysisTaskESDfilter::Terminate(Option_t */*option*/)\r
 {\r
 // Terminate analysis\r
@@ -1509,6 +1738,7 @@ void AliAnalysisTaskESDfilter::Terminate(Option_t */*option*/)
     if (fDebug > 1) printf("AnalysisESDfilter: Terminate() \n");\r
 }\r
 \r
+//______________________________________________________________________________\r
 void  AliAnalysisTaskESDfilter::PrintMCInfo(AliStack *pStack,Int_t label){\r
   if(!pStack)return;\r
   label = TMath::Abs(label);\r
index 544ca30..7fb060a 100644 (file)
-#ifndef ALIANALYSISTASKESDFILTER_H\r
-#define ALIANALYSISTASKESDFILTER_H\r
\r
-/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *\r
- * See cxx source for full Copyright notice                               */\r
-\r
-/* $Id: AliAnalysisTaskESDfilter.h 24429 2008-03-12 10:27:50Z jgrosseo $ */\r
-\r
-#include <TList.h> \r
-#include <TF1.h> \r
-#include "AliAnalysisTaskSE.h"\r
-#include "AliESDtrack.h"\r
-#include "AliAODTrack.h"\r
-#include "AliAODPid.h"\r
-#include "AliESDpid.h"\r
-\r
-class AliAnalysisFilter;\r
-class AliStack;\r
-class AliESDtrack;\r
-\r
-class AliAnalysisTaskESDfilter : public AliAnalysisTaskSE\r
-{\r
- public:\r
-    AliAnalysisTaskESDfilter();\r
-    AliAnalysisTaskESDfilter(const char* name);\r
-    virtual ~AliAnalysisTaskESDfilter() {;}\r
-    // Implementation of interface methods\r
-    virtual void   UserCreateOutputObjects();\r
-    virtual void   Init();\r
-    virtual void   LocalInit() {Init();}\r
-    virtual void   UserExec(Option_t *option);\r
-    virtual void   Terminate(Option_t *option);\r
-\r
-    virtual void ConvertESDtoAOD();\r
-    // Setters\r
-    virtual void SetTrackFilter   (AliAnalysisFilter*   trackF) {fTrackFilter    =   trackF;}\r
-    virtual void SetTPCOnlyFilterMask (UInt_t filterMask)       {fTPCOnlyFilterMask    =  filterMask;}\r
-    virtual void SetKinkFilter    (AliAnalysisFilter*    KinkF) {fKinkFilter     =    KinkF;}\r
-    virtual void SetV0Filter      (AliAnalysisFilter*      V0F) {fV0Filter       =      V0F;}\r
-    virtual void SetCascadeFilter (AliAnalysisFilter* CascadeF) {fCascadeFilter  = CascadeF;}\r
-    virtual void SetPthreshold    (Double_t p)                  {fHighPthreshold =        p;}\r
-    virtual void SetPshape        (TF1 *func)                   {fPtshape        =     func;}\r
-    virtual void SetEnableFillAOD (Bool_t b)                    {fEnableFillAOD  =     b;}\r
-\r
-    virtual void SetAODPID(AliESDtrack *esdtrack, AliAODTrack *aodtrack, AliAODPid *detpid, Double_t bfield, AliESDpid *esdpid);\r
-    void SetDetectorRawSignals(AliAODPid *aodpid, AliESDtrack *track, Double_t bfield, AliESDpid *esdpid);\r
-\r
-    virtual void SetTimeZeroType(AliESDpid::EStartTimeType_t tofTimeZeroType) {fTimeZeroType = tofTimeZeroType;}\r
-\r
- private:\r
-    AliAnalysisTaskESDfilter(const AliAnalysisTaskESDfilter&);\r
-    AliAnalysisTaskESDfilter& operator=(const AliAnalysisTaskESDfilter&);\r
-    void PrintMCInfo(AliStack *pStack,Int_t label); // for debugging\r
-    Double_t Chi2perNDF(AliESDtrack* track);\r
-    \r
-    // Filtering\r
-    AliAnalysisFilter* fTrackFilter;      //  Track   Filter\r
-    AliAnalysisFilter* fKinkFilter;       //  Kink    Filter\r
-    AliAnalysisFilter* fV0Filter;         //  V0      Filter\r
-    AliAnalysisFilter* fCascadeFilter;    //  Cascade Filter\r
-    UInt_t             fTPCOnlyFilterMask;//  Fitler Mask used to select and store refitted TPC only tracks\r
-\r
-\r
-    // PID\r
-    Double_t     fHighPthreshold;    //  Pt threshold for detector signal setting\r
-    TF1 *        fPtshape;           //  Pt spectrum distribution\r
-    Bool_t       fEnableFillAOD;     //  value that decides if this task activates AOD filling\r
-    Int_t        fTimeZeroType;      //  time zero type \r
-\r
-    ClassDef(AliAnalysisTaskESDfilter, 6); // Analysis task for standard ESD filtering\r
-};\r
\r
-#endif\r
+#ifndef ALIANALYSISTASKESDFILTER_H
+#define ALIANALYSISTASKESDFILTER_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+#include <TList.h> 
+#include <TF1.h> 
+#include "AliAnalysisTaskSE.h"
+#include "AliESDtrack.h"
+#include "AliAODTrack.h"
+#include "AliAODPid.h"
+#include "AliESDpid.h"
+
+class AliAnalysisFilter;
+class AliStack;
+class AliESDtrack;
+class AliMCEventHandler;
+class TRefArray;
+class AliAODHeader;
+
+class AliAnalysisTaskESDfilter : public AliAnalysisTaskSE
+{
+ public:
+    AliAnalysisTaskESDfilter();
+    AliAnalysisTaskESDfilter(const char* name);
+    virtual ~AliAnalysisTaskESDfilter() {;}
+    // Implementation of interface methods
+    virtual void   UserCreateOutputObjects();
+    virtual void   Init();
+    virtual void   LocalInit() {Init();}
+    virtual void   UserExec(Option_t *option);
+    virtual void   Terminate(Option_t *option);
+
+    virtual void ConvertESDtoAOD();
+    // Setters
+    virtual void SetTrackFilter   (AliAnalysisFilter*   trackF) {fTrackFilter    =   trackF;}
+    virtual void SetTPCOnlyFilterMask (UInt_t filterMask)       {fTPCOnlyFilterMask    =  filterMask;}
+    virtual void SetKinkFilter    (AliAnalysisFilter*    KinkF) {fKinkFilter     =    KinkF;}
+    virtual void SetV0Filter      (AliAnalysisFilter*      V0F) {fV0Filter       =      V0F;}
+    virtual void SetCascadeFilter (AliAnalysisFilter* CascadeF) {fCascadeFilter  = CascadeF;}
+    virtual void SetPthreshold    (Double_t p)                  {fHighPthreshold =        p;}
+    virtual void SetPshape        (TF1 *func)                   {fPtshape        =     func;}
+    virtual void SetEnableFillAOD (Bool_t b)                    {fEnableFillAOD  =     b;}
+
+    virtual void SetAODPID(AliESDtrack *esdtrack, AliAODTrack *aodtrack, AliAODPid *detpid, Double_t bfield);
+    void SetDetectorRawSignals(AliAODPid *aodpid, AliESDtrack *track, Double_t bfield);
+
+  void PrintTask(Option_t *option="all", Int_t indent=0) const;
+  
+  void DisableVZERO() { fIsVZEROEnabled = kFALSE; }
+  void DisableCascades() { fAreCascadesEnabled = kFALSE; }
+  void DisableV0s() { fAreV0sEnabled = kFALSE; }
+  void DisableKinks() { fAreKinksEnabled = kFALSE; }
+  void DisableTracks() { fAreTracksEnabled = kFALSE; }
+  void DisablePmdClusters() { fArePmdClustersEnabled = kFALSE; }
+  void DisableCaloClusters() { fAreCaloClustersEnabled = kFALSE; }
+  void DisableCells() { fAreEMCALCellsEnabled = fArePHOSCellsEnabled = kFALSE; }
+  void DisableTracklets() { fAreTrackletsEnabled = kFALSE; }
+
+  virtual void SetTimeZeroType(AliESDpid::EStartTimeType_t tofTimeZeroType) {fTimeZeroType = tofTimeZeroType;}
+  
+private:
+    AliAnalysisTaskESDfilter(const AliAnalysisTaskESDfilter&);
+    AliAnalysisTaskESDfilter& operator=(const AliAnalysisTaskESDfilter&);
+    void PrintMCInfo(AliStack *pStack,Int_t label); // for debugging
+    Double_t Chi2perNDF(AliESDtrack* track);
+    
+  AliAODHeader* ConvertHeader(const AliESDEvent& esd);
+  void ConvertCascades(const AliESDEvent& esd);
+  void ConvertV0s(const AliESDEvent& esd);
+  void ConvertKinks(const AliESDEvent& esd);
+  void ConvertPrimaryVertices(const AliESDEvent& esd);
+  void ConvertTracks(const AliESDEvent& esd);
+  void ConvertPmdClusters(const AliESDEvent& esd);
+  void ConvertCaloClusters(const AliESDEvent& esd);
+  void ConvertEMCALCells(const AliESDEvent& esd);
+  void ConvertPHOSCells(const AliESDEvent& esd);
+  void ConvertTracklets(const AliESDEvent& esd);
+  void ConvertTPCOnlyTracks(const AliESDEvent& esd);
+  void ConvertVZERO(const AliESDEvent& esd);
+  
+  TClonesArray& Tracks();
+  TClonesArray& V0s();
+  TClonesArray& Vertices();
+  TClonesArray& Cascades();
+  
+  // Filtering
+  AliAnalysisFilter* fTrackFilter;      //  Track   Filter
+  AliAnalysisFilter* fKinkFilter;       //  Kink    Filter
+  AliAnalysisFilter* fV0Filter;         //  V0      Filter
+  AliAnalysisFilter* fCascadeFilter;    //  Cascade Filter
+  // PID
+  Double_t     fHighPthreshold;    //  Pt threshold for detector signal setting
+  TF1 *        fPtshape;           //  Pt spectrum distribution
+  Bool_t       fEnableFillAOD;     //  value that decides if this task activates AOD filling
+  Bool_t* fUsedTrack; //! indices of used tracks
+  Bool_t* fUsedKink; //! indices of used kinks
+  Bool_t* fUsedV0; //! indices of used V0s
+  TRefArray* fAODTrackRefs; // array of track references
+  TRefArray* fAODV0VtxRefs; // array of v0 vertices references
+  TRefArray* fAODV0Refs ; // array of v0s references
+  AliMCEventHandler* fMChandler; // pointer to MC handler (if any)
+  Int_t fNumberOfTracks; // current number of tracks
+  Int_t fNumberOfPositiveTracks; // current number of positive tracks
+  Int_t fNumberOfV0s; // current number of v0s
+  Int_t fNumberOfVertices; // current number of vertices
+  Int_t fNumberOfCascades; // current number of cascades
+  Int_t fNumberOfKinks; // current number of kinks
+  Bool_t fOldESDformat; // is the ESD in old format ?
+  AliAODVertex* fPrimaryVertex; // pointer to primary vertex of the event
+  UInt_t fTPCOnlyFilterMask; //  Filter Mask used to select and store refitted TPC only tracks
+  Bool_t fIsVZEROEnabled; // whether or not to fill the vzero branch (true by default)
+  Bool_t fAreCascadesEnabled; // whether or not to fill the cascades branch (true by default)
+  Bool_t fAreV0sEnabled; // whether or not to fill the v0 branch (true by default)
+  Bool_t fAreKinksEnabled; // whether or not to fill the kinks (true by default)
+  Bool_t fAreTracksEnabled; // whether or not to fill the (central) tracks branch (true by default)
+  Bool_t fArePmdClustersEnabled; // whether or not to fill the pmd clusters (true by default)
+  Bool_t fAreCaloClustersEnabled; // whether or not to fill the calo clusters (true by default)
+  Bool_t fAreEMCALCellsEnabled; // whether or not to fill the emcal cells (true by default)
+  Bool_t fArePHOSCellsEnabled; // whether or not to fill the phos cells (true by default)
+  Bool_t fAreTrackletsEnabled; // whether or not to fill the tracklets (true by default)
+  AliESDpid* fESDpid; // esd pid
+  Bool_t fIsPidOwner; // whether we own fESDpid
+  Int_t fTimeZeroType;  //  time zero type 
+  
+  ClassDef(AliAnalysisTaskESDfilter, 8); // Analysis task for standard ESD filtering
+};
+#endif
index 95f6812..50e5e9d 100644 (file)
@@ -41,8 +41,12 @@ AliAnalysisTaskESDfilter *AddTaskESDFilter(Bool_t useKineFilter=kTRUE,
    //===========================================================================   
    // Barrel tracks filter
    AliAnalysisTaskESDfilter *esdfilter = new AliAnalysisTaskESDfilter("ESD Filter");
-   mgr->AddTask(esdfilter);
    esdfilter->SetTimeZeroType(tofTimeZeroType);
+   esdfilter->DisableCascades();
+   esdfilter->DisableKinks();
+  
+   mgr->AddTask(esdfilter);
+  
    // Muons
    AliAnalysisTaskESDMuonFilter *esdmuonfilter = new AliAnalysisTaskESDMuonFilter("ESD Muon Filter");
    mgr->AddTask(esdmuonfilter);