bugs corrected
[u/mrichter/AliRoot.git] / PWG4 / PartCorr / AliV0Reader.cxx
index f97f2f781f44b012018e091b933031ca9d9eeafa..7e39f1f54e62eec9848712ce051ad246feccddf5 100644 (file)
-/**************************************************************************
- * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
- *                                                                        *
- * Author: Ana Marin, Kathrin Koch, Kenneth Aamodt                        *
- * Version 1.0                                                            *
- *                                                                        *
- * 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.                  *
- **************************************************************************/
-/**
- * Class for reading V0's
- */
-
-// --- ROOT system ---
-#include <TFormula.h>
-#include <TMath.h>
-
-//---- ANALYSIS system ----
-#include "AliV0Reader.h"
-#include "AliAnalysisManager.h"
-#include "AliESDInputHandler.h"
-#include "AliESDv0.h"
-#include "AliMCEvent.h"
-#include "AliKFVertex.h"
-#include <iostream>
-
-using namespace std;
-
-ClassImp(AliV0Reader)
-
-
-
-AliV0Reader::AliV0Reader() :
-  TObject(),
-  fCurrentEventGoodV0s(),
-  fPreviousEventGoodV0s(),
-  fMCStack(NULL),
-  fMCTruth(NULL),
-  fChain(NULL),
-  fESDHandler(NULL),
-  fESDEvent(NULL),
-  fHistograms(NULL),
-  fCurrentV0IndexNumber(0),
-  fCurrentV0(NULL),
-  fCurrentNegativeKFParticle(NULL),
-  fCurrentPositiveKFParticle(NULL),
-  fCurrentMotherKFCandidate(NULL),
-  fCurrentNegativeESDTrack(NULL),
-  fCurrentPositiveESDTrack(NULL),
-  fNegativeTrackLorentzVector(NULL),
-  fPositiveTrackLorentzVector(NULL),
-  fMotherCandidateLorentzVector(NULL),
-  fCurrentXValue(0),
-  fCurrentYValue(0),
-  fCurrentZValue(0),
-  fPositiveTrackPID(0),
-  fNegativeTrackPID(0),
-  fNegativeMCParticle(NULL),
-  fPositiveMCParticle(NULL),
-  fMotherMCParticle(NULL),
-  fMotherCandidateKFMass(0),
-  fMotherCandidateKFWidth(0),
-  fUseKFParticle(kTRUE),
-  fUseESDTrack(kFALSE),
-  fDoMC(kFALSE),
-  fMaxR(10000),// 100 meter(outside of ALICE)
-  fEtaCut(0.),
-  fPtCut(0.),
-  fChi2Cut(0.),
-  fPIDProbabilityCutNegativeParticle(0),
-  fPIDProbabilityCutPositiveParticle(0),
-  fXVertexCut(0.),
-  fYVertexCut(0.),
-  fZVertexCut(0.),
-  fNSigmaMass(0.),
-  fUseImprovedVertex(kFALSE)
-{
-
-}
-
-
-AliV0Reader::AliV0Reader(const AliV0Reader & original) :
-  TObject(original),
-  fCurrentEventGoodV0s(original.fCurrentEventGoodV0s),
-  fPreviousEventGoodV0s(original.fPreviousEventGoodV0s),
-  fMCStack(original.fMCStack),
-  fMCTruth(original.fMCTruth),
-  fChain(original.fChain),
-  fESDHandler(original.fESDHandler),
-  fESDEvent(original.fESDEvent),
-  fHistograms(original.fHistograms),
-  fCurrentV0IndexNumber(original.fCurrentV0IndexNumber),
-  fCurrentV0(original.fCurrentV0),
-  fCurrentNegativeKFParticle(original.fCurrentNegativeKFParticle),
-  fCurrentPositiveKFParticle(original.fCurrentPositiveKFParticle),
-  fCurrentMotherKFCandidate(original.fCurrentMotherKFCandidate),
-  fCurrentNegativeESDTrack(original.fCurrentNegativeESDTrack),
-  fCurrentPositiveESDTrack(original.fCurrentPositiveESDTrack),
-  fNegativeTrackLorentzVector(original.fNegativeTrackLorentzVector),
-  fPositiveTrackLorentzVector(original.fPositiveTrackLorentzVector),
-  fMotherCandidateLorentzVector(original.fMotherCandidateLorentzVector),
-  fCurrentXValue(original.fCurrentXValue),
-  fCurrentYValue(original.fCurrentYValue),
-  fCurrentZValue(original.fCurrentZValue),
-  fPositiveTrackPID(original.fPositiveTrackPID),
-  fNegativeTrackPID(original.fNegativeTrackPID),
-  fNegativeMCParticle(original.fNegativeMCParticle),
-  fPositiveMCParticle(original.fPositiveMCParticle),
-  fMotherMCParticle(original.fMotherMCParticle),
-  fMotherCandidateKFMass(original.fMotherCandidateKFMass),
-  fMotherCandidateKFWidth(original.fMotherCandidateKFWidth),
-  fUseKFParticle(kTRUE),
-  fUseESDTrack(kFALSE),
-  fDoMC(kFALSE),
-  fMaxR(original.fMaxR),
-  fEtaCut(original.fEtaCut),
-  fPtCut(original.fPtCut),
-  fChi2Cut(original.fChi2Cut),
-  fPIDProbabilityCutNegativeParticle(original.fPIDProbabilityCutNegativeParticle),
-  fPIDProbabilityCutPositiveParticle(original.fPIDProbabilityCutPositiveParticle),
-  fXVertexCut(original.fXVertexCut),
-  fYVertexCut(original.fYVertexCut),
-  fZVertexCut(original.fZVertexCut),
-  fNSigmaMass(original.fNSigmaMass),
-  fUseImprovedVertex(original.fUseImprovedVertex)
-{
-
-}
-
-
-AliV0Reader & AliV0Reader::operator = (const AliV0Reader & /*source*/)
-{
-  // assignment operator
-  return *this;
-}
-
-void AliV0Reader::Initialize(){
-  // Get the input handler from the manager
-  fESDHandler = (AliESDInputHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
-  if(fESDHandler == NULL){
-    //print warning here
-  }
-  
-  // Get pointer to esd event from input handler
-  fESDEvent = fESDHandler->GetEvent();
-  if(fESDEvent == NULL){
-    //print warning here
-  }
-
-  //Get pointer to MCTruth
-  fMCTruth = (AliMCEventHandler*)((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
-  if(fMCTruth == NULL){
-    //print warning here
-  }
-
-  //Get pointer to the mc stack
-  fMCStack = fMCTruth->MCEvent()->Stack();
-  if(fMCStack == NULL){
-    //print warning here
-  }
-
-  AliKFParticle::SetField(fESDEvent->GetMagneticField());
-
-}
-
-AliESDv0* AliV0Reader::GetV0(Int_t index){
-  fCurrentV0 = fESDEvent->GetV0(index);
-  UpdateV0Information();
-  return fCurrentV0;
-}
-
-
-Bool_t AliV0Reader::NextV0(){
-  Bool_t iResult=kFALSE;
-  while(fCurrentV0IndexNumber<fESDEvent->GetNumberOfV0s()){
-    fCurrentV0 = fESDEvent->GetV0(fCurrentV0IndexNumber);
-    
-   //checks if on the fly mode is set
-    if ( !fCurrentV0->GetOnFlyStatus() ){
-      fCurrentV0IndexNumber++;
-      if(fHistograms->fV0MassDebugCut1){fHistograms->fV0MassDebugCut1->Fill(GetMotherCandidateMass());}
-      continue;
-    }
-
-    if(fESDEvent->GetPrimaryVertex()->GetNContributors()<=0) {//checks if we have a vertex
-      fCurrentV0IndexNumber++;
-      if(fHistograms->fV0MassDebugCut2){fHistograms->fV0MassDebugCut2->Fill(GetMotherCandidateMass());}
-      continue;
-    }
-
-    if(CheckPIDProbability(fPIDProbabilityCutNegativeParticle,fPIDProbabilityCutPositiveParticle)==kFALSE){
-      fCurrentV0IndexNumber++;
-      if(fHistograms->fV0MassDebugCut3){fHistograms->fV0MassDebugCut3->Fill(GetMotherCandidateMass());}
-      continue;
-    }
-
-
-    fCurrentV0->GetXYZ(fCurrentXValue,fCurrentYValue,fCurrentZValue);
-    if(GetXYRadius()>fMaxR){ // cuts on distance from collision point
-      fCurrentV0IndexNumber++;
-      if(fHistograms->fV0MassDebugCut4){fHistograms->fV0MassDebugCut4->Fill(GetMotherCandidateMass());}
-      continue;
-    }
-
-    UpdateV0Information();
-        
-    if(fUseKFParticle){
-      if(fCurrentMotherKFCandidate->GetNDF()<=0){
-       fCurrentV0IndexNumber++;
-      if(fHistograms->fV0MassDebugCut5){fHistograms->fV0MassDebugCut5->Fill(GetMotherCandidateMass());}
-       continue;
-      }
-      Double_t chi2V0 = fCurrentMotherKFCandidate->GetChi2()/fCurrentMotherKFCandidate->GetNDF();
-      if(chi2V0 > fChi2Cut || chi2V0 <=0){
-       fCurrentV0IndexNumber++;
-      if(fHistograms->fV0MassDebugCut6){fHistograms->fV0MassDebugCut6->Fill(GetMotherCandidateMass());}
-       continue;
-      }
-      
-      if(TMath::Abs(fMotherCandidateLorentzVector->Eta())> fEtaCut){
-       fCurrentV0IndexNumber++;
-      if(fHistograms->fV0MassDebugCut7){fHistograms->fV0MassDebugCut7->Fill(GetMotherCandidateMass());}
-       continue;
-      }
-      
-      if(fMotherCandidateLorentzVector->Pt()<fPtCut){
-       fCurrentV0IndexNumber++;
-      if(fHistograms->fV0MassDebugCut8){fHistograms->fV0MassDebugCut8->Fill(GetMotherCandidateMass());}
-       continue;
-      }
-      
-    }
-    else if(fUseESDTrack){
-      //TODO
-    }
-
-    iResult=kTRUE;//means we have a v0 who survived all the cuts applied
-
-    fCurrentV0IndexNumber++;
-    
-    break;
-  }
-  return iResult; 
-}
-
-void AliV0Reader::UpdateV0Information(){
-    if(fCurrentNegativeKFParticle != NULL){
-      delete fCurrentNegativeKFParticle;
-      //      fCurrentNegativeKFParticle = NULL;
-    }
-    fCurrentNegativeKFParticle = new AliKFParticle(*(fCurrentV0->GetParamN()),fNegativeTrackPID);
-    
-    if(fCurrentPositiveKFParticle != NULL){
-      delete fCurrentPositiveKFParticle;
-      //      fCurrentPositiveKFParticle = NULL;
-    }
-    fCurrentPositiveKFParticle = new AliKFParticle(*(fCurrentV0->GetParamP()),fPositiveTrackPID);
-    
-    if(fCurrentMotherKFCandidate != NULL){
-      //      cout<<"fCurrentMotherKFCandidate: "<<fCurrentMotherKFCandidate<<endl;
-      delete fCurrentMotherKFCandidate;
-      //      fCurrentMotherKFCandidate = NULL;
-    }
-    fCurrentMotherKFCandidate = new AliKFParticle(*fCurrentNegativeKFParticle,*fCurrentPositiveKFParticle);
-
-    fCurrentNegativeESDTrack = fESDEvent->GetTrack(fCurrentV0->GetNindex());
-
-    fCurrentPositiveESDTrack = fESDEvent->GetTrack(fCurrentV0->GetPindex());
-
-    if(fPositiveTrackPID==-11 && fNegativeTrackPID==11){
-      fCurrentMotherKFCandidate->SetMassConstraint(0,fNSigmaMass);
-    }
-
-    if(fUseImprovedVertex == kTRUE){
-      AliKFVertex primaryVertexImproved(*GetPrimaryVertex());
-      primaryVertexImproved+=*fCurrentMotherKFCandidate;
-      fCurrentMotherKFCandidate->SetProductionVertex(primaryVertexImproved);
-    }
-
-    fCurrentMotherKFCandidate->GetMass(fMotherCandidateKFMass,fMotherCandidateKFWidth);
-
-
-    if(fNegativeTrackLorentzVector != NULL){
-      delete fNegativeTrackLorentzVector;
-    }
-    if(fUseKFParticle){
-      fNegativeTrackLorentzVector = new TLorentzVector(fCurrentNegativeKFParticle->Px(),fCurrentNegativeKFParticle->Py(),fCurrentNegativeKFParticle->Pz());
-    }
-    else if(fUseESDTrack){
-      fNegativeTrackLorentzVector = new TLorentzVector(fCurrentNegativeESDTrack->Px(),fCurrentNegativeESDTrack->Py(),fCurrentNegativeESDTrack->Pz());
-    }
-
-    if(fPositiveTrackLorentzVector != NULL){
-      delete fPositiveTrackLorentzVector;
-    }
-    if(fUseKFParticle){
-      fPositiveTrackLorentzVector = new TLorentzVector(fCurrentPositiveKFParticle->Px(),fCurrentPositiveKFParticle->Py(),fCurrentPositiveKFParticle->Pz());
-    }
-    else if(fUseESDTrack){
-      fPositiveTrackLorentzVector = new TLorentzVector(fCurrentPositiveESDTrack->Px(),fCurrentPositiveESDTrack->Py(),fCurrentPositiveESDTrack->Pz());
-    }
-
-    if(fMotherCandidateLorentzVector != NULL){
-      delete fMotherCandidateLorentzVector;
-    }
-    if(fUseKFParticle){
-      fMotherCandidateLorentzVector = new TLorentzVector(*fNegativeTrackLorentzVector + *fPositiveTrackLorentzVector);
-       // new TLorentzVector(fCurrentMotherKFCandidate->Px(),fCurrentMotherKFCandidate->Py(),fCurrentMotherKFCandidate->Pz());
-    }
-    else if(fUseESDTrack){
-      fMotherCandidateLorentzVector = new TLorentzVector(*fNegativeTrackLorentzVector + *fPositiveTrackLorentzVector);
-       // new TLorentzVector(fCurrentNegativeESDTrack->Px()+fCurrentPositiveESDTrack->Px(),fCurrentNegativeESDTrack->Py()+fCurrentPositiveESDTrack->Py(),fCurrentNegativeESDTrack->Pz()+fCurrentPositiveESDTrack->Pz());
-    }
-
-    if(fPositiveTrackPID==-11 && fNegativeTrackPID==11){
-      fMotherCandidateLorentzVector->SetXYZM(fMotherCandidateLorentzVector->Px() ,fMotherCandidateLorentzVector->Py(),fMotherCandidateLorentzVector->Pz(),0.); 
-    }
-    
-    if(fDoMC){
-      fNegativeMCParticle = fMCStack->Particle(TMath::Abs(fESDEvent->GetTrack(fCurrentV0->GetNindex())->GetLabel()));
-      fPositiveMCParticle = fMCStack->Particle(TMath::Abs(fESDEvent->GetTrack(fCurrentV0->GetPindex())->GetLabel()));
-    }
-}
-
-Bool_t AliV0Reader::HasSameMCMother(){
-  Bool_t iResult = kFALSE;
-  if(fDoMC == kTRUE){
-    if(fNegativeMCParticle != NULL && fPositiveMCParticle != NULL){
-      if(fNegativeMCParticle->GetMother(0) == fPositiveMCParticle->GetMother(0))
-       fMotherMCParticle = fMCStack->Particle(fPositiveMCParticle->GetMother(0));
-       iResult = kTRUE;
-      }
-  }
-  return iResult;
-}
-
-AliKFParticle* AliV0Reader::GetNegativeKFParticle(){
-  return fCurrentNegativeKFParticle;
-}
-
-AliKFParticle* AliV0Reader::GetPositiveKFParticle(){
-  return fCurrentPositiveKFParticle;
-}
-
-AliKFParticle* AliV0Reader::GetMotherCandidateKFCombination(){
-  return fCurrentMotherKFCandidate;
-}
-
-Bool_t AliV0Reader::CheckPIDProbability(Double_t negProbCut, Double_t posProbCut){
-  Bool_t iResult=kFALSE;
-
-  Double_t *posProbArray = new Double_t[10];
-  Double_t *negProbArray = new Double_t[10];
-  AliESDtrack* negTrack  = fESDEvent->GetTrack(fCurrentV0->GetNindex());
-  AliESDtrack* posTrack  = fESDEvent->GetTrack(fCurrentV0->GetPindex());
-  
-  negTrack->GetTPCpid(negProbArray);
-  posTrack->GetTPCpid(posProbArray);
-
-  if(negProbArray!=NULL && posProbArray!=NULL){
-    if(negProbArray[GetSpeciesIndex(-1)]>=negProbCut && posProbArray[GetSpeciesIndex(1)]>=posProbCut){
-      iResult=kTRUE;
-    }
-  }
-  delete [] posProbArray;
-  delete [] negProbArray;
-  return iResult;
-}
-
-void AliV0Reader::UpdateEventByEventData(){
-  fPreviousEventGoodV0s.clear();
-  fPreviousEventGoodV0s = fCurrentEventGoodV0s;
-  fCurrentEventGoodV0s.clear();
-  
-  fCurrentV0IndexNumber=0;
-}
-
-Double_t AliV0Reader::GetNegativeTrackPhi(){
-  Double_t offset=0;
-  if(fNegativeTrackLorentzVector->Phi()> TMath::Pi()){
-    offset = -2*TMath::Pi();
-  }
-  return fNegativeTrackLorentzVector->Phi()+offset;
-}
-
-Double_t AliV0Reader::GetPositiveTrackPhi(){
-  Double_t offset=0;
-  if(fPositiveTrackLorentzVector->Phi()> TMath::Pi()){
-    offset = -2*TMath::Pi();
-  }
-  return fPositiveTrackLorentzVector->Phi()+offset;
-}
-
-Double_t AliV0Reader::GetMotherCandidatePhi(){
-  Double_t offset=0;
-  if(fMotherCandidateLorentzVector->Phi()> TMath::Pi()){
-    offset = -2*TMath::Pi();
-  }
-  return fMotherCandidateLorentzVector->Phi()+offset;
-}
-
-Int_t AliV0Reader::GetSpeciesIndex(Int_t chargeOfTrack){
-
-  Int_t iResult = 10; // Unknown particle
-
-  if(chargeOfTrack==-1){ //negative track
-    switch(abs(fNegativeTrackPID)){
-    case 11:       //electron
-      iResult = 0;
-      break;
-    case 13:       //muon
-      iResult = 1;
-      break;
-    case 211:      //pion
-      iResult = 2;
-      break;
-    case 321:      //kaon
-      iResult = 3;
-      break;
-    case 2212:     //proton
-      iResult = 4;
-      break;
-    case 22:       //photon
-      iResult = 5;
-      break;
-    case 111:      //pi0
-      iResult = 6;
-      break;
-    case 2112:     //neutron
-      iResult = 7;
-      break;
-    case 311:      //K0
-      iResult = 8;
-      break;
-      
-      //Put in here for kSPECIES::kEleCon  ????
-    }
-  }
-  else if(chargeOfTrack==1){ //positive track
-    switch(abs(fPositiveTrackPID)){
-    case 11:       //electron
-      iResult = 0;
-      break;
-    case 13:       //muon
-      iResult = 1;
-      break;
-    case 211:      //pion
-      iResult = 2;
-      break;
-    case 321:      //kaon
-      iResult = 3;
-      break;
-    case 2212:     //proton
-      iResult = 4;
-      break;
-    case 22:       //photon
-      iResult = 5;
-      break;
-    case 111:      //pi0
-      iResult = 6;
-      break;
-    case 2112:     //neutron
-      iResult = 7;
-      break;
-    case 311:      //K0
-      iResult = 8;
-      break;
-
-      //Put in here for kSPECIES::kEleCon  ????
-    }
-  }
-  else{
-    //Wrong parameter.. Print warning
-  }
-  return iResult;
-}
+/**************************************************************************\r
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *\r
+ *                                                                        *\r
+ * Author: Ana Marin, Kathrin Koch, Kenneth Aamodt                        *\r
+ * Version 1.0                                                            *\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
+////////////////////////////////////////////////\r
+//--------------------------------------------- \r
+// Class used to do analysis on conversion pairs\r
+//---------------------------------------------\r
+////////////////////////////////////////////////\r
+\r
+// --- ROOT system ---\r
+#include <TMath.h>\r
+\r
+//---- ANALYSIS system ----\r
+#include "AliV0Reader.h"\r
+#include "AliAnalysisManager.h"\r
+#include "AliESDInputHandler.h"\r
+#include "AliMCEvent.h"\r
+#include "AliKFVertex.h"\r
+\r
+#include "AliStack.h"\r
+#include "AliMCEventHandler.h"\r
+\r
+\r
+class iostream;\r
+class AliESDv0;\r
+class TFormula;\r
+\r
+using namespace std;\r
+\r
+ClassImp(AliV0Reader)\r
+\r
+\r
+\r
+  AliV0Reader::AliV0Reader() :\r
+    TObject(),\r
+    fMCStack(NULL),\r
+    fMCTruth(NULL),\r
+    fChain(NULL),\r
+    fESDHandler(NULL),\r
+    fESDEvent(NULL),\r
+    fHistograms(NULL),\r
+    fCurrentV0IndexNumber(0),\r
+    fCurrentV0(NULL),\r
+    fCurrentNegativeKFParticle(NULL),\r
+    fCurrentPositiveKFParticle(NULL),\r
+    fCurrentMotherKFCandidate(NULL),\r
+    fCurrentNegativeESDTrack(NULL),\r
+    fCurrentPositiveESDTrack(NULL),\r
+    fNegativeTrackLorentzVector(NULL),\r
+    fPositiveTrackLorentzVector(NULL),\r
+    fMotherCandidateLorentzVector(NULL),\r
+    fCurrentXValue(0),\r
+    fCurrentYValue(0),\r
+    fCurrentZValue(0),\r
+    fPositiveTrackPID(0),\r
+    fNegativeTrackPID(0),\r
+    fNegativeMCParticle(NULL),\r
+    fPositiveMCParticle(NULL),\r
+    fMotherMCParticle(NULL),\r
+    fMotherCandidateKFMass(0),\r
+    fMotherCandidateKFWidth(0),\r
+    fUseKFParticle(kTRUE),\r
+    fUseESDTrack(kFALSE),\r
+    fDoMC(kFALSE),\r
+    fMaxR(10000),// 100 meter(outside of ALICE)\r
+    fEtaCut(0.),\r
+    fPtCut(0.),\r
+    fChi2CutConversion(0.),\r
+    fChi2CutMeson(0.),\r
+    fPIDProbabilityCutNegativeParticle(0),\r
+    fPIDProbabilityCutPositiveParticle(0),\r
+    fXVertexCut(0.),\r
+    fYVertexCut(0.),\r
+    fZVertexCut(0.),\r
+    fNSigmaMass(0.),\r
+    fUseImprovedVertex(kFALSE),\r
+    fCurrentEventGoodV0s(),\r
+    fPreviousEventGoodV0s()\r
+{\r
+\r
+}\r
+\r
+\r
+AliV0Reader::AliV0Reader(const AliV0Reader & original) :\r
+  TObject(original),\r
+  fMCStack(original.fMCStack),\r
+  fMCTruth(original.fMCTruth),\r
+  fChain(original.fChain),\r
+  fESDHandler(original.fESDHandler),\r
+  fESDEvent(original.fESDEvent),\r
+  fHistograms(original.fHistograms),\r
+  fCurrentV0IndexNumber(original.fCurrentV0IndexNumber),\r
+  fCurrentV0(original.fCurrentV0),\r
+  fCurrentNegativeKFParticle(original.fCurrentNegativeKFParticle),\r
+  fCurrentPositiveKFParticle(original.fCurrentPositiveKFParticle),\r
+  fCurrentMotherKFCandidate(original.fCurrentMotherKFCandidate),\r
+  fCurrentNegativeESDTrack(original.fCurrentNegativeESDTrack),\r
+  fCurrentPositiveESDTrack(original.fCurrentPositiveESDTrack),\r
+  fNegativeTrackLorentzVector(original.fNegativeTrackLorentzVector),\r
+  fPositiveTrackLorentzVector(original.fPositiveTrackLorentzVector),\r
+  fMotherCandidateLorentzVector(original.fMotherCandidateLorentzVector),\r
+  fCurrentXValue(original.fCurrentXValue),\r
+  fCurrentYValue(original.fCurrentYValue),\r
+  fCurrentZValue(original.fCurrentZValue),\r
+  fPositiveTrackPID(original.fPositiveTrackPID),\r
+  fNegativeTrackPID(original.fNegativeTrackPID),\r
+  fNegativeMCParticle(original.fNegativeMCParticle),\r
+  fPositiveMCParticle(original.fPositiveMCParticle),\r
+  fMotherMCParticle(original.fMotherMCParticle),\r
+  fMotherCandidateKFMass(original.fMotherCandidateKFMass),\r
+  fMotherCandidateKFWidth(original.fMotherCandidateKFWidth),\r
+  fUseKFParticle(kTRUE),\r
+  fUseESDTrack(kFALSE),\r
+  fDoMC(kFALSE),\r
+  fMaxR(original.fMaxR),\r
+  fEtaCut(original.fEtaCut),\r
+  fPtCut(original.fPtCut),\r
+  fChi2CutConversion(original.fChi2CutConversion),\r
+  fChi2CutMeson(original.fChi2CutMeson),\r
+  fPIDProbabilityCutNegativeParticle(original.fPIDProbabilityCutNegativeParticle),\r
+  fPIDProbabilityCutPositiveParticle(original.fPIDProbabilityCutPositiveParticle),\r
+  fXVertexCut(original.fXVertexCut),\r
+  fYVertexCut(original.fYVertexCut),\r
+  fZVertexCut(original.fZVertexCut),\r
+  fNSigmaMass(original.fNSigmaMass),\r
+  fUseImprovedVertex(original.fUseImprovedVertex),\r
+  fCurrentEventGoodV0s(original.fCurrentEventGoodV0s),\r
+  fPreviousEventGoodV0s(original.fPreviousEventGoodV0s)\r
+{\r
+\r
+}\r
+\r
+\r
+AliV0Reader & AliV0Reader::operator = (const AliV0Reader & /*source*/)\r
+{\r
+  // assignment operator\r
+  return *this;\r
+}\r
+\r
+void AliV0Reader::Initialize(){\r
+  //see header file for documentation\r
+\r
+  // Get the input handler from the manager\r
+  fESDHandler = (AliESDInputHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());\r
+  if(fESDHandler == NULL){\r
+    //print warning here\r
+  }\r
+  \r
+  // Get pointer to esd event from input handler\r
+  fESDEvent = fESDHandler->GetEvent();\r
+  if(fESDEvent == NULL){\r
+    //print warning here\r
+  }\r
+\r
+  //Get pointer to MCTruth\r
+  fMCTruth = (AliMCEventHandler*)((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());\r
+  if(fMCTruth == NULL){\r
+    //print warning here\r
+  }\r
+\r
+  //Get pointer to the mc stack\r
+  fMCStack = fMCTruth->MCEvent()->Stack();\r
+  if(fMCStack == NULL){\r
+    //print warning here\r
+  }\r
+\r
+  AliKFParticle::SetField(fESDEvent->GetMagneticField());\r
+\r
+}\r
+\r
+AliESDv0* AliV0Reader::GetV0(Int_t index){\r
+  //see header file for documentation\r
+\r
+  fCurrentV0 = fESDEvent->GetV0(index);\r
+  UpdateV0Information();\r
+  return fCurrentV0;\r
+}\r
+\r
+\r
+Bool_t AliV0Reader::NextV0(){\r
+  //see header file for documentation\r
+\r
+  Bool_t iResult=kFALSE;\r
+  while(fCurrentV0IndexNumber<fESDEvent->GetNumberOfV0s()){\r
+    fCurrentV0 = fESDEvent->GetV0(fCurrentV0IndexNumber);\r
+    \r
+    //checks if on the fly mode is set\r
+    if ( !fCurrentV0->GetOnFlyStatus() ){\r
+      fCurrentV0IndexNumber++;\r
+      fHistograms->FillHistogram("V0MassDebugCut1",GetMotherCandidateMass());\r
+      continue;\r
+    }\r
+\r
+    if(fESDEvent->GetPrimaryVertex()->GetNContributors()<=0) {//checks if we have a vertex\r
+      fCurrentV0IndexNumber++;\r
+      fHistograms->FillHistogram("V0MassDebugCut2",GetMotherCandidateMass());\r
+      continue;\r
+    }\r
+\r
+    if(CheckPIDProbability(fPIDProbabilityCutNegativeParticle,fPIDProbabilityCutPositiveParticle)==kFALSE){\r
+      fCurrentV0IndexNumber++;\r
+      fHistograms->FillHistogram("V0MassDebugCut3",GetMotherCandidateMass());\r
+      continue;\r
+    }\r
+\r
+\r
+    fCurrentV0->GetXYZ(fCurrentXValue,fCurrentYValue,fCurrentZValue);\r
\r
+    if(GetXYRadius()>fMaxR){ // cuts on distance from collision point\r
+      fCurrentV0IndexNumber++;\r
+      fHistograms->FillHistogram("V0MassDebugCut4",GetMotherCandidateMass());\r
+      continue;\r
+    }\r
+\r
+    UpdateV0Information();\r
+        \r
+    if(fUseKFParticle){\r
+      if(fCurrentMotherKFCandidate->GetNDF()<=0){\r
+       fCurrentV0IndexNumber++;\r
+       fHistograms->FillHistogram("V0MassDebugCut5",GetMotherCandidateMass());\r
+       continue;\r
+      }\r
+      Double_t chi2V0 = fCurrentMotherKFCandidate->GetChi2()/fCurrentMotherKFCandidate->GetNDF();\r
+      if(chi2V0 > fChi2CutConversion || chi2V0 <=0){\r
+       fCurrentV0IndexNumber++;\r
+       fHistograms->FillHistogram("V0MassDebugCut6",GetMotherCandidateMass());\r
+       continue;\r
+      }\r
+      \r
+      if(TMath::Abs(fMotherCandidateLorentzVector->Eta())> fEtaCut){\r
+       fCurrentV0IndexNumber++;\r
+       fHistograms->FillHistogram("V0MassDebugCut7",GetMotherCandidateMass());\r
+       continue;\r
+      }\r
+      \r
+      if(fMotherCandidateLorentzVector->Pt()<fPtCut){\r
+       fCurrentV0IndexNumber++;\r
+       fHistograms->FillHistogram("V0MassDebugCut8",GetMotherCandidateMass());\r
+       continue;\r
+      }\r
+      \r
+    }\r
+    else if(fUseESDTrack){\r
+      //TODO\r
+    }\r
+\r
+    iResult=kTRUE;//means we have a v0 who survived all the cuts applied\r
+\r
+    fCurrentV0IndexNumber++;\r
+    \r
+    break;\r
+  }\r
+  return iResult; \r
+}\r
+\r
+void AliV0Reader::UpdateV0Information(){\r
+  //see header file for documentation\r
+  \r
+  if(fCurrentNegativeKFParticle != NULL){\r
+    delete fCurrentNegativeKFParticle;\r
+  }\r
+  fCurrentNegativeKFParticle = new AliKFParticle(*(fCurrentV0->GetParamN()),fNegativeTrackPID);\r
+  \r
+  if(fCurrentPositiveKFParticle != NULL){\r
+    delete fCurrentPositiveKFParticle;\r
+  }\r
+  fCurrentPositiveKFParticle = new AliKFParticle(*(fCurrentV0->GetParamP()),fPositiveTrackPID);\r
+    \r
+  if(fCurrentMotherKFCandidate != NULL){\r
+    delete fCurrentMotherKFCandidate;\r
+  }\r
+  fCurrentMotherKFCandidate = new AliKFParticle(*fCurrentNegativeKFParticle,*fCurrentPositiveKFParticle);\r
+\r
+  fCurrentNegativeESDTrack = fESDEvent->GetTrack(fCurrentV0->GetNindex());\r
+\r
+  fCurrentPositiveESDTrack = fESDEvent->GetTrack(fCurrentV0->GetPindex());\r
+\r
+  if(fPositiveTrackPID==-11 && fNegativeTrackPID==11){\r
+    fCurrentMotherKFCandidate->SetMassConstraint(0,fNSigmaMass);\r
+  }\r
+\r
+  if(fUseImprovedVertex == kTRUE){\r
+    AliKFVertex primaryVertexImproved(*GetPrimaryVertex());\r
+    primaryVertexImproved+=*fCurrentMotherKFCandidate;\r
+    fCurrentMotherKFCandidate->SetProductionVertex(primaryVertexImproved);\r
+  }\r
+\r
+  fCurrentMotherKFCandidate->GetMass(fMotherCandidateKFMass,fMotherCandidateKFWidth);\r
+\r
+\r
+  if(fNegativeTrackLorentzVector != NULL){\r
+    delete fNegativeTrackLorentzVector;\r
+  }\r
+  if(fUseKFParticle){\r
+    fNegativeTrackLorentzVector = new TLorentzVector(fCurrentNegativeKFParticle->Px(),fCurrentNegativeKFParticle->Py(),fCurrentNegativeKFParticle->Pz());\r
+  }\r
+  else if(fUseESDTrack){\r
+    fNegativeTrackLorentzVector = new TLorentzVector(fCurrentNegativeESDTrack->Px(),fCurrentNegativeESDTrack->Py(),fCurrentNegativeESDTrack->Pz());\r
+  }\r
+\r
+  if(fPositiveTrackLorentzVector != NULL){\r
+    delete fPositiveTrackLorentzVector;\r
+  }\r
+  if(fUseKFParticle){\r
+    fPositiveTrackLorentzVector = new TLorentzVector(fCurrentPositiveKFParticle->Px(),fCurrentPositiveKFParticle->Py(),fCurrentPositiveKFParticle->Pz());\r
+  }\r
+  else if(fUseESDTrack){\r
+    fPositiveTrackLorentzVector = new TLorentzVector(fCurrentPositiveESDTrack->Px(),fCurrentPositiveESDTrack->Py(),fCurrentPositiveESDTrack->Pz());\r
+  }\r
+\r
+  if(fMotherCandidateLorentzVector != NULL){\r
+    delete fMotherCandidateLorentzVector;\r
+  }\r
+  if(fUseKFParticle){\r
+    fMotherCandidateLorentzVector = new TLorentzVector(*fNegativeTrackLorentzVector + *fPositiveTrackLorentzVector);\r
+  }\r
+  else if(fUseESDTrack){\r
+    fMotherCandidateLorentzVector = new TLorentzVector(*fNegativeTrackLorentzVector + *fPositiveTrackLorentzVector);\r
+  }\r
+\r
+  if(fPositiveTrackPID==-11 && fNegativeTrackPID==11){\r
+    fMotherCandidateLorentzVector->SetXYZM(fMotherCandidateLorentzVector->Px() ,fMotherCandidateLorentzVector->Py(),fMotherCandidateLorentzVector->Pz(),0.); \r
+  }\r
+    \r
+  if(fDoMC == kTRUE){\r
+    fNegativeMCParticle = fMCStack->Particle(TMath::Abs(fESDEvent->GetTrack(fCurrentV0->GetNindex())->GetLabel()));\r
+    fPositiveMCParticle = fMCStack->Particle(TMath::Abs(fESDEvent->GetTrack(fCurrentV0->GetPindex())->GetLabel()));\r
+  }\r
+  fCurrentEventGoodV0s.push_back(*fCurrentMotherKFCandidate);\r
+}\r
+\r
+Bool_t AliV0Reader::HasSameMCMother(){\r
+  //see header file for documentation\r
+\r
+  Bool_t iResult = kFALSE;\r
+  if(fDoMC == kTRUE){\r
+    if(fNegativeMCParticle != NULL && fPositiveMCParticle != NULL){\r
+      if(fNegativeMCParticle->GetMother(0) == fPositiveMCParticle->GetMother(0))\r
+       fMotherMCParticle = fMCStack->Particle(fPositiveMCParticle->GetMother(0));\r
+      iResult = kTRUE;\r
+    }\r
+  }\r
+  return iResult;\r
+}\r
+\r
+Bool_t AliV0Reader::CheckPIDProbability(Double_t negProbCut, Double_t posProbCut){\r
+  //see header file for documentation\r
+\r
+  Bool_t iResult=kFALSE;\r
+\r
+  Double_t *posProbArray = new Double_t[10];\r
+  Double_t *negProbArray = new Double_t[10];\r
+  AliESDtrack* negTrack  = fESDEvent->GetTrack(fCurrentV0->GetNindex());\r
+  AliESDtrack* posTrack  = fESDEvent->GetTrack(fCurrentV0->GetPindex());\r
+  \r
+  negTrack->GetTPCpid(negProbArray);\r
+  posTrack->GetTPCpid(posProbArray);\r
+\r
+  if(negProbArray!=NULL && posProbArray!=NULL){\r
+    if(negProbArray[GetSpeciesIndex(-1)]>=negProbCut && posProbArray[GetSpeciesIndex(1)]>=posProbCut){\r
+      iResult=kTRUE;\r
+    }\r
+  }\r
+  delete [] posProbArray;\r
+  delete [] negProbArray;\r
+  return iResult;\r
+}\r
+\r
+void AliV0Reader::UpdateEventByEventData(){\r
+  //see header file for documentation\r
+\r
+  if(fCurrentEventGoodV0s.size() >0 ){\r
+    fPreviousEventGoodV0s.clear();\r
+    fPreviousEventGoodV0s = fCurrentEventGoodV0s;\r
+  }\r
+  fCurrentEventGoodV0s.clear();\r
+  \r
+  fCurrentV0IndexNumber=0;\r
+}\r
+\r
+Double_t AliV0Reader::GetNegativeTrackPhi() const{\r
+  //see header file for documentation\r
+\r
+  Double_t offset=0;\r
+  if(fNegativeTrackLorentzVector->Phi()> TMath::Pi()){\r
+    offset = -2*TMath::Pi();\r
+  }\r
+  return fNegativeTrackLorentzVector->Phi()+offset;\r
+}\r
+\r
+Double_t AliV0Reader::GetPositiveTrackPhi() const{\r
+  //see header file for documentation\r
+\r
+  Double_t offset=0;\r
+  if(fPositiveTrackLorentzVector->Phi()> TMath::Pi()){\r
+    offset = -2*TMath::Pi();\r
+  }\r
+  return fPositiveTrackLorentzVector->Phi()+offset;\r
+}\r
+\r
+Double_t AliV0Reader::GetMotherCandidatePhi() const{\r
+  //see header file for documentation\r
+\r
+  Double_t offset=0;\r
+  if(fMotherCandidateLorentzVector->Phi()> TMath::Pi()){\r
+    offset = -2*TMath::Pi();\r
+  }\r
+  return fMotherCandidateLorentzVector->Phi()+offset;\r
+}\r
+\r
+Int_t AliV0Reader::GetSpeciesIndex(Int_t chargeOfTrack){\r
+  //see header file for documentation\r
+\r
+  Int_t iResult = 10; // Unknown particle\r
+\r
+  if(chargeOfTrack==-1){ //negative track\r
+    switch(abs(fNegativeTrackPID)){\r
+    case 11:       //electron\r
+      iResult = 0;\r
+      break;\r
+    case 13:       //muon\r
+      iResult = 1;\r
+      break;\r
+    case 211:      //pion\r
+      iResult = 2;\r
+      break;\r
+    case 321:      //kaon\r
+      iResult = 3;\r
+      break;\r
+    case 2212:     //proton\r
+      iResult = 4;\r
+      break;\r
+    case 22:       //photon\r
+      iResult = 5;\r
+      break;\r
+    case 111:      //pi0\r
+      iResult = 6;\r
+      break;\r
+    case 2112:     //neutron\r
+      iResult = 7;\r
+      break;\r
+    case 311:      //K0\r
+      iResult = 8;\r
+      break;\r
+      \r
+      //Put in here for kSPECIES::kEleCon  ????\r
+    }\r
+  }\r
+  else if(chargeOfTrack==1){ //positive track\r
+    switch(abs(fPositiveTrackPID)){\r
+    case 11:       //electron\r
+      iResult = 0;\r
+      break;\r
+    case 13:       //muon\r
+      iResult = 1;\r
+      break;\r
+    case 211:      //pion\r
+      iResult = 2;\r
+      break;\r
+    case 321:      //kaon\r
+      iResult = 3;\r
+      break;\r
+    case 2212:     //proton\r
+      iResult = 4;\r
+      break;\r
+    case 22:       //photon\r
+      iResult = 5;\r
+      break;\r
+    case 111:      //pi0\r
+      iResult = 6;\r
+      break;\r
+    case 2112:     //neutron\r
+      iResult = 7;\r
+      break;\r
+    case 311:      //K0\r
+      iResult = 8;\r
+      break;\r
+\r
+      //Put in here for kSPECIES::kEleCon  ????\r
+    }\r
+  }\r
+  else{\r
+    //Wrong parameter.. Print warning\r
+  }\r
+  return iResult;\r
+}\r