]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/STRANGENESS/LambdaK0/AliAnalysisTaskExtractV0.cxx
Two histos missing from '(0)' initialization, fixed. (Results produced by this macro...
[u/mrichter/AliRoot.git] / PWGLF / STRANGENESS / LambdaK0 / AliAnalysisTaskExtractV0.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
16 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
17 //
18 // Modified version of AliAnalysisTaskCheckCascade.cxx.
19 // This is a 'hybrid' output version, in that it uses a classic TTree
20 // ROOT object to store the candidates, plus a couple of histograms filled on
21 // a per-event basis for storing variables too numerous to put in a tree. 
22 //
23 // --- Added bits of code for checking V0s 
24 //      (from AliAnalysisTaskCheckStrange.cxx)
25 //
26 //  --- Algorithm Description 
27 //   1. Perform Physics Selection
28 //   2. Perform Primary Vertex |z|<10cm selection
29 //   3. Perform Primary Vertex NoTPCOnly vertexing selection (>0 contrib.)
30 //   4. Perform Pileup Rejection
31 //   5. Analysis Loops: 
32 //    5a. Fill TTree object with V0 information, candidates
33 //
34 //  Please Report Any Bugs! 
35 //
36 //   --- David Dobrigkeit Chinellato
37 //        (david.chinellato@gmail.com)
38 //
39 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40
41 class TTree;
42 class TParticle;
43 class TVector3;
44
45 //class AliMCEventHandler;
46 //class AliMCEvent;
47 //class AliStack;
48
49 class AliESDVertex;
50 class AliAODVertex;
51 class AliESDv0;
52 class AliAODv0;
53
54 #include <Riostream.h>
55 #include "TList.h"
56 #include "TH1.h"
57 #include "TH2.h"
58 #include "TH3.h"
59 #include "THnSparse.h"
60 #include "TVector3.h"
61 #include "TCanvas.h"
62 #include "TMath.h"
63 #include "TLegend.h"
64 #include "AliLog.h"
65
66 #include "AliESDEvent.h"
67 #include "AliAODEvent.h"
68 #include "AliV0vertexer.h"
69 #include "AliCascadeVertexer.h"
70 #include "AliESDpid.h"
71 #include "AliESDtrack.h"
72 #include "AliESDtrackCuts.h"
73 #include "AliInputEventHandler.h"
74 #include "AliAnalysisManager.h"
75 #include "AliMCEventHandler.h"
76
77 #include "AliCFContainer.h"
78 #include "AliMultiplicity.h"
79
80 #include "AliESDcascade.h"
81 #include "AliAODcascade.h"
82 #include "AliESDUtils.h"
83
84 #include "AliAnalysisTaskExtractV0.h"
85
86 ClassImp(AliAnalysisTaskExtractV0)
87
88 AliAnalysisTaskExtractV0::AliAnalysisTaskExtractV0() 
89   : AliAnalysisTaskSE(), fListHistV0(0), fTree(0),
90
91 //------------------------------------------------
92 // HISTOGRAMS
93 // --- Filled on an Event-by-event basis
94 //------------------------------------------------
95    fHistV0MultiplicityBeforeTrigSel(0),
96    fHistV0MultiplicityForTrigEvt(0),
97    fHistV0MultiplicityForSelEvt(0),
98    fHistV0MultiplicityForSelEvtNoTPCOnly(0),
99    fHistV0MultiplicityForSelEvtNoTPCOnlyNoPileup(0),
100    fHistMultiplicityBeforeTrigSel(0),
101    fHistMultiplicityForTrigEvt(0),
102    fHistMultiplicity(0),
103    fHistMultiplicityNoTPCOnly(0),
104    fHistMultiplicityNoTPCOnlyNoPileup(0),
105    fHistPVx(0),
106    fHistPVy(0),
107    fHistPVz(0),
108    fHistPVxAnalysis(0),
109    fHistPVyAnalysis(0),
110    fHistPVzAnalysis(0)
111 {
112   // Dummy Constructor
113 }
114
115 AliAnalysisTaskExtractV0::AliAnalysisTaskExtractV0(const char *name) 
116   : AliAnalysisTaskSE(name), fListHistV0(0), fTree(0),
117      
118 //------------------------------------------------
119 // HISTOGRAMS
120 // --- Filled on an Event-by-event basis
121 //------------------------------------------------
122    fHistV0MultiplicityBeforeTrigSel(0),
123    fHistV0MultiplicityForTrigEvt(0),
124    fHistV0MultiplicityForSelEvt(0),
125    fHistV0MultiplicityForSelEvtNoTPCOnly(0),
126    fHistV0MultiplicityForSelEvtNoTPCOnlyNoPileup(0),
127    fHistMultiplicityBeforeTrigSel(0),
128    fHistMultiplicityForTrigEvt(0),
129    fHistMultiplicity(0),
130    fHistMultiplicityNoTPCOnly(0),
131    fHistMultiplicityNoTPCOnlyNoPileup(0),
132    fHistPVx(0),
133    fHistPVy(0),
134    fHistPVz(0),
135    fHistPVxAnalysis(0),
136    fHistPVyAnalysis(0),
137    fHistPVzAnalysis(0)
138 {
139   // Constructor
140   // Output slot #0 writes into a TList container (Lambda Histos and fTree)
141    DefineOutput(1, TList::Class());
142    DefineOutput(2, TTree::Class());
143 }
144
145
146 AliAnalysisTaskExtractV0::~AliAnalysisTaskExtractV0()
147 {
148 //------------------------------------------------
149 // DESTRUCTOR
150 //------------------------------------------------
151
152    if (fListHistV0){
153       delete fListHistV0;
154       fListHistV0 = 0x0;
155    }
156    if (fTree){
157       delete fTree;
158       fTree = 0x0;
159    }
160 }
161
162
163
164 //________________________________________________________________________
165 void AliAnalysisTaskExtractV0::UserCreateOutputObjects()
166 {
167    // Create histograms
168
169    fListHistV0 = new TList();
170    fListHistV0->SetOwner();  // See http://root.cern.ch/root/html/TCollection.html#TCollection:SetOwner
171
172    // Called once
173    if( !fTree) { 
174       fTree = new TTree("fTree","V0Candidates");
175
176 //------------------------------------------------
177 // fTree Branch definitions
178 //------------------------------------------------
179
180 //-----------BASIC-INFO---------------------------
181 /* 1*/   fTree->Branch("fTreeVariableChi2V0",&fTreeVariableChi2V0,"fTreeVariableChi2V0/F");
182 /* 2*/   fTree->Branch("fTreeVariableDcaV0Daughters",&fTreeVariableDcaV0Daughters,"fTreeVariableDcaV0Daughters/F");
183 /* 3*/  fTree->Branch("fTreeVariableDcaPosToPrimVertex",&fTreeVariableDcaPosToPrimVertex,"fTreeVariableDcaPosToPrimVertex/F");
184 /* 4*/  fTree->Branch("fTreeVariableDcaNegToPrimVertex",&fTreeVariableDcaNegToPrimVertex,"fTreeVariableDcaNegToPrimVertex/F");
185 /* 5*/  fTree->Branch("fTreeVariableV0Radius",&fTreeVariableV0Radius,"fTreeVariableV0Radius/F");
186 /* 6*/  fTree->Branch("fTreeVariablePt",&fTreeVariablePt,"fTreeVariablePt/F");
187 /* 7*/  fTree->Branch("fTreeVariableRapK0Short",&fTreeVariableRapK0Short,"fTreeVariableRapK0Short/F");
188 /* 8*/  fTree->Branch("fTreeVariableRapLambda",&fTreeVariableRapLambda,"fTreeVariableRapLambda/F");
189 /* 9*/  fTree->Branch("fTreeVariableInvMassK0s",&fTreeVariableInvMassK0s,"fTreeVariableInvMassK0s/F");
190 /*10*/  fTree->Branch("fTreeVariableInvMassLambda",&fTreeVariableInvMassLambda,"fTreeVariableInvMassLambda/F");
191 /*11*/  fTree->Branch("fTreeVariableInvMassAntiLambda",&fTreeVariableInvMassAntiLambda,"fTreeVariableInvMassAntiLambda/F");
192 /*12*/  fTree->Branch("fTreeVariableV0CosineOfPointingAngle",&fTreeVariableV0CosineOfPointingAngle,"fTreeVariableV0CosineOfPointingAngle/F");
193 /*13*/  fTree->Branch("fTreeVariableAlphaV0",&fTreeVariableAlphaV0,"fTreeVariableAlphaV0/F");
194 /*14*/  fTree->Branch("fTreeVariablePtArmV0",&fTreeVariablePtArmV0,"fTreeVariablePtArmV0/F");
195 /*15*/  fTree->Branch("fTreeVariableLeastNbrCrossedRows",&fTreeVariableLeastNbrCrossedRows,"fTreeVariableLeastNbrCrossedRows/I");
196 /*16*/  fTree->Branch("fTreeVariableLeastRatioCrossedRowsOverFindable",&fTreeVariableLeastRatioCrossedRowsOverFindable,"fTreeVariableLeastRatioCrossedRowsOverFindable/F");
197 //-----------MULTIPLICITY-INFO--------------------
198 /*17*/  fTree->Branch("fTreeVariableMultiplicity",&fTreeVariableMultiplicity,"fTreeVariableMultiplicity/I");
199 //------------------------------------------------
200 /*18*/  fTree->Branch("fTreeVariableDistOverTotMom",&fTreeVariableDistOverTotMom,"fTreeVariableDistOverTotMom/F");
201 /*19*/  fTree->Branch("fTreeVariableNSigmasPosProton",&fTreeVariableNSigmasPosProton,"fTreeVariableNSigmasPosProton/F");
202 /*20*/  fTree->Branch("fTreeVariableNSigmasPosPion",&fTreeVariableNSigmasPosPion,"fTreeVariableNSigmasPosPion/F");
203 /*21*/  fTree->Branch("fTreeVariableNSigmasNegProton",&fTreeVariableNSigmasNegProton,"fTreeVariableNSigmasNegProton/F");
204 /*22*/  fTree->Branch("fTreeVariableNSigmasNegPion",&fTreeVariableNSigmasNegPion,"fTreeVariableNSigmasNegPion/F");
205 /*23*/  fTree->Branch("fTreeVariableNegEta",&fTreeVariableNegEta,"fTreeVariableNegEta/F");
206 /*24*/  fTree->Branch("fTreeVariablePosEta",&fTreeVariablePosEta,"fTreeVariablePosEta/F");
207
208       //Do not add to list. Add as output container. 
209       //to be added directly to base directory (use disk caching!) 
210       //fListHistV0->Add(fTree);
211    }
212
213 //------------------------------------------------
214 // Particle Identification Setup
215 //------------------------------------------------
216
217    AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
218    AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
219    fPIDResponse = inputHandler->GetPIDResponse();
220
221 //Skipped. Will use Local setup.
222
223 //------------------------------------------------
224 // V0 Multiplicity Histograms
225 //------------------------------------------------
226
227    if(! fHistV0MultiplicityBeforeTrigSel) {
228       fHistV0MultiplicityBeforeTrigSel = new TH1F("fHistV0MultiplicityBeforeTrigSel", 
229          "V0s per event (before Trig. Sel.);Nbr of V0s/Evt;Events", 
230          25, 0, 25);
231       fListHistV0->Add(fHistV0MultiplicityBeforeTrigSel);
232    }
233            
234    if(! fHistV0MultiplicityForTrigEvt) {
235       fHistV0MultiplicityForTrigEvt = new TH1F("fHistV0MultiplicityForTrigEvt", 
236          "V0s per event (for triggered evt);Nbr of V0s/Evt;Events", 
237          25, 0, 25);
238       fListHistV0->Add(fHistV0MultiplicityForTrigEvt);
239    }
240
241    if(! fHistV0MultiplicityForSelEvt) {
242       fHistV0MultiplicityForSelEvt = new TH1F("fHistV0MultiplicityForSelEvt", 
243          "V0s per event;Nbr of V0s/Evt;Events", 
244          25, 0, 25);
245       fListHistV0->Add(fHistV0MultiplicityForSelEvt);
246    }
247
248    if(! fHistV0MultiplicityForSelEvtNoTPCOnly) {
249       fHistV0MultiplicityForSelEvtNoTPCOnly = new TH1F("fHistV0MultiplicityForSelEvtNoTPCOnly", 
250          "V0s per event;Nbr of V0s/Evt;Events", 
251          25, 0, 25);
252       fListHistV0->Add(fHistV0MultiplicityForSelEvtNoTPCOnly);
253    }
254
255    if(! fHistV0MultiplicityForSelEvtNoTPCOnlyNoPileup) {
256       fHistV0MultiplicityForSelEvtNoTPCOnlyNoPileup = new TH1F("fHistV0MultiplicityForSelEvtNoTPCOnlyNoPileup", 
257          "V0s per event;Nbr of V0s/Evt;Events", 
258          25, 0, 25);
259       fListHistV0->Add(fHistV0MultiplicityForSelEvtNoTPCOnlyNoPileup);
260    }
261
262 //------------------------------------------------
263 // Track Multiplicity Histograms
264 //------------------------------------------------
265
266    if(! fHistMultiplicityBeforeTrigSel) {
267       fHistMultiplicityBeforeTrigSel = new TH1F("fHistMultiplicityBeforeTrigSel", 
268          "Tracks per event;Nbr of Tracks;Events", 
269          200, 0, 200);          
270       fListHistV0->Add(fHistMultiplicityBeforeTrigSel);
271    }
272    if(! fHistMultiplicityForTrigEvt) {
273       fHistMultiplicityForTrigEvt = new TH1F("fHistMultiplicityForTrigEvt", 
274          "Tracks per event;Nbr of Tracks;Events", 
275          200, 0, 200);          
276       fListHistV0->Add(fHistMultiplicityForTrigEvt);
277    }
278    if(! fHistMultiplicity) {
279       fHistMultiplicity = new TH1F("fHistMultiplicity", 
280          "Tracks per event;Nbr of Tracks;Events", 
281          200, 0, 200);          
282       fListHistV0->Add(fHistMultiplicity);
283    }
284    if(! fHistMultiplicityNoTPCOnly) {
285       fHistMultiplicityNoTPCOnly = new TH1F("fHistMultiplicityNoTPCOnly", 
286          "Tracks per event;Nbr of Tracks;Events", 
287          200, 0, 200);          
288       fListHistV0->Add(fHistMultiplicityNoTPCOnly);
289    }
290    if(! fHistMultiplicityNoTPCOnlyNoPileup) {
291       fHistMultiplicityNoTPCOnlyNoPileup = new TH1F("fHistMultiplicityNoTPCOnlyNoPileup", 
292          "Tracks per event;Nbr of Tracks;Events", 
293          200, 0, 200);          
294       fListHistV0->Add(fHistMultiplicityNoTPCOnlyNoPileup);
295    }
296
297    if(! fHistPVx) {
298       fHistPVx = new TH1F("fHistPVx", 
299          "PV x position;Nbr of Evts;x", 
300          2000, -0.5, 0.5);              
301       fListHistV0->Add(fHistPVx);
302    }
303    if(! fHistPVy) {
304       fHistPVy = new TH1F("fHistPVy", 
305          "PV y position;Nbr of Evts;y", 
306          2000, -0.5, 0.5);              
307       fListHistV0->Add(fHistPVy);
308    }
309    if(! fHistPVz) {
310       fHistPVz = new TH1F("fHistPVz", 
311          "PV z position;Nbr of Evts;z", 
312          400, -20, 20);                 
313       fListHistV0->Add(fHistPVz);
314    }
315    if(! fHistPVxAnalysis) {
316       fHistPVxAnalysis = new TH1F("fHistPVxAnalysis", 
317          "PV x position;Nbr of Evts;x", 
318          2000, -0.5, 0.5);              
319       fListHistV0->Add(fHistPVxAnalysis);
320    }
321    if(! fHistPVyAnalysis) {
322       fHistPVyAnalysis = new TH1F("fHistPVyAnalysis", 
323          "PV y position;Nbr of Evts;y", 
324          2000, -0.5, 0.5);              
325       fListHistV0->Add(fHistPVyAnalysis);
326    }
327    if(! fHistPVzAnalysis) {
328       fHistPVzAnalysis = new TH1F("fHistPVzAnalysis", 
329          "PV z position;Nbr of Evts;z", 
330          400, -20, 20);                 
331       fListHistV0->Add(fHistPVzAnalysis);
332    }
333    //Regular output: Histograms
334    PostData(1, fListHistV0);
335    //TTree Object: Saved to base directory. Should cache to disk while saving. 
336    //(Important to avoid excessive memory usage, particularly when merging)
337    PostData(2, fTree);
338
339 }// end UserCreateOutputObjects
340
341
342 //________________________________________________________________________
343 void AliAnalysisTaskExtractV0::UserExec(Option_t *) 
344 {
345    // Main loop
346    // Called for each event
347
348    AliESDEvent *lESDevent = 0x0;
349    //AliAODEvent *lAODevent = 0x0;
350    Int_t    nV0s                        = -1;
351
352    Double_t lTrkgPrimaryVtxPos[3]          = {-100.0, -100.0, -100.0};
353    Double_t lBestPrimaryVtxPos[3]          = {-100.0, -100.0, -100.0};
354    Double_t lMagneticField                 = -10.;
355         
356    // Connect to the InputEvent 
357    // After these lines, we should have an ESD/AOD event + the number of cascades in it.
358
359    // Appropriate for ESD analysis! 
360                 
361    lESDevent = dynamic_cast<AliESDEvent*>( InputEvent() );
362    if (!lESDevent) {
363       AliWarning("ERROR: lESDevent not available \n");
364       return;
365    }
366
367    //REVISED multiplicity estimator after 'multiplicity day' (2011)
368    Int_t multiplicity = AliESDtrackCuts::GetReferenceMultiplicity( lESDevent );
369   
370    //Set variable for filling tree afterwards!
371    fTreeVariableMultiplicity = multiplicity;
372         
373    fHistV0MultiplicityBeforeTrigSel->Fill ( lESDevent->GetNumberOfV0s() );
374    fHistMultiplicityBeforeTrigSel->Fill ( multiplicity );
375         
376 //------------------------------------------------
377 // Physics Selection
378 //------------------------------------------------
379
380 // new method        
381    UInt_t maskIsSelected = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
382    Bool_t isSelected = 0;
383    isSelected = (maskIsSelected & AliVEvent::kMB) == AliVEvent::kMB;
384    if ( ! isSelected ) { 
385       PostData(1, fListHistV0);
386       PostData(2, fTree);
387       return;
388    }
389
390 //------------------------------------------------
391 // After Trigger Selection
392 //------------------------------------------------
393
394         nV0s = lESDevent->GetNumberOfV0s();
395
396   fHistV0MultiplicityForTrigEvt     ->Fill( nV0s       );
397   fHistMultiplicityForTrigEvt       ->Fill( multiplicity  );
398
399 //------------------------------------------------
400 // Getting: Primary Vertex + MagField Info
401 //------------------------------------------------
402
403         const AliESDVertex *lPrimaryTrackingESDVtx = lESDevent->GetPrimaryVertexTracks();
404         // get the vtx stored in ESD found with tracks
405         lPrimaryTrackingESDVtx->GetXYZ( lTrkgPrimaryVtxPos );
406         
407         const AliESDVertex *lPrimaryBestESDVtx = lESDevent->GetPrimaryVertex(); 
408   // get the best primary vertex available for the event
409         // As done in AliCascadeVertexer, we keep the one which is the best one available.
410         // between : Tracking vertex > SPD vertex > TPC vertex > default SPD vertex
411         // This one will be used for next calculations (DCA essentially)
412    lPrimaryBestESDVtx->GetXYZ( lBestPrimaryVtxPos );
413
414    Double_t tPrimaryVtxPosition[3];
415    const AliVVertex *primaryVtx = lESDevent->GetPrimaryVertex();
416    tPrimaryVtxPosition[0] = primaryVtx->GetX();
417    tPrimaryVtxPosition[1] = primaryVtx->GetY();
418    tPrimaryVtxPosition[2] = primaryVtx->GetZ();
419    fHistPVx->Fill( tPrimaryVtxPosition[0] );
420    fHistPVy->Fill( tPrimaryVtxPosition[1] );
421    fHistPVz->Fill( tPrimaryVtxPosition[2] );
422
423 //------------------------------------------------
424 // Primary Vertex Z position: SKIP
425 //------------------------------------------------
426
427    if(TMath::Abs(lBestPrimaryVtxPos[2]) > 10.0 ) { 
428       AliWarning("Pb / | Z position of Best Prim Vtx | > 10.0 cm ... return !"); 
429       PostData(1, fListHistV0);
430       PostData(2, fTree);
431       return; 
432    }
433
434    lMagneticField = lESDevent->GetMagneticField( );
435    fHistV0MultiplicityForSelEvt ->Fill( nV0s );
436    fHistMultiplicity->Fill(multiplicity);
437
438 //------------------------------------------------
439 // Only look at events with well-established PV
440 //------------------------------------------------
441         
442    const AliESDVertex *lPrimaryTrackingESDVtxCheck = lESDevent->GetPrimaryVertexTracks();
443    const AliESDVertex *lPrimarySPDVtx = lESDevent->GetPrimaryVertexSPD();
444    if (!lPrimarySPDVtx->GetStatus() && !lPrimaryTrackingESDVtxCheck->GetStatus() ){
445       AliWarning("Pb / No SPD prim. vertex nor prim. Tracking vertex ... return !");
446       PostData(1, fListHistV0);
447       PostData(2, fTree);
448       return;
449    }
450
451    fHistV0MultiplicityForSelEvtNoTPCOnly ->Fill( nV0s );
452    fHistMultiplicityNoTPCOnly->Fill(multiplicity);
453
454 //------------------------------------------------
455 // Pileup Rejection
456 //------------------------------------------------
457
458    // FIXME : quality selection regarding pile-up rejection 
459    if(lESDevent->IsPileupFromSPD() ){// minContributors=3, minZdist=0.8, nSigmaZdist=3., nSigmaDiamXY=2., nSigmaDiamZ=5.  -> see http://alisoft.cern.ch/viewvc/trunk/STEER/AliESDEvent.h?root=AliRoot&r1=41914&r2=42199&pathrev=42199
460       PostData(1, fListHistV0);
461       PostData(2, fTree); 
462       return;
463    }
464    fHistV0MultiplicityForSelEvtNoTPCOnlyNoPileup ->Fill( nV0s );
465    fHistMultiplicityNoTPCOnlyNoPileup->Fill(multiplicity);
466   
467 //------------------------------------------------
468 // MAIN LAMBDA LOOP STARTS HERE
469 //------------------------------------------------
470
471    if( ! (lESDevent->GetPrimaryVertex()->IsFromVertexerZ() )     ){ 
472       fHistPVxAnalysis->Fill( tPrimaryVtxPosition[0] );
473       fHistPVyAnalysis->Fill( tPrimaryVtxPosition[1] );
474       fHistPVzAnalysis->Fill( tPrimaryVtxPosition[2] );
475    }
476
477 //Variable definition
478    Int_t    lOnFlyStatus = 0;// nv0sOn = 0, nv0sOff = 0;
479    Double_t lChi2V0 = 0;
480    Double_t lDcaV0Daughters = 0, lDcaV0ToPrimVertex = 0;
481    Double_t lDcaPosToPrimVertex = 0, lDcaNegToPrimVertex = 0;
482    Double_t lV0CosineOfPointingAngle = 0;
483    Double_t lV0Radius = 0, lPt = 0;
484    Double_t lRapK0Short = 0, lRapLambda = 0;
485    Double_t lInvMassK0s = 0, lInvMassLambda = 0, lInvMassAntiLambda = 0;
486    Double_t lAlphaV0 = 0, lPtArmV0 = 0;
487
488    Double_t fMinV0Pt = 0; 
489    Double_t fMaxV0Pt = 100; 
490
491    Int_t nv0s = 0;
492    nv0s = lESDevent->GetNumberOfV0s();
493
494    for (Int_t iV0 = 0; iV0 < nv0s; iV0++) 
495    {// This is the begining of the V0 loop
496       AliESDv0 *v0 = ((AliESDEvent*)lESDevent)->GetV0(iV0);
497       if (!v0) continue;
498       Double_t tDecayVertexV0[3]; v0->GetXYZ(tDecayVertexV0[0],tDecayVertexV0[1],tDecayVertexV0[2]); 
499       Double_t tV0mom[3];
500       v0->GetPxPyPz( tV0mom[0],tV0mom[1],tV0mom[2] ); 
501       Double_t lV0TotalMomentum = TMath::Sqrt(
502       tV0mom[0]*tV0mom[0]+tV0mom[1]*tV0mom[1]+tV0mom[2]*tV0mom[2] );
503
504       lV0Radius = TMath::Sqrt(tDecayVertexV0[0]*tDecayVertexV0[0]+tDecayVertexV0[1]*tDecayVertexV0[1]);
505       lPt = v0->Pt();
506       lRapK0Short = v0->RapK0Short();
507       lRapLambda  = v0->RapLambda();
508       if ((lPt<fMinV0Pt)||(fMaxV0Pt<lPt)) continue;
509
510       UInt_t lKeyPos = (UInt_t)TMath::Abs(v0->GetPindex());
511       UInt_t lKeyNeg = (UInt_t)TMath::Abs(v0->GetNindex());
512
513       Double_t lMomPos[3]; v0->GetPPxPyPz(lMomPos[0],lMomPos[1],lMomPos[2]);
514       Double_t lMomNeg[3]; v0->GetNPxPyPz(lMomNeg[0],lMomNeg[1],lMomNeg[2]);
515
516       AliESDtrack *pTrack=((AliESDEvent*)lESDevent)->GetTrack(lKeyPos);
517       AliESDtrack *nTrack=((AliESDEvent*)lESDevent)->GetTrack(lKeyNeg);
518       if (!pTrack || !nTrack) {
519          Printf("ERROR: Could not retreive one of the daughter track");
520          continue;
521       }
522
523       //Daughter Eta for Eta selection, afterwards
524       fTreeVariableNegEta = nTrack->Eta();
525       fTreeVariablePosEta = pTrack->Eta();
526
527       // Filter like-sign V0 (next: add counter and distribution)
528       if ( pTrack->GetSign() == nTrack->GetSign()){
529          continue;
530       } 
531
532       //________________________________________________________________________
533       // Track quality cuts 
534       Float_t lPosTrackCrossedRows = pTrack->GetTPCClusterInfo(2,1);
535       Float_t lNegTrackCrossedRows = nTrack->GetTPCClusterInfo(2,1);
536       fTreeVariableLeastNbrCrossedRows = lPosTrackCrossedRows;
537       if( lNegTrackCrossedRows < fTreeVariableLeastNbrCrossedRows )
538          fTreeVariableLeastNbrCrossedRows = lNegTrackCrossedRows;
539
540       // TPC refit condition (done during reconstruction for Offline but not for On-the-fly)
541       if( !(pTrack->GetStatus() & AliESDtrack::kTPCrefit)) continue;
542       if( !(nTrack->GetStatus() & AliESDtrack::kTPCrefit)) continue;
543
544       if ( ( ( pTrack->GetTPCClusterInfo(2,1) ) < 70 ) || ( ( nTrack->GetTPCClusterInfo(2,1) ) < 70 ) ) continue;
545         
546       //GetKinkIndex condition
547       if( pTrack->GetKinkIndex(0)>0 || nTrack->GetKinkIndex(0)>0 ) continue;
548
549       //Findable clusters > 0 condition
550       if( pTrack->GetTPCNclsF()<=0 || nTrack->GetTPCNclsF()<=0 ) continue;
551
552       //Compute ratio Crossed Rows / Findable clusters
553       //Note: above test avoids division by zero! 
554       Float_t lPosTrackCrossedRowsOverFindable = lPosTrackCrossedRows / ((double)(pTrack->GetTPCNclsF())); 
555       Float_t lNegTrackCrossedRowsOverFindable = lNegTrackCrossedRows / ((double)(nTrack->GetTPCNclsF())); 
556
557       fTreeVariableLeastRatioCrossedRowsOverFindable = lPosTrackCrossedRowsOverFindable;
558       if( lNegTrackCrossedRowsOverFindable < fTreeVariableLeastRatioCrossedRowsOverFindable )
559          fTreeVariableLeastRatioCrossedRowsOverFindable = lNegTrackCrossedRowsOverFindable;
560
561       //Lowest Cut Level for Ratio Crossed Rows / Findable = 0.8, set here
562       if ( fTreeVariableLeastRatioCrossedRowsOverFindable < 0.8 ) continue;
563
564       //End track Quality Cuts
565       //________________________________________________________________________
566
567       lDcaPosToPrimVertex = TMath::Abs(pTrack->GetD(tPrimaryVtxPosition[0],
568                                                         tPrimaryVtxPosition[1],
569                                                         lMagneticField) );
570
571       lDcaNegToPrimVertex = TMath::Abs(nTrack->GetD(tPrimaryVtxPosition[0],
572                                                         tPrimaryVtxPosition[1],
573                                                         lMagneticField) );
574
575       lOnFlyStatus = v0->GetOnFlyStatus();
576       lChi2V0 = v0->GetChi2V0();
577       lDcaV0Daughters = v0->GetDcaV0Daughters();
578       lDcaV0ToPrimVertex = v0->GetD(tPrimaryVtxPosition[0],tPrimaryVtxPosition[1],tPrimaryVtxPosition[2]);
579       lV0CosineOfPointingAngle = v0->GetV0CosineOfPointingAngle(tPrimaryVtxPosition[0],tPrimaryVtxPosition[1],tPrimaryVtxPosition[2]);
580       fTreeVariableV0CosineOfPointingAngle=lV0CosineOfPointingAngle;
581
582       // Getting invariant mass infos directly from ESD
583       v0->ChangeMassHypothesis(310);
584       lInvMassK0s = v0->GetEffMass();
585       v0->ChangeMassHypothesis(3122);
586       lInvMassLambda = v0->GetEffMass();
587       v0->ChangeMassHypothesis(-3122);
588       lInvMassAntiLambda = v0->GetEffMass();
589       lAlphaV0 = v0->AlphaV0();
590       lPtArmV0 = v0->PtArmV0();
591
592       fTreeVariablePt = v0->Pt();
593       fTreeVariableChi2V0 = lChi2V0; 
594       fTreeVariableDcaV0ToPrimVertex = lDcaV0ToPrimVertex;
595       fTreeVariableDcaV0Daughters = lDcaV0Daughters;
596       fTreeVariableV0CosineOfPointingAngle = lV0CosineOfPointingAngle; 
597       fTreeVariableV0Radius = lV0Radius;
598       fTreeVariableDcaPosToPrimVertex = lDcaPosToPrimVertex;
599       fTreeVariableDcaNegToPrimVertex = lDcaNegToPrimVertex;
600       fTreeVariableInvMassK0s = lInvMassK0s;
601       fTreeVariableInvMassLambda = lInvMassLambda;
602       fTreeVariableInvMassAntiLambda = lInvMassAntiLambda;
603       fTreeVariableRapK0Short = lRapK0Short;
604       fTreeVariableRapLambda = lRapLambda;
605       fTreeVariableAlphaV0 = lAlphaV0;
606       fTreeVariablePtArmV0 = lPtArmV0;
607
608       //Official means of acquiring N-sigmas 
609       fTreeVariableNSigmasPosProton = fPIDResponse->NumberOfSigmasTPC( pTrack, AliPID::kProton );
610       fTreeVariableNSigmasPosPion   = fPIDResponse->NumberOfSigmasTPC( pTrack, AliPID::kPion );
611       fTreeVariableNSigmasNegProton = fPIDResponse->NumberOfSigmasTPC( nTrack, AliPID::kProton );
612       fTreeVariableNSigmasNegPion   = fPIDResponse->NumberOfSigmasTPC( nTrack, AliPID::kPion );
613
614 //This requires an Invariant Mass Hypothesis afterwards
615       fTreeVariableDistOverTotMom = TMath::Sqrt(
616                                                 TMath::Power( tDecayVertexV0[0] - lBestPrimaryVtxPos[0] , 2) +
617                                                 TMath::Power( tDecayVertexV0[1] - lBestPrimaryVtxPos[1] , 2) +
618                                                 TMath::Power( tDecayVertexV0[2] - lBestPrimaryVtxPos[2] , 2)
619                                         );
620       fTreeVariableDistOverTotMom /= (lV0TotalMomentum+1e-10); //avoid division by zero, to be sure
621
622 //------------------------------------------------
623 // Fill Tree! 
624 //------------------------------------------------
625
626 // The conditionals are meant to decrease excessive
627 // memory usage! 
628
629 //First Selection: Reject OnFly
630       if( lOnFlyStatus == 0 ){
631          //Second Selection: rough 20-sigma band, parametric. 
632          //K0Short: Enough to parametrize peak broadening with linear function.    
633          Double_t lUpperLimitK0Short = (5.63707e-01) + (1.14979e-02)*fTreeVariablePt; 
634          Double_t lLowerLimitK0Short = (4.30006e-01) - (1.10029e-02)*fTreeVariablePt;
635          //Lambda: Linear (for higher pt) plus exponential (for low-pt broadening)
636          //[0]+[1]*x+[2]*TMath::Exp(-[3]*x)
637          Double_t lUpperLimitLambda = (1.13688e+00) + (5.27838e-03)*fTreeVariablePt + (8.42220e-02)*TMath::Exp(-(3.80595e+00)*fTreeVariablePt); 
638          Double_t lLowerLimitLambda = (1.09501e+00) - (5.23272e-03)*fTreeVariablePt - (7.52690e-02)*TMath::Exp(-(3.46339e+00)*fTreeVariablePt);
639          //Do Selection      
640          if( (fTreeVariableInvMassLambda     < lUpperLimitLambda  && fTreeVariableInvMassLambda     > lLowerLimitLambda     ) || 
641              (fTreeVariableInvMassAntiLambda < lUpperLimitLambda  && fTreeVariableInvMassAntiLambda > lLowerLimitLambda     ) || 
642              (fTreeVariableInvMassK0s        < lUpperLimitK0Short && fTreeVariableInvMassK0s        > lLowerLimitK0Short    ) ){
643             fTree->Fill();
644          }
645       }
646
647 //------------------------------------------------
648 // Fill tree over.
649 //------------------------------------------------
650
651    }// This is the end of the V0 loop
652   
653   // Post output data.
654     PostData(1, fListHistV0);
655     PostData(2, fTree);
656 }
657
658 //________________________________________________________________________
659 void AliAnalysisTaskExtractV0::Terminate(Option_t *)
660 {
661    // Draw result to the screen
662    // Called once at the end of the query
663    // This will draw the V0 candidate multiplicity, whose 
664    // number of entries corresponds to the number of triggered events. 
665    TList *cRetrievedList = 0x0;
666    cRetrievedList = (TList*)GetOutputData(1);
667    if(!cRetrievedList){
668       Printf("ERROR - AliAnalysisTaskExtractV0 : ouput data container list not available\n");
669       return;
670    }            
671    fHistV0MultiplicityForTrigEvt = dynamic_cast<TH1F*> (  cRetrievedList->FindObject("fHistV0MultiplicityForTrigEvt")  );
672    if (!fHistV0MultiplicityForTrigEvt) {
673       Printf("ERROR - AliAnalysisTaskExtractV0 : fHistV0MultiplicityForTrigEvt not available");
674       return;
675    }
676    TCanvas *canCheck = new TCanvas("AliAnalysisTaskExtractV0","V0 Multiplicity",10,10,510,510);
677    canCheck->cd(1)->SetLogy();
678    fHistV0MultiplicityForTrigEvt->SetMarkerStyle(22);
679    fHistV0MultiplicityForTrigEvt->DrawCopy("E");
680 }
681