Compatibility with ROOT trunk
authorfca <fca@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 11 Jun 2012 08:43:23 +0000 (08:43 +0000)
committerfca <fca@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 11 Jun 2012 08:43:23 +0000 (08:43 +0000)
22 files changed:
ALIROOT/aliroot.cxx
ANALYSIS/AliAnalysisAlien.cxx
ANALYSIS/AliAnalysisDataContainer.cxx
ANALYSIS/AliAnalysisDataSlot.cxx
ANALYSIS/AliAnalysisManager.cxx
ANALYSIS/AliAnalysisSelector.cxx
ANALYSIS/AliAnalysisStatistics.cxx
ANALYSIS/AliAnalysisTaskCfg.cxx
ANALYSIS/AliAnalysisTaskESDfilter.cxx
ANALYSIS/AliAnalysisTaskTagCreator.cxx
ANALYSIS/AliEPSelectionTask.cxx
ANALYSIS/AliEventPoolManager.cxx
ANALYSIS/AliEventPoolManager.h
ANALYSIS/AliFileMerger.cxx
ANALYSIS/AliPhysicsSelection.cxx
ANALYSIS/AliXMLCollection.h
EVE/EveDet/AliEveEMCALData.cxx
EVE/EveDet/AliEveMUONData.cxx
EVE/EveDet/AliEveMUONTrack.cxx
HLT/BASE/AliHLTTriggerMenuItem.cxx
MONITOR/AliQAHistNavigator.cxx
TPC/AliTPCPreprocessorOffline.cxx

index c41e6dc..5ec45de 100644 (file)
@@ -56,6 +56,9 @@ extern "C" void g95_runtime_start();
   extern "C" int __mb_cur_max=0; 
 #endif 
 
+using std::cout;
+using std::endl;
+
 //_____________________________________________________________________________
 int main(int argc, char **argv)
 {
index 4751770..37c626d 100644 (file)
 #include "AliAnalysisDataContainer.h"
 #include "AliMultiInputEventHandler.h"
 
+using std::ofstream;
+using std::ifstream;
+using std::ios;
+using std::endl;
 ClassImp(AliAnalysisAlien)
 #if 0
 ;
index 6e5a1d5..f875e86 100644 (file)
@@ -56,6 +56,8 @@
 #include "AliAnalysisDataSlot.h"
 #include "AliAnalysisTask.h"
 
+using std::endl;
+using std::cout;
 ClassImp(AliAnalysisDataContainer)
 
 //______________________________________________________________________________
index 343853f..ddcf4fd 100644 (file)
@@ -49,6 +49,8 @@
 #include "AliAnalysisTask.h"
 #include "AliAnalysisDataContainer.h"
 
+using std::endl;
+using std::cout;
 ClassImp(AliAnalysisDataSlot)
 
 //______________________________________________________________________________
index 3469022..ed0a154 100644 (file)
 #include "AliSysInfo.h"
 #include "AliAnalysisStatistics.h"
 
+using std::ofstream;
+using std::ios;
+using std::cout;
+using std::endl;
 ClassImp(AliAnalysisManager)
 
 AliAnalysisManager *AliAnalysisManager::fgAnalysisManager = NULL;
index cfb07a4..b9d18f5 100644 (file)
@@ -30,6 +30,8 @@
 #include "AliAnalysisDataContainer.h"
 #include "AliAnalysisSelector.h"
 
+using std::cout;
+using std::endl;
 ClassImp(AliAnalysisSelector)
 
 //______________________________________________________________________________
index 5c8950d..9b1e30b 100644 (file)
@@ -30,6 +30,8 @@
 
 #include "AliVEvent.h"
 
+using std::cout;
+using std::endl;
 ClassImp(AliAnalysisStatistics)
 
 //______________________________________________________________________________
index 731438d..3b5ba7d 100644 (file)
@@ -73,6 +73,11 @@ __R_ADDTASK__->SelectCollisionCandidates();
 // the right order in the grid handler to generate train macros.
 
 
+using std::cout;
+using std::endl;
+using std::ios;
+using std::ofstream;
+using std::ifstream;
 ClassImp(AliAnalysisTaskCfg)
 
 //______________________________________________________________________________
index 2f58330..2ff038d 100644 (file)
-/**************************************************************************\r
- * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *\r
- *                                                                        *\r
- * Author: The ALICE Off-line Project.                                    *\r
- * Contributors are mentioned in the code where appropriate.              *\r
- *                                                                        *\r
- * Permission to use, copy, modify and distribute this software and its   *\r
- * documentation strictly for non-commercial purposes is hereby granted   *\r
- * without fee, provided that the above copyright notice appears in all   *\r
- * copies and that both the copyright notice and this permission notice   *\r
- * appear in the supporting documentation. The authors make no claims     *\r
- * about the suitability of this software for any purpose. It is          *\r
- * provided "as is" without express or implied warranty.                  *\r
- **************************************************************************/\r
-\r
-/* $Id$ */\r
\r
-#include <TChain.h>\r
-#include <TTree.h>\r
-#include <TList.h>\r
-#include <TArrayI.h>\r
-#include <TParameter.h>\r
-#include <TRandom.h>\r
-#include <TParticle.h>\r
-#include <TFile.h>\r
-\r
-#include "AliAnalysisTaskESDfilter.h"\r
-#include "AliAnalysisManager.h"\r
-#include "AliESDEvent.h"\r
-#include "AliESDRun.h"\r
-#include "AliStack.h"\r
-#include "AliAODEvent.h"\r
-#include "AliMCEvent.h"\r
-#include "AliMCEventHandler.h"\r
-#include "AliESDInputHandler.h"\r
-#include "AliAODHandler.h"\r
-#include "AliAODMCParticle.h"\r
-#include "AliAnalysisFilter.h"\r
-#include "AliESDMuonTrack.h"\r
-#include "AliESDVertex.h"\r
-#include "AliCentrality.h"\r
-#include "AliEventplane.h"\r
-#include "AliESDv0.h"\r
-#include "AliESDkink.h"\r
-#include "AliESDcascade.h"\r
-#include "AliESDPmdTrack.h"\r
-#include "AliESDCaloCluster.h"\r
-#include "AliESDCaloCells.h"\r
-#include "AliMultiplicity.h"\r
-#include "AliLog.h"\r
-#include "AliCodeTimer.h"\r
-#include "AliESDtrackCuts.h"\r
-#include "AliESDpid.h"\r
-#include "AliV0vertexer.h"\r
-#include "AliCascadeVertexer.h"\r
-#include "Riostream.h"\r
-#include "AliExternalTrackParam.h"\r
-#include "AliTrackerBase.h"\r
-#include "TVector3.h"\r
-#include "AliTPCdEdxInfo.h"\r
-\r
-ClassImp(AliAnalysisTaskESDfilter)\r
-\r
-////////////////////////////////////////////////////////////////////////\r
-\r
-AliAnalysisTaskESDfilter::AliAnalysisTaskESDfilter():\r
-  AliAnalysisTaskSE(),\r
-  fTrackFilter(0x0),\r
-  fKinkFilter(0x0),\r
-  fV0Filter(0x0),\r
-  fCascadeFilter(0x0),\r
-  fHighPthreshold(0),\r
-  fPtshape(0x0),\r
-  fEnableFillAOD(kTRUE),\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
-  fTPCConstrainedFilterMask(0),\r
-  fHybridFilterMaskTPCCG(0),\r
-  fWriteHybridTPCCOnly(kFALSE),\r
-  fGlobalConstrainedFilterMask(0),\r
-  fHybridFilterMaskGCG(0),\r
-  fWriteHybridGCOnly(kFALSE),\r
-  fIsVZEROEnabled(kTRUE),\r
-  fIsTZEROEnabled(kTRUE),\r
-  fIsZDCEnabled(kTRUE),\r
-  fIsV0CascadeRecoEnabled(kFALSE),\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
-  fAreEMCALTriggerEnabled(kTRUE),\r
-  fArePHOSTriggerEnabled(kTRUE),\r
-  fAreTrackletsEnabled(kTRUE),\r
-  fESDpid(0x0),\r
-  fIsPidOwner(kFALSE),\r
-  fTimeZeroType(AliESDpid::kTOF_T0),\r
-  fTPCaloneTrackCuts(0),\r
-  fDoPropagateTrackToEMCal(kTRUE)\r
-{\r
-  // Default constructor\r
-    fV0Cuts[0] =  33.   ;   // max allowed chi2\r
-    fV0Cuts[1] =   0.1  ;   // min allowed impact parameter for the 1st daughter\r
-    fV0Cuts[2] =   0.1  ;   // min allowed impact parameter for the 2nd daughter\r
-    fV0Cuts[3] =   1.   ;   // max allowed DCA between the daughter tracks\r
-    fV0Cuts[4] =    .998;   // min allowed cosine of V0's pointing angle\r
-    fV0Cuts[5] =   0.9  ;   // min radius of the fiducial volume\r
-    fV0Cuts[6] = 100.   ;   // max radius of the fiducial volume\r
-\r
-    fCascadeCuts[0] =  33.   ; // max allowed chi2 (same as PDC07)\r
-    fCascadeCuts[1] =   0.05 ; // min allowed V0 impact parameter\r
-    fCascadeCuts[2] =   0.008; // "window" around the Lambda mass\r
-    fCascadeCuts[3] =   0.03 ; // min allowed bachelor's impact parameter\r
-    fCascadeCuts[4] =   0.3  ; // max allowed DCA between the V0 and the bachelor\r
-    fCascadeCuts[5] =   0.999; // min allowed cosine of the cascade pointing angle\r
-    fCascadeCuts[6] =   0.9  ; // min radius of the fiducial volume\r
-    fCascadeCuts[7] = 100.   ; // max radius of the fiducial volume\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
-    fHighPthreshold(0),\r
-    fPtshape(0x0),\r
-    fEnableFillAOD(kTRUE),\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
-  fTPCConstrainedFilterMask(0),\r
-  fHybridFilterMaskTPCCG(0),\r
-  fWriteHybridTPCCOnly(kFALSE),\r
-  fGlobalConstrainedFilterMask(0),\r
-  fHybridFilterMaskGCG(0),\r
-  fWriteHybridGCOnly(kFALSE),\r
-    fIsVZEROEnabled(kTRUE),\r
-    fIsTZEROEnabled(kTRUE),\r
-    fIsZDCEnabled(kTRUE),\r
-    fIsV0CascadeRecoEnabled(kFALSE),\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
-               fAreEMCALTriggerEnabled(kTRUE),\r
-               fArePHOSTriggerEnabled(kTRUE),\r
-               fAreTrackletsEnabled(kTRUE),\r
-    fESDpid(0x0),\r
-    fIsPidOwner(kFALSE),\r
-    fTimeZeroType(AliESDpid::kTOF_T0),\r
-    fTPCaloneTrackCuts(0),\r
-  fDoPropagateTrackToEMCal(kTRUE)\r
-{\r
-  // Constructor\r
-\r
-    fV0Cuts[0] =  33.   ;   // max allowed chi2\r
-    fV0Cuts[1] =   0.1  ;   // min allowed impact parameter for the 1st daughter\r
-    fV0Cuts[2] =   0.1  ;   // min allowed impact parameter for the 2nd daughter\r
-    fV0Cuts[3] =   1.   ;   // max allowed DCA between the daughter tracks\r
-    fV0Cuts[4] =    .998;   // min allowed cosine of V0's pointing angle\r
-    fV0Cuts[5] =   0.9  ;   // min radius of the fiducial volume\r
-    fV0Cuts[6] = 100.   ;   // max radius of the fiducial volume\r
-\r
-    fCascadeCuts[0] =  33.   ; // max allowed chi2 (same as PDC07)\r
-    fCascadeCuts[1] =   0.05 ; // min allowed V0 impact parameter\r
-    fCascadeCuts[2] =   0.008; // "window" around the Lambda mass\r
-    fCascadeCuts[3] =   0.03 ; // min allowed bachelor's impact parameter\r
-    fCascadeCuts[4] =   0.3  ; // max allowed DCA between the V0 and the bachelor\r
-    fCascadeCuts[5] =   0.999; // min allowed cosine of the cascade pointing angle\r
-    fCascadeCuts[6] =   0.9  ; // min radius of the fiducial volume\r
-    fCascadeCuts[7] = 100.   ; // max radius of the fiducial volume\r
-\r
-\r
-\r
-}\r
-AliAnalysisTaskESDfilter::~AliAnalysisTaskESDfilter(){\r
-    if(fIsPidOwner) delete fESDpid;\r
-}\r
-//______________________________________________________________________________\r
-void AliAnalysisTaskESDfilter::UserCreateOutputObjects()\r
-{\r
-  //\r
-  // Create Output Objects conenct filter to outputtree\r
-  // \r
-  if(OutputTree())\r
-  {\r
-    OutputTree()->GetUserInfo()->Add(fTrackFilter);\r
-  }\r
-  else\r
-  {\r
-    AliError("No OutputTree() for adding the track filter");\r
-  }\r
-  fTPCaloneTrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();\r
-}\r
-\r
-//______________________________________________________________________________\r
-void AliAnalysisTaskESDfilter::Init()\r
-{\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
-// Print selection task information\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("EMCAL triggers are %s",fAreEMCALTriggerEnabled ? "ENABLED":"DISABLED") << endl;\r
-       cout << spaces.Data() << Form("PHOS triggers  are %s",fArePHOSTriggerEnabled ? "ENABLED":"DISABLED") << endl;\r
-       cout << spaces.Data() << Form("Tracklets      are %s",fAreTrackletsEnabled ? "ENABLED":"DISABLED") << endl;  \r
-       cout << spaces.Data() << Form("PropagateTrackToEMCal  is %s", fDoPropagateTrackToEMCal ? "ENABLED":"DISABLED") << endl; \r
-}\r
-\r
-//______________________________________________________________________________\r
-void AliAnalysisTaskESDfilter::UserExec(Option_t */*option*/)\r
-{\r
-// Execute analysis for current event\r
-//\r
-                                           \r
-  Long64_t ientry = Entry();\r
-  \r
-  if (fDebug > 0) {\r
-      printf("Filter: Analysing event # %5d\n", (Int_t) ientry);\r
-      if (fHighPthreshold == 0) AliInfo("detector PID signals are stored in each track");\r
-      if (!fPtshape) AliInfo("detector PID signals are not stored below the pt threshold");\r
-  }\r
-  // Filters must explicitely enable AOD filling in their UserExec (AG)\r
-  if (!AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()) AliFatal("Cannot run ESD filter without an output event handler");\r
-  if(fEnableFillAOD) {\r
-     AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kTRUE);\r
-     AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillExtension(kTRUE);\r
-  }   \r
-  ConvertESDtoAOD();\r
-}\r
-\r
-//______________________________________________________________________________\r
-TClonesArray& AliAnalysisTaskESDfilter::Cascades()\r
-{\r
-  return *(AODEvent()->GetCascades());\r
-}\r
-\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
-//______________________________________________________________________________\r
-TClonesArray& AliAnalysisTaskESDfilter::Vertices()\r
-{\r
-  return *(AODEvent()->GetVertices());\r
-}\r
-\r
-//______________________________________________________________________________\r
-AliAODHeader* AliAnalysisTaskESDfilter::ConvertHeader(const AliESDEvent& esd)\r
-{\r
-// Convert header information\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
-  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
-    header->SetEventplane(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(const_cast<AliESDEvent&>(esd).GetCentrality()){\r
-      header->SetCentrality(const_cast<AliESDEvent&>(esd).GetCentrality());\r
-    }\r
-    else{\r
-      header->SetCentrality(0);\r
-    }\r
-    if(const_cast<AliESDEvent&>(esd).GetEventplane()){\r
-      header->SetEventplane(const_cast<AliESDEvent&>(esd).GetEventplane());\r
-    }\r
-    else{\r
-      header->SetEventplane(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
-  // ITS Cluster Multiplicty\r
-  const AliMultiplicity *mult = esd.GetMultiplicity();\r
-  for (Int_t ilay = 0; ilay < 6; ilay++) header->SetITSClusters(ilay, mult->GetNumberOfITSClusters(ilay));\r
-  \r
-  // TPC only Reference Multiplicty\r
-  Int_t refMult  = fTPCaloneTrackCuts ? (Short_t)fTPCaloneTrackCuts->GetReferenceMultiplicity(&esd, kTRUE) : -1;\r
-  header->SetTPConlyRefMultiplicity(refMult);\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
-  // VZERO channel equalization factors for event-plane reconstruction          \r
-  header->SetVZEROEqFactors(esd.GetVZEROEqFactors());\r
-\r
-  return header;\r
-}\r
-\r
-//______________________________________________________________________________\r
-void AliAnalysisTaskESDfilter::ConvertCascades(const AliESDEvent& esd) \r
-{\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
-    // 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<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(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::EStartTimeType_t)fTimeZeroType); //in case of AOD production starting form LHC10e without Tender. \r
-\r
-\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 (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->SetTPCFitMap(esdCascadeBach->GetTPCFitMap());\r
-           aodTrack->SetTPCClusterMap(esdCascadeBach->GetTPCClusterMap());\r
-           aodTrack->SetTPCSharedMap (esdCascadeBach->GetTPCSharedMap());\r
-           aodTrack->SetChi2perNDF(Chi2perNDF(esdCascadeBach));\r
-           aodTrack->SetTPCPointsF(esdCascadeBach->GetTPCNclsF());\r
-           fAODTrackRefs->AddAt(aodTrack,idxBachFromCascade);\r
-           \r
-           if (esdCascadeBach->GetSign() > 0) ++fNumberOfPositiveTracks;\r
-           aodTrack->ConvertAliPIDtoAODPID();\r
-           aodTrack->SetFlags(esdCascadeBach->GetStatus());\r
-      SetAODPID(esdCascadeBach,aodTrack,detpid);\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(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->SetTPCFitMap(esdCascadePos->GetTPCFitMap());\r
-        aodTrack->SetTPCClusterMap(esdCascadePos->GetTPCClusterMap());\r
-        aodTrack->SetTPCSharedMap (esdCascadePos->GetTPCSharedMap());\r
-        aodTrack->SetChi2perNDF(Chi2perNDF(esdCascadePos));\r
-       aodTrack->SetTPCPointsF(esdCascadePos->GetTPCNclsF());\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);\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->SetTPCFitMap(esdCascadeNeg->GetTPCFitMap());\r
-        aodTrack->SetTPCClusterMap(esdCascadeNeg->GetTPCClusterMap());\r
-        aodTrack->SetTPCSharedMap (esdCascadeNeg->GetTPCSharedMap());\r
-        aodTrack->SetChi2perNDF(Chi2perNDF(esdCascadeNeg));\r
-       aodTrack->SetTPCPointsF(esdCascadeNeg->GetTPCNclsF());\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);\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()[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
-    // 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
-    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 > 10) {\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
-    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 (!fOldESDformat) {\r
-           chi2 = v0->GetChi2V0(); // = chi2/NDF since NDF = 2*2-3\r
-           v0->GetPosCov(covVtx);\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()[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(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->SetTPCFitMap(esdV0Pos->GetTPCFitMap());\r
-           aodTrack->SetTPCClusterMap(esdV0Pos->GetTPCClusterMap());\r
-           aodTrack->SetTPCSharedMap (esdV0Pos->GetTPCSharedMap());\r
-           aodTrack->SetChi2perNDF(Chi2perNDF(esdV0Pos));\r
-           aodTrack->SetTPCPointsF(esdV0Pos->GetTPCNclsF());\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) ++fNumberOfPositiveTracks;\r
-           aodTrack->ConvertAliPIDtoAODPID();\r
-           aodTrack->SetFlags(esdV0Pos->GetStatus());\r
-      SetAODPID(esdV0Pos,aodTrack,detpid);\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 (!fUsedTrack[negFromV0]) {\r
-           fUsedTrack[negFromV0] = kTRUE;\r
-           UInt_t selectInfo = 0;\r
-           if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdV0Neg);\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->SetTPCFitMap(esdV0Neg->GetTPCFitMap());\r
-           aodTrack->SetTPCClusterMap(esdV0Neg->GetTPCClusterMap());\r
-           aodTrack->SetTPCSharedMap (esdV0Neg->GetTPCSharedMap());\r
-           aodTrack->SetChi2perNDF(Chi2perNDF(esdV0Neg));\r
-           aodTrack->SetTPCPointsF(esdV0Neg->GetTPCNclsF());\r
-           \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) ++fNumberOfPositiveTracks;\r
-           aodTrack->ConvertAliPIDtoAODPID();\r
-           aodTrack->SetFlags(esdV0Neg->GetStatus());\r
-      SetAODPID(esdV0Neg,aodTrack,detpid);\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
-    \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
-  V0s().Expand(fNumberOfV0s);   \r
-}\r
-\r
-//______________________________________________________________________________\r
-void AliAnalysisTaskESDfilter::ConvertTPCOnlyTracks(const AliESDEvent& esd)\r
-{\r
-  // Convert TPC only tracks\r
-  // Here we have wo hybrid appraoch to remove fakes\r
-  // ******* ITSTPC ********\r
-  // Uses a cut on the ITS properties to select global tracks\r
-  // which are than marked as HybdridITSTPC for the remainder \r
-  // the TPC only tracks are flagged as HybridITSTPConly. \r
-  // Note, in order not to get fakes back in the TPC cuts, one needs \r
-  // two "ITS" cuts one tight (1) (to throw out fakes) and one lose (2) (to NOT flag the trakcs in the TPC only)\r
-  // using cut number (3)\r
-  // so fHybridFilterMask == (1)|(2) fTPCFilterMask = (3), Usercode needs to slect with mask = (1)|(3) and track->IsHybridITSTPC()\r
-  // ******* TPC ********\r
-  // Here, only TPC tracks are flagged that pass the tight ITS cuts and tracks that pass the TPC cuts and NOT the loose ITS cuts\r
-  // the ITS cuts neeed to be added to the filter as extra cuts, since here the selections info is reset in the global and put to the TPC only track\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&fTPCConstrainedFilterMask){\r
-      // we only reset the track select ionfo, no deletion...\r
-      tr->SetFilterMap(map&~fTPCConstrainedFilterMask);\r
-    }\r
-    if(map&fHybridFilterMaskTPCCG){\r
-      // this is one part of the hybrid tracks\r
-      // the others not passing the selection will be TPC only selected below\r
-      tr->SetIsHybridTPCConstrainedGlobal(kTRUE);\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
-\r
-\r
-  Double_t p[3] = { 0. };\r
-\r
-  Double_t pDCA[3] = { 0. }; // momentum at DCA\r
-  Double_t rDCA[3] = { 0. }; // position at DCA\r
-  Float_t  dDCA[2] = {0.};    // DCA to the vertex d and z\r
-  Float_t  cDCA[3] = {0.};    // covariance of impact parameters\r
-\r
-\r
-  AliAODTrack* aodTrack(0x0);\r
-  //  AliAODPid* detpid(0x0);\r
-\r
-  // account for change in pT after the constraint\r
-  Float_t ptMax = 1E10;\r
-  Float_t ptMin = 0;\r
-  for(int i = 0;i<32;i++){\r
-    if(fTPCConstrainedFilterMask&(1<<i)){\r
-      AliESDtrackCuts*cuts = (AliESDtrackCuts*)fTrackFilter->GetCuts()->At(i);\r
-      Float_t tmp1= 0,tmp2 = 0;\r
-      cuts->GetPtRange(tmp1,tmp2);\r
-      if(tmp1>ptMin)ptMin=tmp1;\r
-      if(tmp2<ptMax)ptMax=tmp2;\r
-    }\r
-  } \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
-    Bool_t isHybridITSTPC = false;\r
-    //\r
-    // Track selection\r
-    if (fTrackFilter) {\r
-      selectInfo = fTrackFilter->IsSelected(esdTrack);\r
-    }\r
-\r
-    if(!(selectInfo&fHybridFilterMaskTPCCG)){\r
-      // not already selected tracks, use second part of hybrid tracks\r
-      isHybridITSTPC = true;\r
-      // too save space one could only store these...\r
-    }\r
-\r
-    selectInfo &= fTPCConstrainedFilterMask;\r
-    if (!selectInfo)continue;\r
-    if (fWriteHybridTPCCOnly&&!isHybridITSTPC)continue; // write only complementary tracks\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->RelateToVertexTPC(vtxSPD,esd.GetMagneticField(),kVeryBig,&exParam);\r
-      if(!relate){\r
-        delete track;\r
-        continue;\r
-      }\r
-      // fetch the track parameters at the DCA (unconstraint)\r
-      if(track->GetTPCInnerParam()){\r
-       track->GetTPCInnerParam()->GetPxPyPz(pDCA);\r
-       track->GetTPCInnerParam()->GetXYZ(rDCA);\r
-      }\r
-      // get the DCA to the vertex:\r
-      track->GetImpactParametersTPC(dDCA,cDCA);\r
-      // set the constrained parameters to the track\r
-      track->Set(exParam.GetX(),exParam.GetAlpha(),exParam.GetParameter(),exParam.GetCovariance());\r
-    }\r
-    \r
-    track->GetPxPyPz(p);\r
-\r
-    Float_t pT = track->Pt();\r
-    if(pT<ptMin||pT>ptMax){\r
-      delete track;\r
-      continue;\r
-    }\r
-\r
-    // \r
-\r
-\r
-    track->GetXYZ(pos);\r
-    track->GetCovarianceXYZPxPyPz(covTr);\r
-    esdTrack->GetESDpid(pid);// original PID\r
-\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->SetIsHybridTPCConstrainedGlobal(isHybridITSTPC);    \r
-    aodTrack->SetTPCFitMap(track->GetTPCFitMap());\r
-    aodTrack->SetTPCClusterMap(track->GetTPCClusterMap());\r
-    aodTrack->SetTPCSharedMap (track->GetTPCSharedMap());\r
-    aodTrack->SetIsTPCConstrained(kTRUE);    \r
-    aodTrack->SetChi2perNDF(Chi2perNDF(esdTrack)); // original track\r
-    // set the DCA values to the AOD track\r
-    aodTrack->SetPxPyPzAtDCA(pDCA[0],pDCA[1],pDCA[2]);\r
-    aodTrack->SetXYAtDCA(rDCA[0],rDCA[1]);\r
-    aodTrack->SetDCA(dDCA[0],dDCA[1]);\r
-\r
-    aodTrack->SetFlags(track->GetStatus());\r
-    aodTrack->SetTPCPointsF(track->GetTPCNclsF());\r
-\r
-    // do not duplicate PID information \r
-    //    aodTrack->ConvertAliPIDtoAODPID();\r
-    //    SetAODPID(esdTrack,aodTrack,detpid);\r
-\r
-    delete track;\r
-  } // end of loop on tracks\r
-  \r
-}\r
-\r
-\r
-void AliAnalysisTaskESDfilter::ConvertGlobalConstrainedTracks(const AliESDEvent& esd)\r
-{\r
-\r
-  // Here we have the option to store the complement from global constraint information\r
-  // to tracks passing tight cuts (1) in order not to get fakes back in, one needs \r
-  // two sets of cuts one tight (1) (to throw out fakes) and one lose (2) (fakes/bad tracks would pass (2) but not (1))\r
-  // using cut number (3) selects the tracks that complement (1) e.g. tracks witout ITS refit or cluster requirement\r
-\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&fGlobalConstrainedFilterMask){\r
-      // we only reset the track select info, no deletion...\r
-      // mask reset mask in case track is already taken\r
-      tr->SetFilterMap(map&~fGlobalConstrainedFilterMask);\r
-    }\r
-    if(map&fHybridFilterMaskGCG){\r
-      // this is one part of the hybrid tracks\r
-      // the others not passing the selection will be the ones selected below\r
-      tr->SetIsHybridGlobalConstrainedGlobal(kTRUE);\r
-    }\r
-  }\r
-  // Loop over the ESD trcks and pick out the tracks passing the GlobalConstraint cuts\r
\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
-\r
-  Double_t pDCA[3] = { 0. }; // momentum at DCA\r
-  Double_t rDCA[3] = { 0. }; // position at DCA\r
-  Float_t  dDCA[2] = {0.};    // DCA to the vertex d and z\r
-  Float_t  cDCA[3] = {0.};    // covariance of impact parameters\r
-\r
-\r
-  AliAODTrack* aodTrack(0x0);\r
-  AliAODPid* detpid(0x0);\r
-  const AliESDVertex *vtx = esd.GetPrimaryVertex();\r
-\r
-  // account for change in pT after the constraint\r
-  Float_t ptMax = 1E10;\r
-  Float_t ptMin = 0;\r
-  for(int i = 0;i<32;i++){\r
-    if(fGlobalConstrainedFilterMask&(1<<i)){\r
-      AliESDtrackCuts*cuts = (AliESDtrackCuts*)fTrackFilter->GetCuts()->At(i);\r
-      Float_t tmp1= 0,tmp2 = 0;\r
-      cuts->GetPtRange(tmp1,tmp2);\r
-      if(tmp1>ptMin)ptMin=tmp1;\r
-      if(tmp2<ptMax)ptMax=tmp2;\r
-    }\r
-  } \r
-\r
-\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
-    const AliExternalTrackParam * exParamGC = esdTrack->GetConstrainedParam();\r
-    if(!exParamGC)continue;\r
-\r
-    UInt_t selectInfo = 0;\r
-    Bool_t isHybridGC = false;\r
-\r
-    //\r
-    // Track selection\r
-    if (fTrackFilter) {\r
-      selectInfo = fTrackFilter->IsSelected(esdTrack);\r
-    }\r
-\r
-\r
-    if(!(selectInfo&fHybridFilterMaskGCG))isHybridGC = true;\r
-    if (fWriteHybridGCOnly&&!isHybridGC)continue; // write only complementary tracks\r
-\r
-    selectInfo &= fGlobalConstrainedFilterMask;\r
-    if (!selectInfo)continue;\r
-    // fetch the track parameters at the DCA (unconstrained)\r
-    esdTrack->GetPxPyPz(pDCA);\r
-    esdTrack->GetXYZ(rDCA);\r
-    // get the DCA to the vertex:\r
-    esdTrack->GetImpactParameters(dDCA,cDCA);\r
-\r
-    if (!esdTrack->GetConstrainedPxPyPz(p)) continue;\r
-\r
-\r
-    Float_t pT = exParamGC->Pt();\r
-    if(pT<ptMin||pT>ptMax){\r
-      continue;\r
-    }\r
-\r
-\r
-    esdTrack->GetConstrainedXYZ(pos);\r
-    exParamGC->GetCovarianceXYZPxPyPz(covTr);\r
-    esdTrack->GetESDpid(pid);\r
-    if(fMChandler)fMChandler->SelectParticle(esdTrack->GetLabel());\r
-    aodTrack = new(Tracks()[fNumberOfTracks++]) AliAODTrack((esdTrack->GetID()+1)*-1,\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
-    aodTrack->SetIsHybridGlobalConstrainedGlobal(isHybridGC);    \r
-    aodTrack->SetIsGlobalConstrained(kTRUE);    \r
-    aodTrack->SetTPCFitMap(esdTrack->GetTPCFitMap());\r
-    aodTrack->SetTPCClusterMap(esdTrack->GetTPCClusterMap());\r
-    aodTrack->SetTPCSharedMap (esdTrack->GetTPCSharedMap());\r
-    aodTrack->SetChi2perNDF(Chi2perNDF(esdTrack));\r
-\r
-\r
-    // set the DCA values to the AOD track\r
-    aodTrack->SetPxPyPzAtDCA(pDCA[0],pDCA[1],pDCA[2]);\r
-    aodTrack->SetXYAtDCA(rDCA[0],rDCA[1]);\r
-    aodTrack->SetDCA(dDCA[0],dDCA[1]);\r
-\r
-    aodTrack->SetFlags(esdTrack->GetStatus());\r
-    aodTrack->SetTPCPointsF(esdTrack->GetTPCNclsF());\r
-\r
-    if(isHybridGC){\r
-      // only copy AOD information for hybrid, no duplicate information\r
-      aodTrack->ConvertAliPIDtoAODPID();\r
-      SetAODPID(esdTrack,aodTrack,detpid);\r
-    }\r
-  } // end of loop on tracks\r
-  \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 trkPos[3] = {0.,0.,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(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->SetTPCFitMap(esdTrack->GetTPCFitMap());\r
-    aodTrack->SetTPCClusterMap(esdTrack->GetTPCClusterMap());\r
-    aodTrack->SetTPCSharedMap (esdTrack->GetTPCSharedMap());\r
-    aodTrack->SetChi2perNDF(Chi2perNDF(esdTrack));\r
-    aodTrack->SetTPCPointsF(esdTrack->GetTPCNclsF());\r
-    if(esdTrack->IsEMCAL()) aodTrack->SetEMCALcluster(esdTrack->GetEMCALcluster());\r
-    if(esdTrack->IsPHOS())  aodTrack->SetPHOScluster(esdTrack->GetPHOScluster());\r
-\r
-    //Perform progagation of tracks if needed\r
-    if(fDoPropagateTrackToEMCal)\r
-      {\r
-       Double_t EMCalEta, EMCalPhi;\r
-       Double_t trkphi = esdTrack->Phi()*TMath::RadToDeg();\r
-       if(TMath::Abs(esdTrack->Eta())<0.9 && trkphi > 10 && trkphi < 250 )\r
-         {\r
-           AliExternalTrackParam *trkParam = const_cast<AliExternalTrackParam*>(esdTrack->GetInnerParam());\r
-           if(trkParam)\r
-             {\r
-               AliExternalTrackParam trkParamTmp(*trkParam);\r
-               if(AliTrackerBase::PropagateTrackToBxByBz(&trkParamTmp, 430, esdTrack->GetMass(), 20, kTRUE, 0.8, -1))\r
-                 {\r
-                   trkParamTmp.GetXYZ(trkPos);\r
-                   TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);\r
-                   EMCalEta = trkPosVec.Eta();\r
-                   EMCalPhi = trkPosVec.Phi();\r
-                   if(EMCalPhi<0)  EMCalPhi += 2*TMath::Pi();\r
-                   esdTrack->SetTrackPhiEtaOnEMCal(EMCalPhi,EMCalEta);\r
-                 }\r
-             }\r
-         }\r
-      }\r
-    aodTrack->SetTrackPhiEtaOnEMCal(esdTrack->GetTrackPhiOnEMCal(),esdTrack->GetTrackEtaOnEMCal());\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);\r
-  } // end of loop on tracks\r
-}\r
-\r
-//______________________________________________________________________________\r
-void AliAnalysisTaskESDfilter::ConvertPmdClusters(const AliESDEvent& esd)\r
-{\r
-// Convert PMD Clusters \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
-\r
-//______________________________________________________________________________\r
-void AliAnalysisTaskESDfilter::ConvertCaloClusters(const AliESDEvent& esd)\r
-{\r
-// Convert Calorimeter Clusters\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(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
-    caloCluster->SetTrackDistance(cluster->GetTrackDx(), cluster->GetTrackDz());\r
-    \r
-    Int_t nMatchCount = 0;\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
-         nMatchCount++;\r
-        }\r
-      }\r
-    }\r
-    if(nMatchCount==0)\r
-      caloCluster->SetTrackDistance(-999,-999);\r
-    \r
-  } \r
-  caloClusters.Expand(jClusters); // resize TObjArray to 'remove' slots for pseudo clusters     \r
-}\r
-\r
-//______________________________________________________________________________\r
-void AliAnalysisTaskESDfilter::ConvertCaloTrigger(TString calo, const AliESDEvent& esd)\r
-{\r
-       AliCodeTimerAuto("",0);\r
-               \r
-       if (calo == "PHOS") \r
-       {\r
-         AliAODCaloTrigger &aodTrigger = *(AODEvent()->GetCaloTrigger(calo));\r
-         AliESDCaloTrigger &esdTrigger = *(esd.GetCaloTrigger(calo));\r
-\r
-         aodTrigger.Allocate(esdTrigger.GetEntries());\r
-         esdTrigger.Reset();\r
-\r
-         Float_t a;\r
-         Int_t tmod,tabsId;\r
-\r
-         while (esdTrigger.Next()) {\r
-           esdTrigger.GetPosition(tmod,tabsId);\r
-           esdTrigger.GetAmplitude(a);\r
-           aodTrigger.Add(tmod,tabsId,a,0.,(Int_t*)NULL,0,0,0);\r
-         }\r
-\r
-         return;\r
-       }\r
-                       \r
-       AliAODHandler *aodHandler = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()); \r
-                       \r
-       if (aodHandler)\r
-       {\r
-               TTree *aodTree = aodHandler->GetTree();\r
-                                       \r
-               if (aodTree)\r
-               {\r
-                       Int_t *type = esd.GetCaloTriggerType();\r
-                                                       \r
-                       for (Int_t i = 0; i < 15; i++) \r
-                       {\r
-                               aodTree->GetUserInfo()->Add(new TParameter<int>(Form("EMCALCaloTrigger%d",i), type[i]));\r
-                       }\r
-               }\r
-       }\r
-                                               \r
-       AliAODCaloTrigger &aodTrigger = *(AODEvent()->GetCaloTrigger(calo));\r
-                                               \r
-       AliESDCaloTrigger &esdTrigger = *(esd.GetCaloTrigger(calo));\r
-                                               \r
-       aodTrigger.Allocate(esdTrigger.GetEntries());\r
-                                               \r
-       esdTrigger.Reset();\r
-       while (esdTrigger.Next())\r
-       {         \r
-               Int_t px, py, ts, nTimes, times[10], b; \r
-               Float_t a, t;\r
-                                                               \r
-               esdTrigger.GetPosition(px, py);\r
-                                               \r
-               esdTrigger.GetAmplitude(a);\r
-               esdTrigger.GetTime(t);\r
-                                                               \r
-               esdTrigger.GetL0Times(times);\r
-               esdTrigger.GetNL0Times(nTimes);\r
-                                                               \r
-               esdTrigger.GetL1TimeSum(ts);\r
-                                                               \r
-               esdTrigger.GetTriggerBits(b);\r
-                                                               \r
-               aodTrigger.Add(px, py, a, t, times, nTimes, ts, b);\r
-       }\r
-                                                       \r
-       for (int i = 0; i < 4; i++) aodTrigger.SetL1Threshold(i, esdTrigger.GetL1Threshold(i));\r
-                                                       \r
-       Int_t v0[2] = \r
-       {\r
-               esdTrigger.GetL1V0(0),\r
-               esdTrigger.GetL1V0(1)\r
-       };              \r
-                                                               \r
-       aodTrigger.SetL1V0(v0); \r
-       aodTrigger.SetL1FrameMask(esdTrigger.GetL1FrameMask());\r
-}\r
-\r
-//______________________________________________________________________________\r
-void AliAnalysisTaskESDfilter::ConvertEMCALCells(const AliESDEvent& esd)\r
-{\r
-// Convert EMCAL Cells\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
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/* $Id$ */
+#include <TChain.h>
+#include <TTree.h>
+#include <TList.h>
+#include <TArrayI.h>
+#include <TParameter.h>
+#include <TRandom.h>
+#include <TParticle.h>
+#include <TFile.h>
+
+#include "AliAnalysisTaskESDfilter.h"
+#include "AliAnalysisManager.h"
+#include "AliESDEvent.h"
+#include "AliESDRun.h"
+#include "AliStack.h"
+#include "AliAODEvent.h"
+#include "AliMCEvent.h"
+#include "AliMCEventHandler.h"
+#include "AliESDInputHandler.h"
+#include "AliAODHandler.h"
+#include "AliAODMCParticle.h"
+#include "AliAnalysisFilter.h"
+#include "AliESDMuonTrack.h"
+#include "AliESDVertex.h"
+#include "AliCentrality.h"
+#include "AliEventplane.h"
+#include "AliESDv0.h"
+#include "AliESDkink.h"
+#include "AliESDcascade.h"
+#include "AliESDPmdTrack.h"
+#include "AliESDCaloCluster.h"
+#include "AliESDCaloCells.h"
+#include "AliMultiplicity.h"
+#include "AliLog.h"
+#include "AliCodeTimer.h"
+#include "AliESDtrackCuts.h"
+#include "AliESDpid.h"
+#include "AliV0vertexer.h"
+#include "AliCascadeVertexer.h"
+#include "Riostream.h"
+#include "AliExternalTrackParam.h"
+#include "AliTrackerBase.h"
+#include "TVector3.h"
+#include "AliTPCdEdxInfo.h"
+
+using std::cout;
+using std::endl;
+ClassImp(AliAnalysisTaskESDfilter)
+
+////////////////////////////////////////////////////////////////////////
+
+AliAnalysisTaskESDfilter::AliAnalysisTaskESDfilter():
+  AliAnalysisTaskSE(),
+  fTrackFilter(0x0),
+  fKinkFilter(0x0),
+  fV0Filter(0x0),
+  fCascadeFilter(0x0),
+  fHighPthreshold(0),
+  fPtshape(0x0),
+  fEnableFillAOD(kTRUE),
+  fUsedTrack(0x0),
+  fUsedKink(0x0),
+  fUsedV0(0x0),
+  fAODTrackRefs(0x0),
+  fAODV0VtxRefs(0x0),
+  fAODV0Refs(0x0),
+  fMChandler(0x0),
+  fNumberOfTracks(0),
+  fNumberOfPositiveTracks(0),
+  fNumberOfV0s(0),
+  fNumberOfVertices(0),
+  fNumberOfCascades(0),
+  fNumberOfKinks(0),
+  fOldESDformat(kFALSE),
+  fPrimaryVertex(0x0),
+  fTPCConstrainedFilterMask(0),
+  fHybridFilterMaskTPCCG(0),
+  fWriteHybridTPCCOnly(kFALSE),
+  fGlobalConstrainedFilterMask(0),
+  fHybridFilterMaskGCG(0),
+  fWriteHybridGCOnly(kFALSE),
+  fIsVZEROEnabled(kTRUE),
+  fIsTZEROEnabled(kTRUE),
+  fIsZDCEnabled(kTRUE),
+  fIsV0CascadeRecoEnabled(kFALSE),
+  fAreCascadesEnabled(kTRUE),
+  fAreV0sEnabled(kTRUE),
+  fAreKinksEnabled(kTRUE),
+  fAreTracksEnabled(kTRUE),
+  fArePmdClustersEnabled(kTRUE),
+  fAreCaloClustersEnabled(kTRUE),
+  fAreEMCALCellsEnabled(kTRUE),
+  fArePHOSCellsEnabled(kTRUE),
+  fAreEMCALTriggerEnabled(kTRUE),
+  fArePHOSTriggerEnabled(kTRUE),
+  fAreTrackletsEnabled(kTRUE),
+  fESDpid(0x0),
+  fIsPidOwner(kFALSE),
+  fTimeZeroType(AliESDpid::kTOF_T0),
+  fTPCaloneTrackCuts(0),
+  fDoPropagateTrackToEMCal(kTRUE)
+{
+  // Default constructor
+    fV0Cuts[0] =  33.   ;   // max allowed chi2
+    fV0Cuts[1] =   0.1  ;   // min allowed impact parameter for the 1st daughter
+    fV0Cuts[2] =   0.1  ;   // min allowed impact parameter for the 2nd daughter
+    fV0Cuts[3] =   1.   ;   // max allowed DCA between the daughter tracks
+    fV0Cuts[4] =    .998;   // min allowed cosine of V0's pointing angle
+    fV0Cuts[5] =   0.9  ;   // min radius of the fiducial volume
+    fV0Cuts[6] = 100.   ;   // max radius of the fiducial volume
+
+    fCascadeCuts[0] =  33.   ; // max allowed chi2 (same as PDC07)
+    fCascadeCuts[1] =   0.05 ; // min allowed V0 impact parameter
+    fCascadeCuts[2] =   0.008; // "window" around the Lambda mass
+    fCascadeCuts[3] =   0.03 ; // min allowed bachelor's impact parameter
+    fCascadeCuts[4] =   0.3  ; // max allowed DCA between the V0 and the bachelor
+    fCascadeCuts[5] =   0.999; // min allowed cosine of the cascade pointing angle
+    fCascadeCuts[6] =   0.9  ; // min radius of the fiducial volume
+    fCascadeCuts[7] = 100.   ; // max radius of the fiducial volume
+}
+
+//______________________________________________________________________________
+AliAnalysisTaskESDfilter::AliAnalysisTaskESDfilter(const char* name):
+    AliAnalysisTaskSE(name),
+    fTrackFilter(0x0),
+    fKinkFilter(0x0),
+    fV0Filter(0x0),
+    fCascadeFilter(0x0),
+    fHighPthreshold(0),
+    fPtshape(0x0),
+    fEnableFillAOD(kTRUE),
+    fUsedTrack(0x0),
+    fUsedKink(0x0),
+    fUsedV0(0x0),
+    fAODTrackRefs(0x0),
+    fAODV0VtxRefs(0x0),
+    fAODV0Refs(0x0),
+    fMChandler(0x0),
+    fNumberOfTracks(0),
+    fNumberOfPositiveTracks(0),
+    fNumberOfV0s(0),
+    fNumberOfVertices(0),
+    fNumberOfCascades(0),
+    fNumberOfKinks(0),
+    fOldESDformat(kFALSE),
+    fPrimaryVertex(0x0),
+  fTPCConstrainedFilterMask(0),
+  fHybridFilterMaskTPCCG(0),
+  fWriteHybridTPCCOnly(kFALSE),
+  fGlobalConstrainedFilterMask(0),
+  fHybridFilterMaskGCG(0),
+  fWriteHybridGCOnly(kFALSE),
+    fIsVZEROEnabled(kTRUE),
+    fIsTZEROEnabled(kTRUE),
+    fIsZDCEnabled(kTRUE),
+    fIsV0CascadeRecoEnabled(kFALSE),
+    fAreCascadesEnabled(kTRUE),
+    fAreV0sEnabled(kTRUE),
+    fAreKinksEnabled(kTRUE),
+    fAreTracksEnabled(kTRUE),
+    fArePmdClustersEnabled(kTRUE),
+    fAreCaloClustersEnabled(kTRUE),
+    fAreEMCALCellsEnabled(kTRUE),
+    fArePHOSCellsEnabled(kTRUE),
+               fAreEMCALTriggerEnabled(kTRUE),
+               fArePHOSTriggerEnabled(kTRUE),
+               fAreTrackletsEnabled(kTRUE),
+    fESDpid(0x0),
+    fIsPidOwner(kFALSE),
+    fTimeZeroType(AliESDpid::kTOF_T0),
+    fTPCaloneTrackCuts(0),
+  fDoPropagateTrackToEMCal(kTRUE)
+{
+  // Constructor
+
+    fV0Cuts[0] =  33.   ;   // max allowed chi2
+    fV0Cuts[1] =   0.1  ;   // min allowed impact parameter for the 1st daughter
+    fV0Cuts[2] =   0.1  ;   // min allowed impact parameter for the 2nd daughter
+    fV0Cuts[3] =   1.   ;   // max allowed DCA between the daughter tracks
+    fV0Cuts[4] =    .998;   // min allowed cosine of V0's pointing angle
+    fV0Cuts[5] =   0.9  ;   // min radius of the fiducial volume
+    fV0Cuts[6] = 100.   ;   // max radius of the fiducial volume
+
+    fCascadeCuts[0] =  33.   ; // max allowed chi2 (same as PDC07)
+    fCascadeCuts[1] =   0.05 ; // min allowed V0 impact parameter
+    fCascadeCuts[2] =   0.008; // "window" around the Lambda mass
+    fCascadeCuts[3] =   0.03 ; // min allowed bachelor's impact parameter
+    fCascadeCuts[4] =   0.3  ; // max allowed DCA between the V0 and the bachelor
+    fCascadeCuts[5] =   0.999; // min allowed cosine of the cascade pointing angle
+    fCascadeCuts[6] =   0.9  ; // min radius of the fiducial volume
+    fCascadeCuts[7] = 100.   ; // max radius of the fiducial volume
+
+
+
+}
+AliAnalysisTaskESDfilter::~AliAnalysisTaskESDfilter(){
+    if(fIsPidOwner) delete fESDpid;
+}
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::UserCreateOutputObjects()
+{
+  //
+  // Create Output Objects conenct filter to outputtree
+  // 
+  if(OutputTree())
+  {
+    OutputTree()->GetUserInfo()->Add(fTrackFilter);
+  }
+  else
+  {
+    AliError("No OutputTree() for adding the track filter");
+  }
+  fTPCaloneTrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
+}
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::Init()
+{
+  // Initialization
+  if (fDebug > 1) AliInfo("Init() \n");
+  // Call configuration file
+}
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::PrintTask(Option_t *option, Int_t indent) const
+{
+// Print selection task information
+  AliInfo("");
+  
+  AliAnalysisTaskSE::PrintTask(option,indent);
+  
+  TString spaces(' ',indent+3);
+  
+       cout << spaces.Data() << Form("Cascades       are %s",fAreCascadesEnabled ? "ENABLED":"DISABLED") << endl;
+       cout << spaces.Data() << Form("V0s            are %s",fAreV0sEnabled ? "ENABLED":"DISABLED") << endl;
+       cout << spaces.Data() << Form("Kinks          are %s",fAreKinksEnabled ? "ENABLED":"DISABLED") << endl;
+       cout << spaces.Data() << Form("Tracks         are %s",fAreTracksEnabled ? "ENABLED":"DISABLED") << endl;
+       cout << spaces.Data() << Form("PmdClusters    are %s",fArePmdClustersEnabled ? "ENABLED":"DISABLED") << endl;
+       cout << spaces.Data() << Form("CaloClusters   are %s",fAreCaloClustersEnabled ? "ENABLED":"DISABLED") << endl;
+  cout << spaces.Data() << Form("EMCAL cells    are %s",fAreEMCALCellsEnabled ? "ENABLED":"DISABLED") << endl;
+       cout << spaces.Data() << Form("EMCAL triggers are %s",fAreEMCALTriggerEnabled ? "ENABLED":"DISABLED") << endl;
+       cout << spaces.Data() << Form("PHOS triggers  are %s",fArePHOSTriggerEnabled ? "ENABLED":"DISABLED") << endl;
+       cout << spaces.Data() << Form("Tracklets      are %s",fAreTrackletsEnabled ? "ENABLED":"DISABLED") << endl;  
+       cout << spaces.Data() << Form("PropagateTrackToEMCal  is %s", fDoPropagateTrackToEMCal ? "ENABLED":"DISABLED") << endl; 
+}
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::UserExec(Option_t */*option*/)
+{
+// Execute analysis for current event
+//
+                                           
+  Long64_t ientry = Entry();
+  
+  if (fDebug > 0) {
+      printf("Filter: Analysing event # %5d\n", (Int_t) ientry);
+      if (fHighPthreshold == 0) AliInfo("detector PID signals are stored in each track");
+      if (!fPtshape) AliInfo("detector PID signals are not stored below the pt threshold");
+  }
+  // Filters must explicitely enable AOD filling in their UserExec (AG)
+  if (!AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()) AliFatal("Cannot run ESD filter without an output event handler");
+  if(fEnableFillAOD) {
+     AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kTRUE);
+     AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillExtension(kTRUE);
+  }   
+  ConvertESDtoAOD();
+}
+
+//______________________________________________________________________________
+TClonesArray& AliAnalysisTaskESDfilter::Cascades()
+{
+  return *(AODEvent()->GetCascades());
+}
+
+//______________________________________________________________________________
+TClonesArray& AliAnalysisTaskESDfilter::Tracks()
+{
+  return *(AODEvent()->GetTracks());
+}
+
+//______________________________________________________________________________
+TClonesArray& AliAnalysisTaskESDfilter::V0s()
+{
+  return *(AODEvent()->GetV0s());
+}
+
+//______________________________________________________________________________
+TClonesArray& AliAnalysisTaskESDfilter::Vertices()
+{
+  return *(AODEvent()->GetVertices());
+}
+
+//______________________________________________________________________________
+AliAODHeader* AliAnalysisTaskESDfilter::ConvertHeader(const AliESDEvent& esd)
+{
+// Convert header information
+
+  AliCodeTimerAuto("",0);
+  
+  AliAODHeader* header = AODEvent()->GetHeader();
+  
+  header->SetRunNumber(esd.GetRunNumber());
+  header->SetOfflineTrigger(fInputHandler->IsEventSelected()); // propagate the decision of the physics selection
+
+  TTree* tree = fInputHandler->GetTree();
+  if (tree) {
+    TFile* file = tree->GetCurrentFile();
+    if (file) header->SetESDFileName(file->GetName());
+  }
+  
+  if (fOldESDformat) {
+    header->SetBunchCrossNumber(0);
+    header->SetOrbitNumber(0);
+    header->SetPeriodNumber(0);
+    header->SetEventType(0);
+    header->SetMuonMagFieldScale(-999.);
+    header->SetCentrality(0);       
+    header->SetEventplane(0);
+  } else {
+    header->SetBunchCrossNumber(esd.GetBunchCrossNumber());
+    header->SetOrbitNumber(esd.GetOrbitNumber());
+    header->SetPeriodNumber(esd.GetPeriodNumber());
+    header->SetEventType(esd.GetEventType());
+    
+    header->SetEventNumberESDFile(esd.GetHeader()->GetEventNumberInFile());
+    if(const_cast<AliESDEvent&>(esd).GetCentrality()){
+      header->SetCentrality(const_cast<AliESDEvent&>(esd).GetCentrality());
+    }
+    else{
+      header->SetCentrality(0);
+    }
+    if(const_cast<AliESDEvent&>(esd).GetEventplane()){
+      header->SetEventplane(const_cast<AliESDEvent&>(esd).GetEventplane());
+    }
+    else{
+      header->SetEventplane(0);
+    }
+  }
+  
+  // Trigger
+  header->SetFiredTriggerClasses(esd.GetFiredTriggerClasses());
+  header->SetTriggerMask(esd.GetTriggerMask()); 
+  header->SetTriggerCluster(esd.GetTriggerCluster());
+  header->SetL0TriggerInputs(esd.GetHeader()->GetL0TriggerInputs());    
+  header->SetL1TriggerInputs(esd.GetHeader()->GetL1TriggerInputs());    
+  header->SetL2TriggerInputs(esd.GetHeader()->GetL2TriggerInputs());    
+  
+  header->SetMagneticField(esd.GetMagneticField());
+  header->SetMuonMagFieldScale(esd.GetCurrentDip()/6000.);
+  header->SetZDCN1Energy(esd.GetZDCN1Energy());
+  header->SetZDCP1Energy(esd.GetZDCP1Energy());
+  header->SetZDCN2Energy(esd.GetZDCN2Energy());
+  header->SetZDCP2Energy(esd.GetZDCP2Energy());
+  header->SetZDCEMEnergy(esd.GetZDCEMEnergy(0),esd.GetZDCEMEnergy(1));
+  
+  // ITS Cluster Multiplicty
+  const AliMultiplicity *mult = esd.GetMultiplicity();
+  for (Int_t ilay = 0; ilay < 6; ilay++) header->SetITSClusters(ilay, mult->GetNumberOfITSClusters(ilay));
+  
+  // TPC only Reference Multiplicty
+  Int_t refMult  = fTPCaloneTrackCuts ? (Short_t)fTPCaloneTrackCuts->GetReferenceMultiplicity(&esd, kTRUE) : -1;
+  header->SetTPConlyRefMultiplicity(refMult);
+  
+  //
+  Float_t diamxy[2]={esd.GetDiamondX(),esd.GetDiamondY()};
+  Float_t diamcov[3]; 
+  esd.GetDiamondCovXY(diamcov);
+  header->SetDiamond(diamxy,diamcov);
+  header->SetDiamondZ(esd.GetDiamondZ(),esd.GetSigma2DiamondZ());
+  
+  // VZERO channel equalization factors for event-plane reconstruction          
+  header->SetVZEROEqFactors(esd.GetVZEROEqFactors());
+
+  return header;
+}
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::ConvertCascades(const AliESDEvent& esd) 
+{
+
+  // Convert the cascades part of the ESD.
+  // Return the number of cascades
+  AliCodeTimerAuto("",0);
+  
+  // Create vertices starting from the most complex objects
+  Double_t chi2 = 0.;
+  
+  const AliESDVertex* vtx = esd.GetPrimaryVertex();
+  Double_t pos[3] = { 0. };
+  Double_t covVtx[6] = { 0. };
+  Double_t momBach[3]={0.};
+  Double_t covTr[21]={0.};
+  Double_t pid[10]={0.};
+  AliAODPid* detpid(0x0);
+  AliAODVertex* vV0FromCascade(0x0);
+  AliAODv0* aodV0(0x0);
+  AliAODcascade* aodCascade(0x0);
+  AliAODTrack* aodTrack(0x0);
+  Double_t momPos[3]={0.};
+  Double_t momNeg[3] = { 0. };
+  Double_t momPosAtV0vtx[3]={0.};
+  Double_t momNegAtV0vtx[3]={0.};
+
+  TClonesArray& verticesArray = Vertices();
+  TClonesArray& tracksArray = Tracks();
+  TClonesArray& cascadesArray = Cascades();
+  
+  // Cascades (Modified by A.Maire - February 2009)
+  for (Int_t nCascade = 0; nCascade < esd.GetNumberOfCascades(); ++nCascade) {
+    
+    // 0- Preparation
+    //
+    AliESDcascade *esdCascade = esd.GetCascade(nCascade);
+               Int_t  idxPosFromV0Dghter  = esdCascade->GetPindex();
+               Int_t  idxNegFromV0Dghter  = esdCascade->GetNindex();
+               Int_t  idxBachFromCascade  = esdCascade->GetBindex();
+    
+    AliESDtrack  *esdCascadePos  = esd.GetTrack( idxPosFromV0Dghter);
+    AliESDtrack  *esdCascadeNeg  = esd.GetTrack( idxNegFromV0Dghter);
+    AliESDtrack  *esdCascadeBach = esd.GetTrack( idxBachFromCascade);
+    
+    // Identification of the V0 within the esdCascade (via both daughter track indices)
+    AliESDv0 * currentV0   = 0x0;
+    Int_t      idxV0FromCascade = -1;
+    
+    for (Int_t iV0=0; iV0<esd.GetNumberOfV0s(); ++iV0) {
+      
+      currentV0 = esd.GetV0(iV0);
+      Int_t posCurrentV0 = currentV0->GetPindex();
+      Int_t negCurrentV0 = currentV0->GetNindex();
+      
+      if (posCurrentV0==idxPosFromV0Dghter && negCurrentV0==idxNegFromV0Dghter) {
+        idxV0FromCascade = iV0;
+        break;
+      }
+    }
+    
+    if(idxV0FromCascade < 0){
+      printf("Cascade - no matching for the V0 (index V0 = -1) ! Skip ... \n");
+      continue;
+    }// a priori, useless check, but safer ... in case of pb with tracks "out of bounds"
+    
+    AliESDv0 *esdV0FromCascade   = esd.GetV0(idxV0FromCascade);
+        
+    // 1 - Cascade selection 
+    
+    // AliESDVertex *esdPrimVtx = new AliESDVertex(*(esd.GetPrimaryVertex()));
+    //         TList cascadeObjects;
+    //         cascadeObjects.AddAt(esdV0FromCascade, 0);
+    //         cascadeObjects.AddAt(esdCascadePos,    1);
+    //         cascadeObjects.AddAt(esdCascadeNeg,    2);
+    //         cascadeObjects.AddAt(esdCascade,       3);
+    //         cascadeObjects.AddAt(esdCascadeBach,   4);
+    //         cascadeObjects.AddAt(esdPrimVtx,       5);
+    // 
+    //         UInt_t selectCascade = 0;
+    //         if (fCascadeFilter) {
+    //           // selectCascade = fCascadeFilter->IsSelected(&cascadeObjects); 
+    //                 // FIXME AliESDCascadeCuts to be implemented ...
+    // 
+    //                 // Here we may encounter a moot point at the V0 level 
+    //                 // between the cascade selections and the V0 ones :
+    //                 // the V0 selected along with the cascade (secondary V0) may 
+    //                 // usually be removed from the dedicated V0 selections (prim V0) ...
+    //                 // -> To be discussed !
+    // 
+    //           // this is a little awkward but otherwise the 
+    //           // list wants to access the pointer (delete it) 
+    //           // again when going out of scope
+    //           delete cascadeObjects.RemoveAt(5); // esdPrimVtx created via copy construct
+    //           esdPrimVtx = 0;
+    //           if (!selectCascade) 
+    //             continue;
+    //         }
+    //         else{
+    //           delete cascadeObjects.RemoveAt(5); // esdPrimVtx created via copy construct
+    //           esdPrimVtx = 0;
+    //         }
+    
+    // 2 - Add the cascade vertex
+    
+    esdCascade->GetXYZcascade(pos[0], pos[1], pos[2]);
+    esdCascade->GetPosCovXi(covVtx);
+    chi2 = esdCascade->GetChi2Xi(); 
+    
+    AliAODVertex *vCascade = new(verticesArray[fNumberOfVertices++]) AliAODVertex( pos,
+                                                                     covVtx,
+                                                                     chi2, // FIXME = Chi2/NDF will be needed
+                                                                     fPrimaryVertex,
+                                                                     nCascade, // id
+                                                                     AliAODVertex::kCascade);
+    fPrimaryVertex->AddDaughter(vCascade);
+    
+//    if (fDebug > 2) {
+//      printf("---- Cascade / Cascade Vertex (AOD) : \n");
+//      vCascade->Print();
+//    }
+    
+//    if(esd.GetTOFHeader() && fIsPidOwner) fESDpid->SetTOFResponse(const_cast<AliESDEvent*>(&esd), (AliESDpid::EStartTimeType_t)fTimeZeroType); //in case of AOD production starting form LHC10e without Tender. 
+
+
+    // 3 - Add the bachelor track from the cascade
+    
+    if (!fUsedTrack[idxBachFromCascade]) {
+      
+      esdCascadeBach->GetPxPyPz(momBach);
+      esdCascadeBach->GetXYZ(pos);
+      esdCascadeBach->GetCovarianceXYZPxPyPz(covTr);
+      esdCascadeBach->GetESDpid(pid);
+      
+           fUsedTrack[idxBachFromCascade] = kTRUE;
+           UInt_t selectInfo = 0;
+           if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdCascadeBach);
+           if (fMChandler) fMChandler->SelectParticle(esdCascadeBach->GetLabel());
+           aodTrack = new(tracksArray[fNumberOfTracks++]) AliAODTrack(esdCascadeBach->GetID(),
+                                                                           esdCascadeBach->GetLabel(), 
+                                                                           momBach, 
+                                                                           kTRUE,
+                                                                           pos,
+                                                                           kFALSE, // Why kFALSE for "isDCA" ? FIXME
+                                                                           covTr, 
+                                                                           (Short_t)esdCascadeBach->GetSign(),
+                                                                           esdCascadeBach->GetITSClusterMap(), 
+                                                                           pid,
+                                                                           vCascade,
+                                                                           kTRUE,  // usedForVtxFit = kFALSE ? FIXME
+                                                                           vtx->UsesTrack(esdCascadeBach->GetID()),
+                                                                           AliAODTrack::kSecondary,
+                                                                           selectInfo);
+           aodTrack->SetTPCFitMap(esdCascadeBach->GetTPCFitMap());
+           aodTrack->SetTPCClusterMap(esdCascadeBach->GetTPCClusterMap());
+           aodTrack->SetTPCSharedMap (esdCascadeBach->GetTPCSharedMap());
+           aodTrack->SetChi2perNDF(Chi2perNDF(esdCascadeBach));
+           aodTrack->SetTPCPointsF(esdCascadeBach->GetTPCNclsF());
+           fAODTrackRefs->AddAt(aodTrack,idxBachFromCascade);
+           
+           if (esdCascadeBach->GetSign() > 0) ++fNumberOfPositiveTracks;
+           aodTrack->ConvertAliPIDtoAODPID();
+           aodTrack->SetFlags(esdCascadeBach->GetStatus());
+      SetAODPID(esdCascadeBach,aodTrack,detpid);
+    }
+    else {
+           aodTrack = static_cast<AliAODTrack*>( fAODTrackRefs->At(idxBachFromCascade) );
+    }
+    
+    vCascade->AddDaughter(aodTrack);
+    
+//    if (fDebug > 4) {
+//      printf("---- Cascade / bach dghter : \n");
+//      aodTrack->Print();
+//    }
+    
+    
+    // 4 - Add the V0 from the cascade. 
+    // = V0vtx + both pos and neg daughter tracks + the aodV0 itself
+    //
+    
+    if ( !fUsedV0[idxV0FromCascade] ) {
+      // 4.A - if VO structure hasn't been created yet
+      
+      // 4.A.1 - Create the V0 vertex of the cascade
+      
+      esdV0FromCascade->GetXYZ(pos[0], pos[1], pos[2]);
+      esdV0FromCascade->GetPosCov(covVtx);
+      chi2 = esdV0FromCascade->GetChi2V0();  // = chi2/NDF since NDF = 2*2-3 ?
+                       
+      vV0FromCascade = new(verticesArray[fNumberOfVertices++]) AliAODVertex(pos,
+                                                                         covVtx,
+                                                                         chi2,
+                                                                         vCascade,
+                                                                         idxV0FromCascade, //id of ESDv0
+                                                                         AliAODVertex::kV0);
+      // Note:
+      //    one V0 can be used by several cascades.
+      // So, one AOD V0 vtx can have several parent vtx.
+      // This is not directly allowed by AliAODvertex.
+      // Setting the parent vtx (here = param "vCascade") doesn't lead to a crash
+      // but to a problem of consistency within AODEvent.
+      // -> See below paragraph 4.B, for the proposed treatment of such a case.
+      
+      // Add the vV0FromCascade to the aodVOVtxRefs
+      fAODV0VtxRefs->AddAt(vV0FromCascade,idxV0FromCascade);
+      
+      
+      // 4.A.2 - Add the positive tracks from the V0
+      
+      esdCascadePos->GetPxPyPz(momPos);
+      esdCascadePos->GetXYZ(pos);
+      esdCascadePos->GetCovarianceXYZPxPyPz(covTr);
+      esdCascadePos->GetESDpid(pid);
+      
+      
+      if (!fUsedTrack[idxPosFromV0Dghter]) {
+        fUsedTrack[idxPosFromV0Dghter] = kTRUE;
+        
+        UInt_t selectInfo = 0;
+        if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdCascadePos);
+        if(fMChandler) fMChandler->SelectParticle(esdCascadePos->GetLabel());
+        aodTrack = new(tracksArray[fNumberOfTracks++]) 
+        AliAODTrack(  esdCascadePos->GetID(),
+                    esdCascadePos->GetLabel(), 
+                    momPos, 
+                    kTRUE,
+                    pos,
+                    kFALSE, // Why kFALSE for "isDCA" ? FIXME
+                    covTr, 
+                    (Short_t)esdCascadePos->GetSign(),
+                    esdCascadePos->GetITSClusterMap(), 
+                    pid,
+                    vV0FromCascade,
+                    kTRUE,  // usedForVtxFit = kFALSE ? FIXME
+                    vtx->UsesTrack(esdCascadePos->GetID()),
+                    AliAODTrack::kSecondary,
+                    selectInfo);
+        aodTrack->SetTPCFitMap(esdCascadePos->GetTPCFitMap());
+        aodTrack->SetTPCClusterMap(esdCascadePos->GetTPCClusterMap());
+        aodTrack->SetTPCSharedMap (esdCascadePos->GetTPCSharedMap());
+        aodTrack->SetChi2perNDF(Chi2perNDF(esdCascadePos));
+       aodTrack->SetTPCPointsF(esdCascadePos->GetTPCNclsF());
+        fAODTrackRefs->AddAt(aodTrack,idxPosFromV0Dghter);
+        
+        if (esdCascadePos->GetSign() > 0) ++fNumberOfPositiveTracks;
+        aodTrack->ConvertAliPIDtoAODPID();
+        aodTrack->SetFlags(esdCascadePos->GetStatus());
+        SetAODPID(esdCascadePos,aodTrack,detpid);
+      }
+      else {
+        aodTrack = static_cast<AliAODTrack*>(fAODTrackRefs->At(idxPosFromV0Dghter));
+      }
+      vV0FromCascade->AddDaughter(aodTrack);
+      
+      
+      // 4.A.3 - Add the negative tracks from the V0
+      
+      esdCascadeNeg->GetPxPyPz(momNeg);
+      esdCascadeNeg->GetXYZ(pos);
+      esdCascadeNeg->GetCovarianceXYZPxPyPz(covTr);
+      esdCascadeNeg->GetESDpid(pid);
+      
+      
+      if (!fUsedTrack[idxNegFromV0Dghter]) {
+        fUsedTrack[idxNegFromV0Dghter] = kTRUE;
+        
+        UInt_t selectInfo = 0;
+        if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdCascadeNeg);
+        if(fMChandler)fMChandler->SelectParticle(esdCascadeNeg->GetLabel());
+        aodTrack = new(tracksArray[fNumberOfTracks++]) AliAODTrack(  esdCascadeNeg->GetID(),
+                                                      esdCascadeNeg->GetLabel(),
+                                                      momNeg,
+                                                      kTRUE,
+                                                      pos,
+                                                      kFALSE, // Why kFALSE for "isDCA" ? FIXME
+                                                      covTr, 
+                                                      (Short_t)esdCascadeNeg->GetSign(),
+                                                      esdCascadeNeg->GetITSClusterMap(), 
+                                                      pid,
+                                                      vV0FromCascade,
+                                                      kTRUE,  // usedForVtxFit = kFALSE ? FIXME
+                                                      vtx->UsesTrack(esdCascadeNeg->GetID()),
+                                                      AliAODTrack::kSecondary,
+                                                      selectInfo);
+        aodTrack->SetTPCFitMap(esdCascadeNeg->GetTPCFitMap());
+        aodTrack->SetTPCClusterMap(esdCascadeNeg->GetTPCClusterMap());
+        aodTrack->SetTPCSharedMap (esdCascadeNeg->GetTPCSharedMap());
+        aodTrack->SetChi2perNDF(Chi2perNDF(esdCascadeNeg));
+       aodTrack->SetTPCPointsF(esdCascadeNeg->GetTPCNclsF());
+        fAODTrackRefs->AddAt(aodTrack,idxNegFromV0Dghter);
+        
+        if (esdCascadeNeg->GetSign() > 0) ++fNumberOfPositiveTracks;
+        aodTrack->ConvertAliPIDtoAODPID();
+        aodTrack->SetFlags(esdCascadeNeg->GetStatus());
+        SetAODPID(esdCascadeNeg,aodTrack,detpid);
+      }
+      else {
+        aodTrack = static_cast<AliAODTrack*>(fAODTrackRefs->At(idxNegFromV0Dghter));
+      }
+      
+      vV0FromCascade->AddDaughter(aodTrack);
+      
+                       
+      // 4.A.4 - Add the V0 from cascade to the V0 array
+      
+      Double_t  dcaV0Daughters      = esdV0FromCascade->GetDcaV0Daughters();
+      Double_t  dcaV0ToPrimVertex   = esdV0FromCascade->GetD( esd.GetPrimaryVertex()->GetX(),
+                                                             esd.GetPrimaryVertex()->GetY(),
+                                                             esd.GetPrimaryVertex()->GetZ() );
+      esdV0FromCascade->GetPPxPyPz( momPosAtV0vtx[0],momPosAtV0vtx[1],momPosAtV0vtx[2] ); 
+      esdV0FromCascade->GetNPxPyPz( momNegAtV0vtx[0],momNegAtV0vtx[1],momNegAtV0vtx[2] ); 
+      
+      Double_t dcaDaughterToPrimVertex[2] = { 999., 999.}; // ..[0] = DCA in (x,y) for Pos and ..[1] = Neg
+      dcaDaughterToPrimVertex[0] = TMath::Abs(esdCascadePos->GetD(     esd.GetPrimaryVertex()->GetX(),
+                                                                  esd.GetPrimaryVertex()->GetY(),
+                                                                  esd.GetMagneticField())        );
+      dcaDaughterToPrimVertex[1] = TMath::Abs(esdCascadeNeg->GetD(     esd.GetPrimaryVertex()->GetX(),
+                                                                  esd.GetPrimaryVertex()->GetY(),
+                                                                  esd.GetMagneticField())        );
+      
+      aodV0 = new(V0s()[fNumberOfV0s++]) AliAODv0( vV0FromCascade, 
+                                                  dcaV0Daughters,
+                                                  dcaV0ToPrimVertex, 
+                                                  momPosAtV0vtx, 
+                                                  momNegAtV0vtx, 
+                                                  dcaDaughterToPrimVertex); 
+      // set the aod v0 on-the-fly status
+      aodV0->SetOnFlyStatus(esdV0FromCascade->GetOnFlyStatus());
+      
+      // Add the aodV0 to the aodVORefs
+      fAODV0Refs->AddAt(aodV0,idxV0FromCascade);
+      
+      fUsedV0[idxV0FromCascade] = kTRUE;
+      
+    } else { 
+      // 4.B - if V0 structure already used
+      
+      // Note :
+      //    one V0 can be used by several cascades (frequent in PbPb evts) : 
+      // same V0 which used but attached to different bachelor tracks
+      // -> aodVORefs and fAODV0VtxRefs are needed.
+      // Goal : avoid a redundancy of the info in "Vertices" and "v0s" clones array.
+      
+      vV0FromCascade = static_cast<AliAODVertex*>( fAODV0VtxRefs->At(idxV0FromCascade) );
+      aodV0          = static_cast<AliAODv0*>    ( fAODV0Refs   ->At(idxV0FromCascade) );
+      
+      // - Treatment of the parent for such a "re-used" V0 :
+      // Insert the cascade that reuses the V0 vertex in the lineage chain
+      // Before : vV0 -> vCascade1 -> vPrimary
+      //  - Hyp : cascade2 uses the same V0 as cascade1
+      //  After :  vV0 -> vCascade2 -> vCascade1 -> vPrimary
+      
+      AliAODVertex *vCascadePreviousParent = static_cast<AliAODVertex*> (vV0FromCascade->GetParent());
+                       vV0FromCascade->SetParent(vCascade);
+                       vCascade      ->SetParent(vCascadePreviousParent);
+      
+//      if(fDebug > 2) 
+//        printf("---- Cascade / Lineage insertion\n"
+//               "Parent of V0 vtx                 = Cascade vtx %p\n"
+//               "Parent of the cascade vtx        = Cascade vtx %p\n"
+//               "Parent of the parent cascade vtx = Cascade vtx %p\n", 
+//               static_cast<void*> (vV0FromCascade->GetParent()),
+//               static_cast<void*> (vCascade->GetParent()),
+//               static_cast<void*> (vCascadePreviousParent->GetParent()) );
+      
+    }// end if V0 structure already used
+    
+//    if (fDebug > 2) {
+//      printf("---- Cascade / V0 vertex: \n");
+//      vV0FromCascade->Print();
+//    }
+//    
+//    if (fDebug > 4) {
+//      printf("---- Cascade / pos dghter : \n");
+//                     aodTrack->Print();
+//      printf("---- Cascade / neg dghter : \n");
+//                     aodTrack->Print();
+//      printf("---- Cascade / aodV0 : \n");
+//                     aodV0->Print();
+//    }
+    
+    // In any case (used V0 or not), add the V0 vertex to the cascade one.
+    vCascade->AddDaughter(vV0FromCascade);     
+    
+               
+    // 5 - Add the primary track of the cascade (if any)
+    
+    
+    // 6 - Add the cascade to the AOD array of cascades
+    
+    Double_t dcaBachToPrimVertexXY = TMath::Abs(esdCascadeBach->GetD(esd.GetPrimaryVertex()->GetX(),
+                                                                     esd.GetPrimaryVertex()->GetY(),
+                                                                     esd.GetMagneticField())        );
+    
+    Double_t momBachAtCascadeVtx[3]={0.};
+
+    esdCascade->GetBPxPyPz(momBachAtCascadeVtx[0], momBachAtCascadeVtx[1], momBachAtCascadeVtx[2]);
+    
+    aodCascade = new(cascadesArray[fNumberOfCascades++]) AliAODcascade(  vCascade,
+                                                          esdCascade->Charge(),
+                                                          esdCascade->GetDcaXiDaughters(),
+                                                          -999.,
+                                                          // DCAXiToPrimVtx -> needs to be calculated   ----|
+                                                          // doesn't exist at ESD level;
+                                                          // See AODcascade::DcaXiToPrimVertex(Double, Double, Double)
+                                                          dcaBachToPrimVertexXY,
+                                                          momBachAtCascadeVtx,
+                                                          *aodV0);
+    
+    if (fDebug > 10) {
+      printf("---- Cascade / AOD cascade : \n\n");
+      aodCascade->PrintXi(fPrimaryVertex->GetX(), fPrimaryVertex->GetY(), fPrimaryVertex->GetZ());
+    }
+    
+  } // end of the loop on cascades
+  
+  Cascades().Expand(fNumberOfCascades);
+}
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::ConvertV0s(const AliESDEvent& esd)
+{
+  // Access to the AOD container of V0s
+  
+  AliCodeTimerAuto("",0);
+
+  //
+  // V0s
+  //
+  
+  Double_t pos[3] = { 0. };      
+  Double_t chi2(0.0);
+  Double_t covVtx[6] = { 0. };
+  Double_t momPos[3]={0.};
+  Double_t covTr[21]={0.};
+  Double_t pid[10]={0.};
+  AliAODTrack* aodTrack(0x0);
+  AliAODPid* detpid(0x0);
+  Double_t momNeg[3]={0.};
+  Double_t momPosAtV0vtx[3]={0.};
+  Double_t momNegAtV0vtx[3]={0.};
+    
+  for (Int_t nV0 = 0; nV0 < esd.GetNumberOfV0s(); ++nV0) 
+  {
+    if (fUsedV0[nV0]) continue; // skip if already added to the AOD
+    
+    AliESDv0 *v0 = esd.GetV0(nV0);
+    Int_t posFromV0 = v0->GetPindex();
+    Int_t negFromV0 = v0->GetNindex();
+    
+    // V0 selection 
+    //
+    AliESDVertex *esdVtx   = new AliESDVertex(*(esd.GetPrimaryVertex()));
+    AliESDtrack  *esdV0Pos = esd.GetTrack(posFromV0);
+    AliESDtrack  *esdV0Neg = esd.GetTrack(negFromV0);
+    TList v0objects;
+    v0objects.AddAt(v0,                      0);
+    v0objects.AddAt(esdV0Pos,                1);
+    v0objects.AddAt(esdV0Neg,                2);
+    v0objects.AddAt(esdVtx,                  3);
+    UInt_t selectV0 = 0;
+    if (fV0Filter) {
+      selectV0 = fV0Filter->IsSelected(&v0objects);
+      // this is a little awkward but otherwise the 
+      // list wants to access the pointer (delete it) 
+      // again when going out of scope
+      delete v0objects.RemoveAt(3); // esdVtx created via copy construct
+      esdVtx = 0;
+      if (!selectV0) 
+        continue;
+    }
+    else{
+      delete v0objects.RemoveAt(3); // esdVtx created via copy construct
+      esdVtx = 0;
+    }
+    
+    v0->GetXYZ(pos[0], pos[1], pos[2]);
+    
+    if (!fOldESDformat) {
+           chi2 = v0->GetChi2V0(); // = chi2/NDF since NDF = 2*2-3
+           v0->GetPosCov(covVtx);
+    } else {
+           chi2 = -999.;
+           for (Int_t i = 0; i < 6; i++)  covVtx[i] = 0.;
+    }
+    
+    
+    AliAODVertex * vV0 = 
+         new(Vertices()[fNumberOfVertices++]) AliAODVertex(pos,
+                                                      covVtx,
+                                                      chi2,
+                                                      fPrimaryVertex,
+                                                      nV0,
+                                                      AliAODVertex::kV0);
+    fPrimaryVertex->AddDaughter(vV0);
+    
+    
+    // Add the positive tracks from the V0
+    
+
+    esdV0Pos->GetPxPyPz(momPos);
+    esdV0Pos->GetXYZ(pos);
+    esdV0Pos->GetCovarianceXYZPxPyPz(covTr);
+    esdV0Pos->GetESDpid(pid);
+    
+    const AliESDVertex *vtx = esd.GetPrimaryVertex();
+
+    if (!fUsedTrack[posFromV0]) {
+           fUsedTrack[posFromV0] = kTRUE;
+           UInt_t selectInfo = 0;
+           if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdV0Pos);
+           if(fMChandler)fMChandler->SelectParticle(esdV0Pos->GetLabel());
+           aodTrack = new(Tracks()[fNumberOfTracks++]) AliAODTrack(esdV0Pos->GetID(),
+                                                    esdV0Pos->GetLabel(), 
+                                                    momPos, 
+                                                    kTRUE,
+                                                    pos,
+                                                    kFALSE,
+                                                    covTr, 
+                                                    (Short_t)esdV0Pos->GetSign(),
+                                                    esdV0Pos->GetITSClusterMap(), 
+                                                    pid,
+                                                    vV0,
+                                                    kTRUE,  // check if this is right
+                                                    vtx->UsesTrack(esdV0Pos->GetID()),
+                                                    AliAODTrack::kSecondary,
+                                                    selectInfo);
+           aodTrack->SetTPCFitMap(esdV0Pos->GetTPCFitMap());
+           aodTrack->SetTPCClusterMap(esdV0Pos->GetTPCClusterMap());
+           aodTrack->SetTPCSharedMap (esdV0Pos->GetTPCSharedMap());
+           aodTrack->SetChi2perNDF(Chi2perNDF(esdV0Pos));
+           aodTrack->SetTPCPointsF(esdV0Pos->GetTPCNclsF());
+           fAODTrackRefs->AddAt(aodTrack,posFromV0);
+           //      if (fDebug > 0) printf("-------------------Bo: pos track from original pt %.3f \n",aodTrack->Pt());
+           if (esdV0Pos->GetSign() > 0) ++fNumberOfPositiveTracks;
+           aodTrack->ConvertAliPIDtoAODPID();
+           aodTrack->SetFlags(esdV0Pos->GetStatus());
+      SetAODPID(esdV0Pos,aodTrack,detpid);
+    }
+    else {
+           aodTrack = static_cast<AliAODTrack*>(fAODTrackRefs->At(posFromV0));
+           //      if (fDebug > 0) printf("-------------------Bo pos track from refArray pt %.3f \n",aodTrack->Pt());
+    }
+    vV0->AddDaughter(aodTrack);
+    
+    // Add the negative tracks from the V0
+    
+    esdV0Neg->GetPxPyPz(momNeg);
+    esdV0Neg->GetXYZ(pos);
+    esdV0Neg->GetCovarianceXYZPxPyPz(covTr);
+    esdV0Neg->GetESDpid(pid);
+    
+    if (!fUsedTrack[negFromV0]) {
+           fUsedTrack[negFromV0] = kTRUE;
+           UInt_t selectInfo = 0;
+           if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdV0Neg);
+           if(fMChandler)fMChandler->SelectParticle(esdV0Neg->GetLabel());
+           aodTrack = new(Tracks()[fNumberOfTracks++]) AliAODTrack(esdV0Neg->GetID(),
+                                                    esdV0Neg->GetLabel(),
+                                                    momNeg,
+                                                    kTRUE,
+                                                    pos,
+                                                    kFALSE,
+                                                    covTr, 
+                                                    (Short_t)esdV0Neg->GetSign(),
+                                                    esdV0Neg->GetITSClusterMap(), 
+                                                    pid,
+                                                    vV0,
+                                                    kTRUE,  // check if this is right
+                                                    vtx->UsesTrack(esdV0Neg->GetID()),
+                                                    AliAODTrack::kSecondary,
+                                                    selectInfo);
+           aodTrack->SetTPCFitMap(esdV0Neg->GetTPCFitMap());
+           aodTrack->SetTPCClusterMap(esdV0Neg->GetTPCClusterMap());
+           aodTrack->SetTPCSharedMap (esdV0Neg->GetTPCSharedMap());
+           aodTrack->SetChi2perNDF(Chi2perNDF(esdV0Neg));
+           aodTrack->SetTPCPointsF(esdV0Neg->GetTPCNclsF());
+           
+           fAODTrackRefs->AddAt(aodTrack,negFromV0);
+           //      if (fDebug > 0) printf("-------------------Bo: neg track from original pt %.3f \n",aodTrack->Pt());
+           if (esdV0Neg->GetSign() > 0) ++fNumberOfPositiveTracks;
+           aodTrack->ConvertAliPIDtoAODPID();
+           aodTrack->SetFlags(esdV0Neg->GetStatus());
+      SetAODPID(esdV0Neg,aodTrack,detpid);
+    }
+    else {
+           aodTrack = static_cast<AliAODTrack*>(fAODTrackRefs->At(negFromV0));
+           //      if (fDebug > 0) printf("-------------------Bo neg track from refArray pt %.3f \n",aodTrack->Pt());
+    }
+    vV0->AddDaughter(aodTrack);
+    
+    
+    // Add the V0 the V0 array as well
+    
+    Double_t  dcaV0Daughters      = v0->GetDcaV0Daughters();
+    Double_t  dcaV0ToPrimVertex   = v0->GetD(esd.GetPrimaryVertex()->GetX(),
+                                             esd.GetPrimaryVertex()->GetY(),
+                                             esd.GetPrimaryVertex()->GetZ());
+    
+    v0->GetPPxPyPz(momPosAtV0vtx[0],momPosAtV0vtx[1],momPosAtV0vtx[2]); 
+    v0->GetNPxPyPz(momNegAtV0vtx[0],momNegAtV0vtx[1],momNegAtV0vtx[2]); 
+    
+    Double_t dcaDaughterToPrimVertex[2] = { 999., 999.}; // ..[0] = DCA in (x,y) for Pos and ..[1] = Neg
+    dcaDaughterToPrimVertex[0] = TMath::Abs(esdV0Pos->GetD(  esd.GetPrimaryVertex()->GetX(),
+                                                           esd.GetPrimaryVertex()->GetY(),
+                                                           esd.GetMagneticField()) );
+    dcaDaughterToPrimVertex[1] = TMath::Abs(esdV0Neg->GetD(  esd.GetPrimaryVertex()->GetX(),
+                                                           esd.GetPrimaryVertex()->GetY(),
+                                                           esd.GetMagneticField()) );
+    
+    AliAODv0* aodV0 = new(V0s()[fNumberOfV0s++]) AliAODv0(vV0, 
+                                                dcaV0Daughters,
+                                                dcaV0ToPrimVertex,
+                                                momPosAtV0vtx,
+                                                momNegAtV0vtx,
+                                                dcaDaughterToPrimVertex);
+    
+    // set the aod v0 on-the-fly status
+    aodV0->SetOnFlyStatus(v0->GetOnFlyStatus());
+  }//End of loop on V0s 
+  
+  V0s().Expand(fNumberOfV0s);   
+}
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::ConvertTPCOnlyTracks(const AliESDEvent& esd)
+{
+  // Convert TPC only tracks
+  // Here we have wo hybrid appraoch to remove fakes
+  // ******* ITSTPC ********
+  // Uses a cut on the ITS properties to select global tracks
+  // which are than marked as HybdridITSTPC for the remainder 
+  // the TPC only tracks are flagged as HybridITSTPConly. 
+  // Note, in order not to get fakes back in the TPC cuts, one needs 
+  // two "ITS" cuts one tight (1) (to throw out fakes) and one lose (2) (to NOT flag the trakcs in the TPC only)
+  // using cut number (3)
+  // so fHybridFilterMask == (1)|(2) fTPCFilterMask = (3), Usercode needs to slect with mask = (1)|(3) and track->IsHybridITSTPC()
+  // ******* TPC ********
+  // Here, only TPC tracks are flagged that pass the tight ITS cuts and tracks that pass the TPC cuts and NOT the loose ITS cuts
+  // the ITS cuts neeed to be added to the filter as extra cuts, since here the selections info is reset in the global and put to the TPC only track
+
+  AliCodeTimerAuto("",0);
+  
+  // Loop over the tracks and extract and mask out all aod tracks that pass the selections for AODt racks
+  for(int it = 0;it < fNumberOfTracks;++it)
+  {
+    AliAODTrack *tr = (AliAODTrack*)(Tracks().At(it));
+    if(!tr)continue;
+    UInt_t map = tr->GetFilterMap();
+    if(map&fTPCConstrainedFilterMask){
+      // we only reset the track select ionfo, no deletion...
+      tr->SetFilterMap(map&~fTPCConstrainedFilterMask);
+    }
+    if(map&fHybridFilterMaskTPCCG){
+      // this is one part of the hybrid tracks
+      // the others not passing the selection will be TPC only selected below
+      tr->SetIsHybridTPCConstrainedGlobal(kTRUE);
+    }
+  }
+  // Loop over the ESD trcks and pick out the tracks passing TPC only cuts
+  
+  
+  const AliESDVertex *vtxSPD = esd.GetPrimaryVertexSPD();
+  const AliESDVertex *vtx = esd.GetPrimaryVertex();
+
+  Double_t pos[3] = { 0. };      
+  Double_t covTr[21]={0.};
+  Double_t pid[10]={0.};  
+
+
+  Double_t p[3] = { 0. };
+
+  Double_t pDCA[3] = { 0. }; // momentum at DCA
+  Double_t rDCA[3] = { 0. }; // position at DCA
+  Float_t  dDCA[2] = {0.};    // DCA to the vertex d and z
+  Float_t  cDCA[3] = {0.};    // covariance of impact parameters
+
+
+  AliAODTrack* aodTrack(0x0);
+  //  AliAODPid* detpid(0x0);
+
+  // account for change in pT after the constraint
+  Float_t ptMax = 1E10;
+  Float_t ptMin = 0;
+  for(int i = 0;i<32;i++){
+    if(fTPCConstrainedFilterMask&(1<<i)){
+      AliESDtrackCuts*cuts = (AliESDtrackCuts*)fTrackFilter->GetCuts()->At(i);
+      Float_t tmp1= 0,tmp2 = 0;
+      cuts->GetPtRange(tmp1,tmp2);
+      if(tmp1>ptMin)ptMin=tmp1;
+      if(tmp2<ptMax)ptMax=tmp2;
+    }
+  } 
+
+  for (Int_t nTrack = 0; nTrack < esd.GetNumberOfTracks(); ++nTrack) 
+  {
+    AliESDtrack* esdTrack = esd.GetTrack(nTrack); //carefull do not modify it othwise  need to work with a copy 
+    
+    UInt_t selectInfo = 0;
+    Bool_t isHybridITSTPC = false;
+    //
+    // Track selection
+    if (fTrackFilter) {
+      selectInfo = fTrackFilter->IsSelected(esdTrack);
+    }
+
+    if(!(selectInfo&fHybridFilterMaskTPCCG)){
+      // not already selected tracks, use second part of hybrid tracks
+      isHybridITSTPC = true;
+      // too save space one could only store these...
+    }
+
+    selectInfo &= fTPCConstrainedFilterMask;
+    if (!selectInfo)continue;
+    if (fWriteHybridTPCCOnly&&!isHybridITSTPC)continue; // write only complementary tracks
+    // create a tpc only tracl
+    AliESDtrack *track = AliESDtrackCuts::GetTPCOnlyTrack(const_cast<AliESDEvent*>(&esd),esdTrack->GetID());
+    if(!track) continue;
+    
+    if(track->Pt()>0.)
+    {
+      // only constrain tracks above threshold
+      AliExternalTrackParam exParam;
+      // take the B-field from the ESD, no 3D fieldMap available at this point
+      Bool_t relate = false;
+      relate = track->RelateToVertexTPC(vtxSPD,esd.GetMagneticField(),kVeryBig,&exParam);
+      if(!relate){
+        delete track;
+        continue;
+      }
+      // fetch the track parameters at the DCA (unconstraint)
+      if(track->GetTPCInnerParam()){
+       track->GetTPCInnerParam()->GetPxPyPz(pDCA);
+       track->GetTPCInnerParam()->GetXYZ(rDCA);
+      }
+      // get the DCA to the vertex:
+      track->GetImpactParametersTPC(dDCA,cDCA);
+      // set the constrained parameters to the track
+      track->Set(exParam.GetX(),exParam.GetAlpha(),exParam.GetParameter(),exParam.GetCovariance());
+    }
+    
+    track->GetPxPyPz(p);
+
+    Float_t pT = track->Pt();
+    if(pT<ptMin||pT>ptMax){
+      delete track;
+      continue;
+    }
+
+    // 
+
+
+    track->GetXYZ(pos);
+    track->GetCovarianceXYZPxPyPz(covTr);
+    esdTrack->GetESDpid(pid);// original PID
+
+    if(fMChandler)fMChandler->SelectParticle(esdTrack->GetLabel());
+    aodTrack = new(Tracks()[fNumberOfTracks++]) AliAODTrack((track->GetID()+1)*-1,
+                                                            track->GetLabel(),
+                                                            p,
+                                                            kTRUE,
+                                                            pos,
+                                                            kFALSE,
+                                                            covTr, 
+                                                            (Short_t)track->GetSign(),
+                                                            track->GetITSClusterMap(), 
+                                                            pid,
+                                                            fPrimaryVertex,
+                                                            kTRUE, // check if this is right
+                                                            vtx->UsesTrack(track->GetID()),
+                                                            AliAODTrack::kPrimary, 
+                                                            selectInfo);
+    aodTrack->SetIsHybridTPCConstrainedGlobal(isHybridITSTPC);    
+    aodTrack->SetTPCFitMap(track->GetTPCFitMap());
+    aodTrack->SetTPCClusterMap(track->GetTPCClusterMap());
+    aodTrack->SetTPCSharedMap (track->GetTPCSharedMap());
+    aodTrack->SetIsTPCConstrained(kTRUE);    
+    aodTrack->SetChi2perNDF(Chi2perNDF(esdTrack)); // original track
+    // set the DCA values to the AOD track
+    aodTrack->SetPxPyPzAtDCA(pDCA[0],pDCA[1],pDCA[2]);
+    aodTrack->SetXYAtDCA(rDCA[0],rDCA[1]);
+    aodTrack->SetDCA(dDCA[0],dDCA[1]);
+
+    aodTrack->SetFlags(track->GetStatus());
+    aodTrack->SetTPCPointsF(track->GetTPCNclsF());
+
+    // do not duplicate PID information 
+    //    aodTrack->ConvertAliPIDtoAODPID();
+    //    SetAODPID(esdTrack,aodTrack,detpid);
+
+    delete track;
+  } // end of loop on tracks
+  
+}
+
+
+void AliAnalysisTaskESDfilter::ConvertGlobalConstrainedTracks(const AliESDEvent& esd)
+{
+
+  // Here we have the option to store the complement from global constraint information
+  // to tracks passing tight cuts (1) in order not to get fakes back in, one needs 
+  // two sets of cuts one tight (1) (to throw out fakes) and one lose (2) (fakes/bad tracks would pass (2) but not (1))
+  // using cut number (3) selects the tracks that complement (1) e.g. tracks witout ITS refit or cluster requirement
+
+
+  AliCodeTimerAuto("",0);
+  
+  // Loop over the tracks and extract and mask out all aod tracks that pass the selections for AODt racks
+  for(int it = 0;it < fNumberOfTracks;++it)
+  {
+    AliAODTrack *tr = (AliAODTrack*)(Tracks().At(it));
+    if(!tr)continue;
+    UInt_t map = tr->GetFilterMap();
+    if(map&fGlobalConstrainedFilterMask){
+      // we only reset the track select info, no deletion...
+      // mask reset mask in case track is already taken
+      tr->SetFilterMap(map&~fGlobalConstrainedFilterMask);
+    }
+    if(map&fHybridFilterMaskGCG){
+      // this is one part of the hybrid tracks
+      // the others not passing the selection will be the ones selected below
+      tr->SetIsHybridGlobalConstrainedGlobal(kTRUE);
+    }
+  }
+  // Loop over the ESD trcks and pick out the tracks passing the GlobalConstraint cuts
+
+  Double_t pos[3] = { 0. };      
+  Double_t covTr[21]={0.};
+  Double_t pid[10]={0.};  
+  Double_t p[3] = { 0. };
+
+  Double_t pDCA[3] = { 0. }; // momentum at DCA
+  Double_t rDCA[3] = { 0. }; // position at DCA
+  Float_t  dDCA[2] = {0.};    // DCA to the vertex d and z
+  Float_t  cDCA[3] = {0.};    // covariance of impact parameters
+
+
+  AliAODTrack* aodTrack(0x0);
+  AliAODPid* detpid(0x0);
+  const AliESDVertex *vtx = esd.GetPrimaryVertex();
+
+  // account for change in pT after the constraint
+  Float_t ptMax = 1E10;
+  Float_t ptMin = 0;
+  for(int i = 0;i<32;i++){
+    if(fGlobalConstrainedFilterMask&(1<<i)){
+      AliESDtrackCuts*cuts = (AliESDtrackCuts*)fTrackFilter->GetCuts()->At(i);
+      Float_t tmp1= 0,tmp2 = 0;
+      cuts->GetPtRange(tmp1,tmp2);
+      if(tmp1>ptMin)ptMin=tmp1;
+      if(tmp2<ptMax)ptMax=tmp2;
+    }
+  } 
+
+
+
+ for (Int_t nTrack = 0; nTrack < esd.GetNumberOfTracks(); ++nTrack) 
+  {
+    AliESDtrack* esdTrack = esd.GetTrack(nTrack); //carefull do not modify it othwise  need to work with a copy 
+    const AliExternalTrackParam * exParamGC = esdTrack->GetConstrainedParam();
+    if(!exParamGC)continue;
+
+    UInt_t selectInfo = 0;
+    Bool_t isHybridGC = false;
+
+    //
+    // Track selection
+    if (fTrackFilter) {
+      selectInfo = fTrackFilter->IsSelected(esdTrack);
+    }
+
+
+    if(!(selectInfo&fHybridFilterMaskGCG))isHybridGC = true;
+    if (fWriteHybridGCOnly&&!isHybridGC)continue; // write only complementary tracks
+
+    selectInfo &= fGlobalConstrainedFilterMask;
+    if (!selectInfo)continue;
+    // fetch the track parameters at the DCA (unconstrained)
+    esdTrack->GetPxPyPz(pDCA);
+    esdTrack->GetXYZ(rDCA);
+    // get the DCA to the vertex:
+    esdTrack->GetImpactParameters(dDCA,cDCA);
+
+    if (!esdTrack->GetConstrainedPxPyPz(p)) continue;
+
+
+    Float_t pT = exParamGC->Pt();
+    if(pT<ptMin||pT>ptMax){
+      continue;
+    }
+
+
+    esdTrack->GetConstrainedXYZ(pos);
+    exParamGC->GetCovarianceXYZPxPyPz(covTr);
+    esdTrack->GetESDpid(pid);
+    if(fMChandler)fMChandler->SelectParticle(esdTrack->GetLabel());
+    aodTrack = new(Tracks()[fNumberOfTracks++]) AliAODTrack((esdTrack->GetID()+1)*-1,
+                                                            esdTrack->GetLabel(),
+                                                            p,
+                                                            kTRUE,
+                                                            pos,
+                                                            kFALSE,
+                                                            covTr, 
+                                                            (Short_t)esdTrack->GetSign(),
+                                                            esdTrack->GetITSClusterMap(), 
+                                                            pid,
+                                                            fPrimaryVertex,
+                                                            kTRUE, // check if this is right
+                                                            vtx->UsesTrack(esdTrack->GetID()),
+                                                            AliAODTrack::kPrimary, 
+                                                            selectInfo);
+    aodTrack->SetIsHybridGlobalConstrainedGlobal(isHybridGC);    
+    aodTrack->SetIsGlobalConstrained(kTRUE);    
+    aodTrack->SetTPCFitMap(esdTrack->GetTPCFitMap());
+    aodTrack->SetTPCClusterMap(esdTrack->GetTPCClusterMap());
+    aodTrack->SetTPCSharedMap (esdTrack->GetTPCSharedMap());
+    aodTrack->SetChi2perNDF(Chi2perNDF(esdTrack));
+
+
+    // set the DCA values to the AOD track
+    aodTrack->SetPxPyPzAtDCA(pDCA[0],pDCA[1],pDCA[2]);
+    aodTrack->SetXYAtDCA(rDCA[0],rDCA[1]);
+    aodTrack->SetDCA(dDCA[0],dDCA[1]);
+
+    aodTrack->SetFlags(esdTrack->GetStatus());
+    aodTrack->SetTPCPointsF(esdTrack->GetTPCNclsF());
+
+    if(isHybridGC){
+      // only copy AOD information for hybrid, no duplicate information
+      aodTrack->ConvertAliPIDtoAODPID();
+      SetAODPID(esdTrack,aodTrack,detpid);
+    }
+  } // end of loop on tracks
+  
+}
+
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::ConvertTracks(const AliESDEvent& esd)
+{
+  // Tracks (primary and orphan)
+
+  AliCodeTimerAuto("",0);
+  
+  AliDebug(1,Form("NUMBER OF ESD TRACKS %5d\n", esd.GetNumberOfTracks()));
+  
+  const AliESDVertex *vtx = esd.GetPrimaryVertex();
+  Double_t p[3] = { 0. };
+  Double_t pos[3] = { 0. };
+  Double_t trkPos[3] = {0.,0.,0.};
+  Double_t covTr[21] = { 0. };
+  Double_t pid[10] = { 0. };
+  AliAODTrack* aodTrack(0x0);
+  AliAODPid* detpid(0x0);
+  
+  for (Int_t nTrack = 0; nTrack < esd.GetNumberOfTracks(); ++nTrack) 
+  {
+    if (fUsedTrack[nTrack]) continue;
+    
+    AliESDtrack *esdTrack = esd.GetTrack(nTrack);
+    UInt_t selectInfo = 0;
+    //
+    // Track selection
+    if (fTrackFilter) {
+           selectInfo = fTrackFilter->IsSelected(esdTrack);
+           if (!selectInfo && !vtx->UsesTrack(esdTrack->GetID())) continue;
+    }
+    
+    
+    esdTrack->GetPxPyPz(p);
+    esdTrack->GetXYZ(pos);
+    esdTrack->GetCovarianceXYZPxPyPz(covTr);
+    esdTrack->GetESDpid(pid);
+    if(fMChandler)fMChandler->SelectParticle(esdTrack->GetLabel());
+    fPrimaryVertex->AddDaughter(aodTrack =
+                         new(Tracks()[fNumberOfTracks++]) AliAODTrack(esdTrack->GetID(),
+                                                            esdTrack->GetLabel(),
+                                                            p,
+                                                            kTRUE,
+                                                            pos,
+                                                            kFALSE,
+                                                            covTr, 
+                                                            (Short_t)esdTrack->GetSign(),
+                                                            esdTrack->GetITSClusterMap(), 
+                                                            pid,
+                                                            fPrimaryVertex,
+                                                            kTRUE, // check if this is right
+                                                            vtx->UsesTrack(esdTrack->GetID()),
+                                                            AliAODTrack::kPrimary, 
+                                                            selectInfo)
+                         );
+    aodTrack->SetTPCFitMap(esdTrack->GetTPCFitMap());
+    aodTrack->SetTPCClusterMap(esdTrack->GetTPCClusterMap());
+    aodTrack->SetTPCSharedMap (esdTrack->GetTPCSharedMap());
+    aodTrack->SetChi2perNDF(Chi2perNDF(esdTrack));
+    aodTrack->SetTPCPointsF(esdTrack->GetTPCNclsF());
+    if(esdTrack->IsEMCAL()) aodTrack->SetEMCALcluster(esdTrack->GetEMCALcluster());
+    if(esdTrack->IsPHOS())  aodTrack->SetPHOScluster(esdTrack->GetPHOScluster());
+
+    //Perform progagation of tracks if needed
+    if(fDoPropagateTrackToEMCal)
+      {
+       Double_t EMCalEta, EMCalPhi;
+       Double_t trkphi = esdTrack->Phi()*TMath::RadToDeg();
+       if(TMath::Abs(esdTrack->Eta())<0.9 && trkphi > 10 && trkphi < 250 )
+         {
+           AliExternalTrackParam *trkParam = const_cast<AliExternalTrackParam*>(esdTrack->GetInnerParam());
+           if(trkParam)
+             {
+               AliExternalTrackParam trkParamTmp(*trkParam);
+               if(AliTrackerBase::PropagateTrackToBxByBz(&trkParamTmp, 430, esdTrack->GetMass(), 20, kTRUE, 0.8, -1))
+                 {
+                   trkParamTmp.GetXYZ(trkPos);
+                   TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
+                   EMCalEta = trkPosVec.Eta();
+                   EMCalPhi = trkPosVec.Phi();
+                   if(EMCalPhi<0)  EMCalPhi += 2*TMath::Pi();
+                   esdTrack->SetTrackPhiEtaOnEMCal(EMCalPhi,EMCalEta);
+                 }
+             }
+         }
+      }
+    aodTrack->SetTrackPhiEtaOnEMCal(esdTrack->GetTrackPhiOnEMCal(),esdTrack->GetTrackEtaOnEMCal());
+
+    fAODTrackRefs->AddAt(aodTrack, nTrack);
+    
+    
+    if (esdTrack->GetSign() > 0) ++fNumberOfPositiveTracks;
+    aodTrack->SetFlags(esdTrack->GetStatus());
+    aodTrack->ConvertAliPIDtoAODPID();
+    SetAODPID(esdTrack,aodTrack,detpid);
+  } // end of loop on tracks
+}
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::ConvertPmdClusters(const AliESDEvent& esd)
+{
+// Convert PMD Clusters 
+  AliCodeTimerAuto("",0);
+  Int_t jPmdClusters=0;
+  // Access to the AOD container of PMD clusters
+  TClonesArray &pmdClusters = *(AODEvent()->GetPmdClusters());
+  for (Int_t iPmd = 0; iPmd < esd.GetNumberOfPmdTracks(); ++iPmd) {
+    // file pmd clusters, to be revised!
+    AliESDPmdTrack *pmdTrack = esd.GetPmdTrack(iPmd);
+    Int_t nLabel = 0;
+    Int_t *label = 0x0;
+    Double_t posPmd[3] = { pmdTrack->GetClusterX(), pmdTrack->GetClusterY(), pmdTrack->GetClusterZ()};
+    Double_t pidPmd[13] = { 0.}; // to be revised!
+    // type not set!
+    // assoc cluster not set
+    new(pmdClusters[jPmdClusters++]) AliAODPmdCluster(iPmd, nLabel, label, pmdTrack->GetClusterADC(), posPmd, pidPmd);
+  }
+}
+
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::ConvertCaloClusters(const AliESDEvent& esd)
+{
+// Convert Calorimeter Clusters
+  AliCodeTimerAuto("",0);
+  
+  // Access to the AOD container of clusters
+  TClonesArray &caloClusters = *(AODEvent()->GetCaloClusters());
+  Int_t jClusters(0);
+  
+  for (Int_t iClust=0; iClust<esd.GetNumberOfCaloClusters(); ++iClust) {
+    
+    AliESDCaloCluster * cluster = esd.GetCaloCluster(iClust);
+    
+    Int_t  id        = cluster->GetID();
+    Int_t  nLabel    = cluster->GetNLabels();
+    Int_t *labels    = cluster->GetLabels();
+    if(labels){ 
+                 for(int i = 0;i < nLabel;++i){
+                         if(fMChandler)fMChandler->SelectParticle(labels[i]);
+                 }
+         }             
+    
+    Float_t energy = cluster->E();
+    Float_t posF[3] = { 0.};
+    cluster->GetPosition(posF);
+    
+    AliAODCaloCluster *caloCluster = new(caloClusters[jClusters++]) AliAODCaloCluster(id,
+                                                                                      nLabel,
+                                                                                      labels,
+                                                                                      energy,
+                                                                                      posF,
+                                                                                      NULL,
+                                                                                      cluster->GetType(),0);
+    
+    caloCluster->SetCaloCluster(cluster->GetDistanceToBadChannel(),
+                                cluster->GetDispersion(),
+                                cluster->GetM20(), cluster->GetM02(),
+                                cluster->GetEmcCpvDistance(),  
+                                cluster->GetNExMax(),cluster->GetTOF()) ;
+    
+    caloCluster->SetPIDFromESD(cluster->GetPID());
+    caloCluster->SetNCells(cluster->GetNCells());
+    caloCluster->SetCellsAbsId(cluster->GetCellsAbsId());
+    caloCluster->SetCellsAmplitudeFraction(cluster->GetCellsAmplitudeFraction());
+
+    caloCluster->SetTrackDistance(cluster->GetTrackDx(), cluster->GetTrackDz());
+    
+    Int_t nMatchCount = 0;
+    TArrayI* matchedT =        cluster->GetTracksMatched();
+    if (fNumberOfTracks>0 && matchedT && cluster->GetTrackMatchedIndex() >= 0) {       
+      for (Int_t im = 0; im < matchedT->GetSize(); im++) {
+        Int_t iESDtrack = matchedT->At(im);;
+        if (fAODTrackRefs->At(iESDtrack) != 0) {
+          caloCluster->AddTrackMatched((AliAODTrack*)fAODTrackRefs->At(iESDtrack));
+         nMatchCount++;
+        }
+      }
+    }
+    if(nMatchCount==0)
+      caloCluster->SetTrackDistance(-999,-999);
+    
+  } 
+  caloClusters.Expand(jClusters); // resize TObjArray to 'remove' slots for pseudo clusters     
+}
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::ConvertCaloTrigger(TString calo, const AliESDEvent& esd)
+{
+       AliCodeTimerAuto("",0);
+               
+       if (calo == "PHOS") 
+       {
+         AliAODCaloTrigger &aodTrigger = *(AODEvent()->GetCaloTrigger(calo));
+         AliESDCaloTrigger &esdTrigger = *(esd.GetCaloTrigger(calo));
+
+         aodTrigger.Allocate(esdTrigger.GetEntries());
+         esdTrigger.Reset();
+
+         Float_t a;
+         Int_t tmod,tabsId;
+
+         while (esdTrigger.Next()) {
+           esdTrigger.GetPosition(tmod,tabsId);
+           esdTrigger.GetAmplitude(a);
+           aodTrigger.Add(tmod,tabsId,a,0.,(Int_t*)NULL,0,0,0);
+         }
+
+         return;
+       }
+                       
+       AliAODHandler *aodHandler = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()); 
+                       
+       if (aodHandler)
+       {
+               TTree *aodTree = aodHandler->GetTree();
+                                       
+               if (aodTree)
+               {
+                       Int_t *type = esd.GetCaloTriggerType();
+                                                       
+                       for (Int_t i = 0; i < 15; i++) 
+                       {
+                               aodTree->GetUserInfo()->Add(new TParameter<int>(Form("EMCALCaloTrigger%d",i), type[i]));
+                       }
+               }
+       }
+                                               
+       AliAODCaloTrigger &aodTrigger = *(AODEvent()->GetCaloTrigger(calo));
+                                               
+       AliESDCaloTrigger &esdTrigger = *(esd.GetCaloTrigger(calo));
+                                               
+       aodTrigger.Allocate(esdTrigger.GetEntries());
+                                               
+       esdTrigger.Reset();
+       while (esdTrigger.Next())
+       {         
+               Int_t px, py, ts, nTimes, times[10], b; 
+               Float_t a, t;
+                                                               
+               esdTrigger.GetPosition(px, py);
+                                               
+               esdTrigger.GetAmplitude(a);
+               esdTrigger.GetTime(t);
+                                                               
+               esdTrigger.GetL0Times(times);
+               esdTrigger.GetNL0Times(nTimes);
+                                                               
+               esdTrigger.GetL1TimeSum(ts);
+                                                               
+               esdTrigger.GetTriggerBits(b);
+                                                               
+               aodTrigger.Add(px, py, a, t, times, nTimes, ts, b);
+       }
+                                                       
+       for (int i = 0; i < 4; i++) aodTrigger.SetL1Threshold(i, esdTrigger.GetL1Threshold(i));
+                                                       
+       Int_t v0[2] = 
+       {
+               esdTrigger.GetL1V0(0),
+               esdTrigger.GetL1V0(1)
+       };              
+                                                               
+       aodTrigger.SetL1V0(v0); 
+       aodTrigger.SetL1FrameMask(esdTrigger.GetL1FrameMask());
+}
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::ConvertEMCALCells(const AliESDEvent& esd)
+{
+// Convert EMCAL Cells
+  AliCodeTimerAuto("",0);
+  // fill EMCAL cell info
+  if (esd.GetEMCALCells()) { // protection against missing ESD information
+    AliESDCaloCells &esdEMcells = *(esd.GetEMCALCells());
+    Int_t nEMcell = esdEMcells.GetNumberOfCells() ;
+    
+    AliAODCaloCells &aodEMcells = *(AODEvent()->GetEMCALCells());
+    aodEMcells.CreateContainer(nEMcell);
+    aodEMcells.SetType(AliAODCaloCells::kEMCALCell);
+    for (Int_t iCell = 0; iCell < nEMcell; iCell++) {      
       aodEMcells.SetCell(iCell,esdEMcells.GetCellNumber(iCell),esdEMcells.GetAmplitude(iCell),
-                         esdEMcells.GetTime(iCell), esdEMcells.GetMCLabel(iCell), esdEMcells.GetEFraction(iCell));\r
-    }\r
-    aodEMcells.Sort();\r
-  }\r
-}\r
-\r
-//______________________________________________________________________________\r
-void AliAnalysisTaskESDfilter::ConvertPHOSCells(const AliESDEvent& esd)\r
-{\r
-// Convert PHOS Cells\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
+                         esdEMcells.GetTime(iCell), esdEMcells.GetMCLabel(iCell), esdEMcells.GetEFraction(iCell));
+    }
+    aodEMcells.Sort();
+  }
+}
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::ConvertPHOSCells(const AliESDEvent& esd)
+{
+// Convert PHOS Cells
+  AliCodeTimerAuto("",0);
+  // fill PHOS cell info
+  if (esd.GetPHOSCells()) { // protection against missing ESD information
+    AliESDCaloCells &esdPHcells = *(esd.GetPHOSCells());
+    Int_t nPHcell = esdPHcells.GetNumberOfCells() ;
+    
+    AliAODCaloCells &aodPHcells = *(AODEvent()->GetPHOSCells());
+    aodPHcells.CreateContainer(nPHcell);
+    aodPHcells.SetType(AliAODCaloCells::kPHOSCell);
+    for (Int_t iCell = 0; iCell < nPHcell; iCell++) {      
       aodPHcells.SetCell(iCell,esdPHcells.GetCellNumber(iCell),esdPHcells.GetAmplitude(iCell),
-                         esdPHcells.GetTime(iCell), esdPHcells.GetMCLabel(iCell), esdPHcells.GetEFraction(iCell));\r
-    }\r
-    aodPHcells.Sort();\r
-  }\r
-}\r
-\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
-      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
-    }\r
-  } else {\r
-    //Printf("ERROR: AliMultiplicity could not be retrieved from ESD");\r
-  }\r
-}\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->SetTPCFitMap(esdTrackM->GetTPCFitMap());\r
-            mother->SetTPCClusterMap(esdTrackM->GetTPCClusterMap());\r
-            mother->SetTPCSharedMap (esdTrackM->GetTPCSharedMap());\r
-            mother->SetChi2perNDF(Chi2perNDF(esdTrackM));\r
-            mother->SetTPCPointsF(esdTrackM->GetTPCNclsF());\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);\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->SetTPCFitMap(esdTrackD->GetTPCFitMap());\r
-            daughter->SetTPCClusterMap(esdTrackD->GetTPCClusterMap());\r
-            daughter->SetTPCSharedMap (esdTrackD->GetTPCSharedMap());\r
-           daughter->SetTPCPointsF(esdTrackD->GetTPCNclsF());\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);\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
-  // 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
-    pVSPD->SetBC(vtxP->GetBC());\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
-    pVTRK->SetBC(vtxP->GetBC());\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
-//______________________________________________________________________________\r
-void AliAnalysisTaskESDfilter::ConvertTZERO(const AliESDEvent& esd)\r
-{\r
-  // Convert TZERO data\r
-  const AliESDTZERO* esdTzero = esd.GetESDTZERO(); \r
-  AliAODTZERO* aodTzero = AODEvent()->GetTZEROData();\r
-\r
-  for (Int_t icase=0; icase<3; icase++){ \r
-    aodTzero->SetT0TOF(    icase, esdTzero->GetT0TOF(icase));\r
-    aodTzero->SetT0TOFbest(icase, esdTzero->GetT0TOFbest(icase)); \r
-  }\r
-  aodTzero->SetBackgroundFlag(esdTzero->GetBackgroundFlag());\r
-  aodTzero->SetPileupFlag(esdTzero->GetPileupFlag());\r
-  aodTzero->SetSatelliteFlag(esdTzero->GetSatellite()); \r
-\r
-  Float_t rawTime[24];\r
-  for(Int_t ipmt=0; ipmt<24; ipmt++)\r
-    rawTime[ipmt] = esdTzero->GetTimeFull(ipmt,0);\r
-   \r
-  Int_t idxOfFirstPmtA = -1,       idxOfFirstPmtC = -1;\r
-  Float_t timeOfFirstPmtA = 9999, timeOfFirstPmtC = 9999;\r
-  for(int ipmt=0;  ipmt<12; ipmt++){\r
-    if( rawTime[ipmt] > -200 && rawTime[ipmt] < timeOfFirstPmtC && rawTime[ipmt]!=0){\r
-      timeOfFirstPmtC = rawTime[ipmt];\r
-      idxOfFirstPmtC  = ipmt;\r
-    }\r
-  }\r
-  for(int ipmt=12; ipmt<24; ipmt++){\r
-    if( rawTime[ipmt] > -200 && rawTime[ipmt] < timeOfFirstPmtA && rawTime[ipmt]!=0 ){\r
-      timeOfFirstPmtA = rawTime[ipmt];\r
-      idxOfFirstPmtA  = ipmt;\r
-    }\r
-  }\r
-\r
-  if(idxOfFirstPmtA != -1 && idxOfFirstPmtC != -1){\r
-    //speed of light in cm/ns   TMath::C()*1e-7 \r
-    Float_t vertexraw = TMath::C()*1e-7 * (rawTime[idxOfFirstPmtA] - rawTime[idxOfFirstPmtC])/2;\r
-    aodTzero->SetT0VertexRaw( vertexraw );\r
-  }else{\r
-    aodTzero->SetT0VertexRaw(99999);\r
-  }\r
-\r
-}\r
-\r
-\r
-//______________________________________________________________________________\r
-void AliAnalysisTaskESDfilter::ConvertZDC(const AliESDEvent& esd)\r
-{\r
-  // Convert ZDC data\r
-  AliESDZDC* esdZDC = esd.GetZDCData();\r
-  \r
-  const Double_t zem1Energy = esdZDC->GetZEM1Energy();\r
-  const Double_t zem2Energy = esdZDC->GetZEM2Energy();\r
-   \r
-  const Double_t *towZNC = esdZDC->GetZNCTowerEnergy();\r
-  const Double_t *towZPC = esdZDC->GetZPCTowerEnergy();\r
-  const Double_t *towZNA = esdZDC->GetZNATowerEnergy();\r
-  const Double_t *towZPA = esdZDC->GetZPATowerEnergy();\r
-  const Double_t *towZNCLG = esdZDC->GetZNCTowerEnergyLR();\r
-  const Double_t *towZNALG = esdZDC->GetZNATowerEnergyLR();\r
-  \r
-  AliAODZDC* zdcAOD = AODEvent()->GetZDCData();\r
-\r
-  zdcAOD->SetZEM1Energy(zem1Energy);\r
-  zdcAOD->SetZEM2Energy(zem2Energy);\r
-  zdcAOD->SetZNCTowers(towZNC, towZNCLG);\r
-  zdcAOD->SetZNATowers(towZNA, towZNALG);\r
-  zdcAOD->SetZPCTowers(towZPC);\r
-  zdcAOD->SetZPATowers(towZPA);\r
-  \r
-  zdcAOD->SetZDCParticipants(esdZDC->GetZDCParticipants(), esdZDC->GetZDCPartSideA(), esdZDC->GetZDCPartSideC());\r
-  zdcAOD->SetZDCImpactParameter(esdZDC->GetImpactParameter(), esdZDC->GetImpactParamSideA(), \r
-       esdZDC->GetImpactParamSideC());\r
-  zdcAOD->SetZDCTDCSum(esdZDC->GetZNTDCSum(0));        \r
-  zdcAOD->SetZDCTDCDiff(esdZDC->GetZNTDCDiff(0));      \r
-\r
-}\r
-\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
-      // Reconstruct cascades and V0 here\r
-  if (fIsV0CascadeRecoEnabled) {\r
-    esd->ResetCascades();\r
-    esd->ResetV0s();\r
-\r
-    AliV0vertexer lV0vtxer;\r
-    AliCascadeVertexer lCascVtxer;\r
-\r
-    lV0vtxer.SetCuts(fV0Cuts);\r
-    lCascVtxer.SetCuts(fCascadeCuts);\r
-\r
-\r
-    lV0vtxer.Tracks2V0vertices(esd);\r
-    lCascVtxer.V0sTracks2CascadeVertices(esd);\r
-  }\r
-\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
-  if ( fIsTZEROEnabled ) ConvertTZERO(*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
-  AliESDInputHandler* esdH = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());\r
-  if (esdH)\r
-      fESDpid = esdH->GetESDpid();\r
-\r
-  if (fIsPidOwner && fESDpid){\r
-    delete fESDpid;\r
-    fESDpid = 0;\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
-      //    fESDpid->SetTOFResponse(esd, (AliESDpid::EStartTimeType_t)fTimeZeroType);    \r
-    AliTOFHeader tmpTOFHeader(0,t0spread[0],0,NULL,NULL,NULL,intrinsicTOFres,t0spread[0]);   \r
-    AODEvent()->SetTOFHeader(&tmpTOFHeader);         // write dummy TOF header in AOD\r
-  } else {\r
-    AODEvent()->SetTOFHeader(esd->GetTOFHeader());    // write TOF header in AOD\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 ( fTPCConstrainedFilterMask ) ConvertTPCOnlyTracks(*esd);\r
-  if( fGlobalConstrainedFilterMask) ConvertGlobalConstrainedTracks(*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 ( fAreEMCALTriggerEnabled )ConvertCaloTrigger(TString("EMCAL"), *esd);\r
-\r
-       if ( fArePHOSTriggerEnabled )ConvertCaloTrigger(TString("PHOS"), *esd);\r
-  \r
-  if ( fAreTrackletsEnabled ) ConvertTracklets(*esd);\r
-  if ( fIsZDCEnabled ) ConvertZDC(*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
-  if ( fIsPidOwner){\r
-    delete fESDpid;\r
-    fESDpid = 0x0;\r
-  }\r
-\r
-\r
-}\r
-\r
-\r
-//______________________________________________________________________________\r
-void AliAnalysisTaskESDfilter::SetAODPID(AliESDtrack *esdtrack, AliAODTrack *aodtrack, AliAODPid *detpid)\r
-{\r
-  //\r
-  // Setter for the raw PID detector signals\r
-  //\r
-\r
-  // Save PID object for candidate electrons\r
-    Bool_t pidSave = kFALSE;\r
-    if (fTrackFilter) {\r
-       Bool_t selectInfo = fTrackFilter->IsSelected((char*) "Electrons");\r
-       if (selectInfo)  pidSave = kTRUE;\r
-    }\r
-\r
-\r
-    // Tracks passing pt cut \r
-    if(esdtrack->Pt()>fHighPthreshold) {\r
-       pidSave = kTRUE;\r
-    } else {\r
-       if(fPtshape){\r
-           if(esdtrack->Pt()> fPtshape->GetXmin()){\r
-               Double_t y = fPtshape->Eval(esdtrack->Pt())/fPtshape->Eval(fHighPthreshold);\r
-               if(gRandom->Rndm(0)<1./y){\r
-                   pidSave = kTRUE;\r
-               }//end rndm\r
-           }//end if p < pmin\r
-       }//end if p function\r
-    }// end else\r
-\r
-    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);\r
-       aodtrack->SetDetPID(detpid);\r
-      }\r
-    }\r
-}\r
-\r
-//______________________________________________________________________________\r
-void AliAnalysisTaskESDfilter::SetDetectorRawSignals(AliAODPid *aodpid, AliESDtrack *track)\r
-{\r
-//\r
-//assignment of the detector signals (AliXXXesdPID inspired)\r
-//\r
- if(!track){\r
- AliInfo("no ESD track found. .....exiting");\r
- return;\r
- }\r
- // TPC momentum\r
- const AliExternalTrackParam *in=track->GetInnerParam();\r
- if (in) {\r
-   aodpid->SetTPCmomentum(in->GetP());\r
- }else{\r
-   aodpid->SetTPCmomentum(-1.);\r
- }\r
-\r
-\r
- aodpid->SetITSsignal(track->GetITSsignal());\r
- Double_t itsdedx[4]; // dE/dx samples for individual ITS layers\r
- track->GetITSdEdxSamples(itsdedx);\r
- aodpid->SetITSdEdxSamples(itsdedx);\r
-\r
- aodpid->SetTPCsignal(track->GetTPCsignal());\r
- aodpid->SetTPCsignalN(track->GetTPCsignalN());\r
- if(track->GetTPCdEdxInfo()) aodpid->SetTPCdEdxInfo(track->GetTPCdEdxInfo());\r
-\r
- //n TRD planes = 6\r
- Int_t nslices = track->GetNumberOfTRDslices()*6;\r
- TArrayD trdslices(nslices);\r
- for(Int_t iSl =0; iSl < track->GetNumberOfTRDslices(); iSl++) {\r
-   for(Int_t iPl =0; iPl<6; iPl++) trdslices[iPl*track->GetNumberOfTRDslices()+iSl] = track->GetTRDslice(iPl,iSl);\r
- }\r
\r
-//TRD momentum\r
- for(Int_t iPl=0;iPl<6;iPl++){\r
-   Double_t trdmom=track->GetTRDmomentum(iPl);\r
-   aodpid->SetTRDmomentum(iPl,trdmom);\r
- }\r
-\r
- aodpid->SetTRDsignal(track->GetNumberOfTRDslices()*6,trdslices.GetArray());\r
-\r
- //TRD clusters and tracklets\r
- aodpid->SetTRDncls(track->GetTRDncls());\r
- aodpid->SetTRDntrackletsPID(track->GetTRDntrackletsPID());\r
\r
- //TOF PID  \r
- Double_t times[AliAODPid::kSPECIES]; track->GetIntegratedTimes(times);\r
- aodpid->SetIntegratedTimes(times);\r
-\r
-   //  Float_t tzeroTrack = fESDpid->GetTOFResponse().GetStartTime(track->P());\r
+                         esdPHcells.GetTime(iCell), esdPHcells.GetMCLabel(iCell), esdPHcells.GetEFraction(iCell));
+    }
+    aodPHcells.Sort();
+  }
+}
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::ConvertTracklets(const AliESDEvent& esd)
+{
+  // tracklets    
+  AliCodeTimerAuto("",0);
+
+  AliAODTracklets &SPDTracklets = *(AODEvent()->GetTracklets());
+  const AliMultiplicity *mult = esd.GetMultiplicity();
+  if (mult) {
+    if (mult->GetNumberOfTracklets()>0) {
+      SPDTracklets.CreateContainer(mult->GetNumberOfTracklets());
+      
+      for (Int_t n=0; n<mult->GetNumberOfTracklets(); n++) {
+        if(fMChandler){
+          fMChandler->SelectParticle(mult->GetLabel(n, 0));
+          fMChandler->SelectParticle(mult->GetLabel(n, 1));
+        }
+        SPDTracklets.SetTracklet(n, mult->GetTheta(n), mult->GetPhi(n), mult->GetDeltaPhi(n), mult->GetLabel(n, 0),mult->GetLabel(n, 1));
+      }
+    }
+  } else {
+    //Printf("ERROR: AliMultiplicity could not be retrieved from ESD");
+  }
+}
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::ConvertKinks(const AliESDEvent& esd)
+{
+  AliCodeTimerAuto("",0);
+  
+  // Kinks: it is a big mess the access to the information in the kinks
+  // The loop is on the tracks in order to find the mother and daugther of each kink
+  
+  Double_t covTr[21]={0.};
+  Double_t pid[10]={0.};
+  AliAODPid* detpid(0x0);
+  
+  fNumberOfKinks = esd.GetNumberOfKinks();
+
+  const AliESDVertex* vtx = esd.GetPrimaryVertex();
+  
+  for (Int_t iTrack=0; iTrack<esd.GetNumberOfTracks(); ++iTrack) 
+  {
+    AliESDtrack * esdTrack = esd.GetTrack(iTrack);
+    
+    Int_t ikink = esdTrack->GetKinkIndex(0);
+    
+    if (ikink && fNumberOfKinks) {
+           // Negative kink index: mother, positive: daughter
+           
+           // Search for the second track of the kink
+           
+           for (Int_t jTrack = iTrack+1; jTrack<esd.GetNumberOfTracks(); ++jTrack) {
+        
+        AliESDtrack * esdTrack1 = esd.GetTrack(jTrack);
+        
+        Int_t jkink = esdTrack1->GetKinkIndex(0);
+        
+        if ( TMath::Abs(ikink)==TMath::Abs(jkink) ) {
+          
+          // The two tracks are from the same kink
+          
+          if (fUsedKink[TMath::Abs(ikink)-1]) continue; // skip used kinks
+          
+          Int_t imother = -1;
+          Int_t idaughter = -1;
+          
+          if (ikink<0 && jkink>0) {
+            
+            imother = iTrack;
+            idaughter = jTrack;
+          }
+          else if (ikink>0 && jkink<0) {
+            
+            imother = jTrack;
+            idaughter = iTrack;
+          }
+          else {
+            //                 cerr << "Error: Wrong combination of kink indexes: "
+            //                      << ikink << " " << jkink << endl;
+            continue;
+          }
+          
+          // Add the mother track if it passed primary track selection cuts
+          
+          AliAODTrack * mother = NULL;
+          
+          UInt_t selectInfo = 0;
+          if (fTrackFilter) {
+            selectInfo = fTrackFilter->IsSelected(esd.GetTrack(imother));
+            if (!selectInfo) continue;
+          }
+          
+          if (!fUsedTrack[imother]) {
+            
+            fUsedTrack[imother] = kTRUE;
+            
+            AliESDtrack *esdTrackM = esd.GetTrack(imother);
+            Double_t p[3] = { 0. };
+            Double_t pos[3] = { 0. };
+            esdTrackM->GetPxPyPz(p);
+            esdTrackM->GetXYZ(pos);
+            esdTrackM->GetCovarianceXYZPxPyPz(covTr);
+            esdTrackM->GetESDpid(pid);
+            if(fMChandler)fMChandler->SelectParticle(esdTrackM->GetLabel());
+            mother = 
+            new(Tracks()[fNumberOfTracks++]) AliAODTrack(esdTrackM->GetID(),
+                                               esdTrackM->GetLabel(),
+                                               p,
+                                               kTRUE,
+                                               pos,
+                                               kFALSE,
+                                               covTr, 
+                                               (Short_t)esdTrackM->GetSign(),
+                                               esdTrackM->GetITSClusterMap(), 
+                                               pid,
+                                               fPrimaryVertex,
+                                               kTRUE, // check if this is right
+                                               vtx->UsesTrack(esdTrack->GetID()),
+                                               AliAODTrack::kPrimary,
+                                               selectInfo);
+            mother->SetTPCFitMap(esdTrackM->GetTPCFitMap());
+            mother->SetTPCClusterMap(esdTrackM->GetTPCClusterMap());
+            mother->SetTPCSharedMap (esdTrackM->GetTPCSharedMap());
+            mother->SetChi2perNDF(Chi2perNDF(esdTrackM));
+            mother->SetTPCPointsF(esdTrackM->GetTPCNclsF());
+
+            fAODTrackRefs->AddAt(mother, imother);
+            
+            if (esdTrackM->GetSign() > 0) ++fNumberOfPositiveTracks;
+            mother->SetFlags(esdTrackM->GetStatus());
+            mother->ConvertAliPIDtoAODPID();
+            fPrimaryVertex->AddDaughter(mother);
+            mother->ConvertAliPIDtoAODPID();
+            SetAODPID(esdTrackM,mother,detpid);
+          }
+          else {
+            //                 cerr << "Error: event " << esd.GetEventNumberInFile() << " kink " << TMath::Abs(ikink)-1
+            //                      << " track " << imother << " has already been used!" << endl;
+          }
+          
+          // Add the kink vertex
+          AliESDkink * kink = esd.GetKink(TMath::Abs(ikink)-1);
+          
+          AliAODVertex * vkink = 
+          new(Vertices()[fNumberOfVertices++]) AliAODVertex(kink->GetPosition(),
+                                                  NULL,
+                                                  0.,
+                                                  mother,
+                                                  esdTrack->GetID(),  // This is the track ID of the mother's track!
+                                                  AliAODVertex::kKink);
+          // Add the daughter track
+          
+          AliAODTrack * daughter = NULL;
+          
+          if (!fUsedTrack[idaughter]) {
+            
+            fUsedTrack[idaughter] = kTRUE;
+            
+            AliESDtrack *esdTrackD = esd.GetTrack(idaughter);
+            Double_t p[3] = { 0. };
+            Double_t pos[3] = { 0. };
+
+            esdTrackD->GetPxPyPz(p);
+            esdTrackD->GetXYZ(pos);
+            esdTrackD->GetCovarianceXYZPxPyPz(covTr);
+            esdTrackD->GetESDpid(pid);
+            selectInfo = 0;
+            if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdTrackD);
+            if(fMChandler)fMChandler->SelectParticle(esdTrackD->GetLabel());
+            daughter = 
+            new(Tracks()[fNumberOfTracks++]) AliAODTrack(esdTrackD->GetID(),
+                                               esdTrackD->GetLabel(),
+                                               p,
+                                               kTRUE,
+                                               pos,
+                                               kFALSE,
+                                               covTr, 
+                                               (Short_t)esdTrackD->GetSign(),
+                                               esdTrackD->GetITSClusterMap(), 
+                                               pid,
+                                               vkink,
+                                               kTRUE, // check if this is right
+                                               vtx->UsesTrack(esdTrack->GetID()),
+                                               AliAODTrack::kSecondary,
+                                               selectInfo);
+            daughter->SetTPCFitMap(esdTrackD->GetTPCFitMap());
+            daughter->SetTPCClusterMap(esdTrackD->GetTPCClusterMap());
+            daughter->SetTPCSharedMap (esdTrackD->GetTPCSharedMap());
+           daughter->SetTPCPointsF(esdTrackD->GetTPCNclsF());
+            fAODTrackRefs->AddAt(daughter, idaughter);
+            
+            if (esdTrackD->GetSign() > 0) ++fNumberOfPositiveTracks;
+            daughter->SetFlags(esdTrackD->GetStatus());
+            daughter->ConvertAliPIDtoAODPID();
+            vkink->AddDaughter(daughter);
+            daughter->ConvertAliPIDtoAODPID();
+            SetAODPID(esdTrackD,daughter,detpid);
+          }
+          else {
+            //                 cerr << "Error: event " << esd.GetEventNumberInFile() << " kink " << TMath::Abs(ikink)-1
+            //                      << " track " << idaughter << " has already been used!" << endl;
+          }
+        }
+           }
+    }      
+  }
+}
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::ConvertPrimaryVertices(const AliESDEvent& esd)
+{
+  AliCodeTimerAuto("",0);
+  
+  // Access to the AOD container of vertices
+  fNumberOfVertices = 0;
+  
+  Double_t pos[3] = { 0. };
+  Double_t covVtx[6] = { 0. };
+
+  // Add primary vertex. The primary tracks will be defined
+  // after the loops on the composite objects (V0, cascades, kinks)
+  const AliESDVertex *vtx = esd.GetPrimaryVertex();
+  
+  vtx->GetXYZ(pos); // position
+  vtx->GetCovMatrix(covVtx); //covariance matrix
+  
+  fPrimaryVertex = new(Vertices()[fNumberOfVertices++])
+  AliAODVertex(pos, covVtx, vtx->GetChi2toNDF(), NULL, -1, AliAODVertex::kPrimary);
+  fPrimaryVertex->SetName(vtx->GetName());
+  fPrimaryVertex->SetTitle(vtx->GetTitle());
+  
+  TString vtitle = vtx->GetTitle();
+  if (!vtitle.Contains("VertexerTracks")) 
+    fPrimaryVertex->SetNContributors(vtx->GetNContributors());
+  
+  if (fDebug > 0) fPrimaryVertex->Print();  
+  
+  // Add SPD "main" vertex 
+  const AliESDVertex *vtxS = esd.GetPrimaryVertexSPD();
+  vtxS->GetXYZ(pos); // position
+  vtxS->GetCovMatrix(covVtx); //covariance matrix
+  AliAODVertex * mVSPD = new(Vertices()[fNumberOfVertices++])
+  AliAODVertex(pos, covVtx, vtxS->GetChi2toNDF(), NULL, -1, AliAODVertex::kMainSPD);
+  mVSPD->SetName(vtxS->GetName());
+  mVSPD->SetTitle(vtxS->GetTitle());
+  mVSPD->SetNContributors(vtxS->GetNContributors()); 
+  
+  // Add SPD pileup vertices
+  for(Int_t iV=0; iV<esd.GetNumberOfPileupVerticesSPD(); ++iV)
+  {
+    const AliESDVertex *vtxP = esd.GetPileupVertexSPD(iV);
+    vtxP->GetXYZ(pos); // position
+    vtxP->GetCovMatrix(covVtx); //covariance matrix
+    AliAODVertex * pVSPD =  new(Vertices()[fNumberOfVertices++])
+    AliAODVertex(pos, covVtx, vtxP->GetChi2toNDF(), NULL, -1, AliAODVertex::kPileupSPD);
+    pVSPD->SetName(vtxP->GetName());
+    pVSPD->SetTitle(vtxP->GetTitle());
+    pVSPD->SetNContributors(vtxP->GetNContributors()); 
+    pVSPD->SetBC(vtxP->GetBC());
+  }
+  
+  // Add TRK pileup vertices
+  for(Int_t iV=0; iV<esd.GetNumberOfPileupVerticesTracks(); ++iV)
+  {
+    const AliESDVertex *vtxP = esd.GetPileupVertexTracks(iV);
+    vtxP->GetXYZ(pos); // position
+    vtxP->GetCovMatrix(covVtx); //covariance matrix
+    AliAODVertex * pVTRK = new(Vertices()[fNumberOfVertices++])
+    AliAODVertex(pos, covVtx, vtxP->GetChi2toNDF(), NULL, -1, AliAODVertex::kPileupTracks);
+    pVTRK->SetName(vtxP->GetName());
+    pVTRK->SetTitle(vtxP->GetTitle());
+    pVTRK->SetNContributors(vtxP->GetNContributors());
+    pVTRK->SetBC(vtxP->GetBC());
+  }
+}
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::ConvertVZERO(const AliESDEvent& esd)
+{
+  // Convert VZERO data
+  AliAODVZERO* vzeroData = AODEvent()->GetVZEROData();
+  *vzeroData = *(esd.GetVZEROData());
+}
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::ConvertTZERO(const AliESDEvent& esd)
+{
+  // Convert TZERO data
+  const AliESDTZERO* esdTzero = esd.GetESDTZERO(); 
+  AliAODTZERO* aodTzero = AODEvent()->GetTZEROData();
+
+  for (Int_t icase=0; icase<3; icase++){ 
+    aodTzero->SetT0TOF(    icase, esdTzero->GetT0TOF(icase));
+    aodTzero->SetT0TOFbest(icase, esdTzero->GetT0TOFbest(icase)); 
+  }
+  aodTzero->SetBackgroundFlag(esdTzero->GetBackgroundFlag());
+  aodTzero->SetPileupFlag(esdTzero->GetPileupFlag());
+  aodTzero->SetSatelliteFlag(esdTzero->GetSatellite()); 
+
+  Float_t rawTime[24];
+  for(Int_t ipmt=0; ipmt<24; ipmt++)
+    rawTime[ipmt] = esdTzero->GetTimeFull(ipmt,0);
+   
+  Int_t idxOfFirstPmtA = -1,       idxOfFirstPmtC = -1;
+  Float_t timeOfFirstPmtA = 9999, timeOfFirstPmtC = 9999;
+  for(int ipmt=0;  ipmt<12; ipmt++){
+    if( rawTime[ipmt] > -200 && rawTime[ipmt] < timeOfFirstPmtC && rawTime[ipmt]!=0){
+      timeOfFirstPmtC = rawTime[ipmt];
+      idxOfFirstPmtC  = ipmt;
+    }
+  }
+  for(int ipmt=12; ipmt<24; ipmt++){
+    if( rawTime[ipmt] > -200 && rawTime[ipmt] < timeOfFirstPmtA && rawTime[ipmt]!=0 ){
+      timeOfFirstPmtA = rawTime[ipmt];
+      idxOfFirstPmtA  = ipmt;
+    }
+  }
+
+  if(idxOfFirstPmtA != -1 && idxOfFirstPmtC != -1){
+    //speed of light in cm/ns   TMath::C()*1e-7 
+    Float_t vertexraw = TMath::C()*1e-7 * (rawTime[idxOfFirstPmtA] - rawTime[idxOfFirstPmtC])/2;
+    aodTzero->SetT0VertexRaw( vertexraw );
+  }else{
+    aodTzero->SetT0VertexRaw(99999);
+  }
+
+}
+
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::ConvertZDC(const AliESDEvent& esd)
+{
+  // Convert ZDC data
+  AliESDZDC* esdZDC = esd.GetZDCData();
+  
+  const Double_t zem1Energy = esdZDC->GetZEM1Energy();
+  const Double_t zem2Energy = esdZDC->GetZEM2Energy();
+   
+  const Double_t *towZNC = esdZDC->GetZNCTowerEnergy();
+  const Double_t *towZPC = esdZDC->GetZPCTowerEnergy();
+  const Double_t *towZNA = esdZDC->GetZNATowerEnergy();
+  const Double_t *towZPA = esdZDC->GetZPATowerEnergy();
+  const Double_t *towZNCLG = esdZDC->GetZNCTowerEnergyLR();
+  const Double_t *towZNALG = esdZDC->GetZNATowerEnergyLR();
+  
+  AliAODZDC* zdcAOD = AODEvent()->GetZDCData();
+
+  zdcAOD->SetZEM1Energy(zem1Energy);
+  zdcAOD->SetZEM2Energy(zem2Energy);
+  zdcAOD->SetZNCTowers(towZNC, towZNCLG);
+  zdcAOD->SetZNATowers(towZNA, towZNALG);
+  zdcAOD->SetZPCTowers(towZPC);
+  zdcAOD->SetZPATowers(towZPA);
+  
+  zdcAOD->SetZDCParticipants(esdZDC->GetZDCParticipants(), esdZDC->GetZDCPartSideA(), esdZDC->GetZDCPartSideC());
+  zdcAOD->SetZDCImpactParameter(esdZDC->GetImpactParameter(), esdZDC->GetImpactParamSideA(), 
+       esdZDC->GetImpactParamSideC());
+  zdcAOD->SetZDCTDCSum(esdZDC->GetZNTDCSum(0));        
+  zdcAOD->SetZDCTDCDiff(esdZDC->GetZNTDCDiff(0));      
+
+}
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::ConvertESDtoAOD() 
+{
+  // ESD Filter analysis task executed for each event
+  
+  AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
+  
+  if(!esd)return;
+
+  AliCodeTimerAuto("",0);
+  
+  fOldESDformat = ( esd->GetAliESDOld() != 0x0 );
+      // Reconstruct cascades and V0 here
+  if (fIsV0CascadeRecoEnabled) {
+    esd->ResetCascades();
+    esd->ResetV0s();
+
+    AliV0vertexer lV0vtxer;
+    AliCascadeVertexer lCascVtxer;
+
+    lV0vtxer.SetCuts(fV0Cuts);
+    lCascVtxer.SetCuts(fCascadeCuts);
+
+
+    lV0vtxer.Tracks2V0vertices(esd);
+    lCascVtxer.V0sTracks2CascadeVertices(esd);
+  }
+
+  fNumberOfTracks = 0;
+  fNumberOfPositiveTracks = 0;
+  fNumberOfV0s = 0;
+  fNumberOfVertices = 0;
+  fNumberOfCascades = 0;
+  fNumberOfKinks = 0;
+    
+  AliAODHeader* header = ConvertHeader(*esd);
+
+  if ( fIsVZEROEnabled ) ConvertVZERO(*esd);
+  if ( fIsTZEROEnabled ) ConvertTZERO(*esd);
+  
+  // Fetch Stack for debuggging if available 
+  fMChandler=0x0;
+  if(MCEvent())
+  {
+    fMChandler = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()); 
+  }
+  
+  // loop over events and fill them
+  // Multiplicity information needed by the header (to be revised!)
+  Int_t nTracks    = esd->GetNumberOfTracks();
+  for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) esd->GetTrack(iTrack)->SetESDEvent(esd);
+
+  // Update the header
+
+  Int_t nV0s      = esd->GetNumberOfV0s();
+  Int_t nCascades = esd->GetNumberOfCascades();
+  Int_t nKinks    = esd->GetNumberOfKinks();
+  Int_t nVertices = nV0s + nCascades /*V0 wihtin cascade already counted*/+ nKinks + 1 /* = prim. vtx*/;
+  Int_t nPileSPDVertices=1+esd->GetNumberOfPileupVerticesSPD(); // also SPD main vertex
+  Int_t nPileTrkVertices=esd->GetNumberOfPileupVerticesTracks();
+  nVertices+=nPileSPDVertices;
+  nVertices+=nPileTrkVertices;
+  Int_t nJets     = 0;
+  Int_t nCaloClus = esd->GetNumberOfCaloClusters();
+  Int_t nFmdClus  = 0;
+  Int_t nPmdClus  = esd->GetNumberOfPmdTracks();
+    
+  AliDebug(1,Form("   NV0=%d  NCASCADES=%d  NKINKS=%d", nV0s, nCascades, nKinks));
+       
+  AODEvent()->ResetStd(nTracks, nVertices, nV0s, nCascades, nJets, nCaloClus, nFmdClus, nPmdClus);
+
+  if (nV0s > 0) 
+  {
+    // RefArray to store a mapping between esd V0 number and newly created AOD-Vertex V0
+    fAODV0VtxRefs = new TRefArray(nV0s);
+    // RefArray to store the mapping between esd V0 number and newly created AOD-V0
+    fAODV0Refs = new TRefArray(nV0s); 
+    // Array to take into account the V0s already added to the AOD (V0 within cascades)
+    fUsedV0 = new Bool_t[nV0s];
+    for (Int_t iV0=0; iV0<nV0s; ++iV0) fUsedV0[iV0]=kFALSE;
+  }
+  
+  if (nTracks>0) 
+  {
+    // RefArray to store the mapping between esd track number and newly created AOD-Track
+    
+    fAODTrackRefs = new TRefArray(nTracks);
+
+    // Array to take into account the tracks already added to the AOD    
+    fUsedTrack = new Bool_t[nTracks];
+    for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) fUsedTrack[iTrack]=kFALSE;
+  }
+  
+  // Array to take into account the kinks already added to the AOD
+  if (nKinks>0) 
+  {
+    fUsedKink = new Bool_t[nKinks];
+    for (Int_t iKink=0; iKink<nKinks; ++iKink) fUsedKink[iKink]=kFALSE;
+  }
+    
+  ConvertPrimaryVertices(*esd);
+
+  //setting best TOF PID
+  AliESDInputHandler* esdH = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
+  if (esdH)
+      fESDpid = esdH->GetESDpid();
+
+  if (fIsPidOwner && fESDpid){
+    delete fESDpid;
+    fESDpid = 0;
+  }
+  if(!fESDpid)
+  { //in case of no Tender attached 
+    fESDpid = new AliESDpid;
+    fIsPidOwner = kTRUE;
+  }
+  
+  if(!esd->GetTOFHeader())
+  { //protection in case the pass2 LHC10b,c,d have been processed without tender. 
+    Float_t t0spread[10];
+    Float_t intrinsicTOFres=100; //ps ok for LHC10b,c,d pass2!! 
+    for (Int_t i=0; i<10; i++) t0spread[i] = (TMath::Sqrt(esd->GetSigma2DiamondZ()))/0.03; //0.03 to convert from cm to ps
+    fESDpid->GetTOFResponse().SetT0resolution(t0spread);
+    fESDpid->GetTOFResponse().SetTimeResolution(intrinsicTOFres);
+      //    fESDpid->SetTOFResponse(esd, (AliESDpid::EStartTimeType_t)fTimeZeroType);    
+    AliTOFHeader tmpTOFHeader(0,t0spread[0],0,NULL,NULL,NULL,intrinsicTOFres,t0spread[0]);   
+    AODEvent()->SetTOFHeader(&tmpTOFHeader);         // write dummy TOF header in AOD
+  } else {
+    AODEvent()->SetTOFHeader(esd->GetTOFHeader());    // write TOF header in AOD
+  }
+  
+  //  if(esd->GetTOFHeader() && fIsPidOwner) fESDpid->SetTOFResponse(esd, (AliESDpid::EStartTimeType_t)fTimeZeroType); //in case of AOD production strating form LHC10e without Tender. 
+  
+  if ( fAreCascadesEnabled ) ConvertCascades(*esd);
+
+  if ( fAreV0sEnabled ) ConvertV0s(*esd);
+  
+  if ( fAreKinksEnabled ) ConvertKinks(*esd);
+  
+  if ( fAreTracksEnabled ) ConvertTracks(*esd);
+  
+  // Update number of AOD tracks in header at the end of track loop (M.G.)
+  header->SetRefMultiplicity(fNumberOfTracks);
+  header->SetRefMultiplicityPos(fNumberOfPositiveTracks);
+  header->SetRefMultiplicityNeg(fNumberOfTracks - fNumberOfPositiveTracks);
+
+  if ( fTPCConstrainedFilterMask ) ConvertTPCOnlyTracks(*esd);
+  if( fGlobalConstrainedFilterMask) ConvertGlobalConstrainedTracks(*esd);  
+
+  if ( fArePmdClustersEnabled ) ConvertPmdClusters(*esd);
+  
+  if ( fAreCaloClustersEnabled ) ConvertCaloClusters(*esd);
+  
+  if ( fAreEMCALCellsEnabled )ConvertEMCALCells(*esd);
+  
+  if ( fArePHOSCellsEnabled )ConvertPHOSCells(*esd);
+       
+       if ( fAreEMCALTriggerEnabled )ConvertCaloTrigger(TString("EMCAL"), *esd);
+
+       if ( fArePHOSTriggerEnabled )ConvertCaloTrigger(TString("PHOS"), *esd);
+  
+  if ( fAreTrackletsEnabled ) ConvertTracklets(*esd);
+  if ( fIsZDCEnabled ) ConvertZDC(*esd);
+  
+  delete fAODTrackRefs; fAODTrackRefs=0x0;
+  delete fAODV0VtxRefs; fAODV0VtxRefs=0x0;
+  delete fAODV0Refs; fAODV0Refs=0x0;
+  
+  delete[] fUsedTrack; fUsedTrack=0x0;
+  delete[] fUsedV0; fUsedV0=0x0;
+  delete[] fUsedKink; fUsedKink=0x0;
+
+  if ( fIsPidOwner){
+    delete fESDpid;
+    fESDpid = 0x0;
+  }
+
+
+}
+
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::SetAODPID(AliESDtrack *esdtrack, AliAODTrack *aodtrack, AliAODPid *detpid)
+{
+  //
+  // Setter for the raw PID detector signals
+  //
+
+  // Save PID object for candidate electrons
+    Bool_t pidSave = kFALSE;
+    if (fTrackFilter) {
+       Bool_t selectInfo = fTrackFilter->IsSelected((char*) "Electrons");
+       if (selectInfo)  pidSave = kTRUE;
+    }
+
+
+    // Tracks passing pt cut 
+    if(esdtrack->Pt()>fHighPthreshold) {
+       pidSave = kTRUE;
+    } else {
+       if(fPtshape){
+           if(esdtrack->Pt()> fPtshape->GetXmin()){
+               Double_t y = fPtshape->Eval(esdtrack->Pt())/fPtshape->Eval(fHighPthreshold);
+               if(gRandom->Rndm(0)<1./y){
+                   pidSave = kTRUE;
+               }//end rndm
+           }//end if p < pmin
+       }//end if p function
+    }// end else
+
+    if (pidSave) {
+      if(!aodtrack->GetDetPid()){// prevent memory leak when calling SetAODPID twice for the same track
+       detpid = new AliAODPid();
+       SetDetectorRawSignals(detpid,esdtrack);
+       aodtrack->SetDetPID(detpid);
+      }
+    }
+}
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::SetDetectorRawSignals(AliAODPid *aodpid, AliESDtrack *track)
+{
+//
+//assignment of the detector signals (AliXXXesdPID inspired)
+//
+ if(!track){
+ AliInfo("no ESD track found. .....exiting");
+ return;
+ }
+ // TPC momentum
+ const AliExternalTrackParam *in=track->GetInnerParam();
+ if (in) {
+   aodpid->SetTPCmomentum(in->GetP());
+ }else{
+   aodpid->SetTPCmomentum(-1.);
+ }
+
+
+ aodpid->SetITSsignal(track->GetITSsignal());
+ Double_t itsdedx[4]; // dE/dx samples for individual ITS layers
+ track->GetITSdEdxSamples(itsdedx);
+ aodpid->SetITSdEdxSamples(itsdedx);
+
+ aodpid->SetTPCsignal(track->GetTPCsignal());
+ aodpid->SetTPCsignalN(track->GetTPCsignalN());
+ if(track->GetTPCdEdxInfo()) aodpid->SetTPCdEdxInfo(track->GetTPCdEdxInfo());
+
+ //n TRD planes = 6
+ Int_t nslices = track->GetNumberOfTRDslices()*6;
+ TArrayD trdslices(nslices);
+ for(Int_t iSl =0; iSl < track->GetNumberOfTRDslices(); iSl++) {
+   for(Int_t iPl =0; iPl<6; iPl++) trdslices[iPl*track->GetNumberOfTRDslices()+iSl] = track->GetTRDslice(iPl,iSl);
+ }
+//TRD momentum
+ for(Int_t iPl=0;iPl<6;iPl++){
+   Double_t trdmom=track->GetTRDmomentum(iPl);
+   aodpid->SetTRDmomentum(iPl,trdmom);
+ }
+
+ aodpid->SetTRDsignal(track->GetNumberOfTRDslices()*6,trdslices.GetArray());
+
+ //TRD clusters and tracklets
+ aodpid->SetTRDncls(track->GetTRDncls());
+ aodpid->SetTRDntrackletsPID(track->GetTRDntrackletsPID());
+ //TOF PID  
+ Double_t times[AliAODPid::kSPECIES]; track->GetIntegratedTimes(times);
+ aodpid->SetIntegratedTimes(times);
+
+   //  Float_t tzeroTrack = fESDpid->GetTOFResponse().GetStartTime(track->P());
    //  aodpid->SetTOFsignal(track->GetTOFsignal()-tzeroTrack);
    aodpid->SetTOFsignal(track->GetTOFsignal());
-  \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
+  
+  Double_t tofRes[5];
+  for (Int_t iMass=0; iMass<5; iMass++){
+    //    tofRes[iMass]=(Double_t)fESDpid->GetTOFResponse().GetExpectedSigma(track->P(), times[iMass], AliPID::ParticleMass(iMass));
     tofRes[iMass]=0; //backward compatibility
-  }\r
-  aodpid->SetTOFpidResolution(tofRes);\r
-\r
-  aodpid->SetHMPIDsignal(track->GetHMPIDsignal());\r
-\r
-}\r
-\r
-Double_t  AliAnalysisTaskESDfilter::Chi2perNDF(AliESDtrack* track)\r
-{\r
-    // Calculate chi2 per ndf for track\r
-    Int_t  nClustersTPC = track->GetTPCNcls();\r
-\r
-    if ( nClustersTPC > 5) {\r
-       return (track->GetTPCchi2()/Float_t(nClustersTPC - 5));\r
-    } else {\r
-       return (-1.);\r
-    }\r
- }\r
-\r
-\r
-//______________________________________________________________________________\r
-void AliAnalysisTaskESDfilter::Terminate(Option_t */*option*/)\r
-{\r
-// Terminate analysis\r
-//\r
-    if (fDebug > 1) printf("AnalysisESDfilter: Terminate() \n");\r
-}\r
-\r
-//______________________________________________________________________________\r
-void  AliAnalysisTaskESDfilter::PrintMCInfo(AliStack *pStack,Int_t label){\r
-// Print MC info\r
-  if(!pStack)return;\r
-  label = TMath::Abs(label);\r
-  TParticle *part = pStack->Particle(label);\r
-  Printf("########################");\r
-  Printf("%s:%d %d UniqueID %d PDG %d P %3.3f",(char*)__FILE__,__LINE__,label,part->GetUniqueID(),part->GetPdgCode(),part->P());\r
-  part->Print();\r
-  TParticle* mother = part;\r
-  Int_t imo = part->GetFirstMother();\r
-  Int_t nprim = pStack->GetNprimary();\r
-  //  while((imo >= nprim) && (mother->GetUniqueID() == 4)) {\r
-  while((imo >= nprim)) {\r
-    mother =  pStack->Particle(imo);\r
-    Printf("Mother %s:%d Label %d UniqueID %d PDG %d P %3.3f",(char*)__FILE__,__LINE__,imo,mother->GetUniqueID(),mother->GetPdgCode(),mother->P());\r
-    mother->Print();\r
-    imo =  mother->GetFirstMother();\r
-  }\r
-  Printf("########################");\r
-}\r
-\r
-//______________________________________________________\r
-\r
+  }
+  aodpid->SetTOFpidResolution(tofRes);
+
+  aodpid->SetHMPIDsignal(track->GetHMPIDsignal());
+
+}
+
+Double_t  AliAnalysisTaskESDfilter::Chi2perNDF(AliESDtrack* track)
+{
+    // Calculate chi2 per ndf for track
+    Int_t  nClustersTPC = track->GetTPCNcls();
+
+    if ( nClustersTPC > 5) {
+       return (track->GetTPCchi2()/Float_t(nClustersTPC - 5));
+    } else {
+       return (-1.);
+    }
+ }
+
+
+//______________________________________________________________________________
+void AliAnalysisTaskESDfilter::Terminate(Option_t */*option*/)
+{
+// Terminate analysis
+//
+    if (fDebug > 1) printf("AnalysisESDfilter: Terminate() \n");
+}
+
+//______________________________________________________________________________
+void  AliAnalysisTaskESDfilter::PrintMCInfo(AliStack *pStack,Int_t label){
+// Print MC info
+  if(!pStack)return;
+  label = TMath::Abs(label);
+  TParticle *part = pStack->Particle(label);
+  Printf("########################");
+  Printf("%s:%d %d UniqueID %d PDG %d P %3.3f",(char*)__FILE__,__LINE__,label,part->GetUniqueID(),part->GetPdgCode(),part->P());
+  part->Print();
+  TParticle* mother = part;
+  Int_t imo = part->GetFirstMother();
+  Int_t nprim = pStack->GetNprimary();
+  //  while((imo >= nprim) && (mother->GetUniqueID() == 4)) {
+  while((imo >= nprim)) {
+    mother =  pStack->Particle(imo);
+    Printf("Mother %s:%d Label %d UniqueID %d PDG %d P %3.3f",(char*)__FILE__,__LINE__,imo,mother->GetUniqueID(),mother->GetPdgCode(),mother->P());
+    mother->Print();
+    imo =  mother->GetFirstMother();
+  }
+  Printf("########################");
+}
+
+//______________________________________________________
+
index 50c86ef..48c4b96 100644 (file)
@@ -35,6 +35,9 @@
 #include "AliLog.h"
 
 
+using std::cout;
+using std::endl;
+using std::ofstream;
 ClassImp(AliAnalysisTaskTagCreator)
 
 ////////////////////////////////////////////////////////////////////////
index 976f546..9ba565f 100644 (file)
@@ -62,6 +62,8 @@
 #include "AliVTrack.h"
 #include "AliEventplane.h"
 
+using std::cout;
+using std::endl;
 ClassImp(AliEPSelectionTask)
 
 //________________________________________________________________________
index 87e5dfd..20ae2f1 100644 (file)
@@ -1,5 +1,7 @@
 #include "AliEventPoolManager.h"
 
+using std::cout;
+using std::endl;
 ClassImp(AliEventPool)
 
 void AliEventPool::PrintInfo() const
index 6fa2f54..0eb7f66 100644 (file)
@@ -22,6 +22,8 @@
 //
 // Authors: A. Adare and C. Loizides
 
+using std::deque;
+
 class AliEventPool : public TObject
 {
  public:
index 1f4b5cf..bf34a9e 100644 (file)
 #include "AliFileMerger.h"
 #include "AliLog.h"
 
+using std::cerr;
+using std::endl;
+using std::cout;
+using std::ifstream;
 ClassImp(AliFileMerger)
 
 ProcInfo_t procInfo;//TMP
index 48e22eb..2f8da1d 100644 (file)
 #include "AliOADBFillingScheme.h"
 #include "AliOADBTriggerAnalysis.h"
 
+using std::cout;
+using std::endl;
 ClassImp(AliPhysicsSelection)
 
 AliPhysicsSelection::AliPhysicsSelection() :
index 50732ab..60cd826 100644 (file)
@@ -22,6 +22,7 @@ class TMap;
 class TIter;
 class TEntryList;
 
+using std::ofstream;
 //___________________________________________________________________________
 class AliXMLCollection : public TGridCollection {
  
index 0c46170..ea40eaf 100644 (file)
@@ -42,7 +42,8 @@ class AliEMCAL;
 class AliEMCALGeometry;
 class AliEveEMCALSModule;
 
-
+using std::cout;
+using std::endl;
 ClassImp(AliEveEMCALData)
 
 //______________________________________________________________________________
index 0403722..c8f947a 100644 (file)
@@ -41,6 +41,8 @@
 // AliEveMUONData
 //
 
+using std::cout;
+using std::endl;
 ClassImp(AliEveMUONData)
 
 AliRawReader*            AliEveMUONData::fgRawReader        = 0;
index d2c1ad2..51691dc 100644 (file)
 //______________________________________________________________________________
 // Produce TEveUtil:TEveTrack from AliMUONTrack with dipole field model
 
+using std::cout;
+using std::endl;
+using std::setw;
+using std::setprecision;
 ClassImp(AliEveMUONTrack)
 
 
index b74b59c..c0aedcc 100644 (file)
@@ -26,6 +26,8 @@
 #include "AliHLTTriggerMenuItem.h"
 #include "Riostream.h"
 
+using std::cout;
+using std::endl;
 ClassImp(AliHLTTriggerMenuItem)
 
 
index 777aa23..1a76a7c 100644 (file)
@@ -34,6 +34,9 @@
 #include <TKey.h>
 #include "AliQAHistNavigator.h"
 
+using std::endl;
+using std::cout;
+using std::string;
 ClassImp(AliQAHistNavigator)
 
 //_________________________________________________________________________
index 4b9305a..6af31a5 100644 (file)
@@ -88,6 +88,8 @@
 #include "AliTPCPreprocessorOffline.h"
 #include "AliTPCCorrectionFit.h"
 
+using std::endl;
+using std::cout;
 ClassImp(AliTPCPreprocessorOffline)
 
 AliTPCPreprocessorOffline::AliTPCPreprocessorOffline():