]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/FEMTOSCOPY/PLamAnalysis/AliAnalysisTaskProtonLambda.cxx
Changes to compile with Root6 on macosx64
[u/mrichter/AliRoot.git] / PWGCF / FEMTOSCOPY / PLamAnalysis / AliAnalysisTaskProtonLambda.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15 #if !defined(__CINT__) || defined(__MAKECINT__)
16
17 #include <TH1F.h>
18 #include <TH2F.h>
19 #include <TH3F.h>
20
21 #include <TAxis.h>
22 // #include "TObjArray.h"
23
24 #include <AliAnalysisTask.h>
25 #include <AliAnalysisManager.h>
26
27 #include <AliAODEvent.h>
28 #include <AliAODVertex.h>
29 #include <AliAODv0.h>
30 #include <AliAODInputHandler.h>
31
32 #include "AliAnalysisTaskProtonLambda.h"
33 #include <AliCentrality.h>
34 //#include "AliAODpid.h"
35 #include <AliPID.h>
36 #include <AliPIDResponse.h>
37 // #include <../STEER/STEER/AliV0.h>
38 #include <AliExternalTrackParam.h>
39 //#include <AliAODTrack.h>
40 //#include <AliESDtrack.h>
41
42 //#include "EventCollection.h"
43
44 // Task to study femtoscopic proton-lambda correlations
45 // Author: Hans Beck
46
47 ClassImp(AliAnalysisTaskProtonLambda)
48 //ClassImp(AliAnalysisTaskProtonLambda::GlobalTrackInfo)
49 //ClassImp(AliAnalysisTaskProtonLambda::GTIContainer)
50
51 #endif  
52 //________________________________________________________________________
53 AliAnalysisTaskProtonLambda::AliAnalysisTaskProtonLambda() 
54   : AliAnalysisTaskSE(),
55   fkUseOnTheFly(kTRUE),
56   fkAbsZvertexCut(10.0),
57   fkCentCut(20.0),
58   fkLamMass(1.115683),
59   fkProMass(0.9382720),
60   fkPioMass(0.13957018),
61   fPIDResponse(0), 
62   fTpcResponse(0),
63   fFemtoBuffer(0),
64   fAOD(0), fPrimaryVtx(0), fOutputList(0), fOutputPrimaries(0),
65   fOutput2Part(0),
66   fGTI(0),fTrackBuffSize(18000),
67   fHistGoodEvent(0),
68   // fHistPrimaryVertexPosXY(0), fHistPrimaryVertexPosZ(0),        
69   // fHistTrackMultiplicity(0),    
70   // fHistShareV0pos(0),fHistShareV0neg(0),
71   // fHistPosTofBeforeCut(0), fHistPosTofAfterCut(0),           
72   // fHistNegTofBeforeCut(0), fHistNegTofAfterCut(0),           
73   // fHistPosTpcBeforeCut(0), fHistPosTpcAfterCut(0),            
74   // fHistNegTpcBeforeCut(0), fHistNegTpcAfterCut(0),            
75   // fHistGoodV0(0), fHistCorrectSigns(0),              
76   // fHistDcaPosToPrimVertex(0), fHistDcaNegToPrimVertex(0),        
77   // fHistDcaPosToPrimVertexZoom(0), fHistDcaNegToPrimVertexZoom(0),  
78   // fHistRadiusV0(0), fHistDecayLengthV0(0), fHistDcaV0Daughters(0),          
79   // fHistChi2(0), fHistCosPointAngle(0), fHistCosPointAngleZoom(0),
80   fHistSideBandOffLam(0), fHistSideBandOffALam(0), fHistTPCNclsPosOffLam(0),       
81   fHistTPCNclsNegOffLam(0), fHistTPCNclsPosOffALam(0), fHistTPCNclsNegOffALam(0),      
82   // fHistPosNsigmaTpcOffLam(0), fHistPosNsigmaTpcOffALam(0), fHistNegNsigmaTpcOffLam(0),
83   // fHistNegNsigmaTpcOffALam(0), fHistUseTofOffLam(0), fHistUseTofOffALam(0),
84   // fHistDcaPosOffLam(0), fHistDcaPosOffALam(0), fHistDcaNegOffLam(0),           
85   // fHistDcaNegOffALam(0), fHistDcaV0DaughtersOffLam(0), fHistDcaV0DaughtersOffALam(0),  
86   // fHistCosPointLamOff(0), fHistCosPointALamOff(0), fHistCosPointLamZoomOff(0),     
87   // fHistCosPointALamZoomOff(0), fHistV0RadiusLamOff(0), fHistV0RadiusALamOff(0),        
88   // fHistV0DecayLengthLamOff(0), fHistV0DecayLengthALamOff(0), fHistDcaV0PriVertexLamOff(0),     
89   // fHistDcaV0PriVertexALamOff(0),
90   fHistMassLambdaOff(0), fHistMassAntiLambdaOff(0),        
91   // fHistPtVsMassLambdaOff(0), fHistPtVsMassAntiLambdaOff(0),
92   fHistYPtMassLamOff(0), fHistYPtMassALamOff(0),
93   // fHistPtVsYLambdaOff(0), fHistPtVsYAntiLambdaOff(0),       
94   fHistSideBandOnLam(0), fHistSideBandOnALam(0),
95   // fHistLikeSignOnLam(0), fHistLikeSignOnALam(0),         
96   fHistTPCNclsPosOnLam(0), fHistTPCNclsNegOnLam(0), fHistTPCNclsPosOnALam(0),fHistTPCNclsNegOnALam(0),     
97   // fHistPosNsigmaTpcOnLam(0), fHistPosNsigmaTpcOnALam(0), fHistNegNsigmaTpcOnLam(0), fHistNegNsigmaTpcOnALam(0),        
98   // fHistUseTofOnLam(0),fHistUseTofOnALam(0),fHistDcaPosOnLam(0),fHistDcaPosOnALam(0),fHistDcaNegOnLam(0),               
99   // fHistDcaNegOnALam(0),fHistDcaV0DaughtersOnLam(0),fHistDcaV0DaughtersOnALam(0),fHistCosPointLamOn(0),             
100   // fHistCosPointALamOn(0),fHistCosPointLamZoomOn(0),fHistCosPointALamZoomOn(0),fHistV0RadiusLamOn(0),             
101   // fHistV0RadiusALamOn(0),fHistV0DecayLengthLamOn(0),fHistV0DecayLengthALamOn(0),fHistDcaV0PriVertexLamOn(0),       
102   // fHistDcaV0PriVertexALamOn(0),
103   // fHistChi2TPCPosLamOn(0),  fHistChi2TPCPosALamOn(0),  fHistChi2TPCNegLamOn(0),  fHistChi2TPCNegALamOn(0),
104   // fHistMinvTPConlyLamOn(0),  fHistMinvTPConlyALamOn(0),
105   fHistMassLambdaOn(0),fHistMassAntiLambdaOn(0),
106   // fHistPtVsMassLambdaOn(0), fHistPtVsMassAntiLambdaOn(0),
107   fHistYPtMassLamOn(0),fHistYPtMassALamOn(0),
108   // fHistPtVsYLambdaOn(0), fHistPtVsYAntiLambdaOn(0),
109   // fHistMomDiffLam(0),fHistMomDiffALam(0),fHistMomDiffBgLam(0),fHistMomDiffBgALam(0),
110   // fHistMomDiffWoSPDLam(0),fHistMomDiffWoSPDALam(0),fHistMomDiffWoSPDBgLam(0),fHistMomDiffWoSPDBgALam(0),
111   fPriHistShare(0),
112   // fPriHistPosNsigmaTof(0),
113   fPriHistPosNsigmaTofVsP(0),fPriHistPosNsigmaTofVsPt(0),     
114   // fPriHistNegNsigmaTof(0),
115   fPriHistNegNsigmaTofVsP(0),fPriHistNegNsigmaTofVsPt(0),fPriHistTOFsignalPosVsP(0),      
116   fPriHistTOFsignalPosVsPt(0),fPriHistTOFsignalNegVsP(0),fPriHistTOFsignalNegVsPt(0),fPriHistHybridTOFsigPosWoTPC(0), 
117   fPriHistHybridTOFsigPosTPCok(0),fPriHistHybridTOFsigNegWoTPC(0),fPriHistHybridTOFsigNegTPCok(0),
118   // fPriHistHasTofPos(0),          
119   fPriHistTPCsignalPos(0),
120   // fPriHistNsigmaTPCPos(0), fPriHistTPCsignalTOFcutPos(0),fPriHistNsigmaTPCTOFcutPos(0),   
121   fPriHistTPCsignalLowPPos(0),fPriHistTPCsignalMedPPos(0),fPriHistTPCsignalHigPPos(0),
122   // fPriHistHasTofNeg(0),         
123   fPriHistTPCsignalNeg(0),
124   // fPriHistNsigmaTPCNeg(0),fPriHistTPCsignalTOFcutNeg(0),fPriHistNsigmaTPCTOFcutNeg(0),    
125   fPriHistTPCsignalLowPNeg(0),fPriHistTPCsignalMedPNeg(0),fPriHistTPCsignalHigPNeg(0),
126   fPriHistDCAxyYPtPro(0),fPriHistDCAxyYPtAPro(0),
127   // f2HistLamLamMeanMinDistProReal(0),
128   // f2HistLamLamMeanMinDistPioReal(0),f2HistLamProMeanMinDistProReal(0),f2HistALamALamMeanMinDistAProReal(0), 
129   // f2HistALamALamMeanMinDistPioReal(0),f2HistALamAProMeanMinDistAProReal(0),
130   // f2HistSftLamLamMeanMinDistProReal(0),
131   // f2HistSftLamLamMeanMinDistPioReal(0),f2HistSftLamProMeanMinDistProReal(0),f2HistSftALamALamMeanMinDistAProReal(0), 
132   // f2HistSftALamALamMeanMinDistPioReal(0),f2HistSftALamAProMeanMinDistAProReal(0),
133   // f2HistSftIrocLamLamMeanMinDistProReal(0),
134   // f2HistSftIrocLamLamMeanMinDistPioReal(0),f2HistSftIrocLamProMeanMinDistProReal(0),f2HistSftIrocALamALamMeanMinDistAProReal(0), 
135   // f2HistSftIrocALamALamMeanMinDistPioReal(0),f2HistSftIrocALamAProMeanMinDistAProReal(0),
136   // f2HistSftOrocLamLamMeanMinDistProReal(0),
137   // f2HistSftOrocLamLamMeanMinDistPioReal(0),f2HistSftOrocLamProMeanMinDistProReal(0),f2HistSftOrocALamALamMeanMinDistAProReal(0), 
138   // f2HistSftOrocALamALamMeanMinDistPioReal(0),f2HistSftOrocALamAProMeanMinDistAProReal(0),
139   // f2HistMtLamLamReal(0), 
140   f2HistMtLamProReal(0), 
141   // f2HistMtALamALamReal(0), 
142   f2HistMtALamAProReal(0),
143   // f2HistMtLowQLamLamReal(0), 
144   f2HistMtLowQLamProReal(0), 
145   // f2HistMtLowQALamALamReal(0), 
146   f2HistMtLowQALamAProReal(0),
147   LamProReal(0),ALamAProReal(0),
148   // f3HistLamLamQinvReal(0),               
149   // f3HistALamALamQinvReal(0),f3HistLamLamMinvReal(0),               
150   // f3HistLamProMinvReal(0),f3HistALamALamMinvReal(0),f3HistALamAProMinvReal(0),
151   // f2HistBgLamBgLamMeanMinDistProReal(0),f2HistBgLamBgLamMeanMinDistPioReal(0),
152   // f2HistBgLamProMeanMinDistProReal(0),f2HistBgALamBgALamMeanMinDistAProReal(0),
153   // f2HistBgALamBgALamMeanMinDistPioReal(0),f2HistBgALamAProMeanMinDistAProReal(0),
154   // f2HistSftBgLamBgLamMeanMinDistProReal(0),f2HistSftBgLamBgLamMeanMinDistPioReal(0),
155   // f2HistSftBgLamProMeanMinDistProReal(0),f2HistSftBgALamBgALamMeanMinDistAProReal(0),
156   // f2HistSftBgALamBgALamMeanMinDistPioReal(0),f2HistSftBgALamAProMeanMinDistAProReal(0),
157   // f2HistSftIrocBgLamBgLamMeanMinDistProReal(0),f2HistSftIrocBgLamBgLamMeanMinDistPioReal(0),
158   // f2HistSftIrocBgLamProMeanMinDistProReal(0),f2HistSftIrocBgALamBgALamMeanMinDistAProReal(0),
159   // f2HistSftIrocBgALamBgALamMeanMinDistPioReal(0),f2HistSftIrocBgALamAProMeanMinDistAProReal(0),
160   // f2HistSftOrocBgLamBgLamMeanMinDistProReal(0),f2HistSftOrocBgLamBgLamMeanMinDistPioReal(0),
161   // f2HistSftOrocBgLamProMeanMinDistProReal(0),f2HistSftOrocBgALamBgALamMeanMinDistAProReal(0),
162   // f2HistSftOrocBgALamBgALamMeanMinDistPioReal(0),f2HistSftOrocBgALamAProMeanMinDistAProReal(0),
163   BgLamProReal(0),BgALamAProReal(0),
164   // f3HistBgLamBgLamQinvReal(0),             
165   // f3HistBgALamBgALamQinvReal(0),
166   // f2HistLamLamMeanMinDistProMixed(0),f2HistLamLamMeanMinDistPioMixed(0),
167   // f2HistLamProMeanMinDistProMixed(0),f2HistALamALamMeanMinDistAProMixed(0),   
168   // f2HistALamALamMeanMinDistPioMixed(0),f2HistALamAProMeanMinDistAProMixed(0),
169   // f2HistSftLamLamMeanMinDistProMixed(0),f2HistSftLamLamMeanMinDistPioMixed(0),
170   // f2HistSftLamProMeanMinDistProMixed(0),f2HistSftALamALamMeanMinDistAProMixed(0),   
171   // f2HistSftALamALamMeanMinDistPioMixed(0),f2HistSftALamAProMeanMinDistAProMixed(0),
172   // f2HistSftIrocLamLamMeanMinDistProMixed(0),f2HistSftIrocLamLamMeanMinDistPioMixed(0),
173   // f2HistSftIrocLamProMeanMinDistProMixed(0),f2HistSftIrocALamALamMeanMinDistAProMixed(0),   
174   // f2HistSftIrocALamALamMeanMinDistPioMixed(0),f2HistSftIrocALamAProMeanMinDistAProMixed(0),
175   // f2HistSftOrocLamLamMeanMinDistProMixed(0),f2HistSftOrocLamLamMeanMinDistPioMixed(0),
176   // f2HistSftOrocLamProMeanMinDistProMixed(0),f2HistSftOrocALamALamMeanMinDistAProMixed(0),   
177   // f2HistSftOrocALamALamMeanMinDistPioMixed(0),f2HistSftOrocALamAProMeanMinDistAProMixed(0),
178   LamProMixed(0),ALamAProMixed(0),
179   // f3HistLamLamQinvMixed(0),                
180   // f3HistALamALamQinvMixed(0),f3HistLamLamMinvMixed(0),                
181   // f3HistLamProMinvMixed(0),f3HistALamALamMinvMixed(0),f3HistALamAProMinvMixed(0),
182   // f2HistBgLamBgLamMeanMinDistProMixed(0),f2HistBgLamBgLamMeanMinDistPioMixed(0),
183   // f2HistBgLamProMeanMinDistProMixed(0),f2HistBgALamBgALamMeanMinDistAProMixed(0),
184   // f2HistBgALamBgALamMeanMinDistPioMixed(0),f2HistBgALamAProMeanMinDistAProMixed(0),
185   // f2HistSftBgLamBgLamMeanMinDistProMixed(0),f2HistSftBgLamBgLamMeanMinDistPioMixed(0),
186   // f2HistSftBgLamProMeanMinDistProMixed(0),f2HistSftBgALamBgALamMeanMinDistAProMixed(0),
187   // f2HistSftBgALamBgALamMeanMinDistPioMixed(0),f2HistSftBgALamAProMeanMinDistAProMixed(0),
188   // f2HistSftIrocBgLamBgLamMeanMinDistProMixed(0),f2HistSftIrocBgLamBgLamMeanMinDistPioMixed(0),
189   // f2HistSftIrocBgLamProMeanMinDistProMixed(0),f2HistSftIrocBgALamBgALamMeanMinDistAProMixed(0),
190   // f2HistSftIrocBgALamBgALamMeanMinDistPioMixed(0),f2HistSftIrocBgALamAProMeanMinDistAProMixed(0),
191   // f2HistSftOrocBgLamBgLamMeanMinDistProMixed(0),f2HistSftOrocBgLamBgLamMeanMinDistPioMixed(0),
192   // f2HistSftOrocBgLamProMeanMinDistProMixed(0),f2HistSftOrocBgALamBgALamMeanMinDistAProMixed(0),
193   // f2HistSftOrocBgALamBgALamMeanMinDistPioMixed(0),f2HistSftOrocBgALamAProMeanMinDistAProMixed(0),
194   BgLamProMixed(0),BgALamAProMixed(0)
195   // f3HistBgLamBgLamQinvMixed(0),             
196   // f3HistBgALamBgALamQinvMixed(0)
197 {
198   // Dummy constructor
199   fPrimaryVtxPosition[0]=0;
200   fPrimaryVtxPosition[1]=0;
201   fPrimaryVtxPosition[2]=0;
202 }
203 //________________________________________________________________________
204 AliAnalysisTaskProtonLambda::AliAnalysisTaskProtonLambda(const char *name) 
205   : AliAnalysisTaskSE(name),
206   fkUseOnTheFly(kTRUE),
207   fkAbsZvertexCut(10.0),
208   fkCentCut(20.0),
209   fkLamMass(1.115683),
210   fkProMass(0.9382720),
211   fkPioMass(0.13957018),
212   fPIDResponse(0), 
213   fTpcResponse(0),
214   fFemtoBuffer(0),
215   fAOD(0), fPrimaryVtx(0), fOutputList(0), fOutputPrimaries(0),
216   fOutput2Part(0),
217   fGTI(0),fTrackBuffSize(18000),
218   fHistGoodEvent(0),
219   // fHistPrimaryVertexPosXY(0), fHistPrimaryVertexPosZ(0),        
220   // fHistTrackMultiplicity(0),    
221   // fHistShareV0pos(0),fHistShareV0neg(0),
222   // fHistPosTofBeforeCut(0), fHistPosTofAfterCut(0),           
223   // fHistNegTofBeforeCut(0), fHistNegTofAfterCut(0),           
224   // fHistPosTpcBeforeCut(0), fHistPosTpcAfterCut(0),            
225   // fHistNegTpcBeforeCut(0), fHistNegTpcAfterCut(0),            
226   // fHistGoodV0(0), fHistCorrectSigns(0),              
227   // fHistDcaPosToPrimVertex(0), fHistDcaNegToPrimVertex(0),        
228   // fHistDcaPosToPrimVertexZoom(0), fHistDcaNegToPrimVertexZoom(0),  
229   // fHistRadiusV0(0), fHistDecayLengthV0(0), fHistDcaV0Daughters(0),          
230   // fHistChi2(0), fHistCosPointAngle(0), fHistCosPointAngleZoom(0),
231   fHistSideBandOffLam(0), fHistSideBandOffALam(0), fHistTPCNclsPosOffLam(0),       
232   fHistTPCNclsNegOffLam(0), fHistTPCNclsPosOffALam(0), fHistTPCNclsNegOffALam(0),      
233   // fHistPosNsigmaTpcOffLam(0), fHistPosNsigmaTpcOffALam(0), fHistNegNsigmaTpcOffLam(0),
234   // fHistNegNsigmaTpcOffALam(0), fHistUseTofOffLam(0), fHistUseTofOffALam(0),
235   // fHistDcaPosOffLam(0), fHistDcaPosOffALam(0), fHistDcaNegOffLam(0),           
236   // fHistDcaNegOffALam(0), fHistDcaV0DaughtersOffLam(0), fHistDcaV0DaughtersOffALam(0),  
237   // fHistCosPointLamOff(0), fHistCosPointALamOff(0), fHistCosPointLamZoomOff(0),     
238   // fHistCosPointALamZoomOff(0), fHistV0RadiusLamOff(0), fHistV0RadiusALamOff(0),        
239   // fHistV0DecayLengthLamOff(0), fHistV0DecayLengthALamOff(0), fHistDcaV0PriVertexLamOff(0),     
240   // fHistDcaV0PriVertexALamOff(0),
241   fHistMassLambdaOff(0), fHistMassAntiLambdaOff(0),        
242   // fHistPtVsMassLambdaOff(0), fHistPtVsMassAntiLambdaOff(0),
243   fHistYPtMassLamOff(0), fHistYPtMassALamOff(0),
244   // fHistPtVsYLambdaOff(0), fHistPtVsYAntiLambdaOff(0),       
245   fHistSideBandOnLam(0), fHistSideBandOnALam(0),
246   // fHistLikeSignOnLam(0), fHistLikeSignOnALam(0),         
247   fHistTPCNclsPosOnLam(0), fHistTPCNclsNegOnLam(0), fHistTPCNclsPosOnALam(0),fHistTPCNclsNegOnALam(0),     
248   // fHistPosNsigmaTpcOnLam(0), fHistPosNsigmaTpcOnALam(0), fHistNegNsigmaTpcOnLam(0), fHistNegNsigmaTpcOnALam(0),        
249   // fHistUseTofOnLam(0),fHistUseTofOnALam(0),fHistDcaPosOnLam(0),fHistDcaPosOnALam(0),fHistDcaNegOnLam(0),               
250   // fHistDcaNegOnALam(0),fHistDcaV0DaughtersOnLam(0),fHistDcaV0DaughtersOnALam(0),fHistCosPointLamOn(0),             
251   // fHistCosPointALamOn(0),fHistCosPointLamZoomOn(0),fHistCosPointALamZoomOn(0),fHistV0RadiusLamOn(0),             
252   // fHistV0RadiusALamOn(0),fHistV0DecayLengthLamOn(0),fHistV0DecayLengthALamOn(0),fHistDcaV0PriVertexLamOn(0),       
253   // fHistDcaV0PriVertexALamOn(0),
254   // fHistChi2TPCPosLamOn(0),  fHistChi2TPCPosALamOn(0),  fHistChi2TPCNegLamOn(0),  fHistChi2TPCNegALamOn(0),
255   // fHistMinvTPConlyLamOn(0),  fHistMinvTPConlyALamOn(0),
256   fHistMassLambdaOn(0),fHistMassAntiLambdaOn(0),
257   // fHistPtVsMassLambdaOn(0), fHistPtVsMassAntiLambdaOn(0),
258   fHistYPtMassLamOn(0),fHistYPtMassALamOn(0),
259   // fHistPtVsYLambdaOn(0), fHistPtVsYAntiLambdaOn(0),
260   // fHistMomDiffLam(0),fHistMomDiffALam(0),fHistMomDiffBgLam(0),fHistMomDiffBgALam(0),
261   // fHistMomDiffWoSPDLam(0),fHistMomDiffWoSPDALam(0),fHistMomDiffWoSPDBgLam(0),fHistMomDiffWoSPDBgALam(0),
262   fPriHistShare(0),
263   // fPriHistPosNsigmaTof(0),
264   fPriHistPosNsigmaTofVsP(0),fPriHistPosNsigmaTofVsPt(0),     
265   // fPriHistNegNsigmaTof(0),
266   fPriHistNegNsigmaTofVsP(0),fPriHistNegNsigmaTofVsPt(0),fPriHistTOFsignalPosVsP(0),      
267   fPriHistTOFsignalPosVsPt(0),fPriHistTOFsignalNegVsP(0),fPriHistTOFsignalNegVsPt(0),fPriHistHybridTOFsigPosWoTPC(0), 
268   fPriHistHybridTOFsigPosTPCok(0),fPriHistHybridTOFsigNegWoTPC(0),fPriHistHybridTOFsigNegTPCok(0),
269   // fPriHistHasTofPos(0),          
270   fPriHistTPCsignalPos(0),
271   // fPriHistNsigmaTPCPos(0), fPriHistTPCsignalTOFcutPos(0),fPriHistNsigmaTPCTOFcutPos(0),   
272   fPriHistTPCsignalLowPPos(0),fPriHistTPCsignalMedPPos(0),fPriHistTPCsignalHigPPos(0),
273   // fPriHistHasTofNeg(0),         
274   fPriHistTPCsignalNeg(0),
275   // fPriHistNsigmaTPCNeg(0),fPriHistTPCsignalTOFcutNeg(0),fPriHistNsigmaTPCTOFcutNeg(0),    
276   fPriHistTPCsignalLowPNeg(0),fPriHistTPCsignalMedPNeg(0),fPriHistTPCsignalHigPNeg(0),
277   fPriHistDCAxyYPtPro(0),fPriHistDCAxyYPtAPro(0),
278   // f2HistLamLamMeanMinDistProReal(0),
279   // f2HistLamLamMeanMinDistPioReal(0),f2HistLamProMeanMinDistProReal(0),f2HistALamALamMeanMinDistAProReal(0), 
280   // f2HistALamALamMeanMinDistPioReal(0),f2HistALamAProMeanMinDistAProReal(0),
281   // f2HistSftLamLamMeanMinDistProReal(0),
282   // f2HistSftLamLamMeanMinDistPioReal(0),f2HistSftLamProMeanMinDistProReal(0),f2HistSftALamALamMeanMinDistAProReal(0), 
283   // f2HistSftALamALamMeanMinDistPioReal(0),f2HistSftALamAProMeanMinDistAProReal(0),
284   // f2HistSftIrocLamLamMeanMinDistProReal(0),
285   // f2HistSftIrocLamLamMeanMinDistPioReal(0),f2HistSftIrocLamProMeanMinDistProReal(0),f2HistSftIrocALamALamMeanMinDistAProReal(0), 
286   // f2HistSftIrocALamALamMeanMinDistPioReal(0),f2HistSftIrocALamAProMeanMinDistAProReal(0),
287   // f2HistSftOrocLamLamMeanMinDistProReal(0),
288   // f2HistSftOrocLamLamMeanMinDistPioReal(0),f2HistSftOrocLamProMeanMinDistProReal(0),f2HistSftOrocALamALamMeanMinDistAProReal(0), 
289   // f2HistSftOrocALamALamMeanMinDistPioReal(0),f2HistSftOrocALamAProMeanMinDistAProReal(0),
290   // f2HistMtLamLamReal(0), 
291   f2HistMtLamProReal(0), 
292   // f2HistMtALamALamReal(0), 
293   f2HistMtALamAProReal(0),
294   // f2HistMtLowQLamLamReal(0), 
295   f2HistMtLowQLamProReal(0), 
296   // f2HistMtLowQALamALamReal(0), 
297   f2HistMtLowQALamAProReal(0),
298   LamProReal(0),ALamAProReal(0),
299   // f3HistLamLamQinvReal(0),               
300   // f3HistALamALamQinvReal(0),f3HistLamLamMinvReal(0),               
301   // f3HistLamProMinvReal(0),f3HistALamALamMinvReal(0),f3HistALamAProMinvReal(0),
302   // f2HistBgLamBgLamMeanMinDistProReal(0),f2HistBgLamBgLamMeanMinDistPioReal(0),
303   // f2HistBgLamProMeanMinDistProReal(0),f2HistBgALamBgALamMeanMinDistAProReal(0),
304   // f2HistBgALamBgALamMeanMinDistPioReal(0),f2HistBgALamAProMeanMinDistAProReal(0),
305   // f2HistSftBgLamBgLamMeanMinDistProReal(0),f2HistSftBgLamBgLamMeanMinDistPioReal(0),
306   // f2HistSftBgLamProMeanMinDistProReal(0),f2HistSftBgALamBgALamMeanMinDistAProReal(0),
307   // f2HistSftBgALamBgALamMeanMinDistPioReal(0),f2HistSftBgALamAProMeanMinDistAProReal(0),
308   // f2HistSftIrocBgLamBgLamMeanMinDistProReal(0),f2HistSftIrocBgLamBgLamMeanMinDistPioReal(0),
309   // f2HistSftIrocBgLamProMeanMinDistProReal(0),f2HistSftIrocBgALamBgALamMeanMinDistAProReal(0),
310   // f2HistSftIrocBgALamBgALamMeanMinDistPioReal(0),f2HistSftIrocBgALamAProMeanMinDistAProReal(0),
311   // f2HistSftOrocBgLamBgLamMeanMinDistProReal(0),f2HistSftOrocBgLamBgLamMeanMinDistPioReal(0),
312   // f2HistSftOrocBgLamProMeanMinDistProReal(0),f2HistSftOrocBgALamBgALamMeanMinDistAProReal(0),
313   // f2HistSftOrocBgALamBgALamMeanMinDistPioReal(0),f2HistSftOrocBgALamAProMeanMinDistAProReal(0),
314   BgLamProReal(0),BgALamAProReal(0),
315   // f3HistBgLamBgLamQinvReal(0),             
316   // f3HistBgALamBgALamQinvReal(0),
317   // f2HistLamLamMeanMinDistProMixed(0),f2HistLamLamMeanMinDistPioMixed(0),
318   // f2HistLamProMeanMinDistProMixed(0),f2HistALamALamMeanMinDistAProMixed(0),   
319   // f2HistALamALamMeanMinDistPioMixed(0),f2HistALamAProMeanMinDistAProMixed(0),
320   // f2HistSftLamLamMeanMinDistProMixed(0),f2HistSftLamLamMeanMinDistPioMixed(0),
321   // f2HistSftLamProMeanMinDistProMixed(0),f2HistSftALamALamMeanMinDistAProMixed(0),   
322   // f2HistSftALamALamMeanMinDistPioMixed(0),f2HistSftALamAProMeanMinDistAProMixed(0),
323   // f2HistSftIrocLamLamMeanMinDistProMixed(0),f2HistSftIrocLamLamMeanMinDistPioMixed(0),
324   // f2HistSftIrocLamProMeanMinDistProMixed(0),f2HistSftIrocALamALamMeanMinDistAProMixed(0),   
325   // f2HistSftIrocALamALamMeanMinDistPioMixed(0),f2HistSftIrocALamAProMeanMinDistAProMixed(0),
326   // f2HistSftOrocLamLamMeanMinDistProMixed(0),f2HistSftOrocLamLamMeanMinDistPioMixed(0),
327   // f2HistSftOrocLamProMeanMinDistProMixed(0),f2HistSftOrocALamALamMeanMinDistAProMixed(0),   
328   // f2HistSftOrocALamALamMeanMinDistPioMixed(0),f2HistSftOrocALamAProMeanMinDistAProMixed(0),
329   LamProMixed(0),ALamAProMixed(0),
330   // f3HistLamLamQinvMixed(0),                
331   // f3HistALamALamQinvMixed(0),f3HistLamLamMinvMixed(0),                
332   // f3HistLamProMinvMixed(0),f3HistALamALamMinvMixed(0),f3HistALamAProMinvMixed(0),
333   // f2HistBgLamBgLamMeanMinDistProMixed(0),f2HistBgLamBgLamMeanMinDistPioMixed(0),
334   // f2HistBgLamProMeanMinDistProMixed(0),f2HistBgALamBgALamMeanMinDistAProMixed(0),
335   // f2HistBgALamBgALamMeanMinDistPioMixed(0),f2HistBgALamAProMeanMinDistAProMixed(0),
336   // f2HistSftBgLamBgLamMeanMinDistProMixed(0),f2HistSftBgLamBgLamMeanMinDistPioMixed(0),
337   // f2HistSftBgLamProMeanMinDistProMixed(0),f2HistSftBgALamBgALamMeanMinDistAProMixed(0),
338   // f2HistSftBgALamBgALamMeanMinDistPioMixed(0),f2HistSftBgALamAProMeanMinDistAProMixed(0),
339   // f2HistSftIrocBgLamBgLamMeanMinDistProMixed(0),f2HistSftIrocBgLamBgLamMeanMinDistPioMixed(0),
340   // f2HistSftIrocBgLamProMeanMinDistProMixed(0),f2HistSftIrocBgALamBgALamMeanMinDistAProMixed(0),
341   // f2HistSftIrocBgALamBgALamMeanMinDistPioMixed(0),f2HistSftIrocBgALamAProMeanMinDistAProMixed(0),
342   // f2HistSftOrocBgLamBgLamMeanMinDistProMixed(0),f2HistSftOrocBgLamBgLamMeanMinDistPioMixed(0),
343   // f2HistSftOrocBgLamProMeanMinDistProMixed(0),f2HistSftOrocBgALamBgALamMeanMinDistAProMixed(0),
344   // f2HistSftOrocBgALamBgALamMeanMinDistPioMixed(0),f2HistSftOrocBgALamAProMeanMinDistAProMixed(0),
345   BgLamProMixed(0),BgALamAProMixed(0)
346   // f3HistBgLamBgLamQinvMixed(0),             
347   // f3HistBgALamBgALamQinvMixed(0)
348 {
349   // Constructor
350   fPrimaryVtxPosition[0]=0;
351   fPrimaryVtxPosition[1]=0;
352   fPrimaryVtxPosition[2]=0;
353
354   // Define output slots only here
355   // Output slot #1 writes into a TList container
356   DefineOutput(1, TList::Class());
357   DefineOutput(2, TList::Class());
358   DefineOutput(3, TList::Class());
359 }
360 //________________________________________________________________________
361 AliAnalysisTaskProtonLambda::~AliAnalysisTaskProtonLambda() {
362   // Destructor, go through the data member and delete them
363
364   // fPIDResponse is just a pointer to the pid response task,
365   // we don't create it so we don't delete it. It comes from 
366   // the AliInputEventHandler
367
368   if (fTpcResponse){
369     delete fTpcResponse;
370     fTpcResponse=0;
371   }
372   if(fFemtoBuffer){
373     delete fFemtoBuffer;
374     fFemtoBuffer=0;
375   }
376   // fAOD also just comes from a function of the AliAnalysisTaskSE
377   // fPrimaryVtx comes from the fAOD
378
379   // The lists containing the histograms
380   if (fOutputList){
381     fOutputList->Delete();
382     delete fOutputList;
383     fOutputList=0;
384   }
385   if (fOutputPrimaries){
386     fOutputPrimaries->Delete();
387     delete fOutputPrimaries;
388     fOutputPrimaries=0;
389   }
390   if (fOutput2Part){
391     fOutput2Part->Delete();
392     delete fOutput2Part;
393     fOutput2Part=0;
394   }
395
396   // Array, note the [] with the delete
397   if (fGTI)
398     delete[] fGTI;
399   fGTI=0;
400
401 }
402 //________________________________________________________________________
403 void AliAnalysisTaskProtonLambda::UserCreateOutputObjects()
404 {
405   // Create histograms and other objects and variables
406   // Called once
407
408   // Get the PID response object
409   AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
410   if(!man){AliError("Couldn't get the analysis manager!");}
411   AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
412   if(!inputHandler){AliError("Couldn't get the input handler!");}
413   fPIDResponse = inputHandler->GetPIDResponse();
414   if(!fPIDResponse){AliError("Couldn't get the PID response task!");}
415
416   // Create dE/dx spectra cut. use it by calling
417   // fTpcResponse->GetExpectedSignal(mom, AliPID::kProton)
418   fTpcResponse = new AliTPCPIDResponse();
419   Double_t AlephParameters[5];
420   // They are only valid for data, see $ALICE_ROOT/PWG2/SPECTRA/AliProtonAnalysisBase.cxx
421   // for monte carlo parameters
422   AlephParameters[0] = 0.0283086;
423   AlephParameters[1] = 2.63394e+01;
424   AlephParameters[2] = 5.04114e-11;
425   AlephParameters[3] = 2.12543e+00;
426   AlephParameters[4] = 4.88663e+00;
427   fTpcResponse->SetBetheBlochParameters(AlephParameters[0],AlephParameters[1],AlephParameters[2],AlephParameters[3],AlephParameters[4]);
428   
429   // Create the buffer for event mixing
430   // Standard values are
431   //  fkZvertexBins(10),
432   //  fkCentBins(10),
433   //  fkMixBuff(5),
434   //  fkPriTrackLim(100),
435   //  fkV0Lim(50),
436   //  fFemtoBuffer = new FemtoBuffer(10,10,5,100,50,fkAbsZvertexCut,fkCentCut);
437   fFemtoBuffer = new FemtoBuffer(4,2,7,100,50,fkAbsZvertexCut,fkCentCut);
438
439   // In AODs, TPC only tracks don't have the pid information stored.
440   // Also, the TPC only tracks don't have any resolution in the DCAxy
441   // to distinguish between primaries and secondaries so we need the
442   // corresponding global track for every TPC only track. The way to do 
443   // this is to just store the pointer to the global track for every id.
444   fGTI = new AliAODTrack *[fTrackBuffSize]; // Array of pointers 
445
446   // Create the output list
447   fOutputList = new TList();
448   fOutputList->SetOwner();
449   fOutputPrimaries = new TList();
450   fOutputPrimaries->SetOwner();
451   fOutput2Part = new TList();
452   fOutput2Part->SetOwner();
453
454   // Invariant mass binning for lambdas
455   const Int_t nMinvBins = 140;
456   const Float_t minvLowEdge=1.060683, minvHiEdge=1.200683;
457
458   // Control hist for event cuts
459   fHistGoodEvent = new TH1F("h1GoodEvent","No of events passing the cuts.",10,-.5,9.5);
460   fOutputList->Add(fHistGoodEvent);
461
462   // Primary Vertex:
463   // fHistPrimaryVertexPosXY       = new TH2F("h2PrimaryVertexPosXY", "Primary Vertex Position XY;Primary Vertex Position X (cm);Primary Vertex Position Y (cm)",100,-0.5,0.5,100,-0.5,0.5);
464   // fOutputList->Add(fHistPrimaryVertexPosXY);
465   // fHistPrimaryVertexPosZ       = new TH1F("h1PrimaryVertexPosZ", "Primary Vertex Position Z;Primary Vertex Position Z (cm);Events",200,-12.0,12.0);
466   // fOutputList->Add(fHistPrimaryVertexPosZ);
467
468   // // Multiplicity
469   // fHistTrackMultiplicity = new TH1F("fHistTrackMultiplicity", "Multiplicity distribution;Number of tracks;Events", 200, 0, 40000);
470   // fOutputList->Add(fHistTrackMultiplicity);
471
472   // //
473   // //  V0 histograms
474   // //
475   // // Shared clusters
476   // fHistShareV0pos = new TH1F("h1ShareV0pos","Shared clusters pos V0 daughters;#shared clusters;counts"
477   //                         ,160,0,160);
478   // fOutputList->Add(fHistShareV0pos);
479   // fHistShareV0neg = new TH1F("h1ShareV0neg","Shared clusters neg V0 daughters;#shared clusters;counts"
480   //                         ,160,0,160);
481   // fOutputList->Add(fHistShareV0neg);
482   
483   // // PID via TPC dE/dx
484   // fHistPosTpcBeforeCut = new TH2F ("h2PosTpcBeforeCut","TPC signal (pos daughter) before cut;momentum (GeV/c);TPC signal",40,0,4,100,0,400);
485   // fOutputList->Add(fHistPosTpcBeforeCut);
486   // fHistPosTpcAfterCut  = new TH2F ("h2PosTpcAfterCut","TPC signal (pos daughter) after cut;momentum (GeV/c);TPC signal",40,0,4,100,0,400);
487   // fOutputList->Add(fHistPosTpcAfterCut);
488   // fHistNegTpcBeforeCut = new TH2F ("h2NegTpcBeforeCut","TPC signal (neg daughter) before cut;momentum (GeV/c);TPC signal",40,0,4,100,0,400);
489   // fOutputList->Add(fHistNegTpcBeforeCut);
490   // fHistNegTpcAfterCut  = new TH2F ("h2NegTpcAfterCut","TPC signal (neg daughter) after cut;momentum (GeV/c);TPC signal",40,0,4,100,0,400);
491   // fOutputList->Add(fHistNegTpcAfterCut);
492
493   // // Histograms comparing offline and on-the-fly
494   // fHistGoodV0                  = new TH2F("h2GoodV0","0: all, 1: two daughters, 2: like-sign, 3: 80 clusters4: tpcrefit;id;Status",10,-.5,9.5,2,-.5,1.5);
495   // fOutputList->Add(fHistGoodV0);
496   // fHistCorrectSigns            = new TH2F ("h2CorrectSigns","0: correct, 1: swapped, 2: like-sign;sign;Status",3,-.5,2.5,2,-.5,1.5);
497   // fOutputList->Add(fHistCorrectSigns);
498   // fHistDcaPosToPrimVertex      = new TH2F("h2DcaPosToPrimVertex", "Positive V0 daughter;dca(cm);Status",500,0,5,2,-0.5,1.5);
499   // fOutputList->Add(fHistDcaPosToPrimVertex);
500   // fHistDcaNegToPrimVertex      = new TH2F("h2DcaNegToPrimVertex", "Negative V0 daughter;dca(cm);Status",500,0,5,2,-0.5,1.5);
501   // fOutputList->Add(fHistDcaNegToPrimVertex);
502   // fHistDcaPosToPrimVertexZoom  = new TH2F("h2DcaPosToPrimVertexZoom", "Positive V0 daughter;dca(cm);Status",100,0,0.1,2,-0.5,1.5);
503   // fOutputList->Add(fHistDcaPosToPrimVertexZoom);
504   // fHistDcaNegToPrimVertexZoom  = new TH2F("h2DcaNegToPrimVertexZoom", "Negative V0 daughter;dca(cm);Status",100,0,0.1,2,-0.5,1.5);
505   // fOutputList->Add(fHistDcaNegToPrimVertexZoom);
506   // fHistRadiusV0                = new TH2F("h2RadiusV0", "Radius;Radius(cm);Status",1000,0,100,2,-0.5,1.5);
507   // fOutputList->Add(fHistRadiusV0);
508   // fHistDecayLengthV0           = new TH2F("h2DecayLengthV0", "V0s decay Length;decay length(cm);Status", 200, 0, 100,2,-0.5,1.5);
509   // fOutputList->Add(fHistDecayLengthV0);
510   // fHistDcaV0Daughters          = new TH2F("h2DcaV0Daughters", "DCA between daughters;dca(cm);Status", 160, 0, 4,2,-0.5,1.5);
511   // fOutputList->Add(fHistDcaV0Daughters);
512   // fHistChi2                    = new TH2F("h2Chi2", "V0s chi2;chi2;Status", 12, 0, 1.2,2,-0.5,1.5);
513   // fOutputList->Add(fHistChi2);
514   // fHistCosPointAngle           = new TH2F("h2CosPointAngle", "Cosine of V0's pointing angle", 100,0,1,2,-0.5,1.5);
515   // fOutputList->Add(fHistCosPointAngle);
516   // fHistCosPointAngleZoom       = new TH2F("h2CosPointAngleZoom", "Cosine of V0's pointing angle", 100,0.9,1,2,-0.5,1.5);
517   // fOutputList->Add(fHistCosPointAngleZoom);
518
519   //
520   // V0 offline distributons
521   //
522   
523   // Invariant mass distribution for the side band background
524   fHistSideBandOffLam = new TH1F ("h1SideBandOffLam","m_{inv}(#Lambda) w/o any cuts;m_{inv}(#Lambda)",nMinvBins,minvLowEdge,minvHiEdge);
525   fOutputList->Add(fHistSideBandOffLam);
526   fHistSideBandOffALam  = new TH1F ("h1SideBandOffALam","m_{inv}(#bar{#Lambda}) w/o any cuts;m_{inv}(#bar{#Lambda})",nMinvBins,minvLowEdge,minvHiEdge);
527   fOutputList->Add(fHistSideBandOffALam);
528
529   // Number of TPC clusters
530   fHistTPCNclsPosOffLam = new TH2F ("h2MassLamOffTPCNclsPos","m_{inv}(#Lambda) vs NTPCcls(pos);NTPCcls(pos);minv",18,0,180,nMinvBins,minvLowEdge,minvHiEdge);
531   fOutputList->Add(fHistTPCNclsPosOffLam);
532   fHistTPCNclsNegOffLam = new TH2F ("h2MassLamOffTPCNclsNeg","m_{inv}(#Lambda) vs NTPCcls(neg);NTPCcls(neg);minv",18,0,180,nMinvBins,minvLowEdge,minvHiEdge);
533   fOutputList->Add(fHistTPCNclsNegOffLam);
534   fHistTPCNclsPosOffALam = new TH2F ("h2MassALamOffTPCNclsPos","m_{inv}(#bar{#Lambda}) vs NTPCcls(pos);NTPCcls(pos);minv",18,0,180,nMinvBins,minvLowEdge,minvHiEdge);
535   fOutputList->Add(fHistTPCNclsPosOffALam);
536   fHistTPCNclsNegOffALam = new TH2F ("h2MassALamOffTPCNclsNeg","m_{inv}(#bar{#Lambda}) vs NTPCcls(neg);NTPCcls(neg);minv",18,0,180,nMinvBins,minvLowEdge,minvHiEdge);
537   fOutputList->Add(fHistTPCNclsNegOffALam);
538
539   // fHistPosNsigmaTpcOffLam  = new TH2F ("h2PosNsigmaTpcOffLam","minv vs nsigma tpc pos;Nsigma TPC;m_{inv}",50,0,5,nMinvBins,minvLowEdge,minvHiEdge);
540   // fOutputList->Add(fHistPosNsigmaTpcOffLam);
541   // fHistPosNsigmaTpcOffALam = new TH2F ("h2PosNsigmaTpcOffALam","minv vs nsigma tpc pos;Nsigma TPC;m_{inv}",50,0,5,nMinvBins,minvLowEdge,minvHiEdge);        
542   // fOutputList->Add(fHistPosNsigmaTpcOffALam);
543   // fHistNegNsigmaTpcOffLam  = new TH2F ("h2NegNsigmaTpcOffLam","minv vs nsigma tpc pos;Nsigma TPC;m_{inv}",50,0,5,nMinvBins,minvLowEdge,minvHiEdge);        
544   // fOutputList->Add(fHistNegNsigmaTpcOffLam);
545   // fHistNegNsigmaTpcOffALam = new TH2F ("h2NegNsigmaTpcOffALam","minv vs nsigma tpc pos;Nsigma TPC;m_{inv}",50,0,5,nMinvBins,minvLowEdge,minvHiEdge);        
546   // fOutputList->Add(fHistNegNsigmaTpcOffALam);
547   // fHistUseTofOffLam   = new TH2F ("h2UseTofOffLam","0: no tof or within 5sigma, 1: tof more than 5sigma;m_{inv};TOF",2,-.5,1.5,nMinvBins,minvLowEdge,minvHiEdge);        
548   // fOutputList->Add(fHistUseTofOffLam);
549   // fHistUseTofOffALam  = new TH2F ("h2UseTofOffALam","0: no tof or within 5sigma, 1: tof more than 5sigma;m_{inv};TOF",2,-.5,1.5,nMinvBins,minvLowEdge,minvHiEdge);        
550   // fOutputList->Add(fHistUseTofOffALam);
551
552   // // DCA of daughters to primary vertex
553   // fHistDcaPosOffLam = new TH2F ("h2DcaPosOffLam","m_{inv}(#Lambda) vs dca pos daughter;dca (cm);m_{inv}(p#pi^{-})",50,0,0.5,nMinvBins,minvLowEdge,minvHiEdge);
554   // fOutputList->Add(fHistDcaPosOffLam);
555   // fHistDcaPosOffALam = new TH2F ("h2DcaPosOffALam","m_{inv}(#bar{#Lambda}) vs dca pos daughter;dca (cm);m_{inv}(#bar{p}#pi^{+})",50,0,0.5,nMinvBins,minvLowEdge,minvHiEdge);
556   // fOutputList->Add(fHistDcaPosOffALam);
557   // fHistDcaNegOffLam = new TH2F ("h2DcaNegOffLam","m_{inv}(#Lambda) vs dca neg daughter;dca (cm);m_{inv}(p#pi^{-})",50,0,0.5,nMinvBins,minvLowEdge,minvHiEdge);
558   // fOutputList->Add(fHistDcaNegOffLam);
559   // fHistDcaNegOffALam = new TH2F ("h2DcaNegOffALam","m_{inv}(#bar{#Lambda}) vs dca neg daughter;dca (cm);m_{inv}(#bar{p}#pi^{+})",50,0,0.5,nMinvBins,minvLowEdge,minvHiEdge);
560   // fOutputList->Add(fHistDcaNegOffALam);
561
562   // // DCA of V0 daughters
563   // fHistDcaV0DaughtersOffLam = new TH2F ("h2DcaLamDaughtersOff","DCA of #Lambda daughters vs minv;dca(cm);minv",20,0,2,nMinvBins,minvLowEdge,minvHiEdge);
564   // fOutputList->Add(fHistDcaV0DaughtersOffLam);
565   // fHistDcaV0DaughtersOffALam = new TH2F ("h2DcaALamDaughtersOff","DCA of #bar{#Lambda} daughters vs minv;dca(cm);minv",20,0,2,nMinvBins,minvLowEdge,minvHiEdge);
566   // fOutputList->Add(fHistDcaV0DaughtersOffALam);
567
568   // // Cosine of pointing angle
569   // fHistCosPointLamOff = new TH2F ("h2CosPointLamOff","m_{inv}(#Lambda) vs cos(pointing angle);cos(pointing angle);m_{inv}(#Lambda)",10,0.99,1.0,nMinvBins,minvLowEdge,minvHiEdge);
570   // fOutputList->Add(fHistCosPointLamOff);
571   // fHistCosPointALamOff = new TH2F ("h2CosPointALamOff","m_{inv}(#bar{#Lambda}) vs cos(pointing angle);cos(pointing angle);m_{inv}(#bar{#Lambda})",10,0.99,1.0,nMinvBins,minvLowEdge,minvHiEdge);
572   // fOutputList->Add(fHistCosPointALamOff);
573   // fHistCosPointLamZoomOff = new TH2F ("h2CosPointLamZoomOff","m_{inv}(#Lambda) vs cos(pointing angle);cos(pointing angle);m_{inv}(#Lambda)",10,0.999,1.0,nMinvBins,minvLowEdge,minvHiEdge);
574   // fOutputList->Add(fHistCosPointLamZoomOff);
575   // fHistCosPointALamZoomOff = new TH2F ("h2CosPointALamZoomOff","m_{inv}(#bar{#Lambda}) vs cos(pointing angle);cos(pointing angle);m_{inv}(#bar{#Lambda})",10,0.999,1.0,nMinvBins,minvLowEdge,minvHiEdge);
576   // fOutputList->Add(fHistCosPointALamZoomOff);
577
578   // // Radius of V0 vertex position
579   // fHistV0RadiusLamOff = new TH2F ("h2V0RadiusLamOff","m_{inv}(#Lambda) vs V0 radius of V0 vertex;radius(cm);m_{inv}",20,0,10,nMinvBins,minvLowEdge,minvHiEdge);
580   // fOutputList->Add(fHistV0RadiusLamOff);
581   // fHistV0RadiusALamOff = new TH2F ("h2V0RadiusALamOff","m_{inv}(#bar{#Lambda}) vs V0 radius of V0 vertex;radius(cm);m_{inv}",20,0,10,nMinvBins,minvLowEdge,minvHiEdge);
582   // fOutputList->Add(fHistV0RadiusALamOff);
583
584   // // Decay length of V0
585   // fHistV0DecayLengthLamOff = new TH2F ("h2V0DecayLengthLamOff","m_{inv}(#Lambda) vs decay length of V0;decay length (cm);m_{inv}(#Lambda)",100,0,20,nMinvBins,minvLowEdge,minvHiEdge);
586   // fOutputList->Add(fHistV0DecayLengthLamOff);
587   // fHistV0DecayLengthALamOff = new TH2F ("h2V0DecayLengthALamOff","m_{inv}(#bar{#Lambda}) vs decay length of V0;decay length (cm);m_{inv}(#bar{#Lambda})",100,0,20,nMinvBins,minvLowEdge,minvHiEdge);
588   // fOutputList->Add(fHistV0DecayLengthALamOff);
589
590   // // DCA of primary vertex and V0
591   // fHistDcaV0PriVertexLamOff = new TH2F ("h2DcaV0PriVertexLamOff","m_{inv}(#Lambda) vs dca (V0 - prim. vertex);dca(cm);m_{inv}(#Lambda)",200,0,20,nMinvBins,minvLowEdge,minvHiEdge);
592   // fOutputList->Add(fHistDcaV0PriVertexLamOff);
593   // fHistDcaV0PriVertexALamOff = new TH2F ("h2DcaV0PriVertexALamOff","m_{inv}(#bar{#Lambda}) vs dca (V0 - prim. vertex);dca(cm);m_{inv}(#bar{#Lambda})",200,0,20,nMinvBins,minvLowEdge,minvHiEdge);
594   // fOutputList->Add(fHistDcaV0PriVertexALamOff);
595
596   // Invariant mass, invariant mass vs pt and y-pt
597   fHistMassLambdaOff            = new TH1F("h1MassLambdaOff", "#Lambda^{0} Offline candidates;M(p#pi^{-}) (GeV/c^{2});Counts", nMinvBins, minvLowEdge, minvHiEdge);
598   fOutputList->Add(fHistMassLambdaOff);
599   fHistMassAntiLambdaOff          = new TH1F("h1MassAntiLambdaOff", "#bar{#Lambda}^{0} Offline candidates;M(#bar{p}#pi^{+}) (GeV/c^{2});Counts", nMinvBins, minvLowEdge, minvHiEdge);
600   fOutputList->Add(fHistMassAntiLambdaOff);
601   // fHistPtVsMassLambdaOff         = new TH2F("h2PtVsMassLambdaOff","#Lambda^{0} Offline candidates;p_{t} (GeV/c);M(p#pi^{-}) (GeV/c^{2})",100,0,10,nMinvBins, minvLowEdge, minvHiEdge);
602   // fOutputList->Add(fHistPtVsMassLambdaOff);
603   // fHistPtVsMassAntiLambdaOff     = new TH2F("h2PtVsMassAntiLambdaOff","#bar{#Lambda}^{0} Offline candidates;p_{t} (GeV/c);M(#bar{p}#pi^{+}) (GeV/c^{2})",100,0,10,nMinvBins, minvLowEdge, minvHiEdge);
604   // fOutputList->Add(fHistPtVsMassAntiLambdaOff);
605   // fHistPtVsYLambdaOff          = new TH2F("h2PtVsYLambdaOff", "#Lambda^{0} Offline candidates;p_{t} (GeV/c);rapidity",30,0,15,30,-1.5,1.5);
606   // fOutputList->Add(fHistPtVsYLambdaOff);
607   // fHistPtVsYAntiLambdaOff      = new TH2F("h2PtVsYAntiLambdaOff", "#bar{#Lambda}^{0} Offline candidates;p_{t} (GeV/c);rapidity",30,0,15,30,-1.5,1.5);
608   // fOutputList->Add(fHistPtVsYAntiLambdaOff);
609
610     // 3d y pt mass
611   fHistYPtMassLamOff = new TH3F ("h3YPtMassLamOff","m_{inv}(#Lambda) vs y and pt;y;pt;mass",30,-1.5,1.5,30,0,15,nMinvBins,minvLowEdge,minvHiEdge);
612   fOutputList->Add(fHistYPtMassLamOff);
613   fHistYPtMassALamOff = new TH3F ("h3YPtMassALamOff","m_{inv}(#bar{#Lambda}) vs y and pt;y;pt;mass",30,-1.5,1.5,30,0,15,nMinvBins,minvLowEdge,minvHiEdge);
614   fOutputList->Add(fHistYPtMassALamOff);
615
616   //
617   // V0 on-the-fly distributons
618   //
619   
620   // Invariant mass distribution for the side band background
621   fHistSideBandOnLam = new TH1F ("h1SideBandOnLam","m_{inv}(#Lambda) w/o any cuts;m_{inv}(#Lambda)",nMinvBins,minvLowEdge,minvHiEdge);
622   fOutputList->Add(fHistSideBandOnLam);
623   fHistSideBandOnALam  = new TH1F ("h1SideBandOnALam","m_{inv}(#bar{#Lambda}) w/o any cuts;m_{inv}(#bar{#Lambda})",nMinvBins,minvLowEdge,minvHiEdge);
624   fOutputList->Add(fHistSideBandOnALam);
625   
626   // // Like-sign
627   // fHistLikeSignOnLam = new TH2F ("h2MassLamOnLikeSign"," 0 = ok, 1 = swapped, 2 = like sign;sign;m_{inv} p#pi^{-}",3,-.5,2.5,nMinvBins,minvLowEdge,minvHiEdge);
628   // fOutputList->Add(fHistLikeSignOnLam);
629   // fHistLikeSignOnALam = new TH2F ("h2MassALamOnLikeSign"," 0 = ok, 1 = swapped, 2= like sign;sign;m_{inv} #bar{p}#pi^{+}",3,-.5,2.5,nMinvBins,minvLowEdge,minvHiEdge);
630   // fOutputList->Add(fHistLikeSignOnALam);
631
632   // Number of TPC clusters
633   fHistTPCNclsPosOnLam = new TH2F ("h2MassLamOnTPCNclsPos","m_{inv}(#Lambda) vs NTPCcls(pos);NTPCcls(pos);minv",18,0,180,nMinvBins,minvLowEdge,minvHiEdge);
634   fOutputList->Add(fHistTPCNclsPosOnLam);
635   fHistTPCNclsNegOnLam = new TH2F ("h2MassLamOnTPCNclsNeg","m_{inv}(#Lambda) vs NTPCcls(neg);NTPCcls(neg);minv",18,0,180,nMinvBins,minvLowEdge,minvHiEdge);
636   fOutputList->Add(fHistTPCNclsNegOnLam);
637   fHistTPCNclsPosOnALam = new TH2F ("h2MassALamOnTPCNclsPos","m_{inv}(#bar{#Lambda}) vs NTPCcls(pos);NTPCcls(pos);minv",18,0,180,nMinvBins,minvLowEdge,minvHiEdge);
638   fOutputList->Add(fHistTPCNclsPosOnALam);
639   fHistTPCNclsNegOnALam = new TH2F ("h2MassALamOnTPCNclsNeg","m_{inv}(#bar{#Lambda}) vs NTPCcls(neg);NTPCcls(neg);minv",18,0,180,nMinvBins,minvLowEdge,minvHiEdge);
640   fOutputList->Add(fHistTPCNclsNegOnALam);
641
642 //  fHistPosNsigmaTpcOnLam  = new TH2F ("h2PosNsigmaTpcOnLam","minv vs nsigma tpc pos;Nsigma TPC;m_{inv}",50,0,5,nMinvBins,minvLowEdge,minvHiEdge);
643 //   fOutputList->Add(fHistPosNsigmaTpcOnLam);
644 //   fHistPosNsigmaTpcOnALam = new TH2F ("h2PosNsigmaTpcOnALam","minv vs nsigma tpc pos;Nsigma TPC;m_{inv}",50,0,5,nMinvBins,minvLowEdge,minvHiEdge);        
645 //   fOutputList->Add(fHistPosNsigmaTpcOnALam);
646 //   fHistNegNsigmaTpcOnLam  = new TH2F ("h2NegNsigmaTpcOnLam","minv vs nsigma tpc pos;Nsigma TPC;m_{inv}",50,0,5,nMinvBins,minvLowEdge,minvHiEdge);        
647 //   fOutputList->Add(fHistNegNsigmaTpcOnLam);
648 //   fHistNegNsigmaTpcOnALam = new TH2F ("h2NegNsigmaTpcOnALam","minv vs nsigma tpc pos;Nsigma TPC;m_{inv}",50,0,5,nMinvBins,minvLowEdge,minvHiEdge);        
649 //   fOutputList->Add(fHistNegNsigmaTpcOnALam);
650 //   fHistUseTofOnLam   = new TH2F ("h2UseTofOnLam","0: no tof or within 5sigma, 1: tof more than 5sigma;m_{inv};TOF",2,-.5,1.5,nMinvBins,minvLowEdge,minvHiEdge);        
651 //   fOutputList->Add(fHistUseTofOnLam);
652 //   fHistUseTofOnALam  = new TH2F ("h2UseTofOnALam","0: no tof or within 5sigma, 1: tof more than 5sigma;m_{inv};TOF",2,-.5,1.5,nMinvBins,minvLowEdge,minvHiEdge);        
653 //   fOutputList->Add(fHistUseTofOnALam);
654
655 //   // DCA of daughters to primary vertex
656 //   fHistDcaPosOnLam = new TH2F ("h2DcaPosOnLam","m_{inv}(#Lambda) vs dca pos daughter;dca (cm);m_{inv}(p#pi^{-})",50,0,0.5,nMinvBins,minvLowEdge,minvHiEdge);
657 //   fOutputList->Add(fHistDcaPosOnLam);
658 //   fHistDcaPosOnALam = new TH2F ("h2DcaPosOnALam","m_{inv}(#bar{#Lambda}) vs dca pos daughter;dca (cm);m_{inv}(#bar{p}#pi^{+})",50,0,0.5,nMinvBins,minvLowEdge,minvHiEdge);
659 //   fOutputList->Add(fHistDcaPosOnALam);
660 //   fHistDcaNegOnLam = new TH2F ("h2DcaNegOnLam","m_{inv}(#Lambda) vs dca neg daughter;dca (cm);m_{inv}(p#pi^{-})",50,0,0.5,nMinvBins,minvLowEdge,minvHiEdge);
661 //   fOutputList->Add(fHistDcaNegOnLam);
662 //   fHistDcaNegOnALam = new TH2F ("h2DcaNegOnALam","m_{inv}(#bar{#Lambda}) vs dca neg daughter;dca (cm);m_{inv}(#bar{p}#pi^{+})",50,0,0.5,nMinvBins,minvLowEdge,minvHiEdge);
663 //   fOutputList->Add(fHistDcaNegOnALam);
664
665 //   // DCA of V0 daughters
666 //   fHistDcaV0DaughtersOnLam = new TH2F ("h2DcaLamDaughtersOn","DCA of #Lambda daughters vs minv;dca(cm);minv",20,0,2,nMinvBins,minvLowEdge,minvHiEdge);
667 //   fOutputList->Add(fHistDcaV0DaughtersOnLam);
668 //   fHistDcaV0DaughtersOnALam = new TH2F ("h2DcaALamDaughtersOn","DCA of #bar{#Lambda} daughters vs minv;dca(cm);minv",20,0,2,nMinvBins,minvLowEdge,minvHiEdge);
669 //   fOutputList->Add(fHistDcaV0DaughtersOnALam);
670
671 // // Cosine of pointing angle
672 //   fHistCosPointLamOn = new TH2F ("h2CosPointLamOn","m_{inv}(#Lambda) vs cos(pointing angle);cos(pointing angle);m_{inv}(#Lambda)",10,0.99,1.0,nMinvBins,minvLowEdge,minvHiEdge);
673 //   fOutputList->Add(fHistCosPointLamOn);
674 //   fHistCosPointALamOn = new TH2F ("h2CosPointALamOn","m_{inv}(#bar{#Lambda}) vs cos(pointing angle);cos(pointing angle);m_{inv}(#bar{#Lambda})",10,0.99,1.0,nMinvBins,minvLowEdge,minvHiEdge);
675 //   fOutputList->Add(fHistCosPointALamOn);
676 //   fHistCosPointLamZoomOn = new TH2F ("h2CosPointLamZoomOn","m_{inv}(#Lambda) vs cos(pointing angle);cos(pointing angle);m_{inv}(#Lambda)",10,0.999,1.0,nMinvBins,minvLowEdge,minvHiEdge);
677 //   fOutputList->Add(fHistCosPointLamZoomOn);
678 //   fHistCosPointALamZoomOn = new TH2F ("h2CosPointALamZoomOn","m_{inv}(#bar{#Lambda}) vs cos(pointing angle);cos(pointing angle);m_{inv}(#bar{#Lambda})",10,0.999,1.0,nMinvBins,minvLowEdge,minvHiEdge);
679 //   fOutputList->Add(fHistCosPointALamZoomOn);
680
681 //   // Radius of V0 vertex position
682 //   fHistV0RadiusLamOn = new TH2F ("h2V0RadiusLamOn","m_{inv}(#Lambda) vs V0 radius of V0 vertex;radius(cm);m_{inv}",20,0,10,nMinvBins,minvLowEdge,minvHiEdge);
683 //   fOutputList->Add(fHistV0RadiusLamOn);
684 //   fHistV0RadiusALamOn = new TH2F ("h2V0RadiusALamOn","m_{inv}(#bar{#Lambda}) vs V0 radius of V0 vertex;radius(cm);m_{inv}",20,0,10,nMinvBins,minvLowEdge,minvHiEdge);
685 //   fOutputList->Add(fHistV0RadiusALamOn);
686
687 //   // Decay length of V0
688 //   fHistV0DecayLengthLamOn = new TH2F ("h2V0DecayLengthLamOn","m_{inv}(#Lambda) vs decay length of V0;decay length (cm);m_{inv}(#Lambda)",100,0,20,nMinvBins,minvLowEdge,minvHiEdge);
689 //   fOutputList->Add(fHistV0DecayLengthLamOn);
690 //   fHistV0DecayLengthALamOn = new TH2F ("h2V0DecayLengthALamOn","m_{inv}(#bar{#Lambda}) vs decay length of V0;decay length (cm);m_{inv}(#bar{#Lambda})",100,0,20,nMinvBins,minvLowEdge,minvHiEdge);
691 //   fOutputList->Add(fHistV0DecayLengthALamOn);
692
693 //   // DCA of primary vertex and V0
694 //   fHistDcaV0PriVertexLamOn = new TH2F ("h2DcaV0PriVertexLamOn","m_{inv}(#Lambda) vs dca (V0 - prim. vertex);dca(cm);m_{inv}(#Lambda)",200,0,20,nMinvBins,minvLowEdge,minvHiEdge);
695 //   fOutputList->Add(fHistDcaV0PriVertexLamOn);
696 //   fHistDcaV0PriVertexALamOn = new TH2F ("h2DcaV0PriVertexALamOn","m_{inv}(#bar{#Lambda}) vs dca (V0 - prim. vertex);dca(cm);m_{inv}(#bar{#Lambda})",200,0,20,nMinvBins,minvLowEdge,minvHiEdge);
697 //   fOutputList->Add(fHistDcaV0PriVertexALamOn);
698
699 //   // Chi2 of TPC clusters
700 //   fHistChi2TPCPosLamOn = new TH2F ("h2Chi2TPCPosLamOn","m_{inv}(#Lambda) vs TPC #Chi^{2} / ndf pos daughter;TPC #Chi^{2}/ndf pos daughter;m_{inv}(#Lambda)",100,0.,10.,nMinvBins,minvLowEdge,minvHiEdge);
701 //   fOutputList->Add(fHistChi2TPCPosLamOn);
702 //   fHistChi2TPCPosALamOn = new TH2F ("h2Chi2TPCPosALamOn","m_{inv}(#bar{#Lambda}) vs TPC #Chi^{2} / ndf pos daughter;TPC #Chi^{2}/ndf pos daughter;m_{inv}(#bar{#Lambda})",100,0.,10.,nMinvBins,minvLowEdge,minvHiEdge);
703 //   fOutputList->Add(fHistChi2TPCPosALamOn);
704 //   fHistChi2TPCNegLamOn = new TH2F ("h2Chi2TPCNegLamOn","m_{inv}(#Lambda) vs TPC #Chi^{2} / ndf neg daughter;TPC #Chi^{2}/ndf neg daughter;m_{inv}(#Lambda)",100,0.,10.,nMinvBins,minvLowEdge,minvHiEdge);
705 //   fOutputList->Add(fHistChi2TPCNegLamOn);
706 //   fHistChi2TPCNegALamOn = new TH2F ("h2Chi2TPCNegALamOn","m_{inv}(#bar{#Lambda}) vs TPC #Chi^{2} / ndf neg daughter;TPC #Chi^{2}/ndf neg daughter;m_{inv}(#bar{#Lambda})",100,0.,10.,nMinvBins,minvLowEdge,minvHiEdge);
707 //   fOutputList->Add(fHistChi2TPCNegALamOn);
708 //   // Invariant mass with TPC only tracks
709 //   fHistMinvTPConlyLamOn = new TH1F ("h1MinvTPConlyLamOn","m_{inv}(#Lambda) using TPC only daughters;m_{inv}(p#pi^{-})[GeV/c^{2}]",nMinvBins,minvLowEdge,minvHiEdge);
710 //   fOutputList->Add(fHistMinvTPConlyLamOn);
711 //   fHistMinvTPConlyALamOn = new TH1F ("h1MinvTPConlyALamOn","m_{inv}(#bar{#Lambda}) using TPC only daughters;m_{inv}(#bar{p}#pi^{+})[GeV/c^{2}]",nMinvBins,minvLowEdge,minvHiEdge);
712 //   fOutputList->Add(fHistMinvTPConlyALamOn);
713
714   // Invariant mass, invariant mass vs pt and y-pt
715   fHistMassLambdaOn            = new TH1F("h1MassLambdaOn", "#Lambda^{0} Online candidates;M(p#pi^{-}) (GeV/c^{2});Counts", nMinvBins, minvLowEdge, minvHiEdge);
716   fOutputList->Add(fHistMassLambdaOn);
717   fHistMassAntiLambdaOn          = new TH1F("h1MassAntiLambdaOn", "#bar{#Lambda}^{0} Online candidates;M(#bar{p}#pi^{+}) (GeV/c^{2});Counts", nMinvBins, minvLowEdge, minvHiEdge);
718   fOutputList->Add(fHistMassAntiLambdaOn);
719   // fHistPtVsMassLambdaOn         = new TH2F("h2PtVsMassLambdaOn","#Lambda^{0} Online candidates;p_{t} (GeV/c);M(p#pi^{-}) (GeV/c^{2})",100,0,10,nMinvBins, minvLowEdge, minvHiEdge);
720   // fOutputList->Add(fHistPtVsMassLambdaOn);
721   // fHistPtVsMassAntiLambdaOn     = new TH2F("h2PtVsMassAntiLambdaOn","#bar{#Lambda}^{0} Online candidates;p_{t} (GeV/c);M(#bar{p}#pi^{+}) (GeV/c^{2})",100,0,10,nMinvBins, minvLowEdge, minvHiEdge);
722   // fOutputList->Add(fHistPtVsMassAntiLambdaOn);
723   // fHistPtVsYLambdaOn          = new TH2F("h2PtVsYLambdaOn", "#Lambda^{0} Online candidates;p_{t} (GeV/c);rapidity",30,0,15,30,-1.5,1.5);
724   // fOutputList->Add(fHistPtVsYLambdaOn);
725   // fHistPtVsYAntiLambdaOn      = new TH2F("h2PtVsYAntiLambdaOn", "#bar{#Lambda}^{0} Online candidates;p_{t} (GeV/c);rapidity",30,0,15,30,-1.5,1.5);
726   // fOutputList->Add(fHistPtVsYAntiLambdaOn);
727
728   // 3d y pt mass
729   fHistYPtMassLamOn = new TH3F ("h3YPtMassLamOn","m_{inv}(#Lambda) vs y and pt;y;pt;mass",30,-1.5,1.5,30,0,15,nMinvBins,minvLowEdge,minvHiEdge);
730   fOutputList->Add(fHistYPtMassLamOn);
731   fHistYPtMassALamOn = new TH3F ("h3YPtMassALamOn","m_{inv}(#bar{#Lambda}) vs y and pt;y;pt;mass",30,-1.5,1.5,30,0,15,nMinvBins,minvLowEdge,minvHiEdge);
732   fOutputList->Add(fHistYPtMassALamOn);
733
734   // // Momentum difference of standard (on-the-fly/offline) V0 and TPC only V0
735   // Int_t nPBins=200; Float_t AbsPRange=1.;
736   // fHistMomDiffLam = new TH3F ("h3MomDiffLam","momentum difference #DeltaP standard V0 / TPConly V0 #Lambda;#DeltaP_{x}[GeV/c];#DeltaP_{y}[GeV/c];#DeltaP_{z}[GeV/c]"
737   //                          ,nPBins,-AbsPRange,AbsPRange
738   //                          ,nPBins,-AbsPRange,AbsPRange
739   //                          ,nPBins,-AbsPRange,AbsPRange);
740   // fOutputList->Add(fHistMomDiffLam);
741   // fHistMomDiffALam = new TH3F ("h3MomDiffALam","momentum difference #DeltaP standard V0 / TPConly V0 #bar{#Lamdba};#DeltaP_{x}[GeV/c];#DeltaP_{y}[GeV/c];#DeltaP_{z}[GeV/c]"
742   //                           ,nPBins,-AbsPRange,AbsPRange
743   //                           ,nPBins,-AbsPRange,AbsPRange
744   //                           ,nPBins,-AbsPRange,AbsPRange);
745   // fOutputList->Add(fHistMomDiffALam);
746   // fHistMomDiffBgLam = new TH3F ("h3MomDiffBgLam","momentum difference #DeltaP standard V0 / TPConly V0 Bg#Lambda;#DeltaP_{x}[GeV/c];#DeltaP_{y}[GeV/c];#DeltaP_{z}[GeV/c]"
747   //                            ,nPBins,-AbsPRange,AbsPRange
748   //                            ,nPBins,-AbsPRange,AbsPRange
749   //                            ,nPBins,-AbsPRange,AbsPRange);
750   // fOutputList->Add(fHistMomDiffBgLam);
751   // fHistMomDiffBgALam = new TH3F ("h3MomDiffBgALam","momentum difference #DeltaP standard V0 / TPConly V0 Bg#bar{#Lambda};#DeltaP_{x}[GeV/c];#DeltaP_{y}[GeV/c];#DeltaP_{z}[GeV/c]"
752   //                             ,nPBins,-AbsPRange,AbsPRange
753   //                             ,nPBins,-AbsPRange,AbsPRange
754   //                             ,nPBins,-AbsPRange,AbsPRange);
755   // fOutputList->Add(fHistMomDiffBgALam);
756
757   // // Same momentum difference with rejecting tracks with SPD hits
758   // fHistMomDiffWoSPDLam = new TH3F ("h3MomDiffWoSPDLam","momentum difference #DeltaP standard V0 / TPConly V0 #Lambda;#DeltaP_{x}[GeV/c];#DeltaP_{y}[GeV/c];#DeltaP_{z}[GeV/c]"
759   //                          ,nPBins,-AbsPRange,AbsPRange
760   //                          ,nPBins,-AbsPRange,AbsPRange
761   //                          ,nPBins,-AbsPRange,AbsPRange);
762   // fOutputList->Add(fHistMomDiffWoSPDLam);
763   // fHistMomDiffWoSPDALam = new TH3F ("h3MomDiffWoSPDALam","momentum difference #DeltaP standard V0 / TPConly V0 #bar{#Lamdba};#DeltaP_{x}[GeV/c];#DeltaP_{y}[GeV/c];#DeltaP_{z}[GeV/c]"
764   //                           ,nPBins,-AbsPRange,AbsPRange
765   //                           ,nPBins,-AbsPRange,AbsPRange
766   //                           ,nPBins,-AbsPRange,AbsPRange);
767   // fOutputList->Add(fHistMomDiffWoSPDALam);
768   // fHistMomDiffWoSPDBgLam = new TH3F ("h3MomDiffWoSPDBgLam","momentum difference #DeltaP standard V0 / TPConly V0 Bg#Lambda;#DeltaP_{x}[GeV/c];#DeltaP_{y}[GeV/c];#DeltaP_{z}[GeV/c]"
769   //                            ,nPBins,-AbsPRange,AbsPRange
770   //                            ,nPBins,-AbsPRange,AbsPRange
771   //                            ,nPBins,-AbsPRange,AbsPRange);
772   // fOutputList->Add(fHistMomDiffWoSPDBgLam);
773   // fHistMomDiffWoSPDBgALam = new TH3F ("h3MomDiffWoSPDBgALam","momentum difference #DeltaP standard V0 / TPConly V0 Bg#bar{#Lambda};#DeltaP_{x}[GeV/c];#DeltaP_{y}[GeV/c];#DeltaP_{z}[GeV/c]"
774   //                             ,nPBins,-AbsPRange,AbsPRange
775   //                             ,nPBins,-AbsPRange,AbsPRange
776   //                             ,nPBins,-AbsPRange,AbsPRange);
777   // fOutputList->Add(fHistMomDiffWoSPDBgALam);
778
779   //
780   // Distributions for the primaries 
781   //
782   // Shared clusters
783   fPriHistShare = new TH1F ("h1PriShare","Shared clusters, primaries;#shared clusters;counts",
784                             160,0,160);
785   fOutputPrimaries->Add(fPriHistShare);
786
787   // Nsigma TOF distribution when forcing TOF
788   // fPriHistPosNsigmaTof = new TH1F ("h1PosNsigmaTof","Nsigma distribution for positives;n_{#sigma,TOF}(proton);counts",200,-50,50);
789   // fOutputPrimaries->Add(fPriHistPosNsigmaTof);
790   fPriHistPosNsigmaTofVsP = new TH2F ("h2PosNsigmaTofVsP","Nsigma distribution for positives;total momentum [GeV/c];n_{#sigma,TOF}(proton);counts",20,0,5,200,-50,50);
791   fOutputPrimaries->Add(fPriHistPosNsigmaTofVsP);
792   fPriHistPosNsigmaTofVsPt   = new TH2F ("h2PosNsigmaTofVsPt","Nsigma distribution for positives;transverse momentum [GeV/c];n_{#sigma,TOF}(proton);counts",20,0,5,200,-50,50);
793   fOutputPrimaries->Add(fPriHistPosNsigmaTofVsPt);
794
795   // fPriHistNegNsigmaTof = new TH1F ("h1NegNsigmaTof","Nsigma distribution for negatives;n_{#sigma,TOF}(anti-proton);counts",200,-50,50);
796   // fOutputPrimaries->Add(fPriHistNegNsigmaTof);
797   fPriHistNegNsigmaTofVsP = new TH2F ("h2NegNsigmaTofVsP","Nsigma distribution for negatives;total momentum [GeV/c];n_{#sigma,TOF}(anti-proton);counts",20,0,5,200,-50,50);
798   fOutputPrimaries->Add(fPriHistNegNsigmaTofVsP);
799   fPriHistNegNsigmaTofVsPt   = new TH2F ("h2NegNsigmaTofVsPt","Nsigma distribution for negatives;transverse momentum [GeV/c];n_{#sigma,TOF}(anti-proton);counts",20,0,5,200,-50,50);
800   fOutputPrimaries->Add(fPriHistNegNsigmaTofVsPt);
801   fPriHistTOFsignalPosVsP = new TH2F ("h2TOFsignalPosVsP","tof signal vs p (positives);p [GeV/c];t_{meas} - t_{0} - t_{expected} [ps]",20,0.0,5.0,120,-10000.0,5000.0);
802   fOutputPrimaries->Add(fPriHistTOFsignalPosVsP);
803   fPriHistTOFsignalPosVsPt = new TH2F ("h2TOFsignalPosVsPt","tof signal vs pt (positives);pt [GeV/c];t_{meas} - t_{0} - t_{expected} [ps]",20,0.0,5.0,120,-10000.0,5000.0);
804   fOutputPrimaries->Add(fPriHistTOFsignalPosVsPt);
805   fPriHistTOFsignalNegVsP = new TH2F ("h2TOFsignalNegVsP","tof signal vs p (negatives);p [GeV/c];t_{meas} - t_{0} - t_{expected} [ps]",20,0.0,5.0,120,-10000.0,5000.0);
806   fOutputPrimaries->Add(fPriHistTOFsignalNegVsP);
807   fPriHistTOFsignalNegVsPt = new TH2F ("h2TOFsignalNegVsPt","tof signal vs pt (negatives);pt [GeV/c];t_{meas} - t_{0} - t_{expected} [ps]",20,0.0,5.0,120,-10000.0,5000.0);
808   fOutputPrimaries->Add(fPriHistTOFsignalNegVsPt);
809   // Hybrid analysis
810   fPriHistHybridTOFsigPosWoTPC = new TH1F ("h1HybridTOFsigPosWoTPC","tof signal pos (p=.75-1.0GeV) w/o dedx sel.;t_{meas} - t_{0} - t_{expected} [ps]",120,-10000.0,5000.0);
811   fOutputPrimaries->Add(fPriHistHybridTOFsigPosWoTPC);
812   fPriHistHybridTOFsigPosTPCok = new TH1F ("h1HybridTOFsigPosTPCok","tof signal pos (p=.75-1.0GeV) with dedx sel.;t_{meas} - t_{0} - t_{expected} [ps]",120,-10000.0,5000.0);
813   fOutputPrimaries->Add(fPriHistHybridTOFsigPosTPCok);
814   fPriHistHybridTOFsigNegWoTPC = new TH1F ("h1HybridTOFsigNegWoTPC","tof signal neg (p=.75-1.0GeV) w/o dedx sel.;t_{meas} - t_{0} - t_{expected} [ps]",120,-10000.0,5000.0);
815   fOutputPrimaries->Add(fPriHistHybridTOFsigNegWoTPC);
816   fPriHistHybridTOFsigNegTPCok = new TH1F ("h1HybridTOFsigNegTPCok","tof signal neg (p=.75-1.0GeV) with dedx sel.;t_{meas} - t_{0} - t_{expected} [ps]",120,-10000.0,5000.0);
817   fOutputPrimaries->Add(fPriHistHybridTOFsigNegTPCok);
818   // dEdx analysis
819   // fPriHistHasTofPos = new TH1F ("h1HasTofPos","Positives: 0 = no TOF, 1 = TOFpid bit there",2,-.5,1.5);
820   // fOutputPrimaries->Add(fPriHistHasTofPos);
821   fPriHistTPCsignalPos = new TH2F ("h2TPCsignalPos","TPC signal for positives;p_{tot};dEdx",40,0,4,100,0,400);
822   fOutputPrimaries->Add(fPriHistTPCsignalPos);
823   // fPriHistNsigmaTPCPos = new TH2F ("h2NsigmaTPCPos","Nsigma TPC for positives;p_{tot};N_{#sigma}",40,0,4,100,-5.0,5.0);
824   // fOutputPrimaries->Add(fPriHistNsigmaTPCPos);
825   // fPriHistTPCsignalTOFcutPos = new TH2F ("h2TPCsignalTOFcutPos","TPC signal for positives using a +/- 10sigma TOF cut;p_{tot};dEdx",40,0.0,4.0,100,0.0,400.0);
826   // fOutputPrimaries->Add(fPriHistTPCsignalTOFcutPos);
827   // fPriHistNsigmaTPCTOFcutPos = new TH2F ("h2NsigmaTPCTOFcutPos","Nsigma TPC for positives using a +/- 10sigma TOF cut;p_{tot};N_{#sigma}",40,0.0,4.0,100,-5.0,5.0);
828   // fOutputPrimaries->Add(fPriHistNsigmaTPCTOFcutPos);
829
830   // fPriHistHasTofNeg = new TH1F ("h1HasTofNeg","Negatives: 0 = no TOF, 1 = TOFpid bit there",2,-.5,1.5);
831   // fOutputPrimaries->Add(fPriHistHasTofNeg);
832   fPriHistTPCsignalNeg = new TH2F ("h2TPCsignalNeg","TPC signal for negatives;p_{tot};dEdx",40,0.0,4.0,100,0.0,400.0);
833   fOutputPrimaries->Add(fPriHistTPCsignalNeg);
834   // fPriHistNsigmaTPCNeg = new TH2F ("h2NsigmaTPCNeg","Nsigma TPC for negatives;p_{tot};N_{#sigma}",40,0.0,4.0,100,-5.0,5.0);
835   // fOutputPrimaries->Add(fPriHistNsigmaTPCNeg);
836   // fPriHistTPCsignalTOFcutNeg = new TH2F ("h2TPCsignalTOFcutNeg","TPC signal for negatives using a +/- 10sigma TOF cut;p_{tot};dEdx",40,0.0,4.0,100,0.0,400.0);
837   // fOutputPrimaries->Add(fPriHistTPCsignalTOFcutNeg);
838   // fPriHistNsigmaTPCTOFcutNeg = new TH2F ("h2NsigmaTPCTOFcutNeg","Nsigma TPC for negatives using a +/- 10sigma TOF cut;p_{tot};N_{#sigma}",40,0.0,4.0,100,-5.0,5.0);
839   // fOutputPrimaries->Add(fPriHistNsigmaTPCTOFcutNeg);  
840
841   fPriHistTPCsignalLowPPos = new TH2F ("h2TPCsignalLowPPos","dEdx for low momenta, positives",20,0.1,0.3,3000,0,3000);
842   fOutputPrimaries->Add(fPriHistTPCsignalLowPPos);
843   fPriHistTPCsignalMedPPos = new TH2F ("h2TPCsignalMedPPos","dEdx for medium momenta, positives",60,0.3,0.9,500,0,500);
844   fOutputPrimaries->Add(fPriHistTPCsignalMedPPos);
845   fPriHistTPCsignalHigPPos = new TH2F ("h2TPCsignalHigPPos","dEdx for high momenta, positives",100,0.9,1.9,120,0,120);
846   fOutputPrimaries->Add(fPriHistTPCsignalHigPPos);
847   fPriHistTPCsignalLowPNeg = new TH2F ("h2TPCsignalLowPNeg","dEdx for low momenta, negatives",20,0.1,0.3,3000,0,3000);
848   fOutputPrimaries->Add(fPriHistTPCsignalLowPNeg);
849   fPriHistTPCsignalMedPNeg = new TH2F ("h2TPCsignalMedPNeg","dEdx for medium momenta, negatives",60,0.3,0.9,500,0,500);
850   fOutputPrimaries->Add(fPriHistTPCsignalMedPNeg);
851   fPriHistTPCsignalHigPNeg = new TH2F ("h2TPCsignalHigPNeg","dEdx for high momenta, negatives",100,0.9,1.9,120,0,120);
852   fOutputPrimaries->Add(fPriHistTPCsignalHigPNeg);
853   
854   //  Common for all protons
855
856   // DCA xy distribution to determine primaries, secondaries from weak decay and secondaries from material
857   fPriHistDCAxyYPtPro = new TH3F ("h3DCAxyYPtPro","DCAxy vs (y,pt) protons",100,-3.,3.,30,-1.5,1.5,14,0.,3.5);
858   fOutputPrimaries->Add(fPriHistDCAxyYPtPro);
859   fPriHistDCAxyYPtAPro = new TH3F ("h3DCAxyYPtAPro","DCAxy vs (y,pt) anti-protons",100,-3.,3.,30,-1.5,1.5,14,0.,3.5);
860   fOutputPrimaries->Add(fPriHistDCAxyYPtAPro);
861
862   //  2 particle histograms fOutput2Part
863   // Common binning for TTR
864   Int_t nDistBins=200;
865   Float_t distLow=0.,distHig=20.;
866   //  Two-track resolution: real events
867   // f2HistLamLamMeanMinDistProReal = new TH2F ("h2LamLamMeanMinDistProReal","#Lambda#Lambda Mean vs min dist of decay protons;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
868   // fOutput2Part->Add(f2HistLamLamMeanMinDistProReal);
869   // f2HistLamLamMeanMinDistPioReal = new TH2F ("h2LamLamMeanMinDistPioReal","#Lambda#Lambda Mean vs min dist of decay pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
870   // fOutput2Part->Add(f2HistLamLamMeanMinDistPioReal);
871   // f2HistLamProMeanMinDistProReal = new TH2F ("h2LamProMeanMinDistProReal","p#Lambda Mean vs min dist of pri. p - dec p;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
872   // fOutput2Part->Add(f2HistLamProMeanMinDistProReal);
873   // f2HistALamALamMeanMinDistAProReal = new TH2F ("h2ALamALamMeanMinDistAProReal","#bar{#Lambda}#bar{#Lambda} Mean vs min dist decay #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
874   // fOutput2Part->Add(f2HistALamALamMeanMinDistAProReal);
875   // f2HistALamALamMeanMinDistPioReal = new TH2F ("h2ALamALamMeanMinDistPioReal","#bar{#Lambda}#bar{#Lambda} Mean vs min dist of dec. pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
876   // fOutput2Part->Add(f2HistALamALamMeanMinDistPioReal);
877   // f2HistALamAProMeanMinDistAProReal = new TH2F ("h2ALamAProMeanMinDistProReal","#bar{p}#bar{#Lambda} Mean vs min dist of pri. #bar{p} - dec #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
878   // fOutput2Part->Add(f2HistALamAProMeanMinDistAProReal);
879
880   // f2HistSftLamLamMeanMinDistProReal = new TH2F ("h2SftLamLamMeanMinDistProReal","#Lambda#Lambda Mean vs min dist of decay protons;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
881   // fOutput2Part->Add(f2HistSftLamLamMeanMinDistProReal);
882   // f2HistSftLamLamMeanMinDistPioReal = new TH2F ("h2SftLamLamMeanMinDistPioReal","#Lambda#Lambda Mean vs min dist of decay pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
883   // fOutput2Part->Add(f2HistSftLamLamMeanMinDistPioReal);
884   // f2HistSftLamProMeanMinDistProReal = new TH2F ("h2SftLamProMeanMinDistProReal","p#Lambda Mean vs min dist of pri. p - dec p;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
885   // fOutput2Part->Add(f2HistSftLamProMeanMinDistProReal);
886   // f2HistSftALamALamMeanMinDistAProReal = new TH2F ("h2SftALamALamMeanMinDistAProReal","#bar{#Lambda}#bar{#Lambda} Mean vs min dist decay #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
887   // fOutput2Part->Add(f2HistSftALamALamMeanMinDistAProReal);
888   // f2HistSftALamALamMeanMinDistPioReal = new TH2F ("h2SftALamALamMeanMinDistPioReal","#bar{#Lambda}#bar{#Lambda} Mean vs min dist of dec. pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
889   // fOutput2Part->Add(f2HistSftALamALamMeanMinDistPioReal);
890   // f2HistSftALamAProMeanMinDistAProReal = new TH2F ("h2SftALamAProMeanMinDistProReal","#bar{p}#bar{#Lambda} Mean vs min dist of pri. #bar{p} - dec #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
891   // fOutput2Part->Add(f2HistSftALamAProMeanMinDistAProReal);
892
893   // f2HistSftIrocLamLamMeanMinDistProReal = new TH2F ("h2SftIrocLamLamMeanMinDistProReal","#Lambda#Lambda Mean vs min dist of decay protons;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
894   // fOutput2Part->Add(f2HistSftIrocLamLamMeanMinDistProReal);
895   // f2HistSftIrocLamLamMeanMinDistPioReal = new TH2F ("h2SftIrocLamLamMeanMinDistPioReal","#Lambda#Lambda Mean vs min dist of decay pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
896   // fOutput2Part->Add(f2HistSftIrocLamLamMeanMinDistPioReal);
897   // f2HistSftIrocLamProMeanMinDistProReal = new TH2F ("h2SftIrocLamProMeanMinDistProReal","p#Lambda Mean vs min dist of pri. p - dec p;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
898   // fOutput2Part->Add(f2HistSftIrocLamProMeanMinDistProReal);
899   // f2HistSftIrocALamALamMeanMinDistAProReal = new TH2F ("h2SftIrocALamALamMeanMinDistAProReal","#bar{#Lambda}#bar{#Lambda} Mean vs min dist decay #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
900   // fOutput2Part->Add(f2HistSftIrocALamALamMeanMinDistAProReal);
901   // f2HistSftIrocALamALamMeanMinDistPioReal = new TH2F ("h2SftIrocALamALamMeanMinDistPioReal","#bar{#Lambda}#bar{#Lambda} Mean vs min dist of dec. pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
902   // fOutput2Part->Add(f2HistSftIrocALamALamMeanMinDistPioReal);
903   // f2HistSftIrocALamAProMeanMinDistAProReal = new TH2F ("h2SftIrocALamAProMeanMinDistProReal","#bar{p}#bar{#Lambda} Mean vs min dist of pri. #bar{p} - dec #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
904   // fOutput2Part->Add(f2HistSftIrocALamAProMeanMinDistAProReal);
905
906   // f2HistSftOrocLamLamMeanMinDistProReal = new TH2F ("h2SftOrocLamLamMeanMinDistProReal","#Lambda#Lambda Mean vs min dist of decay protons;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
907   // fOutput2Part->Add(f2HistSftOrocLamLamMeanMinDistProReal);
908   // f2HistSftOrocLamLamMeanMinDistPioReal = new TH2F ("h2SftOrocLamLamMeanMinDistPioReal","#Lambda#Lambda Mean vs min dist of decay pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
909   // fOutput2Part->Add(f2HistSftOrocLamLamMeanMinDistPioReal);
910   // f2HistSftOrocLamProMeanMinDistProReal = new TH2F ("h2SftOrocLamProMeanMinDistProReal","p#Lambda Mean vs min dist of pri. p - dec p;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
911   // fOutput2Part->Add(f2HistSftOrocLamProMeanMinDistProReal);
912   // f2HistSftOrocALamALamMeanMinDistAProReal = new TH2F ("h2SftOrocALamALamMeanMinDistAProReal","#bar{#Lambda}#bar{#Lambda} Mean vs min dist decay #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
913   // fOutput2Part->Add(f2HistSftOrocALamALamMeanMinDistAProReal);
914   // f2HistSftOrocALamALamMeanMinDistPioReal = new TH2F ("h2SftOrocALamALamMeanMinDistPioReal","#bar{#Lambda}#bar{#Lambda} Mean vs min dist of dec. pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
915   // fOutput2Part->Add(f2HistSftOrocALamALamMeanMinDistPioReal);
916   // f2HistSftOrocALamAProMeanMinDistAProReal = new TH2F ("h2SftOrocALamAProMeanMinDistProReal","#bar{p}#bar{#Lambda} Mean vs min dist of pri. #bar{p} - dec #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
917   // fOutput2Part->Add(f2HistSftOrocALamAProMeanMinDistAProReal);
918   
919   // Mt of the pairs
920   Int_t nMtBins=25;
921   Float_t mtLow=1.0,mtHig=3.5;
922   // f2HistMtLamLamReal = new TH1F("h1MtLamLamReal"
923   //                            ,"m_{t}(#Lambda #Lambda);m{t} [GeV];counts"
924   //                            ,nMtBins,mtLow,mtHig);
925   // fOutput2Part->Add(f2HistMtLamLamReal);
926   f2HistMtLamProReal = new TH1F("h1MtLamProReal"
927                                 ,"m_{t}(p #Lambda);m{t} [GeV];counts"
928                                 ,nMtBins,mtLow,mtHig);
929   fOutput2Part->Add(f2HistMtLamProReal);
930   // f2HistMtALamALamReal = new TH1F("h1MtALamALamReal"
931   //                              ,"m_{t}(#bar{#Lambda} #bar{#Lambda});m{t} [GeV];counts"
932   //                              ,nMtBins,mtLow,mtHig);
933   // fOutput2Part->Add(f2HistMtALamALamReal);
934   f2HistMtALamAProReal  = new TH1F("h1MtALamAProReal"
935                                    ,"m_{t}(#bar{#Lambda} #bar{#Lambda});m{t} [GeV];counts"
936                                    ,nMtBins,mtLow,mtHig);
937   fOutput2Part->Add(f2HistMtALamAProReal);
938   // The same only filling for low q pairs
939   // f2HistMtLowQLamLamReal = new TH1F("h1MtLowQLamLamReal"
940   //                            ,"m_{t}(#Lambda #Lambda);m{t} [GeV];counts"
941   //                            ,nMtBins,mtLow,mtHig);
942   // fOutput2Part->Add(f2HistMtLowQLamLamReal);
943   f2HistMtLowQLamProReal = new TH1F("h1MtLowQLamProReal"
944                                 ,"m_{t}(p #Lambda);m{t} [GeV];counts"
945                                 ,nMtBins,mtLow,mtHig);
946   fOutput2Part->Add(f2HistMtLowQLamProReal);
947   // f2HistMtLowQALamALamReal = new TH1F("h1MtLowQALamALamReal"
948   //                              ,"m_{t}(#bar{#Lambda} #bar{#Lambda});m{t} [GeV];counts"
949   //                              ,nMtBins,mtLow,mtHig);
950   // fOutput2Part->Add(f2HistMtLowQALamALamReal);
951   f2HistMtLowQALamAProReal  = new TH1F("h1MtLowQALamAProReal"
952                                    ,"m_{t}(#bar{#Lambda} #bar{#Lambda});m{t} [GeV];counts"
953                                    ,nMtBins,mtLow,mtHig);
954   fOutput2Part->Add(f2HistMtLowQALamAProReal);
955
956   // Common qinv binning
957   Int_t nQinvBins = 400; // also for minv
958   Float_t QinvLow = 0.0;
959   Float_t QinvHig = 2.5;
960
961   // Sept'12 Use a THnSparse for (Bg)(A)Lam(A)Pro with 4 dimensions:
962   // qinv (ppri,ppri), mean dist (ppri,ppri), min dist(ppri,ppri)
963   // qinv (lam pro)
964   Int_t HnSpBins[4]={nQinvBins,nDistBins,nDistBins,nQinvBins};
965   Double_t HnSpMin[4]={QinvLow,distLow,distLow,QinvLow};
966   Double_t HnSpMax[4]={QinvHig,distHig,distHig,QinvHig};
967   LamProReal = new THnSparseF("HnSp4LamProReal","lamProRealQppMeanMinQlamp"
968                               ,4,HnSpBins,HnSpMin,HnSpMax);
969   fOutput2Part->Add(LamProReal);
970   ALamAProReal = new THnSparseF("HnSp4ALamAProReal","alamAProRealQppMeanMinQlamp"
971                               ,4,HnSpBins,HnSpMin,HnSpMax);
972   fOutput2Part->Add(ALamAProReal);
973
974   // Qinv: real events
975   // Since March 4th 2012 do corr. fcts vs distances
976   // f3HistLamLamQinvReal = new TH3F ("h3LamLamQinvReal", "Qinv LamLam;q_{inv} [GeV/c];min(d) p [cm];min(d) #pi [cm]"
977   //                               ,nQinvBins,QinvLow,QinvHig,100,0.,10.,100,0.,10.);
978   // fOutput2Part->Add(f3HistLamLamQinvReal);
979   // f3HistALamALamQinvReal = new TH3F ("h3ALamALamQinvReal", "Qinv ALamALam;q_{inv} [GeV/c];min(d) #bar{p} [cm];min (d) #pi [cm]"
980   //                                 ,nQinvBins,QinvLow,QinvHig,100,0.,10.,100,0.,10.);
981   // fOutput2Part->Add(f3HistALamALamQinvReal);
982   // // minv (H2 dibaryon??)
983   // f3HistLamLamMinvReal = new TH3F ("h3LamLamMinvReal", "Minv LamLam;q_{inv} [GeV/c];min(d) p [cm];min(d) #pi [cm]"
984   //                               ,nQinvBins,2.0,3.0,100,0.,10.,100,0.,10.);
985   // fOutput2Part->Add(f3HistLamLamMinvReal);
986   // f3HistLamProMinvReal = new TH3F ("h3LamProMinvReal", "Minv LamPro;q_{inv} [GeV/c];<d> p [cm];min(d) p [cm]"
987   //                               ,nQinvBins,2.0,3.0,100,0.,10.,100,0.,10.);
988   // fOutput2Part->Add(f3HistLamProMinvReal);
989   // f3HistALamALamMinvReal = new TH3F ("h3ALamALamMinvReal", "Minv ALamALam;q_{inv} [GeV/c];min(d) #bar{p} [cm];min(d) #pi [cm]"
990   //                                 ,nQinvBins,2.0,3.0,100,0.,10.,100,0.,10.);
991   // fOutput2Part->Add(f3HistALamALamMinvReal);
992   // f3HistALamAProMinvReal = new TH3F ("h3ALamAProMinvReal", "Minv ALamAPro;q_{inv} [GeV/c];<d> #bar{p} [cm];min(d) #bar{p} [cm]"
993   //                                 ,nQinvBins,2.0,3.0,100,0.,10.,100,0.,10.);
994   // fOutput2Part->Add(f3HistALamAProMinvReal);
995   
996   
997   // // Two-track resolution: mixed events
998   // f2HistLamLamMeanMinDistProMixed = new TH2F ("h2LamLamMeanMinDistProMixed","#Lambda#Lambda Mean vs min dist of decay protons;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
999   // fOutput2Part->Add(f2HistLamLamMeanMinDistProMixed);
1000   // f2HistLamLamMeanMinDistPioMixed = new TH2F ("h2LamLamMeanMinDistPioMixed","#Lambda#Lambda Mean vs min dist of decay pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1001   // fOutput2Part->Add(f2HistLamLamMeanMinDistPioMixed);
1002   // f2HistLamProMeanMinDistProMixed = new TH2F ("h2LamProMeanMinDistProMixed","p#Lambda Mean vs min dist of pri. p - dec p;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1003   // fOutput2Part->Add(f2HistLamProMeanMinDistProMixed);
1004   // f2HistALamALamMeanMinDistAProMixed = new TH2F ("h2ALamALamMeanMinDistAProMixed","#bar{#Lambda}#bar{#Lambda} Mean vs min dist decay #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1005   // fOutput2Part->Add(f2HistALamALamMeanMinDistAProMixed);
1006   // f2HistALamALamMeanMinDistPioMixed = new TH2F ("h2ALamALamMeanMinDistPioMixed","#bar{#Lambda}#bar{#Lambda} Mean vs min dist of dec. pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1007   // fOutput2Part->Add(f2HistALamALamMeanMinDistPioMixed);
1008   // f2HistALamAProMeanMinDistAProMixed = new TH2F ("h2ALamAProMeanMinDistProMixed","#bar{p}#bar{#Lambda} Mean vs min dist of pri. #bar{p} - dec #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1009   // fOutput2Part->Add(f2HistALamAProMeanMinDistAProMixed);
1010
1011   // f2HistSftLamLamMeanMinDistProMixed = new TH2F ("h2SftLamLamMeanMinDistProMixed","#Lambda#Lambda Mean vs min dist of decay protons;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1012   // fOutput2Part->Add(f2HistSftLamLamMeanMinDistProMixed);
1013   // f2HistSftLamLamMeanMinDistPioMixed = new TH2F ("h2SftLamLamMeanMinDistPioMixed","#Lambda#Lambda Mean vs min dist of decay pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1014   // fOutput2Part->Add(f2HistSftLamLamMeanMinDistPioMixed);
1015   // f2HistSftLamProMeanMinDistProMixed = new TH2F ("h2SftLamProMeanMinDistProMixed","p#Lambda Mean vs min dist of pri. p - dec p;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1016   // fOutput2Part->Add(f2HistSftLamProMeanMinDistProMixed);
1017   // f2HistSftALamALamMeanMinDistAProMixed = new TH2F ("h2SftALamALamMeanMinDistAProMixed","#bar{#Lambda}#bar{#Lambda} Mean vs min dist decay #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1018   // fOutput2Part->Add(f2HistSftALamALamMeanMinDistAProMixed);
1019   // f2HistSftALamALamMeanMinDistPioMixed = new TH2F ("h2SftALamALamMeanMinDistPioMixed","#bar{#Lambda}#bar{#Lambda} Mean vs min dist of dec. pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1020   // fOutput2Part->Add(f2HistSftALamALamMeanMinDistPioMixed);
1021   // f2HistSftALamAProMeanMinDistAProMixed = new TH2F ("h2SftALamAProMeanMinDistProMixed","#bar{p}#bar{#Lambda} Mean vs min dist of pri. #bar{p} - dec #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1022   // fOutput2Part->Add(f2HistSftALamAProMeanMinDistAProMixed);
1023
1024   // f2HistSftIrocLamLamMeanMinDistProMixed = new TH2F ("h2SftIrocLamLamMeanMinDistProMixed","#Lambda#Lambda Mean vs min dist of decay protons;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1025   // fOutput2Part->Add(f2HistSftIrocLamLamMeanMinDistProMixed);
1026   // f2HistSftIrocLamLamMeanMinDistPioMixed = new TH2F ("h2SftIrocLamLamMeanMinDistPioMixed","#Lambda#Lambda Mean vs min dist of decay pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1027   // fOutput2Part->Add(f2HistSftIrocLamLamMeanMinDistPioMixed);
1028   // f2HistSftIrocLamProMeanMinDistProMixed = new TH2F ("h2SftIrocLamProMeanMinDistProMixed","p#Lambda Mean vs min dist of pri. p - dec p;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1029   // fOutput2Part->Add(f2HistSftIrocLamProMeanMinDistProMixed);
1030   // f2HistSftIrocALamALamMeanMinDistAProMixed = new TH2F ("h2SftIrocALamALamMeanMinDistAProMixed","#bar{#Lambda}#bar{#Lambda} Mean vs min dist decay #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1031   // fOutput2Part->Add(f2HistSftIrocALamALamMeanMinDistAProMixed);
1032   // f2HistSftIrocALamALamMeanMinDistPioMixed = new TH2F ("h2SftIrocALamALamMeanMinDistPioMixed","#bar{#Lambda}#bar{#Lambda} Mean vs min dist of dec. pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1033   // fOutput2Part->Add(f2HistSftIrocALamALamMeanMinDistPioMixed);
1034   // f2HistSftIrocALamAProMeanMinDistAProMixed = new TH2F ("h2SftIrocALamAProMeanMinDistProMixed","#bar{p}#bar{#Lambda} Mean vs min dist of pri. #bar{p} - dec #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1035   // fOutput2Part->Add(f2HistSftIrocALamAProMeanMinDistAProMixed);
1036
1037   // f2HistSftOrocLamLamMeanMinDistProMixed = new TH2F ("h2SftOrocLamLamMeanMinDistProMixed","#Lambda#Lambda Mean vs min dist of decay protons;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1038   // fOutput2Part->Add(f2HistSftOrocLamLamMeanMinDistProMixed);
1039   // f2HistSftOrocLamLamMeanMinDistPioMixed = new TH2F ("h2SftOrocLamLamMeanMinDistPioMixed","#Lambda#Lambda Mean vs min dist of decay pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1040   // fOutput2Part->Add(f2HistSftOrocLamLamMeanMinDistPioMixed);
1041   // f2HistSftOrocLamProMeanMinDistProMixed = new TH2F ("h2SftOrocLamProMeanMinDistProMixed","p#Lambda Mean vs min dist of pri. p - dec p;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1042   // fOutput2Part->Add(f2HistSftOrocLamProMeanMinDistProMixed);
1043   // f2HistSftOrocALamALamMeanMinDistAProMixed = new TH2F ("h2SftOrocALamALamMeanMinDistAProMixed","#bar{#Lambda}#bar{#Lambda} Mean vs min dist decay #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1044   // fOutput2Part->Add(f2HistSftOrocALamALamMeanMinDistAProMixed);
1045   // f2HistSftOrocALamALamMeanMinDistPioMixed = new TH2F ("h2SftOrocALamALamMeanMinDistPioMixed","#bar{#Lambda}#bar{#Lambda} Mean vs min dist of dec. pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1046   // fOutput2Part->Add(f2HistSftOrocALamALamMeanMinDistPioMixed);
1047   // f2HistSftOrocALamAProMeanMinDistAProMixed = new TH2F ("h2SftOrocALamAProMeanMinDistProMixed","#bar{p}#bar{#Lambda} Mean vs min dist of pri. #bar{p} - dec #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1048   // fOutput2Part->Add(f2HistSftOrocALamAProMeanMinDistAProMixed);
1049
1050   // Sept'12 Use a THnSparse for (Bg)(A)Lam(A)Pro with 4 dimensions:
1051   // qinv (ppri,ppri), mean dist (ppri,ppri), min dist(ppri,ppri)
1052   // qinv (lam pro)
1053   LamProMixed = new THnSparseF("HnSp4LamProMixed","lamProMixedQppMeanMinQlamp"
1054                               ,4,HnSpBins,HnSpMin,HnSpMax);
1055   fOutput2Part->Add(LamProMixed);
1056   ALamAProMixed = new THnSparseF("HnSp4ALamAProMixed","alamAProMixedQppMeanMinQlamp"
1057                               ,4,HnSpBins,HnSpMin,HnSpMax);
1058   fOutput2Part->Add(ALamAProMixed);
1059
1060   // // Qinv: mixed events
1061   // f3HistLamLamQinvMixed = new TH3F ("h3LamLamQinvMixed", "Qinv LamLam;q_{inv} [GeV/c];min(d) p [cm];min(d) #pi [cm]"
1062   //                                ,nQinvBins,QinvLow,QinvHig,100,0.,10.,100,0.,10.);
1063   // fOutput2Part->Add(f3HistLamLamQinvMixed);
1064   // f3HistALamALamQinvMixed = new TH3F ("h3ALamALamQinvMixed", "Qinv ALamALam;q_{inv} [GeV/c];min(d) #bar{p} [cm];min(d) #pi [cm]"
1065   //                                  ,nQinvBins,QinvLow,QinvHig,100,0.,10.,100,0.,10.);
1066   // fOutput2Part->Add(f3HistALamALamQinvMixed);
1067   // // minv (H2 di-baryon??)
1068   // f3HistLamLamMinvMixed = new TH3F ("h3LamLamMinvMixed", "Minv LamLam;q_{inv} [GeV/c];min(d) p [cm];min(d) #pi [cm]"
1069   //                                ,nQinvBins,2.0,3.0,100,0.,10.,100,0.,10.);
1070   // fOutput2Part->Add(f3HistLamLamMinvMixed);
1071   // f3HistLamProMinvMixed = new TH3F ("h3LamProMinvMixed", "Minv LamPro;q_{inv} [GeV/c];<d> p [cm];min(d) p [cm]"
1072   //                                ,nQinvBins,2.0,3.0,100,0.,10.,100,0.,10.);
1073   // fOutput2Part->Add(f3HistLamProMinvMixed);
1074   // f3HistALamALamMinvMixed = new TH3F ("h3ALamALamMinvMixed", "Minv ALamALam;q_{inv} [GeV/c];min(d) #bar{p} [cm];min(d) #pi [cm]"
1075   //                                  ,nQinvBins,2.0,3.0,100,0.,10.,100,0.,10.);
1076   // fOutput2Part->Add(f3HistALamALamMinvMixed);
1077   // f3HistALamAProMinvMixed = new TH3F ("h3ALamAProMinvMixed", "Minv ALamAPro;q_{inv} [GeV/c];<d> #bar{p} [cm];min(d) #bar{p} [cm]"
1078   //                                  ,nQinvBins,2.0,3.0,100,0.,10.,100,0.,10.);
1079   // fOutput2Part->Add(f3HistALamAProMinvMixed);
1080
1081   // Same for Background (anti-)lambdas
1082
1083   // // Two-track resolution: real events
1084   // f2HistBgLamBgLamMeanMinDistProReal = new TH2F ("h2BgLamBgLamMeanMinDistProReal","#Lambda#Lambda Mean vs min dist of decay protons;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1085   // fOutput2Part->Add(f2HistBgLamBgLamMeanMinDistProReal);
1086   // f2HistBgLamBgLamMeanMinDistPioReal = new TH2F ("h2BgLamBgLamMeanMinDistPioReal","#Lambda#Lambda Mean vs min dist of decay pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1087   // fOutput2Part->Add(f2HistBgLamBgLamMeanMinDistPioReal);
1088   // f2HistBgLamProMeanMinDistProReal = new TH2F ("h2BgLamProMeanMinDistProReal","p#Lambda Mean vs min dist of pri. p - dec p;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1089   // fOutput2Part->Add(f2HistBgLamProMeanMinDistProReal);
1090   // f2HistBgALamBgALamMeanMinDistAProReal = new TH2F ("h2BgALamBgALamMeanMinDistAProReal","#bar{#Lambda}#bar{#Lambda} Mean vs min dist decay #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1091   // fOutput2Part->Add(f2HistBgALamBgALamMeanMinDistAProReal);
1092   // f2HistBgALamBgALamMeanMinDistPioReal = new TH2F ("h2BgALamBgALamMeanMinDistPioReal","#bar{#Lambda}#bar{#Lambda} Mean vs min dist of dec. pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1093   // fOutput2Part->Add(f2HistBgALamBgALamMeanMinDistPioReal);
1094   // f2HistBgALamAProMeanMinDistAProReal = new TH2F ("h2BgALamAProMeanMinDistProReal","#bar{p}#bar{#Lambda} Mean vs min dist of pri. #bar{p} - dec #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1095   // fOutput2Part->Add(f2HistBgALamAProMeanMinDistAProReal);
1096
1097   // f2HistSftBgLamBgLamMeanMinDistProReal = new TH2F ("h2SftBgLamBgLamMeanMinDistProReal","#Lambda#Lambda Mean vs min dist of decay protons;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1098   // fOutput2Part->Add(f2HistSftBgLamBgLamMeanMinDistProReal);
1099   // f2HistSftBgLamBgLamMeanMinDistPioReal = new TH2F ("h2SftBgLamBgLamMeanMinDistPioReal","#Lambda#Lambda Mean vs min dist of decay pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1100   // fOutput2Part->Add(f2HistSftBgLamBgLamMeanMinDistPioReal);
1101   // f2HistSftBgLamProMeanMinDistProReal = new TH2F ("h2SftBgLamProMeanMinDistProReal","p#Lambda Mean vs min dist of pri. p - dec p;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1102   // fOutput2Part->Add(f2HistSftBgLamProMeanMinDistProReal);
1103   // f2HistSftBgALamBgALamMeanMinDistAProReal = new TH2F ("h2SftBgALamBgALamMeanMinDistAProReal","#bar{#Lambda}#bar{#Lambda} Mean vs min dist decay #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1104   // fOutput2Part->Add(f2HistSftBgALamBgALamMeanMinDistAProReal);
1105   // f2HistSftBgALamBgALamMeanMinDistPioReal = new TH2F ("h2SftBgALamBgALamMeanMinDistPioReal","#bar{#Lambda}#bar{#Lambda} Mean vs min dist of dec. pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1106   // fOutput2Part->Add(f2HistSftBgALamBgALamMeanMinDistPioReal);
1107   // f2HistSftBgALamAProMeanMinDistAProReal = new TH2F ("h2SftBgALamAProMeanMinDistProReal","#bar{p}#bar{#Lambda} Mean vs min dist of pri. #bar{p} - dec #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1108   // fOutput2Part->Add(f2HistSftBgALamAProMeanMinDistAProReal);
1109
1110   // f2HistSftIrocBgLamBgLamMeanMinDistProReal = new TH2F ("h2SftIrocBgLamBgLamMeanMinDistProReal","#Lambda#Lambda Mean vs min dist of decay protons;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1111   // fOutput2Part->Add(f2HistSftIrocBgLamBgLamMeanMinDistProReal);
1112   // f2HistSftIrocBgLamBgLamMeanMinDistPioReal = new TH2F ("h2SftIrocBgLamBgLamMeanMinDistPioReal","#Lambda#Lambda Mean vs min dist of decay pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1113   // fOutput2Part->Add(f2HistSftIrocBgLamBgLamMeanMinDistPioReal);
1114   // f2HistSftIrocBgLamProMeanMinDistProReal = new TH2F ("h2SftIrocBgLamProMeanMinDistProReal","p#Lambda Mean vs min dist of pri. p - dec p;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1115   // fOutput2Part->Add(f2HistSftIrocBgLamProMeanMinDistProReal);
1116   // f2HistSftIrocBgALamBgALamMeanMinDistAProReal = new TH2F ("h2SftIrocBgALamBgALamMeanMinDistAProReal","#bar{#Lambda}#bar{#Lambda} Mean vs min dist decay #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1117   // fOutput2Part->Add(f2HistSftIrocBgALamBgALamMeanMinDistAProReal);
1118   // f2HistSftIrocBgALamBgALamMeanMinDistPioReal = new TH2F ("h2SftIrocBgALamBgALamMeanMinDistPioReal","#bar{#Lambda}#bar{#Lambda} Mean vs min dist of dec. pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1119   // fOutput2Part->Add(f2HistSftIrocBgALamBgALamMeanMinDistPioReal);
1120   // f2HistSftIrocBgALamAProMeanMinDistAProReal = new TH2F ("h2SftIrocBgALamAProMeanMinDistProReal","#bar{p}#bar{#Lambda} Mean vs min dist of pri. #bar{p} - dec #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1121   // fOutput2Part->Add(f2HistSftIrocBgALamAProMeanMinDistAProReal);
1122
1123   // f2HistSftOrocBgLamBgLamMeanMinDistProReal = new TH2F ("h2SftOrocBgLamBgLamMeanMinDistProReal","#Lambda#Lambda Mean vs min dist of decay protons;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1124   // fOutput2Part->Add(f2HistSftOrocBgLamBgLamMeanMinDistProReal);
1125   // f2HistSftOrocBgLamBgLamMeanMinDistPioReal = new TH2F ("h2SftOrocBgLamBgLamMeanMinDistPioReal","#Lambda#Lambda Mean vs min dist of decay pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1126   // fOutput2Part->Add(f2HistSftOrocBgLamBgLamMeanMinDistPioReal);
1127   // f2HistSftOrocBgLamProMeanMinDistProReal = new TH2F ("h2SftOrocBgLamProMeanMinDistProReal","p#Lambda Mean vs min dist of pri. p - dec p;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1128   // fOutput2Part->Add(f2HistSftOrocBgLamProMeanMinDistProReal);
1129   // f2HistSftOrocBgALamBgALamMeanMinDistAProReal = new TH2F ("h2SftOrocBgALamBgALamMeanMinDistAProReal","#bar{#Lambda}#bar{#Lambda} Mean vs min dist decay #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1130   // fOutput2Part->Add(f2HistSftOrocBgALamBgALamMeanMinDistAProReal);
1131   // f2HistSftOrocBgALamBgALamMeanMinDistPioReal = new TH2F ("h2SftOrocBgALamBgALamMeanMinDistPioReal","#bar{#Lambda}#bar{#Lambda} Mean vs min dist of dec. pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1132   // fOutput2Part->Add(f2HistSftOrocBgALamBgALamMeanMinDistPioReal);
1133   // f2HistSftOrocBgALamAProMeanMinDistAProReal = new TH2F ("h2SftOrocBgALamAProMeanMinDistProReal","#bar{p}#bar{#Lambda} Mean vs min dist of pri. #bar{p} - dec #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1134   // fOutput2Part->Add(f2HistSftOrocBgALamAProMeanMinDistAProReal);
1135
1136   // Sept'12 Use a THnSparse for (Bg)(A)Lam(A)Pro with 4 dimensions:
1137   // qinv (ppri,ppri), mean dist (ppri,ppri), min dist(ppri,ppri)
1138   // qinv (lam pro)
1139   BgLamProReal = new THnSparseF("HnSp4BgLamProReal","lamProRealQppMeanMinQlamp"
1140                               ,4,HnSpBins,HnSpMin,HnSpMax);
1141   fOutput2Part->Add(BgLamProReal);
1142   BgALamAProReal = new THnSparseF("HnSp4BgALamAProReal","alamAProRealQppMeanMinQlamp"
1143                               ,4,HnSpBins,HnSpMin,HnSpMax);
1144   fOutput2Part->Add(BgALamAProReal);
1145
1146   // Qinv: real events
1147   // f3HistBgLamBgLamQinvReal = new TH3F ("h3BgLamBgLamQinvReal", "Qinv BgLamBgLam;q_{inv} [GeV/c];min(d) p [cm];min(d) #pi [cm]"
1148   //                                   ,nQinvBins,QinvLow,QinvHig,100,0.,10.,100,0.,10.);
1149   // fOutput2Part->Add(f3HistBgLamBgLamQinvReal);
1150   // f3HistBgALamBgALamQinvReal = new TH3F ("h3BgALamBgALamQinvReal", "Qinv BgALamBgALam;q_{inv} [GeV/c];min(d) #bar{p} [cm];min(d) #pi [cm]"
1151   //                                     ,nQinvBins,QinvLow,QinvHig,100,0.,10.,100,0.,10.);
1152   // fOutput2Part->Add(f3HistBgALamBgALamQinvReal);
1153   
1154   // // Two-track resolution: mixed events
1155   // f2HistBgLamBgLamMeanMinDistProMixed = new TH2F ("h2BgLamBgLamMeanMinDistProMixed","#Lambda#Lambda Mean vs min dist of decay protons;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1156   // fOutput2Part->Add(f2HistBgLamBgLamMeanMinDistProMixed);
1157   // f2HistBgLamBgLamMeanMinDistPioMixed = new TH2F ("h2BgLamBgLamMeanMinDistPioMixed","#Lambda#Lambda Mean vs min dist of decay pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1158   // fOutput2Part->Add(f2HistBgLamBgLamMeanMinDistPioMixed);
1159   // f2HistBgLamProMeanMinDistProMixed = new TH2F ("h2BgLamProMeanMinDistProMixed","p#Lambda Mean vs min dist of pri. p - dec p;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1160   // fOutput2Part->Add(f2HistBgLamProMeanMinDistProMixed);
1161   // f2HistBgALamBgALamMeanMinDistAProMixed = new TH2F ("h2BgALamBgALamMeanMinDistAProMixed","#bar{#Lambda}#bar{#Lambda} Mean vs min dist decay #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1162   // fOutput2Part->Add(f2HistBgALamBgALamMeanMinDistAProMixed);
1163   // f2HistBgALamBgALamMeanMinDistPioMixed = new TH2F ("h2BgALamBgALamMeanMinDistPioMixed","#bar{#Lambda}#bar{#Lambda} Mean vs min dist of dec. pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1164   // fOutput2Part->Add(f2HistBgALamBgALamMeanMinDistPioMixed);
1165   // f2HistBgALamAProMeanMinDistAProMixed = new TH2F ("h2BgALamAProMeanMinDistProMixed","#bar{p}#bar{#Lambda} Mean vs min dist of pri. #bar{p} - dec #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1166   // fOutput2Part->Add(f2HistBgALamAProMeanMinDistAProMixed);
1167
1168   // f2HistSftBgLamBgLamMeanMinDistProMixed = new TH2F ("h2SftBgLamBgLamMeanMinDistProMixed","#Lambda#Lambda Mean vs min dist of decay protons;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1169   // fOutput2Part->Add(f2HistSftBgLamBgLamMeanMinDistProMixed);
1170   // f2HistSftBgLamBgLamMeanMinDistPioMixed = new TH2F ("h2SftBgLamBgLamMeanMinDistPioMixed","#Lambda#Lambda Mean vs min dist of decay pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1171   // fOutput2Part->Add(f2HistSftBgLamBgLamMeanMinDistPioMixed);
1172   // f2HistSftBgLamProMeanMinDistProMixed = new TH2F ("h2SftBgLamProMeanMinDistProMixed","p#Lambda Mean vs min dist of pri. p - dec p;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1173   // fOutput2Part->Add(f2HistSftBgLamProMeanMinDistProMixed);
1174   // f2HistSftBgALamBgALamMeanMinDistAProMixed = new TH2F ("h2SftBgALamBgALamMeanMinDistAProMixed","#bar{#Lambda}#bar{#Lambda} Mean vs min dist decay #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1175   // fOutput2Part->Add(f2HistSftBgALamBgALamMeanMinDistAProMixed);
1176   // f2HistSftBgALamBgALamMeanMinDistPioMixed = new TH2F ("h2SftBgALamBgALamMeanMinDistPioMixed","#bar{#Lambda}#bar{#Lambda} Mean vs min dist of dec. pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1177   // fOutput2Part->Add(f2HistSftBgALamBgALamMeanMinDistPioMixed);
1178   // f2HistSftBgALamAProMeanMinDistAProMixed = new TH2F ("h2SftBgALamAProMeanMinDistProMixed","#bar{p}#bar{#Lambda} Mean vs min dist of pri. #bar{p} - dec #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1179   // fOutput2Part->Add(f2HistSftBgALamAProMeanMinDistAProMixed);
1180
1181   // f2HistSftIrocBgLamBgLamMeanMinDistProMixed = new TH2F ("h2SftIrocBgLamBgLamMeanMinDistProMixed","#Lambda#Lambda Mean vs min dist of decay protons;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1182   // fOutput2Part->Add(f2HistSftIrocBgLamBgLamMeanMinDistProMixed);
1183   // f2HistSftIrocBgLamBgLamMeanMinDistPioMixed = new TH2F ("h2SftIrocBgLamBgLamMeanMinDistPioMixed","#Lambda#Lambda Mean vs min dist of decay pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1184   // fOutput2Part->Add(f2HistSftIrocBgLamBgLamMeanMinDistPioMixed);
1185   // f2HistSftIrocBgLamProMeanMinDistProMixed = new TH2F ("h2SftIrocBgLamProMeanMinDistProMixed","p#Lambda Mean vs min dist of pri. p - dec p;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1186   // fOutput2Part->Add(f2HistSftIrocBgLamProMeanMinDistProMixed);
1187   // f2HistSftIrocBgALamBgALamMeanMinDistAProMixed = new TH2F ("h2SftIrocBgALamBgALamMeanMinDistAProMixed","#bar{#Lambda}#bar{#Lambda} Mean vs min dist decay #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1188   // fOutput2Part->Add(f2HistSftIrocBgALamBgALamMeanMinDistAProMixed);
1189   // f2HistSftIrocBgALamBgALamMeanMinDistPioMixed = new TH2F ("h2SftIrocBgALamBgALamMeanMinDistPioMixed","#bar{#Lambda}#bar{#Lambda} Mean vs min dist of dec. pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1190   // fOutput2Part->Add(f2HistSftIrocBgALamBgALamMeanMinDistPioMixed);
1191   // f2HistSftIrocBgALamAProMeanMinDistAProMixed = new TH2F ("h2SftIrocBgALamAProMeanMinDistProMixed","#bar{p}#bar{#Lambda} Mean vs min dist of pri. #bar{p} - dec #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1192   // fOutput2Part->Add(f2HistSftIrocBgALamAProMeanMinDistAProMixed);
1193
1194   // f2HistSftOrocBgLamBgLamMeanMinDistProMixed = new TH2F ("h2SftOrocBgLamBgLamMeanMinDistProMixed","#Lambda#Lambda Mean vs min dist of decay protons;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1195   // fOutput2Part->Add(f2HistSftOrocBgLamBgLamMeanMinDistProMixed);
1196   // f2HistSftOrocBgLamBgLamMeanMinDistPioMixed = new TH2F ("h2SftOrocBgLamBgLamMeanMinDistPioMixed","#Lambda#Lambda Mean vs min dist of decay pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1197   // fOutput2Part->Add(f2HistSftOrocBgLamBgLamMeanMinDistPioMixed);
1198   // f2HistSftOrocBgLamProMeanMinDistProMixed = new TH2F ("h2SftOrocBgLamProMeanMinDistProMixed","p#Lambda Mean vs min dist of pri. p - dec p;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1199   // fOutput2Part->Add(f2HistSftOrocBgLamProMeanMinDistProMixed);
1200   // f2HistSftOrocBgALamBgALamMeanMinDistAProMixed = new TH2F ("h2SftOrocBgALamBgALamMeanMinDistAProMixed","#bar{#Lambda}#bar{#Lambda} Mean vs min dist decay #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig); 
1201   // fOutput2Part->Add(f2HistSftOrocBgALamBgALamMeanMinDistAProMixed);
1202   // f2HistSftOrocBgALamBgALamMeanMinDistPioMixed = new TH2F ("h2SftOrocBgALamBgALamMeanMinDistPioMixed","#bar{#Lambda}#bar{#Lambda} Mean vs min dist of dec. pions;mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1203   // fOutput2Part->Add(f2HistSftOrocBgALamBgALamMeanMinDistPioMixed);
1204   // f2HistSftOrocBgALamAProMeanMinDistAProMixed = new TH2F ("h2SftOrocBgALamAProMeanMinDistProMixed","#bar{p}#bar{#Lambda} Mean vs min dist of pri. #bar{p} - dec #bar{p};mean dist. [cm];min dist [cm]",nDistBins,distLow,distHig,nDistBins,distLow,distHig);
1205   // fOutput2Part->Add(f2HistSftOrocBgALamAProMeanMinDistAProMixed);
1206
1207
1208   // Sept'12 Use a THnSparse for (Bg)(A)Lam(A)Pro with 4 dimensions:
1209   // qinv (ppri,ppri), mean dist (ppri,ppri), min dist(ppri,ppri)
1210   // qinv (lam pro)
1211   BgLamProMixed = new THnSparseF("HnSp4BgLamProMixed","lamProMixedQppMeanMinQlamp"
1212                               ,4,HnSpBins,HnSpMin,HnSpMax);
1213   fOutput2Part->Add(BgLamProMixed);
1214   BgALamAProMixed = new THnSparseF("HnSp4BgALamAProMixed","alamAProMixedQppMeanMinQlamp"
1215                               ,4,HnSpBins,HnSpMin,HnSpMax);
1216   fOutput2Part->Add(BgALamAProMixed);
1217
1218   // Qinv: mixed events
1219   // f3HistBgLamBgLamQinvMixed = new TH3F ("h3BgLamBgLamQinvMixed", "Qinv BgLamBgLam;q_{inv} [GeV/c];min(d) p [cm];min(d) #pi [cm]"
1220   //                                    ,nQinvBins,QinvLow,QinvHig,100,0.,10.,100,0.,10.);
1221   // fOutput2Part->Add(f3HistBgLamBgLamQinvMixed);
1222   // f3HistBgALamBgALamQinvMixed = new TH3F ("h3BgALamBgALamQinvMixed", "Qinv BgALamBgALam;q_{inv} [GeV/c];min(d) #bar{p} [cm];min(d) #pi [cm]"
1223   //                                      ,nQinvBins,QinvLow,QinvHig,100,0.,10.,100,0.,10.);
1224   // fOutput2Part->Add(f3HistBgALamBgALamQinvMixed);
1225   
1226   // Post the data
1227   PostData(1, fOutputList);
1228   PostData(2, fOutputPrimaries);
1229   PostData(3, fOutput2Part);
1230
1231 }
1232
1233 //________________________________________________________________________
1234 void AliAnalysisTaskProtonLambda::UserExec(Option_t *) 
1235 {
1236   // Main loop
1237   // Called for each event
1238   
1239   // Fill a control histogram
1240   fHistGoodEvent->Fill(0.0);
1241
1242   // Get the event
1243   fAOD = dynamic_cast<AliAODEvent*>(InputEvent());
1244   if (!fAOD) {
1245     printf("ERROR: fAOD not available\n");
1246     return;
1247   }
1248
1249   // Fill a control histogram
1250   fHistGoodEvent->Fill(1.0);  
1251
1252   // Get the centrality selection
1253   AliCentrality *centrality=NULL;
1254   centrality = fAOD->GetCentrality();
1255   if (!centrality) {
1256     printf ("ERROR: couldn't get the AliCentrality\n");
1257     return;
1258   }
1259   
1260   // Fill a control histogram
1261   fHistGoodEvent->Fill(2.0);  
1262
1263   // Check the fQuality flag of the centrality task
1264   // for details see
1265   // https://twiki.cern.ch/twiki/bin/viewauth/ALICE/CentStudies#How_we_determine_centrality
1266   if (centrality->GetQuality()){
1267     return;
1268   }
1269
1270   // Fill a control histogram
1271   fHistGoodEvent->Fill(3.0);  
1272
1273   // Analyze only 20% most central events using multiplicity in V0 detector (standard)
1274   Float_t centralityPercentile = centrality->GetCentralityPercentileUnchecked("V0M");
1275   if ( centralityPercentile > fkCentCut){
1276     return;
1277   }
1278
1279   // Fill a control histogram
1280   fHistGoodEvent->Fill(4.0);  
1281
1282   // Primary vertex, GetPrimaryVertex() returns the "best" reconstructed vertex
1283   fPrimaryVtx = fAOD->GetPrimaryVertex();
1284   if (!fPrimaryVtx){
1285     printf ("ERROR: no primary vertex\n");
1286     return;
1287   }
1288
1289   // Fill a control histogram
1290   fHistGoodEvent->Fill(5.0);  
1291   fPrimaryVtx->GetXYZ(fPrimaryVtxPosition);
1292   // fHistPrimaryVertexPosXY->Fill(fPrimaryVtxPosition[0],fPrimaryVtxPosition[1]);
1293   // fHistPrimaryVertexPosZ->Fill(fPrimaryVtxPosition[2]);
1294   
1295   // Zvertex cut, probably done anyhow in centrality task
1296   if (TMath::Abs(fPrimaryVtxPosition[2]) > fkAbsZvertexCut)
1297     return;
1298   
1299   // Fill a control histogram
1300   fHistGoodEvent->Fill(6.0);
1301
1302   // Multiplicity
1303   if (!(fAOD->GetNumberOfTracks())) {
1304     return;
1305   }
1306   
1307   // Fill a control histogram
1308   fHistGoodEvent->Fill(7.0);
1309
1310   // fHistTrackMultiplicity->Fill(fAOD->GetNumberOfTracks());
1311
1312   // Set up the event buffer to store this event
1313   fFemtoBuffer->ShiftAndAdd(fAOD);
1314
1315   // // Debugging: print number of stored tracks in the event
1316   // for(UChar_t i=0;i<fFemtoBuffer->GetMixBuffSize();i++)
1317   //   printf("iMix: %u, NPro %u, NAPro %u, NLam %u, NALam %u"
1318   //       "NBgLam %u, NBgALam %u\n"
1319   //       ,i
1320   //       ,fFemtoBuffer->GetEvt(i)->GetNPro()
1321   //       ,fFemtoBuffer->GetEvt(i)->GetNAPro()
1322   //       ,fFemtoBuffer->GetEvt(i)->GetNLam()
1323   //       ,fFemtoBuffer->GetEvt(i)->GetNALam()
1324   //       ,fFemtoBuffer->GetEvt(i)->GetNBgLam()
1325   //       ,fFemtoBuffer->GetEvt(i)->GetNBgALam()
1326   //       );
1327   // printf("\n");
1328
1329
1330   // Reset the reference array to the global tracks..
1331   ResetGlobalTrackReference();
1332   // ..and set it
1333   AliAODTrack *track=NULL;
1334   for (Int_t iTrack=0;iTrack<fAOD->GetNumberOfTracks();iTrack++){
1335     track = fAOD->GetTrack(iTrack);
1336     if (!track) continue;
1337     
1338     // Store the reference of the global tracks
1339     StoreGlobalTrackReference(track);
1340   }
1341   
1342   // V0 loop
1343   const Int_t nV0s = fAOD->GetNumberOfV0s();
1344   AliAODv0 *v0=NULL;
1345   AliAODTrack *pTrack=NULL;
1346   AliAODTrack *nTrack=NULL;
1347   for (Int_t iV0 = 0; iV0 < nV0s; iV0++) {
1348     v0 = fAOD->GetV0(iV0);
1349
1350     // Skip if V0 is not there
1351     if((!v0))
1352       continue;
1353
1354     // Check that the array fGTI isn't too small
1355     // for the track ids
1356     if(v0->GetPosID() >= fTrackBuffSize||
1357        v0->GetNegID() >= fTrackBuffSize)
1358       continue;
1359
1360     // This is AODs: find the track for given id:
1361     pTrack=fGTI[v0->GetPosID()];
1362     nTrack=fGTI[v0->GetNegID()];
1363         
1364     // Skip if one of the daughter is not there
1365     if ((!pTrack) || (!nTrack)) continue;
1366
1367     // Famous crossed rows / findable clusters cut,
1368     // rejects split tracks very well
1369     // (Don't do it for the V0s as we require 80 clusters 
1370     // and reject shared clusters)
1371     //    if( (!acceptTrack(pTrack)) || (!acceptTrack(nTrack)) )
1372     //      continue;
1373
1374     // Reject tracks with shared clusters
1375     if(!GoodTPCFitMapSharedMap(pTrack,nTrack))
1376       continue;
1377
1378     // Analysis done seperately for offline and on-the-fly
1379     if (!(v0->GetOnFlyStatus()))
1380       ProcessOffline(v0, pTrack, nTrack);
1381     else
1382       ProcessOnTheFly(v0, pTrack, nTrack);
1383
1384     // V0s get added to the mixed events in the 'Process..' fcts
1385     
1386   } // End of V0 loop
1387   
1388
1389   // Loop over primary tracks
1390   for (Int_t iTrack=0;iTrack<fAOD->GetNumberOfTracks();iTrack++){
1391     track = fAOD->GetTrack(iTrack);
1392     if (!track) continue;
1393     
1394     if(!track->TestFilterBit(128))
1395       continue;
1396
1397     // Famous crossed rows / findable clusters cut,
1398     // rejects split tracks very well
1399     if(!acceptTrack(track))
1400       continue;
1401
1402     // Reject tracks with shared clusters
1403     if(!GoodTPCFitMapSharedMap(track))
1404       continue;
1405
1406     // Check that the array fGTI isn't too small
1407     // for the track id
1408     if(-track->GetID()-1 >= fTrackBuffSize)
1409       continue;
1410
1411     // Without a corresponding global track it's useless
1412     if(!fGTI[-track->GetID()-1]){
1413       printf ("No global info! iTrack %d, ID %d\n",iTrack,track->GetID());
1414       continue;
1415     }
1416
1417     // Visualization of TPC dE/dx
1418     FillDedxHist(track);
1419
1420     // Depending on momentum choose pid method
1421     if (track->P() < 0.75){
1422        ProcessTPC(track);
1423     }
1424     else if (track->P() < 1.0){
1425        ProcessHybrid(track);
1426     }
1427     else if (track->P() < 3.25){
1428       ProcessTOF(track);
1429     }
1430
1431     
1432     // Tracks get added to the mixed events in the 'Process..' fcts
1433
1434   } // End of loop over primary tracks
1435
1436   // Track cuts do not allow for split tracks
1437
1438   //
1439   // TODO: Use Adam's shared cluster cut!
1440   //
1441
1442
1443   // Cleaning procedure for lambdas & lambdas, lambdas & protons,
1444   // anti-lambdas & anti-lambdas, anti-lambdas & protons + (anti-)lambda background
1445   CleaningProcedure();
1446
1447   // Process real events
1448   ProcessReal();
1449   ProcessRealBackground();
1450   
1451   // Process mixed events
1452   ProcessMixed();
1453   ProcessMixedBackground();
1454
1455   // Post output data.
1456   PostData(1, fOutputList);
1457   PostData(2, fOutputPrimaries);
1458   PostData(3, fOutput2Part);
1459
1460 }
1461 //________________________________________________________________________
1462 void AliAnalysisTaskProtonLambda::ProcessOffline(AliAODv0 *v0, AliAODTrack *pTrack, AliAODTrack *nTrack) 
1463 {
1464
1465   // For clarity in code: Fill some hists with on-the-fly status
1466   //  const Float_t kOnTheFlyStat = 0.0;
1467
1468   // All cuts are checked with invariant mass histograms
1469   //  v0->ChangeMassHypothesis(3122);
1470   Float_t minvLam = v0->MassLambda();
1471   //  v0->ChangeMassHypothesis(-3122);
1472   Float_t minvALam = v0->MassAntiLambda();
1473   // Cosine as local variable as this is some computation
1474   const Float_t lCosPoint = v0->CosPointingAngle(fPrimaryVtxPosition);
1475
1476   // Also calculate a V0 momentum with TPC only daughters
1477   //  Double_t TPConlyV0Mom[3], TPConlyV0MinvLam=0, TPConlyV0MinvALam=0;
1478   //  getTPConlyV0Info(pTrack, nTrack,
1479   //               TPConlyV0Mom, TPConlyV0MinvLam, TPConlyV0MinvALam);
1480
1481   // Fill a minv hist w/o any cuts. Select background from the sideband
1482   fHistSideBandOffLam->Fill(minvLam);
1483   fHistSideBandOffALam->Fill(minvALam);
1484   // Fill the event buffer w/ background
1485   if (!fkUseOnTheFly){
1486     if ( TMath::Abs(minvLam - fkLamMass) > 0.015 &&
1487          TMath::Abs(minvLam - fkLamMass) < 0.035 ){
1488       fFemtoBuffer->GetEvt(0)->AddBgLam(v0, pTrack, nTrack);
1489     }
1490     if ( TMath::Abs(minvALam - fkLamMass) > 0.015 &&
1491          TMath::Abs(minvALam - fkLamMass) < 0.035 ){
1492       fFemtoBuffer->GetEvt(0)->AddBgALam(v0, pTrack, nTrack);
1493     }
1494   }
1495
1496   // Control histogram: fill all v0s
1497   // fHistGoodV0->Fill(0.0,kOnTheFlyStat);
1498   // fHistGoodV0->Fill(1.0,kOnTheFlyStat);
1499
1500   // Require 80 TPC clusters for both pos and neg daughter
1501   fHistTPCNclsPosOffLam->Fill(pTrack->GetTPCNcls(),minvLam);
1502   fHistTPCNclsNegOffLam->Fill(nTrack->GetTPCNcls(),minvLam);
1503   fHistTPCNclsPosOffALam->Fill(pTrack->GetTPCNcls(),minvALam);
1504   fHistTPCNclsNegOffALam->Fill(nTrack->GetTPCNcls(),minvALam);
1505
1506   if ( ( (pTrack->GetTPCNcls()) < 80 ) || ( (nTrack->GetTPCNcls()) < 80 ) ) 
1507     return;
1508   //  fHistGoodV0->Fill(2.0,kOnTheFlyStat);
1509
1510   // Require a maximum dca of the daughters of 0.6cm
1511   // fHistDcaV0DaughtersOffLam->Fill(v0->DcaV0Daughters(),minvLam);
1512   // fHistDcaV0DaughtersOffALam->Fill(v0->DcaV0Daughters(),minvALam);
1513   // fHistDcaV0Daughters->Fill(v0->DcaV0Daughters(),kOnTheFlyStat);
1514   if (v0->DcaV0Daughters() > 0.6)
1515     return;
1516   //  fHistGoodV0->Fill(3.0,kOnTheFlyStat);
1517   
1518   // Force TPC PID to be present
1519   if (!(pTrack->GetStatus() & AliVTrack::kTPCpid) ||
1520       !(nTrack->GetStatus() & AliVTrack::kTPCpid))
1521     return;
1522   //  fHistGoodV0->Fill(4.0,kOnTheFlyStat);
1523
1524   // Visualize TPC signal before performing selection
1525   // fHistPosTpcBeforeCut->Fill(pTrack->P(),pTrack->GetTPCsignal());
1526   // fHistNegTpcBeforeCut->Fill(nTrack->P(),nTrack->GetTPCsignal());
1527   // The Nsigma distribution for TPC dE/dx
1528   // fHistPosNsigmaTpcOffLam->Fill(TMath::Abs(fPIDResponse->NumberOfSigmasTPC(pTrack, AliPID::kProton)),minvLam);
1529   // fHistPosNsigmaTpcOffALam->Fill(TMath::Abs(fPIDResponse->NumberOfSigmasTPC(pTrack, AliPID::kPion)),minvALam);
1530   // fHistNegNsigmaTpcOffLam->Fill(TMath::Abs(fPIDResponse->NumberOfSigmasTPC(nTrack, AliPID::kPion)),minvLam);
1531   // fHistNegNsigmaTpcOffALam->Fill(TMath::Abs(fPIDResponse->NumberOfSigmasTPC(nTrack, AliPID::kProton)),minvALam);
1532   // Perform cut on TPC dE/dx
1533   if (TMath::Abs(fPIDResponse->NumberOfSigmasTPC(pTrack, AliPID::kProton)) > 3.4)
1534     minvLam=0.0;
1535   // else 
1536   //   fHistPosTpcAfterCut->Fill(pTrack->P(),pTrack->GetTPCsignal());
1537   if (TMath::Abs(fPIDResponse->NumberOfSigmasTPC(nTrack, AliPID::kPion)) > 4.4)
1538     minvLam=0.0;
1539   // else
1540   //   fHistNegTpcAfterCut->Fill(nTrack->P(),nTrack->GetTPCsignal());
1541   if (TMath::Abs(fPIDResponse->NumberOfSigmasTPC(pTrack, AliPID::kPion)) > 4.2)
1542     minvALam=0.0;
1543   if (TMath::Abs(fPIDResponse->NumberOfSigmasTPC(nTrack, AliPID::kProton)) > 3.4)
1544     minvALam=0.0;
1545
1546   // Don't use a tof cut for pions
1547
1548   // Check whether to use a 5sigma tof cut or none for protons
1549   // if (pTrack->GetStatus() & AliVTrack::kTOFpid){
1550   //   if (TMath::Abs(fPIDResponse->NumberOfSigmasTOF(pTrack, AliPID::kProton)) > 5.0)
1551   //     fHistUseTofOffLam->Fill(1.0,minvLam);
1552   //   else
1553   //     fHistUseTofOffLam->Fill(0.0,minvLam);
1554   // }
1555   // else
1556   //   fHistUseTofOffLam->Fill(0.0,minvLam);
1557   // Check whether to use a 5sigma tof cut or none for anti-protons
1558   // if (nTrack->GetStatus() & AliVTrack::kTOFpid){
1559   //   if (TMath::Abs(fPIDResponse->NumberOfSigmasTOF(nTrack, AliPID::kProton)) > 5.0)
1560   //     fHistUseTofOffALam->Fill(1.0,minvALam);
1561   //   else
1562   //     fHistUseTofOffALam->Fill(0.0,minvALam);
1563   // }
1564   // else
1565   //   fHistUseTofOffALam->Fill(0.0,minvALam);
1566
1567   // Don't use a TOF cut for offline
1568   
1569   // Don't need to check for sign of pairs as this is always
1570   // correct for offline finder
1571
1572   // Don't need to check for TPC refit as it is required
1573   // by the offline finder itself
1574
1575   //
1576   // Require a minimum distance between daughters and primary vertex
1577   //
1578   // Fill histograms with the distributions before cutting
1579   // fHistDcaPosOffLam->Fill(v0->DcaPosToPrimVertex(),minvLam);
1580   // fHistDcaPosOffALam->Fill(v0->DcaPosToPrimVertex(),minvALam);
1581   // fHistDcaNegOffLam->Fill(v0->DcaNegToPrimVertex(),minvLam);
1582   // fHistDcaNegOffALam->Fill(v0->DcaNegToPrimVertex(),minvALam);
1583   
1584   // fHistDcaPosToPrimVertex->Fill(v0->DcaPosToPrimVertex(),kOnTheFlyStat);
1585   // fHistDcaNegToPrimVertex->Fill(v0->DcaNegToPrimVertex(),kOnTheFlyStat);
1586   // fHistDcaPosToPrimVertexZoom->Fill(v0->DcaPosToPrimVertex(),kOnTheFlyStat);
1587   // fHistDcaNegToPrimVertexZoom->Fill(v0->DcaNegToPrimVertex(),kOnTheFlyStat);
1588   
1589   // Do the cut
1590   if (v0->DcaPosToPrimVertex() < 0.1)
1591     minvLam=0.0;
1592   if (v0->DcaPosToPrimVertex() < 0.3)
1593     minvALam=0.0;
1594   if (v0->DcaNegToPrimVertex() < 0.1)
1595     minvALam=0.0;
1596   if (v0->DcaNegToPrimVertex() < 0.3)
1597     minvLam=0.0;
1598
1599   // Cosine of pointing angle. Computed at the beginning.
1600   // Fill historgrams before cutting
1601   // fHistCosPointLamOff->Fill(lCosPoint,minvLam);
1602   // fHistCosPointALamOff->Fill(lCosPoint,minvALam);
1603   // fHistCosPointLamZoomOff->Fill(lCosPoint,minvLam);
1604   // fHistCosPointALamZoomOff->Fill(lCosPoint,minvALam);
1605   
1606   // fHistCosPointAngle->Fill(lCosPoint,kOnTheFlyStat);
1607   // fHistCosPointAngleZoom->Fill(lCosPoint,kOnTheFlyStat);
1608   
1609   // Do the cut in cos (pointing angle) 
1610   // (note the difference 0.9996 for offline and 0.9999 for on-the-fly)
1611   if (lCosPoint < 0.9996)
1612     return;
1613   
1614   // fHistGoodV0->Fill(7.0,kOnTheFlyStat);
1615   
1616   // Fill some histograms with cut variables
1617   // fHistChi2->Fill(v0->Chi2V0(),kOnTheFlyStat);
1618   
1619   // Idea to cut on the radius
1620   // fHistRadiusV0->Fill(v0->RadiusV0(),kOnTheFlyStat);
1621   // fHistV0RadiusLamOff->Fill(v0->RadiusV0(),minvLam);
1622   // fHistV0RadiusALamOff->Fill(v0->RadiusV0(),minvALam);
1623
1624   // Idea to cut on the decay length
1625   // fHistDecayLengthV0->Fill(v0->DecayLengthV0(fPrimaryVtxPosition),kOnTheFlyStat);
1626   // fHistV0DecayLengthLamOff->Fill(v0->DecayLengthV0(fPrimaryVtxPosition),minvLam);
1627   // fHistV0DecayLengthALamOff->Fill(v0->DecayLengthV0(fPrimaryVtxPosition),minvALam);
1628  
1629   // Idea to cut on DCA of V0 and primay vertex
1630   // fHistDcaV0PriVertexLamOff->Fill(v0->DcaV0ToPrimVertex(),minvLam);
1631   // fHistDcaV0PriVertexALamOff->Fill(v0->DcaV0ToPrimVertex(),minvALam);
1632      
1633   // Fill some invariant mass distributions
1634   fHistMassLambdaOff->Fill(minvLam);
1635   fHistMassAntiLambdaOff->Fill(minvALam);
1636   // fHistPtVsMassLambdaOff->Fill(v0->Pt(),minvLam);
1637   // fHistPtVsMassAntiLambdaOff->Fill(v0->Pt(),minvALam);
1638
1639   // 3d histogram: rapidity, pt and mass
1640   fHistYPtMassLamOff->Fill(v0->Y(3122),v0->Pt(),minvLam);
1641   fHistYPtMassALamOff->Fill(v0->Y(-3122),v0->Pt(),minvALam);
1642   
1643   // Invariant mass cut lambda :: fill a y-pt hist
1644   // if ( TMath::Abs(minvLam - fkLamMass) < 0.01 ){
1645   //   fHistPtVsYLambdaOff->Fill(v0->Pt(),v0->Y(3122));
1646   // }
1647   // // Invariant mass cut anti-lambda :: fill a y-pt hist
1648   // if ( TMath::Abs(minvALam - fkLamMass) < 0.01 ){
1649   //   fHistPtVsYAntiLambdaOff->Fill(v0->Pt(),v0->Y(-3122));
1650   // }
1651
1652   // Fill the mixed events when offline V0 finder is used
1653   if (!fkUseOnTheFly){
1654     // Highest significance for minv +/- 4 MeV
1655     if ( TMath::Abs(minvLam - fkLamMass) < 0.004 ){
1656       fFemtoBuffer->GetEvt(0)->AddLam(v0, pTrack, nTrack);
1657     }
1658     if ( TMath::Abs(minvALam - fkLamMass) < 0.004 ){
1659       fFemtoBuffer->GetEvt(0)->AddALam(v0, pTrack, nTrack);
1660     }
1661   }
1662 }   
1663 //________________________________________________________________________
1664 void AliAnalysisTaskProtonLambda::ProcessOnTheFly(AliAODv0 *v0, AliAODTrack *pTrack, AliAODTrack *nTrack) 
1665 {
1666   // For clarity in code: Fill some hists with on-the-fly status
1667   //  const Float_t kOnTheFlyStat = 1.0;
1668
1669   // All cuts are checked with invariant mass histograms
1670   Float_t minvLam = v0->MassLambda();
1671   Float_t minvALam = v0->MassAntiLambda();
1672   const Float_t lCosPoint = v0->CosPointingAngle(fPrimaryVtxPosition);
1673
1674   // Control histogram: fill all v0s
1675   //  fHistGoodV0->Fill(0.0,kOnTheFlyStat);
1676   // Control hist: after require two daughter tracks
1677   //  fHistGoodV0->Fill(1.0,kOnTheFlyStat);
1678   // Check the right sign of the tracks (mainly on-the-fly)
1679   if (pTrack->Charge() > 0 && nTrack->Charge() < 0){
1680     // Correct assignment
1681     // fHistCorrectSigns->Fill(0.0,kOnTheFlyStat);
1682
1683     // fHistLikeSignOnLam->Fill(0.0,minvLam);
1684     // fHistLikeSignOnALam->Fill(0.0,minvALam);    
1685   }
1686   else if (pTrack->Charge() < 0 && nTrack->Charge() > 0){
1687     // Swapped sings
1688     //    fHistCorrectSigns->Fill(1.0,kOnTheFlyStat);
1689
1690     pTrack = fGTI[v0->GetNegID()];
1691     nTrack = fGTI[v0->GetPosID()];
1692     
1693
1694     // See http://savannah.cern.ch/bugs/?90749
1695     // For AODs it depends on with which root version 
1696     // the AODs got produced.
1697
1698     // See above: swapping mass assignment
1699     minvLam = v0->MassAntiLambda();
1700     minvALam = v0->MassLambda();
1701
1702     //    fHistLikeSignOnLam->Fill(1.0,minvLam);
1703     //    fHistLikeSignOnALam->Fill(1.0,minvALam);    
1704   }
1705   else {
1706     // Like sign pairs
1707     //    fHistCorrectSigns->Fill(2.0,kOnTheFlyStat);
1708     
1709     //    fHistLikeSignOnLam->Fill(2.0,minvLam);
1710     //    fHistLikeSignOnALam->Fill(2.0,minvALam);    
1711
1712     // Don't use like sign-pairs
1713     return;
1714   }
1715   //  fHistGoodV0->Fill(2.0,kOnTheFlyStat);
1716
1717   // V0 momentum
1718   Double_t V0Mom[3];
1719   v0->PxPyPz(V0Mom);
1720   // Also calculate a V0 momentum with TPC only daughters
1721   //  Double_t TPConlyV0Mom[3], TPConlyV0MinvLam=0, TPConlyV0MinvALam=0;
1722   //  getTPConlyV0Info(pTrack, nTrack,
1723   //               TPConlyV0Mom, TPConlyV0MinvLam, TPConlyV0MinvALam);
1724
1725    // Fill a minv hist w/o any cuts. Select background from the sideband
1726   fHistSideBandOnLam->Fill(minvLam);
1727   fHistSideBandOnALam->Fill(minvALam);
1728   // Fill the event buffer w/ background
1729   if (fkUseOnTheFly){
1730     // Select side band aka background lambdas
1731     if (TMath::Abs(minvLam - fkLamMass) > 0.015 &&
1732         TMath::Abs(minvLam - fkLamMass) < 0.035 ){
1733       
1734       fFemtoBuffer->GetEvt(0)->AddBgLam(v0, pTrack, nTrack);
1735       // Momentum difference of standard V0 / TPC only V0
1736       //      fHistMomDiffBgLam->Fill(V0Mom[0] - TPConlyV0Mom[0], 
1737       //                            V0Mom[1] - TPConlyV0Mom[1],
1738       //                            V0Mom[2] - TPConlyV0Mom[2]);
1739       // Same excluding V0s with daughters with SPD hits
1740       //      if( !(pTrack->HasPointOnITSLayer(0) || pTrack->HasPointOnITSLayer(1) ||
1741       //            nTrack->HasPointOnITSLayer(0) || nTrack->HasPointOnITSLayer(1) )){
1742       // No SPD hits
1743       //        fHistMomDiffWoSPDBgLam->Fill(V0Mom[0] - TPConlyV0Mom[0], 
1744       //                                   V0Mom[1] - TPConlyV0Mom[1],
1745       //                                   V0Mom[2] - TPConlyV0Mom[2]);
1746
1747       //    }
1748     } // End of background lambdas
1749     // Select side band aka background anti-lambdas
1750     if ( TMath::Abs(minvALam - fkLamMass) > 0.015 &&
1751          TMath::Abs(minvALam - fkLamMass) < 0.035 ){
1752
1753       fFemtoBuffer->GetEvt(0)->AddBgALam(v0, pTrack, nTrack);
1754       // Momentum difference of standard V0 / TPC only V0
1755       //      fHistMomDiffBgALam->Fill(V0Mom[0] - TPConlyV0Mom[0], 
1756       //                               V0Mom[1] - TPConlyV0Mom[1],
1757       //                               V0Mom[2] - TPConlyV0Mom[2]);
1758       // Same excluding V0s with daughters with SPD hits
1759       //      if( !(pTrack->HasPointOnITSLayer(0) || pTrack->HasPointOnITSLayer(1) ||
1760       //            nTrack->HasPointOnITSLayer(0) || nTrack->HasPointOnITSLayer(1) )){
1761       // No SPD hits
1762       //        fHistMomDiffWoSPDBgALam->Fill(V0Mom[0] - TPConlyV0Mom[0], 
1763       //                              V0Mom[1] - TPConlyV0Mom[1],
1764       //                                      V0Mom[2] - TPConlyV0Mom[2]);
1765       //      } // No SPD hits
1766     } // End of background anti-lambda
1767   } // End of if use on-the-fly finder
1768
1769   //
1770   // Require 80 TPC clusters for both daughters
1771   //
1772   // There's a lambda signal for 0-9 clusters of the proton 
1773   // as it's for 110-120?!
1774   // There was a bug in the finding of the global track, since 
1775   // fixing it, offline is fine (and the problem looks less 
1776   // severe for on-the-fly). Still there is a problem here. 
1777   // There are tracks with 0 clusters. This is not the case
1778   // for the offline finder. The speculation would be that 
1779   // 1-9 clusters are treated correctly also here, it's just
1780   // the 0 cluster tracks. Should be a filter issue: on-the-fly
1781   // finds a V0, stores the daughter but info doesn't get written.
1782   if(pTrack->GetTPCNcls()){
1783     // More than zero clusters
1784     fHistTPCNclsPosOnLam->Fill(pTrack->GetTPCNcls(),minvLam);
1785     fHistTPCNclsPosOnALam->Fill(pTrack->GetTPCNcls(),minvALam);
1786   }
1787   else {
1788     // Zero clusters, fill the underflow to distinguish
1789     fHistTPCNclsPosOnLam->Fill(-1,minvLam);
1790     fHistTPCNclsPosOnALam->Fill(-1,minvALam);
1791   }
1792   if(nTrack->GetTPCNcls()){
1793     // More than zero clusters
1794     fHistTPCNclsNegOnLam->Fill(nTrack->GetTPCNcls(),minvLam);
1795     fHistTPCNclsNegOnALam->Fill(nTrack->GetTPCNcls(),minvALam);
1796   }
1797   else {
1798     // Zero clusters, fill the underflow to distinguish
1799     fHistTPCNclsNegOnLam->Fill(-1,minvLam);
1800     fHistTPCNclsNegOnALam->Fill(-1,minvALam);
1801   }
1802   
1803   // Do the cut on the TPC clusters, 0 OR at least 80
1804   if ( ( pTrack->GetTPCNcls() < 80 && pTrack->GetTPCNcls() ) ||
1805        ( nTrack->GetTPCNcls() < 80 && nTrack->GetTPCNcls() ) ) 
1806     return;
1807   //  fHistGoodV0->Fill(3.0,kOnTheFlyStat);
1808
1809   // Require a maximum dca of the daughters of 0.2cm
1810   // fHistDcaV0DaughtersOnLam->Fill(v0->DcaV0Daughters(),minvLam);
1811   // fHistDcaV0DaughtersOnALam->Fill(v0->DcaV0Daughters(),minvALam);
1812   // fHistDcaV0Daughters->Fill(v0->DcaV0Daughters(),kOnTheFlyStat);
1813   if (v0->DcaV0Daughters() > 0.2)
1814     return;
1815   //  fHistGoodV0->Fill(4.0,kOnTheFlyStat);
1816   
1817   // Require cosine of pointing angle bigger than 0.9999
1818   // fHistCosPointAngle->Fill(lCosPoint,kOnTheFlyStat);
1819   // fHistCosPointAngleZoom->Fill(lCosPoint,kOnTheFlyStat);
1820   // fHistCosPointLamOn->Fill(lCosPoint,minvLam);
1821   // fHistCosPointALamOn->Fill(lCosPoint,minvALam);
1822   // fHistCosPointLamZoomOn->Fill(lCosPoint,minvLam);
1823   // fHistCosPointALamZoomOn->Fill(lCosPoint,minvALam);
1824   if (lCosPoint<0.9999)
1825     return;
1826   //  fHistGoodV0->Fill(5.0,kOnTheFlyStat);
1827   // Force TPC PID to be present
1828   if (!(pTrack->GetStatus() & AliVTrack::kTPCpid) ||
1829       !(nTrack->GetStatus() & AliVTrack::kTPCpid)) {
1830     // No TPC pid present for this track
1831     return;
1832   }
1833   //  fHistGoodV0->Fill(6.0,kOnTheFlyStat);
1834   // Visualize TPC signal before performing selection
1835   // fHistPosTpcBeforeCut->Fill(pTrack->P(),pTrack->GetTPCsignal());
1836   // fHistNegTpcBeforeCut->Fill(nTrack->P(),nTrack->GetTPCsignal());
1837   // // The Nsigma distribution for TPC dE/dx
1838   // fHistPosNsigmaTpcOnLam->Fill(TMath::Abs(fPIDResponse->NumberOfSigmasTPC(pTrack, AliPID::kProton)),minvLam);
1839   // fHistPosNsigmaTpcOnALam->Fill(TMath::Abs(fPIDResponse->NumberOfSigmasTPC(pTrack, AliPID::kPion)),minvALam);
1840   // fHistNegNsigmaTpcOnLam->Fill(TMath::Abs(fPIDResponse->NumberOfSigmasTPC(nTrack, AliPID::kPion)),minvLam);
1841   // fHistNegNsigmaTpcOnALam->Fill(TMath::Abs(fPIDResponse->NumberOfSigmasTPC(nTrack, AliPID::kProton)),minvALam);
1842
1843   // Perform cut on TPC dE/dx
1844   if (TMath::Abs(fPIDResponse->NumberOfSigmasTPC(pTrack, AliPID::kProton)) > 3.7)
1845     minvLam=0.0;
1846   // else 
1847   //   fHistPosTpcAfterCut->Fill(pTrack->P(),pTrack->GetTPCsignal());
1848   if (TMath::Abs(fPIDResponse->NumberOfSigmasTPC(nTrack, AliPID::kPion)) > 3.8)
1849     minvLam=0.0;
1850   // else
1851   //   fHistNegTpcAfterCut->Fill(nTrack->P(),nTrack->GetTPCsignal());
1852   if (TMath::Abs(fPIDResponse->NumberOfSigmasTPC(pTrack, AliPID::kPion)) > 4.2)
1853     minvALam=0.0;
1854   if (TMath::Abs(fPIDResponse->NumberOfSigmasTPC(nTrack, AliPID::kProton)) > 3.9)
1855     minvALam=0.0;
1856
1857   // Don't use a tof cut for pions
1858
1859   // Check whether to use a 5sigma tof cut or none for protons
1860   // if (pTrack->GetStatus() & AliVTrack::kTOFpid){
1861   //   if (TMath::Abs(fPIDResponse->NumberOfSigmasTOF(pTrack, AliPID::kProton)) > 5.0)
1862   //     fHistUseTofOnLam->Fill(1.0,minvLam);
1863   //   else
1864   //     fHistUseTofOnLam->Fill(0.0,minvLam);
1865   // }
1866   // else
1867   //   fHistUseTofOnLam->Fill(0.0,minvLam);
1868   // // Check whether to use a 5sigma tof cut or none for anti-protons
1869   // if (nTrack->GetStatus() & AliVTrack::kTOFpid){
1870   //   if (TMath::Abs(fPIDResponse->NumberOfSigmasTOF(nTrack, AliPID::kProton)) > 5.0)
1871   //     fHistUseTofOnALam->Fill(1.0,minvALam);
1872   //   else
1873   //     fHistUseTofOnALam->Fill(0.0,minvALam);
1874   // }
1875   // else
1876   //   fHistUseTofOnALam->Fill(0.0,minvALam);
1877
1878   // Reject (anti-)protons with more than 5sigma TOF
1879   if (nTrack->GetStatus() & AliVTrack::kTOFpid){
1880     if (TMath::Abs(fPIDResponse->NumberOfSigmasTOF(nTrack, AliPID::kProton)) > 5.0)
1881       minvALam=0.0;
1882   }
1883   if (pTrack->GetStatus() & AliVTrack::kTOFpid){
1884     if (TMath::Abs(fPIDResponse->NumberOfSigmasTOF(pTrack, AliPID::kProton)) > 5.0)
1885       minvLam=0.0;
1886   }
1887   
1888   // Don't require TPC refit. You would kill nearly your whole signal  
1889
1890   // Distance between daughters and primary vertex
1891   // fHistDcaPosToPrimVertex->Fill(v0->DcaPosToPrimVertex(),kOnTheFlyStat);
1892   // fHistDcaNegToPrimVertex->Fill(v0->DcaNegToPrimVertex(),kOnTheFlyStat);
1893   // fHistDcaPosToPrimVertexZoom->Fill(v0->DcaPosToPrimVertex(),kOnTheFlyStat);
1894   // fHistDcaNegToPrimVertexZoom->Fill(v0->DcaNegToPrimVertex(),kOnTheFlyStat);
1895   // fHistDcaPosOnLam->Fill(v0->DcaPosToPrimVertex(),minvLam);
1896   // fHistDcaPosOnALam->Fill(v0->DcaPosToPrimVertex(),minvALam);
1897   // fHistDcaNegOnLam->Fill(v0->DcaNegToPrimVertex(),minvLam);
1898   // fHistDcaNegOnALam->Fill(v0->DcaNegToPrimVertex(),minvALam);
1899   // Require at least 0.02 cm distance from the primary vertex for the (anti-)protons
1900   if (v0->DcaPosToPrimVertex() < 0.02)
1901     minvLam=0.0;
1902   if (v0->DcaNegToPrimVertex() < 0.02)
1903     minvALam=0.0;
1904   // Require at least 0.05 cm distance from the primary vertex for the pions
1905   if (v0->DcaPosToPrimVertex() < 0.05)
1906     minvALam=0.0;
1907   if (v0->DcaNegToPrimVertex() < 0.05)
1908     minvLam=0.0;
1909   
1910   // Fill some histograms with cut variables
1911   //  fHistChi2->Fill(v0->Chi2V0(),kOnTheFlyStat);
1912   
1913   
1914   // Idea to cut on the radius
1915   // fHistRadiusV0->Fill(v0->RadiusV0(),kOnTheFlyStat);
1916   // fHistV0RadiusLamOn->Fill(v0->RadiusV0(),minvLam);
1917   // fHistV0RadiusALamOn->Fill(v0->RadiusV0(),minvALam);
1918   
1919   // Idea to cut on the decay length
1920   // fHistDecayLengthV0->Fill(v0->DecayLengthV0(fPrimaryVtxPosition),kOnTheFlyStat);
1921   // fHistV0DecayLengthLamOn->Fill(v0->DecayLengthV0(fPrimaryVtxPosition),minvLam);
1922   // fHistV0DecayLengthALamOn->Fill(v0->DecayLengthV0(fPrimaryVtxPosition),minvALam);
1923
1924   // Idea to cut on DCA of V0 and primay vertex
1925   // fHistDcaV0PriVertexLamOn->Fill(v0->DcaV0ToPrimVertex(),minvLam);
1926   // fHistDcaV0PriVertexALamOn->Fill(v0->DcaV0ToPrimVertex(),minvALam);
1927
1928   // TPC Chi2 / number of degrees of freedom
1929   // A cut on at least 80 clusters is already done before,
1930   // no concern to divide by zero
1931   // fHistChi2TPCPosLamOn->Fill(pTrack->Chi2perNDF(),minvLam);
1932   // fHistChi2TPCPosALamOn->Fill(pTrack->Chi2perNDF(),minvALam);
1933   // fHistChi2TPCNegLamOn->Fill(nTrack->Chi2perNDF(),minvLam);
1934   // fHistChi2TPCNegALamOn->Fill(nTrack->Chi2perNDF(),minvALam);
1935   // Don't cut like Chi2/ndf < 4! One might throw away the tracks
1936   // with Chi2/ndf roughly one as they are good primaries
1937
1938   // Fill some invariant mass distributions
1939   fHistMassLambdaOn->Fill(minvLam);
1940   fHistMassAntiLambdaOn->Fill(minvALam);
1941   // fHistPtVsMassLambdaOn->Fill(v0->Pt(),minvLam);
1942   // fHistPtVsMassAntiLambdaOn->Fill(v0->Pt(),minvALam);
1943
1944   // TPC only invariant mass distributions
1945   //  if(minvLam > .1){
1946     // Lambda is good
1947     //    fHistMinvTPConlyLamOn->Fill(TPConlyV0MinvLam);
1948   //  }
1949   //  if (minvALam > .1){
1950     // Anti-lambda is good
1951     //    fHistMinvTPConlyALamOn->Fill(TPConlyV0MinvALam);
1952   //  }
1953   
1954   // 3d histogram: rapidity, pt and mass
1955   fHistYPtMassLamOn->Fill(v0->Y(3122),v0->Pt(),minvLam);
1956   fHistYPtMassALamOn->Fill(v0->Y(-3122),v0->Pt(),minvALam);
1957   
1958   // // Invariant mass cut lambda :: fill a y-pt hists
1959   // if ( TMath::Abs(minvLam - fkLamMass) < 0.01 ){
1960   //   fHistPtVsYLambdaOn->Fill(v0->Pt(),v0->Y(3122));
1961   // }
1962   // // Invariant mass cut anti-lambda :: fill a y-pt hists
1963   // if ( TMath::Abs(minvALam - fkLamMass) < 0.01 ){
1964   //   fHistPtVsYAntiLambdaOn->Fill(v0->Pt(),v0->Y(-3122));
1965   // }
1966   
1967   // Fill the mixed events when on-the-fly V0 finder is used
1968   if (fkUseOnTheFly){
1969
1970     // Highest significance for minv +/- 4 MeV
1971     if ( TMath::Abs(minvLam - fkLamMass) < 0.004 ){
1972       fFemtoBuffer->GetEvt(0)->AddLam(v0, pTrack, nTrack);
1973       // Momentum difference of standard V0 / TPC only V0
1974       //      fHistMomDiffLam->Fill(V0Mom[0] - TPConlyV0Mom[0], 
1975       //                    V0Mom[1] - TPConlyV0Mom[1],
1976       //                    V0Mom[2] - TPConlyV0Mom[2]);
1977       // Same excluding V0s with daughters with SPD hits
1978       //      if( !(pTrack->HasPointOnITSLayer(0) || pTrack->HasPointOnITSLayer(1) ||
1979       //            nTrack->HasPointOnITSLayer(0) || nTrack->HasPointOnITSLayer(1) )){
1980       //        // No SPD hits
1981       //        fHistMomDiffWoSPDLam->Fill(V0Mom[0] - TPConlyV0Mom[0], 
1982       //                                   V0Mom[1] - TPConlyV0Mom[1],
1983       //                                   V0Mom[2] - TPConlyV0Mom[2]);
1984       // } // No SPD hits
1985     } // Good lambda
1986     if ( TMath::Abs(minvALam - fkLamMass) < 0.004 ) {
1987       fFemtoBuffer->GetEvt(0)->AddALam(v0, pTrack, nTrack);
1988       // Momentum difference of standard V0 / TPC only V0
1989       //      fHistMomDiffALam->Fill(V0Mom[0] - TPConlyV0Mom[0], 
1990       //                            V0Mom[1] - TPConlyV0Mom[1],
1991       //                            V0Mom[2] - TPConlyV0Mom[2]);
1992       // Same excluding V0s with daughters with SPD hits
1993       //      if( !(pTrack->HasPointOnITSLayer(0) || pTrack->HasPointOnITSLayer(1) ||
1994       //            nTrack->HasPointOnITSLayer(0) || nTrack->HasPointOnITSLayer(1) )){
1995         // No SPD hits
1996       //        fHistMomDiffWoSPDALam->Fill(V0Mom[0] - TPConlyV0Mom[0], 
1997       //                                   V0Mom[1] - TPConlyV0Mom[1],
1998       //                                   V0Mom[2] - TPConlyV0Mom[2]);
1999       //    } // No SPD hits
2000     } // Good anti-lambda
2001   } // Use on-the-fly finder for Femto analysis
2002 } // ProcessOnTheFly
2003 //________________________________________________________________________
2004 void AliAnalysisTaskProtonLambda::ProcessTOF(AliAODTrack* track) 
2005 {
2006   // Request the kTOFpid bit. There are tracks with kTOFout and wihthout kTOFpid,
2007   // but these tracks have a bad TOF signal.
2008   if(!((fGTI[-track->GetID()-1])->GetStatus() & AliVTrack::kTOFpid))
2009     return;
2010
2011   // TOF signal corrected for expected time and (if neccessary) for start time
2012   Float_t corrTOFsig = GetCorrectedTOFSignal(track);
2013
2014   // Distinguish between charges
2015   if (track->Charge() > 0){
2016     // Simple Nsigma TOF distribution
2017     //    fPriHistPosNsigmaTof->Fill(fPIDResponse->NumberOfSigmasTOF((fGTI[-track->GetID()-1]), AliPID::kProton));
2018     // Nsigma TOF in bins of total momentum
2019     fPriHistPosNsigmaTofVsP->Fill(track->P(),fPIDResponse->NumberOfSigmasTOF((fGTI[-track->GetID()-1]), AliPID::kProton));
2020     // Nsigma TOF in bins of transverse momentum
2021     fPriHistPosNsigmaTofVsPt->Fill(track->Pt(),fPIDResponse->NumberOfSigmasTOF((fGTI[-track->GetID()-1]), AliPID::kProton));
2022     
2023     // Try the tof signal instead of nsigma
2024     fPriHistTOFsignalPosVsP->Fill(track->P(), corrTOFsig);
2025     fPriHistTOFsignalPosVsPt->Fill(track->Pt(), corrTOFsig);
2026     
2027   }
2028   else if (track->Charge() < 0){
2029     // Simple Nsigma TOF distribution
2030     //    fPriHistNegNsigmaTof->Fill(fPIDResponse->NumberOfSigmasTOF((fGTI[-track->GetID()-1]), AliPID::kProton));
2031     // Nsigma TOF in bins of total momentum
2032     fPriHistNegNsigmaTofVsP->Fill(track->P(),fPIDResponse->NumberOfSigmasTOF((fGTI[-track->GetID()-1]), AliPID::kProton));
2033     // Nsigma TOF in bins of transverse momentum
2034     fPriHistNegNsigmaTofVsPt->Fill(track->Pt(),fPIDResponse->NumberOfSigmasTOF((fGTI[-track->GetID()-1]), AliPID::kProton));
2035     
2036     // Try the tof signal instead of nsigma
2037     fPriHistTOFsignalNegVsP->Fill(track->P(), corrTOFsig);
2038     fPriHistTOFsignalNegVsPt->Fill(track->Pt(), corrTOFsig);
2039   }
2040   
2041   // Final judging: simple first idea. 
2042   // min -800 up to 2 GeV and 0 up to 3.25GeV
2043   if (track->P() < 2.0){
2044     //    if (corrTOFsig > -800.0){
2045     // In AODs, the resolution is better, do -500 (AODs) 
2046     // instead of -800 (ESDs)
2047     if (corrTOFsig > -500.0) {
2048       // Create additional TPC only constrained tp pri. vtx track parameters
2049       //        constrainTrack(track);
2050       if (track->Charge()>0){
2051         // Cut .1 cm on DCAxy and fill a histogram
2052         if(goodDCA(track)){
2053           // Add to the femto event
2054           fFemtoBuffer->GetEvt(0)->AddPro(track);
2055         }
2056       }
2057       else{
2058         // Cut .1 cm on DCAxy and fill a histogram
2059         if(goodDCA(track)){
2060           // Add to the femto event
2061           fFemtoBuffer->GetEvt(0)->AddAPro(track);
2062         }
2063       }
2064     }
2065   }
2066   else if (track->P() < 3.25){
2067     if (corrTOFsig > 0){
2068       // Create additional TPC only constrained tp pri. vtx track parameters
2069       //        constrainTrack(track);
2070       if (track->Charge()>0){
2071         // Cut .1 cm on DCAxy and fill a histogram
2072         if(goodDCA(track)){
2073           // Add to the femto event
2074           fFemtoBuffer->GetEvt(0)->AddPro(track);
2075         }
2076       }
2077       else{
2078         // Cut .1 cm on DCAxy and fill a histogram
2079         if(goodDCA(track)){
2080           // Add to the femto event
2081           fFemtoBuffer->GetEvt(0)->AddAPro(track);
2082         }
2083       }
2084     }
2085   }
2086 } // End of void ProcessTOF
2087 //________________________________________________________________________
2088 void AliAnalysisTaskProtonLambda::ProcessTPC(AliAODTrack* track){
2089
2090   // Require the TPCpid bit
2091   if (!((fGTI[-track->GetID()-1])->GetStatus() & AliVTrack::kTPCpid))
2092     return;
2093     
2094   // In contrast to ESDs one doesn't check for AliESDtrack::kTOFpid
2095   // but for AliVTrack::kTOFout?? 
2096   // Check how many particles have TOFout bit
2097   // if (track->Charge() > 0){
2098   //   if ((fGTI[-track->GetID()-1])->GetStatus() & AliVTrack::kTOFpid)
2099   //     fPriHistHasTofPos->Fill(1.0);
2100   //   else 
2101   //     fPriHistHasTofPos->Fill(0.0);
2102   // }
2103   // else{
2104   //   if ((fGTI[-track->GetID()-1])->GetStatus() & AliVTrack::kTOFpid)
2105   //     fPriHistHasTofNeg->Fill(1.0);
2106   //   else 
2107   //     fPriHistHasTofNeg->Fill(0.0);
2108   // }
2109
2110   // For all plots <dE/dx> vs p one should use
2111   // the momentum at the inner wall of the TPC.
2112
2113   // Use a TOF cut and fill the same dE/dx histograms
2114   // Bool_t acceptedTOF=kFALSE;
2115   // if ((fGTI[-track->GetID()-1])->GetStatus() & AliVTrack::kTOFpid){
2116   //   if (fPIDResponse->NumberOfSigmasTOF((fGTI[-track->GetID()-1]), AliPID::kProton) > -10.0)
2117   //     acceptedTOF=kTRUE;
2118   // }
2119   // if (acceptedTOF){
2120   //     if (track->Charge() > 0){
2121   //    fPriHistTPCsignalTOFcutPos->Fill((fGTI[-track->GetID()-1])->GetTPCmomentum(),
2122   //                                     (fGTI[-track->GetID()-1])->GetTPCsignal());
2123   //    fPriHistNsigmaTPCTOFcutPos->Fill((fGTI[-track->GetID()-1])->GetTPCmomentum(),
2124   //                                     fPIDResponse->NumberOfSigmasTPC((fGTI[-track->GetID()-1]), AliPID::kProton));
2125   //     }
2126   //     else{
2127   //    fPriHistTPCsignalTOFcutNeg->Fill((fGTI[-track->GetID()-1])->GetTPCmomentum(),
2128   //                                     (fGTI[-track->GetID()-1])->GetTPCsignal());
2129   //    fPriHistNsigmaTPCTOFcutNeg->Fill((fGTI[-track->GetID()-1])->GetTPCmomentum(),
2130   //                                     fPIDResponse->NumberOfSigmasTPC((fGTI[-track->GetID()-1]), AliPID::kProton));
2131   //     }
2132   // }  
2133     
2134   // A first idea of a cut: use the spectra cut.
2135   // (should perhaps change for momenta ~ 0.75 GeV)
2136   if ( ((fGTI[-track->GetID()-1])->GetTPCsignal() > 
2137         fTpcResponse->GetExpectedSignal((fGTI[-track->GetID()-1])->GetTPCmomentum(),
2138                                         AliPID::kProton))
2139       // New since Sept 10th 2012: Also use a cut to reject deuterons.
2140       // I checked: The cut is good!
2141        && ((fGTI[-track->GetID()-1])->GetTPCsignal() <
2142            2.0*fTpcResponse->GetExpectedSignal((fGTI[-track->GetID()-1])->GetTPCmomentum(),
2143                                       AliPID::kProton))
2144                         ) {
2145     // Distinguish between charges
2146     if (track->Charge()>0){
2147       // Cut .1 cm on DCAxy and fill a histogram
2148       if(goodDCA(track)){
2149         // Add to the femto event
2150         fFemtoBuffer->GetEvt(0)->AddPro(track);
2151       }
2152     }
2153     else{
2154       // Cut .1 cm on DCAxy and fill a histogram
2155       if(goodDCA(track)){
2156         // Add to the femto event
2157         fFemtoBuffer->GetEvt(0)->AddAPro(track);
2158       }
2159     }
2160   }
2161 } // End of void ProcessTPC
2162 //________________________________________________________________________
2163 void AliAnalysisTaskProtonLambda::ProcessHybrid(AliAODTrack *track){
2164   
2165   // Intermediate momentum: use dEdx for a pre-selection
2166   // and do the pid with tof
2167   
2168   // Boolean for extra! tpc pid cuts
2169   Bool_t acceptTPC = kTRUE;
2170
2171   // Require the TPCpid bit
2172   if (!((fGTI[-track->GetID()-1])->GetStatus() & AliVTrack::kTPCpid))
2173     acceptTPC = kFALSE;
2174  
2175   // Pre-selection cut with TPC, don't return immediately to be able
2176   // to visualize the effect
2177   if (acceptTPC){
2178     // Do a mild dEdx cut
2179     if ((fGTI[-track->GetID()-1])->GetTPCsignal() < 
2180         fTpcResponse->GetExpectedSignal((fGTI[-track->GetID()-1])->GetTPCmomentum(),
2181                                         AliPID::kElectron))
2182       acceptTPC = kFALSE;
2183   }
2184     
2185   // Ask for TOF pid flag and fill
2186   if (!((fGTI[-track->GetID()-1])->GetStatus() & AliVTrack::kTOFpid))
2187     return;
2188   
2189   // The corrected TOF signal
2190   Double_t corrTOFsig = GetCorrectedTOFSignal(track);
2191   
2192   // Distinguish between charges
2193   if (track->Charge() > 0) {
2194     // Fill the tof signal w/o dedx pre-selection
2195     fPriHistHybridTOFsigPosWoTPC->Fill(corrTOFsig);
2196     // Do the pre-selection
2197     if (acceptTPC){
2198       fPriHistHybridTOFsigPosTPCok->Fill(corrTOFsig);
2199
2200       // Do the tof cut
2201       // Sept '12: also include an upper cut
2202       if ( (corrTOFsig > -1000.0) && (corrTOFsig < 1250.) ){
2203         // Create additional TPC only constrained to pri. vtx track parameters
2204         //      constrainTrack(track);
2205         // Cut .1 cm on DCAxy and fill a histogram
2206         if(goodDCA(track)){
2207           // Add to the femto event
2208           fFemtoBuffer->GetEvt(0)->AddPro(track);
2209         }
2210       }
2211     }
2212   }
2213   else {
2214     // Fill the tof signal w/o dedx pre-selection
2215     fPriHistHybridTOFsigNegWoTPC->Fill(corrTOFsig);
2216     // Do the pre-selection
2217     if (acceptTPC){
2218       fPriHistHybridTOFsigNegTPCok->Fill(corrTOFsig);
2219       
2220       // Do the tof cut
2221       // Sept '12: also include an upper cut
2222       if ( (corrTOFsig > -1000.0) && (corrTOFsig < 1250.) ){
2223         // Create additional TPC only constrained to pri. vtx track parameters
2224         //      constrainTrack(track);
2225         // Cut .1 cm on DCAxy and fill a histogram
2226         if(goodDCA(track)){
2227           // add to the femto event
2228           fFemtoBuffer->GetEvt(0)->AddAPro(track);
2229         }
2230       }
2231     }
2232   }
2233 } // End of ProcessHybrid
2234 //________________________________________________________________________
2235 void AliAnalysisTaskProtonLambda::CleaningProcedure() {
2236   // fFemtoBuffer->GetEvt(0) pointer must be set
2237   // Checks that no tracks are shared between Lam & Lam, Lam & Pro, ALam & ALam, ALam & APro
2238
2239   // printf ("Cleaning procedure. Lam: %d, ALam: %d, Pro: %d, APro:%d\n"
2240   //      ,fFemtoBuffer->GetEvt(0)->GetNLam(),fFemtoBuffer->GetEvt(0)->GetNALam(),fFemtoBuffer->GetEvt(0)->GetNPro(),fFemtoBuffer->GetEvt(0)->GetNAPro());
2241
2242   //
2243   // Check for lambdas..
2244   //
2245   for (Int_t i=0;i<fFemtoBuffer->GetEvt(0)->GetNLam();i++) {
2246     if (!fFemtoBuffer->GetEvt(0)->fLamTracks[i].UseIt())
2247       continue;
2248     // Unique track id's for first V0
2249     Int_t posId1 = fFemtoBuffer->GetEvt(0)->fLamTracks[i].fPosDaughter.fID;
2250     Int_t negId1 = fFemtoBuffer->GetEvt(0)->fLamTracks[i].fNegDaughter.fID;
2251
2252     // .. & lambdas
2253     for (Int_t j=i+1;j<fFemtoBuffer->GetEvt(0)->GetNLam();j++){
2254       if (!fFemtoBuffer->GetEvt(0)->fLamTracks[j].UseIt())
2255         continue;
2256       // Unique track id's for second V0
2257       Int_t posId2 = fFemtoBuffer->GetEvt(0)->fLamTracks[j].fPosDaughter.fID;
2258       Int_t negId2 = fFemtoBuffer->GetEvt(0)->fLamTracks[j].fPosDaughter.fID;
2259       
2260       // If V0s share a track remove one
2261       if (posId1 == posId2 || negId1 == negId2){
2262
2263         // printf ("shared track lamlam! posId1: %d, posId2: %d, negId1: %d, negId2: %d\n",
2264         //      posId1, posId2, negId1, negId2);
2265         
2266         // Use a criterion to select best V0
2267         if (fFemtoBuffer->GetEvt(0)->fLamTracks[i].fCosPoint > fFemtoBuffer->GetEvt(0)->fLamTracks[j].fCosPoint){
2268           fFemtoBuffer->GetEvt(0)->fLamTracks[j].SetBadFlag();
2269         }
2270         else{
2271           fFemtoBuffer->GetEvt(0)->fLamTracks[i].SetBadFlag();
2272         }
2273       }
2274       
2275     } // Scnd V0 loop
2276
2277     if (!fFemtoBuffer->GetEvt(0)->fLamTracks[i].UseIt())
2278       continue;
2279
2280     // .. & protons
2281     for (Int_t j=0;j<fFemtoBuffer->GetEvt(0)->GetNPro();j++){
2282       if (!fFemtoBuffer->GetEvt(0)->fProTracks[j].UseIt())
2283         continue;
2284       // Unique track id's for second V0
2285       Int_t posId2 = fFemtoBuffer->GetEvt(0)->fProTracks[j].fID;
2286       
2287       // If V0 and proton share a track
2288       if (posId1 == posId2){
2289         //      printf ("shared track lam p! id:%d\n",posId1);
2290         
2291         // Remove the proton
2292         fFemtoBuffer->GetEvt(0)->fProTracks[j].SetBadFlag();
2293       }
2294       
2295     } // Proton loop
2296
2297   } // First V0 loop
2298
2299   //
2300   // Check for anti-lambdas..
2301   //
2302   for (Int_t i=0;i<fFemtoBuffer->GetEvt(0)->GetNALam();i++){
2303     if (!fFemtoBuffer->GetEvt(0)->fALamTracks[i].UseIt())
2304       continue;
2305     // Unique track id's for first V0
2306     Int_t posId1 = fFemtoBuffer->GetEvt(0)->fALamTracks[i].fPosDaughter.fID;
2307     Int_t negId1 = fFemtoBuffer->GetEvt(0)->fALamTracks[i].fNegDaughter.fID;
2308
2309     // .. & anti-lambdas
2310     for (Int_t j=i+1;j<fFemtoBuffer->GetEvt(0)->GetNALam();j++){
2311       if (!fFemtoBuffer->GetEvt(0)->fALamTracks[j].UseIt())
2312         continue;
2313       // Unique track id's for second V0
2314       Int_t posId2 = fFemtoBuffer->GetEvt(0)->fALamTracks[j].fPosDaughter.fID;
2315       Int_t negId2 = fFemtoBuffer->GetEvt(0)->fALamTracks[j].fNegDaughter.fID;
2316       
2317       // If V0s share a track remove one
2318       if (posId1 == posId2 || negId1 == negId2){
2319         
2320         // printf ("shared track ALamALam! posId1: %d, posId2: %d, negId1: %d, negId2: %d\n",
2321         //      posId1, posId2, negId1, negId2);
2322
2323         // Use a criterion to select best V0
2324         if (fFemtoBuffer->GetEvt(0)->fALamTracks[i].fCosPoint > fFemtoBuffer->GetEvt(0)->fALamTracks[j].fCosPoint){
2325           fFemtoBuffer->GetEvt(0)->fALamTracks[j].SetBadFlag();
2326         }
2327         else{
2328           fFemtoBuffer->GetEvt(0)->fALamTracks[i].SetBadFlag();
2329         }
2330       }
2331       
2332     } // Scnd anti-V0 loop
2333
2334     if (!fFemtoBuffer->GetEvt(0)->fALamTracks[i].UseIt())
2335       continue;
2336     
2337     // .. & anti-protons
2338     for (Int_t j=0;j<fFemtoBuffer->GetEvt(0)->GetNAPro();j++){
2339       if (!fFemtoBuffer->GetEvt(0)->fAProTracks[j].UseIt())
2340         continue;
2341       // Unique track id's for second V0
2342       Int_t negId2 = fFemtoBuffer->GetEvt(0)->fAProTracks[j].fID;
2343       
2344       // If V0 and proton share a track
2345       if (negId1 == negId2){
2346         //      printf ("shared track alam ap! id:%d\n",posId1);
2347
2348         // Remove the proton
2349         fFemtoBuffer->GetEvt(0)->fAProTracks[j].SetBadFlag();
2350       }
2351       
2352     } // Anti-proton loop
2353
2354   } // First anti-V0 loop
2355
2356   //
2357   // Do the same with the side band background.
2358   // Discard background when sharing track with primary proton.
2359   //
2360
2361    for (Int_t i=0;i<fFemtoBuffer->GetEvt(0)->GetNBgLam();i++){
2362     if (!fFemtoBuffer->GetEvt(0)->fBgLamTracks[i].UseIt())
2363       continue;
2364     // Unique track id's for first V0
2365     Int_t posId1 = fFemtoBuffer->GetEvt(0)->fBgLamTracks[i].fPosDaughter.fID;
2366     Int_t negId1 = fFemtoBuffer->GetEvt(0)->fBgLamTracks[i].fNegDaughter.fID;
2367
2368     // .. & lambdas
2369     for (Int_t j=i+1;j<fFemtoBuffer->GetEvt(0)->GetNBgLam();j++){
2370       if (!fFemtoBuffer->GetEvt(0)->fBgLamTracks[j].UseIt())
2371         continue;
2372       // Unique track id's for second V0
2373       Int_t posId2 = fFemtoBuffer->GetEvt(0)->fBgLamTracks[j].fPosDaughter.fID;
2374       Int_t negId2 = fFemtoBuffer->GetEvt(0)->fBgLamTracks[j].fNegDaughter.fID;
2375       
2376       // If V0s share a track remove one
2377       if (posId1 == posId2 || negId1 == negId2){
2378
2379         // printf ("shared track bglambglam! posId1: %d, posId2: %d, negId1: %d, negId2: %d\n",
2380         //      posId1, posId2, negId1, negId2);
2381         
2382         // Use a criterion to select best V0
2383         if (fFemtoBuffer->GetEvt(0)->fBgLamTracks[i].fCosPoint > fFemtoBuffer->GetEvt(0)->fBgLamTracks[j].fCosPoint){
2384           fFemtoBuffer->GetEvt(0)->fBgLamTracks[j].SetBadFlag();
2385         }
2386         else{
2387           fFemtoBuffer->GetEvt(0)->fBgLamTracks[i].SetBadFlag();
2388         }
2389       }
2390       
2391     } // Scnd V0 loop
2392
2393     if (!fFemtoBuffer->GetEvt(0)->fBgLamTracks[i].UseIt())
2394       continue;
2395
2396     // .. & protons
2397     for (Int_t j=0;j<fFemtoBuffer->GetEvt(0)->GetNPro();j++) {
2398       if (!fFemtoBuffer->GetEvt(0)->fProTracks[j].UseIt())
2399         continue;
2400       if (!fFemtoBuffer->GetEvt(0)->fBgLamTracks[i].UseIt())
2401         continue;
2402
2403       // Unique track id's for second V0
2404       Int_t posId2 = fFemtoBuffer->GetEvt(0)->fProTracks[j].fID;
2405       
2406       // If V0 and proton share a track
2407       if (posId1 == posId2){
2408         //      printf ("shared track bglam p! id:%d\n",posId1);
2409         // Remove the background lambda
2410         fFemtoBuffer->GetEvt(0)->fBgLamTracks[i].SetBadFlag();
2411       }
2412       
2413     } // Proton loop
2414
2415   } // First V0 loop
2416
2417   //
2418   // Check for anti-lambdas..
2419   //
2420   for (Int_t i=0;i<fFemtoBuffer->GetEvt(0)->GetNBgALam();i++){
2421     if (!fFemtoBuffer->GetEvt(0)->fBgALamTracks[i].UseIt())
2422       continue;
2423     // Unique track id's for first V0
2424     Int_t posId1 = fFemtoBuffer->GetEvt(0)->fBgALamTracks[i].fPosDaughter.fID;
2425     Int_t negId1 = fFemtoBuffer->GetEvt(0)->fBgALamTracks[i].fNegDaughter.fID;
2426
2427     // .. & anti-lambdas
2428     for (Int_t j=i+1;j<fFemtoBuffer->GetEvt(0)->GetNBgALam();j++){
2429       if (!fFemtoBuffer->GetEvt(0)->fBgALamTracks[j].UseIt())
2430         continue;
2431       // Unique track id's for second V0
2432       Int_t posId2 = fFemtoBuffer->GetEvt(0)->fBgALamTracks[j].fPosDaughter.fID;
2433       Int_t negId2 = fFemtoBuffer->GetEvt(0)->fBgALamTracks[j].fNegDaughter.fID;
2434       
2435       // If V0s share a track remove one
2436       if (posId1 == posId2 || negId1 == negId2){
2437         
2438         // printf ("shared track BgALamBgALam! posId1: %d, posId2: %d, negId1: %d, negId2: %d\n",
2439         //      posId1, posId2, negId1, negId2);
2440
2441         // Use a criterion to select best V0
2442         if (fFemtoBuffer->GetEvt(0)->fBgALamTracks[i].fCosPoint > fFemtoBuffer->GetEvt(0)->fBgALamTracks[j].fCosPoint){
2443           fFemtoBuffer->GetEvt(0)->fBgALamTracks[j].SetBadFlag();
2444         }
2445         else{
2446           fFemtoBuffer->GetEvt(0)->fBgALamTracks[i].SetBadFlag();
2447         }
2448       }
2449       
2450     } // Scnd anti-V0 loop
2451
2452     if (!fFemtoBuffer->GetEvt(0)->fBgALamTracks[i].UseIt())
2453       continue;
2454     
2455     // .. & anti-protons
2456     for (Int_t j=0;j<fFemtoBuffer->GetEvt(0)->GetNAPro();j++){
2457       if (!fFemtoBuffer->GetEvt(0)->fAProTracks[j].UseIt())
2458         continue;
2459       if (!fFemtoBuffer->GetEvt(0)->fBgALamTracks[i].UseIt())
2460         continue;
2461       
2462       // Unique track id's for second V0
2463       Int_t negId2 = fFemtoBuffer->GetEvt(0)->fAProTracks[j].fID;
2464       
2465       // If V0 and proton share a track
2466       if (negId1 == negId2){
2467         //      printf ("shared track bgalam ap! id:%d\n",posId1);
2468         // Remove the background anti-lambda
2469         fFemtoBuffer->GetEvt(0)->fBgALamTracks[i].SetBadFlag();
2470       }
2471       
2472     } // Anti-proton loop
2473
2474   } // First anti-V0 loop
2475
2476   
2477 }
2478 //________________________________________________________________________
2479 void AliAnalysisTaskProtonLambda::ProcessReal() {
2480   // Process real events
2481   
2482   // // Count the number of pairs before TTR cut
2483   // Int_t nLamLamPairsWoTTR = 0,nLamProPairsWoTTR=0,nALamALamPairsWoTTR=0,nALamAProPairsWoTTR=0;
2484   // // and with TTR cut
2485   // Int_t nLamLamPairs = 0,nLamProPairs=0,nALamALamPairs=0,nALamAProPairs=0;
2486
2487   // Declare numbers to speed up the code
2488   Int_t iLam,//iLam2,
2489     iRadius,iPro,iALam,
2490     //iALam2,
2491     iAPro,nMeasPro,
2492     //nMeasPio,
2493     nMeasAPro;
2494   //  Int_t nMeasProIroc,nMeasPioIroc,nMeasAProIroc,nMeasProOroc,nMeasPioOroc,nMeasAProOroc;
2495   // Float_t distPro,distPio,minDistPro,meanDistPro,minDistPio,meanDistPio,
2496   //   distAPro,minDistAPro,meanDistAPro;
2497   Float_t distSftPro,//distSftPio,
2498     minDistSftPro,meanDistSftPro,//minDistSftPio,meanDistSftPio,
2499     distSftAPro,minDistSftAPro,meanDistSftAPro;
2500   // Float_t minDistSftIrocPro,meanDistSftIrocPro,minDistSftIrocPio,meanDistSftIrocPio,
2501   //   minDistSftIrocAPro,meanDistSftIrocAPro;
2502   // Float_t minDistSftOrocPro,meanDistSftOrocPro,minDistSftOrocPio,meanDistSftOrocPio,
2503   //   minDistSftOrocAPro,meanDistSftOrocAPro;
2504   
2505   // printf("Real event, NLam: %d, NPro %d, NALam %d, NAPro %d\n",
2506   //     fFemtoBuffer->GetEvt(0)->GetNLam(),
2507   //     fFemtoBuffer->GetEvt(0)->GetNPro(),
2508   //     fFemtoBuffer->GetEvt(0)->GetNALam(),
2509   //     fFemtoBuffer->GetEvt(0)->GetNAPro()
2510   //     );
2511   // Lambda loop
2512   for (iLam = 0; iLam < fFemtoBuffer->GetEvt(0)->GetNLam(); iLam++){
2513
2514     // Skip if unUseIt() entry
2515     if (!fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].UseIt())
2516       continue;
2517     
2518     // // Second lambda loop
2519     // for (iLam2 = iLam+1; iLam2 < fFemtoBuffer->GetEvt(0)->GetNLam(); iLam2++){
2520
2521     //   // Skip if unUseIt() entry
2522     //   if (!fFemtoBuffer->GetEvt(0)->fLamTracks[iLam2].UseIt())
2523     //  continue;
2524
2525     //   // Count the number of lam-lam pairs
2526     //   nLamLamPairsWoTTR++;
2527
2528     //   // Reset the distances for each pair
2529     //   minDistPro=999.0;meanDistPro=0.0;minDistPio=999.0;meanDistPio=0.0;
2530     //   minDistSftPro=999.0;meanDistSftPro=0.0;minDistSftPio=999.0;meanDistSftPio=0.0;
2531     //   minDistSftIrocPro=999.0;meanDistSftIrocPro=0.0;minDistSftIrocPio=999.0;meanDistSftIrocPio=0.0;
2532     //   minDistSftOrocPro=999.0;meanDistSftOrocPro=0.0;minDistSftOrocPio=999.0;meanDistSftOrocPio=0.0;
2533     //   // Reset the number of measurements for the mean
2534     //   nMeasPro=0;nMeasPio=0;nMeasProIroc=0;nMeasPioIroc=0;
2535     //   nMeasProOroc=0;nMeasPioOroc=0;
2536
2537     //   // Check for two-track resolution
2538     //   for (iRadius=0;iRadius<9;iRadius++){
2539     //  // Get the spatial distance at each radius
2540     //  distPro = calcDist(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].fPosDaughter.fXglobal[iRadius],fFemtoBuffer->GetEvt(0)->fLamTracks[iLam2].fPosDaughter.fXglobal[iRadius]);
2541     //  distPio = calcDist(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].fNegDaughter.fXglobal[iRadius],fFemtoBuffer->GetEvt(0)->fLamTracks[iLam2].fNegDaughter.fXglobal[iRadius]);
2542     //  // Shifted distances
2543     //  distSftPro = calcDist(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].fPosDaughter.fXshifted[iRadius],fFemtoBuffer->GetEvt(0)->fLamTracks[iLam2].fPosDaughter.fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),fFemtoBuffer->GetEvt(0));
2544     //  distSftPio = calcDist(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].fNegDaughter.fXshifted[iRadius],fFemtoBuffer->GetEvt(0)->fLamTracks[iLam2].fNegDaughter.fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),fFemtoBuffer->GetEvt(0));
2545
2546     //  // calcDist returns -2.0 if one shouldn't use this distance, see calcDist function
2547     //  if (distPro > -1.0) {
2548     //    // Minimum distance
2549     //    if (distPro < minDistPro)
2550     //      minDistPro = distPro;
2551     //    if (distSftPro < minDistSftPro)
2552     //      minDistSftPro = distSftPro;
2553     //    // Mean distance
2554     //    meanDistPro+=distPro;
2555     //    meanDistSftPro+=distSftPro;
2556     //    nMeasPro++;
2557         
2558     //    // IROC
2559     //    if (iRadius<3){
2560     //      if (distSftPro < minDistSftIrocPro)
2561     //        minDistSftIrocPro = distSftPro;
2562     //      meanDistSftIrocPro+=distSftPro;
2563     //      nMeasProIroc++;
2564     //    }
2565     //    // OROC
2566     //    else {
2567     //      if (distSftPro < minDistSftOrocPro)
2568     //        minDistSftOrocPro = distSftPro;
2569     //      meanDistSftOrocPro+=distSftPro;
2570     //      nMeasProOroc++;         
2571     //    }
2572     //  }
2573     //  if (distPio > -1.0){
2574     //    // Minimum distance
2575     //    if (distPio < minDistPio)
2576     //      minDistPio = distPio;
2577     //    if (distSftPio < minDistSftPio)
2578     //      minDistSftPio = distSftPio;
2579     //    // Mean distance
2580     //    meanDistPio+=distPio;
2581     //    meanDistSftPio+=distSftPio;
2582     //    nMeasPio++; 
2583           
2584     //    // IROC
2585     //    if (iRadius<3){
2586     //      if (distSftPio < minDistSftIrocPio)
2587     //        minDistSftIrocPio = distSftPio;
2588     //      meanDistSftIrocPio+=distSftPio;
2589     //      nMeasPioIroc++;
2590     //    }
2591     //    // OROC
2592     //    else {
2593     //      if (distSftPio < minDistSftOrocPio)
2594     //        minDistSftOrocPio = distSftPio;
2595     //      meanDistSftOrocPio+=distSftPio;
2596     //      nMeasPioOroc++;         
2597     //    }
2598
2599     //  }
2600
2601     //   } // Loop over iRadius
2602       
2603     //   // Require at least one measurement
2604     //   if ( (!nMeasPio) || (!nMeasPro) )
2605     //  continue;
2606
2607     //   // Divide by the number of measurements to get the mean
2608     //   meanDistPro /= (Float_t)nMeasPro;
2609     //   meanDistPio /= (Float_t)nMeasPio;
2610     //   meanDistSftPro /= (Float_t)nMeasPro;
2611     //   meanDistSftPio /= (Float_t)nMeasPio;
2612       
2613     //   // Fill the two track resolution histograms
2614     //   f2HistLamLamMeanMinDistProReal->Fill(meanDistPro,minDistPro);
2615     //   f2HistLamLamMeanMinDistPioReal->Fill(meanDistPio,minDistPio);
2616
2617     //   f2HistSftLamLamMeanMinDistProReal->Fill(meanDistSftPro,minDistSftPro);
2618     //   f2HistSftLamLamMeanMinDistPioReal->Fill(meanDistSftPio,minDistSftPio);
2619
2620     //   // Fill IROC / OROC histograms only with at least one measurement
2621     //   if (nMeasProIroc){
2622     //  meanDistSftIrocPro /= (Float_t)nMeasProIroc;
2623     //  f2HistSftIrocLamLamMeanMinDistProReal->Fill(meanDistSftIrocPro,minDistSftIrocPro);
2624     //   }
2625     //   if (nMeasPioIroc){
2626     //  meanDistSftIrocPio /= (Float_t)nMeasPioIroc;
2627     //  f2HistSftIrocLamLamMeanMinDistPioReal->Fill(meanDistSftIrocPio,minDistSftIrocPio);
2628     //   }
2629     //   if (nMeasProOroc){
2630     //  meanDistSftOrocPro /= (Float_t)nMeasProOroc;
2631     //  f2HistSftOrocLamLamMeanMinDistProReal->Fill(meanDistSftOrocPro,minDistSftOrocPro);
2632     //   }
2633     //   if (nMeasPioOroc){
2634     //  meanDistSftOrocPio /= (Float_t)nMeasPioOroc;
2635     //  f2HistSftOrocLamLamMeanMinDistPioReal->Fill(meanDistSftOrocPio,minDistSftOrocPio);
2636     //   }
2637
2638     //   // Do a cut (value needs to be refined)
2639     //   //      if ( meanDistSftPro < 2.0 || meanDistSftPio < 2.0 )
2640     //   //     continue;
2641       
2642     //   // Count the number of pairs
2643     //   nLamLamPairs++;
2644
2645     //   // Mt of the pair
2646     //   f2HistMtLamLamReal->Fill(mt(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam],
2647     //                                    fFemtoBuffer->GetEvt(0)->fLamTracks[iLam2]));
2648
2649     //   // Fill the qinv, minv histogram
2650     //   f3HistLamLamQinvReal->Fill(Qinv(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam], fFemtoBuffer->GetEvt(0)->fLamTracks[iLam2]),minDistSftPro,minDistSftPio);
2651     //   f3HistLamLamMinvReal->Fill(Minv(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam], fFemtoBuffer->GetEvt(0)->fLamTracks[iLam2]),minDistSftPro,minDistSftPio);
2652       
2653     //   // Mt of the pair fr low q pairs only
2654     //   if(Qinv(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam],
2655     //        fFemtoBuffer->GetEvt(0)->fLamTracks[iLam2]) < .2)
2656     //  f2HistMtLowQLamLamReal->Fill(mt(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam],
2657     //                                  fFemtoBuffer->GetEvt(0)->fLamTracks[iLam2]));
2658
2659     // } // Second lambda loop
2660
2661     // Proton loop
2662     for (iPro=0;iPro<fFemtoBuffer->GetEvt(0)->GetNPro();iPro++){
2663
2664       // Skip if unUseIt() entry
2665       if (!fFemtoBuffer->GetEvt(0)->fProTracks[iPro].UseIt())
2666         continue;
2667
2668       //      printf(".");
2669       //      nLamProPairsWoTTR++;
2670
2671       // Reset the distances for each pair
2672       // minDistPro=999.0;meanDistPro=0.0;
2673       minDistSftPro=999.0;meanDistSftPro=0.0;
2674       //minDistSftIrocPro=999.0;meanDistSftIrocPro=0.0;minDistSftOrocPro=999.0;meanDistSftOrocPro=0.0;
2675       // Reset the number of measurements for the mean
2676       nMeasPro=0;//nMeasProIroc=0;nMeasProOroc=0;
2677       
2678       // Check for two-track resolution
2679       for (iRadius=0;iRadius<9;iRadius++){
2680         // Get the spatial distance at each radius
2681         //      distPro = calcDist(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].fPosDaughter.fXglobal[iRadius],fFemtoBuffer->GetEvt(0)->fProTracks[iPro].fXglobal[iRadius]);
2682         distSftPro = calcDist(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].fPosDaughter.fXshifted[iRadius],fFemtoBuffer->GetEvt(0)->fProTracks[iPro].fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),fFemtoBuffer->GetEvt(0));
2683
2684         // calcDist returns -2.0 if one shouldn't use this distance, see calcDist function
2685         if (distSftPro > -1.0){
2686           // Minimum distance
2687           // if (distPro < minDistPro)
2688           //   minDistPro = distPro;
2689           if (distSftPro < minDistSftPro)
2690             minDistSftPro = distSftPro;
2691           // Mean distance
2692           //      meanDistPro+=distPro;
2693           meanDistSftPro+=distSftPro;
2694           nMeasPro++;
2695           
2696           // // IROC                                   
2697           // if (iRadius<3){
2698           //   if (distSftPro < minDistSftIrocPro)
2699           //     minDistSftIrocPro = distSftPro;
2700           //   meanDistSftIrocPro+=distSftPro;
2701           //   nMeasProIroc++;
2702           // }
2703           // // OROC                                   
2704           // else {
2705           //   if (distSftPro < minDistSftOrocPro)
2706           //     minDistSftOrocPro = distSftPro;
2707           //   meanDistSftOrocPro+=distSftPro;
2708           //   nMeasProOroc++;
2709           // }
2710
2711
2712         }
2713       } // Loop over iRadius
2714
2715       // Require at least one measurement
2716       if ( !nMeasPro )
2717         continue;
2718
2719       // Divide by the number of measurements to get the mean
2720       //      meanDistPro /= (Float_t)nMeasPro;
2721       meanDistSftPro /= (Float_t)nMeasPro;
2722       
2723       // Fill the two track resolution histogram
2724       // f2HistLamProMeanMinDistProReal->Fill(meanDistPro,minDistPro);
2725       // f2HistSftLamProMeanMinDistProReal->Fill(meanDistSftPro,minDistSftPro);
2726
2727       // // Fill IROC / OROC histograms only with at least one measurement                                
2728       // if (nMeasProIroc){
2729       //   meanDistSftIrocPro /= (Float_t)nMeasProIroc;
2730       //   f2HistSftIrocLamProMeanMinDistProReal->Fill(meanDistSftIrocPro,minDistSftIrocPro);
2731       // }
2732       // if (nMeasProOroc){
2733       //   meanDistSftOrocPro /= (Float_t)nMeasProOroc;
2734       //   f2HistSftOrocLamProMeanMinDistProReal->Fill(meanDistSftOrocPro,minDistSftOrocPro);
2735       // }
2736         
2737       // Do a cut (value needs to be refined)
2738       //      if ( meanDistSftPro < 2.0 )
2739       //        continue;
2740
2741       // Look at possible residual correlations of the daughters
2742       // vs mean dist of protons
2743       //      f2HistLamPosDProQinvReal->Fill(QinvProPro(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].fPosDaughter, fFemtoBuffer->GetEvt(0)->fProTracks[iPro]),meanDistSftPro);
2744       //      f2HistLamNegDProQinvReal->Fill(QinvPioPro(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].fNegDaughter, fFemtoBuffer->GetEvt(0)->fProTracks[iPro]),meanDistSftPro);
2745   
2746
2747       // Count the number of pairs
2748       //      nLamProPairs++;
2749
2750       // Mt of the pair
2751       f2HistMtLamProReal->Fill(mt(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam],
2752                                   fFemtoBuffer->GetEvt(0)->fProTracks[iPro]));
2753
2754       // THnSparse with qinvpropro, mean dist propro, min dist propro, qinv lampro
2755       Double_t x[4]={
2756         QinvProPro(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].fPosDaughter,
2757                    fFemtoBuffer->GetEvt(0)->fProTracks[iPro]),
2758         meanDistSftPro,
2759         minDistSftPro,
2760         Qinv(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam],
2761              fFemtoBuffer->GetEvt(0)->fProTracks[iPro])
2762       };
2763       LamProReal->Fill(x);
2764
2765       // Fill the qinv histogram, using TPC only momentum for primary protons
2766       //      f3HistLamProQinvReal->Fill(Qinv(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam], fFemtoBuffer->GetEvt(0)->fProTracks[iPro]),meanDistSftPro,minDistSftPro); // Using THnSparse since sept '12
2767       //      f3HistLamProMinvReal->Fill(Minv(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam], fFemtoBuffer->GetEvt(0)->fProTracks[iPro]),meanDistSftPro,minDistSftPro);
2768       // and using TPC only plus primary vertex constraint momentum for primary protons
2769       //      f3HistLamProQinvConstrReal->Fill(QinvConstr(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam], fFemtoBuffer->GetEvt(0)->fProTracks[iPro]),meanDistSftPro,minDistSftPro);
2770
2771       // Mt of the pair for low q pairs only
2772       if(Qinv(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam],
2773               fFemtoBuffer->GetEvt(0)->fProTracks[iPro]) < .2)
2774         f2HistMtLowQLamProReal->Fill(mt(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam],
2775                                         fFemtoBuffer->GetEvt(0)->fProTracks[iPro]));
2776       
2777     }// Proton loop
2778
2779   }// Lambda loop
2780
2781
2782   
2783   // Anti-lambda loop
2784   for (iALam = 0; iALam < fFemtoBuffer->GetEvt(0)->GetNALam(); iALam++){
2785
2786     // Skip if unUseIt() entry
2787     if (!fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].UseIt())
2788       continue;
2789
2790     // // Second anti-lambda loop
2791     // for (iALam2 = iALam+1; iALam2 < fFemtoBuffer->GetEvt(0)->GetNALam(); iALam2++){
2792
2793     //   // Skip if unUseIt() entry
2794     //   if (!fFemtoBuffer->GetEvt(0)->fALamTracks[iALam2].UseIt())
2795     //  continue;
2796
2797     //   // Count the number of antilam-antilam pairs
2798     //   nALamALamPairsWoTTR++;
2799
2800     //   // Reset the distances for each pair
2801     //   minDistAPro=999.0;meanDistAPro=0.0;minDistPio=999.0;meanDistPio=0.0;
2802     //   minDistSftAPro=999.0;meanDistSftAPro=0.0;minDistSftPio=999.0;meanDistSftPio=0.0;
2803     //   minDistSftIrocAPro=999.0;meanDistSftIrocAPro=0.0;minDistSftIrocPio=999.0;meanDistSftIrocPio=0.0;
2804     //   minDistSftOrocAPro=999.0;meanDistSftOrocAPro=0.0;minDistSftOrocPio=999.0;meanDistSftOrocPio=0.0;
2805     //   // Reset the number of measurements for the mean
2806     //   nMeasAPro=0;nMeasPio=0;nMeasAProIroc=0;nMeasPioIroc=0;nMeasAProOroc=0;nMeasPioOroc=0;
2807
2808     //   // Check for two-track resolution
2809     //   for (iRadius=0;iRadius<9;iRadius++){
2810     //  // Get the spatial distance at each radius
2811     //  distPio = calcDist(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].fPosDaughter.fXglobal[iRadius],fFemtoBuffer->GetEvt(0)->fALamTracks[iALam2].fPosDaughter.fXglobal[iRadius]);
2812     //  distAPro = calcDist(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].fNegDaughter.fXglobal[iRadius],fFemtoBuffer->GetEvt(0)->fALamTracks[iALam2].fNegDaughter.fXglobal[iRadius]);
2813     //  // Shifted distances
2814     //  distSftPio = calcDist(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].fPosDaughter.fXshifted[iRadius],fFemtoBuffer->GetEvt(0)->fALamTracks[iALam2].fPosDaughter.fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),fFemtoBuffer->GetEvt(0));
2815     //  distSftAPro = calcDist(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].fNegDaughter.fXshifted[iRadius],fFemtoBuffer->GetEvt(0)->fALamTracks[iALam2].fNegDaughter.fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),fFemtoBuffer->GetEvt(0));
2816
2817     //  // calcDist returns -2.0 if one shouldn't use this distance, see calcDist function
2818     //     if (distAPro > -1.0){
2819     //       // Minimum distance
2820     //       if (distAPro < minDistAPro)
2821     //         minDistAPro = distAPro;
2822     //    if (distSftAPro < minDistSftAPro)
2823     //         minDistSftAPro = distSftAPro;
2824     //       // Mean distance
2825     //       meanDistAPro+=distAPro;
2826     //       meanDistSftAPro+=distSftAPro;
2827     //       nMeasAPro++;
2828
2829     //    // IROC                                                      
2830     //       if (iRadius<3){
2831     //         if (distSftAPro < minDistSftIrocAPro)
2832     //           minDistSftIrocAPro = distSftAPro;
2833     //         meanDistSftIrocAPro+=distSftAPro;
2834     //         nMeasAProIroc++;
2835     //       }
2836     //       // OROC                                                         
2837     //       else {
2838     //         if (distSftAPro < minDistSftOrocAPro)
2839     //           minDistSftOrocAPro = distSftAPro;
2840     //         meanDistSftOrocAPro+=distSftAPro;
2841     //         nMeasAProOroc++;
2842     //       }
2843
2844     //     }
2845     //     if (distPio > -1.0){
2846     //       // Minimum distance
2847     //       if (distPio < minDistPio)
2848     //         minDistPio = distPio;
2849     //       if (distSftPio < minDistSftPio)
2850     //         minDistSftPio = distSftPio;
2851     //       // Mean distance
2852     //       meanDistPio+=distPio;
2853     //       meanDistSftPio+=distSftPio;
2854     //       nMeasPio++; 
2855
2856     //    // IROC                                                         
2857     //       if (iRadius<3){
2858     //         if (distSftPio < minDistSftIrocPio)
2859     //           minDistSftIrocPio = distSftPio;
2860     //         meanDistSftIrocPio+=distSftPio;
2861     //         nMeasPioIroc++;
2862     //       }
2863     //       // OROC                                                         
2864     //       else {
2865     //         if (distSftPio < minDistSftOrocPio)
2866     //           minDistSftOrocPio = distSftPio;
2867     //         meanDistSftOrocPio+=distSftPio;
2868     //         nMeasPioOroc++;
2869     //       }
2870     //     }
2871     //   } // Loop over iRadius
2872       
2873     //   // Require at least one measurement
2874     //   if ( (!nMeasPio) || (!nMeasAPro) )
2875     //     continue;
2876
2877     //   // Divide by the number of measurements to get the mean
2878     //   meanDistAPro /= (Float_t)nMeasAPro;
2879     //   meanDistPio /= (Float_t)nMeasPio;
2880     //   meanDistSftAPro /= (Float_t)nMeasAPro;
2881     //   meanDistSftPio /= (Float_t)nMeasPio;
2882
2883     //   // Fill the two track resolution histograms
2884     //   f2HistALamALamMeanMinDistAProReal->Fill(meanDistAPro,minDistAPro);
2885     //   f2HistALamALamMeanMinDistPioReal->Fill(meanDistPio,minDistPio);
2886
2887     //   f2HistSftALamALamMeanMinDistAProReal->Fill(meanDistSftAPro,minDistSftAPro);
2888     //   f2HistSftALamALamMeanMinDistPioReal->Fill(meanDistSftPio,minDistSftPio);
2889
2890     //   // Fill IROC / OROC histograms only with at least one measurement   
2891     //   if (nMeasAProIroc){
2892     //     meanDistSftAPro /= (Float_t)nMeasAProIroc;
2893     //     f2HistSftIrocALamALamMeanMinDistAProReal->Fill(meanDistSftIrocAPro,minDistSftIrocAPro);
2894     //   }
2895     //   if (nMeasPioIroc){
2896     //     meanDistSftPio /= (Float_t)nMeasPioIroc;
2897     //     f2HistSftIrocALamALamMeanMinDistPioReal->Fill(meanDistSftIrocPio,minDistSftIrocPio);
2898     //   }
2899     //   if (nMeasAProOroc){
2900     //     meanDistSftAPro /= (Float_t)nMeasAProOroc;
2901     //     f2HistSftOrocALamALamMeanMinDistAProReal->Fill(meanDistSftOrocAPro,minDistSftOrocAPro);
2902     //   }
2903     //   if (nMeasPioOroc){
2904     //     meanDistSftPio /= (Float_t)nMeasPioOroc;
2905     //     f2HistSftOrocALamALamMeanMinDistPioReal->Fill(meanDistSftOrocPio,minDistSftOrocPio);
2906     //   }
2907
2908
2909     //   //      // Do a cut (value needs to be refined)
2910     //   //      if ( meanDistSftAPro < 2.0 || meanDistSftPio < 2.0 )
2911     //   //     continue;
2912       
2913     //   // Count the number of pairs
2914     //   nALamALamPairs++;
2915
2916     //   // Mt of the pair
2917     //   f2HistMtALamALamReal->Fill(mt(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam],
2918     //                              fFemtoBuffer->GetEvt(0)->fALamTracks[iALam2]));
2919
2920     //   // Fill the qinv, minv histogram 
2921     //   f3HistALamALamQinvReal->Fill(Qinv(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam], fFemtoBuffer->GetEvt(0)->fALamTracks[iALam2]),minDistSftAPro,minDistSftPio);
2922     //   f3HistALamALamMinvReal->Fill(Minv(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam], fFemtoBuffer->GetEvt(0)->fALamTracks[iALam2]),minDistSftAPro,minDistSftPio);
2923
2924     //   // Mt of the pair for low q pairs only
2925     //   if(Qinv(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam],
2926     //        fFemtoBuffer->GetEvt(0)->fALamTracks[iALam2]) < .2)
2927     //  f2HistMtLowQALamALamReal->Fill(mt(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam],
2928     //                                fFemtoBuffer->GetEvt(0)->fALamTracks[iALam2]));
2929
2930     // } // Second lambda loop
2931
2932     // AProton loop
2933     for (iAPro=0;iAPro<fFemtoBuffer->GetEvt(0)->GetNAPro();iAPro++){
2934
2935       // Skip if unUseIt() entry
2936       if (!fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro].UseIt())
2937         continue;
2938
2939       //      nALamAProPairsWoTTR++;
2940       
2941       // Reset the distances for each pair
2942       //      minDistAPro=999.0;meanDistAPro=0.0;
2943       minDistSftAPro=999.0;meanDistSftAPro=0.0;
2944       // minDistSftIrocAPro=999.0;meanDistSftIrocAPro=0.0;
2945       // minDistSftOrocAPro=999.0;meanDistSftOrocAPro=0.0;
2946       // Reset the number of measurements for the mean
2947       nMeasAPro=0;//nMeasAProIroc=0;nMeasAProOroc=0;
2948
2949       // Check for two-track resolution
2950       for (iRadius=0;iRadius<9;iRadius++){
2951         // Get the spatial distance at each radius
2952         //      distAPro = calcDist(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].fNegDaughter.fXglobal[iRadius],fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro].fXglobal[iRadius]);
2953         distSftAPro = calcDist(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].fNegDaughter.fXshifted[iRadius],fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro].fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),fFemtoBuffer->GetEvt(0));
2954
2955         // calcDist returns -2.0 if one shouldn't use this distance, see calcDist function
2956         if (distSftAPro > -1.0){
2957           // Minimum distance
2958           // if (distAPro < minDistAPro)
2959           //   minDistAPro = distAPro;
2960           if (distSftAPro < minDistSftAPro)
2961             minDistSftAPro = distSftAPro;
2962           // Mean distance
2963           //          meanDistAPro+=distAPro;
2964           meanDistSftAPro+=distSftAPro;
2965           nMeasAPro++;
2966
2967         //   // IROC                                                             
2968         //   if (iRadius<3){
2969         //     if (distSftAPro < minDistSftIrocAPro)
2970         //       minDistSftIrocAPro = distSftAPro;
2971         //     meanDistSftIrocAPro+=distSftAPro;
2972         //     nMeasAProIroc++;
2973         //   }
2974         //   // OROC                                                             
2975         //   else {
2976         //     if (distSftAPro < minDistSftOrocAPro)
2977         //       minDistSftOrocAPro = distSftAPro;
2978         //     meanDistSftOrocAPro+=distSftAPro;
2979         //     nMeasAProOroc++;
2980         //   }
2981
2982         }
2983       } // Loop over iRadius
2984       
2985       // Require at least one measurement
2986       if ( !nMeasAPro )
2987         continue;
2988
2989       // Divide by the number of measurements to get the mean
2990       //      meanDistAPro /= (Float_t)nMeasAPro;
2991       meanDistSftAPro /= (Float_t)nMeasAPro;
2992
2993       // Fill the two track resolution histogram
2994       // f2HistALamAProMeanMinDistAProReal->Fill(meanDistAPro,minDistAPro);
2995       // f2HistSftALamAProMeanMinDistAProReal->Fill(meanDistSftAPro,minDistSftAPro);
2996
2997       // // Fill IROC / OROC histograms only with at least one measurement
2998       // if (nMeasAProIroc){
2999       //   meanDistSftIrocAPro /= (Float_t)nMeasAProIroc;
3000       //   f2HistSftIrocALamAProMeanMinDistAProReal->Fill(meanDistSftIrocAPro,minDistSftIrocAPro);
3001       // }
3002       // if (nMeasAProOroc){
3003       //   meanDistSftOrocAPro /= (Float_t)nMeasAProOroc;
3004       //   f2HistSftOrocALamAProMeanMinDistAProReal->Fill(meanDistSftOrocAPro,minDistSftOrocAPro);
3005       // }
3006         
3007       // Look at possible residual correlations
3008       //      f2HistALamPosDAProQinvReal->Fill(QinvPioPro(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].fPosDaughter, fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro]),meanDistSftAPro);
3009       //      f2HistALamNegDAProQinvReal->Fill(QinvProPro(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].fNegDaughter, fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro]),meanDistSftAPro);
3010
3011       
3012       //      // Do a cut (value needs to be refined)
3013       //      if ( meanDistSftAPro < 2.0 )
3014       //        continue;
3015
3016       // Count the number of pairs
3017       //      nALamAProPairs++;
3018
3019       // Mt of the pair
3020       f2HistMtALamAProReal->Fill(mt(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam],
3021                                     fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro]));
3022       // Use THnSparse since sept '12
3023       Double_t x[4]={
3024         QinvProPro(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].fNegDaughter, 
3025                    fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro]),
3026         meanDistSftAPro,
3027         minDistSftAPro,
3028         Qinv(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam],
3029              fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro])
3030       };
3031       ALamAProReal->Fill(x);
3032
3033       // Fill the qinv histogram using TPC only momentum for the primary protons
3034       //      f3HistALamAProQinvReal->Fill(Qinv(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam], fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro]),meanDistSftAPro,minDistSftAPro); // Using THnSparse since Sept '12, see above
3035       //      f3HistALamAProMinvReal->Fill(Minv(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam], fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro]),meanDistSftAPro,minDistSftAPro);
3036       // and using TPC only plus primary vertex constraint momentum for primary protons
3037       //      f3HistALamAProQinvConstrReal->Fill(QinvConstr(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam], fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro]),meanDistSftAPro,minDistSftAPro);
3038
3039       // Mt of the pair for low q pairs only
3040       if(Qinv(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam],
3041               fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro]) <.2)
3042         f2HistMtLowQALamAProReal->Fill(mt(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam],
3043                                           fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro]));
3044
3045     }// AProton loop
3046
3047   }// ALambda loop
3048
3049
3050   // Print the number of found pairs in this event
3051   // printf ("w/o  TTR cut: LamLamPairs: %d, LamProPairs: %d, ALamALamPairs: %d, ALamAProPairs: %d\n",
3052   //      nLamLamPairsWoTTR,nLamProPairsWoTTR,nALamALamPairsWoTTR,nALamAProPairsWoTTR);
3053   // printf ("with TTR cut: LamLamPairs: %d, LamProPairs: %d, ALamALamPairs: %d, ALamAProPairs: %d\n",
3054   //      nLamLamPairs,nLamProPairs,nALamALamPairs,nALamAProPairs);
3055   
3056
3057 }
3058
3059 //________________________________________________________________________
3060 void AliAnalysisTaskProtonLambda::ProcessMixed() {
3061   // Process mixed events
3062
3063   // Declare numbers to speed up the code
3064   Int_t iLam,//iLam2,
3065     iRadius,iPro,iALam,
3066     //iALam2,
3067     iAPro,nMeasPro,
3068     //nMeasPio,
3069     nMeasAPro;
3070   //  Int_t nMeasProIroc,nMeasPioIroc,nMeasAProIroc,nMeasProOroc,nMeasPioOroc,nMeasAProOroc;
3071   // Float_t distPro,distPio,minDistPro,meanDistPro,minDistPio,meanDistPio,
3072   //   distAPro,minDistAPro,meanDistAPro;
3073   Float_t distSftPro,
3074     //distSftPio,
3075     minDistSftPro,meanDistSftPro,//minDistSftPio,meanDistSftPio,
3076     distSftAPro,minDistSftAPro,meanDistSftAPro;
3077   // Float_t minDistSftIrocPro,meanDistSftIrocPro,minDistSftIrocPio,meanDistSftIrocPio,
3078   //   minDistSftIrocAPro,meanDistSftIrocAPro;
3079   // Float_t minDistSftOrocPro,meanDistSftOrocPro,minDistSftOrocPio,meanDistSftOrocPio,
3080   //   minDistSftOrocAPro,meanDistSftOrocAPro;
3081   
3082   // Loop over the event buffer
3083   for (UChar_t iMix = 1;iMix<fFemtoBuffer->GetMixBuffSize();iMix++){
3084     // Lambda loop
3085     for (iLam = 0; iLam < fFemtoBuffer->GetEvt(0)->GetNLam(); iLam++){
3086       
3087       // Skip if unUseIt() entry
3088       if (!fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].UseIt())
3089         continue;
3090       
3091       // // Second lambda loop
3092       // for (iLam2 = 0; iLam2 < (fFemtoBuffer->GetEvt(iMix))->GetNLam(); iLam2++){
3093         
3094       //        // Skip if unUseIt() entry
3095       //        if (!(fFemtoBuffer->GetEvt(iMix))->fLamTracks[iLam2].UseIt())
3096       //          continue;
3097         
3098       //        // Reset the distances for each pair
3099       //        minDistPro=999.0;meanDistPro=0.0;minDistPio=999.0;meanDistPio=0.0;
3100       //        minDistSftPro=999.0;meanDistSftPro=0.0;minDistSftPio=999.0;meanDistSftPio=0.0;
3101       //        minDistSftIrocPro=999.0;meanDistSftIrocPro=0.0;minDistSftIrocPio=999.0;meanDistSftIrocPio=0.0;
3102       //        minDistSftOrocPro=999.0;meanDistSftOrocPro=0.0;minDistSftOrocPio=999.0;meanDistSftOrocPio=0.0;
3103       //        // Reset the number of measurements for the mean
3104       //        nMeasPro=0;nMeasPio=0;nMeasProIroc=0;nMeasPioIroc=0;nMeasProOroc=0;nMeasPioOroc=0;
3105         
3106       //        // Check for two-track resolution
3107       //        for (iRadius=0;iRadius<9;iRadius++){
3108       //          // Get the spatial distance at each radius
3109       //          distPro = calcDist(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].fPosDaughter.fXglobal[iRadius],(fFemtoBuffer->GetEvt(iMix))->fLamTracks[iLam2].fPosDaughter.fXglobal[iRadius]);
3110       //          distPio = calcDist(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].fNegDaughter.fXglobal[iRadius],(fFemtoBuffer->GetEvt(iMix))->fLamTracks[iLam2].fNegDaughter.fXglobal[iRadius]);
3111       //          // Shifted distances
3112       //          distSftPro = calcDist(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].fPosDaughter.fXshifted[iRadius],(fFemtoBuffer->GetEvt(iMix))->fLamTracks[iLam2].fPosDaughter.fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),(fFemtoBuffer->GetEvt(iMix)));
3113       //          distSftPio = calcDist(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].fNegDaughter.fXshifted[iRadius],(fFemtoBuffer->GetEvt(iMix))->fLamTracks[iLam2].fNegDaughter.fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),(fFemtoBuffer->GetEvt(iMix)));
3114
3115       //          // calcDist returns -2.0 if one shouldn't use this distance, see calcDist function
3116       //          if (distPro > -1.0){
3117       //            // Minimum distance
3118       //            if (distPro < minDistPro)
3119       //              minDistPro = distPro;
3120       //            if (distSftPro < minDistSftPro)
3121       //              minDistSftPro = distSftPro;
3122       //            // Mean distance
3123       //            meanDistPro+=distPro;
3124       //            meanDistSftPro+=distSftPro;
3125       //            nMeasPro++;
3126             
3127       //            // IROC                                                         
3128       //            if (iRadius<3){
3129       //              if (distSftPro < minDistSftIrocPro)
3130       //                minDistSftIrocPro = distSftPro;
3131       //              meanDistSftIrocPro+=distSftPro;
3132       //              nMeasProIroc++;
3133       //            }
3134       //            // OROC                                                         
3135       //            else {
3136       //              if (distSftPro < minDistSftOrocPro)
3137       //                minDistSftOrocPro = distSftPro;
3138       //              meanDistSftOrocPro+=distSftPro;
3139       //              nMeasProOroc++;
3140       //            }
3141
3142       //          }
3143       //          if (distPio > -1.0){
3144       //            // Minimum distance
3145       //            if (distPio < minDistPio)
3146       //              minDistPio = distPio;
3147       //            if (distSftPio < minDistSftPio)
3148       //              minDistSftPio = distSftPio;
3149       //            // Mean distance
3150       //            meanDistPio+=distPio;
3151       //            meanDistSftPio+=distSftPio;
3152       //            nMeasPio++; 
3153
3154       //            // IROC                                                         
3155       //            if (iRadius<3){
3156       //              if (distSftPio < minDistSftIrocPio)
3157       //                minDistSftIrocPio = distSftPio;
3158       //              meanDistSftIrocPio+=distSftPio;
3159       //              nMeasPioIroc++;
3160       //            }
3161       //            // OROC                                                         
3162       //            else {
3163       //              if (distSftPio < minDistSftOrocPio)
3164       //                minDistSftOrocPio = distSftPio;
3165       //              meanDistSftOrocPio+=distSftPio;
3166       //              nMeasPioOroc++;
3167       //            }
3168             
3169       //          }
3170           
3171       //        } // Loop over iRadius
3172         
3173       //        // Require at least one measurement
3174       //        if ( (!nMeasPio) || (!nMeasPro) )
3175       //          continue;
3176         
3177       //        // Divide by the number of measurements to get the mean
3178       //        meanDistPro /= (Float_t)nMeasPro;
3179       //        meanDistPio /= (Float_t)nMeasPio;
3180       //        meanDistSftPro /= (Float_t)nMeasPro;
3181       //        meanDistSftPio /= (Float_t)nMeasPio;
3182         
3183       //        // Fill the two track resolution histograms
3184       //        f2HistLamLamMeanMinDistProMixed->Fill(meanDistPro,minDistPro);
3185       //        f2HistLamLamMeanMinDistPioMixed->Fill(meanDistPio,minDistPio);
3186
3187       //        f2HistSftLamLamMeanMinDistProMixed->Fill(meanDistSftPro,minDistSftPro);
3188       //        f2HistSftLamLamMeanMinDistPioMixed->Fill(meanDistSftPio,minDistSftPio);
3189
3190       //        // Fill IROC / OROC histograms only with at least one measurement   
3191       //        if (nMeasProIroc){
3192       //          meanDistSftIrocPro /= (Float_t)nMeasProIroc;
3193       //          f2HistSftIrocLamLamMeanMinDistProMixed->Fill(meanDistSftIrocPro,minDistSftIrocPro);
3194       //        }
3195       //        if (nMeasPioIroc){
3196       //          meanDistSftIrocPio /= (Float_t)nMeasPioIroc;
3197       //          f2HistSftIrocLamLamMeanMinDistPioMixed->Fill(meanDistSftIrocPio,minDistSftIrocPio);
3198       //        }
3199       //        if (nMeasProOroc){
3200       //          meanDistSftOrocPro /= (Float_t)nMeasProOroc;
3201       //          f2HistSftOrocLamLamMeanMinDistProMixed->Fill(meanDistSftOrocPro,minDistSftOrocPro);
3202       //        }
3203       //        if (nMeasPioOroc){
3204       //          meanDistSftOrocPio /= (Float_t)nMeasPioOroc;
3205       //          f2HistSftOrocLamLamMeanMinDistPioMixed->Fill(meanDistSftOrocPio,minDistSftOrocPio);
3206       //        }
3207         
3208       //        //      // Do a cut (value needs to be refined)
3209       //        //      if ( meanDistSftPro < 2.0 || meanDistSftPio < 2.0 )
3210       //        //        continue;
3211         
3212       //        // Fill the qinv, minv histogram
3213       //        f3HistLamLamQinvMixed->Fill(Qinv(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam], (fFemtoBuffer->GetEvt(iMix))->fLamTracks[iLam2]),minDistSftPro,minDistSftPio);
3214       //        f3HistLamLamMinvMixed->Fill(Minv(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam], (fFemtoBuffer->GetEvt(iMix))->fLamTracks[iLam2]),minDistSftPro,minDistSftPio);
3215       
3216       // } // Second lambda loop
3217       
3218       // Proton loop
3219       for (iPro=0;iPro<(fFemtoBuffer->GetEvt(iMix))->GetNPro();iPro++){
3220         
3221         // Skip if unUseIt() entry
3222         if (!(fFemtoBuffer->GetEvt(iMix))->fProTracks[iPro].UseIt())
3223           continue;
3224         
3225         // Reset the distances for each pair
3226         //      minDistPro=999.0;meanDistPro=0.0;       
3227         minDistSftPro=999.0;meanDistSftPro=0.0;
3228         // minDistSftIrocPro=999.0;meanDistSftIrocPro=0.0;
3229         // minDistSftOrocPro=999.0;meanDistSftOrocPro=0.0;
3230         // Reset the number of measurements for the mean
3231         nMeasPro=0;//nMeasProIroc=0;nMeasProOroc=0;
3232
3233         // Check for two-track resolution
3234         for (iRadius=0;iRadius<9;iRadius++){
3235           // Get the spatial distance at each radius
3236           //      distPro = calcDist(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].fPosDaughter.fXglobal[iRadius],(fFemtoBuffer->GetEvt(iMix))->fProTracks[iPro].fXglobal[iRadius]);
3237           distSftPro = calcDist(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].fPosDaughter.fXshifted[iRadius],(fFemtoBuffer->GetEvt(iMix))->fProTracks[iPro].fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),(fFemtoBuffer->GetEvt(iMix)));
3238
3239           // calcDist returns -2.0 if one shouldn't use this distance, see calcDist function
3240           if (distSftPro > -1.0){
3241             // Minimum distance
3242             // if (distPro < minDistPro)
3243             //   minDistPro = distPro;
3244             if (distSftPro < minDistSftPro)
3245             minDistSftPro = distSftPro;
3246             // Mean distance
3247             //      meanDistPro+=distPro;
3248             meanDistSftPro+=distSftPro;
3249             nMeasPro++;
3250
3251           //   // IROC                                                         
3252           //   if (iRadius<3){
3253           //     if (distSftPro < minDistSftIrocPro)
3254           //    minDistSftIrocPro = distSftPro;
3255           //     meanDistSftIrocPro+=distSftPro;
3256           //     nMeasProIroc++;
3257           //   }
3258           //   // OROC                                                         
3259           //   else {
3260           //     if (distSftPro < minDistSftOrocPro)
3261           //    minDistSftOrocPro = distSftPro;
3262           //     meanDistSftOrocPro+=distSftPro;
3263           //     nMeasProOroc++;
3264           //   }
3265
3266           }
3267         } // Loop over iRadius
3268         
3269         // Require at least one measurement
3270         if ( !nMeasPro )
3271           continue;
3272
3273         // Divide by the number of measurements to get the mean
3274         //      meanDistPro /= (Float_t)nMeasPro;
3275         meanDistSftPro /= (Float_t)nMeasPro;
3276         
3277         // // Fill the two track resolution histogram
3278         // f2HistLamProMeanMinDistProMixed->Fill(meanDistPro,minDistPro);
3279         // f2HistSftLamProMeanMinDistProMixed->Fill(meanDistSftPro,minDistSftPro);
3280
3281         // // Fill IROC / OROC histograms only with at least one measurement
3282         // if (nMeasProIroc){
3283         //   meanDistSftIrocPro /= (Float_t)nMeasProIroc;
3284         //   f2HistSftIrocLamProMeanMinDistProMixed->Fill(meanDistSftIrocPro,minDistSftIrocPro);
3285         // }
3286         // if (nMeasProOroc){
3287         //   meanDistSftOrocPro /= (Float_t)nMeasProOroc;
3288         //   f2HistSftOrocLamProMeanMinDistProMixed->Fill(meanDistSftOrocPro,minDistSftOrocPro);
3289         // }
3290
3291         // Look at possible residual correlations with the daughters 
3292         //      f2HistLamPosDProQinvMixed->Fill(QinvProPro(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].fPosDaughter, fFemtoBuffer->GetEvt(iMix)->fProTracks[iPro]),meanDistSftPro);
3293         //      f2HistLamNegDProQinvMixed->Fill(QinvPioPro(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].fNegDaughter, fFemtoBuffer->GetEvt(iMix)->fProTracks[iPro]),meanDistSftPro);
3294
3295         
3296         //      // Do a cut (value needs to be refined)
3297         //      if ( meanDistSftPro < 2.0 )
3298         //        continue;
3299
3300         // Use THnSparse since sept '12
3301         Double_t x[4]={
3302           QinvProPro(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam].fPosDaughter,
3303                      fFemtoBuffer->GetEvt(iMix)->fProTracks[iPro]),
3304           meanDistSftPro,
3305           minDistSftPro,
3306           Qinv(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam],
3307                fFemtoBuffer->GetEvt(iMix)->fProTracks[iPro])
3308         };
3309         LamProMixed->Fill(x);
3310
3311         // Fill the qinv histogram using TPC only momentum for the primary protons
3312       //        f3HistLamProQinvMixed->Fill(Qinv(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam], (fFemtoBuffer->GetEvt(iMix))->fProTracks[iPro]),meanDistSftPro,minDistSftPro);
3313         //      f3HistLamProMinvMixed->Fill(Minv(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam], (fFemtoBuffer->GetEvt(iMix))->fProTracks[iPro]),meanDistSftPro,minDistSftPro);
3314         // and using TPC only plus primary vertex constraint for the primary proton
3315         //      f3HistLamProQinvConstrMixed->Fill(QinvConstr(fFemtoBuffer->GetEvt(0)->fLamTracks[iLam], (fFemtoBuffer->GetEvt(iMix))->fProTracks[iPro]),meanDistSftPro,minDistSftPro);
3316
3317       }// Proton loop
3318     }// Lambda loop
3319     
3320     
3321     // Anti-lambda loop
3322     for (iALam = 0; iALam < fFemtoBuffer->GetEvt(0)->GetNALam(); iALam++){
3323       
3324       // Skip if unUseIt() entry
3325       if (!fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].UseIt())
3326         continue;
3327       
3328       // // Second anti-lambda loop
3329       // for (iALam2 = 0; iALam2 < (fFemtoBuffer->GetEvt(iMix))->GetNALam(); iALam2++){
3330         
3331       //        // Skip if unUseIt() entry
3332       //        if (!(fFemtoBuffer->GetEvt(iMix))->fALamTracks[iALam2].UseIt())
3333       //          continue;
3334         
3335       //        // Reset the distances for each pair
3336       //        minDistAPro=999.0;meanDistAPro=0.0;minDistPio=999.0;meanDistPio=0.0;
3337       //        minDistSftAPro=999.0;meanDistSftAPro=0.0;minDistSftPio=999.0;meanDistSftPio=0.0;
3338       //        minDistSftIrocAPro=999.0;meanDistSftIrocAPro=0.0;minDistSftIrocPio=999.0;meanDistSftIrocPio=0.0;
3339       //        minDistSftOrocAPro=999.0;meanDistSftOrocAPro=0.0;minDistSftOrocPio=999.0;meanDistSftOrocPio=0.0;
3340       //        // Reset the number of measurements for the mean
3341       //        nMeasAPro=0;nMeasPio=0;nMeasAProIroc=0;nMeasPioIroc=0;nMeasAProOroc=0;nMeasPioOroc=0;
3342
3343       //        // Check for two-track resolution
3344       //        for (iRadius=0;iRadius<9;iRadius++){
3345       //          // Get the spatial distance at each radius
3346       //          distPio = calcDist(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].fPosDaughter.fXglobal[iRadius],(fFemtoBuffer->GetEvt(iMix))->fALamTracks[iALam2].fPosDaughter.fXglobal[iRadius]);
3347       //          distAPro = calcDist(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].fNegDaughter.fXglobal[iRadius],(fFemtoBuffer->GetEvt(iMix))->fALamTracks[iALam2].fNegDaughter.fXglobal[iRadius]);
3348       //          // Shifted distances                                              
3349       //          distSftPio = calcDist(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].fPosDaughter.fXshifted[iRadius],(fFemtoBuffer->GetEvt(iMix))->fALamTracks[iALam2].fPosDaughter.fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),(fFemtoBuffer->GetEvt(iMix)));
3350       //          distSftAPro = calcDist(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].fNegDaughter.fXshifted[iRadius],(fFemtoBuffer->GetEvt(iMix))->fALamTracks[iALam2].fNegDaughter.fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),(fFemtoBuffer->GetEvt(iMix)));
3351
3352
3353       //          // calcDist returns -2.0 if one shouldn't use this distance, see calcDist function
3354       //          if (distAPro > -1.0){
3355       //            // Minimum distance
3356       //            if (distAPro < minDistAPro)
3357       //              minDistAPro = distAPro;
3358       //            if (distSftAPro < minDistSftAPro)
3359       //              minDistSftAPro = distSftAPro;
3360       //            // Mean distance
3361       //            meanDistAPro+=distAPro;
3362       //            meanDistSftAPro+=distSftAPro;
3363       //            nMeasAPro++;
3364       //            // IROC                                                         
3365       //            if (iRadius<3){
3366       //              if (distSftAPro < minDistSftIrocAPro)
3367       //                minDistSftIrocAPro = distSftAPro;
3368       //              meanDistSftIrocAPro+=distSftAPro;
3369       //              nMeasAProIroc++;
3370       //            }
3371       //            // OROC         
3372       //            else {
3373       //              if (distSftAPro < minDistSftOrocAPro)
3374       //                minDistSftOrocAPro = distSftAPro;
3375       //              meanDistSftOrocAPro+=distSftAPro;
3376       //              nMeasAProOroc++;
3377       //            }
3378       //          }
3379       //          if (distPio > -1.0){
3380       //     // Minimum distance
3381       //            if (distPio < minDistPio)
3382       //              minDistPio = distPio;
3383       //            if (distSftPio < minDistSftPio)
3384       //              minDistSftPio = distSftPio;
3385       //            // Mean distance
3386       //            meanDistPio+=distPio;
3387       //            meanDistSftPio+=distSftPio;
3388       //            nMeasPio++; 
3389       //            // IROC
3390       //            if (iRadius<3){
3391       //              if (distSftPio < minDistSftIrocPio)
3392       //                minDistSftIrocPio = distSftPio;
3393       //              meanDistSftIrocPio+=distSftPio;
3394       //              nMeasPioIroc++;
3395       //            }
3396       //            // OROC
3397       //            else {
3398       //              if (distSftPio < minDistSftOrocPio)
3399       //                minDistSftOrocPio = distSftPio;
3400       //              meanDistSftOrocPio+=distSftPio;
3401       //              nMeasPioOroc++;
3402       //            }
3403       //          }
3404       //        } // Loop over iRadius
3405         
3406       //        // Require at least one measurement
3407       //        if ( (!nMeasPio) || (!nMeasAPro) )
3408       //          continue;
3409         
3410       //        // Divide by the number of measurements to get the mean
3411       //        meanDistAPro /= (Float_t)nMeasAPro;
3412       //        meanDistPio /= (Float_t)nMeasPio;
3413       //        meanDistSftAPro /= (Float_t)nMeasAPro;
3414       //        meanDistSftPio /= (Float_t)nMeasPio;
3415         
3416       //        // Fill the two track resolution histograms
3417       //        f2HistALamALamMeanMinDistAProMixed->Fill(meanDistAPro,minDistAPro);
3418       //        f2HistALamALamMeanMinDistPioMixed->Fill(meanDistPio,minDistPio);
3419       //        f2HistSftALamALamMeanMinDistAProMixed->Fill(meanDistSftAPro,minDistSftAPro);
3420       //        f2HistSftALamALamMeanMinDistPioMixed->Fill(meanDistSftPio,minDistSftPio);
3421
3422       //        // Fill IROC / OROC histograms only with at least one measurement
3423       //        if (nMeasAProIroc){
3424       //          meanDistSftIrocAPro /= (Float_t)nMeasAProIroc;
3425       //          f2HistSftIrocALamALamMeanMinDistAProMixed->Fill(meanDistSftIrocAPro,minDistSftIrocAPro);
3426       //        }
3427       //        if (nMeasPioIroc){
3428       //          meanDistSftIrocPio /= (Float_t)nMeasPioIroc;
3429       //          f2HistSftIrocALamALamMeanMinDistPioMixed->Fill(meanDistSftIrocPio,minDistSftIrocPio);
3430       //        }
3431       //        if (nMeasAProOroc){
3432       //          meanDistSftOrocAPro /= (Float_t)nMeasAProOroc;
3433       //          f2HistSftOrocALamALamMeanMinDistAProMixed->Fill(meanDistSftOrocAPro,minDistSftOrocAPro);
3434       //        }
3435       //        if (nMeasPioOroc){
3436       //          meanDistSftOrocPio /= (Float_t)nMeasPioOroc;
3437       //          f2HistSftOrocALamALamMeanMinDistPioMixed->Fill(meanDistSftOrocPio,minDistSftOrocPio);
3438       //        }
3439       //        //      // Do a cut (value needs to be refined)
3440       //        //      if ( meanDistSftAPro < 2.0 || meanDistSftPio < 2.0 )
3441       //        //        continue;
3442
3443       //        // Fill the qinv, minv histogram
3444       //        f3HistALamALamQinvMixed->Fill(Qinv(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam], (fFemtoBuffer->GetEvt(iMix))->fALamTracks[iALam2]),minDistSftAPro,minDistSftPio);
3445       //        f3HistALamALamMinvMixed->Fill(Minv(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam], (fFemtoBuffer->GetEvt(iMix))->fALamTracks[iALam2]),minDistSftAPro,minDistSftPio);
3446         
3447       // } // Second lambda loop
3448
3449       // AProton loop
3450       for (iAPro=0;iAPro<(fFemtoBuffer->GetEvt(iMix))->GetNAPro();iAPro++){
3451         
3452         // Skip if unUseIt() entry
3453         if (!(fFemtoBuffer->GetEvt(iMix))->fAProTracks[iAPro].UseIt())
3454           continue;
3455         
3456         // Reset the distances for each pair
3457         //      minDistAPro=999.0;meanDistAPro=0.0;     
3458         minDistSftAPro=999.0;meanDistSftAPro=0.0;
3459         // minDistSftIrocAPro=999.0;meanDistSftIrocAPro=0.0;
3460         // minDistSftOrocAPro=999.0;meanDistSftOrocAPro=0.0;
3461         // Reset the number of measurements for the mean
3462         nMeasAPro=0;//nMeasAProIroc=0;nMeasAProOroc=0;
3463
3464         // Check for two-track resolution
3465         for (iRadius=0;iRadius<9;iRadius++){
3466           // Get the spatial distance at each radius
3467           //      distAPro = calcDist(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].fNegDaughter.fXglobal[iRadius],(fFemtoBuffer->GetEvt(iMix))->fAProTracks[iAPro].fXglobal[iRadius]);
3468           distSftAPro = calcDist(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].fNegDaughter.fXshifted[iRadius],(fFemtoBuffer->GetEvt(iMix))->fAProTracks[iAPro].fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),(fFemtoBuffer->GetEvt(iMix)));
3469
3470           // calcDist returns -2.0 if one shouldn't use this distance, see calcDist function
3471           if (distSftAPro > -1.0){
3472             // Minimum distance
3473             // if (distAPro < minDistAPro)
3474             //   minDistAPro = distAPro;
3475             if (distSftAPro < minDistSftAPro)
3476               minDistSftAPro = distSftAPro;
3477             // Mean distance
3478             //      meanDistAPro+=distAPro;
3479             meanDistSftAPro+=distSftAPro;
3480             nMeasAPro++;
3481           //   // IROC                                                                    
3482           //   if (iRadius<3){
3483           //     if (distSftAPro < minDistSftIrocAPro)
3484           //       minDistSftIrocAPro = distSftAPro;
3485           //     meanDistSftIrocAPro+=distSftAPro;
3486           //     nMeasAProIroc++;
3487           //   }
3488           //   // OROC                                                                    
3489           //   else {
3490           //     if (distSftAPro < minDistSftOrocAPro)
3491           //       minDistSftOrocAPro = distSftAPro;
3492           //     meanDistSftOrocAPro+=distSftAPro;
3493           //     nMeasAProOroc++;
3494           //   }
3495
3496           }
3497         } // Loop over iRadius
3498       
3499         // Require at least one measurement
3500         if ( !nMeasAPro )
3501           continue;
3502         
3503         // Divide by the number of measurements to get the mean
3504         //      meanDistAPro /= (Float_t)nMeasAPro;
3505         meanDistSftAPro /= (Float_t)nMeasAPro;
3506         
3507         // // Fill the two track resolution histogram
3508         // f2HistALamAProMeanMinDistAProMixed->Fill(meanDistAPro,minDistAPro);
3509         // f2HistSftALamAProMeanMinDistAProMixed->Fill(meanDistSftAPro,minDistSftAPro);
3510
3511         // // Fill IROC / OROC histograms only with at least one measurement   
3512         // if (nMeasAProIroc){
3513         //   meanDistSftAPro /= (Float_t)nMeasAProIroc;
3514         //   f2HistSftIrocALamAProMeanMinDistAProMixed->Fill(meanDistSftIrocAPro,minDistSftIrocAPro);
3515         // }
3516         // if (nMeasAProOroc){
3517         //   meanDistSftAPro /= (Float_t)nMeasAProOroc;
3518         //   f2HistSftOrocALamAProMeanMinDistAProMixed->Fill(meanDistSftOrocAPro,minDistSftOrocAPro);
3519         // }
3520
3521         // Look at possible residual correlations for the daughters
3522         //      f2HistALamPosDAProQinvMixed->Fill(QinvPioPro(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].fPosDaughter, fFemtoBuffer->GetEvt(iMix)->fAProTracks[iAPro]),meanDistSftAPro);
3523         //      f2HistALamNegDAProQinvMixed->Fill(QinvProPro(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].fNegDaughter, fFemtoBuffer->GetEvt(iMix)->fAProTracks[iAPro]),meanDistSftAPro);
3524
3525         // Do a cut (value needs to be refined)
3526         //      if ( meanDistSftAPro < 2.0 )
3527         //        continue;
3528         
3529         // Use THnSparse since sept '12
3530         Double_t x[4]={
3531           QinvProPro(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam].fNegDaughter,
3532                      fFemtoBuffer->GetEvt(iMix)->fAProTracks[iAPro]),
3533           meanDistSftAPro,
3534           minDistSftAPro,
3535           Qinv(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam],
3536                fFemtoBuffer->GetEvt(iMix)->fAProTracks[iAPro])
3537         };
3538         ALamAProMixed->Fill(x);
3539
3540
3541         // Fill the qinv histogram using TPC only momentum for the primary proton
3542         //      f3HistALamAProQinvMixed->Fill(Qinv(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam], (fFemtoBuffer->GetEvt(iMix))->fAProTracks[iAPro]),meanDistSftAPro,minDistSftAPro);
3543         //      f3HistALamAProMinvMixed->Fill(Minv(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam], (fFemtoBuffer->GetEvt(iMix))->fAProTracks[iAPro]),meanDistSftAPro,minDistSftAPro);
3544         // and using TPC only plus primary vertex constraint for the primary proton
3545         //      f3HistALamAProQinvConstrMixed->Fill(QinvConstr(fFemtoBuffer->GetEvt(0)->fALamTracks[iALam], (fFemtoBuffer->GetEvt(iMix))->fAProTracks[iAPro]),meanDistSftAPro,minDistSftAPro);
3546         
3547       }// AProton loop
3548     }// ALambda loop
3549     
3550   }// Event buffer loop
3551
3552 }// End of void ProcessMixed 
3553 //________________________________________________________________________
3554 void AliAnalysisTaskProtonLambda::ProcessRealBackground() {
3555   // Process real events with background lambdas
3556   
3557   // Declare numbers to speed up the code
3558   Int_t iBgLam,
3559     //iBgLam2,
3560     iRadius,iPro,iBgALam,
3561     //iBgALam2,
3562     iAPro,nMeasPro,
3563     //nMeasPio,
3564     nMeasAPro;
3565   //  Int_t nMeasProIroc,nMeasPioIroc,nMeasAProIroc,nMeasProOroc,nMeasPioOroc,nMeasAProOroc;
3566   // Float_t distPro,distPio,minDistPro=999.0,meanDistPro=0.0,minDistPio=999.0,meanDistPio=0.0,
3567   //   distAPro,minDistAPro=999.0,meanDistAPro=0.0;
3568   Float_t distSftPro,
3569     //distSftPio,
3570     minDistSftPro=999.0,meanDistSftPro=0.0,
3571     //minDistSftPio=999.0,meanDistSftPio=0.0,
3572     distSftAPro,minDistSftAPro=999.0,meanDistSftAPro=0.0;
3573   // Float_t minDistSftIrocPro=999.0,meanDistSftIrocPro=0.0,minDistSftIrocPio=999.0,meanDistSftIrocPio=0.0,
3574   //   minDistSftIrocAPro=999.0,meanDistSftIrocAPro=0.0;
3575   // Float_t minDistSftOrocPro=999.0,meanDistSftOrocPro=0.0,minDistSftOrocPio=999.0,meanDistSftOrocPio=0.0,
3576   //   minDistSftOrocAPro=999.0,meanDistSftOrocAPro=0.0;
3577   
3578       
3579   // BgLambda loop
3580   for (iBgLam = 0; iBgLam < fFemtoBuffer->GetEvt(0)->GetNBgLam(); iBgLam++){
3581
3582     // Skip if unUseIt() entry
3583     if (!fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam].UseIt())
3584       continue;
3585
3586     // // Second lambda loop
3587     // for (iBgLam2 = iBgLam+1; iBgLam2 < fFemtoBuffer->GetEvt(0)->GetNBgLam(); iBgLam2++){
3588
3589     //   // Skip if unUseIt() entry
3590     //   if (!fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam2].UseIt())
3591     //  continue;
3592
3593     //   // Reset the distances for each pair
3594     //   minDistPro=999.0;meanDistPro=0.0;minDistPio=999.0;meanDistPio=0.0;
3595     //   minDistSftPro=999.0;meanDistSftPro=0.0;minDistSftPio=999.0;meanDistSftPio=0.0;
3596     //   minDistSftIrocPro=999.0;meanDistSftIrocPro=0.0;minDistSftIrocPio=999.0;meanDistSftIrocPio=0.0;
3597     //   minDistSftOrocPro=999.0;meanDistSftOrocPro=0.0;minDistSftOrocPio=999.0;meanDistSftOrocPio=0.0;
3598     //   // Reset the number of measurements for the mean
3599     //   nMeasPro=0;nMeasPio=0;nMeasProIroc=0;nMeasPioIroc=0;nMeasProOroc=0;nMeasPioOroc=0;
3600
3601     //   // Check for two-track resolution
3602     //   for (iRadius=0;iRadius<9;iRadius++){
3603     //  // Get the spatial distance at each radius
3604     //  distPro = calcDist(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam].fPosDaughter.fXglobal[iRadius],fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam2].fPosDaughter.fXglobal[iRadius]);
3605     //  distPio = calcDist(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam].fNegDaughter.fXglobal[iRadius],fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam2].fNegDaughter.fXglobal[iRadius]);
3606     //  // Shifted distances
3607     //  distSftPro = calcDist(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam].fPosDaughter.fXshifted[iRadius],fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam2].fPosDaughter.fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),fFemtoBuffer->GetEvt(0));
3608     //  distSftPio = calcDist(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam].fNegDaughter.fXshifted[iRadius],fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam2].fNegDaughter.fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),fFemtoBuffer->GetEvt(0));
3609         
3610     //  // calcDist returns -2.0 if one shouldn't use this distance, see calcDist function
3611     //     if (distPro > -1.0){
3612     //       // Minimum distance
3613     //       if (distPro < minDistPro)
3614     //         minDistPro = distPro;
3615     //    if (distSftPro < minDistSftPro)
3616     //         minDistSftPro = distSftPro;
3617     //       // Mean distance
3618     //       meanDistPro+=distPro;
3619     //    meanDistSftPro+=distSftPro;
3620     //       nMeasPro++;
3621
3622     //    // IROC                                                         
3623     //       if (iRadius<3){
3624     //         if (distSftPro < minDistSftIrocPro)
3625     //           minDistSftIrocPro = distSftPro;
3626     //         meanDistSftIrocPro+=distSftPro;
3627     //         nMeasProIroc++;
3628     //       }
3629     //       // OROC                                                         
3630     //       else {
3631     //         if (distSftPro < minDistSftOrocPro)
3632     //           minDistSftOrocPro = distSftPro;
3633     //         meanDistSftOrocPro+=distSftPro;
3634     //         nMeasProOroc++;
3635     //       }
3636     //     }
3637         
3638     //     if (distPio > -1.0){
3639     //       // Minimum distance
3640     //       if (distPio < minDistPio)
3641     //         minDistPio = distPio;
3642     //    if (distSftPio < minDistSftPio)
3643     //         minDistSftPio = distSftPio;
3644     //       // Mean distance
3645     //       meanDistPio+=distPio;
3646     //    meanDistSftPio+=distSftPio;
3647     //       nMeasPio++; 
3648     //    // IROC                                                         
3649     //       if (iRadius<3){
3650     //         if (distSftPio < minDistSftIrocPio)
3651     //           minDistSftIrocPio = distSftPio;
3652     //         meanDistSftIrocPio+=distSftPio;
3653     //         nMeasPioIroc++;
3654     //       }
3655     //       // OROC                                                         
3656     //       else {
3657     //         if (distSftPio < minDistSftOrocPio)
3658     //           minDistSftOrocPio = distSftPio;
3659     //         meanDistSftOrocPio+=distSftPio;
3660     //         nMeasPioOroc++;
3661     //       }
3662     //     }
3663
3664     //   } // Loop over iRadius
3665
3666
3667       
3668     //   // Require at least one measurement
3669     //   if ( (!nMeasPio) || (!nMeasPro) )
3670     //     continue;
3671       
3672     //   // Divide by the number of measurements to get the mean
3673     //   meanDistPro /= (Float_t)nMeasPro;
3674     //   meanDistPio /= (Float_t)nMeasPio;
3675     //   meanDistSftPro /= (Float_t)nMeasPro;
3676     //   meanDistSftPio /= (Float_t)nMeasPio;
3677
3678     //   // Fill the two track resolution histograms
3679     //   f2HistBgLamBgLamMeanMinDistProReal->Fill(meanDistPro,minDistPro);
3680     //   f2HistBgLamBgLamMeanMinDistPioReal->Fill(meanDistPio,minDistPio);
3681     //   f2HistSftBgLamBgLamMeanMinDistProReal->Fill(meanDistSftPro,minDistSftPro);
3682     //   f2HistSftBgLamBgLamMeanMinDistPioReal->Fill(meanDistSftPio,minDistSftPio);
3683
3684     //   // Fill IROC / OROC histograms only with at least one measurement   
3685     //   if (nMeasProIroc){
3686     //     meanDistSftIrocPro /= (Float_t)nMeasProIroc;
3687     //     f2HistSftIrocBgLamBgLamMeanMinDistProReal->Fill(meanDistSftIrocPro,minDistSftIrocPro);
3688     //   }
3689     //   if (nMeasPioIroc){
3690     //     meanDistSftIrocPio /= (Float_t)nMeasPioIroc;
3691     //     f2HistSftIrocBgLamBgLamMeanMinDistPioReal->Fill(meanDistSftIrocPio,minDistSftIrocPio);
3692     //   }
3693     //   if (nMeasProOroc){
3694     //     meanDistSftOrocPro /= (Float_t)nMeasProOroc;
3695     //     f2HistSftOrocBgLamBgLamMeanMinDistProReal->Fill(meanDistSftOrocPro,minDistSftOrocPro);
3696     //   }
3697     //   if (nMeasPioOroc){
3698     //     meanDistSftOrocPio /= (Float_t)nMeasPioOroc;
3699     //     f2HistSftOrocBgLamBgLamMeanMinDistPioReal->Fill(meanDistSftOrocPio,minDistSftOrocPio);
3700     //   }
3701
3702
3703         
3704     //   //      // Do a cut (value needs to be refined)
3705     //  //      if ( meanDistSftPro < 2.0 || meanDistSftPio < 2.0 )
3706     //   //     continue;
3707       
3708     //   // Fill the qinv, minv histogram
3709     //   f3HistBgLamBgLamQinvReal->Fill(Qinv(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam], fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam2]),minDistSftPro,minDistSftPio);
3710
3711     // } // Second lambda loop
3712
3713
3714     // Proton loop
3715     for (iPro=0;iPro<fFemtoBuffer->GetEvt(0)->GetNPro();iPro++){
3716
3717       // Skip if unUseIt() entry
3718       if (!fFemtoBuffer->GetEvt(0)->fProTracks[iPro].UseIt())
3719         continue;
3720
3721       // Reset the distances for each pair
3722       //      minDistPro=999.0;meanDistPro=0.0;
3723       minDistSftPro=999.0;meanDistSftPro=0.0;
3724       //      minDistSftIrocPro=999.0;meanDistSftIrocPro=0.0;
3725       //      minDistSftOrocPro=999.0;meanDistSftOrocPro=0.0;
3726       // Reset the number of measurements for the mean
3727       nMeasPro=0;//nMeasProIroc=0;nMeasProOroc=0;
3728
3729       // Check for two-track resolution
3730       for (iRadius=0;iRadius<9;iRadius++){
3731         // Get the spatial distance at each radius
3732         //      distPro = calcDist(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam].fPosDaughter.fXglobal[iRadius],fFemtoBuffer->GetEvt(0)->fProTracks[iPro].fXglobal[iRadius]);
3733         distSftPro = calcDist(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam].fPosDaughter.fXshifted[iRadius],fFemtoBuffer->GetEvt(0)->fProTracks[iPro].fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),fFemtoBuffer->GetEvt(0));
3734
3735         // calcDist returns -2.0 if one shouldn't use this distance, see calcDist function
3736         if (distSftPro > -1.0){
3737           // Minimum distance
3738           // if (distPro < minDistPro)
3739           //   minDistPro = distPro;
3740           if (distSftPro < minDistSftPro)
3741             minDistSftPro = distSftPro;
3742           // Mean distance
3743           //          meanDistPro+=distPro;
3744           meanDistSftPro+=distSftPro;
3745           nMeasPro++;
3746           // // IROC                                                         
3747           // if (iRadius<3){
3748           //   if (distSftPro < minDistSftIrocPro)
3749           //     minDistSftIrocPro = distSftPro;
3750           //   meanDistSftIrocPro+=distSftPro;
3751           //   nMeasProIroc++;
3752           // }
3753           // // OROC                                                         
3754           // else {
3755           //   if (distSftPro < minDistSftOrocPro)
3756           //     minDistSftOrocPro = distSftPro;
3757           //   meanDistSftOrocPro+=distSftPro;
3758           //   nMeasProOroc++;
3759           // }
3760
3761         }
3762
3763       } // Loop over iRadius
3764       
3765       // Require at least one measurement
3766       if ( !nMeasPro )
3767         continue;
3768
3769       // Divide by the number of measurements to get the mean
3770       //      meanDistPro /= (Float_t)nMeasPro;
3771       meanDistSftPro /= (Float_t)nMeasPro;
3772
3773       // Fill the two track resolution histogram
3774       // f2HistBgLamProMeanMinDistProReal->Fill(meanDistPro,minDistPro);
3775       // f2HistSftBgLamProMeanMinDistProReal->Fill(meanDistSftPro,minDistSftPro);
3776
3777       // // Fill IROC / OROC histograms only with at least one measurement
3778       // if (nMeasProIroc){
3779       //   meanDistSftIrocPro /= (Float_t)nMeasProIroc;
3780       //   f2HistSftIrocBgLamProMeanMinDistProReal->Fill(meanDistSftIrocPro,minDistSftIrocPro);
3781       // }
3782       // if (nMeasProOroc){
3783       //   meanDistSftOrocPro /= (Float_t)nMeasProOroc;
3784       //   f2HistSftOrocBgLamProMeanMinDistProReal->Fill(meanDistSftOrocPro,minDistSftOrocPro);
3785       // }
3786
3787         
3788       // Do a cut (value needs to be refined)
3789       //      if ( meanDistSftPro < 2.0 )
3790       //        continue;
3791
3792       // Since sept '12 do THnSparse with qinvpropro, 
3793       // mean dist propro, min dist propro, qinv lampro
3794       Double_t x[4]={
3795         QinvProPro(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam].fPosDaughter,
3796                    fFemtoBuffer->GetEvt(0)->fProTracks[iPro]),
3797         meanDistSftPro,
3798         minDistSftPro,
3799         Qinv(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam],
3800              fFemtoBuffer->GetEvt(0)->fProTracks[iPro])
3801       };
3802       BgLamProReal->Fill(x);
3803
3804       // Fill the qinv histogram
3805       //      f3HistBgLamProQinvReal->Fill(Qinv(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam], fFemtoBuffer->GetEvt(0)->fProTracks[iPro]),meanDistSftPro,minDistSftPro);
3806
3807     }// Proton loop
3808   }// BgLambda loop
3809
3810
3811   // Anti-lambda loop
3812   for (iBgALam = 0; iBgALam < fFemtoBuffer->GetEvt(0)->GetNBgALam(); iBgALam++){
3813
3814     // Skip if unUseIt() entry
3815     if (!fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam].UseIt())
3816       continue;
3817     
3818     // // Second anti-lambda loop
3819     // for (iBgALam2 = iBgALam+1; iBgALam2 < fFemtoBuffer->GetEvt(0)->GetNBgALam(); iBgALam2++){
3820
3821     //   // Skip if unUseIt() entry
3822     //   if (!fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam2].UseIt())
3823     //  continue;
3824
3825     //   // Reset the distances for each pair
3826     //   minDistAPro=999.0;meanDistAPro=0.0;minDistPio=999.0;meanDistPio=0.0;
3827     //   minDistSftAPro=999.0;meanDistSftAPro=0.0;minDistSftPio=999.0;meanDistSftPio=0.0;
3828     //   minDistSftIrocAPro=999.0;meanDistSftIrocAPro=0.0;minDistSftIrocPio=999.0;meanDistSftIrocPio=0.0;
3829     //   minDistSftOrocAPro=999.0;meanDistSftOrocAPro=0.0;minDistSftOrocPio=999.0;meanDistSftOrocPio=0.0;
3830     //   // Reset the number of measurements for the mean
3831     //   nMeasAPro=0;nMeasPio=0;
3832     //   nMeasAProIroc=0;nMeasPioIroc=0;
3833     //   nMeasAProOroc=0;nMeasPioOroc=0;
3834
3835     //   // Check for two-track resolution
3836     //   for (iRadius=0;iRadius<9;iRadius++){
3837     //  // Get the spatial distance at each radius
3838     //  distPio = calcDist(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam].fPosDaughter.fXglobal[iRadius],fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam2].fPosDaughter.fXglobal[iRadius]);
3839     //  distAPro = calcDist(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam].fNegDaughter.fXglobal[iRadius],fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam2].fNegDaughter.fXglobal[iRadius]);
3840     //  // Shifted distances                                              
3841     //     distSftPio = calcDist(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam].fPosDaughter.fXshifted[iRadius],fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam2].fPosDaughter.fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),fFemtoBuffer->GetEvt(0));
3842     //     distSftAPro = calcDist(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam].fNegDaughter.fXshifted[iRadius],fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam2].fNegDaughter.fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),fFemtoBuffer->GetEvt(0));
3843
3844     //  // calcDist returns -2.0 if one shouldn't use this distance, see calcDist function
3845     //     if (distAPro > -1.0){
3846     //       // Minimum distance
3847     //       if (distAPro < minDistAPro)
3848     //         minDistAPro = distAPro;
3849     //    if (distSftAPro < minDistSftAPro)
3850     //         minDistSftAPro = distSftAPro;
3851     //       // Mean distance
3852     //       meanDistAPro+=distAPro;
3853     //    meanDistSftAPro+=distSftAPro;
3854     //       nMeasAPro++;
3855
3856     //    // IROC                                                         
3857     //       if (iRadius<3){
3858     //         if (distSftAPro < minDistSftIrocAPro)
3859     //           minDistSftIrocAPro = distSftAPro;
3860     //         meanDistSftIrocAPro+=distSftAPro;
3861     //         nMeasAProIroc++;
3862     //       }
3863     //       // OROC                                                                          
3864     //       else {
3865     //         if (distSftAPro < minDistSftOrocAPro)
3866     //           minDistSftOrocAPro = distSftAPro;
3867     //         meanDistSftOrocAPro+=distSftAPro;
3868     //         nMeasAProOroc++;
3869     //       }
3870
3871     //     }
3872     //     if (distPio > -1.0){
3873     //       // Minimum distance
3874     //       if (distPio < minDistPio)
3875     //         minDistPio = distPio;
3876     //    if (distSftPio < minDistSftPio)
3877     //         minDistSftPio = distSftPio;
3878     //       // Mean distance
3879     //       meanDistPio+=distPio;
3880     //    meanDistSftPio+=distSftPio;
3881     //       nMeasPio++; 
3882     //    // IROC                                                         
3883     //       if (iRadius<3){
3884     //         if (distSftPio < minDistSftIrocPio)
3885     //           minDistSftIrocPio = distSftPio;
3886     //         meanDistSftIrocPio+=distSftPio;
3887     //         nMeasPioIroc++;
3888     //       }
3889     //       // OROC                                                         
3890     //       else {
3891     //         if (distSftPio < minDistSftOrocPio)
3892     //           minDistSftOrocPio = distSftPio;
3893     //         meanDistSftOrocPio+=distSftPio;
3894     //         nMeasPioOroc++;
3895     //       }
3896
3897     //     }
3898
3899     //   } // Loop over iRadius
3900       
3901     //   // Require at least one measurement
3902     //   if ( (!nMeasPio) || (!nMeasAPro) )
3903     //     continue;
3904
3905     //   // Divide by the number of measurements to get the mean
3906     //   meanDistAPro /= (Float_t)nMeasAPro;
3907     //   meanDistPio /= (Float_t)nMeasPio;
3908     //   meanDistSftAPro /= (Float_t)nMeasAPro;
3909     //   meanDistSftPio /= (Float_t)nMeasPio;
3910
3911     //   // Fill the two track resolution histograms
3912     //   f2HistBgALamBgALamMeanMinDistAProReal->Fill(meanDistAPro,minDistAPro);
3913     //   f2HistBgALamBgALamMeanMinDistPioReal->Fill(meanDistPio,minDistPio);
3914     //   f2HistSftBgALamBgALamMeanMinDistAProReal->Fill(meanDistSftAPro,minDistSftAPro);
3915     //   f2HistSftBgALamBgALamMeanMinDistPioReal->Fill(meanDistSftPio,minDistSftPio);
3916     //   // Fill IROC / OROC histograms only with at least one measurement
3917     //   if (nMeasAProIroc){
3918     //     meanDistSftAPro /= (Float_t)nMeasAProIroc;
3919     //     f2HistSftIrocBgALamBgALamMeanMinDistAProReal->Fill(meanDistSftIrocAPro,minDistSftIrocAPro);
3920     //   }
3921     //   if (nMeasPioIroc){
3922     //     meanDistSftPio /= (Float_t)nMeasPioIroc;
3923     //     f2HistSftIrocBgALamBgALamMeanMinDistPioReal->Fill(meanDistSftIrocPio,minDistSftIrocPio);
3924     //   }
3925     //   if (nMeasAProOroc){
3926     //     meanDistSftAPro /= (Float_t)nMeasAProOroc;
3927     //     f2HistSftOrocBgALamBgALamMeanMinDistAProReal->Fill(meanDistSftOrocAPro,minDistSftOrocAPro);
3928     //   }
3929     //   if (nMeasPioOroc){
3930     //     meanDistSftPio /= (Float_t)nMeasPioOroc;
3931     //     f2HistSftOrocBgALamBgALamMeanMinDistPioReal->Fill(meanDistSftOrocPio,minDistSftOrocPio);
3932     //   }
3933
3934         
3935     //   //      // Do a cut (value needs to be refined)
3936     //   //      if ( meanDistSftAPro < 2.0 || meanDistSftPio < 2.0 )
3937     //   //     continue;
3938       
3939     //   // Fill the qinv histogram
3940     //   f3HistBgALamBgALamQinvReal->Fill(Qinv(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam], fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam2]),minDistSftAPro,minDistSftPio);
3941       
3942     // } // Second lambda loop
3943
3944
3945     // AProton loop
3946     for (iAPro=0;iAPro<fFemtoBuffer->GetEvt(0)->GetNAPro();iAPro++){
3947
3948       // Skip if unUseIt() entry
3949       if (!fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro].UseIt())
3950         continue;
3951
3952       // Reset the distances for each pair
3953       //      minDistAPro=999.0;meanDistAPro=0.0;
3954       minDistSftAPro=999.0;meanDistSftAPro=0.0;
3955       // minDistSftIrocAPro=999.0;meanDistSftIrocAPro=0.0;
3956       // minDistSftOrocAPro=999.0;meanDistSftOrocAPro=0.0;
3957       // Reset the number of measurements for the mean
3958       nMeasAPro=0;//nMeasAProIroc=0;nMeasAProOroc=0;
3959       
3960       // Check for two-track resolution
3961       for (iRadius=0;iRadius<9;iRadius++){
3962         // Get the spatial distance at each radius
3963         //      distAPro = calcDist(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam].fNegDaughter.fXglobal[iRadius],fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro].fXglobal[iRadius]);
3964         distSftAPro = calcDist(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam].fNegDaughter.fXshifted[iRadius],fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro].fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),fFemtoBuffer->GetEvt(0));
3965
3966         // calcDist returns -2.0 if one shouldn't use this distance, see calcDist function
3967         if (distSftAPro > -1.0){
3968           // Minimum distance
3969           // if (distAPro < minDistAPro)
3970           //   minDistAPro = distAPro;
3971           if (distSftAPro < minDistSftAPro)
3972             minDistSftAPro = distSftAPro;
3973           // Mean distance
3974           //          meanDistAPro+=distAPro;
3975           meanDistSftAPro+=distSftAPro;
3976           nMeasAPro++;
3977
3978           // // IROC                                                         
3979           // if (iRadius<3){
3980           //   if (distSftAPro < minDistSftIrocAPro)
3981           //     minDistSftIrocAPro = distSftAPro;
3982           //   meanDistSftIrocAPro+=distSftAPro;
3983           //   nMeasAProIroc++;
3984           // }
3985           // // OROC                                                                          
3986           // else {
3987           //   if (distSftAPro < minDistSftOrocAPro)
3988           //     minDistSftOrocAPro = distSftAPro;
3989           //   meanDistSftOrocAPro+=distSftAPro;
3990           //   nMeasAProOroc++;
3991           // }
3992         }
3993       } // Loop over iRadius
3994       
3995       // Require at least one measurement
3996       if ( !nMeasAPro )
3997         continue;
3998
3999       // Divide by the number of measurements to get the mean
4000       //      meanDistAPro /= (Float_t)nMeasAPro;
4001       meanDistSftAPro /= (Float_t)nMeasAPro;
4002
4003       // // Fill the two track resolution histogram
4004       // f2HistBgALamAProMeanMinDistAProReal->Fill(meanDistAPro,minDistAPro);
4005       // f2HistSftBgALamAProMeanMinDistAProReal->Fill(meanDistSftAPro,minDistSftAPro);
4006       // // Fill IROC / OROC histograms only with at least one measurement   
4007       // if (nMeasAProIroc){
4008       //   meanDistSftAPro /= (Float_t)nMeasAProIroc;
4009       //   f2HistSftIrocBgALamAProMeanMinDistAProReal->Fill(meanDistSftIrocAPro,minDistSftIrocAPro);
4010       // }
4011       // if (nMeasAProOroc){
4012       //   meanDistSftAPro /= (Float_t)nMeasAProOroc;
4013       //   f2HistSftOrocBgALamAProMeanMinDistAProReal->Fill(meanDistSftOrocAPro,minDistSftOrocAPro);
4014       // }
4015
4016       
4017       // Do a cut (value needs to be refined)
4018       //      if ( meanDistSftAPro < 2.0 )
4019       //        continue;
4020
4021       // Since sept '12 do THnSparse with qinvpropro, 
4022       // mean dist propro, min dist propro, qinv lampro
4023       Double_t x[4]={
4024         QinvProPro(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam].fNegDaughter,
4025                    fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro]),
4026         meanDistSftAPro,
4027         minDistSftAPro,
4028         Qinv(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam], 
4029              fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro])
4030       };
4031       BgALamAProReal->Fill(x);
4032
4033       // Fill the qinv histogram
4034       //      f3HistBgALamAProQinvReal->Fill(Qinv(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam], fFemtoBuffer->GetEvt(0)->fAProTracks[iAPro]),meanDistSftAPro,minDistSftAPro);
4035
4036     }// AProton loop
4037   }// BgALambda loop
4038 } // End of void ProcessRealBackground
4039
4040 //________________________________________________________________________
4041 void AliAnalysisTaskProtonLambda::ProcessMixedBackground() {
4042   // Process mixed events
4043
4044   // Declare numbers to speed up the code
4045   Int_t iBgLam,
4046     //iBgLam2,
4047     iRadius,iPro,iBgALam,
4048     //iBgALam2,
4049     iAPro,nMeasPro,
4050     //nMeasPio,
4051     nMeasAPro;
4052   //  Int_t nMeasProIroc,nMeasPioIroc,nMeasAProIroc,nMeasProOroc,nMeasPioOroc,nMeasAProOroc;
4053   // Float_t distPro,distPio,minDistPro,meanDistPro,minDistPio,meanDistPio,
4054   //   distAPro,minDistAPro,meanDistAPro;
4055   Float_t distSftPro,//distSftPio,
4056     minDistSftPro,meanDistSftPro,//minDistSftPio,meanDistSftPio,
4057     distSftAPro,minDistSftAPro,meanDistSftAPro;
4058   // Float_t minDistSftIrocPro,meanDistSftIrocPro,minDistSftIrocPio,meanDistSftIrocPio,
4059   //   minDistSftIrocAPro,meanDistSftIrocAPro;
4060   // Float_t minDistSftOrocPro,meanDistSftOrocPro,minDistSftOrocPio,meanDistSftOrocPio,
4061   //   minDistSftOrocAPro,meanDistSftOrocAPro;
4062
4063   
4064   // Loop over the event buffer
4065   for (UChar_t iMix = 1;iMix<fFemtoBuffer->GetMixBuffSize();iMix++){
4066     // BgLambda loop
4067     for (iBgLam = 0; iBgLam < fFemtoBuffer->GetEvt(0)->GetNBgLam(); iBgLam++){
4068
4069       // Skip if unUseIt() entry
4070       if (!fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam].UseIt())
4071         continue;
4072       
4073       // // Second lambda loop
4074       // for (iBgLam2 = 0; iBgLam2 < (fFemtoBuffer->GetEvt(iMix))->GetNBgLam(); iBgLam2++){
4075
4076       //        // Skip if unUseIt() entry
4077       //        if (!(fFemtoBuffer->GetEvt(iMix))->fBgLamTracks[iBgLam2].UseIt())
4078       //          continue;
4079         
4080       //        // Reset the distances for each pair
4081       //        minDistPro=999.0;meanDistPro=0.0;minDistPio=999.0;meanDistPio=0.0;
4082       //        minDistSftPro=999.0;meanDistSftPro=0.0;minDistSftPio=999.0;meanDistSftPio=0.0;
4083       //   minDistSftIrocPro=999.0;meanDistSftIrocPro=0.0;minDistSftIrocPio=999.0;meanDistSftIrocPio=0.0;
4084       //   minDistSftOrocPro=999.0;meanDistSftOrocPro=0.0;minDistSftOrocPio=999.0;meanDistSftOrocPio=0.0;
4085       //        // Reset the number of measurements for the mean
4086       //        nMeasPro=0;nMeasPio=0;nMeasProIroc=0;nMeasPioIroc=0;nMeasProOroc=0;nMeasPioOroc=0;
4087
4088       //        // Check for two-track resolution
4089       //        for (iRadius=0;iRadius<9;iRadius++){
4090       //          // Get the spatial distance at each radius
4091       //          distPro = calcDist(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam].fPosDaughter.fXglobal[iRadius],(fFemtoBuffer->GetEvt(iMix))->fBgLamTracks[iBgLam2].fPosDaughter.fXglobal[iRadius]);
4092       //          distPio = calcDist(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam].fNegDaughter.fXglobal[iRadius],(fFemtoBuffer->GetEvt(iMix))->fBgLamTracks[iBgLam2].fNegDaughter.fXglobal[iRadius]);
4093       //          // Shifted distances                                            
4094       //     distSftPro = calcDist(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam].fPosDaughter.fXshifted[iRadius],(fFemtoBuffer->GetEvt(iMix))->fBgLamTracks[iBgLam2].fPosDaughter.fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),(fFemtoBuffer->GetEvt(iMix)));
4095       //     distSftPio = calcDist(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam].fNegDaughter.fXshifted[iRadius],(fFemtoBuffer->GetEvt(iMix))->fBgLamTracks[iBgLam2].fNegDaughter.fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),(fFemtoBuffer->GetEvt(iMix)));
4096
4097       //          // calcDist returns -2.0 if one shouldn't use this distance, see calcDist function
4098       //          if (distPro > -1.0){
4099       //            // Minimum distance
4100       //            if (distPro < minDistPro)
4101       //              minDistPro = distPro;
4102       //            if (distSftPro < minDistSftPro)
4103       //         minDistSftPro = distSftPro;
4104       //            // Mean distance
4105       //            meanDistPro+=distPro;
4106       //            meanDistSftPro+=distSftPro;
4107       //            nMeasPro++;
4108       //            // IROC                                                                          
4109       //       if (iRadius<3){
4110       //         if (distSftPro < minDistSftIrocPro)
4111       //           minDistSftIrocPro = distSftPro;
4112       //         meanDistSftIrocPro+=distSftPro;
4113       //         nMeasProIroc++;
4114       //       }
4115       //       // OROC                                                                          
4116       //       else {
4117       //         if (distSftPro < minDistSftOrocPro)
4118       //           minDistSftOrocPro = distSftPro;
4119       //         meanDistSftOrocPro+=distSftPro;
4120       //         nMeasProOroc++;
4121       //       }
4122       //          }
4123       //          if (distPio > -1.0){
4124       //            // Minimum distance
4125       //            if (distPio < minDistPio)
4126       //              minDistPio = distPio;
4127       //            if (distSftPio < minDistSftPio)
4128       //         minDistSftPio = distSftPio;
4129       //            // Mean distance
4130       //            meanDistPio+=distPio;
4131       //            meanDistSftPio+=distSftPio;
4132       //            nMeasPio++; 
4133       //            // IROC                                                                          
4134       //       if (iRadius<3){
4135       //         if (distSftPio < minDistSftIrocPio)
4136       //           minDistSftIrocPio = distSftPio;
4137       //         meanDistSftIrocPio+=distSftPio;
4138       //         nMeasPioIroc++;
4139       //       }
4140       //       // OROC                                                                          
4141       //       else {
4142       //         if (distSftPio < minDistSftOrocPio)
4143       //           minDistSftOrocPio = distSftPio;
4144       //         meanDistSftOrocPio+=distSftPio;
4145       //         nMeasPioOroc++;
4146       //       }
4147       //          }       
4148       //        } // Loop over iRadius
4149         
4150       //        // Require at least one measurement
4151       //        if ( (!nMeasPio) || (!nMeasPro) )
4152       //          continue;
4153         
4154       //        // Divide by the number of measurements to get the mean
4155       //        meanDistPro /= (Float_t)nMeasPro;
4156       //        meanDistPio /= (Float_t)nMeasPio;
4157       //        meanDistSftPro /= (Float_t)nMeasPro;
4158       //   meanDistSftPio /= (Float_t)nMeasPio;
4159         
4160       //        // Fill the two track resolution histograms
4161       //        f2HistBgLamBgLamMeanMinDistProMixed->Fill(meanDistPro,minDistPro);
4162       //        f2HistBgLamBgLamMeanMinDistPioMixed->Fill(meanDistPio,minDistPio);
4163       //        f2HistSftBgLamBgLamMeanMinDistProMixed->Fill(meanDistSftPro,minDistSftPro);
4164       //   f2HistSftBgLamBgLamMeanMinDistPioMixed->Fill(meanDistSftPio,minDistSftPio);
4165       //        // Fill IROC / OROC histograms only with at least one measurement
4166       //   if (nMeasProIroc){
4167       //     meanDistSftPro /= (Float_t)nMeasProIroc;
4168       //     f2HistSftIrocBgLamBgLamMeanMinDistProMixed->Fill(meanDistSftIrocPro,minDistSftIrocPro);
4169       //   }
4170       //   if (nMeasPioIroc){
4171       //     meanDistSftPio /= (Float_t)nMeasPioIroc;
4172       //     f2HistSftIrocBgLamBgLamMeanMinDistPioMixed->Fill(meanDistSftIrocPio,minDistSftIrocPio);
4173       //   }
4174       //   if (nMeasProOroc){
4175       //     meanDistSftPro /= (Float_t)nMeasProOroc;
4176       //     f2HistSftOrocBgLamBgLamMeanMinDistProMixed->Fill(meanDistSftOrocPro,minDistSftOrocPro);
4177       //   }
4178       //   if (nMeasPioOroc){
4179       //     meanDistSftPio /= (Float_t)nMeasPioOroc;
4180       //     f2HistSftOrocBgLamBgLamMeanMinDistPioMixed->Fill(meanDistSftOrocPio,minDistSftOrocPio);
4181       //   }
4182
4183       //        //      // Do a cut (value needs to be refined)
4184       //        //      if ( meanDistSftPro < 2.0 || meanDistSftPio < 2.0 )
4185       //        //        continue;
4186         
4187       //        // Fill the qinv, minv histogram
4188       //        f3HistBgLamBgLamQinvMixed->Fill(Qinv(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam], (fFemtoBuffer->GetEvt(iMix))->fBgLamTracks[iBgLam2]),minDistSftPro,minDistSftPio);
4189       
4190       // } // Second lambda loop
4191
4192       
4193       // Proton loop
4194       for (iPro=0;iPro<(fFemtoBuffer->GetEvt(iMix))->GetNPro();iPro++){
4195         
4196         // Skip if unUseIt() entry
4197         if (!(fFemtoBuffer->GetEvt(iMix))->fProTracks[iPro].UseIt())
4198           continue;
4199         
4200         // Reset the distances for each pair
4201         //      minDistPro=999.0;meanDistPro=0.0;
4202         minDistSftPro=999.0;meanDistSftPro=0.0;
4203         // minDistSftIrocPro=999.0;meanDistSftIrocPro=0.0;
4204         // minDistSftOrocPro=999.0;meanDistSftOrocPro=0.0;
4205         // Reset the number of measurements for the mean
4206         nMeasPro=0;//nMeasProIroc=0;nMeasProOroc=0;
4207
4208         // Check for two-track resolution
4209         for (iRadius=0;iRadius<9;iRadius++){
4210           // Get the spatial distance at each radius
4211           //      distPro = calcDist(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam].fPosDaughter.fXglobal[iRadius],(fFemtoBuffer->GetEvt(iMix))->fProTracks[iPro].fXglobal[iRadius]);
4212           distSftPro = calcDist(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam].fPosDaughter.fXshifted[iRadius],
4213                                 (fFemtoBuffer->GetEvt(iMix))->fProTracks[iPro].fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),(fFemtoBuffer->GetEvt(iMix)));
4214
4215           
4216           // calcDist returns -2.0 if one shouldn't use this distance, see calcDist function
4217           if (distSftPro > -1.0){
4218             // Minimum distance
4219             // if (distPro < minDistPro)
4220             //   minDistPro = distPro;
4221             if (distSftPro < minDistSftPro)
4222               minDistSftPro = distSftPro;
4223             // Mean distance
4224             //      meanDistPro+=distPro;
4225             meanDistSftPro+=distSftPro;
4226             nMeasPro++;
4227             // // IROC                                                                    
4228             // if (iRadius<3){
4229             //   if (distSftPro < minDistSftIrocPro)
4230             //     minDistSftIrocPro = distSftPro;
4231             //   meanDistSftIrocPro+=distSftPro;
4232             //   nMeasProIroc++;
4233             // }
4234             // // OROC                                                                    
4235             // else {
4236             //   if (distSftPro < minDistSftOrocPro)
4237             //     minDistSftOrocPro = distSftPro;
4238             //   meanDistSftOrocPro+=distSftPro;
4239             //   nMeasProOroc++;
4240             // }
4241           }
4242         } // Loop over iRadius
4243         
4244         // Require at least one measurement
4245         if ( !nMeasPro )
4246           continue;
4247
4248         // Divide by the number of measurements to get the mean
4249         //      meanDistPro /= (Float_t)nMeasPro;
4250         meanDistSftPro /= (Float_t)nMeasPro;
4251         
4252         // // Fill the two track resolution histogram
4253         // f2HistBgLamProMeanMinDistProMixed->Fill(meanDistPro,minDistPro);
4254         // f2HistSftBgLamProMeanMinDistProMixed->Fill(meanDistSftPro,minDistSftPro);
4255         // // Fill IROC / OROC histograms only with at least one measurement              
4256         // if (nMeasProIroc){
4257         //   meanDistSftIrocPro /= (Float_t)nMeasProIroc;
4258         //   f2HistSftIrocBgLamProMeanMinDistProMixed->Fill(meanDistSftIrocPro,minDistSftIrocPro);
4259         // }
4260         // if (nMeasProOroc){
4261         //   meanDistSftOrocPro /= (Float_t)nMeasProOroc;
4262         //   f2HistSftOrocBgLamProMeanMinDistProMixed->Fill(meanDistSftOrocPro,minDistSftOrocPro);
4263         // }
4264
4265         //      // Do a cut (value needs to be refined)
4266         //      if ( meanDistSftPro < 2.0 )
4267         //        continue;
4268         
4269               // Since sept '12 do THnSparse with qinvpropro, 
4270       // mean dist propro, min dist propro, qinv lampro
4271       Double_t x[4]={
4272         QinvProPro(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam].fPosDaughter,
4273                    fFemtoBuffer->GetEvt(iMix)->fProTracks[iPro]),
4274         meanDistSftPro,
4275         minDistSftPro,
4276         Qinv(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam],
4277              fFemtoBuffer->GetEvt(iMix)->fProTracks[iPro])
4278       };
4279       BgLamProMixed->Fill(x);
4280
4281
4282         // Fill the qinv histogram
4283         //      f3HistBgLamProQinvMixed->Fill(Qinv(fFemtoBuffer->GetEvt(0)->fBgLamTracks[iBgLam], (fFemtoBuffer->GetEvt(iMix))->fProTracks[iPro]),meanDistSftPro,minDistSftPro);
4284         
4285       }// Proton loop
4286     }// BgLambda loop
4287     
4288     
4289     // Anti-lambda loop
4290     for (iBgALam = 0; iBgALam < fFemtoBuffer->GetEvt(0)->GetNBgALam(); iBgALam++){
4291       
4292       // Skip if unUseIt() entry
4293       if (!fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam].UseIt())
4294         continue;
4295       
4296       // // Second anti-lambda loop
4297       // for (iBgALam2 = 0; iBgALam2 < (fFemtoBuffer->GetEvt(iMix))->GetNBgALam(); iBgALam2++){
4298         
4299       //        // Skip if unUseIt() entry
4300       //        if (!(fFemtoBuffer->GetEvt(iMix))->fBgALamTracks[iBgALam2].UseIt())
4301       //          continue;
4302
4303       //        // Reset the distances for each pair
4304       //        minDistAPro=999.0;meanDistAPro=0.0;minDistPio=999.0;meanDistPio=0.0;
4305       //        minDistSftAPro=999.0;meanDistSftAPro=0.0;minDistSftPio=999.0;meanDistSftPio=0.0;
4306       //   minDistSftIrocAPro=999.0;meanDistSftIrocAPro=0.0;minDistSftIrocPio=999.0;meanDistSftIrocPio=0.0;
4307       //   minDistSftOrocAPro=999.0;meanDistSftOrocAPro=0.0;minDistSftOrocPio=999.0;meanDistSftOrocPio=0.0;
4308
4309       //        // Reset the number of measurements for the mean
4310       //        nMeasAPro=0;nMeasPio=0;nMeasAProIroc=0;nMeasPioIroc=0;nMeasAProOroc=0;nMeasPioOroc=0;
4311
4312       //        // Check for two-track resolution
4313       //        for (iRadius=0;iRadius<9;iRadius++){
4314       //          // Get the spatial distance at each radius
4315       //          distPio = calcDist(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam].fPosDaughter.fXglobal[iRadius],
4316       //                             (fFemtoBuffer->GetEvt(iMix))->fBgALamTracks[iBgALam2].fPosDaughter.fXglobal[iRadius]);
4317       //          distAPro = calcDist(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam].fNegDaughter.fXglobal[iRadius],
4318       //                              (fFemtoBuffer->GetEvt(iMix))->fBgALamTracks[iBgALam2].fNegDaughter.fXglobal[iRadius]);
4319       //          // Shifted distances                                                         
4320       //     distSftPio = calcDist(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam].fPosDaughter.fXshifted[iRadius],
4321       //                                fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam2].fPosDaughter.fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),(fFemtoBuffer->GetEvt(iMix)));
4322       //     distSftAPro = calcDist(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam].fNegDaughter.fXshifted[iRadius],
4323       //                                 fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam2].fNegDaughter.fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),(fFemtoBuffer->GetEvt(iMix)));
4324
4325       //          // calcDist returns -2.0 if one shouldn't use this distance, see calcDist function
4326       //          if (distAPro > -1.0){
4327       //            // Minimum distance
4328       //            if (distAPro < minDistAPro)
4329       //              minDistAPro = distAPro;
4330       //            if (distSftAPro < minDistSftAPro)
4331       //         minDistSftAPro = distSftAPro;
4332       //            // Mean distance
4333       //            meanDistAPro+=distAPro;
4334       //            meanDistSftAPro+=distSftAPro;
4335       //            nMeasAPro++;
4336       //            // IROC                                                                    
4337       //       if (iRadius<3){
4338       //         if (distSftAPro < minDistSftIrocAPro)
4339       //           minDistSftIrocAPro = distSftAPro;
4340       //         meanDistSftIrocAPro+=distSftAPro;
4341       //         nMeasAProIroc++;
4342       //       }
4343       //       // OROC                                                                    
4344       //       else {
4345       //         if (distSftAPro < minDistSftOrocAPro)
4346       //           minDistSftOrocAPro = distSftAPro;
4347       //         meanDistSftOrocAPro+=distSftAPro;
4348       //         nMeasAProOroc++;
4349       //       }
4350       //          }
4351
4352       //          if (distPio > -1.0){
4353       //            // Minimum distance
4354       //            if (distPio < minDistPio)
4355       //              minDistPio = distPio;
4356       //            if (distSftPio < minDistSftPio)
4357       //         minDistSftPio = distSftPio;
4358       //            // Mean distance
4359       //            meanDistPio+=distPio;
4360       //            meanDistSftPio+=distSftPio;
4361       //            nMeasPio++; 
4362       //            // IROC                                                                    
4363       //       if (iRadius<3){
4364       //         if (distSftPio < minDistSftIrocPio)
4365       //           minDistSftIrocPio = distSftPio;
4366       //         meanDistSftIrocPio+=distSftPio;
4367       //         nMeasPioIroc++;
4368       //       }
4369       //       // OROC                                                                    
4370       //       else {
4371       //         if (distSftPio < minDistSftOrocPio)
4372       //           minDistSftOrocPio = distSftPio;
4373       //         meanDistSftOrocPio+=distSftPio;
4374       //         nMeasPioOroc++;
4375       //       }
4376       //          }
4377           
4378       //        } // Loop over iRadius
4379       
4380       //        // Require at least one measurement
4381       //        if ( (!nMeasPio) || (!nMeasAPro) )
4382       //          continue;
4383         
4384       //        // Divide by the number of measurements to get the mean
4385       //        meanDistAPro /= (Float_t)nMeasAPro;
4386       //        meanDistPio /= (Float_t)nMeasPio;
4387       //        meanDistSftAPro /= (Float_t)nMeasAPro;
4388       //   meanDistSftPio /= (Float_t)nMeasPio;
4389         
4390       //        // Fill the two track resolution histograms
4391       //        f2HistBgALamBgALamMeanMinDistAProMixed->Fill(meanDistAPro,minDistAPro);
4392       //        f2HistBgALamBgALamMeanMinDistPioMixed->Fill(meanDistPio,minDistPio);
4393       //        f2HistSftBgALamBgALamMeanMinDistAProMixed->Fill(meanDistSftAPro,minDistSftAPro);
4394       //   f2HistSftBgALamBgALamMeanMinDistPioMixed->Fill(meanDistSftPio,minDistSftPio);
4395
4396       //        // Fill IROC / OROC histograms only with at least one measurement              
4397       //   if (nMeasAProIroc){
4398       //     meanDistSftIrocAPro /= (Float_t)nMeasAProIroc;
4399       //     f2HistSftIrocBgALamBgALamMeanMinDistAProMixed->Fill(meanDistSftIrocAPro,minDistSftIrocAPro);
4400       //   }
4401       //   if (nMeasPioIroc){
4402       //     meanDistSftPio /= (Float_t)nMeasPioIroc;
4403       //     f2HistSftIrocBgALamBgALamMeanMinDistPioMixed->Fill(meanDistSftIrocPio,minDistSftIrocPio);
4404       //   }
4405       //   if (nMeasAProOroc){
4406       //          meanDistSftAPro /= (Float_t)nMeasAProOroc;
4407       //     f2HistSftOrocBgALamBgALamMeanMinDistAProMixed->Fill(meanDistSftOrocAPro,minDistSftOrocAPro);
4408       //   }
4409       //   if (nMeasPioOroc){
4410       //     meanDistSftPio /= (Float_t)nMeasPioOroc;
4411       //     f2HistSftOrocBgALamBgALamMeanMinDistPioMixed->Fill(meanDistSftOrocPio,minDistSftOrocPio);
4412       //   }            
4413       //        //      // Do a cut (value needs to be refined)
4414       //        //      if ( meanDistSftAPro < 2.0 || meanDistSftPio < 2.0 )
4415       //        //        continue;
4416         
4417       //        // Fill the qinv, minv histogram
4418       //        f3HistBgALamBgALamQinvMixed->Fill(Qinv(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam], (fFemtoBuffer->GetEvt(iMix))->fBgALamTracks[iBgALam2]),minDistSftAPro,minDistSftPio);
4419
4420       // } // Second lambda loop
4421
4422       // AProton loop
4423       for (iAPro=0;iAPro<(fFemtoBuffer->GetEvt(iMix))->GetNAPro();iAPro++){
4424         
4425         // Skip if unUseIt() entry
4426         if (!(fFemtoBuffer->GetEvt(iMix))->fAProTracks[iAPro].UseIt())
4427           continue;
4428         
4429         // Reset the distances for each pair
4430         //      minDistAPro=999.0;meanDistAPro=0.0;
4431         minDistSftAPro=999.0;meanDistSftAPro=0.0;
4432         // minDistSftIrocAPro=999.0;meanDistSftIrocAPro=0.0;
4433         // minDistSftOrocAPro=999.0;meanDistSftOrocAPro=0.0;
4434         // Reset the number of measurements for the mean
4435         nMeasAPro=0;//nMeasAProIroc=0;nMeasAProOroc=0;
4436
4437         // Check for two-track resolution
4438         for (iRadius=0;iRadius<9;iRadius++){
4439           // Get the spatial distance at each radius
4440           //      distAPro = calcDist(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam].fNegDaughter.fXglobal[iRadius],(fFemtoBuffer->GetEvt(iMix))->fAProTracks[iAPro].fXglobal[iRadius]);
4441           distSftAPro = calcDist(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam].fNegDaughter.fXshifted[iRadius],(fFemtoBuffer->GetEvt(iMix))->fAProTracks[iAPro].fXshifted[iRadius]);//,fFemtoBuffer->GetEvt(0),(fFemtoBuffer->GetEvt(iMix)));
4442           
4443           // calcDist returns -2.0 if one shouldn't use this distance, see calcDist function
4444           if (distSftAPro > -1.0){
4445             // Minimum distance
4446             //      if (distAPro < minDistAPro)
4447             //        minDistAPro = distAPro;
4448             if (distSftAPro < minDistSftAPro)
4449               minDistSftAPro = distSftAPro;
4450             // Mean distance
4451             //      meanDistAPro+=distAPro;
4452             meanDistSftAPro+=distSftAPro;
4453             nMeasAPro++;
4454             // // IROC                                                                    
4455             // if (iRadius<3){
4456             //   if (distSftAPro < minDistSftIrocAPro)
4457             //     minDistSftIrocAPro = distSftAPro;
4458             //   meanDistSftIrocAPro+=distSftAPro;
4459             //   nMeasAProIroc++;
4460             // }
4461             // // OROC                                                                    
4462             // else {
4463             //   if (distSftAPro < minDistSftOrocAPro)
4464             //     minDistSftOrocAPro = distSftAPro;
4465             //   meanDistSftOrocAPro+=distSftAPro;
4466             //   nMeasAProOroc++;
4467             // }
4468           }
4469         } // Loop over iRadius
4470         
4471         // Require at least one measurement
4472         if ( !nMeasAPro )
4473           continue;
4474
4475         // Divide by the number of measurements to get the mean
4476         //      meanDistAPro /= (Float_t)nMeasAPro;
4477         meanDistSftAPro /= (Float_t)nMeasAPro;
4478
4479         // // Fill the two track resolution histogram
4480         // f2HistBgALamAProMeanMinDistAProMixed->Fill(meanDistAPro,minDistAPro);
4481         // f2HistSftBgALamAProMeanMinDistAProMixed->Fill(meanDistSftAPro,minDistSftAPro);
4482         
4483         // // Fill IROC / OROC histograms only with at least one measurement              
4484         // if (nMeasAProIroc){
4485         //   meanDistSftAPro /= (Float_t)nMeasAProIroc;
4486         //   f2HistSftIrocBgALamAProMeanMinDistAProMixed->Fill(meanDistSftIrocAPro,minDistSftIrocAPro);
4487         // }
4488         // if (nMeasAProOroc){
4489         //   meanDistSftAPro /= (Float_t)nMeasAProOroc;
4490         //   f2HistSftOrocBgALamAProMeanMinDistAProMixed->Fill(meanDistSftOrocAPro,minDistSftOrocAPro);
4491         // }
4492         //      // Do a cut (value needs to be refined)
4493         //      if ( meanDistSftAPro < 2.0 )
4494         //        continue;
4495
4496         // Use THnSparse since Sept '12
4497         Double_t x[4]={
4498         QinvProPro(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam].fNegDaughter,
4499                    fFemtoBuffer->GetEvt(iMix)->fAProTracks[iAPro]),
4500         meanDistSftAPro,
4501         minDistSftAPro,
4502         Qinv(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam], 
4503              fFemtoBuffer->GetEvt(iMix)->fAProTracks[iAPro])
4504       };
4505       BgALamAProMixed->Fill(x);
4506
4507         // Fill the qinv histogram
4508         //      f3HistBgALamAProQinvMixed->Fill(Qinv(fFemtoBuffer->GetEvt(0)->fBgALamTracks[iBgALam], (fFemtoBuffer->GetEvt(iMix))->fAProTracks[iAPro]),meanDistSftAPro,minDistSftAPro);
4509         
4510         }// AProton loop
4511     }// BgALambda loop
4512     
4513   }// Event buffer loop
4514
4515 }// End of void ProcessMixedBackground
4516
4517 //________________________________________________________________________
4518 Float_t AliAnalysisTaskProtonLambda::Qinv(FemtoBufferV0 v01, FemtoBufferV0 v02){
4519   // Copied from NA49. See http://na49info.web.cern.ch/na49info/na49/Software/minidst/ana/html/src/T49Tool.cxx.html#T49Tool:Qinv
4520   // Always using lambda mass (no mass difference found yet for lam <-> alam (see PDG))
4521
4522   // printf("v01 px %3.2f py %3.2f pz %3.2f"
4523   //     "v02 px %3.2f py %3.2f pz %3.2f"
4524   //     "\n"
4525   //     ,v01.fP[0],v01.fP[1],v01.fP[2]
4526   //     ,v02.fP[0],v02.fP[1],v02.fP[2]
4527   //     );
4528
4529   //Double_t e1 = t1->GetE(mPart1);
4530   Double_t e1 = sqrt(fkLamMass*fkLamMass + v01.fP[0]*v01.fP[0]+v01.fP[1]*v01.fP[1]+v01.fP[2]*v01.fP[2]);
4531   //Double_t e2 = t2->GetE(mPart2);
4532   Double_t e2 = sqrt(fkLamMass*fkLamMass + v02.fP[0]*v02.fP[0]+v02.fP[1]*v02.fP[1]+v02.fP[2]*v02.fP[2]);
4533   Double_t qinvL;
4534   Double_t qP;
4535   Double_t pinv;
4536   
4537   // First calculate -Qinv^2  as usual : 
4538   //qinvL = (e1-e2) * (e1-e2) - Q(t1,t2) * Q(t1,t2);
4539   qinvL = (e1-e2) * (e1-e2) - ( (v01.fP[0]-v02.fP[0])*(v01.fP[0]-v02.fP[0]) + (v01.fP[1]-v02.fP[1])*(v01.fP[1]-v02.fP[1]) + (v01.fP[2]-v02.fP[2])*(v01.fP[2]-v02.fP[2]) );  
4540
4541   //Qx(T49ParticleRoot* t1,T49ParticleRoot* t2) { return (t1->GetPx()-t2->GetPx()); };
4542   //static Double_t Qy(T49ParticleRoot* t1,T49ParticleRoot* t2) { return (t1->GetPy()-t2->GetPy()); };
4543   //static Double_t Qz(T49ParticleRoot* t1,T49ParticleRoot* t2) { return (t1->GetPz()-t2->GetPz()); };
4544   //static Double_t  Q(T49ParticleRoot* t1,T49ParticleRoot* t2)
4545   //               { return  TMath::Sqrt(Qx(t1,t2)*Qx(t1,t2)+Qy(t1,t2)*Qy(t1,t2)+Qz(t1,t2)*Qz(t1,t2)); };
4546   
4547
4548
4549   //static Double_t Px(T49ParticleRoot* t1,T49ParticleRoot* t2) { return (t1->GetPx()+t2->GetPx()); };
4550   //qP    = (e1-e2)   * (e1+e2)
4551   //      - Qx(t1,t2) * Px(t1,t2)
4552   //      - Qy(t1,t2) * Py(t1,t2)
4553   //      - Qz(t1,t2) * Pz(t1,t2);
4554   qP    = (e1-e2)   * (e1+e2)
4555         - (v01.fP[0]-v02.fP[0]) * (v01.fP[0]+v02.fP[0])
4556         - (v01.fP[1]-v02.fP[1]) * (v01.fP[1]+v02.fP[1])
4557         - (v01.fP[2]-v02.fP[2]) * (v01.fP[2]+v02.fP[2]);
4558
4559   //pinv  = (e1+e2) * (e1+e2) - P(t1,t2) * P(t1,t2);
4560   pinv  = (e1+e2) * (e1+e2) - ( (v01.fP[0]+v02.fP[0])*(v01.fP[0]+v02.fP[0])
4561                                +(v01.fP[1]+v02.fP[1])*(v01.fP[1]+v02.fP[1])
4562                                +(v01.fP[2]+v02.fP[2])*(v01.fP[2]+v02.fP[2]));
4563
4564   return TMath::Sqrt(qP*qP/pinv - qinvL);
4565 }
4566 //________________________________________________________________________
4567 Float_t AliAnalysisTaskProtonLambda::Qinv(FemtoBufferV0 v0, FemtoBufferTrack track) {
4568   // Copied from NA49. See http://na49info.web.cern.ch/na49info/na49/Software/minidst/ana/html/src/T49Tool.cxx.html#T49Tool:Qinv
4569   //  Always using lambda mass (no mass difference found yet for lam <-> alam (see PDG))
4570   
4571   //  Double_t e1 = t1->GetE(mPart1);
4572   Double_t e1 = sqrt(fkLamMass*fkLamMass + v0.fP[0]*v0.fP[0]+v0.fP[1]*v0.fP[1]+v0.fP[2]*v0.fP[2]);
4573   //  Double_t e2 = t2->GetE(mPart2);
4574   Double_t e2 = sqrt(fkProMass*fkProMass + track.fP[0]*track.fP[0]+track.fP[1]*track.fP[1]+track.fP[2]*track.fP[2]);
4575   Double_t qinvL;
4576   Double_t qP;
4577   Double_t pinv;
4578   
4579   // First calculate -Qinv^2  as usual : 
4580   //qinvL = (e1-e2) * (e1-e2) - Q(t1,t2) * Q(t1,t2);
4581   qinvL = (e1-e2) * (e1-e2) - ( (v0.fP[0]-track.fP[0])*(v0.fP[0]-track.fP[0]) + (v0.fP[1]-track.fP[1])*(v0.fP[1]-track.fP[1]) + (v0.fP[2]-track.fP[2])*(v0.fP[2]-track.fP[2]) );  
4582
4583   //Qx(T49ParticleRoot* t1,T49ParticleRoot* t2) { return (t1->GetPx()-t2->GetPx()); };
4584   //static Double_t Qy(T49ParticleRoot* t1,T49ParticleRoot* t2) { return (t1->GetPy()-t2->GetPy()); };
4585   //static Double_t Qz(T49ParticleRoot* t1,T49ParticleRoot* t2) { return (t1->GetPz()-t2->GetPz()); };
4586   //static Double_t  Q(T49ParticleRoot* t1,T49ParticleRoot* t2)
4587   //               { return  TMath::Sqrt(Qx(t1,t2)*Qx(t1,t2)+Qy(t1,t2)*Qy(t1,t2)+Qz(t1,t2)*Qz(t1,t2)); };
4588   
4589
4590
4591   //static Double_t Px(T49ParticleRoot* t1,T49ParticleRoot* t2) { return (t1->GetPx()+t2->GetPx()); };
4592   //qP    = (e1-e2)   * (e1+e2)
4593   //      - Qx(t1,t2) * Px(t1,t2)
4594   //      - Qy(t1,t2) * Py(t1,t2)
4595   //      - Qz(t1,t2) * Pz(t1,t2);
4596   qP    = (e1-e2)   * (e1+e2)
4597         - (v0.fP[0]-track.fP[0]) * (v0.fP[0]+track.fP[0])
4598         - (v0.fP[1]-track.fP[1]) * (v0.fP[1]+track.fP[1])
4599         - (v0.fP[2]-track.fP[2]) * (v0.fP[2]+track.fP[2]);
4600
4601   //pinv  = (e1+e2) * (e1+e2) - P(t1,t2) * P(t1,t2);
4602   pinv  = (e1+e2) * (e1+e2) - ( (v0.fP[0]+track.fP[0])*(v0.fP[0]+track.fP[0])
4603                                +(v0.fP[1]+track.fP[1])*(v0.fP[1]+track.fP[1])
4604                                +(v0.fP[2]+track.fP[2])*(v0.fP[2]+track.fP[2]));
4605
4606   return TMath::Sqrt(qP*qP/pinv - qinvL);
4607 }
4608 //________________________________________________________________________
4609 Float_t AliAnalysisTaskProtonLambda::Qinv(FemtoBufferTrack track, FemtoBufferV0 v0){
4610   return Qinv(v0, track);
4611 }
4612 //________________________________________________________________________
4613 Float_t AliAnalysisTaskProtonLambda::QinvProPro(FemtoBufferTrack proTrack1, FemtoBufferTrack proTrack2) {
4614   // Same as above, with different masses for the tracks,
4615   // here both tracks are protons
4616
4617   // Copied from NA49. See http://na49info.web.cern.ch/na49info/na49/Software/minidst/ana/html/src/T49Tool.cxx.html#T49Tool:Qinv
4618   
4619   //  PDG_t e1 = t1->GetE(mPart1);
4620   Double_t e1 = sqrt(fkProMass*fkProMass + proTrack1.fP[0]*proTrack1.fP[0]+proTrack1.fP[1]*proTrack1.fP[1]+proTrack1.fP[2]*proTrack1.fP[2]);
4621   //  Double_t e2 = t2->GetE(mPart2);
4622   Double_t e2 = sqrt(fkProMass*fkProMass + proTrack2.fP[0]*proTrack2.fP[0]+proTrack2.fP[1]*proTrack2.fP[1]+proTrack2.fP[2]*proTrack2.fP[2]);
4623   Double_t qinvL;
4624   Double_t qP;
4625   Double_t pinv;
4626   
4627   // First calculate -Qinv^2  as usual : 
4628   //qinvL = (e1-e2) * (e1-e2) - Q(t1,t2) * Q(t1,t2);
4629   qinvL = (e1-e2) * (e1-e2) - ( (proTrack1.fP[0]-proTrack2.fP[0])*(proTrack1.fP[0]-proTrack2.fP[0]) + (proTrack1.fP[1]-proTrack2.fP[1])*(proTrack1.fP[1]-proTrack2.fP[1]) + (proTrack1.fP[2]-proTrack2.fP[2])*(proTrack1.fP[2]-proTrack2.fP[2]) );  
4630
4631   //Qx(T49ParticleRoot* t1,T49ParticleRoot* t2) { return (t1->GetPx()-t2->GetPx()); };
4632   //static Double_t Qy(T49ParticleRoot* t1,T49ParticleRoot* t2) { return (t1->GetPy()-t2->GetPy()); };
4633   //static Double_t Qz(T49ParticleRoot* t1,T49ParticleRoot* t2) { return (t1->GetPz()-t2->GetPz()); };
4634   //static Double_t  Q(T49ParticleRoot* t1,T49ParticleRoot* t2)
4635   //               { return  TMath::Sqrt(Qx(t1,t2)*Qx(t1,t2)+Qy(t1,t2)*Qy(t1,t2)+Qz(t1,t2)*Qz(t1,t2)); };
4636   
4637
4638
4639   //static Double_t Px(T49ParticleRoot* t1,T49ParticleRoot* t2) { return (t1->GetPx()+t2->GetPx()); };
4640   //qP    = (e1-e2)   * (e1+e2)
4641   //      - Qx(t1,t2) * Px(t1,t2)
4642   //      - Qy(t1,t2) * Py(t1,t2)
4643   //      - Qz(t1,t2) * Pz(t1,t2);
4644   qP    = (e1-e2)   * (e1+e2)
4645         - (proTrack1.fP[0]-proTrack2.fP[0]) * (proTrack1.fP[0]+proTrack2.fP[0])
4646         - (proTrack1.fP[1]-proTrack2.fP[1]) * (proTrack1.fP[1]+proTrack2.fP[1])
4647         - (proTrack1.fP[2]-proTrack2.fP[2]) * (proTrack1.fP[2]+proTrack2.fP[2]);
4648
4649   //pinv  = (e1+e2) * (e1+e2) - P(t1,t2) * P(t1,t2);
4650   pinv  = (e1+e2) * (e1+e2) - ( (proTrack1.fP[0]+proTrack2.fP[0])*(proTrack1.fP[0]+proTrack2.fP[0])
4651                                +(proTrack1.fP[1]+proTrack2.fP[1])*(proTrack1.fP[1]+proTrack2.fP[1])
4652                                +(proTrack1.fP[2]+proTrack2.fP[2])*(proTrack1.fP[2]+proTrack2.fP[2]));
4653
4654   return TMath::Sqrt(qP*qP/pinv - qinvL);
4655 }
4656 //________________________________________________________________________
4657 Float_t AliAnalysisTaskProtonLambda::QinvPioPro(FemtoBufferTrack pioTrack, FemtoBufferTrack proTrack) {
4658   // Same as above, with different masses for the tracks,
4659   // here both tracks are protons
4660
4661   // Copied from NA49. See http://na49info.web.cern.ch/na49info/na49/Software/minidst/ana/html/src/T49Tool.cxx.html#T49Tool:Qinv
4662   
4663   //  PDG_t e1 = t1->GetE(mPart1);
4664   Double_t e1 = sqrt(fkPioMass*fkPioMass + pioTrack.fP[0]*pioTrack.fP[0]+pioTrack.fP[1]*pioTrack.fP[1]+pioTrack.fP[2]*pioTrack.fP[2]);
4665   //  Double_t e2 = t2->GetE(mPart2);
4666   Double_t e2 = sqrt(fkProMass*fkProMass + proTrack.fP[0]*proTrack.fP[0]+proTrack.fP[1]*proTrack.fP[1]+proTrack.fP[2]*proTrack.fP[2]);
4667   Double_t qinvL;
4668   Double_t qP;
4669   Double_t pinv;
4670   
4671   // First calculate -Qinv^2  as usual : 
4672   //qinvL = (e1-e2) * (e1-e2) - Q(t1,t2) * Q(t1,t2);
4673   qinvL = (e1-e2) * (e1-e2) - ( (pioTrack.fP[0]-proTrack.fP[0])*(pioTrack.fP[0]-proTrack.fP[0]) + (pioTrack.fP[1]-proTrack.fP[1])*(pioTrack.fP[1]-proTrack.fP[1]) + (pioTrack.fP[2]-proTrack.fP[2])*(pioTrack.fP[2]-proTrack.fP[2]) );  
4674
4675   //Qx(T49ParticleRoot* t1,T49ParticleRoot* t2) { return (t1->GetPx()-t2->GetPx()); };
4676   //static Double_t Qy(T49ParticleRoot* t1,T49ParticleRoot* t2) { return (t1->GetPy()-t2->GetPy()); };
4677   //static Double_t Qz(T49ParticleRoot* t1,T49ParticleRoot* t2) { return (t1->GetPz()-t2->GetPz()); };
4678   //static Double_t  Q(T49ParticleRoot* t1,T49ParticleRoot* t2)
4679   //               { return  TMath::Sqrt(Qx(t1,t2)*Qx(t1,t2)+Qy(t1,t2)*Qy(t1,t2)+Qz(t1,t2)*Qz(t1,t2)); };
4680   
4681
4682
4683   //static Double_t Px(T49ParticleRoot* t1,T49ParticleRoot* t2) { return (t1->GetPx()+t2->GetPx()); };
4684   //qP    = (e1-e2)   * (e1+e2)
4685   //      - Qx(t1,t2) * Px(t1,t2)
4686   //      - Qy(t1,t2) * Py(t1,t2)
4687   //      - Qz(t1,t2) * Pz(t1,t2);
4688   qP    = (e1-e2)   * (e1+e2)
4689         - (pioTrack.fP[0]-proTrack.fP[0]) * (pioTrack.fP[0]+proTrack.fP[0])
4690         - (pioTrack.fP[1]-proTrack.fP[1]) * (pioTrack.fP[1]+proTrack.fP[1])
4691         - (pioTrack.fP[2]-proTrack.fP[2]) * (pioTrack.fP[2]+proTrack.fP[2]);
4692
4693   //pinv  = (e1+e2) * (e1+e2) - P(t1,t2) * P(t1,t2);
4694   pinv  = (e1+e2) * (e1+e2) - ( (pioTrack.fP[0]+proTrack.fP[0])*(pioTrack.fP[0]+proTrack.fP[0])
4695                                +(pioTrack.fP[1]+proTrack.fP[1])*(pioTrack.fP[1]+proTrack.fP[1])
4696                                +(pioTrack.fP[2]+proTrack.fP[2])*(pioTrack.fP[2]+proTrack.fP[2]));
4697
4698   return TMath::Sqrt(qP*qP/pinv - qinvL);
4699 }
4700 //________________________________________________________________________
4701 // Float_t AliAnalysisTaskProtonLambda::QinvConstr(FemtoBufferV0 v0, FemtoBufferTrack track) {
4702 //   // Same as Qinv(v0,track) but with constrained momentum for the track
4703
4704 //   // Check whether constrained momentum is there
4705 //   if ((track.fPconstr[0]<0.00001)&&(track.fPconstr[1]<0.00001)&&(track.fPconstr[2]<0.00001))
4706 //     return Qinv(v0,track);
4707
4708 //   // Standard Qinv(v0, track), just with constrained momentum instead of TPC only momentum
4709 //   Double_t e1 = sqrt(fkLamMass*fkLamMass + v0.fP[0]*v0.fP[0]+v0.fP[1]*v0.fP[1]+v0.fP[2]*v0.fP[2]);
4710 //   Double_t e2 = sqrt(fkProMass*fkProMass + track.fPconstr[0]*track.fPconstr[0]+track.fPconstr[1]*track.fPconstr[1]+track.fPconstr[2]*track.fPconstr[2]);
4711 //   Double_t qinvL;
4712 //   Double_t qP;
4713 //   Double_t pinv;
4714 //   qinvL = (e1-e2) * (e1-e2) - ( (v0.fP[0]-track.fPconstr[0])*(v0.fP[0]-track.fPconstr[0]) + (v0.fP[1]-track.fPconstr[1])*(v0.fP[1]-track.fPconstr[1]) + (v0.fP[2]-track.fPconstr[2])*(v0.fP[2]-track.fPconstr[2]) );  
4715 //   qP    = (e1-e2)   * (e1+e2)
4716 //         - (v0.fP[0]-track.fPconstr[0]) * (v0.fP[0]+track.fPconstr[0])
4717 //      - (v0.fP[1]-track.fPconstr[1]) * (v0.fP[1]+track.fPconstr[1])
4718 //      - (v0.fP[2]-track.fPconstr[2]) * (v0.fP[2]+track.fPconstr[2]);
4719 //   pinv  = (e1+e2) * (e1+e2) - ( (v0.fP[0]+track.fPconstr[0])*(v0.fP[0]+track.fPconstr[0])
4720 //                             +(v0.fP[1]+track.fPconstr[1])*(v0.fP[1]+track.fPconstr[1])
4721 //                             +(v0.fP[2]+track.fPconstr[2])*(v0.fP[2]+track.fPconstr[2]));
4722
4723 //   return TMath::Sqrt(qP*qP/pinv - qinvL);
4724 // }
4725 // //________________________________________________________________________
4726 // Float_t AliAnalysisTaskProtonLambda::QinvConstr(FemtoBufferTrack track, FemtoBufferV0 v0){
4727 //   return QinvConstr(v0, track);
4728 // }
4729 //________________________________________________________________________
4730 Float_t AliAnalysisTaskProtonLambda::Minv(FemtoBufferV0 v01, FemtoBufferV0 v02){
4731   // Taken from NA49. See 
4732   // http://na49info.web.cern.ch/na49info/na49/Software/minidst/ana/html/src/T49Tool.cxx.html#T49Tool:Minv
4733   
4734   //  Double_t e1 = t1->GetE(mPart1);
4735   //  Double_t e2 = t2->GetE(mPart2);
4736   //  GetE(Float_t mass)  { return sqrt(GetP()*GetP()+mass*mass); }  
4737   Float_t e1 = TMath::Sqrt(v01.fP[0]*v01.fP[0] + v01.fP[1]*v01.fP[1] + v01.fP[2]*v01.fP[2] 
4738                            + fkLamMass*fkLamMass);
4739   Float_t e2 = TMath::Sqrt(v02.fP[0]*v02.fP[0] + v02.fP[1]*v02.fP[1] + v02.fP[2]*v02.fP[2] 
4740                            + fkLamMass*fkLamMass);
4741   
4742   // return TMath::Sqrt((e1+e2) * (e1+e2) - P(t1,t2) * P(t1,t2));
4743   return TMath::Sqrt((e1+e2) * (e1+e2) - (  (v01.fP[0]+v02.fP[0])*(v01.fP[0]+v02.fP[0])
4744                                            +(v01.fP[1]+v02.fP[1])*(v01.fP[1]+v02.fP[1])
4745                                            +(v01.fP[2]+v02.fP[2])*(v01.fP[2]+v02.fP[2])));
4746
4747 }
4748 //________________________________________________________________________
4749 Float_t AliAnalysisTaskProtonLambda::Minv(FemtoBufferV0 v0, FemtoBufferTrack track){
4750   // Taken from NA49. See 
4751   // http://na49info.web.cern.ch/na49info/na49/Software/minidst/ana/html/src/T49Tool.cxx.html#T49Tool:Minv
4752   
4753   //  Double_t e1 = t1->GetE(mPart1);
4754   //  Double_t e2 = t2->GetE(mPart2);
4755   //  GetE(Float_t mass)  { return sqrt(GetP()*GetP()+mass*mass); }  
4756   Float_t e1 = TMath::Sqrt(v0.fP[0]*v0.fP[0] + v0.fP[1]*v0.fP[1] + v0.fP[2]*v0.fP[2] 
4757                            + fkLamMass*fkLamMass);
4758   Float_t e2 = TMath::Sqrt(track.fP[0]*track.fP[0] + track.fP[1]*track.fP[1] + track.fP[2]*track.fP[2] 
4759                            + fkProMass*fkProMass);
4760   
4761   // return TMath::Sqrt((e1+e2) * (e1+e2) - P(t1,t2) * P(t1,t2));
4762   return TMath::Sqrt((e1+e2) * (e1+e2) - (  (v0.fP[0]+track.fP[0])*(v0.fP[0]+track.fP[0])
4763                                            +(v0.fP[1]+track.fP[1])*(v0.fP[1]+track.fP[1])
4764                                            +(v0.fP[2]+track.fP[2])*(v0.fP[2]+track.fP[2])));
4765
4766 }
4767 //________________________________________________________________________
4768 Float_t AliAnalysisTaskProtonLambda::Minv(FemtoBufferTrack track, FemtoBufferV0 v0){
4769     return Minv(v0, track);
4770 }
4771 //________________________________________________________________________
4772 Float_t AliAnalysisTaskProtonLambda::calcDist(const Float_t r1[3], const Float_t r2[3]){
4773   // Return the spatial distance of two space vectors r1 and r2
4774   
4775   // Return 'error' when no position is given.
4776   // // When a particle doesn't manage to get to a certain radius,
4777   // // the function GetXYZAt returns position 0,0,0
4778   // if ( (r1[0] < 0.0001 && r1[1] < 0.0001 && r1[1] < 0.0001) ||
4779   //      (r2[0] < 0.0001 && r2[1] < 0.0001 && r2[1] < 0.0001) )
4780   //   return -2.0;
4781   
4782   // The above stuff is stupid, this discards every 
4783   // track just going in the negative direction.
4784   // Also we don't use the GetXYZAt anymore and our
4785   // 'bad position' value is -9999.,-9999.-9999.
4786   if ( (r1[0] < -9998. && r1[1] < -9998. && r1[1] < -9998.) ||
4787        (r2[0] < -9998. && r2[1] < -9998. && r2[1] < -9998.) )
4788     return -2.0;
4789   
4790
4791   return TMath::Sqrt((r1[0]-r2[0])*(r1[0]-r2[0]) +
4792                      (r1[1]-r2[1])*(r1[1]-r2[1]) +
4793                      (r1[2]-r2[2])*(r1[2]-r2[2]) );
4794 }
4795 //________________________________________________________________________
4796 // This function is no longer needed
4797 // Float_t AliAnalysisTaskProtonLambda::calcDistSft(const Float_t r1[3], const Float_t r2[3], const FemtoBufferEvent *evt1, const FemtoBufferEvent *evt2){
4798 //   // Return the spatial distance of two space vectors r1 and r2
4799 //   // With each event shifted to (0,0,0)
4800   
4801 //   // // Return 'error' when no position is given.
4802 //   // // When a particle doesn't manage to get to a certain radius,
4803 //   // // the function GetXYZAt returns position 0,0,0
4804 //   // if ( (r1[0] < 0.0001 && r1[1] < 0.0001 && r1[2] < 0.0001) ||
4805 //   //      (r2[0] < 0.0001 && r2[1] < 0.0001 && r2[2] < 0.0001) )
4806 //   //   return -2.0;
4807 //   // The above stuff is stupid, this discards every 
4808 //   // track just going in the negative direction.
4809 //   // Also we don't use the GetXYZAt anymore and our
4810 //   // 'bad position' value is -9999.,-9999.-9999.
4811 //   if ( (r1[0] < -9998. && r1[1] < -9998. && r1[1] < -9998.) ||
4812 //        (r2[0] < -9998. && r2[1] < -9998. && r2[1] < -9998.) )
4813 //     return -2.0;
4814
4815 //   // Get the vertex postions 
4816 //   Double_t vtx1[3],vtx2[3];
4817 //   evt1->GetVtxPos(vtx1);
4818 //   evt2->GetVtxPos(vtx2);
4819   
4820 //   // Calculate shifted positions
4821 //   Double_t r1Sft[3],r2Sft[3];
4822 //   for (Int_t i=0;i<3;i++){
4823 //     r1Sft[i]=r1[i] - vtx1[i];
4824 //     r2Sft[i]=r2[i] - vtx2[i];
4825 //   }
4826
4827 //   // Return shifted distances
4828 //   return TMath::Sqrt((r1Sft[0]-r2Sft[0])*(r1Sft[0]-r2Sft[0]) +
4829 //                   (r1Sft[1]-r2Sft[1])*(r1Sft[1]-r2Sft[1]) +
4830 //                   (r1Sft[2]-r2Sft[2])*(r1Sft[2]-r2Sft[2]) );
4831 // }
4832 //________________________________________________________________________
4833 // void AliAnalysisTaskProtonLambda::constrainTrack(AliAODTrack *track) {
4834 //   // Abuses data members of the AliAODTrack to store a set of track
4835 //   // parameters for TPC only constrained to the primary vtx
4836 //   // plus a bool whether constraining was successful
4837 //   if (!track->GetConstrainedParam())
4838 //     return;
4839   
4840 //   // Constrain track to pri vtx, set the bool to successful / unsuccessful
4841 //   track->SetTOFcluster(track->RelateToVertexTPC(fAOD->GetPrimaryVertex(), fAOD->GetMagneticField(),
4842 //                                              5.0, const_cast<AliExternalTrackParam *> (track->GetConstrainedParam())));
4843 // }
4844 //________________________________________________________________________
4845 Bool_t AliAnalysisTaskProtonLambda::goodDCA(AliAODTrack *track) {
4846   // Get the DCAxy and DCAz. There also exists a TPC only 
4847   // impact parameter, but this has not enough resolution 
4848   // to discriminate between primaries, secondaries and material
4849   Float_t xy=0.,rap=RapidityProton(track),pt=track->Pt();
4850   xy = DCAxy(fGTI[-track->GetID()-1], fAOD);
4851   // Fill the DCAxy histograms
4852   if (track->Charge() > 0){
4853     fPriHistDCAxyYPtPro->Fill(xy,rap,pt);
4854   }
4855   else{
4856     fPriHistDCAxyYPtAPro->Fill(xy,rap,pt);
4857   }
4858   // Do a cut. 0.1 cm shows highest significance for primaries
4859   if (xy>.1)
4860     return kFALSE;
4861   return kTRUE;
4862 }
4863 //_______________________________________________________________
4864 Float_t AliAnalysisTaskProtonLambda::RapidityProton(AliAODTrack *track){
4865   // Can't find how to set the assumed mass for the AliAODTrack.
4866   // Same stuff as in AliAODTrack::Y() just with proton mass
4867   Double_t e = TMath::Sqrt(track->P()*track->P() + fkProMass*fkProMass);
4868   Double_t pz = track->Pz();
4869   if (e != TMath::Abs(pz)) { // energy was not equal to pz
4870     return 0.5*TMath::Log((e+pz)/(e-pz));
4871   } else { // energy was equal to pz
4872     return -999.;
4873   }
4874 }
4875 //________________________________________________________________________
4876 // void AliAnalysisTaskProtonLambda::getTPConlyV0Info(const AliAODTrack *posDaughter,const AliAODTrack *negDaughter, Double_t tpcV0Mom[3], Double_t TPConlyV0MinvLam, Double_t TPConlyV0MinvALam){
4877 //   //
4878 //   // Calculates a V0 with the TPC only parameters
4879 //   //
4880
4881 //   // Duplicate the V0
4882 //   AliV0 tpcV0;
4883 //   // Get the TPC only track parameters from the daughters
4884 //   const AliExternalTrackParam *pParam = 0, *nParam = 0;
4885 //   pParam = posDaughter->GetTPCInnerParam();
4886 //   nParam = negDaughter->GetTPCInnerParam();
4887 //   // Protection if there's no TPC only track parameters
4888 //   if(!pParam||!nParam)
4889 //     return;
4890 //   // Set the tpcV0 daughters to the TPC only ones
4891 //   tpcV0.SetParamP(*pParam);
4892 //   tpcV0.SetParamN(*nParam);
4893 //   // Calculate the new properties of the V0
4894 //   Double_t vertex[3];
4895 //   fFemtoBuffer->GetEvt(0)->GetVtxPos(vertex);
4896 //   tpcV0.Update((Float_t *) vertex);
4897 //   // Get the updated momentum
4898 //   tpcV0.fPxPyPz(tpcV0Mom);
4899 //   // New TPC only mass, lambda..
4900 //   tpcV0.ChangeMassHypothesis(3122);
4901 //   TPConlyV0MinvLam = tpcV0.GetEffMass();
4902 //   // ..anti-lambda.
4903 //   tpcV0.ChangeMassHypothesis(-3122);
4904 //   TPConlyV0MinvALam = tpcV0.GetEffMass();
4905 // }
4906 //________________________________________________________________________
4907 Float_t AliAnalysisTaskProtonLambda::DCAxy(const AliAODTrack *track, const AliVEvent *evt){
4908   // Note that AliAODTrack::PropagateToDCA() changes the track. 
4909   // Don't know whether this is what one wants?
4910   if(!track){
4911     printf("Pointer to track is zero!\n");
4912     return -9999.;
4913   }
4914
4915   // Create an external parameter from the AODtrack
4916   AliExternalTrackParam etp; etp.CopyFromVTrack(track);
4917   // Propagation through the beam pipe would need a correction 
4918   // for material, I guess.
4919   if(etp.GetX()>3.) {
4920     printf("This method can be used only for propagation inside the beam pipe\n");
4921     printf("  id: %d, filtermap: %d\n",track->GetID(),track->GetFilterMap());
4922     return -9999.; 
4923   }
4924   // Do the propagation
4925   Double_t dca[2]={-9999.,-9999.},covar[3]={0.,0.,0.};
4926   if(!etp.PropagateToDCA(evt->GetPrimaryVertex(),evt->GetMagneticField(),10.,dca,covar)) return -9999.;
4927   // return the DCAxy
4928   return dca[0];
4929 }
4930 //________________________________________________________________________
4931 void AliAnalysisTaskProtonLambda::FillDedxHist(const AliVTrack *track){
4932   // This is for visualization. Fill the the dE/dx histograms
4933   // for all tracks, not only for those, where only the TPC
4934   // is used for PID. Thus avoiding the sharp cut off at a 
4935   // momentum of 0.75 GeV/c.
4936
4937   if(!(fGTI[-track->GetID()-1])){
4938     printf("Warning: No global track info there!\n");
4939     return;
4940   }
4941
4942   // TPC signal and Nsigma. See STEER/STEERBase/AliPIDResponse.h for how 
4943   // NSigmaTPC works (and refrain from banging your head against the wall
4944   // when you see it).
4945   // Positive tracks
4946   if (track->Charge() > 0){
4947     fPriHistTPCsignalPos->Fill((fGTI[-track->GetID()-1])->GetTPCmomentum(),(fGTI[-track->GetID()-1])->GetTPCsignal());
4948     // fPriHistNsigmaTPCPos->Fill((fGTI[-track->GetID()-1])->GetTPCmomentum(),
4949     //                         fPIDResponse->GetTPCResponse().GetNumberOfSigmas((fGTI[-track->GetID()-1])->GetTPCmomentum()
4950     //                                                                          ,(fGTI[-track->GetID()-1])->GetTPCsignal()
4951     //                                                                          ,(fGTI[-track->GetID()-1])->GetTPCsignalN()
4952     //                                                                          ,AliPID::kProton));
4953     // Fill histograms in three momentum ranges
4954     fPriHistTPCsignalLowPPos->Fill((fGTI[-track->GetID()-1])->GetTPCmomentum(),(fGTI[-track->GetID()-1])->GetTPCsignal());
4955     fPriHistTPCsignalMedPPos->Fill((fGTI[-track->GetID()-1])->GetTPCmomentum(),(fGTI[-track->GetID()-1])->GetTPCsignal());
4956     fPriHistTPCsignalHigPPos->Fill((fGTI[-track->GetID()-1])->GetTPCmomentum(),(fGTI[-track->GetID()-1])->GetTPCsignal());  
4957     
4958   }
4959   // Negative tracks
4960   else{ 
4961     fPriHistTPCsignalNeg->Fill((fGTI[-track->GetID()-1])->GetTPCmomentum(),(fGTI[-track->GetID()-1])->GetTPCsignal());
4962     // fPriHistNsigmaTPCNeg->Fill((fGTI[-track->GetID()-1])->GetTPCmomentum(),
4963     //                         fPIDResponse->GetTPCResponse().GetNumberOfSigmas((fGTI[-track->GetID()-1])->GetTPCmomentum()
4964     //                                                                          ,(fGTI[-track->GetID()-1])->GetTPCsignal()
4965     //                                                                          ,(fGTI[-track->GetID()-1])->GetTPCsignalN()
4966     //                                                                          ,AliPID::kProton));
4967     // Fill histograms in three momentum ranges
4968     fPriHistTPCsignalLowPNeg->Fill((fGTI[-track->GetID()-1])->GetTPCmomentum(),(fGTI[-track->GetID()-1])->GetTPCsignal());
4969     fPriHistTPCsignalMedPNeg->Fill((fGTI[-track->GetID()-1])->GetTPCmomentum(),(fGTI[-track->GetID()-1])->GetTPCsignal());
4970     fPriHistTPCsignalHigPNeg->Fill((fGTI[-track->GetID()-1])->GetTPCmomentum(),(fGTI[-track->GetID()-1])->GetTPCsignal());  
4971   }
4972 }
4973 //________________________________________________________________________
4974 void AliAnalysisTaskProtonLambda::StoreGlobalTrackReference(AliAODTrack *track){
4975   // Stores the pointer to the global track
4976
4977   // This was AOD073
4978   // // Don't use the filter bits 2 (ITS standalone) and 128 TPC only
4979   // // Remove this return statement and you'll see they don't have
4980   // // any TPC signal
4981   // if(track->TestFilterBit(128) || track->TestFilterBit(2))
4982   //   return;
4983   // This is AOD086
4984   // Another set of tracks was introduced: Global constrained.
4985   // We only want filter bit 1 <-- NO! we also want no 
4986   // filter bit at all, which are the v0 tracks
4987   //  if(!track->TestFilterBit(1))
4988   //    return;
4989
4990   // There are also tracks without any filter bit, i.e. filter map 0,
4991   // at the beginning of the event: they have ~id 1 to 5, 1 to 12
4992   // This are tracks that didn't survive the primary track filter but
4993   // got written cause they are V0 daughters
4994
4995   // Check whether the track has some info
4996   // I don't know: there are tracks with filter bit 0
4997   // and no TPC signal. ITS standalone V0 daughters?
4998   // if(!track->GetTPCsignal()){
4999   //   printf("Warning: track has no TPC signal, "
5000   //       //      "not adding it's info! "
5001   //       "ID: %d FilterMap: %d\n"
5002   //       ,track->GetID(),track->GetFilterMap());
5003   //   //    return;
5004   // }
5005   
5006   // Check that the id is positive
5007   if(track->GetID()<0){
5008     //    printf("Warning: track has negative ID: %d\n",track->GetID());
5009     return;
5010   }
5011
5012   // Check id is not too big for buffer
5013   if(track->GetID()>=fTrackBuffSize){
5014     printf("Warning: track ID too big for buffer: ID: %d, buffer %d\n"
5015            ,track->GetID(),fTrackBuffSize);
5016     return;
5017   }
5018
5019   // Warn if we overwrite a track
5020   if(fGTI[track->GetID()]){
5021     // Seems like there are FilterMap 0 tracks
5022     // that have zero TPCNcls, don't store these!
5023     if( (!track->GetFilterMap()) &&
5024         (!track->GetTPCNcls())   )
5025       return;
5026
5027     // Imagine the other way around,
5028     // the zero map zero clusters track
5029     // is stored and the good one wants 
5030     // to be added. We ommit the warning
5031     // and just overwrite the 'bad' track
5032     if( fGTI[track->GetID()]->GetFilterMap() ||
5033         fGTI[track->GetID()]->GetTPCNcls()   ){
5034       // If we come here, there's a problem
5035       printf("Warning! global track info already there!");
5036       printf("         TPCNcls track1 %u track2 %u",
5037              (fGTI[track->GetID()])->GetTPCNcls(),track->GetTPCNcls());
5038       printf("         FilterMap track1 %u track2 %u\n",
5039              (fGTI[track->GetID()])->GetFilterMap(),track->GetFilterMap());
5040     }
5041   } // Two tracks same id
5042
5043   // // There are tracks with filter bit 0,
5044   // // do they have TPCNcls stored?
5045   // if(!track->GetFilterMap()){
5046   //   printf("Filter map is zero, TPCNcls: %u\n"
5047   //       ,track->GetTPCNcls());
5048   // }
5049
5050   // Assign the pointer
5051   (fGTI[track->GetID()]) = track;
5052 }
5053 //________________________________________________________________________
5054 void AliAnalysisTaskProtonLambda::ResetGlobalTrackReference(){
5055   // Sets all the pointers to zero. To be called at
5056   // the beginning or end of an event
5057   for(UShort_t i=0;i<fTrackBuffSize;i++){
5058     fGTI[i]=0;
5059   }
5060 }
5061 //________________________________________________________________________
5062 Bool_t AliAnalysisTaskProtonLambda::acceptTrack(const AliAODTrack *track){
5063   // Apply additional track cuts
5064
5065   // In the documents
5066   // https://alisoft.cern.ch/AliRoot/trunk/TPC/doc/Definitions/Definitions.pdf
5067   // TPC people describe the cut strategy for the TPC. It is explicitly
5068   // stated that a cut on the number of crossed rows and a cut on the
5069   // number of crossed rows over findable clusters is recommended to 
5070   // remove fakes. In the pdf a cut value of .83 on the ratio 
5071   // is stated, no value for the number of crossed rows. Looking at the 
5072   // AliESDtrackCuts.cxx one sees that exactly this cut is used with
5073   // 0.8 on the ratio and 70 on the crossed rows.
5074
5075   // Checked the filter task and AliAODTrack and AliESDtrack and
5076   // AliESDtrackCuts and the Definitions.pdf:
5077   // The function to get the findable clusters is GetTPCNclsF()
5078   
5079   // For the number fo crossed rows for ESD tracks, the function
5080   // GetTPCCrossedRows() usually is used. Looking at the AliESDtrack.cxx
5081   // one sees that it's just an alias (with additional caching) for
5082   // GetTPCClusterInfo(2, 1); The identical function exists in the
5083   // AliAODTrack.cxx
5084
5085   // I checked: for AOD073 both, the number of crossed rows and the
5086   // number of findable clusters, are there.
5087
5088   // WARNING: in LHC10h pass2 the cluster map is wrong for 
5089   // sector 0 / 18. It's used in the calculation of
5090   // the number of crossed rows!
5091
5092   Float_t nCrossed = track->GetTPCClusterInfo(2, 1);
5093   if(nCrossed<70)
5094     return kFALSE;
5095   if(!track->GetTPCNclsF())
5096     return kFALSE; // Note that the AliESDtrackCuts would here return kTRUE
5097   if((nCrossed/track->GetTPCNclsF()) < .8)
5098     return kFALSE;
5099   return kTRUE;
5100 }
5101 //________________________________________________________________________
5102 Bool_t AliAnalysisTaskProtonLambda::GoodTPCFitMapSharedMap(const AliAODTrack *pTrack,
5103                                                            const AliAODTrack *nTrack){
5104   // Rejects tracks with shared clusters after filling a control histogram
5105   // This overload is used for positive and negative daughters from V0s
5106
5107   // Get the shared maps
5108   const TBits posSharedMap = pTrack->GetTPCSharedMap();
5109   const TBits negSharedMap = nTrack->GetTPCSharedMap();
5110   // Fill a control histogram
5111   //  fHistShareV0pos->Fill(posSharedMap.CountBits());
5112   //  fHistShareV0neg->Fill(negSharedMap.CountBits());
5113   // Reject shared clusters
5114   if( ((posSharedMap.CountBits()) >= 1) ||
5115       ((negSharedMap.CountBits()) >= 1)){
5116     // Bad tracks, have too many shared clusters!
5117     return kFALSE;
5118   }
5119   return kTRUE;
5120 }
5121 //________________________________________________________________________
5122 Bool_t AliAnalysisTaskProtonLambda::GoodTPCFitMapSharedMap(const AliAODTrack *track){
5123   // Rejects tracks with shared clusters after filling a control histogram
5124   // This overload is used for primaries
5125
5126   // Get the shared maps
5127   const TBits sharedMap = track->GetTPCSharedMap();
5128   // Fill a control histogram
5129   fPriHistShare->Fill(sharedMap.CountBits());
5130   // Reject shared clusters
5131   if((sharedMap.CountBits()) >= 1){
5132     // Bad track, has too many shared clusters!
5133     return kFALSE;
5134   }
5135   return kTRUE;
5136 }
5137 //________________________________________________________________________
5138 Float_t AliAnalysisTaskProtonLambda::GetCorrectedTOFSignal(const AliVTrack *track){
5139   // Return the corrected TOF signal, see https://twiki.cern.ch/twiki/bin/viewauth/ALICE/TOF
5140
5141   // Check for the global track
5142   if(!(fGTI[-track->GetID()-1])){
5143     printf("Warning: no corresponding global track found!\n");
5144     return -9999.;
5145   }
5146
5147   // Request the TOFpid bit
5148   if(!((fGTI[-track->GetID()-1])->GetStatus() & AliVTrack::kTOFpid))
5149     return -9999.;
5150
5151   // The expected time
5152   Double_t expectedTimes[AliPID::kSPECIES];
5153   (fGTI[-track->GetID()-1])->GetIntegratedTimes(expectedTimes);
5154
5155   // Check for TOF header
5156   if(fAOD->GetTOFHeader()){
5157     // New AODs without start time subtraction
5158     return ((fGTI[-track->GetID()-1])->GetTOFsignal()
5159             - expectedTimes[AliPID::kProton]
5160             - fPIDResponse->GetTOFResponse().GetStartTime(track->P()));
5161   }
5162
5163   // Old AODs with start time already subtracted
5164   return ((fGTI[-track->GetID()-1])->GetTOFsignal()
5165            - expectedTimes[AliPID::kProton]);
5166 }
5167 //________________________________________________________________________
5168 Float_t AliAnalysisTaskProtonLambda::mt(FemtoBufferTrack track, FemtoBufferV0 v0) {
5169   // Overloaded function
5170   return mt(v0,track);
5171 }
5172 //________________________________________________________________________
5173 Float_t AliAnalysisTaskProtonLambda::mt(FemtoBufferV0 v0, FemtoBufferTrack track){
5174   // Returns the transverse mass of the pair assuming 
5175   // proton mass for track and lambda mass for v0
5176
5177   // Following Phys Rev C 83, 054906
5178   return TMath::Sqrt(ktSquared(v0,track) +
5179                      TMath::Power((0.5*(fkLamMass + fkProMass)),2));
5180 }
5181
5182 //________________________________________________________________________
5183 Float_t AliAnalysisTaskProtonLambda::mt(FemtoBufferV0 v01, FemtoBufferV0 v02){
5184   // Returns the transverse mass of the pair assuming 
5185   // lambda mass for both v0
5186
5187   // Following Phys Rev C 83, 054906
5188   return TMath::Sqrt(ktSquared(v01,v02) +
5189                      TMath::Power(fkLamMass,2));
5190 }
5191 //________________________________________________________________________
5192 Float_t AliAnalysisTaskProtonLambda::ktSquared(FemtoBufferV0 v01, FemtoBufferV0 v02){
5193   // Returns the kt squared
5194   // kt = 1/2 * | (vector{pt1} + vector{pt2}) |
5195   // kt = 1/2 * | ({px1+px2}, {py1+py2}) |
5196   // kt2 = 1/2*1/2 * ( (px1+px2)*(px1+px2) + (py1+py2)*(py1+py2) )
5197   return .5*.5*(  (v01.fP[0] + v02.fP[0])*(v01.fP[0] + v02.fP[0])
5198                 + (v01.fP[1] + v02.fP[1])*(v01.fP[1] + v02.fP[1]));
5199 }
5200 //________________________________________________________________________
5201 Float_t AliAnalysisTaskProtonLambda::ktSquared(FemtoBufferTrack track, FemtoBufferV0 v0){
5202   // Overloaded function
5203   return ktSquared(v0,track);
5204 }
5205 //________________________________________________________________________
5206 Float_t AliAnalysisTaskProtonLambda::ktSquared(FemtoBufferV0 v0, FemtoBufferTrack track){
5207   // Returns the kt squared
5208   // kt = 1/2 * | (vector{pt1} + vector{pt2}) |
5209   // kt = 1/2 * | ({px1+px2}, {py1+py2}) |
5210   // kt2 = 1/2*1/2 * ( (px1+px2)*(px1+px2) + (py1+py2)*(py1+py2) )
5211   return .5*.5*(  (v0.fP[0] + track.fP[0])*(v0.fP[0] + track.fP[0])
5212                 + (v0.fP[1] + track.fP[1])*(v0.fP[1] + track.fP[1]));
5213 }
5214 //________________________________________________________________________
5215 AliAnalysisTaskProtonLambda::AliAnalysisTaskProtonLambda(const AliAnalysisTaskProtonLambda& atpl)
5216   // Not implemented, only initializing the const data member as the compiler complains.
5217   // Implementation is straight forward, though.
5218   : AliAnalysisTaskSE(atpl),
5219     fkUseOnTheFly(atpl.fkUseOnTheFly),
5220     fkAbsZvertexCut(atpl.fkAbsZvertexCut),
5221     fkCentCut(atpl.fkCentCut),
5222     fkLamMass(atpl.fkLamMass),
5223     fkProMass(atpl.fkProMass),
5224     fkPioMass(atpl.fkPioMass),
5225     
5226     fPIDResponse(0), 
5227     fTpcResponse(0),
5228     fFemtoBuffer(0),
5229     fAOD(0), fPrimaryVtx(0), fOutputList(0), fOutputPrimaries(0),
5230     fOutput2Part(0),
5231     fGTI(0),    
5232     fTrackBuffSize(atpl.fTrackBuffSize),
5233     fHistGoodEvent(0),
5234     // fHistPrimaryVertexPosXY(0), fHistPrimaryVertexPosZ(0),        
5235     // fHistTrackMultiplicity(0),    
5236     // fHistShareV0pos(0),fHistShareV0neg(0),
5237     // fHistPosTofBeforeCut(0), fHistPosTofAfterCut(0),           
5238     // fHistNegTofBeforeCut(0), fHistNegTofAfterCut(0),           
5239     // fHistPosTpcBeforeCut(0), fHistPosTpcAfterCut(0),            
5240     // fHistNegTpcBeforeCut(0), fHistNegTpcAfterCut(0),            
5241     // fHistGoodV0(0), fHistCorrectSigns(0),              
5242     // fHistDcaPosToPrimVertex(0), fHistDcaNegToPrimVertex(0),        
5243     // fHistDcaPosToPrimVertexZoom(0), fHistDcaNegToPrimVertexZoom(0),  
5244     // fHistRadiusV0(0), fHistDecayLengthV0(0), fHistDcaV0Daughters(0),          
5245     // fHistChi2(0), fHistCosPointAngle(0), fHistCosPointAngleZoom(0),
5246     fHistSideBandOffLam(0), fHistSideBandOffALam(0), fHistTPCNclsPosOffLam(0),       
5247     fHistTPCNclsNegOffLam(0), fHistTPCNclsPosOffALam(0), fHistTPCNclsNegOffALam(0),      
5248     // fHistPosNsigmaTpcOffLam(0), fHistPosNsigmaTpcOffALam(0), fHistNegNsigmaTpcOffLam(0),
5249     // fHistNegNsigmaTpcOffALam(0), fHistUseTofOffLam(0), fHistUseTofOffALam(0),
5250     // fHistDcaPosOffLam(0), fHistDcaPosOffALam(0), fHistDcaNegOffLam(0),           
5251     // fHistDcaNegOffALam(0), fHistDcaV0DaughtersOffLam(0), fHistDcaV0DaughtersOffALam(0),  
5252     // fHistCosPointLamOff(0), fHistCosPointALamOff(0), fHistCosPointLamZoomOff(0),     
5253     // fHistCosPointALamZoomOff(0), fHistV0RadiusLamOff(0), fHistV0RadiusALamOff(0),        
5254     // fHistV0DecayLengthLamOff(0), fHistV0DecayLengthALamOff(0), fHistDcaV0PriVertexLamOff(0),     
5255     // fHistDcaV0PriVertexALamOff(0),
5256     fHistMassLambdaOff(0), fHistMassAntiLambdaOff(0),        
5257     // fHistPtVsMassLambdaOff(0), fHistPtVsMassAntiLambdaOff(0),
5258     fHistYPtMassLamOff(0), fHistYPtMassALamOff(0),
5259     // fHistPtVsYLambdaOff(0), fHistPtVsYAntiLambdaOff(0),       
5260     fHistSideBandOnLam(0), fHistSideBandOnALam(0),
5261     // fHistLikeSignOnLam(0), fHistLikeSignOnALam(0),         
5262     fHistTPCNclsPosOnLam(0), fHistTPCNclsNegOnLam(0), fHistTPCNclsPosOnALam(0),fHistTPCNclsNegOnALam(0),     
5263     // fHistPosNsigmaTpcOnLam(0), fHistPosNsigmaTpcOnALam(0), fHistNegNsigmaTpcOnLam(0), fHistNegNsigmaTpcOnALam(0),        
5264     // fHistUseTofOnLam(0),fHistUseTofOnALam(0),fHistDcaPosOnLam(0),fHistDcaPosOnALam(0),fHistDcaNegOnLam(0),               
5265     // fHistDcaNegOnALam(0),fHistDcaV0DaughtersOnLam(0),fHistDcaV0DaughtersOnALam(0),fHistCosPointLamOn(0),             
5266     // fHistCosPointALamOn(0),fHistCosPointLamZoomOn(0),fHistCosPointALamZoomOn(0),fHistV0RadiusLamOn(0),             
5267     // fHistV0RadiusALamOn(0),fHistV0DecayLengthLamOn(0),fHistV0DecayLengthALamOn(0),fHistDcaV0PriVertexLamOn(0),       
5268     // fHistDcaV0PriVertexALamOn(0),
5269     // fHistChi2TPCPosLamOn(0),  fHistChi2TPCPosALamOn(0),  fHistChi2TPCNegLamOn(0),  fHistChi2TPCNegALamOn(0),
5270     // fHistMinvTPConlyLamOn(0),  fHistMinvTPConlyALamOn(0),
5271     fHistMassLambdaOn(0),fHistMassAntiLambdaOn(0),
5272     // fHistPtVsMassLambdaOn(0), fHistPtVsMassAntiLambdaOn(0),
5273     fHistYPtMassLamOn(0),fHistYPtMassALamOn(0),
5274     // fHistPtVsYLambdaOn(0), fHistPtVsYAntiLambdaOn(0),
5275     // fHistMomDiffLam(0),fHistMomDiffALam(0),fHistMomDiffBgLam(0),fHistMomDiffBgALam(0),
5276     // fHistMomDiffWoSPDLam(0),fHistMomDiffWoSPDALam(0),fHistMomDiffWoSPDBgLam(0),fHistMomDiffWoSPDBgALam(0),
5277     fPriHistShare(0),
5278     // fPriHistPosNsigmaTof(0),
5279     fPriHistPosNsigmaTofVsP(0),fPriHistPosNsigmaTofVsPt(0),     
5280     // fPriHistNegNsigmaTof(0),
5281     fPriHistNegNsigmaTofVsP(0),fPriHistNegNsigmaTofVsPt(0),fPriHistTOFsignalPosVsP(0),      
5282     fPriHistTOFsignalPosVsPt(0),fPriHistTOFsignalNegVsP(0),fPriHistTOFsignalNegVsPt(0),fPriHistHybridTOFsigPosWoTPC(0), 
5283     fPriHistHybridTOFsigPosTPCok(0),fPriHistHybridTOFsigNegWoTPC(0),fPriHistHybridTOFsigNegTPCok(0),
5284     // fPriHistHasTofPos(0),          
5285     fPriHistTPCsignalPos(0),
5286     // fPriHistNsigmaTPCPos(0), fPriHistTPCsignalTOFcutPos(0),fPriHistNsigmaTPCTOFcutPos(0),   
5287     fPriHistTPCsignalLowPPos(0),fPriHistTPCsignalMedPPos(0),fPriHistTPCsignalHigPPos(0),
5288     // fPriHistHasTofNeg(0),         
5289     fPriHistTPCsignalNeg(0),
5290     // fPriHistNsigmaTPCNeg(0),fPriHistTPCsignalTOFcutNeg(0),fPriHistNsigmaTPCTOFcutNeg(0),    
5291     fPriHistTPCsignalLowPNeg(0),fPriHistTPCsignalMedPNeg(0),fPriHistTPCsignalHigPNeg(0),
5292     fPriHistDCAxyYPtPro(0),fPriHistDCAxyYPtAPro(0),
5293     // f2HistLamLamMeanMinDistProReal(0),
5294     // f2HistLamLamMeanMinDistPioReal(0),f2HistLamProMeanMinDistProReal(0),f2HistALamALamMeanMinDistAProReal(0), 
5295     // f2HistALamALamMeanMinDistPioReal(0),f2HistALamAProMeanMinDistAProReal(0),
5296     // f2HistSftLamLamMeanMinDistProReal(0),
5297     // f2HistSftLamLamMeanMinDistPioReal(0),f2HistSftLamProMeanMinDistProReal(0),f2HistSftALamALamMeanMinDistAProReal(0), 
5298     // f2HistSftALamALamMeanMinDistPioReal(0),f2HistSftALamAProMeanMinDistAProReal(0),
5299     // f2HistSftIrocLamLamMeanMinDistProReal(0),
5300     // f2HistSftIrocLamLamMeanMinDistPioReal(0),f2HistSftIrocLamProMeanMinDistProReal(0),f2HistSftIrocALamALamMeanMinDistAProReal(0), 
5301     // f2HistSftIrocALamALamMeanMinDistPioReal(0),f2HistSftIrocALamAProMeanMinDistAProReal(0),
5302     // f2HistSftOrocLamLamMeanMinDistProReal(0),
5303     // f2HistSftOrocLamLamMeanMinDistPioReal(0),f2HistSftOrocLamProMeanMinDistProReal(0),f2HistSftOrocALamALamMeanMinDistAProReal(0), 
5304     // f2HistSftOrocALamALamMeanMinDistPioReal(0),f2HistSftOrocALamAProMeanMinDistAProReal(0),
5305     // f2HistMtLamLamReal(0), 
5306     f2HistMtLamProReal(0), 
5307     // f2HistMtALamALamReal(0), 
5308     f2HistMtALamAProReal(0),
5309     // f2HistMtLowQLamLamReal(0), 
5310     f2HistMtLowQLamProReal(0), 
5311     // f2HistMtLowQALamALamReal(0), 
5312     f2HistMtLowQALamAProReal(0),
5313     LamProReal(0),ALamAProReal(0),
5314     // f3HistLamLamQinvReal(0),               
5315     // f3HistALamALamQinvReal(0),f3HistLamLamMinvReal(0),               
5316     // f3HistLamProMinvReal(0),f3HistALamALamMinvReal(0),f3HistALamAProMinvReal(0),
5317     // f2HistBgLamBgLamMeanMinDistProReal(0),f2HistBgLamBgLamMeanMinDistPioReal(0),
5318     // f2HistBgLamProMeanMinDistProReal(0),f2HistBgALamBgALamMeanMinDistAProReal(0),
5319     // f2HistBgALamBgALamMeanMinDistPioReal(0),f2HistBgALamAProMeanMinDistAProReal(0),
5320     // f2HistSftBgLamBgLamMeanMinDistProReal(0),f2HistSftBgLamBgLamMeanMinDistPioReal(0),
5321     // f2HistSftBgLamProMeanMinDistProReal(0),f2HistSftBgALamBgALamMeanMinDistAProReal(0),
5322     // f2HistSftBgALamBgALamMeanMinDistPioReal(0),f2HistSftBgALamAProMeanMinDistAProReal(0),
5323     // f2HistSftIrocBgLamBgLamMeanMinDistProReal(0),f2HistSftIrocBgLamBgLamMeanMinDistPioReal(0),
5324     // f2HistSftIrocBgLamProMeanMinDistProReal(0),f2HistSftIrocBgALamBgALamMeanMinDistAProReal(0),
5325     // f2HistSftIrocBgALamBgALamMeanMinDistPioReal(0),f2HistSftIrocBgALamAProMeanMinDistAProReal(0),
5326     // f2HistSftOrocBgLamBgLamMeanMinDistProReal(0),f2HistSftOrocBgLamBgLamMeanMinDistPioReal(0),
5327     // f2HistSftOrocBgLamProMeanMinDistProReal(0),f2HistSftOrocBgALamBgALamMeanMinDistAProReal(0),
5328     // f2HistSftOrocBgALamBgALamMeanMinDistPioReal(0),f2HistSftOrocBgALamAProMeanMinDistAProReal(0),
5329     BgLamProReal(0),BgALamAProReal(0),
5330     // f3HistBgLamBgLamQinvReal(0),             
5331     // f3HistBgALamBgALamQinvReal(0),
5332     // f2HistLamLamMeanMinDistProMixed(0),f2HistLamLamMeanMinDistPioMixed(0),
5333     // f2HistLamProMeanMinDistProMixed(0),f2HistALamALamMeanMinDistAProMixed(0),   
5334     // f2HistALamALamMeanMinDistPioMixed(0),f2HistALamAProMeanMinDistAProMixed(0),
5335     // f2HistSftLamLamMeanMinDistProMixed(0),f2HistSftLamLamMeanMinDistPioMixed(0),
5336     // f2HistSftLamProMeanMinDistProMixed(0),f2HistSftALamALamMeanMinDistAProMixed(0),   
5337     // f2HistSftALamALamMeanMinDistPioMixed(0),f2HistSftALamAProMeanMinDistAProMixed(0),
5338     // f2HistSftIrocLamLamMeanMinDistProMixed(0),f2HistSftIrocLamLamMeanMinDistPioMixed(0),
5339     // f2HistSftIrocLamProMeanMinDistProMixed(0),f2HistSftIrocALamALamMeanMinDistAProMixed(0),   
5340     // f2HistSftIrocALamALamMeanMinDistPioMixed(0),f2HistSftIrocALamAProMeanMinDistAProMixed(0),
5341     // f2HistSftOrocLamLamMeanMinDistProMixed(0),f2HistSftOrocLamLamMeanMinDistPioMixed(0),
5342     // f2HistSftOrocLamProMeanMinDistProMixed(0),f2HistSftOrocALamALamMeanMinDistAProMixed(0),   
5343     // f2HistSftOrocALamALamMeanMinDistPioMixed(0),f2HistSftOrocALamAProMeanMinDistAProMixed(0),
5344     LamProMixed(0),ALamAProMixed(0),
5345     // f3HistLamLamQinvMixed(0),                
5346     // f3HistALamALamQinvMixed(0),f3HistLamLamMinvMixed(0),                
5347     // f3HistLamProMinvMixed(0),f3HistALamALamMinvMixed(0),f3HistALamAProMinvMixed(0),
5348     // f2HistBgLamBgLamMeanMinDistProMixed(0),f2HistBgLamBgLamMeanMinDistPioMixed(0),
5349     // f2HistBgLamProMeanMinDistProMixed(0),f2HistBgALamBgALamMeanMinDistAProMixed(0),
5350     // f2HistBgALamBgALamMeanMinDistPioMixed(0),f2HistBgALamAProMeanMinDistAProMixed(0),
5351     // f2HistSftBgLamBgLamMeanMinDistProMixed(0),f2HistSftBgLamBgLamMeanMinDistPioMixed(0),
5352     // f2HistSftBgLamProMeanMinDistProMixed(0),f2HistSftBgALamBgALamMeanMinDistAProMixed(0),
5353     // f2HistSftBgALamBgALamMeanMinDistPioMixed(0),f2HistSftBgALamAProMeanMinDistAProMixed(0),
5354     // f2HistSftIrocBgLamBgLamMeanMinDistProMixed(0),f2HistSftIrocBgLamBgLamMeanMinDistPioMixed(0),
5355     // f2HistSftIrocBgLamProMeanMinDistProMixed(0),f2HistSftIrocBgALamBgALamMeanMinDistAProMixed(0),
5356     // f2HistSftIrocBgALamBgALamMeanMinDistPioMixed(0),f2HistSftIrocBgALamAProMeanMinDistAProMixed(0),
5357     // f2HistSftOrocBgLamBgLamMeanMinDistProMixed(0),f2HistSftOrocBgLamBgLamMeanMinDistPioMixed(0),
5358     // f2HistSftOrocBgLamProMeanMinDistProMixed(0),f2HistSftOrocBgALamBgALamMeanMinDistAProMixed(0),
5359     // f2HistSftOrocBgALamBgALamMeanMinDistPioMixed(0),f2HistSftOrocBgALamAProMeanMinDistAProMixed(0),
5360     BgLamProMixed(0),BgALamAProMixed(0)
5361     // f3HistBgLamBgLamQinvMixed(0),             
5362     // f3HistBgALamBgALamQinvMixed(0)
5363
5364 {
5365   // Copy constructor
5366   printf("Copy constructor not implemented\n");
5367 }
5368 //________________________________________________________________________
5369 AliAnalysisTaskProtonLambda& AliAnalysisTaskProtonLambda::operator=(const AliAnalysisTaskProtonLambda& atpl)
5370 {
5371   if(this!=&atpl){
5372   // One operation with the atpl to get rid of the warning unused parameter
5373   fPrimaryVtxPosition[0]=atpl.fPrimaryVtxPosition[0];
5374   printf("Assignment operator not implemented\n");
5375   }
5376   return *this;
5377 }
5378 //________________________________________________________________________
5379 void AliAnalysisTaskProtonLambda::Terminate(Option_t *) 
5380 {
5381   // Draw result to the screen
5382   // Called once at the end of the query
5383 }
5384 //________________________________________________________________________
5385 //
5386 //
5387 //     Classes in the class AliAnalysisTaskProtonLambda
5388 //         FemtoBuffer, FemtoBufferEvent, FemtoBufferV0 and FemtoBufferTrack
5389 //
5390 //________________________________________________________________________
5391 //
5392 //                        FemtoBufferTrack
5393 //________________________________________________________________________
5394 AliAnalysisTaskProtonLambda::FemtoBufferTrack::FemtoBufferTrack():
5395   fID(65535)
5396 {
5397   // Standard constructor, initialize everything with values indicating 
5398   // a track that should not be used
5399   
5400   // No idea how to initialize the arrays nicely like the fID(65535)..
5401   for (UChar_t i=0;i<3;i++){
5402     fP[i]=-9999.;
5403     for (UChar_t j=0;j<9;j++){
5404       //      fXglobal[j][i]=-9999.;
5405       fXshifted[j][i]=-9999.;
5406     }
5407   }
5408 }
5409 //________________________________________________________________________
5410 AliAnalysisTaskProtonLambda::FemtoBufferTrack::FemtoBufferTrack(const AliAODTrack *track,const Float_t bfield,const Float_t priVtx[3]):
5411   fID(65535)  
5412 {
5413   // Constructor
5414
5415   // Use the function to have the code in one place
5416   Set(track,bfield,priVtx);
5417 }
5418 //________________________________________________________________________
5419 void AliAnalysisTaskProtonLambda::FemtoBufferTrack::GetGlobalPositionAtGlobalRadii(const AliAODTrack *track, const Float_t bfield){
5420   // Function not used, do dummy operations to get rid of warnings
5421   Float_t a=bfield;
5422   a=track->P();
5423   
5424   // // Gets the global position of the track at nine different radii in the TPC
5425   // // track is the track you want to propagate
5426   // // bfield is the magnetic field of your event
5427   // // globalPositionsAtRadii is the array of global positions in the radii and xyz
5428   
5429   // // We have two versions of the two track resolution plots in our proton-lambda task:
5430   // // a) with all events shifted to (0,0,0), b) without shift.
5431   // // For a) we should compare the tracks at shifted radii,
5432   // // for b) we should still use the global radii. This function here is for b).
5433
5434   // // Initialize the array to something indicating there was no propagation
5435   // for(Int_t i=0;i<9;i++){
5436   //   for(Int_t j=0;j<3;j++){
5437   //     fXglobal[i][j]=-9999.;
5438   //   }
5439   // }
5440
5441   //  // Make a copy of the track to not change parameters of the track
5442   // AliExternalTrackParam etp; etp.CopyFromVTrack(track);
5443   // //  printf("\nAfter CopyFromVTrack\n");
5444   // //  etp.Print();
5445  
5446   // // The global position of the the track
5447   // Double_t xyz[3]={-9999.,-9999.,-9999.};  
5448
5449   // // Counter for which radius we want
5450   // Int_t iR=0; 
5451   // // The radii at which we get the global positions
5452   // // IROC (OROC) from 84.1 cm to 132.1 cm (134.6 cm to 246.6 cm)
5453   // // Compare squared radii for faster code
5454   // Float_t RSquaredWanted[9]={85.*85.,105.*105.,125.*125.,145.*145.,165.*165.,
5455   //                         185.*185.,205.*205.,225.*225.,245.*245.}; 
5456   // // The global radius we are at, squared. Compare squared radii for faster code
5457   // Float_t globalRadiusSquared=0;
5458
5459   // // Propagation is done in local x of the track
5460   // for (Float_t x = 58.;x<247.;x+=1.){
5461   //   // Starts at 83 / Sqrt(2) and goes outwards. 85/Sqrt(2) is the smallest local x
5462   //   // for global radius 85 cm. x = 245 is the outer radial limit of the TPC when
5463   //   // the track is straight, i.e. has inifinite pt and doesn't get bent. 
5464   //   // If the track's momentum is smaller than infinite, it will develop a y-component,
5465   //   // which adds to the global radius
5466
5467   //   // Stop if the propagation was not succesful. This can happen for low pt tracks
5468   //   // that don't reach outer radii
5469   //   if(!etp.PropagateTo(x,bfield))break;
5470   //   etp.GetXYZ(xyz); // GetXYZ returns global coordinates
5471
5472   //   // No shifting for global radii
5473   //   globalRadiusSquared = (xyz[0])*(xyz[0])
5474   //                       + (xyz[1])*(xyz[1]);
5475
5476   //   // Roughly reached the radius we want
5477   //   if(globalRadiusSquared > RSquaredWanted[iR]){
5478       
5479   //     // Bigger loop has bad precision, we're nearly one centimeter too far, 
5480   //     // go back in small steps.
5481   //     while (globalRadiusSquared>RSquaredWanted[iR]){
5482   //    x-=.1;
5483   //    //      printf("propagating to x %5.2f\n",x);
5484   //    if(!etp.PropagateTo(x,bfield))break;
5485   //    etp.GetXYZ(xyz); // GetXYZ returns global coordinates
5486
5487   //    // No shifting for global radii
5488   //    globalRadiusSquared = (xyz[0])*(xyz[0])
5489   //                        + (xyz[1])*(xyz[1]);
5490   //     }
5491   //     //      printf("At Radius:%05.2f (local x %5.2f). Setting position to x %4.1f y %4.1f z %4.1f\n",TMath::Sqrt(globalRadiusSquared),x,xyz[0],xyz[1],xyz[2]);
5492   //     fXglobal[iR][0]=xyz[0];
5493   //     fXglobal[iR][1]=xyz[1];
5494   //     fXglobal[iR][2]=xyz[2];
5495   //     // Indicate we want the next radius    
5496   //     iR+=1;
5497   //   }
5498   //   if(iR>=8){
5499   //     // TPC edge reached
5500   //     return;
5501   //   }
5502   // }
5503 }
5504 //________________________________________________________________________
5505 void AliAnalysisTaskProtonLambda::FemtoBufferTrack::GetShiftedPositionAtShiftedRadii(const AliAODTrack *track, const Float_t bfield, const Float_t priVtx[3]){
5506   // Gets the global position of the track at nine different radii in the TPC
5507   // track is the track you want to propagate
5508   // bfield is the magnetic field of your event
5509   // globalPositionsAtRadii is the array of global positions in the radii and xyz
5510   
5511   // Initialize the array to something indicating there was no propagation
5512   for(Int_t i=0;i<9;i++){
5513     for(Int_t j=0;j<3;j++){
5514       fXshifted[i][j]=-9999.;
5515     }
5516   }
5517
5518    // Make a copy of the track to not change parameters of the track
5519   AliExternalTrackParam etp; etp.CopyFromVTrack(track);
5520   //  printf("\nAfter CopyFromVTrack\n");
5521   //  etp.Print();
5522  
5523   // The global position of the the track
5524   Double_t xyz[3]={-9999.,-9999.,-9999.};  
5525
5526   // Counter for which radius we want
5527   Int_t iR=0; 
5528   // The radii at which we get the global positions
5529   // IROC (OROC) from 84.1 cm to 132.1 cm (134.6 cm to 246.6 cm)
5530   // Compare squared radii for faster code
5531   Float_t RSquaredWanted[9]={85.*85.,105.*105.,125.*125.,145.*145.,165.*165.,
5532                              185.*185.,205.*205.,225.*225.,245.*245.}; 
5533   // The shifted radius we are at, squared. Compare squared radii for faster code
5534   Float_t shiftedRadiusSquared=0;
5535
5536   // Propagation is done in local x of the track
5537   for (Float_t x = 58.;x<247.;x+=1.){
5538     // Starts at 83 / Sqrt(2) and goes outwards. 85/Sqrt(2) is the smallest local x
5539     // for global radius 85 cm. x = 245 is the outer radial limit of the TPC when
5540     // the track is straight, i.e. has inifinite pt and doesn't get bent. 
5541     // If the track's momentum is smaller than infinite, it will develop a y-component,
5542     // which adds to the global radius
5543
5544     // Stop if the propagation was not succesful. This can happen for low pt tracks
5545     // that don't reach outer radii
5546     if(!etp.PropagateTo(x,bfield))break;
5547     etp.GetXYZ(xyz); // GetXYZ returns global coordinates
5548
5549     // Without shifting the primary vertex to (0.,0.,0.) the next line would just be
5550     // WRONG: globalRadiusSquared = xyz[0]*xyz[0]+xyz[1]*xyz[1];
5551     // but as we shift the primary vertex we want to compare positions at shifted radii.
5552     // I can't draw in ASCII but please take a piece of paper and just visualize it once.
5553
5554     // Changing plus to minus on July10th2012
5555     shiftedRadiusSquared = (xyz[0]-priVtx[0])*(xyz[0]-priVtx[0])
5556                          + (xyz[1]-priVtx[1])*(xyz[1]-priVtx[1]);
5557
5558     // Roughly reached the radius we want
5559     if(shiftedRadiusSquared > RSquaredWanted[iR]){
5560       
5561       // Bigger loop has bad precision, we're nearly one centimeter too far, 
5562       // go back in small steps.
5563       while (shiftedRadiusSquared>RSquaredWanted[iR]){
5564         x-=.1;
5565         //      printf("propagating to x %5.2f\n",x);
5566         if(!etp.PropagateTo(x,bfield))break;
5567         etp.GetXYZ(xyz); // GetXYZ returns global coordinates
5568         // Added the shifting also here on July11th2012
5569         shiftedRadiusSquared = (xyz[0]-priVtx[0])*(xyz[0]-priVtx[0])
5570                              + (xyz[1]-priVtx[1])*(xyz[1]-priVtx[1]);
5571       }
5572       //      printf("At Radius:%05.2f (local x %5.2f). Setting position to x %4.1f y %4.1f z %4.1f\n",TMath::Sqrt(globalRadiusSquared),x,xyz[0],xyz[1],xyz[2]);
5573       fXshifted[iR][0]=xyz[0]-priVtx[0];
5574       fXshifted[iR][1]=xyz[1]-priVtx[1];
5575       fXshifted[iR][2]=xyz[2]-priVtx[2];
5576       // Indicate we want the next radius    
5577       iR+=1;
5578     }
5579     if(iR>=8){
5580       // TPC edge reached
5581       return;
5582     }
5583   }
5584 }
5585 //________________________________________________________________________
5586 void AliAnalysisTaskProtonLambda::FemtoBufferTrack::Set(const AliAODTrack *track,const Float_t bfield,const Double_t priVtx[3]){
5587   // Overloaded function
5588   Float_t priVtxPos[3]={static_cast<Float_t>(priVtx[0]),static_cast<Float_t>(priVtx[1]),static_cast<Float_t>(priVtx[2])};
5589   Set(track,bfield,priVtxPos);
5590 }
5591 //________________________________________________________________________
5592 void AliAnalysisTaskProtonLambda::FemtoBufferTrack::Set(const AliAODTrack *track,const Float_t bfield,const Float_t priVtx[3]){
5593   // Set the properties of this to the AliAODtrack
5594   //
5595   //    UShort_t fID;               //! Unique track id (->AliAODTrack.h), UShort_t goes to 65000
5596   //    Double_t fP[3];             //! Momentum of track
5597   //    Float_t  fXglobal[9][3];    //! Global positions at different global radii
5598   //    Float_t  fXshifted[9][3];   //! Shifted positions at different shifted radii
5599
5600
5601   // Set the ID, a good ID also indicates to use the track
5602   if(track->GetID() >=0){
5603     // global tracks, i.e. v0 daughters
5604     fID = track->GetID();
5605   }
5606   else {
5607     // e.g. tpc only tracks, i.e. primary protons
5608     fID = -track->GetID()-1;
5609
5610   }
5611   // Set the momentum
5612   track->PxPyPz(fP);  
5613   //  GetGlobalPositionAtGlobalRadii(track,bfield);
5614   GetShiftedPositionAtShiftedRadii(track,bfield,priVtx);
5615
5616 }
5617 //________________________________________________________________________
5618 AliAnalysisTaskProtonLambda::FemtoBufferTrack::FemtoBufferTrack(const FemtoBufferTrack& fbt):
5619   fID(fbt.fID)
5620  {
5621   // Copy constructor
5622
5623   for (UChar_t i=0;i<3;i++){
5624     fP[i]=fbt.fP[i];
5625     for (UChar_t j=0;j<9;j++){
5626       //      fXglobal[j][i]=fbt.fXglobal[j][i];
5627       fXshifted[j][i]=fbt.fXshifted[j][i];
5628     }
5629   }
5630 }
5631 //________________________________________________________________________
5632 AliAnalysisTaskProtonLambda::FemtoBufferTrack& AliAnalysisTaskProtonLambda::FemtoBufferTrack::operator=(const FemtoBufferTrack& fbt){
5633   // Assignment operator, from wikipedia :)
5634   
5635   // Protect against self-assignment
5636   if(this != &fbt){
5637     fID = fbt.fID;
5638     for (UChar_t i=0;i<3;i++){
5639       fP[i]=fbt.fP[i];
5640       for (UChar_t j=0;j<9;j++){
5641         //      fXglobal[j][i]=fbt.fXglobal[j][i];
5642         fXshifted[j][i]=fbt.fXshifted[j][i];
5643       }
5644     }
5645   }
5646   // By convention, always return *this (Could it be the convention is called c++?)
5647   return *this;
5648 }
5649 //________________________________________________________________________
5650 //
5651 //                        FemtoBufferV0
5652 //________________________________________________________________________
5653 AliAnalysisTaskProtonLambda::FemtoBufferV0::FemtoBufferV0():
5654   fCosPoint(-9999.),
5655   fPosDaughter(),
5656   fNegDaughter()
5657 {
5658   // Dummy constructor, set everything so it
5659   // indicates a V0 which should not be used
5660   fP[0]=-9999.;
5661   fP[1]=-9999.;
5662   fP[2]=-9999.;
5663   // C++11 provides initializer lists, it should work like
5664   //class C
5665   //{
5666   //int x[4];
5667   //public:
5668   //C(): x{0,1,2,3} {}
5669   //};
5670   // and http://clang.llvm.org/cxx_status.html says, they have it in clang 3.1,
5671   // but it doesn't seem to work! :/
5672
5673 }
5674 //________________________________________________________________________
5675 AliAnalysisTaskProtonLambda::FemtoBufferV0::FemtoBufferV0(const AliAODv0 *v0, const AliAODTrack *posDaughter, const AliAODTrack *negDaughter, const Double_t bfield, Double_t priVtxPos[3]):
5676   fCosPoint(-9999.),
5677   fPosDaughter(),
5678   fNegDaughter()
5679 {
5680   // Constructor, set the properties of this to these of the AliAODv0
5681
5682   // Use Set function to keep code in one place. Only constant data member
5683   // would require the FemtoBuff() : fbla(), fblup() {} method
5684   Set(v0,posDaughter,negDaughter,bfield,priVtxPos);
5685 }
5686 //________________________________________________________________________
5687 void AliAnalysisTaskProtonLambda::FemtoBufferV0::Set(const AliAODv0 *v0, const AliAODTrack *posDaughter, const AliAODTrack *negDaughter, const Double_t bfield, Double_t priVtxPos[3])
5688 {
5689   // Set the properties of this to these of the AliAODv0
5690   fCosPoint=v0->CosPointingAngle(priVtxPos);
5691   v0->PxPyPz(fP);
5692   // printf("Set px %3.2f, py %3.2f, pz %3.2f\n"
5693   //     ,fP[0],fP[1],fP[2]
5694   //     );
5695   // The daughters
5696   fPosDaughter.Set(posDaughter,bfield,priVtxPos);
5697   fNegDaughter.Set(negDaughter,bfield,priVtxPos);
5698 }
5699 //________________________________________________________________________
5700 AliAnalysisTaskProtonLambda::FemtoBufferV0::FemtoBufferV0(const FemtoBufferV0 &fbv):
5701   fCosPoint(fbv.fCosPoint),
5702   fPosDaughter(fbv.fPosDaughter),
5703   fNegDaughter(fbv.fNegDaughter)
5704   //,fP{fbv.fP[0],fbv.fP[1],fbv.fP[2]} // C++11
5705 {
5706   // Copy constructor
5707   fP[0] = fbv.fP[0]; // C++03
5708   fP[1] = fbv.fP[1];
5709   fP[2] = fbv.fP[2];
5710 }
5711 //________________________________________________________________________
5712 AliAnalysisTaskProtonLambda::FemtoBufferV0& AliAnalysisTaskProtonLambda::FemtoBufferV0::operator=(const FemtoBufferV0 &fbv){
5713   // Assignment operator
5714
5715   // Protect against self-assignment
5716   if(this != &fbv){
5717     fCosPoint=fbv.fCosPoint;
5718     fP[0]=fbv.fP[0];
5719     fP[1]=fbv.fP[1];
5720     fP[2]=fbv.fP[2];
5721     fPosDaughter=fbv.fPosDaughter;
5722     fNegDaughter=fbv.fNegDaughter;
5723   }
5724   return *this;
5725 }
5726 //________________________________________________________________________
5727 //
5728 //                        FemtoBufferEvent
5729 //________________________________________________________________________
5730 AliAnalysisTaskProtonLambda::FemtoBufferEvent::FemtoBufferEvent():
5731   fPriTrackLim(0),fV0Lim(0)
5732   ,fProTracks(0),fAProTracks(0)
5733   ,fLamTracks(0),fALamTracks(0)
5734   ,fBgLamTracks(0),fBgALamTracks(0)
5735   ,fNProTracks(0),fNAProTracks(0),fNLamTracks(0),fNALamTracks(0)
5736   ,fNBgLamTracks(0),fNBgALamTracks(0)
5737   ,fBfield(-9999.)
5738 {
5739   // Standard constructor, all pointer to zero
5740   fPriVtxPos[0]=-9999.;
5741   fPriVtxPos[1]=-9999.;
5742   fPriVtxPos[2]=-9999.;
5743
5744   printf("This constructor has zero size in the arrays!\n");
5745 }
5746 //________________________________________________________________________
5747 AliAnalysisTaskProtonLambda::FemtoBufferEvent::FemtoBufferEvent(const UShort_t priTrackBuff,const UShort_t V0Buff,const Double_t bfield,const Double_t priVtxPos[3]):
5748   fPriTrackLim(priTrackBuff),fV0Lim(V0Buff)
5749   ,fProTracks(new FemtoBufferTrack[fPriTrackLim])
5750   ,fAProTracks(new FemtoBufferTrack[fPriTrackLim])
5751   ,fLamTracks (new FemtoBufferV0[fV0Lim])
5752   ,fALamTracks(new FemtoBufferV0[fV0Lim])
5753   ,fBgLamTracks(new FemtoBufferV0[fV0Lim])
5754   ,fBgALamTracks(new FemtoBufferV0[fV0Lim])
5755   ,fNProTracks(0),fNAProTracks(0),fNLamTracks(0),fNALamTracks(0)
5756   ,fNBgLamTracks(0),fNBgALamTracks(0)
5757   ,fBfield(-bfield)
5758   //  ,fPriVtxPos{priVtxPos[0],priVtxPos[1],priVtxPos[2]} // This is C++11
5759 {
5760   // Constructor.
5761   fPriVtxPos[0] = priVtxPos[0]; // This is some old C++
5762   fPriVtxPos[1] = priVtxPos[1];
5763   fPriVtxPos[2] = priVtxPos[2];
5764 }
5765 //________________________________________________________________________
5766 AliAnalysisTaskProtonLambda::FemtoBufferEvent::FemtoBufferEvent(const UShort_t priTrackBuff,const UShort_t V0Buff):
5767   fPriTrackLim(priTrackBuff),fV0Lim(V0Buff)
5768   ,fProTracks(new FemtoBufferTrack[fPriTrackLim])
5769   ,fAProTracks(new FemtoBufferTrack[fPriTrackLim])
5770   ,fLamTracks (new FemtoBufferV0[fV0Lim])
5771   ,fALamTracks(new FemtoBufferV0[fV0Lim])
5772   ,fBgLamTracks(new FemtoBufferV0[fV0Lim])
5773   ,fBgALamTracks(new FemtoBufferV0[fV0Lim])
5774   ,fNProTracks(0),fNAProTracks(0),fNLamTracks(0),fNALamTracks(0)
5775   ,fNBgLamTracks(0),fNBgALamTracks(0)
5776   ,fBfield(-9999.)
5777   //  ,fPriVtxPos{-9999.,-9999.,-9999.} // This is C++11
5778 {  
5779   // Constructor. fBfield and fPriVtxPos not needed yet, can be set later.
5780   fPriVtxPos[0] = -9999.; // This is C++03
5781   fPriVtxPos[1] = -9999.;
5782   fPriVtxPos[2] = -9999.;
5783
5784   //  printf("constructed eventwith NBgLam: %u\n",fNBgLamTracks);
5785 }
5786 //________________________________________________________________________
5787 AliAnalysisTaskProtonLambda::FemtoBufferEvent::FemtoBufferEvent(const FemtoBufferEvent &fbe):
5788   fPriTrackLim(fbe.GetPriTrackLim())
5789   ,fV0Lim(fbe.GetV0Lim())
5790   ,fProTracks(new FemtoBufferTrack[fPriTrackLim])
5791   ,fAProTracks(new FemtoBufferTrack[fPriTrackLim])
5792   ,fLamTracks (new FemtoBufferV0[fV0Lim])
5793   ,fALamTracks(new FemtoBufferV0[fV0Lim])
5794   ,fBgLamTracks(new FemtoBufferV0[fV0Lim])
5795   ,fBgALamTracks(new FemtoBufferV0[fV0Lim])
5796   ,fNProTracks(fbe.GetNPro()),fNAProTracks(fbe.GetNAPro())
5797   ,fNLamTracks(fbe.GetNLam()),fNALamTracks(fbe.GetNALam())
5798   ,fNBgLamTracks(fbe.GetNBgLam()),fNBgALamTracks(fbe.GetNBgALam())
5799   ,fBfield(fbe.GetBfield())
5800 {
5801   // Copy constructor
5802   fbe.GetVtxPos(fPriVtxPos);
5803   // Avoid to much creation and deletion of objects
5804   UShort_t i;
5805   // Copy the primary tracks
5806   for (i=0;i<fPriTrackLim;i++){
5807     fProTracks[i]=fbe.fProTracks[i];
5808     fAProTracks[i]=fbe.fAProTracks[i];
5809   }
5810   // Copy the V0s
5811   for (i=0;i<fV0Lim;i++){
5812     fLamTracks[i]=fbe.fLamTracks[i];
5813     fALamTracks[i]=fbe.fALamTracks[i];
5814     fBgLamTracks[i]=fbe.fBgLamTracks[i];
5815     fBgALamTracks[i]=fbe.fBgALamTracks[i];
5816   }
5817 }
5818 //________________________________________________________________________
5819 AliAnalysisTaskProtonLambda::FemtoBufferEvent& AliAnalysisTaskProtonLambda::FemtoBufferEvent::operator=(const FemtoBufferEvent &fbe){
5820   // Assignment operator
5821
5822   // Protect against self-assignment
5823   if(this!=&fbe){
5824     // Well, we use arrays of a constant size to avoid
5825     // excessive memory allocation and won't give this up.
5826     // So we'll only copy as much as fits on the left side
5827     // from the right side.
5828     // DON'T COPY THE ARRAY SIZES fV0Lim AND fPriTrackLim !!!
5829     if(fPriTrackLim < fbe.GetPriTrackLim() 
5830        || fV0Lim < fbe.GetV0Lim()){
5831       // AliWarning(Form("Trying to assign too big event (buffer %d/%d) to"
5832       //                    " this (buffer %d/%d). Only partially copying.",
5833       //                    fbe.GetPriTrackLim(),fbe.GetV0Lim(),
5834       //                    fPriTrackLim,fV0Lim));
5835       printf("Trying to assign too big event (buffer %d/%d) to"
5836                     " this (buffer %d/%d). Only partially copying.\n",
5837              fbe.GetPriTrackLim(),fbe.GetV0Lim(),
5838              fPriTrackLim,fV0Lim);
5839     }
5840     // Always start with the easy stuff :)
5841     fbe.GetVtxPos(fPriVtxPos);
5842     fBfield = fbe.GetBfield();
5843     // Number of tracks is minimum of array size of 'this'
5844     // and the number of tracks from the right side
5845     fNProTracks = TMath::Min(fPriTrackLim,fbe.GetNPro());
5846     fNAProTracks = TMath::Min(fPriTrackLim,fbe.GetNAPro());
5847     fNLamTracks = TMath::Min(fV0Lim,fbe.GetNLam());
5848     fNALamTracks = TMath::Min(fV0Lim,fbe.GetNALam());
5849     fNBgLamTracks = TMath::Min(fV0Lim,fbe.GetNBgLam());
5850     fNBgALamTracks = TMath::Min(fV0Lim,fbe.GetNBgALam());
5851     
5852     // Avoid creation and deletion of 'i' for every loop
5853     UShort_t i;
5854     // Copy primary tracks. No need to set a 'bad track'
5855     // flag for the entries above GetNPro() (...) as
5856     // above everything is bad by definition.
5857     // Protons
5858     for (i=0;i<GetNPro();i++)
5859       fProTracks[i]=fbe.fProTracks[i];
5860     // Anti-protons
5861     for (i=0;i<GetNAPro();i++)
5862       fAProTracks[i]=fbe.fAProTracks[i];
5863     // Copy the V0s 
5864     // Lambdas
5865     for (i=0;i<GetNLam();i++){
5866       fLamTracks[i]=fbe.fLamTracks[i];
5867     }
5868     // Anti-lambdas
5869     for (i=0;i<GetNALam();i++){
5870       fALamTracks[i]=fbe.fALamTracks[i];
5871     }
5872     // Background lambdas
5873     for (i=0;i<GetNBgLam();i++){
5874       fBgLamTracks[i]=fbe.fBgLamTracks[i];
5875     }
5876     // Background anti-lambdas
5877     for (i=0;i<GetNBgALam();i++){
5878       fBgALamTracks[i]=fbe.fBgALamTracks[i];
5879     }  
5880   }
5881   return *this;
5882 }
5883 //________________________________________________________________________
5884 AliAnalysisTaskProtonLambda::FemtoBufferEvent::~FemtoBufferEvent(){
5885   // Destructor
5886
5887   // Delete the arrays of tracks,
5888   // note the [] with the delete
5889   if(fProTracks){
5890     delete[] fProTracks;
5891     fProTracks=0;
5892   }
5893   if(fAProTracks){
5894     delete[] fAProTracks;
5895     fAProTracks=0;
5896   }
5897   if(fLamTracks){
5898     delete[] fLamTracks;
5899     fLamTracks=0;
5900   }
5901   if(fALamTracks){
5902     delete[] fALamTracks;
5903     fALamTracks=0;
5904   }
5905   if(fBgLamTracks){
5906     delete[] fBgLamTracks;
5907     fBgLamTracks=0;
5908   }
5909   if(fBgALamTracks){
5910     delete[] fBgALamTracks;
5911     fBgALamTracks=0;
5912   }
5913 }
5914 //________________________________________________________________________
5915 void AliAnalysisTaskProtonLambda::FemtoBufferEvent::Reset(const Double_t bfield, const Double_t priVtxPos[3]){
5916   // Reset the old event, i.e., make clear 'here is no info'
5917   // by setting the 'number of stored ...' to zero
5918   fNProTracks=0;
5919   fNAProTracks=0;
5920   fNLamTracks=0;
5921   fNALamTracks=0;
5922   fNBgLamTracks=0;
5923   fNBgALamTracks=0;
5924   
5925   // And set the new event properties 
5926   fBfield = bfield;
5927   fPriVtxPos[0]=priVtxPos[0];
5928   fPriVtxPos[1]=priVtxPos[1];
5929   fPriVtxPos[2]=priVtxPos[2];
5930 }
5931 //________________________________________________________________________
5932 void AliAnalysisTaskProtonLambda::FemtoBufferEvent::AddPro(const AliAODTrack *track){
5933   // Add a proton to this event
5934
5935   // Check whether there is still space in the array
5936   if(fNProTracks > fPriTrackLim-1){
5937     // AliWarning(Form("Cannot add proton, array size (%d) too small"
5938     //              ,fPriTrackLim));
5939     printf("Cannot add proton, array size (%d) too small\n"
5940                     ,fPriTrackLim);
5941     return;
5942   }
5943   // Add the V0 at the end of the array
5944   fProTracks[fNProTracks].Set(track,fBfield,fPriVtxPos);
5945   fNProTracks++;
5946   //  printf("Added proton %d/%d\n",fNProTracks,fPriTrackLim);
5947
5948 }  
5949 //________________________________________________________________________
5950 void AliAnalysisTaskProtonLambda::FemtoBufferEvent::AddAPro(const AliAODTrack *track){
5951   // Add a anti-proton to this event
5952
5953   // Check whether there is still space in the array
5954   if(fNAProTracks > fPriTrackLim-1){
5955     // AliWarning(Form("Cannot add anti-proton, array size (%d) too small"
5956     //              ,fPriTrackLim));
5957     printf("Cannot add anti-proton, array size (%d) too small\n"
5958                     ,fPriTrackLim);
5959     return;
5960   }
5961   // Add the V0 at the end of the array
5962   fAProTracks[fNAProTracks].Set(track,fBfield,fPriVtxPos);
5963   fNAProTracks++;
5964 }  
5965 //________________________________________________________________________
5966 void AliAnalysisTaskProtonLambda::FemtoBufferEvent::AddLam(const AliAODv0 *v0,const AliAODTrack *posDaughter,const AliAODTrack *negDaughter){
5967   // Adds a lambda with it's daughters to the event
5968
5969   // Check whether there is still space in the array
5970   if(fNLamTracks > fV0Lim-1){
5971     // AliWarning(Form("Cannot add lambda, array size (%d) too small"
5972     //              ,fV0Lim));
5973     printf("Cannot add lambda, array size (%d) too small"
5974                     ,fV0Lim);
5975     return;
5976   }
5977  
5978   // Add the V0 at the end of the array
5979   fLamTracks[fNLamTracks].Set(v0,posDaughter,negDaughter,
5980                               fBfield,fPriVtxPos);
5981   fNLamTracks++;
5982 }
5983 //________________________________________________________________________
5984 void AliAnalysisTaskProtonLambda::FemtoBufferEvent::AddALam(const AliAODv0 *v0,const AliAODTrack *posDaughter,const AliAODTrack *negDaughter){
5985   // Adds a lambda with it's daughters to the event
5986
5987   // Check whether there is still space in the array
5988   if(fNALamTracks > fV0Lim-1){
5989     // AliWarning(Form("Cannot add anti-lambda, array size (%d) too small"
5990     //              ,fV0Lim));
5991     printf("Cannot add anti-lambda, array size (%d) too small\n"
5992                     ,fV0Lim);
5993     return;
5994   }
5995  
5996   // Add the V0 at the end of the array
5997   fALamTracks[fNALamTracks].Set(v0,posDaughter,negDaughter,
5998                                 fBfield,fPriVtxPos);
5999   fNALamTracks++;
6000 }
6001 //________________________________________________________________________
6002 void AliAnalysisTaskProtonLambda::FemtoBufferEvent::AddBgLam(const AliAODv0 *v0,const AliAODTrack *posDaughter,const AliAODTrack *negDaughter){
6003   // Adds a lambda with it's daughters to the event
6004
6005   // Check whether there is still space in the array
6006   if(fNBgLamTracks > fV0Lim-1){
6007     // AliWarning(Form("Cannot add background lambda,"
6008     //              " array size (%d) too small"
6009     //              ,fV0Lim));
6010     // printf("Cannot add background lambda,"
6011     //     "already stored %d" 
6012     //     " array size (%d) too small\n"
6013     //     ,fNBgLamTracks
6014     //     ,fV0Lim);
6015     return;
6016   }
6017  
6018   // Add the V0 at the end of the array
6019   fBgLamTracks[fNALamTracks].Set(v0,posDaughter,negDaughter,
6020                                 fBfield,fPriVtxPos);
6021   fNBgLamTracks++;
6022 }
6023 //________________________________________________________________________
6024 void AliAnalysisTaskProtonLambda::FemtoBufferEvent::AddBgALam(const AliAODv0 *v0,const AliAODTrack *posDaughter,const AliAODTrack *negDaughter){
6025   // Adds a lambda with it's daughters to the event
6026
6027   // Check whether there is still space in the array
6028   if(fNBgALamTracks > fV0Lim-1){
6029     // AliWarning(Form("Cannot add background anti-lambda,"
6030     //              " array size (%d) too small"
6031     //              ,fV0Lim));
6032     //    printf("Cannot add background anti-lambda,"
6033     //              " array size (%d) too small\n"
6034     //              ,fV0Lim);
6035     return;
6036   }
6037  
6038   // Add the V0 at the end of the array
6039   fBgALamTracks[fNALamTracks].Set(v0,posDaughter,negDaughter,
6040                                 fBfield,fPriVtxPos);
6041   fNBgALamTracks++;
6042 }
6043 //________________________________________________________________________
6044 //
6045 //                        FemtoBuffer
6046 //________________________________________________________________________
6047 AliAnalysisTaskProtonLambda::FemtoBuffer::FemtoBuffer() :
6048   fkZvertexBins(0),
6049   fkCentBins(0),
6050   fkMixBuffSize(0),
6051   fkPriTrackLim(0),
6052   fkV0Lim(0),
6053   fZvertexAxis(0),
6054   fCentAxis(0),
6055   fCurEvt(0),
6056   fEC(0)
6057 {
6058   // Dummy constructor, create arrays with zero size
6059   // Note that some data member are constant, you
6060   // won't be able to create the FemtoBuffer first with this
6061   // constructor and then set the appropiate size.
6062   
6063 }
6064 //________________________________________________________________________
6065 AliAnalysisTaskProtonLambda::FemtoBuffer::FemtoBuffer(const UChar_t ZvertexBins,const UChar_t CentBins,const UChar_t MixBuff,const UShort_t PriTrackLim,const UShort_t V0Lim, const Float_t AbsZvertexCut,const Float_t CentCut) :
6066   fkZvertexBins(ZvertexBins),
6067   fkCentBins(CentBins),
6068   fkMixBuffSize(MixBuff),
6069   fkPriTrackLim(PriTrackLim),
6070   fkV0Lim(V0Lim),
6071   fZvertexAxis(new TAxis(fkZvertexBins,-AbsZvertexCut,AbsZvertexCut)),
6072   fCentAxis(new TAxis (fkCentBins,0.0,CentCut)),
6073   fCurEvt(new FemtoBufferEvent *[fkMixBuffSize]),
6074   fEC(new FemtoBufferEvent ***[fkZvertexBins])
6075 {
6076   // Constructor, creates at once all events with all tracks
6077   //  printf ("Creating with pritracklim %d and v0lim %d\n",fkPriTrackLim,fkV0Lim);
6078
6079   // Create the array step by step
6080   // Bins in z of the primary vertex position. Do this as
6081   // the detector looks different from a different z coordinate
6082   for (UChar_t iZBin=0;iZBin<fkZvertexBins;iZBin++){
6083     fEC[iZBin] = new FemtoBufferEvent **[fkCentBins];
6084     // Bins in centrality
6085     for (UChar_t iCentBin=0;iCentBin<fkCentBins;iCentBin++){
6086       fEC[iZBin][iCentBin] = new FemtoBufferEvent *[fkMixBuffSize];
6087       // The number of events to keep for one mixing class
6088       for(UChar_t iMixBuff=0;iMixBuff<fkMixBuffSize;iMixBuff++){
6089         // Create an event to hold the info for mixing
6090         fEC[iZBin][iCentBin][iMixBuff] = new FemtoBufferEvent(fkPriTrackLim,fkV0Lim);
6091       }
6092     }
6093   }
6094 }
6095 //________________________________________________________________________
6096 AliAnalysisTaskProtonLambda::FemtoBuffer::FemtoBuffer(const AliAnalysisTaskProtonLambda::FemtoBuffer &fb) :
6097   fkZvertexBins(fb.fkZvertexBins),
6098   fkCentBins(fb.fkCentBins),
6099   fkMixBuffSize(fb.fkMixBuffSize),
6100   fkPriTrackLim(fb.fkPriTrackLim),
6101   fkV0Lim(fb.fkV0Lim),
6102   fZvertexAxis(new TAxis(*(fb.fZvertexAxis))),
6103   fCentAxis(new TAxis (*(fb.fCentAxis))),
6104   fCurEvt(new FemtoBufferEvent *[fkMixBuffSize]),
6105   fEC(new FemtoBufferEvent ***[fkZvertexBins])
6106 {
6107   // Copy constructor. Linux complains not having this and 
6108   // compiling this task with aliroot
6109
6110   printf("FemtoBuffer ctor not tested yet, be cautious\n");
6111   
6112   // Create the array step by step
6113   // Bins in z of the primary vertex position. Do this as
6114   // the detector looks different from a different z coordinate
6115   for (UChar_t iZBin=0;iZBin<fkZvertexBins;iZBin++){
6116     fEC[iZBin] = new FemtoBufferEvent **[fkCentBins];
6117     // Bins in centrality
6118     for (UChar_t iCentBin=0;iCentBin<fkCentBins;iCentBin++){
6119       fEC[iZBin][iCentBin] = new FemtoBufferEvent *[fkMixBuffSize];
6120       // The number of events to keep for one mixing class
6121       for(UChar_t iMixBuff=0;iMixBuff<fkMixBuffSize;iMixBuff++){
6122         // Create an event to hold the info for mixing
6123         fEC[iZBin][iCentBin][iMixBuff] = new FemtoBufferEvent(*(fb.fEC[iZBin][iCentBin][iMixBuff]));
6124       }
6125     }
6126   }
6127 }
6128 //________________________________________________________________________
6129 AliAnalysisTaskProtonLambda::FemtoBuffer& AliAnalysisTaskProtonLambda::FemtoBuffer::operator=(const AliAnalysisTaskProtonLambda::FemtoBuffer& fb){
6130   //Assignment operator
6131   if(this!=&fb){
6132     printf("FemtoBuffer assignment operator not implemented\n");
6133   }
6134   return *this;
6135   
6136 }
6137 //________________________________________________________________________
6138 AliAnalysisTaskProtonLambda::FemtoBuffer::~FemtoBuffer(){
6139   // Destructor
6140   // The axes to fin the correct bins
6141   if(fZvertexAxis){
6142     delete fZvertexAxis;
6143     fZvertexAxis=0;
6144   }
6145   if(fCentAxis){
6146     delete fCentAxis;
6147     fCentAxis=0;
6148   }
6149   // fCurEvt is an array of pointer
6150   if(fCurEvt){
6151     delete[] fCurEvt;
6152     fCurEvt=0;
6153   }
6154   // Delete all the events and the pointer to them
6155   for (UChar_t iZBin=0;iZBin<fkZvertexBins;iZBin++){
6156     for (UChar_t iCentBin=0;iCentBin<fkCentBins;iCentBin++){
6157       for(UChar_t iMixBuff=0;iMixBuff<fkMixBuffSize;iMixBuff++){
6158         if(fEC[iZBin][iCentBin][iMixBuff]){
6159           delete fEC[iZBin][iCentBin][iMixBuff];
6160           fEC[iZBin][iCentBin][iMixBuff]=0;
6161         }
6162       }
6163       if(fEC[iZBin][iCentBin]){
6164         delete fEC[iZBin][iCentBin];
6165         fEC[iZBin][iCentBin]=0;
6166       }
6167     }
6168     if(fEC[iZBin]){
6169       delete fEC[iZBin];
6170       fEC[iZBin]=0;
6171     }
6172   }
6173   if(fEC){
6174     delete fEC;
6175     fEC=0;
6176   }
6177 }
6178 //________________________________________________________________________
6179 void AliAnalysisTaskProtonLambda::FemtoBuffer::ShiftAndAdd(AliAODEvent *evt){
6180   // Shift the events in the appropiate centrality / zvertex bin and set the 
6181   // current event pointer correctly
6182   Double_t priVtxPos[3];
6183   evt->GetPrimaryVertex()->GetXYZ(priVtxPos);
6184   //  printf("Mag field: %f\n",evt->GetMagneticField());
6185   ShiftAndAdd(evt->GetMagneticField(),
6186               priVtxPos,
6187               evt->GetCentrality()->GetCentralityPercentileUnchecked("V0M"));
6188 }
6189 //________________________________________________________________________
6190 void AliAnalysisTaskProtonLambda::FemtoBuffer::ShiftAndAdd(const Double_t bfield,const Double_t priVtxPos[3],const Float_t centrality){
6191   // Shift the events in the appropiate centrality / zvertex bin and set the 
6192   // current event pointer correctly
6193
6194   // Find the correct centrality/zvertex bin 
6195   const UChar_t ZvertexBin = fZvertexAxis->FindFixBin(priVtxPos[2]) - 1; // -1 for array starting at 0
6196   const UChar_t CentBin = fCentAxis->FindFixBin(centrality) - 1;// -1 for array starting at 0
6197
6198   // The new current event is the old last event
6199   fCurEvt[0] = fEC[ZvertexBin][CentBin][fkMixBuffSize-1];
6200
6201   // Shift the pointer, starting from the back
6202   UChar_t iMix;
6203   for(iMix=fkMixBuffSize-1;iMix>0;iMix--){
6204     fEC[ZvertexBin][CentBin][iMix] = fEC[ZvertexBin][CentBin][iMix-1];
6205   }
6206   // And reset the zero'th one
6207   fEC[ZvertexBin][CentBin][0] = fCurEvt[0];
6208   fEC[ZvertexBin][CentBin][0]->Reset(bfield,priVtxPos);
6209   // Also set the pointer to the other events..
6210   for (iMix=1;iMix<fkMixBuffSize;iMix++){
6211     fCurEvt[iMix] = fEC[ZvertexBin][CentBin][iMix];
6212   }
6213 }