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