]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWGLF/STRANGENESS/Cascades/AliAnalysisTaskExtractCascade.cxx
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / PWGLF / STRANGENESS / Cascades / AliAnalysisTaskExtractCascade.cxx
index 6c8b6e7ce90837996240a3ea92b7f123adad27e4..13e3c183b79e839e6f2f48a3921f760fe838bd2c 100644 (file)
@@ -87,6 +87,7 @@ class AliAODv0;
 #include "AliAODcascade.h"
 #include "AliESDUtils.h"
 #include "AliGenEventHeader.h"
+#include "AliAnalysisUtils.h"
 
 #include "AliAnalysisTaskExtractCascade.h"
 
@@ -96,10 +97,15 @@ using std::endl;
 ClassImp(AliAnalysisTaskExtractCascade)
 
 AliAnalysisTaskExtractCascade::AliAnalysisTaskExtractCascade() 
-  : AliAnalysisTaskSE(), fListHist(0), fTreeCascade(0), fPIDResponse(0), fESDtrackCuts(0),
+  : AliAnalysisTaskSE(), fListHist(0), fTreeCascade(0), fPIDResponse(0), fESDtrackCuts(0), fUtils(0),
    fkIsNuclear   ( kFALSE ), 
    fkSwitchINT7  ( kFALSE ),
    fCentralityEstimator("V0M"),
+   fkpAVertexSelection( kFALSE ),
+   fEtaRefMult ( 0.5 ),
+   fkRunVertexers ( kFALSE ),
+   fkDebugMode (kTRUE),
+   fkSelectPeripheral (kFALSE),
 //------------------------------------------------
 // Tree Variables
 //------------------------------------------------
@@ -125,6 +131,7 @@ AliAnalysisTaskExtractCascade::AliAnalysisTaskExtractCascade()
    fTreeCascVarCascRadius(0),
    fTreeCascVarV0Mass(0),
    fTreeCascVarV0CosPointingAngle(0),
+   fTreeCascVarV0CosPointingAngleSpecial(0),
    fTreeCascVarV0Radius(0),
    fTreeCascVarLeastNbrClusters(0),
    fTreeCascVarMultiplicity(0),
@@ -137,6 +144,7 @@ AliAnalysisTaskExtractCascade::AliAnalysisTaskExtractCascade()
    fTreeCascVarPIDBachelor(0),
    fTreeCascVarPIDNegative(0),
    fTreeCascVarPIDPositive(0),
+   fTreeCascVarBachTransMom(0),
    fTreeCascVarPosTransMom(0),
    fTreeCascVarNegTransMom(0),
    fTreeCascVarPosTransMomMC(0),
@@ -148,6 +156,45 @@ AliAnalysisTaskExtractCascade::AliAnalysisTaskExtractCascade()
    fTreeCascVarBachNSigmaPion(0),
    fTreeCascVarBachNSigmaKaon(0),
 
+  fTreeCascVarkITSRefitBachelor(0),
+  fTreeCascVarkITSRefitNegative(0),
+  fTreeCascVarkITSRefitPositive(0),
+
+//Debug information
+//Part A: EbyE info, Run number
+fTreeCascVarRunNumber(0),
+fTreeCascVarEventNumber(0),
+
+//Part B: Shared Clusters
+fTreeCascVarNegClusters(0),
+fTreeCascVarPosClusters(0),
+fTreeCascVarBachClusters(0),
+fTreeCascVarNegSharedClusters(0),
+fTreeCascVarPosSharedClusters(0),
+fTreeCascVarBachSharedClusters(0),
+
+//Part C: All momenta
+fTreeCascVarNegPx(0),
+fTreeCascVarNegPy(0),
+fTreeCascVarNegPz(0),
+fTreeCascVarPosPx(0),
+fTreeCascVarPosPy(0),
+fTreeCascVarPosPz(0),
+fTreeCascVarBachPx(0),
+fTreeCascVarBachPy(0),
+fTreeCascVarBachPz(0),
+
+fTreeCascVarV0DecayX(0),
+fTreeCascVarV0DecayY(0),
+fTreeCascVarV0DecayZ(0),
+
+fTreeCascVarCascadeDecayX(0),
+fTreeCascVarCascadeDecayY(0),
+fTreeCascVarCascadeDecayZ(0),
+
+fTreeCascVarBadCascadeJai(0),
+fTreeCascVarDeltaDCA(0),
+
 //------------------------------------------------
 // HISTOGRAMS
 // --- Filled on an Event-by-event basis
@@ -202,10 +249,15 @@ fHistMultiplicitySPDNoTPCOnlyNoPileup(0),
 }
 
 AliAnalysisTaskExtractCascade::AliAnalysisTaskExtractCascade(const char *name) 
-  : AliAnalysisTaskSE(name), fListHist(0), fTreeCascade(0), fPIDResponse(0), fESDtrackCuts(0),
+  : AliAnalysisTaskSE(name), fListHist(0), fTreeCascade(0), fPIDResponse(0), fESDtrackCuts(0), fUtils(0),
    fkIsNuclear   ( kFALSE ), 
    fkSwitchINT7  ( kFALSE ),
-   fCentralityEstimator("V0M"),     
+   fCentralityEstimator("V0M"),
+   fkpAVertexSelection( kFALSE ),
+   fEtaRefMult ( 0.5 ),
+   fkRunVertexers ( kFALSE ),
+   fkDebugMode (kTRUE),
+   fkSelectPeripheral (kFALSE),
 //------------------------------------------------
 // Tree Variables
 //------------------------------------------------
@@ -231,6 +283,7 @@ AliAnalysisTaskExtractCascade::AliAnalysisTaskExtractCascade(const char *name)
    fTreeCascVarCascRadius(0),
    fTreeCascVarV0Mass(0),
    fTreeCascVarV0CosPointingAngle(0),
+   fTreeCascVarV0CosPointingAngleSpecial(0),
    fTreeCascVarV0Radius(0),
    fTreeCascVarLeastNbrClusters(0),
    fTreeCascVarMultiplicity(0),
@@ -243,6 +296,7 @@ AliAnalysisTaskExtractCascade::AliAnalysisTaskExtractCascade(const char *name)
    fTreeCascVarPIDBachelor(0),
    fTreeCascVarPIDNegative(0),
    fTreeCascVarPIDPositive(0),
+   fTreeCascVarBachTransMom(0),
    fTreeCascVarPosTransMom(0),
    fTreeCascVarNegTransMom(0),
    fTreeCascVarPosTransMomMC(0),
@@ -254,6 +308,46 @@ AliAnalysisTaskExtractCascade::AliAnalysisTaskExtractCascade(const char *name)
    fTreeCascVarBachNSigmaPion(0),
    fTreeCascVarBachNSigmaKaon(0),
 
+   fTreeCascVarkITSRefitBachelor(0),
+   fTreeCascVarkITSRefitNegative(0),
+   fTreeCascVarkITSRefitPositive(0),
+
+    //Debug information
+    //Part A: EbyE info, Run number
+    fTreeCascVarRunNumber(0),
+    fTreeCascVarEventNumber(0),
+
+    //Part B: Shared Clusters
+    fTreeCascVarNegClusters(0),
+    fTreeCascVarPosClusters(0),
+    fTreeCascVarBachClusters(0),
+    fTreeCascVarNegSharedClusters(0),
+    fTreeCascVarPosSharedClusters(0),
+    fTreeCascVarBachSharedClusters(0),
+
+    //Part C: All momenta
+    fTreeCascVarNegPx(0),
+    fTreeCascVarNegPy(0),
+    fTreeCascVarNegPz(0),
+    fTreeCascVarPosPx(0),
+    fTreeCascVarPosPy(0),
+    fTreeCascVarPosPz(0),
+    fTreeCascVarBachPx(0),
+    fTreeCascVarBachPy(0),
+    fTreeCascVarBachPz(0),
+
+    fTreeCascVarV0DecayX(0),
+    fTreeCascVarV0DecayY(0),
+    fTreeCascVarV0DecayZ(0),
+
+    fTreeCascVarCascadeDecayX(0),
+    fTreeCascVarCascadeDecayY(0),
+    fTreeCascVarCascadeDecayZ(0),
+    
+    fTreeCascVarBadCascadeJai(0), 
+    fTreeCascVarDeltaDCA(0),
+
+
 //------------------------------------------------
 // HISTOGRAMS
 // --- Filled on an Event-by-event basis
@@ -310,23 +404,23 @@ fHistMultiplicitySPDNoTPCOnlyNoPileup(0),
         
         // New Loose : 1st step for the 7 TeV pp analysis
         
-        fV0Sels[0] =  33.  ;  // max allowed chi2
-        fV0Sels[1] =   0.02;  // min allowed impact parameter for the 1st daughter (LHC09a4 : 0.05)
-        fV0Sels[2] =   0.02;  // min allowed impact parameter for the 2nd daughter (LHC09a4 : 0.05)
-        fV0Sels[3] =   2.0 ;  // max allowed DCA between the daughter tracks       (LHC09a4 : 0.5)
-        fV0Sels[4] =   0.95;  // min allowed cosine of V0's pointing angle         (LHC09a4 : 0.99)
-        fV0Sels[5] =   1.0 ;  // min radius of the fiducial volume                 (LHC09a4 : 0.2)
-        fV0Sels[6] = 100.  ;  // max radius of the fiducial volume                 (LHC09a4 : 100.0)
+        fV0VertexerSels[0] =  33.  ;  // max allowed chi2
+        fV0VertexerSels[1] =   0.02;  // min allowed impact parameter for the 1st daughter (LHC09a4 : 0.05)
+        fV0VertexerSels[2] =   0.02;  // min allowed impact parameter for the 2nd daughter (LHC09a4 : 0.05)
+        fV0VertexerSels[3] =   2.0 ;  // max allowed DCA between the daughter tracks       (LHC09a4 : 0.5)
+        fV0VertexerSels[4] =   0.95;  // min allowed cosine of V0's pointing angle         (LHC09a4 : 0.99)
+        fV0VertexerSels[5] =   1.0 ;  // min radius of the fiducial volume                 (LHC09a4 : 0.2)
+        fV0VertexerSels[6] = 200.  ;  // max radius of the fiducial volume                 (LHC09a4 : 100.0)
+        
+        fCascadeVertexerSels[0] =  33.   ;  // max allowed chi2 (same as PDC07)
+        fCascadeVertexerSels[1] =   0.05 ;  // min allowed V0 impact parameter                    (PDC07 : 0.05   / LHC09a4 : 0.025 )
+        fCascadeVertexerSels[2] =   0.010;  // "window" around the Lambda mass                    (PDC07 : 0.008  / LHC09a4 : 0.010 )
+        fCascadeVertexerSels[3] =   0.03 ;  // min allowed bachelor's impact parameter            (PDC07 : 0.035  / LHC09a4 : 0.025 )
+        fCascadeVertexerSels[4] =   2.0  ;  // max allowed DCA between the V0 and the bachelor    (PDC07 : 0.1    / LHC09a4 : 0.2   )
+        fCascadeVertexerSels[5] =   0.95 ;  // min allowed cosine of the cascade pointing angle   (PDC07 : 0.9985 / LHC09a4 : 0.998 )
+        fCascadeVertexerSels[6] =   0.4  ;  // min radius of the fiducial volume                  (PDC07 : 0.9    / LHC09a4 : 0.2   )
+        fCascadeVertexerSels[7] = 100.   ;  // max radius of the fiducial volume                  (PDC07 : 100    / LHC09a4 : 100   )
         
-        fCascSels[0] =  33.   ;  // max allowed chi2 (same as PDC07)
-        fCascSels[1] =   0.05 ;  // min allowed V0 impact parameter                    (PDC07 : 0.05   / LHC09a4 : 0.025 )
-        fCascSels[2] =   0.010;  // "window" around the Lambda mass                    (PDC07 : 0.008  / LHC09a4 : 0.010 )
-        fCascSels[3] =   0.03 ;  // min allowed bachelor's impact parameter            (PDC07 : 0.035  / LHC09a4 : 0.025 )
-        fCascSels[4] =   2.0  ;  // max allowed DCA between the V0 and the bachelor    (PDC07 : 0.1    / LHC09a4 : 0.2   )
-        fCascSels[5] =   0.95 ;  // min allowed cosine of the cascade pointing angle   (PDC07 : 0.9985 / LHC09a4 : 0.998 )
-        fCascSels[6] =   0.4  ;  // min radius of the fiducial volume                  (PDC07 : 0.9    / LHC09a4 : 0.2   )
-        fCascSels[7] = 100.   ;  // max radius of the fiducial volume                  (PDC07 : 100    / LHC09a4 : 100   )
-
    // Output slot #0 writes into a TList container (Cascade)
    DefineOutput(1, TList::Class());
    DefineOutput(2, TTree::Class());
@@ -352,6 +446,10 @@ AliAnalysisTaskExtractCascade::~AliAnalysisTaskExtractCascade()
     delete fESDtrackCuts;
     fESDtrackCuts = 0x0; 
   }
+  if (fUtils){
+    delete fUtils;
+    fUtils = 0x0;
+  }
 
 }
 
@@ -394,6 +492,7 @@ void AliAnalysisTaskExtractCascade::UserCreateOutputObjects()
 /*17*/         fTreeCascade->Branch("fTreeCascVarCascRadius",&fTreeCascVarCascRadius,"fTreeCascVarCascRadius/F");
 /*18*/         fTreeCascade->Branch("fTreeCascVarV0Mass",&fTreeCascVarV0Mass,"fTreeCascVarV0Mass/F");
 /*19*/         fTreeCascade->Branch("fTreeCascVarV0CosPointingAngle",&fTreeCascVarV0CosPointingAngle,"fTreeCascVarV0CosPointingAngle/F");
+/*19*/         fTreeCascade->Branch("fTreeCascVarV0CosPointingAngleSpecial",&fTreeCascVarV0CosPointingAngleSpecial,"fTreeCascVarV0CosPointingAngleSpecial/F");
 /*20*/         fTreeCascade->Branch("fTreeCascVarV0Radius",&fTreeCascVarV0Radius,"fTreeCascVarV0Radius/F");
 /*21*/         fTreeCascade->Branch("fTreeCascVarLeastNbrClusters",&fTreeCascVarLeastNbrClusters,"fTreeCascVarLeastNbrClusters/I");
 //-----------MULTIPLICITY-INFO--------------------
@@ -411,7 +510,57 @@ void AliAnalysisTaskExtractCascade::UserCreateOutputObjects()
 /*27*/         fTreeCascade->Branch("fTreeCascVarPosNSigmaProton",&fTreeCascVarPosNSigmaProton,"fTreeCascVarPosNSigmaProton/F");
 /*28*/         fTreeCascade->Branch("fTreeCascVarBachNSigmaPion",&fTreeCascVarBachNSigmaPion,"fTreeCascVarBachNSigmaPion/F");
 /*29*/         fTreeCascade->Branch("fTreeCascVarBachNSigmaKaon",&fTreeCascVarBachNSigmaKaon,"fTreeCascVarBachNSigmaKaon/F");
+    
+        //Commented out: not needed since all momenta provided! (less info)
+/*30*/         //fTreeCascade->Branch("fTreeCascVarBachTransMom",&fTreeCascVarBachTransMom,"fTreeCascVarBachTransMom/F");
+/*30*/         //fTreeCascade->Branch("fTreeCascVarPosTransMom",&fTreeCascVarPosTransMom,"fTreeCascVarPosTransMom/F");
+/*31*/         //fTreeCascade->Branch("fTreeCascVarNegTransMom",&fTreeCascVarNegTransMom,"fTreeCascVarNegTransMom/F");
+
+/*29*/         fTreeCascade->Branch("fTreeCascVarkITSRefitBachelor",&fTreeCascVarkITSRefitBachelor,"fTreeCascVarkITSRefitBachelor/O");
+/*29*/         fTreeCascade->Branch("fTreeCascVarkITSRefitNegative",&fTreeCascVarkITSRefitNegative,"fTreeCascVarkITSRefitNegative/O");
+/*29*/         fTreeCascade->Branch("fTreeCascVarkITSRefitPositive",&fTreeCascVarkITSRefitPositive,"fTreeCascVarkITSRefitPositive/O");
+
+    //-----------Debugging information----------------
+
+  if(fkDebugMode){ 
+      //Only save this if requested - can be turned off
 
+      //Part A: Event-by-event, run-by-run debugging
+      fTreeCascade->Branch("fTreeCascVarRunNumber",&fTreeCascVarRunNumber,"fTreeCascVarRunNumber/I");
+      fTreeCascade->Branch("fTreeCascVarEventNumber",&fTreeCascVarEventNumber,"fTreeCascVarEventNumber/l");
+      
+      //Part B: Shared Clusters for all daughter tracks
+      fTreeCascade->Branch("fTreeCascVarNegClusters",&fTreeCascVarNegClusters,"fTreeCascVarNegClusters/I");
+      fTreeCascade->Branch("fTreeCascVarPosClusters",&fTreeCascVarPosClusters,"fTreeCascVarPosClusters/I");
+      fTreeCascade->Branch("fTreeCascVarBachClusters",&fTreeCascVarBachClusters,"fTreeCascVarBachClusters/I");
+      fTreeCascade->Branch("fTreeCascVarNegSharedClusters",&fTreeCascVarNegSharedClusters,"fTreeCascVarNegSharedClusters/I");
+      fTreeCascade->Branch("fTreeCascVarPosSharedClusters",&fTreeCascVarPosSharedClusters,"fTreeCascVarPosSharedClusters/I");
+      fTreeCascade->Branch("fTreeCascVarBachSharedClusters",&fTreeCascVarBachSharedClusters,"fTreeCascVarBachSharedClusters/I");
+      
+      //Part C: All Momenta of all daughters
+      fTreeCascade->Branch("fTreeCascVarNegPx",&fTreeCascVarNegPx,"fTreeCascVarNegPx/F");
+      fTreeCascade->Branch("fTreeCascVarNegPy",&fTreeCascVarNegPy,"fTreeCascVarNegPy/F");
+      fTreeCascade->Branch("fTreeCascVarNegPz",&fTreeCascVarNegPz,"fTreeCascVarNegPz/F");
+      fTreeCascade->Branch("fTreeCascVarPosPx",&fTreeCascVarPosPx,"fTreeCascVarPosPx/F");
+      fTreeCascade->Branch("fTreeCascVarPosPy",&fTreeCascVarPosPy,"fTreeCascVarPosPy/F");
+      fTreeCascade->Branch("fTreeCascVarPosPz",&fTreeCascVarPosPz,"fTreeCascVarPosPz/F");
+      fTreeCascade->Branch("fTreeCascVarBachPx",&fTreeCascVarBachPx,"fTreeCascVarBachPx/F");
+      fTreeCascade->Branch("fTreeCascVarBachPy",&fTreeCascVarBachPy,"fTreeCascVarBachPy/F");
+      fTreeCascade->Branch("fTreeCascVarBachPz",&fTreeCascVarBachPz,"fTreeCascVarBachPz/F");
+      
+      //Part D: Decay positions
+      fTreeCascade->Branch("fTreeCascVarV0DecayX",&fTreeCascVarV0DecayX,"fTreeCascVarV0DecayX/F");
+      fTreeCascade->Branch("fTreeCascVarV0DecayY",&fTreeCascVarV0DecayY,"fTreeCascVarV0DecayY/F");
+      fTreeCascade->Branch("fTreeCascVarV0DecayZ",&fTreeCascVarV0DecayZ,"fTreeCascVarV0DecayZ/F");
+      fTreeCascade->Branch("fTreeCascVarCascadeDecayX",&fTreeCascVarCascadeDecayX,"fTreeCascVarCascadeDecayX/F");
+      fTreeCascade->Branch("fTreeCascVarCascadeDecayY",&fTreeCascVarCascadeDecayY,"fTreeCascVarCascadeDecayY/F");
+      fTreeCascade->Branch("fTreeCascVarCascadeDecayZ",&fTreeCascVarCascadeDecayZ,"fTreeCascVarCascadeDecayZ/F");
+      
+      fTreeCascade->Branch("fTreeCascVarBadCascadeJai",&fTreeCascVarBadCascadeJai,"fTreeCascVarBadCascadeJai/O");
+      fTreeCascade->Branch("fTreeCascVarDeltaDCA",&fTreeCascVarDeltaDCA,"fTreeCascVarDeltaDCA/F");
+      //------------------------------------------------
+  }
+    
 //------------------------------------------------
 // Particle Identification Setup
 //------------------------------------------------
@@ -422,9 +571,12 @@ void AliAnalysisTaskExtractCascade::UserCreateOutputObjects()
 
 // Multiplicity 
 
-    if(! fESDtrackCuts ){
-          fESDtrackCuts = new AliESDtrackCuts();
-    }
+  if(! fESDtrackCuts ){
+    fESDtrackCuts = new AliESDtrackCuts();
+  }
+  if(! fUtils ){
+    fUtils = new AliAnalysisUtils();
+  }
 
 //------------------------------------------------
 // V0 Multiplicity Histograms
@@ -711,13 +863,13 @@ void AliAnalysisTaskExtractCascade::UserExec(Option_t *)
       return;
    }
 
-/* --- Acquisition of exact event ID
-   fTreeVariableRunNumber = lESDevent->GetRunNumber();
-   fTreeVariableEventNumber =  
+    //--- Acquisition of exact event ID
+   fTreeCascVarRunNumber = lESDevent->GetRunNumber();
+   fTreeCascVarEventNumber =
     ( ( ((ULong64_t)lESDevent->GetPeriodNumber() ) << 36 ) |
       ( ((ULong64_t)lESDevent->GetOrbitNumber () ) << 12 ) |
         ((ULong64_t)lESDevent->GetBunchCrossNumber() )  );
-*/
+
         
 //------------------------------------------------
 // Multiplicity Information Acquistion
@@ -731,7 +883,7 @@ void AliAnalysisTaskExtractCascade::UserExec(Option_t *)
   Int_t lMultiplicitySPD = -100;
 
    //testing purposes
-   if(fkIsNuclear == kFALSE) lMultiplicity =  fESDtrackCuts->GetReferenceMultiplicity(lESDevent, AliESDtrackCuts::kTrackletsITSTPC,0.5);
+   if(fkIsNuclear == kFALSE) lMultiplicity =  fESDtrackCuts->GetReferenceMultiplicity(lESDevent, AliESDtrackCuts::kTrackletsITSTPC,  fEtaRefMult );
 
    //---> If this is a nuclear collision, then go nuclear on "multiplicity" variable...
    //---> Warning: Experimental
@@ -749,6 +901,15 @@ void AliAnalysisTaskExtractCascade::UserExec(Option_t *)
         return;
       }
    }
+    
+    if( fkSelectPeripheral ){
+        if( lMultiplicity < 60 || lMultiplicity >= 80. ){
+            //Event is outside 60-80% centrality in V0M!
+            PostData(1, fListHist);
+            PostData(2, fTreeCascade);
+            return;
+        }
+    }
   
    //Set variable for filling tree afterwards!
    //---> pp case......: GetReferenceMultiplicity
@@ -788,19 +949,20 @@ void AliAnalysisTaskExtractCascade::UserExec(Option_t *)
 //------------------------------------------------
 // Rerun cascade vertexer! 
 //------------------------------------------------
-/*
-  lESDevent->ResetCascades();
-  lESDevent->ResetV0s();
-
-  AliV0vertexer lV0vtxer;
-  AliCascadeVertexer lCascVtxer;
-                
-  lV0vtxer.SetDefaultCuts(fV0Sels);
-  lCascVtxer.SetDefaultCuts(fCascSels);
-
-  lV0vtxer.Tracks2V0vertices(lESDevent);
-  lCascVtxer.V0sTracks2CascadeVertices(lESDevent);
-*/
+
+  if( fkRunVertexers ){ 
+    lESDevent->ResetCascades();
+    lESDevent->ResetV0s();
+
+    AliV0vertexer lV0vtxer;
+    AliCascadeVertexer lCascVtxer;
+                  
+    lV0vtxer.SetDefaultCuts(fV0VertexerSels);
+    lCascVtxer.SetDefaultCuts(fCascadeVertexerSels);
+
+    lV0vtxer.Tracks2V0vertices(lESDevent);
+    lCascVtxer.V0sTracks2CascadeVertices(lESDevent);
+  }
 //------------------------------------------------
 // After Trigger Selection
 //------------------------------------------------
@@ -839,24 +1001,62 @@ void AliAnalysisTaskExtractCascade::UserExec(Option_t *)
    fHistPVy->Fill( lPrimaryVtxPosition[1] );
    fHistPVz->Fill( lPrimaryVtxPosition[2] );
 
-//------------------------------------------------
-// Primary Vertex Z position: SKIP
-//------------------------------------------------
-
-   if(TMath::Abs(lBestPrimaryVtxPos[2]) > 10.0 ) { 
-      AliWarning("Pb / | Z position of Best Prim Vtx | > 10.0 cm ... return !"); 
-        PostData(1, fListHist);
-        PostData(2, fTreeCascade);
-      return; 
-   }
-
-   lMagneticField = lESDevent->GetMagneticField( );
-   fHistV0MultiplicityForSelEvt ->Fill( lNumberOfV0s );
-   fHistMultiplicity->Fill(lMultiplicity);
-   fHistMultiplicityV0A->Fill(lMultiplicityV0A);
-   fHistMultiplicityZNA->Fill(lMultiplicityZNA);
-   fHistMultiplicityTRK->Fill(lMultiplicityTRK);
-   fHistMultiplicitySPD->Fill(lMultiplicitySPD);
+  //------------------------------------------------
+  // Primary Vertex Requirements Section:
+  //  ---> pp and PbPb: Only requires |z|<10cm
+  //  ---> pPb: all requirements checked at this stage
+  //------------------------------------------------
+  
+  //Roberto's PV selection criteria, implemented 17th April 2013
+  
+  /* vertex selection */
+  Bool_t fHasVertex = kFALSE;
+  
+  const AliESDVertex *vertex = lESDevent->GetPrimaryVertexTracks();
+  if (vertex->GetNContributors() < 1) {
+    vertex = lESDevent->GetPrimaryVertexSPD();
+    if (vertex->GetNContributors() < 1) fHasVertex = kFALSE;
+    else fHasVertex = kTRUE;
+    TString vtxTyp = vertex->GetTitle();
+    Double_t cov[6]={0};
+    vertex->GetCovarianceMatrix(cov);
+    Double_t zRes = TMath::Sqrt(cov[5]);
+    if (vtxTyp.Contains("vertexer:Z") && (zRes>0.25)) fHasVertex = kFALSE;
+  }
+  else fHasVertex = kTRUE;
+  
+  //Is First event in chunk rejection: Still present!
+  if(fkpAVertexSelection==kTRUE && fHasVertex == kFALSE) {
+    AliWarning("Pb / | PV does not satisfy selection criteria!");
+    PostData(1, fListHist);
+    PostData(2, fTreeCascade);
+    return;
+  }
+  
+  //Is First event in chunk rejection: Still present!
+  if(fkpAVertexSelection==kTRUE && fUtils->IsFirstEventInChunk(lESDevent)) {
+    AliWarning("Pb / | This is the first event in the chunk!");
+    PostData(1, fListHist);
+    PostData(2, fTreeCascade);
+    return;
+  }
+  
+  //17 April Fix: Always do primary vertex Z selection, after pA vertex selection from Roberto
+  if(TMath::Abs(lBestPrimaryVtxPos[2]) > 10.0) {
+    AliWarning("Pb / | Z position of Best Prim Vtx | > 10.0 cm ... return !");
+    PostData(1, fListHist);
+    PostData(2, fTreeCascade);
+    return;
+  }
+  
+  
+  lMagneticField = lESDevent->GetMagneticField( );
+  fHistV0MultiplicityForSelEvt ->Fill( lNumberOfV0s );
+  fHistMultiplicity->Fill(lMultiplicity);
+  fHistMultiplicityV0A->Fill(lMultiplicityV0A);
+  fHistMultiplicityZNA->Fill(lMultiplicityZNA);
+  fHistMultiplicityTRK->Fill(lMultiplicityTRK);
+  fHistMultiplicitySPD->Fill(lMultiplicitySPD);
 
 //------------------------------------------------
 // SKIP: Events with well-established PVtx
@@ -864,7 +1064,7 @@ void AliAnalysisTaskExtractCascade::UserExec(Option_t *)
        
    const AliESDVertex *lPrimaryTrackingESDVtxCheck = lESDevent->GetPrimaryVertexTracks();
    const AliESDVertex *lPrimarySPDVtx = lESDevent->GetPrimaryVertexSPD();
-   if (!lPrimarySPDVtx->GetStatus() && !lPrimaryTrackingESDVtxCheck->GetStatus() ){
+   if (!lPrimarySPDVtx->GetStatus() && !lPrimaryTrackingESDVtxCheck->GetStatus() && fkpAVertexSelection==kFALSE ){
       AliWarning("Pb / No SPD prim. vertex nor prim. Tracking vertex ... return !");
         PostData(1, fListHist);
         PostData(2, fTreeCascade);
@@ -917,6 +1117,7 @@ void AliAnalysisTaskExtractCascade::UserExec(Option_t *)
     //------------------------------------------------ 
          //Double_t lTrkgPrimaryVtxRadius3D = -500.0;
          //Double_t lBestPrimaryVtxRadius3D = -500.0;
+         fTreeCascVarBadCascadeJai = kFALSE ;
 
          // - 1st part of initialisation : variables needed to store AliESDCascade data members
          Double_t lEffMassXi      = 0. ;
@@ -940,6 +1141,7 @@ void AliAnalysisTaskExtractCascade::UserExec(Option_t *)
          Double_t lDcaPosToPrimVertexXi  = -1.;
          Double_t lDcaNegToPrimVertexXi  = -1.;
          Double_t lV0CosineOfPointingAngleXi = -1. ;
+         Double_t lV0CosineOfPointingAngleXiSpecial = -1. ;
          Double_t lPosV0Xi[3] = { -1000. , -1000., -1000. }; // Position of VO coming from cascade
          Double_t lV0RadiusXi = -1000.0;
          Double_t lV0quality  = 0.;
@@ -1006,6 +1208,10 @@ void AliAnalysisTaskExtractCascade::UserExec(Option_t *)
          xi->GetXYZcascade( lPosXi[0],  lPosXi[1], lPosXi[2] ); 
          lXiRadius                     = TMath::Sqrt( lPosXi[0]*lPosXi[0]  +  lPosXi[1]*lPosXi[1] );           
 
+    fTreeCascVarCascadeDecayX = lPosXi[0];
+    fTreeCascVarCascadeDecayY = lPosXi[1];
+    fTreeCascVarCascadeDecayZ = lPosXi[2];
+
                // - II.Step 3 : around the tracks : Bach + V0 (ESD)
                // ~ Necessary variables for ESDcascade data members coming from the ESDv0 part (inheritance)
                //-------------
@@ -1033,9 +1239,34 @@ void AliAnalysisTaskExtractCascade::UserExec(Option_t *)
                  continue;
          }
 
-   fTreeCascVarPosEta = pTrackXi->Eta();
-   fTreeCascVarNegEta = nTrackXi->Eta();
-   fTreeCascVarBachEta = bachTrackXi->Eta();
+      fTreeCascVarPosEta = pTrackXi->Eta();
+      fTreeCascVarNegEta = nTrackXi->Eta();
+      fTreeCascVarBachEta = bachTrackXi->Eta();
+      
+      //Save shared clusters information
+      fTreeCascVarNegSharedClusters = nTrackXi->GetTPCnclsS(0,159);
+      fTreeCascVarPosSharedClusters = pTrackXi->GetTPCnclsS(0,159);
+      fTreeCascVarBachSharedClusters = bachTrackXi->GetTPCnclsS(0,159);
+      
+      Double_t lBMom[3], lNMom[3], lPMom[3];
+      xi->GetBPxPyPz( lBMom[0], lBMom[1], lBMom[2] );
+      xi->GetPPxPyPz( lPMom[0], lPMom[1], lPMom[2] );
+      xi->GetNPxPyPz( lNMom[0], lNMom[1], lNMom[2] );
+      
+      //Save all momentum information
+      fTreeCascVarNegPx = lNMom[0];
+      fTreeCascVarNegPy = lNMom[1];
+      fTreeCascVarNegPz = lNMom[2];
+      fTreeCascVarPosPx = lPMom[0];
+      fTreeCascVarPosPy = lPMom[1];
+      fTreeCascVarPosPz = lPMom[2];
+      fTreeCascVarBachPx = lBMom[0];
+      fTreeCascVarBachPy = lBMom[1];
+      fTreeCascVarBachPz = lBMom[2];
+      
+      fTreeCascVarBachTransMom = TMath::Sqrt( lBMom[0]*lBMom[0] + lBMom[1]*lBMom[1] );
+      fTreeCascVarPosTransMom  = TMath::Sqrt( lPMom[0]*lPMom[0] + lPMom[1]*lPMom[1] );
+      fTreeCascVarNegTransMom  = TMath::Sqrt( lNMom[0]*lNMom[0] + lNMom[1]*lNMom[1] );
   
     //------------------------------------------------
     // TPC dEdx information 
@@ -1056,14 +1287,29 @@ void AliAnalysisTaskExtractCascade::UserExec(Option_t *)
          lPosTPCClusters   = pTrackXi->GetTPCNcls();
          lNegTPCClusters   = nTrackXi->GetTPCNcls();
          lBachTPCClusters  = bachTrackXi->GetTPCNcls(); 
+         
+      fTreeCascVarNegClusters = lNegTPCClusters;
+      fTreeCascVarPosClusters = lPosTPCClusters;
+      fTreeCascVarBachClusters = lBachTPCClusters;
 
     // 1 - Poor quality related to TPCrefit
          ULong_t pStatus    = pTrackXi->GetStatus();
          ULong_t nStatus    = nTrackXi->GetStatus();
          ULong_t bachStatus = bachTrackXi->GetStatus();
+
+    fTreeCascVarkITSRefitBachelor = kTRUE; 
+    fTreeCascVarkITSRefitNegative = kTRUE; 
+    fTreeCascVarkITSRefitPositive = kTRUE; 
+
     if ((pStatus&AliESDtrack::kTPCrefit)    == 0) { AliWarning("Pb / V0 Pos. track has no TPCrefit ... continue!"); continue; }
     if ((nStatus&AliESDtrack::kTPCrefit)    == 0) { AliWarning("Pb / V0 Neg. track has no TPCrefit ... continue!"); continue; }
     if ((bachStatus&AliESDtrack::kTPCrefit) == 0) { AliWarning("Pb / Bach.   track has no TPCrefit ... continue!"); continue; }
+
+    //Extra Debug Information: booleans for ITS refit
+    if ((pStatus&AliESDtrack::kITSrefit)    == 0) { fTreeCascVarkITSRefitPositive = kFALSE; }
+    if ((nStatus&AliESDtrack::kITSrefit)    == 0) { fTreeCascVarkITSRefitNegative = kFALSE; }
+    if ((bachStatus&AliESDtrack::kITSrefit) == 0) { fTreeCascVarkITSRefitBachelor = kFALSE; }
+
          // 2 - Poor quality related to TPC clusters: lowest cut of 70 clusters
     if(lPosTPCClusters  < 70) { AliWarning("Pb / V0 Pos. track has less than 70 TPC clusters ... continue!"); continue; }
          if(lNegTPCClusters  < 70) { AliWarning("Pb / V0 Neg. track has less than 70 TPC clusters ... continue!"); continue; }
@@ -1081,6 +1327,10 @@ void AliAnalysisTaskExtractCascade::UserExec(Option_t *)
          lV0CosineOfPointingAngleXi    = xi->GetV0CosineOfPointingAngle( lBestPrimaryVtxPos[0],
                                                                            lBestPrimaryVtxPos[1],
                                                                            lBestPrimaryVtxPos[2] );
+    //Modification: V0 CosPA wrt to Cascade decay vertex
+         lV0CosineOfPointingAngleXiSpecial     = xi->GetV0CosineOfPointingAngle( lPosXi[0],
+                                                                           lPosXi[1],
+                                                                           lPosXi[2] );
 
          lDcaV0ToPrimVertexXi          = xi->GetD( lBestPrimaryVtxPos[0], 
                                                      lBestPrimaryVtxPos[1], 
@@ -1094,6 +1344,10 @@ void AliAnalysisTaskExtractCascade::UserExec(Option_t *)
          xi->GetXYZ( lPosV0Xi[0],  lPosV0Xi[1], lPosV0Xi[2] ); 
          lV0RadiusXi           = TMath::Sqrt( lPosV0Xi[0]*lPosV0Xi[0]  +  lPosV0Xi[1]*lPosV0Xi[1] );
        
+    fTreeCascVarV0DecayX = lPosV0Xi[0];
+    fTreeCascVarV0DecayY = lPosV0Xi[1];
+    fTreeCascVarV0DecayZ = lPosV0Xi[2];
+
          lDcaPosToPrimVertexXi         = TMath::Abs( pTrackXi  ->GetD( lBestPrimaryVtxPos[0], 
                                                                lBestPrimaryVtxPos[1], 
                                                                lMagneticField  )     ); 
@@ -1162,6 +1416,27 @@ void AliAnalysisTaskExtractCascade::UserExec(Option_t *)
          //lPhi      = xi->Phi()   *180.0/TMath::Pi();
          //lAlphaXi  = xi->AlphaXi();
          //lPtArmXi  = xi->PtArmXi();
+         
+  //------------------------------------------------
+  // Jai Salzwedel's femto-cut: better V0 exists
+  //------------------------------------------------                     
+
+  fTreeCascVarDeltaDCA = -100;
+  Float_t DCAV0DaughtersDiff = -100; 
+  for (Int_t iv0=0; iv0<lESDevent->GetNumberOfV0s(); iv0++) {
+    AliESDv0 *v0 = lESDevent->GetV0(iv0);
+    UInt_t posV0TrackIdx = (UInt_t) v0->GetPindex();
+    UInt_t negV0TrackIdx = (UInt_t) v0->GetNindex();
+    if ((posV0TrackIdx == lIdxPosXi) && (negV0TrackIdx == lIdxNegXi)) continue;
+      // if both tracks are the same ones as the cascades V0 daughter tracks, then the V0 belongs to the cascade being analysed; so avoid it
+    if ((posV0TrackIdx == lIdxPosXi) || (negV0TrackIdx == lIdxNegXi)) {
+    DCAV0DaughtersDiff = lDcaV0DaughtersXi - v0->GetDcaV0Daughters();
+    if( fTreeCascVarDeltaDCA < DCAV0DaughtersDiff ) fTreeCascVarDeltaDCA = DCAV0DaughtersDiff;
+      if ( lDcaV0DaughtersXi > v0->GetDcaV0Daughters() )  {    // DCA comparison criterion
+        fTreeCascVarBadCascadeJai = kTRUE;
+      } //end DCA comparison 
+    } // end shares a daughter check 
+  } //end V0 loop 
 
   //------------------------------------------------
   // Set Variables for adding to tree
@@ -1187,6 +1462,7 @@ void AliAnalysisTaskExtractCascade::UserExec(Option_t *)
 /*14*/         fTreeCascVarCascRadius = lXiRadius;
 /*15*/         fTreeCascVarV0Mass = lInvMassLambdaAsCascDghter;
 /*16*/         fTreeCascVarV0CosPointingAngle = lV0CosineOfPointingAngleXi;
+/*16*/         fTreeCascVarV0CosPointingAngleSpecial = lV0CosineOfPointingAngleXiSpecial;
 /*17*/         fTreeCascVarV0Radius = lV0RadiusXi;
 /*20*/         fTreeCascVarLeastNbrClusters = leastnumberofclusters;
 /*21*/         fTreeCascVarMultiplicity = lMultiplicity; //multiplicity, whatever that may be