]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - CORRFW/AliCFTrackIsPrimaryCuts.cxx
bug fix: data member of AliCFTrackIsPrimaryCuts changed from AliESD to AliESDEvent
[u/mrichter/AliRoot.git] / CORRFW / AliCFTrackIsPrimaryCuts.cxx
index 2bd2f5707f8084133ea8691d9accabe291c68e6e..89aefdbca1314ff0a1d66bf499ef447559a61b75 100644 (file)
 // ESD and AOD data.
 // It mainly consists of a IsSelected function that returns a boolean.
 // This function checks whether the considered track passes a set of cuts:
-// - distance to main vertex in units of sigma (resolution)
+// - min. and max. distance to main vertex in transverse plane (xy)
+// - min. and max. longitudinal distance to main vertex (z)
+// - min. and max. distance to main vertex as ellpise in xy - z plane
+// - all above cuts on absolute values or in units of sigma (resolution)
+// - min. and max. distance to main vertex in units of sigma (resolution)
+// - max. transverse (xy) and longitudinal (z) impact parameter resolution
 // - require that the dca calculation doesn't fail
 // - accept or not accept daughter tracks of kink decays
 //
+// By default, the distance to 'vertex calculated from tracks' is used.
+// Optionally the SPD (tracklet based) or TPC (TPC only tracks based) vertex
+// can be used.
+// Note: the distance to the TPC-vertex is already stored in the ESD,
+// the distance to the SPD-vertex has to be re-calculated by propagating each
+// track while executing this cut.
+//
 // The cut values for these cuts are set with the corresponding set functions.
 // All cut classes provided by the correction framework are supposed to be
 // added in the Analysis Framwork's class AliAnalysisFilter and applied by
 
 #include <TCanvas.h>
 #include <TDirectory.h>
-#include <TBits.h>
 #include <TH2.h>
+#include <TBits.h>
+
 #include <AliESDtrack.h>
+#include <AliESDEvent.h>
 #include <AliLog.h>
 #include "AliCFTrackIsPrimaryCuts.h"
 
@@ -49,8 +63,21 @@ ClassImp(AliCFTrackIsPrimaryCuts)
 //__________________________________________________________________________________
 AliCFTrackIsPrimaryCuts::AliCFTrackIsPrimaryCuts() :
   AliCFCutBase(),
+  fESD(0x0),
+  fUseSPDvertex(0),
+  fUseTPCvertex(0),
+  fMinDCAToVertexXY(0),
+  fMinDCAToVertexZ(0),
+  fMaxDCAToVertexXY(0),
+  fMaxDCAToVertexZ(0),
+  fDCAToVertex2D(0),
+  fAbsDCAToVertex(0),
+  fNSigmaToVertexMin(0),
   fNSigmaToVertexMax(0),
+  fSigmaDCAxy(0),
+  fSigmaDCAz(0),
   fRequireSigmaToVertex(0),
+  fAODType(AliAODTrack::kUndef),
   fAcceptKinkDaughters(0),
   fhCutStatistics(0),
   fhCutCorrelation(0),
@@ -62,25 +89,41 @@ AliCFTrackIsPrimaryCuts::AliCFTrackIsPrimaryCuts() :
   fhNBinsDcaZ(0),
   fhNBinsDcaXYnorm(0),
   fhNBinsDcaZnorm(0),
+  fhNBinsSigmaDcaXY(0),
+  fhNBinsSigmaDcaZ(0),
   fhBinLimNSigma(0x0),
   fhBinLimRequireSigma(0x0),
   fhBinLimAcceptKink(0x0),
   fhBinLimDcaXY(0x0),
   fhBinLimDcaZ(0x0),
   fhBinLimDcaXYnorm(0x0),
-  fhBinLimDcaZnorm(0x0)
+  fhBinLimDcaZnorm(0x0),
+  fhBinLimSigmaDcaXY(0x0),
+  fhBinLimSigmaDcaZ(0x0)
 {
   //
   // Default constructor
   //
-  fBitmap=new TBits(0);
   Initialise();
 }
 //__________________________________________________________________________________
 AliCFTrackIsPrimaryCuts::AliCFTrackIsPrimaryCuts(Char_t* name, Char_t* title) :
   AliCFCutBase(name,title),
+  fESD(0x0),
+  fUseSPDvertex(0),
+  fUseTPCvertex(0),
+  fMinDCAToVertexXY(0),
+  fMinDCAToVertexZ(0),
+  fMaxDCAToVertexXY(0),
+  fMaxDCAToVertexZ(0),
+  fDCAToVertex2D(0),
+  fAbsDCAToVertex(0),
+  fNSigmaToVertexMin(0),
   fNSigmaToVertexMax(0),
+  fSigmaDCAxy(0),
+  fSigmaDCAz(0),
   fRequireSigmaToVertex(0),
+  fAODType(AliAODTrack::kUndef),
   fAcceptKinkDaughters(0),
   fhCutStatistics(0),
   fhCutCorrelation(0),
@@ -92,25 +135,41 @@ AliCFTrackIsPrimaryCuts::AliCFTrackIsPrimaryCuts(Char_t* name, Char_t* title) :
   fhNBinsDcaZ(0),
   fhNBinsDcaXYnorm(0),
   fhNBinsDcaZnorm(0),
+  fhNBinsSigmaDcaXY(0),
+  fhNBinsSigmaDcaZ(0),
   fhBinLimNSigma(0x0),
   fhBinLimRequireSigma(0x0),
   fhBinLimAcceptKink(0x0),
   fhBinLimDcaXY(0x0),
   fhBinLimDcaZ(0x0),
   fhBinLimDcaXYnorm(0x0),
-  fhBinLimDcaZnorm(0x0)
+  fhBinLimDcaZnorm(0x0),
+  fhBinLimSigmaDcaXY(0x0),
+  fhBinLimSigmaDcaZ(0x0)
 {
   //
   // Constructor
   //
-  fBitmap=new TBits(0);
   Initialise();
 }
 //__________________________________________________________________________________
 AliCFTrackIsPrimaryCuts::AliCFTrackIsPrimaryCuts(const AliCFTrackIsPrimaryCuts& c) :
   AliCFCutBase(c),
+  fESD(c.fESD),
+  fUseSPDvertex(c.fUseSPDvertex),
+  fUseTPCvertex(c.fUseTPCvertex),
+  fMinDCAToVertexXY(c.fMinDCAToVertexXY),
+  fMinDCAToVertexZ(c.fMinDCAToVertexZ),
+  fMaxDCAToVertexXY(c.fMaxDCAToVertexXY),
+  fMaxDCAToVertexZ(c.fMaxDCAToVertexZ),
+  fDCAToVertex2D(c.fDCAToVertex2D),
+  fAbsDCAToVertex(c.fAbsDCAToVertex),
+  fNSigmaToVertexMin(c.fNSigmaToVertexMin),
   fNSigmaToVertexMax(c.fNSigmaToVertexMax),
+  fSigmaDCAxy(c.fSigmaDCAxy),
+  fSigmaDCAz(c.fSigmaDCAz),
   fRequireSigmaToVertex(c.fRequireSigmaToVertex),
+  fAODType(c.fAODType),
   fAcceptKinkDaughters(c.fAcceptKinkDaughters),
   fhCutStatistics(c.fhCutStatistics),
   fhCutCorrelation(c.fhCutCorrelation),
@@ -122,13 +181,17 @@ AliCFTrackIsPrimaryCuts::AliCFTrackIsPrimaryCuts(const AliCFTrackIsPrimaryCuts&
   fhNBinsDcaZ(c.fhNBinsDcaZ),
   fhNBinsDcaXYnorm(c.fhNBinsDcaXYnorm),
   fhNBinsDcaZnorm(c.fhNBinsDcaZnorm),
+  fhNBinsSigmaDcaXY(c.fhNBinsSigmaDcaXY),
+  fhNBinsSigmaDcaZ(c.fhNBinsSigmaDcaZ),
   fhBinLimNSigma(c.fhBinLimNSigma),
   fhBinLimRequireSigma(c.fhBinLimRequireSigma),
   fhBinLimAcceptKink(c.fhBinLimAcceptKink),
   fhBinLimDcaXY(c.fhBinLimDcaXY),
   fhBinLimDcaZ(c.fhBinLimDcaZ),
   fhBinLimDcaXYnorm(c.fhBinLimDcaXYnorm),
-  fhBinLimDcaZnorm(c.fhBinLimDcaZnorm)
+  fhBinLimDcaZnorm(c.fhBinLimDcaZnorm),
+  fhBinLimSigmaDcaXY(c.fhBinLimSigmaDcaXY),
+  fhBinLimSigmaDcaZ(c.fhBinLimSigmaDcaZ)
 {
   //
   // copy constructor
@@ -143,8 +206,21 @@ AliCFTrackIsPrimaryCuts& AliCFTrackIsPrimaryCuts::operator=(const AliCFTrackIsPr
   //
   if (this != &c) {
     AliCFCutBase::operator=(c) ;
+    fESD = c.fESD;
+    fUseSPDvertex = c.fUseSPDvertex;
+    fUseTPCvertex = c.fUseTPCvertex;
+    fMinDCAToVertexXY = c.fMinDCAToVertexXY;
+    fMinDCAToVertexZ = c.fMinDCAToVertexZ;
+    fMaxDCAToVertexXY = c.fMaxDCAToVertexXY;
+    fMaxDCAToVertexZ = c.fMaxDCAToVertexZ;
+    fDCAToVertex2D = c.fDCAToVertex2D;
+    fAbsDCAToVertex = c.fAbsDCAToVertex;
+    fNSigmaToVertexMin = c.fNSigmaToVertexMin ;
     fNSigmaToVertexMax = c.fNSigmaToVertexMax ;
+    fSigmaDCAxy = c.fSigmaDCAxy ;
+    fSigmaDCAz = c.fSigmaDCAz ;
     fRequireSigmaToVertex = c.fRequireSigmaToVertex ;
+    fAODType = c.fAODType ;
     fAcceptKinkDaughters = c.fAcceptKinkDaughters ;
     fhCutStatistics = c.fhCutStatistics ;
     fhCutCorrelation = c.fhCutCorrelation ;
@@ -156,6 +232,8 @@ AliCFTrackIsPrimaryCuts& AliCFTrackIsPrimaryCuts::operator=(const AliCFTrackIsPr
     fhNBinsDcaZ = c.fhNBinsDcaZ;
     fhNBinsDcaXYnorm = c.fhNBinsDcaXYnorm;
     fhNBinsDcaZnorm = c.fhNBinsDcaZnorm;
+    fhNBinsSigmaDcaXY = c.fhNBinsSigmaDcaXY;
+    fhNBinsSigmaDcaZ = c.fhNBinsSigmaDcaZ;
     fhBinLimNSigma = c.fhBinLimNSigma;
     fhBinLimRequireSigma = c.fhBinLimRequireSigma;
     fhBinLimAcceptKink = c.fhBinLimAcceptKink;
@@ -163,15 +241,16 @@ AliCFTrackIsPrimaryCuts& AliCFTrackIsPrimaryCuts::operator=(const AliCFTrackIsPr
     fhBinLimDcaZ = c.fhBinLimDcaZ;
     fhBinLimDcaXYnorm = c.fhBinLimDcaXYnorm;
     fhBinLimDcaZnorm = c.fhBinLimDcaZnorm;
-    
-    for (Int_t i=0; i<c.kNHist; i++){
-      for (Int_t j=0; j<c.kNStepQA; j++){
+    fhBinLimSigmaDcaXY = c.fhBinLimSigmaDcaXY;
+    fhBinLimSigmaDcaZ = c.fhBinLimSigmaDcaZ;
+
+    for (Int_t j=0; j<6; j++) fDCA[j] = c.fDCA[j];
+    for (Int_t j=0; j<c.kNStepQA; j++){
+      if(c.fhDcaXYvsDcaZ[j]) fhDcaXYvsDcaZ[j] = (TH2F*)c.fhDcaXYvsDcaZ[j]->Clone();
+      for (Int_t i=0; i<c.kNHist; i++){
        if(c.fhQA[i][j]) fhQA[i][j] = (TH1F*)c.fhQA[i][j]->Clone();
-       if(c.fhDcaXYvsDcaZ[j]) fhDcaXYvsDcaZ[j] = (TH2F*)c.fhDcaXYvsDcaZ[j]->Clone();
-       if(c.fhDcaXYvsDcaZnorm[j]) fhDcaXYvsDcaZnorm[j] = (TH2F*)c.fhDcaXYvsDcaZnorm[j]->Clone();
       }
     }
-
     ((AliCFTrackIsPrimaryCuts &) c).Copy(*this);
  }
   return *this;
@@ -186,22 +265,21 @@ AliCFTrackIsPrimaryCuts::~AliCFTrackIsPrimaryCuts()
   if (fhCutCorrelation)                        delete fhCutCorrelation;
 
   for (Int_t j=0; j<kNStepQA; j++){
-    for (Int_t i=0; i<kNHist; i++){
-      if(fhQA[i][j]) delete fhQA[i][j];
-    }
-    if(fhDcaXYvsDcaZ[j]) delete fhDcaXYvsDcaZ[j];
-    if(fhDcaXYvsDcaZnorm[j]) delete fhDcaXYvsDcaZnorm[j];
+    if(fhDcaXYvsDcaZ[j])       delete fhDcaXYvsDcaZ[j];
+    for (Int_t i=0; i<kNHist; i++)
+      if(fhQA[i][j])           delete fhQA[i][j];
   }
-
-  if (fBitmap) delete fBitmap;
-  
-  if(fhBinLimNSigma) delete fhBinLimNSigma;
-  if(fhBinLimRequireSigma) delete fhBinLimRequireSigma;
-  if(fhBinLimAcceptKink) delete fhBinLimAcceptKink;
-  if(fhBinLimDcaXY) delete fhBinLimDcaXY;
-  if(fhBinLimDcaZ) delete fhBinLimDcaZ;
-  if(fhBinLimDcaXYnorm) delete fhBinLimDcaXYnorm;
-  if(fhBinLimDcaZnorm) delete fhBinLimDcaZnorm;
+  if(fESD)                     delete fESD;
+  if(fBitmap)                  delete fBitmap;
+  if(fhBinLimNSigma)           delete fhBinLimNSigma;
+  if(fhBinLimRequireSigma)     delete fhBinLimRequireSigma;
+  if(fhBinLimAcceptKink)       delete fhBinLimAcceptKink;
+  if(fhBinLimDcaXY)            delete fhBinLimDcaXY;
+  if(fhBinLimDcaZ)             delete fhBinLimDcaZ;
+  if(fhBinLimDcaXYnorm)        delete fhBinLimDcaXYnorm;
+  if(fhBinLimDcaZnorm)                 delete fhBinLimDcaZnorm;
+  if(fhBinLimSigmaDcaXY)       delete fhBinLimSigmaDcaXY;
+  if(fhBinLimSigmaDcaZ)        delete fhBinLimSigmaDcaZ;
 }
 //__________________________________________________________________________________
 void AliCFTrackIsPrimaryCuts::Initialise()
@@ -209,31 +287,56 @@ void AliCFTrackIsPrimaryCuts::Initialise()
   //
   // sets everything to zero
   //
+  fUseSPDvertex = 0;
+  fUseTPCvertex = 0;
+  fMinDCAToVertexXY = 0;
+  fMinDCAToVertexZ = 0;
+  fMaxDCAToVertexXY = 0;
+  fMaxDCAToVertexZ = 0;
+  fDCAToVertex2D = 0;
+  fAbsDCAToVertex = 0;
+  fNSigmaToVertexMin = 0;
   fNSigmaToVertexMax = 0;
+  fSigmaDCAxy = 0;
+  fSigmaDCAz = 0;
   fRequireSigmaToVertex = 0;
   fAcceptKinkDaughters = 0;
-
+  fAODType = AliAODTrack::kUndef;
+
+  SetMinDCAToVertexXY();
+  SetMinDCAToVertexZ();
+  SetMaxDCAToVertexXY();
+  SetMaxDCAToVertexZ();
+  SetDCAToVertex2D();
+  SetAbsDCAToVertex();
+  SetMinNSigmaToVertex();
   SetMaxNSigmaToVertex();
+  SetMaxSigmaDCAxy();
+  SetMaxSigmaDCAz();
   SetRequireSigmaToVertex();
+  SetAcceptKinkDaughters();
+  SetAODType();
 
+  for (Int_t j=0; j<6; j++) fDCA[j] = 0.;
   for (Int_t j=0; j<kNStepQA; j++)  {
-    for (Int_t i=0; i<kNHist; i++){
-      fhQA[i][j] = 0x0;
-    }
     fhDcaXYvsDcaZ[j] = 0x0;
-    fhDcaXYvsDcaZnorm[j] = 0x0;
+    for (Int_t i=0; i<kNHist; i++)
+      fhQA[i][j] = 0x0;
   }
   fhCutStatistics = 0;
   fhCutCorrelation = 0;
-  
+  fBitmap=new TBits(0);
+
   //set default bining for QA histograms
-  SetHistogramBins(kCutNSigmaToVertex,500,0,50);
-  SetHistogramBins(kCutRequireSigmaToVertex,2,-0.5,1.5);
-  SetHistogramBins(kCutAcceptKinkDaughters,2,-0.5,1.5);
-  SetHistogramBins(kDcaXY,500,-10,10);
-  SetHistogramBins(kDcaZ,500,-10,10);
-  SetHistogramBins(kDcaXYnorm,500,-10,10);
-  SetHistogramBins(kDcaZnorm,500,-10,10);
+  SetHistogramBins(kCutNSigmaToVertex,100,0.,10.);
+  SetHistogramBins(kCutRequireSigmaToVertex,5,-0.75,1.75);
+  SetHistogramBins(kCutAcceptKinkDaughters,5,-0.75,1.75);
+  SetHistogramBins(kDcaXY,500,-10.,10.);
+  SetHistogramBins(kDcaZ,500,-10.,10.);
+  SetHistogramBins(kDcaXYnorm,500,-10.,10.);
+  SetHistogramBins(kDcaZnorm,500,-10.,10.);
+  SetHistogramBins(kSigmaDcaXY,500,-0.1,0.9);
+  SetHistogramBins(kSigmaDcaZ,500,-0.1,0.9);
 }
 //__________________________________________________________________________________
 void AliCFTrackIsPrimaryCuts::Copy(TObject &c) const
@@ -248,67 +351,90 @@ void AliCFTrackIsPrimaryCuts::Copy(TObject &c) const
   if (fhCutStatistics)  target.fhCutStatistics = (TH1F*) fhCutStatistics->Clone();
   if (fhCutCorrelation) target.fhCutCorrelation = (TH2F*) fhCutCorrelation->Clone();
 
+  for (Int_t j=0; j<6; j++) target.fDCA[j] = fDCA[j];
   for (Int_t j=0; j<kNStepQA; j++){
-    for (Int_t i=0; i<kNHist; i++){
-      if(fhQA[i][j]) target.fhQA[i][j] = (TH1F*)fhQA[i][j]->Clone();
-      
-    }
     if(fhDcaXYvsDcaZ[j]) target.fhDcaXYvsDcaZ[j] = (TH2F*)fhDcaXYvsDcaZ[j]->Clone();
-    if(fhDcaXYvsDcaZnorm[j]) target.fhDcaXYvsDcaZnorm[j] = (TH2F*)fhDcaXYvsDcaZnorm[j]->Clone();
+    for (Int_t i=0; i<kNHist; i++)
+      if(fhQA[i][j]) target.fhQA[i][j] = (TH1F*)fhQA[i][j]->Clone();
   }
-  
   TNamed::Copy(c);
 }
-//____________________________________________________________________
-Float_t AliCFTrackIsPrimaryCuts::GetSigmaToVertex(AliESDtrack* esdTrack) const
-{
+//__________________________________________________________________________________
+void AliCFTrackIsPrimaryCuts::SetEvtInfo(TObject* esd) {
   //
-  // Calculates the number of sigma to the vertex.
+  // Sets pointer to esd event information (AliESDEvent)
   //
-  Float_t b[2];
-  Float_t bRes[2];
-  Float_t bCov[3];
-  esdTrack->GetImpactParameters(b,bCov);
-  if (bCov[0]<=0 || bCov[2]<=0) {
-    AliDebug(1, "Estimated b resolution lower or equal zero!");
-    bCov[0]=0; bCov[2]=0;
+  if (!esd) {
+    AliError("Pointer to AliESDEvent !");
+    return;
   }
-  bRes[0] = TMath::Sqrt(bCov[0]);
-  bRes[1] = TMath::Sqrt(bCov[2]);
-
-  // -----------------------------------
-  // How to get to a n-sigma cut?
-  //
-  // The accumulated statistics from 0 to d is
-  //
-  // ->  Erf(d/Sqrt(2)) for a 1-dim gauss (d = n_sigma)
-  // ->  1 - Exp(-d**2) for a 2-dim gauss (d*d = dx*dx + dy*dy != n_sigma)
-  //
-  // It means that for a 2-dim gauss: n_sigma(d) = Sqrt(2)*ErfInv(1 - Exp((-x**2)/2)
-  // Can this be expressed in a different way?
-
-  if (bRes[0] == 0 || bRes[1] ==0)
-    return -1;
-
-  Float_t d = TMath::Sqrt(TMath::Power(b[0]/bRes[0],2) + TMath::Power(b[1]/bRes[1],2));
-
-  // stupid rounding problem screws up everything:
-  // if d is too big, TMath::Exp(...) gets 0, and TMath::ErfInverse(1) that should be infinite, gets 0 :(
-  if (TMath::Exp(-d * d / 2) < 1e-10)
-    return 1000;
-
-  d = TMath::ErfInverse(1 - TMath::Exp(-d * d / 2)) * TMath::Sqrt(2);
-  return d;
+  TString className(esd->ClassName());
+  if (className.CompareTo("AliESDEvent") != 0) {
+    AliError("argument must point to an AliESDEvent !");
+    return ;
+  }
+  fESD = (AliESDEvent*) esd;
 }
 //__________________________________________________________________________________
-void AliCFTrackIsPrimaryCuts::GetBitMap(TObject* obj, TBits *bitmap)  {
-  //
-  // retrieve the pointer to the bitmap
-  //
-  bitmap = SelectionBitMap(obj);
+void AliCFTrackIsPrimaryCuts::UseSPDvertex(Bool_t b) {
+  fUseSPDvertex = b;
+  if(fUseTPCvertex) fUseSPDvertex = kFALSE;
+}
+//__________________________________________________________________________________
+void AliCFTrackIsPrimaryCuts::UseTPCvertex(Bool_t b) {
+  fUseTPCvertex = b;
+  if(fUseTPCvertex) fUseSPDvertex = kFALSE;
+}
+//__________________________________________________________________________________
+void AliCFTrackIsPrimaryCuts::GetDCA(AliESDtrack* esdTrack)
+{
+  if (!esdTrack) return;
+
+  Float_t b[2] = {0.,0.};
+  Float_t bCov[3] = {0.,0.,0.};
+  if(!fUseSPDvertex && !fUseTPCvertex) esdTrack->GetImpactParameters(b,bCov);
+  if( fUseTPCvertex)                   esdTrack->GetImpactParametersTPC(b,bCov);
+
+  if( fUseSPDvertex) {
+       if (!fESD) return;
+       const AliESDVertex *vtx = fESD->GetVertex();
+       const Double_t Bz = fESD->GetMagneticField();
+       AliExternalTrackParam *cParam = 0;
+       Bool_t success = esdTrack->RelateToVertex(vtx, Bz, kVeryBig, cParam);
+       if (success) esdTrack->GetImpactParameters(b,bCov);
+  }
+
+  if (bCov[0]<=0 || bCov[2]<=0) {
+      bCov[0]=0; bCov[2]=0;
+  }
+  fDCA[0] = b[0]; // impact parameter xy
+  fDCA[1] = b[1]; // impact parameter z
+  fDCA[2] = TMath::Sqrt(bCov[0]); // resolution xy
+  fDCA[3] = TMath::Sqrt(bCov[2]); // resolution z
+
+  if (!fAbsDCAToVertex) {
+       if (fDCA[2] > 0) fDCA[0] = fDCA[0]/fDCA[2]; // normalised impact parameter xy
+       if (fDCA[3] > 0) fDCA[1] = fDCA[1]/fDCA[3]; // normalised impact parameter z
+  }
+
+  // get n_sigma
+  if(!fUseSPDvertex && !fUseTPCvertex)
+       fDCA[5] = AliESDtrackCuts::GetSigmaToVertex(esdTrack);
+
+  if(fUseTPCvertex) {
+       fDCA[5] = -1;
+       if (fDCA[2]==0 || fDCA[3]==0)
+         return;
+       fDCA[5] = 1000.;
+       Float_t d = TMath::Sqrt(TMath::Power(b[0]/fDCA[2],2) + TMath::Power(b[1]/fDCA[3],2));
+       if (TMath::Exp(-d * d / 2) < 1e-15)
+         return;
+       fDCA[5] = TMath::ErfInverse(1 - TMath::Exp(-d * d / 2)) * TMath::Sqrt(2);
+  }
+  return;
 }
 //__________________________________________________________________________________
-TBits* AliCFTrackIsPrimaryCuts::SelectionBitMap(TObject* obj)
+void AliCFTrackIsPrimaryCuts::SelectionBitMap(TObject* obj)
 {
   //
   // test if the track passes the single cuts
@@ -318,50 +444,140 @@ TBits* AliCFTrackIsPrimaryCuts::SelectionBitMap(TObject* obj)
   // bitmap stores the decision of each single cut
   for(Int_t i=0; i<kNCuts; i++)fBitmap->SetBitNumber(i,kFALSE);
 
-  // cast TObject into ESDtrack
-  AliESDtrack* esdTrack = dynamic_cast<AliESDtrack *>(obj);
-  if ( !esdTrack ) return fBitmap ;
+  // check TObject and cast into ESDtrack
+  if (!obj) return;
+  if (!obj->InheritsFrom("AliVParticle")) {
+    AliError("object must derived from AliVParticle !");
+    return;
+  }
+
+  Bool_t isESDTrack = strcmp(obj->ClassName(),"AliESDtrack") == 0 ? kTRUE : kFALSE ;
+  Bool_t isAODTrack = strcmp(obj->ClassName(),"AliAODTrack") == 0 ? kTRUE : kFALSE ;
 
+  AliESDtrack * esdTrack = 0x0 ;
+  AliAODTrack * aodTrack = 0x0 ; 
+  if (isESDTrack) esdTrack = dynamic_cast<AliESDtrack*>(obj);
+  if (isAODTrack) aodTrack = dynamic_cast<AliAODTrack*>(obj);
 
-  for(Int_t i=0; i<kNCuts; i++)fBitmap->SetBitNumber(i,kTRUE);
+  // get the track to vertex parameter for ESD track
+  if (isESDTrack) GetDCA(esdTrack);
 
-  // get the track to vertex parameter
-  Float_t nSigmaToVertex = GetSigmaToVertex(esdTrack);
+  Float_t bxy = 0, bz = 0;
+  if (isESDTrack) {
+       bxy = TMath::Abs(fDCA[0]);
+       bz  = TMath::Abs(fDCA[1]);
+ }
+  Float_t b2Dmin = 0, b2Dmax = 0;
+  if (isESDTrack) {
+    if (fMinDCAToVertexXY>0 && fMinDCAToVertexZ>0)
+       b2Dmin = fDCA[0]*fDCA[0]/fMinDCAToVertexXY/fMinDCAToVertexXY + fDCA[1]*fDCA[1]/fMinDCAToVertexZ/fMinDCAToVertexZ;
+    if (fMaxDCAToVertexXY>0 && fMaxDCAToVertexZ>0) 
+       b2Dmax = fDCA[0]*fDCA[0]/fMaxDCAToVertexXY/fMaxDCAToVertexXY + fDCA[1]*fDCA[1]/fMaxDCAToVertexZ/fMaxDCAToVertexZ;
+  }
 
   // fill the bitmap
   Int_t iCutBit = 0;
-  if (nSigmaToVertex > fNSigmaToVertexMax)
-       fBitmap->SetBitNumber(iCutBit,kFALSE);
+
+  if (isESDTrack) {
+    if (fDCAToVertex2D || (!fDCAToVertex2D && bxy >= fMinDCAToVertexXY && bxy <= fMaxDCAToVertexXY)) {
+      fBitmap->SetBitNumber(iCutBit,kTRUE);
+    }
+  }
+  else fBitmap->SetBitNumber(iCutBit,kTRUE);
+
   iCutBit++;
-  if (nSigmaToVertex<0 && fRequireSigmaToVertex)
-       fBitmap->SetBitNumber(iCutBit,kFALSE);
+
+  if (isESDTrack) {
+    if (fDCAToVertex2D || (!fDCAToVertex2D && bz  >= fMinDCAToVertexZ && bz  <= fMaxDCAToVertexZ)) {
+      fBitmap->SetBitNumber(iCutBit,kTRUE);
+    }
+  }
+  else fBitmap->SetBitNumber(iCutBit,kTRUE);
+
+  iCutBit++;
+
+  if (isESDTrack) {
+    if (!fDCAToVertex2D || (fDCAToVertex2D && b2Dmin > 1  && b2Dmax < 1)) {
+      fBitmap->SetBitNumber(iCutBit,kTRUE);
+    }
+  }
+  else fBitmap->SetBitNumber(iCutBit,kTRUE);
+
   iCutBit++;
-  if (!fAcceptKinkDaughters && esdTrack->GetKinkIndex(0)>0)
-       fBitmap->SetBitNumber(iCutBit,kFALSE);
 
-  return fBitmap;
+  if (isESDTrack) {
+    if (fDCA[5] >= fNSigmaToVertexMin && fDCA[5] <= fNSigmaToVertexMax) {
+      fBitmap->SetBitNumber(iCutBit,kTRUE);
+    }
+  }
+  else fBitmap->SetBitNumber(iCutBit,kTRUE);
+
+  iCutBit++;
+
+  if (isESDTrack) {
+    if (fDCA[2] < fSigmaDCAxy) {
+      fBitmap->SetBitNumber(iCutBit,kTRUE);
+    }
+  }
+  else fBitmap->SetBitNumber(iCutBit,kTRUE);
+
+  iCutBit++;
+
+  if (isESDTrack) {
+    if (fDCA[3] < fSigmaDCAz) {
+      fBitmap->SetBitNumber(iCutBit,kTRUE);
+    }
+  }
+  else fBitmap->SetBitNumber(iCutBit,kTRUE);
+
+  iCutBit++;
+
+  if (isESDTrack) {
+    if (!fRequireSigmaToVertex || (fDCA[5]>=0 && fRequireSigmaToVertex)) {
+      fBitmap->SetBitNumber(iCutBit,kTRUE);
+    }
+  }
+  else fBitmap->SetBitNumber(iCutBit,kTRUE);
+
+  iCutBit++;
+
+  if (esdTrack) {
+    if (fAcceptKinkDaughters || (!fAcceptKinkDaughters && esdTrack->GetKinkIndex(0)<=0)) {
+      fBitmap->SetBitNumber(iCutBit,kTRUE);
+    }
+  }
+  else fBitmap->SetBitNumber(iCutBit,kTRUE);
+  
+  iCutBit++;
+  
+  if (isAODTrack) {
+    if (fAODType==AliAODTrack::kUndef || fAODType == aodTrack->GetType()) {
+      fBitmap->SetBitNumber(iCutBit,kTRUE);
+    }
+  }
+  else fBitmap->SetBitNumber(iCutBit,kTRUE);
+  
+  return;
 }
 //__________________________________________________________________________________
 Bool_t AliCFTrackIsPrimaryCuts::IsSelected(TObject* obj) {
   //
   // loops over decisions of single cuts and returns if the track is accepted
   //
-  TBits* bitmap = SelectionBitMap(obj);
+  SelectionBitMap(obj);
 
+  if (fIsQAOn) FillHistograms(obj,0);
   Bool_t isSelected = kTRUE;
 
-  for (UInt_t icut=0; icut<bitmap->GetNbits();icut++)
-       if(!bitmap->TestBitNumber(icut)) isSelected = kFALSE;
-
-  return isSelected;
-}
-//__________________________________________________________________________________
-void AliCFTrackIsPrimaryCuts::Init() {
-  //
-  // initialises all histograms and the TList which holds the histograms
-  //
-  if(fIsQAOn)
-    DefineHistograms();
+  for (UInt_t icut=0; icut<fBitmap->GetNbits();icut++) {
+    if(!fBitmap->TestBitNumber(icut)) {
+       isSelected = kFALSE;
+       break;
+    }
+  }
+  if (!isSelected) return kFALSE ;
+  if (fIsQAOn) FillHistograms(obj,1);
+  return kTRUE;
 }
 //__________________________________________________________________________________
 void AliCFTrackIsPrimaryCuts::SetHistogramBins(Int_t index, Int_t nbins, Double_t *bins)
@@ -373,46 +589,58 @@ void AliCFTrackIsPrimaryCuts::SetHistogramBins(Int_t index, Int_t nbins, Double_
 
   switch(index){
   case kCutNSigmaToVertex:
-    fhNBinsNSigma=nbins;
+    fhNBinsNSigma=nbins+1;
     fhBinLimNSigma=new Double_t[nbins+1];
     for(Int_t i=0;i<nbins+1;i++)fhBinLimNSigma[i]=bins[i];
     break;
 
   case kCutRequireSigmaToVertex:
-    fhNBinsRequireSigma=nbins;
+    fhNBinsRequireSigma=nbins+1;
     fhBinLimRequireSigma=new Double_t[nbins+1];
     for(Int_t i=0;i<nbins+1;i++)fhBinLimRequireSigma[i]=bins[i];
     break;
 
   case kCutAcceptKinkDaughters:
-    fhNBinsAcceptKink=nbins;
+    fhNBinsAcceptKink=nbins+1;
     fhBinLimAcceptKink=new Double_t[nbins+1];
     for(Int_t i=0;i<nbins+1;i++)fhBinLimAcceptKink[i]=bins[i];
     break;
 
   case kDcaXY:
-    fhNBinsDcaXY=nbins;
+    fhNBinsDcaXY=nbins+1;
     fhBinLimDcaXY=new Double_t[nbins+1];
     for(Int_t i=0;i<nbins+1;i++)fhBinLimDcaXY[i]=bins[i];
     break;
-    
+
   case kDcaZ:
-    fhNBinsDcaZ=nbins;
+    fhNBinsDcaZ=nbins+1;
     fhBinLimDcaZ=new Double_t[nbins+1];
     for(Int_t i=0;i<nbins+1;i++)fhBinLimDcaZ[i]=bins[i];
     break;
-    
+
   case kDcaXYnorm:
-    fhNBinsDcaXYnorm=nbins;
+    fhNBinsDcaXYnorm=nbins+1;
     fhBinLimDcaXYnorm=new Double_t[nbins+1];
     for(Int_t i=0;i<nbins+1;i++)fhBinLimDcaXYnorm[i]=bins[i];
     break;
-    
+
   case kDcaZnorm:
-    fhNBinsDcaZnorm=nbins;
+    fhNBinsDcaZnorm=nbins+1;
     fhBinLimDcaZnorm=new Double_t[nbins+1];
     for(Int_t i=0;i<nbins+1;i++)fhBinLimDcaZnorm[i]=bins[i];
     break;
+
+  case kSigmaDcaXY:
+    fhNBinsSigmaDcaXY=nbins+1;
+    fhBinLimSigmaDcaXY=new Double_t[nbins+1];
+    for(Int_t i=0;i<nbins+1;i++)fhBinLimSigmaDcaXY[i]=bins[i];
+    break;
+
+  case kSigmaDcaZ:
+    fhNBinsSigmaDcaZ=nbins+1;
+    fhBinLimSigmaDcaZ=new Double_t[nbins+1];
+    for(Int_t i=0;i<nbins+1;i++)fhBinLimSigmaDcaZ[i]=bins[i];
+    break;
   }
 }
 //__________________________________________________________________________________
@@ -421,50 +649,60 @@ void AliCFTrackIsPrimaryCuts::SetHistogramBins(Int_t index, Int_t nbins, Double_
   //
   // fixed bin size
   //
-  if(!fIsQAOn) return;
-
   switch(index){
   case kCutNSigmaToVertex:
-    fhNBinsNSigma=nbins;
+    fhNBinsNSigma=nbins+1;
     fhBinLimNSigma=new Double_t[nbins+1];
     for(Int_t i=0;i<nbins+1;i++)fhBinLimNSigma[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
     break;
 
   case kCutRequireSigmaToVertex:
-    fhNBinsRequireSigma=nbins;
+    fhNBinsRequireSigma=nbins+1;
     fhBinLimRequireSigma=new Double_t[nbins+1];
     for(Int_t i=0;i<nbins+1;i++)fhBinLimRequireSigma[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
     break;
 
   case kCutAcceptKinkDaughters:
-    fhNBinsAcceptKink=nbins;
+    fhNBinsAcceptKink=nbins+1;
     fhBinLimAcceptKink=new Double_t[nbins+1];
     for(Int_t i=0;i<nbins+1;i++)fhBinLimAcceptKink[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
     break;
 
   case kDcaXY:
-    fhNBinsDcaXY=nbins;
+    fhNBinsDcaXY=nbins+1;
     fhBinLimDcaXY=new Double_t[nbins+1];
     for(Int_t i=0;i<nbins+1;i++)fhBinLimDcaXY[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
     break;
-    
+
   case kDcaZ:
-    fhNBinsDcaZ=nbins;
+    fhNBinsDcaZ=nbins+1;
     fhBinLimDcaZ=new Double_t[nbins+1];
     for(Int_t i=0;i<nbins+1;i++)fhBinLimDcaZ[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
     break;
-    
+
   case kDcaXYnorm:
-    fhNBinsDcaXYnorm=nbins;
+    fhNBinsDcaXYnorm=nbins+1;
     fhBinLimDcaXYnorm=new Double_t[nbins+1];
     for(Int_t i=0;i<nbins+1;i++)fhBinLimDcaXYnorm[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
     break;
-    
+
   case kDcaZnorm:
-    fhNBinsDcaZnorm=nbins;
+    fhNBinsDcaZnorm=nbins+1;
     fhBinLimDcaZnorm=new Double_t[nbins+1];
     for(Int_t i=0;i<nbins+1;i++)fhBinLimDcaZnorm[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
     break;
+
+  case kSigmaDcaXY:
+    fhNBinsSigmaDcaXY=nbins+1;
+    fhBinLimSigmaDcaXY=new Double_t[nbins+1];
+    for(Int_t i=0;i<nbins+1;i++)fhBinLimSigmaDcaXY[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
+    break;
+
+  case kSigmaDcaZ:
+    fhNBinsSigmaDcaZ=nbins+1;
+    fhBinLimSigmaDcaZ=new Double_t[nbins+1];
+    for(Int_t i=0;i<nbins+1;i++)fhBinLimSigmaDcaZ[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
+    break;
   }
 }
 //__________________________________________________________________________________
@@ -472,47 +710,62 @@ void AliCFTrackIsPrimaryCuts::SetHistogramBins(Int_t index, Int_t nbins, Double_
   //
   // histograms for cut variables, cut statistics and cut correlations
   //
-
   Int_t color = 2;
 
   // book cut statistics and cut correlation histograms
   fhCutStatistics = new TH1F(Form("%s_cut_statistics",GetName()), Form("%s cut statistics",GetName()), kNCuts,0.5,kNCuts+0.5);
   fhCutStatistics->SetLineWidth(2);
-  fhCutStatistics->GetXaxis()->SetBinLabel(1,"n dca");
-  fhCutStatistics->GetXaxis()->SetBinLabel(2,"require dca");
-  fhCutStatistics->GetXaxis()->SetBinLabel(3,"kink daughter");
+  fhCutStatistics->GetXaxis()->SetBinLabel(1,"dca xy");
+  fhCutStatistics->GetXaxis()->SetBinLabel(2,"dca z");
+  fhCutStatistics->GetXaxis()->SetBinLabel(3,"dca ellipse");
+  fhCutStatistics->GetXaxis()->SetBinLabel(4,"n dca");
+  fhCutStatistics->GetXaxis()->SetBinLabel(5,"sigma dca xy");
+  fhCutStatistics->GetXaxis()->SetBinLabel(6,"sigma dca z");
+  fhCutStatistics->GetXaxis()->SetBinLabel(7,"require dca");
+  fhCutStatistics->GetXaxis()->SetBinLabel(8,"kink daughter");
+  fhCutStatistics->GetXaxis()->SetBinLabel(9,"AOD type");
 
   fhCutCorrelation = new TH2F(Form("%s_cut_correlation",GetName()), Form("%s cut  correlation",GetName()), kNCuts,0.5,kNCuts+0.5,kNCuts,0.5,kNCuts+0.5);
   fhCutCorrelation->SetLineWidth(2);
-  fhCutCorrelation->GetXaxis()->SetBinLabel(1,"n dca");
-  fhCutCorrelation->GetXaxis()->SetBinLabel(2,"require dca");
-  fhCutCorrelation->GetXaxis()->SetBinLabel(3,"kink daughter");
-
-  fhCutCorrelation->GetYaxis()->SetBinLabel(1,"n dca");
-  fhCutCorrelation->GetYaxis()->SetBinLabel(2,"require dca");
-  fhCutCorrelation->GetYaxis()->SetBinLabel(3,"kink daughter");
+  fhCutCorrelation->GetXaxis()->SetBinLabel(1,"dca xy");
+  fhCutCorrelation->GetXaxis()->SetBinLabel(2,"dca z");
+  fhCutCorrelation->GetXaxis()->SetBinLabel(3,"dca ellipse");
+  fhCutCorrelation->GetXaxis()->SetBinLabel(4,"n dca");
+  fhCutCorrelation->GetXaxis()->SetBinLabel(5,"sigma dca xy");
+  fhCutCorrelation->GetXaxis()->SetBinLabel(6,"sigma dca z");
+  fhCutCorrelation->GetXaxis()->SetBinLabel(7,"require dca");
+  fhCutCorrelation->GetXaxis()->SetBinLabel(8,"kink daughter");
+  fhCutCorrelation->GetXaxis()->SetBinLabel(9,"AOD type");
+
+  fhCutCorrelation->GetYaxis()->SetBinLabel(1,"dca xy");
+  fhCutCorrelation->GetYaxis()->SetBinLabel(2,"dca z");
+  fhCutCorrelation->GetYaxis()->SetBinLabel(3,"dca ellipse");
+  fhCutCorrelation->GetYaxis()->SetBinLabel(4,"n dca");
+  fhCutCorrelation->GetYaxis()->SetBinLabel(5,"sigma dca xy");
+  fhCutCorrelation->GetYaxis()->SetBinLabel(6,"sigma dca z");
+  fhCutCorrelation->GetYaxis()->SetBinLabel(7,"require dca");
+  fhCutCorrelation->GetYaxis()->SetBinLabel(8,"kink daughter");
+  fhCutCorrelation->GetYaxis()->SetBinLabel(9,"AOD type");
 
   // book QA histograms
   Char_t str[256];
   for (Int_t i=0; i<kNStepQA; i++) {
     if (i==0) sprintf(str," ");
     else sprintf(str,"_cut");
-  
-    fhDcaXYvsDcaZ[i]            = new  TH2F(Form("%s_dcaXYvsDcaZ%s",GetName(),str),"",200,-10,10,200,-10,10);
-    fhDcaXYvsDcaZnorm[i]        = new  TH2F(Form("%s_dcaXYvsDcaZnorm%s",GetName(),str),"",200,-10,10,200,-10,10);
 
-    fhQA[kCutNSigmaToVertex][i]        = new TH1F(Form("%s_nSigmaToVertex%s",GetName(),str),"",fhNBinsNSigma,fhBinLimNSigma);
-    fhQA[kCutRequireSigmaToVertex][i] = new TH1F(Form("%s_requireSigmaToVertex%s",GetName(),str),"",fhNBinsRequireSigma,fhBinLimRequireSigma);
-    fhQA[kCutAcceptKinkDaughters][i] = new TH1F(Form("%s_acceptKinkDaughters%s",GetName(),str),"",fhNBinsAcceptKink,fhBinLimAcceptKink);
-    fhQA[kDcaXY][i]            = new TH1F(Form("%s_dcaXY%s",GetName(),str),"",fhNBinsDcaXY,fhBinLimDcaXY);
-    fhQA[kDcaZ][i]             = new TH1F(Form("%s_dcaZ%s",GetName(),str),"",fhNBinsDcaZ,fhBinLimDcaZ);
-    fhQA[kDcaXYnorm][i]                = new TH1F(Form("%s_dcaXYnorm%s",GetName(),str),"",fhNBinsDcaXYnorm,fhBinLimDcaXYnorm);
-    fhQA[kDcaZnorm][i]         = new TH1F(Form("%s_dcaZnorm%s",GetName(),str),"",fhNBinsDcaZnorm,fhBinLimDcaZnorm);
+    fhDcaXYvsDcaZ[i]            = new  TH2F(Form("%s_dcaXYvsDcaZ%s",GetName(),str),"",200,-10,10,200,-10,10);
+    fhQA[kCutNSigmaToVertex][i]        = new TH1F(Form("%s_nSigmaToVertex%s",GetName(),str),"",fhNBinsNSigma-1,fhBinLimNSigma);
+    fhQA[kCutRequireSigmaToVertex][i] = new TH1F(Form("%s_requireSigmaToVertex%s",GetName(),str),"",fhNBinsRequireSigma-1,fhBinLimRequireSigma);
+    fhQA[kCutAcceptKinkDaughters][i] = new TH1F(Form("%s_acceptKinkDaughters%s",GetName(),str),"",fhNBinsAcceptKink-1,fhBinLimAcceptKink);
+    fhQA[kDcaXY][i]            = new TH1F(Form("%s_dcaXY%s",GetName(),str),"",fhNBinsDcaXY-1,fhBinLimDcaXY);
+    fhQA[kDcaZ][i]             = new TH1F(Form("%s_dcaZ%s",GetName(),str),"",fhNBinsDcaZ-1,fhBinLimDcaZ);
+    fhQA[kDcaXYnorm][i]                = new TH1F(Form("%s_dcaXYnorm%s",GetName(),str),"",fhNBinsDcaXYnorm-1,fhBinLimDcaXYnorm);
+    fhQA[kDcaZnorm][i]         = new TH1F(Form("%s_dcaZnorm%s",GetName(),str),"",fhNBinsDcaZnorm-1,fhBinLimDcaZnorm);
+    fhQA[kSigmaDcaXY][i]       = new TH1F(Form("%s_sigmaDcaXY%s",GetName(),str),"",fhNBinsSigmaDcaXY-1,fhBinLimSigmaDcaXY);
+    fhQA[kSigmaDcaZ][i]                = new TH1F(Form("%s_sigmaDcaZ%s",GetName(),str),"",fhNBinsSigmaDcaZ-1,fhBinLimSigmaDcaZ);
 
     fhDcaXYvsDcaZ[i]->SetXTitle("impact par. d_{z}");
     fhDcaXYvsDcaZ[i]->SetYTitle("impact par. d_{xy}");
-    fhDcaXYvsDcaZnorm[i]->SetXTitle("norm. impact par. d_{z} / #sigma_{z}");
-    fhDcaXYvsDcaZnorm[i]->SetYTitle("norm. impact par. d_{xy} / #sigma_{xy}");
 
     fhQA[kCutNSigmaToVertex][i]->SetXTitle("n #sigma to vertex");
     fhQA[kCutRequireSigmaToVertex][i]->SetXTitle("require #sigma to vertex");
@@ -521,10 +774,10 @@ void AliCFTrackIsPrimaryCuts::SetHistogramBins(Int_t index, Int_t nbins, Double_
     fhQA[kDcaZ][i]->SetXTitle("impact par. d_{z}");
     fhQA[kDcaXYnorm][i]->SetXTitle("norm. impact par. d_{xy} / #sigma_{xy}");
     fhQA[kDcaZnorm][i]->SetXTitle("norm. impact par. d_{z} / #sigma_{z}");
+    fhQA[kSigmaDcaXY][i]->SetXTitle("impact par. resolution #sigma_{xy}");
+    fhQA[kSigmaDcaZ][i]->SetXTitle("impact par. resolution #sigma_{z}");
   }
-
   for(Int_t i=0; i<kNHist; i++) fhQA[i][1]->SetLineColor(color);
-
 }
 //__________________________________________________________________________________
 void AliCFTrackIsPrimaryCuts::FillHistograms(TObject* obj, Bool_t f)
@@ -532,63 +785,54 @@ void AliCFTrackIsPrimaryCuts::FillHistograms(TObject* obj, Bool_t f)
   //
   // fill the QA histograms
   //
-  if(!fIsQAOn) return;
 
-  // cast TObject into ESDtrack
-  AliESDtrack* esdTrack = dynamic_cast<AliESDtrack *>(obj);
-  if ( !esdTrack ) return;
-
-  // index = 0: fill histograms before cuts
-  // index = 1: fill histograms after cuts
-  Int_t index = -1;
-  index = ((f) ? 1 : 0);
-
-       Float_t b[2];
-       Float_t bRes[2];
-       Float_t bCov[3];
-       esdTrack->GetImpactParameters(b,bCov);
-       if (bCov[0]<=0 || bCov[2]<=0) {
-          AliDebug(1, "Estimated b resolution lower or equal zero!");
-          bCov[0]=0; bCov[2]=0;
-       }
-       bRes[0] = TMath::Sqrt(bCov[0]);
-       bRes[1] = TMath::Sqrt(bCov[2]);
+  if (!obj) return;
 
-       fhQA[kDcaZ][index]->Fill(b[1]);
-       fhQA[kDcaXY][index]->Fill(b[0]);
-       fhDcaXYvsDcaZ[index]->Fill(b[1],b[0]);
+  Bool_t isESDTrack = strcmp(obj->ClassName(),"AliESDtrack") == 0 ? kTRUE : kFALSE ;
+  Bool_t isAODTrack = strcmp(obj->ClassName(),"AliAODTrack") == 0 ? kTRUE : kFALSE ;
 
-       if (bRes[0]!=0 && bRes[1]!=0) {
-          fhQA[kDcaZnorm][index]->Fill(b[1]/bRes[1]);
-          fhQA[kDcaXYnorm][index]->Fill(b[0]/bRes[0]);
-          fhDcaXYvsDcaZnorm[index]->Fill(b[1]/bRes[1], b[0]/bRes[0]);
-       }
+  AliESDtrack * esdTrack = 0x0 ;
+  AliAODTrack * aodTrack = 0x0 ; 
+  if (isESDTrack) esdTrack = dynamic_cast<AliESDtrack*>(obj);
+  if (isAODTrack) aodTrack = dynamic_cast<AliAODTrack*>(obj);
 
-  // getting the track to vertex parameters
-  Float_t nSigmaToVertex = GetSigmaToVertex(esdTrack);
+  // f = 0: fill histograms before cuts
+  // f = 1: fill histograms after cuts
 
-  fhQA[kCutNSigmaToVertex][index]->Fill(nSigmaToVertex);
-  if (nSigmaToVertex<0 && fRequireSigmaToVertex) fhQA[kCutRequireSigmaToVertex][index]->Fill(0.);
-  if (!(nSigmaToVertex<0 && fRequireSigmaToVertex)) fhQA[kCutRequireSigmaToVertex][index]->Fill(1.);
+  // get the track to vertex parameter for ESD track
+  if (esdTrack) {
 
+    fhQA[kDcaZ][f]->Fill(fDCA[1]);
+    fhQA[kDcaXY][f]->Fill(fDCA[0]);
+    fhDcaXYvsDcaZ[f]->Fill(fDCA[1],fDCA[0]);
+    fhQA[kSigmaDcaXY][f]->Fill(fDCA[2]);
+    fhQA[kSigmaDcaZ][f]->Fill(fDCA[3]);
+// // // // // // //  delete histograms
+      fhQA[kDcaZnorm][f]->Fill(fDCA[1]);
+      fhQA[kDcaXYnorm][f]->Fill(fDCA[0]);
 
-  if (!fAcceptKinkDaughters && esdTrack->GetKinkIndex(0)>0) fhQA[kCutAcceptKinkDaughters][index]->Fill(0.);
-  if (!(!fAcceptKinkDaughters && esdTrack->GetKinkIndex(0)>0)) fhQA[kCutAcceptKinkDaughters][index]->Fill(0.);
+    fhQA[kCutNSigmaToVertex][f]->Fill(fDCA[5]);
+    if (fDCA[5]<0 && fRequireSigmaToVertex) fhQA[kCutRequireSigmaToVertex][f]->Fill(0.);
+    if (!(fDCA[5]<0 && fRequireSigmaToVertex)) fhQA[kCutRequireSigmaToVertex][f]->Fill(1.);
+
+    if (!fAcceptKinkDaughters && esdTrack->GetKinkIndex(0)>0) fhQA[kCutAcceptKinkDaughters][f]->Fill(0.);
+    if (!(!fAcceptKinkDaughters && esdTrack->GetKinkIndex(0)>0)) fhQA[kCutAcceptKinkDaughters][f]->Fill(0.);
+  }
 
   // fill cut statistics and cut correlation histograms with information from the bitmap
   if (f) return;
 
   // Get the bitmap of the single cuts
   if ( !obj ) return;
-  TBits* bitmap = SelectionBitMap(obj);
+  SelectionBitMap(obj);
 
   // Number of single cuts in this class
-  UInt_t ncuts = bitmap->GetNbits();
+  UInt_t ncuts = fBitmap->GetNbits();
   for(UInt_t bit=0; bit<ncuts;bit++) {
-    if (!bitmap->TestBitNumber(bit)) {
+    if (!fBitmap->TestBitNumber(bit)) {
        fhCutStatistics->Fill(bit+1);
        for (UInt_t bit2=bit; bit2<ncuts;bit2++) {
-         if (!bitmap->TestBitNumber(bit2)) 
+         if (!fBitmap->TestBitNumber(bit2)) 
            fhCutCorrelation->Fill(bit+1,bit2+1);
        }
     }
@@ -620,7 +864,6 @@ void AliCFTrackIsPrimaryCuts::SaveHistograms(const Char_t* dir) {
       gDirectory->cd("after_cuts");
 
     fhDcaXYvsDcaZ[j]    ->Write();
-    fhDcaXYvsDcaZnorm[j]->Write();
 
     for(Int_t i=0; i<kNHist; i++) fhQA[i][j]->Write();
 
@@ -712,8 +955,8 @@ void AliCFTrackIsPrimaryCuts::DrawHistograms()
 
   // -----
 
-  TCanvas* canvas3 = new TCanvas("Track_QA_Primary_3", "Track QA Primary 3", 800, 800);
-  canvas3->Divide(2, 2);
+  TCanvas* canvas3 = new TCanvas("Track_QA_Primary_3", "Track QA Primary 3", 800, 400);
+  canvas3->Divide(2, 1);
 
   canvas3->cd(1);
   gPad->SetRightMargin(right);
@@ -733,42 +976,42 @@ void AliCFTrackIsPrimaryCuts::DrawHistograms()
   fhQA[kDcaZnorm][0]->Draw();
   fhQA[kDcaZnorm][1]->Draw("same");
 
-  canvas3->cd(3);
-//   fhDXYvsDZ[0]->SetStats(kFALSE);
-  gPad->SetLogz();
-  gPad->SetLeftMargin(bottom);
-  gPad->SetTopMargin(0.1);
-  gPad->SetBottomMargin(bottom);
-  gPad->SetRightMargin(0.2);
-  fhDcaXYvsDcaZnorm[0]->Draw("COLZ");
-
-  canvas3->cd(4);
-//   fhDXYvsDZ[1]->SetStats(kFALSE);
-  gPad->SetLogz();
-  gPad->SetLeftMargin(bottom);
-  gPad->SetTopMargin(0.1);
-  gPad->SetBottomMargin(bottom);
-  gPad->SetRightMargin(0.2);
-  fhDcaXYvsDcaZnorm[1]->Draw("COLZ");
-
   canvas3->SaveAs(Form("%s.eps", canvas3->GetName()));
   canvas3->SaveAs(Form("%s.ps", canvas3->GetName()));
 
   // -----
 
-  TCanvas* canvas4 = new TCanvas("Track_QA_Primary_4", "Track QA Primary 4", 1200, 500);
-  canvas4->Divide(3, 1);
+  TCanvas* canvas4 = new TCanvas("Track_QA_Primary_4", "Track QA Primary 4", 1200, 800);
+  canvas4->Divide(3, 2);
 
   canvas4->cd(1);
   gPad->SetRightMargin(right);
   gPad->SetLeftMargin(left);
   gPad->SetTopMargin(top);
   gPad->SetBottomMargin(bottom);
+  fhQA[kSigmaDcaXY][0]->SetStats(kFALSE);
+  fhQA[kSigmaDcaXY][0]->Draw();
+  fhQA[kSigmaDcaXY][1]->Draw("same");
+
+  canvas4->cd(2);
+  gPad->SetRightMargin(right);
+  gPad->SetLeftMargin(left);
+  gPad->SetTopMargin(top);
+  gPad->SetBottomMargin(bottom);
+  fhQA[kSigmaDcaZ][0]->SetStats(kFALSE);
+  fhQA[kSigmaDcaZ][0]->Draw();
+  fhQA[kSigmaDcaZ][1]->Draw("same");
+
+  canvas4->cd(4);
+  gPad->SetRightMargin(right);
+  gPad->SetLeftMargin(left);
+  gPad->SetTopMargin(top);
+  gPad->SetBottomMargin(bottom);
   fhQA[kCutNSigmaToVertex][0]->SetStats(kFALSE);
   fhQA[kCutNSigmaToVertex][0]->Draw();
   fhQA[kCutNSigmaToVertex][1]->Draw("same");
 
-  canvas4->cd(2);
+  canvas4->cd(5);
   gPad->SetRightMargin(right);
   gPad->SetLeftMargin(left);
   gPad->SetTopMargin(top);
@@ -777,7 +1020,7 @@ void AliCFTrackIsPrimaryCuts::DrawHistograms()
   fhQA[kCutRequireSigmaToVertex][0]->Draw();
   fhQA[kCutRequireSigmaToVertex][1]->Draw("same");
 
-  canvas4->cd(3);
+  canvas4->cd(6);
   gPad->SetRightMargin(right);
   gPad->SetLeftMargin(left);
   gPad->SetTopMargin(top);
@@ -790,19 +1033,18 @@ void AliCFTrackIsPrimaryCuts::DrawHistograms()
   canvas4->SaveAs(Form("%s.ps", canvas4->GetName()));
 }
 //__________________________________________________________________________________
-void AliCFTrackIsPrimaryCuts::AddQAHistograms(TList *qaList) const {
+void AliCFTrackIsPrimaryCuts::AddQAHistograms(TList *qaList) {
   //
   // saves the histograms in a TList
   //
-  if(!fIsQAOn) return;
+  DefineHistograms();
 
   qaList->Add(fhCutStatistics);
   qaList->Add(fhCutCorrelation);
 
   for (Int_t j=0; j<kNStepQA; j++) {
     qaList->Add(fhDcaXYvsDcaZ[j]);
-    qaList->Add(fhDcaXYvsDcaZnorm[j]);    
     for(Int_t i=0; i<kNHist; i++)
-      qaList->Add(fhQA[i][j]);
+       qaList->Add(fhQA[i][j]);
   }
 }