]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG1/AliAnalysisTaskV0QA.cxx
add parameter path to the add task macros. (Markus)
[u/mrichter/AliRoot.git] / PWG1 / AliAnalysisTaskV0QA.cxx
1 //------------------------------------------------
2 // Implementation of AliAnalysisTaskV0QA class.
3 // Calculates the "on the fly" V0 method efficiency 
4 // for Gamma, K0s, lambda, antilambda
5 // Needs MC information
6 // Author: A. Marin  Revision 18/10/09
7 //-------------------------------------------------
8 #define AliAnalysisTaskV0QA_cxx
9
10 #include "TChain.h"
11 #include "TH1.h"
12 #include "TH2.h"
13
14
15 //#include "TLorentzVector.h"
16
17 #include "AliAnalysisTaskSE.h"
18 #include "AliTrackReference.h"
19 #include "AliKFParticle.h"
20 #include "AliKFVertex.h"
21 #include "AliVertexerTracks.h"
22 #include "AliESDEvent.h"
23 #include "AliESDInputHandler.h"
24 #include "AliMCEvent.h"
25 #include "AliMCEventHandler.h"
26 #include "AliStack.h"
27 #include "AliESD.h"
28 #include "AliLog.h"
29
30 #include "AliAnalysisTaskV0QA.h"
31
32 ClassImp(AliAnalysisTaskV0QA)
33 AliAnalysisTaskV0QA::AliAnalysisTaskV0QA() :AliAnalysisTaskSE(), 
34 fESD(0), 
35 fStack(0),
36 fMCtruth(0),
37 fChain(0),
38 fOutputContainer(0),
39 fSparseV0(0),
40 fSparseK0(0),
41 fSparseL(0),
42 fSparseAL(0),
43 fnEv(0),
44 fgDim(50),
45 fnConvGamGeant(-1),
46 fgConvGamGeantIndex(0),
47 feNegConvGamGeantIndex(0),
48 fePosConvGamGeantIndex(0),
49 feNegConvGamGeantLength(0),
50 fePosConvGamGeantLength(0),
51 feNegConvGamSingleRecIndex(0),
52 fePosConvGamSingleRecIndex(0),
53 feNegConvGamV0RecIndex(0),
54 fePosConvGamV0RecIndex(0),
55 fConvGamV0RecIndexPos(0),
56 fConvGamV0RecIndexNeg(0),
57 fnDecayLGeant(-1),
58 flDecayLGeantIndex(0),
59 fpiNegDecayLGeantIndex(0),
60 fpPosDecayLGeantIndex(0),
61 fpiNegDecayLGeantLength(0),
62 fpPosDecayLGeantLength(0),
63 fpiNegDecayLSingleRecIndex(0),
64 fpPosDecayLSingleRecIndex(0),
65 fpiNegDecayLV0RecIndex(0),
66 fpPosDecayLV0RecIndex(0),
67 fDecayLV0RecIndexPos(0),
68 fDecayLV0RecIndexNeg(0),
69 fnDecayALGeant(-1),
70 falDecayALGeantIndex(0),
71 fpiPosDecayALGeantIndex(0),
72 fapNegDecayALGeantIndex(0),
73 fpiPosDecayALGeantLength(0),
74 fapNegDecayALGeantLength(0),
75 fpiPosDecayALSingleRecIndex(0),
76 fapNegDecayALSingleRecIndex(0),
77 fpiPosDecayALV0RecIndex(0),
78 fapNegDecayALV0RecIndex(0),
79 fDecayALV0RecIndexPos(0),
80 fDecayALV0RecIndexNeg(0),
81 fnDecayK0Geant(-1),
82 fK0DecayK0GeantIndex(0),
83 fpiNegDecayK0GeantIndex(0),
84 fpiPosDecayK0GeantIndex(0),
85 fpiNegDecayK0GeantLength(0),
86 fpiPosDecayK0GeantLength(0),
87 fpiNegDecayK0SingleRecIndex(0),
88 fpiPosDecayK0SingleRecIndex(0),
89 fpiNegDecayK0V0RecIndex(0),
90 fpiPosDecayK0V0RecIndex(0),
91 fDecayK0V0RecIndexPos(0),
92 fDecayK0V0RecIndexNeg(0),
93 fpiPosK0Index(-1),
94 fpiNegK0Index(-1),
95 fnTracksPrim(-1),
96 ftpcRefit(0),
97 fitsRefit(0),
98 ftrdRefit(0),
99 ftrdOut(0),
100 fDim(37),
101 fValueL(0),
102 fValueAL(0),
103 fValueK0(0),
104 fValueV0(0),
105 fxminV0(0),
106 fxmaxV0(0),
107 fbinsV0(0),
108 fRefTPC(0),
109 fclRefsN(0),
110 fclRefsP(0)
111
112  {
113   // Default Constructor.
114
115  }
116
117 //________________________________________________________________________
118 AliAnalysisTaskV0QA::AliAnalysisTaskV0QA(const char *name) :AliAnalysisTaskSE(name), 
119 fESD(0), 
120 fStack(0),
121 fMCtruth(0),
122 fChain(0),
123 fOutputContainer(0),
124 fSparseV0(0),
125 fSparseK0(0),
126 fSparseL(0),
127 fSparseAL(0),
128 fnEv(0),
129 fgDim(50),
130 fnConvGamGeant(-1),
131 fgConvGamGeantIndex(0),
132 feNegConvGamGeantIndex(0),
133 fePosConvGamGeantIndex(0),
134 feNegConvGamGeantLength(0),
135 fePosConvGamGeantLength(0),
136 feNegConvGamSingleRecIndex(0),
137 fePosConvGamSingleRecIndex(0),
138 feNegConvGamV0RecIndex(0),
139 fePosConvGamV0RecIndex(0),
140 fConvGamV0RecIndexPos(0),
141 fConvGamV0RecIndexNeg(0),
142 fnDecayLGeant(-1),
143 flDecayLGeantIndex(0),
144 fpiNegDecayLGeantIndex(0),
145 fpPosDecayLGeantIndex(0),
146 fpiNegDecayLGeantLength(0),
147 fpPosDecayLGeantLength(0),
148 fpiNegDecayLSingleRecIndex(0),
149 fpPosDecayLSingleRecIndex(0),
150 fpiNegDecayLV0RecIndex(0),
151 fpPosDecayLV0RecIndex(0),
152 fDecayLV0RecIndexPos(0),
153 fDecayLV0RecIndexNeg(0),
154 fnDecayALGeant(-1),
155 falDecayALGeantIndex(0),
156 fpiPosDecayALGeantIndex(0),
157 fapNegDecayALGeantIndex(0),
158 fpiPosDecayALGeantLength(0),
159 fapNegDecayALGeantLength(0),
160 fpiPosDecayALSingleRecIndex(0),
161 fapNegDecayALSingleRecIndex(0),
162 fpiPosDecayALV0RecIndex(0),
163 fapNegDecayALV0RecIndex(0),
164 fDecayALV0RecIndexPos(0),
165 fDecayALV0RecIndexNeg(0),
166 fnDecayK0Geant(-1),
167 fK0DecayK0GeantIndex(0),
168 fpiNegDecayK0GeantIndex(0),
169 fpiPosDecayK0GeantIndex(0),
170 fpiNegDecayK0GeantLength(0),
171 fpiPosDecayK0GeantLength(0),
172 fpiNegDecayK0SingleRecIndex(0),
173 fpiPosDecayK0SingleRecIndex(0),
174 fpiNegDecayK0V0RecIndex(0),
175 fpiPosDecayK0V0RecIndex(0),
176 fDecayK0V0RecIndexPos(0),
177 fDecayK0V0RecIndexNeg(0),
178 fpiPosK0Index(-1),
179 fpiNegK0Index(-1),
180 fnTracksPrim(-1),
181 ftpcRefit(0),
182 fitsRefit(0),
183 ftrdRefit(0),
184 ftrdOut(0),
185 fDim(37),
186 fValueL(0),
187 fValueAL(0),
188 fValueK0(0),
189 fValueV0(0),
190 fxminV0(0),
191 fxmaxV0(0),
192 fbinsV0(0),
193 fRefTPC(0),
194 fclRefsN(0),
195 fclRefsP(0)
196
197  {
198
199    fnEv=0;
200    fDim=37; 
201
202    fValueK0 = new Double_t[fDim];
203    fValueL = new Double_t[fDim];
204    fValueAL = new Double_t[fDim];
205    fValueV0 = new Double_t[fDim];
206    fxminV0 = new Double_t[fDim];
207    fxmaxV0 = new Double_t[fDim];
208    fbinsV0 = new Int_t[fDim];
209
210
211   fgDim=50; 
212   fgConvGamGeantIndex = new Int_t[fgDim];
213   feNegConvGamGeantIndex = new Int_t[fgDim];
214   fePosConvGamGeantIndex = new Int_t[fgDim];
215   feNegConvGamGeantLength = new Float_t[fgDim];
216   fePosConvGamGeantLength = new Float_t[fgDim];
217
218   feNegConvGamSingleRecIndex = new Int_t[fgDim];
219   fePosConvGamSingleRecIndex = new Int_t[fgDim];
220
221   feNegConvGamV0RecIndex = new Int_t[fgDim];
222   fePosConvGamV0RecIndex = new Int_t[fgDim];
223
224   fConvGamV0RecIndexPos = new Int_t[fgDim];
225   fConvGamV0RecIndexNeg = new Int_t[fgDim];
226
227   // Lambda to proton pi-
228   flDecayLGeantIndex = new Int_t[fgDim];
229   fpiNegDecayLGeantIndex = new Int_t[fgDim];
230   fpPosDecayLGeantIndex = new Int_t[fgDim];
231   fpiNegDecayLGeantLength = new Float_t[fgDim];
232   fpPosDecayLGeantLength = new Float_t[fgDim];
233
234   fpiNegDecayLSingleRecIndex = new Int_t[fgDim];
235   fpPosDecayLSingleRecIndex = new Int_t[fgDim];
236
237   fpiNegDecayLV0RecIndex = new Int_t[fgDim];
238   fpPosDecayLV0RecIndex = new Int_t[fgDim];
239
240   fDecayLV0RecIndexPos = new Int_t[fgDim];
241   fDecayLV0RecIndexNeg = new Int_t[fgDim];
242
243   //K0S to pi+ pi-
244   fK0DecayK0GeantIndex = new Int_t[fgDim];
245   fpiNegDecayK0GeantIndex = new Int_t[fgDim];
246   fpiPosDecayK0GeantIndex = new Int_t[fgDim];
247   fpiNegDecayK0GeantLength = new Float_t[fgDim];
248   fpiPosDecayK0GeantLength = new Float_t[fgDim];
249
250   fpiNegDecayK0SingleRecIndex = new Int_t[fgDim];
251   fpiPosDecayK0SingleRecIndex = new Int_t[fgDim];
252
253   fpiNegDecayK0V0RecIndex = new Int_t[fgDim];
254   fpiPosDecayK0V0RecIndex = new Int_t[fgDim];
255
256   fDecayK0V0RecIndexPos = new Int_t[fgDim];
257   fDecayK0V0RecIndexNeg = new Int_t[fgDim];
258
259   //Antilambda to antiproton piplus
260   falDecayALGeantIndex = new Int_t[fgDim];
261   fpiPosDecayALGeantIndex = new Int_t[fgDim];
262   fapNegDecayALGeantIndex = new Int_t[fgDim];
263   fpiPosDecayALGeantLength = new Float_t[fgDim];
264   fapNegDecayALGeantLength = new Float_t[fgDim];
265
266   fpiPosDecayALSingleRecIndex = new Int_t[fgDim];
267   fapNegDecayALSingleRecIndex = new Int_t[fgDim];
268
269   fpiPosDecayALV0RecIndex = new Int_t[fgDim];
270   fapNegDecayALV0RecIndex = new Int_t[fgDim];
271
272   fDecayALV0RecIndexPos = new Int_t[fgDim];
273   fDecayALV0RecIndexNeg = new Int_t[fgDim];
274
275
276  
277   fclRefsP = new TClonesArray("AliTrackReference");
278   fclRefsN = new TClonesArray("AliTrackReference");
279
280   //  SetESDtrackCuts();
281
282
283   AliLog::SetGlobalLogLevel(AliLog::kError);
284 //
285   DefineOutput(1, TList::Class());
286 }
287
288 //_____________________________________________________
289 AliAnalysisTaskV0QA::~AliAnalysisTaskV0QA()
290 {
291   // Remove all pointers
292
293
294   delete [] fclRefsP;
295   delete [] fclRefsN;
296
297
298   delete [] fValueK0;
299   delete [] fValueL;
300   delete [] fValueAL;
301   delete [] fValueV0;
302   delete [] fbinsV0;
303   delete [] fxminV0;
304   delete [] fxmaxV0;
305
306   delete [] fgConvGamGeantIndex;
307   delete [] feNegConvGamGeantIndex;
308   delete [] fePosConvGamGeantIndex;
309
310   delete [] feNegConvGamSingleRecIndex;
311   delete [] fePosConvGamSingleRecIndex;
312
313   delete [] feNegConvGamV0RecIndex;
314   delete [] fePosConvGamV0RecIndex;
315   delete [] fConvGamV0RecIndexPos;
316   delete [] fConvGamV0RecIndexNeg;
317
318   delete [] flDecayLGeantIndex;
319   delete [] fpiNegDecayLGeantIndex;
320   delete [] fpPosDecayLGeantIndex;
321
322   delete [] fpiNegDecayLGeantLength;
323   delete [] fpPosDecayLGeantLength;
324   delete [] fpiNegDecayLSingleRecIndex;
325   delete [] fpPosDecayLSingleRecIndex;
326
327   delete [] fpiNegDecayLV0RecIndex;
328   delete [] fpPosDecayLV0RecIndex;
329   delete [] fDecayLV0RecIndexPos;
330   delete [] fDecayLV0RecIndexNeg;
331
332   delete [] falDecayALGeantIndex;
333   delete [] fpiPosDecayALGeantIndex;
334   delete [] fapNegDecayALGeantIndex;
335
336   delete [] fpiPosDecayALGeantLength;
337   delete [] fapNegDecayALGeantLength;
338   delete [] fpiPosDecayALSingleRecIndex;
339   delete [] fapNegDecayALSingleRecIndex;
340
341   delete [] fpiPosDecayALV0RecIndex;
342   delete [] fapNegDecayALV0RecIndex;
343   delete [] fDecayALV0RecIndexPos;
344   delete [] fDecayALV0RecIndexNeg;
345
346
347   delete [] fpiNegDecayK0GeantIndex;
348   delete [] fpiPosDecayK0GeantIndex;
349
350   delete [] fpiNegDecayK0GeantLength;
351   delete [] fpiPosDecayK0GeantLength;
352   delete [] fpiNegDecayK0SingleRecIndex;
353   delete [] fpiPosDecayK0SingleRecIndex;
354
355   delete [] fpiNegDecayK0V0RecIndex;
356   delete [] fpiPosDecayK0V0RecIndex;
357
358   delete [] fDecayK0V0RecIndexPos;
359   delete [] fDecayK0V0RecIndexNeg;
360
361 }
362
363
364 //________________________________________________________________________
365 void AliAnalysisTaskV0QA::UserCreateOutputObjects() {
366   // Create Ouptut objects
367
368   for(Int_t d=0;d<fDim;d++){
369     fbinsV0[d]=70;
370   }
371   fxminV0[0]=   0;     // 1/sqrt(pt) Gamma geant
372   fxmaxV0[0]=   8;
373
374
375   fxminV0[1]=-2.5;   // eta Gamma Geant
376   fxmaxV0[1]= 1.5;
377
378
379   fxminV0[2]=-2*TMath::Pi();   // phi Gamma geant
380   fxmaxV0[2]= TMath::Pi();
381
382
383   fxminV0[3]=   0;     // r geant
384   fxmaxV0[3]= 200;
385
386
387   fxminV0[4]=-250;   // z geant
388   fxmaxV0[4]= 250;
389
390
391   fxminV0[5]=   0;     // 1/sqrt(pt) Geant Pos
392   fxmaxV0[5]=   8;
393
394
395   fxminV0[6]=-2.5;   // eta geant Pos
396   fxmaxV0[6]= 1.5;
397
398
399   fxminV0[7]=-2*TMath::Pi();   // phi Geant Pos
400   fxmaxV0[7]= TMath::Pi();
401
402   
403   fxminV0[8]=0;   // Track Length TPC Geant Pos
404   fxmaxV0[8]= 200;
405
406
407   fxminV0[9]=   0;     // 1/sqrt(pt) Geant Neg
408   fxmaxV0[9]=   8;
409
410
411   fxminV0[10]=-2.5;   // eta Geant Neg
412   fxmaxV0[10]= 1.5;
413
414
415   fxminV0[11]=-2*TMath::Pi();   // phi Geant Neg
416   fxmaxV0[11]= TMath::Pi();
417
418
419   fxminV0[12]=0;   // Track Length TPC Geant Neg
420   fxmaxV0[12]= 200;
421
422
423
424   //-----------Rec single variables
425
426   fxminV0[13]=   -0.5;     // (pt-ptGeant)/ptGeant rec Pos
427   fxmaxV0[13]=   0.5;
428
429
430   fxminV0[14]=-2.5;   // eta  rec Pos
431   fxmaxV0[14]= 1.5;
432
433
434   fxminV0[15]=-2*TMath::Pi();   // phi rec Pos
435   fxmaxV0[15]= TMath::Pi();
436
437
438   fxminV0[16]=   0;     // Impact parameter rec Pos
439   fxmaxV0[16]=   100;
440
441
442   fxminV0[17]=   0;     // nsigmas Impact parameter rec Pos
443   fxmaxV0[17]=   100;
444
445
446
447   fxminV0[18]=   -1;     // Ncls ITS rec Pos
448   fxmaxV0[18]=   6;
449
450
451   fxminV0[19]=   -1;     // Ncls TPC rec Pos
452   fxmaxV0[19]=   180;
453
454
455   fxminV0[20]=   -2;     // Status Single  TPC rec Pos
456   fxmaxV0[20]=   2;
457
458
459   fxminV0[21]=   -0.5;     // (pt-ptGeant)/ptGeant rec Neg
460   fxmaxV0[21]=   0.5;
461
462
463   fxminV0[22]=-2.5;   // eta  rec Neg
464   fxmaxV0[22]= 1.5;
465
466
467   fxminV0[23]=-2*TMath::Pi();   // phi rec Neg
468   fxmaxV0[23]= TMath::Pi();
469
470
471   fxminV0[24]=   0;     // Impact parameter rec Neg
472   fxmaxV0[24]=   100;
473
474
475   fxminV0[25]=   0;     // Sigmas Impact parameter rec Neg
476   fxmaxV0[25]=   100;
477
478
479
480   fxminV0[26]=   -1;     // Ncls ITS rec Neg
481   fxmaxV0[26]=   6;
482
483
484   fxminV0[27]=   -1;     // Ncls TPC rec Neg
485   fxmaxV0[27]=   180;
486
487
488   fxminV0[28]=   -2;     // Status Single  TPC rec Neg
489   fxmaxV0[28]=   2;
490
491   // ------------------Rec V0 variables
492
493
494
495   fxminV0[29]=   -0.5;     // (pt-ptGeant)/ptGeant rec V0 Pos
496   fxmaxV0[29]=   0.5;
497
498
499   fxminV0[30]=-2.5;   // eta  rec V0 Pos
500   fxmaxV0[30]= 1.5;
501
502
503   fxminV0[31]=-2*TMath::Pi();   // phi rec V0 Pos
504   fxmaxV0[31]= TMath::Pi();
505
506
507   fxminV0[32]=   -2;     // Status V0 TPC rec Pos
508   fxmaxV0[32]=   2;
509
510
511
512
513   fxminV0[33]=   -0.5;     // 1/sqrt(pt) rec V0 Neg
514   fxmaxV0[33]=   0.5;
515
516
517   fxminV0[34]=-2.5;   // eta  rec V0 Neg
518   fxmaxV0[34]= 1.5;
519
520
521   fxminV0[35]=-2*TMath::Pi();   // phi rec V0 Neg
522   fxmaxV0[35]= TMath::Pi();
523
524
525
526   fxminV0[36]=   -2;     // Status V0 TPC rec Neg
527   fxmaxV0[36]=   2;
528
529
530
531   TString  axisName[37]={"ptGammaGeant", 
532                          "etaGammaGeant",
533                          "phiGammaGeant",
534                          "rGeant",
535                          "zGeant",
536                          "ptEPlusGeant",  
537                          "etaEPlusGeant",
538                          "phiEPlusGeant",
539                          "TPCTrackLengthEPlusGeant",
540                          "ptEMinusGeant", 
541                          "etaEMinusGeant",
542                          "phiEMinusGeant",
543                          "TPCTrackLengthEMinusGeant",
544                          "ptResEPlusRecSingle", 
545                          "etaEPlusRecSingle",
546                          "phiEPlusRecSingle",
547                          "bXYZEPlusRecSingle",
548                          "sigbXYZEPlusRecSingle",
549                          "NclsITSEPlusRecSingle",
550                          "NclsTPCEPlusRecSingle",
551                          "statusRecSinglePos",
552                          "ptResEMinusRecSingle", 
553                          "etaEMinusRecSingle",
554                          "phiEMinusRecSingle",
555                          "bXYZEMinusRecSingle",
556                          "sigbXYZEMinusRecSingle",
557                          "NclsITSEMinusRecSingle",
558                          "NclsTPCEMinusRecSingle",
559                          "statusRecSingleNeg",
560                          "ptResEPlusRecV0", 
561                          "etaEPlusRecV0",
562                          "phiEPlusRecV0",
563                          "statusV0SinglePos",
564                          "ptResEMinusRecV0", 
565                          "etaEMinusRecV0",
566                          "phiEMinusRecV0",
567                          "statusV0SingleNeg"};
568
569
570   fSparseV0= new THnSparseF("sparseV0","sparseV0",fDim,fbinsV0,fxminV0,fxmaxV0);
571
572   for (Int_t iaxis=0; iaxis<fDim; iaxis++){
573    fSparseV0->GetAxis(iaxis)->SetName(axisName[iaxis]);
574    fSparseV0->GetAxis(iaxis)->SetTitle(axisName[iaxis]);
575   }
576
577   TString  axisNameK0[37]={"ptK0Geant", 
578                          "etaK0Geant",
579                          "phiK0Geant",
580                          "rGeant",
581                          "zGeant",
582                          "ptPiPlusGeant",  
583                          "etaPiPlusGeant",
584                          "phiPiPlusGeant",
585                          "TPCTrackLengthPiPlusGeant",
586                          "ptPiMinusGeant", 
587                          "etaPiMinusGeant",
588                          "phiPiMinusGeant",
589                          "TPCTrackLengthPiMinusGeant",
590                          "ptResPiPlusRecSingle", 
591                          "etaPiPlusRecSingle",
592                          "phiPiPlusRecSingle",
593                          "bXYZPiPlusRecSingle",
594                          "sigbXYZPiPlusRecSingle",
595                          "NclsITSPiPlusRecSingle",
596                          "NclsTPCPiPlusRecSingle",
597                          "statusRecSinglePos",
598                          "ptResPiMinusRecSingle", 
599                          "etaPiMinusRecSingle",
600                          "phiPiMinusRecSingle",
601                          "bXYZPiMinusRecSingle",
602                          "sigbXYZPiMinusRecSingle",
603                          "NclsITSPiMinusRecSingle",
604                          "NclsTPCPiMinusRecSingle",
605                          "statusRecSingleNeg",
606                          "ptResPiPlusRecV0", 
607                          "etaPiPlusRecV0",
608                          "phiPiPlusRecV0",
609                          "statusRecV0Pos",
610                          "ptResPiMinusRecV0", 
611                          "etaPiMinusRecV0",
612                          "phiPiMinusRecV0",
613                          "statusRecV0Neg"};
614
615
616
617   fSparseK0= new THnSparseF("sparseK0","sparseK0",fDim,fbinsV0,fxminV0,fxmaxV0);
618   for (Int_t iaxis=0; iaxis<fDim; iaxis++){
619    fSparseK0->GetAxis(iaxis)->SetName(axisNameK0[iaxis]);
620    fSparseK0->GetAxis(iaxis)->SetTitle(axisNameK0[iaxis]);
621   }
622
623   TString  axisNameL[37]={"ptLGeant", 
624                          "etaLGeant",
625                          "phiLGeant",
626                          "rGeant",
627                          "zGeant",
628                          "ptPPlusGeant",  
629                          "etaPPlusGeant",
630                          "phiPPlusGeant",
631                          "TPCTrackLengthPPlusGeant",
632                          "ptPiMinusGeant", 
633                          "etaPiMinusGeant",
634                          "phiPiMinusGeant",
635                          "TPCTrackLengthPiMinusGeant",
636                          "ptResPPlusRecSingle", 
637                          "etaPPlusRecSingle",
638                          "phiPPlusRecSingle",
639                          "bXYZPPlusRecSingle",
640                          "sigbXYZPPlusRecSingle",
641                          "NclsITSPPlusRecSingle",
642                          "NclsTPCPPlusRecSingle",
643                          "statusRecSinglePos",
644                          "ptResPiMinusRecSingle", 
645                          "etaPiMinusRecSingle",
646                          "phiPiMinusRecSingle",
647                          "bXYZPiMinusRecSingle",
648                          "sigbXYZPiMinusRecSingle",
649                          "NclsITSPiMinusRecSingle",
650                          "NclsTPCPiMinusRecSingle",
651                          "statusRecSingleNeg",
652                          "ptResPPlusRecV0", 
653                          "etaPPlusRecV0",
654                          "phiPPlusRecV0",
655                          "statusRecV0Pos",
656                          "ptResPiMinusRecV0", 
657                          "etaPiMinusRecV0",
658                          "phiPiMinusRecV0",
659                          "statusRecV0Neg"};
660
661
662   fSparseL= new THnSparseF("sparseL","sparseL",fDim,fbinsV0,fxminV0,fxmaxV0);
663   for (Int_t iaxis=0; iaxis<fDim; iaxis++){
664    fSparseL->GetAxis(iaxis)->SetName(axisNameL[iaxis]);
665    fSparseL->GetAxis(iaxis)->SetTitle(axisNameL[iaxis]);
666   }
667
668   TString  axisNameAL[37]={"ptALGeant", 
669                          "etaALGeant",
670                          "phiALGeant",
671                          "rGeant",
672                          "zGeant",
673                          "ptPiPluusGeant",  
674                          "etaPiPlusGeant",
675                          "phiPiPlusGeant",
676                          "TPCTrackLengthPiPlusGeant",
677                          "ptAPMinusGeant", 
678                          "etaAPMinusGeant",
679                          "phiAPMinusGeant",
680                          "TPCTrackLengthAPMinusGeant",
681                          "ptResPiPlusRecSingle", 
682                          "etaPiPlusRecSingle",
683                          "phiPiPlusRecSingle",
684                          "bXYZPiPlusRecSingle",
685                          "sigbXYZPiPlusRecSingle",
686                          "NclsITSPiPlusRecSingle",
687                          "NclsTPCPiPlusRecSingle",
688                          "statusRecSinglePos",
689                          "ptResAPMinusRecSingle", 
690                          "etaAPMinusRecSingle",
691                          "phiAPMinusRecSingle",
692                          "bXYZAPMinusRecSingle",
693                          "sigbXYZAPMinusRecSingle",
694                          "NclsITSAPMinusRecSingle",
695                          "NclsTPCAPMinusRecSingle",
696                          "statusRecSingleNeg",
697                          "ptResPiPlusRecV0", 
698                          "etaPiPlusRecV0",
699                          "phiPiPlusRecV0",
700                          "statusRecV0Pos",
701                          "ptResAPMinusRecV0", 
702                          "etaAPMinusRecV0",
703                          "phiAPMinusRecV0",
704                          "statusRecV0Neg"};
705
706
707   fSparseAL= new THnSparseF("sparseAL","sparseAL",fDim,fbinsV0,fxminV0,fxmaxV0);
708   for (Int_t iaxis=0; iaxis<fDim; iaxis++){
709    fSparseAL->GetAxis(iaxis)->SetName(axisNameAL[iaxis]);
710    fSparseAL->GetAxis(iaxis)->SetTitle(axisNameAL[iaxis]);
711   }
712
713   // create output container
714  
715   fOutputContainer = new TList() ;
716   fOutputContainer->SetName(GetName()) ;
717
718
719   fOutputContainer->Add(fSparseV0);
720   fOutputContainer->Add(fSparseK0);
721   fOutputContainer->Add(fSparseL);
722   fOutputContainer->Add(fSparseAL);
723   
724 }
725
726 //________________________________________________________________________
727 void AliAnalysisTaskV0QA::UserExec(Option_t *) {
728   // Execution of the Task
729
730     fESD = dynamic_cast<AliESDEvent*>(InputEvent());
731     
732   if (!fESD) {
733     //cout<< "not a tree"<< endl;
734     return;
735   }
736
737   fnEv++;
738
739
740   //Get MC data 
741   fMCtruth = (AliMCEventHandler*)((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
742
743   //  Double_t vertex[3];
744   Double_t maxVertex=150.;
745   Double_t maxEta=1.2;
746   Double_t lineCutZRSlope=0.662486;
747   Double_t lineCutZValue=7.;
748   Int_t elecGIndex=-1;
749   Int_t posiGIndex=-1;
750   Int_t pPosLIndex=-1;
751   Int_t piNegLIndex=-1;
752
753   Int_t apNegALIndex=-1;
754   Int_t piPosALIndex=-1;
755
756   fnConvGamGeant=-1;
757   fnDecayK0Geant=-1;
758   fnDecayLGeant=-1;
759   fnDecayALGeant=-1;
760
761   for(Int_t i=0; i<fgDim;i++){
762     fgConvGamGeantIndex[i] = -1;
763     feNegConvGamGeantIndex[i] = -1;
764     fePosConvGamGeantIndex[i] = -1;
765     
766     feNegConvGamSingleRecIndex[i] = -1;
767     fePosConvGamSingleRecIndex[i] = -1;
768
769     feNegConvGamV0RecIndex[i] = -1;
770     fePosConvGamV0RecIndex[i] = -1;
771     fConvGamV0RecIndexPos[i] = -1;
772     fConvGamV0RecIndexNeg[i] = -1;
773
774
775     fK0DecayK0GeantIndex[i] = -1;
776     fpiNegDecayK0GeantIndex[i] = -1;
777     fpiPosDecayK0GeantIndex[i] = -1;
778     
779     fpiNegDecayK0SingleRecIndex[i] = -1;
780     fpiPosDecayK0SingleRecIndex[i] = -1;
781
782     fpiNegDecayK0V0RecIndex[i] = -1;
783     fpiPosDecayK0V0RecIndex[i] = -1;
784     fDecayK0V0RecIndexPos[i] = -1;
785     fDecayK0V0RecIndexNeg[i] = -1;
786
787
788     flDecayLGeantIndex[i] = -1;
789     fpiNegDecayLGeantIndex[i] = -1;
790     fpPosDecayLGeantIndex[i] = -1;
791     
792     fpiNegDecayLSingleRecIndex[i] = -1;
793     fpPosDecayLSingleRecIndex[i] = -1;
794
795     fpiNegDecayLV0RecIndex[i] = -1;
796     fpPosDecayLV0RecIndex[i] = -1;
797     fDecayLV0RecIndexPos[i] = -1;
798     fDecayLV0RecIndexNeg[i] = -1;
799
800     // Antilambda
801     falDecayALGeantIndex[i] = -1;
802     fpiPosDecayALGeantIndex[i] = -1;
803     fapNegDecayALGeantIndex[i] = -1;
804     
805     fpiPosDecayALSingleRecIndex[i] = -1;
806     fapNegDecayALSingleRecIndex[i] = -1;
807
808     fpiPosDecayALV0RecIndex[i] = -1;
809     fapNegDecayALV0RecIndex[i] = -1;
810     fDecayALV0RecIndexPos[i] = -1;
811     fDecayALV0RecIndexNeg[i] = -1;
812
813
814   }
815
816   Int_t doMC=1;
817
818   AliKFVertex primVtx(*(fESD->GetPrimaryVertex()));
819   fnTracksPrim=primVtx.GetNContributors();
820
821
822   if(fMCtruth && fnTracksPrim>0){
823
824    fStack = fMCtruth->MCEvent()->Stack();
825
826
827    if ( doMC){
828
829     for (Int_t iTracks = 0; iTracks < fMCtruth->MCEvent()->GetNumberOfTracks(); iTracks++) {
830       
831
832      TParticle* particle = fStack->Particle(iTracks);
833
834
835
836      if (!particle) {
837        Printf("ERROR: Could not receive particle %d (mc loop)", iTracks);
838        continue;
839      }
840      
841      if(particle->Pt()<0.050) continue;
842      if(TMath::Abs(particle->Eta())> 1.2) continue;
843
844      
845      if (particle->GetPdgCode()== 22){
846        
847        
848        if(particle->GetMother(0) >-1 && fStack->Particle(particle->GetMother(0))->GetPdgCode() == 22){
849          continue; // no photon as mothers!
850        }
851        
852        if(particle->GetMother(0) >= fStack->GetNprimary()){
853          continue; // the gamma has a mother, and it is not a primary particle
854        }
855        
856        TParticle* ePos = NULL;
857        TParticle* eNeg = NULL;
858        elecGIndex=-1;
859        posiGIndex=-1;
860   
861        if(particle->GetNDaughters() >= 2){
862          for(Int_t daughterIndex=particle->GetFirstDaughter();daughterIndex<=particle->GetLastDaughter();daughterIndex++){
863            TParticle *tmpDaughter = fStack->Particle(daughterIndex);
864            if(tmpDaughter->GetUniqueID() == 5){
865              if(tmpDaughter->GetPdgCode() == 11){
866                eNeg = tmpDaughter;
867                elecGIndex=daughterIndex;
868              }
869              else if(tmpDaughter->GetPdgCode() == -11){
870                ePos = tmpDaughter;
871                posiGIndex=daughterIndex;
872              }
873            }
874          }
875        }
876        
877        
878        if(ePos == NULL || eNeg == NULL){ // means we do not have two daughters from pair production
879          continue;
880        }
881        
882        if(TMath::Abs(ePos->Eta())> maxEta || TMath::Abs(eNeg->Eta())> maxEta){
883          continue;
884        }        
885        
886        if(ePos->R()> maxVertex ){
887          continue; // cuts on distance from collision point
888        }
889       
890       
891        if( (TMath::Abs(ePos->Vz()) * lineCutZRSlope - lineCutZValue)  > ePos->R() ){
892          continue;               // line cut to exclude regions where we do not reconstruct
893        }                
894
895        
896        // Looking at the existance of TPC references
897
898        TParticle* ePosTPC;
899        fMCtruth->MCEvent()->GetParticleAndTR(posiGIndex,ePosTPC,fclRefsP);
900
901        AliMCParticle *mcParticlePos = (AliMCParticle*) (fMCtruth->MCEvent()->GetTrack(posiGIndex));
902        if(!mcParticlePos) continue;
903
904        Int_t counter; 
905        Float_t tpcTrackLengthePos = mcParticlePos->GetTPCTrackLength(fESD->GetMagneticField(),0.05,counter,3.0); 
906
907  
908
909        int nPointsP =  fclRefsP->GetEntries();
910
911        if (fRefTPC) delete fRefTPC;fRefTPC=NULL;
912        fRefTPC = new TObjArray();
913
914        for(int iPoint=0; iPoint<nPointsP; iPoint++) {
915          AliTrackReference *ref = (AliTrackReference*)fclRefsP->At(iPoint);
916          if (ref->DetectorId() == AliTrackReference::kTPC) fRefTPC->Add(new AliTrackReference(*ref));    
917        }
918
919        fRefTPC->Sort();
920
921        for(int i=0; i<fRefTPC->GetEntries(); i++) {
922          AliTrackReference *ref = (AliTrackReference*)(*fRefTPC)[i]; 
923          fLabelsTPC[i] = ref->GetTrack();
924        }
925        int labelPosRefs=0;
926        for(int iPoint=GetTPCReference(iTracks);iPoint<fRefTPC->GetEntries();iPoint++){
927          AliTrackReference* aRef = (AliTrackReference*)(*fRefTPC)[iPoint];
928          if (aRef->GetTrack() != posiGIndex ) break;                    
929          ++labelPosRefs;
930        }
931      
932
933
934
935        TParticle* eNegTPC;
936        fMCtruth->MCEvent()->GetParticleAndTR(elecGIndex,eNegTPC,fclRefsN);
937
938        AliMCParticle *mcParticleNeg = (AliMCParticle*) (fMCtruth->MCEvent()->GetTrack(elecGIndex));
939        if(!mcParticleNeg) continue;
940
941        Int_t counterN; 
942        Float_t tpcTrackLengtheNeg = mcParticleNeg->GetTPCTrackLength(fESD->GetMagneticField(),0.05,counterN,3.0); 
943        int nPointsN =  fclRefsN->GetEntries();
944
945        if (fRefTPC) delete fRefTPC; fRefTPC=NULL;
946        fRefTPC = new TObjArray();
947
948        for(int iPoint=0; iPoint<nPointsN; iPoint++) {
949          AliTrackReference *ref = (AliTrackReference*)fclRefsN->At(iPoint);
950          if (ref->DetectorId() == AliTrackReference::kTPC) fRefTPC->Add(new AliTrackReference(*ref));    
951        }
952
953        fRefTPC->Sort();
954
955        for(int i=0; i<fRefTPC->GetEntries(); i++) {
956          AliTrackReference *ref = (AliTrackReference*)(*fRefTPC)[i]; 
957          fLabelsTPC[i] = ref->GetTrack();
958        }
959        int labelNegRefs=0;
960        for(int iPoint=GetTPCReference(iTracks);iPoint<fRefTPC->GetEntries();iPoint++){
961          AliTrackReference* aRef = (AliTrackReference*)(*fRefTPC)[iPoint];
962          if (aRef->GetTrack() != elecGIndex ) break;                    
963          ++labelNegRefs;
964        }
965
966
967        
968        if ( labelNegRefs==0 || labelPosRefs==0) continue; // if e+/e- do not have a TPC ref continue;
969        ////////////////////////////////////////////////////////////////////
970        
971        
972        fnConvGamGeant++;
973        fgConvGamGeantIndex[fnConvGamGeant]=iTracks;
974        feNegConvGamGeantIndex[fnConvGamGeant] = elecGIndex;
975        fePosConvGamGeantIndex[fnConvGamGeant] = posiGIndex;
976        
977        feNegConvGamGeantLength[fnConvGamGeant] = tpcTrackLengtheNeg;
978        fePosConvGamGeantLength[fnConvGamGeant] = tpcTrackLengthePos;
979
980      }
981
982      
983      TParticle* piPos = NULL;
984      TParticle* piNeg = NULL;
985      fpiPosK0Index=-1;
986      fpiNegK0Index=-1;
987
988      if (particle->GetPdgCode()== 310){          // k0short
989        if(particle->GetNDaughters() == 2){
990          for(Int_t daughterIndex=particle->GetFirstDaughter();daughterIndex<=particle->GetLastDaughter();daughterIndex++){
991            TParticle *tmpDaughter = fStack->Particle(daughterIndex);
992            if(tmpDaughter->GetPdgCode() == 211){
993              piPos= tmpDaughter;
994              fpiPosK0Index=daughterIndex;
995            }
996            else if(tmpDaughter->GetPdgCode() == -211){
997              piNeg = tmpDaughter;
998              fpiNegK0Index=daughterIndex;
999            }
1000          }
1001        }
1002
1003        if(piPos == NULL || piNeg == NULL){ // means we do not have two daughters from K0short decay
1004          continue;
1005        }
1006        
1007        if(TMath::Abs(piPos->Eta())> maxEta || TMath::Abs(piNeg->Eta())> maxEta){
1008          continue;
1009        }        
1010        
1011        if(piPos->R()> maxVertex ){
1012          continue; // cuts on distance from collision point
1013        }
1014       
1015       
1016        if( (TMath::Abs(piPos->Vz()) * lineCutZRSlope - lineCutZValue)  > piPos->R() ){
1017          continue;               // line cut to exclude regions where we do not reconstruct
1018        }                
1019
1020       // Looking at the existance of TPC references
1021
1022        TParticle* ePosTPC;
1023        fMCtruth->MCEvent()->GetParticleAndTR(fpiPosK0Index,ePosTPC,fclRefsP);
1024
1025        AliMCParticle *mcParticlePos = (AliMCParticle*) (fMCtruth->MCEvent()->GetTrack(fpiPosK0Index));
1026        if(!mcParticlePos) continue;
1027
1028        Int_t counter; 
1029        Float_t tpcTrackLengthePos = mcParticlePos->GetTPCTrackLength(fESD->GetMagneticField(),0.05,counter,3.0); 
1030  
1031
1032        int nPointsP =  fclRefsP->GetEntries();
1033        if (fRefTPC) delete fRefTPC; fRefTPC=NULL;
1034        fRefTPC = new TObjArray();
1035
1036        for(int iPoint=0; iPoint<nPointsP; iPoint++) {
1037          AliTrackReference *ref = (AliTrackReference*)fclRefsP->At(iPoint);
1038          if (ref->DetectorId() == AliTrackReference::kTPC) fRefTPC->Add(new AliTrackReference(*ref));    
1039        }
1040
1041        fRefTPC->Sort();
1042
1043        for(int i=0; i<fRefTPC->GetEntries(); i++) {
1044          AliTrackReference *ref = (AliTrackReference*)(*fRefTPC)[i]; 
1045          fLabelsTPC[i] = ref->GetTrack();
1046        }
1047        int labelPosRefs=0;
1048        for(int iPoint=GetTPCReference(iTracks);iPoint<fRefTPC->GetEntries();iPoint++){
1049          AliTrackReference* aRef = (AliTrackReference*)(*fRefTPC)[iPoint];
1050          if (aRef->GetTrack() != fpiPosK0Index ) break;                 
1051          ++labelPosRefs;
1052        }
1053      
1054
1055
1056
1057        TParticle* eNegTPC;
1058        fMCtruth->MCEvent()->GetParticleAndTR(fpiNegK0Index,eNegTPC,fclRefsN);
1059
1060        AliMCParticle *mcParticleNeg = (AliMCParticle*) (fMCtruth->MCEvent()->GetTrack(fpiNegK0Index));
1061        if(!mcParticleNeg) continue;
1062
1063        Int_t counterN; 
1064        Float_t tpcTrackLengtheNeg = mcParticleNeg->GetTPCTrackLength(fESD->GetMagneticField(),0.05,counterN,3.0); 
1065
1066        int nPointsN =  fclRefsN->GetEntries();
1067        if (fRefTPC) delete fRefTPC; fRefTPC=NULL;
1068        fRefTPC = new TObjArray();
1069
1070        for(int iPoint=0; iPoint<nPointsN; iPoint++) {
1071          AliTrackReference *ref = (AliTrackReference*)fclRefsN->At(iPoint);
1072          if (ref->DetectorId() == AliTrackReference::kTPC) fRefTPC->Add(new AliTrackReference(*ref));    
1073        }
1074
1075        fRefTPC->Sort();
1076
1077        for(int i=0; i<fRefTPC->GetEntries(); i++) {
1078          AliTrackReference *ref = (AliTrackReference*)(*fRefTPC)[i]; 
1079          fLabelsTPC[i] = ref->GetTrack();
1080        }
1081        int labelNegRefs=0;
1082        for(int iPoint=GetTPCReference(iTracks);iPoint<fRefTPC->GetEntries();iPoint++){
1083          AliTrackReference* aRef = (AliTrackReference*)(*fRefTPC)[iPoint];
1084          if (aRef->GetTrack() != fpiNegK0Index ) break;                 
1085          ++labelNegRefs;
1086        }
1087        
1088        if ( labelNegRefs==0 || labelPosRefs==0) continue; // if pi+/pi- do not have a TPC ref continue;
1089        ////////////////////////////////////////////////////////////////////
1090        
1091        fnDecayK0Geant++;
1092
1093        fK0DecayK0GeantIndex[fnDecayK0Geant]=iTracks;
1094        fpiNegDecayK0GeantIndex[fnDecayK0Geant]=fpiNegK0Index;
1095        fpiPosDecayK0GeantIndex[fnDecayK0Geant]=fpiPosK0Index;
1096        fpiNegDecayK0GeantLength[fnDecayK0Geant]=tpcTrackLengtheNeg;
1097        fpiPosDecayK0GeantLength[fnDecayK0Geant]=tpcTrackLengthePos;
1098       
1099      }    
1100
1101
1102      TParticle* pPos = NULL;
1103      TParticle* piNegL = NULL;
1104      pPosLIndex=-1;
1105      piNegLIndex=-1;
1106
1107  
1108      if (particle->GetPdgCode()== 3122){        //lambda
1109       
1110        if(particle->GetNDaughters() == 2){
1111          for(Int_t daughterIndex=particle->GetFirstDaughter();daughterIndex<=particle->GetLastDaughter();daughterIndex++){
1112            TParticle *tmpDaughter = fStack->Particle(daughterIndex);
1113            if(tmpDaughter->GetPdgCode() == 2212){
1114              pPos= tmpDaughter;
1115              pPosLIndex=daughterIndex;
1116            }
1117            else if(tmpDaughter->GetPdgCode() == -211){
1118              piNegL = tmpDaughter;
1119              piNegLIndex=daughterIndex;
1120            }
1121          }
1122        }
1123
1124        if(pPos == NULL || piNegL == NULL){ // means we do not have two daughters from lambda decay
1125          continue;
1126        }
1127
1128        if(TMath::Abs(pPos->Eta())> maxEta || TMath::Abs(piNegL->Eta())> maxEta){
1129          continue;
1130        }        
1131        
1132        if(pPos->R()> maxVertex ){
1133          continue; // cuts on distance from collision point
1134        }
1135       
1136       
1137        if( (TMath::Abs(pPos->Vz()) * lineCutZRSlope - lineCutZValue)  > pPos->R() ){
1138          continue;               // line cut to exclude regions where we do not reconstruct
1139        }
1140
1141
1142      // Looking at the existance of TPC references
1143
1144        TParticle* ePosTPC;
1145        fMCtruth->MCEvent()->GetParticleAndTR(pPosLIndex,ePosTPC,fclRefsP);
1146
1147        AliMCParticle *mcParticlePos = (AliMCParticle*) (fMCtruth->MCEvent()->GetTrack(pPosLIndex));
1148        if(!mcParticlePos) continue;
1149
1150        Int_t counter; 
1151        Float_t tpcTrackLengthePos = mcParticlePos->GetTPCTrackLength(fESD->GetMagneticField(),0.05,counter,3.0); 
1152  
1153
1154        int nPointsP =  fclRefsP->GetEntries();
1155        if (fRefTPC) delete fRefTPC; fRefTPC=NULL;
1156        fRefTPC = new TObjArray();
1157
1158        for(int iPoint=0; iPoint<nPointsP; iPoint++) {
1159          AliTrackReference *ref = (AliTrackReference*)fclRefsP->At(iPoint);
1160          if (ref->DetectorId() == AliTrackReference::kTPC) fRefTPC->Add(new AliTrackReference(*ref));    
1161        }
1162
1163        fRefTPC->Sort();
1164
1165        for(int i=0; i<fRefTPC->GetEntries(); i++) {
1166          AliTrackReference *ref = (AliTrackReference*)(*fRefTPC)[i]; 
1167          fLabelsTPC[i] = ref->GetTrack();
1168        }
1169        int labelPosRefs=0;
1170        for(int iPoint=GetTPCReference(iTracks);iPoint<fRefTPC->GetEntries();iPoint++){
1171          AliTrackReference* aRef = (AliTrackReference*)(*fRefTPC)[iPoint];
1172          if (aRef->GetTrack() != pPosLIndex ) break;                    
1173          ++labelPosRefs;
1174        }
1175      
1176
1177
1178
1179        TParticle* eNegTPC;
1180        fMCtruth->MCEvent()->GetParticleAndTR(piNegLIndex,eNegTPC,fclRefsN);
1181
1182        AliMCParticle *mcParticleNeg = (AliMCParticle*) (fMCtruth->MCEvent()->GetTrack(piNegLIndex));
1183        if(!mcParticleNeg) continue;
1184
1185        Int_t counterN; 
1186        Float_t tpcTrackLengtheNeg = mcParticleNeg->GetTPCTrackLength(fESD->GetMagneticField(),0.05,counterN,3.0); 
1187
1188        int nPointsN =  fclRefsN->GetEntries();
1189        if (fRefTPC) delete fRefTPC;
1190        fRefTPC = new TObjArray();
1191
1192        for(int iPoint=0; iPoint<nPointsN; iPoint++) {
1193          AliTrackReference *ref = (AliTrackReference*)fclRefsN->At(iPoint);
1194          if (ref->DetectorId() == AliTrackReference::kTPC) fRefTPC->Add(new AliTrackReference(*ref));    
1195        }
1196
1197        fRefTPC->Sort();
1198
1199        for(int i=0; i<fRefTPC->GetEntries(); i++) {
1200          AliTrackReference *ref = (AliTrackReference*)(*fRefTPC)[i]; 
1201          fLabelsTPC[i] = ref->GetTrack();
1202        }
1203        int labelNegRefs=0;
1204        for(int iPoint=GetTPCReference(iTracks);iPoint<fRefTPC->GetEntries();iPoint++){
1205          AliTrackReference* aRef = (AliTrackReference*)(*fRefTPC)[iPoint];
1206          if (aRef->GetTrack() != piNegLIndex ) break;                   
1207          ++labelNegRefs;
1208        }
1209        
1210        if ( labelNegRefs==0 || labelPosRefs==0) continue; // if proton/pi- do not have a TPC ref continue;
1211        ////////////////////////////////////////////////////////////////////
1212      
1213        fnDecayLGeant++;
1214
1215        flDecayLGeantIndex[fnDecayLGeant]=iTracks;
1216      
1217        fpiNegDecayLGeantIndex[fnDecayLGeant]=piNegLIndex;
1218        fpPosDecayLGeantIndex[fnDecayLGeant]=pPosLIndex;
1219
1220        fpiNegDecayLGeantLength[fnDecayLGeant]=tpcTrackLengtheNeg;
1221        fpPosDecayLGeantLength[fnDecayLGeant]=tpcTrackLengthePos;
1222
1223      
1224      }
1225
1226      /////////////////////////////////////////////////////
1227
1228      // AntiLambda    
1229      TParticle* apNeg = NULL;
1230      TParticle* piPosAL = NULL;
1231      apNegALIndex=-1;
1232      piPosALIndex=-1;
1233
1234  
1235      if (particle->GetPdgCode()== -3122){        //antilambda
1236
1237        if(particle->GetNDaughters() == 2){
1238          for(Int_t daughterIndex=particle->GetFirstDaughter();daughterIndex<=particle->GetLastDaughter();daughterIndex++){
1239            TParticle *tmpDaughter = fStack->Particle(daughterIndex);
1240            if(tmpDaughter->GetPdgCode() == -2212){
1241              apNeg= tmpDaughter;
1242              apNegALIndex=daughterIndex;
1243            }
1244            else if(tmpDaughter->GetPdgCode() == 211){
1245              piPosAL = tmpDaughter;
1246              piPosALIndex=daughterIndex;
1247            }
1248          }
1249        }
1250
1251        if(apNeg == NULL || piPosAL == NULL){ // means we do not have two daughters from antilambda decay
1252          continue;
1253        }
1254
1255        if(TMath::Abs(apNeg->Eta())> maxEta || TMath::Abs(piPosAL->Eta())> maxEta){
1256          continue;
1257        }        
1258        
1259        if(apNeg->R()> maxVertex ){
1260          continue; // cuts on distance from collision point
1261        }
1262       
1263       
1264        if( (TMath::Abs(apNeg->Vz()) * lineCutZRSlope - lineCutZValue)  > apNeg->R() ){
1265          continue;               // line cut to exclude regions where we do not reconstruct
1266        }
1267
1268
1269      // Looking at the existance of TPC references
1270
1271        TParticle* ePosTPC;
1272        fMCtruth->MCEvent()->GetParticleAndTR(piPosALIndex,ePosTPC,fclRefsP);
1273
1274        AliMCParticle *mcParticlePos = (AliMCParticle*) (fMCtruth->MCEvent()->GetTrack(piPosALIndex));
1275        if(!mcParticlePos) continue;
1276
1277        Int_t counter; 
1278        Float_t tpcTrackLengthePos = mcParticlePos->GetTPCTrackLength(fESD->GetMagneticField(),0.05,counter,3.0); 
1279
1280        int nPointsP =  fclRefsP->GetEntries();
1281        if (fRefTPC) delete fRefTPC;
1282        fRefTPC = new TObjArray();
1283
1284        for(int iPoint=0; iPoint<nPointsP; iPoint++) {
1285          AliTrackReference *ref = (AliTrackReference*)fclRefsP->At(iPoint);
1286          if (ref->DetectorId() == AliTrackReference::kTPC) fRefTPC->Add(new AliTrackReference(*ref));    
1287        }
1288
1289        fRefTPC->Sort();
1290
1291        for(int i=0; i<fRefTPC->GetEntries(); i++) {
1292          AliTrackReference *ref = (AliTrackReference*)(*fRefTPC)[i]; 
1293          fLabelsTPC[i] = ref->GetTrack();
1294        }
1295        int labelPosRefs=0;
1296        for(int iPoint=GetTPCReference(iTracks);iPoint<fRefTPC->GetEntries();iPoint++){
1297          AliTrackReference* aRef = (AliTrackReference*)(*fRefTPC)[iPoint];
1298          if (aRef->GetTrack() != piPosALIndex ) break;                  
1299          ++labelPosRefs;
1300        }
1301      
1302
1303        TParticle* eNegTPC;
1304        fMCtruth->MCEvent()->GetParticleAndTR(apNegALIndex,eNegTPC,fclRefsN);
1305
1306        AliMCParticle *mcParticleNeg = (AliMCParticle*) (fMCtruth->MCEvent()->GetTrack(apNegALIndex));
1307        if(!mcParticleNeg) continue;
1308
1309        Int_t counterN; 
1310        Float_t tpcTrackLengtheNeg = mcParticleNeg->GetTPCTrackLength(fESD->GetMagneticField(),0.05,counterN,3.0); 
1311
1312        int nPointsN =  fclRefsN->GetEntries();
1313        if (fRefTPC) delete fRefTPC;
1314        fRefTPC = new TObjArray();
1315
1316        for(int iPoint=0; iPoint<nPointsN; iPoint++) {
1317          AliTrackReference *ref = (AliTrackReference*)fclRefsN->At(iPoint);
1318          if (ref->DetectorId() == AliTrackReference::kTPC) fRefTPC->Add(new AliTrackReference(*ref));    
1319        }
1320
1321        fRefTPC->Sort();
1322
1323        for(int i=0; i<fRefTPC->GetEntries(); i++) {
1324          AliTrackReference *ref = (AliTrackReference*)(*fRefTPC)[i]; 
1325          fLabelsTPC[i] = ref->GetTrack();
1326        }
1327        int labelNegRefs=0;
1328        for(int iPoint=GetTPCReference(iTracks);iPoint<fRefTPC->GetEntries();iPoint++){
1329          AliTrackReference* aRef = (AliTrackReference*)(*fRefTPC)[iPoint];
1330          if (aRef->GetTrack() != apNegALIndex ) break;                  
1331          ++labelNegRefs;
1332        }
1333
1334
1335        
1336        if ( labelNegRefs==0 || labelPosRefs==0) continue; // if proton/pi- do not have a TPC ref continue;
1337        ////////////////////////////////////////////////////////////////////
1338      
1339        fnDecayALGeant++;
1340        falDecayALGeantIndex[fnDecayALGeant]=iTracks;
1341      
1342        fpiPosDecayALGeantIndex[fnDecayALGeant]=piPosALIndex;
1343        fapNegDecayALGeantIndex[fnDecayALGeant]=apNegALIndex;
1344
1345        fpiPosDecayALGeantLength[fnDecayALGeant]=tpcTrackLengthePos;
1346        fapNegDecayALGeantLength[fnDecayALGeant]=tpcTrackLengtheNeg;
1347
1348      
1349      }  // AntiLambda    
1350
1351     } //track loop 
1352    }    
1353
1354   }
1355
1356
1357   AliKFParticle::SetField(fESD->GetMagneticField());
1358
1359   const AliESDVertex *pvertex = fESD->GetPrimaryVertex();
1360   Double_t xyzVtx[3];
1361   pvertex->GetXYZ(xyzVtx);
1362
1363   if(fnTracksPrim>0) {
1364
1365     InspectListOfChargedParticles();
1366     InspectListOfV0s();
1367
1368
1369     if(fnConvGamGeant>-1){
1370       FillHnSparseGamma();
1371     }
1372
1373     if(fnDecayK0Geant>-1){
1374       FillHnSparseK0();
1375     }
1376
1377     if(fnDecayLGeant>-1){
1378       FillHnSparseL();
1379     }
1380
1381     if(fnDecayALGeant>-1){
1382       FillHnSparseAL();
1383     }
1384
1385   }
1386
1387  
1388   PostData(1, fOutputContainer );
1389   
1390
1391 }
1392
1393 void AliAnalysisTaskV0QA::Terminate(Option_t *) {
1394   // Draw some histogram at the end.
1395
1396 }
1397
1398
1399 Int_t AliAnalysisTaskV0QA::GetTPCReference(Int_t label) {
1400   // Get TPC References
1401
1402   int start = TMath::BinarySearch(fRefTPC->GetEntries(), fLabelsTPC, label);
1403
1404   while (start >= 0) {
1405     AliTrackReference *ref = (AliTrackReference*)(*fRefTPC)[start];
1406     if (ref->GetTrack() != label) return start+1;
1407     start--;
1408   }
1409
1410   return 0;
1411 }
1412
1413
1414
1415
1416
1417 void AliAnalysisTaskV0QA::InspectListOfChargedParticles(){
1418   // Look at the list of particles for the single track reconstruction
1419
1420   for(Int_t iTracks = 0; iTracks < fESD->GetNumberOfTracks(); iTracks++){
1421
1422     AliESDtrack* curTrack = fESD->GetTrack(iTracks);
1423
1424     if(!curTrack){
1425       continue;
1426     }
1427
1428
1429 //     if( !(curTrack->GetStatus() & AliESDtrack::kTPCrefit)){
1430 //       continue;
1431 //     }
1432
1433
1434     Int_t labelMC = TMath::Abs(curTrack->GetLabel());
1435
1436     if ( labelMC > fStack->GetNtrack() ) continue;
1437
1438
1439     TParticle* curParticle = fStack->Particle(labelMC);
1440     if(curParticle->GetMother(0)==-1){
1441       continue;
1442     }
1443
1444      
1445     if(TMath::Abs(curParticle->GetPdgCode()) == 11){ // e+/e-
1446       
1447       if( fStack->Particle(curParticle->GetMother(0))->GetPdgCode()==22 ){  // e+/e- from gamma
1448         if( curParticle->GetUniqueID()!=5 ){ // e+/e- from gamma conversion
1449           continue;
1450         }
1451
1452         for(Int_t iGamConv=0;iGamConv<fnConvGamGeant+1;iGamConv++ ){
1453           if(curTrack->GetSign()>0){
1454             if (labelMC== fePosConvGamGeantIndex[iGamConv]){
1455               fePosConvGamSingleRecIndex[iGamConv]=iTracks;
1456             }
1457           }else{
1458             if (labelMC== feNegConvGamGeantIndex[iGamConv]){
1459               feNegConvGamSingleRecIndex[iGamConv]=iTracks;
1460             }
1461           }
1462         } // loop over geant converted gammas
1463
1464       }
1465     } // condition to select reconstructed electrons
1466   
1467
1468
1469     if(TMath::Abs(curParticle->GetPdgCode()) == 211 || TMath::Abs(curParticle->GetPdgCode())==2212 ){ // pi+/pi-
1470       
1471       if( fStack->Particle(curParticle->GetMother(0))->GetPdgCode()==310 || 
1472           fStack->Particle(curParticle->GetMother(0))->GetPdgCode()==3122 || 
1473           fStack->Particle(curParticle->GetMother(0))->GetPdgCode()==-3122 ){  // pi+/proton/pi- from K0/Lambda
1474
1475         for(Int_t iK0Dec=0;iK0Dec<fnDecayK0Geant+1;iK0Dec++ ){
1476           if(curTrack->GetSign()>0){
1477             if (labelMC== fpiPosDecayK0GeantIndex[iK0Dec]){
1478               fpiPosDecayK0SingleRecIndex[iK0Dec]=iTracks;
1479             }
1480           }else{
1481             if (labelMC== fpiNegDecayK0GeantIndex[iK0Dec]){
1482               fpiNegDecayK0SingleRecIndex[iK0Dec]=iTracks;
1483             }
1484           }
1485         } // loop over geant decay K0
1486
1487         for(Int_t iLDec=0;iLDec<fnDecayLGeant+1;iLDec++ ){
1488           if(curTrack->GetSign()>0){
1489             if (labelMC== fpPosDecayLGeantIndex[iLDec]){
1490               fpPosDecayLSingleRecIndex[iLDec]=iTracks;
1491             }
1492           }else{
1493             if (labelMC== fpiNegDecayLGeantIndex[iLDec]){
1494               fpiNegDecayLSingleRecIndex[iLDec]=iTracks;
1495             }
1496           }
1497         } // loop over geant decay Lambda
1498
1499         for(Int_t iALDec=0;iALDec<fnDecayALGeant+1;iALDec++ ){
1500           if(curTrack->GetSign()<0){
1501             if (labelMC== fapNegDecayALGeantIndex[iALDec]){
1502               fapNegDecayALSingleRecIndex[iALDec]=iTracks;
1503             }
1504           }else{
1505             if (labelMC== fpiPosDecayALGeantIndex[iALDec]){
1506               fpiPosDecayALSingleRecIndex[iALDec]=iTracks;
1507             }
1508           }
1509         } // loop over geant decay antiLambda
1510       }
1511     } // condition to select reconstructed electrons
1512    } // all reconstructed track
1513
1514
1515 }
1516
1517 void AliAnalysisTaskV0QA::InspectListOfV0s(){
1518   // Look at the list of particles for the V0 reconstruction
1519
1520   AliESDtrack* trackPos= NULL;
1521   AliESDtrack* trackNeg= NULL;
1522   Int_t grandMotherPos=-1;
1523   Int_t grandMotherNeg=-1;
1524   Int_t motherPos=-1;
1525   Int_t motherNeg=-1;
1526   Int_t pIndex=-1;
1527   Int_t nIndex=-1;
1528
1529   for(Int_t iV0MI = 0; iV0MI < fESD->GetNumberOfV0s(); iV0MI++) {
1530
1531     AliESDv0 * fV0MIs = fESD->GetV0(iV0MI);
1532     
1533
1534     if ( !fV0MIs->GetOnFlyStatus() ){
1535         continue;
1536     }
1537     if(fnTracksPrim<=0) {
1538       continue;
1539     }
1540
1541
1542     AliESDtrack* trackPosTest = fESD->GetTrack(fV0MIs->GetPindex());
1543     AliESDtrack* trackNegTest = fESD->GetTrack(fV0MIs->GetNindex());
1544
1545
1546     if ( trackPosTest->GetSign() == trackNegTest->GetSign()){
1547      continue;
1548     }
1549
1550     //To avoid ghosts
1551
1552 //     if( !(trackPosTest->GetStatus() & AliESDtrack::kTPCrefit)){
1553 //       continue;
1554 //     }
1555
1556 //     if( !(trackNegTest->GetStatus() & AliESDtrack::kTPCrefit)){
1557 //       continue;
1558 //     }
1559
1560     if( trackPosTest->GetSign() ==1){
1561       trackPos =fESD->GetTrack(fV0MIs->GetPindex());
1562       trackNeg =fESD->GetTrack(fV0MIs->GetNindex());
1563       pIndex=fV0MIs->GetPindex();
1564       nIndex=fV0MIs->GetNindex();
1565     }
1566
1567     if( trackPosTest->GetSign() ==-1){
1568       trackPos =fESD->GetTrack(fV0MIs->GetNindex());
1569       trackNeg =fESD->GetTrack(fV0MIs->GetPindex());
1570       pIndex=fV0MIs->GetNindex();
1571       nIndex=fV0MIs->GetPindex();
1572
1573     }
1574
1575     Int_t labelNeg=TMath::Abs(trackNeg->GetLabel());
1576     if(labelNeg > fStack->GetNtrack() ) continue;
1577     TParticle * particleNeg= fStack->Particle(labelNeg);
1578
1579     Int_t labelPos=TMath::Abs(trackPos->GetLabel());
1580     if(labelPos > fStack->GetNtrack() ) continue;
1581     TParticle * particlePos= fStack->Particle(labelPos);
1582
1583
1584     if(particlePos->GetMother(0)>-1){
1585       grandMotherPos=fStack->Particle(particlePos->GetMother(0))->GetMother(0);
1586       motherPos=particlePos->GetMother(0);
1587     }
1588     
1589     if(particleNeg->GetMother(0)>-1){
1590       grandMotherNeg=fStack->Particle(particleNeg->GetMother(0))->GetMother(0);
1591       motherNeg=particleNeg->GetMother(0);
1592     }
1593
1594     if(motherPos == motherNeg &&  motherPos!=-1 ){
1595       if( particlePos->GetPdgCode() ==-11  &&   particleNeg->GetPdgCode()==11 ){
1596         for(Int_t iGamConv=0;iGamConv<fnConvGamGeant+1;iGamConv++ ){
1597           if (labelPos== fePosConvGamGeantIndex[iGamConv]){
1598             fePosConvGamV0RecIndex[iGamConv]=pIndex;
1599             fConvGamV0RecIndexPos[iGamConv]=iV0MI;
1600           }
1601           if (labelNeg== feNegConvGamGeantIndex[iGamConv]){
1602             feNegConvGamV0RecIndex[iGamConv]=nIndex;
1603             fConvGamV0RecIndexNeg[iGamConv]=iV0MI;
1604           }
1605
1606         } // loop over geant converted gammas
1607       }
1608
1609       if( particlePos->GetPdgCode()==211  &&   particleNeg->GetPdgCode()==-211 ){
1610         for(Int_t iK0Dec=0;iK0Dec<fnDecayK0Geant+1;iK0Dec++ ){
1611           if (labelPos== fpiPosDecayK0GeantIndex[iK0Dec]){
1612             fpiPosDecayK0V0RecIndex[iK0Dec]=pIndex;
1613             fDecayK0V0RecIndexPos[iK0Dec]=iV0MI;
1614           }
1615           if (labelNeg== fpiNegDecayK0GeantIndex[iK0Dec]){
1616             fpiNegDecayK0V0RecIndex[iK0Dec]=nIndex;
1617             fDecayK0V0RecIndexNeg[iK0Dec]=iV0MI;
1618           }
1619
1620         } // loop over geant K0
1621       }
1622
1623       if( particlePos->GetPdgCode()==2212  && particleNeg->GetPdgCode()==-211 ){
1624         for(Int_t iLDec=0;iLDec<fnDecayLGeant+1;iLDec++ ){
1625           if (labelPos== fpPosDecayLGeantIndex[iLDec]){
1626             fpPosDecayLV0RecIndex[iLDec]=pIndex;
1627             fDecayLV0RecIndexPos[iLDec]=iV0MI;
1628           }
1629           if (labelNeg== fpiNegDecayLGeantIndex[iLDec]){
1630             fpiNegDecayLV0RecIndex[iLDec]=nIndex;
1631             fDecayLV0RecIndexNeg[iLDec]=iV0MI;
1632           }
1633
1634         } // loop over geant Lambda
1635       }
1636
1637       if( particleNeg->GetPdgCode()==-2212  && particlePos->GetPdgCode()==211 ){
1638         for(Int_t iALDec=0;iALDec<fnDecayALGeant+1;iALDec++ ){
1639           if (labelNeg== fapNegDecayALGeantIndex[iALDec]){
1640             fapNegDecayALV0RecIndex[iALDec]=nIndex;
1641             fDecayALV0RecIndexNeg[iALDec]=iV0MI;
1642           }
1643           if (labelPos== fpiPosDecayALGeantIndex[iALDec]){
1644             fpiPosDecayALV0RecIndex[iALDec]=pIndex;
1645             fDecayALV0RecIndexPos[iALDec]=iV0MI;
1646           }
1647
1648         } // loop over geant antiLambda
1649       }
1650
1651
1652     }
1653     
1654   }
1655   for(Int_t iGamConv=0;iGamConv<fnConvGamGeant+1;iGamConv++ ){
1656     if ( fConvGamV0RecIndexNeg[iGamConv]!=  fConvGamV0RecIndexPos[iGamConv]){
1657       fePosConvGamV0RecIndex[iGamConv]=-1;
1658       feNegConvGamV0RecIndex[iGamConv]=-1; 
1659       fConvGamV0RecIndexNeg[iGamConv]=-1;
1660       fConvGamV0RecIndexPos[iGamConv]=-1;
1661
1662     }
1663   }
1664
1665   for(Int_t iLDec=0;iLDec<fnDecayLGeant+1;iLDec++ ){
1666     if(fDecayLV0RecIndexPos[iLDec] !=  fDecayLV0RecIndexNeg[iLDec]){
1667       fpiNegDecayLV0RecIndex[iLDec]=-1;
1668       fpPosDecayLV0RecIndex[iLDec]=-1;
1669       fDecayLV0RecIndexNeg[iLDec]=-1;
1670       fDecayLV0RecIndexPos[iLDec]=-1;
1671     }
1672   }
1673
1674   for(Int_t iALDec=0;iALDec<fnDecayALGeant+1;iALDec++ ){
1675     if(fDecayALV0RecIndexPos[iALDec] !=  fDecayALV0RecIndexNeg[iALDec]){
1676       fpiPosDecayALV0RecIndex[iALDec]=-1;
1677       fapNegDecayALV0RecIndex[iALDec]=-1;
1678       fDecayALV0RecIndexNeg[iALDec]=-1;
1679       fDecayALV0RecIndexPos[iALDec]=-1;
1680     }
1681   }
1682
1683   for(Int_t iK0Dec=0;iK0Dec<fnDecayK0Geant+1;iK0Dec++ ){
1684     if(fDecayK0V0RecIndexPos[iK0Dec] !=  fDecayK0V0RecIndexNeg[iK0Dec]){
1685       fpiNegDecayK0V0RecIndex[iK0Dec]=-1;
1686       fpiPosDecayK0V0RecIndex[iK0Dec]=-1;
1687       fDecayK0V0RecIndexNeg[iK0Dec]=-1;
1688       fDecayK0V0RecIndexPos[iK0Dec]=-1;
1689     }
1690   }
1691   
1692
1693 }
1694 void AliAnalysisTaskV0QA::FillHnSparseGamma()
1695 {
1696   // Fill THnSparse Gamma
1697
1698   Double_t massE=0.00051099892;
1699   Double_t ppSgl[3];
1700   Double_t pmSgl[3];
1701   Float_t bPosSgl[2];
1702   Float_t bNegSgl[2];
1703   Float_t bPosCov[3];
1704   Float_t bNegCov[3];
1705   
1706   Double_t ppV0[3];
1707   Double_t pmV0[3];
1708   Double_t xrG[3];
1709   
1710   TLorentzVector posSglTrack;
1711   TLorentzVector negSglTrack;
1712   Double_t posPt,posEta,posPhi;
1713   Double_t negPt,negEta,negPhi;
1714
1715   TLorentzVector posV0Track;
1716   TLorentzVector negV0Track;
1717   Double_t posV0Pt,posV0Eta,posV0Phi;
1718   Double_t negV0Pt,negV0Eta,negV0Phi;
1719   
1720   Float_t nClsITSPos=-1;
1721   Float_t nClsITSNeg=-1;
1722
1723   Float_t nClsTPCPos=-1;
1724   Float_t nClsTPCNeg=-1;
1725
1726   Int_t statusSingPos=-1;
1727   Int_t statusSingNeg=-1;
1728
1729   Int_t statusV0Pos=-1;
1730   Int_t statusV0Neg=-1;
1731
1732
1733   for(Int_t i=0;i<fnConvGamGeant+1;i++){
1734     TParticle* gamPart = fStack->Particle(fgConvGamGeantIndex[i]);
1735     TParticle* ePosPart = fStack->Particle(fePosConvGamGeantIndex[i]);
1736     TParticle* eNegPart = fStack->Particle(feNegConvGamGeantIndex[i]);
1737     if (fePosConvGamSingleRecIndex[i]!=-1){
1738       AliESDtrack * ePosSglTrack = fESD->GetTrack(fePosConvGamSingleRecIndex[i]);
1739       ePosSglTrack->GetPxPyPz(ppSgl); 
1740       posSglTrack.SetXYZM(ppSgl[0],ppSgl[1],ppSgl[2],massE);
1741       posPt  = posSglTrack.Pt();
1742       posEta = posSglTrack.Eta();
1743       posPhi = posSglTrack.Phi();
1744       ePosSglTrack->GetImpactParameters(bPosSgl,bPosCov);
1745       nClsITSPos=ePosSglTrack->GetNcls(0);
1746       nClsTPCPos=ePosSglTrack->GetNcls(1);
1747       statusSingPos=1;
1748     }else{
1749       posPt  = 1000000;
1750       posEta = -2.;
1751       posPhi = -2*TMath::Pi();
1752       bPosSgl[0]=-100.;
1753       bPosSgl[1]=-100.;
1754       bPosCov[0]=-100;
1755       bPosCov[2]=-100;
1756       nClsITSPos=-1;
1757       nClsTPCPos=-1;
1758       statusSingPos=-1;
1759     }
1760     
1761     if (feNegConvGamSingleRecIndex[i]!=-1){
1762       AliESDtrack * eNegSglTrack = fESD->GetTrack(feNegConvGamSingleRecIndex[i]);
1763       eNegSglTrack->GetPxPyPz(pmSgl); 
1764       negSglTrack.SetXYZM(pmSgl[0],pmSgl[1],pmSgl[2],massE);
1765       negPt  = negSglTrack.Pt();
1766       negEta = negSglTrack.Eta();
1767       negPhi = negSglTrack.Phi();
1768       eNegSglTrack->GetImpactParameters(bNegSgl,bNegCov);
1769       nClsITSNeg=eNegSglTrack->GetNcls(0);
1770       nClsTPCNeg=eNegSglTrack->GetNcls(1);
1771       statusSingNeg=1;
1772     }else{
1773       negPt  = 1000000;
1774       negEta = -2.;
1775       negPhi = -2*TMath::Pi();
1776       bNegSgl[0]=-100.;
1777       bNegSgl[1]=-100.;
1778       bNegCov[0]=-100;
1779       bNegCov[2]=-100;
1780       nClsITSNeg=-1;
1781       nClsTPCNeg=-1;
1782       statusSingNeg=-1;
1783     }
1784
1785     posV0Pt  = 1000000;
1786     posV0Eta = -2.;
1787     posV0Phi = -2*TMath::Pi();
1788     negV0Pt  = 1000000;
1789     negV0Eta = -2.;
1790     negV0Phi = -2*TMath::Pi();
1791     
1792     if(fConvGamV0RecIndexPos[i]!=-1){
1793       AliESDv0 * fV0MIs = fESD->GetV0(fConvGamV0RecIndexPos[i]);
1794       AliESDtrack* trackPosTest = fESD->GetTrack(fV0MIs->GetPindex());
1795       AliESDtrack* trackNegTest = fESD->GetTrack(fV0MIs->GetNindex());
1796
1797       if (fePosConvGamV0RecIndex[i]!=-1 ){
1798         //      AliESDtrack * ePosV0Track = fESD->GetTrack(ePosConvGamV0RecIndex[i]);
1799         if ( trackPosTest->GetSign()==1 ) {
1800           fV0MIs->GetPPxPyPz(ppV0[0],ppV0[1],ppV0[2]);
1801         }else{
1802           fV0MIs->GetNPxPyPz(ppV0[0],ppV0[1],ppV0[2]);
1803         }
1804         posV0Track.SetXYZM(ppV0[0],ppV0[1],ppV0[2],massE);
1805
1806         posV0Pt  = posV0Track.Pt();
1807         posV0Eta = posV0Track.Eta();
1808         posV0Phi = posV0Track.Phi();
1809         statusV0Pos=1;
1810       }else{
1811         posV0Pt  = 1000000;
1812         posV0Eta = -2.;
1813         posV0Phi = -2*TMath::Pi();
1814         statusV0Pos=-1;
1815       }
1816       
1817       if (feNegConvGamV0RecIndex[i]!=-1 ){
1818         //      AliESDtrack * eNegV0Track = fESD->GetTrack(eNegConvGamV0RecIndex[i]);
1819         if ( trackNegTest->GetSign()==-1 ) {
1820           fV0MIs->GetNPxPyPz(pmV0[0],pmV0[1],pmV0[2]);
1821         }else{
1822           fV0MIs->GetPPxPyPz(pmV0[0],pmV0[1],pmV0[2]);
1823         }
1824         negV0Track.SetXYZM(pmV0[0],pmV0[1],pmV0[2],massE);
1825         
1826         negV0Pt  = negV0Track.Pt();
1827         negV0Eta = negV0Track.Eta();
1828         negV0Phi = negV0Track.Phi();
1829         statusV0Neg=1;
1830       }else{
1831         negV0Pt  = 1000000;
1832         negV0Eta = -2.;
1833         negV0Phi = -2*TMath::Pi();
1834         statusV0Neg=-1;
1835       }
1836     }
1837     
1838     xrG[0] = ePosPart->Vx();
1839     xrG[1] = ePosPart->Vy();
1840     xrG[2] = ePosPart->Vz();
1841     
1842     //--------- Geant variables ----------------------
1843     fValueV0[0] = 1./TMath::Sqrt(gamPart->Pt());
1844     fValueV0[1] = gamPart->Eta();
1845
1846     Double_t tmpGPhi=gamPart->Phi();
1847     if( gamPart->Phi()>TMath::Pi()){
1848       tmpGPhi=gamPart->Phi()-2*TMath::Pi();
1849     }
1850     fValueV0[2] = tmpGPhi;
1851
1852     fValueV0[3] = TMath::Sqrt(xrG[0]*xrG[0]+xrG[1]*xrG[1]);
1853     fValueV0[4] = xrG[2];
1854  
1855
1856     fValueV0[5] = 1./TMath::Sqrt(ePosPart->Pt());
1857     fValueV0[6] = ePosPart->Eta();
1858
1859     Double_t tmpPPhi=ePosPart->Phi();
1860     if( ePosPart->Phi()>TMath::Pi()){
1861       tmpPPhi = ePosPart->Phi()-2*TMath::Pi();
1862     }
1863      fValueV0[7] = tmpPPhi;
1864      fValueV0[8] = fePosConvGamGeantLength[i];
1865
1866     fValueV0[9] = 1./TMath::Sqrt(eNegPart->Pt());
1867     fValueV0[10] = eNegPart->Eta();
1868
1869     Double_t tmpNPhi=eNegPart->Phi();
1870     if( eNegPart->Phi()>TMath::Pi()){
1871       tmpNPhi = eNegPart->Phi()-2*TMath::Pi();
1872     }
1873     fValueV0[11] = tmpNPhi;
1874     fValueV0[12] = feNegConvGamGeantLength[i];    
1875
1876     //---- Single track variables----------------------
1877
1878     fValueV0[13] = (posPt-ePosPart->Pt())/ePosPart->Pt();
1879     fValueV0[14] = posEta;
1880     fValueV0[15] = posPhi;
1881     fValueV0[16] = TMath::Sqrt( bPosSgl[0]* bPosSgl[0] +  bPosSgl[1]* bPosSgl[1] );
1882     fValueV0[17] = TMath::Sqrt( bPosSgl[0]* bPosSgl[0] +  bPosSgl[1]* bPosSgl[1] )/TMath::Sqrt(bPosCov[0]*bPosCov[0]+bPosCov[2]*bPosCov[2]);
1883     fValueV0[18] = nClsITSPos;
1884     fValueV0[19] = nClsTPCPos;
1885     fValueV0[20] = statusSingPos;
1886
1887
1888     fValueV0[21] = (negPt-eNegPart->Pt())/eNegPart->Pt();
1889     fValueV0[22] = negEta;
1890     fValueV0[23] = negPhi;
1891     fValueV0[24] = TMath::Sqrt( bNegSgl[0]* bNegSgl[0] +  bNegSgl[1]* bNegSgl[1] );
1892     fValueV0[25] = TMath::Sqrt( bNegSgl[0]* bNegSgl[0] +  bNegSgl[1]* bNegSgl[1] )/TMath::Sqrt(bNegCov[0]*bNegCov[0]+bNegCov[2]*bNegCov[2]);
1893
1894     fValueV0[26] = nClsITSNeg;
1895     fValueV0[27] = nClsTPCNeg;
1896     fValueV0[28] = statusSingNeg;
1897
1898     
1899     //---- V0 track variables----------------------
1900
1901     fValueV0[29] = (posV0Pt-ePosPart->Pt())/ePosPart->Pt();
1902     fValueV0[30] = posV0Eta;
1903     fValueV0[31] = posV0Phi;
1904     fValueV0[32] = statusV0Pos;
1905
1906     fValueV0[33] = (negV0Pt-eNegPart->Pt())/eNegPart->Pt();
1907     fValueV0[34] = negV0Eta;
1908     fValueV0[35] = negV0Phi;
1909     fValueV0[36] = statusV0Neg;
1910
1911     fSparseV0->Fill(fValueV0);
1912   }
1913
1914
1915 }
1916
1917 void AliAnalysisTaskV0QA::FillHnSparseK0()
1918 {
1919   // Fill THnSparse K0
1920
1921   Double_t massPi=0.13957018;
1922   Double_t ppSgl[3];
1923   Double_t pmSgl[3];
1924   Float_t bPosSgl[2];
1925   Float_t bNegSgl[2];
1926   Float_t bPosCov[3];
1927   Float_t bNegCov[3];
1928   
1929   Double_t ppV0[3];
1930   Double_t pmV0[3];
1931   Double_t xrG[3];
1932   
1933   TLorentzVector posSglTrack;
1934   TLorentzVector negSglTrack;
1935   Double_t posPt,posEta,posPhi;
1936   Double_t negPt,negEta,negPhi;
1937
1938   TLorentzVector posV0Track;
1939   TLorentzVector negV0Track;
1940   Double_t posV0Pt,posV0Eta,posV0Phi;
1941   Double_t negV0Pt,negV0Eta,negV0Phi;
1942   
1943   Float_t nClsITSPos=-1;
1944   Float_t nClsITSNeg=-1;
1945
1946   Float_t nClsTPCPos=-1;
1947   Float_t nClsTPCNeg=-1;
1948
1949   Int_t statusSingPos=-1;
1950   Int_t statusSingNeg=-1;
1951
1952   Int_t statusV0Pos=-1;
1953   Int_t statusV0Neg=-1;
1954   
1955   for(Int_t i=0;i<fnDecayK0Geant+1;i++){
1956     TParticle* k0Part = fStack->Particle(fK0DecayK0GeantIndex[i]);
1957     TParticle* ePosPart = fStack->Particle(fpiPosDecayK0GeantIndex[i]);
1958     TParticle* eNegPart = fStack->Particle(fpiNegDecayK0GeantIndex[i]);
1959     if (fpiPosDecayK0SingleRecIndex[i]!=-1){
1960       AliESDtrack * ePosSglTrack = fESD->GetTrack(fpiPosDecayK0SingleRecIndex[i]);
1961       ePosSglTrack->GetPxPyPz(ppSgl); 
1962       posSglTrack.SetXYZM(ppSgl[0],ppSgl[1],ppSgl[2],massPi);
1963       posPt  = posSglTrack.Pt();
1964       posEta = posSglTrack.Eta();
1965       posPhi = posSglTrack.Phi();
1966       ePosSglTrack->GetImpactParameters(bPosSgl,bPosCov);
1967       nClsITSPos=ePosSglTrack->GetNcls(0);
1968       nClsTPCPos=ePosSglTrack->GetNcls(1);
1969       statusSingPos=1;
1970     }else{
1971       posPt  = 1000000;
1972       posEta = -2.;
1973       posPhi = -2*TMath::Pi();
1974       bPosSgl[0]=-100.;
1975       bPosSgl[1]=-100.;
1976       bPosCov[0]=-100;
1977       bPosCov[2]=-100;
1978
1979       nClsITSPos=-1;
1980       nClsTPCPos=-1;
1981       statusSingPos=-1;
1982     }
1983
1984     if (fpiNegDecayK0SingleRecIndex[i]!=-1){
1985       AliESDtrack * eNegSglTrack = fESD->GetTrack(fpiNegDecayK0SingleRecIndex[i]);
1986       eNegSglTrack->GetPxPyPz(pmSgl); 
1987       negSglTrack.SetXYZM(pmSgl[0],pmSgl[1],pmSgl[2],massPi);
1988       negPt  = negSglTrack.Pt();
1989       negEta = negSglTrack.Eta();
1990       negPhi = negSglTrack.Phi();
1991       eNegSglTrack->GetImpactParameters(bNegSgl,bNegCov);
1992       nClsITSNeg=eNegSglTrack->GetNcls(0);
1993       nClsTPCNeg=eNegSglTrack->GetNcls(1);
1994       statusSingNeg=1;
1995     }else{
1996       negPt  = 1000000;
1997       negEta = -2.;
1998       negPhi = -2*TMath::Pi();
1999       bNegSgl[0]=-100.;
2000       bNegSgl[1]=-100.;
2001       bNegCov[0]=-100;
2002       bNegCov[2]=-100;
2003       nClsITSNeg=-1;
2004       nClsTPCNeg=-1;
2005       statusSingNeg=-1;
2006     }
2007
2008     posV0Pt  = 1000000;
2009     posV0Eta = -2.;
2010     posV0Phi = -2*TMath::Pi();
2011     negV0Pt  = 1000000;
2012     negV0Eta = -2.;
2013     negV0Phi = -2*TMath::Pi();
2014
2015     if(fDecayK0V0RecIndexPos[i]!=-1){
2016       AliESDv0 * fV0MIs = fESD->GetV0(fDecayK0V0RecIndexPos[i]);
2017       AliESDtrack* trackPosTest = fESD->GetTrack(fV0MIs->GetPindex());
2018       AliESDtrack* trackNegTest = fESD->GetTrack(fV0MIs->GetNindex());
2019
2020       if (fpiPosDecayK0V0RecIndex[i]!=-1 ){
2021         //      AliESDtrack * ePosV0Track = fESD->GetTrack(piPosDecayK0V0RecIndex[i]);
2022         if ( trackPosTest->GetSign()==1 ) {
2023           fV0MIs->GetPPxPyPz(ppV0[0],ppV0[1],ppV0[2]);
2024         }else{
2025           fV0MIs->GetNPxPyPz(ppV0[0],ppV0[1],ppV0[2]);
2026         }
2027         posV0Track.SetXYZM(ppV0[0],ppV0[1],ppV0[2],massPi);
2028
2029         posV0Pt  = posV0Track.Pt();
2030         posV0Eta = posV0Track.Eta();
2031         posV0Phi = posV0Track.Phi();
2032         statusV0Pos=1;
2033       }else{
2034         posV0Pt  = 1000000;
2035         posV0Eta = -2.;
2036         posV0Phi = -2*TMath::Pi();
2037         statusV0Pos=-1;
2038       }
2039       
2040       if (fpiNegDecayK0V0RecIndex[i]!=-1 ){
2041         //      AliESDtrack * eNegV0Track = fESD->GetTrack(piNegDecayK0V0RecIndex[i]);
2042         if ( trackNegTest->GetSign()==-1 ) {
2043           fV0MIs->GetNPxPyPz(pmV0[0],pmV0[1],pmV0[2]);
2044         }else{
2045           fV0MIs->GetPPxPyPz(pmV0[0],pmV0[1],pmV0[2]);
2046         }
2047         negV0Track.SetXYZM(pmV0[0],pmV0[1],pmV0[2],massPi);
2048         
2049         negV0Pt  = negV0Track.Pt();
2050         negV0Eta = negV0Track.Eta();
2051         negV0Phi = negV0Track.Phi();
2052         statusV0Neg=1;
2053       }else{
2054         negV0Pt  = 1000000;
2055         negV0Eta = -2.;
2056         negV0Phi = -2*TMath::Pi();
2057         statusV0Neg=-1;
2058       }
2059     }
2060
2061     xrG[0] = ePosPart->Vx();
2062     xrG[1] = ePosPart->Vy();
2063     xrG[2] = ePosPart->Vz();
2064     
2065     
2066     //--------- Geant variables ----------------------
2067     fValueK0[0] = 1./TMath::Sqrt(k0Part->Pt());
2068     fValueK0[1] = k0Part->Eta();
2069
2070     Double_t tmpGPhi=k0Part->Phi();
2071     if( k0Part->Phi()>TMath::Pi()){
2072       tmpGPhi=k0Part->Phi()-2*TMath::Pi();
2073     }
2074     fValueK0[2] = tmpGPhi;
2075
2076     fValueK0[3] = TMath::Sqrt(xrG[0]*xrG[0]+xrG[1]*xrG[1]);
2077     fValueK0[4] = xrG[2];
2078  
2079
2080     fValueK0[5] = 1./TMath::Sqrt(ePosPart->Pt());
2081     fValueK0[6] = ePosPart->Eta();
2082
2083     Double_t tmpPPhi=ePosPart->Phi();
2084     if( ePosPart->Phi()>TMath::Pi()){
2085       tmpPPhi = ePosPart->Phi()-2*TMath::Pi();
2086     }
2087      fValueK0[7] = tmpPPhi;
2088      fValueK0[8] = fpiPosDecayK0GeantLength[i];
2089
2090     fValueK0[9] = 1./TMath::Sqrt(eNegPart->Pt());
2091     fValueK0[10] = eNegPart->Eta();
2092
2093     Double_t tmpNPhi=eNegPart->Phi();
2094     if( eNegPart->Phi()>TMath::Pi()){
2095       tmpNPhi = eNegPart->Phi()-2*TMath::Pi();
2096     }
2097     fValueK0[11] = tmpNPhi;
2098     fValueK0[12] = fpiNegDecayK0GeantLength[i];    
2099     //---- Single track variables----------------------
2100
2101     fValueK0[13] = (posPt-ePosPart->Pt())/ePosPart->Pt() ;
2102     fValueK0[14] = posEta;
2103     fValueK0[15] = posPhi;
2104     fValueK0[16] = TMath::Sqrt( bPosSgl[0]* bPosSgl[0] +  bPosSgl[1]* bPosSgl[1] );
2105     fValueK0[17] = TMath::Sqrt( bPosSgl[0]* bPosSgl[0] +  bPosSgl[1]* bPosSgl[1] )/TMath::Sqrt(bPosCov[0]*bPosCov[0]+bPosCov[2]*bPosCov[2]);
2106    
2107     fValueK0[18] = nClsITSPos;
2108     fValueK0[19] = nClsTPCPos;
2109     fValueK0[20] = statusSingPos;
2110
2111     fValueK0[21] = (negPt-eNegPart->Pt())/eNegPart->Pt();
2112     fValueK0[22] = negEta;
2113     fValueK0[23] = negPhi;
2114     fValueK0[24] = TMath::Sqrt( bNegSgl[0]* bNegSgl[0]+  bNegSgl[1]* bNegSgl[1] );
2115     fValueK0[25] = TMath::Sqrt( bNegSgl[0]* bNegSgl[0]+  bNegSgl[1]* bNegSgl[1] )/TMath::Sqrt(bNegCov[0]*bNegCov[0]+bNegCov[2]*bNegCov[2]);
2116     fValueK0[26] = nClsITSNeg;
2117     fValueK0[27] = nClsTPCNeg;
2118     fValueK0[28] = statusSingNeg;
2119
2120     
2121     //---- V0 track variables----------------------
2122
2123     fValueK0[29] = (posV0Pt-ePosPart->Pt())/ePosPart->Pt();
2124     fValueK0[30] = posV0Eta;
2125     fValueK0[31] = posV0Phi;
2126     fValueK0[32] = statusV0Pos;
2127
2128     fValueK0[33] = (negV0Pt-eNegPart->Pt())/eNegPart->Pt();
2129     fValueK0[34] = negV0Eta;
2130     fValueK0[35] = negV0Phi;
2131     fValueK0[36] = statusV0Neg;
2132
2133     fSparseK0->Fill(fValueK0);
2134   }
2135   
2136
2137 }
2138 void AliAnalysisTaskV0QA::FillHnSparseL()
2139 {
2140   // Fill THnSparse Lambda
2141
2142   Double_t massPi=0.13957018;
2143   Double_t massP=0.93827203;
2144
2145
2146   Double_t ppSgl[3];
2147   Double_t pmSgl[3];
2148   Float_t bPosSgl[2];
2149   Float_t bNegSgl[2];
2150   Float_t bPosCov[3];
2151   Float_t bNegCov[3];
2152   
2153   Double_t ppV0[3];
2154   Double_t pmV0[3];
2155   Double_t xrG[3];
2156   
2157   TLorentzVector posSglTrack;
2158   TLorentzVector negSglTrack;
2159   Double_t posPt,posEta,posPhi;
2160   Double_t negPt,negEta,negPhi;
2161
2162   TLorentzVector posV0Track;
2163   TLorentzVector negV0Track;
2164   Double_t posV0Pt,posV0Eta,posV0Phi;
2165   Double_t negV0Pt,negV0Eta,negV0Phi;
2166   
2167   Float_t nClsITSPos=-1;
2168   Float_t nClsITSNeg=-1;
2169
2170   Float_t nClsTPCPos=-1;
2171   Float_t nClsTPCNeg=-1;
2172
2173   Int_t statusSingPos=-1;
2174   Int_t statusSingNeg=-1;
2175
2176   Int_t statusV0Pos=-1;
2177   Int_t statusV0Neg=-1;
2178
2179   for(Int_t i=0;i<fnDecayLGeant+1;i++){
2180     TParticle* lPart = fStack->Particle(flDecayLGeantIndex[i]);
2181     TParticle* ePosPart = fStack->Particle(fpPosDecayLGeantIndex[i]);
2182     TParticle* eNegPart = fStack->Particle(fpiNegDecayLGeantIndex[i]);
2183     if (fpPosDecayLSingleRecIndex[i]!=-1){
2184       AliESDtrack * ePosSglTrack = fESD->GetTrack(fpPosDecayLSingleRecIndex[i]);
2185       ePosSglTrack->GetPxPyPz(ppSgl); 
2186       posSglTrack.SetXYZM(ppSgl[0],ppSgl[1],ppSgl[2],massP);
2187       posPt  = posSglTrack.Pt();
2188       posEta = posSglTrack.Eta();
2189       posPhi = posSglTrack.Phi();
2190       ePosSglTrack->GetImpactParameters(bPosSgl,bPosCov);
2191       nClsITSPos=ePosSglTrack->GetNcls(0);
2192       nClsTPCPos=ePosSglTrack->GetNcls(1);
2193       statusSingPos=1;
2194     }else{
2195       posPt  = 1000000;
2196       posEta = -2.;
2197       posPhi = -2*TMath::Pi();
2198       bPosSgl[0]=-100.;
2199       bPosSgl[1]=-100.;
2200       bPosCov[0]=-100;
2201       bPosCov[2]=-100;
2202       nClsITSPos=-1;
2203       nClsTPCPos=-1;
2204       statusSingPos=-1;
2205     }
2206     
2207     if (fpiNegDecayLSingleRecIndex[i]!=-1){
2208       AliESDtrack * eNegSglTrack = fESD->GetTrack(fpiNegDecayLSingleRecIndex[i]);
2209       eNegSglTrack->GetPxPyPz(pmSgl); 
2210       negSglTrack.SetXYZM(pmSgl[0],pmSgl[1],pmSgl[2],massPi);
2211       negPt  = negSglTrack.Pt();
2212       negEta = negSglTrack.Eta();
2213       negPhi = negSglTrack.Phi();
2214       eNegSglTrack->GetImpactParameters(bNegSgl,bNegCov);
2215       nClsITSNeg=eNegSglTrack->GetNcls(0);
2216       nClsTPCNeg=eNegSglTrack->GetNcls(1);
2217       statusSingNeg=1;
2218     }else{
2219       negPt  = 1000000;
2220       negEta = -2.;
2221       negPhi = -2*TMath::Pi();
2222       bNegSgl[0]=-100.;
2223       bNegSgl[1]=-100.;
2224       bNegCov[0]=-100;
2225       bNegCov[2]=-100;
2226       nClsITSNeg=-1;
2227       nClsTPCNeg=-1;
2228       statusSingNeg=-1;
2229     }
2230
2231     posV0Pt  = 1000000;
2232     posV0Eta = -2.;
2233     posV0Phi = -2*TMath::Pi();
2234     negV0Pt  = 1000000;
2235     negV0Eta = -2.;
2236     negV0Phi = -2*TMath::Pi();
2237     
2238     if(fDecayLV0RecIndexPos[i]!=-1){
2239       AliESDv0 * fV0MIs = fESD->GetV0(fDecayLV0RecIndexPos[i]);
2240       AliESDtrack* trackPosTest = fESD->GetTrack(fV0MIs->GetPindex());
2241       AliESDtrack* trackNegTest = fESD->GetTrack(fV0MIs->GetNindex());
2242
2243       if (fpPosDecayLV0RecIndex[i]!=-1 ){
2244         //      AliESDtrack * ePosV0Track = fESD->GetTrack(pPosDecayLV0RecIndex[i]);
2245         if ( trackPosTest->GetSign()==1 ) {
2246           fV0MIs->GetPPxPyPz(ppV0[0],ppV0[1],ppV0[2]);
2247         }else{
2248           fV0MIs->GetNPxPyPz(ppV0[0],ppV0[1],ppV0[2]);
2249         }
2250         posV0Track.SetXYZM(ppV0[0],ppV0[1],ppV0[2],massP);
2251
2252         posV0Pt  = posV0Track.Pt();
2253         posV0Eta = posV0Track.Eta();
2254         posV0Phi = posV0Track.Phi();
2255         statusV0Pos=1;
2256       }else{
2257         posV0Pt  = 1000000;
2258         posV0Eta = -2.;
2259         posV0Phi = -2*TMath::Pi();
2260         statusV0Pos=-1;
2261       }
2262       
2263       if (fpiNegDecayLV0RecIndex[i]!=-1 ){
2264         //      AliESDtrack * eNegV0Track = fESD->GetTrack(piNegDecayLV0RecIndex[i]);
2265         if ( trackNegTest->GetSign()==-1 ) {
2266           fV0MIs->GetNPxPyPz(pmV0[0],pmV0[1],pmV0[2]);
2267         }else{
2268           fV0MIs->GetPPxPyPz(pmV0[0],pmV0[1],pmV0[2]);
2269         }
2270         negV0Track.SetXYZM(pmV0[0],pmV0[1],pmV0[2],massPi);
2271         
2272         negV0Pt  = negV0Track.Pt();
2273         negV0Eta = negV0Track.Eta();
2274         negV0Phi = negV0Track.Phi();
2275         statusV0Neg=1;
2276       }else{
2277         negV0Pt  = 1000000;
2278         negV0Eta = -2.;
2279         negV0Phi = -2*TMath::Pi();
2280         statusV0Neg=-1;
2281       }
2282     }
2283     
2284     xrG[0] = ePosPart->Vx();
2285     xrG[1] = ePosPart->Vy();
2286     xrG[2] = ePosPart->Vz();
2287     
2288     //--------- Geant variables ----------------------
2289     fValueL[0] = 1./TMath::Sqrt(lPart->Pt());
2290     fValueL[1] = lPart->Eta();
2291
2292     Double_t tmpGPhi=lPart->Phi();
2293     if( lPart->Phi()>TMath::Pi()){
2294       tmpGPhi=lPart->Phi()-2*TMath::Pi();
2295     }
2296     fValueL[2] = tmpGPhi;
2297
2298     fValueL[3] = TMath::Sqrt(xrG[0]*xrG[0]+xrG[1]*xrG[1]);
2299     fValueL[4] = xrG[2];
2300  
2301
2302     fValueL[5] = 1./TMath::Sqrt(ePosPart->Pt());
2303     fValueL[6] = ePosPart->Eta();
2304
2305     Double_t tmpPPhi=ePosPart->Phi();
2306     if( ePosPart->Phi()>TMath::Pi()){
2307       tmpPPhi = ePosPart->Phi()-2*TMath::Pi();
2308     }
2309      fValueL[7] = tmpPPhi;
2310      fValueL[8] = fpPosDecayLGeantLength[i];
2311
2312     fValueL[9] = 1./TMath::Sqrt(eNegPart->Pt());
2313     fValueL[10] = eNegPart->Eta();
2314
2315     Double_t tmpNPhi=eNegPart->Phi();
2316     if( eNegPart->Phi()>TMath::Pi()){
2317       tmpNPhi = eNegPart->Phi()-2*TMath::Pi();
2318     }
2319     fValueL[11] = tmpNPhi;
2320     fValueL[12] = fpiNegDecayLGeantLength[i];    
2321     //---- Single track variables----------------------
2322
2323     fValueL[13] = (posPt-ePosPart->Pt())/ePosPart->Pt();
2324     fValueL[14] = posEta;
2325     fValueL[15] = posPhi;
2326     fValueL[16] = TMath::Sqrt( bPosSgl[0]* bPosSgl[0] +  bPosSgl[1]* bPosSgl[1]);
2327     fValueL[17] = TMath::Sqrt( bPosSgl[0]* bPosSgl[0] +  bPosSgl[1]* bPosSgl[1] )/TMath::Sqrt(bPosCov[0]*bPosCov[0]+bPosCov[2]*bPosCov[2]);   
2328     fValueL[18] = nClsITSPos;
2329     fValueL[19] = nClsTPCPos;
2330     fValueL[20] = statusSingPos;
2331
2332     fValueL[21] = (negPt-eNegPart->Pt())/eNegPart->Pt() ;
2333     fValueL[22] = negEta;
2334     fValueL[23] = negPhi;
2335     fValueL[24] = TMath::Sqrt( bNegSgl[0]* bNegSgl[0] +  bNegSgl[1]* bNegSgl[1] );
2336     fValueL[25] = TMath::Sqrt( bNegSgl[0]* bNegSgl[0] +  bNegSgl[1]* bNegSgl[1] )/TMath::Sqrt(bNegCov[0]*bNegCov[0]+bNegCov[2]*bNegCov[2]);
2337     fValueL[26] = nClsITSNeg;
2338     fValueL[27] = nClsTPCNeg;
2339     fValueL[28] = statusSingNeg;
2340
2341
2342     
2343     //---- V0 track variables----------------------
2344
2345     fValueL[29] = (posV0Pt-ePosPart->Pt())/ePosPart->Pt();
2346     fValueL[30] = posV0Eta;
2347     fValueL[31] = posV0Phi;
2348     fValueL[32] = statusV0Pos;
2349
2350
2351     fValueL[33] = (negV0Pt-eNegPart->Pt())/eNegPart->Pt();
2352     fValueL[34] = negV0Eta;
2353     fValueL[35] = negV0Phi;
2354     fValueL[36] = statusV0Neg;
2355
2356     fSparseL->Fill(fValueL);
2357   }
2358
2359
2360 }
2361
2362 void AliAnalysisTaskV0QA::FillHnSparseAL()
2363 {
2364   // Fill THnSparse Antilambda
2365
2366   Double_t massPi=0.13957018;
2367   Double_t massP=0.93827203;
2368
2369
2370   Double_t ppSgl[3];
2371   Double_t pmSgl[3];
2372   Float_t bPosSgl[2];
2373   Float_t bNegSgl[2];
2374   Float_t bPosCov[3];
2375   Float_t bNegCov[3];
2376   
2377   Double_t ppV0[3];
2378   Double_t pmV0[3];
2379   Double_t xrG[3];
2380   
2381   TLorentzVector posSglTrack;
2382   TLorentzVector negSglTrack;
2383   Double_t posPt,posEta,posPhi;
2384   Double_t negPt,negEta,negPhi;
2385
2386   TLorentzVector posV0Track;
2387   TLorentzVector negV0Track;
2388   Double_t posV0Pt,posV0Eta,posV0Phi;
2389   Double_t negV0Pt,negV0Eta,negV0Phi;
2390   
2391   Float_t nClsITSPos=-1;
2392   Float_t nClsITSNeg=-1;
2393
2394   Float_t nClsTPCPos=-1;
2395   Float_t nClsTPCNeg=-1;
2396
2397   Int_t statusSingPos=-1;
2398   Int_t statusSingNeg=-1;
2399
2400   Int_t statusV0Pos=-1;
2401   Int_t statusV0Neg=-1;
2402
2403
2404   for(Int_t i=0;i<fnDecayALGeant+1;i++){
2405     TParticle* alPart = fStack->Particle(falDecayALGeantIndex[i]);
2406     TParticle* eNegPart = fStack->Particle(fapNegDecayALGeantIndex[i]);
2407     TParticle* ePosPart = fStack->Particle(fpiPosDecayALGeantIndex[i]);
2408     if (fpiPosDecayALSingleRecIndex[i]!=-1){
2409       AliESDtrack * ePosSglTrack = fESD->GetTrack(fpiPosDecayALSingleRecIndex[i]);
2410       ePosSglTrack->GetPxPyPz(ppSgl); 
2411       posSglTrack.SetXYZM(ppSgl[0],ppSgl[1],ppSgl[2],massPi);
2412       posPt  = posSglTrack.Pt();
2413       posEta = posSglTrack.Eta();
2414       posPhi = posSglTrack.Phi();
2415       ePosSglTrack->GetImpactParameters(bPosSgl,bPosCov);
2416       nClsITSPos=ePosSglTrack->GetNcls(0);
2417       nClsTPCPos=ePosSglTrack->GetNcls(1);
2418       statusSingPos=1;
2419     }else{
2420       posPt  = 1000000;
2421       posEta = -2.;
2422       posPhi = -2*TMath::Pi();
2423       bPosSgl[0]=-100.;
2424       bPosSgl[1]=-100.;
2425       bPosCov[0]=-100;
2426       bPosCov[2]=-100;
2427       nClsITSPos=-1;
2428       nClsTPCPos=-1;
2429       statusSingPos=-1;
2430     }
2431     
2432     if (fapNegDecayALSingleRecIndex[i]!=-1){
2433       AliESDtrack * eNegSglTrack = fESD->GetTrack(fapNegDecayALSingleRecIndex[i]);
2434       eNegSglTrack->GetPxPyPz(pmSgl); 
2435       negSglTrack.SetXYZM(pmSgl[0],pmSgl[1],pmSgl[2],massP);
2436       negPt  = negSglTrack.Pt();
2437       negEta = negSglTrack.Eta();
2438       negPhi = negSglTrack.Phi();
2439       eNegSglTrack->GetImpactParameters(bNegSgl,bNegCov);
2440       nClsITSNeg=eNegSglTrack->GetNcls(0);
2441       nClsTPCNeg=eNegSglTrack->GetNcls(1);
2442       statusSingNeg=1;
2443     }else{
2444       negPt  = 1000000;
2445       negEta = -2.;
2446       negPhi = -2*TMath::Pi();
2447       bNegSgl[0]=-100.;
2448       bNegSgl[1]=-100.;
2449       bNegCov[0]=-100;
2450       bNegCov[2]=-100;
2451       nClsITSNeg=-1;
2452       nClsTPCNeg=-1;
2453       statusSingNeg=-1;
2454     }
2455
2456     posV0Pt  = 1000000;
2457     posV0Eta = -2.;
2458     posV0Phi = -2*TMath::Pi();
2459     negV0Pt  = 1000000;
2460     negV0Eta = -2.;
2461     negV0Phi = -2*TMath::Pi();
2462     
2463     if(fDecayALV0RecIndexPos[i]!=-1){
2464       AliESDv0 * fV0MIs = fESD->GetV0(fDecayALV0RecIndexPos[i]);
2465       AliESDtrack* trackPosTest = fESD->GetTrack(fV0MIs->GetPindex());
2466       AliESDtrack* trackNegTest = fESD->GetTrack(fV0MIs->GetNindex());
2467
2468       if (fpiPosDecayALV0RecIndex[i]!=-1 ){
2469         //      AliESDtrack * ePosV0Track = fESD->GetTrack(piPosDecayALV0RecIndex[i]);
2470         if ( trackPosTest->GetSign()==1 ) {
2471           fV0MIs->GetPPxPyPz(ppV0[0],ppV0[1],ppV0[2]);
2472         }else{
2473           fV0MIs->GetNPxPyPz(ppV0[0],ppV0[1],ppV0[2]);
2474         }
2475         posV0Track.SetXYZM(ppV0[0],ppV0[1],ppV0[2],massPi);
2476
2477         posV0Pt  = posV0Track.Pt();
2478         posV0Eta = posV0Track.Eta();
2479         posV0Phi = posV0Track.Phi();
2480         statusV0Pos=1;
2481       }else{
2482         posV0Pt  = 1000000;
2483         posV0Eta = -2.;
2484         posV0Phi = -2*TMath::Pi();
2485         statusV0Pos=-1;
2486       }
2487       
2488       if (fapNegDecayALV0RecIndex[i]!=-1 ){
2489         //      AliESDtrack * eNegV0Track = fESD->GetTrack(apNegDecayALV0RecIndex[i]);
2490         if ( trackNegTest->GetSign()==-1 ) {
2491           fV0MIs->GetNPxPyPz(pmV0[0],pmV0[1],pmV0[2]);
2492         }else{
2493           fV0MIs->GetPPxPyPz(pmV0[0],pmV0[1],pmV0[2]);
2494         }
2495         negV0Track.SetXYZM(pmV0[0],pmV0[1],pmV0[2],massP);
2496         
2497         negV0Pt  = negV0Track.Pt();
2498         negV0Eta = negV0Track.Eta();
2499         negV0Phi = negV0Track.Phi();
2500         statusV0Neg=1;
2501       }else{
2502         negV0Pt  = 1000000;
2503         negV0Eta = -2.;
2504         negV0Phi = -2*TMath::Pi();
2505         statusV0Neg=-1;
2506       }
2507     }
2508     
2509     xrG[0] = ePosPart->Vx();
2510     xrG[1] = ePosPart->Vy();
2511     xrG[2] = ePosPart->Vz();
2512     
2513     //--------- Geant variables ----------------------
2514     fValueAL[0] = 1./TMath::Sqrt(alPart->Pt());
2515     fValueAL[1] = alPart->Eta();
2516
2517     Double_t tmpGPhi=alPart->Phi();
2518     if( alPart->Phi()>TMath::Pi()){
2519       tmpGPhi=alPart->Phi()-2*TMath::Pi();
2520     }
2521     fValueAL[2] = tmpGPhi;
2522
2523     fValueAL[3] = TMath::Sqrt(xrG[0]*xrG[0]+xrG[1]*xrG[1]);
2524     fValueAL[4] = xrG[2];
2525  
2526
2527     fValueAL[5] = 1./TMath::Sqrt(ePosPart->Pt());
2528     fValueAL[6] = ePosPart->Eta();
2529
2530     Double_t tmpPPhi=ePosPart->Phi();
2531     if( ePosPart->Phi()>TMath::Pi()){
2532       tmpPPhi = ePosPart->Phi()-2*TMath::Pi();
2533     }
2534      fValueAL[7] = tmpPPhi;
2535      fValueAL[8] = fpiPosDecayALGeantLength[i];
2536
2537     fValueAL[9] = 1./TMath::Sqrt(eNegPart->Pt());
2538     fValueAL[10] = eNegPart->Eta();
2539
2540     Double_t tmpNPhi=eNegPart->Phi();
2541     if( eNegPart->Phi()>TMath::Pi()){
2542       tmpNPhi = eNegPart->Phi()-2*TMath::Pi();
2543     }
2544     fValueAL[11] = tmpNPhi;
2545     fValueAL[12] = fapNegDecayALGeantLength[i];    
2546     //---- Single track variables----------------------
2547
2548     fValueAL[13] = (posPt-ePosPart->Pt())/ePosPart->Pt();
2549     fValueAL[14] = posEta;
2550     fValueAL[15] = posPhi;
2551     fValueAL[16] = TMath::Sqrt( bPosSgl[0]* bPosSgl[0] +  bPosSgl[1]* bPosSgl[1]);
2552     fValueAL[17] = TMath::Sqrt( bPosSgl[0]* bPosSgl[0] +  bPosSgl[1]* bPosSgl[1] )/TMath::Sqrt(bPosCov[0]*bPosCov[0]+bPosCov[2]*bPosCov[2]);   
2553     fValueAL[18] = nClsITSPos;
2554     fValueAL[19] = nClsTPCPos;
2555     fValueAL[20] = statusSingPos;
2556
2557     fValueAL[21] = (negPt-eNegPart->Pt())/eNegPart->Pt() ;
2558     fValueAL[22] = negEta;
2559     fValueAL[23] = negPhi;
2560     fValueAL[24] = TMath::Sqrt( bNegSgl[0]* bNegSgl[0] +  bNegSgl[1]* bNegSgl[1] );
2561     fValueAL[25] = TMath::Sqrt( bNegSgl[0]* bNegSgl[0] +  bNegSgl[1]* bNegSgl[1] )/TMath::Sqrt(bNegCov[0]*bNegCov[0]+bNegCov[2]*bNegCov[2]);
2562     fValueAL[26] = nClsITSNeg;
2563     fValueAL[27] = nClsTPCNeg;
2564     fValueAL[28] = statusSingNeg;
2565
2566
2567     
2568     //---- V0 track variables----------------------
2569
2570     fValueAL[29] = (posV0Pt-ePosPart->Pt())/ePosPart->Pt();
2571     fValueAL[30] = posV0Eta;
2572     fValueAL[31] = posV0Phi;
2573     fValueAL[32] = statusV0Pos;
2574
2575
2576     fValueAL[33] = (negV0Pt-eNegPart->Pt())/eNegPart->Pt();
2577     fValueAL[34] = negV0Eta;
2578     fValueAL[35] = negV0Phi;
2579     fValueAL[36] = statusV0Neg;
2580
2581     fSparseAL->Fill(fValueAL);
2582   }
2583 }
2584
2585
2586 // void AliAnalysisTaskV0QA::SetESDtrackCuts()
2587 // {
2588
2589 //   fEsdTrackCuts = new AliESDtrackCuts("AliESDtrackCuts");
2590
2591 //   fEsdTrackCuts->SetRequireTPCRefit(kTRUE);
2592 //   fEsdTrackCuts->SetAcceptKinkDaughters(kFALSE);
2593
2594
2595
2596 // }